Translation update done using Pootle.
[phpmyadmin/ammaryasirr.git] / libraries / display_tbl.lib.php
blob5243dff9c011c62c19887d78f1f1954c1532c306
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * library for displaying table with results from all sort of select queries
6 * @package phpMyAdmin
7 */
9 /**
12 require_once './libraries/Index.class.php';
14 /**
15 * Defines the display mode to use for the results of a SQL query
17 * It uses a synthetic string that contains all the required informations.
18 * In this string:
19 * - the first two characters stand for the action to do while
20 * clicking on the "edit" link (e.g. 'ur' for update a row, 'nn' for no
21 * edit link...);
22 * - the next two characters stand for the action to do while
23 * clicking on the "delete" link (e.g. 'kp' for kill a process, 'nn' for
24 * no delete link...);
25 * - the next characters are boolean values (1/0) and respectively stand
26 * for sorting links, navigation bar, "insert a new row" link, the
27 * bookmark feature, the expand/collapse text/blob fields button and
28 * the "display printable view" option.
29 * Of course '0'/'1' means the feature won't/will be enabled.
31 * @param string &$the_disp_mode the synthetic value for display_mode (see a few
32 * lines above for explanations)
33 * @param integer &$the_total the total number of rows returned by the SQL query
34 * without any programmatically appended "LIMIT" clause
35 * (just a copy of $unlim_num_rows if it exists, else
36 * computed inside this function)
38 * @return array an array with explicit indexes for all the display
39 * elements
41 * @global string the database name
42 * @global string the table name
43 * @global integer the total number of rows returned by the SQL query
44 * without any programmatically appended "LIMIT" clause
45 * @global array the properties of the fields returned by the query
46 * @global string the URL to return to in case of error in a SQL
47 * statement
49 * @access private
51 * @see PMA_displayTable()
53 function PMA_setDisplayMode(&$the_disp_mode, &$the_total)
55 global $db, $table;
56 global $unlim_num_rows, $fields_meta;
57 global $err_url;
59 // 1. Initializes the $do_display array
60 $do_display = array();
61 $do_display['edit_lnk'] = $the_disp_mode[0] . $the_disp_mode[1];
62 $do_display['del_lnk'] = $the_disp_mode[2] . $the_disp_mode[3];
63 $do_display['sort_lnk'] = (string) $the_disp_mode[4];
64 $do_display['nav_bar'] = (string) $the_disp_mode[5];
65 $do_display['ins_row'] = (string) $the_disp_mode[6];
66 $do_display['bkm_form'] = (string) $the_disp_mode[7];
67 $do_display['text_btn'] = (string) $the_disp_mode[8];
68 $do_display['pview_lnk'] = (string) $the_disp_mode[9];
70 // 2. Display mode is not "false for all elements" -> updates the
71 // display mode
72 if ($the_disp_mode != 'nnnn000000') {
73 if (isset($GLOBALS['printview']) && $GLOBALS['printview'] == '1') {
74 // 2.0 Print view -> set all elements to false!
75 $do_display['edit_lnk'] = 'nn'; // no edit link
76 $do_display['del_lnk'] = 'nn'; // no delete link
77 $do_display['sort_lnk'] = (string) '0';
78 $do_display['nav_bar'] = (string) '0';
79 $do_display['ins_row'] = (string) '0';
80 $do_display['bkm_form'] = (string) '0';
81 $do_display['text_btn'] = (string) '0';
82 $do_display['pview_lnk'] = (string) '0';
83 } elseif ($GLOBALS['is_count'] || $GLOBALS['is_analyse'] || $GLOBALS['is_maint'] || $GLOBALS['is_explain']) {
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 $do_display['edit_lnk'] = 'nn'; // no edit link
88 $do_display['del_lnk'] = 'nn'; // no delete link
89 $do_display['sort_lnk'] = (string) '0';
90 $do_display['nav_bar'] = (string) '0';
91 $do_display['ins_row'] = (string) '0';
92 $do_display['bkm_form'] = (string) '1';
93 if ($GLOBALS['is_maint']) {
94 $do_display['text_btn'] = (string) '1';
95 } else {
96 $do_display['text_btn'] = (string) '0';
98 $do_display['pview_lnk'] = (string) '1';
99 } elseif ($GLOBALS['is_show']) {
100 // 2.2 Statement is a "SHOW..."
102 * 2.2.1
103 * @todo defines edit/delete links depending on show statement
105 $tmp = preg_match('@^SHOW[[:space:]]+(VARIABLES|(FULL[[:space:]]+)?PROCESSLIST|STATUS|TABLE|GRANTS|CREATE|LOGS|DATABASES|FIELDS)@i', $GLOBALS['sql_query'], $which);
106 if (isset($which[1]) && strpos(' ' . strtoupper($which[1]), 'PROCESSLIST') > 0) {
107 $do_display['edit_lnk'] = 'nn'; // no edit link
108 $do_display['del_lnk'] = 'kp'; // "kill process" type edit link
109 } else {
110 // Default case -> no links
111 $do_display['edit_lnk'] = 'nn'; // no edit link
112 $do_display['del_lnk'] = 'nn'; // no delete link
114 // 2.2.2 Other settings
115 $do_display['sort_lnk'] = (string) '0';
116 $do_display['nav_bar'] = (string) '0';
117 $do_display['ins_row'] = (string) '0';
118 $do_display['bkm_form'] = (string) '1';
119 $do_display['text_btn'] = (string) '1';
120 $do_display['pview_lnk'] = (string) '1';
121 } else {
122 // 2.3 Other statements (ie "SELECT" ones) -> updates
123 // $do_display['edit_lnk'], $do_display['del_lnk'] and
124 // $do_display['text_btn'] (keeps other default values)
125 $prev_table = $fields_meta[0]->table;
126 $do_display['text_btn'] = (string) '1';
127 for ($i = 0; $i < $GLOBALS['fields_cnt']; $i++) {
128 $is_link = ($do_display['edit_lnk'] != 'nn'
129 || $do_display['del_lnk'] != 'nn'
130 || $do_display['sort_lnk'] != '0'
131 || $do_display['ins_row'] != '0');
132 // 2.3.2 Displays edit/delete/sort/insert links?
133 if ($is_link
134 && ($fields_meta[$i]->table == '' || $fields_meta[$i]->table != $prev_table)) {
135 $do_display['edit_lnk'] = 'nn'; // don't display links
136 $do_display['del_lnk'] = 'nn';
138 * @todo May be problematic with same fields names in two joined table.
140 // $do_display['sort_lnk'] = (string) '0';
141 $do_display['ins_row'] = (string) '0';
142 if ($do_display['text_btn'] == '1') {
143 break;
145 } // end if (2.3.2)
146 // 2.3.3 Always display print view link
147 $do_display['pview_lnk'] = (string) '1';
148 $prev_table = $fields_meta[$i]->table;
149 } // end for
150 } // end if..elseif...else (2.1 -> 2.3)
151 } // end if (2)
153 // 3. Gets the total number of rows if it is unknown
154 if (isset($unlim_num_rows) && $unlim_num_rows != '') {
155 $the_total = $unlim_num_rows;
156 } elseif (($do_display['nav_bar'] == '1' || $do_display['sort_lnk'] == '1')
157 && (strlen($db) && !empty($table))) {
158 $the_total = PMA_Table::countRecords($db, $table);
161 // 4. If navigation bar or sorting fields names URLs should be
162 // displayed but there is only one row, change these settings to
163 // false
164 if ($do_display['nav_bar'] == '1' || $do_display['sort_lnk'] == '1') {
166 // - Do not display sort links if less than 2 rows.
167 // - For a VIEW we (probably) did not count the number of rows
168 // so don't test this number here, it would remove the possibility
169 // of sorting VIEW results.
170 if (isset($unlim_num_rows) && $unlim_num_rows < 2 && ! PMA_Table::isView($db, $table)) {
171 // force display of navbar for vertical/horizontal display-choice.
172 // $do_display['nav_bar'] = (string) '0';
173 $do_display['sort_lnk'] = (string) '0';
175 } // end if (3)
177 // 5. Updates the synthetic var
178 $the_disp_mode = join('', $do_display);
180 return $do_display;
181 } // end of the 'PMA_setDisplayMode()' function
185 * Return true if we are executing a query in the form of
186 * "SELECT * FROM <a table> ..."
188 * @return boolean
190 function PMA_isSelect()
192 // global variables set from sql.php
193 global $is_count, $is_export, $is_func, $is_analyse;
194 global $analyzed_sql;
196 return ! ($is_count || $is_export || $is_func || $is_analyse)
197 && count($analyzed_sql[0]['select_expr']) == 0
198 && isset($analyzed_sql[0]['queryflags']['select_from'])
199 && count($analyzed_sql[0]['table_ref']) == 1;
204 * Displays a navigation button
207 * @param string $caption iconic caption for button
208 * @param string $title text for button
209 * @param integer $pos position for next query
210 * @param string $html_sql_query query ready for display
211 * @param string $onsubmit optional onsubmit clause
212 * @param string $input_for_real_end optional hidden field for special treatment
213 * @param string $onclick optional onclick clause
215 * @global string $db the database name
216 * @global string $table the table name
217 * @global string $goto the URL to go back in case of errors
219 * @access private
221 * @see PMA_displayTableNavigation()
223 function PMA_displayTableNavigationOneButton($caption, $title, $pos, $html_sql_query, $onsubmit = '', $input_for_real_end = '', $onclick = '') {
225 global $db, $table, $goto;
227 $caption_output = '';
228 // for true or 'both'
229 if ($GLOBALS['cfg']['NavigationBarIconic']) {
230 $caption_output .= $caption;
232 // for false or 'both'
233 if (false === $GLOBALS['cfg']['NavigationBarIconic'] || 'both' === $GLOBALS['cfg']['NavigationBarIconic']) {
234 $caption_output .= '&nbsp;' . $title;
236 $title_output = ' title="' . $title . '"';
238 <td>
239 <form action="sql.php" method="post" <?php echo $onsubmit; ?>>
240 <?php echo PMA_generate_common_hidden_inputs($db, $table); ?>
241 <input type="hidden" name="sql_query" value="<?php echo $html_sql_query; ?>" />
242 <input type="hidden" name="pos" value="<?php echo $pos; ?>" />
243 <input type="hidden" name="goto" value="<?php echo $goto; ?>" />
244 <?php echo $input_for_real_end; ?>
245 <input type="submit" name="navig" <?php echo ($GLOBALS['cfg']['AjaxEnable'] ? ' class="ajax" ' : '' ); ?> value="<?php echo $caption_output; ?>"<?php echo $title_output . $onclick; ?> />
246 </form>
247 </td>
248 <?php
249 } // end function PMA_displayTableNavigationOneButton()
252 * Displays a navigation bar to browse among the results of a SQL query
254 * @param integer $pos_next the offset for the "next" page
255 * @param integer $pos_prev the offset for the "previous" page
256 * @param string $sql_query the URL-encoded query
257 * @param string $id_for_direction_dropdown the id for the direction dropdown
259 * @global string $db the database name
260 * @global string $table the table name
261 * @global string $goto the URL to go back in case of errors
262 * @global integer $num_rows the total number of rows returned by the
263 * SQL query
264 * @global integer $unlim_num_rows the total number of rows returned by the
265 * SQL any programmatically appended "LIMIT" clause
266 * @global boolean $is_innodb whether its InnoDB or not
267 * @global array $showtable table definitions
269 * @access private
271 * @see PMA_displayTable()
273 function PMA_displayTableNavigation($pos_next, $pos_prev, $sql_query, $id_for_direction_dropdown)
275 global $db, $table, $goto;
276 global $num_rows, $unlim_num_rows;
277 global $is_innodb;
278 global $showtable;
280 // here, using htmlentities() would cause problems if the query
281 // contains accented characters
282 $html_sql_query = htmlspecialchars($sql_query);
285 * @todo move this to a central place
286 * @todo for other future table types
288 $is_innodb = (isset($showtable['Type']) && $showtable['Type'] == 'InnoDB');
292 <!-- Navigation bar -->
293 <table border="0" cellpadding="0" cellspacing="0" class="navigation">
294 <tr>
295 <td class="navigation_separator"></td>
296 <?php
297 // Move to the beginning or to the previous page
298 if ($_SESSION['tmp_user_values']['pos'] && $_SESSION['tmp_user_values']['max_rows'] != 'all') {
299 PMA_displayTableNavigationOneButton('&lt;&lt;', __('Begin'), 0, $html_sql_query);
300 PMA_displayTableNavigationOneButton('&lt;', __('Previous'), $pos_prev, $html_sql_query);
302 } // end move back
304 //page redirection
305 // (unless we are showing all records)
306 if ('all' != $_SESSION['tmp_user_values']['max_rows']) { //if1
307 $pageNow = @floor($_SESSION['tmp_user_values']['pos'] / $_SESSION['tmp_user_values']['max_rows']) + 1;
308 $nbTotalPage = @ceil($unlim_num_rows / $_SESSION['tmp_user_values']['max_rows']);
310 if ($nbTotalPage > 1) { //if2
312 <td>
313 <?php
314 $_url_params = array(
315 'db' => $db,
316 'table' => $table,
317 'sql_query' => $sql_query,
318 'goto' => $goto,
320 //<form> to keep the form alignment of button < and <<
321 // and also to know what to execute when the selector changes
322 echo '<form action="sql.php' . PMA_generate_common_url($_url_params). '" method="post">';
323 echo PMA_pageselector(
324 $_SESSION['tmp_user_values']['max_rows'],
325 $pageNow,
326 $nbTotalPage,
327 200,
334 </form>
335 </td>
336 <?php
337 } //_if2
338 } //_if1
340 // Display the "Show all" button if allowed
341 if ($GLOBALS['cfg']['ShowAll'] && ($num_rows < $unlim_num_rows)) {
342 echo "\n";
344 <td>
345 <form action="sql.php" method="post">
346 <?php echo PMA_generate_common_hidden_inputs($db, $table); ?>
347 <input type="hidden" name="sql_query" value="<?php echo $html_sql_query; ?>" />
348 <input type="hidden" name="pos" value="0" />
349 <input type="hidden" name="session_max_rows" value="all" />
350 <input type="hidden" name="goto" value="<?php echo $goto; ?>" />
351 <input type="submit" name="navig" value="<?php echo __('Show all'); ?>" />
352 </form>
353 </td>
354 <?php
355 } // end show all
357 // Move to the next page or to the last one
358 if (($_SESSION['tmp_user_values']['pos'] + $_SESSION['tmp_user_values']['max_rows'] < $unlim_num_rows) && $num_rows >= $_SESSION['tmp_user_values']['max_rows']
359 && $_SESSION['tmp_user_values']['max_rows'] != 'all') {
361 // display the Next button
362 PMA_displayTableNavigationOneButton('&gt;',
363 __('Next'),
364 $pos_next,
365 $html_sql_query);
367 // prepare some options for the End button
368 if ($is_innodb && $unlim_num_rows > $GLOBALS['cfg']['MaxExactCount']) {
369 $input_for_real_end = '<input id="real_end_input" type="hidden" name="find_real_end" value="1" />';
370 // no backquote around this message
371 $onclick = '';
372 } else {
373 $input_for_real_end = $onclick = '';
376 // display the End button
377 PMA_displayTableNavigationOneButton('&gt;&gt;',
378 __('End'),
379 @((ceil($unlim_num_rows / $_SESSION['tmp_user_values']['max_rows'])- 1) * $_SESSION['tmp_user_values']['max_rows']),
380 $html_sql_query,
381 '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') . '"',
382 $input_for_real_end,
383 $onclick
385 } // end move toward
387 // show separator if pagination happen
388 if ($nbTotalPage > 1) {
389 echo '<td><div class="navigation_separator">|</div></td>';
392 <td>
393 <div class="restore_column hide">
394 <input type="submit" value="<?php echo __('Restore column order'); ?>" />
395 <div class="navigation_separator">|</div>
396 </div>
397 <?php
398 if (PMA_isSelect()) {
399 // generate the column order, if it is set
400 $pmatable = new PMA_Table($GLOBALS['table'], $GLOBALS['db']);
401 $col_order = $pmatable->getUiProp(PMA_Table::PROP_COLUMN_ORDER);
402 if ($col_order) {
403 echo '<input id="col_order" type="hidden" value="' . implode(',', $col_order) . '" />';
405 $col_visib = $pmatable->getUiProp(PMA_Table::PROP_COLUMN_VISIB);
406 if ($col_visib) {
407 echo '<input id="col_visib" type="hidden" value="' . implode(',', $col_visib) . '" />';
409 // generate table create time
410 echo '<input id="table_create_time" type="hidden" value="' .
411 PMA_Table::sGetStatusInfo($GLOBALS['db'], $GLOBALS['table'], 'Create_time') . '" />';
413 // generate hints
414 echo '<input id="col_order_hint" type="hidden" value="' . __('Drag to reorder') . '" />';
415 echo '<input id="sort_hint" type="hidden" value="' . __('Click to sort') . '" />';
416 echo '<input id="col_mark_hint" type="hidden" value="' . __('Click to mark/unmark') . '" />';
417 echo '<input id="col_visib_hint" type="hidden" value="' . __('Click the drop-down arrow<br />to toggle column\'s visibility') . '" />';
418 echo '<input id="show_all_col_text" type="hidden" value="' . __('Show all') . '" />';
420 </td>
422 <?php // if displaying a VIEW, $unlim_num_rows could be zero because
423 // of $cfg['MaxExactCountViews']; in this case, avoid passing
424 // the 5th parameter to checkFormElementInRange()
425 // (this means we can't validate the upper limit ?>
426 <td class="navigation_goto">
427 <form action="sql.php" method="post"
428 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 : ''; ?>))">
429 <?php echo PMA_generate_common_hidden_inputs($db, $table); ?>
430 <input type="hidden" name="sql_query" value="<?php echo $html_sql_query; ?>" />
431 <input type="hidden" name="goto" value="<?php echo $goto; ?>" />
432 <input type="submit" name="navig" <?php echo ($GLOBALS['cfg']['AjaxEnable'] ? ' class="ajax"' : ''); ?> value="<?php echo __('Show'); ?> :" />
433 <?php echo __('Start row') . ': ' . "\n"; ?>
434 <input type="text" name="pos" size="3" value="<?php echo (($pos_next >= $unlim_num_rows) ? 0 : $pos_next); ?>" class="textfield" onfocus="this.select()" />
435 <?php echo __('Number of rows') . ': ' . "\n"; ?>
436 <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()" />
437 <?php
438 if ($GLOBALS['cfg']['ShowDisplayDirection']) {
439 // Display mode (horizontal/vertical and repeat headers)
440 echo __('Mode') . ': ' . "\n";
441 $choices = array(
442 'horizontal' => __('horizontal'),
443 'horizontalflipped' => __('horizontal (rotated headers)'),
444 'vertical' => __('vertical'));
445 echo PMA_generate_html_dropdown('disp_direction', $choices, $_SESSION['tmp_user_values']['disp_direction'], $id_for_direction_dropdown);
446 unset($choices);
449 printf(__('Headers every %s rows'),
450 '<input type="text" size="3" name="repeat_cells" value="' . $_SESSION['tmp_user_values']['repeat_cells'] . '" class="textfield" />');
451 echo "\n";
453 </form>
454 </td>
455 <td class="navigation_separator"></td>
456 </tr>
457 </table>
459 <?php
460 } // end of the 'PMA_displayTableNavigation()' function
464 * Displays the headers of the results table
466 * @param array which elements to display
467 * @param array the list of fields properties
468 * @param integer the total number of fields returned by the SQL query
469 * @param array the analyzed query
471 * @return boolean $clause_is_unique
473 * @global string $db the database name
474 * @global string $table the table name
475 * @global string $goto the URL to go back in case of errors
476 * @global string $sql_query the SQL query
477 * @global integer $num_rows the total number of rows returned by the
478 * SQL query
479 * @global array $vertical_display informations used with vertical display
480 * mode
482 * @access private
484 * @see PMA_displayTable()
486 function PMA_displayTableHeaders(&$is_display, &$fields_meta, $fields_cnt = 0, $analyzed_sql = '', $sort_expression, $sort_expression_nodirection, $sort_direction)
488 global $db, $table, $goto;
489 global $sql_query, $num_rows;
490 global $vertical_display, $highlight_columns;
492 // required to generate sort links that will remember whether the
493 // "Show all" button has been clicked
494 $sql_md5 = md5($GLOBALS['sql_query']);
495 $session_max_rows = $_SESSION['tmp_user_values']['query'][$sql_md5]['max_rows'];
497 if ($analyzed_sql == '') {
498 $analyzed_sql = array();
501 // can the result be sorted?
502 if ($is_display['sort_lnk'] == '1') {
504 // Just as fallback
505 $unsorted_sql_query = $sql_query;
506 if (isset($analyzed_sql[0]['unsorted_query'])) {
507 $unsorted_sql_query = $analyzed_sql[0]['unsorted_query'];
509 // Handles the case of multiple clicks on a column's header
510 // which would add many spaces before "ORDER BY" in the
511 // generated query.
512 $unsorted_sql_query = trim($unsorted_sql_query);
514 // sorting by indexes, only if it makes sense (only one table ref)
515 if (isset($analyzed_sql) && isset($analyzed_sql[0]) &&
516 isset($analyzed_sql[0]['querytype']) && $analyzed_sql[0]['querytype'] == 'SELECT' &&
517 isset($analyzed_sql[0]['table_ref']) && count($analyzed_sql[0]['table_ref']) == 1) {
519 // grab indexes data:
520 $indexes = PMA_Index::getFromTable($table, $db);
522 // do we have any index?
523 if ($indexes) {
525 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
526 || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') {
527 $span = $fields_cnt;
528 if ($is_display['edit_lnk'] != 'nn') {
529 $span++;
531 if ($is_display['del_lnk'] != 'nn') {
532 $span++;
534 if ($is_display['del_lnk'] != 'kp' && $is_display['del_lnk'] != 'nn') {
535 $span++;
537 } else {
538 $span = $num_rows + floor($num_rows/$_SESSION['tmp_user_values']['repeat_cells']) + 1;
541 echo '<form action="sql.php" method="post">' . "\n";
542 echo PMA_generate_common_hidden_inputs($db, $table);
543 echo __('Sort by key') . ': <select name="sql_query" onchange="this.form.submit();">' . "\n";
544 $used_index = false;
545 $local_order = (isset($sort_expression) ? $sort_expression : '');
546 foreach ($indexes as $index) {
547 $asc_sort = '`' . implode('` ASC, `', array_keys($index->getColumns())) . '` ASC';
548 $desc_sort = '`' . implode('` DESC, `', array_keys($index->getColumns())) . '` DESC';
549 $used_index = $used_index || $local_order == $asc_sort || $local_order == $desc_sort;
550 echo '<option value="'
551 . htmlspecialchars($unsorted_sql_query . ' ORDER BY ' . $asc_sort)
552 . '"' . ($local_order == $asc_sort ? ' selected="selected"' : '')
553 . '>' . htmlspecialchars($index->getName()) . ' ('
554 . __('Ascending') . ')</option>';
555 echo '<option value="'
556 . htmlspecialchars($unsorted_sql_query . ' ORDER BY ' . $desc_sort)
557 . '"' . ($local_order == $desc_sort ? ' selected="selected"' : '')
558 . '>' . htmlspecialchars($index->getName()) . ' ('
559 . __('Descending') . ')</option>';
561 echo '<option value="' . htmlspecialchars($unsorted_sql_query) . '"' . ($used_index ? '' : ' selected="selected"') . '>' . __('None') . '</option>';
562 echo '</select>' . "\n";
563 echo '<noscript><input type="submit" value="' . __('Go') . '" /></noscript>';
564 echo '</form>' . "\n";
570 $vertical_display['emptypre'] = 0;
571 $vertical_display['emptyafter'] = 0;
572 $vertical_display['textbtn'] = '';
574 // Display options (if we are not in print view)
575 if (! (isset($GLOBALS['printview']) && $GLOBALS['printview'] == '1')) {
576 echo '<form method="post" action="sql.php" name="displayOptionsForm" id="displayOptionsForm"';
577 if ($GLOBALS['cfg']['AjaxEnable']) {
578 echo ' class="ajax" ';
580 echo '>';
581 $url_params = array(
582 'db' => $db,
583 'table' => $table,
584 'sql_query' => $sql_query,
585 'goto' => $goto,
586 'display_options_form' => 1
588 echo PMA_generate_common_hidden_inputs($url_params);
589 echo '<br />';
590 PMA_generate_slider_effect('displayoptions',__('Options'));
591 echo '<fieldset>';
593 echo '<div class="formelement">';
594 $choices = array(
595 'P' => __('Partial texts'),
596 'F' => __('Full texts')
598 PMA_display_html_radio('display_text', $choices, $_SESSION['tmp_user_values']['display_text']);
599 echo '</div>';
601 // prepare full/partial text button or link
602 if ($_SESSION['tmp_user_values']['display_text']=='F') {
603 // currently in fulltext mode so show the opposite link
604 $tmp_image_file = $GLOBALS['pmaThemeImage'] . 's_partialtext.png';
605 $tmp_txt = __('Partial texts');
606 $url_params['display_text'] = 'P';
607 } else {
608 $tmp_image_file = $GLOBALS['pmaThemeImage'] . 's_fulltext.png';
609 $tmp_txt = __('Full texts');
610 $url_params['display_text'] = 'F';
613 $tmp_image = '<img class="fulltext" src="' . $tmp_image_file . '" alt="' . $tmp_txt . '" title="' . $tmp_txt . '" />';
614 $tmp_url = 'sql.php' . PMA_generate_common_url($url_params);
615 $full_or_partial_text_link = PMA_linkOrButton($tmp_url, $tmp_image, array(), false);
616 unset($tmp_image_file, $tmp_txt, $tmp_url, $tmp_image);
619 if ($GLOBALS['cfgRelation']['relwork'] && $GLOBALS['cfgRelation']['displaywork']) {
620 echo '<div class="formelement">';
621 $choices = array(
622 'K' => __('Relational key'),
623 'D' => __('Relational display column')
625 PMA_display_html_radio('relational_display', $choices, $_SESSION['tmp_user_values']['relational_display']);
626 echo '</div>';
629 echo '<div class="formelement">';
630 PMA_display_html_checkbox('display_binary', __('Show binary contents'), ! empty($_SESSION['tmp_user_values']['display_binary']), false);
631 echo '<br />';
632 PMA_display_html_checkbox('display_blob', __('Show BLOB contents'), ! empty($_SESSION['tmp_user_values']['display_blob']), false);
633 echo '<br />';
634 PMA_display_html_checkbox('display_binary_as_hex', __('Show binary contents as HEX'), ! empty($_SESSION['tmp_user_values']['display_binary_as_hex']), false);
635 echo '</div>';
637 // I would have preferred to name this "display_transformation".
638 // This is the only way I found to be able to keep this setting sticky
639 // per SQL query, and at the same time have a default that displays
640 // the transformations.
641 echo '<div class="formelement">';
642 PMA_display_html_checkbox('hide_transformation', __('Hide') . ' ' . __('Browser transformation'), ! empty($_SESSION['tmp_user_values']['hide_transformation']), false);
643 echo '</div>';
645 echo '<div class="formelement">';
646 $choices = array(
647 'GEOM' => __('Geometry'),
648 'WKT' => __('Well Known Text'),
649 'WKB' => __('Well Known Binary')
651 PMA_display_html_radio('geometry_display', $choices, $_SESSION['tmp_user_values']['geometry_display']);
652 echo '</div>';
654 echo '<div class="clearfloat"></div>';
655 echo '</fieldset>';
657 echo '<fieldset class="tblFooters">';
658 echo '<input type="submit" value="' . __('Go') . '" />';
659 echo '</fieldset>';
660 echo '</div>';
661 echo '</form>';
664 // Start of form for multi-rows edit/delete/export
666 if ($is_display['del_lnk'] == 'dr' || $is_display['del_lnk'] == 'kp') {
667 echo '<form method="post" action="tbl_row_action.php" name="resultsForm" id="resultsForm"';
668 if ($GLOBALS['cfg']['AjaxEnable']) {
669 echo ' class="ajax" ';
671 echo '>' . "\n";
672 echo PMA_generate_common_hidden_inputs($db, $table, 1);
673 echo '<input type="hidden" name="goto" value="sql.php" />' . "\n";
676 echo '<table id="table_results" class="data';
677 if ($GLOBALS['cfg']['AjaxEnable']) {
678 echo ' ajax';
680 echo '">' . "\n";
681 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
682 || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') {
683 echo '<thead><tr>' . "\n";
686 // 1. Displays the full/partial text button (part 1)...
687 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
688 || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') {
689 $colspan = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn')
690 ? ' colspan="4"'
691 : '';
692 } else {
693 $rowspan = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn')
694 ? ' rowspan="4"'
695 : '';
698 // ... before the result table
699 if (($is_display['edit_lnk'] == 'nn' && $is_display['del_lnk'] == 'nn')
700 && $is_display['text_btn'] == '1') {
701 $vertical_display['emptypre'] = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn') ? 4 : 0;
702 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
703 || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') {
705 <th colspan="<?php echo $fields_cnt; ?>"></th>
706 </tr>
707 <tr>
708 <?php
709 } // end horizontal/horizontalflipped mode
710 else {
712 <tr>
713 <th colspan="<?php echo $num_rows + floor($num_rows/$_SESSION['tmp_user_values']['repeat_cells']) + 1; ?>"></th>
714 </tr>
715 <?php
716 } // end vertical mode
719 // ... at the left column of the result table header if possible
720 // and required
721 elseif (($GLOBALS['cfg']['RowActionLinks'] == 'left' || $GLOBALS['cfg']['RowActionLinks'] == 'both')
722 && $is_display['text_btn'] == '1') {
723 $vertical_display['emptypre'] = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn') ? 4 : 0;
724 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
725 || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') {
727 <th <?php echo $colspan; ?>><?php echo $full_or_partial_text_link;?></th>
728 <?php
729 } // end horizontal/horizontalflipped mode
730 else {
731 $vertical_display['textbtn'] = ' <th ' . $rowspan . ' valign="middle">' . "\n"
732 . ' ' . "\n"
733 . ' </th>' . "\n";
734 } // end vertical mode
737 // ... elseif no button, displays empty(ies) col(s) if required
738 elseif (($GLOBALS['cfg']['RowActionLinks'] == 'left' || $GLOBALS['cfg']['RowActionLinks'] == 'both')
739 && ($is_display['edit_lnk'] != 'nn' || $is_display['del_lnk'] != 'nn')) {
740 $vertical_display['emptypre'] = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn') ? 4 : 0;
741 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
742 || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') {
744 <td<?php echo $colspan; ?>></td>
745 <?php
746 } // end horizontal/horizontalfipped mode
747 else {
748 $vertical_display['textbtn'] = ' <td' . $rowspan . '></td>' . "\n";
749 } // end vertical mode
752 // ... elseif display an empty column if the actions links are disabled to match the rest of the table
753 elseif ($GLOBALS['cfg']['RowActionLinks'] == 'none' && ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
754 || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped')) {
755 echo '<th></th>';
758 // 2. Displays the fields' name
759 // 2.0 If sorting links should be used, checks if the query is a "JOIN"
760 // statement (see 2.1.3)
762 // 2.0.1 Prepare Display column comments if enabled ($GLOBALS['cfg']['ShowBrowseComments']).
763 // Do not show comments, if using horizontalflipped mode, because of space usage
764 if ($GLOBALS['cfg']['ShowBrowseComments']
765 && $_SESSION['tmp_user_values']['disp_direction'] != 'horizontalflipped') {
766 $comments_map = array();
767 if (isset($analyzed_sql[0]) && is_array($analyzed_sql[0])) {
768 foreach ($analyzed_sql[0]['table_ref'] as $tbl) {
769 $tb = $tbl['table_true_name'];
770 $comments_map[$tb] = PMA_getComments($db, $tb);
771 unset($tb);
776 if ($GLOBALS['cfgRelation']['commwork'] && $GLOBALS['cfgRelation']['mimework'] && $GLOBALS['cfg']['BrowseMIME'] && ! $_SESSION['tmp_user_values']['hide_transformation']) {
777 require_once './libraries/transformations.lib.php';
778 $GLOBALS['mime_map'] = PMA_getMIME($db, $table);
781 // See if we have to highlight any header fields of a WHERE query.
782 // Uses SQL-Parser results.
783 $highlight_columns = array();
784 if (isset($analyzed_sql) && isset($analyzed_sql[0]) &&
785 isset($analyzed_sql[0]['where_clause_identifiers'])) {
787 $wi = 0;
788 if (isset($analyzed_sql[0]['where_clause_identifiers']) && is_array($analyzed_sql[0]['where_clause_identifiers'])) {
789 foreach ($analyzed_sql[0]['where_clause_identifiers'] AS $wci_nr => $wci) {
790 $highlight_columns[$wci] = 'true';
795 if (PMA_isSelect()) {
796 // prepare to get the column order, if available
797 $pmatable = new PMA_Table($GLOBALS['table'], $GLOBALS['db']);
798 $col_order = $pmatable->getUiProp(PMA_Table::PROP_COLUMN_ORDER);
799 $col_visib = $pmatable->getUiProp(PMA_Table::PROP_COLUMN_VISIB);
800 } else {
801 $col_order = false;
802 $col_visib = false;
805 for ($j = 0; $j < $fields_cnt; $j++) {
806 // assign $i with appropriate column order
807 $i = $col_order ? $col_order[$j] : $j;
808 // See if this column should get highlight because it's used in the
809 // where-query.
810 if (isset($highlight_columns[$fields_meta[$i]->name]) || isset($highlight_columns[PMA_backquote($fields_meta[$i]->name)])) {
811 $condition_field = true;
812 } else {
813 $condition_field = false;
816 // 2.0 Prepare comment-HTML-wrappers for each row, if defined/enabled.
817 if (isset($comments_map) &&
818 isset($comments_map[$fields_meta[$i]->table]) &&
819 isset($comments_map[$fields_meta[$i]->table][$fields_meta[$i]->name])) {
820 $comments = '<span class="tblcomment">' . htmlspecialchars($comments_map[$fields_meta[$i]->table][$fields_meta[$i]->name]) . '</span>';
821 } else {
822 $comments = '';
825 // 2.1 Results can be sorted
826 if ($is_display['sort_lnk'] == '1') {
828 // 2.1.1 Checks if the table name is required; it's the case
829 // for a query with a "JOIN" statement and if the column
830 // isn't aliased, or in queries like
831 // SELECT `1`.`master_field` , `2`.`master_field`
832 // FROM `PMA_relation` AS `1` , `PMA_relation` AS `2`
834 if (isset($fields_meta[$i]->table) && strlen($fields_meta[$i]->table)) {
835 $sort_tbl = PMA_backquote($fields_meta[$i]->table) . '.';
836 } else {
837 $sort_tbl = '';
840 // 2.1.2 Checks if the current column is used to sort the
841 // results
842 // the orgname member does not exist for all MySQL versions
843 // but if found, it's the one on which to sort
844 $name_to_use_in_sort = $fields_meta[$i]->name;
845 $is_orgname = false;
846 if (isset($fields_meta[$i]->orgname) && strlen($fields_meta[$i]->orgname)) {
847 $name_to_use_in_sort = $fields_meta[$i]->orgname;
848 $is_orgname = true;
850 // $name_to_use_in_sort might contain a space due to
851 // formatting of function expressions like "COUNT(name )"
852 // so we remove the space in this situation
853 $name_to_use_in_sort = str_replace(' )', ')', $name_to_use_in_sort);
855 if (empty($sort_expression)) {
856 $is_in_sort = false;
857 } else {
858 // Field name may be preceded by a space, or any number
859 // of characters followed by a dot (tablename.fieldname)
860 // so do a direct comparison for the sort expression;
861 // this avoids problems with queries like
862 // "SELECT id, count(id)..." and clicking to sort
863 // on id or on count(id).
864 // Another query to test this:
865 // SELECT p.*, FROM_UNIXTIME(p.temps) FROM mytable AS p
866 // (and try clicking on each column's header twice)
867 if (! empty($sort_tbl) && strpos($sort_expression_nodirection, $sort_tbl) === false && strpos($sort_expression_nodirection, '(') === false) {
868 $sort_expression_nodirection = $sort_tbl . $sort_expression_nodirection;
870 $is_in_sort = (str_replace('`', '', $sort_tbl) . $name_to_use_in_sort == str_replace('`', '', $sort_expression_nodirection) ? true : false);
872 // 2.1.3 Check the field name for a bracket.
873 // If it contains one, it's probably a function column
874 // like 'COUNT(`field`)'
875 // It still might be a column name of a view. See bug #3383711
876 // Check is_orgname.
877 if (strpos($name_to_use_in_sort, '(') !== false && ! $is_orgname) {
878 $sort_order = ' ORDER BY ' . $name_to_use_in_sort . ' ';
879 } else {
880 $sort_order = ' ORDER BY ' . $sort_tbl . PMA_backquote($name_to_use_in_sort) . ' ';
882 unset($name_to_use_in_sort);
883 unset($is_orgname);
885 // 2.1.4 Do define the sorting URL
886 if (! $is_in_sort) {
887 // patch #455484 ("Smart" order)
888 $GLOBALS['cfg']['Order'] = strtoupper($GLOBALS['cfg']['Order']);
889 if ($GLOBALS['cfg']['Order'] === 'SMART') {
890 $sort_order .= (preg_match('@time|date@i', $fields_meta[$i]->type)) ? 'DESC' : 'ASC';
891 } else {
892 $sort_order .= $GLOBALS['cfg']['Order'];
894 $order_img = '';
895 } elseif ('DESC' == $sort_direction) {
896 $sort_order .= ' ASC';
897 $order_img = ' <img class="icon ic_s_desc" src="themes/dot.gif" alt="'. __('Descending') . '" title="'. __('Descending') . '" id="soimg' . $i . '" />';
898 } else {
899 $sort_order .= ' DESC';
900 $order_img = ' <img class="icon ic_s_asc" src="themes/dot.gif" alt="'. __('Ascending') . '" title="'. __('Ascending') . '" id="soimg' . $i . '" />';
903 if (preg_match('@(.*)([[:space:]](LIMIT (.*)|PROCEDURE (.*)|FOR UPDATE|LOCK IN SHARE MODE))@is', $unsorted_sql_query, $regs3)) {
904 $sorted_sql_query = $regs3[1] . $sort_order . $regs3[2];
905 } else {
906 $sorted_sql_query = $unsorted_sql_query . $sort_order;
908 $_url_params = array(
909 'db' => $db,
910 'table' => $table,
911 'sql_query' => $sorted_sql_query,
912 'session_max_rows' => $session_max_rows
914 $order_url = 'sql.php' . PMA_generate_common_url($_url_params);
916 // 2.1.5 Displays the sorting URL
917 // enable sort order swapping for image
918 $order_link_params = array();
919 if (isset($order_img) && $order_img!='') {
920 if (strstr($order_img, 'asc')) {
921 $order_link_params['onmouseover'] = 'if ($(\'#soimg' . $i . '\').length > 0) { $(\'#soimg' . $i . '\').attr(\'class\', \'icon ic_s_desc\'); }';
922 $order_link_params['onmouseout'] = 'if ($(\'#soimg' . $i . '\').length > 0) { $(\'#soimg' . $i . '\').attr(\'class\', \'icon ic_s_asc\'); }';
923 } elseif (strstr($order_img, 'desc')) {
924 $order_link_params['onmouseover'] = 'if ($(\'#soimg' . $i . '\').length > 0) { $(\'#soimg' . $i . '\').attr(\'class\', \'icon ic_s_asc\'); }';
925 $order_link_params['onmouseout'] = 'if ($(\'#soimg' . $i . '\').length > 0) { $(\'#soimg' . $i . '\').attr(\'class\', \'icon ic_s_desc\'); }';
928 if ($GLOBALS['cfg']['HeaderFlipType'] == 'auto') {
929 if (PMA_USR_BROWSER_AGENT == 'IE') {
930 $GLOBALS['cfg']['HeaderFlipType'] = 'css';
931 } else {
932 $GLOBALS['cfg']['HeaderFlipType'] = 'fake';
935 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped'
936 && $GLOBALS['cfg']['HeaderFlipType'] == 'css') {
937 $order_link_params['style'] = 'direction: ltr; writing-mode: tb-rl;';
939 $order_link_params['title'] = __('Sort');
940 $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));
941 $order_link = PMA_linkOrButton($order_url, $order_link_content . $order_img, $order_link_params, false, true);
943 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
944 || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') {
945 echo '<th';
946 $th_class = array();
947 $th_class[] = 'draggable';
948 if ($col_visib && !$col_visib[$j]) {
949 $th_class[] = 'hide';
951 if ($condition_field) {
952 $th_class[] = 'condition';
954 $th_class[] = 'column_heading';
955 if ($GLOBALS['cfg']['BrowsePointerEnable'] == true) {
956 $th_class[] = 'pointer';
958 if ($GLOBALS['cfg']['BrowseMarkerEnable'] == true) {
959 $th_class[] = 'marker';
961 echo ' class="' . implode(' ', $th_class) . '"';
963 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') {
964 echo ' valign="bottom"';
966 echo '>' . $order_link . $comments . '</th>';
968 $vertical_display['desc'][] = ' <th '
969 . 'class="draggable'
970 . ($condition_field ? ' condition' : '')
971 . '">' . "\n"
972 . $order_link . $comments . ' </th>' . "\n";
973 } // end if (2.1)
975 // 2.2 Results can't be sorted
976 else {
977 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
978 || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') {
979 echo '<th';
980 $th_class = array();
981 $th_class[] = 'draggable';
982 if ($col_visib && !$col_visib[$j]) {
983 $th_class[] = 'hide';
985 if ($condition_field) {
986 $th_class[] = 'condition';
988 echo ' class="' . implode(' ', $th_class) . '"';
989 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') {
990 echo ' valign="bottom"';
992 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped'
993 && $GLOBALS['cfg']['HeaderFlipType'] == 'css') {
994 echo ' style="direction: ltr; writing-mode: tb-rl;"';
996 echo '>';
997 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped'
998 && $GLOBALS['cfg']['HeaderFlipType'] == 'fake') {
999 echo PMA_flipstring(htmlspecialchars($fields_meta[$i]->name), '<br />');
1000 } else {
1001 echo htmlspecialchars($fields_meta[$i]->name);
1003 echo "\n" . $comments . '</th>';
1005 $vertical_display['desc'][] = ' <th '
1006 . 'class="draggable'
1007 . ($condition_field ? ' condition"' : '')
1008 . '">' . "\n"
1009 . ' ' . htmlspecialchars($fields_meta[$i]->name) . "\n"
1010 . $comments . ' </th>';
1011 } // end else (2.2)
1012 } // end for
1014 // 3. Displays the needed checkboxes at the right
1015 // column of the result table header if possible and required...
1016 if (($GLOBALS['cfg']['RowActionLinks'] == 'right' || $GLOBALS['cfg']['RowActionLinks'] == 'both')
1017 && ($is_display['edit_lnk'] != 'nn' || $is_display['del_lnk'] != 'nn')
1018 && $is_display['text_btn'] == '1') {
1019 $vertical_display['emptyafter'] = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn') ? 4 : 1;
1020 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
1021 || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') {
1022 echo "\n";
1024 <th <?php echo $colspan; ?>><?php echo $full_or_partial_text_link;?>
1025 </th>
1026 <?php
1027 } // end horizontal/horizontalflipped mode
1028 else {
1029 $vertical_display['textbtn'] = ' <th ' . $rowspan . ' valign="middle">' . "\n"
1030 . ' ' . "\n"
1031 . ' </th>' . "\n";
1032 } // end vertical mode
1035 // ... elseif no button, displays empty columns if required
1036 // (unless coming from Browse mode print view)
1037 elseif (($GLOBALS['cfg']['RowActionLinks'] == 'left' || $GLOBALS['cfg']['RowActionLinks'] == 'both')
1038 && ($is_display['edit_lnk'] == 'nn' && $is_display['del_lnk'] == 'nn')
1039 && (!$GLOBALS['is_header_sent'])) {
1040 $vertical_display['emptyafter'] = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn') ? 4 : 1;
1041 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
1042 || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') {
1043 echo "\n";
1045 <td<?php echo $colspan; ?>></td>
1046 <?php
1047 } // end horizontal/horizontalflipped mode
1048 else {
1049 $vertical_display['textbtn'] = ' <td' . $rowspan . '></td>' . "\n";
1050 } // end vertical mode
1053 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
1054 || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') {
1056 </tr>
1057 </thead>
1058 <?php
1061 return true;
1062 } // end of the 'PMA_displayTableHeaders()' function
1066 * Prepares the display for a value
1068 * @param string $class
1069 * @param string $condition_field
1070 * @param string $value
1072 * @return string the td
1074 function PMA_buildValueDisplay($class, $condition_field, $value) {
1075 return '<td align="left"' . ' class="' . $class . ($condition_field ? ' condition' : '') . '">' . $value . '</td>';
1079 * Prepares the display for a null value
1081 * @param string $class
1082 * @param string $condition_field
1084 * @return string the td
1086 function PMA_buildNullDisplay($class, $condition_field) {
1087 // the null class is needed for inline editing
1088 return '<td align="right"' . ' class="' . $class . ($condition_field ? ' condition' : '') . ' null"><i>NULL</i></td>';
1092 * Prepares the display for an empty value
1094 * @param string $class
1095 * @param string $condition_field
1096 * @param string $align
1098 * @return string the td
1100 function PMA_buildEmptyDisplay($class, $condition_field, $meta, $align = '') {
1101 $nowrap = ' nowrap';
1102 return '<td ' . $align . ' class="' . PMA_addClass($class, $condition_field, $meta, $nowrap) . '"></td>';
1106 * Adds the relavant classes.
1108 * @param string $class
1109 * @param string $condition_field
1110 * @param object $meta the meta-information about this field
1111 * @param string $nowrap
1112 * @param bool $is_field_truncated
1113 * @param string $transform_function
1114 * @param string $default_function
1116 * @return string the list of classes
1118 function PMA_addClass($class, $condition_field, $meta, $nowrap, $is_field_truncated = false, $transform_function = '', $default_function = '') {
1119 // Define classes to be added to this data field based on the type of data
1120 $enum_class = '';
1121 if (strpos($meta->flags, 'enum') !== false) {
1122 $enum_class = ' enum';
1125 $set_class = '';
1126 if (strpos($meta->flags, 'set') !== false) {
1127 $set_class = ' set';
1130 $bit_class = '';
1131 if (strpos($meta->type, 'bit') !== false) {
1132 $bit_class = ' bit';
1135 $mime_type_class = '';
1136 if (isset($meta->mimetype)) {
1137 $mime_type_class = ' ' . preg_replace('/\//', '_', $meta->mimetype);
1140 $result = $class . ($condition_field ? ' condition' : '') . $nowrap
1141 . ' ' . ($is_field_truncated ? ' truncated' : '')
1142 . ($transform_function != $default_function ? ' transformed' : '')
1143 . $enum_class . $set_class . $bit_class . $mime_type_class;
1145 return $result;
1148 * Displays the body of the results table
1150 * @param integer the link id associated to the query which results have
1151 * to be displayed
1152 * @param array which elements to display
1153 * @param array the list of relations
1154 * @param array the analyzed query
1156 * @return boolean always true
1158 * @global string $db the database name
1159 * @global string $table the table name
1160 * @global string $goto the URL to go back in case of errors
1161 * @global string $sql_query the SQL query
1162 * @global array $fields_meta the list of fields properties
1163 * @global integer $fields_cnt the total number of fields returned by
1164 * the SQL query
1165 * @global array $vertical_display informations used with vertical display
1166 * mode
1167 * @global array $highlight_columns column names to highlight
1168 * @global array $row current row data
1170 * @access private
1172 * @see PMA_displayTable()
1174 function PMA_displayTableBody(&$dt_result, &$is_display, $map, $analyzed_sql) {
1175 global $db, $table, $goto;
1176 global $sql_query, $fields_meta, $fields_cnt;
1177 global $vertical_display, $highlight_columns;
1178 global $row; // mostly because of browser transformations, to make the row-data accessible in a plugin
1180 $url_sql_query = $sql_query;
1182 // query without conditions to shorten URLs when needed, 200 is just
1183 // guess, it should depend on remaining URL length
1185 if (isset($analyzed_sql) && isset($analyzed_sql[0]) &&
1186 isset($analyzed_sql[0]['querytype']) && $analyzed_sql[0]['querytype'] == 'SELECT' &&
1187 strlen($sql_query) > 200) {
1189 $url_sql_query = 'SELECT ';
1190 if (isset($analyzed_sql[0]['queryflags']['distinct'])) {
1191 $url_sql_query .= ' DISTINCT ';
1193 $url_sql_query .= $analyzed_sql[0]['select_expr_clause'];
1194 if (!empty($analyzed_sql[0]['from_clause'])) {
1195 $url_sql_query .= ' FROM ' . $analyzed_sql[0]['from_clause'];
1199 if (! is_array($map)) {
1200 $map = array();
1202 $row_no = 0;
1203 $vertical_display['edit'] = array();
1204 $vertical_display['copy'] = array();
1205 $vertical_display['delete'] = array();
1206 $vertical_display['data'] = array();
1207 $vertical_display['row_delete'] = array();
1208 // name of the class added to all inline editable elements
1209 $inline_edit_class = 'inline_edit';
1211 // prepare to get the column order, if available
1212 if (PMA_isSelect()) {
1213 $pmatable = new PMA_Table($GLOBALS['table'], $GLOBALS['db']);
1214 $col_order = $pmatable->getUiProp(PMA_Table::PROP_COLUMN_ORDER);
1215 $col_visib = $pmatable->getUiProp(PMA_Table::PROP_COLUMN_VISIB);
1216 } else {
1217 $col_order = false;
1218 $col_visib = false;
1221 // Correction University of Virginia 19991216 in the while below
1222 // Previous code assumed that all tables have keys, specifically that
1223 // the phpMyAdmin GUI should support row delete/edit only for such
1224 // tables.
1225 // Although always using keys is arguably the prescribed way of
1226 // defining a relational table, it is not required. This will in
1227 // particular be violated by the novice.
1228 // We want to encourage phpMyAdmin usage by such novices. So the code
1229 // below has been changed to conditionally work as before when the
1230 // table being displayed has one or more keys; but to display
1231 // delete/edit options correctly for tables without keys.
1233 $odd_row = true;
1234 while ($row = PMA_DBI_fetch_row($dt_result)) {
1235 // "vertical display" mode stuff
1236 if ($row_no != 0 && $_SESSION['tmp_user_values']['repeat_cells'] != 0 && !($row_no % $_SESSION['tmp_user_values']['repeat_cells'])
1237 && ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
1238 || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped'))
1240 echo '<tr>' . "\n";
1241 if ($vertical_display['emptypre'] > 0) {
1242 echo ' <th colspan="' . $vertical_display['emptypre'] . '">' . "\n"
1243 .' &nbsp;</th>' . "\n";
1244 } else if ($GLOBALS['cfg']['RowActionLinks'] == 'none') {
1245 echo ' <th></th>' . "\n";
1248 foreach ($vertical_display['desc'] as $val) {
1249 echo $val;
1252 if ($vertical_display['emptyafter'] > 0) {
1253 echo ' <th colspan="' . $vertical_display['emptyafter'] . '">' . "\n"
1254 .' &nbsp;</th>' . "\n";
1256 echo '</tr>' . "\n";
1257 } // end if
1259 $alternating_color_class = ($odd_row ? 'odd' : 'even');
1260 $odd_row = ! $odd_row;
1262 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
1263 || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') {
1264 // pointer code part
1265 echo '<tr class="' . $alternating_color_class . '">';
1269 // 1. Prepares the row
1270 // 1.1 Results from a "SELECT" statement -> builds the
1271 // WHERE clause to use in links (a unique key if possible)
1273 * @todo $where_clause could be empty, for example a table
1274 * with only one field and it's a BLOB; in this case,
1275 * avoid to display the delete and edit links
1277 list($where_clause, $clause_is_unique) = PMA_getUniqueCondition($dt_result, $fields_cnt, $fields_meta, $row);
1278 $where_clause_html = urlencode($where_clause);
1280 // 1.2 Defines the URLs for the modify/delete link(s)
1282 if ($is_display['edit_lnk'] != 'nn' || $is_display['del_lnk'] != 'nn') {
1283 // We need to copy the value or else the == 'both' check will always return true
1285 if ($GLOBALS['cfg']['PropertiesIconic'] === 'both') {
1286 $iconic_spacer = '<div class="nowrap">';
1287 } else {
1288 $iconic_spacer = '';
1291 // 1.2.1 Modify link(s)
1292 if ($is_display['edit_lnk'] == 'ur') { // update row case
1293 $_url_params = array(
1294 'db' => $db,
1295 'table' => $table,
1296 'where_clause' => $where_clause,
1297 'clause_is_unique' => $clause_is_unique,
1298 'sql_query' => $url_sql_query,
1299 'goto' => 'sql.php',
1301 $edit_url = 'tbl_change.php' . PMA_generate_common_url($_url_params + array('default_action' => 'update'));
1302 $copy_url = 'tbl_change.php' . PMA_generate_common_url($_url_params + array('default_action' => 'insert'));
1304 $edit_str = PMA_getIcon('b_edit.png', __('Edit'));
1305 $copy_str = PMA_getIcon('b_insrow.png', __('Copy'));
1307 // Class definitions required for inline editing jQuery scripts
1308 $edit_anchor_class = "edit_row_anchor";
1309 if ( $clause_is_unique == 0) {
1310 $edit_anchor_class .= ' nonunique';
1312 } // end if (1.2.1)
1314 // 1.2.2 Delete/Kill link(s)
1315 if ($is_display['del_lnk'] == 'dr') { // delete row case
1316 $_url_params = array(
1317 'db' => $db,
1318 'table' => $table,
1319 'sql_query' => $url_sql_query,
1320 'message_to_show' => __('The row has been deleted'),
1321 'goto' => (empty($goto) ? 'tbl_sql.php' : $goto),
1323 $lnk_goto = 'sql.php' . PMA_generate_common_url($_url_params, 'text');
1325 $del_query = 'DELETE FROM ' . PMA_backquote($db) . '.' . PMA_backquote($table)
1326 . ' WHERE ' . $where_clause . ($clause_is_unique ? '' : ' LIMIT 1');
1328 $_url_params = array(
1329 'db' => $db,
1330 'table' => $table,
1331 'sql_query' => $del_query,
1332 'message_to_show' => __('The row has been deleted'),
1333 'goto' => $lnk_goto,
1335 $del_url = 'sql.php' . PMA_generate_common_url($_url_params);
1337 $js_conf = 'DELETE FROM ' . PMA_jsFormat($db) . '.' . PMA_jsFormat($table)
1338 . ' WHERE ' . PMA_jsFormat($where_clause, false)
1339 . ($clause_is_unique ? '' : ' LIMIT 1');
1340 $del_str = PMA_getIcon('b_drop.png', __('Delete'));
1341 } elseif ($is_display['del_lnk'] == 'kp') { // kill process case
1343 $_url_params = array(
1344 'db' => $db,
1345 'table' => $table,
1346 'sql_query' => $url_sql_query,
1347 'goto' => 'main.php',
1349 $lnk_goto = 'sql.php' . PMA_generate_common_url($_url_params, 'text');
1351 $_url_params = array(
1352 'db' => 'mysql',
1353 'sql_query' => 'KILL ' . $row[0],
1354 'goto' => $lnk_goto,
1356 $del_url = 'sql.php' . PMA_generate_common_url($_url_params);
1357 $del_query = 'KILL ' . $row[0];
1358 $js_conf = 'KILL ' . $row[0];
1359 $del_str = PMA_getIcon('b_drop.png', __('Kill'));
1360 } // end if (1.2.2)
1362 // 1.3 Displays the links at left if required
1363 if (($GLOBALS['cfg']['RowActionLinks'] == 'left' || $GLOBALS['cfg']['RowActionLinks'] == 'both')
1364 && ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
1365 || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped')) {
1366 if (! isset($js_conf)) {
1367 $js_conf = '';
1369 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);
1370 } else if (($GLOBALS['cfg']['RowActionLinks'] == 'none')
1371 && ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
1372 || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped')) {
1373 if (! isset($js_conf)) {
1374 $js_conf = '';
1376 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);
1377 } // end if (1.3)
1378 } // end if (1)
1380 // 2. Displays the rows' values
1382 for ($j = 0; $j < $fields_cnt; ++$j) {
1383 // assign $i with appropriate column order
1384 $i = $col_order ? $col_order[$j] : $j;
1386 $meta = $fields_meta[$i];
1387 $not_null_class = $meta->not_null ? 'not_null' : '';
1388 $relation_class = isset($map[$meta->name]) ? 'relation' : '';
1389 $hide_class = ($col_visib && !$col_visib[$j] &&
1390 // hide per <td> only if the display direction is not vertical
1391 $_SESSION['tmp_user_values']['disp_direction'] != 'vertical') ? 'hide' : '';
1392 $pointer = $i;
1393 $is_field_truncated = false;
1394 //If the previous column had blob data, we need to reset the class
1395 // to $inline_edit_class
1396 $class = 'data ' . $inline_edit_class . ' ' . $not_null_class . ' ' . $relation_class; //' ' . $alternating_color_class .
1398 // See if this column should get highlight because it's used in the
1399 // where-query.
1400 if (isset($highlight_columns) && (isset($highlight_columns[$meta->name]) || isset($highlight_columns[PMA_backquote($meta->name)]))) {
1401 $condition_field = true;
1402 } else {
1403 $condition_field = false;
1406 if ($_SESSION['tmp_user_values']['disp_direction'] == 'vertical' && (! isset($GLOBALS['printview']) || ($GLOBALS['printview'] != '1'))) {
1407 // the row number corresponds to a data row, not HTML table row
1408 $class .= ' row_' . $row_no;
1409 if ($GLOBALS['cfg']['BrowsePointerEnable'] == true) {
1410 $class .= ' vpointer';
1412 if ($GLOBALS['cfg']['BrowseMarkerEnable'] == true) {
1413 $class .= ' vmarker';
1415 }// end if
1417 // Wrap MIME-transformations. [MIME]
1418 $default_function = 'default_function'; // default_function
1419 $transform_function = $default_function;
1420 $transform_options = array();
1422 if ($GLOBALS['cfgRelation']['mimework'] && $GLOBALS['cfg']['BrowseMIME']) {
1424 if (isset($GLOBALS['mime_map'][$meta->name]['mimetype']) && isset($GLOBALS['mime_map'][$meta->name]['transformation']) && !empty($GLOBALS['mime_map'][$meta->name]['transformation'])) {
1425 $include_file = PMA_securePath($GLOBALS['mime_map'][$meta->name]['transformation']);
1427 if (file_exists('./libraries/transformations/' . $include_file)) {
1428 $transformfunction_name = str_replace('.inc.php', '', $GLOBALS['mime_map'][$meta->name]['transformation']);
1430 require_once './libraries/transformations/' . $include_file;
1432 if (function_exists('PMA_transformation_' . $transformfunction_name)) {
1433 $transform_function = 'PMA_transformation_' . $transformfunction_name;
1434 $transform_options = PMA_transformation_getOptions((isset($GLOBALS['mime_map'][$meta->name]['transformation_options']) ? $GLOBALS['mime_map'][$meta->name]['transformation_options'] : ''));
1435 $meta->mimetype = str_replace('_', '/', $GLOBALS['mime_map'][$meta->name]['mimetype']);
1437 } // end if file_exists
1438 } // end if transformation is set
1439 } // end if mime/transformation works.
1441 $_url_params = array(
1442 'db' => $db,
1443 'table' => $table,
1444 'where_clause' => $where_clause,
1445 'transform_key' => $meta->name,
1448 if (! empty($sql_query)) {
1449 $_url_params['sql_query'] = $url_sql_query;
1452 $transform_options['wrapper_link'] = PMA_generate_common_url($_url_params);
1454 // n u m e r i c
1455 if ($meta->numeric == 1) {
1457 // if two fields have the same name (this is possible
1458 // with self-join queries, for example), using $meta->name
1459 // will show both fields NULL even if only one is NULL,
1460 // so use the $pointer
1462 if (! isset($row[$i]) || is_null($row[$i])) {
1463 $vertical_display['data'][$row_no][$i] = PMA_buildNullDisplay($class, $condition_field);
1464 } elseif ($row[$i] != '') {
1466 $nowrap = ' nowrap';
1467 $where_comparison = ' = ' . $row[$i];
1469 $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);
1470 } else {
1471 $vertical_display['data'][$row_no][$i] = PMA_buildEmptyDisplay($class, $condition_field, $meta, 'align="right"');
1474 // b l o b
1476 } elseif (stristr($meta->type, 'BLOB')) {
1477 // PMA_mysql_fetch_fields returns BLOB in place of
1478 // TEXT fields type so we have to ensure it's really a BLOB
1479 $field_flags = PMA_DBI_field_flags($dt_result, $i);
1481 // remove 'inline_edit' from $class as we can't edit binary data.
1482 $class = str_replace('inline_edit', '', $class);
1484 if (stristr($field_flags, 'BINARY')) {
1485 if (! isset($row[$i]) || is_null($row[$i])) {
1486 $vertical_display['data'][$row_no][$i] = PMA_buildNullDisplay($class, $condition_field);
1487 } else {
1488 // for blobstreaming
1489 // if valid BS reference exists
1490 if (PMA_BS_IsPBMSReference($row[$i], $db)) {
1491 $blobtext = PMA_BS_CreateReferenceLink($row[$i], $db);
1492 } else {
1493 $blobtext = PMA_handle_non_printable_contents('BLOB', (isset($row[$i]) ? $row[$i] : ''), $transform_function, $transform_options, $default_function, $meta, $_url_params);
1496 $vertical_display['data'][$row_no][$i] = PMA_buildValueDisplay($class, $condition_field, $blobtext);
1497 unset($blobtext);
1499 // not binary:
1500 } else {
1501 if (! isset($row[$i]) || is_null($row[$i])) {
1502 $vertical_display['data'][$row_no][$i] = PMA_buildNullDisplay($class, $condition_field);
1503 } elseif ($row[$i] != '') {
1504 // if a transform function for blob is set, none of these replacements will be made
1505 if (PMA_strlen($row[$i]) > $GLOBALS['cfg']['LimitChars'] && $_SESSION['tmp_user_values']['display_text'] == 'P') {
1506 $row[$i] = PMA_substr($row[$i], 0, $GLOBALS['cfg']['LimitChars']) . '...';
1507 $is_field_truncated = true;
1509 // displays all space characters, 4 space
1510 // characters for tabulations and <cr>/<lf>
1511 $row[$i] = ($default_function != $transform_function ? $transform_function($row[$i], $transform_options, $meta) : $default_function($row[$i], array(), $meta));
1513 $vertical_display['data'][$row_no][$i] = PMA_buildValueDisplay($class, $condition_field, $row[$i]);
1514 } else {
1515 $vertical_display['data'][$row_no][$i] = PMA_buildEmptyDisplay($class, $condition_field, $meta);
1518 // g e o m e t r y
1519 } elseif ($meta->type == 'geometry') {
1521 // Remove 'inline_edit' from $class as we do not allow to inline-edit geometry data.
1522 $class = str_replace('inline_edit', '', $class);
1524 // Display as [GEOMETRY - (size)]
1525 if ('GEOM' == $_SESSION['tmp_user_values']['geometry_display']) {
1526 $geometry_text = PMA_handle_non_printable_contents(
1527 'GEOMETRY', (isset($row[$i]) ? $row[$i] : ''), $transform_function,
1528 $transform_options, $default_function, $meta
1530 $vertical_display['data'][$row_no][$i] = PMA_buildValueDisplay(
1531 $class, $condition_field, $geometry_text
1534 // Display in Well Known Text(WKT) format.
1535 } elseif ('WKT' == $_SESSION['tmp_user_values']['geometry_display']) {
1536 // Convert to WKT format
1537 $wktsql = "SELECT ASTEXT (GeomFromWKB(x'" . PMA_substr(bin2hex($row[$i]), 8) . "'))";
1538 $wktresult = PMA_DBI_try_query($wktsql, null, PMA_DBI_QUERY_STORE);
1539 $wktarr = PMA_DBI_fetch_row($wktresult, 0);
1540 $wktval = $wktarr[0];
1541 @PMA_DBI_free_result($wktresult);
1543 if (PMA_strlen($wktval) > $GLOBALS['cfg']['LimitChars']
1544 && $_SESSION['tmp_user_values']['display_text'] == 'P'
1546 $wktval = PMA_substr($wktval, 0, $GLOBALS['cfg']['LimitChars']) . '...';
1547 $is_field_truncated = true;
1550 $vertical_display['data'][$row_no][$i] = '<td ' . PMA_prepare_row_data(
1551 $class, $condition_field, $analyzed_sql, $meta, $map, $wktval, $transform_function,
1552 $default_function, $nowrap, $where_comparison, $transform_options, $is_field_truncated
1555 // Display in Well Known Binary(WKB) format.
1556 } else {
1557 if ($_SESSION['tmp_user_values']['display_binary']) {
1558 if ($_SESSION['tmp_user_values']['display_binary_as_hex']
1559 && PMA_contains_nonprintable_ascii($row[$i])
1561 $wkbval = PMA_substr(bin2hex($row[$i]), 8);
1562 } else {
1563 $wkbval = htmlspecialchars(PMA_replace_binary_contents($row[$i]));
1566 if (PMA_strlen($wkbval) > $GLOBALS['cfg']['LimitChars']
1567 && $_SESSION['tmp_user_values']['display_text'] == 'P'
1569 $wkbval = PMA_substr($wkbval, 0, $GLOBALS['cfg']['LimitChars']) . '...';
1570 $is_field_truncated = true;
1573 $vertical_display['data'][$row_no][$i] = '<td ' . PMA_prepare_row_data(
1574 $class, $condition_field, $analyzed_sql, $meta, $map, $wkbval, $transform_function,
1575 $default_function, $nowrap, $where_comparison, $transform_options, $is_field_truncated
1577 } else {
1578 $wkbval = PMA_handle_non_printable_contents(
1579 'BINARY', $row[$i], $transform_function, $transform_options, $default_function, $meta, $_url_params
1581 $vertical_display['data'][$row_no][$i] = PMA_buildValueDisplay($class, $condition_field, $wkbval);
1585 // n o t n u m e r i c a n d n o t B L O B
1586 } else {
1587 if (! isset($row[$i]) || is_null($row[$i])) {
1588 $vertical_display['data'][$row_no][$i] = PMA_buildNullDisplay($class, $condition_field);
1589 } elseif ($row[$i] != '') {
1590 // support blanks in the key
1591 $relation_id = $row[$i];
1593 // Cut all fields to $GLOBALS['cfg']['LimitChars']
1594 // (unless it's a link-type transformation)
1595 if (PMA_strlen($row[$i]) > $GLOBALS['cfg']['LimitChars'] && $_SESSION['tmp_user_values']['display_text'] == 'P' && !strpos($transform_function, 'link') === true) {
1596 $row[$i] = PMA_substr($row[$i], 0, $GLOBALS['cfg']['LimitChars']) . '...';
1597 $is_field_truncated = true;
1600 // displays special characters from binaries
1601 $field_flags = PMA_DBI_field_flags($dt_result, $i);
1602 if (isset($meta->_type) && $meta->_type === MYSQLI_TYPE_BIT) {
1603 $row[$i] = PMA_printable_bit_value($row[$i], $meta->length);
1604 // some results of PROCEDURE ANALYSE() are reported as
1605 // being BINARY but they are quite readable,
1606 // so don't treat them as BINARY
1607 } elseif (stristr($field_flags, 'BINARY') && $meta->type == 'string' && !(isset($GLOBALS['is_analyse']) && $GLOBALS['is_analyse'])) {
1608 if ($_SESSION['tmp_user_values']['display_binary']) {
1609 // user asked to see the real contents of BINARY
1610 // fields
1611 if ($_SESSION['tmp_user_values']['display_binary_as_hex'] && PMA_contains_nonprintable_ascii($row[$i])) {
1612 $row[$i] = bin2hex($row[$i]);
1613 } else {
1614 $row[$i] = htmlspecialchars(PMA_replace_binary_contents($row[$i]));
1616 } else {
1617 // we show the BINARY message and field's size
1618 // (or maybe use a transformation)
1619 $row[$i] = PMA_handle_non_printable_contents('BINARY', $row[$i], $transform_function, $transform_options, $default_function, $meta, $_url_params);
1623 // transform functions may enable no-wrapping:
1624 $function_nowrap = $transform_function . '_nowrap';
1625 $bool_nowrap = (($default_function != $transform_function && function_exists($function_nowrap)) ? $function_nowrap($transform_options) : false);
1627 // do not wrap if date field type
1628 $nowrap = ((preg_match('@DATE|TIME@i', $meta->type) || $bool_nowrap) ? ' nowrap' : '');
1629 $where_comparison = ' = \'' . PMA_sqlAddSlashes($row[$i]) . '\'';
1630 $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);
1632 } else {
1633 $vertical_display['data'][$row_no][$i] = PMA_buildEmptyDisplay($class, $condition_field, $meta);
1637 // output stored cell
1638 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
1639 || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') {
1640 echo $vertical_display['data'][$row_no][$i];
1643 if (isset($vertical_display['rowdata'][$i][$row_no])) {
1644 $vertical_display['rowdata'][$i][$row_no] .= $vertical_display['data'][$row_no][$i];
1645 } else {
1646 $vertical_display['rowdata'][$i][$row_no] = $vertical_display['data'][$row_no][$i];
1648 } // end for (2)
1650 // 3. Displays the modify/delete links on the right if required
1651 if (($GLOBALS['cfg']['RowActionLinks'] == 'right' || $GLOBALS['cfg']['RowActionLinks'] == 'both')
1652 && ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
1653 || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped')) {
1654 if (! isset($js_conf)) {
1655 $js_conf = '';
1657 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);
1658 } // end if (3)
1660 if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
1661 || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') {
1663 </tr>
1664 <?php
1665 } // end if
1667 // 4. Gather links of del_urls and edit_urls in an array for later
1668 // output
1669 if (! isset($vertical_display['edit'][$row_no])) {
1670 $vertical_display['edit'][$row_no] = '';
1671 $vertical_display['copy'][$row_no] = '';
1672 $vertical_display['delete'][$row_no] = '';
1673 $vertical_display['row_delete'][$row_no] = '';
1675 $vertical_class = ' row_' . $row_no;
1676 if ($GLOBALS['cfg']['BrowsePointerEnable'] == true) {
1677 $vertical_class .= ' vpointer';
1679 if ($GLOBALS['cfg']['BrowseMarkerEnable'] == true) {
1680 $vertical_class .= ' vmarker';
1683 if (!empty($del_url) && $is_display['del_lnk'] != 'kp') {
1684 $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);
1685 } else {
1686 unset($vertical_display['row_delete'][$row_no]);
1689 if (isset($edit_url)) {
1690 $vertical_display['edit'][$row_no] .= PMA_generateEditLink($edit_url, $alternating_color_class . ' ' . $edit_anchor_class . $vertical_class, $edit_str, $where_clause, $where_clause_html);
1691 } else {
1692 unset($vertical_display['edit'][$row_no]);
1695 if (isset($copy_url)) {
1696 $vertical_display['copy'][$row_no] .= PMA_generateCopyLink($copy_url, $copy_str, $where_clause, $where_clause_html, $alternating_color_class . $vertical_class);
1697 } else {
1698 unset($vertical_display['copy'][$row_no]);
1701 if (isset($del_url)) {
1702 if (! isset($js_conf)) {
1703 $js_conf = '';
1705 $vertical_display['delete'][$row_no] .= PMA_generateDeleteLink($del_url, $del_str, $js_conf, $alternating_color_class . $vertical_class);
1706 } else {
1707 unset($vertical_display['delete'][$row_no]);
1710 echo (($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal' || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') ? "\n" : '');
1711 $row_no++;
1712 } // end while
1714 // this is needed by PMA_displayTable() to generate the proper param
1715 // in the multi-edit and multi-delete form
1716 return $clause_is_unique;
1717 } // end of the 'PMA_displayTableBody()' function
1721 * Do display the result table with the vertical direction mode.
1723 * @return boolean always true
1725 * @global array $vertical_display the information to display
1727 * @access private
1729 * @see PMA_displayTable()
1731 function PMA_displayVerticalTable()
1733 global $vertical_display;
1735 // Displays "multi row delete" link at top if required
1736 if (($GLOBALS['cfg']['RowActionLinks'] != 'right')
1737 && is_array($vertical_display['row_delete']) && (count($vertical_display['row_delete']) > 0 || !empty($vertical_display['textbtn']))) {
1738 echo '<tr>' . "\n";
1739 if ($GLOBALS['cfg']['RowActionLinks'] == 'none') {
1740 // if we are not showing the RowActionLinks, then we need to show the Multi-Row-Action checkboxes
1741 echo '<th></th>' . "\n";
1743 echo $vertical_display['textbtn'];
1744 $cell_displayed = 0;
1745 foreach ($vertical_display['row_delete'] as $val) {
1746 if (($cell_displayed != 0) && ($_SESSION['tmp_user_values']['repeat_cells'] != 0) && !($cell_displayed % $_SESSION['tmp_user_values']['repeat_cells'])) {
1747 echo '<th' .
1748 (($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn') ? ' rowspan="4"' : '') .
1749 '></th>' . "\n";
1751 echo str_replace('[%_PMA_CHECKBOX_DIR_%]', '_left', $val);
1752 $cell_displayed++;
1753 } // end while
1754 echo '</tr>' . "\n";
1755 } // end if
1757 // Displays "edit" link at top if required
1758 if (($GLOBALS['cfg']['RowActionLinks'] == 'left' || $GLOBALS['cfg']['RowActionLinks'] == 'both')
1759 && is_array($vertical_display['edit']) && (count($vertical_display['edit']) > 0 || !empty($vertical_display['textbtn']))) {
1760 echo '<tr>' . "\n";
1761 if (! is_array($vertical_display['row_delete'])) {
1762 echo $vertical_display['textbtn'];
1764 foreach ($vertical_display['edit'] as $val) {
1765 echo $val;
1766 } // end while
1767 echo '</tr>' . "\n";
1768 } // end if
1770 // Displays "copy" link at top if required
1771 if (($GLOBALS['cfg']['RowActionLinks'] == 'left' || $GLOBALS['cfg']['RowActionLinks'] == 'both')
1772 && is_array($vertical_display['copy']) && (count($vertical_display['copy']) > 0 || !empty($vertical_display['textbtn']))) {
1773 echo '<tr>' . "\n";
1774 if (! is_array($vertical_display['row_delete'])) {
1775 echo $vertical_display['textbtn'];
1777 foreach ($vertical_display['copy'] as $val) {
1778 echo $val;
1779 } // end while
1780 echo '</tr>' . "\n";
1781 } // end if
1783 // Displays "delete" link at top if required
1784 if (($GLOBALS['cfg']['RowActionLinks'] == 'left' || $GLOBALS['cfg']['RowActionLinks'] == 'both')
1785 && is_array($vertical_display['delete']) && (count($vertical_display['delete']) > 0 || !empty($vertical_display['textbtn']))) {
1786 echo '<tr>' . "\n";
1787 if (! is_array($vertical_display['edit']) && ! is_array($vertical_display['row_delete'])) {
1788 echo $vertical_display['textbtn'];
1790 foreach ($vertical_display['delete'] as $val) {
1791 echo $val;
1792 } // end while
1793 echo '</tr>' . "\n";
1794 } // end if
1796 if (PMA_isSelect()) {
1797 // prepare to get the column order, if available
1798 $pmatable = new PMA_Table($GLOBALS['table'], $GLOBALS['db']);
1799 $col_order = $pmatable->getUiProp(PMA_Table::PROP_COLUMN_ORDER);
1800 $col_visib = $pmatable->getUiProp(PMA_Table::PROP_COLUMN_VISIB);
1801 } else {
1802 $col_order = false;
1803 $col_visib = false;
1806 // Displays data
1807 foreach ($vertical_display['desc'] AS $j => $val) {
1808 // assign appropriate key with current column order
1809 $key = $col_order ? $col_order[$j] : $j;
1811 echo '<tr' . (($col_visib && !$col_visib[$j]) ? ' class="hide"' : '') . '>' . "\n";
1812 echo $val;
1814 $cell_displayed = 0;
1815 foreach ($vertical_display['rowdata'][$key] as $subval) {
1816 if (($cell_displayed != 0) && ($_SESSION['tmp_user_values']['repeat_cells'] != 0) and !($cell_displayed % $_SESSION['tmp_user_values']['repeat_cells'])) {
1817 echo $val;
1820 echo $subval;
1821 $cell_displayed++;
1822 } // end while
1824 echo '</tr>' . "\n";
1825 } // end while
1827 // Displays "multi row delete" link at bottom if required
1828 if (($GLOBALS['cfg']['RowActionLinks'] == 'right' || $GLOBALS['cfg']['RowActionLinks'] == 'both')
1829 && is_array($vertical_display['row_delete']) && (count($vertical_display['row_delete']) > 0 || !empty($vertical_display['textbtn']))) {
1830 echo '<tr>' . "\n";
1831 echo $vertical_display['textbtn'];
1832 $cell_displayed = 0;
1833 foreach ($vertical_display['row_delete'] as $val) {
1834 if (($cell_displayed != 0) && ($_SESSION['tmp_user_values']['repeat_cells'] != 0) && !($cell_displayed % $_SESSION['tmp_user_values']['repeat_cells'])) {
1835 echo '<th' .
1836 (($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn') ? ' rowspan="4"' : '') .
1837 '></th>' . "\n";
1840 echo str_replace('[%_PMA_CHECKBOX_DIR_%]', '_right', $val);
1841 $cell_displayed++;
1842 } // end while
1843 echo '</tr>' . "\n";
1844 } // end if
1846 // Displays "edit" link at bottom if required
1847 if (($GLOBALS['cfg']['RowActionLinks'] == 'right' || $GLOBALS['cfg']['RowActionLinks'] == 'both')
1848 && is_array($vertical_display['edit']) && (count($vertical_display['edit']) > 0 || !empty($vertical_display['textbtn']))) {
1849 echo '<tr>' . "\n";
1850 if (! is_array($vertical_display['row_delete'])) {
1851 echo $vertical_display['textbtn'];
1853 foreach ($vertical_display['edit'] as $val) {
1854 echo $val;
1855 } // end while
1856 echo '</tr>' . "\n";
1857 } // end if
1859 // Displays "copy" link at bottom if required
1860 if (($GLOBALS['cfg']['RowActionLinks'] == 'right' || $GLOBALS['cfg']['RowActionLinks'] == 'both')
1861 && is_array($vertical_display['copy']) && (count($vertical_display['copy']) > 0 || !empty($vertical_display['textbtn']))) {
1862 echo '<tr>' . "\n";
1863 if (! is_array($vertical_display['row_delete'])) {
1864 echo $vertical_display['textbtn'];
1866 foreach ($vertical_display['copy'] as $val) {
1867 echo $val;
1868 } // end while
1869 echo '</tr>' . "\n";
1870 } // end if
1872 // Displays "delete" link at bottom if required
1873 if (($GLOBALS['cfg']['RowActionLinks'] == 'right' || $GLOBALS['cfg']['RowActionLinks'] == 'both')
1874 && is_array($vertical_display['delete']) && (count($vertical_display['delete']) > 0 || !empty($vertical_display['textbtn']))) {
1875 echo '<tr>' . "\n";
1876 if (! is_array($vertical_display['edit']) && ! is_array($vertical_display['row_delete'])) {
1877 echo $vertical_display['textbtn'];
1879 foreach ($vertical_display['delete'] as $val) {
1880 echo $val;
1881 } // end while
1882 echo '</tr>' . "\n";
1885 return true;
1886 } // end of the 'PMA_displayVerticalTable' function
1890 * @todo make maximum remembered queries configurable
1891 * @todo move/split into SQL class!?
1892 * @todo currently this is called twice unnecessary
1893 * @todo ignore LIMIT and ORDER in query!?
1895 function PMA_displayTable_checkConfigParams()
1897 $sql_md5 = md5($GLOBALS['sql_query']);
1899 $_SESSION['tmp_user_values']['query'][$sql_md5]['sql'] = $GLOBALS['sql_query'];
1901 if (PMA_isValid($_REQUEST['disp_direction'], array('horizontal', 'vertical', 'horizontalflipped'))) {
1902 $_SESSION['tmp_user_values']['query'][$sql_md5]['disp_direction'] = $_REQUEST['disp_direction'];
1903 unset($_REQUEST['disp_direction']);
1904 } elseif (empty($_SESSION['tmp_user_values']['query'][$sql_md5]['disp_direction'])) {
1905 $_SESSION['tmp_user_values']['query'][$sql_md5]['disp_direction'] = $GLOBALS['cfg']['DefaultDisplay'];
1908 if (PMA_isValid($_REQUEST['repeat_cells'], 'numeric')) {
1909 $_SESSION['tmp_user_values']['query'][$sql_md5]['repeat_cells'] = $_REQUEST['repeat_cells'];
1910 unset($_REQUEST['repeat_cells']);
1911 } elseif (empty($_SESSION['tmp_user_values']['query'][$sql_md5]['repeat_cells'])) {
1912 $_SESSION['tmp_user_values']['query'][$sql_md5]['repeat_cells'] = $GLOBALS['cfg']['RepeatCells'];
1915 // as this is a form value, the type is always string so we cannot
1916 // use PMA_isValid($_REQUEST['session_max_rows'], 'integer')
1917 if ((PMA_isValid($_REQUEST['session_max_rows'], 'numeric')
1918 && (int) $_REQUEST['session_max_rows'] == $_REQUEST['session_max_rows'])
1919 || $_REQUEST['session_max_rows'] == 'all') {
1920 $_SESSION['tmp_user_values']['query'][$sql_md5]['max_rows'] = $_REQUEST['session_max_rows'];
1921 unset($_REQUEST['session_max_rows']);
1922 } elseif (empty($_SESSION['tmp_user_values']['query'][$sql_md5]['max_rows'])) {
1923 $_SESSION['tmp_user_values']['query'][$sql_md5]['max_rows'] = $GLOBALS['cfg']['MaxRows'];
1926 if (PMA_isValid($_REQUEST['pos'], 'numeric')) {
1927 $_SESSION['tmp_user_values']['query'][$sql_md5]['pos'] = $_REQUEST['pos'];
1928 unset($_REQUEST['pos']);
1929 } elseif (empty($_SESSION['tmp_user_values']['query'][$sql_md5]['pos'])) {
1930 $_SESSION['tmp_user_values']['query'][$sql_md5]['pos'] = 0;
1933 if (PMA_isValid($_REQUEST['display_text'], array('P', 'F'))) {
1934 $_SESSION['tmp_user_values']['query'][$sql_md5]['display_text'] = $_REQUEST['display_text'];
1935 unset($_REQUEST['display_text']);
1936 } elseif (empty($_SESSION['tmp_user_values']['query'][$sql_md5]['display_text'])) {
1937 $_SESSION['tmp_user_values']['query'][$sql_md5]['display_text'] = 'P';
1940 if (PMA_isValid($_REQUEST['relational_display'], array('K', 'D'))) {
1941 $_SESSION['tmp_user_values']['query'][$sql_md5]['relational_display'] = $_REQUEST['relational_display'];
1942 unset($_REQUEST['relational_display']);
1943 } elseif (empty($_SESSION['tmp_user_values']['query'][$sql_md5]['relational_display'])) {
1944 $_SESSION['tmp_user_values']['query'][$sql_md5]['relational_display'] = 'K';
1947 if (PMA_isValid($_REQUEST['geometry_display'], array('WKT', 'WKB', 'GEOM'))) {
1948 $_SESSION['tmp_user_values']['query'][$sql_md5]['geometry_display'] = $_REQUEST['geometry_display'];
1949 unset($_REQUEST['geometry_display']);
1950 } elseif (empty($_SESSION['tmp_user_values']['query'][$sql_md5]['geometry_display'])) {
1951 $_SESSION['tmp_user_values']['query'][$sql_md5]['geometry_display'] = 'GEOM';
1954 if (isset($_REQUEST['display_binary'])) {
1955 $_SESSION['tmp_user_values']['query'][$sql_md5]['display_binary'] = true;
1956 unset($_REQUEST['display_binary']);
1957 } elseif (isset($_REQUEST['display_options_form'])) {
1958 // we know that the checkbox was unchecked
1959 unset($_SESSION['tmp_user_values']['query'][$sql_md5]['display_binary']);
1960 } else {
1961 // selected by default because some operations like OPTIMIZE TABLE
1962 // and all queries involving functions return "binary" contents,
1963 // according to low-level field flags
1964 $_SESSION['tmp_user_values']['query'][$sql_md5]['display_binary'] = true;
1967 if (isset($_REQUEST['display_binary_as_hex'])) {
1968 $_SESSION['tmp_user_values']['query'][$sql_md5]['display_binary_as_hex'] = true;
1969 unset($_REQUEST['display_binary_as_hex']);
1970 } elseif (isset($_REQUEST['display_options_form'])) {
1971 // we know that the checkbox was unchecked
1972 unset($_SESSION['tmp_user_values']['query'][$sql_md5]['display_binary_as_hex']);
1973 } else {
1974 // display_binary_as_hex config option
1975 if (isset($GLOBALS['cfg']['DisplayBinaryAsHex']) && true === $GLOBALS['cfg']['DisplayBinaryAsHex']) {
1976 $_SESSION['tmp_user_values']['query'][$sql_md5]['display_binary_as_hex'] = true;
1980 if (isset($_REQUEST['display_blob'])) {
1981 $_SESSION['tmp_user_values']['query'][$sql_md5]['display_blob'] = true;
1982 unset($_REQUEST['display_blob']);
1983 } elseif (isset($_REQUEST['display_options_form'])) {
1984 // we know that the checkbox was unchecked
1985 unset($_SESSION['tmp_user_values']['query'][$sql_md5]['display_blob']);
1988 if (isset($_REQUEST['hide_transformation'])) {
1989 $_SESSION['tmp_user_values']['query'][$sql_md5]['hide_transformation'] = true;
1990 unset($_REQUEST['hide_transformation']);
1991 } elseif (isset($_REQUEST['display_options_form'])) {
1992 // we know that the checkbox was unchecked
1993 unset($_SESSION['tmp_user_values']['query'][$sql_md5]['hide_transformation']);
1996 // move current query to the last position, to be removed last
1997 // so only least executed query will be removed if maximum remembered queries
1998 // limit is reached
1999 $tmp = $_SESSION['tmp_user_values']['query'][$sql_md5];
2000 unset($_SESSION['tmp_user_values']['query'][$sql_md5]);
2001 $_SESSION['tmp_user_values']['query'][$sql_md5] = $tmp;
2003 // do not exceed a maximum number of queries to remember
2004 if (count($_SESSION['tmp_user_values']['query']) > 10) {
2005 array_shift($_SESSION['tmp_user_values']['query']);
2006 //echo 'deleting one element ...';
2009 // populate query configuration
2010 $_SESSION['tmp_user_values']['display_text'] = $_SESSION['tmp_user_values']['query'][$sql_md5]['display_text'];
2011 $_SESSION['tmp_user_values']['relational_display'] = $_SESSION['tmp_user_values']['query'][$sql_md5]['relational_display'];
2012 $_SESSION['tmp_user_values']['geometry_display'] = $_SESSION['tmp_user_values']['query'][$sql_md5]['geometry_display'];
2013 $_SESSION['tmp_user_values']['display_binary'] = isset($_SESSION['tmp_user_values']['query'][$sql_md5]['display_binary']) ? true : false;
2014 $_SESSION['tmp_user_values']['display_binary_as_hex'] = isset($_SESSION['tmp_user_values']['query'][$sql_md5]['display_binary_as_hex']) ? true : false;
2015 $_SESSION['tmp_user_values']['display_blob'] = isset($_SESSION['tmp_user_values']['query'][$sql_md5]['display_blob']) ? true : false;
2016 $_SESSION['tmp_user_values']['hide_transformation'] = isset($_SESSION['tmp_user_values']['query'][$sql_md5]['hide_transformation']) ? true : false;
2017 $_SESSION['tmp_user_values']['pos'] = $_SESSION['tmp_user_values']['query'][$sql_md5]['pos'];
2018 $_SESSION['tmp_user_values']['max_rows'] = $_SESSION['tmp_user_values']['query'][$sql_md5]['max_rows'];
2019 $_SESSION['tmp_user_values']['repeat_cells'] = $_SESSION['tmp_user_values']['query'][$sql_md5]['repeat_cells'];
2020 $_SESSION['tmp_user_values']['disp_direction'] = $_SESSION['tmp_user_values']['query'][$sql_md5]['disp_direction'];
2023 * debugging
2024 echo '<pre>';
2025 var_dump($_SESSION['tmp_user_values']);
2026 echo '</pre>';
2031 * Displays a table of results returned by a SQL query.
2032 * This function is called by the "sql.php" script.
2034 * @param integer the link id associated to the query which results have
2035 * to be displayed
2036 * @param array the display mode
2037 * @param array the analyzed query
2039 * @global string $db the database name
2040 * @global string $table the table name
2041 * @global string $goto the URL to go back in case of errors
2042 * @global string $sql_query the current SQL query
2043 * @global integer $num_rows the total number of rows returned by the
2044 * SQL query
2045 * @global integer $unlim_num_rows the total number of rows returned by the
2046 * SQL query without any programmatically
2047 * appended "LIMIT" clause
2048 * @global array $fields_meta the list of fields properties
2049 * @global integer $fields_cnt the total number of fields returned by
2050 * the SQL query
2051 * @global array $vertical_display informations used with vertical display
2052 * mode
2053 * @global array $highlight_columns column names to highlight
2054 * @global array $cfgRelation the relation settings
2056 * @access private
2058 * @see PMA_showMessage(), PMA_setDisplayMode(),
2059 * PMA_displayTableNavigation(), PMA_displayTableHeaders(),
2060 * PMA_displayTableBody(), PMA_displayResultsOperations()
2062 function PMA_displayTable(&$dt_result, &$the_disp_mode, $analyzed_sql)
2064 global $db, $table, $goto;
2065 global $sql_query, $num_rows, $unlim_num_rows, $fields_meta, $fields_cnt;
2066 global $vertical_display, $highlight_columns;
2067 global $cfgRelation;
2068 global $showtable;
2070 // why was this called here? (already called from sql.php)
2071 //PMA_displayTable_checkConfigParams();
2074 * @todo move this to a central place
2075 * @todo for other future table types
2077 $is_innodb = (isset($showtable['Type']) && $showtable['Type'] == 'InnoDB');
2079 if ($is_innodb
2080 && ! isset($analyzed_sql[0]['queryflags']['union'])
2081 && ! isset($analyzed_sql[0]['table_ref'][1]['table_name'])
2082 && (empty($analyzed_sql[0]['where_clause'])
2083 || $analyzed_sql[0]['where_clause'] == '1 ')) {
2084 // "j u s t b r o w s i n g"
2085 $pre_count = '~';
2086 $after_count = PMA_showHint(PMA_sanitize(__('May be approximate. See [a@./Documentation.html#faq3_11@Documentation]FAQ 3.11[/a]')));
2087 } else {
2088 $pre_count = '';
2089 $after_count = '';
2092 // 1. ----- Prepares the work -----
2094 // 1.1 Gets the informations about which functionalities should be
2095 // displayed
2096 $total = '';
2097 $is_display = PMA_setDisplayMode($the_disp_mode, $total);
2099 // 1.2 Defines offsets for the next and previous pages
2100 if ($is_display['nav_bar'] == '1') {
2101 if ($_SESSION['tmp_user_values']['max_rows'] == 'all') {
2102 $pos_next = 0;
2103 $pos_prev = 0;
2104 } else {
2105 $pos_next = $_SESSION['tmp_user_values']['pos'] + $_SESSION['tmp_user_values']['max_rows'];
2106 $pos_prev = $_SESSION['tmp_user_values']['pos'] - $_SESSION['tmp_user_values']['max_rows'];
2107 if ($pos_prev < 0) {
2108 $pos_prev = 0;
2111 } // end if
2113 // 1.3 Find the sort expression
2115 // we need $sort_expression and $sort_expression_nodirection
2116 // even if there are many table references
2117 if (! empty($analyzed_sql[0]['order_by_clause'])) {
2118 $sort_expression = trim(str_replace(' ', ' ', $analyzed_sql[0]['order_by_clause']));
2120 * Get rid of ASC|DESC
2122 preg_match('@(.*)([[:space:]]*(ASC|DESC))@si', $sort_expression, $matches);
2123 $sort_expression_nodirection = isset($matches[1]) ? trim($matches[1]) : $sort_expression;
2124 $sort_direction = isset($matches[2]) ? trim($matches[2]) : '';
2125 unset($matches);
2126 } else {
2127 $sort_expression = $sort_expression_nodirection = $sort_direction = '';
2130 // 1.4 Prepares display of first and last value of the sorted column
2132 if (! empty($sort_expression_nodirection)) {
2133 if (strpos($sort_expression_nodirection, '.') === false) {
2134 $sort_table = $table;
2135 $sort_column = $sort_expression_nodirection;
2136 } else {
2137 list($sort_table, $sort_column) = explode('.', $sort_expression_nodirection);
2139 $sort_table = PMA_unQuote($sort_table);
2140 $sort_column = PMA_unQuote($sort_column);
2141 // find the sorted column index in row result
2142 // (this might be a multi-table query)
2143 $sorted_column_index = false;
2144 foreach ($fields_meta as $key => $meta) {
2145 if ($meta->table == $sort_table && $meta->name == $sort_column) {
2146 $sorted_column_index = $key;
2147 break;
2150 if ($sorted_column_index !== false) {
2151 // fetch first row of the result set
2152 $row = PMA_DBI_fetch_row($dt_result);
2153 // initializing default arguments
2154 $default_function = 'default_function';
2155 $transform_function = $default_function;
2156 $transform_options = array();
2157 // check for non printable sorted row data
2158 $meta = $fields_meta[$sorted_column_index];
2159 if (stristr($meta->type, 'BLOB') || $meta->type == 'geometry') {
2160 $column_for_first_row = PMA_handle_non_printable_contents($meta->type, $row[$sorted_column_index], $transform_function, $transform_options, $default_function, $meta, NULL);
2161 } else {
2162 $column_for_first_row = $row[$sorted_column_index];
2164 $column_for_first_row = strtoupper(substr($column_for_first_row, 0, $GLOBALS['cfg']['LimitChars']));
2165 // fetch last row of the result set
2166 PMA_DBI_data_seek($dt_result, $num_rows - 1);
2167 $row = PMA_DBI_fetch_row($dt_result);
2168 // check for non printable sorted row data
2169 $meta = $fields_meta[$sorted_column_index];
2170 if (stristr($meta->type, 'BLOB') || $meta->type == 'geometry') {
2171 $column_for_last_row = PMA_handle_non_printable_contents($meta->type, $row[$sorted_column_index], $transform_function, $transform_options, $default_function, $meta, NULL);
2172 } else {
2173 $column_for_last_row = $row[$sorted_column_index];
2175 $column_for_last_row = strtoupper(substr($column_for_last_row, 0, $GLOBALS['cfg']['LimitChars']));
2176 // reset to first row for the loop in PMA_displayTableBody()
2177 PMA_DBI_data_seek($dt_result, 0);
2178 // we could also use here $sort_expression_nodirection
2179 $sorted_column_message = ' [' . htmlspecialchars($sort_column) . ': <strong>' . htmlspecialchars($column_for_first_row) . ' - ' . htmlspecialchars($column_for_last_row) . '</strong>]';
2180 unset($row, $column_for_first_row, $column_for_last_row, $meta, $default_function, $transform_function, $transform_options);
2182 unset($sorted_column_index, $sort_table, $sort_column);
2185 // 2. ----- Displays the top of the page -----
2187 // 2.1 Displays a messages with position informations
2188 if ($is_display['nav_bar'] == '1' && isset($pos_next)) {
2189 if (isset($unlim_num_rows) && $unlim_num_rows != $total) {
2190 $selectstring = ', ' . $unlim_num_rows . ' ' . __('in query');
2191 } else {
2192 $selectstring = '';
2194 $last_shown_rec = ($_SESSION['tmp_user_values']['max_rows'] == 'all' || $pos_next > $total)
2195 ? $total - 1
2196 : $pos_next - 1;
2198 if (PMA_Table::isView($db, $table)
2199 && $total == $GLOBALS['cfg']['MaxExactCountViews']) {
2200 $message = PMA_Message::notice(__('This view has at least this number of rows. Please refer to %sdocumentation%s.'));
2201 $message->addParam('[a@./Documentation.html#cfg_MaxExactCount@_blank]');
2202 $message->addParam('[/a]');
2203 $message_view_warning = PMA_showHint($message);
2204 } else {
2205 $message_view_warning = false;
2208 $message = PMA_Message::success(__('Showing rows'));
2209 $message->addMessage($_SESSION['tmp_user_values']['pos']);
2210 if ($message_view_warning) {
2211 $message->addMessage('...', ' - ');
2212 $message->addMessage($message_view_warning);
2213 $message->addMessage('(');
2214 } else {
2215 $message->addMessage($last_shown_rec, ' - ');
2216 $message->addMessage(' (');
2217 $message->addMessage($pre_count . PMA_formatNumber($total, 0));
2218 $message->addString(__('total'));
2219 if (!empty($after_count)) {
2220 $message->addMessage($after_count);
2222 $message->addMessage($selectstring, '');
2223 $message->addMessage(', ', '');
2226 $messagge_qt = PMA_Message::notice(__('Query took %01.4f sec'));
2227 $messagge_qt->addParam($GLOBALS['querytime']);
2229 $message->addMessage($messagge_qt, '');
2230 $message->addMessage(')', '');
2232 $message->addMessage(isset($sorted_column_message) ? $sorted_column_message : '', '');
2234 PMA_showMessage($message, $sql_query, 'success');
2236 } elseif (! isset($GLOBALS['printview']) || $GLOBALS['printview'] != '1') {
2237 PMA_showMessage(__('Your SQL query has been executed successfully'), $sql_query, 'success');
2240 // 2.3 Displays the navigation bars
2241 if (! strlen($table)) {
2242 if (isset($analyzed_sql[0]['query_type'])
2243 && $analyzed_sql[0]['query_type'] == 'SELECT') {
2244 // table does not always contain a real table name,
2245 // for example in MySQL 5.0.x, the query SHOW STATUS
2246 // returns STATUS as a table name
2247 $table = $fields_meta[0]->table;
2248 } else {
2249 $table = '';
2253 if ($is_display['nav_bar'] == '1') {
2254 PMA_displayTableNavigation($pos_next, $pos_prev, $sql_query, 'top_direction_dropdown');
2255 echo "\n";
2256 } elseif (! isset($GLOBALS['printview']) || $GLOBALS['printview'] != '1') {
2257 echo "\n" . '<br /><br />' . "\n";
2260 // 2b ----- Get field references from Database -----
2261 // (see the 'relation' configuration variable)
2263 // initialize map
2264 $map = array();
2266 // find tables
2267 $target=array();
2268 if (isset($analyzed_sql[0]['table_ref']) && is_array($analyzed_sql[0]['table_ref'])) {
2269 foreach ($analyzed_sql[0]['table_ref'] AS $table_ref_position => $table_ref) {
2270 $target[] = $analyzed_sql[0]['table_ref'][$table_ref_position]['table_true_name'];
2273 $tabs = '(\'' . join('\',\'', $target) . '\')';
2275 if (! strlen($table)) {
2276 $exist_rel = false;
2277 } else {
2278 // To be able to later display a link to the related table,
2279 // we verify both types of relations: either those that are
2280 // native foreign keys or those defined in the phpMyAdmin
2281 // configuration storage. If no PMA storage, we won't be able
2282 // to use the "column to display" notion (for example show
2283 // the name related to a numeric id).
2284 $exist_rel = PMA_getForeigners($db, $table, '', 'both');
2285 if ($exist_rel) {
2286 foreach ($exist_rel AS $master_field => $rel) {
2287 $display_field = PMA_getDisplayField($rel['foreign_db'], $rel['foreign_table']);
2288 $map[$master_field] = array($rel['foreign_table'],
2289 $rel['foreign_field'],
2290 $display_field,
2291 $rel['foreign_db']);
2292 } // end while
2293 } // end if
2294 } // end if
2295 // end 2b
2297 // 3. ----- Displays the results table -----
2298 PMA_displayTableHeaders($is_display, $fields_meta, $fields_cnt, $analyzed_sql, $sort_expression, $sort_expression_nodirection, $sort_direction);
2299 $url_query = '';
2300 echo '<tbody>' . "\n";
2301 $clause_is_unique = PMA_displayTableBody($dt_result, $is_display, $map, $analyzed_sql);
2302 // vertical output case
2303 if ($_SESSION['tmp_user_values']['disp_direction'] == 'vertical') {
2304 PMA_displayVerticalTable();
2305 } // end if
2306 unset($vertical_display);
2307 echo '</tbody>' . "\n";
2309 </table>
2311 <?php
2312 // 4. ----- Displays the link for multi-fields edit and delete
2314 if ($is_display['del_lnk'] == 'dr' && $is_display['del_lnk'] != 'kp') {
2316 $delete_text = $is_display['del_lnk'] == 'dr' ? __('Delete') : __('Kill');
2318 $_url_params = array(
2319 'db' => $db,
2320 'table' => $table,
2321 'sql_query' => $sql_query,
2322 'goto' => $goto,
2324 $uncheckall_url = 'sql.php' . PMA_generate_common_url($_url_params);
2326 $_url_params['checkall'] = '1';
2327 $checkall_url = 'sql.php' . PMA_generate_common_url($_url_params);
2329 if ($_SESSION['tmp_user_values']['disp_direction'] == 'vertical') {
2330 $checkall_params['onclick'] = 'if (setCheckboxes(\'resultsForm\', true)) return false;';
2331 $uncheckall_params['onclick'] = 'if (setCheckboxes(\'resultsForm\', false)) return false;';
2332 } else {
2333 $checkall_params['onclick'] = 'if (markAllRows(\'resultsForm\')) return false;';
2334 $uncheckall_params['onclick'] = 'if (unMarkAllRows(\'resultsForm\')) return false;';
2336 $checkall_link = PMA_linkOrButton($checkall_url, __('Check All'), $checkall_params, false);
2337 $uncheckall_link = PMA_linkOrButton($uncheckall_url, __('Uncheck All'), $uncheckall_params, false);
2338 if ($_SESSION['tmp_user_values']['disp_direction'] != 'vertical') {
2339 echo '<img class="selectallarrow" width="38" height="22"'
2340 .' src="' . $GLOBALS['pmaThemeImage'] . 'arrow_' . $GLOBALS['text_dir'] . '.png' . '"'
2341 .' alt="' . __('With selected:') . '" />';
2343 echo $checkall_link . "\n"
2344 .' / ' . "\n"
2345 .$uncheckall_link . "\n"
2346 .'<i>' . __('With selected:') . '</i>' . "\n";
2348 PMA_buttonOrImage('submit_mult', 'mult_submit',
2349 'submit_mult_change', __('Change'), 'b_edit.png', 'edit');
2350 PMA_buttonOrImage('submit_mult', 'mult_submit',
2351 'submit_mult_delete', $delete_text, 'b_drop.png', 'delete');
2352 if (isset($analyzed_sql[0]) && $analyzed_sql[0]['querytype'] == 'SELECT') {
2353 PMA_buttonOrImage('submit_mult', 'mult_submit',
2354 'submit_mult_export', __('Export'),
2355 'b_tblexport.png', 'export');
2357 echo "\n";
2359 echo '<input type="hidden" name="sql_query"'
2360 .' value="' . htmlspecialchars($sql_query) . '" />' . "\n";
2362 if (! empty($GLOBALS['url_query'])) {
2363 echo '<input type="hidden" name="url_query"'
2364 .' value="' . $GLOBALS['url_query'] . '" />' . "\n";
2367 echo '<input type="hidden" name="clause_is_unique"'
2368 .' value="' . $clause_is_unique . '" />' . "\n";
2370 echo '</form>' . "\n";
2373 // 5. ----- Displays the navigation bar at the bottom if required -----
2375 if ($is_display['nav_bar'] == '1') {
2376 echo '<br />' . "\n";
2377 PMA_displayTableNavigation($pos_next, $pos_prev, $sql_query, 'bottom_direction_dropdown');
2378 } elseif (! isset($GLOBALS['printview']) || $GLOBALS['printview'] != '1') {
2379 echo "\n" . '<br /><br />' . "\n";
2382 // 6. ----- Displays "Query results operations"
2383 if (! isset($GLOBALS['printview']) || $GLOBALS['printview'] != '1') {
2384 PMA_displayResultsOperations($the_disp_mode, $analyzed_sql);
2386 } // end of the 'PMA_displayTable()' function
2388 function default_function($buffer) {
2389 $buffer = htmlspecialchars($buffer);
2390 $buffer = str_replace("\011", ' &nbsp;&nbsp;&nbsp;',
2391 str_replace(' ', ' &nbsp;', $buffer));
2392 $buffer = preg_replace("@((\015\012)|(\015)|(\012))@", '<br />', $buffer);
2394 return $buffer;
2398 * Displays operations that are available on results.
2400 * @param array the display mode
2401 * @param array the analyzed query
2403 * @global string $db the database name
2404 * @global string $table the table name
2405 * @global string $sql_query the current SQL query
2406 * @global integer $unlim_num_rows the total number of rows returned by the
2407 * SQL query without any programmatically
2408 * appended "LIMIT" clause
2410 * @access private
2412 * @see PMA_showMessage(), PMA_setDisplayMode(),
2413 * PMA_displayTableNavigation(), PMA_displayTableHeaders(),
2414 * PMA_displayTableBody(), PMA_displayResultsOperations()
2416 function PMA_displayResultsOperations($the_disp_mode, $analyzed_sql) {
2417 global $db, $table, $sql_query, $unlim_num_rows, $fields_meta;
2419 $header_shown = false;
2420 $header = '<fieldset><legend>' . __('Query results operations') . '</legend>';
2422 if ($the_disp_mode[6] == '1' || $the_disp_mode[9] == '1') {
2423 // Displays "printable view" link if required
2424 if ($the_disp_mode[9] == '1') {
2426 if (!$header_shown) {
2427 echo $header;
2428 $header_shown = true;
2431 $_url_params = array(
2432 'db' => $db,
2433 'table' => $table,
2434 'printview' => '1',
2435 'sql_query' => $sql_query,
2437 $url_query = PMA_generate_common_url($_url_params);
2439 echo PMA_linkOrButton(
2440 'sql.php' . $url_query,
2441 PMA_getIcon('b_print.png', __('Print view')),
2442 '', true, true, 'print_view') . "\n";
2444 if ($_SESSION['tmp_user_values']['display_text']) {
2445 $_url_params['display_text'] = 'F';
2446 echo PMA_linkOrButton(
2447 'sql.php' . PMA_generate_common_url($_url_params),
2448 PMA_getIcon('b_print.png', __('Print view (with full texts)')),
2449 '', true, true, 'print_view') . "\n";
2450 unset($_url_params['display_text']);
2452 } // end displays "printable view"
2455 // Export link
2456 // (the url_query has extra parameters that won't be used to export)
2457 // (the single_table parameter is used in display_export.lib.php
2458 // to hide the SQL and the structure export dialogs)
2459 // If the parser found a PROCEDURE clause
2460 // (most probably PROCEDURE ANALYSE()) it makes no sense to
2461 // display the Export link).
2462 if (isset($analyzed_sql[0]) && $analyzed_sql[0]['querytype'] == 'SELECT' && ! isset($printview) && ! isset($analyzed_sql[0]['queryflags']['procedure'])) {
2463 if (isset($analyzed_sql[0]['table_ref'][0]['table_true_name']) && ! isset($analyzed_sql[0]['table_ref'][1]['table_true_name'])) {
2464 $_url_params['single_table'] = 'true';
2466 if (!$header_shown) {
2467 echo $header;
2468 $header_shown = true;
2470 $_url_params['unlim_num_rows'] = $unlim_num_rows;
2473 * At this point we don't know the table name; this can happen
2474 * for example with a query like
2475 * SELECT bike_code FROM (SELECT bike_code FROM bikes) tmp
2476 * As a workaround we set in the table parameter the name of the
2477 * first table of this database, so that tbl_export.php and
2478 * the script it calls do not fail
2480 if (empty($_url_params['table']) && !empty($_url_params['db'])) {
2481 $_url_params['table'] = PMA_DBI_fetch_value("SHOW TABLES");
2482 /* No result (probably no database selected) */
2483 if ($_url_params['table'] === FALSE) {
2484 unset($_url_params['table']);
2488 echo PMA_linkOrButton(
2489 'tbl_export.php' . PMA_generate_common_url($_url_params),
2490 PMA_getIcon('b_tblexport.png', __('Export')),
2491 '', true, true, '') . "\n";
2493 // show chart
2494 echo PMA_linkOrButton(
2495 'tbl_chart.php' . PMA_generate_common_url($_url_params),
2496 PMA_getIcon('b_chart.png', __('Display chart')),
2497 '', true, true, '') . "\n";
2499 // show GIS chart
2500 $geometry_found = false;
2501 // If atleast one geometry field is found
2502 foreach ($fields_meta as $meta) {
2503 if ($meta->type == 'geometry') {
2504 $geometry_found = true;
2505 break;
2508 if ($geometry_found) {
2509 echo PMA_linkOrButton(
2510 'tbl_gis_visualization.php' . PMA_generate_common_url($_url_params),
2511 PMA_getIcon('b_globe.gif', __('Visualize GIS data')),
2512 '', true, true, '') . "\n";
2516 // CREATE VIEW
2519 * @todo detect privileges to create a view
2520 * (but see 2006-01-19 note in display_create_table.lib.php,
2521 * I think we cannot detect db-specific privileges reliably)
2522 * Note: we don't display a Create view link if we found a PROCEDURE clause
2524 if (!$header_shown) {
2525 echo $header;
2526 $header_shown = true;
2528 if (! isset($analyzed_sql[0]['queryflags']['procedure'])) {
2529 echo PMA_linkOrButton(
2530 'view_create.php' . $url_query,
2531 PMA_getIcon('b_views.png', __('Create view')),
2532 '', true, true, '') . "\n";
2534 if ($header_shown) {
2535 echo '</fieldset><br />';
2540 * Verifies what to do with non-printable contents (binary or BLOB)
2541 * in Browse mode.
2543 * @param string $category BLOB|BINARY|GEOMETRY
2544 * @param string $content the binary content
2545 * @param string $transform_function
2546 * @param string $transform_options
2547 * @param string $default_function
2548 * @param object $meta the meta-information about this field
2549 * @return mixed string or float
2551 function PMA_handle_non_printable_contents($category, $content, $transform_function, $transform_options, $default_function, $meta, $url_params = array()) {
2552 $result = '[' . $category;
2553 if (is_null($content)) {
2554 $result .= ' - NULL';
2555 $size = 0;
2556 } elseif (isset($content)) {
2557 $size = strlen($content);
2558 $display_size = PMA_formatByteDown($size, 3, 1);
2559 $result .= ' - '. $display_size[0] . ' ' . $display_size[1];
2561 $result .= ']';
2563 if (strpos($transform_function, 'octetstream')) {
2564 $result = $content;
2566 if ($size > 0) {
2567 if ($default_function != $transform_function) {
2568 $result = $transform_function($result, $transform_options, $meta);
2569 } else {
2570 $result = $default_function($result, array(), $meta);
2571 if (stristr($meta->type, 'BLOB') && $_SESSION['tmp_user_values']['display_blob']) {
2572 // in this case, restart from the original $content
2573 $result = htmlspecialchars(PMA_replace_binary_contents($content));
2575 /* Create link to download */
2576 if (count($url_params) > 0) {
2577 $result = '<a href="tbl_get_field.php' . PMA_generate_common_url($url_params) . '">' . $result . '</a>';
2581 return($result);
2585 * Prepares the displayable content of a data cell in Browse mode,
2586 * taking into account foreign key description field and transformations
2588 * @param string $class
2589 * @param string $condition_field
2590 * @param string $analyzed_sql
2591 * @param object $meta the meta-information about this field
2592 * @param string $map
2593 * @param string $data
2594 * @param string $transform_function
2595 * @param string $default_function
2596 * @param string $nowrap
2597 * @param string $where_comparison
2598 * @param bool $is_field_truncated
2599 * @return string formatted data
2601 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 ) {
2603 $result = ' class="' . PMA_addClass($class, $condition_field, $meta, $nowrap, $is_field_truncated, $transform_function, $default_function) . '">';
2605 if (isset($analyzed_sql[0]['select_expr']) && is_array($analyzed_sql[0]['select_expr'])) {
2606 foreach ($analyzed_sql[0]['select_expr'] AS $select_expr_position => $select_expr) {
2607 $alias = $analyzed_sql[0]['select_expr'][$select_expr_position]['alias'];
2608 if (isset($alias) && strlen($alias)) {
2609 $true_column = $analyzed_sql[0]['select_expr'][$select_expr_position]['column'];
2610 if ($alias == $meta->name) {
2611 // this change in the parameter does not matter
2612 // outside of the function
2613 $meta->name = $true_column;
2614 } // end if
2615 } // end if
2616 } // end foreach
2617 } // end if
2619 if (isset($map[$meta->name])) {
2620 // Field to display from the foreign table?
2621 if (isset($map[$meta->name][2]) && strlen($map[$meta->name][2])) {
2622 $dispsql = 'SELECT ' . PMA_backquote($map[$meta->name][2])
2623 . ' FROM ' . PMA_backquote($map[$meta->name][3])
2624 . '.' . PMA_backquote($map[$meta->name][0])
2625 . ' WHERE ' . PMA_backquote($map[$meta->name][1])
2626 . $where_comparison;
2627 $dispresult = PMA_DBI_try_query($dispsql, null, PMA_DBI_QUERY_STORE);
2628 if ($dispresult && PMA_DBI_num_rows($dispresult) > 0) {
2629 list($dispval) = PMA_DBI_fetch_row($dispresult, 0);
2630 } else {
2631 $dispval = __('Link not found');
2633 @PMA_DBI_free_result($dispresult);
2634 } else {
2635 $dispval = '';
2636 } // end if... else...
2638 if (isset($GLOBALS['printview']) && $GLOBALS['printview'] == '1') {
2639 $result .= ($transform_function != $default_function ? $transform_function($data, $transform_options, $meta) : $transform_function($data, array(), $meta)) . ' <code>[-&gt;' . $dispval . ']</code>';
2640 } else {
2642 if ('K' == $_SESSION['tmp_user_values']['relational_display']) {
2643 // user chose "relational key" in the display options, so
2644 // the title contains the display field
2645 $title = (! empty($dispval))? ' title="' . htmlspecialchars($dispval) . '"' : '';
2646 } else {
2647 $title = ' title="' . htmlspecialchars($data) . '"';
2650 $_url_params = array(
2651 'db' => $map[$meta->name][3],
2652 'table' => $map[$meta->name][0],
2653 'pos' => '0',
2654 'sql_query' => 'SELECT * FROM '
2655 . PMA_backquote($map[$meta->name][3]) . '.' . PMA_backquote($map[$meta->name][0])
2656 . ' WHERE ' . PMA_backquote($map[$meta->name][1])
2657 . $where_comparison,
2659 $result .= '<a href="sql.php' . PMA_generate_common_url($_url_params)
2660 . '"' . $title . '>';
2662 if ($transform_function != $default_function) {
2663 // always apply a transformation on the real data,
2664 // not on the display field
2665 $result .= $transform_function($data, $transform_options, $meta);
2666 } else {
2667 if ('D' == $_SESSION['tmp_user_values']['relational_display']) {
2668 // user chose "relational display field" in the
2669 // display options, so show display field in the cell
2670 $result .= $transform_function($dispval, array(), $meta);
2671 } else {
2672 // otherwise display data in the cell
2673 $result .= $transform_function($data, array(), $meta);
2676 $result .= '</a>';
2678 } else {
2679 $result .= ($transform_function != $default_function ? $transform_function($data, $transform_options, $meta) : $transform_function($data, array(), $meta));
2681 $result .= '</td>' . "\n";
2683 return $result;
2687 * Generates a checkbox for multi-row submits
2689 * @param string $del_url
2690 * @param array $is_display
2691 * @param string $row_no
2692 * @param string $where_clause_html
2693 * @param string $del_query
2694 * @param string $id_suffix
2695 * @param string $class
2696 * @return string the generated HTML
2699 function PMA_generateCheckboxForMulti($del_url, $is_display, $row_no, $where_clause_html, $del_query, $id_suffix, $class) {
2700 $ret = '';
2701 if (! empty($del_url) && $is_display['del_lnk'] != 'kp') {
2702 $ret .= '<td ';
2703 if (! empty($class)) {
2704 $ret .= 'class="' . $class . '"';
2706 $ret .= ' align="center">'
2707 . '<input type="checkbox" id="id_rows_to_delete' . $row_no . $id_suffix . '" name="rows_to_delete[' . $where_clause_html . ']"'
2708 . ' class="multi_checkbox"'
2709 . ' value="' . htmlspecialchars($del_query) . '" ' . (isset($GLOBALS['checkall']) ? 'checked="checked"' : '') . ' />'
2710 . ' </td>';
2712 return $ret;
2716 * Generates an Edit link
2718 * @param string $edit_url
2719 * @param string $class
2720 * @param string $edit_str
2721 * @param string $where_clause
2722 * @param string $where_clause_html
2723 * @return string the generated HTML
2725 function PMA_generateEditLink($edit_url, $class, $edit_str, $where_clause, $where_clause_html) {
2726 $ret = '';
2727 if (! empty($edit_url)) {
2728 $ret .= '<td class="' . $class . '" align="center" ' . ' ><span class="nowrap">'
2729 . PMA_linkOrButton($edit_url, $edit_str, array(), false);
2731 * Where clause for selecting this row uniquely is provided as
2732 * a hidden input. Used by jQuery scripts for handling inline editing
2734 if (! empty($where_clause)) {
2735 $ret .= '<input type="hidden" class="where_clause" value ="' . $where_clause_html . '" />';
2737 $ret .= '</span></td>';
2739 return $ret;
2743 * Generates an Copy link
2745 * @param string $copy_url
2746 * @param string $copy_str
2747 * @param string $where_clause
2748 * @param string $where_clause_html
2749 * @return string the generated HTML
2751 function PMA_generateCopyLink($copy_url, $copy_str, $where_clause, $where_clause_html, $class) {
2752 $ret = '';
2753 if (! empty($copy_url)) {
2754 $ret .= '<td ';
2755 if (! empty($class)) {
2756 $ret .= 'class="' . $class . '" ';
2758 $ret .= 'align="center" ' . ' ><span class="nowrap">'
2759 . PMA_linkOrButton($copy_url, $copy_str, array(), false);
2761 * Where clause for selecting this row uniquely is provided as
2762 * a hidden input. Used by jQuery scripts for handling inline editing
2764 if (! empty($where_clause)) {
2765 $ret .= '<input type="hidden" class="where_clause" value ="' . $where_clause_html . '" />';
2767 $ret .= '</span></td>';
2769 return $ret;
2773 * Generates a Delete link
2775 * @param string $del_url
2776 * @param string $del_str
2777 * @param string $js_conf
2778 * @param string $class
2779 * @return string the generated HTML
2781 function PMA_generateDeleteLink($del_url, $del_str, $js_conf, $class) {
2782 $ret = '';
2783 if (! empty($del_url)) {
2784 $ret .= '<td ';
2785 if (! empty($class)) {
2786 $ret .= 'class="' . $class . '" ';
2788 $ret .= 'align="center" ' . ' >'
2789 . PMA_linkOrButton($del_url, $del_str, $js_conf, false)
2790 . '</td>';
2792 return $ret;
2796 * Generates checkbox and links at some position (left or right)
2797 * (only called for horizontal mode)
2799 * @param string $position
2800 * @param string $del_url
2801 * @param array $is_display
2802 * @param string $row_no
2803 * @param string $where_clause
2804 * @param string $where_clause_html
2805 * @param string $del_query
2806 * @param string $id_suffix
2807 * @param string $edit_url
2808 * @param string $copy_url
2809 * @param string $class
2810 * @param string $edit_str
2811 * @param string $del_str
2812 * @param string $js_conf
2813 * @return string the generated HTML
2815 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) {
2816 $ret = '';
2818 if ($position == 'left') {
2819 $ret .= PMA_generateCheckboxForMulti($del_url, $is_display, $row_no, $where_clause_html, $del_query, $id_suffix='_left', '', '', '');
2821 $ret .= PMA_generateEditLink($edit_url, $class, $edit_str, $where_clause, $where_clause_html, '');
2823 $ret .= PMA_generateCopyLink($copy_url, $copy_str, $where_clause, $where_clause_html, '');
2825 $ret .= PMA_generateDeleteLink($del_url, $del_str, $js_conf, '', '');
2827 } elseif ($position == 'right') {
2828 $ret .= PMA_generateDeleteLink($del_url, $del_str, $js_conf, '', '');
2830 $ret .= PMA_generateCopyLink($copy_url, $copy_str, $where_clause, $where_clause_html, '');
2832 $ret .= PMA_generateEditLink($edit_url, $class, $edit_str, $where_clause, $where_clause_html, '');
2834 $ret .= PMA_generateCheckboxForMulti($del_url, $is_display, $row_no, $where_clause_html, $del_query, $id_suffix='_right', '', '', '');
2835 } else { // $position == 'none'
2836 $ret .= PMA_generateCheckboxForMulti($del_url, $is_display, $row_no, $where_clause_html, $del_query, $id_suffix='_left', '', '', '');
2838 return $ret;