BLOB streaming documentation
[phpmyadmin/crack.git] / libraries / display_tbl.lib.php
blob806b49651c0b2ac1c5d03b88aad9db991cc18f0f
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 = '', $sort_expression, $sort_expression_nodirection, $sort_direction)
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'];
469 // Handles the case of multiple clicks on a column's header
470 // which would add many spaces before "ORDER BY" in the
471 // generated query.
472 $unsorted_sql_query = trim($unsorted_sql_query);
474 // sorting by indexes, only if it makes sense (only one table ref)
475 if (isset($analyzed_sql) && isset($analyzed_sql[0]) &&
476 isset($analyzed_sql[0]['querytype']) && $analyzed_sql[0]['querytype'] == 'SELECT' &&
477 isset($analyzed_sql[0]['table_ref']) && count($analyzed_sql[0]['table_ref']) == 1) {
479 // grab indexes data:
480 $indexes = PMA_Index::getFromTable($table, $db);
482 // do we have any index?
483 if ($indexes) {
485 if ($_SESSION['userconf']['disp_direction'] == 'horizontal'
486 || $_SESSION['userconf']['disp_direction'] == 'horizontalflipped') {
487 $span = $fields_cnt;
488 if ($is_display['edit_lnk'] != 'nn') {
489 $span++;
491 if ($is_display['del_lnk'] != 'nn') {
492 $span++;
494 if ($is_display['del_lnk'] != 'kp' && $is_display['del_lnk'] != 'nn') {
495 $span++;
497 } else {
498 $span = $num_rows + floor($num_rows/$_SESSION['userconf']['repeat_cells']) + 1;
501 echo '<form action="sql.php" method="post">' . "\n";
502 echo PMA_generate_common_hidden_inputs($db, $table);
503 echo $GLOBALS['strSortByKey'] . ': <select name="sql_query" onchange="this.form.submit();">' . "\n";
504 $used_index = false;
505 $local_order = (isset($sort_expression) ? $sort_expression : '');
506 foreach ($indexes as $index) {
507 $asc_sort = '`' . implode('` ASC, `', array_keys($index->getColumns())) . '` ASC';
508 $desc_sort = '`' . implode('` DESC, `', array_keys($index->getColumns())) . '` DESC';
509 $used_index = $used_index || $local_order == $asc_sort || $local_order == $desc_sort;
510 echo '<option value="'
511 . htmlspecialchars($unsorted_sql_query . ' ORDER BY ' . $asc_sort)
512 . '"' . ($local_order == $asc_sort ? ' selected="selected"' : '')
513 . '>' . htmlspecialchars($index->getName()) . ' ('
514 . $GLOBALS['strAscending'] . ')</option>';
515 echo '<option value="'
516 . htmlspecialchars($unsorted_sql_query . ' ORDER BY ' . $desc_sort)
517 . '"' . ($local_order == $desc_sort ? ' selected="selected"' : '')
518 . '>' . htmlspecialchars($index->getName()) . ' ('
519 . $GLOBALS['strDescending'] . ')</option>';
521 echo '<option value="' . htmlspecialchars($unsorted_sql_query) . '"' . ($used_index ? '' : ' selected="selected"') . '>' . $GLOBALS['strNone'] . '</option>';
522 echo '</select>' . "\n";
523 echo '<noscript><input type="submit" value="' . $GLOBALS['strGo'] . '" /></noscript>';
524 echo '</form>' . "\n";
530 $vertical_display['emptypre'] = 0;
531 $vertical_display['emptyafter'] = 0;
532 $vertical_display['textbtn'] = '';
534 // Display options (if we are not in print view)
535 if (! (isset($GLOBALS['printview']) && $GLOBALS['printview'] == '1')) {
536 echo '<form method="post" action="sql.php" name="displayOptionsForm" id="displayOptionsForm">';
537 $url_params = array(
538 'db' => $db,
539 'table' => $table,
540 'sql_query' => $sql_query,
541 'goto' => $goto,
542 'display_options_form' => 1
544 echo PMA_generate_common_hidden_inputs($url_params);
545 echo '<br />';
546 PMA_generate_slider_effect('displayoptions',$GLOBALS['strOptions']);
547 echo '<fieldset>';
549 echo '<div class="formelement">';
550 $choices = array(
551 'P' => $GLOBALS['strPartialText'],
552 'F' => $GLOBALS['strFullText']
554 PMA_generate_html_radio('display_text', $choices, $_SESSION['userconf']['display_text']);
555 echo '</div>';
557 if ($GLOBALS['cfgRelation']['relwork']) {
558 echo '<div class="formelement">';
559 $choices = array(
560 'K' => $GLOBALS['strRelationalKey'],
561 'D' => $GLOBALS['strRelationalDisplayField']
563 PMA_generate_html_radio('relational_display', $choices, $_SESSION['userconf']['relational_display']);
564 echo '</div>';
567 echo '<div class="formelement">';
568 PMA_generate_html_checkbox('display_binary', $GLOBALS['strShow'] . ' BINARY', ! empty($_SESSION['userconf']['display_binary']), false);
570 PMA_generate_html_checkbox('display_blob', $GLOBALS['strShow'] . ' BLOB', ! empty($_SESSION['userconf']['display_blob']), false);
571 echo '</div>';
573 // I would have preferred to name this "display_transformation".
574 // This is the only way I found to be able to keep this setting sticky
575 // per SQL query, and at the same time have a default that displays
576 // the transformations.
577 echo '<div class="formelement">';
578 PMA_generate_html_checkbox('hide_transformation', $GLOBALS['strHide'] . ' ' . $GLOBALS['strMIME_transformation'], ! empty($_SESSION['userconf']['hide_transformation']), false);
579 echo '</div>';
581 echo '<div class="clearfloat"></div>';
582 echo '</fieldset>';
584 echo '<fieldset class="tblFooters">';
585 echo '<input type="submit" value="' . $GLOBALS['strGo'] . '" />';
586 echo '</fieldset>';
587 echo '</div>';
588 echo '</form>';
591 // Start of form for multi-rows edit/delete/export
593 if ($is_display['del_lnk'] == 'dr' || $is_display['del_lnk'] == 'kp') {
594 echo '<form method="post" action="tbl_row_action.php" name="rowsDeleteForm" id="rowsDeleteForm">' . "\n";
595 echo PMA_generate_common_hidden_inputs($db, $table, 1);
596 echo '<input type="hidden" name="goto" value="sql.php" />' . "\n";
599 echo '<table id="table_results" class="data">' . "\n";
600 if ($_SESSION['userconf']['disp_direction'] == 'horizontal'
601 || $_SESSION['userconf']['disp_direction'] == 'horizontalflipped') {
602 echo '<thead><tr>' . "\n";
605 // 1. Displays the full/partial text button (part 1)...
606 if ($_SESSION['userconf']['disp_direction'] == 'horizontal'
607 || $_SESSION['userconf']['disp_direction'] == 'horizontalflipped') {
608 $colspan = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn')
609 ? ' colspan="3"'
610 : '';
611 } else {
612 $rowspan = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn')
613 ? ' rowspan="3"'
614 : '';
617 // ... before the result table
618 if (($is_display['edit_lnk'] == 'nn' && $is_display['del_lnk'] == 'nn')
619 && $is_display['text_btn'] == '1') {
620 $vertical_display['emptypre'] = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn') ? 3 : 0;
621 if ($_SESSION['userconf']['disp_direction'] == 'horizontal'
622 || $_SESSION['userconf']['disp_direction'] == 'horizontalflipped') {
624 <th colspan="<?php echo $fields_cnt; ?>"></th>
625 </tr>
626 <tr>
627 <?php
628 } // end horizontal/horizontalflipped mode
629 else {
631 <tr>
632 <th colspan="<?php echo $num_rows + floor($num_rows/$_SESSION['userconf']['repeat_cells']) + 1; ?>"></th>
633 </tr>
634 <?php
635 } // end vertical mode
638 // ... at the left column of the result table header if possible
639 // and required
640 elseif ($GLOBALS['cfg']['ModifyDeleteAtLeft'] && $is_display['text_btn'] == '1') {
641 $vertical_display['emptypre'] = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn') ? 3 : 0;
642 if ($_SESSION['userconf']['disp_direction'] == 'horizontal'
643 || $_SESSION['userconf']['disp_direction'] == 'horizontalflipped') {
645 <th <?php echo $colspan; ?>></th>
646 <?php
647 } // end horizontal/horizontalflipped mode
648 else {
649 $vertical_display['textbtn'] = ' <th ' . $rowspan . ' valign="middle">' . "\n"
650 . ' ' . "\n"
651 . ' </th>' . "\n";
652 } // end vertical mode
655 // ... elseif no button, displays empty(ies) col(s) if required
656 elseif ($GLOBALS['cfg']['ModifyDeleteAtLeft']
657 && ($is_display['edit_lnk'] != 'nn' || $is_display['del_lnk'] != 'nn')) {
658 $vertical_display['emptypre'] = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn') ? 3 : 0;
659 if ($_SESSION['userconf']['disp_direction'] == 'horizontal'
660 || $_SESSION['userconf']['disp_direction'] == 'horizontalflipped') {
662 <td<?php echo $colspan; ?>></td>
663 <?php
664 } // end horizontal/horizontalfipped mode
665 else {
666 $vertical_display['textbtn'] = ' <td' . $rowspan . '></td>' . "\n";
667 } // end vertical mode
670 // 2. Displays the fields' name
671 // 2.0 If sorting links should be used, checks if the query is a "JOIN"
672 // statement (see 2.1.3)
674 // 2.0.1 Prepare Display column comments if enabled ($GLOBALS['cfg']['ShowBrowseComments']).
675 // Do not show comments, if using horizontalflipped mode, because of space usage
676 if ($GLOBALS['cfg']['ShowBrowseComments']
677 && $_SESSION['userconf']['disp_direction'] != 'horizontalflipped') {
678 $comments_map = array();
679 if (isset($analyzed_sql[0]) && is_array($analyzed_sql[0])) {
680 foreach ($analyzed_sql[0]['table_ref'] as $tbl) {
681 $tb = $tbl['table_true_name'];
682 $comments_map[$tb] = PMA_getComments($db, $tb);
683 unset($tb);
688 if ($GLOBALS['cfgRelation']['commwork'] && $GLOBALS['cfgRelation']['mimework'] && $GLOBALS['cfg']['BrowseMIME'] && ! $_SESSION['userconf']['hide_transformation']) {
689 require_once './libraries/transformations.lib.php';
690 $GLOBALS['mime_map'] = PMA_getMIME($db, $table);
693 if ($is_display['sort_lnk'] == '1') {
694 $select_expr = $analyzed_sql[0]['select_expr_clause'];
697 // garvin: See if we have to highlight any header fields of a WHERE query.
698 // Uses SQL-Parser results.
699 $highlight_columns = array();
700 if (isset($analyzed_sql) && isset($analyzed_sql[0]) &&
701 isset($analyzed_sql[0]['where_clause_identifiers'])) {
703 $wi = 0;
704 if (isset($analyzed_sql[0]['where_clause_identifiers']) && is_array($analyzed_sql[0]['where_clause_identifiers'])) {
705 foreach ($analyzed_sql[0]['where_clause_identifiers'] AS $wci_nr => $wci) {
706 $highlight_columns[$wci] = 'true';
711 for ($i = 0; $i < $fields_cnt; $i++) {
712 // garvin: See if this column should get highlight because it's used in the
713 // where-query.
714 if (isset($highlight_columns[$fields_meta[$i]->name]) || isset($highlight_columns[PMA_backquote($fields_meta[$i]->name)])) {
715 $condition_field = true;
716 } else {
717 $condition_field = false;
720 // 2.0 Prepare comment-HTML-wrappers for each row, if defined/enabled.
721 if (isset($comments_map) &&
722 isset($comments_map[$fields_meta[$i]->table]) &&
723 isset($comments_map[$fields_meta[$i]->table][$fields_meta[$i]->name])) {
724 $comments = '<span class="tblcomment">' . htmlspecialchars($comments_map[$fields_meta[$i]->table][$fields_meta[$i]->name]) . '</span>';
725 } else {
726 $comments = '';
729 // 2.1 Results can be sorted
730 if ($is_display['sort_lnk'] == '1') {
732 // 2.1.1 Checks if the table name is required; it's the case
733 // for a query with a "JOIN" statement and if the column
734 // isn't aliased, or in queries like
735 // SELECT `1`.`master_field` , `2`.`master_field`
736 // FROM `PMA_relation` AS `1` , `PMA_relation` AS `2`
738 if (isset($fields_meta[$i]->table) && strlen($fields_meta[$i]->table)) {
739 $sort_tbl = PMA_backquote($fields_meta[$i]->table) . '.';
740 } else {
741 $sort_tbl = '';
744 // 2.1.2 Checks if the current column is used to sort the
745 // results
746 // the orgname member does not exist for all MySQL versions
747 // but if found, it's the one on which to sort
748 $name_to_use_in_sort = $fields_meta[$i]->name;
749 if (isset($fields_meta[$i]->orgname)) {
750 $name_to_use_in_sort = $fields_meta[$i]->orgname;
752 // $name_to_use_in_sort might contain a space due to
753 // formatting of function expressions like "COUNT(name )"
754 // so we remove the space in this situation
755 $name_to_use_in_sort = str_replace(' )', ')', $name_to_use_in_sort);
757 if (empty($sort_expression)) {
758 $is_in_sort = false;
759 } else {
760 // field name may be preceded by a space, or any number
761 // of characters followed by a dot (tablename.fieldname)
762 // so do a direct comparison
763 // for the sort expression (avoids problems with queries
764 // like "SELECT id, count(id)..." and clicking to sort
765 // on id or on count(id))
766 $is_in_sort = (str_replace('`', '', $sort_tbl) . $name_to_use_in_sort == str_replace('`', '', $sort_expression_nodirection) ? true : false);
768 // 2.1.3 Check the field name for a bracket.
769 // If it contains one, it's probably a function column
770 // like 'COUNT(`field`)'
771 if (strpos($name_to_use_in_sort, '(') !== false) {
772 $sort_order = ' ORDER BY ' . $name_to_use_in_sort . ' ';
773 } else {
774 $sort_order = ' ORDER BY ' . $sort_tbl . PMA_backquote($name_to_use_in_sort) . ' ';
776 unset($name_to_use_in_sort);
778 // 2.1.4 Do define the sorting URL
779 if (! $is_in_sort) {
780 // loic1: patch #455484 ("Smart" order)
781 $GLOBALS['cfg']['Order'] = strtoupper($GLOBALS['cfg']['Order']);
782 if ($GLOBALS['cfg']['Order'] === 'SMART') {
783 $sort_order .= (preg_match('@time|date@i', $fields_meta[$i]->type)) ? 'DESC' : 'ASC';
784 } else {
785 $sort_order .= $GLOBALS['cfg']['Order'];
787 $order_img = '';
788 } elseif ('DESC' == $sort_direction) {
789 $sort_order .= ' ASC';
790 $order_img = ' <img class="icon" src="' . $GLOBALS['pmaThemeImage'] . 's_desc.png" width="11" height="9" alt="'. $GLOBALS['strDescending'] . '" title="'. $GLOBALS['strDescending'] . '" id="soimg' . $i . '" />';
791 } else {
792 $sort_order .= ' DESC';
793 $order_img = ' <img class="icon" src="' . $GLOBALS['pmaThemeImage'] . 's_asc.png" width="11" height="9" alt="'. $GLOBALS['strAscending'] . '" title="'. $GLOBALS['strAscending'] . '" id="soimg' . $i . '" />';
796 if (preg_match('@(.*)([[:space:]](LIMIT (.*)|PROCEDURE (.*)|FOR UPDATE|LOCK IN SHARE MODE))@i', $unsorted_sql_query, $regs3)) {
797 $sorted_sql_query = $regs3[1] . $sort_order . $regs3[2];
798 } else {
799 $sorted_sql_query = $unsorted_sql_query . $sort_order;
801 $_url_params = array(
802 'db' => $db,
803 'table' => $table,
804 'sql_query' => $sorted_sql_query,
806 $order_url = 'sql.php' . PMA_generate_common_url($_url_params);
808 // 2.1.5 Displays the sorting URL
809 // added 20004-06-09: Michael Keck <mail@michaelkeck.de>
810 // enable sort order swapping for image
811 $order_link_params = array();
812 if (isset($order_img) && $order_img!='') {
813 if (strstr($order_img, 'asc')) {
814 $order_link_params['onmouseover'] = 'if(document.getElementById(\'soimg' . $i . '\')){ document.getElementById(\'soimg' . $i . '\').src=\'' . $GLOBALS['pmaThemeImage'] . 's_desc.png\'; }';
815 $order_link_params['onmouseout'] = 'if(document.getElementById(\'soimg' . $i . '\')){ document.getElementById(\'soimg' . $i . '\').src=\'' . $GLOBALS['pmaThemeImage'] . 's_asc.png\'; }';
816 } elseif (strstr($order_img, 'desc')) {
817 $order_link_params['onmouseover'] = 'if(document.getElementById(\'soimg' . $i . '\')){ document.getElementById(\'soimg' . $i . '\').src=\'' . $GLOBALS['pmaThemeImage'] . 's_asc.png\'; }';
818 $order_link_params['onmouseout'] = 'if(document.getElementById(\'soimg' . $i . '\')){ document.getElementById(\'soimg' . $i . '\').src=\'' . $GLOBALS['pmaThemeImage'] . 's_desc.png\'; }';
821 if ($_SESSION['userconf']['disp_direction'] == 'horizontalflipped'
822 && $GLOBALS['cfg']['HeaderFlipType'] == 'css') {
823 $order_link_params['style'] = 'direction: ltr; writing-mode: tb-rl;';
825 $order_link_params['title'] = $GLOBALS['strSort'];
826 $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));
827 $order_link = PMA_linkOrButton($order_url, $order_link_content . $order_img, $order_link_params, false, true);
829 if ($_SESSION['userconf']['disp_direction'] == 'horizontal'
830 || $_SESSION['userconf']['disp_direction'] == 'horizontalflipped') {
831 echo '<th';
832 if ($condition_field) {
833 echo ' class="condition"';
835 if ($_SESSION['userconf']['disp_direction'] == 'horizontalflipped') {
836 echo ' valign="bottom"';
838 echo '>' . $order_link . $comments . '</th>';
840 $vertical_display['desc'][] = ' <th '
841 . ($condition_field ? ' class="condition"' : '') . '>' . "\n"
842 . $order_link . $comments . ' </th>' . "\n";
843 } // end if (2.1)
845 // 2.2 Results can't be sorted
846 else {
847 if ($_SESSION['userconf']['disp_direction'] == 'horizontal'
848 || $_SESSION['userconf']['disp_direction'] == 'horizontalflipped') {
849 echo '<th';
850 if ($condition_field) {
851 echo ' class="condition"';
853 if ($_SESSION['userconf']['disp_direction'] == 'horizontalflipped') {
854 echo ' valign="bottom"';
856 if ($_SESSION['userconf']['disp_direction'] == 'horizontalflipped'
857 && $GLOBALS['cfg']['HeaderFlipType'] == 'css') {
858 echo ' style="direction: ltr; writing-mode: tb-rl;"';
860 echo '>';
861 if ($_SESSION['userconf']['disp_direction'] == 'horizontalflipped'
862 && $GLOBALS['cfg']['HeaderFlipType'] == 'fake') {
863 echo PMA_flipstring(htmlspecialchars($fields_meta[$i]->name), '<br />');
864 } else {
865 echo htmlspecialchars($fields_meta[$i]->name);
867 echo "\n" . $comments . '</th>';
869 $vertical_display['desc'][] = ' <th '
870 . ($condition_field ? ' class="condition"' : '') . '>' . "\n"
871 . ' ' . htmlspecialchars($fields_meta[$i]->name) . "\n"
872 . $comments . ' </th>';
873 } // end else (2.2)
874 } // end for
876 // 3. Displays the needed checkboxes at the right
877 // column of the result table header if possible and required...
878 if ($GLOBALS['cfg']['ModifyDeleteAtRight']
879 && ($is_display['edit_lnk'] != 'nn' || $is_display['del_lnk'] != 'nn')
880 && $is_display['text_btn'] == '1') {
881 $vertical_display['emptyafter'] = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn') ? 3 : 1;
882 if ($_SESSION['userconf']['disp_direction'] == 'horizontal'
883 || $_SESSION['userconf']['disp_direction'] == 'horizontalflipped') {
884 echo "\n";
886 <th <?php echo $colspan; ?>>
887 </th>
888 <?php
889 } // end horizontal/horizontalflipped mode
890 else {
891 $vertical_display['textbtn'] = ' <th ' . $rowspan . ' valign="middle">' . "\n"
892 . ' ' . "\n"
893 . ' </th>' . "\n";
894 } // end vertical mode
897 // ... elseif no button, displays empty columns if required
898 // (unless coming from Browse mode print view)
899 elseif ($GLOBALS['cfg']['ModifyDeleteAtRight']
900 && ($is_display['edit_lnk'] == 'nn' && $is_display['del_lnk'] == 'nn')
901 && (!$GLOBALS['is_header_sent'])) {
902 $vertical_display['emptyafter'] = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn') ? 3 : 1;
903 if ($_SESSION['userconf']['disp_direction'] == 'horizontal'
904 || $_SESSION['userconf']['disp_direction'] == 'horizontalflipped') {
905 echo "\n";
907 <td<?php echo $colspan; ?>></td>
908 <?php
909 } // end horizontal/horizontalflipped mode
910 else {
911 $vertical_display['textbtn'] = ' <td' . $rowspan . '></td>' . "\n";
912 } // end vertical mode
915 if ($_SESSION['userconf']['disp_direction'] == 'horizontal'
916 || $_SESSION['userconf']['disp_direction'] == 'horizontalflipped') {
918 </tr>
919 </thead>
920 <?php
923 return true;
924 } // end of the 'PMA_displayTableHeaders()' function
929 * Displays the body of the results table
931 * @uses $_SESSION['userconf']['disp_direction']
932 * @uses $_SESSION['userconf']['repeat_cells']
933 * @uses $_SESSION['userconf']['max_rows']
934 * @uses $_SESSION['userconf']['display_text']
935 * @uses $_SESSION['userconf']['display_binary']
936 * @uses $_SESSION['userconf']['display_blob']
937 * @param integer the link id associated to the query which results have
938 * to be displayed
939 * @param array which elements to display
940 * @param array the list of relations
941 * @param array the analyzed query
943 * @return boolean always true
945 * @global string $db the database name
946 * @global string $table the table name
947 * @global string $goto the URL to go back in case of errors
948 * @global string $sql_query the SQL query
949 * @global array $fields_meta the list of fields properties
950 * @global integer $fields_cnt the total number of fields returned by
951 * the SQL query
952 * @global array $vertical_display informations used with vertical display
953 * mode
954 * @global array $highlight_columns column names to highlight
955 * @global array $row current row data
957 * @access private
959 * @see PMA_displayTable()
961 function PMA_displayTableBody(&$dt_result, &$is_display, $map, $analyzed_sql) {
962 global $db, $table, $goto;
963 global $sql_query, $fields_meta, $fields_cnt;
964 global $vertical_display, $highlight_columns;
965 global $row; // mostly because of browser transformations, to make the row-data accessible in a plugin
967 $url_sql_query = $sql_query;
969 // query without conditions to shorten URLs when needed, 200 is just
970 // guess, it should depend on remaining URL length
972 if (isset($analyzed_sql) && isset($analyzed_sql[0]) &&
973 isset($analyzed_sql[0]['querytype']) && $analyzed_sql[0]['querytype'] == 'SELECT' &&
974 strlen($sql_query) > 200) {
976 $url_sql_query = 'SELECT ';
977 if (isset($analyzed_sql[0]['queryflags']['distinct'])) {
978 $url_sql_query .= ' DISTINCT ';
980 $url_sql_query .= $analyzed_sql[0]['select_expr_clause'];
981 if (!empty($analyzed_sql[0]['from_clause'])) {
982 $url_sql_query .= ' FROM ' . $analyzed_sql[0]['from_clause'];
986 if (!is_array($map)) {
987 $map = array();
989 $row_no = 0;
990 $vertical_display['edit'] = array();
991 $vertical_display['delete'] = array();
992 $vertical_display['data'] = array();
993 $vertical_display['row_delete'] = array();
995 // Correction University of Virginia 19991216 in the while below
996 // Previous code assumed that all tables have keys, specifically that
997 // the phpMyAdmin GUI should support row delete/edit only for such
998 // tables.
999 // Although always using keys is arguably the prescribed way of
1000 // defining a relational table, it is not required. This will in
1001 // particular be violated by the novice.
1002 // We want to encourage phpMyAdmin usage by such novices. So the code
1003 // below has been changed to conditionally work as before when the
1004 // table being displayed has one or more keys; but to display
1005 // delete/edit options correctly for tables without keys.
1007 $odd_row = true;
1008 while ($row = PMA_DBI_fetch_row($dt_result)) {
1009 // lem9: "vertical display" mode stuff
1010 if ($row_no != 0 && $_SESSION['userconf']['repeat_cells'] != 0 && !($row_no % $_SESSION['userconf']['repeat_cells'])
1011 && ($_SESSION['userconf']['disp_direction'] == 'horizontal'
1012 || $_SESSION['userconf']['disp_direction'] == 'horizontalflipped'))
1014 echo '<tr>' . "\n";
1015 if ($vertical_display['emptypre'] > 0) {
1016 echo ' <th colspan="' . $vertical_display['emptypre'] . '">' . "\n"
1017 .' &nbsp;</th>' . "\n";
1020 foreach ($vertical_display['desc'] as $val) {
1021 echo $val;
1024 if ($vertical_display['emptyafter'] > 0) {
1025 echo ' <th colspan="' . $vertical_display['emptyafter'] . '">' . "\n"
1026 .' &nbsp;</th>' . "\n";
1028 echo '</tr>' . "\n";
1029 } // end if
1031 $class = $odd_row ? 'odd' : 'even';
1032 $odd_row = ! $odd_row;
1033 if ($_SESSION['userconf']['disp_direction'] == 'horizontal'
1034 || $_SESSION['userconf']['disp_direction'] == 'horizontalflipped') {
1035 // loic1: pointer code part
1036 echo ' <tr class="' . $class . '">' . "\n";
1037 $class = '';
1041 // 1. Prepares the row (gets primary keys to use)
1042 // 1.1 Results from a "SELECT" statement -> builds the
1043 // "primary" key to use in links
1045 * @todo $unique_condition could be empty, for example a table
1046 * with only one field and it's a BLOB; in this case,
1047 * avoid to display the delete and edit links
1049 $unique_condition = PMA_getUniqueCondition($dt_result, $fields_cnt, $fields_meta, $row);
1050 $unique_condition_html = htmlspecialchars($unique_condition);
1052 // 1.2 Defines the URLs for the modify/delete link(s)
1054 if ($is_display['edit_lnk'] != 'nn' || $is_display['del_lnk'] != 'nn') {
1055 // We need to copy the value or else the == 'both' check will always return true
1057 if ($GLOBALS['cfg']['PropertiesIconic'] === 'both') {
1058 $iconic_spacer = '<div class="nowrap">';
1059 } else {
1060 $iconic_spacer = '';
1063 // 1.2.1 Modify link(s)
1064 if ($is_display['edit_lnk'] == 'ur') { // update row case
1065 $_url_params = array(
1066 'db' => $db,
1067 'table' => $table,
1068 'primary_key' => $unique_condition,
1069 'sql_query' => $url_sql_query,
1070 'goto' => 'sql.php',
1072 $edit_url = 'tbl_change.php' . PMA_generate_common_url($_url_params);
1074 $edit_str = PMA_getIcon('b_edit.png', $GLOBALS['strEdit'], true);
1075 } // end if (1.2.1)
1077 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])) {
1078 $_url_params = array(
1079 'db' => $row[1],
1080 'id_bookmark' => $row[0],
1081 'action_bookmark' => '0',
1082 'action_bookmark_all' => '1',
1083 'SQL' => $GLOBALS['strExecuteBookmarked'],
1085 $bookmark_go = '<a href="import.php'
1086 . PMA_generate_common_url($_url_params)
1087 .' " title="' . $GLOBALS['strExecuteBookmarked'] . '">';
1089 $bookmark_go .= PMA_getIcon('b_bookmark.png', $GLOBALS['strExecuteBookmarked'], true);
1091 $bookmark_go .= '</a>';
1092 } else {
1093 $bookmark_go = '';
1096 // 1.2.2 Delete/Kill link(s)
1097 if ($is_display['del_lnk'] == 'dr') { // delete row case
1098 $_url_params = array(
1099 'db' => $db,
1100 'table' => $table,
1101 'sql_query' => $url_sql_query,
1102 'zero_rows' => $GLOBALS['strDeleted'],
1103 'goto' => (empty($goto) ? 'tbl_sql.php' : $goto),
1105 $lnk_goto = 'sql.php' . PMA_generate_common_url($_url_params, 'text');
1107 $del_query = 'DELETE FROM ' . PMA_backquote($db) . '.' . PMA_backquote($table)
1108 . ' WHERE' . $unique_condition . ' LIMIT 1';
1110 $_url_params = array(
1111 'db' => $db,
1112 'table' => $table,
1113 'sql_query' => $del_query,
1114 'zero_rows' => $GLOBALS['strDeleted'],
1115 'goto' => $lnk_goto,
1117 $del_url = 'sql.php' . PMA_generate_common_url($_url_params);
1119 $js_conf = 'DELETE FROM ' . PMA_jsFormat($db) . '.' . PMA_jsFormat($table)
1120 . ' WHERE ' . trim(PMA_jsFormat($unique_condition, false))
1121 . ' LIMIT 1';
1122 $del_str = PMA_getIcon('b_drop.png', $GLOBALS['strDelete'], true);
1123 } elseif ($is_display['del_lnk'] == 'kp') { // kill process case
1125 $_url_params = array(
1126 'db' => $db,
1127 'table' => $table,
1128 'sql_query' => $url_sql_query,
1129 'goto' => 'main.php',
1131 $lnk_goto = 'sql.php' . PMA_generate_common_url($_url_params, 'text');
1133 $_url_params = array(
1134 'db' => 'mysql',
1135 'sql_query' => 'KILL ' . $row[0],
1136 'goto' => $lnk_goto,
1138 $del_url = 'sql.php' . PMA_generate_common_url($_url_params);
1139 $del_query = 'KILL ' . $row[0];
1140 $js_conf = 'KILL ' . $row[0];
1141 $del_str = PMA_getIcon('b_drop.png', $GLOBALS['strKill'], true);
1142 } // end if (1.2.2)
1144 // 1.3 Displays the links at left if required
1145 if ($GLOBALS['cfg']['ModifyDeleteAtLeft']
1146 && ($_SESSION['userconf']['disp_direction'] == 'horizontal'
1147 || $_SESSION['userconf']['disp_direction'] == 'horizontalflipped')) {
1148 $doWriteModifyAt = 'left';
1149 require './libraries/display_tbl_links.lib.php';
1150 } // end if (1.3)
1151 } // end if (1)
1153 // 2. Displays the rows' values
1154 for ($i = 0; $i < $fields_cnt; ++$i) {
1155 $meta = $fields_meta[$i];
1156 $pointer = $i;
1157 // garvin: See if this column should get highlight because it's used in the
1158 // where-query.
1159 if (isset($highlight_columns) && (isset($highlight_columns[$meta->name]) || isset($highlight_columns[PMA_backquote($meta->name)]))) {
1160 $condition_field = true;
1161 } else {
1162 $condition_field = false;
1165 $mouse_events = '';
1166 if ($_SESSION['userconf']['disp_direction'] == 'vertical' && (!isset($GLOBALS['printview']) || ($GLOBALS['printview'] != '1'))) {
1167 if ($GLOBALS['cfg']['BrowsePointerEnable'] == true) {
1168 $mouse_events .= ' onmouseover="setVerticalPointer(this, ' . $row_no . ', \'over\', \'odd\', \'even\', \'hover\', \'marked\');"'
1169 . ' onmouseout="setVerticalPointer(this, ' . $row_no . ', \'out\', \'odd\', \'even\', \'hover\', \'marked\');" ';
1171 if ($GLOBALS['cfg']['BrowseMarkerEnable'] == true) {
1172 $mouse_events .= ' onmousedown="setVerticalPointer(this, ' . $row_no . ', \'click\', \'odd\', \'even\', \'hover\', \'marked\'); setCheckboxColumn(\'id_rows_to_delete' . $row_no . '\');" ';
1173 } else {
1174 $mouse_events .= ' onmousedown="setCheckboxColumn(\'id_rows_to_delete' . $row_no . '\');" ';
1176 }// end if
1178 // garvin: Wrap MIME-transformations. [MIME]
1179 $default_function = 'default_function'; // default_function
1180 $transform_function = $default_function;
1181 $transform_options = array();
1183 if ($GLOBALS['cfgRelation']['mimework'] && $GLOBALS['cfg']['BrowseMIME']) {
1185 if (isset($GLOBALS['mime_map'][$meta->name]['mimetype']) && isset($GLOBALS['mime_map'][$meta->name]['transformation']) && !empty($GLOBALS['mime_map'][$meta->name]['transformation'])) {
1186 $include_file = $GLOBALS['mime_map'][$meta->name]['transformation'];
1188 if (file_exists('./libraries/transformations/' . $include_file)) {
1189 $transformfunction_name = str_replace('.inc.php', '', $GLOBALS['mime_map'][$meta->name]['transformation']);
1191 require_once './libraries/transformations/' . $include_file;
1193 if (function_exists('PMA_transformation_' . $transformfunction_name)) {
1194 $transform_function = 'PMA_transformation_' . $transformfunction_name;
1195 $transform_options = PMA_transformation_getOptions((isset($GLOBALS['mime_map'][$meta->name]['transformation_options']) ? $GLOBALS['mime_map'][$meta->name]['transformation_options'] : ''));
1196 $meta->mimetype = str_replace('_', '/', $GLOBALS['mime_map'][$meta->name]['mimetype']);
1198 } // end if file_exists
1199 } // end if transformation is set
1200 } // end if mime/transformation works.
1202 $_url_params = array(
1203 'db' => $db,
1204 'table' => $table,
1205 'primary_key' => $unique_condition,
1206 'transform_key' => $meta->name,
1209 if (! empty($sql_query)) {
1210 $_url_params['sql_query'] = $url_sql_query;
1213 $transform_options['wrapper_link'] = PMA_generate_common_url($_url_params);
1215 // n u m e r i c
1216 if ($meta->numeric == 1) {
1218 // lem9: if two fields have the same name (this is possible
1219 // with self-join queries, for example), using $meta->name
1220 // will show both fields NULL even if only one is NULL,
1221 // so use the $pointer
1223 if (!isset($row[$i]) || is_null($row[$i])) {
1224 $vertical_display['data'][$row_no][$i] = ' <td align="right"' . $mouse_events . ' class="' . $class . ($condition_field ? ' condition' : '') . '"><i>NULL</i></td>' . "\n";
1225 } elseif ($row[$i] != '') {
1227 $nowrap = ' nowrap';
1228 $where_comparison = ' = ' . $row[$i];
1230 $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);
1231 } else {
1232 $vertical_display['data'][$row_no][$i] = ' <td align="right"' . $mouse_events . ' class="' . $class . ' nowrap' . ($condition_field ? ' condition' : '') . '">&nbsp;</td>' . "\n";
1235 // b l o b
1237 } elseif (stristr($meta->type, 'BLOB')) {
1238 // loic1 : PMA_mysql_fetch_fields returns BLOB in place of
1239 // TEXT fields type so we have to ensure it's really a BLOB
1240 $field_flags = PMA_DBI_field_flags($dt_result, $i);
1241 if (stristr($field_flags, 'BINARY')) {
1242 // rajk - for blobstreaming
1244 $bs_reference_exists = $allBSTablesExist = FALSE;
1246 // load PMA configuration
1247 $PMA_Config = $_SESSION['PMA_Config'];
1249 // if PMA configuration exists
1250 if ($PMA_Config)
1252 // load BS variables
1253 $pluginsExist = $PMA_Config->get('BLOBSTREAMING_PLUGINS_EXIST');
1255 // if BS plugins exist
1256 if ($pluginsExist)
1258 // load BS databases
1259 $bs_tables = $PMA_Config->get('BLOBSTREAMABLE_DATABASES');
1261 // if BS db array and specified db string not empty and valid
1262 if (!empty($bs_tables) && strlen($db) > 0)
1264 $bs_tables = $bs_tables[$db];
1266 if (isset($bs_tables))
1268 $allBSTablesExist = TRUE;
1270 // check if BS tables exist for given database
1271 foreach ($bs_tables as $table_key=>$bs_tbl)
1272 if (!$bs_tables[$table_key]['Exists'])
1274 $allBSTablesExist = FALSE;
1275 break;
1282 // if necessary BS tables exist
1283 if ($allBSTablesExist)
1284 $bs_reference_exists = PMA_BS_ReferenceExists($row[$i], $db);
1286 // if valid BS reference exists
1287 if ($bs_reference_exists)
1288 $blobtext = PMA_BS_CreateReferenceLink($row[$i], $db);
1289 else
1290 $blobtext = PMA_handle_non_printable_contents('BLOB', (isset($row[$i]) ? $row[$i] : ''), $transform_function, $transform_options, $default_function, $meta);
1292 $vertical_display['data'][$row_no][$i] = ' <td align="left"' . $mouse_events . ' class="' . $class . ($condition_field ? ' condition' : '') . '">' . $blobtext . '</td>';
1293 unset($blobtext);
1294 } else {
1295 if (!isset($row[$i]) || is_null($row[$i])) {
1296 $vertical_display['data'][$row_no][$i] = ' <td' . $mouse_events . ' class="' . $class . ($condition_field ? ' condition' : '') . '"><i>NULL</i></td>' . "\n";
1297 } elseif ($row[$i] != '') {
1298 // garvin: if a transform function for blob is set, none of these replacements will be made
1299 if (PMA_strlen($row[$i]) > $GLOBALS['cfg']['LimitChars'] && $_SESSION['userconf']['display_text'] == 'P') {
1300 $row[$i] = PMA_substr($row[$i], 0, $GLOBALS['cfg']['LimitChars']) . '...';
1302 // loic1: displays all space characters, 4 space
1303 // characters for tabulations and <cr>/<lf>
1304 $row[$i] = ($default_function != $transform_function ? $transform_function($row[$i], $transform_options, $meta) : $default_function($row[$i], array(), $meta));
1306 $vertical_display['data'][$row_no][$i] = ' <td' . $mouse_events . ' class="' . $class . ($condition_field ? ' condition' : '') . '">' . $row[$i] . '</td>' . "\n";
1307 } else {
1308 $vertical_display['data'][$row_no][$i] = ' <td' . $mouse_events . ' class="' . $class . ($condition_field ? ' condition' : '') . '">&nbsp;</td>' . "\n";
1311 } else {
1312 if (!isset($row[$i]) || is_null($row[$i])) {
1313 $vertical_display['data'][$row_no][$i] = ' <td' . $mouse_events . ' class="' . $class . ($condition_field ? ' condition' : '') . '"><i>NULL</i></td>' . "\n";
1314 } elseif ($row[$i] != '') {
1315 // loic1: support blanks in the key
1316 $relation_id = $row[$i];
1318 // nijel: Cut all fields to $GLOBALS['cfg']['LimitChars']
1319 // lem9: (unless it's a link-type transformation)
1320 if (PMA_strlen($row[$i]) > $GLOBALS['cfg']['LimitChars'] && $_SESSION['userconf']['display_text'] == 'P' && !strpos($transform_function, 'link') === true) {
1321 $row[$i] = PMA_substr($row[$i], 0, $GLOBALS['cfg']['LimitChars']) . '...';
1324 // loic1: displays special characters from binaries
1325 $field_flags = PMA_DBI_field_flags($dt_result, $i);
1326 if (isset($meta->_type) && $meta->_type === MYSQLI_TYPE_BIT) {
1327 $row[$i] = PMA_printable_bit_value($row[$i], $meta->length);
1328 } elseif (stristr($field_flags, 'BINARY') && $meta->type == 'string') {
1329 if ($_SESSION['userconf']['display_binary'] || (isset($GLOBALS['is_analyse']) && $GLOBALS['is_analyse'])) {
1330 // user asked to see the real contents of BINARY
1331 // fields, or we detected a PROCEDURE ANALYSE in
1332 // the query (results are reported as being
1333 // binary strings)
1334 $row[$i] = PMA_replace_binary_contents($row[$i]);
1335 } else {
1336 // we show the BINARY message and field's size
1337 // (or maybe use a transformation)
1338 $row[$i] = PMA_handle_non_printable_contents('BINARY', $row[$i], $transform_function, $transform_options, $default_function, $meta);
1342 // garvin: transform functions may enable no-wrapping:
1343 $function_nowrap = $transform_function . '_nowrap';
1344 $bool_nowrap = (($default_function != $transform_function && function_exists($function_nowrap)) ? $function_nowrap($transform_options) : false);
1346 // loic1: do not wrap if date field type
1347 $nowrap = ((preg_match('@DATE|TIME@i', $meta->type) || $bool_nowrap) ? ' nowrap' : '');
1348 $where_comparison = ' = \'' . PMA_sqlAddslashes($row[$i]) . '\'';
1349 $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);
1351 } else {
1352 $vertical_display['data'][$row_no][$i] = ' <td' . $mouse_events . ' class="' . $class . ($condition_field ? ' condition' : '') . '">&nbsp;</td>' . "\n";
1356 // lem9: output stored cell
1357 if ($_SESSION['userconf']['disp_direction'] == 'horizontal'
1358 || $_SESSION['userconf']['disp_direction'] == 'horizontalflipped') {
1359 echo $vertical_display['data'][$row_no][$i];
1362 if (isset($vertical_display['rowdata'][$i][$row_no])) {
1363 $vertical_display['rowdata'][$i][$row_no] .= $vertical_display['data'][$row_no][$i];
1364 } else {
1365 $vertical_display['rowdata'][$i][$row_no] = $vertical_display['data'][$row_no][$i];
1367 } // end for (2)
1369 // 3. Displays the modify/delete links on the right if required
1370 if ($GLOBALS['cfg']['ModifyDeleteAtRight']
1371 && ($_SESSION['userconf']['disp_direction'] == 'horizontal'
1372 || $_SESSION['userconf']['disp_direction'] == 'horizontalflipped')) {
1373 $doWriteModifyAt = 'right';
1374 require './libraries/display_tbl_links.lib.php';
1375 } // end if (3)
1377 if ($_SESSION['userconf']['disp_direction'] == 'horizontal'
1378 || $_SESSION['userconf']['disp_direction'] == 'horizontalflipped') {
1380 </tr>
1381 <?php
1382 } // end if
1384 // 4. Gather links of del_urls and edit_urls in an array for later
1385 // output
1386 if (!isset($vertical_display['edit'][$row_no])) {
1387 $vertical_display['edit'][$row_no] = '';
1388 $vertical_display['delete'][$row_no] = '';
1389 $vertical_display['row_delete'][$row_no] = '';
1392 $column_style_vertical = '';
1393 if ($GLOBALS['cfg']['BrowsePointerEnable'] == true) {
1394 $column_style_vertical .= ' onmouseover="setVerticalPointer(this, ' . $row_no . ', \'over\', \'odd\', \'even\', \'hover\', \'marked\');"'
1395 . ' onmouseout="setVerticalPointer(this, ' . $row_no . ', \'out\', \'odd\', \'even\', \'hover\', \'marked\');"';
1397 $column_marker_vertical = '';
1398 if ($GLOBALS['cfg']['BrowseMarkerEnable'] == true) {
1399 $column_marker_vertical .= 'setVerticalPointer(this, ' . $row_no . ', \'click\', \'odd\', \'even\', \'hover\', \'marked\');';
1402 if (!empty($del_url) && $is_display['del_lnk'] != 'kp') {
1403 $vertical_display['row_delete'][$row_no] .= ' <td align="center" class="' . $class . '" ' . $column_style_vertical . '>' . "\n"
1404 . ' <input type="checkbox" id="id_rows_to_delete' . $row_no . '[%_PMA_CHECKBOX_DIR_%]" name="rows_to_delete[' . $unique_condition_html . ']"'
1405 . ' onclick="' . $column_marker_vertical . 'copyCheckboxesRange(\'rowsDeleteForm\', \'id_rows_to_delete' . $row_no . '\',\'[%_PMA_CHECKBOX_DIR_%]\');"'
1406 . ' value="' . htmlspecialchars($del_query) . '" ' . (isset($GLOBALS['checkall']) ? 'checked="checked"' : '') . ' />' . "\n"
1407 . ' </td>' . "\n";
1408 } else {
1409 unset($vertical_display['row_delete'][$row_no]);
1412 if (isset($edit_url)) {
1413 $vertical_display['edit'][$row_no] .= ' <td align="center" class="' . $class . '" ' . $column_style_vertical . '>' . "\n"
1414 . PMA_linkOrButton($edit_url, $edit_str, array(), false)
1415 . $bookmark_go
1416 . ' </td>' . "\n";
1417 } else {
1418 unset($vertical_display['edit'][$row_no]);
1421 if (isset($del_url)) {
1422 $vertical_display['delete'][$row_no] .= ' <td align="center" class="' . $class . '" ' . $column_style_vertical . '>' . "\n"
1423 . PMA_linkOrButton($del_url, $del_str, (isset($js_conf) ? $js_conf : ''), false)
1424 . ' </td>' . "\n";
1425 } else {
1426 unset($vertical_display['delete'][$row_no]);
1429 echo (($_SESSION['userconf']['disp_direction'] == 'horizontal' || $_SESSION['userconf']['disp_direction'] == 'horizontalflipped') ? "\n" : '');
1430 $row_no++;
1431 } // end while
1433 return true;
1434 } // end of the 'PMA_displayTableBody()' function
1438 * Do display the result table with the vertical direction mode.
1439 * Credits for this feature goes to Garvin Hicking <hicking@faktor-e.de>.
1441 * @return boolean always true
1443 * @uses $_SESSION['userconf']['repeat_cells']
1444 * @global array $vertical_display the information to display
1446 * @access private
1448 * @see PMA_displayTable()
1450 function PMA_displayVerticalTable()
1452 global $vertical_display;
1454 // Displays "multi row delete" link at top if required
1455 if ($GLOBALS['cfg']['ModifyDeleteAtLeft'] && is_array($vertical_display['row_delete']) && (count($vertical_display['row_delete']) > 0 || !empty($vertical_display['textbtn']))) {
1456 echo '<tr>' . "\n";
1457 echo $vertical_display['textbtn'];
1458 $foo_counter = 0;
1459 foreach ($vertical_display['row_delete'] as $val) {
1460 if (($foo_counter != 0) && ($_SESSION['userconf']['repeat_cells'] != 0) && !($foo_counter % $_SESSION['userconf']['repeat_cells'])) {
1461 echo '<th>&nbsp;</th>' . "\n";
1464 echo str_replace('[%_PMA_CHECKBOX_DIR_%]', '', $val);
1465 $foo_counter++;
1466 } // end while
1467 echo '</tr>' . "\n";
1468 } // end if
1470 // Displays "edit" link at top if required
1471 if ($GLOBALS['cfg']['ModifyDeleteAtLeft'] && is_array($vertical_display['edit']) && (count($vertical_display['edit']) > 0 || !empty($vertical_display['textbtn']))) {
1472 echo '<tr>' . "\n";
1473 if (!is_array($vertical_display['row_delete'])) {
1474 echo $vertical_display['textbtn'];
1476 $foo_counter = 0;
1477 foreach ($vertical_display['edit'] as $val) {
1478 if (($foo_counter != 0) && ($_SESSION['userconf']['repeat_cells'] != 0) && !($foo_counter % $_SESSION['userconf']['repeat_cells'])) {
1479 echo ' <th>&nbsp;</th>' . "\n";
1482 echo $val;
1483 $foo_counter++;
1484 } // end while
1485 echo '</tr>' . "\n";
1486 } // end if
1488 // Displays "delete" link at top if required
1489 if ($GLOBALS['cfg']['ModifyDeleteAtLeft'] && is_array($vertical_display['delete']) && (count($vertical_display['delete']) > 0 || !empty($vertical_display['textbtn']))) {
1490 echo '<tr>' . "\n";
1491 if (!is_array($vertical_display['edit']) && !is_array($vertical_display['row_delete'])) {
1492 echo $vertical_display['textbtn'];
1494 $foo_counter = 0;
1495 foreach ($vertical_display['delete'] as $val) {
1496 if (($foo_counter != 0) && ($_SESSION['userconf']['repeat_cells'] != 0) && !($foo_counter % $_SESSION['userconf']['repeat_cells'])) {
1497 echo '<th>&nbsp;</th>' . "\n";
1500 echo $val;
1501 $foo_counter++;
1502 } // end while
1503 echo '</tr>' . "\n";
1504 } // end if
1506 // Displays data
1507 foreach ($vertical_display['desc'] AS $key => $val) {
1509 echo '<tr>' . "\n";
1510 echo $val;
1512 $foo_counter = 0;
1513 foreach ($vertical_display['rowdata'][$key] as $subval) {
1514 if (($foo_counter != 0) && ($_SESSION['userconf']['repeat_cells'] != 0) and !($foo_counter % $_SESSION['userconf']['repeat_cells'])) {
1515 echo $val;
1518 echo $subval;
1519 $foo_counter++;
1520 } // end while
1522 echo '</tr>' . "\n";
1523 } // end while
1525 // Displays "multi row delete" link at bottom if required
1526 if ($GLOBALS['cfg']['ModifyDeleteAtRight'] && is_array($vertical_display['row_delete']) && (count($vertical_display['row_delete']) > 0 || !empty($vertical_display['textbtn']))) {
1527 echo '<tr>' . "\n";
1528 echo $vertical_display['textbtn'];
1529 $foo_counter = 0;
1530 foreach ($vertical_display['row_delete'] as $val) {
1531 if (($foo_counter != 0) && ($_SESSION['userconf']['repeat_cells'] != 0) && !($foo_counter % $_SESSION['userconf']['repeat_cells'])) {
1532 echo '<th>&nbsp;</th>' . "\n";
1535 echo str_replace('[%_PMA_CHECKBOX_DIR_%]', 'r', $val);
1536 $foo_counter++;
1537 } // end while
1538 echo '</tr>' . "\n";
1539 } // end if
1541 // Displays "edit" link at bottom if required
1542 if ($GLOBALS['cfg']['ModifyDeleteAtRight'] && is_array($vertical_display['edit']) && (count($vertical_display['edit']) > 0 || !empty($vertical_display['textbtn']))) {
1543 echo '<tr>' . "\n";
1544 if (!is_array($vertical_display['row_delete'])) {
1545 echo $vertical_display['textbtn'];
1547 $foo_counter = 0;
1548 foreach ($vertical_display['edit'] as $val) {
1549 if (($foo_counter != 0) && ($_SESSION['userconf']['repeat_cells'] != 0) && !($foo_counter % $_SESSION['userconf']['repeat_cells'])) {
1550 echo '<th>&nbsp;</th>' . "\n";
1553 echo $val;
1554 $foo_counter++;
1555 } // end while
1556 echo '</tr>' . "\n";
1557 } // end if
1559 // Displays "delete" link at bottom if required
1560 if ($GLOBALS['cfg']['ModifyDeleteAtRight'] && is_array($vertical_display['delete']) && (count($vertical_display['delete']) > 0 || !empty($vertical_display['textbtn']))) {
1561 echo '<tr>' . "\n";
1562 if (!is_array($vertical_display['edit']) && !is_array($vertical_display['row_delete'])) {
1563 echo $vertical_display['textbtn'];
1565 $foo_counter = 0;
1566 foreach ($vertical_display['delete'] as $val) {
1567 if (($foo_counter != 0) && ($_SESSION['userconf']['repeat_cells'] != 0) && !($foo_counter % $_SESSION['userconf']['repeat_cells'])) {
1568 echo '<th>&nbsp;</th>' . "\n";
1571 echo $val;
1572 $foo_counter++;
1573 } // end while
1574 echo '</tr>' . "\n";
1577 return true;
1578 } // end of the 'PMA_displayVerticalTable' function
1582 * @uses $_SESSION['userconf']['disp_direction']
1583 * @uses $_REQUEST['disp_direction']
1584 * @uses $GLOBALS['cfg']['DefaultDisplay']
1585 * @uses $_SESSION['userconf']['repeat_cells']
1586 * @uses $_REQUEST['repeat_cells']
1587 * @uses $GLOBALS['cfg']['RepeatCells']
1588 * @uses $_SESSION['userconf']['max_rows']
1589 * @uses $_REQUEST['session_max_rows']
1590 * @uses $GLOBALS['cfg']['MaxRows']
1591 * @uses $_SESSION['userconf']['pos']
1592 * @uses $_REQUEST['pos']
1593 * @uses $_SESSION['userconf']['display_text']
1594 * @uses $_REQUEST['display_text']
1595 * @uses $_SESSION['userconf']['relational_display']
1596 * @uses $_REQUEST['relational_display']
1597 * @uses $_SESSION['userconf']['display_binary']
1598 * @uses $_REQUEST['display_binary']
1599 * @uses $_SESSION['userconf']['display_blob']
1600 * @uses $_REQUEST['display_blob']
1601 * @uses PMA_isValid()
1602 * @uses $GLOBALS['sql_query']
1603 * @todo make maximum remembered queries configurable
1604 * @todo move/split into SQL class!?
1605 * @todo currently this is called twice unnecessary
1606 * @todo ignore LIMIT and ORDER in query!?
1608 function PMA_displayTable_checkConfigParams()
1610 $sql_key = md5($GLOBALS['sql_query']);
1612 $_SESSION['userconf']['query'][$sql_key]['sql'] = $GLOBALS['sql_query'];
1614 if (PMA_isValid($_REQUEST['disp_direction'], array('horizontal', 'vertical', 'horizontalflipped'))) {
1615 $_SESSION['userconf']['query'][$sql_key]['disp_direction'] = $_REQUEST['disp_direction'];
1616 unset($_REQUEST['disp_direction']);
1617 } elseif (empty($_SESSION['userconf']['query'][$sql_key]['disp_direction'])) {
1618 $_SESSION['userconf']['query'][$sql_key]['disp_direction'] = $GLOBALS['cfg']['DefaultDisplay'];
1621 if (PMA_isValid($_REQUEST['repeat_cells'], 'numeric')) {
1622 $_SESSION['userconf']['query'][$sql_key]['repeat_cells'] = $_REQUEST['repeat_cells'];
1623 unset($_REQUEST['repeat_cells']);
1624 } elseif (empty($_SESSION['userconf']['query'][$sql_key]['repeat_cells'])) {
1625 $_SESSION['userconf']['query'][$sql_key]['repeat_cells'] = $GLOBALS['cfg']['RepeatCells'];
1628 if (PMA_isValid($_REQUEST['session_max_rows'], 'numeric') || $_REQUEST['session_max_rows'] == 'all') {
1629 $_SESSION['userconf']['query'][$sql_key]['max_rows'] = $_REQUEST['session_max_rows'];
1630 unset($_REQUEST['session_max_rows']);
1631 } elseif (empty($_SESSION['userconf']['query'][$sql_key]['max_rows'])) {
1632 $_SESSION['userconf']['query'][$sql_key]['max_rows'] = $GLOBALS['cfg']['MaxRows'];
1635 if (PMA_isValid($_REQUEST['pos'], 'numeric')) {
1636 $_SESSION['userconf']['query'][$sql_key]['pos'] = $_REQUEST['pos'];
1637 unset($_REQUEST['pos']);
1638 } elseif (empty($_SESSION['userconf']['query'][$sql_key]['pos'])) {
1639 $_SESSION['userconf']['query'][$sql_key]['pos'] = 0;
1642 if (PMA_isValid($_REQUEST['display_text'], array('P', 'F'))) {
1643 $_SESSION['userconf']['query'][$sql_key]['display_text'] = $_REQUEST['display_text'];
1644 unset($_REQUEST['display_text']);
1645 } elseif (empty($_SESSION['userconf']['query'][$sql_key]['display_text'])) {
1646 $_SESSION['userconf']['query'][$sql_key]['display_text'] = 'P';
1649 if (PMA_isValid($_REQUEST['relational_display'], array('K', 'D'))) {
1650 $_SESSION['userconf']['query'][$sql_key]['relational_display'] = $_REQUEST['relational_display'];
1651 unset($_REQUEST['relational_display']);
1652 } elseif (empty($_SESSION['userconf']['query'][$sql_key]['relational_display'])) {
1653 $_SESSION['userconf']['query'][$sql_key]['relational_display'] = 'K';
1656 if (isset($_REQUEST['display_binary'])) {
1657 $_SESSION['userconf']['query'][$sql_key]['display_binary'] = true;
1658 unset($_REQUEST['display_binary']);
1659 } elseif (isset($_REQUEST['display_options_form'])) {
1660 // we know that the checkbox was unchecked
1661 unset($_SESSION['userconf']['query'][$sql_key]['display_binary']);
1664 if (isset($_REQUEST['display_blob'])) {
1665 $_SESSION['userconf']['query'][$sql_key]['display_blob'] = true;
1666 unset($_REQUEST['display_blob']);
1667 } elseif (isset($_REQUEST['display_options_form'])) {
1668 // we know that the checkbox was unchecked
1669 unset($_SESSION['userconf']['query'][$sql_key]['display_blob']);
1672 if (isset($_REQUEST['hide_transformation'])) {
1673 $_SESSION['userconf']['query'][$sql_key]['hide_transformation'] = true;
1674 unset($_REQUEST['hide_transformation']);
1675 } elseif (isset($_REQUEST['display_options_form'])) {
1676 // we know that the checkbox was unchecked
1677 unset($_SESSION['userconf']['query'][$sql_key]['hide_transformation']);
1680 // move current query to the last position, to be removed last
1681 // so only least executed query will be removed if maximum remembered queries
1682 // limit is reached
1683 $tmp = $_SESSION['userconf']['query'][$sql_key];
1684 unset($_SESSION['userconf']['query'][$sql_key]);
1685 $_SESSION['userconf']['query'][$sql_key] = $tmp;
1687 // do not exceed a maximum number of queries to remember
1688 if (count($_SESSION['userconf']['query']) > 10) {
1689 array_shift($_SESSION['userconf']['query']);
1690 //echo 'deleting one element ...';
1693 // populate query configuration
1694 $_SESSION['userconf']['display_text'] = $_SESSION['userconf']['query'][$sql_key]['display_text'];
1695 $_SESSION['userconf']['relational_display'] = $_SESSION['userconf']['query'][$sql_key]['relational_display'];
1696 $_SESSION['userconf']['display_binary'] = isset($_SESSION['userconf']['query'][$sql_key]['display_binary']) ? true : false;
1697 $_SESSION['userconf']['display_blob'] = isset($_SESSION['userconf']['query'][$sql_key]['display_blob']) ? true : false;
1698 $_SESSION['userconf']['hide_transformation'] = isset($_SESSION['userconf']['query'][$sql_key]['hide_transformation']) ? true : false;
1699 $_SESSION['userconf']['pos'] = $_SESSION['userconf']['query'][$sql_key]['pos'];
1700 $_SESSION['userconf']['max_rows'] = $_SESSION['userconf']['query'][$sql_key]['max_rows'];
1701 $_SESSION['userconf']['repeat_cells'] = $_SESSION['userconf']['query'][$sql_key]['repeat_cells'];
1702 $_SESSION['userconf']['disp_direction'] = $_SESSION['userconf']['query'][$sql_key]['disp_direction'];
1705 * debugging
1706 echo '<pre>';
1707 var_dump($_SESSION['userconf']);
1708 echo '</pre>';
1713 * Displays a table of results returned by a SQL query.
1714 * This function is called by the "sql.php" script.
1716 * @param integer the link id associated to the query which results have
1717 * to be displayed
1718 * @param array the display mode
1719 * @param array the analyzed query
1721 * @uses $_SESSION['userconf']['pos']
1722 * @global string $db the database name
1723 * @global string $table the table name
1724 * @global string $goto the URL to go back in case of errors
1725 * @global string $sql_query the current SQL query
1726 * @global integer $num_rows the total number of rows returned by the
1727 * SQL query
1728 * @global integer $unlim_num_rows the total number of rows returned by the
1729 * SQL query without any programmatically
1730 * appended "LIMIT" clause
1731 * @global array $fields_meta the list of fields properties
1732 * @global integer $fields_cnt the total number of fields returned by
1733 * the SQL query
1734 * @global array $vertical_display informations used with vertical display
1735 * mode
1736 * @global array $highlight_columns column names to highlight
1737 * @global array $cfgRelation the relation settings
1739 * @access private
1741 * @see PMA_showMessage(), PMA_setDisplayMode(),
1742 * PMA_displayTableNavigation(), PMA_displayTableHeaders(),
1743 * PMA_displayTableBody(), PMA_displayResultsOperations()
1745 function PMA_displayTable(&$dt_result, &$the_disp_mode, $analyzed_sql)
1747 global $db, $table, $goto;
1748 global $sql_query, $num_rows, $unlim_num_rows, $fields_meta, $fields_cnt;
1749 global $vertical_display, $highlight_columns;
1750 global $cfgRelation;
1751 global $showtable;
1753 // why was this called here? (already called from sql.php)
1754 //PMA_displayTable_checkConfigParams();
1757 * @todo move this to a central place
1758 * @todo for other future table types
1760 $is_innodb = (isset($showtable['Type']) && $showtable['Type'] == 'InnoDB');
1762 if ($is_innodb
1763 && ! isset($analyzed_sql[0]['queryflags']['union'])
1764 && ! isset($analyzed_sql[0]['table_ref'][1]['table_name'])
1765 && (empty($analyzed_sql[0]['where_clause'])
1766 || $analyzed_sql[0]['where_clause'] == '1 ')) {
1767 // "j u s t b r o w s i n g"
1768 $pre_count = '~';
1769 $after_count = PMA_showHint(PMA_sanitize($GLOBALS['strApproximateCount']), true);
1770 } else {
1771 $pre_count = '';
1772 $after_count = '';
1775 // 1. ----- Prepares the work -----
1777 // 1.1 Gets the informations about which functionalities should be
1778 // displayed
1779 $total = '';
1780 $is_display = PMA_setDisplayMode($the_disp_mode, $total);
1782 // 1.2 Defines offsets for the next and previous pages
1783 if ($is_display['nav_bar'] == '1') {
1784 if ($_SESSION['userconf']['max_rows'] == 'all') {
1785 $pos_next = 0;
1786 $pos_prev = 0;
1787 } else {
1788 $pos_next = $_SESSION['userconf']['pos'] + $_SESSION['userconf']['max_rows'];
1789 $pos_prev = $_SESSION['userconf']['pos'] - $_SESSION['userconf']['max_rows'];
1790 if ($pos_prev < 0) {
1791 $pos_prev = 0;
1794 } // end if
1796 // 1.3 Find the sort expression
1798 // we need $sort_expression and $sort_expression_nodirection
1799 // even if there are many table references
1800 if (! empty($analyzed_sql[0]['order_by_clause'])) {
1801 $sort_expression = trim(str_replace(' ', ' ', $analyzed_sql[0]['order_by_clause']));
1803 * Get rid of ASC|DESC
1805 preg_match('@(.*)([[:space:]]*(ASC|DESC))@si', $sort_expression, $matches);
1806 $sort_expression_nodirection = isset($matches[1]) ? trim($matches[1]) : $sort_expression;
1807 $sort_direction = isset($matches[2]) ? trim($matches[2]) : '';
1808 unset($matches);
1809 } else {
1810 $sort_expression = $sort_expression_nodirection = $sort_direction = '';
1813 // 1.4 Prepares display of first and last value of the sorted column
1815 if (! empty($sort_expression_nodirection)) {
1816 list($sort_table, $sort_column) = explode('.', $sort_expression_nodirection);
1817 $sort_table = PMA_unQuote($sort_table);
1818 $sort_column = PMA_unQuote($sort_column);
1819 // find the sorted column index in row result
1820 // (this might be a multi-table query)
1821 $sorted_column_index = false;
1822 foreach($fields_meta as $key => $meta) {
1823 if ($meta->table == $sort_table && $meta->name == $sort_column) {
1824 $sorted_column_index = $key;
1825 break;
1828 if ($sorted_column_index !== false) {
1829 // fetch first row of the result set
1830 $row = PMA_DBI_fetch_row($dt_result);
1831 $column_for_first_row = $row[$sorted_column_index];
1832 // fetch last row of the result set
1833 PMA_DBI_data_seek($dt_result, $num_rows - 1);
1834 $row = PMA_DBI_fetch_row($dt_result);
1835 $column_for_last_row = $row[$sorted_column_index];
1836 // reset to first row for the loop in PMA_displayTableBody()
1837 PMA_DBI_data_seek($dt_result, 0);
1838 // we could also use here $sort_expression_nodirection
1839 $sorted_column_message = ' [' . htmlspecialchars($sort_column) . ': <strong>' . htmlspecialchars($column_for_first_row) . ' - ' . htmlspecialchars($column_for_last_row) . '</strong>]';
1840 unset($row, $column_for_first_row, $column_for_last_row);
1842 unset($sorted_column_index, $sort_table, $sort_column);
1845 // 2. ----- Displays the top of the page -----
1847 // 2.1 Displays a messages with position informations
1848 if ($is_display['nav_bar'] == '1' && isset($pos_next)) {
1849 if (isset($unlim_num_rows) && $unlim_num_rows != $total) {
1850 $selectstring = ', ' . $unlim_num_rows . ' ' . $GLOBALS['strSelectNumRows'];
1851 } else {
1852 $selectstring = '';
1854 $last_shown_rec = ($_SESSION['userconf']['max_rows'] == 'all' || $pos_next > $total)
1855 ? $total - 1
1856 : $pos_next - 1;
1858 if (PMA_Table::isView($db, $table)
1859 && $total == $GLOBALS['cfg']['MaxExactCountViews']) {
1860 $message = PMA_Message::notice('strViewHasAtLeast');
1861 $message->addParam('[a@./Documentation.html#cfg_MaxExactCount@_blank]');
1862 $message->addParam('[/a]');
1863 $message_view_warning = PMA_showHint($message);
1864 } else {
1865 $message_view_warning = false;
1868 $message = PMA_Message::success('strShowingRecords');
1869 $message->addMessage($_SESSION['userconf']['pos']);
1870 if ($message_view_warning) {
1871 $message->addMessage('...', ' - ');
1872 $message->addMessage($message_view_warning);
1873 $message->addMessage('(');
1874 } else {
1875 $message->addMessage($last_shown_rec, ' - ');
1876 $message->addMessage($pre_count . PMA_formatNumber($total, 0) . $after_count, ' (');
1877 $message->addString('strTotal');
1878 $message->addMessage($selectstring, '');
1879 $message->addMessage(', ', '');
1882 $messagge_qt = PMA_Message::notice('strQueryTime');
1883 $messagge_qt->addParam($GLOBALS['querytime']);
1885 $message->addMessage($messagge_qt, '');
1886 $message->addMessage(')', '');
1888 $message->addMessage(isset($sorted_column_message) ? $sorted_column_message : '', '');
1890 PMA_showMessage($message, $sql_query, 'success');
1892 } elseif (!isset($GLOBALS['printview']) || $GLOBALS['printview'] != '1') {
1893 PMA_showMessage($GLOBALS['strSuccess'], $sql_query, 'success');
1896 // 2.3 Displays the navigation bars
1897 if (! strlen($table)) {
1898 if (isset($analyzed_sql[0]['query_type'])
1899 && $analyzed_sql[0]['query_type'] == 'SELECT') {
1900 // table does not always contain a real table name,
1901 // for example in MySQL 5.0.x, the query SHOW STATUS
1902 // returns STATUS as a table name
1903 $table = $fields_meta[0]->table;
1904 } else {
1905 $table = '';
1909 if ($is_display['nav_bar'] == '1') {
1910 PMA_displayTableNavigation($pos_next, $pos_prev, $sql_query);
1911 echo "\n";
1912 } elseif (!isset($GLOBALS['printview']) || $GLOBALS['printview'] != '1') {
1913 echo "\n" . '<br /><br />' . "\n";
1916 // 2b ----- Get field references from Database -----
1917 // (see the 'relation' configuration variable)
1918 // loic1, 2002-03-02: extended to php3
1920 // initialize map
1921 $map = array();
1923 // find tables
1924 $target=array();
1925 if (isset($analyzed_sql[0]['table_ref']) && is_array($analyzed_sql[0]['table_ref'])) {
1926 foreach ($analyzed_sql[0]['table_ref'] AS $table_ref_position => $table_ref) {
1927 $target[] = $analyzed_sql[0]['table_ref'][$table_ref_position]['table_true_name'];
1930 $tabs = '(\'' . join('\',\'', $target) . '\')';
1932 if ($cfgRelation['displaywork']) {
1933 if (! strlen($table)) {
1934 $exist_rel = false;
1935 } else {
1936 $exist_rel = PMA_getForeigners($db, $table, '', 'both');
1937 if ($exist_rel) {
1938 foreach ($exist_rel AS $master_field => $rel) {
1939 $display_field = PMA_getDisplayField($rel['foreign_db'], $rel['foreign_table']);
1940 $map[$master_field] = array($rel['foreign_table'],
1941 $rel['foreign_field'],
1942 $display_field,
1943 $rel['foreign_db']);
1944 } // end while
1945 } // end if
1946 } // end if
1947 } // end if
1948 // end 2b
1950 // 3. ----- Displays the results table -----
1951 PMA_displayTableHeaders($is_display, $fields_meta, $fields_cnt, $analyzed_sql, $sort_expression, $sort_expression_nodirection, $sort_direction);
1952 $url_query = '';
1953 echo '<tbody>' . "\n";
1954 PMA_displayTableBody($dt_result, $is_display, $map, $analyzed_sql);
1955 // vertical output case
1956 if ($_SESSION['userconf']['disp_direction'] == 'vertical') {
1957 PMA_displayVerticalTable();
1958 } // end if
1959 unset($vertical_display);
1960 echo '</tbody>' . "\n";
1962 </table>
1964 <?php
1965 // 4. ----- Displays the link for multi-fields delete
1967 if ($is_display['del_lnk'] == 'dr' && $is_display['del_lnk'] != 'kp') {
1969 $delete_text = $is_display['del_lnk'] == 'dr' ? $GLOBALS['strDelete'] : $GLOBALS['strKill'];
1971 $_url_params = array(
1972 'db' => $db,
1973 'table' => $table,
1974 'sql_query' => $sql_query,
1975 'goto' => $goto,
1977 $uncheckall_url = 'sql.php' . PMA_generate_common_url($_url_params);
1979 $_url_params['checkall'] = '1';
1980 $checkall_url = 'sql.php' . PMA_generate_common_url($_url_params);
1982 if ($_SESSION['userconf']['disp_direction'] == 'vertical') {
1983 $checkall_params['onclick'] = 'if (setCheckboxes(\'rowsDeleteForm\', true)) return false;';
1984 $uncheckall_params['onclick'] = 'if (setCheckboxes(\'rowsDeleteForm\', false)) return false;';
1985 } else {
1986 $checkall_params['onclick'] = 'if (markAllRows(\'rowsDeleteForm\')) return false;';
1987 $uncheckall_params['onclick'] = 'if (unMarkAllRows(\'rowsDeleteForm\')) return false;';
1989 $checkall_link = PMA_linkOrButton($checkall_url, $GLOBALS['strCheckAll'], $checkall_params, false);
1990 $uncheckall_link = PMA_linkOrButton($uncheckall_url, $GLOBALS['strUncheckAll'], $uncheckall_params, false);
1991 if ($_SESSION['userconf']['disp_direction'] != 'vertical') {
1992 echo '<img class="selectallarrow" width="38" height="22"'
1993 .' src="' . $GLOBALS['pmaThemeImage'] . 'arrow_' . $GLOBALS['text_dir'] . '.png' . '"'
1994 .' alt="' . $GLOBALS['strWithChecked'] . '" />';
1996 echo $checkall_link . "\n"
1997 .' / ' . "\n"
1998 .$uncheckall_link . "\n"
1999 .'<i>' . $GLOBALS['strWithChecked'] . '</i>' . "\n";
2001 PMA_buttonOrImage('submit_mult', 'mult_submit',
2002 'submit_mult_change', $GLOBALS['strChange'], 'b_edit.png');
2003 PMA_buttonOrImage('submit_mult', 'mult_submit',
2004 'submit_mult_delete', $delete_text, 'b_drop.png');
2005 if ($analyzed_sql[0]['querytype'] == 'SELECT') {
2006 PMA_buttonOrImage('submit_mult', 'mult_submit',
2007 'submit_mult_export', $GLOBALS['strExport'],
2008 'b_tblexport.png');
2010 echo "\n";
2012 echo '<input type="hidden" name="sql_query"'
2013 .' value="' . htmlspecialchars($sql_query) . '" />' . "\n";
2014 echo '<input type="hidden" name="url_query"'
2015 .' value="' . $GLOBALS['url_query'] . '" />' . "\n";
2016 echo '</form>' . "\n";
2019 // 5. ----- Displays the navigation bar at the bottom if required -----
2021 if ($is_display['nav_bar'] == '1') {
2022 echo '<br />' . "\n";
2023 PMA_displayTableNavigation($pos_next, $pos_prev, $sql_query);
2024 } elseif (!isset($GLOBALS['printview']) || $GLOBALS['printview'] != '1') {
2025 echo "\n" . '<br /><br />' . "\n";
2028 // 6. ----- Displays "Query results operations"
2029 if (!isset($GLOBALS['printview']) || $GLOBALS['printview'] != '1') {
2030 PMA_displayResultsOperations($the_disp_mode, $analyzed_sql);
2032 } // end of the 'PMA_displayTable()' function
2034 function default_function($buffer) {
2035 $buffer = htmlspecialchars($buffer);
2036 $buffer = str_replace("\011", ' &nbsp;&nbsp;&nbsp;',
2037 str_replace(' ', ' &nbsp;', $buffer));
2038 $buffer = preg_replace("@((\015\012)|(\015)|(\012))@", '<br />', $buffer);
2040 return $buffer;
2044 * Displays operations that are available on results.
2046 * @param array the display mode
2047 * @param array the analyzed query
2049 * @uses $_SESSION['userconf']['pos']
2050 * @uses $_SESSION['userconf']['display_text']
2051 * @global string $db the database name
2052 * @global string $table the table name
2053 * @global string $sql_query the current SQL query
2054 * @global integer $unlim_num_rows the total number of rows returned by the
2055 * SQL query without any programmatically
2056 * appended "LIMIT" clause
2058 * @access private
2060 * @see PMA_showMessage(), PMA_setDisplayMode(),
2061 * PMA_displayTableNavigation(), PMA_displayTableHeaders(),
2062 * PMA_displayTableBody(), PMA_displayResultsOperations()
2064 function PMA_displayResultsOperations($the_disp_mode, $analyzed_sql) {
2065 global $db, $table, $sql_query, $unlim_num_rows;
2067 $header_shown = FALSE;
2068 $header = '<fieldset><legend>' . $GLOBALS['strQueryResultsOperations'] . '</legend>';
2070 if ($the_disp_mode[6] == '1' || $the_disp_mode[9] == '1') {
2071 // Displays "printable view" link if required
2072 if ($the_disp_mode[9] == '1') {
2074 if (!$header_shown) {
2075 echo $header;
2076 $header_shown = TRUE;
2079 $_url_params = array(
2080 'db' => $db,
2081 'table' => $table,
2082 'printview' => '1',
2083 'sql_query' => $sql_query,
2085 $url_query = PMA_generate_common_url($_url_params);
2087 echo PMA_linkOrButton(
2088 'sql.php' . $url_query,
2089 PMA_getIcon('b_print.png', $GLOBALS['strPrintView'], false, true),
2090 '', true, true, 'print_view') . "\n";
2092 if ($_SESSION['userconf']['display_text']) {
2093 $_url_params['display_text'] = 'F';
2094 echo PMA_linkOrButton(
2095 'sql.php' . PMA_generate_common_url($_url_params),
2096 PMA_getIcon('b_print.png', $GLOBALS['strPrintViewFull'], false, true),
2097 '', true, true, 'print_view') . "\n";
2098 unset($_url_params['display_text']);
2100 } // end displays "printable view"
2103 // Export link
2104 // (the url_query has extra parameters that won't be used to export)
2105 // (the single_table parameter is used in display_export.lib.php
2106 // to hide the SQL and the structure export dialogs)
2107 // If the parser found a PROCEDURE clause
2108 // (most probably PROCEDURE ANALYSE()) it makes no sense to
2109 // display the Export link).
2110 if (isset($analyzed_sql[0]) && $analyzed_sql[0]['querytype'] == 'SELECT' && !isset($printview) && ! isset($analyzed_sql[0]['queryflags']['procedure'])) {
2111 if (isset($analyzed_sql[0]['table_ref'][0]['table_true_name']) && !isset($analyzed_sql[0]['table_ref'][1]['table_true_name'])) {
2112 $_url_params['single_table'] = 'true';
2114 if (!$header_shown) {
2115 echo $header;
2116 $header_shown = TRUE;
2118 $_url_params['unlim_num_rows'] = $unlim_num_rows;
2119 echo PMA_linkOrButton(
2120 'tbl_export.php' . PMA_generate_common_url($_url_params),
2121 PMA_getIcon('b_tblexport.png', $GLOBALS['strExport'], false, true),
2122 '', true, true, '') . "\n";
2125 // CREATE VIEW
2128 * @todo detect privileges to create a view
2129 * (but see 2006-01-19 note in display_create_table.lib.php,
2130 * I think we cannot detect db-specific privileges reliably)
2131 * Note: we don't display a Create view link if we found a PROCEDURE clause
2133 if (!$header_shown) {
2134 echo $header;
2135 $header_shown = TRUE;
2137 if (! isset($analyzed_sql[0]['queryflags']['procedure'])) {
2138 echo PMA_linkOrButton(
2139 'view_create.php' . $url_query,
2140 PMA_getIcon('b_views.png', 'CREATE VIEW', false, true),
2141 '', true, true, '') . "\n";
2143 if ($header_shown) {
2144 echo '</fieldset><br />';
2149 * Verifies what to do with non-printable contents (binary or BLOB)
2150 * in Browse mode.
2152 * @uses is_null()
2153 * @uses isset()
2154 * @uses strlen()
2155 * @uses PMA_formatByteDown()
2156 * @uses strpos()
2157 * @uses str_replace()
2158 * @param string $category BLOB|BINARY
2159 * @param string $content the binary content
2160 * @param string $transform_function
2161 * @param string $transform_options
2162 * @param string $default_function
2163 * @param object $meta the meta-information about this field
2164 * @return mixed string or float
2166 function PMA_handle_non_printable_contents($category, $content, $transform_function, $transform_options, $default_function, $meta) {
2167 $result = '[' . $category;
2168 if (is_null($content)) {
2169 $result .= ' - NULL';
2170 $size = 0;
2171 } elseif (isset($content)) {
2172 $size = strlen($content);
2173 $display_size = PMA_formatByteDown($size, 3, 1);
2174 $result .= ' - '. $display_size[0] . $display_size[1];
2176 $result .= ']';
2178 if (strpos($transform_function, 'octetstream')) {
2179 $result = $content;
2181 if ($size > 0) {
2182 if ($default_function != $transform_function) {
2183 $result = $transform_function($result, $transform_options, $meta);
2184 } else {
2185 $result = $default_function($result, array(), $meta);
2186 if (stristr($meta->type, 'BLOB') && $_SESSION['userconf']['display_blob']) {
2187 // in this case, restart from the original $content
2188 $result = PMA_replace_binary_contents($content);
2192 return($result);
2196 * Prepares the displayable content of a data cell in Browse mode,
2197 * taking into account foreign key description field and transformations
2199 * @uses is_array()
2200 * @uses PMA_backquote()
2201 * @uses PMA_DBI_try_query()
2202 * @uses PMA_DBI_num_rows()
2203 * @uses PMA_DBI_fetch_row()
2204 * @uses $GLOBALS['strLinkNotFound']
2205 * @uses PMA_DBI_free_result()
2206 * @uses $GLOBALS['printview']
2207 * @uses htmlspecialchars()
2208 * @uses PMA_generate_common_url()
2209 * @param string $mouse_events
2210 * @param string $class
2211 * @param string $condition_field
2212 * @param string $analyzed_sql
2213 * @param object $meta the meta-information about this field
2214 * @param string $map
2215 * @param string $data
2216 * @param string $transform_function
2217 * @param string $default_function
2218 * @param string $nowrap
2219 * @param string $where_comparison
2220 * @return string formatted data
2222 function PMA_prepare_row_data($mouse_events, $class, $condition_field, $analyzed_sql, $meta, $map, $data, $transform_function, $default_function, $nowrap, $where_comparison) {
2224 // continue the <td> tag started before calling this function:
2225 $result = $mouse_events . ' class="' . $class . ($condition_field ? ' condition' : '') . $nowrap . '">';
2227 if (isset($analyzed_sql[0]['select_expr']) && is_array($analyzed_sql[0]['select_expr'])) {
2228 foreach ($analyzed_sql[0]['select_expr'] AS $select_expr_position => $select_expr) {
2229 $alias = $analyzed_sql[0]['select_expr'][$select_expr_position]['alias'];
2230 if (isset($alias) && strlen($alias)) {
2231 $true_column = $analyzed_sql[0]['select_expr'][$select_expr_position]['column'];
2232 if ($alias == $meta->name) {
2233 // this change in the parameter does not matter
2234 // outside of the function
2235 $meta->name = $true_column;
2236 } // end if
2237 } // end if
2238 } // end foreach
2239 } // end if
2241 if (isset($map[$meta->name])) {
2242 // Field to display from the foreign table?
2243 if (isset($map[$meta->name][2]) && strlen($map[$meta->name][2])) {
2244 $dispsql = 'SELECT ' . PMA_backquote($map[$meta->name][2])
2245 . ' FROM ' . PMA_backquote($map[$meta->name][3])
2246 . '.' . PMA_backquote($map[$meta->name][0])
2247 . ' WHERE ' . PMA_backquote($map[$meta->name][1])
2248 . $where_comparison;
2249 $dispresult = PMA_DBI_try_query($dispsql, null, PMA_DBI_QUERY_STORE);
2250 if ($dispresult && PMA_DBI_num_rows($dispresult) > 0) {
2251 list($dispval) = PMA_DBI_fetch_row($dispresult, 0);
2252 } else {
2253 $dispval = $GLOBALS['strLinkNotFound'];
2255 @PMA_DBI_free_result($dispresult);
2256 } else {
2257 $dispval = '';
2258 } // end if... else...
2260 if (isset($GLOBALS['printview']) && $GLOBALS['printview'] == '1') {
2261 $result .= ($transform_function != $default_function ? $transform_function($data, $transform_options, $meta) : $transform_function($data, array(), $meta)) . ' <code>[-&gt;' . $dispval . ']</code>';
2262 } else {
2264 if ('K' == $_SESSION['userconf']['relational_display']) {
2265 // user chose "relational key" in the display options, so
2266 // the title contains the display field
2267 $title = (! empty($dispval))? ' title="' . htmlspecialchars($dispval) . '"' : '';
2268 } else {
2269 $title = ' title="' . htmlspecialchars($data) . '"';
2272 $_url_params = array(
2273 'db' => $map[$meta->name][3],
2274 'table' => $map[$meta->name][0],
2275 'pos' => '0',
2276 'sql_query' => 'SELECT * FROM '
2277 . PMA_backquote($map[$meta->name][3]) . '.' . PMA_backquote($map[$meta->name][0])
2278 . ' WHERE ' . PMA_backquote($map[$meta->name][1])
2279 . $where_comparison,
2281 $result .= '<a href="sql.php' . PMA_generate_common_url($_url_params)
2282 . '"' . $title . '>';
2284 if ($transform_function != $default_function) {
2285 // always apply a transformation on the real data,
2286 // not on the display field
2287 $result .= $transform_function($data, $transform_options, $meta);
2288 } else {
2289 if ('D' == $_SESSION['userconf']['relational_display']) {
2290 // user chose "relational display field" in the
2291 // display options, so show display field in the cell
2292 $result .= $transform_function($dispval, array(), $meta);
2293 } else {
2294 // otherwise display data in the cell
2295 $result .= $transform_function($data, array(), $meta);
2298 $result .= '</a>';
2300 } else {
2301 $result .= ($transform_function != $default_function ? $transform_function($data, $transform_options, $meta) : $transform_function($data, array(), $meta));
2303 $result .= '</td>' . "\n";
2305 return $result;