bug #2837722 [export] Run complex SQL then export does not work
[phpmyadmin/crack.git] / libraries / display_tbl.lib.php
blob8050ffe7dd3ff4eea64e8c494ae0beadb9660d40
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 * @version $Id$
7 * @package phpMyAdmin
8 */
10 /**
13 require_once './libraries/Table.class.php';
14 require_once './libraries/Index.class.php';
16 /**
17 * Defines the display mode to use for the results of a SQL query
19 * It uses a synthetic string that contains all the required informations.
20 * In this string:
21 * - the first two characters stand for the action to do while
22 * clicking on the "edit" link (e.g. 'ur' for update a row, 'nn' for no
23 * edit link...);
24 * - the next two characters stand for the action to do while
25 * clicking on the "delete" link (e.g. 'kp' for kill a process, 'nn' for
26 * no delete link...);
27 * - the next characters are boolean values (1/0) and respectively stand
28 * for sorting links, navigation bar, "insert a new row" link, the
29 * bookmark feature, the expand/collapse text/blob fields button and
30 * the "display printable view" option.
31 * Of course '0'/'1' means the feature won't/will be enabled.
33 * @param string the synthetic value for display_mode (see a few
34 * lines above for explanations)
35 * @param integer the total number of rows returned by the SQL query
36 * without any programmatically appended "LIMIT" clause
37 * (just a copy of $unlim_num_rows if it exists, else
38 * computed inside this function)
40 * @return array an array with explicit indexes for all the display
41 * elements
43 * @global string the database name
44 * @global string the table name
45 * @global integer the total number of rows returned by the SQL query
46 * without any programmatically appended "LIMIT" clause
47 * @global array the properties of the fields returned by the query
48 * @global string the URL to return to in case of error in a SQL
49 * statement
51 * @access private
53 * @see PMA_displayTable()
55 function PMA_setDisplayMode(&$the_disp_mode, &$the_total)
57 global $db, $table;
58 global $unlim_num_rows, $fields_meta;
59 global $err_url;
61 // 1. Initializes the $do_display array
62 $do_display = array();
63 $do_display['edit_lnk'] = $the_disp_mode[0] . $the_disp_mode[1];
64 $do_display['del_lnk'] = $the_disp_mode[2] . $the_disp_mode[3];
65 $do_display['sort_lnk'] = (string) $the_disp_mode[4];
66 $do_display['nav_bar'] = (string) $the_disp_mode[5];
67 $do_display['ins_row'] = (string) $the_disp_mode[6];
68 $do_display['bkm_form'] = (string) $the_disp_mode[7];
69 $do_display['text_btn'] = (string) $the_disp_mode[8];
70 $do_display['pview_lnk'] = (string) $the_disp_mode[9];
72 // 2. Display mode is not "false for all elements" -> updates the
73 // display mode
74 if ($the_disp_mode != 'nnnn000000') {
75 // 2.0 Print view -> set all elements to false!
76 if (isset($GLOBALS['printview']) && $GLOBALS['printview'] == '1') {
77 $do_display['edit_lnk'] = 'nn'; // no edit link
78 $do_display['del_lnk'] = 'nn'; // no delete link
79 $do_display['sort_lnk'] = (string) '0';
80 $do_display['nav_bar'] = (string) '0';
81 $do_display['ins_row'] = (string) '0';
82 $do_display['bkm_form'] = (string) '0';
83 $do_display['text_btn'] = (string) '0';
84 $do_display['pview_lnk'] = (string) '0';
86 // 2.1 Statement is a "SELECT COUNT", a
87 // "CHECK/ANALYZE/REPAIR/OPTIMIZE", an "EXPLAIN" one or
88 // contains a "PROC ANALYSE" part
89 elseif ($GLOBALS['is_count'] || $GLOBALS['is_analyse'] || $GLOBALS['is_maint'] || $GLOBALS['is_explain']) {
90 $do_display['edit_lnk'] = 'nn'; // no edit link
91 $do_display['del_lnk'] = 'nn'; // no delete link
92 $do_display['sort_lnk'] = (string) '0';
93 $do_display['nav_bar'] = (string) '0';
94 $do_display['ins_row'] = (string) '0';
95 $do_display['bkm_form'] = (string) '1';
96 if ($GLOBALS['is_maint']) {
97 $do_display['text_btn'] = (string) '1';
98 } else {
99 $do_display['text_btn'] = (string) '0';
101 $do_display['pview_lnk'] = (string) '1';
103 // 2.2 Statement is a "SHOW..."
104 elseif ($GLOBALS['is_show']) {
106 * 2.2.1
107 * @todo defines edit/delete links depending on show statement
109 $tmp = preg_match('@^SHOW[[:space:]]+(VARIABLES|(FULL[[:space:]]+)?PROCESSLIST|STATUS|TABLE|GRANTS|CREATE|LOGS|DATABASES|FIELDS)@i', $GLOBALS['sql_query'], $which);
110 if (isset($which[1]) && strpos(' ' . strtoupper($which[1]), 'PROCESSLIST') > 0) {
111 $do_display['edit_lnk'] = 'nn'; // no edit link
112 $do_display['del_lnk'] = 'kp'; // "kill process" type edit link
113 } else {
114 // Default case -> no links
115 $do_display['edit_lnk'] = 'nn'; // no edit link
116 $do_display['del_lnk'] = 'nn'; // no delete link
118 // 2.2.2 Other settings
119 $do_display['sort_lnk'] = (string) '0';
120 $do_display['nav_bar'] = (string) '0';
121 $do_display['ins_row'] = (string) '0';
122 $do_display['bkm_form'] = (string) '1';
123 $do_display['text_btn'] = (string) '1';
124 $do_display['pview_lnk'] = (string) '1';
126 // 2.3 Other statements (ie "SELECT" ones) -> updates
127 // $do_display['edit_lnk'], $do_display['del_lnk'] and
128 // $do_display['text_btn'] (keeps other default values)
129 else {
130 $prev_table = $fields_meta[0]->table;
131 $do_display['text_btn'] = (string) '1';
132 for ($i = 0; $i < $GLOBALS['fields_cnt']; $i++) {
133 $is_link = ($do_display['edit_lnk'] != 'nn'
134 || $do_display['del_lnk'] != 'nn'
135 || $do_display['sort_lnk'] != '0'
136 || $do_display['ins_row'] != '0');
137 // 2.3.2 Displays edit/delete/sort/insert links?
138 if ($is_link
139 && ($fields_meta[$i]->table == '' || $fields_meta[$i]->table != $prev_table)) {
140 $do_display['edit_lnk'] = 'nn'; // don't display links
141 $do_display['del_lnk'] = 'nn';
143 * @todo May be problematic with same fields names in two joined table.
145 // $do_display['sort_lnk'] = (string) '0';
146 $do_display['ins_row'] = (string) '0';
147 if ($do_display['text_btn'] == '1') {
148 break;
150 } // end if (2.3.2)
151 // 2.3.3 Always display print view link
152 $do_display['pview_lnk'] = (string) '1';
153 $prev_table = $fields_meta[$i]->table;
154 } // end for
155 } // end if..elseif...else (2.1 -> 2.3)
156 } // end if (2)
158 // 3. Gets the total number of rows if it is unknown
159 if (isset($unlim_num_rows) && $unlim_num_rows != '') {
160 $the_total = $unlim_num_rows;
161 } elseif (($do_display['nav_bar'] == '1' || $do_display['sort_lnk'] == '1')
162 && (strlen($db) && !empty($table))) {
163 $the_total = PMA_Table::countRecords($db, $table, true);
166 // 4. If navigation bar or sorting fields names URLs should be
167 // displayed but there is only one row, change these settings to
168 // false
169 if ($do_display['nav_bar'] == '1' || $do_display['sort_lnk'] == '1') {
171 // - Do not display sort links if less than 2 rows.
172 // - For a VIEW we (probably) did not count the number of rows
173 // so don't test this number here, it would remove the possibility
174 // of sorting VIEW results.
175 if (isset($unlim_num_rows) && $unlim_num_rows < 2 && ! PMA_Table::isView($db, $table)) {
176 // garvin: force display of navbar for vertical/horizontal display-choice.
177 // $do_display['nav_bar'] = (string) '0';
178 $do_display['sort_lnk'] = (string) '0';
180 } // end if (3)
182 // 5. Updates the synthetic var
183 $the_disp_mode = join('', $do_display);
185 return $do_display;
186 } // end of the 'PMA_setDisplayMode()' function
190 * Displays a navigation bar to browse among the results of a SQL query
192 * @uses $_SESSION['userconf']['disp_direction']
193 * @uses $_SESSION['userconf']['repeat_cells']
194 * @uses $_SESSION['userconf']['max_rows']
195 * @uses $_SESSION['userconf']['pos']
196 * @param integer the offset for the "next" page
197 * @param integer the offset for the "previous" page
198 * @param string the URL-encoded query
200 * @global string $db the database name
201 * @global string $table the table name
202 * @global string $goto the URL to go back in case of errors
203 * @global integer $num_rows the total number of rows returned by the
204 * SQL query
205 * @global integer $unlim_num_rows the total number of rows returned by the
206 * SQL any programmatically appended "LIMIT" clause
207 * @global boolean $is_innodb whether its InnoDB or not
208 * @global array $showtable table definitions
210 * @access private
212 * @see PMA_displayTable()
214 function PMA_displayTableNavigation($pos_next, $pos_prev, $sql_query)
216 global $db, $table, $goto;
217 global $num_rows, $unlim_num_rows;
218 global $is_innodb;
219 global $showtable;
221 // here, using htmlentities() would cause problems if the query
222 // contains accented characters
223 $html_sql_query = htmlspecialchars($sql_query);
226 * @todo move this to a central place
227 * @todo for other future table types
229 $is_innodb = (isset($showtable['Type']) && $showtable['Type'] == 'InnoDB');
233 <!-- Navigation bar -->
234 <table border="0" cellpadding="2" cellspacing="0">
235 <tr>
236 <?php
237 // Move to the beginning or to the previous page
238 if ($_SESSION['userconf']['pos'] && $_SESSION['userconf']['max_rows'] != 'all') {
239 // loic1: patch #474210 from Gosha Sakovich - part 1
240 if ($GLOBALS['cfg']['NavigationBarIconic']) {
241 $caption1 = '&lt;&lt;';
242 $caption2 = ' &lt; ';
243 $title1 = ' title="' . $GLOBALS['strPos1'] . '"';
244 $title2 = ' title="' . $GLOBALS['strPrevious'] . '"';
245 } else {
246 $caption1 = $GLOBALS['strPos1'] . ' &lt;&lt;';
247 $caption2 = $GLOBALS['strPrevious'] . ' &lt;';
248 $title1 = '';
249 $title2 = '';
250 } // end if... else...
252 <td>
253 <form action="sql.php" method="post">
254 <?php echo PMA_generate_common_hidden_inputs($db, $table); ?>
255 <input type="hidden" name="sql_query" value="<?php echo $html_sql_query; ?>" />
256 <input type="hidden" name="pos" value="0" />
257 <input type="hidden" name="goto" value="<?php echo $goto; ?>" />
258 <input type="submit" name="navig" value="<?php echo $caption1; ?>"<?php echo $title1; ?> />
259 </form>
260 </td>
261 <td>
262 <form action="sql.php" method="post">
263 <?php echo PMA_generate_common_hidden_inputs($db, $table); ?>
264 <input type="hidden" name="sql_query" value="<?php echo $html_sql_query; ?>" />
265 <input type="hidden" name="pos" value="<?php echo $pos_prev; ?>" />
266 <input type="hidden" name="goto" value="<?php echo $goto; ?>" />
267 <input type="submit" name="navig" value="<?php echo $caption2; ?>"<?php echo $title2; ?> />
268 </form>
269 </td>
270 <?php
271 } // end move back
273 <td>
274 &nbsp;&nbsp;&nbsp;
275 </td>
276 <td align="center">
277 <?php // if displaying a VIEW, $unlim_num_rows could be zero because
278 // of $cfg['MaxExactCountViews']; in this case, avoid passing
279 // the 5th parameter to checkFormElementInRange()
280 // (this means we can't validate the upper limit ?>
281 <form action="sql.php" method="post"
282 onsubmit="return (checkFormElementInRange(this, 'session_max_rows', '<?php echo str_replace('\'', '\\\'', $GLOBALS['strInvalidRowNumber']); ?>', 1) &amp;&amp; checkFormElementInRange(this, 'pos', '<?php echo str_replace('\'', '\\\'', $GLOBALS['strInvalidRowNumber']); ?>', 0<?php echo $unlim_num_rows > 0 ? ',' . $unlim_num_rows - 1 : ''; ?>))">
283 <?php echo PMA_generate_common_hidden_inputs($db, $table); ?>
284 <input type="hidden" name="sql_query" value="<?php echo $html_sql_query; ?>" />
285 <input type="hidden" name="goto" value="<?php echo $goto; ?>" />
286 <input type="submit" name="navig" value="<?php echo $GLOBALS['strShow']; ?> :" />
287 <input type="text" name="session_max_rows" size="3" value="<?php echo (($_SESSION['userconf']['max_rows'] != 'all') ? $_SESSION['userconf']['max_rows'] : $GLOBALS['cfg']['MaxRows']); ?>" class="textfield" onfocus="this.select()" />
288 <?php echo $GLOBALS['strRowsFrom'] . "\n"; ?>
289 <input type="text" name="pos" size="6" value="<?php echo (($pos_next >= $unlim_num_rows) ? 0 : $pos_next); ?>" class="textfield" onfocus="this.select()" />
290 <br />
291 <?php
292 // Display mode (horizontal/vertical and repeat headers)
293 $param1 = ' <select name="disp_direction">' . "\n"
294 . ' <option value="horizontal"' . (($_SESSION['userconf']['disp_direction'] == 'horizontal') ? ' selected="selected"': '') . '>' . $GLOBALS['strRowsModeHorizontal'] . '</option>' . "\n"
295 . ' <option value="horizontalflipped"' . (($_SESSION['userconf']['disp_direction'] == 'horizontalflipped') ? ' selected="selected"': '') . '>' . $GLOBALS['strRowsModeFlippedHorizontal'] . '</option>' . "\n"
296 . ' <option value="vertical"' . (($_SESSION['userconf']['disp_direction'] == 'vertical') ? ' selected="selected"': '') . '>' . $GLOBALS['strRowsModeVertical'] . '</option>' . "\n"
297 . ' </select>' . "\n"
298 . ' ';
299 $param2 = ' <input type="text" size="3" name="repeat_cells" value="' . $_SESSION['userconf']['repeat_cells'] . '" class="textfield" />' . "\n"
300 . ' ';
301 echo ' ' . sprintf($GLOBALS['strRowsModeOptions'], "\n" . $param1, "\n" . $param2) . "\n";
303 </form>
304 </td>
305 <td>
306 &nbsp;&nbsp;&nbsp;
307 </td>
308 <?php
309 // Move to the next page or to the last one
310 if (($_SESSION['userconf']['pos'] + $_SESSION['userconf']['max_rows'] < $unlim_num_rows) && $num_rows >= $_SESSION['userconf']['max_rows']
311 && $_SESSION['userconf']['max_rows'] != 'all') {
312 // loic1: patch #474210 from Gosha Sakovich - part 2
313 if ($GLOBALS['cfg']['NavigationBarIconic']) {
314 $caption3 = ' &gt; ';
315 $caption4 = '&gt;&gt;';
316 $title3 = ' title="' . $GLOBALS['strNext'] . '"';
317 $title4 = ' title="' . $GLOBALS['strEnd'] . '"';
318 } else {
319 $caption3 = '&gt; ' . $GLOBALS['strNext'];
320 $caption4 = '&gt;&gt; ' . $GLOBALS['strEnd'];
321 $title3 = '';
322 $title4 = '';
323 } // end if... else...
324 echo "\n";
326 <td>
327 <form action="sql.php" method="post">
328 <?php echo PMA_generate_common_hidden_inputs($db, $table); ?>
329 <input type="hidden" name="sql_query" value="<?php echo $html_sql_query; ?>" />
330 <input type="hidden" name="pos" value="<?php echo $pos_next; ?>" />
331 <input type="hidden" name="goto" value="<?php echo $goto; ?>" />
332 <input type="submit" name="navig" value="<?php echo $caption3; ?>"<?php echo $title3; ?> />
333 </form>
334 </td>
335 <td>
336 <form action="sql.php" method="post"
337 onsubmit="return <?php echo (($_SESSION['userconf']['pos'] + $_SESSION['userconf']['max_rows'] < $unlim_num_rows && $num_rows >= $_SESSION['userconf']['max_rows']) ? 'true' : 'false'); ?>">
338 <?php echo PMA_generate_common_hidden_inputs($db, $table); ?>
339 <input type="hidden" name="sql_query" value="<?php echo $html_sql_query; ?>" />
340 <input type="hidden" name="pos" value="<?php echo @((ceil($unlim_num_rows / $_SESSION['userconf']['max_rows'])- 1) * $_SESSION['userconf']['max_rows']); ?>" />
341 <?php
342 if ($is_innodb && $unlim_num_rows > $GLOBALS['cfg']['MaxExactCount']) {
343 echo '<input type="hidden" name="find_real_end" value="1" />' . "\n";
344 // no backquote around this message
345 $onclick = ' onclick="return confirmAction(\'' . PMA_jsFormat($GLOBALS['strLongOperation'], false) . '\')"';
348 <input type="hidden" name="goto" value="<?php echo $goto; ?>" />
349 <input type="submit" name="navig" value="<?php echo $caption4; ?>"<?php echo $title4; ?> <?php echo (empty($onclick) ? '' : $onclick); ?>/>
350 </form>
351 </td>
352 <?php
353 } // end move toward
356 //page redirection
357 // (unless we are showing all records)
358 if ('all' != $_SESSION['userconf']['max_rows']) { //if1
359 $pageNow = @floor($_SESSION['userconf']['pos'] / $_SESSION['userconf']['max_rows']) + 1;
360 $nbTotalPage = @ceil($unlim_num_rows / $_SESSION['userconf']['max_rows']);
362 if ($nbTotalPage > 1){ //if2
364 <td>
365 &nbsp;&nbsp;&nbsp;
366 </td>
367 <td>
368 <?php //<form> for keep the form alignment of button < and << ?>
369 <form action="none">
370 <?php
371 $_url_params = array(
372 'db' => $db,
373 'table' => $table,
374 'sql_query' => $sql_query,
375 'goto' => $goto,
377 echo PMA_pageselector(
378 'sql.php' . PMA_generate_common_url($_url_params) . PMA_get_arg_separator('js'),
379 $_SESSION['userconf']['max_rows'],
380 $pageNow,
381 $nbTotalPage,
382 200,
387 $GLOBALS['strPageNumber']
390 </form>
391 </td>
392 <?php
393 } //_if2
394 } //_if1
396 // Display the "Show all" button if allowed
397 if ($GLOBALS['cfg']['ShowAll'] && ($num_rows < $unlim_num_rows)) {
398 echo "\n";
400 <td>
401 &nbsp;&nbsp;&nbsp;
402 </td>
403 <td>
404 <form action="sql.php" method="post">
405 <?php echo PMA_generate_common_hidden_inputs($db, $table); ?>
406 <input type="hidden" name="sql_query" value="<?php echo $html_sql_query; ?>" />
407 <input type="hidden" name="pos" value="0" />
408 <input type="hidden" name="session_max_rows" value="all" />
409 <input type="hidden" name="goto" value="<?php echo $goto; ?>" />
410 <input type="submit" name="navig" value="<?php echo $GLOBALS['strShowAll']; ?>" />
411 </form>
412 </td>
413 <?php
414 } // end show all
415 echo "\n";
417 </tr>
418 </table>
420 <?php
421 } // end of the 'PMA_displayTableNavigation()' function
425 * Displays the headers of the results table
427 * @uses $_SESSION['userconf']['disp_direction']
428 * @uses $_SESSION['userconf']['repeat_cells']
429 * @uses $_SESSION['userconf']['max_rows']
430 * @uses $_SESSION['userconf']['display_text']
431 * @uses $_SESSION['userconf']['display_binary']
432 * @param array which elements to display
433 * @param array the list of fields properties
434 * @param integer the total number of fields returned by the SQL query
435 * @param array the analyzed query
437 * @return boolean always true
439 * @global string $db the database name
440 * @global string $table the table name
441 * @global string $goto the URL to go back in case of errors
442 * @global string $sql_query the SQL query
443 * @global integer $num_rows the total number of rows returned by the
444 * SQL query
445 * @global array $vertical_display informations used with vertical display
446 * mode
448 * @access private
450 * @see PMA_displayTable()
452 function PMA_displayTableHeaders(&$is_display, &$fields_meta, $fields_cnt = 0, $analyzed_sql = '', $sort_expression, $sort_expression_nodirection, $sort_direction)
454 global $db, $table, $goto;
455 global $sql_query, $num_rows;
456 global $vertical_display, $highlight_columns;
458 if ($analyzed_sql == '') {
459 $analyzed_sql = array();
462 // can the result be sorted?
463 if ($is_display['sort_lnk'] == '1') {
465 // Just as fallback
466 $unsorted_sql_query = $sql_query;
467 if (isset($analyzed_sql[0]['unsorted_query'])) {
468 $unsorted_sql_query = $analyzed_sql[0]['unsorted_query'];
470 // Handles the case of multiple clicks on a column's header
471 // which would add many spaces before "ORDER BY" in the
472 // generated query.
473 $unsorted_sql_query = trim($unsorted_sql_query);
475 // sorting by indexes, only if it makes sense (only one table ref)
476 if (isset($analyzed_sql) && isset($analyzed_sql[0]) &&
477 isset($analyzed_sql[0]['querytype']) && $analyzed_sql[0]['querytype'] == 'SELECT' &&
478 isset($analyzed_sql[0]['table_ref']) && count($analyzed_sql[0]['table_ref']) == 1) {
480 // grab indexes data:
481 $indexes = PMA_Index::getFromTable($table, $db);
483 // do we have any index?
484 if ($indexes) {
486 if ($_SESSION['userconf']['disp_direction'] == 'horizontal'
487 || $_SESSION['userconf']['disp_direction'] == 'horizontalflipped') {
488 $span = $fields_cnt;
489 if ($is_display['edit_lnk'] != 'nn') {
490 $span++;
492 if ($is_display['del_lnk'] != 'nn') {
493 $span++;
495 if ($is_display['del_lnk'] != 'kp' && $is_display['del_lnk'] != 'nn') {
496 $span++;
498 } else {
499 $span = $num_rows + floor($num_rows/$_SESSION['userconf']['repeat_cells']) + 1;
502 echo '<form action="sql.php" method="post">' . "\n";
503 echo PMA_generate_common_hidden_inputs($db, $table);
504 echo $GLOBALS['strSortByKey'] . ': <select name="sql_query" onchange="this.form.submit();">' . "\n";
505 $used_index = false;
506 $local_order = (isset($sort_expression) ? $sort_expression : '');
507 foreach ($indexes as $index) {
508 $asc_sort = '`' . implode('` ASC, `', array_keys($index->getColumns())) . '` ASC';
509 $desc_sort = '`' . implode('` DESC, `', array_keys($index->getColumns())) . '` DESC';
510 $used_index = $used_index || $local_order == $asc_sort || $local_order == $desc_sort;
511 echo '<option value="'
512 . htmlspecialchars($unsorted_sql_query . ' ORDER BY ' . $asc_sort)
513 . '"' . ($local_order == $asc_sort ? ' selected="selected"' : '')
514 . '>' . htmlspecialchars($index->getName()) . ' ('
515 . $GLOBALS['strAscending'] . ')</option>';
516 echo '<option value="'
517 . htmlspecialchars($unsorted_sql_query . ' ORDER BY ' . $desc_sort)
518 . '"' . ($local_order == $desc_sort ? ' selected="selected"' : '')
519 . '>' . htmlspecialchars($index->getName()) . ' ('
520 . $GLOBALS['strDescending'] . ')</option>';
522 echo '<option value="' . htmlspecialchars($unsorted_sql_query) . '"' . ($used_index ? '' : ' selected="selected"') . '>' . $GLOBALS['strNone'] . '</option>';
523 echo '</select>' . "\n";
524 echo '<noscript><input type="submit" value="' . $GLOBALS['strGo'] . '" /></noscript>';
525 echo '</form>' . "\n";
531 $vertical_display['emptypre'] = 0;
532 $vertical_display['emptyafter'] = 0;
533 $vertical_display['textbtn'] = '';
535 // Display options (if we are not in print view)
536 if (! (isset($GLOBALS['printview']) && $GLOBALS['printview'] == '1')) {
537 echo '<form method="post" action="sql.php" name="displayOptionsForm" id="displayOptionsForm">';
538 $url_params = array(
539 'db' => $db,
540 'table' => $table,
541 'sql_query' => $sql_query,
542 'goto' => $goto,
543 'display_options_form' => 1
545 echo PMA_generate_common_hidden_inputs($url_params);
546 echo '<br />';
547 PMA_generate_slider_effect('displayoptions',$GLOBALS['strOptions']);
548 echo '<fieldset>';
550 echo '<div class="formelement">';
551 $choices = array(
552 'P' => $GLOBALS['strPartialText'],
553 'F' => $GLOBALS['strFullText']
555 PMA_generate_html_radio('display_text', $choices, $_SESSION['userconf']['display_text']);
556 echo '</div>';
558 if ($GLOBALS['cfgRelation']['relwork'] && $GLOBALS['cfgRelation']['displaywork']) {
559 echo '<div class="formelement">';
560 $choices = array(
561 'K' => $GLOBALS['strRelationalKey'],
562 'D' => $GLOBALS['strRelationalDisplayField']
564 PMA_generate_html_radio('relational_display', $choices, $_SESSION['userconf']['relational_display']);
565 echo '</div>';
568 echo '<div class="formelement">';
569 PMA_generate_html_checkbox('display_binary', $GLOBALS['strShowBinaryContents'], ! empty($_SESSION['userconf']['display_binary']), false);
570 echo '<br />';
571 PMA_generate_html_checkbox('display_blob', $GLOBALS['strShowBLOBContents'], ! empty($_SESSION['userconf']['display_blob']), false);
572 echo '</div>';
574 // I would have preferred to name this "display_transformation".
575 // This is the only way I found to be able to keep this setting sticky
576 // per SQL query, and at the same time have a default that displays
577 // the transformations.
578 echo '<div class="formelement">';
579 PMA_generate_html_checkbox('hide_transformation', $GLOBALS['strHide'] . ' ' . $GLOBALS['strMIME_transformation'], ! empty($_SESSION['userconf']['hide_transformation']), false);
580 echo '</div>';
582 echo '<div class="clearfloat"></div>';
583 echo '</fieldset>';
585 echo '<fieldset class="tblFooters">';
586 echo '<input type="submit" value="' . $GLOBALS['strGo'] . '" />';
587 echo '</fieldset>';
588 echo '</div>';
589 echo '</form>';
592 // Start of form for multi-rows edit/delete/export
594 if ($is_display['del_lnk'] == 'dr' || $is_display['del_lnk'] == 'kp') {
595 echo '<form method="post" action="tbl_row_action.php" name="rowsDeleteForm" id="rowsDeleteForm">' . "\n";
596 echo PMA_generate_common_hidden_inputs($db, $table, 1);
597 echo '<input type="hidden" name="goto" value="sql.php" />' . "\n";
600 echo '<table id="table_results" class="data">' . "\n";
601 if ($_SESSION['userconf']['disp_direction'] == 'horizontal'
602 || $_SESSION['userconf']['disp_direction'] == 'horizontalflipped') {
603 echo '<thead><tr>' . "\n";
606 // 1. Displays the full/partial text button (part 1)...
607 if ($_SESSION['userconf']['disp_direction'] == 'horizontal'
608 || $_SESSION['userconf']['disp_direction'] == 'horizontalflipped') {
609 $colspan = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn')
610 ? ' colspan="3"'
611 : '';
612 } else {
613 $rowspan = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn')
614 ? ' rowspan="3"'
615 : '';
618 // ... before the result table
619 if (($is_display['edit_lnk'] == 'nn' && $is_display['del_lnk'] == 'nn')
620 && $is_display['text_btn'] == '1') {
621 $vertical_display['emptypre'] = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn') ? 3 : 0;
622 if ($_SESSION['userconf']['disp_direction'] == 'horizontal'
623 || $_SESSION['userconf']['disp_direction'] == 'horizontalflipped') {
625 <th colspan="<?php echo $fields_cnt; ?>"></th>
626 </tr>
627 <tr>
628 <?php
629 } // end horizontal/horizontalflipped mode
630 else {
632 <tr>
633 <th colspan="<?php echo $num_rows + floor($num_rows/$_SESSION['userconf']['repeat_cells']) + 1; ?>"></th>
634 </tr>
635 <?php
636 } // end vertical mode
639 // ... at the left column of the result table header if possible
640 // and required
641 elseif ($GLOBALS['cfg']['ModifyDeleteAtLeft'] && $is_display['text_btn'] == '1') {
642 $vertical_display['emptypre'] = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn') ? 3 : 0;
643 if ($_SESSION['userconf']['disp_direction'] == 'horizontal'
644 || $_SESSION['userconf']['disp_direction'] == 'horizontalflipped') {
646 <th <?php echo $colspan; ?>></th>
647 <?php
648 } // end horizontal/horizontalflipped mode
649 else {
650 $vertical_display['textbtn'] = ' <th ' . $rowspan . ' valign="middle">' . "\n"
651 . ' ' . "\n"
652 . ' </th>' . "\n";
653 } // end vertical mode
656 // ... elseif no button, displays empty(ies) col(s) if required
657 elseif ($GLOBALS['cfg']['ModifyDeleteAtLeft']
658 && ($is_display['edit_lnk'] != 'nn' || $is_display['del_lnk'] != 'nn')) {
659 $vertical_display['emptypre'] = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn') ? 3 : 0;
660 if ($_SESSION['userconf']['disp_direction'] == 'horizontal'
661 || $_SESSION['userconf']['disp_direction'] == 'horizontalflipped') {
663 <td<?php echo $colspan; ?>></td>
664 <?php
665 } // end horizontal/horizontalfipped mode
666 else {
667 $vertical_display['textbtn'] = ' <td' . $rowspan . '></td>' . "\n";
668 } // end vertical mode
671 // 2. Displays the fields' name
672 // 2.0 If sorting links should be used, checks if the query is a "JOIN"
673 // statement (see 2.1.3)
675 // 2.0.1 Prepare Display column comments if enabled ($GLOBALS['cfg']['ShowBrowseComments']).
676 // Do not show comments, if using horizontalflipped mode, because of space usage
677 if ($GLOBALS['cfg']['ShowBrowseComments']
678 && $_SESSION['userconf']['disp_direction'] != 'horizontalflipped') {
679 $comments_map = array();
680 if (isset($analyzed_sql[0]) && is_array($analyzed_sql[0])) {
681 foreach ($analyzed_sql[0]['table_ref'] as $tbl) {
682 $tb = $tbl['table_true_name'];
683 $comments_map[$tb] = PMA_getComments($db, $tb);
684 unset($tb);
689 if ($GLOBALS['cfgRelation']['commwork'] && $GLOBALS['cfgRelation']['mimework'] && $GLOBALS['cfg']['BrowseMIME'] && ! $_SESSION['userconf']['hide_transformation']) {
690 require_once './libraries/transformations.lib.php';
691 $GLOBALS['mime_map'] = PMA_getMIME($db, $table);
694 if ($is_display['sort_lnk'] == '1') {
695 $select_expr = $analyzed_sql[0]['select_expr_clause'];
698 // garvin: See if we have to highlight any header fields of a WHERE query.
699 // Uses SQL-Parser results.
700 $highlight_columns = array();
701 if (isset($analyzed_sql) && isset($analyzed_sql[0]) &&
702 isset($analyzed_sql[0]['where_clause_identifiers'])) {
704 $wi = 0;
705 if (isset($analyzed_sql[0]['where_clause_identifiers']) && is_array($analyzed_sql[0]['where_clause_identifiers'])) {
706 foreach ($analyzed_sql[0]['where_clause_identifiers'] AS $wci_nr => $wci) {
707 $highlight_columns[$wci] = 'true';
712 for ($i = 0; $i < $fields_cnt; $i++) {
713 // garvin: See if this column should get highlight because it's used in the
714 // where-query.
715 if (isset($highlight_columns[$fields_meta[$i]->name]) || isset($highlight_columns[PMA_backquote($fields_meta[$i]->name)])) {
716 $condition_field = true;
717 } else {
718 $condition_field = false;
721 // 2.0 Prepare comment-HTML-wrappers for each row, if defined/enabled.
722 if (isset($comments_map) &&
723 isset($comments_map[$fields_meta[$i]->table]) &&
724 isset($comments_map[$fields_meta[$i]->table][$fields_meta[$i]->name])) {
725 $comments = '<span class="tblcomment">' . htmlspecialchars($comments_map[$fields_meta[$i]->table][$fields_meta[$i]->name]) . '</span>';
726 } else {
727 $comments = '';
730 // 2.1 Results can be sorted
731 if ($is_display['sort_lnk'] == '1') {
733 // 2.1.1 Checks if the table name is required; it's the case
734 // for a query with a "JOIN" statement and if the column
735 // isn't aliased, or in queries like
736 // SELECT `1`.`master_field` , `2`.`master_field`
737 // FROM `PMA_relation` AS `1` , `PMA_relation` AS `2`
739 if (isset($fields_meta[$i]->table) && strlen($fields_meta[$i]->table)) {
740 $sort_tbl = PMA_backquote($fields_meta[$i]->table) . '.';
741 } else {
742 $sort_tbl = '';
745 // 2.1.2 Checks if the current column is used to sort the
746 // results
747 // the orgname member does not exist for all MySQL versions
748 // but if found, it's the one on which to sort
749 $name_to_use_in_sort = $fields_meta[$i]->name;
750 if (isset($fields_meta[$i]->orgname) && strlen($fields_meta[$i]->orgname)) {
751 $name_to_use_in_sort = $fields_meta[$i]->orgname;
753 // $name_to_use_in_sort might contain a space due to
754 // formatting of function expressions like "COUNT(name )"
755 // so we remove the space in this situation
756 $name_to_use_in_sort = str_replace(' )', ')', $name_to_use_in_sort);
758 if (empty($sort_expression)) {
759 $is_in_sort = false;
760 } else {
761 // field name may be preceded by a space, or any number
762 // of characters followed by a dot (tablename.fieldname)
763 // so do a direct comparison
764 // for the sort expression (avoids problems with queries
765 // like "SELECT id, count(id)..." and clicking to sort
766 // on id or on count(id))
767 if (strpos($sort_expression_nodirection, $sort_tbl) === false) {
768 $sort_expression_nodirection = $sort_tbl . $sort_expression_nodirection;
770 $is_in_sort = (str_replace('`', '', $sort_tbl) . $name_to_use_in_sort == str_replace('`', '', $sort_expression_nodirection) ? true : false);
772 // 2.1.3 Check the field name for a bracket.
773 // If it contains one, it's probably a function column
774 // like 'COUNT(`field`)'
775 if (strpos($name_to_use_in_sort, '(') !== false) {
776 $sort_order = ' ORDER BY ' . $name_to_use_in_sort . ' ';
777 } else {
778 $sort_order = ' ORDER BY ' . $sort_tbl . PMA_backquote($name_to_use_in_sort) . ' ';
780 unset($name_to_use_in_sort);
782 // 2.1.4 Do define the sorting URL
783 if (! $is_in_sort) {
784 // loic1: patch #455484 ("Smart" order)
785 $GLOBALS['cfg']['Order'] = strtoupper($GLOBALS['cfg']['Order']);
786 if ($GLOBALS['cfg']['Order'] === 'SMART') {
787 $sort_order .= (preg_match('@time|date@i', $fields_meta[$i]->type)) ? 'DESC' : 'ASC';
788 } else {
789 $sort_order .= $GLOBALS['cfg']['Order'];
791 $order_img = '';
792 } elseif ('DESC' == $sort_direction) {
793 $sort_order .= ' ASC';
794 $order_img = ' <img class="icon" src="' . $GLOBALS['pmaThemeImage'] . 's_desc.png" width="11" height="9" alt="'. $GLOBALS['strDescending'] . '" title="'. $GLOBALS['strDescending'] . '" id="soimg' . $i . '" />';
795 } else {
796 $sort_order .= ' DESC';
797 $order_img = ' <img class="icon" src="' . $GLOBALS['pmaThemeImage'] . 's_asc.png" width="11" height="9" alt="'. $GLOBALS['strAscending'] . '" title="'. $GLOBALS['strAscending'] . '" id="soimg' . $i . '" />';
800 if (preg_match('@(.*)([[:space:]](LIMIT (.*)|PROCEDURE (.*)|FOR UPDATE|LOCK IN SHARE MODE))@i', $unsorted_sql_query, $regs3)) {
801 $sorted_sql_query = $regs3[1] . $sort_order . $regs3[2];
802 } else {
803 $sorted_sql_query = $unsorted_sql_query . $sort_order;
805 $_url_params = array(
806 'db' => $db,
807 'table' => $table,
808 'sql_query' => $sorted_sql_query,
810 $order_url = 'sql.php' . PMA_generate_common_url($_url_params);
812 // 2.1.5 Displays the sorting URL
813 // added 20004-06-09: Michael Keck <mail@michaelkeck.de>
814 // enable sort order swapping for image
815 $order_link_params = array();
816 if (isset($order_img) && $order_img!='') {
817 if (strstr($order_img, 'asc')) {
818 $order_link_params['onmouseover'] = 'if(document.getElementById(\'soimg' . $i . '\')){ document.getElementById(\'soimg' . $i . '\').src=\'' . $GLOBALS['pmaThemeImage'] . 's_desc.png\'; }';
819 $order_link_params['onmouseout'] = 'if(document.getElementById(\'soimg' . $i . '\')){ document.getElementById(\'soimg' . $i . '\').src=\'' . $GLOBALS['pmaThemeImage'] . 's_asc.png\'; }';
820 } elseif (strstr($order_img, 'desc')) {
821 $order_link_params['onmouseover'] = 'if(document.getElementById(\'soimg' . $i . '\')){ document.getElementById(\'soimg' . $i . '\').src=\'' . $GLOBALS['pmaThemeImage'] . 's_asc.png\'; }';
822 $order_link_params['onmouseout'] = 'if(document.getElementById(\'soimg' . $i . '\')){ document.getElementById(\'soimg' . $i . '\').src=\'' . $GLOBALS['pmaThemeImage'] . 's_desc.png\'; }';
825 if ($_SESSION['userconf']['disp_direction'] == 'horizontalflipped'
826 && $GLOBALS['cfg']['HeaderFlipType'] == 'css') {
827 $order_link_params['style'] = 'direction: ltr; writing-mode: tb-rl;';
829 $order_link_params['title'] = $GLOBALS['strSort'];
830 $order_link_content = ($_SESSION['userconf']['disp_direction'] == 'horizontalflipped' && $GLOBALS['cfg']['HeaderFlipType'] == 'fake' ? PMA_flipstring(htmlspecialchars($fields_meta[$i]->name), "<br />\n") : htmlspecialchars($fields_meta[$i]->name));
831 $order_link = PMA_linkOrButton($order_url, $order_link_content . $order_img, $order_link_params, false, true);
833 if ($_SESSION['userconf']['disp_direction'] == 'horizontal'
834 || $_SESSION['userconf']['disp_direction'] == 'horizontalflipped') {
835 echo '<th';
836 if ($condition_field) {
837 echo ' class="condition"';
839 if ($_SESSION['userconf']['disp_direction'] == 'horizontalflipped') {
840 echo ' valign="bottom"';
842 echo '>' . $order_link . $comments . '</th>';
844 $vertical_display['desc'][] = ' <th '
845 . ($condition_field ? ' class="condition"' : '') . '>' . "\n"
846 . $order_link . $comments . ' </th>' . "\n";
847 } // end if (2.1)
849 // 2.2 Results can't be sorted
850 else {
851 if ($_SESSION['userconf']['disp_direction'] == 'horizontal'
852 || $_SESSION['userconf']['disp_direction'] == 'horizontalflipped') {
853 echo '<th';
854 if ($condition_field) {
855 echo ' class="condition"';
857 if ($_SESSION['userconf']['disp_direction'] == 'horizontalflipped') {
858 echo ' valign="bottom"';
860 if ($_SESSION['userconf']['disp_direction'] == 'horizontalflipped'
861 && $GLOBALS['cfg']['HeaderFlipType'] == 'css') {
862 echo ' style="direction: ltr; writing-mode: tb-rl;"';
864 echo '>';
865 if ($_SESSION['userconf']['disp_direction'] == 'horizontalflipped'
866 && $GLOBALS['cfg']['HeaderFlipType'] == 'fake') {
867 echo PMA_flipstring(htmlspecialchars($fields_meta[$i]->name), '<br />');
868 } else {
869 echo htmlspecialchars($fields_meta[$i]->name);
871 echo "\n" . $comments . '</th>';
873 $vertical_display['desc'][] = ' <th '
874 . ($condition_field ? ' class="condition"' : '') . '>' . "\n"
875 . ' ' . htmlspecialchars($fields_meta[$i]->name) . "\n"
876 . $comments . ' </th>';
877 } // end else (2.2)
878 } // end for
880 // 3. Displays the needed checkboxes at the right
881 // column of the result table header if possible and required...
882 if ($GLOBALS['cfg']['ModifyDeleteAtRight']
883 && ($is_display['edit_lnk'] != 'nn' || $is_display['del_lnk'] != 'nn')
884 && $is_display['text_btn'] == '1') {
885 $vertical_display['emptyafter'] = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn') ? 3 : 1;
886 if ($_SESSION['userconf']['disp_direction'] == 'horizontal'
887 || $_SESSION['userconf']['disp_direction'] == 'horizontalflipped') {
888 echo "\n";
890 <th <?php echo $colspan; ?>>
891 </th>
892 <?php
893 } // end horizontal/horizontalflipped mode
894 else {
895 $vertical_display['textbtn'] = ' <th ' . $rowspan . ' valign="middle">' . "\n"
896 . ' ' . "\n"
897 . ' </th>' . "\n";
898 } // end vertical mode
901 // ... elseif no button, displays empty columns if required
902 // (unless coming from Browse mode print view)
903 elseif ($GLOBALS['cfg']['ModifyDeleteAtRight']
904 && ($is_display['edit_lnk'] == 'nn' && $is_display['del_lnk'] == 'nn')
905 && (!$GLOBALS['is_header_sent'])) {
906 $vertical_display['emptyafter'] = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn') ? 3 : 1;
907 if ($_SESSION['userconf']['disp_direction'] == 'horizontal'
908 || $_SESSION['userconf']['disp_direction'] == 'horizontalflipped') {
909 echo "\n";
911 <td<?php echo $colspan; ?>></td>
912 <?php
913 } // end horizontal/horizontalflipped mode
914 else {
915 $vertical_display['textbtn'] = ' <td' . $rowspan . '></td>' . "\n";
916 } // end vertical mode
919 if ($_SESSION['userconf']['disp_direction'] == 'horizontal'
920 || $_SESSION['userconf']['disp_direction'] == 'horizontalflipped') {
922 </tr>
923 </thead>
924 <?php
927 return true;
928 } // end of the 'PMA_displayTableHeaders()' function
933 * Displays the body of the results table
935 * @uses $_SESSION['userconf']['disp_direction']
936 * @uses $_SESSION['userconf']['repeat_cells']
937 * @uses $_SESSION['userconf']['max_rows']
938 * @uses $_SESSION['userconf']['display_text']
939 * @uses $_SESSION['userconf']['display_binary']
940 * @uses $_SESSION['userconf']['display_blob']
941 * @param integer the link id associated to the query which results have
942 * to be displayed
943 * @param array which elements to display
944 * @param array the list of relations
945 * @param array the analyzed query
947 * @return boolean always true
949 * @global string $db the database name
950 * @global string $table the table name
951 * @global string $goto the URL to go back in case of errors
952 * @global string $sql_query the SQL query
953 * @global array $fields_meta the list of fields properties
954 * @global integer $fields_cnt the total number of fields returned by
955 * the SQL query
956 * @global array $vertical_display informations used with vertical display
957 * mode
958 * @global array $highlight_columns column names to highlight
959 * @global array $row current row data
961 * @access private
963 * @see PMA_displayTable()
965 function PMA_displayTableBody(&$dt_result, &$is_display, $map, $analyzed_sql) {
966 global $db, $table, $goto;
967 global $sql_query, $fields_meta, $fields_cnt;
968 global $vertical_display, $highlight_columns;
969 global $row; // mostly because of browser transformations, to make the row-data accessible in a plugin
971 $url_sql_query = $sql_query;
973 // query without conditions to shorten URLs when needed, 200 is just
974 // guess, it should depend on remaining URL length
976 if (isset($analyzed_sql) && isset($analyzed_sql[0]) &&
977 isset($analyzed_sql[0]['querytype']) && $analyzed_sql[0]['querytype'] == 'SELECT' &&
978 strlen($sql_query) > 200) {
980 $url_sql_query = 'SELECT ';
981 if (isset($analyzed_sql[0]['queryflags']['distinct'])) {
982 $url_sql_query .= ' DISTINCT ';
984 $url_sql_query .= $analyzed_sql[0]['select_expr_clause'];
985 if (!empty($analyzed_sql[0]['from_clause'])) {
986 $url_sql_query .= ' FROM ' . $analyzed_sql[0]['from_clause'];
990 if (!is_array($map)) {
991 $map = array();
993 $row_no = 0;
994 $vertical_display['edit'] = array();
995 $vertical_display['delete'] = array();
996 $vertical_display['data'] = array();
997 $vertical_display['row_delete'] = array();
999 // Correction University of Virginia 19991216 in the while below
1000 // Previous code assumed that all tables have keys, specifically that
1001 // the phpMyAdmin GUI should support row delete/edit only for such
1002 // tables.
1003 // Although always using keys is arguably the prescribed way of
1004 // defining a relational table, it is not required. This will in
1005 // particular be violated by the novice.
1006 // We want to encourage phpMyAdmin usage by such novices. So the code
1007 // below has been changed to conditionally work as before when the
1008 // table being displayed has one or more keys; but to display
1009 // delete/edit options correctly for tables without keys.
1011 $odd_row = true;
1012 while ($row = PMA_DBI_fetch_row($dt_result)) {
1013 // lem9: "vertical display" mode stuff
1014 if ($row_no != 0 && $_SESSION['userconf']['repeat_cells'] != 0 && !($row_no % $_SESSION['userconf']['repeat_cells'])
1015 && ($_SESSION['userconf']['disp_direction'] == 'horizontal'
1016 || $_SESSION['userconf']['disp_direction'] == 'horizontalflipped'))
1018 echo '<tr>' . "\n";
1019 if ($vertical_display['emptypre'] > 0) {
1020 echo ' <th colspan="' . $vertical_display['emptypre'] . '">' . "\n"
1021 .' &nbsp;</th>' . "\n";
1024 foreach ($vertical_display['desc'] as $val) {
1025 echo $val;
1028 if ($vertical_display['emptyafter'] > 0) {
1029 echo ' <th colspan="' . $vertical_display['emptyafter'] . '">' . "\n"
1030 .' &nbsp;</th>' . "\n";
1032 echo '</tr>' . "\n";
1033 } // end if
1035 $class = $odd_row ? 'odd' : 'even';
1036 $odd_row = ! $odd_row;
1037 if ($_SESSION['userconf']['disp_direction'] == 'horizontal'
1038 || $_SESSION['userconf']['disp_direction'] == 'horizontalflipped') {
1039 // loic1: pointer code part
1040 echo ' <tr class="' . $class . '">' . "\n";
1041 $class = '';
1045 // 1. Prepares the row (gets primary keys to use)
1046 // 1.1 Results from a "SELECT" statement -> builds the
1047 // "primary" key to use in links
1049 * @todo $unique_condition could be empty, for example a table
1050 * with only one field and it's a BLOB; in this case,
1051 * avoid to display the delete and edit links
1053 $unique_condition = PMA_getUniqueCondition($dt_result, $fields_cnt, $fields_meta, $row);
1054 $unique_condition_html = urlencode($unique_condition);
1056 // 1.2 Defines the URLs for the modify/delete link(s)
1058 if ($is_display['edit_lnk'] != 'nn' || $is_display['del_lnk'] != 'nn') {
1059 // We need to copy the value or else the == 'both' check will always return true
1061 if ($GLOBALS['cfg']['PropertiesIconic'] === 'both') {
1062 $iconic_spacer = '<div class="nowrap">';
1063 } else {
1064 $iconic_spacer = '';
1067 // 1.2.1 Modify link(s)
1068 if ($is_display['edit_lnk'] == 'ur') { // update row case
1069 $_url_params = array(
1070 'db' => $db,
1071 'table' => $table,
1072 'primary_key' => $unique_condition,
1073 'sql_query' => $url_sql_query,
1074 'goto' => 'sql.php',
1076 $edit_url = 'tbl_change.php' . PMA_generate_common_url($_url_params);
1078 $edit_str = PMA_getIcon('b_edit.png', $GLOBALS['strEdit'], true);
1079 } // end if (1.2.1)
1081 if (isset($GLOBALS['cfg']['Bookmark']['table']) && isset($GLOBALS['cfg']['Bookmark']['db']) && $table == $GLOBALS['cfg']['Bookmark']['table'] && $db == $GLOBALS['cfg']['Bookmark']['db'] && isset($row[1]) && isset($row[0])) {
1082 $_url_params = array(
1083 'db' => $row[1],
1084 'id_bookmark' => $row[0],
1085 'action_bookmark' => '0',
1086 'action_bookmark_all' => '1',
1087 'SQL' => $GLOBALS['strExecuteBookmarked'],
1089 $bookmark_go = '<a href="import.php'
1090 . PMA_generate_common_url($_url_params)
1091 .' " title="' . $GLOBALS['strExecuteBookmarked'] . '">';
1093 $bookmark_go .= PMA_getIcon('b_bookmark.png', $GLOBALS['strExecuteBookmarked'], true);
1095 $bookmark_go .= '</a>';
1096 } else {
1097 $bookmark_go = '';
1100 // 1.2.2 Delete/Kill link(s)
1101 if ($is_display['del_lnk'] == 'dr') { // delete row case
1102 $_url_params = array(
1103 'db' => $db,
1104 'table' => $table,
1105 'sql_query' => $url_sql_query,
1106 'zero_rows' => $GLOBALS['strDeleted'],
1107 'goto' => (empty($goto) ? 'tbl_sql.php' : $goto),
1109 $lnk_goto = 'sql.php' . PMA_generate_common_url($_url_params, 'text');
1111 $del_query = 'DELETE FROM ' . PMA_backquote($db) . '.' . PMA_backquote($table)
1112 . ' WHERE ' . $unique_condition . ' LIMIT 1';
1114 $_url_params = array(
1115 'db' => $db,
1116 'table' => $table,
1117 'sql_query' => $del_query,
1118 'zero_rows' => $GLOBALS['strDeleted'],
1119 'goto' => $lnk_goto,
1121 $del_url = 'sql.php' . PMA_generate_common_url($_url_params);
1123 $js_conf = 'DELETE FROM ' . PMA_jsFormat($db) . '.' . PMA_jsFormat($table)
1124 . ' WHERE ' . PMA_jsFormat($unique_condition, false)
1125 . ' LIMIT 1';
1126 $del_str = PMA_getIcon('b_drop.png', $GLOBALS['strDelete'], true);
1127 } elseif ($is_display['del_lnk'] == 'kp') { // kill process case
1129 $_url_params = array(
1130 'db' => $db,
1131 'table' => $table,
1132 'sql_query' => $url_sql_query,
1133 'goto' => 'main.php',
1135 $lnk_goto = 'sql.php' . PMA_generate_common_url($_url_params, 'text');
1137 $_url_params = array(
1138 'db' => 'mysql',
1139 'sql_query' => 'KILL ' . $row[0],
1140 'goto' => $lnk_goto,
1142 $del_url = 'sql.php' . PMA_generate_common_url($_url_params);
1143 $del_query = 'KILL ' . $row[0];
1144 $js_conf = 'KILL ' . $row[0];
1145 $del_str = PMA_getIcon('b_drop.png', $GLOBALS['strKill'], true);
1146 } // end if (1.2.2)
1148 // 1.3 Displays the links at left if required
1149 if ($GLOBALS['cfg']['ModifyDeleteAtLeft']
1150 && ($_SESSION['userconf']['disp_direction'] == 'horizontal'
1151 || $_SESSION['userconf']['disp_direction'] == 'horizontalflipped')) {
1152 $doWriteModifyAt = 'left';
1153 require './libraries/display_tbl_links.lib.php';
1154 } // end if (1.3)
1155 } // end if (1)
1157 // 2. Displays the rows' values
1158 for ($i = 0; $i < $fields_cnt; ++$i) {
1159 $meta = $fields_meta[$i];
1160 $pointer = $i;
1161 // garvin: See if this column should get highlight because it's used in the
1162 // where-query.
1163 if (isset($highlight_columns) && (isset($highlight_columns[$meta->name]) || isset($highlight_columns[PMA_backquote($meta->name)]))) {
1164 $condition_field = true;
1165 } else {
1166 $condition_field = false;
1169 $mouse_events = '';
1170 if ($_SESSION['userconf']['disp_direction'] == 'vertical' && (!isset($GLOBALS['printview']) || ($GLOBALS['printview'] != '1'))) {
1171 if ($GLOBALS['cfg']['BrowsePointerEnable'] == true) {
1172 $mouse_events .= ' onmouseover="setVerticalPointer(this, ' . $row_no . ', \'over\', \'odd\', \'even\', \'hover\', \'marked\');"'
1173 . ' onmouseout="setVerticalPointer(this, ' . $row_no . ', \'out\', \'odd\', \'even\', \'hover\', \'marked\');" ';
1175 if ($GLOBALS['cfg']['BrowseMarkerEnable'] == true) {
1176 $mouse_events .= ' onmousedown="setVerticalPointer(this, ' . $row_no . ', \'click\', \'odd\', \'even\', \'hover\', \'marked\'); setCheckboxColumn(\'id_rows_to_delete' . $row_no . '\');" ';
1177 } else {
1178 $mouse_events .= ' onmousedown="setCheckboxColumn(\'id_rows_to_delete' . $row_no . '\');" ';
1180 }// end if
1182 // garvin: Wrap MIME-transformations. [MIME]
1183 $default_function = 'default_function'; // default_function
1184 $transform_function = $default_function;
1185 $transform_options = array();
1187 if ($GLOBALS['cfgRelation']['mimework'] && $GLOBALS['cfg']['BrowseMIME']) {
1189 if (isset($GLOBALS['mime_map'][$meta->name]['mimetype']) && isset($GLOBALS['mime_map'][$meta->name]['transformation']) && !empty($GLOBALS['mime_map'][$meta->name]['transformation'])) {
1190 $include_file = $GLOBALS['mime_map'][$meta->name]['transformation'];
1192 if (file_exists('./libraries/transformations/' . $include_file)) {
1193 $transformfunction_name = str_replace('.inc.php', '', $GLOBALS['mime_map'][$meta->name]['transformation']);
1195 require_once './libraries/transformations/' . $include_file;
1197 if (function_exists('PMA_transformation_' . $transformfunction_name)) {
1198 $transform_function = 'PMA_transformation_' . $transformfunction_name;
1199 $transform_options = PMA_transformation_getOptions((isset($GLOBALS['mime_map'][$meta->name]['transformation_options']) ? $GLOBALS['mime_map'][$meta->name]['transformation_options'] : ''));
1200 $meta->mimetype = str_replace('_', '/', $GLOBALS['mime_map'][$meta->name]['mimetype']);
1202 } // end if file_exists
1203 } // end if transformation is set
1204 } // end if mime/transformation works.
1206 $_url_params = array(
1207 'db' => $db,
1208 'table' => $table,
1209 'primary_key' => $unique_condition,
1210 'transform_key' => $meta->name,
1213 if (! empty($sql_query)) {
1214 $_url_params['sql_query'] = $url_sql_query;
1217 $transform_options['wrapper_link'] = PMA_generate_common_url($_url_params);
1219 // n u m e r i c
1220 if ($meta->numeric == 1) {
1222 // lem9: if two fields have the same name (this is possible
1223 // with self-join queries, for example), using $meta->name
1224 // will show both fields NULL even if only one is NULL,
1225 // so use the $pointer
1227 if (!isset($row[$i]) || is_null($row[$i])) {
1228 $vertical_display['data'][$row_no][$i] = ' <td align="right"' . $mouse_events . ' class="' . $class . ($condition_field ? ' condition' : '') . '"><i>NULL</i></td>' . "\n";
1229 } elseif ($row[$i] != '') {
1231 $nowrap = ' nowrap';
1232 $where_comparison = ' = ' . $row[$i];
1234 $vertical_display['data'][$row_no][$i] = '<td align="right"' . PMA_prepare_row_data($mouse_events, $class, $condition_field, $analyzed_sql, $meta, $map, $row[$i], $transform_function, $default_function, $nowrap, $where_comparison, $transform_options);
1235 } else {
1236 $vertical_display['data'][$row_no][$i] = ' <td align="right"' . $mouse_events . ' class="' . $class . ' nowrap' . ($condition_field ? ' condition' : '') . '">&nbsp;</td>' . "\n";
1239 // b l o b
1241 } elseif (stristr($meta->type, 'BLOB')) {
1242 // loic1 : PMA_mysql_fetch_fields returns BLOB in place of
1243 // TEXT fields type so we have to ensure it's really a BLOB
1244 $field_flags = PMA_DBI_field_flags($dt_result, $i);
1245 if (stristr($field_flags, 'BINARY')) {
1246 // rajk - for blobstreaming
1248 $bs_reference_exists = $allBSTablesExist = FALSE;
1250 // load PMA configuration
1251 $PMA_Config = $_SESSION['PMA_Config'];
1253 // if PMA configuration exists
1254 if ($PMA_Config)
1256 // load BS variables
1257 $pluginsExist = $PMA_Config->get('BLOBSTREAMING_PLUGINS_EXIST');
1259 // if BS plugins exist
1260 if ($pluginsExist)
1262 // load BS databases
1263 $bs_tables = $PMA_Config->get('BLOBSTREAMABLE_DATABASES');
1265 // if BS db array and specified db string not empty and valid
1266 if (!empty($bs_tables) && strlen($db) > 0)
1268 $bs_tables = $bs_tables[$db];
1270 if (isset($bs_tables))
1272 $allBSTablesExist = TRUE;
1274 // check if BS tables exist for given database
1275 foreach ($bs_tables as $table_key=>$bs_tbl)
1276 if (!$bs_tables[$table_key]['Exists'])
1278 $allBSTablesExist = FALSE;
1279 break;
1286 // if necessary BS tables exist
1287 if ($allBSTablesExist)
1288 $bs_reference_exists = PMA_BS_ReferenceExists($row[$i], $db);
1290 // if valid BS reference exists
1291 if ($bs_reference_exists)
1292 $blobtext = PMA_BS_CreateReferenceLink($row[$i], $db);
1293 else
1294 $blobtext = PMA_handle_non_printable_contents('BLOB', (isset($row[$i]) ? $row[$i] : ''), $transform_function, $transform_options, $default_function, $meta);
1296 $vertical_display['data'][$row_no][$i] = ' <td align="left"' . $mouse_events . ' class="' . $class . ($condition_field ? ' condition' : '') . '">' . $blobtext . '</td>';
1297 unset($blobtext);
1298 } else {
1299 if (!isset($row[$i]) || is_null($row[$i])) {
1300 $vertical_display['data'][$row_no][$i] = ' <td' . $mouse_events . ' class="' . $class . ($condition_field ? ' condition' : '') . '"><i>NULL</i></td>' . "\n";
1301 } elseif ($row[$i] != '') {
1302 // garvin: if a transform function for blob is set, none of these replacements will be made
1303 if (PMA_strlen($row[$i]) > $GLOBALS['cfg']['LimitChars'] && $_SESSION['userconf']['display_text'] == 'P') {
1304 $row[$i] = PMA_substr($row[$i], 0, $GLOBALS['cfg']['LimitChars']) . '...';
1306 // loic1: displays all space characters, 4 space
1307 // characters for tabulations and <cr>/<lf>
1308 $row[$i] = ($default_function != $transform_function ? $transform_function($row[$i], $transform_options, $meta) : $default_function($row[$i], array(), $meta));
1310 $vertical_display['data'][$row_no][$i] = ' <td' . $mouse_events . ' class="' . $class . ($condition_field ? ' condition' : '') . '">' . $row[$i] . '</td>' . "\n";
1311 } else {
1312 $vertical_display['data'][$row_no][$i] = ' <td' . $mouse_events . ' class="' . $class . ($condition_field ? ' condition' : '') . '">&nbsp;</td>' . "\n";
1315 } else {
1316 if (!isset($row[$i]) || is_null($row[$i])) {
1317 $vertical_display['data'][$row_no][$i] = ' <td' . $mouse_events . ' class="' . $class . ($condition_field ? ' condition' : '') . '"><i>NULL</i></td>' . "\n";
1318 } elseif ($row[$i] != '') {
1319 // loic1: support blanks in the key
1320 $relation_id = $row[$i];
1322 // nijel: Cut all fields to $GLOBALS['cfg']['LimitChars']
1323 // lem9: (unless it's a link-type transformation)
1324 if (PMA_strlen($row[$i]) > $GLOBALS['cfg']['LimitChars'] && $_SESSION['userconf']['display_text'] == 'P' && !strpos($transform_function, 'link') === true) {
1325 $row[$i] = PMA_substr($row[$i], 0, $GLOBALS['cfg']['LimitChars']) . '...';
1328 // loic1: displays special characters from binaries
1329 $field_flags = PMA_DBI_field_flags($dt_result, $i);
1330 if (isset($meta->_type) && $meta->_type === MYSQLI_TYPE_BIT) {
1331 $row[$i] = PMA_printable_bit_value($row[$i], $meta->length);
1332 } elseif (stristr($field_flags, 'BINARY') && $meta->type == 'string') {
1333 if ($_SESSION['userconf']['display_binary'] || (isset($GLOBALS['is_analyse']) && $GLOBALS['is_analyse'])) {
1334 // user asked to see the real contents of BINARY
1335 // fields, or we detected a PROCEDURE ANALYSE in
1336 // the query (results are reported as being
1337 // binary strings)
1338 $row[$i] = PMA_replace_binary_contents($row[$i]);
1339 } else {
1340 // we show the BINARY message and field's size
1341 // (or maybe use a transformation)
1342 $row[$i] = PMA_handle_non_printable_contents('BINARY', $row[$i], $transform_function, $transform_options, $default_function, $meta);
1346 // garvin: transform functions may enable no-wrapping:
1347 $function_nowrap = $transform_function . '_nowrap';
1348 $bool_nowrap = (($default_function != $transform_function && function_exists($function_nowrap)) ? $function_nowrap($transform_options) : false);
1350 // loic1: do not wrap if date field type
1351 $nowrap = ((preg_match('@DATE|TIME@i', $meta->type) || $bool_nowrap) ? ' nowrap' : '');
1352 $where_comparison = ' = \'' . PMA_sqlAddslashes($row[$i]) . '\'';
1353 $vertical_display['data'][$row_no][$i] = '<td ' . PMA_prepare_row_data($mouse_events, $class, $condition_field, $analyzed_sql, $meta, $map, $row[$i], $transform_function, $default_function, $nowrap, $where_comparison, $transform_options);
1355 } else {
1356 $vertical_display['data'][$row_no][$i] = ' <td' . $mouse_events . ' class="' . $class . ($condition_field ? ' condition' : '') . '">&nbsp;</td>' . "\n";
1360 // lem9: output stored cell
1361 if ($_SESSION['userconf']['disp_direction'] == 'horizontal'
1362 || $_SESSION['userconf']['disp_direction'] == 'horizontalflipped') {
1363 echo $vertical_display['data'][$row_no][$i];
1366 if (isset($vertical_display['rowdata'][$i][$row_no])) {
1367 $vertical_display['rowdata'][$i][$row_no] .= $vertical_display['data'][$row_no][$i];
1368 } else {
1369 $vertical_display['rowdata'][$i][$row_no] = $vertical_display['data'][$row_no][$i];
1371 } // end for (2)
1373 // 3. Displays the modify/delete links on the right if required
1374 if ($GLOBALS['cfg']['ModifyDeleteAtRight']
1375 && ($_SESSION['userconf']['disp_direction'] == 'horizontal'
1376 || $_SESSION['userconf']['disp_direction'] == 'horizontalflipped')) {
1377 $doWriteModifyAt = 'right';
1378 require './libraries/display_tbl_links.lib.php';
1379 } // end if (3)
1381 if ($_SESSION['userconf']['disp_direction'] == 'horizontal'
1382 || $_SESSION['userconf']['disp_direction'] == 'horizontalflipped') {
1384 </tr>
1385 <?php
1386 } // end if
1388 // 4. Gather links of del_urls and edit_urls in an array for later
1389 // output
1390 if (!isset($vertical_display['edit'][$row_no])) {
1391 $vertical_display['edit'][$row_no] = '';
1392 $vertical_display['delete'][$row_no] = '';
1393 $vertical_display['row_delete'][$row_no] = '';
1396 $column_style_vertical = '';
1397 if ($GLOBALS['cfg']['BrowsePointerEnable'] == true) {
1398 $column_style_vertical .= ' onmouseover="setVerticalPointer(this, ' . $row_no . ', \'over\', \'odd\', \'even\', \'hover\', \'marked\');"'
1399 . ' onmouseout="setVerticalPointer(this, ' . $row_no . ', \'out\', \'odd\', \'even\', \'hover\', \'marked\');"';
1401 $column_marker_vertical = '';
1402 if ($GLOBALS['cfg']['BrowseMarkerEnable'] == true) {
1403 $column_marker_vertical .= 'setVerticalPointer(this, ' . $row_no . ', \'click\', \'odd\', \'even\', \'hover\', \'marked\');';
1406 if (!empty($del_url) && $is_display['del_lnk'] != 'kp') {
1407 $vertical_display['row_delete'][$row_no] .= ' <td align="center" class="' . $class . '" ' . $column_style_vertical . '>' . "\n"
1408 . ' <input type="checkbox" id="id_rows_to_delete' . $row_no . '[%_PMA_CHECKBOX_DIR_%]" name="rows_to_delete[' . $unique_condition_html . ']"'
1409 . ' onclick="' . $column_marker_vertical . 'copyCheckboxesRange(\'rowsDeleteForm\', \'id_rows_to_delete' . $row_no . '\',\'[%_PMA_CHECKBOX_DIR_%]\');"'
1410 . ' value="' . htmlspecialchars($del_query) . '" ' . (isset($GLOBALS['checkall']) ? 'checked="checked"' : '') . ' />' . "\n"
1411 . ' </td>' . "\n";
1412 } else {
1413 unset($vertical_display['row_delete'][$row_no]);
1416 if (isset($edit_url)) {
1417 $vertical_display['edit'][$row_no] .= ' <td align="center" class="' . $class . '" ' . $column_style_vertical . '>' . "\n"
1418 . PMA_linkOrButton($edit_url, $edit_str, array(), false)
1419 . $bookmark_go
1420 . ' </td>' . "\n";
1421 } else {
1422 unset($vertical_display['edit'][$row_no]);
1425 if (isset($del_url)) {
1426 $vertical_display['delete'][$row_no] .= ' <td align="center" class="' . $class . '" ' . $column_style_vertical . '>' . "\n"
1427 . PMA_linkOrButton($del_url, $del_str, (isset($js_conf) ? $js_conf : ''), false)
1428 . ' </td>' . "\n";
1429 } else {
1430 unset($vertical_display['delete'][$row_no]);
1433 echo (($_SESSION['userconf']['disp_direction'] == 'horizontal' || $_SESSION['userconf']['disp_direction'] == 'horizontalflipped') ? "\n" : '');
1434 $row_no++;
1435 } // end while
1437 return true;
1438 } // end of the 'PMA_displayTableBody()' function
1442 * Do display the result table with the vertical direction mode.
1443 * Credits for this feature goes to Garvin Hicking <hicking@faktor-e.de>.
1445 * @return boolean always true
1447 * @uses $_SESSION['userconf']['repeat_cells']
1448 * @global array $vertical_display the information to display
1450 * @access private
1452 * @see PMA_displayTable()
1454 function PMA_displayVerticalTable()
1456 global $vertical_display;
1458 // Displays "multi row delete" link at top if required
1459 if ($GLOBALS['cfg']['ModifyDeleteAtLeft'] && is_array($vertical_display['row_delete']) && (count($vertical_display['row_delete']) > 0 || !empty($vertical_display['textbtn']))) {
1460 echo '<tr>' . "\n";
1461 echo $vertical_display['textbtn'];
1462 $foo_counter = 0;
1463 foreach ($vertical_display['row_delete'] as $val) {
1464 if (($foo_counter != 0) && ($_SESSION['userconf']['repeat_cells'] != 0) && !($foo_counter % $_SESSION['userconf']['repeat_cells'])) {
1465 echo '<th></th>' . "\n";
1468 echo str_replace('[%_PMA_CHECKBOX_DIR_%]', '', $val);
1469 $foo_counter++;
1470 } // end while
1471 echo '</tr>' . "\n";
1472 } // end if
1474 // Displays "edit" link at top if required
1475 if ($GLOBALS['cfg']['ModifyDeleteAtLeft'] && is_array($vertical_display['edit']) && (count($vertical_display['edit']) > 0 || !empty($vertical_display['textbtn']))) {
1476 echo '<tr>' . "\n";
1477 if (!is_array($vertical_display['row_delete'])) {
1478 echo $vertical_display['textbtn'];
1480 $foo_counter = 0;
1481 foreach ($vertical_display['edit'] as $val) {
1482 if (($foo_counter != 0) && ($_SESSION['userconf']['repeat_cells'] != 0) && !($foo_counter % $_SESSION['userconf']['repeat_cells'])) {
1483 echo ' <th></th>' . "\n";
1486 echo $val;
1487 $foo_counter++;
1488 } // end while
1489 echo '</tr>' . "\n";
1490 } // end if
1492 // Displays "delete" link at top if required
1493 if ($GLOBALS['cfg']['ModifyDeleteAtLeft'] && is_array($vertical_display['delete']) && (count($vertical_display['delete']) > 0 || !empty($vertical_display['textbtn']))) {
1494 echo '<tr>' . "\n";
1495 if (!is_array($vertical_display['edit']) && !is_array($vertical_display['row_delete'])) {
1496 echo $vertical_display['textbtn'];
1498 $foo_counter = 0;
1499 foreach ($vertical_display['delete'] as $val) {
1500 if (($foo_counter != 0) && ($_SESSION['userconf']['repeat_cells'] != 0) && !($foo_counter % $_SESSION['userconf']['repeat_cells'])) {
1501 echo '<th></th>' . "\n";
1504 echo $val;
1505 $foo_counter++;
1506 } // end while
1507 echo '</tr>' . "\n";
1508 } // end if
1510 // Displays data
1511 foreach ($vertical_display['desc'] AS $key => $val) {
1513 echo '<tr>' . "\n";
1514 echo $val;
1516 $foo_counter = 0;
1517 foreach ($vertical_display['rowdata'][$key] as $subval) {
1518 if (($foo_counter != 0) && ($_SESSION['userconf']['repeat_cells'] != 0) and !($foo_counter % $_SESSION['userconf']['repeat_cells'])) {
1519 echo $val;
1522 echo $subval;
1523 $foo_counter++;
1524 } // end while
1526 echo '</tr>' . "\n";
1527 } // end while
1529 // Displays "multi row delete" link at bottom if required
1530 if ($GLOBALS['cfg']['ModifyDeleteAtRight'] && is_array($vertical_display['row_delete']) && (count($vertical_display['row_delete']) > 0 || !empty($vertical_display['textbtn']))) {
1531 echo '<tr>' . "\n";
1532 echo $vertical_display['textbtn'];
1533 $foo_counter = 0;
1534 foreach ($vertical_display['row_delete'] as $val) {
1535 if (($foo_counter != 0) && ($_SESSION['userconf']['repeat_cells'] != 0) && !($foo_counter % $_SESSION['userconf']['repeat_cells'])) {
1536 echo '<th></th>' . "\n";
1539 echo str_replace('[%_PMA_CHECKBOX_DIR_%]', 'r', $val);
1540 $foo_counter++;
1541 } // end while
1542 echo '</tr>' . "\n";
1543 } // end if
1545 // Displays "edit" link at bottom if required
1546 if ($GLOBALS['cfg']['ModifyDeleteAtRight'] && is_array($vertical_display['edit']) && (count($vertical_display['edit']) > 0 || !empty($vertical_display['textbtn']))) {
1547 echo '<tr>' . "\n";
1548 if (!is_array($vertical_display['row_delete'])) {
1549 echo $vertical_display['textbtn'];
1551 $foo_counter = 0;
1552 foreach ($vertical_display['edit'] as $val) {
1553 if (($foo_counter != 0) && ($_SESSION['userconf']['repeat_cells'] != 0) && !($foo_counter % $_SESSION['userconf']['repeat_cells'])) {
1554 echo '<th></th>' . "\n";
1557 echo $val;
1558 $foo_counter++;
1559 } // end while
1560 echo '</tr>' . "\n";
1561 } // end if
1563 // Displays "delete" link at bottom if required
1564 if ($GLOBALS['cfg']['ModifyDeleteAtRight'] && is_array($vertical_display['delete']) && (count($vertical_display['delete']) > 0 || !empty($vertical_display['textbtn']))) {
1565 echo '<tr>' . "\n";
1566 if (!is_array($vertical_display['edit']) && !is_array($vertical_display['row_delete'])) {
1567 echo $vertical_display['textbtn'];
1569 $foo_counter = 0;
1570 foreach ($vertical_display['delete'] as $val) {
1571 if (($foo_counter != 0) && ($_SESSION['userconf']['repeat_cells'] != 0) && !($foo_counter % $_SESSION['userconf']['repeat_cells'])) {
1572 echo '<th></th>' . "\n";
1575 echo $val;
1576 $foo_counter++;
1577 } // end while
1578 echo '</tr>' . "\n";
1581 return true;
1582 } // end of the 'PMA_displayVerticalTable' function
1586 * @uses $_SESSION['userconf']['disp_direction']
1587 * @uses $_REQUEST['disp_direction']
1588 * @uses $GLOBALS['cfg']['DefaultDisplay']
1589 * @uses $_SESSION['userconf']['repeat_cells']
1590 * @uses $_REQUEST['repeat_cells']
1591 * @uses $GLOBALS['cfg']['RepeatCells']
1592 * @uses $_SESSION['userconf']['max_rows']
1593 * @uses $_REQUEST['session_max_rows']
1594 * @uses $GLOBALS['cfg']['MaxRows']
1595 * @uses $_SESSION['userconf']['pos']
1596 * @uses $_REQUEST['pos']
1597 * @uses $_SESSION['userconf']['display_text']
1598 * @uses $_REQUEST['display_text']
1599 * @uses $_SESSION['userconf']['relational_display']
1600 * @uses $_REQUEST['relational_display']
1601 * @uses $_SESSION['userconf']['display_binary']
1602 * @uses $_REQUEST['display_binary']
1603 * @uses $_SESSION['userconf']['display_blob']
1604 * @uses $_REQUEST['display_blob']
1605 * @uses PMA_isValid()
1606 * @uses $GLOBALS['sql_query']
1607 * @todo make maximum remembered queries configurable
1608 * @todo move/split into SQL class!?
1609 * @todo currently this is called twice unnecessary
1610 * @todo ignore LIMIT and ORDER in query!?
1612 function PMA_displayTable_checkConfigParams()
1614 $sql_key = md5($GLOBALS['sql_query']);
1616 $_SESSION['userconf']['query'][$sql_key]['sql'] = $GLOBALS['sql_query'];
1618 if (PMA_isValid($_REQUEST['disp_direction'], array('horizontal', 'vertical', 'horizontalflipped'))) {
1619 $_SESSION['userconf']['query'][$sql_key]['disp_direction'] = $_REQUEST['disp_direction'];
1620 unset($_REQUEST['disp_direction']);
1621 } elseif (empty($_SESSION['userconf']['query'][$sql_key]['disp_direction'])) {
1622 $_SESSION['userconf']['query'][$sql_key]['disp_direction'] = $GLOBALS['cfg']['DefaultDisplay'];
1625 if (PMA_isValid($_REQUEST['repeat_cells'], 'numeric')) {
1626 $_SESSION['userconf']['query'][$sql_key]['repeat_cells'] = $_REQUEST['repeat_cells'];
1627 unset($_REQUEST['repeat_cells']);
1628 } elseif (empty($_SESSION['userconf']['query'][$sql_key]['repeat_cells'])) {
1629 $_SESSION['userconf']['query'][$sql_key]['repeat_cells'] = $GLOBALS['cfg']['RepeatCells'];
1632 if (PMA_isValid($_REQUEST['session_max_rows'], 'numeric') || $_REQUEST['session_max_rows'] == 'all') {
1633 $_SESSION['userconf']['query'][$sql_key]['max_rows'] = $_REQUEST['session_max_rows'];
1634 unset($_REQUEST['session_max_rows']);
1635 } elseif (empty($_SESSION['userconf']['query'][$sql_key]['max_rows'])) {
1636 $_SESSION['userconf']['query'][$sql_key]['max_rows'] = $GLOBALS['cfg']['MaxRows'];
1639 if (PMA_isValid($_REQUEST['pos'], 'numeric')) {
1640 $_SESSION['userconf']['query'][$sql_key]['pos'] = $_REQUEST['pos'];
1641 unset($_REQUEST['pos']);
1642 } elseif (empty($_SESSION['userconf']['query'][$sql_key]['pos'])) {
1643 $_SESSION['userconf']['query'][$sql_key]['pos'] = 0;
1646 if (PMA_isValid($_REQUEST['display_text'], array('P', 'F'))) {
1647 $_SESSION['userconf']['query'][$sql_key]['display_text'] = $_REQUEST['display_text'];
1648 unset($_REQUEST['display_text']);
1649 } elseif (empty($_SESSION['userconf']['query'][$sql_key]['display_text'])) {
1650 $_SESSION['userconf']['query'][$sql_key]['display_text'] = 'P';
1653 if (PMA_isValid($_REQUEST['relational_display'], array('K', 'D'))) {
1654 $_SESSION['userconf']['query'][$sql_key]['relational_display'] = $_REQUEST['relational_display'];
1655 unset($_REQUEST['relational_display']);
1656 } elseif (empty($_SESSION['userconf']['query'][$sql_key]['relational_display'])) {
1657 $_SESSION['userconf']['query'][$sql_key]['relational_display'] = 'K';
1660 if (isset($_REQUEST['display_binary'])) {
1661 $_SESSION['userconf']['query'][$sql_key]['display_binary'] = true;
1662 unset($_REQUEST['display_binary']);
1663 } elseif (isset($_REQUEST['display_options_form'])) {
1664 // we know that the checkbox was unchecked
1665 unset($_SESSION['userconf']['query'][$sql_key]['display_binary']);
1666 } else {
1667 // selected by default because some operations like OPTIMIZE TABLE
1668 // and all queries involving functions return "binary" contents,
1669 // according to low-level field flags
1670 $_SESSION['userconf']['query'][$sql_key]['display_binary'] = true;
1673 if (isset($_REQUEST['display_blob'])) {
1674 $_SESSION['userconf']['query'][$sql_key]['display_blob'] = true;
1675 unset($_REQUEST['display_blob']);
1676 } elseif (isset($_REQUEST['display_options_form'])) {
1677 // we know that the checkbox was unchecked
1678 unset($_SESSION['userconf']['query'][$sql_key]['display_blob']);
1681 if (isset($_REQUEST['hide_transformation'])) {
1682 $_SESSION['userconf']['query'][$sql_key]['hide_transformation'] = true;
1683 unset($_REQUEST['hide_transformation']);
1684 } elseif (isset($_REQUEST['display_options_form'])) {
1685 // we know that the checkbox was unchecked
1686 unset($_SESSION['userconf']['query'][$sql_key]['hide_transformation']);
1689 // move current query to the last position, to be removed last
1690 // so only least executed query will be removed if maximum remembered queries
1691 // limit is reached
1692 $tmp = $_SESSION['userconf']['query'][$sql_key];
1693 unset($_SESSION['userconf']['query'][$sql_key]);
1694 $_SESSION['userconf']['query'][$sql_key] = $tmp;
1696 // do not exceed a maximum number of queries to remember
1697 if (count($_SESSION['userconf']['query']) > 10) {
1698 array_shift($_SESSION['userconf']['query']);
1699 //echo 'deleting one element ...';
1702 // populate query configuration
1703 $_SESSION['userconf']['display_text'] = $_SESSION['userconf']['query'][$sql_key]['display_text'];
1704 $_SESSION['userconf']['relational_display'] = $_SESSION['userconf']['query'][$sql_key]['relational_display'];
1705 $_SESSION['userconf']['display_binary'] = isset($_SESSION['userconf']['query'][$sql_key]['display_binary']) ? true : false;
1706 $_SESSION['userconf']['display_blob'] = isset($_SESSION['userconf']['query'][$sql_key]['display_blob']) ? true : false;
1707 $_SESSION['userconf']['hide_transformation'] = isset($_SESSION['userconf']['query'][$sql_key]['hide_transformation']) ? true : false;
1708 $_SESSION['userconf']['pos'] = $_SESSION['userconf']['query'][$sql_key]['pos'];
1709 $_SESSION['userconf']['max_rows'] = $_SESSION['userconf']['query'][$sql_key]['max_rows'];
1710 $_SESSION['userconf']['repeat_cells'] = $_SESSION['userconf']['query'][$sql_key]['repeat_cells'];
1711 $_SESSION['userconf']['disp_direction'] = $_SESSION['userconf']['query'][$sql_key]['disp_direction'];
1714 * debugging
1715 echo '<pre>';
1716 var_dump($_SESSION['userconf']);
1717 echo '</pre>';
1722 * Displays a table of results returned by a SQL query.
1723 * This function is called by the "sql.php" script.
1725 * @param integer the link id associated to the query which results have
1726 * to be displayed
1727 * @param array the display mode
1728 * @param array the analyzed query
1730 * @uses $_SESSION['userconf']['pos']
1731 * @global string $db the database name
1732 * @global string $table the table name
1733 * @global string $goto the URL to go back in case of errors
1734 * @global string $sql_query the current SQL query
1735 * @global integer $num_rows the total number of rows returned by the
1736 * SQL query
1737 * @global integer $unlim_num_rows the total number of rows returned by the
1738 * SQL query without any programmatically
1739 * appended "LIMIT" clause
1740 * @global array $fields_meta the list of fields properties
1741 * @global integer $fields_cnt the total number of fields returned by
1742 * the SQL query
1743 * @global array $vertical_display informations used with vertical display
1744 * mode
1745 * @global array $highlight_columns column names to highlight
1746 * @global array $cfgRelation the relation settings
1748 * @access private
1750 * @see PMA_showMessage(), PMA_setDisplayMode(),
1751 * PMA_displayTableNavigation(), PMA_displayTableHeaders(),
1752 * PMA_displayTableBody(), PMA_displayResultsOperations()
1754 function PMA_displayTable(&$dt_result, &$the_disp_mode, $analyzed_sql)
1756 global $db, $table, $goto;
1757 global $sql_query, $num_rows, $unlim_num_rows, $fields_meta, $fields_cnt;
1758 global $vertical_display, $highlight_columns;
1759 global $cfgRelation;
1760 global $showtable;
1762 // why was this called here? (already called from sql.php)
1763 //PMA_displayTable_checkConfigParams();
1766 * @todo move this to a central place
1767 * @todo for other future table types
1769 $is_innodb = (isset($showtable['Type']) && $showtable['Type'] == 'InnoDB');
1771 if ($is_innodb
1772 && ! isset($analyzed_sql[0]['queryflags']['union'])
1773 && ! isset($analyzed_sql[0]['table_ref'][1]['table_name'])
1774 && (empty($analyzed_sql[0]['where_clause'])
1775 || $analyzed_sql[0]['where_clause'] == '1 ')) {
1776 // "j u s t b r o w s i n g"
1777 $pre_count = '~';
1778 $after_count = PMA_showHint(PMA_sanitize($GLOBALS['strApproximateCount']), true);
1779 } else {
1780 $pre_count = '';
1781 $after_count = '';
1784 // 1. ----- Prepares the work -----
1786 // 1.1 Gets the informations about which functionalities should be
1787 // displayed
1788 $total = '';
1789 $is_display = PMA_setDisplayMode($the_disp_mode, $total);
1791 // 1.2 Defines offsets for the next and previous pages
1792 if ($is_display['nav_bar'] == '1') {
1793 if ($_SESSION['userconf']['max_rows'] == 'all') {
1794 $pos_next = 0;
1795 $pos_prev = 0;
1796 } else {
1797 $pos_next = $_SESSION['userconf']['pos'] + $_SESSION['userconf']['max_rows'];
1798 $pos_prev = $_SESSION['userconf']['pos'] - $_SESSION['userconf']['max_rows'];
1799 if ($pos_prev < 0) {
1800 $pos_prev = 0;
1803 } // end if
1805 // 1.3 Find the sort expression
1807 // we need $sort_expression and $sort_expression_nodirection
1808 // even if there are many table references
1809 if (! empty($analyzed_sql[0]['order_by_clause'])) {
1810 $sort_expression = trim(str_replace(' ', ' ', $analyzed_sql[0]['order_by_clause']));
1812 * Get rid of ASC|DESC
1814 preg_match('@(.*)([[:space:]]*(ASC|DESC))@si', $sort_expression, $matches);
1815 $sort_expression_nodirection = isset($matches[1]) ? trim($matches[1]) : $sort_expression;
1816 $sort_direction = isset($matches[2]) ? trim($matches[2]) : '';
1817 unset($matches);
1818 } else {
1819 $sort_expression = $sort_expression_nodirection = $sort_direction = '';
1822 // 1.4 Prepares display of first and last value of the sorted column
1824 if (! empty($sort_expression_nodirection)) {
1825 list($sort_table, $sort_column) = explode('.', $sort_expression_nodirection);
1826 $sort_table = PMA_unQuote($sort_table);
1827 $sort_column = PMA_unQuote($sort_column);
1828 // find the sorted column index in row result
1829 // (this might be a multi-table query)
1830 $sorted_column_index = false;
1831 foreach($fields_meta as $key => $meta) {
1832 if ($meta->table == $sort_table && $meta->name == $sort_column) {
1833 $sorted_column_index = $key;
1834 break;
1837 if ($sorted_column_index !== false) {
1838 // fetch first row of the result set
1839 $row = PMA_DBI_fetch_row($dt_result);
1840 $column_for_first_row = $row[$sorted_column_index];
1841 // fetch last row of the result set
1842 PMA_DBI_data_seek($dt_result, $num_rows - 1);
1843 $row = PMA_DBI_fetch_row($dt_result);
1844 $column_for_last_row = $row[$sorted_column_index];
1845 // reset to first row for the loop in PMA_displayTableBody()
1846 PMA_DBI_data_seek($dt_result, 0);
1847 // we could also use here $sort_expression_nodirection
1848 $sorted_column_message = ' [' . htmlspecialchars($sort_column) . ': <strong>' . htmlspecialchars($column_for_first_row) . ' - ' . htmlspecialchars($column_for_last_row) . '</strong>]';
1849 unset($row, $column_for_first_row, $column_for_last_row);
1851 unset($sorted_column_index, $sort_table, $sort_column);
1854 // 2. ----- Displays the top of the page -----
1856 // 2.1 Displays a messages with position informations
1857 if ($is_display['nav_bar'] == '1' && isset($pos_next)) {
1858 if (isset($unlim_num_rows) && $unlim_num_rows != $total) {
1859 $selectstring = ', ' . $unlim_num_rows . ' ' . $GLOBALS['strSelectNumRows'];
1860 } else {
1861 $selectstring = '';
1863 $last_shown_rec = ($_SESSION['userconf']['max_rows'] == 'all' || $pos_next > $total)
1864 ? $total - 1
1865 : $pos_next - 1;
1867 if (PMA_Table::isView($db, $table)
1868 && $total == $GLOBALS['cfg']['MaxExactCountViews']) {
1869 $message = PMA_Message::notice('strViewHasAtLeast');
1870 $message->addParam('[a@./Documentation.html#cfg_MaxExactCount@_blank]');
1871 $message->addParam('[/a]');
1872 $message_view_warning = PMA_showHint($message);
1873 } else {
1874 $message_view_warning = false;
1877 $message = PMA_Message::success('strShowingRecords');
1878 $message->addMessage($_SESSION['userconf']['pos']);
1879 if ($message_view_warning) {
1880 $message->addMessage('...', ' - ');
1881 $message->addMessage($message_view_warning);
1882 $message->addMessage('(');
1883 } else {
1884 $message->addMessage($last_shown_rec, ' - ');
1885 $message->addMessage($pre_count . PMA_formatNumber($total, 0) . $after_count, ' (');
1886 $message->addString('strTotal');
1887 $message->addMessage($selectstring, '');
1888 $message->addMessage(', ', '');
1891 $messagge_qt = PMA_Message::notice('strQueryTime');
1892 $messagge_qt->addParam($GLOBALS['querytime']);
1894 $message->addMessage($messagge_qt, '');
1895 $message->addMessage(')', '');
1897 $message->addMessage(isset($sorted_column_message) ? $sorted_column_message : '', '');
1899 PMA_showMessage($message, $sql_query, 'success');
1901 } elseif (!isset($GLOBALS['printview']) || $GLOBALS['printview'] != '1') {
1902 PMA_showMessage($GLOBALS['strSuccess'], $sql_query, 'success');
1905 // 2.3 Displays the navigation bars
1906 if (! strlen($table)) {
1907 if (isset($analyzed_sql[0]['query_type'])
1908 && $analyzed_sql[0]['query_type'] == 'SELECT') {
1909 // table does not always contain a real table name,
1910 // for example in MySQL 5.0.x, the query SHOW STATUS
1911 // returns STATUS as a table name
1912 $table = $fields_meta[0]->table;
1913 } else {
1914 $table = '';
1918 if ($is_display['nav_bar'] == '1') {
1919 PMA_displayTableNavigation($pos_next, $pos_prev, $sql_query);
1920 echo "\n";
1921 } elseif (!isset($GLOBALS['printview']) || $GLOBALS['printview'] != '1') {
1922 echo "\n" . '<br /><br />' . "\n";
1925 // 2b ----- Get field references from Database -----
1926 // (see the 'relation' configuration variable)
1927 // loic1, 2002-03-02: extended to php3
1929 // initialize map
1930 $map = array();
1932 // find tables
1933 $target=array();
1934 if (isset($analyzed_sql[0]['table_ref']) && is_array($analyzed_sql[0]['table_ref'])) {
1935 foreach ($analyzed_sql[0]['table_ref'] AS $table_ref_position => $table_ref) {
1936 $target[] = $analyzed_sql[0]['table_ref'][$table_ref_position]['table_true_name'];
1939 $tabs = '(\'' . join('\',\'', $target) . '\')';
1941 if ($cfgRelation['displaywork']) {
1942 if (! strlen($table)) {
1943 $exist_rel = false;
1944 } else {
1945 $exist_rel = PMA_getForeigners($db, $table, '', 'both');
1946 if ($exist_rel) {
1947 foreach ($exist_rel AS $master_field => $rel) {
1948 $display_field = PMA_getDisplayField($rel['foreign_db'], $rel['foreign_table']);
1949 $map[$master_field] = array($rel['foreign_table'],
1950 $rel['foreign_field'],
1951 $display_field,
1952 $rel['foreign_db']);
1953 } // end while
1954 } // end if
1955 } // end if
1956 } // end if
1957 // end 2b
1959 // 3. ----- Displays the results table -----
1960 PMA_displayTableHeaders($is_display, $fields_meta, $fields_cnt, $analyzed_sql, $sort_expression, $sort_expression_nodirection, $sort_direction);
1961 $url_query = '';
1962 echo '<tbody>' . "\n";
1963 PMA_displayTableBody($dt_result, $is_display, $map, $analyzed_sql);
1964 // vertical output case
1965 if ($_SESSION['userconf']['disp_direction'] == 'vertical') {
1966 PMA_displayVerticalTable();
1967 } // end if
1968 unset($vertical_display);
1969 echo '</tbody>' . "\n";
1971 </table>
1973 <?php
1974 // 4. ----- Displays the link for multi-fields delete
1976 if ($is_display['del_lnk'] == 'dr' && $is_display['del_lnk'] != 'kp') {
1978 $delete_text = $is_display['del_lnk'] == 'dr' ? $GLOBALS['strDelete'] : $GLOBALS['strKill'];
1980 $_url_params = array(
1981 'db' => $db,
1982 'table' => $table,
1983 'sql_query' => $sql_query,
1984 'goto' => $goto,
1986 $uncheckall_url = 'sql.php' . PMA_generate_common_url($_url_params);
1988 $_url_params['checkall'] = '1';
1989 $checkall_url = 'sql.php' . PMA_generate_common_url($_url_params);
1991 if ($_SESSION['userconf']['disp_direction'] == 'vertical') {
1992 $checkall_params['onclick'] = 'if (setCheckboxes(\'rowsDeleteForm\', true)) return false;';
1993 $uncheckall_params['onclick'] = 'if (setCheckboxes(\'rowsDeleteForm\', false)) return false;';
1994 } else {
1995 $checkall_params['onclick'] = 'if (markAllRows(\'rowsDeleteForm\')) return false;';
1996 $uncheckall_params['onclick'] = 'if (unMarkAllRows(\'rowsDeleteForm\')) return false;';
1998 $checkall_link = PMA_linkOrButton($checkall_url, $GLOBALS['strCheckAll'], $checkall_params, false);
1999 $uncheckall_link = PMA_linkOrButton($uncheckall_url, $GLOBALS['strUncheckAll'], $uncheckall_params, false);
2000 if ($_SESSION['userconf']['disp_direction'] != 'vertical') {
2001 echo '<img class="selectallarrow" width="38" height="22"'
2002 .' src="' . $GLOBALS['pmaThemeImage'] . 'arrow_' . $GLOBALS['text_dir'] . '.png' . '"'
2003 .' alt="' . $GLOBALS['strWithChecked'] . '" />';
2005 echo $checkall_link . "\n"
2006 .' / ' . "\n"
2007 .$uncheckall_link . "\n"
2008 .'<i>' . $GLOBALS['strWithChecked'] . '</i>' . "\n";
2010 PMA_buttonOrImage('submit_mult', 'mult_submit',
2011 'submit_mult_change', $GLOBALS['strChange'], 'b_edit.png');
2012 PMA_buttonOrImage('submit_mult', 'mult_submit',
2013 'submit_mult_delete', $delete_text, 'b_drop.png');
2014 if ($analyzed_sql[0]['querytype'] == 'SELECT') {
2015 PMA_buttonOrImage('submit_mult', 'mult_submit',
2016 'submit_mult_export', $GLOBALS['strExport'],
2017 'b_tblexport.png');
2019 echo "\n";
2021 echo '<input type="hidden" name="sql_query"'
2022 .' value="' . htmlspecialchars($sql_query) . '" />' . "\n";
2023 echo '<input type="hidden" name="url_query"'
2024 .' value="' . $GLOBALS['url_query'] . '" />' . "\n";
2025 echo '</form>' . "\n";
2028 // 5. ----- Displays the navigation bar at the bottom if required -----
2030 if ($is_display['nav_bar'] == '1') {
2031 echo '<br />' . "\n";
2032 PMA_displayTableNavigation($pos_next, $pos_prev, $sql_query);
2033 } elseif (!isset($GLOBALS['printview']) || $GLOBALS['printview'] != '1') {
2034 echo "\n" . '<br /><br />' . "\n";
2037 // 6. ----- Displays "Query results operations"
2038 if (!isset($GLOBALS['printview']) || $GLOBALS['printview'] != '1') {
2039 PMA_displayResultsOperations($the_disp_mode, $analyzed_sql);
2041 } // end of the 'PMA_displayTable()' function
2043 function default_function($buffer) {
2044 $buffer = htmlspecialchars($buffer);
2045 $buffer = str_replace("\011", ' &nbsp;&nbsp;&nbsp;',
2046 str_replace(' ', ' &nbsp;', $buffer));
2047 $buffer = preg_replace("@((\015\012)|(\015)|(\012))@", '<br />', $buffer);
2049 return $buffer;
2053 * Displays operations that are available on results.
2055 * @param array the display mode
2056 * @param array the analyzed query
2058 * @uses $_SESSION['userconf']['pos']
2059 * @uses $_SESSION['userconf']['display_text']
2060 * @global string $db the database name
2061 * @global string $table the table name
2062 * @global string $sql_query the current SQL query
2063 * @global integer $unlim_num_rows the total number of rows returned by the
2064 * SQL query without any programmatically
2065 * appended "LIMIT" clause
2067 * @access private
2069 * @see PMA_showMessage(), PMA_setDisplayMode(),
2070 * PMA_displayTableNavigation(), PMA_displayTableHeaders(),
2071 * PMA_displayTableBody(), PMA_displayResultsOperations()
2073 function PMA_displayResultsOperations($the_disp_mode, $analyzed_sql) {
2074 global $db, $table, $sql_query, $unlim_num_rows;
2076 $header_shown = FALSE;
2077 $header = '<fieldset><legend>' . $GLOBALS['strQueryResultsOperations'] . '</legend>';
2079 if ($the_disp_mode[6] == '1' || $the_disp_mode[9] == '1') {
2080 // Displays "printable view" link if required
2081 if ($the_disp_mode[9] == '1') {
2083 if (!$header_shown) {
2084 echo $header;
2085 $header_shown = TRUE;
2088 $_url_params = array(
2089 'db' => $db,
2090 'table' => $table,
2091 'printview' => '1',
2092 'sql_query' => $sql_query,
2094 $url_query = PMA_generate_common_url($_url_params);
2096 echo PMA_linkOrButton(
2097 'sql.php' . $url_query,
2098 PMA_getIcon('b_print.png', $GLOBALS['strPrintView'], false, true),
2099 '', true, true, 'print_view') . "\n";
2101 if ($_SESSION['userconf']['display_text']) {
2102 $_url_params['display_text'] = 'F';
2103 echo PMA_linkOrButton(
2104 'sql.php' . PMA_generate_common_url($_url_params),
2105 PMA_getIcon('b_print.png', $GLOBALS['strPrintViewFull'], false, true),
2106 '', true, true, 'print_view') . "\n";
2107 unset($_url_params['display_text']);
2109 } // end displays "printable view"
2112 // Export link
2113 // (the url_query has extra parameters that won't be used to export)
2114 // (the single_table parameter is used in display_export.lib.php
2115 // to hide the SQL and the structure export dialogs)
2116 // If the parser found a PROCEDURE clause
2117 // (most probably PROCEDURE ANALYSE()) it makes no sense to
2118 // display the Export link).
2119 if (isset($analyzed_sql[0]) && $analyzed_sql[0]['querytype'] == 'SELECT' && !isset($printview) && ! isset($analyzed_sql[0]['queryflags']['procedure'])) {
2120 if (isset($analyzed_sql[0]['table_ref'][0]['table_true_name']) && !isset($analyzed_sql[0]['table_ref'][1]['table_true_name'])) {
2121 $_url_params['single_table'] = 'true';
2123 if (!$header_shown) {
2124 echo $header;
2125 $header_shown = TRUE;
2127 $_url_params['unlim_num_rows'] = $unlim_num_rows;
2130 * At this point we don't know the table name; this can happen
2131 * for example with a query like
2132 * SELECT bike_code FROM (SELECT bike_code FROM bikes) tmp
2133 * As a workaround we set in the table parameter the name of the
2134 * first table of this database, so that tbl_export.php and
2135 * the script it calls do not fail
2137 if (empty($_url_params['table'])) {
2138 $_url_params['table'] = PMA_DBI_fetch_value("SHOW TABLES");
2141 echo PMA_linkOrButton(
2142 'tbl_export.php' . PMA_generate_common_url($_url_params),
2143 PMA_getIcon('b_tblexport.png', $GLOBALS['strExport'], false, true),
2144 '', true, true, '') . "\n";
2147 // CREATE VIEW
2150 * @todo detect privileges to create a view
2151 * (but see 2006-01-19 note in display_create_table.lib.php,
2152 * I think we cannot detect db-specific privileges reliably)
2153 * Note: we don't display a Create view link if we found a PROCEDURE clause
2155 if (!$header_shown) {
2156 echo $header;
2157 $header_shown = TRUE;
2159 if (! isset($analyzed_sql[0]['queryflags']['procedure'])) {
2160 echo PMA_linkOrButton(
2161 'view_create.php' . $url_query,
2162 PMA_getIcon('b_views.png', 'CREATE VIEW', false, true),
2163 '', true, true, '') . "\n";
2165 if ($header_shown) {
2166 echo '</fieldset><br />';
2171 * Verifies what to do with non-printable contents (binary or BLOB)
2172 * in Browse mode.
2174 * @uses is_null()
2175 * @uses isset()
2176 * @uses strlen()
2177 * @uses PMA_formatByteDown()
2178 * @uses strpos()
2179 * @uses str_replace()
2180 * @param string $category BLOB|BINARY
2181 * @param string $content the binary content
2182 * @param string $transform_function
2183 * @param string $transform_options
2184 * @param string $default_function
2185 * @param object $meta the meta-information about this field
2186 * @return mixed string or float
2188 function PMA_handle_non_printable_contents($category, $content, $transform_function, $transform_options, $default_function, $meta) {
2189 $result = '[' . $category;
2190 if (is_null($content)) {
2191 $result .= ' - NULL';
2192 $size = 0;
2193 } elseif (isset($content)) {
2194 $size = strlen($content);
2195 $display_size = PMA_formatByteDown($size, 3, 1);
2196 $result .= ' - '. $display_size[0] . $display_size[1];
2198 $result .= ']';
2200 if (strpos($transform_function, 'octetstream')) {
2201 $result = $content;
2203 if ($size > 0) {
2204 if ($default_function != $transform_function) {
2205 $result = $transform_function($result, $transform_options, $meta);
2206 } else {
2207 $result = $default_function($result, array(), $meta);
2208 if (stristr($meta->type, 'BLOB') && $_SESSION['userconf']['display_blob']) {
2209 // in this case, restart from the original $content
2210 $result = PMA_replace_binary_contents($content);
2214 return($result);
2218 * Prepares the displayable content of a data cell in Browse mode,
2219 * taking into account foreign key description field and transformations
2221 * @uses is_array()
2222 * @uses PMA_backquote()
2223 * @uses PMA_DBI_try_query()
2224 * @uses PMA_DBI_num_rows()
2225 * @uses PMA_DBI_fetch_row()
2226 * @uses $GLOBALS['strLinkNotFound']
2227 * @uses PMA_DBI_free_result()
2228 * @uses $GLOBALS['printview']
2229 * @uses htmlspecialchars()
2230 * @uses PMA_generate_common_url()
2231 * @param string $mouse_events
2232 * @param string $class
2233 * @param string $condition_field
2234 * @param string $analyzed_sql
2235 * @param object $meta the meta-information about this field
2236 * @param string $map
2237 * @param string $data
2238 * @param string $transform_function
2239 * @param string $default_function
2240 * @param string $nowrap
2241 * @param string $where_comparison
2242 * @return string formatted data
2244 function PMA_prepare_row_data($mouse_events, $class, $condition_field, $analyzed_sql, $meta, $map, $data, $transform_function, $default_function, $nowrap, $where_comparison, $transform_options) {
2246 // continue the <td> tag started before calling this function:
2247 $result = $mouse_events . ' class="' . $class . ($condition_field ? ' condition' : '') . $nowrap . '">';
2249 if (isset($analyzed_sql[0]['select_expr']) && is_array($analyzed_sql[0]['select_expr'])) {
2250 foreach ($analyzed_sql[0]['select_expr'] AS $select_expr_position => $select_expr) {
2251 $alias = $analyzed_sql[0]['select_expr'][$select_expr_position]['alias'];
2252 if (isset($alias) && strlen($alias)) {
2253 $true_column = $analyzed_sql[0]['select_expr'][$select_expr_position]['column'];
2254 if ($alias == $meta->name) {
2255 // this change in the parameter does not matter
2256 // outside of the function
2257 $meta->name = $true_column;
2258 } // end if
2259 } // end if
2260 } // end foreach
2261 } // end if
2263 if (isset($map[$meta->name])) {
2264 // Field to display from the foreign table?
2265 if (isset($map[$meta->name][2]) && strlen($map[$meta->name][2])) {
2266 $dispsql = 'SELECT ' . PMA_backquote($map[$meta->name][2])
2267 . ' FROM ' . PMA_backquote($map[$meta->name][3])
2268 . '.' . PMA_backquote($map[$meta->name][0])
2269 . ' WHERE ' . PMA_backquote($map[$meta->name][1])
2270 . $where_comparison;
2271 $dispresult = PMA_DBI_try_query($dispsql, null, PMA_DBI_QUERY_STORE);
2272 if ($dispresult && PMA_DBI_num_rows($dispresult) > 0) {
2273 list($dispval) = PMA_DBI_fetch_row($dispresult, 0);
2274 } else {
2275 $dispval = $GLOBALS['strLinkNotFound'];
2277 @PMA_DBI_free_result($dispresult);
2278 } else {
2279 $dispval = '';
2280 } // end if... else...
2282 if (isset($GLOBALS['printview']) && $GLOBALS['printview'] == '1') {
2283 $result .= ($transform_function != $default_function ? $transform_function($data, $transform_options, $meta) : $transform_function($data, array(), $meta)) . ' <code>[-&gt;' . $dispval . ']</code>';
2284 } else {
2286 if ('K' == $_SESSION['userconf']['relational_display']) {
2287 // user chose "relational key" in the display options, so
2288 // the title contains the display field
2289 $title = (! empty($dispval))? ' title="' . htmlspecialchars($dispval) . '"' : '';
2290 } else {
2291 $title = ' title="' . htmlspecialchars($data) . '"';
2294 $_url_params = array(
2295 'db' => $map[$meta->name][3],
2296 'table' => $map[$meta->name][0],
2297 'pos' => '0',
2298 'sql_query' => 'SELECT * FROM '
2299 . PMA_backquote($map[$meta->name][3]) . '.' . PMA_backquote($map[$meta->name][0])
2300 . ' WHERE ' . PMA_backquote($map[$meta->name][1])
2301 . $where_comparison,
2303 $result .= '<a href="sql.php' . PMA_generate_common_url($_url_params)
2304 . '"' . $title . '>';
2306 if ($transform_function != $default_function) {
2307 // always apply a transformation on the real data,
2308 // not on the display field
2309 $result .= $transform_function($data, $transform_options, $meta);
2310 } else {
2311 if ('D' == $_SESSION['userconf']['relational_display']) {
2312 // user chose "relational display field" in the
2313 // display options, so show display field in the cell
2314 $result .= $transform_function($dispval, array(), $meta);
2315 } else {
2316 // otherwise display data in the cell
2317 $result .= $transform_function($data, array(), $meta);
2320 $result .= '</a>';
2322 } else {
2323 $result .= ($transform_function != $default_function ? $transform_function($data, $transform_options, $meta) : $transform_function($data, array(), $meta));
2325 $result .= '</td>' . "\n";
2327 return $result;