remove unneeded comments
[phpmyadmin/crack.git] / libraries / display_tbl.lib.php
blob3cb381a679c6111181bb1668afb333c33dc76fd5
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 */
9 /**
12 require_once './libraries/Table.class.php';
13 require_once './libraries/Index.class.php';
15 /**
16 * Defines the display mode to use for the results of a SQL query
18 * It uses a synthetic string that contains all the required informations.
19 * In this string:
20 * - the first two characters stand for the action to do while
21 * clicking on the "edit" link (e.g. 'ur' for update a row, 'nn' for no
22 * edit link...);
23 * - the next two characters stand for the action to do while
24 * clicking on the "delete" link (e.g. 'kp' for kill a process, 'nn' for
25 * no delete link...);
26 * - the next characters are boolean values (1/0) and respectively stand
27 * for sorting links, navigation bar, "insert a new row" link, the
28 * bookmark feature, the expand/collapse text/blob fields button and
29 * the "display printable view" option.
30 * Of course '0'/'1' means the feature won't/will be enabled.
32 * @param string the synthetic value for display_mode (see a few
33 * lines above for explanations)
34 * @param integer the total number of rows returned by the SQL query
35 * without any programmatically appended "LIMIT" clause
36 * (just a copy of $unlim_num_rows if it exists, else
37 * computed inside this function)
39 * @return array an array with explicit indexes for all the display
40 * elements
42 * @global string the database name
43 * @global string the table name
44 * @global integer the total number of rows returned by the SQL query
45 * without any programmatically appended "LIMIT" clause
46 * @global array the properties of the fields returned by the query
47 * @global string the URL to return to in case of error in a SQL
48 * statement
50 * @access private
52 * @see PMA_displayTable()
54 function PMA_setDisplayMode(&$the_disp_mode, &$the_total)
56 global $db, $table;
57 global $unlim_num_rows, $fields_meta;
58 global $err_url;
60 // 1. Initializes the $do_display array
61 $do_display = array();
62 $do_display['edit_lnk'] = $the_disp_mode[0] . $the_disp_mode[1];
63 $do_display['del_lnk'] = $the_disp_mode[2] . $the_disp_mode[3];
64 $do_display['sort_lnk'] = (string) $the_disp_mode[4];
65 $do_display['nav_bar'] = (string) $the_disp_mode[5];
66 $do_display['ins_row'] = (string) $the_disp_mode[6];
67 $do_display['bkm_form'] = (string) $the_disp_mode[7];
68 $do_display['text_btn'] = (string) $the_disp_mode[8];
69 $do_display['pview_lnk'] = (string) $the_disp_mode[9];
71 // 2. Display mode is not "false for all elements" -> updates the
72 // display mode
73 if ($the_disp_mode != 'nnnn000000') {
74 // 2.0 Print view -> set all elements to false!
75 if (isset($GLOBALS['printview']) && $GLOBALS['printview'] == '1') {
76 $do_display['edit_lnk'] = 'nn'; // no edit link
77 $do_display['del_lnk'] = 'nn'; // no delete link
78 $do_display['sort_lnk'] = (string) '0';
79 $do_display['nav_bar'] = (string) '0';
80 $do_display['ins_row'] = (string) '0';
81 $do_display['bkm_form'] = (string) '0';
82 $do_display['text_btn'] = (string) '0';
83 $do_display['pview_lnk'] = (string) '0';
85 // 2.1 Statement is a "SELECT COUNT", a
86 // "CHECK/ANALYZE/REPAIR/OPTIMIZE", an "EXPLAIN" one or
87 // contains a "PROC ANALYSE" part
88 elseif ($GLOBALS['is_count'] || $GLOBALS['is_analyse'] || $GLOBALS['is_maint'] || $GLOBALS['is_explain']) {
89 $do_display['edit_lnk'] = 'nn'; // no edit link
90 $do_display['del_lnk'] = 'nn'; // no delete link
91 $do_display['sort_lnk'] = (string) '0';
92 $do_display['nav_bar'] = (string) '0';
93 $do_display['ins_row'] = (string) '0';
94 $do_display['bkm_form'] = (string) '1';
95 if ($GLOBALS['is_maint']) {
96 $do_display['text_btn'] = (string) '1';
97 } else {
98 $do_display['text_btn'] = (string) '0';
100 $do_display['pview_lnk'] = (string) '1';
102 // 2.2 Statement is a "SHOW..."
103 elseif ($GLOBALS['is_show']) {
105 * 2.2.1
106 * @todo defines edit/delete links depending on show statement
108 $tmp = preg_match('@^SHOW[[:space:]]+(VARIABLES|(FULL[[:space:]]+)?PROCESSLIST|STATUS|TABLE|GRANTS|CREATE|LOGS|DATABASES|FIELDS)@i', $GLOBALS['sql_query'], $which);
109 if (isset($which[1]) && strpos(' ' . strtoupper($which[1]), 'PROCESSLIST') > 0) {
110 $do_display['edit_lnk'] = 'nn'; // no edit link
111 $do_display['del_lnk'] = 'kp'; // "kill process" type edit link
112 } else {
113 // Default case -> no links
114 $do_display['edit_lnk'] = 'nn'; // no edit link
115 $do_display['del_lnk'] = 'nn'; // no delete link
117 // 2.2.2 Other settings
118 $do_display['sort_lnk'] = (string) '0';
119 $do_display['nav_bar'] = (string) '0';
120 $do_display['ins_row'] = (string) '0';
121 $do_display['bkm_form'] = (string) '1';
122 $do_display['text_btn'] = (string) '1';
123 $do_display['pview_lnk'] = (string) '1';
125 // 2.3 Other statements (ie "SELECT" ones) -> updates
126 // $do_display['edit_lnk'], $do_display['del_lnk'] and
127 // $do_display['text_btn'] (keeps other default values)
128 else {
129 $prev_table = $fields_meta[0]->table;
130 $do_display['text_btn'] = (string) '1';
131 for ($i = 0; $i < $GLOBALS['fields_cnt']; $i++) {
132 $is_link = ($do_display['edit_lnk'] != 'nn'
133 || $do_display['del_lnk'] != 'nn'
134 || $do_display['sort_lnk'] != '0'
135 || $do_display['ins_row'] != '0');
136 // 2.3.2 Displays edit/delete/sort/insert links?
137 if ($is_link
138 && ($fields_meta[$i]->table == '' || $fields_meta[$i]->table != $prev_table)) {
139 $do_display['edit_lnk'] = 'nn'; // don't display links
140 $do_display['del_lnk'] = 'nn';
142 * @todo May be problematic with same fields names in two joined table.
144 // $do_display['sort_lnk'] = (string) '0';
145 $do_display['ins_row'] = (string) '0';
146 if ($do_display['text_btn'] == '1') {
147 break;
149 } // end if (2.3.2)
150 // 2.3.3 Always display print view link
151 $do_display['pview_lnk'] = (string) '1';
152 $prev_table = $fields_meta[$i]->table;
153 } // end for
154 } // end if..elseif...else (2.1 -> 2.3)
155 } // end if (2)
157 // 3. Gets the total number of rows if it is unknown
158 if (isset($unlim_num_rows) && $unlim_num_rows != '') {
159 $the_total = $unlim_num_rows;
160 } elseif (($do_display['nav_bar'] == '1' || $do_display['sort_lnk'] == '1')
161 && (strlen($db) && !empty($table))) {
162 $the_total = PMA_Table::countRecords($db, $table, true);
165 // 4. If navigation bar or sorting fields names URLs should be
166 // displayed but there is only one row, change these settings to
167 // false
168 if ($do_display['nav_bar'] == '1' || $do_display['sort_lnk'] == '1') {
170 // - Do not display sort links if less than 2 rows.
171 // - For a VIEW we (probably) did not count the number of rows
172 // so don't test this number here, it would remove the possibility
173 // of sorting VIEW results.
174 if (isset($unlim_num_rows) && $unlim_num_rows < 2 && ! PMA_Table::isView($db, $table)) {
175 // garvin: force display of navbar for vertical/horizontal display-choice.
176 // $do_display['nav_bar'] = (string) '0';
177 $do_display['sort_lnk'] = (string) '0';
179 } // end if (3)
181 // 5. Updates the synthetic var
182 $the_disp_mode = join('', $do_display);
184 return $do_display;
185 } // end of the 'PMA_setDisplayMode()' function
189 * Displays a navigation bar to browse among the results of a SQL query
191 * @uses $_SESSION['userconf']['disp_direction']
192 * @uses $_SESSION['userconf']['repeat_cells']
193 * @uses $_SESSION['userconf']['max_rows']
194 * @uses $_SESSION['userconf']['pos']
195 * @param integer the offset for the "next" page
196 * @param integer the offset for the "previous" page
197 * @param string the URL-encoded query
199 * @global string $db the database name
200 * @global string $table the table name
201 * @global string $goto the URL to go back in case of errors
202 * @global integer $num_rows the total number of rows returned by the
203 * SQL query
204 * @global integer $unlim_num_rows the total number of rows returned by the
205 * SQL any programmatically appended "LIMIT" clause
206 * @global boolean $is_innodb whether its InnoDB or not
207 * @global array $showtable table definitions
209 * @access private
211 * @see PMA_displayTable()
213 function PMA_displayTableNavigation($pos_next, $pos_prev, $sql_query)
215 global $db, $table, $goto;
216 global $num_rows, $unlim_num_rows;
217 global $is_innodb;
218 global $showtable;
220 // here, using htmlentities() would cause problems if the query
221 // contains accented characters
222 $html_sql_query = htmlspecialchars($sql_query);
225 * @todo move this to a central place
226 * @todo for other future table types
228 $is_innodb = (isset($showtable['Type']) && $showtable['Type'] == 'InnoDB');
232 <!-- Navigation bar -->
233 <table border="0" cellpadding="2" cellspacing="0">
234 <tr>
235 <?php
236 // Move to the beginning or to the previous page
237 if ($_SESSION['userconf']['pos'] && $_SESSION['userconf']['max_rows'] != 'all') {
238 // loic1: patch #474210 from Gosha Sakovich - part 1
239 if ($GLOBALS['cfg']['NavigationBarIconic']) {
240 $caption1 = '&lt;&lt;';
241 $caption2 = ' &lt; ';
242 $title1 = ' title="' . $GLOBALS['strPos1'] . '"';
243 $title2 = ' title="' . $GLOBALS['strPrevious'] . '"';
244 } else {
245 $caption1 = $GLOBALS['strPos1'] . ' &lt;&lt;';
246 $caption2 = $GLOBALS['strPrevious'] . ' &lt;';
247 $title1 = '';
248 $title2 = '';
249 } // end if... else...
251 <td>
252 <form action="sql.php" method="post">
253 <?php echo PMA_generate_common_hidden_inputs($db, $table); ?>
254 <input type="hidden" name="sql_query" value="<?php echo $html_sql_query; ?>" />
255 <input type="hidden" name="pos" value="0" />
256 <input type="hidden" name="goto" value="<?php echo $goto; ?>" />
257 <input type="submit" name="navig" value="<?php echo $caption1; ?>"<?php echo $title1; ?> />
258 </form>
259 </td>
260 <td>
261 <form action="sql.php" method="post">
262 <?php echo PMA_generate_common_hidden_inputs($db, $table); ?>
263 <input type="hidden" name="sql_query" value="<?php echo $html_sql_query; ?>" />
264 <input type="hidden" name="pos" value="<?php echo $pos_prev; ?>" />
265 <input type="hidden" name="goto" value="<?php echo $goto; ?>" />
266 <input type="submit" name="navig" value="<?php echo $caption2; ?>"<?php echo $title2; ?> />
267 </form>
268 </td>
269 <?php
270 } // end move back
272 <td>
273 &nbsp;&nbsp;&nbsp;
274 </td>
275 <td align="center">
276 <?php // if displaying a VIEW, $unlim_num_rows could be zero because
277 // of $cfg['MaxExactCountViews']; in this case, avoid passing
278 // the 5th parameter to checkFormElementInRange()
279 // (this means we can't validate the upper limit ?>
280 <form action="sql.php" method="post"
281 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 : ''; ?>))">
282 <?php echo PMA_generate_common_hidden_inputs($db, $table); ?>
283 <input type="hidden" name="sql_query" value="<?php echo $html_sql_query; ?>" />
284 <input type="hidden" name="goto" value="<?php echo $goto; ?>" />
285 <input type="submit" name="navig" value="<?php echo $GLOBALS['strShow']; ?> :" />
286 <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()" />
287 <?php echo $GLOBALS['strRowsFrom'] . "\n"; ?>
288 <input type="text" name="pos" size="6" value="<?php echo (($pos_next >= $unlim_num_rows) ? 0 : $pos_next); ?>" class="textfield" onfocus="this.select()" />
289 <br />
290 <?php
291 // Display mode (horizontal/vertical and repeat headers)
292 $param1 = ' <select name="disp_direction">' . "\n"
293 . ' <option value="horizontal"' . (($_SESSION['userconf']['disp_direction'] == 'horizontal') ? ' selected="selected"': '') . '>' . $GLOBALS['strRowsModeHorizontal'] . '</option>' . "\n"
294 . ' <option value="horizontalflipped"' . (($_SESSION['userconf']['disp_direction'] == 'horizontalflipped') ? ' selected="selected"': '') . '>' . $GLOBALS['strRowsModeFlippedHorizontal'] . '</option>' . "\n"
295 . ' <option value="vertical"' . (($_SESSION['userconf']['disp_direction'] == 'vertical') ? ' selected="selected"': '') . '>' . $GLOBALS['strRowsModeVertical'] . '</option>' . "\n"
296 . ' </select>' . "\n"
297 . ' ';
298 $param2 = ' <input type="text" size="3" name="repeat_cells" value="' . $_SESSION['userconf']['repeat_cells'] . '" class="textfield" />' . "\n"
299 . ' ';
300 echo ' ' . sprintf($GLOBALS['strRowsModeOptions'], "\n" . $param1, "\n" . $param2) . "\n";
302 </form>
303 </td>
304 <td>
305 &nbsp;&nbsp;&nbsp;
306 </td>
307 <?php
308 // Move to the next page or to the last one
309 if (($_SESSION['userconf']['pos'] + $_SESSION['userconf']['max_rows'] < $unlim_num_rows) && $num_rows >= $_SESSION['userconf']['max_rows']
310 && $_SESSION['userconf']['max_rows'] != 'all') {
311 // loic1: patch #474210 from Gosha Sakovich - part 2
312 if ($GLOBALS['cfg']['NavigationBarIconic']) {
313 $caption3 = ' &gt; ';
314 $caption4 = '&gt;&gt;';
315 $title3 = ' title="' . $GLOBALS['strNext'] . '"';
316 $title4 = ' title="' . $GLOBALS['strEnd'] . '"';
317 } else {
318 $caption3 = '&gt; ' . $GLOBALS['strNext'];
319 $caption4 = '&gt;&gt; ' . $GLOBALS['strEnd'];
320 $title3 = '';
321 $title4 = '';
322 } // end if... else...
323 echo "\n";
325 <td>
326 <form action="sql.php" method="post">
327 <?php echo PMA_generate_common_hidden_inputs($db, $table); ?>
328 <input type="hidden" name="sql_query" value="<?php echo $html_sql_query; ?>" />
329 <input type="hidden" name="pos" value="<?php echo $pos_next; ?>" />
330 <input type="hidden" name="goto" value="<?php echo $goto; ?>" />
331 <input type="submit" name="navig" value="<?php echo $caption3; ?>"<?php echo $title3; ?> />
332 </form>
333 </td>
334 <td>
335 <form action="sql.php" method="post"
336 onsubmit="return <?php echo (($_SESSION['userconf']['pos'] + $_SESSION['userconf']['max_rows'] < $unlim_num_rows && $num_rows >= $_SESSION['userconf']['max_rows']) ? 'true' : 'false'); ?>">
337 <?php echo PMA_generate_common_hidden_inputs($db, $table); ?>
338 <input type="hidden" name="sql_query" value="<?php echo $html_sql_query; ?>" />
339 <input type="hidden" name="pos" value="<?php echo @((ceil($unlim_num_rows / $_SESSION['userconf']['max_rows'])- 1) * $_SESSION['userconf']['max_rows']); ?>" />
340 <?php
341 if ($is_innodb && $unlim_num_rows > $GLOBALS['cfg']['MaxExactCount']) {
342 echo '<input type="hidden" name="find_real_end" value="1" />' . "\n";
343 // no backquote around this message
344 $onclick = ' onclick="return confirmAction(\'' . PMA_jsFormat($GLOBALS['strLongOperation'], false) . '\')"';
347 <input type="hidden" name="goto" value="<?php echo $goto; ?>" />
348 <input type="submit" name="navig" value="<?php echo $caption4; ?>"<?php echo $title4; ?> <?php echo (empty($onclick) ? '' : $onclick); ?>/>
349 </form>
350 </td>
351 <?php
352 } // end move toward
355 //page redirection
356 // (unless we are showing all records)
357 if ('all' != $_SESSION['userconf']['max_rows']) { //if1
358 $pageNow = @floor($_SESSION['userconf']['pos'] / $_SESSION['userconf']['max_rows']) + 1;
359 $nbTotalPage = @ceil($unlim_num_rows / $_SESSION['userconf']['max_rows']);
361 if ($nbTotalPage > 1){ //if2
363 <td>
364 &nbsp;&nbsp;&nbsp;
365 </td>
366 <td>
367 <?php //<form> for keep the form alignment of button < and << ?>
368 <form action="none">
369 <?php
370 $_url_params = array(
371 'db' => $db,
372 'table' => $table,
373 'sql_query' => $sql_query,
374 'goto' => $goto,
376 echo PMA_pageselector(
377 'sql.php' . PMA_generate_common_url($_url_params) . PMA_get_arg_separator('js'),
378 $_SESSION['userconf']['max_rows'],
379 $pageNow,
380 $nbTotalPage,
381 200,
386 $GLOBALS['strPageNumber']
389 </form>
390 </td>
391 <?php
392 } //_if2
393 } //_if1
395 // Display the "Show all" button if allowed
396 if ($GLOBALS['cfg']['ShowAll'] && ($num_rows < $unlim_num_rows)) {
397 echo "\n";
399 <td>
400 &nbsp;&nbsp;&nbsp;
401 </td>
402 <td>
403 <form action="sql.php" method="post">
404 <?php echo PMA_generate_common_hidden_inputs($db, $table); ?>
405 <input type="hidden" name="sql_query" value="<?php echo $html_sql_query; ?>" />
406 <input type="hidden" name="pos" value="0" />
407 <input type="hidden" name="session_max_rows" value="all" />
408 <input type="hidden" name="goto" value="<?php echo $goto; ?>" />
409 <input type="submit" name="navig" value="<?php echo $GLOBALS['strShowAll']; ?>" />
410 </form>
411 </td>
412 <?php
413 } // end show all
414 echo "\n";
416 </tr>
417 </table>
419 <?php
420 } // end of the 'PMA_displayTableNavigation()' function
424 * Displays the headers of the results table
426 * @uses $_SESSION['userconf']['disp_direction']
427 * @uses $_SESSION['userconf']['repeat_cells']
428 * @uses $_SESSION['userconf']['max_rows']
429 * @uses $_SESSION['userconf']['display_text']
430 * @uses $_SESSION['userconf']['display_binary']
431 * @param array which elements to display
432 * @param array the list of fields properties
433 * @param integer the total number of fields returned by the SQL query
434 * @param array the analyzed query
436 * @return boolean always true
438 * @global string $db the database name
439 * @global string $table the table name
440 * @global string $goto the URL to go back in case of errors
441 * @global string $sql_query the SQL query
442 * @global integer $num_rows the total number of rows returned by the
443 * SQL query
444 * @global array $vertical_display informations used with vertical display
445 * mode
447 * @access private
449 * @see PMA_displayTable()
451 function PMA_displayTableHeaders(&$is_display, &$fields_meta, $fields_cnt = 0, $analyzed_sql = '')
453 global $db, $table, $goto;
454 global $sql_query, $num_rows;
455 global $vertical_display, $highlight_columns;
457 if ($analyzed_sql == '') {
458 $analyzed_sql = array();
461 // can the result be sorted?
462 if ($is_display['sort_lnk'] == '1') {
464 // Just as fallback
465 $unsorted_sql_query = $sql_query;
466 if (isset($analyzed_sql[0]['unsorted_query'])) {
467 $unsorted_sql_query = $analyzed_sql[0]['unsorted_query'];
470 // we need $sort_expression and $sort_expression_nodirection
471 // even if there are many table references
473 $sort_expression = trim(str_replace(' ', ' ', $analyzed_sql[0]['order_by_clause']));
476 * Get rid of ASC|DESC
477 * @todo analyzer
479 preg_match('@(.*)([[:space:]]*(ASC|DESC))@si', $sort_expression, $matches);
480 $sort_expression_nodirection = isset($matches[1]) ? trim($matches[1]) : $sort_expression;
482 // sorting by indexes, only if it makes sense (only one table ref)
483 if (isset($analyzed_sql) && isset($analyzed_sql[0]) &&
484 isset($analyzed_sql[0]['querytype']) && $analyzed_sql[0]['querytype'] == 'SELECT' &&
485 isset($analyzed_sql[0]['table_ref']) && count($analyzed_sql[0]['table_ref']) == 1) {
487 // grab indexes data:
488 $indexes = PMA_Index::getFromTable($table, $db);
490 // do we have any index?
491 if ($indexes) {
493 if ($_SESSION['userconf']['disp_direction'] == 'horizontal'
494 || $_SESSION['userconf']['disp_direction'] == 'horizontalflipped') {
495 $span = $fields_cnt;
496 if ($is_display['edit_lnk'] != 'nn') {
497 $span++;
499 if ($is_display['del_lnk'] != 'nn') {
500 $span++;
502 if ($is_display['del_lnk'] != 'kp' && $is_display['del_lnk'] != 'nn') {
503 $span++;
505 } else {
506 $span = $num_rows + floor($num_rows/$_SESSION['userconf']['repeat_cells']) + 1;
509 echo '<form action="sql.php" method="post">' . "\n";
510 echo PMA_generate_common_hidden_inputs($db, $table);
511 echo $GLOBALS['strSortByKey'] . ': <select name="sql_query" onchange="this.form.submit();">' . "\n";
512 $used_index = false;
513 $local_order = (isset($sort_expression) ? $sort_expression : '');
514 foreach ($indexes as $index) {
515 $asc_sort = '`' . implode('` ASC, `', array_keys($index->getColumns())) . '` ASC';
516 $desc_sort = '`' . implode('` DESC, `', array_keys($index->getColumns())) . '` DESC';
517 $used_index = $used_index || $local_order == $asc_sort || $local_order == $desc_sort;
518 echo '<option value="'
519 . htmlspecialchars($unsorted_sql_query . ' ORDER BY ' . $asc_sort)
520 . '"' . ($local_order == $asc_sort ? ' selected="selected"' : '')
521 . '>' . htmlspecialchars($index->getName()) . ' ('
522 . $GLOBALS['strAscending'] . ')</option>';
523 echo '<option value="'
524 . htmlspecialchars($unsorted_sql_query . ' ORDER BY ' . $desc_sort)
525 . '"' . ($local_order == $desc_sort ? ' selected="selected"' : '')
526 . '>' . htmlspecialchars($index->getName()) . ' ('
527 . $GLOBALS['strDescending'] . ')</option>';
529 echo '<option value="' . htmlspecialchars($unsorted_sql_query) . '"' . ($used_index ? '' : ' selected="selected"') . '>' . $GLOBALS['strNone'] . '</option>';
530 echo '</select>' . "\n";
531 echo '<noscript><input type="submit" value="' . $GLOBALS['strGo'] . '" /></noscript>';
532 echo '</form>' . "\n";
538 $vertical_display['emptypre'] = 0;
539 $vertical_display['emptyafter'] = 0;
540 $vertical_display['textbtn'] = '';
542 // Display options (if we are not in print view)
543 if (! (isset($GLOBALS['printview']) && $GLOBALS['printview'] == '1')) {
544 echo '<form method="post" action="sql.php" name="displayOptionsForm" id="displayOptionsForm">';
545 $url_params = array(
546 'db' => $db,
547 'table' => $table,
548 'sql_query' => $sql_query,
549 'goto' => $goto,
550 'display_options_form' => 1
552 echo PMA_generate_common_hidden_inputs($url_params);
553 echo '<br />';
554 PMA_generate_slider_effect('displayoptions',$GLOBALS['strOptions']);
555 echo '<fieldset>';
557 echo '<div class="formelement">';
558 $choices = array(
559 'P' => $GLOBALS['strPartialText'],
560 'F' => $GLOBALS['strFullText']
562 PMA_generate_html_radio('display_text', $choices, $_SESSION['userconf']['display_text']);
563 echo '</div>';
565 if ($GLOBALS['cfgRelation']['relwork']) {
566 echo '<div class="formelement">';
567 $choices = array(
568 'K' => $GLOBALS['strRelationalKey'],
569 'D' => $GLOBALS['strRelationalDisplayField']
571 PMA_generate_html_radio('relational_display', $choices, $_SESSION['userconf']['relational_display']);
572 echo '</div>';
575 echo '<div class="formelement">';
576 PMA_generate_html_checkbox('display_binary', $GLOBALS['strShow'] . ' BINARY', ! empty($_SESSION['userconf']['display_binary']), false);
578 PMA_generate_html_checkbox('display_blob', $GLOBALS['strShow'] . ' BLOB', ! empty($_SESSION['userconf']['display_blob']), false);
579 echo '</div>';
581 // I would have preferred to name this "display_transformation".
582 // This is the only way I found to be able to keep this setting sticky
583 // per SQL query, and at the same time have a default that displays
584 // the transformations.
585 echo '<div class="formelement">';
586 PMA_generate_html_checkbox('hide_transformation', $GLOBALS['strHide'] . ' ' . $GLOBALS['strMIME_transformation'], ! empty($_SESSION['userconf']['hide_transformation']), false);
587 echo '</div>';
589 echo '<div class="clearfloat"></div>';
590 echo '</fieldset>';
592 echo '<fieldset class="tblFooters">';
593 echo '<input type="submit" value="' . $GLOBALS['strGo'] . '" />';
594 echo '</fieldset>';
595 echo '</div>';
596 echo '</form>';
599 // Start of form for multi-rows edit/delete/export
601 if ($is_display['del_lnk'] == 'dr' || $is_display['del_lnk'] == 'kp') {
602 echo '<form method="post" action="tbl_row_action.php" name="rowsDeleteForm" id="rowsDeleteForm">' . "\n";
603 echo PMA_generate_common_hidden_inputs($db, $table, 1);
604 echo '<input type="hidden" name="goto" value="sql.php" />' . "\n";
607 echo '<table id="table_results" class="data">' . "\n";
608 if ($_SESSION['userconf']['disp_direction'] == 'horizontal'
609 || $_SESSION['userconf']['disp_direction'] == 'horizontalflipped') {
610 echo '<thead><tr>' . "\n";
613 // 1. Displays the full/partial text button (part 1)...
614 if ($_SESSION['userconf']['disp_direction'] == 'horizontal'
615 || $_SESSION['userconf']['disp_direction'] == 'horizontalflipped') {
616 $colspan = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn')
617 ? ' colspan="3"'
618 : '';
619 } else {
620 $rowspan = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn')
621 ? ' rowspan="3"'
622 : '';
625 // ... before the result table
626 if (($is_display['edit_lnk'] == 'nn' && $is_display['del_lnk'] == 'nn')
627 && $is_display['text_btn'] == '1') {
628 $vertical_display['emptypre'] = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn') ? 3 : 0;
629 if ($_SESSION['userconf']['disp_direction'] == 'horizontal'
630 || $_SESSION['userconf']['disp_direction'] == 'horizontalflipped') {
632 <th colspan="<?php echo $fields_cnt; ?>"></th>
633 </tr>
634 <tr>
635 <?php
636 } // end horizontal/horizontalflipped mode
637 else {
639 <tr>
640 <th colspan="<?php echo $num_rows + floor($num_rows/$_SESSION['userconf']['repeat_cells']) + 1; ?>"></th>
641 </tr>
642 <?php
643 } // end vertical mode
646 // ... at the left column of the result table header if possible
647 // and required
648 elseif ($GLOBALS['cfg']['ModifyDeleteAtLeft'] && $is_display['text_btn'] == '1') {
649 $vertical_display['emptypre'] = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn') ? 3 : 0;
650 if ($_SESSION['userconf']['disp_direction'] == 'horizontal'
651 || $_SESSION['userconf']['disp_direction'] == 'horizontalflipped') {
653 <th <?php echo $colspan; ?>></th>
654 <?php
655 } // end horizontal/horizontalflipped mode
656 else {
657 $vertical_display['textbtn'] = ' <th ' . $rowspan . ' valign="middle">' . "\n"
658 . ' ' . "\n"
659 . ' </th>' . "\n";
660 } // end vertical mode
663 // ... elseif no button, displays empty(ies) col(s) if required
664 elseif ($GLOBALS['cfg']['ModifyDeleteAtLeft']
665 && ($is_display['edit_lnk'] != 'nn' || $is_display['del_lnk'] != 'nn')) {
666 $vertical_display['emptypre'] = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn') ? 3 : 0;
667 if ($_SESSION['userconf']['disp_direction'] == 'horizontal'
668 || $_SESSION['userconf']['disp_direction'] == 'horizontalflipped') {
670 <td<?php echo $colspan; ?>></td>
671 <?php
672 } // end horizontal/horizontalfipped mode
673 else {
674 $vertical_display['textbtn'] = ' <td' . $rowspan . '></td>' . "\n";
675 } // end vertical mode
678 // 2. Displays the fields' name
679 // 2.0 If sorting links should be used, checks if the query is a "JOIN"
680 // statement (see 2.1.3)
682 // 2.0.1 Prepare Display column comments if enabled ($GLOBALS['cfg']['ShowBrowseComments']).
683 // Do not show comments, if using horizontalflipped mode, because of space usage
684 if ($GLOBALS['cfg']['ShowBrowseComments']
685 && $_SESSION['userconf']['disp_direction'] != 'horizontalflipped') {
686 $comments_map = array();
687 if (isset($analyzed_sql[0]) && is_array($analyzed_sql[0])) {
688 foreach ($analyzed_sql[0]['table_ref'] as $tbl) {
689 $tb = $tbl['table_true_name'];
690 $comments_map[$tb] = PMA_getComments($db, $tb);
691 unset($tb);
696 if ($GLOBALS['cfgRelation']['commwork'] && $GLOBALS['cfgRelation']['mimework'] && $GLOBALS['cfg']['BrowseMIME'] && ! $_SESSION['userconf']['hide_transformation']) {
697 require_once './libraries/transformations.lib.php';
698 $GLOBALS['mime_map'] = PMA_getMIME($db, $table);
701 if ($is_display['sort_lnk'] == '1') {
702 $select_expr = $analyzed_sql[0]['select_expr_clause'];
705 // garvin: See if we have to highlight any header fields of a WHERE query.
706 // Uses SQL-Parser results.
707 $highlight_columns = array();
708 if (isset($analyzed_sql) && isset($analyzed_sql[0]) &&
709 isset($analyzed_sql[0]['where_clause_identifiers'])) {
711 $wi = 0;
712 if (isset($analyzed_sql[0]['where_clause_identifiers']) && is_array($analyzed_sql[0]['where_clause_identifiers'])) {
713 foreach ($analyzed_sql[0]['where_clause_identifiers'] AS $wci_nr => $wci) {
714 $highlight_columns[$wci] = 'true';
719 for ($i = 0; $i < $fields_cnt; $i++) {
720 // garvin: See if this column should get highlight because it's used in the
721 // where-query.
722 if (isset($highlight_columns[$fields_meta[$i]->name]) || isset($highlight_columns[PMA_backquote($fields_meta[$i]->name)])) {
723 $condition_field = true;
724 } else {
725 $condition_field = false;
728 // 2.0 Prepare comment-HTML-wrappers for each row, if defined/enabled.
729 if (isset($comments_map) &&
730 isset($comments_map[$fields_meta[$i]->table]) &&
731 isset($comments_map[$fields_meta[$i]->table][$fields_meta[$i]->name])) {
732 $comments = '<span class="tblcomment">' . htmlspecialchars($comments_map[$fields_meta[$i]->table][$fields_meta[$i]->name]) . '</span>';
733 } else {
734 $comments = '';
737 // 2.1 Results can be sorted
738 if ($is_display['sort_lnk'] == '1') {
740 // 2.1.1 Checks if the table name is required; it's the case
741 // for a query with a "JOIN" statement and if the column
742 // isn't aliased, or in queries like
743 // SELECT `1`.`master_field` , `2`.`master_field`
744 // FROM `PMA_relation` AS `1` , `PMA_relation` AS `2`
746 if (isset($fields_meta[$i]->table) && strlen($fields_meta[$i]->table)) {
747 $sort_tbl = PMA_backquote($fields_meta[$i]->table) . '.';
748 } else {
749 $sort_tbl = '';
752 // 2.1.2 Checks if the current column is used to sort the
753 // results
754 // the orgname member does not exist for all MySQL versions
755 // but if found, it's the one on which to sort
756 $name_to_use_in_sort = $fields_meta[$i]->name;
757 if (isset($fields_meta[$i]->orgname)) {
758 $name_to_use_in_sort = $fields_meta[$i]->orgname;
760 // $name_to_use_in_sort might contain a space due to
761 // formatting of function expressions like "COUNT(name )"
762 // so we remove the space in this situation
763 $name_to_use_in_sort = str_replace(' )', ')', $name_to_use_in_sort);
765 if (empty($sort_expression)) {
766 $is_in_sort = false;
767 } else {
768 // field name may be preceded by a space, or any number
769 // of characters followed by a dot (tablename.fieldname)
770 // so do a direct comparison
771 // for the sort expression (avoids problems with queries
772 // like "SELECT id, count(id)..." and clicking to sort
773 // on id or on count(id))
774 $is_in_sort = (str_replace('`', '', $sort_tbl) . $name_to_use_in_sort == str_replace('`', '', $sort_expression_nodirection) ? true : false);
776 // 2.1.3 Check the field name for a bracket.
777 // If it contains one, it's probably a function column
778 // like 'COUNT(`field`)'
779 if (strpos($name_to_use_in_sort, '(') !== false) {
780 $sort_order = ' ORDER BY ' . $name_to_use_in_sort . ' ';
781 } else {
782 $sort_order = ' ORDER BY ' . $sort_tbl . PMA_backquote($name_to_use_in_sort) . ' ';
784 unset($name_to_use_in_sort);
786 // 2.1.4 Do define the sorting URL
787 if (! $is_in_sort) {
788 // loic1: patch #455484 ("Smart" order)
789 $GLOBALS['cfg']['Order'] = strtoupper($GLOBALS['cfg']['Order']);
790 if ($GLOBALS['cfg']['Order'] === 'SMART') {
791 $sort_order .= (preg_match('@time|date@i', $fields_meta[$i]->type)) ? 'DESC' : 'ASC';
792 } else {
793 $sort_order .= $GLOBALS['cfg']['Order'];
795 $order_img = '';
796 } elseif (preg_match('@[[:space:]]DESC$@i', $sort_expression)) {
797 $sort_order .= ' ASC';
798 $order_img = ' <img class="icon" src="' . $GLOBALS['pmaThemeImage'] . 's_desc.png" width="11" height="9" alt="'. $GLOBALS['strDescending'] . '" title="'. $GLOBALS['strDescending'] . '" id="soimg' . $i . '" />';
799 } else {
800 $sort_order .= ' DESC';
801 $order_img = ' <img class="icon" src="' . $GLOBALS['pmaThemeImage'] . 's_asc.png" width="11" height="9" alt="'. $GLOBALS['strAscending'] . '" title="'. $GLOBALS['strAscending'] . '" id="soimg' . $i . '" />';
804 if (preg_match('@(.*)([[:space:]](LIMIT (.*)|PROCEDURE (.*)|FOR UPDATE|LOCK IN SHARE MODE))@i', $unsorted_sql_query, $regs3)) {
805 $sorted_sql_query = $regs3[1] . $sort_order . $regs3[2];
806 } else {
807 $sorted_sql_query = $unsorted_sql_query . $sort_order;
809 $_url_params = array(
810 'db' => $db,
811 'table' => $table,
812 'sql_query' => $sorted_sql_query,
814 $order_url = 'sql.php' . PMA_generate_common_url($_url_params);
816 // 2.1.5 Displays the sorting URL
817 // added 20004-06-09: Michael Keck <mail@michaelkeck.de>
818 // enable sort order swapping for image
819 $order_link_params = array();
820 if (isset($order_img) && $order_img!='') {
821 if (strstr($order_img, 'asc')) {
822 $order_link_params['onmouseover'] = 'if(document.getElementById(\'soimg' . $i . '\')){ document.getElementById(\'soimg' . $i . '\').src=\'' . $GLOBALS['pmaThemeImage'] . 's_desc.png\'; }';
823 $order_link_params['onmouseout'] = 'if(document.getElementById(\'soimg' . $i . '\')){ document.getElementById(\'soimg' . $i . '\').src=\'' . $GLOBALS['pmaThemeImage'] . 's_asc.png\'; }';
824 } elseif (strstr($order_img, 'desc')) {
825 $order_link_params['onmouseover'] = 'if(document.getElementById(\'soimg' . $i . '\')){ document.getElementById(\'soimg' . $i . '\').src=\'' . $GLOBALS['pmaThemeImage'] . 's_asc.png\'; }';
826 $order_link_params['onmouseout'] = 'if(document.getElementById(\'soimg' . $i . '\')){ document.getElementById(\'soimg' . $i . '\').src=\'' . $GLOBALS['pmaThemeImage'] . 's_desc.png\'; }';
829 if ($_SESSION['userconf']['disp_direction'] == 'horizontalflipped'
830 && $GLOBALS['cfg']['HeaderFlipType'] == 'css') {
831 $order_link_params['style'] = 'direction: ltr; writing-mode: tb-rl;';
833 $order_link_params['title'] = $GLOBALS['strSort'];
834 $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));
835 $order_link = PMA_linkOrButton($order_url, $order_link_content . $order_img, $order_link_params, false, true);
837 if ($_SESSION['userconf']['disp_direction'] == 'horizontal'
838 || $_SESSION['userconf']['disp_direction'] == 'horizontalflipped') {
839 echo '<th';
840 if ($condition_field) {
841 echo ' class="condition"';
843 if ($_SESSION['userconf']['disp_direction'] == 'horizontalflipped') {
844 echo ' valign="bottom"';
846 echo '>' . $order_link . $comments . '</th>';
848 $vertical_display['desc'][] = ' <th '
849 . ($condition_field ? ' class="condition"' : '') . '>' . "\n"
850 . $order_link . $comments . ' </th>' . "\n";
851 } // end if (2.1)
853 // 2.2 Results can't be sorted
854 else {
855 if ($_SESSION['userconf']['disp_direction'] == 'horizontal'
856 || $_SESSION['userconf']['disp_direction'] == 'horizontalflipped') {
857 echo '<th';
858 if ($condition_field) {
859 echo ' class="condition"';
861 if ($_SESSION['userconf']['disp_direction'] == 'horizontalflipped') {
862 echo ' valign="bottom"';
864 if ($_SESSION['userconf']['disp_direction'] == 'horizontalflipped'
865 && $GLOBALS['cfg']['HeaderFlipType'] == 'css') {
866 echo ' style="direction: ltr; writing-mode: tb-rl;"';
868 echo '>';
869 if ($_SESSION['userconf']['disp_direction'] == 'horizontalflipped'
870 && $GLOBALS['cfg']['HeaderFlipType'] == 'fake') {
871 echo PMA_flipstring(htmlspecialchars($fields_meta[$i]->name), '<br />');
872 } else {
873 echo htmlspecialchars($fields_meta[$i]->name);
875 echo "\n" . $comments . '</th>';
877 $vertical_display['desc'][] = ' <th '
878 . ($condition_field ? ' class="condition"' : '') . '>' . "\n"
879 . ' ' . htmlspecialchars($fields_meta[$i]->name) . "\n"
880 . $comments . ' </th>';
881 } // end else (2.2)
882 } // end for
884 // 3. Displays the needed checkboxes at the right
885 // column of the result table header if possible and required...
886 if ($GLOBALS['cfg']['ModifyDeleteAtRight']
887 && ($is_display['edit_lnk'] != 'nn' || $is_display['del_lnk'] != 'nn')
888 && $is_display['text_btn'] == '1') {
889 $vertical_display['emptyafter'] = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn') ? 3 : 1;
890 if ($_SESSION['userconf']['disp_direction'] == 'horizontal'
891 || $_SESSION['userconf']['disp_direction'] == 'horizontalflipped') {
892 echo "\n";
894 <th <?php echo $colspan; ?>>
895 </th>
896 <?php
897 } // end horizontal/horizontalflipped mode
898 else {
899 $vertical_display['textbtn'] = ' <th ' . $rowspan . ' valign="middle">' . "\n"
900 . ' ' . "\n"
901 . ' </th>' . "\n";
902 } // end vertical mode
905 // ... elseif no button, displays empty columns if required
906 // (unless coming from Browse mode print view)
907 elseif ($GLOBALS['cfg']['ModifyDeleteAtRight']
908 && ($is_display['edit_lnk'] == 'nn' && $is_display['del_lnk'] == 'nn')
909 && (!$GLOBALS['is_header_sent'])) {
910 $vertical_display['emptyafter'] = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn') ? 3 : 1;
911 if ($_SESSION['userconf']['disp_direction'] == 'horizontal'
912 || $_SESSION['userconf']['disp_direction'] == 'horizontalflipped') {
913 echo "\n";
915 <td<?php echo $colspan; ?>></td>
916 <?php
917 } // end horizontal/horizontalflipped mode
918 else {
919 $vertical_display['textbtn'] = ' <td' . $rowspan . '></td>' . "\n";
920 } // end vertical mode
923 if ($_SESSION['userconf']['disp_direction'] == 'horizontal'
924 || $_SESSION['userconf']['disp_direction'] == 'horizontalflipped') {
926 </tr>
927 </thead>
928 <?php
931 return true;
932 } // end of the 'PMA_displayTableHeaders()' function
937 * Displays the body of the results table
939 * @uses $_SESSION['userconf']['disp_direction']
940 * @uses $_SESSION['userconf']['repeat_cells']
941 * @uses $_SESSION['userconf']['max_rows']
942 * @uses $_SESSION['userconf']['display_text']
943 * @uses $_SESSION['userconf']['display_binary']
944 * @uses $_SESSION['userconf']['display_blob']
945 * @param integer the link id associated to the query which results have
946 * to be displayed
947 * @param array which elements to display
948 * @param array the list of relations
949 * @param array the analyzed query
951 * @return boolean always true
953 * @global string $db the database name
954 * @global string $table the table name
955 * @global string $goto the URL to go back in case of errors
956 * @global string $sql_query the SQL query
957 * @global array $fields_meta the list of fields properties
958 * @global integer $fields_cnt the total number of fields returned by
959 * the SQL query
960 * @global array $vertical_display informations used with vertical display
961 * mode
962 * @global array $highlight_columns column names to highlight
963 * @global array $row current row data
965 * @access private
967 * @see PMA_displayTable()
969 function PMA_displayTableBody(&$dt_result, &$is_display, $map, $analyzed_sql) {
970 global $db, $table, $goto;
971 global $sql_query, $fields_meta, $fields_cnt;
972 global $vertical_display, $highlight_columns;
973 global $row; // mostly because of browser transformations, to make the row-data accessible in a plugin
975 $url_sql_query = $sql_query;
977 // query without conditions to shorten URLs when needed, 200 is just
978 // guess, it should depend on remaining URL length
980 if (isset($analyzed_sql) && isset($analyzed_sql[0]) &&
981 isset($analyzed_sql[0]['querytype']) && $analyzed_sql[0]['querytype'] == 'SELECT' &&
982 strlen($sql_query) > 200) {
984 $url_sql_query = 'SELECT ';
985 if (isset($analyzed_sql[0]['queryflags']['distinct'])) {
986 $url_sql_query .= ' DISTINCT ';
988 $url_sql_query .= $analyzed_sql[0]['select_expr_clause'];
989 if (!empty($analyzed_sql[0]['from_clause'])) {
990 $url_sql_query .= ' FROM ' . $analyzed_sql[0]['from_clause'];
994 if (!is_array($map)) {
995 $map = array();
997 $row_no = 0;
998 $vertical_display['edit'] = array();
999 $vertical_display['delete'] = array();
1000 $vertical_display['data'] = array();
1001 $vertical_display['row_delete'] = array();
1003 // Correction University of Virginia 19991216 in the while below
1004 // Previous code assumed that all tables have keys, specifically that
1005 // the phpMyAdmin GUI should support row delete/edit only for such
1006 // tables.
1007 // Although always using keys is arguably the prescribed way of
1008 // defining a relational table, it is not required. This will in
1009 // particular be violated by the novice.
1010 // We want to encourage phpMyAdmin usage by such novices. So the code
1011 // below has been changed to conditionally work as before when the
1012 // table being displayed has one or more keys; but to display
1013 // delete/edit options correctly for tables without keys.
1015 $odd_row = true;
1016 while ($row = PMA_DBI_fetch_row($dt_result)) {
1017 // lem9: "vertical display" mode stuff
1018 if ($row_no != 0 && $_SESSION['userconf']['repeat_cells'] != 0 && !($row_no % $_SESSION['userconf']['repeat_cells'])
1019 && ($_SESSION['userconf']['disp_direction'] == 'horizontal'
1020 || $_SESSION['userconf']['disp_direction'] == 'horizontalflipped'))
1022 echo '<tr>' . "\n";
1023 if ($vertical_display['emptypre'] > 0) {
1024 echo ' <th colspan="' . $vertical_display['emptypre'] . '">' . "\n"
1025 .' &nbsp;</th>' . "\n";
1028 foreach ($vertical_display['desc'] as $val) {
1029 echo $val;
1032 if ($vertical_display['emptyafter'] > 0) {
1033 echo ' <th colspan="' . $vertical_display['emptyafter'] . '">' . "\n"
1034 .' &nbsp;</th>' . "\n";
1036 echo '</tr>' . "\n";
1037 } // end if
1039 $class = $odd_row ? 'odd' : 'even';
1040 $odd_row = ! $odd_row;
1041 if ($_SESSION['userconf']['disp_direction'] == 'horizontal'
1042 || $_SESSION['userconf']['disp_direction'] == 'horizontalflipped') {
1043 // loic1: pointer code part
1044 echo ' <tr class="' . $class . '">' . "\n";
1045 $class = '';
1049 // 1. Prepares the row (gets primary keys to use)
1050 // 1.1 Results from a "SELECT" statement -> builds the
1051 // "primary" key to use in links
1053 * @todo $unique_condition could be empty, for example a table
1054 * with only one field and it's a BLOB; in this case,
1055 * avoid to display the delete and edit links
1057 //$unique_condition = urlencode(PMA_getUniqueCondition($dt_result, $fields_cnt, $fields_meta, $row));
1058 $unique_condition = PMA_getUniqueCondition($dt_result, $fields_cnt, $fields_meta, $row);
1059 $unique_condition_html = htmlspecialchars($unique_condition);
1061 // 1.2 Defines the URLs for the modify/delete link(s)
1063 if ($is_display['edit_lnk'] != 'nn' || $is_display['del_lnk'] != 'nn') {
1064 // We need to copy the value or else the == 'both' check will always return true
1066 if ($GLOBALS['cfg']['PropertiesIconic'] === 'both') {
1067 $iconic_spacer = '<div class="nowrap">';
1068 } else {
1069 $iconic_spacer = '';
1072 // 1.2.1 Modify link(s)
1073 if ($is_display['edit_lnk'] == 'ur') { // update row case
1074 $_url_params = array(
1075 'db' => $db,
1076 'table' => $table,
1077 'primary_key' => $unique_condition,
1078 'sql_query' => $url_sql_query,
1079 'goto' => 'sql.php',
1081 $edit_url = 'tbl_change.php' . PMA_generate_common_url($_url_params);
1083 $edit_str = PMA_getIcon('b_edit.png', $GLOBALS['strEdit'], true);
1084 } // end if (1.2.1)
1086 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])) {
1087 $_url_params = array(
1088 'db' => $row[1],
1089 'id_bookmark' => $row[0],
1090 'action_bookmark' => '0',
1091 'action_bookmark_all' => '1',
1092 'SQL' => $GLOBALS['strExecuteBookmarked'],
1094 $bookmark_go = '<a href="import.php'
1095 . PMA_generate_common_url($_url_params)
1096 .' " title="' . $GLOBALS['strExecuteBookmarked'] . '">';
1098 $bookmark_go .= PMA_getIcon('b_bookmark.png', $GLOBALS['strExecuteBookmarked'], true);
1100 $bookmark_go .= '</a>';
1101 } else {
1102 $bookmark_go = '';
1105 // 1.2.2 Delete/Kill link(s)
1106 if ($is_display['del_lnk'] == 'dr') { // delete row case
1107 $_url_params = array(
1108 'db' => $db,
1109 'table' => $table,
1110 'sql_query' => $url_sql_query,
1111 'zero_rows' => $GLOBALS['strDeleted'],
1112 'goto' => (empty($goto) ? 'tbl_sql.php' : $goto),
1114 $lnk_goto = 'sql.php' . PMA_generate_common_url($_url_params, 'text');
1116 $del_query = 'DELETE FROM ' . PMA_backquote($db) . '.' . PMA_backquote($table)
1117 . ' WHERE' . $unique_condition . ' LIMIT 1';
1119 $_url_params = array(
1120 'db' => $db,
1121 'table' => $table,
1122 'sql_query' => $del_query,
1123 'zero_rows' => $GLOBALS['strDeleted'],
1124 'goto' => $lnk_goto,
1126 $del_url = 'sql.php' . PMA_generate_common_url($_url_params);
1128 $js_conf = 'DELETE FROM ' . PMA_jsFormat($db) . '.' . PMA_jsFormat($table)
1129 . ' WHERE ' . trim(PMA_jsFormat($unique_condition, false))
1130 . ' LIMIT 1';
1131 $del_str = PMA_getIcon('b_drop.png', $GLOBALS['strDelete'], true);
1132 } elseif ($is_display['del_lnk'] == 'kp') { // kill process case
1134 $_url_params = array(
1135 'db' => $db,
1136 'table' => $table,
1137 'sql_query' => $url_sql_query,
1138 'goto' => 'main.php',
1140 $lnk_goto = 'sql.php' . PMA_generate_common_url($_url_params, 'text');
1142 $_url_params = array(
1143 'db' => 'mysql',
1144 'sql_query' => 'KILL ' . $row[0],
1145 'goto' => $lnk_goto,
1147 $del_url = 'sql.php' . PMA_generate_common_url($_url_params);
1148 $del_query = 'KILL ' . $row[0];
1149 $js_conf = 'KILL ' . $row[0];
1150 $del_str = PMA_getIcon('b_drop.png', $GLOBALS['strKill'], true);
1151 } // end if (1.2.2)
1153 // 1.3 Displays the links at left if required
1154 if ($GLOBALS['cfg']['ModifyDeleteAtLeft']
1155 && ($_SESSION['userconf']['disp_direction'] == 'horizontal'
1156 || $_SESSION['userconf']['disp_direction'] == 'horizontalflipped')) {
1157 $doWriteModifyAt = 'left';
1158 require './libraries/display_tbl_links.lib.php';
1159 } // end if (1.3)
1160 } // end if (1)
1162 // 2. Displays the rows' values
1163 for ($i = 0; $i < $fields_cnt; ++$i) {
1164 $meta = $fields_meta[$i];
1165 $pointer = $i;
1166 // garvin: See if this column should get highlight because it's used in the
1167 // where-query.
1168 if (isset($highlight_columns) && (isset($highlight_columns[$meta->name]) || isset($highlight_columns[PMA_backquote($meta->name)]))) {
1169 $condition_field = true;
1170 } else {
1171 $condition_field = false;
1174 $mouse_events = '';
1175 if ($_SESSION['userconf']['disp_direction'] == 'vertical' && (!isset($GLOBALS['printview']) || ($GLOBALS['printview'] != '1'))) {
1176 if ($GLOBALS['cfg']['BrowsePointerEnable'] == true) {
1177 $mouse_events .= ' onmouseover="setVerticalPointer(this, ' . $row_no . ', \'over\', \'odd\', \'even\', \'hover\', \'marked\');"'
1178 . ' onmouseout="setVerticalPointer(this, ' . $row_no . ', \'out\', \'odd\', \'even\', \'hover\', \'marked\');" ';
1180 if ($GLOBALS['cfg']['BrowseMarkerEnable'] == true) {
1181 $mouse_events .= ' onmousedown="setVerticalPointer(this, ' . $row_no . ', \'click\', \'odd\', \'even\', \'hover\', \'marked\'); setCheckboxColumn(\'id_rows_to_delete' . $row_no . '\');" ';
1182 } else {
1183 $mouse_events .= ' onmousedown="setCheckboxColumn(\'id_rows_to_delete' . $row_no . '\');" ';
1185 }// end if
1187 // garvin: Wrap MIME-transformations. [MIME]
1188 $default_function = 'default_function'; // default_function
1189 $transform_function = $default_function;
1190 $transform_options = array();
1192 if ($GLOBALS['cfgRelation']['mimework'] && $GLOBALS['cfg']['BrowseMIME']) {
1194 if (isset($GLOBALS['mime_map'][$meta->name]['mimetype']) && isset($GLOBALS['mime_map'][$meta->name]['transformation']) && !empty($GLOBALS['mime_map'][$meta->name]['transformation'])) {
1195 $include_file = $GLOBALS['mime_map'][$meta->name]['transformation'];
1197 if (file_exists('./libraries/transformations/' . $include_file)) {
1198 $transformfunction_name = str_replace('.inc.php', '', $GLOBALS['mime_map'][$meta->name]['transformation']);
1200 require_once './libraries/transformations/' . $include_file;
1202 if (function_exists('PMA_transformation_' . $transformfunction_name)) {
1203 $transform_function = 'PMA_transformation_' . $transformfunction_name;
1204 $transform_options = PMA_transformation_getOptions((isset($GLOBALS['mime_map'][$meta->name]['transformation_options']) ? $GLOBALS['mime_map'][$meta->name]['transformation_options'] : ''));
1205 $meta->mimetype = str_replace('_', '/', $GLOBALS['mime_map'][$meta->name]['mimetype']);
1207 } // end if file_exists
1208 } // end if transformation is set
1209 } // end if mime/transformation works.
1211 $_url_params = array(
1212 'db' => $db,
1213 'table' => $table,
1214 'primary_key' => $unique_condition,
1215 // $sql_goto ??? typo?
1216 //'goto' => (isset($sql_goto) ? $lnk_goto : ''),
1217 'transform_key' => $meta->name,
1220 if (! empty($sql_query)) {
1221 $_url_params['sql_query'] = $url_sql_query;
1224 $transform_options['wrapper_link'] = PMA_generate_common_url($_url_params);
1226 // n u m e r i c
1227 if ($meta->numeric == 1) {
1229 // lem9: if two fields have the same name (this is possible
1230 // with self-join queries, for example), using $meta->name
1231 // will show both fields NULL even if only one is NULL,
1232 // so use the $pointer
1234 if (!isset($row[$i]) || is_null($row[$i])) {
1235 $vertical_display['data'][$row_no][$i] = ' <td align="right"' . $mouse_events . ' class="' . $class . ($condition_field ? ' condition' : '') . '"><i>NULL</i></td>' . "\n";
1236 } elseif ($row[$i] != '') {
1238 $nowrap = ' nowrap';
1239 $where_comparison = ' = ' . $row[$i];
1241 $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, $transform_options, $default_function, $nowrap, $where_comparison);
1242 } else {
1243 $vertical_display['data'][$row_no][$i] = ' <td align="right"' . $mouse_events . ' class="' . $class . ' nowrap' . ($condition_field ? ' condition' : '') . '">&nbsp;</td>' . "\n";
1246 // b l o b
1248 } elseif (stristr($meta->type, 'BLOB')) {
1249 // loic1 : PMA_mysql_fetch_fields returns BLOB in place of
1250 // TEXT fields type so we have to ensure it's really a BLOB
1251 $field_flags = PMA_DBI_field_flags($dt_result, $i);
1252 if (stristr($field_flags, 'BINARY')) {
1253 $blobtext = PMA_handle_non_printable_contents('BLOB', (isset($row[$i]) ? $row[$i] : ''), $transform_function, $transform_options, $default_function, $meta);
1254 $vertical_display['data'][$row_no][$i] = ' <td align="left"' . $mouse_events . ' class="' . $class . ($condition_field ? ' condition' : '') . '">' . $blobtext . '</td>';
1255 unset($blobtext);
1256 } else {
1257 if (!isset($row[$i]) || is_null($row[$i])) {
1258 $vertical_display['data'][$row_no][$i] = ' <td' . $mouse_events . ' class="' . $class . ($condition_field ? ' condition' : '') . '"><i>NULL</i></td>' . "\n";
1259 } elseif ($row[$i] != '') {
1260 // garvin: if a transform function for blob is set, none of these replacements will be made
1261 if (PMA_strlen($row[$i]) > $GLOBALS['cfg']['LimitChars'] && $_SESSION['userconf']['display_text'] == 'P') {
1262 $row[$i] = PMA_substr($row[$i], 0, $GLOBALS['cfg']['LimitChars']) . '...';
1264 // loic1: displays all space characters, 4 space
1265 // characters for tabulations and <cr>/<lf>
1266 $row[$i] = ($default_function != $transform_function ? $transform_function($row[$i], $transform_options, $meta) : $default_function($row[$i], array(), $meta));
1268 $vertical_display['data'][$row_no][$i] = ' <td' . $mouse_events . ' class="' . $class . ($condition_field ? ' condition' : '') . '">' . $row[$i] . '</td>' . "\n";
1269 } else {
1270 $vertical_display['data'][$row_no][$i] = ' <td' . $mouse_events . ' class="' . $class . ($condition_field ? ' condition' : '') . '">&nbsp;</td>' . "\n";
1273 } else {
1274 if (!isset($row[$i]) || is_null($row[$i])) {
1275 $vertical_display['data'][$row_no][$i] = ' <td' . $mouse_events . ' class="' . $class . ($condition_field ? ' condition' : '') . '"><i>NULL</i></td>' . "\n";
1276 } elseif ($row[$i] != '') {
1277 // loic1: support blanks in the key
1278 $relation_id = $row[$i];
1280 // nijel: Cut all fields to $GLOBALS['cfg']['LimitChars']
1281 // lem9: (unless it's a link-type transformation)
1282 if (PMA_strlen($row[$i]) > $GLOBALS['cfg']['LimitChars'] && $_SESSION['userconf']['display_text'] == 'P' && !strpos($transform_function, 'link') === true) {
1283 $row[$i] = PMA_substr($row[$i], 0, $GLOBALS['cfg']['LimitChars']) . '...';
1286 // loic1: displays special characters from binaries
1287 $field_flags = PMA_DBI_field_flags($dt_result, $i);
1288 if (isset($meta->_type) && $meta->_type === MYSQLI_TYPE_BIT) {
1289 $row[$i] = PMA_printable_bit_value($row[$i], $meta->length);
1290 } elseif (stristr($field_flags, 'BINARY') && $meta->type == 'string') {
1291 if ($_SESSION['userconf']['display_binary']) {
1292 // user asked to see the real contents of BINARY fields
1293 $row[$i] = PMA_replace_binary_contents($row[$i]);
1294 } else {
1295 // we show the BINARY message and field's size
1296 // (or maybe use a transformation)
1297 $row[$i] = PMA_handle_non_printable_contents('BINARY', $row[$i], $transform_function, $transform_options, $default_function, $meta);
1301 // garvin: transform functions may enable no-wrapping:
1302 $function_nowrap = $transform_function . '_nowrap';
1303 $bool_nowrap = (($default_function != $transform_function && function_exists($function_nowrap)) ? $function_nowrap($transform_options) : false);
1305 // loic1: do not wrap if date field type
1306 $nowrap = ((preg_match('@DATE|TIME@i', $meta->type) || $bool_nowrap) ? ' nowrap' : '');
1307 $where_comparison = ' = \'' . PMA_sqlAddslashes($row[$i]) . '\'';
1308 $vertical_display['data'][$row_no][$i] = '<td ' . PMA_prepare_row_data($mouse_events, $class, $condition_field, $analyzed_sql, $meta, $map, $row[$i], $transform_function, $transform_options, $default_function, $nowrap, $where_comparison);
1310 } else {
1311 $vertical_display['data'][$row_no][$i] = ' <td' . $mouse_events . ' class="' . $class . ($condition_field ? ' condition' : '') . '">&nbsp;</td>' . "\n";
1315 // lem9: output stored cell
1316 if ($_SESSION['userconf']['disp_direction'] == 'horizontal'
1317 || $_SESSION['userconf']['disp_direction'] == 'horizontalflipped') {
1318 echo $vertical_display['data'][$row_no][$i];
1321 if (isset($vertical_display['rowdata'][$i][$row_no])) {
1322 $vertical_display['rowdata'][$i][$row_no] .= $vertical_display['data'][$row_no][$i];
1323 } else {
1324 $vertical_display['rowdata'][$i][$row_no] = $vertical_display['data'][$row_no][$i];
1326 } // end for (2)
1328 // 3. Displays the modify/delete links on the right if required
1329 if ($GLOBALS['cfg']['ModifyDeleteAtRight']
1330 && ($_SESSION['userconf']['disp_direction'] == 'horizontal'
1331 || $_SESSION['userconf']['disp_direction'] == 'horizontalflipped')) {
1332 $doWriteModifyAt = 'right';
1333 require './libraries/display_tbl_links.lib.php';
1334 } // end if (3)
1336 if ($_SESSION['userconf']['disp_direction'] == 'horizontal'
1337 || $_SESSION['userconf']['disp_direction'] == 'horizontalflipped') {
1339 </tr>
1340 <?php
1341 } // end if
1343 // 4. Gather links of del_urls and edit_urls in an array for later
1344 // output
1345 if (!isset($vertical_display['edit'][$row_no])) {
1346 $vertical_display['edit'][$row_no] = '';
1347 $vertical_display['delete'][$row_no] = '';
1348 $vertical_display['row_delete'][$row_no] = '';
1351 $column_style_vertical = '';
1352 if ($GLOBALS['cfg']['BrowsePointerEnable'] == true) {
1353 $column_style_vertical .= ' onmouseover="setVerticalPointer(this, ' . $row_no . ', \'over\', \'odd\', \'even\', \'hover\', \'marked\');"'
1354 . ' onmouseout="setVerticalPointer(this, ' . $row_no . ', \'out\', \'odd\', \'even\', \'hover\', \'marked\');"';
1356 $column_marker_vertical = '';
1357 if ($GLOBALS['cfg']['BrowseMarkerEnable'] == true) {
1358 $column_marker_vertical .= 'setVerticalPointer(this, ' . $row_no . ', \'click\', \'odd\', \'even\', \'hover\', \'marked\');';
1361 if (!empty($del_url) && $is_display['del_lnk'] != 'kp') {
1362 $vertical_display['row_delete'][$row_no] .= ' <td align="center" class="' . $class . '" ' . $column_style_vertical . '>' . "\n"
1363 . ' <input type="checkbox" id="id_rows_to_delete' . $row_no . '[%_PMA_CHECKBOX_DIR_%]" name="rows_to_delete[' . $unique_condition_html . ']"'
1364 . ' onclick="' . $column_marker_vertical . 'copyCheckboxesRange(\'rowsDeleteForm\', \'id_rows_to_delete' . $row_no . '\',\'[%_PMA_CHECKBOX_DIR_%]\');"'
1365 . ' value="' . htmlspecialchars($del_query) . '" ' . (isset($GLOBALS['checkall']) ? 'checked="checked"' : '') . ' />' . "\n"
1366 . ' </td>' . "\n";
1367 } else {
1368 unset($vertical_display['row_delete'][$row_no]);
1371 if (isset($edit_url)) {
1372 $vertical_display['edit'][$row_no] .= ' <td align="center" class="' . $class . '" ' . $column_style_vertical . '>' . "\n"
1373 . PMA_linkOrButton($edit_url, $edit_str, array(), false)
1374 . $bookmark_go
1375 . ' </td>' . "\n";
1376 } else {
1377 unset($vertical_display['edit'][$row_no]);
1380 if (isset($del_url)) {
1381 $vertical_display['delete'][$row_no] .= ' <td align="center" class="' . $class . '" ' . $column_style_vertical . '>' . "\n"
1382 . PMA_linkOrButton($del_url, $del_str, (isset($js_conf) ? $js_conf : ''), false)
1383 . ' </td>' . "\n";
1384 } else {
1385 unset($vertical_display['delete'][$row_no]);
1388 echo (($_SESSION['userconf']['disp_direction'] == 'horizontal' || $_SESSION['userconf']['disp_direction'] == 'horizontalflipped') ? "\n" : '');
1389 $row_no++;
1390 } // end while
1392 return true;
1393 } // end of the 'PMA_displayTableBody()' function
1397 * Do display the result table with the vertical direction mode.
1398 * Credits for this feature goes to Garvin Hicking <hicking@faktor-e.de>.
1400 * @return boolean always true
1402 * @uses $_SESSION['userconf']['repeat_cells']
1403 * @global array $vertical_display the information to display
1405 * @access private
1407 * @see PMA_displayTable()
1409 function PMA_displayVerticalTable()
1411 global $vertical_display;
1413 // Displays "multi row delete" link at top if required
1414 if ($GLOBALS['cfg']['ModifyDeleteAtLeft'] && is_array($vertical_display['row_delete']) && (count($vertical_display['row_delete']) > 0 || !empty($vertical_display['textbtn']))) {
1415 echo '<tr>' . "\n";
1416 echo $vertical_display['textbtn'];
1417 $foo_counter = 0;
1418 foreach ($vertical_display['row_delete'] as $val) {
1419 if (($foo_counter != 0) && ($_SESSION['userconf']['repeat_cells'] != 0) && !($foo_counter % $_SESSION['userconf']['repeat_cells'])) {
1420 echo '<th>&nbsp;</th>' . "\n";
1423 echo str_replace('[%_PMA_CHECKBOX_DIR_%]', '', $val);
1424 $foo_counter++;
1425 } // end while
1426 echo '</tr>' . "\n";
1427 } // end if
1429 // Displays "edit" link at top if required
1430 if ($GLOBALS['cfg']['ModifyDeleteAtLeft'] && is_array($vertical_display['edit']) && (count($vertical_display['edit']) > 0 || !empty($vertical_display['textbtn']))) {
1431 echo '<tr>' . "\n";
1432 if (!is_array($vertical_display['row_delete'])) {
1433 echo $vertical_display['textbtn'];
1435 $foo_counter = 0;
1436 foreach ($vertical_display['edit'] as $val) {
1437 if (($foo_counter != 0) && ($_SESSION['userconf']['repeat_cells'] != 0) && !($foo_counter % $_SESSION['userconf']['repeat_cells'])) {
1438 echo ' <th>&nbsp;</th>' . "\n";
1441 echo $val;
1442 $foo_counter++;
1443 } // end while
1444 echo '</tr>' . "\n";
1445 } // end if
1447 // Displays "delete" link at top if required
1448 if ($GLOBALS['cfg']['ModifyDeleteAtLeft'] && is_array($vertical_display['delete']) && (count($vertical_display['delete']) > 0 || !empty($vertical_display['textbtn']))) {
1449 echo '<tr>' . "\n";
1450 if (!is_array($vertical_display['edit']) && !is_array($vertical_display['row_delete'])) {
1451 echo $vertical_display['textbtn'];
1453 $foo_counter = 0;
1454 foreach ($vertical_display['delete'] as $val) {
1455 if (($foo_counter != 0) && ($_SESSION['userconf']['repeat_cells'] != 0) && !($foo_counter % $_SESSION['userconf']['repeat_cells'])) {
1456 echo '<th>&nbsp;</th>' . "\n";
1459 echo $val;
1460 $foo_counter++;
1461 } // end while
1462 echo '</tr>' . "\n";
1463 } // end if
1465 // Displays data
1466 foreach ($vertical_display['desc'] AS $key => $val) {
1468 echo '<tr>' . "\n";
1469 echo $val;
1471 $foo_counter = 0;
1472 foreach ($vertical_display['rowdata'][$key] as $subval) {
1473 if (($foo_counter != 0) && ($_SESSION['userconf']['repeat_cells'] != 0) and !($foo_counter % $_SESSION['userconf']['repeat_cells'])) {
1474 echo $val;
1477 echo $subval;
1478 $foo_counter++;
1479 } // end while
1481 echo '</tr>' . "\n";
1482 } // end while
1484 // Displays "multi row delete" link at bottom if required
1485 if ($GLOBALS['cfg']['ModifyDeleteAtRight'] && is_array($vertical_display['row_delete']) && (count($vertical_display['row_delete']) > 0 || !empty($vertical_display['textbtn']))) {
1486 echo '<tr>' . "\n";
1487 echo $vertical_display['textbtn'];
1488 $foo_counter = 0;
1489 foreach ($vertical_display['row_delete'] as $val) {
1490 if (($foo_counter != 0) && ($_SESSION['userconf']['repeat_cells'] != 0) && !($foo_counter % $_SESSION['userconf']['repeat_cells'])) {
1491 echo '<th>&nbsp;</th>' . "\n";
1494 echo str_replace('[%_PMA_CHECKBOX_DIR_%]', 'r', $val);
1495 $foo_counter++;
1496 } // end while
1497 echo '</tr>' . "\n";
1498 } // end if
1500 // Displays "edit" link at bottom if required
1501 if ($GLOBALS['cfg']['ModifyDeleteAtRight'] && is_array($vertical_display['edit']) && (count($vertical_display['edit']) > 0 || !empty($vertical_display['textbtn']))) {
1502 echo '<tr>' . "\n";
1503 if (!is_array($vertical_display['row_delete'])) {
1504 echo $vertical_display['textbtn'];
1506 $foo_counter = 0;
1507 foreach ($vertical_display['edit'] as $val) {
1508 if (($foo_counter != 0) && ($_SESSION['userconf']['repeat_cells'] != 0) && !($foo_counter % $_SESSION['userconf']['repeat_cells'])) {
1509 echo '<th>&nbsp;</th>' . "\n";
1512 echo $val;
1513 $foo_counter++;
1514 } // end while
1515 echo '</tr>' . "\n";
1516 } // end if
1518 // Displays "delete" link at bottom if required
1519 if ($GLOBALS['cfg']['ModifyDeleteAtRight'] && is_array($vertical_display['delete']) && (count($vertical_display['delete']) > 0 || !empty($vertical_display['textbtn']))) {
1520 echo '<tr>' . "\n";
1521 if (!is_array($vertical_display['edit']) && !is_array($vertical_display['row_delete'])) {
1522 echo $vertical_display['textbtn'];
1524 $foo_counter = 0;
1525 foreach ($vertical_display['delete'] as $val) {
1526 if (($foo_counter != 0) && ($_SESSION['userconf']['repeat_cells'] != 0) && !($foo_counter % $_SESSION['userconf']['repeat_cells'])) {
1527 echo '<th>&nbsp;</th>' . "\n";
1530 echo $val;
1531 $foo_counter++;
1532 } // end while
1533 echo '</tr>' . "\n";
1536 return true;
1537 } // end of the 'PMA_displayVerticalTable' function
1541 * @uses $_SESSION['userconf']['disp_direction']
1542 * @uses $_REQUEST['disp_direction']
1543 * @uses $GLOBALS['cfg']['DefaultDisplay']
1544 * @uses $_SESSION['userconf']['repeat_cells']
1545 * @uses $_REQUEST['repeat_cells']
1546 * @uses $GLOBALS['cfg']['RepeatCells']
1547 * @uses $_SESSION['userconf']['max_rows']
1548 * @uses $_REQUEST['session_max_rows']
1549 * @uses $GLOBALS['cfg']['MaxRows']
1550 * @uses $_SESSION['userconf']['pos']
1551 * @uses $_REQUEST['pos']
1552 * @uses $_SESSION['userconf']['display_text']
1553 * @uses $_REQUEST['display_text']
1554 * @uses $_SESSION['userconf']['relational_display']
1555 * @uses $_REQUEST['relational_display']
1556 * @uses $_SESSION['userconf']['display_binary']
1557 * @uses $_REQUEST['display_binary']
1558 * @uses $_SESSION['userconf']['display_blob']
1559 * @uses $_REQUEST['display_blob']
1560 * @uses PMA_isValid()
1561 * @uses $GLOBALS['sql_query']
1562 * @todo make maximum remembered queries configurable
1563 * @todo move/split into SQL class!?
1564 * @todo currently this is called twice unnecessary
1565 * @todo ignore LIMIT and ORDER in query!?
1567 function PMA_displayTable_checkConfigParams()
1569 $sql_key = md5($GLOBALS['sql_query']);
1571 $_SESSION['userconf']['query'][$sql_key]['sql'] = $GLOBALS['sql_query'];
1573 if (PMA_isValid($_REQUEST['disp_direction'], array('horizontal', 'vertical', 'horizontalflipped'))) {
1574 $_SESSION['userconf']['query'][$sql_key]['disp_direction'] = $_REQUEST['disp_direction'];
1575 unset($_REQUEST['disp_direction']);
1576 } elseif (empty($_SESSION['userconf']['query'][$sql_key]['disp_direction'])) {
1577 $_SESSION['userconf']['query'][$sql_key]['disp_direction'] = $GLOBALS['cfg']['DefaultDisplay'];
1580 if (PMA_isValid($_REQUEST['repeat_cells'], 'numeric')) {
1581 $_SESSION['userconf']['query'][$sql_key]['repeat_cells'] = $_REQUEST['repeat_cells'];
1582 unset($_REQUEST['repeat_cells']);
1583 } elseif (empty($_SESSION['userconf']['query'][$sql_key]['repeat_cells'])) {
1584 $_SESSION['userconf']['query'][$sql_key]['repeat_cells'] = $GLOBALS['cfg']['RepeatCells'];
1587 if (PMA_isValid($_REQUEST['session_max_rows'], 'numeric') || $_REQUEST['session_max_rows'] == 'all') {
1588 $_SESSION['userconf']['query'][$sql_key]['max_rows'] = $_REQUEST['session_max_rows'];
1589 unset($_REQUEST['session_max_rows']);
1590 } elseif (empty($_SESSION['userconf']['query'][$sql_key]['max_rows'])) {
1591 $_SESSION['userconf']['query'][$sql_key]['max_rows'] = $GLOBALS['cfg']['MaxRows'];
1594 if (PMA_isValid($_REQUEST['pos'], 'numeric')) {
1595 $_SESSION['userconf']['query'][$sql_key]['pos'] = $_REQUEST['pos'];
1596 unset($_REQUEST['pos']);
1597 } elseif (empty($_SESSION['userconf']['query'][$sql_key]['pos'])) {
1598 $_SESSION['userconf']['query'][$sql_key]['pos'] = 0;
1601 if (PMA_isValid($_REQUEST['display_text'], array('P', 'F'))) {
1602 $_SESSION['userconf']['query'][$sql_key]['display_text'] = $_REQUEST['display_text'];
1603 unset($_REQUEST['display_text']);
1604 } elseif (empty($_SESSION['userconf']['query'][$sql_key]['display_text'])) {
1605 $_SESSION['userconf']['query'][$sql_key]['display_text'] = 'P';
1608 if (PMA_isValid($_REQUEST['relational_display'], array('K', 'D'))) {
1609 $_SESSION['userconf']['query'][$sql_key]['relational_display'] = $_REQUEST['relational_display'];
1610 unset($_REQUEST['relational_display']);
1611 } elseif (empty($_SESSION['userconf']['query'][$sql_key]['relational_display'])) {
1612 $_SESSION['userconf']['query'][$sql_key]['relational_display'] = 'K';
1615 if (isset($_REQUEST['display_binary'])) {
1616 $_SESSION['userconf']['query'][$sql_key]['display_binary'] = true;
1617 unset($_REQUEST['display_binary']);
1618 } elseif (isset($_REQUEST['display_options_form'])) {
1619 // we know that the checkbox was unchecked
1620 unset($_SESSION['userconf']['query'][$sql_key]['display_binary']);
1623 if (isset($_REQUEST['display_blob'])) {
1624 $_SESSION['userconf']['query'][$sql_key]['display_blob'] = true;
1625 unset($_REQUEST['display_blob']);
1626 } elseif (isset($_REQUEST['display_options_form'])) {
1627 // we know that the checkbox was unchecked
1628 unset($_SESSION['userconf']['query'][$sql_key]['display_blob']);
1631 if (isset($_REQUEST['hide_transformation'])) {
1632 $_SESSION['userconf']['query'][$sql_key]['hide_transformation'] = true;
1633 unset($_REQUEST['hide_transformation']);
1634 } elseif (isset($_REQUEST['display_options_form'])) {
1635 // we know that the checkbox was unchecked
1636 unset($_SESSION['userconf']['query'][$sql_key]['hide_transformation']);
1639 // move current query to the last position, to be removed last
1640 // so only least executed query will be removed if maximum remembered queries
1641 // limit is reached
1642 $tmp = $_SESSION['userconf']['query'][$sql_key];
1643 unset($_SESSION['userconf']['query'][$sql_key]);
1644 $_SESSION['userconf']['query'][$sql_key] = $tmp;
1646 // do not exceed a maximum number of queries to remember
1647 if (count($_SESSION['userconf']['query']) > 10) {
1648 array_shift($_SESSION['userconf']['query']);
1649 //echo 'deleting one element ...';
1652 // populate query configuration
1653 $_SESSION['userconf']['display_text'] = $_SESSION['userconf']['query'][$sql_key]['display_text'];
1654 $_SESSION['userconf']['relational_display'] = $_SESSION['userconf']['query'][$sql_key]['relational_display'];
1655 $_SESSION['userconf']['display_binary'] = isset($_SESSION['userconf']['query'][$sql_key]['display_binary']) ? true : false;
1656 $_SESSION['userconf']['display_blob'] = isset($_SESSION['userconf']['query'][$sql_key]['display_blob']) ? true : false;
1657 $_SESSION['userconf']['hide_transformation'] = isset($_SESSION['userconf']['query'][$sql_key]['hide_transformation']) ? true : false;
1658 $_SESSION['userconf']['pos'] = $_SESSION['userconf']['query'][$sql_key]['pos'];
1659 $_SESSION['userconf']['max_rows'] = $_SESSION['userconf']['query'][$sql_key]['max_rows'];
1660 $_SESSION['userconf']['repeat_cells'] = $_SESSION['userconf']['query'][$sql_key]['repeat_cells'];
1661 $_SESSION['userconf']['disp_direction'] = $_SESSION['userconf']['query'][$sql_key]['disp_direction'];
1664 * debugging
1665 echo '<pre>';
1666 var_dump($_SESSION['userconf']);
1667 echo '</pre>';
1672 * Displays a table of results returned by a SQL query.
1673 * This function is called by the "sql.php" script.
1675 * @param integer the link id associated to the query which results have
1676 * to be displayed
1677 * @param array the display mode
1678 * @param array the analyzed query
1680 * @uses $_SESSION['userconf']['pos']
1681 * @global string $db the database name
1682 * @global string $table the table name
1683 * @global string $goto the URL to go back in case of errors
1684 * @global string $sql_query the current SQL query
1685 * @global integer $num_rows the total number of rows returned by the
1686 * SQL query
1687 * @global integer $unlim_num_rows the total number of rows returned by the
1688 * SQL query without any programmatically
1689 * appended "LIMIT" clause
1690 * @global array $fields_meta the list of fields properties
1691 * @global integer $fields_cnt the total number of fields returned by
1692 * the SQL query
1693 * @global array $vertical_display informations used with vertical display
1694 * mode
1695 * @global array $highlight_columns column names to highlight
1696 * @global array $cfgRelation the relation settings
1698 * @access private
1700 * @see PMA_showMessage(), PMA_setDisplayMode(),
1701 * PMA_displayTableNavigation(), PMA_displayTableHeaders(),
1702 * PMA_displayTableBody(), PMA_displayResultsOperations()
1704 function PMA_displayTable(&$dt_result, &$the_disp_mode, $analyzed_sql)
1706 global $db, $table, $goto;
1707 global $sql_query, $num_rows, $unlim_num_rows, $fields_meta, $fields_cnt;
1708 global $vertical_display, $highlight_columns;
1709 global $cfgRelation;
1710 global $showtable;
1712 // why was this called here? (already called from sql.php)
1713 //PMA_displayTable_checkConfigParams();
1716 * @todo move this to a central place
1717 * @todo for other future table types
1719 $is_innodb = (isset($showtable['Type']) && $showtable['Type'] == 'InnoDB');
1721 if ($is_innodb
1722 && ! isset($analyzed_sql[0]['queryflags']['union'])
1723 && ! isset($analyzed_sql[0]['table_ref'][1]['table_name'])
1724 && (empty($analyzed_sql[0]['where_clause'])
1725 || $analyzed_sql[0]['where_clause'] == '1 ')) {
1726 // "j u s t b r o w s i n g"
1727 $pre_count = '~';
1728 $after_count = PMA_showHint($GLOBALS['strApproximateCount'], true);
1729 } else {
1730 $pre_count = '';
1731 $after_count = '';
1734 // 1. ----- Prepares the work -----
1736 // 1.1 Gets the informations about which functionalities should be
1737 // displayed
1738 $total = '';
1739 $is_display = PMA_setDisplayMode($the_disp_mode, $total);
1741 // 1.2 Defines offsets for the next and previous pages
1742 if ($is_display['nav_bar'] == '1') {
1743 if ($_SESSION['userconf']['max_rows'] == 'all') {
1744 $pos_next = 0;
1745 $pos_prev = 0;
1746 } else {
1747 $pos_next = $_SESSION['userconf']['pos'] + $_SESSION['userconf']['max_rows'];
1748 $pos_prev = $_SESSION['userconf']['pos'] - $_SESSION['userconf']['max_rows'];
1749 if ($pos_prev < 0) {
1750 $pos_prev = 0;
1753 } // end if
1755 // 1.3 URL-encodes the query to use in input form fields
1756 // @todo where is this used?
1757 //$encoded_sql_query = urlencode($sql_query);
1759 // 2. ----- Displays the top of the page -----
1761 // 2.1 Displays a messages with position informations
1762 if ($is_display['nav_bar'] == '1' && isset($pos_next)) {
1763 if (isset($unlim_num_rows) && $unlim_num_rows != $total) {
1764 $selectstring = ', ' . $unlim_num_rows . ' ' . $GLOBALS['strSelectNumRows'];
1765 } else {
1766 $selectstring = '';
1768 $last_shown_rec = ($_SESSION['userconf']['max_rows'] == 'all' || $pos_next > $total)
1769 ? $total - 1
1770 : $pos_next - 1;
1772 if (PMA_Table::isView($db, $table)
1773 && $total == $GLOBALS['cfg']['MaxExactCountViews']) {
1774 $message = PMA_Message::notice('strViewMaxExactCount');
1775 $message->addParam($GLOBALS['cfg']['MaxExactCountViews']);
1776 $message->addParam('[a@./Documentation.html#cfg_MaxExactCount@_blank]');
1777 $message->addParam('[/a]');
1778 $message_view_warning = PMA_showHint($message);
1779 } else {
1780 $message_view_warning = false;
1783 $message = PMA_Message::success('strShowingRecords');
1784 $message->addMessage($_SESSION['userconf']['pos']);
1785 if ($message_view_warning) {
1786 $message->addMessage('...', ' - ');
1787 $message->addMessage($message_view_warning);
1788 $message->addMessage('(');
1789 } else {
1790 $message->addMessage($last_shown_rec, ' - ');
1791 $message->addMessage($pre_count . PMA_formatNumber($total, 0) . $after_count, ' (');
1792 $message->addString('strTotal');
1793 $message->addMessage($selectstring, '');
1794 $message->addMessage(', ', '');
1797 $messagge_qt = PMA_Message::notice('strQueryTime');
1798 $messagge_qt->addParam($GLOBALS['querytime']);
1800 $message->addMessage($messagge_qt, '');
1801 $message->addMessage(')', '');
1803 PMA_showMessage($message, $sql_query, 'success');
1805 } elseif (!isset($GLOBALS['printview']) || $GLOBALS['printview'] != '1') {
1806 PMA_showMessage($GLOBALS['strSuccess'], $sql_query, 'success');
1809 // 2.3 Displays the navigation bars
1810 if (! strlen($table)) {
1811 if (isset($analyzed_sql[0]['query_type'])
1812 && $analyzed_sql[0]['query_type'] == 'SELECT') {
1813 // table does not always contain a real table name,
1814 // for example in MySQL 5.0.x, the query SHOW STATUS
1815 // returns STATUS as a table name
1816 $table = $fields_meta[0]->table;
1817 } else {
1818 $table = '';
1822 if ($is_display['nav_bar'] == '1') {
1823 PMA_displayTableNavigation($pos_next, $pos_prev, $sql_query);
1824 echo "\n";
1825 } elseif (!isset($GLOBALS['printview']) || $GLOBALS['printview'] != '1') {
1826 echo "\n" . '<br /><br />' . "\n";
1829 // 2b ----- Get field references from Database -----
1830 // (see the 'relation' configuration variable)
1831 // loic1, 2002-03-02: extended to php3
1833 // initialize map
1834 $map = array();
1836 // find tables
1837 $target=array();
1838 if (isset($analyzed_sql[0]['table_ref']) && is_array($analyzed_sql[0]['table_ref'])) {
1839 foreach ($analyzed_sql[0]['table_ref'] AS $table_ref_position => $table_ref) {
1840 $target[] = $analyzed_sql[0]['table_ref'][$table_ref_position]['table_true_name'];
1843 $tabs = '(\'' . join('\',\'', $target) . '\')';
1845 if ($cfgRelation['displaywork']) {
1846 if (! strlen($table)) {
1847 $exist_rel = false;
1848 } else {
1849 $exist_rel = PMA_getForeigners($db, $table, '', 'both');
1850 if ($exist_rel) {
1851 foreach ($exist_rel AS $master_field => $rel) {
1852 $display_field = PMA_getDisplayField($rel['foreign_db'], $rel['foreign_table']);
1853 $map[$master_field] = array($rel['foreign_table'],
1854 $rel['foreign_field'],
1855 $display_field,
1856 $rel['foreign_db']);
1857 } // end while
1858 } // end if
1859 } // end if
1860 } // end if
1861 // end 2b
1863 // 3. ----- Displays the results table -----
1864 PMA_displayTableHeaders($is_display, $fields_meta, $fields_cnt, $analyzed_sql);
1865 $url_query = '';
1866 echo '<tbody>' . "\n";
1867 PMA_displayTableBody($dt_result, $is_display, $map, $analyzed_sql);
1868 // vertical output case
1869 if ($_SESSION['userconf']['disp_direction'] == 'vertical') {
1870 PMA_displayVerticalTable();
1871 } // end if
1872 unset($vertical_display);
1873 echo '</tbody>' . "\n";
1875 </table>
1877 <?php
1878 // 4. ----- Displays the link for multi-fields delete
1880 if ($is_display['del_lnk'] == 'dr' && $is_display['del_lnk'] != 'kp') {
1882 $delete_text = $is_display['del_lnk'] == 'dr' ? $GLOBALS['strDelete'] : $GLOBALS['strKill'];
1884 $_url_params = array(
1885 'db' => $db,
1886 'table' => $table,
1887 'sql_query' => $sql_query,
1888 'goto' => $goto,
1890 $uncheckall_url = 'sql.php' . PMA_generate_common_url($_url_params);
1892 $_url_params['checkall'] = '1';
1893 $checkall_url = 'sql.php' . PMA_generate_common_url($_url_params);
1895 if ($_SESSION['userconf']['disp_direction'] == 'vertical') {
1896 $checkall_params['onclick'] = 'if (setCheckboxes(\'rowsDeleteForm\', true)) return false;';
1897 $uncheckall_params['onclick'] = 'if (setCheckboxes(\'rowsDeleteForm\', false)) return false;';
1898 } else {
1899 $checkall_params['onclick'] = 'if (markAllRows(\'rowsDeleteForm\')) return false;';
1900 $uncheckall_params['onclick'] = 'if (unMarkAllRows(\'rowsDeleteForm\')) return false;';
1902 $checkall_link = PMA_linkOrButton($checkall_url, $GLOBALS['strCheckAll'], $checkall_params, false);
1903 $uncheckall_link = PMA_linkOrButton($uncheckall_url, $GLOBALS['strUncheckAll'], $uncheckall_params, false);
1904 if ($_SESSION['userconf']['disp_direction'] != 'vertical') {
1905 echo '<img class="selectallarrow" width="38" height="22"'
1906 .' src="' . $GLOBALS['pmaThemeImage'] . 'arrow_' . $GLOBALS['text_dir'] . '.png' . '"'
1907 .' alt="' . $GLOBALS['strWithChecked'] . '" />';
1909 echo $checkall_link . "\n"
1910 .' / ' . "\n"
1911 .$uncheckall_link . "\n"
1912 .'<i>' . $GLOBALS['strWithChecked'] . '</i>' . "\n";
1914 PMA_buttonOrImage('submit_mult', 'mult_submit',
1915 'submit_mult_change', $GLOBALS['strChange'], 'b_edit.png');
1916 PMA_buttonOrImage('submit_mult', 'mult_submit',
1917 'submit_mult_delete', $delete_text, 'b_drop.png');
1918 if ($analyzed_sql[0]['querytype'] == 'SELECT') {
1919 PMA_buttonOrImage('submit_mult', 'mult_submit',
1920 'submit_mult_export', $GLOBALS['strExport'],
1921 'b_tblexport.png');
1923 echo "\n";
1925 echo '<input type="hidden" name="sql_query"'
1926 .' value="' . htmlspecialchars($sql_query) . '" />' . "\n";
1927 echo '<input type="hidden" name="url_query"'
1928 .' value="' . $GLOBALS['url_query'] . '" />' . "\n";
1929 echo '</form>' . "\n";
1932 // 5. ----- Displays the navigation bar at the bottom if required -----
1934 if ($is_display['nav_bar'] == '1') {
1935 echo '<br />' . "\n";
1936 PMA_displayTableNavigation($pos_next, $pos_prev, $sql_query);
1937 } elseif (!isset($GLOBALS['printview']) || $GLOBALS['printview'] != '1') {
1938 echo "\n" . '<br /><br />' . "\n";
1941 // 6. ----- Displays "Query results operations"
1942 if (!isset($GLOBALS['printview']) || $GLOBALS['printview'] != '1') {
1943 PMA_displayResultsOperations($the_disp_mode, $analyzed_sql);
1945 } // end of the 'PMA_displayTable()' function
1947 function default_function($buffer) {
1948 $buffer = htmlspecialchars($buffer);
1949 $buffer = str_replace("\011", ' &nbsp;&nbsp;&nbsp;',
1950 str_replace(' ', ' &nbsp;', $buffer));
1951 $buffer = preg_replace("@((\015\012)|(\015)|(\012))@", '<br />', $buffer);
1953 return $buffer;
1957 * Displays operations that are available on results.
1959 * @param array the display mode
1960 * @param array the analyzed query
1962 * @uses $_SESSION['userconf']['pos']
1963 * @uses $_SESSION['userconf']['display_text']
1964 * @global string $db the database name
1965 * @global string $table the table name
1966 * @global string $sql_query the current SQL query
1967 * @global integer $unlim_num_rows the total number of rows returned by the
1968 * SQL query without any programmatically
1969 * appended "LIMIT" clause
1971 * @access private
1973 * @see PMA_showMessage(), PMA_setDisplayMode(),
1974 * PMA_displayTableNavigation(), PMA_displayTableHeaders(),
1975 * PMA_displayTableBody(), PMA_displayResultsOperations()
1977 function PMA_displayResultsOperations($the_disp_mode, $analyzed_sql) {
1978 global $db, $table, $sql_query, $unlim_num_rows;
1980 $header_shown = FALSE;
1981 $header = '<fieldset><legend>' . $GLOBALS['strQueryResultsOperations'] . '</legend>';
1983 if ($the_disp_mode[6] == '1' || $the_disp_mode[9] == '1') {
1984 // Displays "printable view" link if required
1985 if ($the_disp_mode[9] == '1') {
1987 if (!$header_shown) {
1988 echo $header;
1989 $header_shown = TRUE;
1992 $_url_params = array(
1993 'db' => $db,
1994 'table' => $table,
1995 'printview' => '1',
1996 'sql_query' => $sql_query,
1998 $url_query = PMA_generate_common_url($_url_params);
2000 echo PMA_linkOrButton(
2001 'sql.php' . $url_query,
2002 PMA_getIcon('b_print.png', $GLOBALS['strPrintView'], false, true),
2003 '', true, true, 'print_view') . "\n";
2005 if ($_SESSION['userconf']['display_text']) {
2006 $_url_params['display_text'] = 'F';
2007 echo PMA_linkOrButton(
2008 'sql.php' . PMA_generate_common_url($_url_params),
2009 PMA_getIcon('b_print.png', $GLOBALS['strPrintViewFull'], false, true),
2010 '', true, true, 'print_view') . "\n";
2011 unset($_url_params['display_text']);
2013 } // end displays "printable view"
2016 // Export link
2017 // (the url_query has extra parameters that won't be used to export)
2018 // (the single_table parameter is used in display_export.lib.php
2019 // to hide the SQL and the structure export dialogs)
2020 // If the parser found a PROCEDURE clause
2021 // (most probably PROCEDURE ANALYSE()) it makes no sense to
2022 // display the Export link).
2023 if (isset($analyzed_sql[0]) && $analyzed_sql[0]['querytype'] == 'SELECT' && !isset($printview) && ! isset($analyzed_sql[0]['queryflags']['procedure'])) {
2024 if (isset($analyzed_sql[0]['table_ref'][0]['table_true_name']) && !isset($analyzed_sql[0]['table_ref'][1]['table_true_name'])) {
2025 $_url_params['single_table'] = 'true';
2027 if (!$header_shown) {
2028 echo $header;
2029 $header_shown = TRUE;
2031 $_url_params['unlim_num_rows'] = $unlim_num_rows;
2032 echo PMA_linkOrButton(
2033 'tbl_export.php' . PMA_generate_common_url($_url_params),
2034 PMA_getIcon('b_tblexport.png', $GLOBALS['strExport'], false, true),
2035 '', true, true, '') . "\n";
2038 // CREATE VIEW
2041 * @todo detect privileges to create a view
2042 * (but see 2006-01-19 note in display_create_table.lib.php,
2043 * I think we cannot detect db-specific privileges reliably)
2044 * Note: we don't display a Create view link if we found a PROCEDURE clause
2046 if (!$header_shown) {
2047 echo $header;
2048 $header_shown = TRUE;
2050 if (! isset($analyzed_sql[0]['queryflags']['procedure'])) {
2051 echo PMA_linkOrButton(
2052 'view_create.php' . $url_query,
2053 PMA_getIcon('b_views.png', 'CREATE VIEW', false, true),
2054 '', true, true, '') . "\n";
2056 if ($header_shown) {
2057 echo '</fieldset><br />';
2062 * Verifies what to do with non-printable contents (binary or BLOB)
2063 * in Browse mode.
2065 * @uses is_null()
2066 * @uses isset()
2067 * @uses strlen()
2068 * @uses PMA_formatByteDown()
2069 * @uses strpos()
2070 * @uses str_replace()
2071 * @param string $category BLOB|BINARY
2072 * @param string $content the binary content
2073 * @param string $transform_function
2074 * @param string $transform_options
2075 * @param string $default_function
2076 * @param object $meta the meta-information about this field
2077 * @return mixed string or float
2079 function PMA_handle_non_printable_contents($category, $content, $transform_function, $transform_options, $default_function, $meta) {
2080 $result = '[' . $category;
2081 if (is_null($content)) {
2082 $result .= ' - NULL';
2083 $size = 0;
2084 } elseif (isset($content)) {
2085 $size = strlen($content);
2086 $display_size = PMA_formatByteDown($size, 3, 1);
2087 $result .= ' - '. $display_size[0] . $display_size[1];
2089 $result .= ']';
2091 if (strpos($transform_function, 'octetstream')) {
2092 $result = $content;
2094 if ($size > 0) {
2095 if ($default_function != $transform_function) {
2096 $result = $transform_function($result, $transform_options, $meta);
2097 } else {
2098 $result = $default_function($result, array(), $meta);
2099 if (stristr($meta->type, 'BLOB') && $_SESSION['userconf']['display_blob']) {
2100 // in this case, restart from the original $content
2101 $result = PMA_replace_binary_contents($content);
2105 return($result);
2109 * Prepares the displayable content of a data cell in Browse mode,
2110 * taking into account foreign key description field and transformations
2112 * @uses is_array()
2113 * @uses PMA_backquote()
2114 * @uses PMA_DBI_try_query()
2115 * @uses PMA_DBI_num_rows()
2116 * @uses PMA_DBI_fetch_row()
2117 * @uses $GLOBALS['strLinkNotFound']
2118 * @uses PMA_DBI_free_result()
2119 * @uses $GLOBALS['printview']
2120 * @uses htmlspecialchars()
2121 * @uses PMA_generate_common_url()
2122 * @param string $mouse_events
2123 * @param string $class
2124 * @param string $condition_field
2125 * @param string $analyzed_sql
2126 * @param object $meta the meta-information about this field
2127 * @param string $map
2128 * @param string $data
2129 * @param string $transform_function
2130 * @param string $transform_options
2131 * @param string $default_function
2132 * @param string $nowrap
2133 * @param string $where_comparison
2134 * @return string formatted data
2136 function PMA_prepare_row_data($mouse_events, $class, $condition_field, $analyzed_sql, $meta, $map, $data, $transform_function, $transform_options, $default_function, $nowrap, $where_comparison) {
2138 // continue the <td> tag started before calling this function:
2139 $result = $mouse_events . ' class="' . $class . ($condition_field ? ' condition' : '') . $nowrap . '">';
2141 if (isset($analyzed_sql[0]['select_expr']) && is_array($analyzed_sql[0]['select_expr'])) {
2142 foreach ($analyzed_sql[0]['select_expr'] AS $select_expr_position => $select_expr) {
2143 $alias = $analyzed_sql[0]['select_expr'][$select_expr_position]['alias'];
2144 if (isset($alias) && strlen($alias)) {
2145 $true_column = $analyzed_sql[0]['select_expr'][$select_expr_position]['column'];
2146 if ($alias == $meta->name) {
2147 // this change in the parameter does not matter
2148 // outside of the function
2149 $meta->name = $true_column;
2150 } // end if
2151 } // end if
2152 } // end foreach
2153 } // end if
2155 if (isset($map[$meta->name])) {
2156 // Field to display from the foreign table?
2157 if (isset($map[$meta->name][2]) && strlen($map[$meta->name][2])) {
2158 $dispsql = 'SELECT ' . PMA_backquote($map[$meta->name][2])
2159 . ' FROM ' . PMA_backquote($map[$meta->name][3])
2160 . '.' . PMA_backquote($map[$meta->name][0])
2161 . ' WHERE ' . PMA_backquote($map[$meta->name][1])
2162 . $where_comparison;
2163 $dispresult = PMA_DBI_try_query($dispsql, null, PMA_DBI_QUERY_STORE);
2164 if ($dispresult && PMA_DBI_num_rows($dispresult) > 0) {
2165 list($dispval) = PMA_DBI_fetch_row($dispresult, 0);
2166 } else {
2167 $dispval = $GLOBALS['strLinkNotFound'];
2169 @PMA_DBI_free_result($dispresult);
2170 } else {
2171 $dispval = '';
2172 } // end if... else...
2174 if (isset($GLOBALS['printview']) && $GLOBALS['printview'] == '1') {
2175 $result .= ($transform_function != $default_function ? $transform_function($data, $transform_options, $meta) : $transform_function($data, array(), $meta)) . ' <code>[-&gt;' . $dispval . ']</code>';
2176 } else {
2178 if ('K' == $_SESSION['userconf']['relational_display']) {
2179 // user chose "relational key" in the display options, so
2180 // the title contains the display field
2181 $title = (! empty($dispval))? ' title="' . htmlspecialchars($dispval) . '"' : '';
2182 } else {
2183 $title = ' title="' . htmlspecialchars($data) . '"';
2186 $_url_params = array(
2187 'db' => $map[$meta->name][3],
2188 'table' => $map[$meta->name][0],
2189 'pos' => '0',
2190 'sql_query' => 'SELECT * FROM '
2191 . PMA_backquote($map[$meta->name][3]) . '.' . PMA_backquote($map[$meta->name][0])
2192 . ' WHERE ' . PMA_backquote($map[$meta->name][1])
2193 . $where_comparison,
2195 $result .= '<a href="sql.php' . PMA_generate_common_url($_url_params)
2196 . '"' . $title . '>';
2198 if ($transform_function != $default_function) {
2199 // always apply a transformation on the real data,
2200 // not on the display field
2201 $result .= $transform_function($data, $transform_options, $meta);
2202 } else {
2203 if ('D' == $_SESSION['userconf']['relational_display']) {
2204 // user chose "relational display field" in the
2205 // display options, so show display field in the cell
2206 $result .= $transform_function($dispval, array(), $meta);
2207 } else {
2208 // otherwise display data in the cell
2209 $result .= $transform_function($data, array(), $meta);
2212 $result .= '</a>';
2214 } else {
2215 $result .= ($transform_function != $default_function ? $transform_function($data, $transform_options, $meta) : $transform_function($data, array(), $meta));
2217 $result .= '</td>' . "\n";
2219 return $result;