Translation update done using Pootle.
[phpmyadmin.git] / libraries / display_tbl.lib.php
blob63121ac73ad5df2e861b96d6ebe43f5e8849a41c
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 $nbTotalPage = 1;
312 //page redirection
313 // (unless we are showing all records)
314 if ('all' != $_SESSION['tmp_user_values']['max_rows']) { //if1
315 $pageNow = @floor($_SESSION['tmp_user_values']['pos'] / $_SESSION['tmp_user_values']['max_rows']) + 1;
316 $nbTotalPage = @ceil($unlim_num_rows / $_SESSION['tmp_user_values']['max_rows']);
318 if ($nbTotalPage > 1) { //if2
320 <td>
321 <?php
322 $_url_params = array(
323 'db' => $db,
324 'table' => $table,
325 'sql_query' => $sql_query,
326 'goto' => $goto,
328 //<form> to keep the form alignment of button < and <<
329 // and also to know what to execute when the selector changes
330 echo '<form action="sql.php' . PMA_generate_common_url($_url_params). '" method="post">';
331 echo PMA_pageselector(
332 $_SESSION['tmp_user_values']['max_rows'],
333 $pageNow,
334 $nbTotalPage,
335 200,
342 </form>
343 </td>
344 <?php
345 } //_if2
346 } //_if1
348 // Display the "Show all" button if allowed
349 if (($num_rows < $unlim_num_rows) && ($GLOBALS['cfg']['ShowAll'] || ($GLOBALS['cfg']['MaxRows'] * 5 >= $unlim_num_rows))) {
350 echo "\n";
352 <td>
353 <form action="sql.php" method="post">
354 <?php echo PMA_generate_common_hidden_inputs($db, $table); ?>
355 <input type="hidden" name="sql_query" value="<?php echo $html_sql_query; ?>" />
356 <input type="hidden" name="pos" value="0" />
357 <input type="hidden" name="session_max_rows" value="all" />
358 <input type="hidden" name="goto" value="<?php echo $goto; ?>" />
359 <input type="submit" name="navig" value="<?php echo __('Show all'); ?>" />
360 </form>
361 </td>
362 <?php
363 } // end show all
365 // Move to the next page or to the last one
366 if (($_SESSION['tmp_user_values']['pos'] + $_SESSION['tmp_user_values']['max_rows'] < $unlim_num_rows)
367 && $num_rows >= $_SESSION['tmp_user_values']['max_rows']
368 && $_SESSION['tmp_user_values']['max_rows'] != 'all'
370 // display the Next button
371 PMA_displayTableNavigationOneButton(
372 '&gt;',
373 _pgettext('Next page', 'Next'),
374 $pos_next,
375 $html_sql_query
378 // prepare some options for the End button
379 if ($is_innodb && $unlim_num_rows > $GLOBALS['cfg']['MaxExactCount']) {
380 $input_for_real_end = '<input id="real_end_input" type="hidden" name="find_real_end" value="1" />';
381 // no backquote around this message
382 $onclick = '';
383 } else {
384 $input_for_real_end = $onclick = '';
387 // display the End button
388 PMA_displayTableNavigationOneButton(
389 '&gt;&gt;',
390 _pgettext('Last page', 'End'),
391 @((ceil($unlim_num_rows / $_SESSION['tmp_user_values']['max_rows'])- 1) * $_SESSION['tmp_user_values']['max_rows']),
392 $html_sql_query,
393 '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') . '"',
394 $input_for_real_end,
395 $onclick
397 } // end move toward
399 // show separator if pagination happen
400 if ($nbTotalPage > 1) {
401 echo '<td><div class="navigation_separator">|</div></td>';
404 <td>
405 <div class="save_edited hide">
406 <input type="submit" value="<?php echo __('Save edited data'); ?>" />
407 <div class="navigation_separator">|</div>
408 </div>
409 </td>
410 <td>
411 <div class="restore_column hide">
412 <input type="submit" value="<?php echo __('Restore column order'); ?>" />
413 <div class="navigation_separator">|</div>
414 </div>
415 </td>
417 <?php // if displaying a VIEW, $unlim_num_rows could be zero because
418 // of $cfg['MaxExactCountViews']; in this case, avoid passing
419 // the 5th parameter to checkFormElementInRange()
420 // (this means we can't validate the upper limit ?>
421 <td class="navigation_goto">
422 <form action="sql.php" method="post"
423 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 : ''; ?>))">
424 <?php echo PMA_generate_common_hidden_inputs($db, $table); ?>
425 <input type="hidden" name="sql_query" value="<?php echo $html_sql_query; ?>" />
426 <input type="hidden" name="goto" value="<?php echo $goto; ?>" />
427 <input type="submit" name="navig" <?php echo ($GLOBALS['cfg']['AjaxEnable'] ? ' class="ajax"' : ''); ?> value="<?php echo __('Show'); ?> :" />
428 <?php echo __('Start row') . ': ' . "\n"; ?>
429 <input type="text" name="pos" size="3" value="<?php echo (($pos_next >= $unlim_num_rows) ? 0 : $pos_next); ?>" class="textfield" onfocus="this.select()" />
430 <?php echo __('Number of rows') . ': ' . "\n"; ?>
431 <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()" />
432 <?php
433 if ($GLOBALS['cfg']['ShowDisplayDirection']) {
434 // Display mode (horizontal/vertical and repeat headers)
435 echo __('Mode') . ': ' . "\n";
436 $choices = array(
437 'horizontal' => __('horizontal'),
438 'horizontalflipped' => __('horizontal (rotated headers)'),
439 'vertical' => __('vertical'));
440 echo PMA_generate_html_dropdown('disp_direction', $choices, $_SESSION['tmp_user_values']['disp_direction'], $id_for_direction_dropdown);
441 unset($choices);
444 printf(
445 __('Headers every %s rows'),
446 '<input type="text" size="3" name="repeat_cells" value="' . $_SESSION['tmp_user_values']['repeat_cells'] . '" class="textfield" />'
448 echo "\n";
450 </form>
451 </td>
452 <td class="navigation_separator"></td>
453 </tr>
454 </table>
456 <?php
457 } // end of the 'PMA_displayTableNavigation()' function
461 * Displays the headers of the results table
463 * @param array &$is_display which elements to display
464 * @param array &$fields_meta the list of fields properties
465 * @param integer $fields_cnt the total number of fields returned by the SQL query
466 * @param array $analyzed_sql the analyzed query
467 * @param string $sort_expression sort expression
468 * @param string $sort_expression_nodirection sort expression without direction
469 * @param string $sort_direction sort direction
471 * @return boolean $clause_is_unique
473 * @global string $db the database name
474 * @global string $table the table name
475 * @global string $goto the URL to go back in case of errors
476 * @global string $sql_query the SQL query
477 * @global integer $num_rows the total number of rows returned by the
478 * SQL query
479 * @global array $vertical_display informations used with vertical display
480 * mode
482 * @access private
484 * @see PMA_displayTable()
486 function PMA_displayTableHeaders(&$is_display, &$fields_meta, $fields_cnt = 0, $analyzed_sql = '', $sort_expression, $sort_expression_nodirection, $sort_direction)
488 global $db, $table, $goto;
489 global $sql_query, $num_rows;
490 global $vertical_display, $highlight_columns;
492 // required to generate sort links that will remember whether the
493 // "Show all" button has been clicked
494 $sql_md5 = md5($GLOBALS['sql_query']);
495 $session_max_rows = $_SESSION['tmp_user_values']['query'][$sql_md5]['max_rows'];
497 if ($analyzed_sql == '') {
498 $analyzed_sql = array();
501 // can the result be sorted?
502 if ($is_display['sort_lnk'] == '1') {
504 // Just as fallback
505 $unsorted_sql_query = $sql_query;
506 if (isset($analyzed_sql[0]['unsorted_query'])) {
507 $unsorted_sql_query = $analyzed_sql[0]['unsorted_query'];
509 // Handles the case of multiple clicks on a column's header
510 // which would add many spaces before "ORDER BY" in the
511 // generated query.
512 $unsorted_sql_query = trim($unsorted_sql_query);
514 // sorting by indexes, only if it makes sense (only one table ref)
515 if (isset($analyzed_sql)
516 && isset($analyzed_sql[0])
517 && isset($analyzed_sql[0]['querytype'])
518 && $analyzed_sql[0]['querytype'] == 'SELECT'
519 && isset($analyzed_sql[0]['table_ref'])
520 && count($analyzed_sql[0]['table_ref']) == 1
523 // grab indexes data:
524 $indexes = PMA_Index::getFromTable($table, $db);
526 // do we have any index?
527 if ($indexes) {
529 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
530 || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped'
532 $span = $fields_cnt;
533 if ($is_display['edit_lnk'] != 'nn') {
534 $span++;
536 if ($is_display['del_lnk'] != 'nn') {
537 $span++;
539 if ($is_display['del_lnk'] != 'kp' && $is_display['del_lnk'] != 'nn') {
540 $span++;
542 } else {
543 $span = $num_rows + floor($num_rows/$_SESSION['tmp_user_values']['repeat_cells']) + 1;
546 echo '<form action="sql.php" method="post">' . "\n";
547 echo PMA_generate_common_hidden_inputs($db, $table);
548 echo __('Sort by key') . ': <select name="sql_query" class="autosubmit">' . "\n";
549 $used_index = false;
550 $local_order = (isset($sort_expression) ? $sort_expression : '');
551 foreach ($indexes as $index) {
552 $asc_sort = '`' . implode('` ASC, `', array_keys($index->getColumns())) . '` ASC';
553 $desc_sort = '`' . implode('` DESC, `', array_keys($index->getColumns())) . '` DESC';
554 $used_index = $used_index || $local_order == $asc_sort || $local_order == $desc_sort;
555 if (preg_match('@(.*)([[:space:]](LIMIT (.*)|PROCEDURE (.*)|FOR UPDATE|LOCK IN SHARE MODE))@is', $unsorted_sql_query, $my_reg)) {
556 $unsorted_sql_query_first_part = $my_reg[1];
557 $unsorted_sql_query_second_part = $my_reg[2];
558 } else {
559 $unsorted_sql_query_first_part = $unsorted_sql_query;
560 $unsorted_sql_query_second_part = '';
562 echo '<option value="'
563 . htmlspecialchars($unsorted_sql_query_first_part . "\n" . ' ORDER BY ' . $asc_sort . $unsorted_sql_query_second_part)
564 . '"' . ($local_order == $asc_sort ? ' selected="selected"' : '')
565 . '>' . htmlspecialchars($index->getName()) . ' ('
566 . __('Ascending') . ')</option>';
567 echo '<option value="'
568 . htmlspecialchars($unsorted_sql_query_first_part . "\n" . ' ORDER BY ' . $desc_sort . $unsorted_sql_query_second_part)
569 . '"' . ($local_order == $desc_sort ? ' selected="selected"' : '')
570 . '>' . htmlspecialchars($index->getName()) . ' ('
571 . __('Descending') . ')</option>';
573 echo '<option value="' . htmlspecialchars($unsorted_sql_query) . '"' . ($used_index ? '' : ' selected="selected"') . '>' . __('None') . '</option>';
574 echo '</select>' . "\n";
575 echo '<noscript><input type="submit" value="' . __('Go') . '" /></noscript>';
576 echo '</form>' . "\n";
582 // Output data needed for grid editing
583 echo '<input id="save_cells_at_once" type="hidden" value="' . $GLOBALS['cfg']['SaveCellsAtOnce'] . '" />';
584 echo '<div class="common_hidden_inputs">';
585 echo PMA_generate_common_hidden_inputs($db, $table);
586 echo '</div>';
587 // Output data needed for column reordering and show/hide column
588 if (PMA_isSelect()) {
589 // generate the column order, if it is set
590 $pmatable = new PMA_Table($GLOBALS['table'], $GLOBALS['db']);
591 $col_order = $pmatable->getUiProp(PMA_Table::PROP_COLUMN_ORDER);
592 if ($col_order) {
593 echo '<input id="col_order" type="hidden" value="' . implode(',', $col_order) . '" />';
595 $col_visib = $pmatable->getUiProp(PMA_Table::PROP_COLUMN_VISIB);
596 if ($col_visib) {
597 echo '<input id="col_visib" type="hidden" value="' . implode(',', $col_visib) . '" />';
599 // generate table create time
600 if (! PMA_Table::isView($GLOBALS['table'], $GLOBALS['db'])) {
601 echo '<input id="table_create_time" type="hidden" value="' .
602 PMA_Table::sGetStatusInfo($GLOBALS['db'], $GLOBALS['table'], 'Create_time') . '" />';
607 $vertical_display['emptypre'] = 0;
608 $vertical_display['emptyafter'] = 0;
609 $vertical_display['textbtn'] = '';
611 // Display options (if we are not in print view)
612 if (! (isset($GLOBALS['printview']) && $GLOBALS['printview'] == '1')) {
613 echo '<form method="post" action="sql.php" name="displayOptionsForm" id="displayOptionsForm"';
614 if ($GLOBALS['cfg']['AjaxEnable']) {
615 echo ' class="ajax" ';
617 echo '>';
618 $url_params = array(
619 'db' => $db,
620 'table' => $table,
621 'sql_query' => $sql_query,
622 'goto' => $goto,
623 'display_options_form' => 1
625 echo PMA_generate_common_hidden_inputs($url_params);
626 echo '<br />';
627 PMA_generate_slider_effect('displayoptions', __('Options'));
628 echo '<fieldset>';
630 echo '<div class="formelement">';
631 $choices = array(
632 'P' => __('Partial texts'),
633 'F' => __('Full texts')
635 PMA_display_html_radio('display_text', $choices, $_SESSION['tmp_user_values']['display_text']);
636 echo '</div>';
638 // prepare full/partial text button or link
639 $url_params_full_text = array(
640 'db' => $db,
641 'table' => $table,
642 'sql_query' => $sql_query,
643 'goto' => $goto,
644 'full_text_button' => 1
647 if ($_SESSION['tmp_user_values']['display_text']=='F') {
648 // currently in fulltext mode so show the opposite link
649 $tmp_image_file = $GLOBALS['pmaThemeImage'] . 's_partialtext.png';
650 $tmp_txt = __('Partial texts');
651 $url_params_full_text['display_text'] = 'P';
652 } else {
653 $tmp_image_file = $GLOBALS['pmaThemeImage'] . 's_fulltext.png';
654 $tmp_txt = __('Full texts');
655 $url_params_full_text['display_text'] = 'F';
658 $tmp_image = '<img class="fulltext" src="' . $tmp_image_file . '" alt="' . $tmp_txt . '" title="' . $tmp_txt . '" />';
659 $tmp_url = 'sql.php' . PMA_generate_common_url($url_params_full_text);
660 $full_or_partial_text_link = PMA_linkOrButton($tmp_url, $tmp_image, array(), false);
661 unset($tmp_image_file, $tmp_txt, $tmp_url, $tmp_image);
664 if ($GLOBALS['cfgRelation']['relwork'] && $GLOBALS['cfgRelation']['displaywork']) {
665 echo '<div class="formelement">';
666 $choices = array(
667 'K' => __('Relational key'),
668 'D' => __('Relational display column')
670 PMA_display_html_radio('relational_display', $choices, $_SESSION['tmp_user_values']['relational_display']);
671 echo '</div>';
674 echo '<div class="formelement">';
675 PMA_display_html_checkbox('display_binary', __('Show binary contents'), ! empty($_SESSION['tmp_user_values']['display_binary']), false);
676 echo '<br />';
677 PMA_display_html_checkbox('display_blob', __('Show BLOB contents'), ! empty($_SESSION['tmp_user_values']['display_blob']), false);
678 echo '<br />';
679 PMA_display_html_checkbox('display_binary_as_hex', __('Show binary contents as HEX'), ! empty($_SESSION['tmp_user_values']['display_binary_as_hex']), false);
680 echo '</div>';
682 // I would have preferred to name this "display_transformation".
683 // This is the only way I found to be able to keep this setting sticky
684 // per SQL query, and at the same time have a default that displays
685 // the transformations.
686 echo '<div class="formelement">';
687 PMA_display_html_checkbox('hide_transformation', __('Hide browser transformation'), ! empty($_SESSION['tmp_user_values']['hide_transformation']), false);
688 echo '</div>';
690 if (! PMA_DRIZZLE) {
691 echo '<div class="formelement">';
692 $choices = array(
693 'GEOM' => __('Geometry'),
694 'WKT' => __('Well Known Text'),
695 'WKB' => __('Well Known Binary')
697 PMA_display_html_radio('geometry_display', $choices, $_SESSION['tmp_user_values']['geometry_display']);
698 echo '</div>';
701 echo '<div class="clearfloat"></div>';
702 echo '</fieldset>';
704 echo '<fieldset class="tblFooters">';
705 echo '<input type="submit" value="' . __('Go') . '" />';
706 echo '</fieldset>';
707 echo '</div>';
708 echo '</form>';
711 // Start of form for multi-rows edit/delete/export
713 if ($is_display['del_lnk'] == 'dr' || $is_display['del_lnk'] == 'kp') {
714 echo '<form method="post" action="tbl_row_action.php" name="resultsForm" id="resultsForm"';
715 if ($GLOBALS['cfg']['AjaxEnable']) {
716 echo ' class="ajax" ';
718 echo '>' . "\n";
719 echo PMA_generate_common_hidden_inputs($db, $table, 1);
720 echo '<input type="hidden" name="goto" value="sql.php" />' . "\n";
723 echo '<table id="table_results" class="data';
724 if ($GLOBALS['cfg']['AjaxEnable']) {
725 echo ' ajax';
727 echo '">' . "\n";
728 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
729 || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped'
731 echo '<thead><tr>' . "\n";
734 // 1. Displays the full/partial text button (part 1)...
735 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
736 || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped'
738 $colspan = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn')
739 ? ' colspan="4"'
740 : '';
741 } else {
742 $rowspan = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn')
743 ? ' rowspan="4"'
744 : '';
747 // ... before the result table
748 if (($is_display['edit_lnk'] == 'nn' && $is_display['del_lnk'] == 'nn')
749 && $is_display['text_btn'] == '1'
751 $vertical_display['emptypre'] = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn') ? 4 : 0;
752 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
753 || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped'
756 <th colspan="<?php echo $fields_cnt; ?>"></th>
757 </tr>
758 <tr>
759 <?php
760 // end horizontal/horizontalflipped mode
761 } else {
763 <tr>
764 <th colspan="<?php echo $num_rows + floor($num_rows/$_SESSION['tmp_user_values']['repeat_cells']) + 1; ?>"></th>
765 </tr>
766 <?php
767 } // end vertical mode
770 // ... at the left column of the result table header if possible
771 // and required
772 elseif (($GLOBALS['cfg']['RowActionLinks'] == 'left' || $GLOBALS['cfg']['RowActionLinks'] == 'both')
773 && $is_display['text_btn'] == '1'
775 $vertical_display['emptypre'] = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn') ? 4 : 0;
776 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
777 || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped'
780 <th <?php echo $colspan; ?>><?php echo $full_or_partial_text_link;?></th>
781 <?php
782 // end horizontal/horizontalflipped mode
783 } else {
784 $vertical_display['textbtn'] = ' <th ' . $rowspan . ' valign="middle">' . "\n"
785 . ' ' . "\n"
786 . ' </th>' . "\n";
787 } // end vertical mode
790 // ... elseif no button, displays empty(ies) col(s) if required
791 elseif (($GLOBALS['cfg']['RowActionLinks'] == 'left' || $GLOBALS['cfg']['RowActionLinks'] == 'both')
792 && ($is_display['edit_lnk'] != 'nn' || $is_display['del_lnk'] != 'nn')) {
793 $vertical_display['emptypre'] = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn') ? 4 : 0;
794 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
795 || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped'
798 <td<?php echo $colspan; ?>></td>
799 <?php
800 // end horizontal/horizontalfipped mode
801 } else {
802 $vertical_display['textbtn'] = ' <td' . $rowspan . '></td>' . "\n";
803 } // end vertical mode
806 // ... elseif display an empty column if the actions links are disabled to match the rest of the table
807 elseif ($GLOBALS['cfg']['RowActionLinks'] == 'none'
808 && ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal' || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped')
810 echo '<th></th>';
813 // 2. Displays the fields' name
814 // 2.0 If sorting links should be used, checks if the query is a "JOIN"
815 // statement (see 2.1.3)
817 // 2.0.1 Prepare Display column comments if enabled ($GLOBALS['cfg']['ShowBrowseComments']).
818 // Do not show comments, if using horizontalflipped mode, because of space usage
819 if ($GLOBALS['cfg']['ShowBrowseComments']
820 && $_SESSION['tmp_user_values']['disp_direction'] != 'horizontalflipped'
822 $comments_map = array();
823 if (isset($analyzed_sql[0]) && is_array($analyzed_sql[0])) {
824 foreach ($analyzed_sql[0]['table_ref'] as $tbl) {
825 $tb = $tbl['table_true_name'];
826 $comments_map[$tb] = PMA_getComments($db, $tb);
827 unset($tb);
832 if ($GLOBALS['cfgRelation']['commwork'] && $GLOBALS['cfgRelation']['mimework'] && $GLOBALS['cfg']['BrowseMIME'] && ! $_SESSION['tmp_user_values']['hide_transformation']) {
833 include_once './libraries/transformations.lib.php';
834 $GLOBALS['mime_map'] = PMA_getMIME($db, $table);
837 // See if we have to highlight any header fields of a WHERE query.
838 // Uses SQL-Parser results.
839 $highlight_columns = array();
840 if (isset($analyzed_sql) && isset($analyzed_sql[0])
841 && isset($analyzed_sql[0]['where_clause_identifiers'])
844 $wi = 0;
845 if (isset($analyzed_sql[0]['where_clause_identifiers']) && is_array($analyzed_sql[0]['where_clause_identifiers'])) {
846 foreach ($analyzed_sql[0]['where_clause_identifiers'] AS $wci_nr => $wci) {
847 $highlight_columns[$wci] = 'true';
852 if (PMA_isSelect()) {
853 // prepare to get the column order, if available
854 $pmatable = new PMA_Table($GLOBALS['table'], $GLOBALS['db']);
855 $col_order = $pmatable->getUiProp(PMA_Table::PROP_COLUMN_ORDER);
856 $col_visib = $pmatable->getUiProp(PMA_Table::PROP_COLUMN_VISIB);
857 } else {
858 $col_order = false;
859 $col_visib = false;
862 for ($j = 0; $j < $fields_cnt; $j++) {
863 // assign $i with appropriate column order
864 $i = $col_order ? $col_order[$j] : $j;
865 // See if this column should get highlight because it's used in the
866 // where-query.
867 if (isset($highlight_columns[$fields_meta[$i]->name]) || isset($highlight_columns[PMA_backquote($fields_meta[$i]->name)])) {
868 $condition_field = true;
869 } else {
870 $condition_field = false;
873 // 2.0 Prepare comment-HTML-wrappers for each row, if defined/enabled.
874 if (isset($comments_map)
875 && isset($comments_map[$fields_meta[$i]->table])
876 && isset($comments_map[$fields_meta[$i]->table][$fields_meta[$i]->name])
878 $comments = '<span class="tblcomment">' . htmlspecialchars($comments_map[$fields_meta[$i]->table][$fields_meta[$i]->name]) . '</span>';
879 } else {
880 $comments = '';
883 // 2.1 Results can be sorted
884 if ($is_display['sort_lnk'] == '1') {
886 // 2.1.1 Checks if the table name is required; it's the case
887 // for a query with a "JOIN" statement and if the column
888 // isn't aliased, or in queries like
889 // SELECT `1`.`master_field` , `2`.`master_field`
890 // FROM `PMA_relation` AS `1` , `PMA_relation` AS `2`
892 if (isset($fields_meta[$i]->table) && strlen($fields_meta[$i]->table)) {
893 $sort_tbl = PMA_backquote($fields_meta[$i]->table) . '.';
894 } else {
895 $sort_tbl = '';
898 // 2.1.2 Checks if the current column is used to sort the
899 // results
900 // the orgname member does not exist for all MySQL versions
901 // but if found, it's the one on which to sort
902 $name_to_use_in_sort = $fields_meta[$i]->name;
903 $is_orgname = false;
904 if (isset($fields_meta[$i]->orgname) && strlen($fields_meta[$i]->orgname)) {
905 $name_to_use_in_sort = $fields_meta[$i]->orgname;
906 $is_orgname = true;
908 // $name_to_use_in_sort might contain a space due to
909 // formatting of function expressions like "COUNT(name )"
910 // so we remove the space in this situation
911 $name_to_use_in_sort = str_replace(' )', ')', $name_to_use_in_sort);
913 if (empty($sort_expression)) {
914 $is_in_sort = false;
915 } else {
916 // Field name may be preceded by a space, or any number
917 // of characters followed by a dot (tablename.fieldname)
918 // so do a direct comparison for the sort expression;
919 // this avoids problems with queries like
920 // "SELECT id, count(id)..." and clicking to sort
921 // on id or on count(id).
922 // Another query to test this:
923 // SELECT p.*, FROM_UNIXTIME(p.temps) FROM mytable AS p
924 // (and try clicking on each column's header twice)
925 if (! empty($sort_tbl)
926 && strpos($sort_expression_nodirection, $sort_tbl) === false
927 && strpos($sort_expression_nodirection, '(') === false
929 $sort_expression_nodirection = $sort_tbl . $sort_expression_nodirection;
931 $is_in_sort = (str_replace('`', '', $sort_tbl) . $name_to_use_in_sort == str_replace('`', '', $sort_expression_nodirection) ? true : false);
933 // 2.1.3 Check the field name for a bracket.
934 // If it contains one, it's probably a function column
935 // like 'COUNT(`field`)'
936 // It still might be a column name of a view. See bug #3383711
937 // Check is_orgname.
938 if (strpos($name_to_use_in_sort, '(') !== false && ! $is_orgname) {
939 $sort_order = "\n" . 'ORDER BY ' . $name_to_use_in_sort . ' ';
940 } else {
941 $sort_order = "\n" . 'ORDER BY ' . $sort_tbl . PMA_backquote($name_to_use_in_sort) . ' ';
943 unset($name_to_use_in_sort);
944 unset($is_orgname);
946 // 2.1.4 Do define the sorting URL
947 if (! $is_in_sort) {
948 // patch #455484 ("Smart" order)
949 $GLOBALS['cfg']['Order'] = strtoupper($GLOBALS['cfg']['Order']);
950 if ($GLOBALS['cfg']['Order'] === 'SMART') {
951 $sort_order .= (preg_match('@time|date@i', $fields_meta[$i]->type)) ? 'DESC' : 'ASC';
952 } else {
953 $sort_order .= $GLOBALS['cfg']['Order'];
955 $order_img = '';
956 } elseif ('DESC' == $sort_direction) {
957 $sort_order .= ' ASC';
958 $order_img = ' ' . PMA_getImage('s_desc.png', __('Descending'), array('class' => "soimg$i", 'title' => ''));
959 $order_img .= ' ' . PMA_getImage('s_asc.png', __('Ascending'), array('class' => "soimg$i hide", 'title' => ''));
960 } else {
961 $sort_order .= ' DESC';
962 $order_img = ' ' . PMA_getImage('s_asc.png', __('Ascending'), array('class' => "soimg$i", 'title' => ''));
963 $order_img .= ' ' . PMA_getImage('s_desc.png', __('Descending'), array('class' => "soimg$i hide", 'title' => ''));
966 if (preg_match('@(.*)([[:space:]](LIMIT (.*)|PROCEDURE (.*)|FOR UPDATE|LOCK IN SHARE MODE))@is', $unsorted_sql_query, $regs3)) {
967 $sorted_sql_query = $regs3[1] . $sort_order . $regs3[2];
968 } else {
969 $sorted_sql_query = $unsorted_sql_query . $sort_order;
971 $_url_params = array(
972 'db' => $db,
973 'table' => $table,
974 'sql_query' => $sorted_sql_query,
975 'session_max_rows' => $session_max_rows
977 $order_url = 'sql.php' . PMA_generate_common_url($_url_params);
979 // 2.1.5 Displays the sorting URL
980 // enable sort order swapping for image
981 $order_link_params = array();
982 if (isset($order_img) && $order_img!='') {
983 if (strstr($order_img, 'asc')) {
984 $order_link_params['onmouseover'] = "$('.soimg$i').toggle()";
985 $order_link_params['onmouseout'] = "$('.soimg$i').toggle()";
986 } elseif (strstr($order_img, 'desc')) {
987 $order_link_params['onmouseover'] = "$('.soimg$i').toggle()";
988 $order_link_params['onmouseout'] = "$('.soimg$i').toggle()";
991 if ($GLOBALS['cfg']['HeaderFlipType'] == 'auto') {
992 if (PMA_USR_BROWSER_AGENT == 'IE') {
993 $GLOBALS['cfg']['HeaderFlipType'] = 'css';
994 } else {
995 $GLOBALS['cfg']['HeaderFlipType'] = 'fake';
998 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped'
999 && $GLOBALS['cfg']['HeaderFlipType'] == 'css'
1001 $order_link_params['style'] = 'direction: ltr; writing-mode: tb-rl;';
1003 $order_link_params['title'] = __('Sort');
1004 $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));
1005 $order_link = PMA_linkOrButton($order_url, $order_link_content . $order_img, $order_link_params, false, true);
1007 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
1008 || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped'
1010 echo '<th';
1011 $th_class = array();
1012 $th_class[] = 'draggable';
1013 if ($col_visib && !$col_visib[$j]) {
1014 $th_class[] = 'hide';
1016 if ($condition_field) {
1017 $th_class[] = 'condition';
1019 $th_class[] = 'column_heading';
1020 if ($GLOBALS['cfg']['BrowsePointerEnable'] == true) {
1021 $th_class[] = 'pointer';
1023 if ($GLOBALS['cfg']['BrowseMarkerEnable'] == true) {
1024 $th_class[] = 'marker';
1026 echo ' class="' . implode(' ', $th_class) . '"';
1028 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') {
1029 echo ' valign="bottom"';
1031 echo '>' . $order_link . $comments . '</th>';
1033 $vertical_display['desc'][] = ' <th '
1034 . 'class="draggable'
1035 . ($condition_field ? ' condition' : '')
1036 . '">' . "\n"
1037 . $order_link . $comments . ' </th>' . "\n";
1038 } // end if (2.1)
1040 // 2.2 Results can't be sorted
1041 else {
1042 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
1043 || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped'
1045 echo '<th';
1046 $th_class = array();
1047 $th_class[] = 'draggable';
1048 if ($col_visib && !$col_visib[$j]) {
1049 $th_class[] = 'hide';
1051 if ($condition_field) {
1052 $th_class[] = 'condition';
1054 echo ' class="' . implode(' ', $th_class) . '"';
1055 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') {
1056 echo ' valign="bottom"';
1058 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped'
1059 && $GLOBALS['cfg']['HeaderFlipType'] == 'css'
1061 echo ' style="direction: ltr; writing-mode: tb-rl;"';
1063 echo '>';
1064 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped'
1065 && $GLOBALS['cfg']['HeaderFlipType'] == 'fake'
1067 echo PMA_flipstring(htmlspecialchars($fields_meta[$i]->name), '<br />');
1068 } else {
1069 echo htmlspecialchars($fields_meta[$i]->name);
1071 echo "\n" . $comments . '</th>';
1073 $vertical_display['desc'][] = ' <th '
1074 . 'class="draggable'
1075 . ($condition_field ? ' condition"' : '')
1076 . '">' . "\n"
1077 . ' ' . htmlspecialchars($fields_meta[$i]->name) . "\n"
1078 . $comments . ' </th>';
1079 } // end else (2.2)
1080 } // end for
1082 // 3. Displays the needed checkboxes at the right
1083 // column of the result table header if possible and required...
1084 if (($GLOBALS['cfg']['RowActionLinks'] == 'right' || $GLOBALS['cfg']['RowActionLinks'] == 'both')
1085 && ($is_display['edit_lnk'] != 'nn' || $is_display['del_lnk'] != 'nn')
1086 && $is_display['text_btn'] == '1'
1088 $vertical_display['emptyafter'] = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn') ? 4 : 1;
1089 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
1090 || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped'
1092 echo "\n";
1094 <th <?php echo $colspan; ?>><?php echo $full_or_partial_text_link;?>
1095 </th>
1096 <?php
1097 // end horizontal/horizontalflipped mode
1098 } else {
1099 $vertical_display['textbtn'] = ' <th ' . $rowspan . ' valign="middle">' . "\n"
1100 . ' ' . "\n"
1101 . ' </th>' . "\n";
1102 } // end vertical mode
1105 // ... elseif no button, displays empty columns if required
1106 // (unless coming from Browse mode print view)
1107 elseif (($GLOBALS['cfg']['RowActionLinks'] == 'left' || $GLOBALS['cfg']['RowActionLinks'] == 'both')
1108 && ($is_display['edit_lnk'] == 'nn' && $is_display['del_lnk'] == 'nn')
1109 && (! $GLOBALS['is_header_sent'])
1111 $vertical_display['emptyafter'] = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn') ? 4 : 1;
1112 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
1113 || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped'
1115 echo "\n";
1117 <td<?php echo $colspan; ?>></td>
1118 <?php
1119 // end horizontal/horizontalflipped mode
1120 } else {
1121 $vertical_display['textbtn'] = ' <td' . $rowspan . '></td>' . "\n";
1122 } // end vertical mode
1125 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
1126 || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped'
1129 </tr>
1130 </thead>
1131 <?php
1134 return true;
1135 } // end of the 'PMA_displayTableHeaders()' function
1139 * Prepares the display for a value
1141 * @param string $class class of table cell
1142 * @param bool $condition_field whether to add CSS class condition
1143 * @param string $value value to display
1145 * @return string the td
1147 function PMA_buildValueDisplay($class, $condition_field, $value)
1149 return '<td align="left"' . ' class="' . $class . ($condition_field ? ' condition' : '') . '">' . $value . '</td>';
1153 * Prepares the display for a null value
1155 * @param string $class class of table cell
1156 * @param bool $condition_field whether to add CSS class condition
1157 * @param object $meta the meta-information about this field
1158 * @param string $align cell allignment
1160 * @return string the td
1162 function PMA_buildNullDisplay($class, $condition_field, $meta, $align = '')
1164 // the null class is needed for grid editing
1165 return '<td ' . $align . ' class="' . PMA_addClass($class, $condition_field, $meta, '') . ' null"><i>NULL</i></td>';
1169 * Prepares the display for an empty value
1171 * @param string $class class of table cell
1172 * @param bool $condition_field whether to add CSS class condition
1173 * @param object $meta the meta-information about this field
1174 * @param string $align cell allignment
1176 * @return string the td
1178 function PMA_buildEmptyDisplay($class, $condition_field, $meta, $align = '')
1180 $nowrap = ' nowrap';
1181 return '<td ' . $align . ' class="' . PMA_addClass($class, $condition_field, $meta, $nowrap) . '"></td>';
1185 * Adds the relavant classes.
1187 * @param string $class class of table cell
1188 * @param bool $condition_field whether to add CSS class condition
1189 * @param object $meta the meta-information about this field
1190 * @param string $nowrap avoid wrapping
1191 * @param bool $is_field_truncated is field truncated (display ...)
1192 * @param string $transform_function transformation function
1193 * @param string $default_function default transformation function
1195 * @return string the list of classes
1197 function PMA_addClass($class, $condition_field, $meta, $nowrap, $is_field_truncated = false, $transform_function = '', $default_function = '')
1199 // Define classes to be added to this data field based on the type of data
1200 $enum_class = '';
1201 if (strpos($meta->flags, 'enum') !== false) {
1202 $enum_class = ' enum';
1205 $set_class = '';
1206 if (strpos($meta->flags, 'set') !== false) {
1207 $set_class = ' set';
1210 $bit_class = '';
1211 if (strpos($meta->type, 'bit') !== false) {
1212 $bit_class = ' bit';
1215 $mime_type_class = '';
1216 if (isset($meta->mimetype)) {
1217 $mime_type_class = ' ' . preg_replace('/\//', '_', $meta->mimetype);
1220 $result = $class . ($condition_field ? ' condition' : '') . $nowrap
1221 . ' ' . ($is_field_truncated ? ' truncated' : '')
1222 . ($transform_function != $default_function ? ' transformed' : '')
1223 . $enum_class . $set_class . $bit_class . $mime_type_class;
1225 return $result;
1228 * Displays the body of the results table
1230 * @param integer &$dt_result the link id associated to the query which results have
1231 * to be displayed
1232 * @param array &$is_display which elements to display
1233 * @param array $map the list of relations
1234 * @param array $analyzed_sql the analyzed query
1236 * @return boolean always true
1238 * @global string $db the database name
1239 * @global string $table the table name
1240 * @global string $goto the URL to go back in case of errors
1241 * @global string $sql_query the SQL query
1242 * @global array $fields_meta the list of fields properties
1243 * @global integer $fields_cnt the total number of fields returned by
1244 * the SQL query
1245 * @global array $vertical_display informations used with vertical display
1246 * mode
1247 * @global array $highlight_columns column names to highlight
1248 * @global array $row current row data
1250 * @access private
1252 * @see PMA_displayTable()
1254 function PMA_displayTableBody(&$dt_result, &$is_display, $map, $analyzed_sql)
1256 global $db, $table, $goto;
1257 global $sql_query, $fields_meta, $fields_cnt;
1258 global $vertical_display, $highlight_columns;
1259 global $row; // mostly because of browser transformations, to make the row-data accessible in a plugin
1261 $url_sql_query = $sql_query;
1263 // query without conditions to shorten URLs when needed, 200 is just
1264 // guess, it should depend on remaining URL length
1266 if (isset($analyzed_sql)
1267 && isset($analyzed_sql[0])
1268 && isset($analyzed_sql[0]['querytype'])
1269 && $analyzed_sql[0]['querytype'] == 'SELECT'
1270 && strlen($sql_query) > 200
1273 $url_sql_query = 'SELECT ';
1274 if (isset($analyzed_sql[0]['queryflags']['distinct'])) {
1275 $url_sql_query .= ' DISTINCT ';
1277 $url_sql_query .= $analyzed_sql[0]['select_expr_clause'];
1278 if (!empty($analyzed_sql[0]['from_clause'])) {
1279 $url_sql_query .= ' FROM ' . $analyzed_sql[0]['from_clause'];
1283 if (! is_array($map)) {
1284 $map = array();
1286 $row_no = 0;
1287 $vertical_display['edit'] = array();
1288 $vertical_display['copy'] = array();
1289 $vertical_display['delete'] = array();
1290 $vertical_display['data'] = array();
1291 $vertical_display['row_delete'] = array();
1292 // name of the class added to all grid editable elements
1293 $grid_edit_class = 'grid_edit';
1295 // prepare to get the column order, if available
1296 if (PMA_isSelect()) {
1297 $pmatable = new PMA_Table($GLOBALS['table'], $GLOBALS['db']);
1298 $col_order = $pmatable->getUiProp(PMA_Table::PROP_COLUMN_ORDER);
1299 $col_visib = $pmatable->getUiProp(PMA_Table::PROP_COLUMN_VISIB);
1300 } else {
1301 $col_order = false;
1302 $col_visib = false;
1305 // Correction University of Virginia 19991216 in the while below
1306 // Previous code assumed that all tables have keys, specifically that
1307 // the phpMyAdmin GUI should support row delete/edit only for such
1308 // tables.
1309 // Although always using keys is arguably the prescribed way of
1310 // defining a relational table, it is not required. This will in
1311 // particular be violated by the novice.
1312 // We want to encourage phpMyAdmin usage by such novices. So the code
1313 // below has been changed to conditionally work as before when the
1314 // table being displayed has one or more keys; but to display
1315 // delete/edit options correctly for tables without keys.
1317 $odd_row = true;
1318 while ($row = PMA_DBI_fetch_row($dt_result)) {
1319 // "vertical display" mode stuff
1320 if ($row_no != 0 && $_SESSION['tmp_user_values']['repeat_cells'] != 0
1321 && !($row_no % $_SESSION['tmp_user_values']['repeat_cells'])
1322 && ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
1323 || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped')
1325 echo '<tr>' . "\n";
1326 if ($vertical_display['emptypre'] > 0) {
1327 echo ' <th colspan="' . $vertical_display['emptypre'] . '">' . "\n"
1328 .' &nbsp;</th>' . "\n";
1329 } else if ($GLOBALS['cfg']['RowActionLinks'] == 'none') {
1330 echo ' <th></th>' . "\n";
1333 foreach ($vertical_display['desc'] as $val) {
1334 echo $val;
1337 if ($vertical_display['emptyafter'] > 0) {
1338 echo ' <th colspan="' . $vertical_display['emptyafter'] . '">' . "\n"
1339 .' &nbsp;</th>' . "\n";
1341 echo '</tr>' . "\n";
1342 } // end if
1344 $alternating_color_class = ($odd_row ? 'odd' : 'even');
1345 $odd_row = ! $odd_row;
1347 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
1348 || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped'
1350 // pointer code part
1351 echo '<tr class="' . $alternating_color_class . '">';
1355 // 1. Prepares the row
1356 // 1.1 Results from a "SELECT" statement -> builds the
1357 // WHERE clause to use in links (a unique key if possible)
1359 * @todo $where_clause could be empty, for example a table
1360 * with only one field and it's a BLOB; in this case,
1361 * avoid to display the delete and edit links
1363 list($where_clause, $clause_is_unique, $condition_array) = PMA_getUniqueCondition($dt_result, $fields_cnt, $fields_meta, $row);
1364 $where_clause_html = urlencode($where_clause);
1366 // 1.2 Defines the URLs for the modify/delete link(s)
1368 if ($is_display['edit_lnk'] != 'nn' || $is_display['del_lnk'] != 'nn') {
1369 // We need to copy the value or else the == 'both' check will always return true
1371 if ($GLOBALS['cfg']['PropertiesIconic'] === 'both') {
1372 $iconic_spacer = '<div class="nowrap">';
1373 } else {
1374 $iconic_spacer = '';
1377 // 1.2.1 Modify link(s)
1378 if ($is_display['edit_lnk'] == 'ur') { // update row case
1379 $_url_params = array(
1380 'db' => $db,
1381 'table' => $table,
1382 'where_clause' => $where_clause,
1383 'clause_is_unique' => $clause_is_unique,
1384 'sql_query' => $url_sql_query,
1385 'goto' => 'sql.php',
1387 $edit_url = 'tbl_change.php' . PMA_generate_common_url($_url_params + array('default_action' => 'update'));
1388 $copy_url = 'tbl_change.php' . PMA_generate_common_url($_url_params + array('default_action' => 'insert'));
1390 $edit_str = PMA_getIcon('b_edit.png', __('Edit'));
1391 $copy_str = PMA_getIcon('b_insrow.png', __('Copy'));
1393 // Class definitions required for grid editing jQuery scripts
1394 $edit_anchor_class = "edit_row_anchor";
1395 if ( $clause_is_unique == 0) {
1396 $edit_anchor_class .= ' nonunique';
1398 } // end if (1.2.1)
1400 // 1.2.2 Delete/Kill link(s)
1401 if ($is_display['del_lnk'] == 'dr') { // delete row case
1402 $_url_params = array(
1403 'db' => $db,
1404 'table' => $table,
1405 'sql_query' => $url_sql_query,
1406 'message_to_show' => __('The row has been deleted'),
1407 'goto' => (empty($goto) ? 'tbl_sql.php' : $goto),
1409 $lnk_goto = 'sql.php' . PMA_generate_common_url($_url_params, 'text');
1411 $del_query = 'DELETE FROM ' . PMA_backquote($db) . '.' . PMA_backquote($table)
1412 . ' WHERE ' . $where_clause . ($clause_is_unique ? '' : ' LIMIT 1');
1414 $_url_params = array(
1415 'db' => $db,
1416 'table' => $table,
1417 'sql_query' => $del_query,
1418 'message_to_show' => __('The row has been deleted'),
1419 'goto' => $lnk_goto,
1421 $del_url = 'sql.php' . PMA_generate_common_url($_url_params);
1423 $js_conf = 'DELETE FROM ' . PMA_jsFormat($db) . '.' . PMA_jsFormat($table)
1424 . ' WHERE ' . PMA_jsFormat($where_clause, false)
1425 . ($clause_is_unique ? '' : ' LIMIT 1');
1426 $del_str = PMA_getIcon('b_drop.png', __('Delete'));
1427 } elseif ($is_display['del_lnk'] == 'kp') { // kill process case
1429 $_url_params = array(
1430 'db' => $db,
1431 'table' => $table,
1432 'sql_query' => $url_sql_query,
1433 'goto' => 'main.php',
1435 $lnk_goto = 'sql.php' . PMA_generate_common_url($_url_params, 'text');
1437 $_url_params = array(
1438 'db' => 'mysql',
1439 'sql_query' => 'KILL ' . $row[0],
1440 'goto' => $lnk_goto,
1442 $del_url = 'sql.php' . PMA_generate_common_url($_url_params);
1443 $del_query = 'KILL ' . $row[0];
1444 $js_conf = 'KILL ' . $row[0];
1445 $del_str = PMA_getIcon('b_drop.png', __('Kill'));
1446 } // end if (1.2.2)
1448 // 1.3 Displays the links at left if required
1449 if (($GLOBALS['cfg']['RowActionLinks'] == 'left' || $GLOBALS['cfg']['RowActionLinks'] == 'both')
1450 && ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
1451 || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped')
1453 if (! isset($js_conf)) {
1454 $js_conf = '';
1456 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);
1457 } elseif (($GLOBALS['cfg']['RowActionLinks'] == 'none')
1458 && ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
1459 || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped')
1461 if (! isset($js_conf)) {
1462 $js_conf = '';
1464 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);
1465 } // end if (1.3)
1466 } // end if (1)
1468 // 2. Displays the rows' values
1470 for ($j = 0; $j < $fields_cnt; ++$j) {
1471 // assign $i with appropriate column order
1472 $i = $col_order ? $col_order[$j] : $j;
1474 $meta = $fields_meta[$i];
1475 $not_null_class = $meta->not_null ? 'not_null' : '';
1476 $relation_class = isset($map[$meta->name]) ? 'relation' : '';
1477 $hide_class = ($col_visib && !$col_visib[$j] &&
1478 // hide per <td> only if the display direction is not vertical
1479 $_SESSION['tmp_user_values']['disp_direction'] != 'vertical') ? 'hide' : '';
1480 // handle datetime-related class, for grid editing
1481 if (substr($meta->type, 0, 9) == 'timestamp' || $meta->type == 'datetime') {
1482 $field_type_class = 'datetimefield';
1483 } else if ($meta->type == 'date') {
1484 $field_type_class = 'datefield';
1485 } else {
1486 $field_type_class = '';
1488 $pointer = $i;
1489 $is_field_truncated = false;
1490 //If the previous column had blob data, we need to reset the class
1491 // to $inline_edit_class
1492 $class = 'data ' . $grid_edit_class . ' ' . $not_null_class . ' ' . $relation_class . ' ' . $hide_class . ' ' . $field_type_class; //' ' . $alternating_color_class .
1494 // See if this column should get highlight because it's used in the
1495 // where-query.
1496 if (isset($highlight_columns) && (isset($highlight_columns[$meta->name]) || isset($highlight_columns[PMA_backquote($meta->name)]))) {
1497 $condition_field = true;
1498 } else {
1499 $condition_field = false;
1502 if ($_SESSION['tmp_user_values']['disp_direction'] == 'vertical' && (! isset($GLOBALS['printview']) || ($GLOBALS['printview'] != '1'))) {
1503 // the row number corresponds to a data row, not HTML table row
1504 $class .= ' row_' . $row_no;
1505 if ($GLOBALS['cfg']['BrowsePointerEnable'] == true) {
1506 $class .= ' vpointer';
1508 if ($GLOBALS['cfg']['BrowseMarkerEnable'] == true) {
1509 $class .= ' vmarker';
1511 }// end if
1513 // Wrap MIME-transformations. [MIME]
1514 $default_function = 'default_function'; // default_function
1515 $transform_function = $default_function;
1516 $transform_options = array();
1518 if ($GLOBALS['cfgRelation']['mimework'] && $GLOBALS['cfg']['BrowseMIME']) {
1520 if (isset($GLOBALS['mime_map'][$meta->name]['mimetype']) && isset($GLOBALS['mime_map'][$meta->name]['transformation']) && !empty($GLOBALS['mime_map'][$meta->name]['transformation'])) {
1521 $include_file = PMA_securePath($GLOBALS['mime_map'][$meta->name]['transformation']);
1523 if (file_exists('./libraries/transformations/' . $include_file)) {
1524 $transformfunction_name = str_replace('.inc.php', '', $GLOBALS['mime_map'][$meta->name]['transformation']);
1526 include_once './libraries/transformations/' . $include_file;
1528 if (function_exists('PMA_transformation_' . $transformfunction_name)) {
1529 $transform_function = 'PMA_transformation_' . $transformfunction_name;
1530 $transform_options = PMA_transformation_getOptions((isset($GLOBALS['mime_map'][$meta->name]['transformation_options']) ? $GLOBALS['mime_map'][$meta->name]['transformation_options'] : ''));
1531 $meta->mimetype = str_replace('_', '/', $GLOBALS['mime_map'][$meta->name]['mimetype']);
1533 } // end if file_exists
1534 } // end if transformation is set
1535 } // end if mime/transformation works.
1537 $_url_params = array(
1538 'db' => $db,
1539 'table' => $table,
1540 'where_clause' => $where_clause,
1541 'transform_key' => $meta->name,
1544 if (! empty($sql_query)) {
1545 $_url_params['sql_query'] = $url_sql_query;
1548 $transform_options['wrapper_link'] = PMA_generate_common_url($_url_params);
1550 // n u m e r i c
1551 if ($meta->numeric == 1) {
1553 // if two fields have the same name (this is possible
1554 // with self-join queries, for example), using $meta->name
1555 // will show both fields NULL even if only one is NULL,
1556 // so use the $pointer
1558 if (! isset($row[$i]) || is_null($row[$i])) {
1559 $vertical_display['data'][$row_no][$i] = PMA_buildNullDisplay($class, $condition_field, $meta, 'align="right"');
1560 } elseif ($row[$i] != '') {
1562 $nowrap = ' nowrap';
1563 $where_comparison = ' = ' . $row[$i];
1565 $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);
1566 } else {
1567 $vertical_display['data'][$row_no][$i] = PMA_buildEmptyDisplay($class, $condition_field, $meta, 'align="right"');
1570 // b l o b
1572 } elseif (stristr($meta->type, 'BLOB')) {
1573 // PMA_mysql_fetch_fields returns BLOB in place of
1574 // TEXT fields type so we have to ensure it's really a BLOB
1575 $field_flags = PMA_DBI_field_flags($dt_result, $i);
1577 if (stristr($field_flags, 'BINARY')) {
1578 // remove 'grid_edit' from $class as we can't edit binary data.
1579 $class = str_replace('grid_edit', '', $class);
1581 if (! isset($row[$i]) || is_null($row[$i])) {
1582 $vertical_display['data'][$row_no][$i] = PMA_buildNullDisplay($class, $condition_field, $meta);
1583 } else {
1584 // for blobstreaming
1585 // if valid BS reference exists
1586 if (PMA_BS_IsPBMSReference($row[$i], $db)) {
1587 $blobtext = PMA_BS_CreateReferenceLink($row[$i], $db);
1588 } else {
1589 $blobtext = PMA_handle_non_printable_contents('BLOB', (isset($row[$i]) ? $row[$i] : ''), $transform_function, $transform_options, $default_function, $meta, $_url_params);
1592 $vertical_display['data'][$row_no][$i] = PMA_buildValueDisplay($class, $condition_field, $blobtext);
1593 unset($blobtext);
1595 // not binary:
1596 } else {
1597 if (! isset($row[$i]) || is_null($row[$i])) {
1598 $vertical_display['data'][$row_no][$i] = PMA_buildNullDisplay($class, $condition_field, $meta);
1599 } elseif ($row[$i] != '') {
1600 // if a transform function for blob is set, none of these replacements will be made
1601 if (PMA_strlen($row[$i]) > $GLOBALS['cfg']['LimitChars'] && $_SESSION['tmp_user_values']['display_text'] == 'P') {
1602 $row[$i] = PMA_substr($row[$i], 0, $GLOBALS['cfg']['LimitChars']) . '...';
1603 $is_field_truncated = true;
1605 // displays all space characters, 4 space
1606 // characters for tabulations and <cr>/<lf>
1607 $row[$i] = ($default_function != $transform_function ? $transform_function($row[$i], $transform_options, $meta) : $default_function($row[$i], array(), $meta));
1609 if ($is_field_truncated) {
1610 $class .= ' truncated';
1613 $vertical_display['data'][$row_no][$i] = PMA_buildValueDisplay($class, $condition_field, $row[$i]);
1614 } else {
1615 $vertical_display['data'][$row_no][$i] = PMA_buildEmptyDisplay($class, $condition_field, $meta);
1618 // g e o m e t r y
1619 } elseif ($meta->type == 'geometry') {
1621 // Remove 'grid_edit' from $class as we do not allow to inline-edit geometry data.
1622 $class = str_replace('grid_edit', '', $class);
1624 if (! isset($row[$i]) || is_null($row[$i])) {
1625 $vertical_display['data'][$row_no][$i] = PMA_buildNullDisplay($class, $condition_field, $meta);
1626 } elseif ($row[$i] != '') {
1627 // Display as [GEOMETRY - (size)]
1628 if ('GEOM' == $_SESSION['tmp_user_values']['geometry_display']) {
1629 $geometry_text = PMA_handle_non_printable_contents(
1630 'GEOMETRY', (isset($row[$i]) ? $row[$i] : ''), $transform_function,
1631 $transform_options, $default_function, $meta
1633 $vertical_display['data'][$row_no][$i] = PMA_buildValueDisplay(
1634 $class, $condition_field, $geometry_text
1637 // Display in Well Known Text(WKT) format.
1638 } elseif ('WKT' == $_SESSION['tmp_user_values']['geometry_display']) {
1639 $where_comparison = ' = ' . $row[$i];
1641 // Convert to WKT format
1642 $wktval = PMA_asWKT($row[$i]);
1644 if (PMA_strlen($wktval) > $GLOBALS['cfg']['LimitChars']
1645 && $_SESSION['tmp_user_values']['display_text'] == 'P'
1647 $wktval = PMA_substr($wktval, 0, $GLOBALS['cfg']['LimitChars']) . '...';
1648 $is_field_truncated = true;
1651 $vertical_display['data'][$row_no][$i] = '<td ' . PMA_prepare_row_data(
1652 $class, $condition_field, $analyzed_sql, $meta, $map, $wktval, $transform_function,
1653 $default_function, '', $where_comparison, $transform_options, $is_field_truncated
1656 // Display in Well Known Binary(WKB) format.
1657 } else {
1658 if ($_SESSION['tmp_user_values']['display_binary']) {
1659 $where_comparison = ' = ' . $row[$i];
1661 if ($_SESSION['tmp_user_values']['display_binary_as_hex']
1662 && PMA_contains_nonprintable_ascii($row[$i])
1664 $wkbval = PMA_substr(bin2hex($row[$i]), 8);
1665 } else {
1666 $wkbval = htmlspecialchars(PMA_replace_binary_contents($row[$i]));
1669 if (PMA_strlen($wkbval) > $GLOBALS['cfg']['LimitChars']
1670 && $_SESSION['tmp_user_values']['display_text'] == 'P'
1672 $wkbval = PMA_substr($wkbval, 0, $GLOBALS['cfg']['LimitChars']) . '...';
1673 $is_field_truncated = true;
1676 $vertical_display['data'][$row_no][$i] = '<td ' . PMA_prepare_row_data(
1677 $class, $condition_field, $analyzed_sql, $meta, $map, $wkbval, $transform_function,
1678 $default_function, '', $where_comparison, $transform_options, $is_field_truncated
1680 } else {
1681 $wkbval = PMA_handle_non_printable_contents(
1682 'BINARY', $row[$i], $transform_function, $transform_options, $default_function, $meta, $_url_params
1684 $vertical_display['data'][$row_no][$i] = PMA_buildValueDisplay($class, $condition_field, $wkbval);
1687 } else {
1688 $vertical_display['data'][$row_no][$i] = PMA_buildEmptyDisplay($class, $condition_field, $meta);
1691 // n o t n u m e r i c a n d n o t B L O B
1692 } else {
1693 if (! isset($row[$i]) || is_null($row[$i])) {
1694 $vertical_display['data'][$row_no][$i] = PMA_buildNullDisplay($class, $condition_field, $meta);
1695 } elseif ($row[$i] != '') {
1696 // support blanks in the key
1697 $relation_id = $row[$i];
1699 // Cut all fields to $GLOBALS['cfg']['LimitChars']
1700 // (unless it's a link-type transformation)
1701 if (PMA_strlen($row[$i]) > $GLOBALS['cfg']['LimitChars'] && $_SESSION['tmp_user_values']['display_text'] == 'P' && !strpos($transform_function, 'link') === true) {
1702 $row[$i] = PMA_substr($row[$i], 0, $GLOBALS['cfg']['LimitChars']) . '...';
1703 $is_field_truncated = true;
1706 // displays special characters from binaries
1707 $field_flags = PMA_DBI_field_flags($dt_result, $i);
1708 $formatted = false;
1709 if (isset($meta->_type) && $meta->_type === MYSQLI_TYPE_BIT) {
1710 $row[$i] = PMA_printable_bit_value($row[$i], $meta->length);
1711 // some results of PROCEDURE ANALYSE() are reported as
1712 // being BINARY but they are quite readable,
1713 // so don't treat them as BINARY
1714 } elseif (stristr($field_flags, 'BINARY') && $meta->type == 'string' && !(isset($GLOBALS['is_analyse']) && $GLOBALS['is_analyse'])) {
1715 if ($_SESSION['tmp_user_values']['display_binary']) {
1716 // user asked to see the real contents of BINARY
1717 // fields
1718 if ($_SESSION['tmp_user_values']['display_binary_as_hex'] && PMA_contains_nonprintable_ascii($row[$i])) {
1719 $row[$i] = bin2hex($row[$i]);
1720 } else {
1721 $row[$i] = htmlspecialchars(PMA_replace_binary_contents($row[$i]));
1723 } else {
1724 // we show the BINARY message and field's size
1725 // (or maybe use a transformation)
1726 $row[$i] = PMA_handle_non_printable_contents('BINARY', $row[$i], $transform_function, $transform_options, $default_function, $meta, $_url_params);
1727 $formatted = true;
1731 if ($formatted) {
1732 $vertical_display['data'][$row_no][$i] = PMA_buildValueDisplay($class, $condition_field, $row[$i]);
1733 } else {
1734 // transform functions may enable no-wrapping:
1735 $function_nowrap = $transform_function . '_nowrap';
1736 $bool_nowrap = (($default_function != $transform_function && function_exists($function_nowrap)) ? $function_nowrap($transform_options) : false);
1738 // do not wrap if date field type
1739 $nowrap = ((preg_match('@DATE|TIME@i', $meta->type) || $bool_nowrap) ? ' nowrap' : '');
1740 $where_comparison = ' = \'' . PMA_sqlAddSlashes($row[$i]) . '\'';
1741 $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);
1743 } else {
1744 $vertical_display['data'][$row_no][$i] = PMA_buildEmptyDisplay($class, $condition_field, $meta);
1748 // output stored cell
1749 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
1750 || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped'
1752 echo $vertical_display['data'][$row_no][$i];
1755 if (isset($vertical_display['rowdata'][$i][$row_no])) {
1756 $vertical_display['rowdata'][$i][$row_no] .= $vertical_display['data'][$row_no][$i];
1757 } else {
1758 $vertical_display['rowdata'][$i][$row_no] = $vertical_display['data'][$row_no][$i];
1760 } // end for (2)
1762 // 3. Displays the modify/delete links on the right if required
1763 if (($GLOBALS['cfg']['RowActionLinks'] == 'right' || $GLOBALS['cfg']['RowActionLinks'] == 'both')
1764 && ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
1765 || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped')
1767 if (! isset($js_conf)) {
1768 $js_conf = '';
1770 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);
1771 } // end if (3)
1773 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
1774 || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped'
1777 </tr>
1778 <?php
1779 } // end if
1781 // 4. Gather links of del_urls and edit_urls in an array for later
1782 // output
1783 if (! isset($vertical_display['edit'][$row_no])) {
1784 $vertical_display['edit'][$row_no] = '';
1785 $vertical_display['copy'][$row_no] = '';
1786 $vertical_display['delete'][$row_no] = '';
1787 $vertical_display['row_delete'][$row_no] = '';
1789 $vertical_class = ' row_' . $row_no;
1790 if ($GLOBALS['cfg']['BrowsePointerEnable'] == true) {
1791 $vertical_class .= ' vpointer';
1793 if ($GLOBALS['cfg']['BrowseMarkerEnable'] == true) {
1794 $vertical_class .= ' vmarker';
1797 if (!empty($del_url) && $is_display['del_lnk'] != 'kp') {
1798 $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);
1799 } else {
1800 unset($vertical_display['row_delete'][$row_no]);
1803 if (isset($edit_url)) {
1804 $vertical_display['edit'][$row_no] .= PMA_generateEditLink($edit_url, $alternating_color_class . ' ' . $edit_anchor_class . $vertical_class, $edit_str, $where_clause, $where_clause_html);
1805 } else {
1806 unset($vertical_display['edit'][$row_no]);
1809 if (isset($copy_url)) {
1810 $vertical_display['copy'][$row_no] .= PMA_generateCopyLink($copy_url, $copy_str, $where_clause, $where_clause_html, $alternating_color_class . $vertical_class);
1811 } else {
1812 unset($vertical_display['copy'][$row_no]);
1815 if (isset($del_url)) {
1816 if (! isset($js_conf)) {
1817 $js_conf = '';
1819 $vertical_display['delete'][$row_no] .= PMA_generateDeleteLink($del_url, $del_str, $js_conf, $alternating_color_class . $vertical_class);
1820 } else {
1821 unset($vertical_display['delete'][$row_no]);
1824 echo (($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal' || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') ? "\n" : '');
1825 $row_no++;
1826 } // end while
1828 // this is needed by PMA_displayTable() to generate the proper param
1829 // in the multi-edit and multi-delete form
1830 return $clause_is_unique;
1831 } // end of the 'PMA_displayTableBody()' function
1835 * Do display the result table with the vertical direction mode.
1837 * @return boolean always true
1839 * @global array $vertical_display the information to display
1841 * @access private
1843 * @see PMA_displayTable()
1845 function PMA_displayVerticalTable()
1847 global $vertical_display;
1849 // Displays "multi row delete" link at top if required
1850 if ($GLOBALS['cfg']['RowActionLinks'] != 'right'
1851 && is_array($vertical_display['row_delete'])
1852 && (count($vertical_display['row_delete']) > 0 || !empty($vertical_display['textbtn']))
1854 echo '<tr>' . "\n";
1855 if ($GLOBALS['cfg']['RowActionLinks'] == 'none') {
1856 // if we are not showing the RowActionLinks, then we need to show the Multi-Row-Action checkboxes
1857 echo '<th></th>' . "\n";
1859 echo $vertical_display['textbtn'];
1860 $cell_displayed = 0;
1861 foreach ($vertical_display['row_delete'] as $val) {
1862 if (($cell_displayed != 0) && ($_SESSION['tmp_user_values']['repeat_cells'] != 0) && !($cell_displayed % $_SESSION['tmp_user_values']['repeat_cells'])) {
1863 echo '<th' .
1864 (($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn') ? ' rowspan="4"' : '') .
1865 '></th>' . "\n";
1867 echo str_replace('[%_PMA_CHECKBOX_DIR_%]', '_left', $val);
1868 $cell_displayed++;
1869 } // end while
1870 echo '</tr>' . "\n";
1871 } // end if
1873 // Displays "edit" link at top if required
1874 if (($GLOBALS['cfg']['RowActionLinks'] == 'left' || $GLOBALS['cfg']['RowActionLinks'] == 'both')
1875 && is_array($vertical_display['edit'])
1876 && (count($vertical_display['edit']) > 0 || !empty($vertical_display['textbtn']))
1878 echo '<tr>' . "\n";
1879 if (! is_array($vertical_display['row_delete'])) {
1880 echo $vertical_display['textbtn'];
1882 foreach ($vertical_display['edit'] as $val) {
1883 echo $val;
1884 } // end while
1885 echo '</tr>' . "\n";
1886 } // end if
1888 // Displays "copy" link at top if required
1889 if (($GLOBALS['cfg']['RowActionLinks'] == 'left' || $GLOBALS['cfg']['RowActionLinks'] == 'both')
1890 && is_array($vertical_display['copy'])
1891 && (count($vertical_display['copy']) > 0 || !empty($vertical_display['textbtn']))
1893 echo '<tr>' . "\n";
1894 if (! is_array($vertical_display['row_delete'])) {
1895 echo $vertical_display['textbtn'];
1897 foreach ($vertical_display['copy'] as $val) {
1898 echo $val;
1899 } // end while
1900 echo '</tr>' . "\n";
1901 } // end if
1903 // Displays "delete" link at top if required
1904 if (($GLOBALS['cfg']['RowActionLinks'] == 'left' || $GLOBALS['cfg']['RowActionLinks'] == 'both')
1905 && is_array($vertical_display['delete'])
1906 && (count($vertical_display['delete']) > 0 || !empty($vertical_display['textbtn']))
1908 echo '<tr>' . "\n";
1909 if (! is_array($vertical_display['edit']) && ! is_array($vertical_display['row_delete'])) {
1910 echo $vertical_display['textbtn'];
1912 foreach ($vertical_display['delete'] as $val) {
1913 echo $val;
1914 } // end while
1915 echo '</tr>' . "\n";
1916 } // end if
1918 if (PMA_isSelect()) {
1919 // prepare to get the column order, if available
1920 $pmatable = new PMA_Table($GLOBALS['table'], $GLOBALS['db']);
1921 $col_order = $pmatable->getUiProp(PMA_Table::PROP_COLUMN_ORDER);
1922 $col_visib = $pmatable->getUiProp(PMA_Table::PROP_COLUMN_VISIB);
1923 } else {
1924 $col_order = false;
1925 $col_visib = false;
1928 // Displays data
1929 foreach ($vertical_display['desc'] AS $j => $val) {
1930 // assign appropriate key with current column order
1931 $key = $col_order ? $col_order[$j] : $j;
1933 echo '<tr' . (($col_visib && !$col_visib[$j]) ? ' class="hide"' : '') . '>' . "\n";
1934 echo $val;
1936 $cell_displayed = 0;
1937 foreach ($vertical_display['rowdata'][$key] as $subval) {
1938 if (($cell_displayed != 0) && ($_SESSION['tmp_user_values']['repeat_cells'] != 0) and !($cell_displayed % $_SESSION['tmp_user_values']['repeat_cells'])) {
1939 echo $val;
1942 echo $subval;
1943 $cell_displayed++;
1944 } // end while
1946 echo '</tr>' . "\n";
1947 } // end while
1949 // Displays "multi row delete" link at bottom if required
1950 if (($GLOBALS['cfg']['RowActionLinks'] == 'right' || $GLOBALS['cfg']['RowActionLinks'] == 'both')
1951 && is_array($vertical_display['row_delete'])
1952 && (count($vertical_display['row_delete']) > 0 || !empty($vertical_display['textbtn']))
1954 echo '<tr>' . "\n";
1955 echo $vertical_display['textbtn'];
1956 $cell_displayed = 0;
1957 foreach ($vertical_display['row_delete'] as $val) {
1958 if (($cell_displayed != 0) && ($_SESSION['tmp_user_values']['repeat_cells'] != 0) && !($cell_displayed % $_SESSION['tmp_user_values']['repeat_cells'])) {
1959 echo '<th' .
1960 (($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn') ? ' rowspan="4"' : '') .
1961 '></th>' . "\n";
1964 echo str_replace('[%_PMA_CHECKBOX_DIR_%]', '_right', $val);
1965 $cell_displayed++;
1966 } // end while
1967 echo '</tr>' . "\n";
1968 } // end if
1970 // Displays "edit" link at bottom if required
1971 if (($GLOBALS['cfg']['RowActionLinks'] == 'right' || $GLOBALS['cfg']['RowActionLinks'] == 'both')
1972 && is_array($vertical_display['edit'])
1973 && (count($vertical_display['edit']) > 0 || !empty($vertical_display['textbtn']))
1975 echo '<tr>' . "\n";
1976 if (! is_array($vertical_display['row_delete'])) {
1977 echo $vertical_display['textbtn'];
1979 foreach ($vertical_display['edit'] as $val) {
1980 echo $val;
1981 } // end while
1982 echo '</tr>' . "\n";
1983 } // end if
1985 // Displays "copy" link at bottom if required
1986 if (($GLOBALS['cfg']['RowActionLinks'] == 'right' || $GLOBALS['cfg']['RowActionLinks'] == 'both')
1987 && is_array($vertical_display['copy'])
1988 && (count($vertical_display['copy']) > 0 || !empty($vertical_display['textbtn']))
1990 echo '<tr>' . "\n";
1991 if (! is_array($vertical_display['row_delete'])) {
1992 echo $vertical_display['textbtn'];
1994 foreach ($vertical_display['copy'] as $val) {
1995 echo $val;
1996 } // end while
1997 echo '</tr>' . "\n";
1998 } // end if
2000 // Displays "delete" link at bottom if required
2001 if (($GLOBALS['cfg']['RowActionLinks'] == 'right' || $GLOBALS['cfg']['RowActionLinks'] == 'both')
2002 && is_array($vertical_display['delete'])
2003 && (count($vertical_display['delete']) > 0 || !empty($vertical_display['textbtn']))
2005 echo '<tr>' . "\n";
2006 if (! is_array($vertical_display['edit']) && ! is_array($vertical_display['row_delete'])) {
2007 echo $vertical_display['textbtn'];
2009 foreach ($vertical_display['delete'] as $val) {
2010 echo $val;
2011 } // end while
2012 echo '</tr>' . "\n";
2015 return true;
2016 } // end of the 'PMA_displayVerticalTable' function
2019 * Checks the posted options for viewing query resutls
2020 * and sets appropriate values in the session.
2022 * @todo make maximum remembered queries configurable
2023 * @todo move/split into SQL class!?
2024 * @todo currently this is called twice unnecessary
2025 * @todo ignore LIMIT and ORDER in query!?
2027 * @return nothing
2029 function PMA_displayTable_checkConfigParams()
2031 $sql_md5 = md5($GLOBALS['sql_query']);
2033 $_SESSION['tmp_user_values']['query'][$sql_md5]['sql'] = $GLOBALS['sql_query'];
2035 if (PMA_isValid($_REQUEST['disp_direction'], array('horizontal', 'vertical', 'horizontalflipped'))) {
2036 $_SESSION['tmp_user_values']['query'][$sql_md5]['disp_direction'] = $_REQUEST['disp_direction'];
2037 unset($_REQUEST['disp_direction']);
2038 } elseif (empty($_SESSION['tmp_user_values']['query'][$sql_md5]['disp_direction'])) {
2039 $_SESSION['tmp_user_values']['query'][$sql_md5]['disp_direction'] = $GLOBALS['cfg']['DefaultDisplay'];
2042 if (PMA_isValid($_REQUEST['repeat_cells'], 'numeric')) {
2043 $_SESSION['tmp_user_values']['query'][$sql_md5]['repeat_cells'] = $_REQUEST['repeat_cells'];
2044 unset($_REQUEST['repeat_cells']);
2045 } elseif (empty($_SESSION['tmp_user_values']['query'][$sql_md5]['repeat_cells'])) {
2046 $_SESSION['tmp_user_values']['query'][$sql_md5]['repeat_cells'] = $GLOBALS['cfg']['RepeatCells'];
2049 // as this is a form value, the type is always string so we cannot
2050 // use PMA_isValid($_REQUEST['session_max_rows'], 'integer')
2051 if ((PMA_isValid($_REQUEST['session_max_rows'], 'numeric')
2052 && (int) $_REQUEST['session_max_rows'] == $_REQUEST['session_max_rows'])
2053 || $_REQUEST['session_max_rows'] == 'all'
2055 $_SESSION['tmp_user_values']['query'][$sql_md5]['max_rows'] = $_REQUEST['session_max_rows'];
2056 unset($_REQUEST['session_max_rows']);
2057 } elseif (empty($_SESSION['tmp_user_values']['query'][$sql_md5]['max_rows'])) {
2058 $_SESSION['tmp_user_values']['query'][$sql_md5]['max_rows'] = $GLOBALS['cfg']['MaxRows'];
2061 if (PMA_isValid($_REQUEST['pos'], 'numeric')) {
2062 $_SESSION['tmp_user_values']['query'][$sql_md5]['pos'] = $_REQUEST['pos'];
2063 unset($_REQUEST['pos']);
2064 } elseif (empty($_SESSION['tmp_user_values']['query'][$sql_md5]['pos'])) {
2065 $_SESSION['tmp_user_values']['query'][$sql_md5]['pos'] = 0;
2068 if (PMA_isValid($_REQUEST['display_text'], array('P', 'F'))) {
2069 $_SESSION['tmp_user_values']['query'][$sql_md5]['display_text'] = $_REQUEST['display_text'];
2070 unset($_REQUEST['display_text']);
2071 } elseif (empty($_SESSION['tmp_user_values']['query'][$sql_md5]['display_text'])) {
2072 $_SESSION['tmp_user_values']['query'][$sql_md5]['display_text'] = 'P';
2075 if (PMA_isValid($_REQUEST['relational_display'], array('K', 'D'))) {
2076 $_SESSION['tmp_user_values']['query'][$sql_md5]['relational_display'] = $_REQUEST['relational_display'];
2077 unset($_REQUEST['relational_display']);
2078 } elseif (empty($_SESSION['tmp_user_values']['query'][$sql_md5]['relational_display'])) {
2079 $_SESSION['tmp_user_values']['query'][$sql_md5]['relational_display'] = 'K';
2082 if (PMA_isValid($_REQUEST['geometry_display'], array('WKT', 'WKB', 'GEOM'))) {
2083 $_SESSION['tmp_user_values']['query'][$sql_md5]['geometry_display'] = $_REQUEST['geometry_display'];
2084 unset($_REQUEST['geometry_display']);
2085 } elseif (empty($_SESSION['tmp_user_values']['query'][$sql_md5]['geometry_display'])) {
2086 $_SESSION['tmp_user_values']['query'][$sql_md5]['geometry_display'] = 'GEOM';
2089 if (isset($_REQUEST['display_binary'])) {
2090 $_SESSION['tmp_user_values']['query'][$sql_md5]['display_binary'] = true;
2091 unset($_REQUEST['display_binary']);
2092 } elseif (isset($_REQUEST['display_options_form'])) {
2093 // we know that the checkbox was unchecked
2094 unset($_SESSION['tmp_user_values']['query'][$sql_md5]['display_binary']);
2095 } elseif (isset($_REQUEST['full_text_button'])) {
2096 // do nothing to keep the value that is there in the session
2097 } else {
2098 // selected by default because some operations like OPTIMIZE TABLE
2099 // and all queries involving functions return "binary" contents,
2100 // according to low-level field flags
2101 $_SESSION['tmp_user_values']['query'][$sql_md5]['display_binary'] = true;
2104 if (isset($_REQUEST['display_binary_as_hex'])) {
2105 $_SESSION['tmp_user_values']['query'][$sql_md5]['display_binary_as_hex'] = true;
2106 unset($_REQUEST['display_binary_as_hex']);
2107 } elseif (isset($_REQUEST['display_options_form'])) {
2108 // we know that the checkbox was unchecked
2109 unset($_SESSION['tmp_user_values']['query'][$sql_md5]['display_binary_as_hex']);
2110 } elseif (isset($_REQUEST['full_text_button'])) {
2111 // do nothing to keep the value that is there in the session
2112 } else {
2113 // display_binary_as_hex config option
2114 if (isset($GLOBALS['cfg']['DisplayBinaryAsHex']) && true === $GLOBALS['cfg']['DisplayBinaryAsHex']) {
2115 $_SESSION['tmp_user_values']['query'][$sql_md5]['display_binary_as_hex'] = true;
2119 if (isset($_REQUEST['display_blob'])) {
2120 $_SESSION['tmp_user_values']['query'][$sql_md5]['display_blob'] = true;
2121 unset($_REQUEST['display_blob']);
2122 } elseif (isset($_REQUEST['display_options_form'])) {
2123 // we know that the checkbox was unchecked
2124 unset($_SESSION['tmp_user_values']['query'][$sql_md5]['display_blob']);
2127 if (isset($_REQUEST['hide_transformation'])) {
2128 $_SESSION['tmp_user_values']['query'][$sql_md5]['hide_transformation'] = true;
2129 unset($_REQUEST['hide_transformation']);
2130 } elseif (isset($_REQUEST['display_options_form'])) {
2131 // we know that the checkbox was unchecked
2132 unset($_SESSION['tmp_user_values']['query'][$sql_md5]['hide_transformation']);
2135 // move current query to the last position, to be removed last
2136 // so only least executed query will be removed if maximum remembered queries
2137 // limit is reached
2138 $tmp = $_SESSION['tmp_user_values']['query'][$sql_md5];
2139 unset($_SESSION['tmp_user_values']['query'][$sql_md5]);
2140 $_SESSION['tmp_user_values']['query'][$sql_md5] = $tmp;
2142 // do not exceed a maximum number of queries to remember
2143 if (count($_SESSION['tmp_user_values']['query']) > 10) {
2144 array_shift($_SESSION['tmp_user_values']['query']);
2145 //echo 'deleting one element ...';
2148 // populate query configuration
2149 $_SESSION['tmp_user_values']['display_text'] = $_SESSION['tmp_user_values']['query'][$sql_md5]['display_text'];
2150 $_SESSION['tmp_user_values']['relational_display'] = $_SESSION['tmp_user_values']['query'][$sql_md5]['relational_display'];
2151 $_SESSION['tmp_user_values']['geometry_display'] = $_SESSION['tmp_user_values']['query'][$sql_md5]['geometry_display'];
2152 $_SESSION['tmp_user_values']['display_binary'] = isset($_SESSION['tmp_user_values']['query'][$sql_md5]['display_binary']) ? true : false;
2153 $_SESSION['tmp_user_values']['display_binary_as_hex'] = isset($_SESSION['tmp_user_values']['query'][$sql_md5]['display_binary_as_hex']) ? true : false;
2154 $_SESSION['tmp_user_values']['display_blob'] = isset($_SESSION['tmp_user_values']['query'][$sql_md5]['display_blob']) ? true : false;
2155 $_SESSION['tmp_user_values']['hide_transformation'] = isset($_SESSION['tmp_user_values']['query'][$sql_md5]['hide_transformation']) ? true : false;
2156 $_SESSION['tmp_user_values']['pos'] = $_SESSION['tmp_user_values']['query'][$sql_md5]['pos'];
2157 $_SESSION['tmp_user_values']['max_rows'] = $_SESSION['tmp_user_values']['query'][$sql_md5]['max_rows'];
2158 $_SESSION['tmp_user_values']['repeat_cells'] = $_SESSION['tmp_user_values']['query'][$sql_md5]['repeat_cells'];
2159 $_SESSION['tmp_user_values']['disp_direction'] = $_SESSION['tmp_user_values']['query'][$sql_md5]['disp_direction'];
2162 * debugging
2163 echo '<pre>';
2164 var_dump($_SESSION['tmp_user_values']);
2165 echo '</pre>';
2170 * Displays a table of results returned by a SQL query.
2171 * This function is called by the "sql.php" script.
2173 * @param integer &$dt_result the link id associated to the query which results have
2174 * to be displayed
2175 * @param array &$the_disp_mode the display mode
2176 * @param array $analyzed_sql the analyzed query
2178 * @global string $db the database name
2179 * @global string $table the table name
2180 * @global string $goto the URL to go back in case of errors
2181 * @global string $sql_query the current SQL query
2182 * @global integer $num_rows the total number of rows returned by the
2183 * SQL query
2184 * @global integer $unlim_num_rows the total number of rows returned by the
2185 * SQL query without any programmatically
2186 * appended "LIMIT" clause
2187 * @global array $fields_meta the list of fields properties
2188 * @global integer $fields_cnt the total number of fields returned by
2189 * the SQL query
2190 * @global array $vertical_display informations used with vertical display
2191 * mode
2192 * @global array $highlight_columns column names to highlight
2193 * @global array $cfgRelation the relation settings
2194 * @global array $showtable table definitions
2196 * @access private
2198 * @see PMA_showMessage(), PMA_setDisplayMode(),
2199 * PMA_displayTableNavigation(), PMA_displayTableHeaders(),
2200 * PMA_displayTableBody(), PMA_displayResultsOperations()
2202 * @return nothing
2204 function PMA_displayTable(&$dt_result, &$the_disp_mode, $analyzed_sql)
2206 global $db, $table, $goto;
2207 global $sql_query, $num_rows, $unlim_num_rows, $fields_meta, $fields_cnt;
2208 global $vertical_display, $highlight_columns;
2209 global $cfgRelation;
2210 global $showtable;
2212 // why was this called here? (already called from sql.php)
2213 //PMA_displayTable_checkConfigParams();
2216 * @todo move this to a central place
2217 * @todo for other future table types
2219 $is_innodb = (isset($showtable['Type']) && $showtable['Type'] == 'InnoDB');
2221 if ($is_innodb
2222 && ! isset($analyzed_sql[0]['queryflags']['union'])
2223 && ! isset($analyzed_sql[0]['table_ref'][1]['table_name'])
2224 && (empty($analyzed_sql[0]['where_clause']) || $analyzed_sql[0]['where_clause'] == '1 ')
2226 // "j u s t b r o w s i n g"
2227 $pre_count = '~';
2228 $after_count = PMA_showHint(PMA_sanitize(__('May be approximate. See [a@./Documentation.html#faq3_11@Documentation]FAQ 3.11[/a]')));
2229 } else {
2230 $pre_count = '';
2231 $after_count = '';
2234 // 1. ----- Prepares the work -----
2236 // 1.1 Gets the informations about which functionalities should be
2237 // displayed
2238 $total = '';
2239 $is_display = PMA_setDisplayMode($the_disp_mode, $total);
2241 // 1.2 Defines offsets for the next and previous pages
2242 if ($is_display['nav_bar'] == '1') {
2243 if ($_SESSION['tmp_user_values']['max_rows'] == 'all') {
2244 $pos_next = 0;
2245 $pos_prev = 0;
2246 } else {
2247 $pos_next = $_SESSION['tmp_user_values']['pos'] + $_SESSION['tmp_user_values']['max_rows'];
2248 $pos_prev = $_SESSION['tmp_user_values']['pos'] - $_SESSION['tmp_user_values']['max_rows'];
2249 if ($pos_prev < 0) {
2250 $pos_prev = 0;
2253 } // end if
2255 // 1.3 Find the sort expression
2257 // we need $sort_expression and $sort_expression_nodirection
2258 // even if there are many table references
2259 if (! empty($analyzed_sql[0]['order_by_clause'])) {
2260 $sort_expression = trim(str_replace(' ', ' ', $analyzed_sql[0]['order_by_clause']));
2262 * Get rid of ASC|DESC
2264 preg_match('@(.*)([[:space:]]*(ASC|DESC))@si', $sort_expression, $matches);
2265 $sort_expression_nodirection = isset($matches[1]) ? trim($matches[1]) : $sort_expression;
2266 $sort_direction = isset($matches[2]) ? trim($matches[2]) : '';
2267 unset($matches);
2268 } else {
2269 $sort_expression = $sort_expression_nodirection = $sort_direction = '';
2272 // 1.4 Prepares display of first and last value of the sorted column
2274 if (! empty($sort_expression_nodirection)) {
2275 if (strpos($sort_expression_nodirection, '.') === false) {
2276 $sort_table = $table;
2277 $sort_column = $sort_expression_nodirection;
2278 } else {
2279 list($sort_table, $sort_column) = explode('.', $sort_expression_nodirection);
2281 $sort_table = PMA_unQuote($sort_table);
2282 $sort_column = PMA_unQuote($sort_column);
2283 // find the sorted column index in row result
2284 // (this might be a multi-table query)
2285 $sorted_column_index = false;
2286 foreach ($fields_meta as $key => $meta) {
2287 if ($meta->table == $sort_table && $meta->name == $sort_column) {
2288 $sorted_column_index = $key;
2289 break;
2292 if ($sorted_column_index !== false) {
2293 // fetch first row of the result set
2294 $row = PMA_DBI_fetch_row($dt_result);
2295 // initializing default arguments
2296 $default_function = 'default_function';
2297 $transform_function = $default_function;
2298 $transform_options = array();
2299 // check for non printable sorted row data
2300 $meta = $fields_meta[$sorted_column_index];
2301 if (stristr($meta->type, 'BLOB') || $meta->type == 'geometry') {
2302 $column_for_first_row = PMA_handle_non_printable_contents($meta->type, $row[$sorted_column_index], $transform_function, $transform_options, $default_function, $meta, null);
2303 } else {
2304 $column_for_first_row = $row[$sorted_column_index];
2306 $column_for_first_row = strtoupper(substr($column_for_first_row, 0, $GLOBALS['cfg']['LimitChars']));
2307 // fetch last row of the result set
2308 PMA_DBI_data_seek($dt_result, $num_rows - 1);
2309 $row = PMA_DBI_fetch_row($dt_result);
2310 // check for non printable sorted row data
2311 $meta = $fields_meta[$sorted_column_index];
2312 if (stristr($meta->type, 'BLOB') || $meta->type == 'geometry') {
2313 $column_for_last_row = PMA_handle_non_printable_contents($meta->type, $row[$sorted_column_index], $transform_function, $transform_options, $default_function, $meta, null);
2314 } else {
2315 $column_for_last_row = $row[$sorted_column_index];
2317 $column_for_last_row = strtoupper(substr($column_for_last_row, 0, $GLOBALS['cfg']['LimitChars']));
2318 // reset to first row for the loop in PMA_displayTableBody()
2319 PMA_DBI_data_seek($dt_result, 0);
2320 // we could also use here $sort_expression_nodirection
2321 $sorted_column_message = ' [' . htmlspecialchars($sort_column) . ': <strong>' . htmlspecialchars($column_for_first_row) . ' - ' . htmlspecialchars($column_for_last_row) . '</strong>]';
2322 unset($row, $column_for_first_row, $column_for_last_row, $meta, $default_function, $transform_function, $transform_options);
2324 unset($sorted_column_index, $sort_table, $sort_column);
2327 // 2. ----- Displays the top of the page -----
2329 // 2.1 Displays a messages with position informations
2330 if ($is_display['nav_bar'] == '1' && isset($pos_next)) {
2331 if (isset($unlim_num_rows) && $unlim_num_rows != $total) {
2332 $selectstring = ', ' . $unlim_num_rows . ' ' . __('in query');
2333 } else {
2334 $selectstring = '';
2337 if (! empty($analyzed_sql[0]['limit_clause'])) {
2338 $limit_data = PMA_analyzeLimitClause($analyzed_sql[0]['limit_clause']);
2339 $first_shown_rec = $limit_data['start'];
2340 if ($limit_data['length'] < $total) {
2341 $last_shown_rec = $limit_data['start'] + $limit_data['length'] - 1;
2342 } else {
2343 $last_shown_rec = $limit_data['start'] + $total - 1;
2345 } elseif ($_SESSION['tmp_user_values']['max_rows'] == 'all' || $pos_next > $total) {
2346 $first_shown_rec = $_SESSION['tmp_user_values']['pos'];
2347 $last_shown_rec = $total - 1;
2348 } else {
2349 $first_shown_rec = $_SESSION['tmp_user_values']['pos'];
2350 $last_shown_rec = $pos_next - 1;
2353 if (PMA_Table::isView($db, $table)
2354 && $total == $GLOBALS['cfg']['MaxExactCountViews']
2356 $message = PMA_Message::notice(__('This view has at least this number of rows. Please refer to %sdocumentation%s.'));
2357 $message->addParam('[a@./Documentation.html#cfg_MaxExactCount@_blank]');
2358 $message->addParam('[/a]');
2359 $message_view_warning = PMA_showHint($message);
2360 } else {
2361 $message_view_warning = false;
2364 $message = PMA_Message::success(__('Showing rows'));
2365 $message->addMessage($first_shown_rec);
2366 if ($message_view_warning) {
2367 $message->addMessage('...', ' - ');
2368 $message->addMessage($message_view_warning);
2369 $message->addMessage('(');
2370 } else {
2371 $message->addMessage($last_shown_rec, ' - ');
2372 $message->addMessage(' (');
2373 $message->addMessage($pre_count . PMA_formatNumber($total, 0));
2374 $message->addString(__('total'));
2375 if (!empty($after_count)) {
2376 $message->addMessage($after_count);
2378 $message->addMessage($selectstring, '');
2379 $message->addMessage(', ', '');
2382 $messagge_qt = PMA_Message::notice(__('Query took %01.4f sec'));
2383 $messagge_qt->addParam($GLOBALS['querytime']);
2385 $message->addMessage($messagge_qt, '');
2386 $message->addMessage(')', '');
2388 $message->addMessage(isset($sorted_column_message) ? $sorted_column_message : '', '');
2390 PMA_showMessage($message, $sql_query, 'success');
2392 } elseif (! isset($GLOBALS['printview']) || $GLOBALS['printview'] != '1') {
2393 PMA_showMessage(__('Your SQL query has been executed successfully'), $sql_query, 'success');
2396 // 2.3 Displays the navigation bars
2397 if (! strlen($table)) {
2398 if (isset($analyzed_sql[0]['query_type'])
2399 && $analyzed_sql[0]['query_type'] == 'SELECT'
2401 // table does not always contain a real table name,
2402 // for example in MySQL 5.0.x, the query SHOW STATUS
2403 // returns STATUS as a table name
2404 $table = $fields_meta[0]->table;
2405 } else {
2406 $table = '';
2410 if ($is_display['nav_bar'] == '1' && empty($analyzed_sql[0]['limit_clause'])) {
2411 PMA_displayTableNavigation($pos_next, $pos_prev, $sql_query, 'top_direction_dropdown');
2412 echo "\n";
2413 } elseif (! isset($GLOBALS['printview']) || $GLOBALS['printview'] != '1') {
2414 echo "\n" . '<br /><br />' . "\n";
2417 // 2b ----- Get field references from Database -----
2418 // (see the 'relation' configuration variable)
2420 // initialize map
2421 $map = array();
2423 // find tables
2424 $target=array();
2425 if (isset($analyzed_sql[0]['table_ref']) && is_array($analyzed_sql[0]['table_ref'])) {
2426 foreach ($analyzed_sql[0]['table_ref'] AS $table_ref_position => $table_ref) {
2427 $target[] = $analyzed_sql[0]['table_ref'][$table_ref_position]['table_true_name'];
2430 $tabs = '(\'' . join('\',\'', $target) . '\')';
2432 if (! strlen($table)) {
2433 $exist_rel = false;
2434 } else {
2435 // To be able to later display a link to the related table,
2436 // we verify both types of relations: either those that are
2437 // native foreign keys or those defined in the phpMyAdmin
2438 // configuration storage. If no PMA storage, we won't be able
2439 // to use the "column to display" notion (for example show
2440 // the name related to a numeric id).
2441 $exist_rel = PMA_getForeigners($db, $table, '', 'both');
2442 if ($exist_rel) {
2443 foreach ($exist_rel AS $master_field => $rel) {
2444 $display_field = PMA_getDisplayField($rel['foreign_db'], $rel['foreign_table']);
2445 $map[$master_field] = array($rel['foreign_table'],
2446 $rel['foreign_field'],
2447 $display_field,
2448 $rel['foreign_db']);
2449 } // end while
2450 } // end if
2451 } // end if
2452 // end 2b
2454 // 3. ----- Displays the results table -----
2455 PMA_displayTableHeaders($is_display, $fields_meta, $fields_cnt, $analyzed_sql, $sort_expression, $sort_expression_nodirection, $sort_direction);
2456 $url_query = '';
2457 echo '<tbody>' . "\n";
2458 $clause_is_unique = PMA_displayTableBody($dt_result, $is_display, $map, $analyzed_sql);
2459 // vertical output case
2460 if ($_SESSION['tmp_user_values']['disp_direction'] == 'vertical') {
2461 PMA_displayVerticalTable();
2462 } // end if
2463 unset($vertical_display);
2464 echo '</tbody>' . "\n";
2466 </table>
2468 <?php
2469 // 4. ----- Displays the link for multi-fields edit and delete
2471 if ($is_display['del_lnk'] == 'dr' && $is_display['del_lnk'] != 'kp') {
2473 $delete_text = $is_display['del_lnk'] == 'dr' ? __('Delete') : __('Kill');
2475 $_url_params = array(
2476 'db' => $db,
2477 'table' => $table,
2478 'sql_query' => $sql_query,
2479 'goto' => $goto,
2481 $uncheckall_url = 'sql.php' . PMA_generate_common_url($_url_params);
2483 $_url_params['checkall'] = '1';
2484 $checkall_url = 'sql.php' . PMA_generate_common_url($_url_params);
2486 if ($_SESSION['tmp_user_values']['disp_direction'] == 'vertical') {
2487 $checkall_params['onclick'] = 'if (setCheckboxes(\'resultsForm\', true)) return false;';
2488 $uncheckall_params['onclick'] = 'if (setCheckboxes(\'resultsForm\', false)) return false;';
2489 } else {
2490 $checkall_params['onclick'] = 'if (markAllRows(\'resultsForm\')) return false;';
2491 $uncheckall_params['onclick'] = 'if (unMarkAllRows(\'resultsForm\')) return false;';
2493 $checkall_link = PMA_linkOrButton($checkall_url, __('Check All'), $checkall_params, false);
2494 $uncheckall_link = PMA_linkOrButton($uncheckall_url, __('Uncheck All'), $uncheckall_params, false);
2495 if ($_SESSION['tmp_user_values']['disp_direction'] != 'vertical') {
2496 echo '<img class="selectallarrow" width="38" height="22"'
2497 .' src="' . $GLOBALS['pmaThemeImage'] . 'arrow_' . $GLOBALS['text_dir'] . '.png' . '"'
2498 .' alt="' . __('With selected:') . '" />';
2500 echo $checkall_link . "\n"
2501 .' / ' . "\n"
2502 .$uncheckall_link . "\n"
2503 .'<i>' . __('With selected:') . '</i>' . "\n";
2505 PMA_buttonOrImage(
2506 'submit_mult', 'mult_submit', 'submit_mult_change',
2507 __('Change'), 'b_edit.png', 'edit'
2509 PMA_buttonOrImage(
2510 'submit_mult', 'mult_submit', 'submit_mult_delete',
2511 $delete_text, 'b_drop.png', 'delete'
2513 if (isset($analyzed_sql[0]) && $analyzed_sql[0]['querytype'] == 'SELECT') {
2514 PMA_buttonOrImage(
2515 'submit_mult', 'mult_submit', 'submit_mult_export',
2516 __('Export'), 'b_tblexport.png', 'export'
2519 echo "\n";
2521 echo '<input type="hidden" name="sql_query"'
2522 .' value="' . htmlspecialchars($sql_query) . '" />' . "\n";
2524 if (! empty($GLOBALS['url_query'])) {
2525 echo '<input type="hidden" name="url_query"'
2526 .' value="' . $GLOBALS['url_query'] . '" />' . "\n";
2529 echo '<input type="hidden" name="clause_is_unique"'
2530 .' value="' . $clause_is_unique . '" />' . "\n";
2532 echo '</form>' . "\n";
2535 // 5. ----- Displays the navigation bar at the bottom if required -----
2537 if ($is_display['nav_bar'] == '1' && empty($analyzed_sql[0]['limit_clause'])) {
2538 echo '<br />' . "\n";
2539 PMA_displayTableNavigation($pos_next, $pos_prev, $sql_query, 'bottom_direction_dropdown');
2540 } elseif (! isset($GLOBALS['printview']) || $GLOBALS['printview'] != '1') {
2541 echo "\n" . '<br /><br />' . "\n";
2544 // 6. ----- Displays "Query results operations"
2545 if (! isset($GLOBALS['printview']) || $GLOBALS['printview'] != '1') {
2546 PMA_displayResultsOperations($the_disp_mode, $analyzed_sql);
2548 } // end of the 'PMA_displayTable()' function
2550 function default_function($buffer)
2552 $buffer = htmlspecialchars($buffer);
2553 $buffer = str_replace("\011", ' &nbsp;&nbsp;&nbsp;', str_replace(' ', ' &nbsp;', $buffer));
2554 $buffer = preg_replace("@((\015\012)|(\015)|(\012))@", '<br />', $buffer);
2556 return $buffer;
2560 * Displays operations that are available on results.
2562 * @param array $the_disp_mode the display mode
2563 * @param array $analyzed_sql the analyzed query
2565 * @global string $db the database name
2566 * @global string $table the table name
2567 * @global string $sql_query the current SQL query
2568 * @global integer $unlim_num_rows the total number of rows returned by the
2569 * SQL query without any programmatically
2570 * appended "LIMIT" clause
2572 * @access private
2574 * @see PMA_showMessage(), PMA_setDisplayMode(),
2575 * PMA_displayTableNavigation(), PMA_displayTableHeaders(),
2576 * PMA_displayTableBody(), PMA_displayResultsOperations()
2578 * @return nothing
2580 function PMA_displayResultsOperations($the_disp_mode, $analyzed_sql)
2582 global $db, $table, $sql_query, $unlim_num_rows, $fields_meta;
2584 $header_shown = false;
2585 $header = '<fieldset><legend>' . __('Query results operations') . '</legend>';
2587 if ($the_disp_mode[6] == '1' || $the_disp_mode[9] == '1') {
2588 // Displays "printable view" link if required
2589 if ($the_disp_mode[9] == '1') {
2591 if (!$header_shown) {
2592 echo $header;
2593 $header_shown = true;
2596 $_url_params = array(
2597 'db' => $db,
2598 'table' => $table,
2599 'printview' => '1',
2600 'sql_query' => $sql_query,
2602 $url_query = PMA_generate_common_url($_url_params);
2604 echo PMA_linkOrButton(
2605 'sql.php' . $url_query,
2606 PMA_getIcon('b_print.png', __('Print view'), true),
2607 '', true, true, 'print_view'
2608 ) . "\n";
2610 if ($_SESSION['tmp_user_values']['display_text']) {
2611 $_url_params['display_text'] = 'F';
2612 echo PMA_linkOrButton(
2613 'sql.php' . PMA_generate_common_url($_url_params),
2614 PMA_getIcon('b_print.png', __('Print view (with full texts)'), true),
2615 '', true, true, 'print_view'
2616 ) . "\n";
2617 unset($_url_params['display_text']);
2619 } // end displays "printable view"
2622 // Export link
2623 // (the url_query has extra parameters that won't be used to export)
2624 // (the single_table parameter is used in display_export.lib.php
2625 // to hide the SQL and the structure export dialogs)
2626 // If the parser found a PROCEDURE clause
2627 // (most probably PROCEDURE ANALYSE()) it makes no sense to
2628 // display the Export link).
2629 if (isset($analyzed_sql[0]) && $analyzed_sql[0]['querytype'] == 'SELECT' && ! isset($printview) && ! isset($analyzed_sql[0]['queryflags']['procedure'])) {
2630 if (isset($analyzed_sql[0]['table_ref'][0]['table_true_name']) && ! isset($analyzed_sql[0]['table_ref'][1]['table_true_name'])) {
2631 $_url_params['single_table'] = 'true';
2633 if (!$header_shown) {
2634 echo $header;
2635 $header_shown = true;
2637 $_url_params['unlim_num_rows'] = $unlim_num_rows;
2640 * At this point we don't know the table name; this can happen
2641 * for example with a query like
2642 * SELECT bike_code FROM (SELECT bike_code FROM bikes) tmp
2643 * As a workaround we set in the table parameter the name of the
2644 * first table of this database, so that tbl_export.php and
2645 * the script it calls do not fail
2647 if (empty($_url_params['table']) && !empty($_url_params['db'])) {
2648 $_url_params['table'] = PMA_DBI_fetch_value("SHOW TABLES");
2649 /* No result (probably no database selected) */
2650 if ($_url_params['table'] === false) {
2651 unset($_url_params['table']);
2655 echo PMA_linkOrButton(
2656 'tbl_export.php' . PMA_generate_common_url($_url_params),
2657 PMA_getIcon('b_tblexport.png', __('Export'), true),
2658 '', true, true, ''
2659 ) . "\n";
2661 // show chart
2662 echo PMA_linkOrButton(
2663 'tbl_chart.php' . PMA_generate_common_url($_url_params),
2664 PMA_getIcon('b_chart.png', __('Display chart'), true),
2665 '', true, true, ''
2666 ) . "\n";
2668 // show GIS chart
2669 $geometry_found = false;
2670 // If atleast one geometry field is found
2671 foreach ($fields_meta as $meta) {
2672 if ($meta->type == 'geometry') {
2673 $geometry_found = true;
2674 break;
2677 if ($geometry_found) {
2678 echo PMA_linkOrButton(
2679 'tbl_gis_visualization.php' . PMA_generate_common_url($_url_params),
2680 PMA_getIcon('b_globe.gif', __('Visualize GIS data'), true),
2681 '', true, true, ''
2682 ) . "\n";
2686 // CREATE VIEW
2689 * @todo detect privileges to create a view
2690 * (but see 2006-01-19 note in display_create_table.lib.php,
2691 * I think we cannot detect db-specific privileges reliably)
2692 * Note: we don't display a Create view link if we found a PROCEDURE clause
2694 if (!$header_shown) {
2695 echo $header;
2696 $header_shown = true;
2698 if (!PMA_DRIZZLE && !isset($analyzed_sql[0]['queryflags']['procedure'])) {
2699 echo PMA_linkOrButton(
2700 'view_create.php' . $url_query,
2701 PMA_getIcon('b_views.png', __('Create view'), true),
2702 '', true, true, ''
2703 ) . "\n";
2705 if ($header_shown) {
2706 echo '</fieldset><br />';
2711 * Verifies what to do with non-printable contents (binary or BLOB)
2712 * in Browse mode.
2714 * @param string $category BLOB|BINARY|GEOMETRY
2715 * @param string $content the binary content
2716 * @param string $transform_function transformation function
2717 * @param string $transform_options transformation parameters
2718 * @param string $default_function default transformation function
2719 * @param object $meta the meta-information about this field
2720 * @param array $url_params parameters that should go to the download link
2722 * @return mixed string or float
2724 function PMA_handle_non_printable_contents($category, $content, $transform_function, $transform_options, $default_function, $meta, $url_params = array())
2726 $result = '[' . $category;
2727 if (is_null($content)) {
2728 $result .= ' - NULL';
2729 $size = 0;
2730 } elseif (isset($content)) {
2731 $size = strlen($content);
2732 $display_size = PMA_formatByteDown($size, 3, 1);
2733 $result .= ' - '. $display_size[0] . ' ' . $display_size[1];
2735 $result .= ']';
2737 if (strpos($transform_function, 'octetstream')) {
2738 $result = $content;
2740 if ($size > 0) {
2741 if ($default_function != $transform_function) {
2742 $result = $transform_function($result, $transform_options, $meta);
2743 } else {
2744 $result = $default_function($result, array(), $meta);
2745 if (stristr($meta->type, 'BLOB') && $_SESSION['tmp_user_values']['display_blob']) {
2746 // in this case, restart from the original $content
2747 $result = htmlspecialchars(PMA_replace_binary_contents($content));
2749 /* Create link to download */
2750 if (count($url_params) > 0) {
2751 $result = '<a href="tbl_get_field.php' . PMA_generate_common_url($url_params) . '">' . $result . '</a>';
2755 return($result);
2759 * Prepares the displayable content of a data cell in Browse mode,
2760 * taking into account foreign key description field and transformations
2762 * @param string $class css classes for the td element
2763 * @param bool $condition_field whether the column is a part of the where clause
2764 * @param string $analyzed_sql the analyzed query
2765 * @param object $meta the meta-information about this field
2766 * @param array $map the list of relations
2767 * @param string $data data
2768 * @param string $transform_function transformation function
2769 * @param string $default_function default function
2770 * @param string $nowrap 'nowrap' if the content should not be wrapped
2771 * @param string $where_comparison data for the where cluase
2772 * @param array $transform_options array of options for transformation
2773 * @param bool $is_field_truncated whether the field is truncated
2775 * @return string formatted data
2777 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 )
2780 $result = ' class="' . PMA_addClass($class, $condition_field, $meta, $nowrap, $is_field_truncated, $transform_function, $default_function) . '">';
2782 if (isset($analyzed_sql[0]['select_expr']) && is_array($analyzed_sql[0]['select_expr'])) {
2783 foreach ($analyzed_sql[0]['select_expr'] AS $select_expr_position => $select_expr) {
2784 $alias = $analyzed_sql[0]['select_expr'][$select_expr_position]['alias'];
2785 if (isset($alias) && strlen($alias)) {
2786 $true_column = $analyzed_sql[0]['select_expr'][$select_expr_position]['column'];
2787 if ($alias == $meta->name) {
2788 // this change in the parameter does not matter
2789 // outside of the function
2790 $meta->name = $true_column;
2791 } // end if
2792 } // end if
2793 } // end foreach
2794 } // end if
2796 if (isset($map[$meta->name])) {
2797 // Field to display from the foreign table?
2798 if (isset($map[$meta->name][2]) && strlen($map[$meta->name][2])) {
2799 $dispsql = 'SELECT ' . PMA_backquote($map[$meta->name][2])
2800 . ' FROM ' . PMA_backquote($map[$meta->name][3])
2801 . '.' . PMA_backquote($map[$meta->name][0])
2802 . ' WHERE ' . PMA_backquote($map[$meta->name][1])
2803 . $where_comparison;
2804 $dispresult = PMA_DBI_try_query($dispsql, null, PMA_DBI_QUERY_STORE);
2805 if ($dispresult && PMA_DBI_num_rows($dispresult) > 0) {
2806 list($dispval) = PMA_DBI_fetch_row($dispresult, 0);
2807 } else {
2808 $dispval = __('Link not found');
2810 @PMA_DBI_free_result($dispresult);
2811 } else {
2812 $dispval = '';
2813 } // end if... else...
2815 if (isset($GLOBALS['printview']) && $GLOBALS['printview'] == '1') {
2816 $result .= ($transform_function != $default_function ? $transform_function($data, $transform_options, $meta) : $transform_function($data, array(), $meta)) . ' <code>[-&gt;' . $dispval . ']</code>';
2817 } else {
2819 if ('K' == $_SESSION['tmp_user_values']['relational_display']) {
2820 // user chose "relational key" in the display options, so
2821 // the title contains the display field
2822 $title = (! empty($dispval))? ' title="' . htmlspecialchars($dispval) . '"' : '';
2823 } else {
2824 $title = ' title="' . htmlspecialchars($data) . '"';
2827 $_url_params = array(
2828 'db' => $map[$meta->name][3],
2829 'table' => $map[$meta->name][0],
2830 'pos' => '0',
2831 'sql_query' => 'SELECT * FROM '
2832 . PMA_backquote($map[$meta->name][3]) . '.' . PMA_backquote($map[$meta->name][0])
2833 . ' WHERE ' . PMA_backquote($map[$meta->name][1])
2834 . $where_comparison,
2836 $result .= '<a href="sql.php' . PMA_generate_common_url($_url_params)
2837 . '"' . $title . '>';
2839 if ($transform_function != $default_function) {
2840 // always apply a transformation on the real data,
2841 // not on the display field
2842 $result .= $transform_function($data, $transform_options, $meta);
2843 } else {
2844 if ('D' == $_SESSION['tmp_user_values']['relational_display']) {
2845 // user chose "relational display field" in the
2846 // display options, so show display field in the cell
2847 $result .= $transform_function($dispval, array(), $meta);
2848 } else {
2849 // otherwise display data in the cell
2850 $result .= $transform_function($data, array(), $meta);
2853 $result .= '</a>';
2855 } else {
2856 $result .= ($transform_function != $default_function ? $transform_function($data, $transform_options, $meta) : $transform_function($data, array(), $meta));
2858 $result .= '</td>' . "\n";
2860 return $result;
2864 * Generates a checkbox for multi-row submits
2866 * @param string $del_url delete url
2867 * @param array $is_display array with explicit indexes for all the display elements
2868 * @param string $row_no the row number
2869 * @param string $where_clause_html url encoded where cluase
2870 * @param array $condition_array array of conditions in the where cluase
2871 * @param string $del_query delete query
2872 * @param string $id_suffix suffix for the id
2873 * @param string $class css classes for the td element
2875 * @return string the generated HTML
2878 function PMA_generateCheckboxForMulti($del_url, $is_display, $row_no, $where_clause_html, $condition_array, $del_query, $id_suffix, $class)
2880 $ret = '';
2881 if (! empty($del_url) && $is_display['del_lnk'] != 'kp') {
2882 $ret .= '<td ';
2883 if (! empty($class)) {
2884 $ret .= 'class="' . $class . '"';
2886 $ret .= ' align="center">'
2887 . '<input type="checkbox" id="id_rows_to_delete' . $row_no . $id_suffix . '" name="rows_to_delete[' . $where_clause_html . ']"'
2888 . ' class="multi_checkbox"'
2889 . ' value="' . htmlspecialchars($del_query) . '" ' . (isset($GLOBALS['checkall']) ? 'checked="checked"' : '') . ' />'
2890 . '<input type="hidden" class="condition_array" value="' . htmlspecialchars(json_encode($condition_array)) . '" />'
2891 . ' </td>';
2893 return $ret;
2897 * Generates an Edit link
2899 * @param string $edit_url edit url
2900 * @param string $class css classes for td element
2901 * @param string $edit_str text for the edit link
2902 * @param string $where_clause where cluase
2903 * @param string $where_clause_html url encoded where cluase
2905 * @return string the generated HTML
2907 function PMA_generateEditLink($edit_url, $class, $edit_str, $where_clause, $where_clause_html)
2909 $ret = '';
2910 if (! empty($edit_url)) {
2911 $ret .= '<td class="' . $class . '" align="center" ' . ' ><span class="nowrap">'
2912 . PMA_linkOrButton($edit_url, $edit_str, array(), false);
2914 * Where clause for selecting this row uniquely is provided as
2915 * a hidden input. Used by jQuery scripts for handling grid editing
2917 if (! empty($where_clause)) {
2918 $ret .= '<input type="hidden" class="where_clause" value ="' . $where_clause_html . '" />';
2920 $ret .= '</span></td>';
2922 return $ret;
2926 * Generates an Copy link
2928 * @param string $copy_url copy url
2929 * @param string $copy_str text for the copy link
2930 * @param string $where_clause where clause
2931 * @param string $where_clause_html url encoded where cluase
2932 * @param string $class css classes for the td element
2934 * @return string the generated HTML
2936 function PMA_generateCopyLink($copy_url, $copy_str, $where_clause, $where_clause_html, $class)
2938 $ret = '';
2939 if (! empty($copy_url)) {
2940 $ret .= '<td ';
2941 if (! empty($class)) {
2942 $ret .= 'class="' . $class . '" ';
2944 $ret .= 'align="center" ' . ' ><span class="nowrap">'
2945 . PMA_linkOrButton($copy_url, $copy_str, array(), false);
2947 * Where clause for selecting this row uniquely is provided as
2948 * a hidden input. Used by jQuery scripts for handling grid editing
2950 if (! empty($where_clause)) {
2951 $ret .= '<input type="hidden" class="where_clause" value ="' . $where_clause_html . '" />';
2953 $ret .= '</span></td>';
2955 return $ret;
2959 * Generates a Delete link
2961 * @param string $del_url delete url
2962 * @param string $del_str text for the delete link
2963 * @param string $js_conf text for the JS confirmation
2964 * @param string $class css classes for the td element
2966 * @return string the generated HTML
2968 function PMA_generateDeleteLink($del_url, $del_str, $js_conf, $class)
2970 $ret = '';
2971 if (! empty($del_url)) {
2972 $ret .= '<td ';
2973 if (! empty($class)) {
2974 $ret .= 'class="' . $class . '" ';
2976 $ret .= 'align="center" ' . ' >'
2977 . PMA_linkOrButton($del_url, $del_str, $js_conf, false)
2978 . '</td>';
2980 return $ret;
2984 * Generates checkbox and links at some position (left or right)
2985 * (only called for horizontal mode)
2987 * @param string $position the position of the checkbox and links
2988 * @param string $del_url delete url
2989 * @param array $is_display array with explicit indexes for all the display elements
2990 * @param string $row_no row number
2991 * @param string $where_clause where clause
2992 * @param string $where_clause_html url encoded where cluase
2993 * @param array $condition_array array of conditions in the where cluase
2994 * @param string $del_query delete query
2995 * @param string $id_suffix suffix for the id
2996 * @param string $edit_url edit url
2997 * @param string $copy_url copy url
2998 * @param string $class css classes for the td elements
2999 * @param string $edit_str text for the edit link
3000 * @param string $copy_str text for the copy link
3001 * @param string $del_str text for the delete link
3002 * @param string $js_conf text for the JS confirmation
3004 * @return string the generated HTML
3006 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)
3008 $ret = '';
3010 if ($position == 'left') {
3011 $ret .= PMA_generateCheckboxForMulti($del_url, $is_display, $row_no, $where_clause_html, $condition_array, $del_query, $id_suffix = '_left', '', '', '');
3013 $ret .= PMA_generateEditLink($edit_url, $class, $edit_str, $where_clause, $where_clause_html, '');
3015 $ret .= PMA_generateCopyLink($copy_url, $copy_str, $where_clause, $where_clause_html, '');
3017 $ret .= PMA_generateDeleteLink($del_url, $del_str, $js_conf, '', '');
3019 } elseif ($position == 'right') {
3020 $ret .= PMA_generateDeleteLink($del_url, $del_str, $js_conf, '', '');
3022 $ret .= PMA_generateCopyLink($copy_url, $copy_str, $where_clause, $where_clause_html, '');
3024 $ret .= PMA_generateEditLink($edit_url, $class, $edit_str, $where_clause, $where_clause_html, '');
3026 $ret .= PMA_generateCheckboxForMulti($del_url, $is_display, $row_no, $where_clause_html, $condition_array, $del_query, $id_suffix = '_right', '', '', '');
3027 } else { // $position == 'none'
3028 $ret .= PMA_generateCheckboxForMulti($del_url, $is_display, $row_no, $where_clause_html, $condition_array, $del_query, $id_suffix = '_left', '', '', '');
3030 return $ret;