Update .po files
[phpmyadmin.git] / libraries / display_tbl.lib.php
blob48ac01acbdee18157adba7d5f2d0d29a36b5e1e8
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)
366 && $num_rows >= $_SESSION['tmp_user_values']['max_rows']
367 && $_SESSION['tmp_user_values']['max_rows'] != 'all'
369 // display the Next button
370 PMA_displayTableNavigationOneButton(
371 '&gt;',
372 _pgettext('Next page', 'Next'),
373 $pos_next,
374 $html_sql_query
377 // prepare some options for the End button
378 if ($is_innodb && $unlim_num_rows > $GLOBALS['cfg']['MaxExactCount']) {
379 $input_for_real_end = '<input id="real_end_input" type="hidden" name="find_real_end" value="1" />';
380 // no backquote around this message
381 $onclick = '';
382 } else {
383 $input_for_real_end = $onclick = '';
386 // display the End button
387 PMA_displayTableNavigationOneButton(
388 '&gt;&gt;',
389 _pgettext('Last page', 'End'),
390 @((ceil($unlim_num_rows / $_SESSION['tmp_user_values']['max_rows'])- 1) * $_SESSION['tmp_user_values']['max_rows']),
391 $html_sql_query,
392 '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') . '"',
393 $input_for_real_end,
394 $onclick
396 } // end move toward
398 // show separator if pagination happen
399 if ($nbTotalPage > 1) {
400 echo '<td><div class="navigation_separator">|</div></td>';
403 <td>
404 <div class="save_edited hide">
405 <input type="submit" value="<?php echo __('Save edited data'); ?>" />
406 <div class="navigation_separator">|</div>
407 </div>
408 </td>
409 <td>
410 <div class="restore_column hide">
411 <input type="submit" value="<?php echo __('Restore column order'); ?>" />
412 <div class="navigation_separator">|</div>
413 </div>
414 </td>
416 <?php // if displaying a VIEW, $unlim_num_rows could be zero because
417 // of $cfg['MaxExactCountViews']; in this case, avoid passing
418 // the 5th parameter to checkFormElementInRange()
419 // (this means we can't validate the upper limit ?>
420 <td class="navigation_goto">
421 <form action="sql.php" method="post"
422 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 : ''; ?>))">
423 <?php echo PMA_generate_common_hidden_inputs($db, $table); ?>
424 <input type="hidden" name="sql_query" value="<?php echo $html_sql_query; ?>" />
425 <input type="hidden" name="goto" value="<?php echo $goto; ?>" />
426 <input type="submit" name="navig" <?php echo ($GLOBALS['cfg']['AjaxEnable'] ? ' class="ajax"' : ''); ?> value="<?php echo __('Show'); ?> :" />
427 <?php echo __('Start row') . ': ' . "\n"; ?>
428 <input type="text" name="pos" size="3" value="<?php echo (($pos_next >= $unlim_num_rows) ? 0 : $pos_next); ?>" class="textfield" onfocus="this.select()" />
429 <?php echo __('Number of rows') . ': ' . "\n"; ?>
430 <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()" />
431 <?php
432 if ($GLOBALS['cfg']['ShowDisplayDirection']) {
433 // Display mode (horizontal/vertical and repeat headers)
434 echo __('Mode') . ': ' . "\n";
435 $choices = array(
436 'horizontal' => __('horizontal'),
437 'horizontalflipped' => __('horizontal (rotated headers)'),
438 'vertical' => __('vertical'));
439 echo PMA_generate_html_dropdown('disp_direction', $choices, $_SESSION['tmp_user_values']['disp_direction'], $id_for_direction_dropdown);
440 unset($choices);
443 printf(
444 __('Headers every %s rows'),
445 '<input type="text" size="3" name="repeat_cells" value="' . $_SESSION['tmp_user_values']['repeat_cells'] . '" class="textfield" />'
447 echo "\n";
449 </form>
450 </td>
451 <td class="navigation_separator"></td>
452 </tr>
453 </table>
455 <?php
456 } // end of the 'PMA_displayTableNavigation()' function
460 * Displays the headers of the results table
462 * @param array &$is_display which elements to display
463 * @param array &$fields_meta the list of fields properties
464 * @param integer $fields_cnt the total number of fields returned by the SQL query
465 * @param array $analyzed_sql the analyzed query
466 * @param string $sort_expression sort expression
467 * @param string $sort_expression_nodirection sort expression without direction
468 * @param string $sort_direction sort direction
470 * @return boolean $clause_is_unique
472 * @global string $db the database name
473 * @global string $table the table name
474 * @global string $goto the URL to go back in case of errors
475 * @global string $sql_query the SQL query
476 * @global integer $num_rows the total number of rows returned by the
477 * SQL query
478 * @global array $vertical_display informations used with vertical display
479 * mode
481 * @access private
483 * @see PMA_displayTable()
485 function PMA_displayTableHeaders(&$is_display, &$fields_meta, $fields_cnt = 0, $analyzed_sql = '', $sort_expression, $sort_expression_nodirection, $sort_direction)
487 global $db, $table, $goto;
488 global $sql_query, $num_rows;
489 global $vertical_display, $highlight_columns;
491 // required to generate sort links that will remember whether the
492 // "Show all" button has been clicked
493 $sql_md5 = md5($GLOBALS['sql_query']);
494 $session_max_rows = $_SESSION['tmp_user_values']['query'][$sql_md5]['max_rows'];
496 if ($analyzed_sql == '') {
497 $analyzed_sql = array();
500 // can the result be sorted?
501 if ($is_display['sort_lnk'] == '1') {
503 // Just as fallback
504 $unsorted_sql_query = $sql_query;
505 if (isset($analyzed_sql[0]['unsorted_query'])) {
506 $unsorted_sql_query = $analyzed_sql[0]['unsorted_query'];
508 // Handles the case of multiple clicks on a column's header
509 // which would add many spaces before "ORDER BY" in the
510 // generated query.
511 $unsorted_sql_query = trim($unsorted_sql_query);
513 // sorting by indexes, only if it makes sense (only one table ref)
514 if (isset($analyzed_sql)
515 && isset($analyzed_sql[0])
516 && isset($analyzed_sql[0]['querytype'])
517 && $analyzed_sql[0]['querytype'] == 'SELECT'
518 && isset($analyzed_sql[0]['table_ref'])
519 && count($analyzed_sql[0]['table_ref']) == 1
522 // grab indexes data:
523 $indexes = PMA_Index::getFromTable($table, $db);
525 // do we have any index?
526 if ($indexes) {
528 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
529 || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped'
531 $span = $fields_cnt;
532 if ($is_display['edit_lnk'] != 'nn') {
533 $span++;
535 if ($is_display['del_lnk'] != 'nn') {
536 $span++;
538 if ($is_display['del_lnk'] != 'kp' && $is_display['del_lnk'] != 'nn') {
539 $span++;
541 } else {
542 $span = $num_rows + floor($num_rows/$_SESSION['tmp_user_values']['repeat_cells']) + 1;
545 echo '<form action="sql.php" method="post">' . "\n";
546 echo PMA_generate_common_hidden_inputs($db, $table);
547 echo __('Sort by key') . ': <select name="sql_query" class="autosubmit">' . "\n";
548 $used_index = false;
549 $local_order = (isset($sort_expression) ? $sort_expression : '');
550 foreach ($indexes as $index) {
551 $asc_sort = '`' . implode('` ASC, `', array_keys($index->getColumns())) . '` ASC';
552 $desc_sort = '`' . implode('` DESC, `', array_keys($index->getColumns())) . '` DESC';
553 $used_index = $used_index || $local_order == $asc_sort || $local_order == $desc_sort;
554 if (preg_match('@(.*)([[:space:]](LIMIT (.*)|PROCEDURE (.*)|FOR UPDATE|LOCK IN SHARE MODE))@is', $unsorted_sql_query, $my_reg)) {
555 $unsorted_sql_query_first_part = $my_reg[1];
556 $unsorted_sql_query_second_part = $my_reg[2];
557 } else {
558 $unsorted_sql_query_first_part = $unsorted_sql_query;
559 $unsorted_sql_query_second_part = '';
561 echo '<option value="'
562 . htmlspecialchars($unsorted_sql_query_first_part . "\n" . ' ORDER BY ' . $asc_sort . $unsorted_sql_query_second_part)
563 . '"' . ($local_order == $asc_sort ? ' selected="selected"' : '')
564 . '>' . htmlspecialchars($index->getName()) . ' ('
565 . __('Ascending') . ')</option>';
566 echo '<option value="'
567 . htmlspecialchars($unsorted_sql_query_first_part . "\n" . ' ORDER BY ' . $desc_sort . $unsorted_sql_query_second_part)
568 . '"' . ($local_order == $desc_sort ? ' selected="selected"' : '')
569 . '>' . htmlspecialchars($index->getName()) . ' ('
570 . __('Descending') . ')</option>';
572 echo '<option value="' . htmlspecialchars($unsorted_sql_query) . '"' . ($used_index ? '' : ' selected="selected"') . '>' . __('None') . '</option>';
573 echo '</select>' . "\n";
574 echo '<noscript><input type="submit" value="' . __('Go') . '" /></noscript>';
575 echo '</form>' . "\n";
581 // Output data needed for grid editing
582 echo '<input id="save_cells_at_once" type="hidden" value="' . $GLOBALS['cfg']['SaveCellsAtOnce'] . '" />';
583 echo '<div class="common_hidden_inputs">';
584 echo PMA_generate_common_hidden_inputs($db, $table);
585 echo '</div>';
586 // Output data needed for column reordering and show/hide column
587 if (PMA_isSelect()) {
588 // generate the column order, if it is set
589 $pmatable = new PMA_Table($GLOBALS['table'], $GLOBALS['db']);
590 $col_order = $pmatable->getUiProp(PMA_Table::PROP_COLUMN_ORDER);
591 if ($col_order) {
592 echo '<input id="col_order" type="hidden" value="' . implode(',', $col_order) . '" />';
594 $col_visib = $pmatable->getUiProp(PMA_Table::PROP_COLUMN_VISIB);
595 if ($col_visib) {
596 echo '<input id="col_visib" type="hidden" value="' . implode(',', $col_visib) . '" />';
598 // generate table create time
599 if (! PMA_Table::isView($GLOBALS['table'], $GLOBALS['db'])) {
600 echo '<input id="table_create_time" type="hidden" value="' .
601 PMA_Table::sGetStatusInfo($GLOBALS['db'], $GLOBALS['table'], 'Create_time') . '" />';
606 $vertical_display['emptypre'] = 0;
607 $vertical_display['emptyafter'] = 0;
608 $vertical_display['textbtn'] = '';
610 // Display options (if we are not in print view)
611 if (! (isset($GLOBALS['printview']) && $GLOBALS['printview'] == '1')) {
612 echo '<form method="post" action="sql.php" name="displayOptionsForm" id="displayOptionsForm"';
613 if ($GLOBALS['cfg']['AjaxEnable']) {
614 echo ' class="ajax" ';
616 echo '>';
617 $url_params = array(
618 'db' => $db,
619 'table' => $table,
620 'sql_query' => $sql_query,
621 'goto' => $goto,
622 'display_options_form' => 1
624 echo PMA_generate_common_hidden_inputs($url_params);
625 echo '<br />';
626 PMA_generate_slider_effect('displayoptions', __('Options'));
627 echo '<fieldset>';
629 echo '<div class="formelement">';
630 $choices = array(
631 'P' => __('Partial texts'),
632 'F' => __('Full texts')
634 PMA_display_html_radio('display_text', $choices, $_SESSION['tmp_user_values']['display_text']);
635 echo '</div>';
637 // prepare full/partial text button or link
638 $url_params_full_text = array(
639 'db' => $db,
640 'table' => $table,
641 'sql_query' => $sql_query,
642 'goto' => $goto,
643 'full_text_button' => 1
646 if ($_SESSION['tmp_user_values']['display_text']=='F') {
647 // currently in fulltext mode so show the opposite link
648 $tmp_image_file = $GLOBALS['pmaThemeImage'] . 's_partialtext.png';
649 $tmp_txt = __('Partial texts');
650 $url_params_full_text['display_text'] = 'P';
651 } else {
652 $tmp_image_file = $GLOBALS['pmaThemeImage'] . 's_fulltext.png';
653 $tmp_txt = __('Full texts');
654 $url_params_full_text['display_text'] = 'F';
657 $tmp_image = '<img class="fulltext" src="' . $tmp_image_file . '" alt="' . $tmp_txt . '" title="' . $tmp_txt . '" />';
658 $tmp_url = 'sql.php' . PMA_generate_common_url($url_params_full_text);
659 $full_or_partial_text_link = PMA_linkOrButton($tmp_url, $tmp_image, array(), false);
660 unset($tmp_image_file, $tmp_txt, $tmp_url, $tmp_image);
663 if ($GLOBALS['cfgRelation']['relwork'] && $GLOBALS['cfgRelation']['displaywork']) {
664 echo '<div class="formelement">';
665 $choices = array(
666 'K' => __('Relational key'),
667 'D' => __('Relational display column')
669 PMA_display_html_radio('relational_display', $choices, $_SESSION['tmp_user_values']['relational_display']);
670 echo '</div>';
673 echo '<div class="formelement">';
674 PMA_display_html_checkbox('display_binary', __('Show binary contents'), ! empty($_SESSION['tmp_user_values']['display_binary']), false);
675 echo '<br />';
676 PMA_display_html_checkbox('display_blob', __('Show BLOB contents'), ! empty($_SESSION['tmp_user_values']['display_blob']), false);
677 echo '<br />';
678 PMA_display_html_checkbox('display_binary_as_hex', __('Show binary contents as HEX'), ! empty($_SESSION['tmp_user_values']['display_binary_as_hex']), false);
679 echo '</div>';
681 // I would have preferred to name this "display_transformation".
682 // This is the only way I found to be able to keep this setting sticky
683 // per SQL query, and at the same time have a default that displays
684 // the transformations.
685 echo '<div class="formelement">';
686 PMA_display_html_checkbox('hide_transformation', __('Hide') . ' ' . __('Browser transformation'), ! empty($_SESSION['tmp_user_values']['hide_transformation']), false);
687 echo '</div>';
689 if (! PMA_DRIZZLE) {
690 echo '<div class="formelement">';
691 $choices = array(
692 'GEOM' => __('Geometry'),
693 'WKT' => __('Well Known Text'),
694 'WKB' => __('Well Known Binary')
696 PMA_display_html_radio('geometry_display', $choices, $_SESSION['tmp_user_values']['geometry_display']);
697 echo '</div>';
700 echo '<div class="clearfloat"></div>';
701 echo '</fieldset>';
703 echo '<fieldset class="tblFooters">';
704 echo '<input type="submit" value="' . __('Go') . '" />';
705 echo '</fieldset>';
706 echo '</div>';
707 echo '</form>';
710 // Start of form for multi-rows edit/delete/export
712 if ($is_display['del_lnk'] == 'dr' || $is_display['del_lnk'] == 'kp') {
713 echo '<form method="post" action="tbl_row_action.php" name="resultsForm" id="resultsForm"';
714 if ($GLOBALS['cfg']['AjaxEnable']) {
715 echo ' class="ajax" ';
717 echo '>' . "\n";
718 echo PMA_generate_common_hidden_inputs($db, $table, 1);
719 echo '<input type="hidden" name="goto" value="sql.php" />' . "\n";
722 echo '<table id="table_results" class="data';
723 if ($GLOBALS['cfg']['AjaxEnable']) {
724 echo ' ajax';
726 echo '">' . "\n";
727 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
728 || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped'
730 echo '<thead><tr>' . "\n";
733 // 1. Displays the full/partial text button (part 1)...
734 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
735 || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped'
737 $colspan = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn')
738 ? ' colspan="4"'
739 : '';
740 } else {
741 $rowspan = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn')
742 ? ' rowspan="4"'
743 : '';
746 // ... before the result table
747 if (($is_display['edit_lnk'] == 'nn' && $is_display['del_lnk'] == 'nn')
748 && $is_display['text_btn'] == '1'
750 $vertical_display['emptypre'] = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn') ? 4 : 0;
751 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
752 || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped'
755 <th colspan="<?php echo $fields_cnt; ?>"></th>
756 </tr>
757 <tr>
758 <?php
759 // end horizontal/horizontalflipped mode
760 } else {
762 <tr>
763 <th colspan="<?php echo $num_rows + floor($num_rows/$_SESSION['tmp_user_values']['repeat_cells']) + 1; ?>"></th>
764 </tr>
765 <?php
766 } // end vertical mode
769 // ... at the left column of the result table header if possible
770 // and required
771 elseif (($GLOBALS['cfg']['RowActionLinks'] == 'left' || $GLOBALS['cfg']['RowActionLinks'] == 'both')
772 && $is_display['text_btn'] == '1'
774 $vertical_display['emptypre'] = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn') ? 4 : 0;
775 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
776 || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped'
779 <th <?php echo $colspan; ?>><?php echo $full_or_partial_text_link;?></th>
780 <?php
781 // end horizontal/horizontalflipped mode
782 } else {
783 $vertical_display['textbtn'] = ' <th ' . $rowspan . ' valign="middle">' . "\n"
784 . ' ' . "\n"
785 . ' </th>' . "\n";
786 } // end vertical mode
789 // ... elseif no button, displays empty(ies) col(s) if required
790 elseif (($GLOBALS['cfg']['RowActionLinks'] == 'left' || $GLOBALS['cfg']['RowActionLinks'] == 'both')
791 && ($is_display['edit_lnk'] != 'nn' || $is_display['del_lnk'] != 'nn')) {
792 $vertical_display['emptypre'] = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn') ? 4 : 0;
793 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
794 || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped'
797 <td<?php echo $colspan; ?>></td>
798 <?php
799 // end horizontal/horizontalfipped mode
800 } else {
801 $vertical_display['textbtn'] = ' <td' . $rowspan . '></td>' . "\n";
802 } // end vertical mode
805 // ... elseif display an empty column if the actions links are disabled to match the rest of the table
806 elseif ($GLOBALS['cfg']['RowActionLinks'] == 'none'
807 && ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal' || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped')
809 echo '<th></th>';
812 // 2. Displays the fields' name
813 // 2.0 If sorting links should be used, checks if the query is a "JOIN"
814 // statement (see 2.1.3)
816 // 2.0.1 Prepare Display column comments if enabled ($GLOBALS['cfg']['ShowBrowseComments']).
817 // Do not show comments, if using horizontalflipped mode, because of space usage
818 if ($GLOBALS['cfg']['ShowBrowseComments']
819 && $_SESSION['tmp_user_values']['disp_direction'] != 'horizontalflipped'
821 $comments_map = array();
822 if (isset($analyzed_sql[0]) && is_array($analyzed_sql[0])) {
823 foreach ($analyzed_sql[0]['table_ref'] as $tbl) {
824 $tb = $tbl['table_true_name'];
825 $comments_map[$tb] = PMA_getComments($db, $tb);
826 unset($tb);
831 if ($GLOBALS['cfgRelation']['commwork'] && $GLOBALS['cfgRelation']['mimework'] && $GLOBALS['cfg']['BrowseMIME'] && ! $_SESSION['tmp_user_values']['hide_transformation']) {
832 include_once './libraries/transformations.lib.php';
833 $GLOBALS['mime_map'] = PMA_getMIME($db, $table);
836 // See if we have to highlight any header fields of a WHERE query.
837 // Uses SQL-Parser results.
838 $highlight_columns = array();
839 if (isset($analyzed_sql) && isset($analyzed_sql[0])
840 && isset($analyzed_sql[0]['where_clause_identifiers'])
843 $wi = 0;
844 if (isset($analyzed_sql[0]['where_clause_identifiers']) && is_array($analyzed_sql[0]['where_clause_identifiers'])) {
845 foreach ($analyzed_sql[0]['where_clause_identifiers'] AS $wci_nr => $wci) {
846 $highlight_columns[$wci] = 'true';
851 if (PMA_isSelect()) {
852 // prepare to get the column order, if available
853 $pmatable = new PMA_Table($GLOBALS['table'], $GLOBALS['db']);
854 $col_order = $pmatable->getUiProp(PMA_Table::PROP_COLUMN_ORDER);
855 $col_visib = $pmatable->getUiProp(PMA_Table::PROP_COLUMN_VISIB);
856 } else {
857 $col_order = false;
858 $col_visib = false;
861 for ($j = 0; $j < $fields_cnt; $j++) {
862 // assign $i with appropriate column order
863 $i = $col_order ? $col_order[$j] : $j;
864 // See if this column should get highlight because it's used in the
865 // where-query.
866 if (isset($highlight_columns[$fields_meta[$i]->name]) || isset($highlight_columns[PMA_backquote($fields_meta[$i]->name)])) {
867 $condition_field = true;
868 } else {
869 $condition_field = false;
872 // 2.0 Prepare comment-HTML-wrappers for each row, if defined/enabled.
873 if (isset($comments_map)
874 && isset($comments_map[$fields_meta[$i]->table])
875 && isset($comments_map[$fields_meta[$i]->table][$fields_meta[$i]->name])
877 $comments = '<span class="tblcomment">' . htmlspecialchars($comments_map[$fields_meta[$i]->table][$fields_meta[$i]->name]) . '</span>';
878 } else {
879 $comments = '';
882 // 2.1 Results can be sorted
883 if ($is_display['sort_lnk'] == '1') {
885 // 2.1.1 Checks if the table name is required; it's the case
886 // for a query with a "JOIN" statement and if the column
887 // isn't aliased, or in queries like
888 // SELECT `1`.`master_field` , `2`.`master_field`
889 // FROM `PMA_relation` AS `1` , `PMA_relation` AS `2`
891 if (isset($fields_meta[$i]->table) && strlen($fields_meta[$i]->table)) {
892 $sort_tbl = PMA_backquote($fields_meta[$i]->table) . '.';
893 } else {
894 $sort_tbl = '';
897 // 2.1.2 Checks if the current column is used to sort the
898 // results
899 // the orgname member does not exist for all MySQL versions
900 // but if found, it's the one on which to sort
901 $name_to_use_in_sort = $fields_meta[$i]->name;
902 $is_orgname = false;
903 if (isset($fields_meta[$i]->orgname) && strlen($fields_meta[$i]->orgname)) {
904 $name_to_use_in_sort = $fields_meta[$i]->orgname;
905 $is_orgname = true;
907 // $name_to_use_in_sort might contain a space due to
908 // formatting of function expressions like "COUNT(name )"
909 // so we remove the space in this situation
910 $name_to_use_in_sort = str_replace(' )', ')', $name_to_use_in_sort);
912 if (empty($sort_expression)) {
913 $is_in_sort = false;
914 } else {
915 // Field name may be preceded by a space, or any number
916 // of characters followed by a dot (tablename.fieldname)
917 // so do a direct comparison for the sort expression;
918 // this avoids problems with queries like
919 // "SELECT id, count(id)..." and clicking to sort
920 // on id or on count(id).
921 // Another query to test this:
922 // SELECT p.*, FROM_UNIXTIME(p.temps) FROM mytable AS p
923 // (and try clicking on each column's header twice)
924 if (! empty($sort_tbl)
925 && strpos($sort_expression_nodirection, $sort_tbl) === false
926 && strpos($sort_expression_nodirection, '(') === false
928 $sort_expression_nodirection = $sort_tbl . $sort_expression_nodirection;
930 $is_in_sort = (str_replace('`', '', $sort_tbl) . $name_to_use_in_sort == str_replace('`', '', $sort_expression_nodirection) ? true : false);
932 // 2.1.3 Check the field name for a bracket.
933 // If it contains one, it's probably a function column
934 // like 'COUNT(`field`)'
935 // It still might be a column name of a view. See bug #3383711
936 // Check is_orgname.
937 if (strpos($name_to_use_in_sort, '(') !== false && ! $is_orgname) {
938 $sort_order = "\n" . 'ORDER BY ' . $name_to_use_in_sort . ' ';
939 } else {
940 $sort_order = "\n" . 'ORDER BY ' . $sort_tbl . PMA_backquote($name_to_use_in_sort) . ' ';
942 unset($name_to_use_in_sort);
943 unset($is_orgname);
945 // 2.1.4 Do define the sorting URL
946 if (! $is_in_sort) {
947 // patch #455484 ("Smart" order)
948 $GLOBALS['cfg']['Order'] = strtoupper($GLOBALS['cfg']['Order']);
949 if ($GLOBALS['cfg']['Order'] === 'SMART') {
950 $sort_order .= (preg_match('@time|date@i', $fields_meta[$i]->type)) ? 'DESC' : 'ASC';
951 } else {
952 $sort_order .= $GLOBALS['cfg']['Order'];
954 $order_img = '';
955 } elseif ('DESC' == $sort_direction) {
956 $sort_order .= ' ASC';
957 $order_img = ' ' . PMA_getImage('s_desc.png', __('Descending'), array('class' => "soimg$i", 'title' => ''));
958 $order_img .= ' ' . PMA_getImage('s_asc.png', __('Ascending'), array('class' => "soimg$i hide", 'title' => ''));
959 } else {
960 $sort_order .= ' DESC';
961 $order_img = ' ' . PMA_getImage('s_asc.png', __('Ascending'), array('class' => "soimg$i", 'title' => ''));
962 $order_img .= ' ' . PMA_getImage('s_desc.png', __('Descending'), array('class' => "soimg$i hide", 'title' => ''));
965 if (preg_match('@(.*)([[:space:]](LIMIT (.*)|PROCEDURE (.*)|FOR UPDATE|LOCK IN SHARE MODE))@is', $unsorted_sql_query, $regs3)) {
966 $sorted_sql_query = $regs3[1] . $sort_order . $regs3[2];
967 } else {
968 $sorted_sql_query = $unsorted_sql_query . $sort_order;
970 $_url_params = array(
971 'db' => $db,
972 'table' => $table,
973 'sql_query' => $sorted_sql_query,
974 'session_max_rows' => $session_max_rows
976 $order_url = 'sql.php' . PMA_generate_common_url($_url_params);
978 // 2.1.5 Displays the sorting URL
979 // enable sort order swapping for image
980 $order_link_params = array();
981 if (isset($order_img) && $order_img!='') {
982 if (strstr($order_img, 'asc')) {
983 $order_link_params['onmouseover'] = "$('.soimg$i').toggle()";
984 $order_link_params['onmouseout'] = "$('.soimg$i').toggle()";
985 } elseif (strstr($order_img, 'desc')) {
986 $order_link_params['onmouseover'] = "$('.soimg$i').toggle()";
987 $order_link_params['onmouseout'] = "$('.soimg$i').toggle()";
990 if ($GLOBALS['cfg']['HeaderFlipType'] == 'auto') {
991 if (PMA_USR_BROWSER_AGENT == 'IE') {
992 $GLOBALS['cfg']['HeaderFlipType'] = 'css';
993 } else {
994 $GLOBALS['cfg']['HeaderFlipType'] = 'fake';
997 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped'
998 && $GLOBALS['cfg']['HeaderFlipType'] == 'css'
1000 $order_link_params['style'] = 'direction: ltr; writing-mode: tb-rl;';
1002 $order_link_params['title'] = __('Sort');
1003 $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));
1004 $order_link = PMA_linkOrButton($order_url, $order_link_content . $order_img, $order_link_params, false, true);
1006 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
1007 || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped'
1009 echo '<th';
1010 $th_class = array();
1011 $th_class[] = 'draggable';
1012 if ($col_visib && !$col_visib[$j]) {
1013 $th_class[] = 'hide';
1015 if ($condition_field) {
1016 $th_class[] = 'condition';
1018 $th_class[] = 'column_heading';
1019 if ($GLOBALS['cfg']['BrowsePointerEnable'] == true) {
1020 $th_class[] = 'pointer';
1022 if ($GLOBALS['cfg']['BrowseMarkerEnable'] == true) {
1023 $th_class[] = 'marker';
1025 echo ' class="' . implode(' ', $th_class) . '"';
1027 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') {
1028 echo ' valign="bottom"';
1030 echo '>' . $order_link . $comments . '</th>';
1032 $vertical_display['desc'][] = ' <th '
1033 . 'class="draggable'
1034 . ($condition_field ? ' condition' : '')
1035 . '">' . "\n"
1036 . $order_link . $comments . ' </th>' . "\n";
1037 } // end if (2.1)
1039 // 2.2 Results can't be sorted
1040 else {
1041 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
1042 || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped'
1044 echo '<th';
1045 $th_class = array();
1046 $th_class[] = 'draggable';
1047 if ($col_visib && !$col_visib[$j]) {
1048 $th_class[] = 'hide';
1050 if ($condition_field) {
1051 $th_class[] = 'condition';
1053 echo ' class="' . implode(' ', $th_class) . '"';
1054 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') {
1055 echo ' valign="bottom"';
1057 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped'
1058 && $GLOBALS['cfg']['HeaderFlipType'] == 'css'
1060 echo ' style="direction: ltr; writing-mode: tb-rl;"';
1062 echo '>';
1063 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped'
1064 && $GLOBALS['cfg']['HeaderFlipType'] == 'fake'
1066 echo PMA_flipstring(htmlspecialchars($fields_meta[$i]->name), '<br />');
1067 } else {
1068 echo htmlspecialchars($fields_meta[$i]->name);
1070 echo "\n" . $comments . '</th>';
1072 $vertical_display['desc'][] = ' <th '
1073 . 'class="draggable'
1074 . ($condition_field ? ' condition"' : '')
1075 . '">' . "\n"
1076 . ' ' . htmlspecialchars($fields_meta[$i]->name) . "\n"
1077 . $comments . ' </th>';
1078 } // end else (2.2)
1079 } // end for
1081 // 3. Displays the needed checkboxes at the right
1082 // column of the result table header if possible and required...
1083 if (($GLOBALS['cfg']['RowActionLinks'] == 'right' || $GLOBALS['cfg']['RowActionLinks'] == 'both')
1084 && ($is_display['edit_lnk'] != 'nn' || $is_display['del_lnk'] != 'nn')
1085 && $is_display['text_btn'] == '1'
1087 $vertical_display['emptyafter'] = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn') ? 4 : 1;
1088 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
1089 || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped'
1091 echo "\n";
1093 <th <?php echo $colspan; ?>><?php echo $full_or_partial_text_link;?>
1094 </th>
1095 <?php
1096 // end horizontal/horizontalflipped mode
1097 } else {
1098 $vertical_display['textbtn'] = ' <th ' . $rowspan . ' valign="middle">' . "\n"
1099 . ' ' . "\n"
1100 . ' </th>' . "\n";
1101 } // end vertical mode
1104 // ... elseif no button, displays empty columns if required
1105 // (unless coming from Browse mode print view)
1106 elseif (($GLOBALS['cfg']['RowActionLinks'] == 'left' || $GLOBALS['cfg']['RowActionLinks'] == 'both')
1107 && ($is_display['edit_lnk'] == 'nn' && $is_display['del_lnk'] == 'nn')
1108 && (! $GLOBALS['is_header_sent'])
1110 $vertical_display['emptyafter'] = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn') ? 4 : 1;
1111 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
1112 || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped'
1114 echo "\n";
1116 <td<?php echo $colspan; ?>></td>
1117 <?php
1118 // end horizontal/horizontalflipped mode
1119 } else {
1120 $vertical_display['textbtn'] = ' <td' . $rowspan . '></td>' . "\n";
1121 } // end vertical mode
1124 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
1125 || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped'
1128 </tr>
1129 </thead>
1130 <?php
1133 return true;
1134 } // end of the 'PMA_displayTableHeaders()' function
1138 * Prepares the display for a value
1140 * @param string $class class of table cell
1141 * @param bool $condition_field whether to add CSS class condition
1142 * @param string $value value to display
1144 * @return string the td
1146 function PMA_buildValueDisplay($class, $condition_field, $value)
1148 return '<td align="left"' . ' class="' . $class . ($condition_field ? ' condition' : '') . '">' . $value . '</td>';
1152 * Prepares the display for a null value
1154 * @param string $class class of table cell
1155 * @param bool $condition_field whether to add CSS class condition
1156 * @param object $meta the meta-information about this field
1157 * @param string $align cell allignment
1159 * @return string the td
1161 function PMA_buildNullDisplay($class, $condition_field, $meta, $align = '')
1163 // the null class is needed for grid editing
1164 return '<td ' . $align . ' class="' . PMA_addClass($class, $condition_field, $meta, '') . ' null"><i>NULL</i></td>';
1168 * Prepares the display for an empty value
1170 * @param string $class class of table cell
1171 * @param bool $condition_field whether to add CSS class condition
1172 * @param object $meta the meta-information about this field
1173 * @param string $align cell allignment
1175 * @return string the td
1177 function PMA_buildEmptyDisplay($class, $condition_field, $meta, $align = '')
1179 $nowrap = ' nowrap';
1180 return '<td ' . $align . ' class="' . PMA_addClass($class, $condition_field, $meta, $nowrap) . '"></td>';
1184 * Adds the relavant classes.
1186 * @param string $class class of table cell
1187 * @param bool $condition_field whether to add CSS class condition
1188 * @param object $meta the meta-information about this field
1189 * @param string $nowrap avoid wrapping
1190 * @param bool $is_field_truncated is field truncated (display ...)
1191 * @param string $transform_function transformation function
1192 * @param string $default_function default transformation function
1194 * @return string the list of classes
1196 function PMA_addClass($class, $condition_field, $meta, $nowrap, $is_field_truncated = false, $transform_function = '', $default_function = '')
1198 // Define classes to be added to this data field based on the type of data
1199 $enum_class = '';
1200 if (strpos($meta->flags, 'enum') !== false) {
1201 $enum_class = ' enum';
1204 $set_class = '';
1205 if (strpos($meta->flags, 'set') !== false) {
1206 $set_class = ' set';
1209 $bit_class = '';
1210 if (strpos($meta->type, 'bit') !== false) {
1211 $bit_class = ' bit';
1214 $mime_type_class = '';
1215 if (isset($meta->mimetype)) {
1216 $mime_type_class = ' ' . preg_replace('/\//', '_', $meta->mimetype);
1219 $result = $class . ($condition_field ? ' condition' : '') . $nowrap
1220 . ' ' . ($is_field_truncated ? ' truncated' : '')
1221 . ($transform_function != $default_function ? ' transformed' : '')
1222 . $enum_class . $set_class . $bit_class . $mime_type_class;
1224 return $result;
1227 * Displays the body of the results table
1229 * @param integer &$dt_result the link id associated to the query which results have
1230 * to be displayed
1231 * @param array &$is_display which elements to display
1232 * @param array $map the list of relations
1233 * @param array $analyzed_sql the analyzed query
1235 * @return boolean always true
1237 * @global string $db the database name
1238 * @global string $table the table name
1239 * @global string $goto the URL to go back in case of errors
1240 * @global string $sql_query the SQL query
1241 * @global array $fields_meta the list of fields properties
1242 * @global integer $fields_cnt the total number of fields returned by
1243 * the SQL query
1244 * @global array $vertical_display informations used with vertical display
1245 * mode
1246 * @global array $highlight_columns column names to highlight
1247 * @global array $row current row data
1249 * @access private
1251 * @see PMA_displayTable()
1253 function PMA_displayTableBody(&$dt_result, &$is_display, $map, $analyzed_sql)
1255 global $db, $table, $goto;
1256 global $sql_query, $fields_meta, $fields_cnt;
1257 global $vertical_display, $highlight_columns;
1258 global $row; // mostly because of browser transformations, to make the row-data accessible in a plugin
1260 $url_sql_query = $sql_query;
1262 // query without conditions to shorten URLs when needed, 200 is just
1263 // guess, it should depend on remaining URL length
1265 if (isset($analyzed_sql)
1266 && isset($analyzed_sql[0])
1267 && isset($analyzed_sql[0]['querytype'])
1268 && $analyzed_sql[0]['querytype'] == 'SELECT'
1269 && strlen($sql_query) > 200
1272 $url_sql_query = 'SELECT ';
1273 if (isset($analyzed_sql[0]['queryflags']['distinct'])) {
1274 $url_sql_query .= ' DISTINCT ';
1276 $url_sql_query .= $analyzed_sql[0]['select_expr_clause'];
1277 if (!empty($analyzed_sql[0]['from_clause'])) {
1278 $url_sql_query .= ' FROM ' . $analyzed_sql[0]['from_clause'];
1282 if (! is_array($map)) {
1283 $map = array();
1285 $row_no = 0;
1286 $vertical_display['edit'] = array();
1287 $vertical_display['copy'] = array();
1288 $vertical_display['delete'] = array();
1289 $vertical_display['data'] = array();
1290 $vertical_display['row_delete'] = array();
1291 // name of the class added to all grid editable elements
1292 $grid_edit_class = 'grid_edit';
1294 // prepare to get the column order, if available
1295 if (PMA_isSelect()) {
1296 $pmatable = new PMA_Table($GLOBALS['table'], $GLOBALS['db']);
1297 $col_order = $pmatable->getUiProp(PMA_Table::PROP_COLUMN_ORDER);
1298 $col_visib = $pmatable->getUiProp(PMA_Table::PROP_COLUMN_VISIB);
1299 } else {
1300 $col_order = false;
1301 $col_visib = false;
1304 // Correction University of Virginia 19991216 in the while below
1305 // Previous code assumed that all tables have keys, specifically that
1306 // the phpMyAdmin GUI should support row delete/edit only for such
1307 // tables.
1308 // Although always using keys is arguably the prescribed way of
1309 // defining a relational table, it is not required. This will in
1310 // particular be violated by the novice.
1311 // We want to encourage phpMyAdmin usage by such novices. So the code
1312 // below has been changed to conditionally work as before when the
1313 // table being displayed has one or more keys; but to display
1314 // delete/edit options correctly for tables without keys.
1316 $odd_row = true;
1317 while ($row = PMA_DBI_fetch_row($dt_result)) {
1318 // "vertical display" mode stuff
1319 if ($row_no != 0 && $_SESSION['tmp_user_values']['repeat_cells'] != 0
1320 && !($row_no % $_SESSION['tmp_user_values']['repeat_cells'])
1321 && ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
1322 || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped')
1324 echo '<tr>' . "\n";
1325 if ($vertical_display['emptypre'] > 0) {
1326 echo ' <th colspan="' . $vertical_display['emptypre'] . '">' . "\n"
1327 .' &nbsp;</th>' . "\n";
1328 } else if ($GLOBALS['cfg']['RowActionLinks'] == 'none') {
1329 echo ' <th></th>' . "\n";
1332 foreach ($vertical_display['desc'] as $val) {
1333 echo $val;
1336 if ($vertical_display['emptyafter'] > 0) {
1337 echo ' <th colspan="' . $vertical_display['emptyafter'] . '">' . "\n"
1338 .' &nbsp;</th>' . "\n";
1340 echo '</tr>' . "\n";
1341 } // end if
1343 $alternating_color_class = ($odd_row ? 'odd' : 'even');
1344 $odd_row = ! $odd_row;
1346 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
1347 || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped'
1349 // pointer code part
1350 echo '<tr class="' . $alternating_color_class . '">';
1354 // 1. Prepares the row
1355 // 1.1 Results from a "SELECT" statement -> builds the
1356 // WHERE clause to use in links (a unique key if possible)
1358 * @todo $where_clause could be empty, for example a table
1359 * with only one field and it's a BLOB; in this case,
1360 * avoid to display the delete and edit links
1362 list($where_clause, $clause_is_unique, $condition_array) = PMA_getUniqueCondition($dt_result, $fields_cnt, $fields_meta, $row);
1363 $where_clause_html = urlencode($where_clause);
1365 // 1.2 Defines the URLs for the modify/delete link(s)
1367 if ($is_display['edit_lnk'] != 'nn' || $is_display['del_lnk'] != 'nn') {
1368 // We need to copy the value or else the == 'both' check will always return true
1370 if ($GLOBALS['cfg']['PropertiesIconic'] === 'both') {
1371 $iconic_spacer = '<div class="nowrap">';
1372 } else {
1373 $iconic_spacer = '';
1376 // 1.2.1 Modify link(s)
1377 if ($is_display['edit_lnk'] == 'ur') { // update row case
1378 $_url_params = array(
1379 'db' => $db,
1380 'table' => $table,
1381 'where_clause' => $where_clause,
1382 'clause_is_unique' => $clause_is_unique,
1383 'sql_query' => $url_sql_query,
1384 'goto' => 'sql.php',
1386 $edit_url = 'tbl_change.php' . PMA_generate_common_url($_url_params + array('default_action' => 'update'));
1387 $copy_url = 'tbl_change.php' . PMA_generate_common_url($_url_params + array('default_action' => 'insert'));
1389 $edit_str = PMA_getIcon('b_edit.png', __('Edit'));
1390 $copy_str = PMA_getIcon('b_insrow.png', __('Copy'));
1392 // Class definitions required for grid editing jQuery scripts
1393 $edit_anchor_class = "edit_row_anchor";
1394 if ( $clause_is_unique == 0) {
1395 $edit_anchor_class .= ' nonunique';
1397 } // end if (1.2.1)
1399 // 1.2.2 Delete/Kill link(s)
1400 if ($is_display['del_lnk'] == 'dr') { // delete row case
1401 $_url_params = array(
1402 'db' => $db,
1403 'table' => $table,
1404 'sql_query' => $url_sql_query,
1405 'message_to_show' => __('The row has been deleted'),
1406 'goto' => (empty($goto) ? 'tbl_sql.php' : $goto),
1408 $lnk_goto = 'sql.php' . PMA_generate_common_url($_url_params, 'text');
1410 $del_query = 'DELETE FROM ' . PMA_backquote($db) . '.' . PMA_backquote($table)
1411 . ' WHERE ' . $where_clause . ($clause_is_unique ? '' : ' LIMIT 1');
1413 $_url_params = array(
1414 'db' => $db,
1415 'table' => $table,
1416 'sql_query' => $del_query,
1417 'message_to_show' => __('The row has been deleted'),
1418 'goto' => $lnk_goto,
1420 $del_url = 'sql.php' . PMA_generate_common_url($_url_params);
1422 $js_conf = 'DELETE FROM ' . PMA_jsFormat($db) . '.' . PMA_jsFormat($table)
1423 . ' WHERE ' . PMA_jsFormat($where_clause, false)
1424 . ($clause_is_unique ? '' : ' LIMIT 1');
1425 $del_str = PMA_getIcon('b_drop.png', __('Delete'));
1426 } elseif ($is_display['del_lnk'] == 'kp') { // kill process case
1428 $_url_params = array(
1429 'db' => $db,
1430 'table' => $table,
1431 'sql_query' => $url_sql_query,
1432 'goto' => 'main.php',
1434 $lnk_goto = 'sql.php' . PMA_generate_common_url($_url_params, 'text');
1436 $_url_params = array(
1437 'db' => 'mysql',
1438 'sql_query' => 'KILL ' . $row[0],
1439 'goto' => $lnk_goto,
1441 $del_url = 'sql.php' . PMA_generate_common_url($_url_params);
1442 $del_query = 'KILL ' . $row[0];
1443 $js_conf = 'KILL ' . $row[0];
1444 $del_str = PMA_getIcon('b_drop.png', __('Kill'));
1445 } // end if (1.2.2)
1447 // 1.3 Displays the links at left if required
1448 if (($GLOBALS['cfg']['RowActionLinks'] == 'left' || $GLOBALS['cfg']['RowActionLinks'] == 'both')
1449 && ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
1450 || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped')
1452 if (! isset($js_conf)) {
1453 $js_conf = '';
1455 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);
1456 } elseif (($GLOBALS['cfg']['RowActionLinks'] == 'none')
1457 && ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
1458 || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped')
1460 if (! isset($js_conf)) {
1461 $js_conf = '';
1463 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);
1464 } // end if (1.3)
1465 } // end if (1)
1467 // 2. Displays the rows' values
1469 for ($j = 0; $j < $fields_cnt; ++$j) {
1470 // assign $i with appropriate column order
1471 $i = $col_order ? $col_order[$j] : $j;
1473 $meta = $fields_meta[$i];
1474 $not_null_class = $meta->not_null ? 'not_null' : '';
1475 $relation_class = isset($map[$meta->name]) ? 'relation' : '';
1476 $hide_class = ($col_visib && !$col_visib[$j] &&
1477 // hide per <td> only if the display direction is not vertical
1478 $_SESSION['tmp_user_values']['disp_direction'] != 'vertical') ? 'hide' : '';
1479 // handle datetime-related class, for grid editing
1480 if (substr($meta->type, 0, 9) == 'timestamp' || $meta->type == 'datetime') {
1481 $field_type_class = 'datetimefield';
1482 } else if ($meta->type == 'date') {
1483 $field_type_class = 'datefield';
1484 } else {
1485 $field_type_class = '';
1487 $pointer = $i;
1488 $is_field_truncated = false;
1489 //If the previous column had blob data, we need to reset the class
1490 // to $inline_edit_class
1491 $class = 'data ' . $grid_edit_class . ' ' . $not_null_class . ' ' . $relation_class . ' ' . $hide_class . ' ' . $field_type_class; //' ' . $alternating_color_class .
1493 // See if this column should get highlight because it's used in the
1494 // where-query.
1495 if (isset($highlight_columns) && (isset($highlight_columns[$meta->name]) || isset($highlight_columns[PMA_backquote($meta->name)]))) {
1496 $condition_field = true;
1497 } else {
1498 $condition_field = false;
1501 if ($_SESSION['tmp_user_values']['disp_direction'] == 'vertical' && (! isset($GLOBALS['printview']) || ($GLOBALS['printview'] != '1'))) {
1502 // the row number corresponds to a data row, not HTML table row
1503 $class .= ' row_' . $row_no;
1504 if ($GLOBALS['cfg']['BrowsePointerEnable'] == true) {
1505 $class .= ' vpointer';
1507 if ($GLOBALS['cfg']['BrowseMarkerEnable'] == true) {
1508 $class .= ' vmarker';
1510 }// end if
1512 // Wrap MIME-transformations. [MIME]
1513 $default_function = 'default_function'; // default_function
1514 $transform_function = $default_function;
1515 $transform_options = array();
1517 if ($GLOBALS['cfgRelation']['mimework'] && $GLOBALS['cfg']['BrowseMIME']) {
1519 if (isset($GLOBALS['mime_map'][$meta->name]['mimetype']) && isset($GLOBALS['mime_map'][$meta->name]['transformation']) && !empty($GLOBALS['mime_map'][$meta->name]['transformation'])) {
1520 $include_file = PMA_securePath($GLOBALS['mime_map'][$meta->name]['transformation']);
1522 if (file_exists('./libraries/transformations/' . $include_file)) {
1523 $transformfunction_name = str_replace('.inc.php', '', $GLOBALS['mime_map'][$meta->name]['transformation']);
1525 include_once './libraries/transformations/' . $include_file;
1527 if (function_exists('PMA_transformation_' . $transformfunction_name)) {
1528 $transform_function = 'PMA_transformation_' . $transformfunction_name;
1529 $transform_options = PMA_transformation_getOptions((isset($GLOBALS['mime_map'][$meta->name]['transformation_options']) ? $GLOBALS['mime_map'][$meta->name]['transformation_options'] : ''));
1530 $meta->mimetype = str_replace('_', '/', $GLOBALS['mime_map'][$meta->name]['mimetype']);
1532 } // end if file_exists
1533 } // end if transformation is set
1534 } // end if mime/transformation works.
1536 $_url_params = array(
1537 'db' => $db,
1538 'table' => $table,
1539 'where_clause' => $where_clause,
1540 'transform_key' => $meta->name,
1543 if (! empty($sql_query)) {
1544 $_url_params['sql_query'] = $url_sql_query;
1547 $transform_options['wrapper_link'] = PMA_generate_common_url($_url_params);
1549 // n u m e r i c
1550 if ($meta->numeric == 1) {
1552 // if two fields have the same name (this is possible
1553 // with self-join queries, for example), using $meta->name
1554 // will show both fields NULL even if only one is NULL,
1555 // so use the $pointer
1557 if (! isset($row[$i]) || is_null($row[$i])) {
1558 $vertical_display['data'][$row_no][$i] = PMA_buildNullDisplay($class, $condition_field, $meta, 'align="right"');
1559 } elseif ($row[$i] != '') {
1561 $nowrap = ' nowrap';
1562 $where_comparison = ' = ' . $row[$i];
1564 $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);
1565 } else {
1566 $vertical_display['data'][$row_no][$i] = PMA_buildEmptyDisplay($class, $condition_field, $meta, 'align="right"');
1569 // b l o b
1571 } elseif (stristr($meta->type, 'BLOB')) {
1572 // PMA_mysql_fetch_fields returns BLOB in place of
1573 // TEXT fields type so we have to ensure it's really a BLOB
1574 $field_flags = PMA_DBI_field_flags($dt_result, $i);
1576 if (stristr($field_flags, 'BINARY')) {
1577 // remove 'grid_edit' from $class as we can't edit binary data.
1578 $class = str_replace('grid_edit', '', $class);
1580 if (! isset($row[$i]) || is_null($row[$i])) {
1581 $vertical_display['data'][$row_no][$i] = PMA_buildNullDisplay($class, $condition_field, $meta);
1582 } else {
1583 // for blobstreaming
1584 // if valid BS reference exists
1585 if (PMA_BS_IsPBMSReference($row[$i], $db)) {
1586 $blobtext = PMA_BS_CreateReferenceLink($row[$i], $db);
1587 } else {
1588 $blobtext = PMA_handle_non_printable_contents('BLOB', (isset($row[$i]) ? $row[$i] : ''), $transform_function, $transform_options, $default_function, $meta, $_url_params);
1591 $vertical_display['data'][$row_no][$i] = PMA_buildValueDisplay($class, $condition_field, $blobtext);
1592 unset($blobtext);
1594 // not binary:
1595 } else {
1596 if (! isset($row[$i]) || is_null($row[$i])) {
1597 $vertical_display['data'][$row_no][$i] = PMA_buildNullDisplay($class, $condition_field, $meta);
1598 } elseif ($row[$i] != '') {
1599 // if a transform function for blob is set, none of these replacements will be made
1600 if (PMA_strlen($row[$i]) > $GLOBALS['cfg']['LimitChars'] && $_SESSION['tmp_user_values']['display_text'] == 'P') {
1601 $row[$i] = PMA_substr($row[$i], 0, $GLOBALS['cfg']['LimitChars']) . '...';
1602 $is_field_truncated = true;
1604 // displays all space characters, 4 space
1605 // characters for tabulations and <cr>/<lf>
1606 $row[$i] = ($default_function != $transform_function ? $transform_function($row[$i], $transform_options, $meta) : $default_function($row[$i], array(), $meta));
1608 if ($is_field_truncated) {
1609 $class .= ' truncated';
1612 $vertical_display['data'][$row_no][$i] = PMA_buildValueDisplay($class, $condition_field, $row[$i]);
1613 } else {
1614 $vertical_display['data'][$row_no][$i] = PMA_buildEmptyDisplay($class, $condition_field, $meta);
1617 // g e o m e t r y
1618 } elseif ($meta->type == 'geometry') {
1620 // Remove 'grid_edit' from $class as we do not allow to inline-edit geometry data.
1621 $class = str_replace('grid_edit', '', $class);
1623 if (! isset($row[$i]) || is_null($row[$i])) {
1624 $vertical_display['data'][$row_no][$i] = PMA_buildNullDisplay($class, $condition_field, $meta);
1625 } elseif ($row[$i] != '') {
1626 // Display as [GEOMETRY - (size)]
1627 if ('GEOM' == $_SESSION['tmp_user_values']['geometry_display']) {
1628 $geometry_text = PMA_handle_non_printable_contents(
1629 'GEOMETRY', (isset($row[$i]) ? $row[$i] : ''), $transform_function,
1630 $transform_options, $default_function, $meta
1632 $vertical_display['data'][$row_no][$i] = PMA_buildValueDisplay(
1633 $class, $condition_field, $geometry_text
1636 // Display in Well Known Text(WKT) format.
1637 } elseif ('WKT' == $_SESSION['tmp_user_values']['geometry_display']) {
1638 $where_comparison = ' = ' . $row[$i];
1640 // Convert to WKT format
1641 $wktval = PMA_asWKT($row[$i]);
1643 if (PMA_strlen($wktval) > $GLOBALS['cfg']['LimitChars']
1644 && $_SESSION['tmp_user_values']['display_text'] == 'P'
1646 $wktval = PMA_substr($wktval, 0, $GLOBALS['cfg']['LimitChars']) . '...';
1647 $is_field_truncated = true;
1650 $vertical_display['data'][$row_no][$i] = '<td ' . PMA_prepare_row_data(
1651 $class, $condition_field, $analyzed_sql, $meta, $map, $wktval, $transform_function,
1652 $default_function, '', $where_comparison, $transform_options, $is_field_truncated
1655 // Display in Well Known Binary(WKB) format.
1656 } else {
1657 if ($_SESSION['tmp_user_values']['display_binary']) {
1658 $where_comparison = ' = ' . $row[$i];
1660 if ($_SESSION['tmp_user_values']['display_binary_as_hex']
1661 && PMA_contains_nonprintable_ascii($row[$i])
1663 $wkbval = PMA_substr(bin2hex($row[$i]), 8);
1664 } else {
1665 $wkbval = htmlspecialchars(PMA_replace_binary_contents($row[$i]));
1668 if (PMA_strlen($wkbval) > $GLOBALS['cfg']['LimitChars']
1669 && $_SESSION['tmp_user_values']['display_text'] == 'P'
1671 $wkbval = PMA_substr($wkbval, 0, $GLOBALS['cfg']['LimitChars']) . '...';
1672 $is_field_truncated = true;
1675 $vertical_display['data'][$row_no][$i] = '<td ' . PMA_prepare_row_data(
1676 $class, $condition_field, $analyzed_sql, $meta, $map, $wkbval, $transform_function,
1677 $default_function, '', $where_comparison, $transform_options, $is_field_truncated
1679 } else {
1680 $wkbval = PMA_handle_non_printable_contents(
1681 'BINARY', $row[$i], $transform_function, $transform_options, $default_function, $meta, $_url_params
1683 $vertical_display['data'][$row_no][$i] = PMA_buildValueDisplay($class, $condition_field, $wkbval);
1686 } else {
1687 $vertical_display['data'][$row_no][$i] = PMA_buildEmptyDisplay($class, $condition_field, $meta);
1690 // n o t n u m e r i c a n d n o t B L O B
1691 } else {
1692 if (! isset($row[$i]) || is_null($row[$i])) {
1693 $vertical_display['data'][$row_no][$i] = PMA_buildNullDisplay($class, $condition_field, $meta);
1694 } elseif ($row[$i] != '') {
1695 // support blanks in the key
1696 $relation_id = $row[$i];
1698 // Cut all fields to $GLOBALS['cfg']['LimitChars']
1699 // (unless it's a link-type transformation)
1700 if (PMA_strlen($row[$i]) > $GLOBALS['cfg']['LimitChars'] && $_SESSION['tmp_user_values']['display_text'] == 'P' && !strpos($transform_function, 'link') === true) {
1701 $row[$i] = PMA_substr($row[$i], 0, $GLOBALS['cfg']['LimitChars']) . '...';
1702 $is_field_truncated = true;
1705 // displays special characters from binaries
1706 $field_flags = PMA_DBI_field_flags($dt_result, $i);
1707 $formatted = false;
1708 if (isset($meta->_type) && $meta->_type === MYSQLI_TYPE_BIT) {
1709 $row[$i] = PMA_printable_bit_value($row[$i], $meta->length);
1710 // some results of PROCEDURE ANALYSE() are reported as
1711 // being BINARY but they are quite readable,
1712 // so don't treat them as BINARY
1713 } elseif (stristr($field_flags, 'BINARY') && $meta->type == 'string' && !(isset($GLOBALS['is_analyse']) && $GLOBALS['is_analyse'])) {
1714 if ($_SESSION['tmp_user_values']['display_binary']) {
1715 // user asked to see the real contents of BINARY
1716 // fields
1717 if ($_SESSION['tmp_user_values']['display_binary_as_hex'] && PMA_contains_nonprintable_ascii($row[$i])) {
1718 $row[$i] = bin2hex($row[$i]);
1719 } else {
1720 $row[$i] = htmlspecialchars(PMA_replace_binary_contents($row[$i]));
1722 } else {
1723 // we show the BINARY message and field's size
1724 // (or maybe use a transformation)
1725 $row[$i] = PMA_handle_non_printable_contents('BINARY', $row[$i], $transform_function, $transform_options, $default_function, $meta, $_url_params);
1726 $formatted = true;
1730 if ($formatted) {
1731 $vertical_display['data'][$row_no][$i] = PMA_buildValueDisplay($class, $condition_field, $row[$i]);
1732 } else {
1733 // transform functions may enable no-wrapping:
1734 $function_nowrap = $transform_function . '_nowrap';
1735 $bool_nowrap = (($default_function != $transform_function && function_exists($function_nowrap)) ? $function_nowrap($transform_options) : false);
1737 // do not wrap if date field type
1738 $nowrap = ((preg_match('@DATE|TIME@i', $meta->type) || $bool_nowrap) ? ' nowrap' : '');
1739 $where_comparison = ' = \'' . PMA_sqlAddSlashes($row[$i]) . '\'';
1740 $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);
1742 } else {
1743 $vertical_display['data'][$row_no][$i] = PMA_buildEmptyDisplay($class, $condition_field, $meta);
1747 // output stored cell
1748 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
1749 || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped'
1751 echo $vertical_display['data'][$row_no][$i];
1754 if (isset($vertical_display['rowdata'][$i][$row_no])) {
1755 $vertical_display['rowdata'][$i][$row_no] .= $vertical_display['data'][$row_no][$i];
1756 } else {
1757 $vertical_display['rowdata'][$i][$row_no] = $vertical_display['data'][$row_no][$i];
1759 } // end for (2)
1761 // 3. Displays the modify/delete links on the right if required
1762 if (($GLOBALS['cfg']['RowActionLinks'] == 'right' || $GLOBALS['cfg']['RowActionLinks'] == 'both')
1763 && ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
1764 || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped')
1766 if (! isset($js_conf)) {
1767 $js_conf = '';
1769 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);
1770 } // end if (3)
1772 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
1773 || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped'
1776 </tr>
1777 <?php
1778 } // end if
1780 // 4. Gather links of del_urls and edit_urls in an array for later
1781 // output
1782 if (! isset($vertical_display['edit'][$row_no])) {
1783 $vertical_display['edit'][$row_no] = '';
1784 $vertical_display['copy'][$row_no] = '';
1785 $vertical_display['delete'][$row_no] = '';
1786 $vertical_display['row_delete'][$row_no] = '';
1788 $vertical_class = ' row_' . $row_no;
1789 if ($GLOBALS['cfg']['BrowsePointerEnable'] == true) {
1790 $vertical_class .= ' vpointer';
1792 if ($GLOBALS['cfg']['BrowseMarkerEnable'] == true) {
1793 $vertical_class .= ' vmarker';
1796 if (!empty($del_url) && $is_display['del_lnk'] != 'kp') {
1797 $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);
1798 } else {
1799 unset($vertical_display['row_delete'][$row_no]);
1802 if (isset($edit_url)) {
1803 $vertical_display['edit'][$row_no] .= PMA_generateEditLink($edit_url, $alternating_color_class . ' ' . $edit_anchor_class . $vertical_class, $edit_str, $where_clause, $where_clause_html);
1804 } else {
1805 unset($vertical_display['edit'][$row_no]);
1808 if (isset($copy_url)) {
1809 $vertical_display['copy'][$row_no] .= PMA_generateCopyLink($copy_url, $copy_str, $where_clause, $where_clause_html, $alternating_color_class . $vertical_class);
1810 } else {
1811 unset($vertical_display['copy'][$row_no]);
1814 if (isset($del_url)) {
1815 if (! isset($js_conf)) {
1816 $js_conf = '';
1818 $vertical_display['delete'][$row_no] .= PMA_generateDeleteLink($del_url, $del_str, $js_conf, $alternating_color_class . $vertical_class);
1819 } else {
1820 unset($vertical_display['delete'][$row_no]);
1823 echo (($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal' || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') ? "\n" : '');
1824 $row_no++;
1825 } // end while
1827 // this is needed by PMA_displayTable() to generate the proper param
1828 // in the multi-edit and multi-delete form
1829 return $clause_is_unique;
1830 } // end of the 'PMA_displayTableBody()' function
1834 * Do display the result table with the vertical direction mode.
1836 * @return boolean always true
1838 * @global array $vertical_display the information to display
1840 * @access private
1842 * @see PMA_displayTable()
1844 function PMA_displayVerticalTable()
1846 global $vertical_display;
1848 // Displays "multi row delete" link at top if required
1849 if ($GLOBALS['cfg']['RowActionLinks'] != 'right'
1850 && is_array($vertical_display['row_delete'])
1851 && (count($vertical_display['row_delete']) > 0 || !empty($vertical_display['textbtn']))
1853 echo '<tr>' . "\n";
1854 if ($GLOBALS['cfg']['RowActionLinks'] == 'none') {
1855 // if we are not showing the RowActionLinks, then we need to show the Multi-Row-Action checkboxes
1856 echo '<th></th>' . "\n";
1858 echo $vertical_display['textbtn'];
1859 $cell_displayed = 0;
1860 foreach ($vertical_display['row_delete'] as $val) {
1861 if (($cell_displayed != 0) && ($_SESSION['tmp_user_values']['repeat_cells'] != 0) && !($cell_displayed % $_SESSION['tmp_user_values']['repeat_cells'])) {
1862 echo '<th' .
1863 (($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn') ? ' rowspan="4"' : '') .
1864 '></th>' . "\n";
1866 echo str_replace('[%_PMA_CHECKBOX_DIR_%]', '_left', $val);
1867 $cell_displayed++;
1868 } // end while
1869 echo '</tr>' . "\n";
1870 } // end if
1872 // Displays "edit" link at top if required
1873 if (($GLOBALS['cfg']['RowActionLinks'] == 'left' || $GLOBALS['cfg']['RowActionLinks'] == 'both')
1874 && is_array($vertical_display['edit'])
1875 && (count($vertical_display['edit']) > 0 || !empty($vertical_display['textbtn']))
1877 echo '<tr>' . "\n";
1878 if (! is_array($vertical_display['row_delete'])) {
1879 echo $vertical_display['textbtn'];
1881 foreach ($vertical_display['edit'] as $val) {
1882 echo $val;
1883 } // end while
1884 echo '</tr>' . "\n";
1885 } // end if
1887 // Displays "copy" link at top if required
1888 if (($GLOBALS['cfg']['RowActionLinks'] == 'left' || $GLOBALS['cfg']['RowActionLinks'] == 'both')
1889 && is_array($vertical_display['copy'])
1890 && (count($vertical_display['copy']) > 0 || !empty($vertical_display['textbtn']))
1892 echo '<tr>' . "\n";
1893 if (! is_array($vertical_display['row_delete'])) {
1894 echo $vertical_display['textbtn'];
1896 foreach ($vertical_display['copy'] as $val) {
1897 echo $val;
1898 } // end while
1899 echo '</tr>' . "\n";
1900 } // end if
1902 // Displays "delete" link at top if required
1903 if (($GLOBALS['cfg']['RowActionLinks'] == 'left' || $GLOBALS['cfg']['RowActionLinks'] == 'both')
1904 && is_array($vertical_display['delete'])
1905 && (count($vertical_display['delete']) > 0 || !empty($vertical_display['textbtn']))
1907 echo '<tr>' . "\n";
1908 if (! is_array($vertical_display['edit']) && ! is_array($vertical_display['row_delete'])) {
1909 echo $vertical_display['textbtn'];
1911 foreach ($vertical_display['delete'] as $val) {
1912 echo $val;
1913 } // end while
1914 echo '</tr>' . "\n";
1915 } // end if
1917 if (PMA_isSelect()) {
1918 // prepare to get the column order, if available
1919 $pmatable = new PMA_Table($GLOBALS['table'], $GLOBALS['db']);
1920 $col_order = $pmatable->getUiProp(PMA_Table::PROP_COLUMN_ORDER);
1921 $col_visib = $pmatable->getUiProp(PMA_Table::PROP_COLUMN_VISIB);
1922 } else {
1923 $col_order = false;
1924 $col_visib = false;
1927 // Displays data
1928 foreach ($vertical_display['desc'] AS $j => $val) {
1929 // assign appropriate key with current column order
1930 $key = $col_order ? $col_order[$j] : $j;
1932 echo '<tr' . (($col_visib && !$col_visib[$j]) ? ' class="hide"' : '') . '>' . "\n";
1933 echo $val;
1935 $cell_displayed = 0;
1936 foreach ($vertical_display['rowdata'][$key] as $subval) {
1937 if (($cell_displayed != 0) && ($_SESSION['tmp_user_values']['repeat_cells'] != 0) and !($cell_displayed % $_SESSION['tmp_user_values']['repeat_cells'])) {
1938 echo $val;
1941 echo $subval;
1942 $cell_displayed++;
1943 } // end while
1945 echo '</tr>' . "\n";
1946 } // end while
1948 // Displays "multi row delete" link at bottom if required
1949 if (($GLOBALS['cfg']['RowActionLinks'] == 'right' || $GLOBALS['cfg']['RowActionLinks'] == 'both')
1950 && is_array($vertical_display['row_delete'])
1951 && (count($vertical_display['row_delete']) > 0 || !empty($vertical_display['textbtn']))
1953 echo '<tr>' . "\n";
1954 echo $vertical_display['textbtn'];
1955 $cell_displayed = 0;
1956 foreach ($vertical_display['row_delete'] as $val) {
1957 if (($cell_displayed != 0) && ($_SESSION['tmp_user_values']['repeat_cells'] != 0) && !($cell_displayed % $_SESSION['tmp_user_values']['repeat_cells'])) {
1958 echo '<th' .
1959 (($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn') ? ' rowspan="4"' : '') .
1960 '></th>' . "\n";
1963 echo str_replace('[%_PMA_CHECKBOX_DIR_%]', '_right', $val);
1964 $cell_displayed++;
1965 } // end while
1966 echo '</tr>' . "\n";
1967 } // end if
1969 // Displays "edit" link at bottom if required
1970 if (($GLOBALS['cfg']['RowActionLinks'] == 'right' || $GLOBALS['cfg']['RowActionLinks'] == 'both')
1971 && is_array($vertical_display['edit'])
1972 && (count($vertical_display['edit']) > 0 || !empty($vertical_display['textbtn']))
1974 echo '<tr>' . "\n";
1975 if (! is_array($vertical_display['row_delete'])) {
1976 echo $vertical_display['textbtn'];
1978 foreach ($vertical_display['edit'] as $val) {
1979 echo $val;
1980 } // end while
1981 echo '</tr>' . "\n";
1982 } // end if
1984 // Displays "copy" link at bottom if required
1985 if (($GLOBALS['cfg']['RowActionLinks'] == 'right' || $GLOBALS['cfg']['RowActionLinks'] == 'both')
1986 && is_array($vertical_display['copy'])
1987 && (count($vertical_display['copy']) > 0 || !empty($vertical_display['textbtn']))
1989 echo '<tr>' . "\n";
1990 if (! is_array($vertical_display['row_delete'])) {
1991 echo $vertical_display['textbtn'];
1993 foreach ($vertical_display['copy'] as $val) {
1994 echo $val;
1995 } // end while
1996 echo '</tr>' . "\n";
1997 } // end if
1999 // Displays "delete" link at bottom if required
2000 if (($GLOBALS['cfg']['RowActionLinks'] == 'right' || $GLOBALS['cfg']['RowActionLinks'] == 'both')
2001 && is_array($vertical_display['delete'])
2002 && (count($vertical_display['delete']) > 0 || !empty($vertical_display['textbtn']))
2004 echo '<tr>' . "\n";
2005 if (! is_array($vertical_display['edit']) && ! is_array($vertical_display['row_delete'])) {
2006 echo $vertical_display['textbtn'];
2008 foreach ($vertical_display['delete'] as $val) {
2009 echo $val;
2010 } // end while
2011 echo '</tr>' . "\n";
2014 return true;
2015 } // end of the 'PMA_displayVerticalTable' function
2018 * Checks the posted options for viewing query resutls
2019 * and sets appropriate values in the session.
2021 * @todo make maximum remembered queries configurable
2022 * @todo move/split into SQL class!?
2023 * @todo currently this is called twice unnecessary
2024 * @todo ignore LIMIT and ORDER in query!?
2026 * @return nothing
2028 function PMA_displayTable_checkConfigParams()
2030 $sql_md5 = md5($GLOBALS['sql_query']);
2032 $_SESSION['tmp_user_values']['query'][$sql_md5]['sql'] = $GLOBALS['sql_query'];
2034 if (PMA_isValid($_REQUEST['disp_direction'], array('horizontal', 'vertical', 'horizontalflipped'))) {
2035 $_SESSION['tmp_user_values']['query'][$sql_md5]['disp_direction'] = $_REQUEST['disp_direction'];
2036 unset($_REQUEST['disp_direction']);
2037 } elseif (empty($_SESSION['tmp_user_values']['query'][$sql_md5]['disp_direction'])) {
2038 $_SESSION['tmp_user_values']['query'][$sql_md5]['disp_direction'] = $GLOBALS['cfg']['DefaultDisplay'];
2041 if (PMA_isValid($_REQUEST['repeat_cells'], 'numeric')) {
2042 $_SESSION['tmp_user_values']['query'][$sql_md5]['repeat_cells'] = $_REQUEST['repeat_cells'];
2043 unset($_REQUEST['repeat_cells']);
2044 } elseif (empty($_SESSION['tmp_user_values']['query'][$sql_md5]['repeat_cells'])) {
2045 $_SESSION['tmp_user_values']['query'][$sql_md5]['repeat_cells'] = $GLOBALS['cfg']['RepeatCells'];
2048 // as this is a form value, the type is always string so we cannot
2049 // use PMA_isValid($_REQUEST['session_max_rows'], 'integer')
2050 if ((PMA_isValid($_REQUEST['session_max_rows'], 'numeric')
2051 && (int) $_REQUEST['session_max_rows'] == $_REQUEST['session_max_rows'])
2052 || $_REQUEST['session_max_rows'] == 'all'
2054 $_SESSION['tmp_user_values']['query'][$sql_md5]['max_rows'] = $_REQUEST['session_max_rows'];
2055 unset($_REQUEST['session_max_rows']);
2056 } elseif (empty($_SESSION['tmp_user_values']['query'][$sql_md5]['max_rows'])) {
2057 $_SESSION['tmp_user_values']['query'][$sql_md5]['max_rows'] = $GLOBALS['cfg']['MaxRows'];
2060 if (PMA_isValid($_REQUEST['pos'], 'numeric')) {
2061 $_SESSION['tmp_user_values']['query'][$sql_md5]['pos'] = $_REQUEST['pos'];
2062 unset($_REQUEST['pos']);
2063 } elseif (empty($_SESSION['tmp_user_values']['query'][$sql_md5]['pos'])) {
2064 $_SESSION['tmp_user_values']['query'][$sql_md5]['pos'] = 0;
2067 if (PMA_isValid($_REQUEST['display_text'], array('P', 'F'))) {
2068 $_SESSION['tmp_user_values']['query'][$sql_md5]['display_text'] = $_REQUEST['display_text'];
2069 unset($_REQUEST['display_text']);
2070 } elseif (empty($_SESSION['tmp_user_values']['query'][$sql_md5]['display_text'])) {
2071 $_SESSION['tmp_user_values']['query'][$sql_md5]['display_text'] = 'P';
2074 if (PMA_isValid($_REQUEST['relational_display'], array('K', 'D'))) {
2075 $_SESSION['tmp_user_values']['query'][$sql_md5]['relational_display'] = $_REQUEST['relational_display'];
2076 unset($_REQUEST['relational_display']);
2077 } elseif (empty($_SESSION['tmp_user_values']['query'][$sql_md5]['relational_display'])) {
2078 $_SESSION['tmp_user_values']['query'][$sql_md5]['relational_display'] = 'K';
2081 if (PMA_isValid($_REQUEST['geometry_display'], array('WKT', 'WKB', 'GEOM'))) {
2082 $_SESSION['tmp_user_values']['query'][$sql_md5]['geometry_display'] = $_REQUEST['geometry_display'];
2083 unset($_REQUEST['geometry_display']);
2084 } elseif (empty($_SESSION['tmp_user_values']['query'][$sql_md5]['geometry_display'])) {
2085 $_SESSION['tmp_user_values']['query'][$sql_md5]['geometry_display'] = 'GEOM';
2088 if (isset($_REQUEST['display_binary'])) {
2089 $_SESSION['tmp_user_values']['query'][$sql_md5]['display_binary'] = true;
2090 unset($_REQUEST['display_binary']);
2091 } elseif (isset($_REQUEST['display_options_form'])) {
2092 // we know that the checkbox was unchecked
2093 unset($_SESSION['tmp_user_values']['query'][$sql_md5]['display_binary']);
2094 } elseif (isset($_REQUEST['full_text_button'])) {
2095 // do nothing to keep the value that is there in the session
2096 } else {
2097 // selected by default because some operations like OPTIMIZE TABLE
2098 // and all queries involving functions return "binary" contents,
2099 // according to low-level field flags
2100 $_SESSION['tmp_user_values']['query'][$sql_md5]['display_binary'] = true;
2103 if (isset($_REQUEST['display_binary_as_hex'])) {
2104 $_SESSION['tmp_user_values']['query'][$sql_md5]['display_binary_as_hex'] = true;
2105 unset($_REQUEST['display_binary_as_hex']);
2106 } elseif (isset($_REQUEST['display_options_form'])) {
2107 // we know that the checkbox was unchecked
2108 unset($_SESSION['tmp_user_values']['query'][$sql_md5]['display_binary_as_hex']);
2109 } elseif (isset($_REQUEST['full_text_button'])) {
2110 // do nothing to keep the value that is there in the session
2111 } else {
2112 // display_binary_as_hex config option
2113 if (isset($GLOBALS['cfg']['DisplayBinaryAsHex']) && true === $GLOBALS['cfg']['DisplayBinaryAsHex']) {
2114 $_SESSION['tmp_user_values']['query'][$sql_md5]['display_binary_as_hex'] = true;
2118 if (isset($_REQUEST['display_blob'])) {
2119 $_SESSION['tmp_user_values']['query'][$sql_md5]['display_blob'] = true;
2120 unset($_REQUEST['display_blob']);
2121 } elseif (isset($_REQUEST['display_options_form'])) {
2122 // we know that the checkbox was unchecked
2123 unset($_SESSION['tmp_user_values']['query'][$sql_md5]['display_blob']);
2126 if (isset($_REQUEST['hide_transformation'])) {
2127 $_SESSION['tmp_user_values']['query'][$sql_md5]['hide_transformation'] = true;
2128 unset($_REQUEST['hide_transformation']);
2129 } elseif (isset($_REQUEST['display_options_form'])) {
2130 // we know that the checkbox was unchecked
2131 unset($_SESSION['tmp_user_values']['query'][$sql_md5]['hide_transformation']);
2134 // move current query to the last position, to be removed last
2135 // so only least executed query will be removed if maximum remembered queries
2136 // limit is reached
2137 $tmp = $_SESSION['tmp_user_values']['query'][$sql_md5];
2138 unset($_SESSION['tmp_user_values']['query'][$sql_md5]);
2139 $_SESSION['tmp_user_values']['query'][$sql_md5] = $tmp;
2141 // do not exceed a maximum number of queries to remember
2142 if (count($_SESSION['tmp_user_values']['query']) > 10) {
2143 array_shift($_SESSION['tmp_user_values']['query']);
2144 //echo 'deleting one element ...';
2147 // populate query configuration
2148 $_SESSION['tmp_user_values']['display_text'] = $_SESSION['tmp_user_values']['query'][$sql_md5]['display_text'];
2149 $_SESSION['tmp_user_values']['relational_display'] = $_SESSION['tmp_user_values']['query'][$sql_md5]['relational_display'];
2150 $_SESSION['tmp_user_values']['geometry_display'] = $_SESSION['tmp_user_values']['query'][$sql_md5]['geometry_display'];
2151 $_SESSION['tmp_user_values']['display_binary'] = isset($_SESSION['tmp_user_values']['query'][$sql_md5]['display_binary']) ? true : false;
2152 $_SESSION['tmp_user_values']['display_binary_as_hex'] = isset($_SESSION['tmp_user_values']['query'][$sql_md5]['display_binary_as_hex']) ? true : false;
2153 $_SESSION['tmp_user_values']['display_blob'] = isset($_SESSION['tmp_user_values']['query'][$sql_md5]['display_blob']) ? true : false;
2154 $_SESSION['tmp_user_values']['hide_transformation'] = isset($_SESSION['tmp_user_values']['query'][$sql_md5]['hide_transformation']) ? true : false;
2155 $_SESSION['tmp_user_values']['pos'] = $_SESSION['tmp_user_values']['query'][$sql_md5]['pos'];
2156 $_SESSION['tmp_user_values']['max_rows'] = $_SESSION['tmp_user_values']['query'][$sql_md5]['max_rows'];
2157 $_SESSION['tmp_user_values']['repeat_cells'] = $_SESSION['tmp_user_values']['query'][$sql_md5]['repeat_cells'];
2158 $_SESSION['tmp_user_values']['disp_direction'] = $_SESSION['tmp_user_values']['query'][$sql_md5]['disp_direction'];
2161 * debugging
2162 echo '<pre>';
2163 var_dump($_SESSION['tmp_user_values']);
2164 echo '</pre>';
2169 * Displays a table of results returned by a SQL query.
2170 * This function is called by the "sql.php" script.
2172 * @param integer &$dt_result the link id associated to the query which results have
2173 * to be displayed
2174 * @param array &$the_disp_mode the display mode
2175 * @param array $analyzed_sql the analyzed query
2177 * @global string $db the database name
2178 * @global string $table the table name
2179 * @global string $goto the URL to go back in case of errors
2180 * @global string $sql_query the current SQL query
2181 * @global integer $num_rows the total number of rows returned by the
2182 * SQL query
2183 * @global integer $unlim_num_rows the total number of rows returned by the
2184 * SQL query without any programmatically
2185 * appended "LIMIT" clause
2186 * @global array $fields_meta the list of fields properties
2187 * @global integer $fields_cnt the total number of fields returned by
2188 * the SQL query
2189 * @global array $vertical_display informations used with vertical display
2190 * mode
2191 * @global array $highlight_columns column names to highlight
2192 * @global array $cfgRelation the relation settings
2193 * @global array $showtable table definitions
2195 * @access private
2197 * @see PMA_showMessage(), PMA_setDisplayMode(),
2198 * PMA_displayTableNavigation(), PMA_displayTableHeaders(),
2199 * PMA_displayTableBody(), PMA_displayResultsOperations()
2201 * @return nothing
2203 function PMA_displayTable(&$dt_result, &$the_disp_mode, $analyzed_sql)
2205 global $db, $table, $goto;
2206 global $sql_query, $num_rows, $unlim_num_rows, $fields_meta, $fields_cnt;
2207 global $vertical_display, $highlight_columns;
2208 global $cfgRelation;
2209 global $showtable;
2211 // why was this called here? (already called from sql.php)
2212 //PMA_displayTable_checkConfigParams();
2215 * @todo move this to a central place
2216 * @todo for other future table types
2218 $is_innodb = (isset($showtable['Type']) && $showtable['Type'] == 'InnoDB');
2220 if ($is_innodb
2221 && ! isset($analyzed_sql[0]['queryflags']['union'])
2222 && ! isset($analyzed_sql[0]['table_ref'][1]['table_name'])
2223 && (empty($analyzed_sql[0]['where_clause']) || $analyzed_sql[0]['where_clause'] == '1 ')
2225 // "j u s t b r o w s i n g"
2226 $pre_count = '~';
2227 $after_count = PMA_showHint(PMA_sanitize(__('May be approximate. See [a@./Documentation.html#faq3_11@Documentation]FAQ 3.11[/a]')));
2228 } else {
2229 $pre_count = '';
2230 $after_count = '';
2233 // 1. ----- Prepares the work -----
2235 // 1.1 Gets the informations about which functionalities should be
2236 // displayed
2237 $total = '';
2238 $is_display = PMA_setDisplayMode($the_disp_mode, $total);
2240 // 1.2 Defines offsets for the next and previous pages
2241 if ($is_display['nav_bar'] == '1') {
2242 if ($_SESSION['tmp_user_values']['max_rows'] == 'all') {
2243 $pos_next = 0;
2244 $pos_prev = 0;
2245 } else {
2246 $pos_next = $_SESSION['tmp_user_values']['pos'] + $_SESSION['tmp_user_values']['max_rows'];
2247 $pos_prev = $_SESSION['tmp_user_values']['pos'] - $_SESSION['tmp_user_values']['max_rows'];
2248 if ($pos_prev < 0) {
2249 $pos_prev = 0;
2252 } // end if
2254 // 1.3 Find the sort expression
2256 // we need $sort_expression and $sort_expression_nodirection
2257 // even if there are many table references
2258 if (! empty($analyzed_sql[0]['order_by_clause'])) {
2259 $sort_expression = trim(str_replace(' ', ' ', $analyzed_sql[0]['order_by_clause']));
2261 * Get rid of ASC|DESC
2263 preg_match('@(.*)([[:space:]]*(ASC|DESC))@si', $sort_expression, $matches);
2264 $sort_expression_nodirection = isset($matches[1]) ? trim($matches[1]) : $sort_expression;
2265 $sort_direction = isset($matches[2]) ? trim($matches[2]) : '';
2266 unset($matches);
2267 } else {
2268 $sort_expression = $sort_expression_nodirection = $sort_direction = '';
2271 // 1.4 Prepares display of first and last value of the sorted column
2273 if (! empty($sort_expression_nodirection)) {
2274 if (strpos($sort_expression_nodirection, '.') === false) {
2275 $sort_table = $table;
2276 $sort_column = $sort_expression_nodirection;
2277 } else {
2278 list($sort_table, $sort_column) = explode('.', $sort_expression_nodirection);
2280 $sort_table = PMA_unQuote($sort_table);
2281 $sort_column = PMA_unQuote($sort_column);
2282 // find the sorted column index in row result
2283 // (this might be a multi-table query)
2284 $sorted_column_index = false;
2285 foreach ($fields_meta as $key => $meta) {
2286 if ($meta->table == $sort_table && $meta->name == $sort_column) {
2287 $sorted_column_index = $key;
2288 break;
2291 if ($sorted_column_index !== false) {
2292 // fetch first row of the result set
2293 $row = PMA_DBI_fetch_row($dt_result);
2294 // initializing default arguments
2295 $default_function = 'default_function';
2296 $transform_function = $default_function;
2297 $transform_options = array();
2298 // check for non printable sorted row data
2299 $meta = $fields_meta[$sorted_column_index];
2300 if (stristr($meta->type, 'BLOB') || $meta->type == 'geometry') {
2301 $column_for_first_row = PMA_handle_non_printable_contents($meta->type, $row[$sorted_column_index], $transform_function, $transform_options, $default_function, $meta, null);
2302 } else {
2303 $column_for_first_row = $row[$sorted_column_index];
2305 $column_for_first_row = strtoupper(substr($column_for_first_row, 0, $GLOBALS['cfg']['LimitChars']));
2306 // fetch last row of the result set
2307 PMA_DBI_data_seek($dt_result, $num_rows - 1);
2308 $row = PMA_DBI_fetch_row($dt_result);
2309 // check for non printable sorted row data
2310 $meta = $fields_meta[$sorted_column_index];
2311 if (stristr($meta->type, 'BLOB') || $meta->type == 'geometry') {
2312 $column_for_last_row = PMA_handle_non_printable_contents($meta->type, $row[$sorted_column_index], $transform_function, $transform_options, $default_function, $meta, null);
2313 } else {
2314 $column_for_last_row = $row[$sorted_column_index];
2316 $column_for_last_row = strtoupper(substr($column_for_last_row, 0, $GLOBALS['cfg']['LimitChars']));
2317 // reset to first row for the loop in PMA_displayTableBody()
2318 PMA_DBI_data_seek($dt_result, 0);
2319 // we could also use here $sort_expression_nodirection
2320 $sorted_column_message = ' [' . htmlspecialchars($sort_column) . ': <strong>' . htmlspecialchars($column_for_first_row) . ' - ' . htmlspecialchars($column_for_last_row) . '</strong>]';
2321 unset($row, $column_for_first_row, $column_for_last_row, $meta, $default_function, $transform_function, $transform_options);
2323 unset($sorted_column_index, $sort_table, $sort_column);
2326 // 2. ----- Displays the top of the page -----
2328 // 2.1 Displays a messages with position informations
2329 if ($is_display['nav_bar'] == '1' && isset($pos_next)) {
2330 if (isset($unlim_num_rows) && $unlim_num_rows != $total) {
2331 $selectstring = ', ' . $unlim_num_rows . ' ' . __('in query');
2332 } else {
2333 $selectstring = '';
2336 if (! empty($analyzed_sql[0]['limit_clause'])) {
2337 $limit_data = PMA_analyzeLimitClause($analyzed_sql[0]['limit_clause']);
2338 $first_shown_rec = $limit_data['start'];
2339 if ($limit_data['length'] < $total) {
2340 $last_shown_rec = $limit_data['start'] + $limit_data['length'] - 1;
2341 } else {
2342 $last_shown_rec = $limit_data['start'] + $total - 1;
2344 } elseif ($_SESSION['tmp_user_values']['max_rows'] == 'all' || $pos_next > $total) {
2345 $first_shown_rec = $_SESSION['tmp_user_values']['pos'];
2346 $last_shown_rec = $total - 1;
2347 } else {
2348 $first_shown_rec = $_SESSION['tmp_user_values']['pos'];
2349 $last_shown_rec = $pos_next - 1;
2352 if (PMA_Table::isView($db, $table)
2353 && $total == $GLOBALS['cfg']['MaxExactCountViews']
2355 $message = PMA_Message::notice(__('This view has at least this number of rows. Please refer to %sdocumentation%s.'));
2356 $message->addParam('[a@./Documentation.html#cfg_MaxExactCount@_blank]');
2357 $message->addParam('[/a]');
2358 $message_view_warning = PMA_showHint($message);
2359 } else {
2360 $message_view_warning = false;
2363 $message = PMA_Message::success(__('Showing rows'));
2364 $message->addMessage($first_shown_rec);
2365 if ($message_view_warning) {
2366 $message->addMessage('...', ' - ');
2367 $message->addMessage($message_view_warning);
2368 $message->addMessage('(');
2369 } else {
2370 $message->addMessage($last_shown_rec, ' - ');
2371 $message->addMessage(' (');
2372 $message->addMessage($pre_count . PMA_formatNumber($total, 0));
2373 $message->addString(__('total'));
2374 if (!empty($after_count)) {
2375 $message->addMessage($after_count);
2377 $message->addMessage($selectstring, '');
2378 $message->addMessage(', ', '');
2381 $messagge_qt = PMA_Message::notice(__('Query took %01.4f sec'));
2382 $messagge_qt->addParam($GLOBALS['querytime']);
2384 $message->addMessage($messagge_qt, '');
2385 $message->addMessage(')', '');
2387 $message->addMessage(isset($sorted_column_message) ? $sorted_column_message : '', '');
2389 PMA_showMessage($message, $sql_query, 'success');
2391 } elseif (! isset($GLOBALS['printview']) || $GLOBALS['printview'] != '1') {
2392 PMA_showMessage(__('Your SQL query has been executed successfully'), $sql_query, 'success');
2395 // 2.3 Displays the navigation bars
2396 if (! strlen($table)) {
2397 if (isset($analyzed_sql[0]['query_type'])
2398 && $analyzed_sql[0]['query_type'] == 'SELECT'
2400 // table does not always contain a real table name,
2401 // for example in MySQL 5.0.x, the query SHOW STATUS
2402 // returns STATUS as a table name
2403 $table = $fields_meta[0]->table;
2404 } else {
2405 $table = '';
2409 if ($is_display['nav_bar'] == '1' && empty($analyzed_sql[0]['limit_clause'])) {
2410 PMA_displayTableNavigation($pos_next, $pos_prev, $sql_query, 'top_direction_dropdown');
2411 echo "\n";
2412 } elseif (! isset($GLOBALS['printview']) || $GLOBALS['printview'] != '1') {
2413 echo "\n" . '<br /><br />' . "\n";
2416 // 2b ----- Get field references from Database -----
2417 // (see the 'relation' configuration variable)
2419 // initialize map
2420 $map = array();
2422 // find tables
2423 $target=array();
2424 if (isset($analyzed_sql[0]['table_ref']) && is_array($analyzed_sql[0]['table_ref'])) {
2425 foreach ($analyzed_sql[0]['table_ref'] AS $table_ref_position => $table_ref) {
2426 $target[] = $analyzed_sql[0]['table_ref'][$table_ref_position]['table_true_name'];
2429 $tabs = '(\'' . join('\',\'', $target) . '\')';
2431 if (! strlen($table)) {
2432 $exist_rel = false;
2433 } else {
2434 // To be able to later display a link to the related table,
2435 // we verify both types of relations: either those that are
2436 // native foreign keys or those defined in the phpMyAdmin
2437 // configuration storage. If no PMA storage, we won't be able
2438 // to use the "column to display" notion (for example show
2439 // the name related to a numeric id).
2440 $exist_rel = PMA_getForeigners($db, $table, '', 'both');
2441 if ($exist_rel) {
2442 foreach ($exist_rel AS $master_field => $rel) {
2443 $display_field = PMA_getDisplayField($rel['foreign_db'], $rel['foreign_table']);
2444 $map[$master_field] = array($rel['foreign_table'],
2445 $rel['foreign_field'],
2446 $display_field,
2447 $rel['foreign_db']);
2448 } // end while
2449 } // end if
2450 } // end if
2451 // end 2b
2453 // 3. ----- Displays the results table -----
2454 PMA_displayTableHeaders($is_display, $fields_meta, $fields_cnt, $analyzed_sql, $sort_expression, $sort_expression_nodirection, $sort_direction);
2455 $url_query = '';
2456 echo '<tbody>' . "\n";
2457 $clause_is_unique = PMA_displayTableBody($dt_result, $is_display, $map, $analyzed_sql);
2458 // vertical output case
2459 if ($_SESSION['tmp_user_values']['disp_direction'] == 'vertical') {
2460 PMA_displayVerticalTable();
2461 } // end if
2462 unset($vertical_display);
2463 echo '</tbody>' . "\n";
2465 </table>
2467 <?php
2468 // 4. ----- Displays the link for multi-fields edit and delete
2470 if ($is_display['del_lnk'] == 'dr' && $is_display['del_lnk'] != 'kp') {
2472 $delete_text = $is_display['del_lnk'] == 'dr' ? __('Delete') : __('Kill');
2474 $_url_params = array(
2475 'db' => $db,
2476 'table' => $table,
2477 'sql_query' => $sql_query,
2478 'goto' => $goto,
2480 $uncheckall_url = 'sql.php' . PMA_generate_common_url($_url_params);
2482 $_url_params['checkall'] = '1';
2483 $checkall_url = 'sql.php' . PMA_generate_common_url($_url_params);
2485 if ($_SESSION['tmp_user_values']['disp_direction'] == 'vertical') {
2486 $checkall_params['onclick'] = 'if (setCheckboxes(\'resultsForm\', true)) return false;';
2487 $uncheckall_params['onclick'] = 'if (setCheckboxes(\'resultsForm\', false)) return false;';
2488 } else {
2489 $checkall_params['onclick'] = 'if (markAllRows(\'resultsForm\')) return false;';
2490 $uncheckall_params['onclick'] = 'if (unMarkAllRows(\'resultsForm\')) return false;';
2492 $checkall_link = PMA_linkOrButton($checkall_url, __('Check All'), $checkall_params, false);
2493 $uncheckall_link = PMA_linkOrButton($uncheckall_url, __('Uncheck All'), $uncheckall_params, false);
2494 if ($_SESSION['tmp_user_values']['disp_direction'] != 'vertical') {
2495 echo '<img class="selectallarrow" width="38" height="22"'
2496 .' src="' . $GLOBALS['pmaThemeImage'] . 'arrow_' . $GLOBALS['text_dir'] . '.png' . '"'
2497 .' alt="' . __('With selected:') . '" />';
2499 echo $checkall_link . "\n"
2500 .' / ' . "\n"
2501 .$uncheckall_link . "\n"
2502 .'<i>' . __('With selected:') . '</i>' . "\n";
2504 PMA_buttonOrImage(
2505 'submit_mult', 'mult_submit', 'submit_mult_change',
2506 __('Change'), 'b_edit.png', 'edit'
2508 PMA_buttonOrImage(
2509 'submit_mult', 'mult_submit', 'submit_mult_delete',
2510 $delete_text, 'b_drop.png', 'delete'
2512 if (isset($analyzed_sql[0]) && $analyzed_sql[0]['querytype'] == 'SELECT') {
2513 PMA_buttonOrImage(
2514 'submit_mult', 'mult_submit', 'submit_mult_export',
2515 __('Export'), 'b_tblexport.png', 'export'
2518 echo "\n";
2520 echo '<input type="hidden" name="sql_query"'
2521 .' value="' . htmlspecialchars($sql_query) . '" />' . "\n";
2523 if (! empty($GLOBALS['url_query'])) {
2524 echo '<input type="hidden" name="url_query"'
2525 .' value="' . $GLOBALS['url_query'] . '" />' . "\n";
2528 echo '<input type="hidden" name="clause_is_unique"'
2529 .' value="' . $clause_is_unique . '" />' . "\n";
2531 echo '</form>' . "\n";
2534 // 5. ----- Displays the navigation bar at the bottom if required -----
2536 if ($is_display['nav_bar'] == '1' && empty($analyzed_sql[0]['limit_clause'])) {
2537 echo '<br />' . "\n";
2538 PMA_displayTableNavigation($pos_next, $pos_prev, $sql_query, 'bottom_direction_dropdown');
2539 } elseif (! isset($GLOBALS['printview']) || $GLOBALS['printview'] != '1') {
2540 echo "\n" . '<br /><br />' . "\n";
2543 // 6. ----- Displays "Query results operations"
2544 if (! isset($GLOBALS['printview']) || $GLOBALS['printview'] != '1') {
2545 PMA_displayResultsOperations($the_disp_mode, $analyzed_sql);
2547 } // end of the 'PMA_displayTable()' function
2549 function default_function($buffer)
2551 $buffer = htmlspecialchars($buffer);
2552 $buffer = str_replace("\011", ' &nbsp;&nbsp;&nbsp;', str_replace(' ', ' &nbsp;', $buffer));
2553 $buffer = preg_replace("@((\015\012)|(\015)|(\012))@", '<br />', $buffer);
2555 return $buffer;
2559 * Displays operations that are available on results.
2561 * @param array $the_disp_mode the display mode
2562 * @param array $analyzed_sql the analyzed query
2564 * @global string $db the database name
2565 * @global string $table the table name
2566 * @global string $sql_query the current SQL query
2567 * @global integer $unlim_num_rows the total number of rows returned by the
2568 * SQL query without any programmatically
2569 * appended "LIMIT" clause
2571 * @access private
2573 * @see PMA_showMessage(), PMA_setDisplayMode(),
2574 * PMA_displayTableNavigation(), PMA_displayTableHeaders(),
2575 * PMA_displayTableBody(), PMA_displayResultsOperations()
2577 * @return nothing
2579 function PMA_displayResultsOperations($the_disp_mode, $analyzed_sql)
2581 global $db, $table, $sql_query, $unlim_num_rows, $fields_meta;
2583 $header_shown = false;
2584 $header = '<fieldset><legend>' . __('Query results operations') . '</legend>';
2586 if ($the_disp_mode[6] == '1' || $the_disp_mode[9] == '1') {
2587 // Displays "printable view" link if required
2588 if ($the_disp_mode[9] == '1') {
2590 if (!$header_shown) {
2591 echo $header;
2592 $header_shown = true;
2595 $_url_params = array(
2596 'db' => $db,
2597 'table' => $table,
2598 'printview' => '1',
2599 'sql_query' => $sql_query,
2601 $url_query = PMA_generate_common_url($_url_params);
2603 echo PMA_linkOrButton(
2604 'sql.php' . $url_query,
2605 PMA_getIcon('b_print.png', __('Print view'), true),
2606 '', true, true, 'print_view'
2607 ) . "\n";
2609 if ($_SESSION['tmp_user_values']['display_text']) {
2610 $_url_params['display_text'] = 'F';
2611 echo PMA_linkOrButton(
2612 'sql.php' . PMA_generate_common_url($_url_params),
2613 PMA_getIcon('b_print.png', __('Print view (with full texts)'), true),
2614 '', true, true, 'print_view'
2615 ) . "\n";
2616 unset($_url_params['display_text']);
2618 } // end displays "printable view"
2621 // Export link
2622 // (the url_query has extra parameters that won't be used to export)
2623 // (the single_table parameter is used in display_export.lib.php
2624 // to hide the SQL and the structure export dialogs)
2625 // If the parser found a PROCEDURE clause
2626 // (most probably PROCEDURE ANALYSE()) it makes no sense to
2627 // display the Export link).
2628 if (isset($analyzed_sql[0]) && $analyzed_sql[0]['querytype'] == 'SELECT' && ! isset($printview) && ! isset($analyzed_sql[0]['queryflags']['procedure'])) {
2629 if (isset($analyzed_sql[0]['table_ref'][0]['table_true_name']) && ! isset($analyzed_sql[0]['table_ref'][1]['table_true_name'])) {
2630 $_url_params['single_table'] = 'true';
2632 if (!$header_shown) {
2633 echo $header;
2634 $header_shown = true;
2636 $_url_params['unlim_num_rows'] = $unlim_num_rows;
2639 * At this point we don't know the table name; this can happen
2640 * for example with a query like
2641 * SELECT bike_code FROM (SELECT bike_code FROM bikes) tmp
2642 * As a workaround we set in the table parameter the name of the
2643 * first table of this database, so that tbl_export.php and
2644 * the script it calls do not fail
2646 if (empty($_url_params['table']) && !empty($_url_params['db'])) {
2647 $_url_params['table'] = PMA_DBI_fetch_value("SHOW TABLES");
2648 /* No result (probably no database selected) */
2649 if ($_url_params['table'] === false) {
2650 unset($_url_params['table']);
2654 echo PMA_linkOrButton(
2655 'tbl_export.php' . PMA_generate_common_url($_url_params),
2656 PMA_getIcon('b_tblexport.png', __('Export'), true),
2657 '', true, true, ''
2658 ) . "\n";
2660 // show chart
2661 echo PMA_linkOrButton(
2662 'tbl_chart.php' . PMA_generate_common_url($_url_params),
2663 PMA_getIcon('b_chart.png', __('Display chart'), true),
2664 '', true, true, ''
2665 ) . "\n";
2667 // show GIS chart
2668 $geometry_found = false;
2669 // If atleast one geometry field is found
2670 foreach ($fields_meta as $meta) {
2671 if ($meta->type == 'geometry') {
2672 $geometry_found = true;
2673 break;
2676 if ($geometry_found) {
2677 echo PMA_linkOrButton(
2678 'tbl_gis_visualization.php' . PMA_generate_common_url($_url_params),
2679 PMA_getIcon('b_globe.gif', __('Visualize GIS data'), true),
2680 '', true, true, ''
2681 ) . "\n";
2685 // CREATE VIEW
2688 * @todo detect privileges to create a view
2689 * (but see 2006-01-19 note in display_create_table.lib.php,
2690 * I think we cannot detect db-specific privileges reliably)
2691 * Note: we don't display a Create view link if we found a PROCEDURE clause
2693 if (!$header_shown) {
2694 echo $header;
2695 $header_shown = true;
2697 if (!PMA_DRIZZLE && !isset($analyzed_sql[0]['queryflags']['procedure'])) {
2698 echo PMA_linkOrButton(
2699 'view_create.php' . $url_query,
2700 PMA_getIcon('b_views.png', __('Create view'), true),
2701 '', true, true, ''
2702 ) . "\n";
2704 if ($header_shown) {
2705 echo '</fieldset><br />';
2710 * Verifies what to do with non-printable contents (binary or BLOB)
2711 * in Browse mode.
2713 * @param string $category BLOB|BINARY|GEOMETRY
2714 * @param string $content the binary content
2715 * @param string $transform_function transformation function
2716 * @param string $transform_options transformation parameters
2717 * @param string $default_function default transformation function
2718 * @param object $meta the meta-information about this field
2719 * @param array $url_params parameters that should go to the download link
2721 * @return mixed string or float
2723 function PMA_handle_non_printable_contents($category, $content, $transform_function, $transform_options, $default_function, $meta, $url_params = array())
2725 $result = '[' . $category;
2726 if (is_null($content)) {
2727 $result .= ' - NULL';
2728 $size = 0;
2729 } elseif (isset($content)) {
2730 $size = strlen($content);
2731 $display_size = PMA_formatByteDown($size, 3, 1);
2732 $result .= ' - '. $display_size[0] . ' ' . $display_size[1];
2734 $result .= ']';
2736 if (strpos($transform_function, 'octetstream')) {
2737 $result = $content;
2739 if ($size > 0) {
2740 if ($default_function != $transform_function) {
2741 $result = $transform_function($result, $transform_options, $meta);
2742 } else {
2743 $result = $default_function($result, array(), $meta);
2744 if (stristr($meta->type, 'BLOB') && $_SESSION['tmp_user_values']['display_blob']) {
2745 // in this case, restart from the original $content
2746 $result = htmlspecialchars(PMA_replace_binary_contents($content));
2748 /* Create link to download */
2749 if (count($url_params) > 0) {
2750 $result = '<a href="tbl_get_field.php' . PMA_generate_common_url($url_params) . '">' . $result . '</a>';
2754 return($result);
2758 * Prepares the displayable content of a data cell in Browse mode,
2759 * taking into account foreign key description field and transformations
2761 * @param string $class css classes for the td element
2762 * @param bool $condition_field whether the column is a part of the where clause
2763 * @param string $analyzed_sql the analyzed query
2764 * @param object $meta the meta-information about this field
2765 * @param array $map the list of relations
2766 * @param string $data data
2767 * @param string $transform_function transformation function
2768 * @param string $default_function default function
2769 * @param string $nowrap 'nowrap' if the content should not be wrapped
2770 * @param string $where_comparison data for the where cluase
2771 * @param array $transform_options array of options for transformation
2772 * @param bool $is_field_truncated whether the field is truncated
2774 * @return string formatted data
2776 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 )
2779 $result = ' class="' . PMA_addClass($class, $condition_field, $meta, $nowrap, $is_field_truncated, $transform_function, $default_function) . '">';
2781 if (isset($analyzed_sql[0]['select_expr']) && is_array($analyzed_sql[0]['select_expr'])) {
2782 foreach ($analyzed_sql[0]['select_expr'] AS $select_expr_position => $select_expr) {
2783 $alias = $analyzed_sql[0]['select_expr'][$select_expr_position]['alias'];
2784 if (isset($alias) && strlen($alias)) {
2785 $true_column = $analyzed_sql[0]['select_expr'][$select_expr_position]['column'];
2786 if ($alias == $meta->name) {
2787 // this change in the parameter does not matter
2788 // outside of the function
2789 $meta->name = $true_column;
2790 } // end if
2791 } // end if
2792 } // end foreach
2793 } // end if
2795 if (isset($map[$meta->name])) {
2796 // Field to display from the foreign table?
2797 if (isset($map[$meta->name][2]) && strlen($map[$meta->name][2])) {
2798 $dispsql = 'SELECT ' . PMA_backquote($map[$meta->name][2])
2799 . ' FROM ' . PMA_backquote($map[$meta->name][3])
2800 . '.' . PMA_backquote($map[$meta->name][0])
2801 . ' WHERE ' . PMA_backquote($map[$meta->name][1])
2802 . $where_comparison;
2803 $dispresult = PMA_DBI_try_query($dispsql, null, PMA_DBI_QUERY_STORE);
2804 if ($dispresult && PMA_DBI_num_rows($dispresult) > 0) {
2805 list($dispval) = PMA_DBI_fetch_row($dispresult, 0);
2806 } else {
2807 $dispval = __('Link not found');
2809 @PMA_DBI_free_result($dispresult);
2810 } else {
2811 $dispval = '';
2812 } // end if... else...
2814 if (isset($GLOBALS['printview']) && $GLOBALS['printview'] == '1') {
2815 $result .= ($transform_function != $default_function ? $transform_function($data, $transform_options, $meta) : $transform_function($data, array(), $meta)) . ' <code>[-&gt;' . $dispval . ']</code>';
2816 } else {
2818 if ('K' == $_SESSION['tmp_user_values']['relational_display']) {
2819 // user chose "relational key" in the display options, so
2820 // the title contains the display field
2821 $title = (! empty($dispval))? ' title="' . htmlspecialchars($dispval) . '"' : '';
2822 } else {
2823 $title = ' title="' . htmlspecialchars($data) . '"';
2826 $_url_params = array(
2827 'db' => $map[$meta->name][3],
2828 'table' => $map[$meta->name][0],
2829 'pos' => '0',
2830 'sql_query' => 'SELECT * FROM '
2831 . PMA_backquote($map[$meta->name][3]) . '.' . PMA_backquote($map[$meta->name][0])
2832 . ' WHERE ' . PMA_backquote($map[$meta->name][1])
2833 . $where_comparison,
2835 $result .= '<a href="sql.php' . PMA_generate_common_url($_url_params)
2836 . '"' . $title . '>';
2838 if ($transform_function != $default_function) {
2839 // always apply a transformation on the real data,
2840 // not on the display field
2841 $result .= $transform_function($data, $transform_options, $meta);
2842 } else {
2843 if ('D' == $_SESSION['tmp_user_values']['relational_display']) {
2844 // user chose "relational display field" in the
2845 // display options, so show display field in the cell
2846 $result .= $transform_function($dispval, array(), $meta);
2847 } else {
2848 // otherwise display data in the cell
2849 $result .= $transform_function($data, array(), $meta);
2852 $result .= '</a>';
2854 } else {
2855 $result .= ($transform_function != $default_function ? $transform_function($data, $transform_options, $meta) : $transform_function($data, array(), $meta));
2857 $result .= '</td>' . "\n";
2859 return $result;
2863 * Generates a checkbox for multi-row submits
2865 * @param string $del_url delete url
2866 * @param array $is_display array with explicit indexes for all the display elements
2867 * @param string $row_no the row number
2868 * @param string $where_clause_html url encoded where cluase
2869 * @param array $condition_array array of conditions in the where cluase
2870 * @param string $del_query delete query
2871 * @param string $id_suffix suffix for the id
2872 * @param string $class css classes for the td element
2874 * @return string the generated HTML
2877 function PMA_generateCheckboxForMulti($del_url, $is_display, $row_no, $where_clause_html, $condition_array, $del_query, $id_suffix, $class)
2879 $ret = '';
2880 if (! empty($del_url) && $is_display['del_lnk'] != 'kp') {
2881 $ret .= '<td ';
2882 if (! empty($class)) {
2883 $ret .= 'class="' . $class . '"';
2885 $ret .= ' align="center">'
2886 . '<input type="checkbox" id="id_rows_to_delete' . $row_no . $id_suffix . '" name="rows_to_delete[' . $where_clause_html . ']"'
2887 . ' class="multi_checkbox"'
2888 . ' value="' . htmlspecialchars($del_query) . '" ' . (isset($GLOBALS['checkall']) ? 'checked="checked"' : '') . ' />'
2889 . '<input type="hidden" class="condition_array" value="' . htmlspecialchars(json_encode($condition_array)) . '" />'
2890 . ' </td>';
2892 return $ret;
2896 * Generates an Edit link
2898 * @param string $edit_url edit url
2899 * @param string $class css classes for td element
2900 * @param string $edit_str text for the edit link
2901 * @param string $where_clause where cluase
2902 * @param string $where_clause_html url encoded where cluase
2904 * @return string the generated HTML
2906 function PMA_generateEditLink($edit_url, $class, $edit_str, $where_clause, $where_clause_html)
2908 $ret = '';
2909 if (! empty($edit_url)) {
2910 $ret .= '<td class="' . $class . '" align="center" ' . ' ><span class="nowrap">'
2911 . PMA_linkOrButton($edit_url, $edit_str, array(), false);
2913 * Where clause for selecting this row uniquely is provided as
2914 * a hidden input. Used by jQuery scripts for handling grid editing
2916 if (! empty($where_clause)) {
2917 $ret .= '<input type="hidden" class="where_clause" value ="' . $where_clause_html . '" />';
2919 $ret .= '</span></td>';
2921 return $ret;
2925 * Generates an Copy link
2927 * @param string $copy_url copy url
2928 * @param string $copy_str text for the copy link
2929 * @param string $where_clause where clause
2930 * @param string $where_clause_html url encoded where cluase
2931 * @param string $class css classes for the td element
2933 * @return string the generated HTML
2935 function PMA_generateCopyLink($copy_url, $copy_str, $where_clause, $where_clause_html, $class)
2937 $ret = '';
2938 if (! empty($copy_url)) {
2939 $ret .= '<td ';
2940 if (! empty($class)) {
2941 $ret .= 'class="' . $class . '" ';
2943 $ret .= 'align="center" ' . ' ><span class="nowrap">'
2944 . PMA_linkOrButton($copy_url, $copy_str, array(), false);
2946 * Where clause for selecting this row uniquely is provided as
2947 * a hidden input. Used by jQuery scripts for handling grid editing
2949 if (! empty($where_clause)) {
2950 $ret .= '<input type="hidden" class="where_clause" value ="' . $where_clause_html . '" />';
2952 $ret .= '</span></td>';
2954 return $ret;
2958 * Generates a Delete link
2960 * @param string $del_url delete url
2961 * @param string $del_str text for the delete link
2962 * @param string $js_conf text for the JS confirmation
2963 * @param string $class css classes for the td element
2965 * @return string the generated HTML
2967 function PMA_generateDeleteLink($del_url, $del_str, $js_conf, $class)
2969 $ret = '';
2970 if (! empty($del_url)) {
2971 $ret .= '<td ';
2972 if (! empty($class)) {
2973 $ret .= 'class="' . $class . '" ';
2975 $ret .= 'align="center" ' . ' >'
2976 . PMA_linkOrButton($del_url, $del_str, $js_conf, false)
2977 . '</td>';
2979 return $ret;
2983 * Generates checkbox and links at some position (left or right)
2984 * (only called for horizontal mode)
2986 * @param string $position the position of the checkbox and links
2987 * @param string $del_url delete url
2988 * @param array $is_display array with explicit indexes for all the display elements
2989 * @param string $row_no row number
2990 * @param string $where_clause where clause
2991 * @param string $where_clause_html url encoded where cluase
2992 * @param array $condition_array array of conditions in the where cluase
2993 * @param string $del_query delete query
2994 * @param string $id_suffix suffix for the id
2995 * @param string $edit_url edit url
2996 * @param string $copy_url copy url
2997 * @param string $class css classes for the td elements
2998 * @param string $edit_str text for the edit link
2999 * @param string $copy_str text for the copy link
3000 * @param string $del_str text for the delete link
3001 * @param string $js_conf text for the JS confirmation
3003 * @return string the generated HTML
3005 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)
3007 $ret = '';
3009 if ($position == 'left') {
3010 $ret .= PMA_generateCheckboxForMulti($del_url, $is_display, $row_no, $where_clause_html, $condition_array, $del_query, $id_suffix = '_left', '', '', '');
3012 $ret .= PMA_generateEditLink($edit_url, $class, $edit_str, $where_clause, $where_clause_html, '');
3014 $ret .= PMA_generateCopyLink($copy_url, $copy_str, $where_clause, $where_clause_html, '');
3016 $ret .= PMA_generateDeleteLink($del_url, $del_str, $js_conf, '', '');
3018 } elseif ($position == 'right') {
3019 $ret .= PMA_generateDeleteLink($del_url, $del_str, $js_conf, '', '');
3021 $ret .= PMA_generateCopyLink($copy_url, $copy_str, $where_clause, $where_clause_html, '');
3023 $ret .= PMA_generateEditLink($edit_url, $class, $edit_str, $where_clause, $where_clause_html, '');
3025 $ret .= PMA_generateCheckboxForMulti($del_url, $is_display, $row_no, $where_clause_html, $condition_array, $del_query, $id_suffix = '_right', '', '', '');
3026 } else { // $position == 'none'
3027 $ret .= PMA_generateCheckboxForMulti($del_url, $is_display, $row_no, $where_clause_html, $condition_array, $del_query, $id_suffix = '_left', '', '', '');
3029 return $ret;