Merge remote-tracking branch 'origin/master' into drizzle
[phpmyadmin.git] / libraries / display_tbl.lib.php
blobc3ce47cb77ec23e59b7a989197aa31b007051941
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * library for displaying table with results from all sort of select queries
6 * @package phpMyAdmin
7 */
9 /**
12 require_once './libraries/Index.class.php';
14 /**
15 * Defines the display mode to use for the results of a SQL query
17 * It uses a synthetic string that contains all the required informations.
18 * In this string:
19 * - the first two characters stand for the action to do while
20 * clicking on the "edit" link (e.g. 'ur' for update a row, 'nn' for no
21 * edit link...);
22 * - the next two characters stand for the action to do while
23 * clicking on the "delete" link (e.g. 'kp' for kill a process, 'nn' for
24 * no delete link...);
25 * - the next characters are boolean values (1/0) and respectively stand
26 * for sorting links, navigation bar, "insert a new row" link, the
27 * bookmark feature, the expand/collapse text/blob fields button and
28 * the "display printable view" option.
29 * Of course '0'/'1' means the feature won't/will be enabled.
31 * @param string the synthetic value for display_mode (see a few
32 * lines above for explanations)
33 * @param integer the total number of rows returned by the SQL query
34 * without any programmatically appended "LIMIT" clause
35 * (just a copy of $unlim_num_rows if it exists, else
36 * computed inside this function)
38 * @return array an array with explicit indexes for all the display
39 * elements
41 * @global string the database name
42 * @global string the table name
43 * @global integer the total number of rows returned by the SQL query
44 * without any programmatically appended "LIMIT" clause
45 * @global array the properties of the fields returned by the query
46 * @global string the URL to return to in case of error in a SQL
47 * statement
49 * @access private
51 * @see PMA_displayTable()
53 function PMA_setDisplayMode(&$the_disp_mode, &$the_total)
55 global $db, $table;
56 global $unlim_num_rows, $fields_meta;
57 global $err_url;
59 // 1. Initializes the $do_display array
60 $do_display = array();
61 $do_display['edit_lnk'] = $the_disp_mode[0] . $the_disp_mode[1];
62 $do_display['del_lnk'] = $the_disp_mode[2] . $the_disp_mode[3];
63 $do_display['sort_lnk'] = (string) $the_disp_mode[4];
64 $do_display['nav_bar'] = (string) $the_disp_mode[5];
65 $do_display['ins_row'] = (string) $the_disp_mode[6];
66 $do_display['bkm_form'] = (string) $the_disp_mode[7];
67 $do_display['text_btn'] = (string) $the_disp_mode[8];
68 $do_display['pview_lnk'] = (string) $the_disp_mode[9];
70 // 2. Display mode is not "false for all elements" -> updates the
71 // display mode
72 if ($the_disp_mode != 'nnnn000000') {
73 // 2.0 Print view -> set all elements to false!
74 if (isset($GLOBALS['printview']) && $GLOBALS['printview'] == '1') {
75 $do_display['edit_lnk'] = 'nn'; // no edit link
76 $do_display['del_lnk'] = 'nn'; // no delete link
77 $do_display['sort_lnk'] = (string) '0';
78 $do_display['nav_bar'] = (string) '0';
79 $do_display['ins_row'] = (string) '0';
80 $do_display['bkm_form'] = (string) '0';
81 $do_display['text_btn'] = (string) '0';
82 $do_display['pview_lnk'] = (string) '0';
84 // 2.1 Statement is a "SELECT COUNT", a
85 // "CHECK/ANALYZE/REPAIR/OPTIMIZE", an "EXPLAIN" one or
86 // contains a "PROC ANALYSE" part
87 elseif ($GLOBALS['is_count'] || $GLOBALS['is_analyse'] || $GLOBALS['is_maint'] || $GLOBALS['is_explain']) {
88 $do_display['edit_lnk'] = 'nn'; // no edit link
89 $do_display['del_lnk'] = 'nn'; // no delete link
90 $do_display['sort_lnk'] = (string) '0';
91 $do_display['nav_bar'] = (string) '0';
92 $do_display['ins_row'] = (string) '0';
93 $do_display['bkm_form'] = (string) '1';
94 if ($GLOBALS['is_maint']) {
95 $do_display['text_btn'] = (string) '1';
96 } else {
97 $do_display['text_btn'] = (string) '0';
99 $do_display['pview_lnk'] = (string) '1';
101 // 2.2 Statement is a "SHOW..."
102 elseif ($GLOBALS['is_show']) {
104 * 2.2.1
105 * @todo defines edit/delete links depending on show statement
107 $tmp = preg_match('@^SHOW[[:space:]]+(VARIABLES|(FULL[[:space:]]+)?PROCESSLIST|STATUS|TABLE|GRANTS|CREATE|LOGS|DATABASES|FIELDS)@i', $GLOBALS['sql_query'], $which);
108 if (isset($which[1]) && strpos(' ' . strtoupper($which[1]), 'PROCESSLIST') > 0) {
109 $do_display['edit_lnk'] = 'nn'; // no edit link
110 $do_display['del_lnk'] = 'kp'; // "kill process" type edit link
111 } else {
112 // Default case -> no links
113 $do_display['edit_lnk'] = 'nn'; // no edit link
114 $do_display['del_lnk'] = 'nn'; // no delete link
116 // 2.2.2 Other settings
117 $do_display['sort_lnk'] = (string) '0';
118 $do_display['nav_bar'] = (string) '0';
119 $do_display['ins_row'] = (string) '0';
120 $do_display['bkm_form'] = (string) '1';
121 $do_display['text_btn'] = (string) '1';
122 $do_display['pview_lnk'] = (string) '1';
124 // 2.3 Other statements (ie "SELECT" ones) -> updates
125 // $do_display['edit_lnk'], $do_display['del_lnk'] and
126 // $do_display['text_btn'] (keeps other default values)
127 else {
128 $prev_table = $fields_meta[0]->table;
129 $do_display['text_btn'] = (string) '1';
130 for ($i = 0; $i < $GLOBALS['fields_cnt']; $i++) {
131 $is_link = ($do_display['edit_lnk'] != 'nn'
132 || $do_display['del_lnk'] != 'nn'
133 || $do_display['sort_lnk'] != '0'
134 || $do_display['ins_row'] != '0');
135 // 2.3.2 Displays edit/delete/sort/insert links?
136 if ($is_link
137 && ($fields_meta[$i]->table == '' || $fields_meta[$i]->table != $prev_table)) {
138 $do_display['edit_lnk'] = 'nn'; // don't display links
139 $do_display['del_lnk'] = 'nn';
141 * @todo May be problematic with same fields names in two joined table.
143 // $do_display['sort_lnk'] = (string) '0';
144 $do_display['ins_row'] = (string) '0';
145 if ($do_display['text_btn'] == '1') {
146 break;
148 } // end if (2.3.2)
149 // 2.3.3 Always display print view link
150 $do_display['pview_lnk'] = (string) '1';
151 $prev_table = $fields_meta[$i]->table;
152 } // end for
153 } // end if..elseif...else (2.1 -> 2.3)
154 } // end if (2)
156 // 3. Gets the total number of rows if it is unknown
157 if (isset($unlim_num_rows) && $unlim_num_rows != '') {
158 $the_total = $unlim_num_rows;
159 } elseif (($do_display['nav_bar'] == '1' || $do_display['sort_lnk'] == '1')
160 && (strlen($db) && !empty($table))) {
161 $the_total = PMA_Table::countRecords($db, $table);
164 // 4. If navigation bar or sorting fields names URLs should be
165 // displayed but there is only one row, change these settings to
166 // false
167 if ($do_display['nav_bar'] == '1' || $do_display['sort_lnk'] == '1') {
169 // - Do not display sort links if less than 2 rows.
170 // - For a VIEW we (probably) did not count the number of rows
171 // so don't test this number here, it would remove the possibility
172 // of sorting VIEW results.
173 if (isset($unlim_num_rows) && $unlim_num_rows < 2 && ! PMA_Table::isView($db, $table)) {
174 // force display of navbar for vertical/horizontal display-choice.
175 // $do_display['nav_bar'] = (string) '0';
176 $do_display['sort_lnk'] = (string) '0';
178 } // end if (3)
180 // 5. Updates the synthetic var
181 $the_disp_mode = join('', $do_display);
183 return $do_display;
184 } // end of the 'PMA_setDisplayMode()' function
188 * 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
210 * @param string iconic caption for button
211 * @param string text for button
212 * @param integer position for next query
213 * @param string query ready for display
214 * @param string optional onsubmit clause
215 * @param string optional hidden field for special treatment
216 * @param string optional onclick clause
218 * @global string $db the database name
219 * @global string $table the table name
220 * @global string $goto the URL to go back in case of errors
222 * @access private
224 * @see PMA_displayTableNavigation()
226 function PMA_displayTableNavigationOneButton($caption, $title, $pos, $html_sql_query, $onsubmit = '', $input_for_real_end = '', $onclick = '') {
228 global $db, $table, $goto;
230 $caption_output = '';
231 // for true or 'both'
232 if ($GLOBALS['cfg']['NavigationBarIconic']) {
233 $caption_output .= $caption;
235 // for false or 'both'
236 if (false === $GLOBALS['cfg']['NavigationBarIconic'] || 'both' === $GLOBALS['cfg']['NavigationBarIconic']) {
237 $caption_output .= '&nbsp;' . $title;
239 $title_output = ' title="' . $title . '"';
241 <td>
242 <form action="sql.php" method="post" <?php echo $onsubmit; ?>>
243 <?php echo PMA_generate_common_hidden_inputs($db, $table); ?>
244 <input type="hidden" name="sql_query" value="<?php echo $html_sql_query; ?>" />
245 <input type="hidden" name="pos" value="<?php echo $pos; ?>" />
246 <input type="hidden" name="goto" value="<?php echo $goto; ?>" />
247 <?php echo $input_for_real_end; ?>
248 <input type="submit" name="navig" <?php echo ($GLOBALS['cfg']['AjaxEnable'] ? ' class="ajax" ' : '' ); ?> value="<?php echo $caption_output; ?>"<?php echo $title_output . $onclick; ?> />
249 </form>
250 </td>
251 <?php
252 } // end function PMA_displayTableNavigationOneButton()
255 * Displays a navigation bar to browse among the results of a SQL query
257 * @param integer the offset for the "next" page
258 * @param integer the offset for the "previous" page
259 * @param string the URL-encoded query
260 * @param string the id for the direction dropdown
262 * @global string $db the database name
263 * @global string $table the table name
264 * @global string $goto the URL to go back in case of errors
265 * @global integer $num_rows the total number of rows returned by the
266 * SQL query
267 * @global integer $unlim_num_rows the total number of rows returned by the
268 * SQL any programmatically appended "LIMIT" clause
269 * @global boolean $is_innodb whether its InnoDB or not
270 * @global array $showtable table definitions
272 * @access private
274 * @see PMA_displayTable()
276 function PMA_displayTableNavigation($pos_next, $pos_prev, $sql_query, $id_for_direction_dropdown)
278 global $db, $table, $goto;
279 global $num_rows, $unlim_num_rows;
280 global $is_innodb;
281 global $showtable;
283 // here, using htmlentities() would cause problems if the query
284 // contains accented characters
285 $html_sql_query = htmlspecialchars($sql_query);
288 * @todo move this to a central place
289 * @todo for other future table types
291 $is_innodb = (isset($showtable['Type']) && $showtable['Type'] == 'InnoDB');
295 <!-- Navigation bar -->
296 <table border="0" cellpadding="0" cellspacing="0" class="navigation">
297 <tr>
298 <td class="navigation_separator"></td>
299 <?php
300 // Move to the beginning or to the previous page
301 if ($_SESSION['tmp_user_values']['pos'] && $_SESSION['tmp_user_values']['max_rows'] != 'all') {
302 PMA_displayTableNavigationOneButton('&lt;&lt;', __('Begin'), 0, $html_sql_query);
303 PMA_displayTableNavigationOneButton('&lt;', __('Previous'), $pos_prev, $html_sql_query);
305 } // end move back
307 //page redirection
308 // (unless we are showing all records)
309 if ('all' != $_SESSION['tmp_user_values']['max_rows']) { //if1
310 $pageNow = @floor($_SESSION['tmp_user_values']['pos'] / $_SESSION['tmp_user_values']['max_rows']) + 1;
311 $nbTotalPage = @ceil($unlim_num_rows / $_SESSION['tmp_user_values']['max_rows']);
313 if ($nbTotalPage > 1){ //if2
315 <td>
316 <?php
317 $_url_params = array(
318 'db' => $db,
319 'table' => $table,
320 'sql_query' => $sql_query,
321 'goto' => $goto,
323 //<form> to keep the form alignment of button < and <<
324 // and also to know what to execute when the selector changes
325 echo '<form action="sql.php' . PMA_generate_common_url($_url_params). '" method="post">';
326 echo PMA_pageselector(
327 $_SESSION['tmp_user_values']['max_rows'],
328 $pageNow,
329 $nbTotalPage,
330 200,
337 </form>
338 </td>
339 <?php
340 } //_if2
341 } //_if1
343 // Display the "Show all" button if allowed
344 if ($GLOBALS['cfg']['ShowAll'] && ($num_rows < $unlim_num_rows)) {
345 echo "\n";
347 <td>
348 <form action="sql.php" method="post">
349 <?php echo PMA_generate_common_hidden_inputs($db, $table); ?>
350 <input type="hidden" name="sql_query" value="<?php echo $html_sql_query; ?>" />
351 <input type="hidden" name="pos" value="0" />
352 <input type="hidden" name="session_max_rows" value="all" />
353 <input type="hidden" name="goto" value="<?php echo $goto; ?>" />
354 <input type="submit" name="navig" value="<?php echo __('Show all'); ?>" />
355 </form>
356 </td>
357 <?php
358 } // end show all
360 // Move to the next page or to the last one
361 if (($_SESSION['tmp_user_values']['pos'] + $_SESSION['tmp_user_values']['max_rows'] < $unlim_num_rows) && $num_rows >= $_SESSION['tmp_user_values']['max_rows']
362 && $_SESSION['tmp_user_values']['max_rows'] != 'all') {
364 // display the Next button
365 PMA_displayTableNavigationOneButton('&gt;',
366 __('Next'),
367 $pos_next,
368 $html_sql_query);
370 // prepare some options for the End button
371 if ($is_innodb && $unlim_num_rows > $GLOBALS['cfg']['MaxExactCount']) {
372 $input_for_real_end = '<input id="real_end_input" type="hidden" name="find_real_end" value="1" />';
373 // no backquote around this message
374 $onclick = '';
375 } else {
376 $input_for_real_end = $onclick = '';
379 // display the End button
380 PMA_displayTableNavigationOneButton('&gt;&gt;',
381 __('End'),
382 @((ceil($unlim_num_rows / $_SESSION['tmp_user_values']['max_rows'])- 1) * $_SESSION['tmp_user_values']['max_rows']),
383 $html_sql_query,
384 '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') . '"',
385 $input_for_real_end,
386 $onclick
388 } // end move toward
390 // show separator if pagination happen
391 if ($nbTotalPage > 1){
392 echo '<td><div class="navigation_separator">|</div></td>';
395 <td>
396 <div class="restore_column hide">
397 <input type="submit" value="<?php echo __('Restore column order'); ?>" />
398 <div class="navigation_separator">|</div>
399 </div>
400 <?php
401 if (PMA_isSelect()) {
402 // generate the column order, if it is set
403 $pmatable = new PMA_Table($GLOBALS['table'], $GLOBALS['db']);
404 $col_order = $pmatable->getUiProp(PMA_Table::PROP_COLUMN_ORDER);
405 if ($col_order) {
406 echo '<input id="col_order" type="hidden" value="' . implode(',', $col_order) . '" />';
408 $col_visib = $pmatable->getUiProp(PMA_Table::PROP_COLUMN_VISIB);
409 if ($col_visib) {
410 echo '<input id="col_visib" type="hidden" value="' . implode(',', $col_visib) . '" />';
412 // generate table create time
413 echo '<input id="table_create_time" type="hidden" value="' .
414 PMA_Table::sGetStatusInfo($GLOBALS['db'], $GLOBALS['table'], 'Create_time') . '" />';
416 // generate hints
417 echo '<input id="col_order_hint" type="hidden" value="' . __('Drag to reorder') . '" />';
418 echo '<input id="sort_hint" type="hidden" value="' . __('Click to sort') . '" />';
419 echo '<input id="col_mark_hint" type="hidden" value="' . __('Click to mark/unmark') . '" />';
420 echo '<input id="col_visib_hint" type="hidden" value="' . __('Click the drop-down arrow<br />to toggle column\'s visibility') . '" />';
421 echo '<input id="show_all_col_text" type="hidden" value="' . __('Show all') . '" />';
423 </td>
425 <?php // if displaying a VIEW, $unlim_num_rows could be zero because
426 // of $cfg['MaxExactCountViews']; in this case, avoid passing
427 // the 5th parameter to checkFormElementInRange()
428 // (this means we can't validate the upper limit ?>
429 <td class="navigation_goto">
430 <form action="sql.php" method="post"
431 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 : ''; ?>))">
432 <?php echo PMA_generate_common_hidden_inputs($db, $table); ?>
433 <input type="hidden" name="sql_query" value="<?php echo $html_sql_query; ?>" />
434 <input type="hidden" name="goto" value="<?php echo $goto; ?>" />
435 <input type="submit" name="navig" <?php echo ($GLOBALS['cfg']['AjaxEnable'] ? ' class="ajax"' : ''); ?> value="<?php echo __('Show'); ?> :" />
436 <?php echo __('Start row') . ': ' . "\n"; ?>
437 <input type="text" name="pos" size="3" value="<?php echo (($pos_next >= $unlim_num_rows) ? 0 : $pos_next); ?>" class="textfield" onfocus="this.select()" />
438 <?php echo __('Number of rows') . ': ' . "\n"; ?>
439 <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()" />
440 <?php
441 if ($GLOBALS['cfg']['ShowDisplayDirection']) {
442 // Display mode (horizontal/vertical and repeat headers)
443 echo __('Mode') . ': ' . "\n";
444 $choices = array(
445 'horizontal' => __('horizontal'),
446 'horizontalflipped' => __('horizontal (rotated headers)'),
447 'vertical' => __('vertical'));
448 echo PMA_generate_html_dropdown('disp_direction', $choices, $_SESSION['tmp_user_values']['disp_direction'], $id_for_direction_dropdown);
449 unset($choices);
452 printf(__('Headers every %s rows'),
453 '<input type="text" size="3" name="repeat_cells" value="' . $_SESSION['tmp_user_values']['repeat_cells'] . '" class="textfield" />');
454 echo "\n";
456 </form>
457 </td>
458 <td class="navigation_separator"></td>
459 </tr>
460 </table>
462 <?php
463 } // end of the 'PMA_displayTableNavigation()' function
467 * Displays the headers of the results table
469 * @param array which elements to display
470 * @param array the list of fields properties
471 * @param integer the total number of fields returned by the SQL query
472 * @param array the analyzed query
474 * @return boolean $clause_is_unique
476 * @global string $db the database name
477 * @global string $table the table name
478 * @global string $goto the URL to go back in case of errors
479 * @global string $sql_query the SQL query
480 * @global integer $num_rows the total number of rows returned by the
481 * SQL query
482 * @global array $vertical_display informations used with vertical display
483 * mode
485 * @access private
487 * @see PMA_displayTable()
489 function PMA_displayTableHeaders(&$is_display, &$fields_meta, $fields_cnt = 0, $analyzed_sql = '', $sort_expression, $sort_expression_nodirection, $sort_direction)
491 global $db, $table, $goto;
492 global $sql_query, $num_rows;
493 global $vertical_display, $highlight_columns;
495 // required to generate sort links that will remember whether the
496 // "Show all" button has been clicked
497 $sql_md5 = md5($GLOBALS['sql_query']);
498 $session_max_rows = $_SESSION['tmp_user_values']['query'][$sql_md5]['max_rows'];
500 if ($analyzed_sql == '') {
501 $analyzed_sql = array();
504 // can the result be sorted?
505 if ($is_display['sort_lnk'] == '1') {
507 // Just as fallback
508 $unsorted_sql_query = $sql_query;
509 if (isset($analyzed_sql[0]['unsorted_query'])) {
510 $unsorted_sql_query = $analyzed_sql[0]['unsorted_query'];
512 // Handles the case of multiple clicks on a column's header
513 // which would add many spaces before "ORDER BY" in the
514 // generated query.
515 $unsorted_sql_query = trim($unsorted_sql_query);
517 // sorting by indexes, only if it makes sense (only one table ref)
518 if (isset($analyzed_sql) && isset($analyzed_sql[0]) &&
519 isset($analyzed_sql[0]['querytype']) && $analyzed_sql[0]['querytype'] == 'SELECT' &&
520 isset($analyzed_sql[0]['table_ref']) && count($analyzed_sql[0]['table_ref']) == 1) {
522 // grab indexes data:
523 $indexes = PMA_Index::getFromTable($table, $db);
525 // do we have any index?
526 if ($indexes) {
528 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
529 || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') {
530 $span = $fields_cnt;
531 if ($is_display['edit_lnk'] != 'nn') {
532 $span++;
534 if ($is_display['del_lnk'] != 'nn') {
535 $span++;
537 if ($is_display['del_lnk'] != 'kp' && $is_display['del_lnk'] != 'nn') {
538 $span++;
540 } else {
541 $span = $num_rows + floor($num_rows/$_SESSION['tmp_user_values']['repeat_cells']) + 1;
544 echo '<form action="sql.php" method="post">' . "\n";
545 echo PMA_generate_common_hidden_inputs($db, $table);
546 echo __('Sort by key') . ': <select name="sql_query" onchange="this.form.submit();">' . "\n";
547 $used_index = false;
548 $local_order = (isset($sort_expression) ? $sort_expression : '');
549 foreach ($indexes as $index) {
550 $asc_sort = '`' . implode('` ASC, `', array_keys($index->getColumns())) . '` ASC';
551 $desc_sort = '`' . implode('` DESC, `', array_keys($index->getColumns())) . '` DESC';
552 $used_index = $used_index || $local_order == $asc_sort || $local_order == $desc_sort;
553 echo '<option value="'
554 . htmlspecialchars($unsorted_sql_query . ' ORDER BY ' . $asc_sort)
555 . '"' . ($local_order == $asc_sort ? ' selected="selected"' : '')
556 . '>' . htmlspecialchars($index->getName()) . ' ('
557 . __('Ascending') . ')</option>';
558 echo '<option value="'
559 . htmlspecialchars($unsorted_sql_query . ' ORDER BY ' . $desc_sort)
560 . '"' . ($local_order == $desc_sort ? ' selected="selected"' : '')
561 . '>' . htmlspecialchars($index->getName()) . ' ('
562 . __('Descending') . ')</option>';
564 echo '<option value="' . htmlspecialchars($unsorted_sql_query) . '"' . ($used_index ? '' : ' selected="selected"') . '>' . __('None') . '</option>';
565 echo '</select>' . "\n";
566 echo '<noscript><input type="submit" value="' . __('Go') . '" /></noscript>';
567 echo '</form>' . "\n";
573 $vertical_display['emptypre'] = 0;
574 $vertical_display['emptyafter'] = 0;
575 $vertical_display['textbtn'] = '';
577 // Display options (if we are not in print view)
578 if (! (isset($GLOBALS['printview']) && $GLOBALS['printview'] == '1')) {
579 echo '<form method="post" action="sql.php" name="displayOptionsForm" id="displayOptionsForm"';
580 if ($GLOBALS['cfg']['AjaxEnable']) {
581 echo ' class="ajax" ';
583 echo '>';
584 $url_params = array(
585 'db' => $db,
586 'table' => $table,
587 'sql_query' => $sql_query,
588 'goto' => $goto,
589 'display_options_form' => 1
591 echo PMA_generate_common_hidden_inputs($url_params);
592 echo '<br />';
593 PMA_generate_slider_effect('displayoptions',__('Options'));
594 echo '<fieldset>';
596 echo '<div class="formelement">';
597 $choices = array(
598 'P' => __('Partial texts'),
599 'F' => __('Full texts')
601 PMA_display_html_radio('display_text', $choices, $_SESSION['tmp_user_values']['display_text']);
602 echo '</div>';
604 // prepare full/partial text button or link
605 if ($_SESSION['tmp_user_values']['display_text']=='F') {
606 // currently in fulltext mode so show the opposite link
607 $tmp_image_file = $GLOBALS['pmaThemeImage'] . 's_partialtext.png';
608 $tmp_txt = __('Partial texts');
609 $url_params['display_text'] = 'P';
610 } else {
611 $tmp_image_file = $GLOBALS['pmaThemeImage'] . 's_fulltext.png';
612 $tmp_txt = __('Full texts');
613 $url_params['display_text'] = 'F';
616 $tmp_image = '<img class="fulltext" src="' . $tmp_image_file . '" alt="' . $tmp_txt . '" title="' . $tmp_txt . '" />';
617 $tmp_url = 'sql.php' . PMA_generate_common_url($url_params);
618 $full_or_partial_text_link = PMA_linkOrButton($tmp_url, $tmp_image, array(), false);
619 unset($tmp_image_file, $tmp_txt, $tmp_url, $tmp_image);
622 if ($GLOBALS['cfgRelation']['relwork'] && $GLOBALS['cfgRelation']['displaywork']) {
623 echo '<div class="formelement">';
624 $choices = array(
625 'K' => __('Relational key'),
626 'D' => __('Relational display column')
628 PMA_display_html_radio('relational_display', $choices, $_SESSION['tmp_user_values']['relational_display']);
629 echo '</div>';
632 echo '<div class="formelement">';
633 PMA_display_html_checkbox('display_binary', __('Show binary contents'), ! empty($_SESSION['tmp_user_values']['display_binary']), false);
634 echo '<br />';
635 PMA_display_html_checkbox('display_blob', __('Show BLOB contents'), ! empty($_SESSION['tmp_user_values']['display_blob']), false);
636 echo '<br />';
637 PMA_display_html_checkbox('display_binary_as_hex', __('Show binary contents as HEX'), ! empty($_SESSION['tmp_user_values']['display_binary_as_hex']), false);
638 echo '</div>';
640 // I would have preferred to name this "display_transformation".
641 // This is the only way I found to be able to keep this setting sticky
642 // per SQL query, and at the same time have a default that displays
643 // the transformations.
644 echo '<div class="formelement">';
645 PMA_display_html_checkbox('hide_transformation', __('Hide') . ' ' . __('Browser transformation'), ! empty($_SESSION['tmp_user_values']['hide_transformation']), false);
646 echo '</div>';
648 echo '<div class="formelement">';
649 $choices = array(
650 'GEOM' => __('Geometry'),
651 'WKT' => __('Well Known Text'),
652 'WKB' => __('Well Known Binary')
654 PMA_display_html_radio('geometry_display', $choices, $_SESSION['tmp_user_values']['geometry_display']);
655 echo '</div>';
657 echo '<div class="clearfloat"></div>';
658 echo '</fieldset>';
660 echo '<fieldset class="tblFooters">';
661 echo '<input type="submit" value="' . __('Go') . '" />';
662 echo '</fieldset>';
663 echo '</div>';
664 echo '</form>';
667 // Start of form for multi-rows edit/delete/export
669 if ($is_display['del_lnk'] == 'dr' || $is_display['del_lnk'] == 'kp') {
670 echo '<form method="post" action="tbl_row_action.php" name="resultsForm" id="resultsForm"';
671 if ($GLOBALS['cfg']['AjaxEnable']) {
672 echo ' class="ajax" ';
674 echo '>' . "\n";
675 echo PMA_generate_common_hidden_inputs($db, $table, 1);
676 echo '<input type="hidden" name="goto" value="sql.php" />' . "\n";
679 echo '<table id="table_results" class="data';
680 if ($GLOBALS['cfg']['AjaxEnable']) {
681 echo ' ajax';
683 echo '">' . "\n";
684 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
685 || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') {
686 echo '<thead><tr>' . "\n";
689 // 1. Displays the full/partial text button (part 1)...
690 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
691 || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') {
692 $colspan = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn')
693 ? ' colspan="4"'
694 : '';
695 } else {
696 $rowspan = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn')
697 ? ' rowspan="4"'
698 : '';
701 // ... before the result table
702 if (($is_display['edit_lnk'] == 'nn' && $is_display['del_lnk'] == 'nn')
703 && $is_display['text_btn'] == '1') {
704 $vertical_display['emptypre'] = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn') ? 4 : 0;
705 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
706 || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') {
708 <th colspan="<?php echo $fields_cnt; ?>"></th>
709 </tr>
710 <tr>
711 <?php
712 } // end horizontal/horizontalflipped mode
713 else {
715 <tr>
716 <th colspan="<?php echo $num_rows + floor($num_rows/$_SESSION['tmp_user_values']['repeat_cells']) + 1; ?>"></th>
717 </tr>
718 <?php
719 } // end vertical mode
722 // ... at the left column of the result table header if possible
723 // and required
724 elseif (($GLOBALS['cfg']['RowActionLinks'] == 'left' || $GLOBALS['cfg']['RowActionLinks'] == 'both')
725 && $is_display['text_btn'] == '1') {
726 $vertical_display['emptypre'] = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn') ? 4 : 0;
727 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
728 || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') {
730 <th <?php echo $colspan; ?>><?php echo $full_or_partial_text_link;?></th>
731 <?php
732 } // end horizontal/horizontalflipped mode
733 else {
734 $vertical_display['textbtn'] = ' <th ' . $rowspan . ' valign="middle">' . "\n"
735 . ' ' . "\n"
736 . ' </th>' . "\n";
737 } // end vertical mode
740 // ... elseif no button, displays empty(ies) col(s) if required
741 elseif (($GLOBALS['cfg']['RowActionLinks'] == 'left' || $GLOBALS['cfg']['RowActionLinks'] == 'both')
742 && ($is_display['edit_lnk'] != 'nn' || $is_display['del_lnk'] != 'nn')) {
743 $vertical_display['emptypre'] = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn') ? 4 : 0;
744 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
745 || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') {
747 <td<?php echo $colspan; ?>></td>
748 <?php
749 } // end horizontal/horizontalfipped mode
750 else {
751 $vertical_display['textbtn'] = ' <td' . $rowspan . '></td>' . "\n";
752 } // end vertical mode
755 // ... elseif display an empty column if the actions links are disabled to match the rest of the table
756 elseif ($GLOBALS['cfg']['RowActionLinks'] == 'none' && ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
757 || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped')) {
758 echo '<th></th>';
761 // 2. Displays the fields' name
762 // 2.0 If sorting links should be used, checks if the query is a "JOIN"
763 // statement (see 2.1.3)
765 // 2.0.1 Prepare Display column comments if enabled ($GLOBALS['cfg']['ShowBrowseComments']).
766 // Do not show comments, if using horizontalflipped mode, because of space usage
767 if ($GLOBALS['cfg']['ShowBrowseComments']
768 && $_SESSION['tmp_user_values']['disp_direction'] != 'horizontalflipped') {
769 $comments_map = array();
770 if (isset($analyzed_sql[0]) && is_array($analyzed_sql[0])) {
771 foreach ($analyzed_sql[0]['table_ref'] as $tbl) {
772 $tb = $tbl['table_true_name'];
773 $comments_map[$tb] = PMA_getComments($db, $tb);
774 unset($tb);
779 if ($GLOBALS['cfgRelation']['commwork'] && $GLOBALS['cfgRelation']['mimework'] && $GLOBALS['cfg']['BrowseMIME'] && ! $_SESSION['tmp_user_values']['hide_transformation']) {
780 require_once './libraries/transformations.lib.php';
781 $GLOBALS['mime_map'] = PMA_getMIME($db, $table);
784 // See if we have to highlight any header fields of a WHERE query.
785 // Uses SQL-Parser results.
786 $highlight_columns = array();
787 if (isset($analyzed_sql) && isset($analyzed_sql[0]) &&
788 isset($analyzed_sql[0]['where_clause_identifiers'])) {
790 $wi = 0;
791 if (isset($analyzed_sql[0]['where_clause_identifiers']) && is_array($analyzed_sql[0]['where_clause_identifiers'])) {
792 foreach ($analyzed_sql[0]['where_clause_identifiers'] AS $wci_nr => $wci) {
793 $highlight_columns[$wci] = 'true';
798 if (PMA_isSelect()) {
799 // prepare to get the column order, if available
800 $pmatable = new PMA_Table($GLOBALS['table'], $GLOBALS['db']);
801 $col_order = $pmatable->getUiProp(PMA_Table::PROP_COLUMN_ORDER);
802 $col_visib = $pmatable->getUiProp(PMA_Table::PROP_COLUMN_VISIB);
803 } else {
804 $col_order = false;
805 $col_visib = false;
808 for ($j = 0; $j < $fields_cnt; $j++) {
809 // assign $i with appropriate column order
810 $i = $col_order ? $col_order[$j] : $j;
811 // See if this column should get highlight because it's used in the
812 // where-query.
813 if (isset($highlight_columns[$fields_meta[$i]->name]) || isset($highlight_columns[PMA_backquote($fields_meta[$i]->name)])) {
814 $condition_field = true;
815 } else {
816 $condition_field = false;
819 // 2.0 Prepare comment-HTML-wrappers for each row, if defined/enabled.
820 if (isset($comments_map) &&
821 isset($comments_map[$fields_meta[$i]->table]) &&
822 isset($comments_map[$fields_meta[$i]->table][$fields_meta[$i]->name])) {
823 $comments = '<span class="tblcomment">' . htmlspecialchars($comments_map[$fields_meta[$i]->table][$fields_meta[$i]->name]) . '</span>';
824 } else {
825 $comments = '';
828 // 2.1 Results can be sorted
829 if ($is_display['sort_lnk'] == '1') {
831 // 2.1.1 Checks if the table name is required; it's the case
832 // for a query with a "JOIN" statement and if the column
833 // isn't aliased, or in queries like
834 // SELECT `1`.`master_field` , `2`.`master_field`
835 // FROM `PMA_relation` AS `1` , `PMA_relation` AS `2`
837 if (isset($fields_meta[$i]->table) && strlen($fields_meta[$i]->table)) {
838 $sort_tbl = PMA_backquote($fields_meta[$i]->table) . '.';
839 } else {
840 $sort_tbl = '';
843 // 2.1.2 Checks if the current column is used to sort the
844 // results
845 // the orgname member does not exist for all MySQL versions
846 // but if found, it's the one on which to sort
847 $name_to_use_in_sort = $fields_meta[$i]->name;
848 if (isset($fields_meta[$i]->orgname) && strlen($fields_meta[$i]->orgname)) {
849 $name_to_use_in_sort = $fields_meta[$i]->orgname;
851 // $name_to_use_in_sort might contain a space due to
852 // formatting of function expressions like "COUNT(name )"
853 // so we remove the space in this situation
854 $name_to_use_in_sort = str_replace(' )', ')', $name_to_use_in_sort);
856 if (empty($sort_expression)) {
857 $is_in_sort = false;
858 } else {
859 // Field name may be preceded by a space, or any number
860 // of characters followed by a dot (tablename.fieldname)
861 // so do a direct comparison for the sort expression;
862 // this avoids problems with queries like
863 // "SELECT id, count(id)..." and clicking to sort
864 // on id or on count(id).
865 // Another query to test this:
866 // SELECT p.*, FROM_UNIXTIME(p.temps) FROM mytable AS p
867 // (and try clicking on each column's header twice)
868 if (! empty($sort_tbl) && strpos($sort_expression_nodirection, $sort_tbl) === false && strpos($sort_expression_nodirection, '(') === false) {
869 $sort_expression_nodirection = $sort_tbl . $sort_expression_nodirection;
871 $is_in_sort = (str_replace('`', '', $sort_tbl) . $name_to_use_in_sort == str_replace('`', '', $sort_expression_nodirection) ? true : false);
873 // 2.1.3 Check the field name for a bracket.
874 // If it contains one, it's probably a function column
875 // like 'COUNT(`field`)'
876 if (strpos($name_to_use_in_sort, '(') !== false) {
877 $sort_order = ' ORDER BY ' . $name_to_use_in_sort . ' ';
878 } else {
879 $sort_order = ' ORDER BY ' . $sort_tbl . PMA_backquote($name_to_use_in_sort) . ' ';
881 unset($name_to_use_in_sort);
883 // 2.1.4 Do define the sorting URL
884 if (! $is_in_sort) {
885 // patch #455484 ("Smart" order)
886 $GLOBALS['cfg']['Order'] = strtoupper($GLOBALS['cfg']['Order']);
887 if ($GLOBALS['cfg']['Order'] === 'SMART') {
888 $sort_order .= (preg_match('@time|date@i', $fields_meta[$i]->type)) ? 'DESC' : 'ASC';
889 } else {
890 $sort_order .= $GLOBALS['cfg']['Order'];
892 $order_img = '';
893 } elseif ('DESC' == $sort_direction) {
894 $sort_order .= ' ASC';
895 $order_img = ' <img class="icon" src="' . $GLOBALS['pmaThemeImage'] . 's_desc.png" width="11" height="9" alt="'. __('Descending') . '" title="'. __('Descending') . '" id="soimg' . $i . '" />';
896 } else {
897 $sort_order .= ' DESC';
898 $order_img = ' <img class="icon" src="' . $GLOBALS['pmaThemeImage'] . 's_asc.png" width="11" height="9" alt="'. __('Ascending') . '" title="'. __('Ascending') . '" id="soimg' . $i . '" />';
901 if (preg_match('@(.*)([[:space:]](LIMIT (.*)|PROCEDURE (.*)|FOR UPDATE|LOCK IN SHARE MODE))@is', $unsorted_sql_query, $regs3)) {
902 $sorted_sql_query = $regs3[1] . $sort_order . $regs3[2];
903 } else {
904 $sorted_sql_query = $unsorted_sql_query . $sort_order;
906 $_url_params = array(
907 'db' => $db,
908 'table' => $table,
909 'sql_query' => $sorted_sql_query,
910 'session_max_rows' => $session_max_rows
912 $order_url = 'sql.php' . PMA_generate_common_url($_url_params);
914 // 2.1.5 Displays the sorting URL
915 // enable sort order swapping for image
916 $order_link_params = array();
917 if (isset($order_img) && $order_img!='') {
918 if (strstr($order_img, 'asc')) {
919 $order_link_params['onmouseover'] = 'if(document.getElementById(\'soimg' . $i . '\')){ document.getElementById(\'soimg' . $i . '\').src=\'' . $GLOBALS['pmaThemeImage'] . 's_desc.png\'; }';
920 $order_link_params['onmouseout'] = 'if(document.getElementById(\'soimg' . $i . '\')){ document.getElementById(\'soimg' . $i . '\').src=\'' . $GLOBALS['pmaThemeImage'] . 's_asc.png\'; }';
921 } elseif (strstr($order_img, 'desc')) {
922 $order_link_params['onmouseover'] = 'if(document.getElementById(\'soimg' . $i . '\')){ document.getElementById(\'soimg' . $i . '\').src=\'' . $GLOBALS['pmaThemeImage'] . 's_asc.png\'; }';
923 $order_link_params['onmouseout'] = 'if(document.getElementById(\'soimg' . $i . '\')){ document.getElementById(\'soimg' . $i . '\').src=\'' . $GLOBALS['pmaThemeImage'] . 's_desc.png\'; }';
926 if ($GLOBALS['cfg']['HeaderFlipType'] == 'auto') {
927 if (PMA_USR_BROWSER_AGENT == 'IE') {
928 $GLOBALS['cfg']['HeaderFlipType'] = 'css';
929 } else {
930 $GLOBALS['cfg']['HeaderFlipType'] = 'fake';
933 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped'
934 && $GLOBALS['cfg']['HeaderFlipType'] == 'css') {
935 $order_link_params['style'] = 'direction: ltr; writing-mode: tb-rl;';
937 $order_link_params['title'] = __('Sort');
938 $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));
939 $order_link = PMA_linkOrButton($order_url, $order_link_content . $order_img, $order_link_params, false, true);
941 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
942 || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') {
943 echo '<th';
944 $th_class = array();
945 $th_class[] = 'draggable';
946 if ($col_visib && !$col_visib[$j]) {
947 $th_class[] = 'hide';
949 if ($condition_field) {
950 $th_class[] = 'condition';
952 $th_class[] = 'column_heading';
953 if ($GLOBALS['cfg']['BrowsePointerEnable'] == true) {
954 $th_class[] = 'pointer';
956 if ($GLOBALS['cfg']['BrowseMarkerEnable'] == true) {
957 $th_class[] = 'marker';
959 echo ' class="' . implode(' ', $th_class) . '"';
961 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') {
962 echo ' valign="bottom"';
964 echo '>' . $order_link . $comments . '</th>';
966 $vertical_display['desc'][] = ' <th '
967 . 'class="draggable'
968 . ($condition_field ? ' condition' : '')
969 . '">' . "\n"
970 . $order_link . $comments . ' </th>' . "\n";
971 } // end if (2.1)
973 // 2.2 Results can't be sorted
974 else {
975 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
976 || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') {
977 echo '<th';
978 $th_class = array();
979 $th_class[] = 'draggable';
980 if ($col_visib && !$col_visib[$j]) {
981 $th_class[] = 'hide';
983 if ($condition_field) {
984 $th_class[] = 'condition';
986 echo ' class="' . implode(' ', $th_class) . '"';
987 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') {
988 echo ' valign="bottom"';
990 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped'
991 && $GLOBALS['cfg']['HeaderFlipType'] == 'css') {
992 echo ' style="direction: ltr; writing-mode: tb-rl;"';
994 echo '>';
995 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped'
996 && $GLOBALS['cfg']['HeaderFlipType'] == 'fake') {
997 echo PMA_flipstring(htmlspecialchars($fields_meta[$i]->name), '<br />');
998 } else {
999 echo htmlspecialchars($fields_meta[$i]->name);
1001 echo "\n" . $comments . '</th>';
1003 $vertical_display['desc'][] = ' <th '
1004 . 'class="draggable'
1005 . ($condition_field ? ' condition"' : '')
1006 . '">' . "\n"
1007 . ' ' . htmlspecialchars($fields_meta[$i]->name) . "\n"
1008 . $comments . ' </th>';
1009 } // end else (2.2)
1010 } // end for
1012 // 3. Displays the needed checkboxes at the right
1013 // column of the result table header if possible and required...
1014 if (($GLOBALS['cfg']['RowActionLinks'] == 'right' || $GLOBALS['cfg']['RowActionLinks'] == 'both')
1015 && ($is_display['edit_lnk'] != 'nn' || $is_display['del_lnk'] != 'nn')
1016 && $is_display['text_btn'] == '1') {
1017 $vertical_display['emptyafter'] = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn') ? 4 : 1;
1018 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
1019 || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') {
1020 echo "\n";
1022 <th <?php echo $colspan; ?>><?php echo $full_or_partial_text_link;?>
1023 </th>
1024 <?php
1025 } // end horizontal/horizontalflipped mode
1026 else {
1027 $vertical_display['textbtn'] = ' <th ' . $rowspan . ' valign="middle">' . "\n"
1028 . ' ' . "\n"
1029 . ' </th>' . "\n";
1030 } // end vertical mode
1033 // ... elseif no button, displays empty columns if required
1034 // (unless coming from Browse mode print view)
1035 elseif (($GLOBALS['cfg']['RowActionLinks'] == 'left' || $GLOBALS['cfg']['RowActionLinks'] == 'both')
1036 && ($is_display['edit_lnk'] == 'nn' && $is_display['del_lnk'] == 'nn')
1037 && (!$GLOBALS['is_header_sent'])) {
1038 $vertical_display['emptyafter'] = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn') ? 4 : 1;
1039 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
1040 || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') {
1041 echo "\n";
1043 <td<?php echo $colspan; ?>></td>
1044 <?php
1045 } // end horizontal/horizontalflipped mode
1046 else {
1047 $vertical_display['textbtn'] = ' <td' . $rowspan . '></td>' . "\n";
1048 } // end vertical mode
1051 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
1052 || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') {
1054 </tr>
1055 </thead>
1056 <?php
1059 return true;
1060 } // end of the 'PMA_displayTableHeaders()' function
1064 * Prepares the display for a value
1066 * @param string $class
1067 * @param string $condition_field
1068 * @param string $value
1070 * @return string the td
1072 function PMA_buildValueDisplay($class, $condition_field, $value) {
1073 return '<td align="left"' . ' class="' . $class . ($condition_field ? ' condition' : '') . '">' . $value . '</td>';
1077 * Prepares the display for a null value
1079 * @param string $class
1080 * @param string $condition_field
1082 * @return string the td
1084 function PMA_buildNullDisplay($class, $condition_field) {
1085 // the null class is needed for inline editing
1086 return '<td align="right"' . ' class="' . $class . ($condition_field ? ' condition' : '') . ' null"><i>NULL</i></td>';
1090 * Prepares the display for an empty value
1092 * @param string $class
1093 * @param string $condition_field
1094 * @param string $align
1096 * @return string the td
1098 function PMA_buildEmptyDisplay($class, $condition_field, $meta, $align = '') {
1099 $nowrap = ' nowrap';
1100 return '<td ' . $align . ' class="' . PMA_addClass($class, $condition_field, $meta, $nowrap) . '"></td>';
1104 * Adds the relavant classes.
1106 * @param string $class
1107 * @param string $condition_field
1108 * @param object $meta the meta-information about this field
1109 * @param string $nowrap
1110 * @param bool $is_field_truncated
1111 * @param string $transform_function
1112 * @param string $default_function
1114 * @return string the list of classes
1116 function PMA_addClass($class, $condition_field, $meta, $nowrap, $is_field_truncated = false, $transform_function = '', $default_function = '') {
1117 // Define classes to be added to this data field based on the type of data
1118 $enum_class = '';
1119 if(strpos($meta->flags, 'enum') !== false) {
1120 $enum_class = ' enum';
1123 $set_class = '';
1124 if(strpos($meta->flags, 'set') !== false) {
1125 $set_class = ' set';
1128 $bit_class = '';
1129 if(strpos($meta->type, 'bit') !== false) {
1130 $bit_class = ' bit';
1133 $mime_type_class = '';
1134 if(isset($meta->mimetype)) {
1135 $mime_type_class = ' ' . preg_replace('/\//', '_', $meta->mimetype);
1138 $result = $class . ($condition_field ? ' condition' : '') . $nowrap
1139 . ' ' . ($is_field_truncated ? ' truncated' : '')
1140 . ($transform_function != $default_function ? ' transformed' : '')
1141 . $enum_class . $set_class . $bit_class . $mime_type_class;
1143 return $result;
1146 * Displays the body of the results table
1148 * @param integer the link id associated to the query which results have
1149 * to be displayed
1150 * @param array which elements to display
1151 * @param array the list of relations
1152 * @param array the analyzed query
1154 * @return boolean always true
1156 * @global string $db the database name
1157 * @global string $table the table name
1158 * @global string $goto the URL to go back in case of errors
1159 * @global string $sql_query the SQL query
1160 * @global array $fields_meta the list of fields properties
1161 * @global integer $fields_cnt the total number of fields returned by
1162 * the SQL query
1163 * @global array $vertical_display informations used with vertical display
1164 * mode
1165 * @global array $highlight_columns column names to highlight
1166 * @global array $row current row data
1168 * @access private
1170 * @see PMA_displayTable()
1172 function PMA_displayTableBody(&$dt_result, &$is_display, $map, $analyzed_sql) {
1173 global $db, $table, $goto;
1174 global $sql_query, $fields_meta, $fields_cnt;
1175 global $vertical_display, $highlight_columns;
1176 global $row; // mostly because of browser transformations, to make the row-data accessible in a plugin
1178 $url_sql_query = $sql_query;
1180 // query without conditions to shorten URLs when needed, 200 is just
1181 // guess, it should depend on remaining URL length
1183 if (isset($analyzed_sql) && isset($analyzed_sql[0]) &&
1184 isset($analyzed_sql[0]['querytype']) && $analyzed_sql[0]['querytype'] == 'SELECT' &&
1185 strlen($sql_query) > 200) {
1187 $url_sql_query = 'SELECT ';
1188 if (isset($analyzed_sql[0]['queryflags']['distinct'])) {
1189 $url_sql_query .= ' DISTINCT ';
1191 $url_sql_query .= $analyzed_sql[0]['select_expr_clause'];
1192 if (!empty($analyzed_sql[0]['from_clause'])) {
1193 $url_sql_query .= ' FROM ' . $analyzed_sql[0]['from_clause'];
1197 if (! is_array($map)) {
1198 $map = array();
1200 $row_no = 0;
1201 $vertical_display['edit'] = array();
1202 $vertical_display['copy'] = array();
1203 $vertical_display['delete'] = array();
1204 $vertical_display['data'] = array();
1205 $vertical_display['row_delete'] = array();
1206 // name of the class added to all inline editable elements
1207 $inline_edit_class = 'inline_edit';
1209 // prepare to get the column order, if available
1210 if (PMA_isSelect()) {
1211 $pmatable = new PMA_Table($GLOBALS['table'], $GLOBALS['db']);
1212 $col_order = $pmatable->getUiProp(PMA_Table::PROP_COLUMN_ORDER);
1213 $col_visib = $pmatable->getUiProp(PMA_Table::PROP_COLUMN_VISIB);
1214 } else {
1215 $col_order = false;
1216 $col_visib = false;
1219 // Correction University of Virginia 19991216 in the while below
1220 // Previous code assumed that all tables have keys, specifically that
1221 // the phpMyAdmin GUI should support row delete/edit only for such
1222 // tables.
1223 // Although always using keys is arguably the prescribed way of
1224 // defining a relational table, it is not required. This will in
1225 // particular be violated by the novice.
1226 // We want to encourage phpMyAdmin usage by such novices. So the code
1227 // below has been changed to conditionally work as before when the
1228 // table being displayed has one or more keys; but to display
1229 // delete/edit options correctly for tables without keys.
1231 $odd_row = true;
1232 while ($row = PMA_DBI_fetch_row($dt_result)) {
1233 // "vertical display" mode stuff
1234 if ($row_no != 0 && $_SESSION['tmp_user_values']['repeat_cells'] != 0 && !($row_no % $_SESSION['tmp_user_values']['repeat_cells'])
1235 && ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
1236 || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped'))
1238 echo '<tr>' . "\n";
1239 if ($vertical_display['emptypre'] > 0) {
1240 echo ' <th colspan="' . $vertical_display['emptypre'] . '">' . "\n"
1241 .' &nbsp;</th>' . "\n";
1242 } else if ($GLOBALS['cfg']['RowActionLinks'] == 'none') {
1243 echo ' <th></th>' . "\n";
1246 foreach ($vertical_display['desc'] as $val) {
1247 echo $val;
1250 if ($vertical_display['emptyafter'] > 0) {
1251 echo ' <th colspan="' . $vertical_display['emptyafter'] . '">' . "\n"
1252 .' &nbsp;</th>' . "\n";
1254 echo '</tr>' . "\n";
1255 } // end if
1257 $alternating_color_class = ($odd_row ? 'odd' : 'even');
1258 $odd_row = ! $odd_row;
1260 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
1261 || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') {
1262 // pointer code part
1263 echo '<tr class="' . $alternating_color_class . '">';
1267 // 1. Prepares the row
1268 // 1.1 Results from a "SELECT" statement -> builds the
1269 // WHERE clause to use in links (a unique key if possible)
1271 * @todo $where_clause could be empty, for example a table
1272 * with only one field and it's a BLOB; in this case,
1273 * avoid to display the delete and edit links
1275 list($where_clause, $clause_is_unique) = PMA_getUniqueCondition($dt_result, $fields_cnt, $fields_meta, $row);
1276 $where_clause_html = urlencode($where_clause);
1278 // 1.2 Defines the URLs for the modify/delete link(s)
1280 if ($is_display['edit_lnk'] != 'nn' || $is_display['del_lnk'] != 'nn') {
1281 // We need to copy the value or else the == 'both' check will always return true
1283 if ($GLOBALS['cfg']['PropertiesIconic'] === 'both') {
1284 $iconic_spacer = '<div class="nowrap">';
1285 } else {
1286 $iconic_spacer = '';
1289 // 1.2.1 Modify link(s)
1290 if ($is_display['edit_lnk'] == 'ur') { // update row case
1291 $_url_params = array(
1292 'db' => $db,
1293 'table' => $table,
1294 'where_clause' => $where_clause,
1295 'clause_is_unique' => $clause_is_unique,
1296 'sql_query' => $url_sql_query,
1297 'goto' => 'sql.php',
1299 $edit_url = 'tbl_change.php' . PMA_generate_common_url($_url_params + array('default_action' => 'update'));
1300 $copy_url = 'tbl_change.php' . PMA_generate_common_url($_url_params + array('default_action' => 'insert'));
1302 $edit_str = PMA_getIcon('b_edit.png', __('Edit'), true);
1303 $copy_str = PMA_getIcon('b_insrow.png', __('Copy'), true);
1305 // Class definitions required for inline editing jQuery scripts
1306 $edit_anchor_class = "edit_row_anchor";
1307 if( $clause_is_unique == 0) {
1308 $edit_anchor_class .= ' nonunique';
1310 } // end if (1.2.1)
1312 // 1.2.2 Delete/Kill link(s)
1313 if ($is_display['del_lnk'] == 'dr') { // delete row case
1314 $_url_params = array(
1315 'db' => $db,
1316 'table' => $table,
1317 'sql_query' => $url_sql_query,
1318 'message_to_show' => __('The row has been deleted'),
1319 'goto' => (empty($goto) ? 'tbl_sql.php' : $goto),
1321 $lnk_goto = 'sql.php' . PMA_generate_common_url($_url_params, 'text');
1323 $del_query = 'DELETE FROM ' . PMA_backquote($db) . '.' . PMA_backquote($table)
1324 . ' WHERE ' . $where_clause . ($clause_is_unique ? '' : ' LIMIT 1');
1326 $_url_params = array(
1327 'db' => $db,
1328 'table' => $table,
1329 'sql_query' => $del_query,
1330 'message_to_show' => __('The row has been deleted'),
1331 'goto' => $lnk_goto,
1333 $del_url = 'sql.php' . PMA_generate_common_url($_url_params);
1335 $js_conf = 'DELETE FROM ' . PMA_jsFormat($db) . '.' . PMA_jsFormat($table)
1336 . ' WHERE ' . PMA_jsFormat($where_clause, false)
1337 . ($clause_is_unique ? '' : ' LIMIT 1');
1338 $del_str = PMA_getIcon('b_drop.png', __('Delete'), true);
1339 } elseif ($is_display['del_lnk'] == 'kp') { // kill process case
1341 $_url_params = array(
1342 'db' => $db,
1343 'table' => $table,
1344 'sql_query' => $url_sql_query,
1345 'goto' => 'main.php',
1347 $lnk_goto = 'sql.php' . PMA_generate_common_url($_url_params, 'text');
1349 $_url_params = array(
1350 'db' => 'mysql',
1351 'sql_query' => 'KILL ' . $row[0],
1352 'goto' => $lnk_goto,
1354 $del_url = 'sql.php' . PMA_generate_common_url($_url_params);
1355 $del_query = 'KILL ' . $row[0];
1356 $js_conf = 'KILL ' . $row[0];
1357 $del_str = PMA_getIcon('b_drop.png', __('Kill'), true);
1358 } // end if (1.2.2)
1360 // 1.3 Displays the links at left if required
1361 if (($GLOBALS['cfg']['RowActionLinks'] == 'left' || $GLOBALS['cfg']['RowActionLinks'] == 'both')
1362 && ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
1363 || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped')) {
1364 if (! isset($js_conf)) {
1365 $js_conf = '';
1367 echo PMA_generateCheckboxAndLinks('left', $del_url, $is_display, $row_no, $where_clause, $where_clause_html, $del_query, 'l', $edit_url, $copy_url, $edit_anchor_class, $edit_str, $copy_str, $del_str, $js_conf);
1368 } else if (($GLOBALS['cfg']['RowActionLinks'] == 'none')
1369 && ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
1370 || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped')) {
1371 if (! isset($js_conf)) {
1372 $js_conf = '';
1374 echo PMA_generateCheckboxAndLinks('none', $del_url, $is_display, $row_no, $where_clause, $where_clause_html, $del_query, 'l', $edit_url, $copy_url, $edit_anchor_class, $edit_str, $copy_str, $del_str, $js_conf);
1375 } // end if (1.3)
1376 } // end if (1)
1378 // 2. Displays the rows' values
1380 for ($j = 0; $j < $fields_cnt; ++$j) {
1381 // assign $i with appropriate column order
1382 $i = $col_order ? $col_order[$j] : $j;
1384 $meta = $fields_meta[$i];
1385 $not_null_class = $meta->not_null ? 'not_null' : '';
1386 $relation_class = isset($map[$meta->name]) ? 'relation' : '';
1387 $hide_class = ($col_visib && !$col_visib[$j] &&
1388 // hide per <td> only if the display direction is not vertical
1389 $_SESSION['tmp_user_values']['disp_direction'] != 'vertical') ? 'hide' : '';
1390 $pointer = $i;
1391 $is_field_truncated = false;
1392 //If the previous column had blob data, we need to reset the class
1393 // to $inline_edit_class
1394 $class = 'data ' . $inline_edit_class . ' ' . $not_null_class . ' ' . $alternating_color_class . ' ' . $relation_class . ' ' . $hide_class;
1396 // See if this column should get highlight because it's used in the
1397 // where-query.
1398 if (isset($highlight_columns) && (isset($highlight_columns[$meta->name]) || isset($highlight_columns[PMA_backquote($meta->name)]))) {
1399 $condition_field = true;
1400 } else {
1401 $condition_field = false;
1404 if ($_SESSION['tmp_user_values']['disp_direction'] == 'vertical' && (! isset($GLOBALS['printview']) || ($GLOBALS['printview'] != '1'))) {
1405 // the row number corresponds to a data row, not HTML table row
1406 $class .= ' row_' . $row_no;
1407 if ($GLOBALS['cfg']['BrowsePointerEnable'] == true) {
1408 $class .= ' vpointer';
1410 if ($GLOBALS['cfg']['BrowseMarkerEnable'] == true) {
1411 $class .= ' vmarker';
1413 }// end if
1415 // Wrap MIME-transformations. [MIME]
1416 $default_function = 'default_function'; // default_function
1417 $transform_function = $default_function;
1418 $transform_options = array();
1420 if ($GLOBALS['cfgRelation']['mimework'] && $GLOBALS['cfg']['BrowseMIME']) {
1422 if (isset($GLOBALS['mime_map'][$meta->name]['mimetype']) && isset($GLOBALS['mime_map'][$meta->name]['transformation']) && !empty($GLOBALS['mime_map'][$meta->name]['transformation'])) {
1423 $include_file = PMA_securePath($GLOBALS['mime_map'][$meta->name]['transformation']);
1425 if (file_exists('./libraries/transformations/' . $include_file)) {
1426 $transformfunction_name = str_replace('.inc.php', '', $GLOBALS['mime_map'][$meta->name]['transformation']);
1428 require_once './libraries/transformations/' . $include_file;
1430 if (function_exists('PMA_transformation_' . $transformfunction_name)) {
1431 $transform_function = 'PMA_transformation_' . $transformfunction_name;
1432 $transform_options = PMA_transformation_getOptions((isset($GLOBALS['mime_map'][$meta->name]['transformation_options']) ? $GLOBALS['mime_map'][$meta->name]['transformation_options'] : ''));
1433 $meta->mimetype = str_replace('_', '/', $GLOBALS['mime_map'][$meta->name]['mimetype']);
1435 } // end if file_exists
1436 } // end if transformation is set
1437 } // end if mime/transformation works.
1439 $_url_params = array(
1440 'db' => $db,
1441 'table' => $table,
1442 'where_clause' => $where_clause,
1443 'transform_key' => $meta->name,
1446 if (! empty($sql_query)) {
1447 $_url_params['sql_query'] = $url_sql_query;
1450 $transform_options['wrapper_link'] = PMA_generate_common_url($_url_params);
1452 // n u m e r i c
1453 if ($meta->numeric == 1) {
1455 // if two fields have the same name (this is possible
1456 // with self-join queries, for example), using $meta->name
1457 // will show both fields NULL even if only one is NULL,
1458 // so use the $pointer
1460 if (! isset($row[$i]) || is_null($row[$i])) {
1461 $vertical_display['data'][$row_no][$i] = PMA_buildNullDisplay($class, $condition_field);
1462 } elseif ($row[$i] != '') {
1464 $nowrap = ' nowrap';
1465 $where_comparison = ' = ' . $row[$i];
1467 $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);
1468 } else {
1469 $vertical_display['data'][$row_no][$i] = PMA_buildEmptyDisplay($class, $condition_field, $meta, 'align="right"');
1472 // b l o b
1474 } elseif (stristr($meta->type, 'BLOB')) {
1475 // PMA_mysql_fetch_fields returns BLOB in place of
1476 // TEXT fields type so we have to ensure it's really a BLOB
1477 $field_flags = PMA_DBI_field_flags($dt_result, $i);
1479 // remove 'inline_edit' from $class as we can't edit binary data.
1480 $class = str_replace('inline_edit', '', $class);
1482 if (stristr($field_flags, 'BINARY')) {
1483 if (! isset($row[$i]) || is_null($row[$i])) {
1484 $vertical_display['data'][$row_no][$i] = PMA_buildNullDisplay($class, $condition_field);
1485 } else {
1486 // for blobstreaming
1487 // if valid BS reference exists
1488 if (PMA_BS_IsPBMSReference($row[$i], $db)) {
1489 $blobtext = PMA_BS_CreateReferenceLink($row[$i], $db);
1490 } else {
1491 $blobtext = PMA_handle_non_printable_contents('BLOB', (isset($row[$i]) ? $row[$i] : ''), $transform_function, $transform_options, $default_function, $meta, $_url_params);
1494 $vertical_display['data'][$row_no][$i] = PMA_buildValueDisplay($class, $condition_field, $blobtext);
1495 unset($blobtext);
1497 // not binary:
1498 } else {
1499 if (! isset($row[$i]) || is_null($row[$i])) {
1500 $vertical_display['data'][$row_no][$i] = PMA_buildNullDisplay($class, $condition_field);
1501 } elseif ($row[$i] != '') {
1502 // if a transform function for blob is set, none of these replacements will be made
1503 if (PMA_strlen($row[$i]) > $GLOBALS['cfg']['LimitChars'] && $_SESSION['tmp_user_values']['display_text'] == 'P') {
1504 $row[$i] = PMA_substr($row[$i], 0, $GLOBALS['cfg']['LimitChars']) . '...';
1505 $is_field_truncated = true;
1507 // displays all space characters, 4 space
1508 // characters for tabulations and <cr>/<lf>
1509 $row[$i] = ($default_function != $transform_function ? $transform_function($row[$i], $transform_options, $meta) : $default_function($row[$i], array(), $meta));
1511 $vertical_display['data'][$row_no][$i] = PMA_buildValueDisplay($class, $condition_field, $row[$i]);
1512 } else {
1513 $vertical_display['data'][$row_no][$i] = PMA_buildEmptyDisplay($class, $condition_field, $meta);
1516 // g e o m e t r y
1517 } elseif ($meta->type == 'geometry') {
1519 // Remove 'inline_edit' from $class as we do not allow to inline-edit geometry data.
1520 $class = str_replace('inline_edit', '', $class);
1522 // Display as [GEOMETRY - (size)]
1523 if ('GEOM' == $_SESSION['tmp_user_values']['geometry_display']) {
1524 $geometry_text = PMA_handle_non_printable_contents(
1525 'GEOMETRY', (isset($row[$i]) ? $row[$i] : ''), $transform_function,
1526 $transform_options, $default_function, $meta
1528 $vertical_display['data'][$row_no][$i] = PMA_buildValueDisplay(
1529 $class, $condition_field, $geometry_text
1532 // Display in Well Known Text(WKT) format.
1533 } elseif ('WKT' == $_SESSION['tmp_user_values']['geometry_display']) {
1534 // Convert to WKT format
1535 $wktsql = "SELECT ASTEXT (GeomFromWKB(x'" . PMA_substr(bin2hex($row[$i]), 8) . "'))";
1536 $wktresult = PMA_DBI_try_query($wktsql, null, PMA_DBI_QUERY_STORE);
1537 $wktarr = PMA_DBI_fetch_row($wktresult, 0);
1538 $wktval = $wktarr[0];
1539 @PMA_DBI_free_result($wktresult);
1541 if (PMA_strlen($wktval) > $GLOBALS['cfg']['LimitChars']
1542 && $_SESSION['tmp_user_values']['display_text'] == 'P'
1544 $wktval = PMA_substr($wktval, 0, $GLOBALS['cfg']['LimitChars']) . '...';
1545 $is_field_truncated = true;
1548 $vertical_display['data'][$row_no][$i] = '<td ' . PMA_prepare_row_data(
1549 $class, $condition_field, $analyzed_sql, $meta, $map, $wktval, $transform_function,
1550 $default_function, $nowrap, $where_comparison, $transform_options, $is_field_truncated
1553 // Display in Well Known Binary(WKB) format.
1554 } else {
1555 if ($_SESSION['tmp_user_values']['display_binary']) {
1556 if ($_SESSION['tmp_user_values']['display_binary_as_hex']
1557 && PMA_contains_nonprintable_ascii($row[$i])
1559 $wkbval = PMA_substr(bin2hex($row[$i]), 8);
1560 } else {
1561 $wkbval = htmlspecialchars(PMA_replace_binary_contents($row[$i]));
1564 if (PMA_strlen($wkbval) > $GLOBALS['cfg']['LimitChars']
1565 && $_SESSION['tmp_user_values']['display_text'] == 'P'
1567 $wkbval = PMA_substr($wkbval, 0, $GLOBALS['cfg']['LimitChars']) . '...';
1568 $is_field_truncated = true;
1571 $vertical_display['data'][$row_no][$i] = '<td ' . PMA_prepare_row_data(
1572 $class, $condition_field, $analyzed_sql, $meta, $map, $wkbval, $transform_function,
1573 $default_function, $nowrap, $where_comparison, $transform_options, $is_field_truncated
1575 } else {
1576 $wkbval = PMA_handle_non_printable_contents(
1577 'BINARY', $row[$i], $transform_function, $transform_options, $default_function, $meta, $_url_params
1579 $vertical_display['data'][$row_no][$i] = PMA_buildValueDisplay($class, $condition_field, $wkbval);
1583 // n o t n u m e r i c a n d n o t B L O B
1584 } else {
1585 if (! isset($row[$i]) || is_null($row[$i])) {
1586 $vertical_display['data'][$row_no][$i] = PMA_buildNullDisplay($class, $condition_field);
1587 } elseif ($row[$i] != '') {
1588 // support blanks in the key
1589 $relation_id = $row[$i];
1591 // Cut all fields to $GLOBALS['cfg']['LimitChars']
1592 // (unless it's a link-type transformation)
1593 if (PMA_strlen($row[$i]) > $GLOBALS['cfg']['LimitChars'] && $_SESSION['tmp_user_values']['display_text'] == 'P' && !strpos($transform_function, 'link') === true) {
1594 $row[$i] = PMA_substr($row[$i], 0, $GLOBALS['cfg']['LimitChars']) . '...';
1595 $is_field_truncated = true;
1598 // displays special characters from binaries
1599 $field_flags = PMA_DBI_field_flags($dt_result, $i);
1600 if (isset($meta->_type) && $meta->_type === MYSQLI_TYPE_BIT) {
1601 $row[$i] = PMA_printable_bit_value($row[$i], $meta->length);
1602 // some results of PROCEDURE ANALYSE() are reported as
1603 // being BINARY but they are quite readable,
1604 // so don't treat them as BINARY
1605 } elseif (stristr($field_flags, 'BINARY') && $meta->type == 'string' && !(isset($GLOBALS['is_analyse']) && $GLOBALS['is_analyse'])) {
1606 if ($_SESSION['tmp_user_values']['display_binary']) {
1607 // user asked to see the real contents of BINARY
1608 // fields
1609 if ($_SESSION['tmp_user_values']['display_binary_as_hex'] && PMA_contains_nonprintable_ascii($row[$i])) {
1610 $row[$i] = bin2hex($row[$i]);
1611 } else {
1612 $row[$i] = htmlspecialchars(PMA_replace_binary_contents($row[$i]));
1614 } else {
1615 // we show the BINARY message and field's size
1616 // (or maybe use a transformation)
1617 $row[$i] = PMA_handle_non_printable_contents('BINARY', $row[$i], $transform_function, $transform_options, $default_function, $meta, $_url_params);
1621 // transform functions may enable no-wrapping:
1622 $function_nowrap = $transform_function . '_nowrap';
1623 $bool_nowrap = (($default_function != $transform_function && function_exists($function_nowrap)) ? $function_nowrap($transform_options) : false);
1625 // do not wrap if date field type
1626 $nowrap = ((preg_match('@DATE|TIME@i', $meta->type) || $bool_nowrap) ? ' nowrap' : '');
1627 $where_comparison = ' = \'' . PMA_sqlAddSlashes($row[$i]) . '\'';
1628 $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);
1630 } else {
1631 $vertical_display['data'][$row_no][$i] = PMA_buildEmptyDisplay($class, $condition_field, $meta);
1635 // output stored cell
1636 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
1637 || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') {
1638 echo $vertical_display['data'][$row_no][$i];
1641 if (isset($vertical_display['rowdata'][$i][$row_no])) {
1642 $vertical_display['rowdata'][$i][$row_no] .= $vertical_display['data'][$row_no][$i];
1643 } else {
1644 $vertical_display['rowdata'][$i][$row_no] = $vertical_display['data'][$row_no][$i];
1646 } // end for (2)
1648 // 3. Displays the modify/delete links on the right if required
1649 if (($GLOBALS['cfg']['RowActionLinks'] == 'right' || $GLOBALS['cfg']['RowActionLinks'] == 'both')
1650 && ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
1651 || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped')) {
1652 if (! isset($js_conf)) {
1653 $js_conf = '';
1655 echo PMA_generateCheckboxAndLinks('right', $del_url, $is_display, $row_no, $where_clause, $where_clause_html, $del_query, 'r', $edit_url, $copy_url, $edit_anchor_class, $edit_str, $copy_str, $del_str, $js_conf);
1656 } // end if (3)
1658 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
1659 || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') {
1661 </tr>
1662 <?php
1663 } // end if
1665 // 4. Gather links of del_urls and edit_urls in an array for later
1666 // output
1667 if (! isset($vertical_display['edit'][$row_no])) {
1668 $vertical_display['edit'][$row_no] = '';
1669 $vertical_display['copy'][$row_no] = '';
1670 $vertical_display['delete'][$row_no] = '';
1671 $vertical_display['row_delete'][$row_no] = '';
1673 $vertical_class = ' row_' . $row_no;
1674 if ($GLOBALS['cfg']['BrowsePointerEnable'] == true) {
1675 $vertical_class .= ' vpointer';
1677 if ($GLOBALS['cfg']['BrowseMarkerEnable'] == true) {
1678 $vertical_class .= ' vmarker';
1681 if (!empty($del_url) && $is_display['del_lnk'] != 'kp') {
1682 $vertical_display['row_delete'][$row_no] .= PMA_generateCheckboxForMulti($del_url, $is_display, $row_no, $where_clause_html, $del_query, '[%_PMA_CHECKBOX_DIR_%]', $alternating_color_class . $vertical_class);
1683 } else {
1684 unset($vertical_display['row_delete'][$row_no]);
1687 if (isset($edit_url)) {
1688 $vertical_display['edit'][$row_no] .= PMA_generateEditLink($edit_url, $alternating_color_class . ' ' . $edit_anchor_class . $vertical_class, $edit_str, $where_clause, $where_clause_html);
1689 } else {
1690 unset($vertical_display['edit'][$row_no]);
1693 if (isset($copy_url)) {
1694 $vertical_display['copy'][$row_no] .= PMA_generateCopyLink($copy_url, $copy_str, $where_clause, $where_clause_html, $alternating_color_class . $vertical_class);
1695 } else {
1696 unset($vertical_display['copy'][$row_no]);
1699 if (isset($del_url)) {
1700 if (! isset($js_conf)) {
1701 $js_conf = '';
1703 $vertical_display['delete'][$row_no] .= PMA_generateDeleteLink($del_url, $del_str, $js_conf, $alternating_color_class . $vertical_class);
1704 } else {
1705 unset($vertical_display['delete'][$row_no]);
1708 echo (($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal' || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') ? "\n" : '');
1709 $row_no++;
1710 } // end while
1712 // this is needed by PMA_displayTable() to generate the proper param
1713 // in the multi-edit and multi-delete form
1714 return $clause_is_unique;
1715 } // end of the 'PMA_displayTableBody()' function
1719 * Do display the result table with the vertical direction mode.
1721 * @return boolean always true
1723 * @global array $vertical_display the information to display
1725 * @access private
1727 * @see PMA_displayTable()
1729 function PMA_displayVerticalTable()
1731 global $vertical_display;
1733 // Displays "multi row delete" link at top if required
1734 if (($GLOBALS['cfg']['RowActionLinks'] != 'right')
1735 && is_array($vertical_display['row_delete']) && (count($vertical_display['row_delete']) > 0 || !empty($vertical_display['textbtn']))) {
1736 echo '<tr>' . "\n";
1737 if ($GLOBALS['cfg']['RowActionLinks'] == 'none') {
1738 // if we are not showing the RowActionLinks, then we need to show the Multi-Row-Action checkboxes
1739 echo '<th></th>' . "\n";
1741 echo $vertical_display['textbtn'];
1742 $cell_displayed = 0;
1743 foreach ($vertical_display['row_delete'] as $val) {
1744 if (($cell_displayed != 0) && ($_SESSION['tmp_user_values']['repeat_cells'] != 0) && !($cell_displayed % $_SESSION['tmp_user_values']['repeat_cells'])) {
1745 echo '<th' .
1746 (($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn') ? ' rowspan="4"' : '') .
1747 '></th>' . "\n";
1749 echo str_replace('[%_PMA_CHECKBOX_DIR_%]', '_left', $val);
1750 $cell_displayed++;
1751 } // end while
1752 echo '</tr>' . "\n";
1753 } // end if
1755 // Displays "edit" link at top if required
1756 if (($GLOBALS['cfg']['RowActionLinks'] == 'left' || $GLOBALS['cfg']['RowActionLinks'] == 'both')
1757 && is_array($vertical_display['edit']) && (count($vertical_display['edit']) > 0 || !empty($vertical_display['textbtn']))) {
1758 echo '<tr>' . "\n";
1759 if (! is_array($vertical_display['row_delete'])) {
1760 echo $vertical_display['textbtn'];
1762 foreach ($vertical_display['edit'] as $val) {
1763 echo $val;
1764 } // end while
1765 echo '</tr>' . "\n";
1766 } // end if
1768 // Displays "copy" link at top if required
1769 if (($GLOBALS['cfg']['RowActionLinks'] == 'left' || $GLOBALS['cfg']['RowActionLinks'] == 'both')
1770 && is_array($vertical_display['copy']) && (count($vertical_display['copy']) > 0 || !empty($vertical_display['textbtn']))) {
1771 echo '<tr>' . "\n";
1772 if (! is_array($vertical_display['row_delete'])) {
1773 echo $vertical_display['textbtn'];
1775 foreach ($vertical_display['copy'] as $val) {
1776 echo $val;
1777 } // end while
1778 echo '</tr>' . "\n";
1779 } // end if
1781 // Displays "delete" link at top if required
1782 if (($GLOBALS['cfg']['RowActionLinks'] == 'left' || $GLOBALS['cfg']['RowActionLinks'] == 'both')
1783 && is_array($vertical_display['delete']) && (count($vertical_display['delete']) > 0 || !empty($vertical_display['textbtn']))) {
1784 echo '<tr>' . "\n";
1785 if (! is_array($vertical_display['edit']) && ! is_array($vertical_display['row_delete'])) {
1786 echo $vertical_display['textbtn'];
1788 foreach ($vertical_display['delete'] as $val) {
1789 echo $val;
1790 } // end while
1791 echo '</tr>' . "\n";
1792 } // end if
1794 if (PMA_isSelect()) {
1795 // prepare to get the column order, if available
1796 $pmatable = new PMA_Table($GLOBALS['table'], $GLOBALS['db']);
1797 $col_order = $pmatable->getUiProp(PMA_Table::PROP_COLUMN_ORDER);
1798 $col_visib = $pmatable->getUiProp(PMA_Table::PROP_COLUMN_VISIB);
1799 } else {
1800 $col_order = false;
1801 $col_visib = false;
1804 // Displays data
1805 foreach ($vertical_display['desc'] AS $j => $val) {
1806 // assign appropriate key with current column order
1807 $key = $col_order ? $col_order[$j] : $j;
1809 echo '<tr' . (($col_visib && !$col_visib[$j]) ? ' class="hide"' : '') . '>' . "\n";
1810 echo $val;
1812 $cell_displayed = 0;
1813 foreach ($vertical_display['rowdata'][$key] as $subval) {
1814 if (($cell_displayed != 0) && ($_SESSION['tmp_user_values']['repeat_cells'] != 0) and !($cell_displayed % $_SESSION['tmp_user_values']['repeat_cells'])) {
1815 echo $val;
1818 echo $subval;
1819 $cell_displayed++;
1820 } // end while
1822 echo '</tr>' . "\n";
1823 } // end while
1825 // Displays "multi row delete" link at bottom if required
1826 if (($GLOBALS['cfg']['RowActionLinks'] == 'right' || $GLOBALS['cfg']['RowActionLinks'] == 'both')
1827 && is_array($vertical_display['row_delete']) && (count($vertical_display['row_delete']) > 0 || !empty($vertical_display['textbtn']))) {
1828 echo '<tr>' . "\n";
1829 echo $vertical_display['textbtn'];
1830 $cell_displayed = 0;
1831 foreach ($vertical_display['row_delete'] as $val) {
1832 if (($cell_displayed != 0) && ($_SESSION['tmp_user_values']['repeat_cells'] != 0) && !($cell_displayed % $_SESSION['tmp_user_values']['repeat_cells'])) {
1833 echo '<th' .
1834 (($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn') ? ' rowspan="4"' : '') .
1835 '></th>' . "\n";
1838 echo str_replace('[%_PMA_CHECKBOX_DIR_%]', '_right', $val);
1839 $cell_displayed++;
1840 } // end while
1841 echo '</tr>' . "\n";
1842 } // end if
1844 // Displays "edit" link at bottom if required
1845 if (($GLOBALS['cfg']['RowActionLinks'] == 'right' || $GLOBALS['cfg']['RowActionLinks'] == 'both')
1846 && is_array($vertical_display['edit']) && (count($vertical_display['edit']) > 0 || !empty($vertical_display['textbtn']))) {
1847 echo '<tr>' . "\n";
1848 if (! is_array($vertical_display['row_delete'])) {
1849 echo $vertical_display['textbtn'];
1851 foreach ($vertical_display['edit'] as $val) {
1852 echo $val;
1853 } // end while
1854 echo '</tr>' . "\n";
1855 } // end if
1857 // Displays "copy" link at bottom if required
1858 if (($GLOBALS['cfg']['RowActionLinks'] == 'right' || $GLOBALS['cfg']['RowActionLinks'] == 'both')
1859 && is_array($vertical_display['copy']) && (count($vertical_display['copy']) > 0 || !empty($vertical_display['textbtn']))) {
1860 echo '<tr>' . "\n";
1861 if (! is_array($vertical_display['row_delete'])) {
1862 echo $vertical_display['textbtn'];
1864 foreach ($vertical_display['copy'] as $val) {
1865 echo $val;
1866 } // end while
1867 echo '</tr>' . "\n";
1868 } // end if
1870 // Displays "delete" link at bottom if required
1871 if (($GLOBALS['cfg']['RowActionLinks'] == 'right' || $GLOBALS['cfg']['RowActionLinks'] == 'both')
1872 && is_array($vertical_display['delete']) && (count($vertical_display['delete']) > 0 || !empty($vertical_display['textbtn']))) {
1873 echo '<tr>' . "\n";
1874 if (! is_array($vertical_display['edit']) && ! is_array($vertical_display['row_delete'])) {
1875 echo $vertical_display['textbtn'];
1877 foreach ($vertical_display['delete'] as $val) {
1878 echo $val;
1879 } // end while
1880 echo '</tr>' . "\n";
1883 return true;
1884 } // end of the 'PMA_displayVerticalTable' function
1888 * @todo make maximum remembered queries configurable
1889 * @todo move/split into SQL class!?
1890 * @todo currently this is called twice unnecessary
1891 * @todo ignore LIMIT and ORDER in query!?
1893 function PMA_displayTable_checkConfigParams()
1895 $sql_md5 = md5($GLOBALS['sql_query']);
1897 $_SESSION['tmp_user_values']['query'][$sql_md5]['sql'] = $GLOBALS['sql_query'];
1899 if (PMA_isValid($_REQUEST['disp_direction'], array('horizontal', 'vertical', 'horizontalflipped'))) {
1900 $_SESSION['tmp_user_values']['query'][$sql_md5]['disp_direction'] = $_REQUEST['disp_direction'];
1901 unset($_REQUEST['disp_direction']);
1902 } elseif (empty($_SESSION['tmp_user_values']['query'][$sql_md5]['disp_direction'])) {
1903 $_SESSION['tmp_user_values']['query'][$sql_md5]['disp_direction'] = $GLOBALS['cfg']['DefaultDisplay'];
1906 if (PMA_isValid($_REQUEST['repeat_cells'], 'numeric')) {
1907 $_SESSION['tmp_user_values']['query'][$sql_md5]['repeat_cells'] = $_REQUEST['repeat_cells'];
1908 unset($_REQUEST['repeat_cells']);
1909 } elseif (empty($_SESSION['tmp_user_values']['query'][$sql_md5]['repeat_cells'])) {
1910 $_SESSION['tmp_user_values']['query'][$sql_md5]['repeat_cells'] = $GLOBALS['cfg']['RepeatCells'];
1913 // as this is a form value, the type is always string so we cannot
1914 // use PMA_isValid($_REQUEST['session_max_rows'], 'integer')
1915 if ((PMA_isValid($_REQUEST['session_max_rows'], 'numeric')
1916 && (int) $_REQUEST['session_max_rows'] == $_REQUEST['session_max_rows'])
1917 || $_REQUEST['session_max_rows'] == 'all') {
1918 $_SESSION['tmp_user_values']['query'][$sql_md5]['max_rows'] = $_REQUEST['session_max_rows'];
1919 unset($_REQUEST['session_max_rows']);
1920 } elseif (empty($_SESSION['tmp_user_values']['query'][$sql_md5]['max_rows'])) {
1921 $_SESSION['tmp_user_values']['query'][$sql_md5]['max_rows'] = $GLOBALS['cfg']['MaxRows'];
1924 if (PMA_isValid($_REQUEST['pos'], 'numeric')) {
1925 $_SESSION['tmp_user_values']['query'][$sql_md5]['pos'] = $_REQUEST['pos'];
1926 unset($_REQUEST['pos']);
1927 } elseif (empty($_SESSION['tmp_user_values']['query'][$sql_md5]['pos'])) {
1928 $_SESSION['tmp_user_values']['query'][$sql_md5]['pos'] = 0;
1931 if (PMA_isValid($_REQUEST['display_text'], array('P', 'F'))) {
1932 $_SESSION['tmp_user_values']['query'][$sql_md5]['display_text'] = $_REQUEST['display_text'];
1933 unset($_REQUEST['display_text']);
1934 } elseif (empty($_SESSION['tmp_user_values']['query'][$sql_md5]['display_text'])) {
1935 $_SESSION['tmp_user_values']['query'][$sql_md5]['display_text'] = 'P';
1938 if (PMA_isValid($_REQUEST['relational_display'], array('K', 'D'))) {
1939 $_SESSION['tmp_user_values']['query'][$sql_md5]['relational_display'] = $_REQUEST['relational_display'];
1940 unset($_REQUEST['relational_display']);
1941 } elseif (empty($_SESSION['tmp_user_values']['query'][$sql_md5]['relational_display'])) {
1942 $_SESSION['tmp_user_values']['query'][$sql_md5]['relational_display'] = 'K';
1945 if (PMA_isValid($_REQUEST['geometry_display'], array('WKT', 'WKB', 'GEOM'))) {
1946 $_SESSION['tmp_user_values']['query'][$sql_md5]['geometry_display'] = $_REQUEST['geometry_display'];
1947 unset($_REQUEST['geometry_display']);
1948 } elseif (empty($_SESSION['tmp_user_values']['query'][$sql_md5]['geometry_display'])) {
1949 $_SESSION['tmp_user_values']['query'][$sql_md5]['geometry_display'] = 'GEOM';
1952 if (isset($_REQUEST['display_binary'])) {
1953 $_SESSION['tmp_user_values']['query'][$sql_md5]['display_binary'] = true;
1954 unset($_REQUEST['display_binary']);
1955 } elseif (isset($_REQUEST['display_options_form'])) {
1956 // we know that the checkbox was unchecked
1957 unset($_SESSION['tmp_user_values']['query'][$sql_md5]['display_binary']);
1958 } else {
1959 // selected by default because some operations like OPTIMIZE TABLE
1960 // and all queries involving functions return "binary" contents,
1961 // according to low-level field flags
1962 $_SESSION['tmp_user_values']['query'][$sql_md5]['display_binary'] = true;
1965 if (isset($_REQUEST['display_binary_as_hex'])) {
1966 $_SESSION['tmp_user_values']['query'][$sql_md5]['display_binary_as_hex'] = true;
1967 unset($_REQUEST['display_binary_as_hex']);
1968 } elseif (isset($_REQUEST['display_options_form'])) {
1969 // we know that the checkbox was unchecked
1970 unset($_SESSION['tmp_user_values']['query'][$sql_md5]['display_binary_as_hex']);
1971 } else {
1972 // display_binary_as_hex config option
1973 if (isset($GLOBALS['cfg']['DisplayBinaryAsHex']) && true === $GLOBALS['cfg']['DisplayBinaryAsHex']) {
1974 $_SESSION['tmp_user_values']['query'][$sql_md5]['display_binary_as_hex'] = true;
1978 if (isset($_REQUEST['display_blob'])) {
1979 $_SESSION['tmp_user_values']['query'][$sql_md5]['display_blob'] = true;
1980 unset($_REQUEST['display_blob']);
1981 } elseif (isset($_REQUEST['display_options_form'])) {
1982 // we know that the checkbox was unchecked
1983 unset($_SESSION['tmp_user_values']['query'][$sql_md5]['display_blob']);
1986 if (isset($_REQUEST['hide_transformation'])) {
1987 $_SESSION['tmp_user_values']['query'][$sql_md5]['hide_transformation'] = true;
1988 unset($_REQUEST['hide_transformation']);
1989 } elseif (isset($_REQUEST['display_options_form'])) {
1990 // we know that the checkbox was unchecked
1991 unset($_SESSION['tmp_user_values']['query'][$sql_md5]['hide_transformation']);
1994 // move current query to the last position, to be removed last
1995 // so only least executed query will be removed if maximum remembered queries
1996 // limit is reached
1997 $tmp = $_SESSION['tmp_user_values']['query'][$sql_md5];
1998 unset($_SESSION['tmp_user_values']['query'][$sql_md5]);
1999 $_SESSION['tmp_user_values']['query'][$sql_md5] = $tmp;
2001 // do not exceed a maximum number of queries to remember
2002 if (count($_SESSION['tmp_user_values']['query']) > 10) {
2003 array_shift($_SESSION['tmp_user_values']['query']);
2004 //echo 'deleting one element ...';
2007 // populate query configuration
2008 $_SESSION['tmp_user_values']['display_text'] = $_SESSION['tmp_user_values']['query'][$sql_md5]['display_text'];
2009 $_SESSION['tmp_user_values']['relational_display'] = $_SESSION['tmp_user_values']['query'][$sql_md5]['relational_display'];
2010 $_SESSION['tmp_user_values']['geometry_display'] = $_SESSION['tmp_user_values']['query'][$sql_md5]['geometry_display'];
2011 $_SESSION['tmp_user_values']['display_binary'] = isset($_SESSION['tmp_user_values']['query'][$sql_md5]['display_binary']) ? true : false;
2012 $_SESSION['tmp_user_values']['display_binary_as_hex'] = isset($_SESSION['tmp_user_values']['query'][$sql_md5]['display_binary_as_hex']) ? true : false;
2013 $_SESSION['tmp_user_values']['display_blob'] = isset($_SESSION['tmp_user_values']['query'][$sql_md5]['display_blob']) ? true : false;
2014 $_SESSION['tmp_user_values']['hide_transformation'] = isset($_SESSION['tmp_user_values']['query'][$sql_md5]['hide_transformation']) ? true : false;
2015 $_SESSION['tmp_user_values']['pos'] = $_SESSION['tmp_user_values']['query'][$sql_md5]['pos'];
2016 $_SESSION['tmp_user_values']['max_rows'] = $_SESSION['tmp_user_values']['query'][$sql_md5]['max_rows'];
2017 $_SESSION['tmp_user_values']['repeat_cells'] = $_SESSION['tmp_user_values']['query'][$sql_md5]['repeat_cells'];
2018 $_SESSION['tmp_user_values']['disp_direction'] = $_SESSION['tmp_user_values']['query'][$sql_md5]['disp_direction'];
2021 * debugging
2022 echo '<pre>';
2023 var_dump($_SESSION['tmp_user_values']);
2024 echo '</pre>';
2029 * Displays a table of results returned by a SQL query.
2030 * This function is called by the "sql.php" script.
2032 * @param integer the link id associated to the query which results have
2033 * to be displayed
2034 * @param array the display mode
2035 * @param array the analyzed query
2037 * @global string $db the database name
2038 * @global string $table the table name
2039 * @global string $goto the URL to go back in case of errors
2040 * @global string $sql_query the current SQL query
2041 * @global integer $num_rows the total number of rows returned by the
2042 * SQL query
2043 * @global integer $unlim_num_rows the total number of rows returned by the
2044 * SQL query without any programmatically
2045 * appended "LIMIT" clause
2046 * @global array $fields_meta the list of fields properties
2047 * @global integer $fields_cnt the total number of fields returned by
2048 * the SQL query
2049 * @global array $vertical_display informations used with vertical display
2050 * mode
2051 * @global array $highlight_columns column names to highlight
2052 * @global array $cfgRelation the relation settings
2054 * @access private
2056 * @see PMA_showMessage(), PMA_setDisplayMode(),
2057 * PMA_displayTableNavigation(), PMA_displayTableHeaders(),
2058 * PMA_displayTableBody(), PMA_displayResultsOperations()
2060 function PMA_displayTable(&$dt_result, &$the_disp_mode, $analyzed_sql)
2062 global $db, $table, $goto;
2063 global $sql_query, $num_rows, $unlim_num_rows, $fields_meta, $fields_cnt;
2064 global $vertical_display, $highlight_columns;
2065 global $cfgRelation;
2066 global $showtable;
2068 // why was this called here? (already called from sql.php)
2069 //PMA_displayTable_checkConfigParams();
2072 * @todo move this to a central place
2073 * @todo for other future table types
2075 $is_innodb = (isset($showtable['Type']) && $showtable['Type'] == 'InnoDB');
2077 if ($is_innodb
2078 && ! isset($analyzed_sql[0]['queryflags']['union'])
2079 && ! isset($analyzed_sql[0]['table_ref'][1]['table_name'])
2080 && (empty($analyzed_sql[0]['where_clause'])
2081 || $analyzed_sql[0]['where_clause'] == '1 ')) {
2082 // "j u s t b r o w s i n g"
2083 $pre_count = '~';
2084 $after_count = PMA_showHint(PMA_sanitize(__('May be approximate. See [a@./Documentation.html#faq3_11@Documentation]FAQ 3.11[/a]')), true);
2085 } else {
2086 $pre_count = '';
2087 $after_count = '';
2090 // 1. ----- Prepares the work -----
2092 // 1.1 Gets the informations about which functionalities should be
2093 // displayed
2094 $total = '';
2095 $is_display = PMA_setDisplayMode($the_disp_mode, $total);
2097 // 1.2 Defines offsets for the next and previous pages
2098 if ($is_display['nav_bar'] == '1') {
2099 if ($_SESSION['tmp_user_values']['max_rows'] == 'all') {
2100 $pos_next = 0;
2101 $pos_prev = 0;
2102 } else {
2103 $pos_next = $_SESSION['tmp_user_values']['pos'] + $_SESSION['tmp_user_values']['max_rows'];
2104 $pos_prev = $_SESSION['tmp_user_values']['pos'] - $_SESSION['tmp_user_values']['max_rows'];
2105 if ($pos_prev < 0) {
2106 $pos_prev = 0;
2109 } // end if
2111 // 1.3 Find the sort expression
2113 // we need $sort_expression and $sort_expression_nodirection
2114 // even if there are many table references
2115 if (! empty($analyzed_sql[0]['order_by_clause'])) {
2116 $sort_expression = trim(str_replace(' ', ' ', $analyzed_sql[0]['order_by_clause']));
2118 * Get rid of ASC|DESC
2120 preg_match('@(.*)([[:space:]]*(ASC|DESC))@si', $sort_expression, $matches);
2121 $sort_expression_nodirection = isset($matches[1]) ? trim($matches[1]) : $sort_expression;
2122 $sort_direction = isset($matches[2]) ? trim($matches[2]) : '';
2123 unset($matches);
2124 } else {
2125 $sort_expression = $sort_expression_nodirection = $sort_direction = '';
2128 // 1.4 Prepares display of first and last value of the sorted column
2130 if (! empty($sort_expression_nodirection)) {
2131 if (strpos($sort_expression_nodirection, '.') === false) {
2132 $sort_table = $table;
2133 $sort_column = $sort_expression_nodirection;
2134 } else {
2135 list($sort_table, $sort_column) = explode('.', $sort_expression_nodirection);
2137 $sort_table = PMA_unQuote($sort_table);
2138 $sort_column = PMA_unQuote($sort_column);
2139 // find the sorted column index in row result
2140 // (this might be a multi-table query)
2141 $sorted_column_index = false;
2142 foreach($fields_meta as $key => $meta) {
2143 if ($meta->table == $sort_table && $meta->name == $sort_column) {
2144 $sorted_column_index = $key;
2145 break;
2148 if ($sorted_column_index !== false) {
2149 // fetch first row of the result set
2150 $row = PMA_DBI_fetch_row($dt_result);
2151 // initializing default arguments
2152 $default_function = 'default_function';
2153 $transform_function = $default_function;
2154 $transform_options = array();
2155 // check for non printable sorted row data
2156 $meta = $fields_meta[$sorted_column_index];
2157 if (stristr($meta->type, 'BLOB') || $meta->type == 'geometry') {
2158 $column_for_first_row = PMA_handle_non_printable_contents($meta->type, $row[$sorted_column_index], $transform_function, $transform_options, $default_function, $meta, NULL);
2159 } else {
2160 $column_for_first_row = $row[$sorted_column_index];
2162 $column_for_first_row = strtoupper(substr($column_for_first_row, 0, $GLOBALS['cfg']['LimitChars']));
2163 // fetch last row of the result set
2164 PMA_DBI_data_seek($dt_result, $num_rows - 1);
2165 $row = PMA_DBI_fetch_row($dt_result);
2166 // check for non printable sorted row data
2167 $meta = $fields_meta[$sorted_column_index];
2168 if (stristr($meta->type, 'BLOB') || $meta->type == 'geometry') {
2169 $column_for_last_row = PMA_handle_non_printable_contents($meta->type, $row[$sorted_column_index], $transform_function, $transform_options, $default_function, $meta, NULL);
2170 } else {
2171 $column_for_last_row = $row[$sorted_column_index];
2173 $column_for_last_row = strtoupper(substr($column_for_last_row, 0, $GLOBALS['cfg']['LimitChars']));
2174 // reset to first row for the loop in PMA_displayTableBody()
2175 PMA_DBI_data_seek($dt_result, 0);
2176 // we could also use here $sort_expression_nodirection
2177 $sorted_column_message = ' [' . htmlspecialchars($sort_column) . ': <strong>' . htmlspecialchars($column_for_first_row) . ' - ' . htmlspecialchars($column_for_last_row) . '</strong>]';
2178 unset($row, $column_for_first_row, $column_for_last_row, $meta, $default_function, $transform_function, $transform_options);
2180 unset($sorted_column_index, $sort_table, $sort_column);
2183 // 2. ----- Displays the top of the page -----
2185 // 2.1 Displays a messages with position informations
2186 if ($is_display['nav_bar'] == '1' && isset($pos_next)) {
2187 if (isset($unlim_num_rows) && $unlim_num_rows != $total) {
2188 $selectstring = ', ' . $unlim_num_rows . ' ' . __('in query');
2189 } else {
2190 $selectstring = '';
2192 $last_shown_rec = ($_SESSION['tmp_user_values']['max_rows'] == 'all' || $pos_next > $total)
2193 ? $total - 1
2194 : $pos_next - 1;
2196 if (PMA_Table::isView($db, $table)
2197 && $total == $GLOBALS['cfg']['MaxExactCountViews']) {
2198 $message = PMA_Message::notice(__('This view has at least this number of rows. Please refer to %sdocumentation%s.'));
2199 $message->addParam('[a@./Documentation.html#cfg_MaxExactCount@_blank]');
2200 $message->addParam('[/a]');
2201 $message_view_warning = PMA_showHint($message);
2202 } else {
2203 $message_view_warning = false;
2206 $message = PMA_Message::success(__('Showing rows'));
2207 $message->addMessage($_SESSION['tmp_user_values']['pos']);
2208 if ($message_view_warning) {
2209 $message->addMessage('...', ' - ');
2210 $message->addMessage($message_view_warning);
2211 $message->addMessage('(');
2212 } else {
2213 $message->addMessage($last_shown_rec, ' - ');
2214 $message->addMessage(' (');
2215 $message->addMessage($pre_count . PMA_formatNumber($total, 0));
2216 $message->addString(__('total'));
2217 if (!empty($after_count)) {
2218 $message->addMessage($after_count);
2220 $message->addMessage($selectstring, '');
2221 $message->addMessage(', ', '');
2224 $messagge_qt = PMA_Message::notice(__('Query took %01.4f sec'));
2225 $messagge_qt->addParam($GLOBALS['querytime']);
2227 $message->addMessage($messagge_qt, '');
2228 $message->addMessage(')', '');
2230 $message->addMessage(isset($sorted_column_message) ? $sorted_column_message : '', '');
2232 PMA_showMessage($message, $sql_query, 'success');
2234 } elseif (! isset($GLOBALS['printview']) || $GLOBALS['printview'] != '1') {
2235 PMA_showMessage(__('Your SQL query has been executed successfully'), $sql_query, 'success');
2238 // 2.3 Displays the navigation bars
2239 if (! strlen($table)) {
2240 if (isset($analyzed_sql[0]['query_type'])
2241 && $analyzed_sql[0]['query_type'] == 'SELECT') {
2242 // table does not always contain a real table name,
2243 // for example in MySQL 5.0.x, the query SHOW STATUS
2244 // returns STATUS as a table name
2245 $table = $fields_meta[0]->table;
2246 } else {
2247 $table = '';
2251 if ($is_display['nav_bar'] == '1') {
2252 PMA_displayTableNavigation($pos_next, $pos_prev, $sql_query, 'top_direction_dropdown');
2253 echo "\n";
2254 } elseif (! isset($GLOBALS['printview']) || $GLOBALS['printview'] != '1') {
2255 echo "\n" . '<br /><br />' . "\n";
2258 // 2b ----- Get field references from Database -----
2259 // (see the 'relation' configuration variable)
2261 // initialize map
2262 $map = array();
2264 // find tables
2265 $target=array();
2266 if (isset($analyzed_sql[0]['table_ref']) && is_array($analyzed_sql[0]['table_ref'])) {
2267 foreach ($analyzed_sql[0]['table_ref'] AS $table_ref_position => $table_ref) {
2268 $target[] = $analyzed_sql[0]['table_ref'][$table_ref_position]['table_true_name'];
2271 $tabs = '(\'' . join('\',\'', $target) . '\')';
2273 if (! strlen($table)) {
2274 $exist_rel = false;
2275 } else {
2276 // To be able to later display a link to the related table,
2277 // we verify both types of relations: either those that are
2278 // native foreign keys or those defined in the phpMyAdmin
2279 // configuration storage. If no PMA storage, we won't be able
2280 // to use the "column to display" notion (for example show
2281 // the name related to a numeric id).
2282 $exist_rel = PMA_getForeigners($db, $table, '', 'both');
2283 if ($exist_rel) {
2284 foreach ($exist_rel AS $master_field => $rel) {
2285 $display_field = PMA_getDisplayField($rel['foreign_db'], $rel['foreign_table']);
2286 $map[$master_field] = array($rel['foreign_table'],
2287 $rel['foreign_field'],
2288 $display_field,
2289 $rel['foreign_db']);
2290 } // end while
2291 } // end if
2292 } // end if
2293 // end 2b
2295 // 3. ----- Displays the results table -----
2296 PMA_displayTableHeaders($is_display, $fields_meta, $fields_cnt, $analyzed_sql, $sort_expression, $sort_expression_nodirection, $sort_direction);
2297 $url_query = '';
2298 echo '<tbody>' . "\n";
2299 $clause_is_unique = PMA_displayTableBody($dt_result, $is_display, $map, $analyzed_sql);
2300 // vertical output case
2301 if ($_SESSION['tmp_user_values']['disp_direction'] == 'vertical') {
2302 PMA_displayVerticalTable();
2303 } // end if
2304 unset($vertical_display);
2305 echo '</tbody>' . "\n";
2307 </table>
2309 <?php
2310 // 4. ----- Displays the link for multi-fields edit and delete
2312 if ($is_display['del_lnk'] == 'dr' && $is_display['del_lnk'] != 'kp') {
2314 $delete_text = $is_display['del_lnk'] == 'dr' ? __('Delete') : __('Kill');
2316 $_url_params = array(
2317 'db' => $db,
2318 'table' => $table,
2319 'sql_query' => $sql_query,
2320 'goto' => $goto,
2322 $uncheckall_url = 'sql.php' . PMA_generate_common_url($_url_params);
2324 $_url_params['checkall'] = '1';
2325 $checkall_url = 'sql.php' . PMA_generate_common_url($_url_params);
2327 if ($_SESSION['tmp_user_values']['disp_direction'] == 'vertical') {
2328 $checkall_params['onclick'] = 'if (setCheckboxes(\'resultsForm\', true)) return false;';
2329 $uncheckall_params['onclick'] = 'if (setCheckboxes(\'resultsForm\', false)) return false;';
2330 } else {
2331 $checkall_params['onclick'] = 'if (markAllRows(\'resultsForm\')) return false;';
2332 $uncheckall_params['onclick'] = 'if (unMarkAllRows(\'resultsForm\')) return false;';
2334 $checkall_link = PMA_linkOrButton($checkall_url, __('Check All'), $checkall_params, false);
2335 $uncheckall_link = PMA_linkOrButton($uncheckall_url, __('Uncheck All'), $uncheckall_params, false);
2336 if ($_SESSION['tmp_user_values']['disp_direction'] != 'vertical') {
2337 echo '<img class="selectallarrow" width="38" height="22"'
2338 .' src="' . $GLOBALS['pmaThemeImage'] . 'arrow_' . $GLOBALS['text_dir'] . '.png' . '"'
2339 .' alt="' . __('With selected:') . '" />';
2341 echo $checkall_link . "\n"
2342 .' / ' . "\n"
2343 .$uncheckall_link . "\n"
2344 .'<i>' . __('With selected:') . '</i>' . "\n";
2346 PMA_buttonOrImage('submit_mult', 'mult_submit',
2347 'submit_mult_change', __('Change'), 'b_edit.png', 'edit');
2348 PMA_buttonOrImage('submit_mult', 'mult_submit',
2349 'submit_mult_delete', $delete_text, 'b_drop.png', 'delete');
2350 if (isset($analyzed_sql[0]) && $analyzed_sql[0]['querytype'] == 'SELECT') {
2351 PMA_buttonOrImage('submit_mult', 'mult_submit',
2352 'submit_mult_export', __('Export'),
2353 'b_tblexport.png', 'export');
2355 echo "\n";
2357 echo '<input type="hidden" name="sql_query"'
2358 .' value="' . htmlspecialchars($sql_query) . '" />' . "\n";
2360 if (! empty($GLOBALS['url_query'])) {
2361 echo '<input type="hidden" name="url_query"'
2362 .' value="' . $GLOBALS['url_query'] . '" />' . "\n";
2365 echo '<input type="hidden" name="clause_is_unique"'
2366 .' value="' . $clause_is_unique . '" />' . "\n";
2368 echo '</form>' . "\n";
2371 // 5. ----- Displays the navigation bar at the bottom if required -----
2373 if ($is_display['nav_bar'] == '1') {
2374 echo '<br />' . "\n";
2375 PMA_displayTableNavigation($pos_next, $pos_prev, $sql_query, 'bottom_direction_dropdown');
2376 } elseif (! isset($GLOBALS['printview']) || $GLOBALS['printview'] != '1') {
2377 echo "\n" . '<br /><br />' . "\n";
2380 // 6. ----- Displays "Query results operations"
2381 if (! isset($GLOBALS['printview']) || $GLOBALS['printview'] != '1') {
2382 PMA_displayResultsOperations($the_disp_mode, $analyzed_sql);
2384 } // end of the 'PMA_displayTable()' function
2386 function default_function($buffer) {
2387 $buffer = htmlspecialchars($buffer);
2388 $buffer = str_replace("\011", ' &nbsp;&nbsp;&nbsp;',
2389 str_replace(' ', ' &nbsp;', $buffer));
2390 $buffer = preg_replace("@((\015\012)|(\015)|(\012))@", '<br />', $buffer);
2392 return $buffer;
2396 * Displays operations that are available on results.
2398 * @param array the display mode
2399 * @param array the analyzed query
2401 * @global string $db the database name
2402 * @global string $table the table name
2403 * @global string $sql_query the current SQL query
2404 * @global integer $unlim_num_rows the total number of rows returned by the
2405 * SQL query without any programmatically
2406 * appended "LIMIT" clause
2408 * @access private
2410 * @see PMA_showMessage(), PMA_setDisplayMode(),
2411 * PMA_displayTableNavigation(), PMA_displayTableHeaders(),
2412 * PMA_displayTableBody(), PMA_displayResultsOperations()
2414 function PMA_displayResultsOperations($the_disp_mode, $analyzed_sql) {
2415 global $db, $table, $sql_query, $unlim_num_rows, $fields_meta;
2417 $header_shown = false;
2418 $header = '<fieldset><legend>' . __('Query results operations') . '</legend>';
2420 if ($the_disp_mode[6] == '1' || $the_disp_mode[9] == '1') {
2421 // Displays "printable view" link if required
2422 if ($the_disp_mode[9] == '1') {
2424 if (!$header_shown) {
2425 echo $header;
2426 $header_shown = true;
2429 $_url_params = array(
2430 'db' => $db,
2431 'table' => $table,
2432 'printview' => '1',
2433 'sql_query' => $sql_query,
2435 $url_query = PMA_generate_common_url($_url_params);
2437 echo PMA_linkOrButton(
2438 'sql.php' . $url_query,
2439 PMA_getIcon('b_print.png', __('Print view'), false, true),
2440 '', true, true, 'print_view') . "\n";
2442 if ($_SESSION['tmp_user_values']['display_text']) {
2443 $_url_params['display_text'] = 'F';
2444 echo PMA_linkOrButton(
2445 'sql.php' . PMA_generate_common_url($_url_params),
2446 PMA_getIcon('b_print.png', __('Print view (with full texts)'), false, true),
2447 '', true, true, 'print_view') . "\n";
2448 unset($_url_params['display_text']);
2450 } // end displays "printable view"
2453 // Export link
2454 // (the url_query has extra parameters that won't be used to export)
2455 // (the single_table parameter is used in display_export.lib.php
2456 // to hide the SQL and the structure export dialogs)
2457 // If the parser found a PROCEDURE clause
2458 // (most probably PROCEDURE ANALYSE()) it makes no sense to
2459 // display the Export link).
2460 if (isset($analyzed_sql[0]) && $analyzed_sql[0]['querytype'] == 'SELECT' && ! isset($printview) && ! isset($analyzed_sql[0]['queryflags']['procedure'])) {
2461 if (isset($analyzed_sql[0]['table_ref'][0]['table_true_name']) && ! isset($analyzed_sql[0]['table_ref'][1]['table_true_name'])) {
2462 $_url_params['single_table'] = 'true';
2464 if (!$header_shown) {
2465 echo $header;
2466 $header_shown = true;
2468 $_url_params['unlim_num_rows'] = $unlim_num_rows;
2471 * At this point we don't know the table name; this can happen
2472 * for example with a query like
2473 * SELECT bike_code FROM (SELECT bike_code FROM bikes) tmp
2474 * As a workaround we set in the table parameter the name of the
2475 * first table of this database, so that tbl_export.php and
2476 * the script it calls do not fail
2478 if (empty($_url_params['table']) && !empty($_url_params['db'])) {
2479 $_url_params['table'] = PMA_DBI_fetch_value("SHOW TABLES");
2480 /* No result (probably no database selected) */
2481 if ($_url_params['table'] === FALSE) {
2482 unset($_url_params['table']);
2486 echo PMA_linkOrButton(
2487 'tbl_export.php' . PMA_generate_common_url($_url_params),
2488 PMA_getIcon('b_tblexport.png', __('Export'), false, true),
2489 '', true, true, '') . "\n";
2491 // show chart
2492 echo PMA_linkOrButton(
2493 'tbl_chart.php' . PMA_generate_common_url($_url_params),
2494 PMA_getIcon('b_chart.png', __('Display chart'), false, true),
2495 '', true, true, '') . "\n";
2497 // show GIS chart
2498 $geometry_found = false;
2499 // If atleast one geometry field is found
2500 foreach ($fields_meta as $meta) {
2501 if ($meta->type == 'geometry') {
2502 $geometry_found = true;
2503 break;
2506 if ($geometry_found) {
2507 echo PMA_linkOrButton(
2508 'tbl_gis_visualization.php' . PMA_generate_common_url($_url_params),
2509 PMA_getIcon('b_globe.gif', __('Visualize GIS data'), false, true),
2510 '', true, true, '') . "\n";
2514 // CREATE VIEW
2517 * @todo detect privileges to create a view
2518 * (but see 2006-01-19 note in display_create_table.lib.php,
2519 * I think we cannot detect db-specific privileges reliably)
2520 * Note: we don't display a Create view link if we found a PROCEDURE clause
2522 if (!$header_shown) {
2523 echo $header;
2524 $header_shown = true;
2526 if (!PMA_DRIZZLE && !isset($analyzed_sql[0]['queryflags']['procedure'])) {
2527 echo PMA_linkOrButton(
2528 'view_create.php' . $url_query,
2529 PMA_getIcon('b_views.png', __('Create view'), false, true),
2530 '', true, true, '') . "\n";
2532 if ($header_shown) {
2533 echo '</fieldset><br />';
2538 * Verifies what to do with non-printable contents (binary or BLOB)
2539 * in Browse mode.
2541 * @param string $category BLOB|BINARY|GEOMETRY
2542 * @param string $content the binary content
2543 * @param string $transform_function
2544 * @param string $transform_options
2545 * @param string $default_function
2546 * @param object $meta the meta-information about this field
2547 * @return mixed string or float
2549 function PMA_handle_non_printable_contents($category, $content, $transform_function, $transform_options, $default_function, $meta, $url_params = array()) {
2550 $result = '[' . $category;
2551 if (is_null($content)) {
2552 $result .= ' - NULL';
2553 $size = 0;
2554 } elseif (isset($content)) {
2555 $size = strlen($content);
2556 $display_size = PMA_formatByteDown($size, 3, 1);
2557 $result .= ' - '. $display_size[0] . ' ' . $display_size[1];
2559 $result .= ']';
2561 if (strpos($transform_function, 'octetstream')) {
2562 $result = $content;
2564 if ($size > 0) {
2565 if ($default_function != $transform_function) {
2566 $result = $transform_function($result, $transform_options, $meta);
2567 } else {
2568 $result = $default_function($result, array(), $meta);
2569 if (stristr($meta->type, 'BLOB') && $_SESSION['tmp_user_values']['display_blob']) {
2570 // in this case, restart from the original $content
2571 $result = htmlspecialchars(PMA_replace_binary_contents($content));
2573 /* Create link to download */
2574 if (count($url_params) > 0) {
2575 $result = '<a href="tbl_get_field.php' . PMA_generate_common_url($url_params) . '">' . $result . '</a>';
2579 return($result);
2583 * Prepares the displayable content of a data cell in Browse mode,
2584 * taking into account foreign key description field and transformations
2586 * @param string $class
2587 * @param string $condition_field
2588 * @param string $analyzed_sql
2589 * @param object $meta the meta-information about this field
2590 * @param string $map
2591 * @param string $data
2592 * @param string $transform_function
2593 * @param string $default_function
2594 * @param string $nowrap
2595 * @param string $where_comparison
2596 * @param bool $is_field_truncated
2597 * @return string formatted data
2599 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 ) {
2601 $result = ' class="' . PMA_addClass($class, $condition_field, $meta, $nowrap, $is_field_truncated, $transform_function, $default_function) . '">';
2603 if (isset($analyzed_sql[0]['select_expr']) && is_array($analyzed_sql[0]['select_expr'])) {
2604 foreach ($analyzed_sql[0]['select_expr'] AS $select_expr_position => $select_expr) {
2605 $alias = $analyzed_sql[0]['select_expr'][$select_expr_position]['alias'];
2606 if (isset($alias) && strlen($alias)) {
2607 $true_column = $analyzed_sql[0]['select_expr'][$select_expr_position]['column'];
2608 if ($alias == $meta->name) {
2609 // this change in the parameter does not matter
2610 // outside of the function
2611 $meta->name = $true_column;
2612 } // end if
2613 } // end if
2614 } // end foreach
2615 } // end if
2617 if (isset($map[$meta->name])) {
2618 // Field to display from the foreign table?
2619 if (isset($map[$meta->name][2]) && strlen($map[$meta->name][2])) {
2620 $dispsql = 'SELECT ' . PMA_backquote($map[$meta->name][2])
2621 . ' FROM ' . PMA_backquote($map[$meta->name][3])
2622 . '.' . PMA_backquote($map[$meta->name][0])
2623 . ' WHERE ' . PMA_backquote($map[$meta->name][1])
2624 . $where_comparison;
2625 $dispresult = PMA_DBI_try_query($dispsql, null, PMA_DBI_QUERY_STORE);
2626 if ($dispresult && PMA_DBI_num_rows($dispresult) > 0) {
2627 list($dispval) = PMA_DBI_fetch_row($dispresult, 0);
2628 } else {
2629 $dispval = __('Link not found');
2631 @PMA_DBI_free_result($dispresult);
2632 } else {
2633 $dispval = '';
2634 } // end if... else...
2636 if (isset($GLOBALS['printview']) && $GLOBALS['printview'] == '1') {
2637 $result .= ($transform_function != $default_function ? $transform_function($data, $transform_options, $meta) : $transform_function($data, array(), $meta)) . ' <code>[-&gt;' . $dispval . ']</code>';
2638 } else {
2640 if ('K' == $_SESSION['tmp_user_values']['relational_display']) {
2641 // user chose "relational key" in the display options, so
2642 // the title contains the display field
2643 $title = (! empty($dispval))? ' title="' . htmlspecialchars($dispval) . '"' : '';
2644 } else {
2645 $title = ' title="' . htmlspecialchars($data) . '"';
2648 $_url_params = array(
2649 'db' => $map[$meta->name][3],
2650 'table' => $map[$meta->name][0],
2651 'pos' => '0',
2652 'sql_query' => 'SELECT * FROM '
2653 . PMA_backquote($map[$meta->name][3]) . '.' . PMA_backquote($map[$meta->name][0])
2654 . ' WHERE ' . PMA_backquote($map[$meta->name][1])
2655 . $where_comparison,
2657 $result .= '<a href="sql.php' . PMA_generate_common_url($_url_params)
2658 . '"' . $title . '>';
2660 if ($transform_function != $default_function) {
2661 // always apply a transformation on the real data,
2662 // not on the display field
2663 $result .= $transform_function($data, $transform_options, $meta);
2664 } else {
2665 if ('D' == $_SESSION['tmp_user_values']['relational_display']) {
2666 // user chose "relational display field" in the
2667 // display options, so show display field in the cell
2668 $result .= $transform_function($dispval, array(), $meta);
2669 } else {
2670 // otherwise display data in the cell
2671 $result .= $transform_function($data, array(), $meta);
2674 $result .= '</a>';
2676 } else {
2677 $result .= ($transform_function != $default_function ? $transform_function($data, $transform_options, $meta) : $transform_function($data, array(), $meta));
2679 $result .= '</td>' . "\n";
2681 return $result;
2685 * Generates a checkbox for multi-row submits
2687 * @param string $del_url
2688 * @param array $is_display
2689 * @param string $row_no
2690 * @param string $where_clause_html
2691 * @param string $del_query
2692 * @param string $id_suffix
2693 * @param string $class
2694 * @return string the generated HTML
2697 function PMA_generateCheckboxForMulti($del_url, $is_display, $row_no, $where_clause_html, $del_query, $id_suffix, $class) {
2698 $ret = '';
2699 if (! empty($del_url) && $is_display['del_lnk'] != 'kp') {
2700 $ret .= '<td ';
2701 if (! empty($class)) {
2702 $ret .= 'class="' . $class . '"';
2704 $ret .= ' align="center">'
2705 . '<input type="checkbox" id="id_rows_to_delete' . $row_no . $id_suffix . '" name="rows_to_delete[' . $where_clause_html . ']"'
2706 . ' class="multi_checkbox"'
2707 . ' value="' . htmlspecialchars($del_query) . '" ' . (isset($GLOBALS['checkall']) ? 'checked="checked"' : '') . ' />'
2708 . ' </td>';
2710 return $ret;
2714 * Generates an Edit link
2716 * @param string $edit_url
2717 * @param string $class
2718 * @param string $edit_str
2719 * @param string $where_clause
2720 * @param string $where_clause_html
2721 * @return string the generated HTML
2723 function PMA_generateEditLink($edit_url, $class, $edit_str, $where_clause, $where_clause_html) {
2724 $ret = '';
2725 if (! empty($edit_url)) {
2726 $ret .= '<td class="' . $class . '" align="center" ' . ' ><span class="nowrap">'
2727 . PMA_linkOrButton($edit_url, $edit_str, array(), false);
2729 * Where clause for selecting this row uniquely is provided as
2730 * a hidden input. Used by jQuery scripts for handling inline editing
2732 if(! empty($where_clause)) {
2733 $ret .= '<input type="hidden" class="where_clause" value ="' . $where_clause_html . '" />';
2735 $ret .= '</span></td>';
2737 return $ret;
2741 * Generates an Copy link
2743 * @param string $copy_url
2744 * @param string $copy_str
2745 * @param string $where_clause
2746 * @param string $where_clause_html
2747 * @return string the generated HTML
2749 function PMA_generateCopyLink($copy_url, $copy_str, $where_clause, $where_clause_html, $class) {
2750 $ret = '';
2751 if (! empty($copy_url)) {
2752 $ret .= '<td ';
2753 if (! empty($class)) {
2754 $ret .= 'class="' . $class . '" ';
2756 $ret .= 'align="center" ' . ' ><span class="nowrap">'
2757 . PMA_linkOrButton($copy_url, $copy_str, array(), false);
2759 * Where clause for selecting this row uniquely is provided as
2760 * a hidden input. Used by jQuery scripts for handling inline editing
2762 if(! empty($where_clause)) {
2763 $ret .= '<input type="hidden" class="where_clause" value ="' . $where_clause_html . '" />';
2765 $ret .= '</span></td>';
2767 return $ret;
2771 * Generates a Delete link
2773 * @param string $del_url
2774 * @param string $del_str
2775 * @param string $js_conf
2776 * @param string $class
2777 * @return string the generated HTML
2779 function PMA_generateDeleteLink($del_url, $del_str, $js_conf, $class) {
2780 $ret = '';
2781 if (! empty($del_url)) {
2782 $ret .= '<td ';
2783 if (! empty($class)) {
2784 $ret .= 'class="' . $class . '" ';
2786 $ret .= 'align="center" ' . ' >'
2787 . PMA_linkOrButton($del_url, $del_str, $js_conf, false)
2788 . '</td>';
2790 return $ret;
2794 * Generates checkbox and links at some position (left or right)
2795 * (only called for horizontal mode)
2797 * @param string $position
2798 * @param string $del_url
2799 * @param array $is_display
2800 * @param string $row_no
2801 * @param string $where_clause
2802 * @param string $where_clause_html
2803 * @param string $del_query
2804 * @param string $id_suffix
2805 * @param string $edit_url
2806 * @param string $copy_url
2807 * @param string $class
2808 * @param string $edit_str
2809 * @param string $del_str
2810 * @param string $js_conf
2811 * @return string the generated HTML
2813 function PMA_generateCheckboxAndLinks($position, $del_url, $is_display, $row_no, $where_clause, $where_clause_html, $del_query, $id_suffix, $edit_url, $copy_url, $class, $edit_str, $copy_str, $del_str, $js_conf) {
2814 $ret = '';
2816 if ($position == 'left') {
2817 $ret .= PMA_generateCheckboxForMulti($del_url, $is_display, $row_no, $where_clause_html, $del_query, $id_suffix='_left', '', '', '');
2819 $ret .= PMA_generateEditLink($edit_url, $class, $edit_str, $where_clause, $where_clause_html, '');
2821 $ret .= PMA_generateCopyLink($copy_url, $copy_str, $where_clause, $where_clause_html, '');
2823 $ret .= PMA_generateDeleteLink($del_url, $del_str, $js_conf, '', '');
2825 } elseif ($position == 'right') {
2826 $ret .= PMA_generateDeleteLink($del_url, $del_str, $js_conf, '', '');
2828 $ret .= PMA_generateCopyLink($copy_url, $copy_str, $where_clause, $where_clause_html, '');
2830 $ret .= PMA_generateEditLink($edit_url, $class, $edit_str, $where_clause, $where_clause_html, '');
2832 $ret .= PMA_generateCheckboxForMulti($del_url, $is_display, $row_no, $where_clause_html, $del_query, $id_suffix='_right', '', '', '');
2833 } else { // $position == 'none'
2834 $ret .= PMA_generateCheckboxForMulti($del_url, $is_display, $row_no, $where_clause_html, $del_query, $id_suffix='_left', '', '', '');
2836 return $ret;