bug #1910621 [display] part 2: do not display a BINARY content as text
[phpmyadmin/crack.git] / libraries / display_tbl.lib.php
blob983be700db7e7718d99f6d63c6c384b58cec67b5
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
5 * @version $Id$
6 */
8 /**
11 require_once './libraries/Table.class.php';
13 /**
14 * Set of functions used to display the records returned by a SQL query
17 /**
18 * Defines the display mode to use for the results of a SQL query
20 * It uses a synthetic string that contains all the required informations.
21 * In this string:
22 * - the first two characters stand for the action to do while
23 * clicking on the "edit" link (e.g. 'ur' for update a row, 'nn' for no
24 * edit link...);
25 * - the next two characters stand for the action to do while
26 * clicking on the "delete" link (e.g. 'kp' for kill a process, 'nn' for
27 * no delete link...);
28 * - the next characters are boolean values (1/0) and respectively stand
29 * for sorting links, navigation bar, "insert a new row" link, the
30 * bookmark feature, the expand/collapse text/blob fields button and
31 * the "display printable view" option.
32 * Of course '0'/'1' means the feature won't/will be enabled.
34 * @param string the synthetic value for display_mode (see a few
35 * lines above for explanations)
36 * @param integer the total number of rows returned by the SQL query
37 * without any programmatically appended "LIMIT" clause
38 * (just a copy of $unlim_num_rows if it exists, else
39 * computed inside this function)
41 * @return array an array with explicit indexes for all the display
42 * elements
44 * @global string the database name
45 * @global string the table name
46 * @global integer the total number of rows returned by the SQL query
47 * without any programmatically appended "LIMIT" clause
48 * @global array the properties of the fields returned by the query
49 * @global string the URL to return to in case of error in a SQL
50 * statement
52 * @access private
54 * @see PMA_displayTable()
56 function PMA_setDisplayMode(&$the_disp_mode, &$the_total)
58 global $db, $table;
59 global $unlim_num_rows, $fields_meta;
60 global $err_url;
62 // 1. Initializes the $do_display array
63 $do_display = array();
64 $do_display['edit_lnk'] = $the_disp_mode[0] . $the_disp_mode[1];
65 $do_display['del_lnk'] = $the_disp_mode[2] . $the_disp_mode[3];
66 $do_display['sort_lnk'] = (string) $the_disp_mode[4];
67 $do_display['nav_bar'] = (string) $the_disp_mode[5];
68 $do_display['ins_row'] = (string) $the_disp_mode[6];
69 $do_display['bkm_form'] = (string) $the_disp_mode[7];
70 $do_display['text_btn'] = (string) $the_disp_mode[8];
71 $do_display['pview_lnk'] = (string) $the_disp_mode[9];
73 // 2. Display mode is not "false for all elements" -> updates the
74 // display mode
75 if ($the_disp_mode != 'nnnn000000') {
76 // 2.0 Print view -> set all elements to false!
77 if (isset($GLOBALS['printview']) && $GLOBALS['printview'] == '1') {
78 $do_display['edit_lnk'] = 'nn'; // no edit link
79 $do_display['del_lnk'] = 'nn'; // no delete link
80 $do_display['sort_lnk'] = (string) '0';
81 $do_display['nav_bar'] = (string) '0';
82 $do_display['ins_row'] = (string) '0';
83 $do_display['bkm_form'] = (string) '0';
84 $do_display['text_btn'] = (string) '0';
85 $do_display['pview_lnk'] = (string) '0';
87 // 2.1 Statement is a "SELECT COUNT", a
88 // "CHECK/ANALYZE/REPAIR/OPTIMIZE", an "EXPLAIN" one or
89 // contains a "PROC ANALYSE" part
90 elseif ($GLOBALS['is_count'] || $GLOBALS['is_analyse'] || $GLOBALS['is_maint'] || $GLOBALS['is_explain']) {
91 $do_display['edit_lnk'] = 'nn'; // no edit link
92 $do_display['del_lnk'] = 'nn'; // no delete link
93 $do_display['sort_lnk'] = (string) '0';
94 $do_display['nav_bar'] = (string) '0';
95 $do_display['ins_row'] = (string) '0';
96 $do_display['bkm_form'] = (string) '1';
97 if ($GLOBALS['is_maint']) {
98 $do_display['text_btn'] = (string) '1';
99 } else {
100 $do_display['text_btn'] = (string) '0';
102 $do_display['pview_lnk'] = (string) '1';
104 // 2.2 Statement is a "SHOW..."
105 elseif ($GLOBALS['is_show']) {
107 * 2.2.1
108 * @todo defines edit/delete links depending on show statement
110 $tmp = preg_match('@^SHOW[[:space:]]+(VARIABLES|(FULL[[:space:]]+)?PROCESSLIST|STATUS|TABLE|GRANTS|CREATE|LOGS|DATABASES|FIELDS)@i', $GLOBALS['sql_query'], $which);
111 if (isset($which[1]) && strpos(' ' . strtoupper($which[1]), 'PROCESSLIST') > 0) {
112 $do_display['edit_lnk'] = 'nn'; // no edit link
113 $do_display['del_lnk'] = 'kp'; // "kill process" type edit link
114 } else {
115 // Default case -> no links
116 $do_display['edit_lnk'] = 'nn'; // no edit link
117 $do_display['del_lnk'] = 'nn'; // no delete link
119 // 2.2.2 Other settings
120 $do_display['sort_lnk'] = (string) '0';
121 $do_display['nav_bar'] = (string) '0';
122 $do_display['ins_row'] = (string) '0';
123 $do_display['bkm_form'] = (string) '1';
124 $do_display['text_btn'] = (string) '1';
125 $do_display['pview_lnk'] = (string) '1';
127 // 2.3 Other statements (ie "SELECT" ones) -> updates
128 // $do_display['edit_lnk'], $do_display['del_lnk'] and
129 // $do_display['text_btn'] (keeps other default values)
130 else {
131 $prev_table = $fields_meta[0]->table;
132 $do_display['text_btn'] = (string) '1';
133 for ($i = 0; $i < $GLOBALS['fields_cnt']; $i++) {
134 $is_link = ($do_display['edit_lnk'] != 'nn'
135 || $do_display['del_lnk'] != 'nn'
136 || $do_display['sort_lnk'] != '0'
137 || $do_display['ins_row'] != '0');
138 // 2.3.2 Displays edit/delete/sort/insert links?
139 if ($is_link
140 && ($fields_meta[$i]->table == '' || $fields_meta[$i]->table != $prev_table)) {
141 $do_display['edit_lnk'] = 'nn'; // don't display links
142 $do_display['del_lnk'] = 'nn';
144 * @todo May be problematic with same fields names in two joined table.
146 // $do_display['sort_lnk'] = (string) '0';
147 $do_display['ins_row'] = (string) '0';
148 if ($do_display['text_btn'] == '1') {
149 break;
151 } // end if (2.3.2)
152 // 2.3.3 Always display print view link
153 $do_display['pview_lnk'] = (string) '1';
154 $prev_table = $fields_meta[$i]->table;
155 } // end for
156 } // end if..elseif...else (2.1 -> 2.3)
157 } // end if (2)
159 // 3. Gets the total number of rows if it is unknown
160 if (isset($unlim_num_rows) && $unlim_num_rows != '') {
161 $the_total = $unlim_num_rows;
162 } elseif (($do_display['nav_bar'] == '1' || $do_display['sort_lnk'] == '1')
163 && (strlen($db) && !empty($table))) {
164 $the_total = PMA_Table::countRecords($db, $table, true);
167 // 4. If navigation bar or sorting fields names URLs should be
168 // displayed but there is only one row, change these settings to
169 // false
170 if ($do_display['nav_bar'] == '1' || $do_display['sort_lnk'] == '1') {
172 // - Do not display sort links if less than 2 rows.
173 // - For a VIEW we (probably) did not count the number of rows
174 // so don't test this number here, it would remove the possibility
175 // of sorting VIEW results.
176 if (isset($unlim_num_rows) && $unlim_num_rows < 2 && ! PMA_Table::isView($db, $table)) {
177 // garvin: force display of navbar for vertical/horizontal display-choice.
178 // $do_display['nav_bar'] = (string) '0';
179 $do_display['sort_lnk'] = (string) '0';
181 } // end if (3)
183 // 5. Updates the synthetic var
184 $the_disp_mode = join('', $do_display);
186 return $do_display;
187 } // end of the 'PMA_setDisplayMode()' function
191 * Displays a navigation bar to browse among the results of a SQL query
193 * @uses $_SESSION['userconf']['disp_direction']
194 * @uses $_SESSION['userconf']['repeat_cells']
195 * @uses $_SESSION['userconf']['max_rows']
196 * @uses $_SESSION['userconf']['pos']
197 * @param integer the offset for the "next" page
198 * @param integer the offset for the "previous" page
199 * @param string the URL-encoded query
201 * @global string $db the database name
202 * @global string $table the table name
203 * @global string $goto the URL to go back in case of errors
204 * @global integer $num_rows the total number of rows returned by the
205 * SQL query
206 * @global integer $unlim_num_rows the total number of rows returned by the
207 * SQL any programmatically appended "LIMIT" clause
208 * @global boolean $is_innodb whether its InnoDB or not
209 * @global array $showtable table definitions
211 * @access private
213 * @see PMA_displayTable()
215 function PMA_displayTableNavigation($pos_next, $pos_prev, $sql_query)
217 global $db, $table, $goto;
218 global $num_rows, $unlim_num_rows;
219 global $is_innodb;
220 global $showtable;
222 // here, using htmlentities() would cause problems if the query
223 // contains accented characters
224 $html_sql_query = htmlspecialchars($sql_query);
227 * @todo move this to a central place
228 * @todo for other future table types
230 $is_innodb = (isset($showtable['Type']) && $showtable['Type'] == 'InnoDB');
234 <!-- Navigation bar -->
235 <table border="0" cellpadding="2" cellspacing="0">
236 <tr>
237 <?php
238 // Move to the beginning or to the previous page
239 if ($_SESSION['userconf']['pos'] && $_SESSION['userconf']['max_rows'] != 'all') {
240 // loic1: patch #474210 from Gosha Sakovich - part 1
241 if ($GLOBALS['cfg']['NavigationBarIconic']) {
242 $caption1 = '&lt;&lt;';
243 $caption2 = ' &lt; ';
244 $title1 = ' title="' . $GLOBALS['strPos1'] . '"';
245 $title2 = ' title="' . $GLOBALS['strPrevious'] . '"';
246 } else {
247 $caption1 = $GLOBALS['strPos1'] . ' &lt;&lt;';
248 $caption2 = $GLOBALS['strPrevious'] . ' &lt;';
249 $title1 = '';
250 $title2 = '';
251 } // end if... else...
253 <td>
254 <form action="sql.php" method="post">
255 <?php echo PMA_generate_common_hidden_inputs($db, $table); ?>
256 <input type="hidden" name="sql_query" value="<?php echo $html_sql_query; ?>" />
257 <input type="hidden" name="pos" value="0" />
258 <input type="hidden" name="goto" value="<?php echo $goto; ?>" />
259 <input type="submit" name="navig" value="<?php echo $caption1; ?>"<?php echo $title1; ?> />
260 </form>
261 </td>
262 <td>
263 <form action="sql.php" method="post">
264 <?php echo PMA_generate_common_hidden_inputs($db, $table); ?>
265 <input type="hidden" name="sql_query" value="<?php echo $html_sql_query; ?>" />
266 <input type="hidden" name="pos" value="<?php echo $pos_prev; ?>" />
267 <input type="hidden" name="goto" value="<?php echo $goto; ?>" />
268 <input type="submit" name="navig" value="<?php echo $caption2; ?>"<?php echo $title2; ?> />
269 </form>
270 </td>
271 <?php
272 } // end move back
274 <td>
275 &nbsp;&nbsp;&nbsp;
276 </td>
277 <td align="center">
278 <?php // if displaying a VIEW, $unlim_num_rows could be zero because
279 // of $cfg['MaxExactCountViews']; in this case, avoid passing
280 // the 5th parameter to checkFormElementInRange()
281 // (this means we can't validate the upper limit ?>
282 <form action="sql.php" method="post"
283 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 : ''; ?>))">
284 <?php echo PMA_generate_common_hidden_inputs($db, $table); ?>
285 <input type="hidden" name="sql_query" value="<?php echo $html_sql_query; ?>" />
286 <input type="hidden" name="goto" value="<?php echo $goto; ?>" />
287 <input type="submit" name="navig" value="<?php echo $GLOBALS['strShow']; ?> :" />
288 <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()" />
289 <?php echo $GLOBALS['strRowsFrom'] . "\n"; ?>
290 <input type="text" name="pos" size="6" value="<?php echo (($pos_next >= $unlim_num_rows) ? 0 : $pos_next); ?>" class="textfield" onfocus="this.select()" />
291 <br />
292 <?php
293 // Display mode (horizontal/vertical and repeat headers)
294 $param1 = ' <select name="disp_direction">' . "\n"
295 . ' <option value="horizontal"' . (($_SESSION['userconf']['disp_direction'] == 'horizontal') ? ' selected="selected"': '') . '>' . $GLOBALS['strRowsModeHorizontal'] . '</option>' . "\n"
296 . ' <option value="horizontalflipped"' . (($_SESSION['userconf']['disp_direction'] == 'horizontalflipped') ? ' selected="selected"': '') . '>' . $GLOBALS['strRowsModeFlippedHorizontal'] . '</option>' . "\n"
297 . ' <option value="vertical"' . (($_SESSION['userconf']['disp_direction'] == 'vertical') ? ' selected="selected"': '') . '>' . $GLOBALS['strRowsModeVertical'] . '</option>' . "\n"
298 . ' </select>' . "\n"
299 . ' ';
300 $param2 = ' <input type="text" size="3" name="repeat_cells" value="' . $_SESSION['userconf']['repeat_cells'] . '" class="textfield" />' . "\n"
301 . ' ';
302 echo ' ' . sprintf($GLOBALS['strRowsModeOptions'], "\n" . $param1, "\n" . $param2) . "\n";
304 </form>
305 </td>
306 <td>
307 &nbsp;&nbsp;&nbsp;
308 </td>
309 <?php
310 // Move to the next page or to the last one
311 if (($_SESSION['userconf']['pos'] + $_SESSION['userconf']['max_rows'] < $unlim_num_rows) && $num_rows >= $_SESSION['userconf']['max_rows']
312 && $_SESSION['userconf']['max_rows'] != 'all') {
313 // loic1: patch #474210 from Gosha Sakovich - part 2
314 if ($GLOBALS['cfg']['NavigationBarIconic']) {
315 $caption3 = ' &gt; ';
316 $caption4 = '&gt;&gt;';
317 $title3 = ' title="' . $GLOBALS['strNext'] . '"';
318 $title4 = ' title="' . $GLOBALS['strEnd'] . '"';
319 } else {
320 $caption3 = '&gt; ' . $GLOBALS['strNext'];
321 $caption4 = '&gt;&gt; ' . $GLOBALS['strEnd'];
322 $title3 = '';
323 $title4 = '';
324 } // end if... else...
325 echo "\n";
327 <td>
328 <form action="sql.php" method="post">
329 <?php echo PMA_generate_common_hidden_inputs($db, $table); ?>
330 <input type="hidden" name="sql_query" value="<?php echo $html_sql_query; ?>" />
331 <input type="hidden" name="pos" value="<?php echo $pos_next; ?>" />
332 <input type="hidden" name="goto" value="<?php echo $goto; ?>" />
333 <input type="submit" name="navig" value="<?php echo $caption3; ?>"<?php echo $title3; ?> />
334 </form>
335 </td>
336 <td>
337 <form action="sql.php" method="post"
338 onsubmit="return <?php echo (($_SESSION['userconf']['pos'] + $_SESSION['userconf']['max_rows'] < $unlim_num_rows && $num_rows >= $_SESSION['userconf']['max_rows']) ? 'true' : 'false'); ?>">
339 <?php echo PMA_generate_common_hidden_inputs($db, $table); ?>
340 <input type="hidden" name="sql_query" value="<?php echo $html_sql_query; ?>" />
341 <input type="hidden" name="pos" value="<?php echo @((ceil($unlim_num_rows / $_SESSION['userconf']['max_rows'])- 1) * $_SESSION['userconf']['max_rows']); ?>" />
342 <?php
343 if ($is_innodb && $unlim_num_rows > $GLOBALS['cfg']['MaxExactCount']) {
344 echo '<input type="hidden" name="find_real_end" value="1" />' . "\n";
345 // no backquote around this message
346 $onclick = ' onclick="return confirmAction(\'' . PMA_jsFormat($GLOBALS['strLongOperation'], false) . '\')"';
349 <input type="hidden" name="goto" value="<?php echo $goto; ?>" />
350 <input type="submit" name="navig" value="<?php echo $caption4; ?>"<?php echo $title4; ?> <?php echo (empty($onclick) ? '' : $onclick); ?>/>
351 </form>
352 </td>
353 <?php
354 } // end move toward
357 //page redirection
358 // (unless we are showing all records)
359 if ('all' != $_SESSION['userconf']['max_rows']) { //if1
360 $pageNow = @floor($_SESSION['userconf']['pos'] / $_SESSION['userconf']['max_rows']) + 1;
361 $nbTotalPage = @ceil($unlim_num_rows / $_SESSION['userconf']['max_rows']);
363 if ($nbTotalPage > 1){ //if2
365 <td>
366 &nbsp;&nbsp;&nbsp;
367 </td>
368 <td>
369 <?php //<form> for keep the form alignment of button < and << ?>
370 <form action="none">
371 <?php echo PMA_pageselector(
372 'sql.php?sql_query=' . urlencode($sql_query) .
373 '&amp;goto=' . $goto .
374 '&amp;' . PMA_generate_common_url($db, $table) .
375 '&amp;',
376 $_SESSION['userconf']['max_rows'],
377 $pageNow,
378 $nbTotalPage,
379 200,
384 $GLOBALS['strPageNumber']
387 </form>
388 </td>
389 <?php
390 } //_if2
391 } //_if1
394 // Display the "Show all" button if allowed
395 if ($GLOBALS['cfg']['ShowAll'] && ($num_rows < $unlim_num_rows)) {
396 echo "\n";
398 <td>
399 &nbsp;&nbsp;&nbsp;
400 </td>
401 <td>
402 <form action="sql.php" method="post">
403 <?php echo PMA_generate_common_hidden_inputs($db, $table); ?>
404 <input type="hidden" name="sql_query" value="<?php echo $html_sql_query; ?>" />
405 <input type="hidden" name="pos" value="0" />
406 <input type="hidden" name="session_max_rows" value="all" />
407 <input type="hidden" name="goto" value="<?php echo $goto; ?>" />
408 <input type="submit" name="navig" value="<?php echo $GLOBALS['strShowAll']; ?>" />
409 </form>
410 </td>
411 <?php
412 } // end show all
413 echo "\n";
415 </tr>
416 </table>
418 <?php
419 } // end of the 'PMA_displayTableNavigation()' function
423 * Displays the headers of the results table
425 * @uses $_SESSION['userconf']['disp_direction']
426 * @uses $_SESSION['userconf']['repeat_cells']
427 * @uses $_SESSION['userconf']['max_rows']
428 * @uses $_SESSION['userconf']['dontlimitchars']
429 * @param array which elements to display
430 * @param array the list of fields properties
431 * @param integer the total number of fields returned by the SQL query
432 * @param array the analyzed query
434 * @return boolean always true
436 * @global string $db the database name
437 * @global string $table the table name
438 * @global string $goto the URL to go back in case of errors
439 * @global string $sql_query the SQL query
440 * @global integer $num_rows the total number of rows returned by the
441 * SQL query
442 * @global array $vertical_display informations used with vertical display
443 * mode
445 * @access private
447 * @see PMA_displayTable()
449 function PMA_displayTableHeaders(&$is_display, &$fields_meta, $fields_cnt = 0, $analyzed_sql = '')
451 global $db, $table, $goto;
452 global $sql_query, $num_rows;
453 global $vertical_display, $highlight_columns;
455 if ($analyzed_sql == '') {
456 $analyzed_sql = array();
459 // can the result be sorted?
460 if ($is_display['sort_lnk'] == '1') {
462 // Just as fallback
463 $unsorted_sql_query = $sql_query;
464 if (isset($analyzed_sql[0]['unsorted_query'])) {
465 $unsorted_sql_query = $analyzed_sql[0]['unsorted_query'];
468 // we need $sort_expression and $sort_expression_nodirection
469 // even if there are many table references
471 $sort_expression = trim(str_replace(' ', ' ', $analyzed_sql[0]['order_by_clause']));
474 * Get rid of ASC|DESC
475 * @todo analyzer
477 preg_match('@(.*)([[:space:]]*(ASC|DESC))@si', $sort_expression, $matches);
478 $sort_expression_nodirection = isset($matches[1]) ? trim($matches[1]) : $sort_expression;
480 // sorting by indexes, only if it makes sense (only one table ref)
481 if (isset($analyzed_sql) && isset($analyzed_sql[0]) &&
482 isset($analyzed_sql[0]['querytype']) && $analyzed_sql[0]['querytype'] == 'SELECT' &&
483 isset($analyzed_sql[0]['table_ref']) && count($analyzed_sql[0]['table_ref']) == 1) {
485 // grab indexes data:
486 PMA_DBI_select_db($db);
487 if (!defined('PMA_IDX_INCLUDED')) {
488 $ret_keys = PMA_get_indexes($table);
491 $prev_index = '';
492 foreach ($ret_keys as $row) {
494 if ($row['Key_name'] != $prev_index){
495 $indexes[] = $row['Key_name'];
496 $prev_index = $row['Key_name'];
498 $indexes_info[$row['Key_name']]['Sequences'][] = $row['Seq_in_index'];
499 $indexes_info[$row['Key_name']]['Non_unique'] = $row['Non_unique'];
500 if (isset($row['Cardinality'])) {
501 $indexes_info[$row['Key_name']]['Cardinality'] = $row['Cardinality'];
503 // I don't know what does the following column mean....
504 // $indexes_info[$row['Key_name']]['Packed'] = $row['Packed'];
505 $indexes_info[$row['Key_name']]['Comment'] = (isset($row['Comment']))
506 ? $row['Comment']
507 : '';
508 $indexes_info[$row['Key_name']]['Index_type'] = (isset($row['Index_type']))
509 ? $row['Index_type']
510 : '';
512 $indexes_data[$row['Key_name']][$row['Seq_in_index']]['Column_name'] = $row['Column_name'];
513 if (isset($row['Sub_part'])) {
514 $indexes_data[$row['Key_name']][$row['Seq_in_index']]['Sub_part'] = $row['Sub_part'];
516 } // end while
518 // do we have any index?
519 if (isset($indexes_data)) {
521 if ($_SESSION['userconf']['disp_direction'] == 'horizontal'
522 || $_SESSION['userconf']['disp_direction'] == 'horizontalflipped') {
523 $span = $fields_cnt;
524 if ($is_display['edit_lnk'] != 'nn') {
525 $span++;
527 if ($is_display['del_lnk'] != 'nn') {
528 $span++;
530 if ($is_display['del_lnk'] != 'kp' && $is_display['del_lnk'] != 'nn') {
531 $span++;
533 } else {
534 $span = $num_rows + floor($num_rows/$_SESSION['userconf']['repeat_cells']) + 1;
537 echo '<form action="sql.php" method="post">' . "\n";
538 echo PMA_generate_common_hidden_inputs($db, $table, 5);
539 echo $GLOBALS['strSortByKey'] . ': <select name="sql_query" onchange="this.form.submit();">' . "\n";
540 $used_index = false;
541 $local_order = (isset($sort_expression) ? $sort_expression : '');
542 foreach ($indexes_data AS $key => $val) {
543 $asc_sort = '';
544 $desc_sort = '';
545 foreach ($val AS $key2 => $val2) {
546 $asc_sort .= PMA_backquote($val2['Column_name']) . ' ASC , ';
547 $desc_sort .= PMA_backquote($val2['Column_name']) . ' DESC , ';
549 $asc_sort = substr($asc_sort, 0, -3);
550 $desc_sort = substr($desc_sort, 0, -3);
551 $used_index = $used_index || $local_order == $asc_sort || $local_order == $desc_sort;
552 echo '<option value="' . htmlspecialchars($unsorted_sql_query . ' ORDER BY ' . $asc_sort) . '"' . ($local_order == $asc_sort ? ' selected="selected"' : '') . '>' . htmlspecialchars($key) . ' (' . $GLOBALS['strAscending'] . ')</option>';
553 echo "\n";
554 echo '<option value="' . htmlspecialchars($unsorted_sql_query . ' ORDER BY ' . $desc_sort) . '"' . ($local_order == $desc_sort ? ' selected="selected"' : '') . '>' . htmlspecialchars($key) . ' (' . $GLOBALS['strDescending'] . ')</option>';
555 echo "\n";
557 echo '<option value="' . htmlspecialchars($unsorted_sql_query) . '"' . ($used_index ? '' : ' selected="selected"') . '>' . $GLOBALS['strNone'] . '</option>';
558 echo "\n";
559 echo '</select>' . "\n";
560 echo '<noscript><input type="submit" value="' . $GLOBALS['strGo'] . '" /></noscript>';
561 echo "\n";
562 echo '</form>' . "\n";
568 $vertical_display['emptypre'] = 0;
569 $vertical_display['emptyafter'] = 0;
570 $vertical_display['textbtn'] = '';
573 // Start of form for multi-rows delete
575 if ($is_display['del_lnk'] == 'dr' || $is_display['del_lnk'] == 'kp') {
576 echo '<form method="post" action="tbl_row_action.php" name="rowsDeleteForm" id="rowsDeleteForm">' . "\n";
577 echo PMA_generate_common_hidden_inputs($db, $table, 1);
578 echo '<input type="hidden" name="goto" value="sql.php" />' . "\n";
581 echo '<table id="table_results" class="data">' . "\n";
582 if ($_SESSION['userconf']['disp_direction'] == 'horizontal'
583 || $_SESSION['userconf']['disp_direction'] == 'horizontalflipped') {
584 echo '<thead><tr>' . "\n";
587 // 1. Displays the full/partial text button (part 1)...
588 if ($_SESSION['userconf']['disp_direction'] == 'horizontal'
589 || $_SESSION['userconf']['disp_direction'] == 'horizontalflipped') {
590 $colspan = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn')
591 ? ' colspan="3"'
592 : '';
593 } else {
594 $rowspan = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn')
595 ? ' rowspan="3"'
596 : '';
598 $url_params = array(
599 'db' => $db,
600 'table' => $table,
601 'sql_query' => $sql_query,
602 'goto' => $goto,
604 $text_message = '<img class="fulltext" width="50" height="20"';
605 if ($_SESSION['userconf']['dontlimitchars']) {
606 $url_params['dontlimitchars'] = '0';
607 $text_message .= ''
608 . ' src="' . $GLOBALS['pmaThemeImage'] . 's_partialtext.png"'
609 . ' alt="' . $GLOBALS['strPartialText'] . '"'
610 . ' title="' . $GLOBALS['strPartialText'] . '"';
611 } else {
612 $url_params['dontlimitchars'] = '1';
613 $text_message .= ''
614 . ' src="' . $GLOBALS['pmaThemeImage'] . 's_fulltext.png"'
615 . ' alt="' . $GLOBALS['strFullText'] . '"'
616 . ' title="' . $GLOBALS['strFullText'] . '"';
618 $text_message .= ' />';
619 $text_url = 'sql.php' . PMA_generate_common_url($url_params);
620 $text_link = PMA_linkOrButton($text_url, $text_message, array(), false);
622 // ... before the result table
623 if (($is_display['edit_lnk'] == 'nn' && $is_display['del_lnk'] == 'nn')
624 && $is_display['text_btn'] == '1') {
625 $vertical_display['emptypre'] = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn') ? 3 : 0;
626 if ($_SESSION['userconf']['disp_direction'] == 'horizontal'
627 || $_SESSION['userconf']['disp_direction'] == 'horizontalflipped') {
629 <th colspan="<?php echo $fields_cnt; ?>"><?php echo $text_link; ?></th>
630 </tr>
631 <tr>
632 <?php
633 } // end horizontal/horizontalflipped mode
634 else {
636 <tr>
637 <th colspan="<?php echo $num_rows + floor($num_rows/$_SESSION['userconf']['repeat_cells']) + 1; ?>">
638 <?php echo $text_link; ?></th>
639 </tr>
640 <?php
641 } // end vertical mode
644 // ... at the left column of the result table header if possible
645 // and required
646 elseif ($GLOBALS['cfg']['ModifyDeleteAtLeft'] && $is_display['text_btn'] == '1') {
647 $vertical_display['emptypre'] = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn') ? 3 : 0;
648 if ($_SESSION['userconf']['disp_direction'] == 'horizontal'
649 || $_SESSION['userconf']['disp_direction'] == 'horizontalflipped') {
651 <th <?php echo $colspan; ?>><?php echo $text_link; ?></th>
652 <?php
653 } // end horizontal/horizontalflipped mode
654 else {
655 $vertical_display['textbtn'] = ' <th ' . $rowspan . ' valign="middle">' . "\n"
656 . ' ' . $text_link . "\n"
657 . ' </th>' . "\n";
658 } // end vertical mode
661 // ... elseif no button, displays empty(ies) col(s) if required
662 elseif ($GLOBALS['cfg']['ModifyDeleteAtLeft']
663 && ($is_display['edit_lnk'] != 'nn' || $is_display['del_lnk'] != 'nn')) {
664 $vertical_display['emptypre'] = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn') ? 3 : 0;
665 if ($_SESSION['userconf']['disp_direction'] == 'horizontal'
666 || $_SESSION['userconf']['disp_direction'] == 'horizontalflipped') {
668 <td<?php echo $colspan; ?>></td>
669 <?php
670 } // end horizontal/horizontalfipped mode
671 else {
672 $vertical_display['textbtn'] = ' <td' . $rowspan . '></td>' . "\n";
673 } // end vertical mode
676 // 2. Displays the fields' name
677 // 2.0 If sorting links should be used, checks if the query is a "JOIN"
678 // statement (see 2.1.3)
680 // 2.0.1 Prepare Display column comments if enabled ($GLOBALS['cfg']['ShowBrowseComments']).
681 // Do not show comments, if using horizontalflipped mode, because of space usage
682 if ($GLOBALS['cfg']['ShowBrowseComments']
683 && ($GLOBALS['cfgRelation']['commwork']
684 || PMA_MYSQL_INT_VERSION >= 40100)
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']) {
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`)'
780 if (strpos($name_to_use_in_sort, '(') !== false) {
781 $sort_order = ' ORDER BY ' . $name_to_use_in_sort . ' ';
782 } else {
783 $sort_order = ' ORDER BY ' . $sort_tbl . PMA_backquote($name_to_use_in_sort) . ' ';
785 unset($name_to_use_in_sort);
787 // 2.1.4 Do define the sorting URL
788 if (! $is_in_sort) {
789 // loic1: patch #455484 ("Smart" order)
790 $GLOBALS['cfg']['Order'] = strtoupper($GLOBALS['cfg']['Order']);
791 if ($GLOBALS['cfg']['Order'] === 'SMART') {
792 $sort_order .= (preg_match('@time|date@i', $fields_meta[$i]->type)) ? 'DESC' : 'ASC';
793 } else {
794 $sort_order .= $GLOBALS['cfg']['Order'];
796 $order_img = '';
797 } elseif (preg_match('@[[:space:]]DESC$@i', $sort_expression)) {
798 $sort_order .= ' ASC';
799 $order_img = ' <img class="icon" src="' . $GLOBALS['pmaThemeImage'] . 's_desc.png" width="11" height="9" alt="'. $GLOBALS['strDescending'] . '" title="'. $GLOBALS['strDescending'] . '" id="soimg' . $i . '" />';
800 } else {
801 $sort_order .= ' DESC';
802 $order_img = ' <img class="icon" src="' . $GLOBALS['pmaThemeImage'] . 's_asc.png" width="11" height="9" alt="'. $GLOBALS['strAscending'] . '" title="'. $GLOBALS['strAscending'] . '" id="soimg' . $i . '" />';
805 if (preg_match('@(.*)([[:space:]](LIMIT (.*)|PROCEDURE (.*)|FOR UPDATE|LOCK IN SHARE MODE))@i', $unsorted_sql_query, $regs3)) {
806 $sorted_sql_query = $regs3[1] . $sort_order . $regs3[2];
807 } else {
808 $sorted_sql_query = $unsorted_sql_query . $sort_order;
810 $url_query = PMA_generate_common_url($db, $table)
811 . '&amp;sql_query=' . urlencode($sorted_sql_query);
812 $order_url = 'sql.php?' . $url_query;
814 // 2.1.5 Displays the sorting URL
815 // added 20004-06-09: Michael Keck <mail@michaelkeck.de>
816 // enable sort order swapping for image
817 $order_link_params = array();
818 if (isset($order_img) && $order_img!='') {
819 if (strstr($order_img, 'asc')) {
820 $order_link_params['onmouseover'] = 'if(document.getElementById(\'soimg' . $i . '\')){ document.getElementById(\'soimg' . $i . '\').src=\'' . $GLOBALS['pmaThemeImage'] . 's_desc.png\'; }';
821 $order_link_params['onmouseout'] = 'if(document.getElementById(\'soimg' . $i . '\')){ document.getElementById(\'soimg' . $i . '\').src=\'' . $GLOBALS['pmaThemeImage'] . 's_asc.png\'; }';
822 } elseif (strstr($order_img, 'desc')) {
823 $order_link_params['onmouseover'] = 'if(document.getElementById(\'soimg' . $i . '\')){ document.getElementById(\'soimg' . $i . '\').src=\'' . $GLOBALS['pmaThemeImage'] . 's_asc.png\'; }';
824 $order_link_params['onmouseout'] = 'if(document.getElementById(\'soimg' . $i . '\')){ document.getElementById(\'soimg' . $i . '\').src=\'' . $GLOBALS['pmaThemeImage'] . 's_desc.png\'; }';
827 if ($_SESSION['userconf']['disp_direction'] == 'horizontalflipped'
828 && $GLOBALS['cfg']['HeaderFlipType'] == 'css') {
829 $order_link_params['style'] = 'direction: ltr; writing-mode: tb-rl;';
831 $order_link_params['title'] = $GLOBALS['strSort'];
832 $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));
833 $order_link = PMA_linkOrButton($order_url, $order_link_content . $order_img, $order_link_params, false, true);
835 if ($_SESSION['userconf']['disp_direction'] == 'horizontal'
836 || $_SESSION['userconf']['disp_direction'] == 'horizontalflipped') {
837 echo '<th';
838 if ($condition_field) {
839 echo ' class="condition"';
841 if ($_SESSION['userconf']['disp_direction'] == 'horizontalflipped') {
842 echo ' valign="bottom"';
844 echo '>' . $order_link . $comments . '</th>';
846 $vertical_display['desc'][] = ' <th '
847 . ($condition_field ? ' class="condition"' : '') . '>' . "\n"
848 . $order_link . $comments . ' </th>' . "\n";
849 } // end if (2.1)
851 // 2.2 Results can't be sorted
852 else {
853 if ($_SESSION['userconf']['disp_direction'] == 'horizontal'
854 || $_SESSION['userconf']['disp_direction'] == 'horizontalflipped') {
855 echo '<th';
856 if ($condition_field) {
857 echo ' class="condition"';
859 if ($_SESSION['userconf']['disp_direction'] == 'horizontalflipped') {
860 echo ' valign="bottom"';
862 if ($_SESSION['userconf']['disp_direction'] == 'horizontalflipped'
863 && $GLOBALS['cfg']['HeaderFlipType'] == 'css') {
864 echo ' style="direction: ltr; writing-mode: tb-rl;"';
866 echo '>';
867 if ($_SESSION['userconf']['disp_direction'] == 'horizontalflipped'
868 && $GLOBALS['cfg']['HeaderFlipType'] == 'fake') {
869 echo PMA_flipstring(htmlspecialchars($fields_meta[$i]->name), '<br />');
870 } else {
871 echo htmlspecialchars($fields_meta[$i]->name);
873 echo "\n" . $comments . '</th>';
875 $vertical_display['desc'][] = ' <th '
876 . ($condition_field ? ' class="condition"' : '') . '>' . "\n"
877 . ' ' . htmlspecialchars($fields_meta[$i]->name) . "\n"
878 . $comments . ' </th>';
879 } // end else (2.2)
880 } // end for
882 // 3. Displays the full/partial text button (part 2) at the right
883 // column of the result table header if possible and required...
884 if ($GLOBALS['cfg']['ModifyDeleteAtRight']
885 && ($is_display['edit_lnk'] != 'nn' || $is_display['del_lnk'] != 'nn')
886 && $is_display['text_btn'] == '1') {
887 $vertical_display['emptyafter'] = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn') ? 3 : 1;
888 if ($_SESSION['userconf']['disp_direction'] == 'horizontal'
889 || $_SESSION['userconf']['disp_direction'] == 'horizontalflipped') {
890 echo "\n";
892 <th <?php echo $colspan; ?>>
893 <?php echo $text_link; ?>
894 </th>
895 <?php
896 } // end horizontal/horizontalflipped mode
897 else {
898 $vertical_display['textbtn'] = ' <th ' . $rowspan . ' valign="middle">' . "\n"
899 . ' ' . $text_link . "\n"
900 . ' </th>' . "\n";
901 } // end vertical mode
904 // ... elseif no button, displays empty columns if required
905 // (unless coming from Browse mode print view)
906 elseif ($GLOBALS['cfg']['ModifyDeleteAtRight']
907 && ($is_display['edit_lnk'] == 'nn' && $is_display['del_lnk'] == 'nn')
908 && (!$GLOBALS['is_header_sent'])) {
909 $vertical_display['emptyafter'] = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn') ? 3 : 1;
910 if ($_SESSION['userconf']['disp_direction'] == 'horizontal'
911 || $_SESSION['userconf']['disp_direction'] == 'horizontalflipped') {
912 echo "\n";
914 <td<?php echo $colspan; ?>></td>
915 <?php
916 } // end horizontal/horizontalflipped mode
917 else {
918 $vertical_display['textbtn'] = ' <td' . $rowspan . '></td>' . "\n";
919 } // end vertical mode
922 if ($_SESSION['userconf']['disp_direction'] == 'horizontal'
923 || $_SESSION['userconf']['disp_direction'] == 'horizontalflipped') {
925 </tr>
926 </thead>
927 <?php
930 return true;
931 } // end of the 'PMA_displayTableHeaders()' function
936 * Displays the body of the results table
938 * @uses $_SESSION['userconf']['disp_direction']
939 * @uses $_SESSION['userconf']['repeat_cells']
940 * @uses $_SESSION['userconf']['max_rows']
941 * @uses $_SESSION['userconf']['dontlimitchars']
942 * @param integer the link id associated to the query which results have
943 * to be displayed
944 * @param array which elements to display
945 * @param array the list of relations
946 * @param array the analyzed query
948 * @return boolean always true
950 * @global string $db the database name
951 * @global string $table the table name
952 * @global string $goto the URL to go back in case of errors
953 * @global string $sql_query the SQL query
954 * @global array $fields_meta the list of fields properties
955 * @global integer $fields_cnt the total number of fields returned by
956 * the SQL query
957 * @global array $vertical_display informations used with vertical display
958 * mode
959 * @global array $highlight_columns column names to highlight
960 * @global array $row current row data
962 * @access private
964 * @see PMA_displayTable()
966 function PMA_displayTableBody(&$dt_result, &$is_display, $map, $analyzed_sql) {
967 global $db, $table, $goto;
968 global $sql_query, $fields_meta, $fields_cnt;
969 global $vertical_display, $highlight_columns;
970 global $row; // mostly because of browser transformations, to make the row-data accessible in a plugin
972 $url_sql_query = $sql_query;
974 // query without conditions to shorten URLs when needed, 200 is just
975 // guess, it should depend on remaining URL length
977 if (isset($analyzed_sql) && isset($analyzed_sql[0]) &&
978 isset($analyzed_sql[0]['querytype']) && $analyzed_sql[0]['querytype'] == 'SELECT' &&
979 strlen($sql_query) > 200) {
981 $url_sql_query = 'SELECT ';
982 if (isset($analyzed_sql[0]['queryflags']['distinct'])) {
983 $url_sql_query .= ' DISTINCT ';
985 $url_sql_query .= $analyzed_sql[0]['select_expr_clause'];
986 if (!empty($analyzed_sql[0]['from_clause'])) {
987 $url_sql_query .= ' FROM ' . $analyzed_sql[0]['from_clause'];
991 if (!is_array($map)) {
992 $map = array();
994 $row_no = 0;
995 $vertical_display['edit'] = array();
996 $vertical_display['delete'] = array();
997 $vertical_display['data'] = array();
998 $vertical_display['row_delete'] = array();
1000 // Correction University of Virginia 19991216 in the while below
1001 // Previous code assumed that all tables have keys, specifically that
1002 // the phpMyAdmin GUI should support row delete/edit only for such
1003 // tables.
1004 // Although always using keys is arguably the prescribed way of
1005 // defining a relational table, it is not required. This will in
1006 // particular be violated by the novice.
1007 // We want to encourage phpMyAdmin usage by such novices. So the code
1008 // below has been changed to conditionally work as before when the
1009 // table being displayed has one or more keys; but to display
1010 // delete/edit options correctly for tables without keys.
1012 // loic1: use 'PMA_mysql_fetch_array' rather than 'PMA_mysql_fetch_row'
1013 // to get the NULL values
1015 // rabus: This function needs a little rework.
1016 // Using MYSQL_BOTH just pollutes the memory!
1018 // ne0x: Use function PMA_DBI_fetch_array() due to mysqli
1019 // compatibility. Now this function is wrapped.
1021 $odd_row = true;
1022 while ($row = PMA_DBI_fetch_row($dt_result)) {
1023 // lem9: "vertical display" mode stuff
1024 if ($row_no != 0 && $_SESSION['userconf']['repeat_cells'] != 0 && !($row_no % $_SESSION['userconf']['repeat_cells'])
1025 && ($_SESSION['userconf']['disp_direction'] == 'horizontal'
1026 || $_SESSION['userconf']['disp_direction'] == 'horizontalflipped'))
1028 echo '<tr>' . "\n";
1029 if ($vertical_display['emptypre'] > 0) {
1030 echo ' <th colspan="' . $vertical_display['emptypre'] . '">' . "\n"
1031 .' &nbsp;</th>' . "\n";
1034 foreach ($vertical_display['desc'] as $val) {
1035 echo $val;
1038 if ($vertical_display['emptyafter'] > 0) {
1039 echo ' <th colspan="' . $vertical_display['emptyafter'] . '">' . "\n"
1040 .' &nbsp;</th>' . "\n";
1042 echo '</tr>' . "\n";
1043 } // end if
1045 $class = $odd_row ? 'odd' : 'even';
1046 $odd_row = ! $odd_row;
1047 if ($_SESSION['userconf']['disp_direction'] == 'horizontal'
1048 || $_SESSION['userconf']['disp_direction'] == 'horizontalflipped') {
1049 // loic1: pointer code part
1050 echo ' <tr class="' . $class . '">' . "\n";
1051 $class = '';
1055 // 1. Prepares the row (gets primary keys to use)
1056 // 1.1 Results from a "SELECT" statement -> builds the
1057 // "primary" key to use in links
1059 * @todo $unique_condition could be empty, for example a table
1060 * with only one field and it's a BLOB; in this case,
1061 * avoid to display the delete and edit links
1063 $unique_condition = urlencode(PMA_getUniqueCondition($dt_result, $fields_cnt, $fields_meta, $row));
1065 // 1.2 Defines the URLs for the modify/delete link(s)
1066 $url_query = PMA_generate_common_url($db, $table);
1068 if ($is_display['edit_lnk'] != 'nn' || $is_display['del_lnk'] != 'nn') {
1069 // We need to copy the value or else the == 'both' check will always return true
1071 if ($GLOBALS['cfg']['PropertiesIconic'] === 'both') {
1072 $iconic_spacer = '<div class="nowrap">';
1073 } else {
1074 $iconic_spacer = '';
1077 // 1.2.1 Modify link(s)
1078 if ($is_display['edit_lnk'] == 'ur') { // update row case
1079 $lnk_goto = 'sql.php';
1081 $edit_url = 'tbl_change.php'
1082 . '?' . $url_query
1083 . '&amp;primary_key=' . $unique_condition
1084 . '&amp;sql_query=' . urlencode($url_sql_query)
1085 . '&amp;goto=' . urlencode($lnk_goto);
1086 if ($GLOBALS['cfg']['PropertiesIconic'] === false) {
1087 $edit_str = $GLOBALS['strEdit'];
1088 } else {
1089 $edit_str = $iconic_spacer . '<img class="icon" width="16" height="16" src="' . $GLOBALS['pmaThemeImage'] . 'b_edit.png" alt="' . $GLOBALS['strEdit'] . '" title="' . $GLOBALS['strEdit'] . '" />';
1090 if ($GLOBALS['cfg']['PropertiesIconic'] === 'both') {
1091 $edit_str .= ' ' . $GLOBALS['strEdit'] . '</div>';
1094 } // end if (1.2.1)
1096 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])) {
1097 $bookmark_go = '<a href="import.php?'
1098 . PMA_generate_common_url($row[1], '')
1099 . '&amp;id_bookmark=' . $row[0]
1100 . '&amp;action_bookmark=0'
1101 . '&amp;action_bookmark_all=1'
1102 . '&amp;SQL=' . $GLOBALS['strExecuteBookmarked']
1103 .' " title="' . $GLOBALS['strExecuteBookmarked'] . '">';
1105 if ($GLOBALS['cfg']['PropertiesIconic'] === false) {
1106 $bookmark_go .= $GLOBALS['strExecuteBookmarked'];
1107 } else {
1108 $bookmark_go .= $iconic_spacer . '<img class="icon" width="16" height="16" src="' . $GLOBALS['pmaThemeImage'] . 'b_bookmark.png" alt="' . $GLOBALS['strExecuteBookmarked'] . '" title="' . $GLOBALS['strExecuteBookmarked'] . '" />';
1109 if ($GLOBALS['cfg']['PropertiesIconic'] === 'both') {
1110 $bookmark_go .= ' ' . $GLOBALS['strExecuteBookmarked'] . '</div>';
1114 $bookmark_go .= '</a>';
1115 } else {
1116 $bookmark_go = '';
1119 // 1.2.2 Delete/Kill link(s)
1120 if ($is_display['del_lnk'] == 'dr') { // delete row case
1121 $lnk_goto = 'sql.php'
1122 . '?' . str_replace('&amp;', '&', $url_query)
1123 . '&sql_query=' . urlencode($url_sql_query)
1124 . '&zero_rows=' . urlencode(htmlspecialchars($GLOBALS['strDeleted']))
1125 . '&goto=' . (empty($goto) ? 'tbl_sql.php' : $goto);
1126 $del_query = urlencode('DELETE FROM ' . PMA_backquote($table) . ' WHERE') . $unique_condition . '+LIMIT+1';
1127 $del_url = 'sql.php'
1128 . '?' . $url_query
1129 . '&amp;sql_query=' . $del_query
1130 . '&amp;zero_rows=' . urlencode(htmlspecialchars($GLOBALS['strDeleted']))
1131 . '&amp;goto=' . urlencode($lnk_goto);
1132 $js_conf = 'DELETE FROM ' . PMA_jsFormat($table)
1133 . ' WHERE ' . trim(PMA_jsFormat(urldecode($unique_condition), false))
1134 . ' LIMIT 1';
1135 if ($GLOBALS['cfg']['PropertiesIconic'] === false) {
1136 $del_str = $GLOBALS['strDelete'];
1137 } else {
1138 $del_str = $iconic_spacer . '<img class="icon" width="16" height="16" src="' . $GLOBALS['pmaThemeImage'] . 'b_drop.png" alt="' . $GLOBALS['strDelete'] . '" title="' . $GLOBALS['strDelete'] . '" />';
1139 if ($GLOBALS['cfg']['PropertiesIconic'] === 'both') {
1140 $del_str .= ' ' . $GLOBALS['strDelete'] . '</div>';
1143 } elseif ($is_display['del_lnk'] == 'kp') { // kill process case
1144 $lnk_goto = 'sql.php'
1145 . '?' . str_replace('&amp;', '&', $url_query)
1146 . '&sql_query=' . urlencode($url_sql_query)
1147 . '&goto=main.php';
1148 $del_url = 'sql.php?'
1149 . PMA_generate_common_url('mysql')
1150 . '&amp;sql_query=' . urlencode('KILL ' . $row[0])
1151 . '&amp;goto=' . urlencode($lnk_goto);
1152 $del_query = urlencode('KILL ' . $row[0]);
1153 $js_conf = 'KILL ' . $row[0];
1154 if ($GLOBALS['cfg']['PropertiesIconic'] === false) {
1155 $del_str = $GLOBALS['strKill'];
1156 } else {
1157 $del_str = $iconic_spacer . '<img class="icon" width="16" height="16" src="' . $GLOBALS['pmaThemeImage'] . 'b_drop.png" alt="' . $GLOBALS['strKill'] . '" title="' . $GLOBALS['strKill'] . '" />';
1158 if ($GLOBALS['cfg']['PropertiesIconic'] === 'both') {
1159 $del_str .= ' ' . $GLOBALS['strKill'] . '</div>';
1162 } // end if (1.2.2)
1164 // 1.3 Displays the links at left if required
1165 if ($GLOBALS['cfg']['ModifyDeleteAtLeft']
1166 && ($_SESSION['userconf']['disp_direction'] == 'horizontal'
1167 || $_SESSION['userconf']['disp_direction'] == 'horizontalflipped')) {
1168 $doWriteModifyAt = 'left';
1169 require './libraries/display_tbl_links.lib.php';
1170 } // end if (1.3)
1171 } // end if (1)
1173 // 2. Displays the rows' values
1174 for ($i = 0; $i < $fields_cnt; ++$i) {
1175 $meta = $fields_meta[$i];
1176 // loic1: To fix bug #474943 under php4, the row pointer will
1177 // depend on whether the "is_null" php4 function is
1178 // available or not
1179 $pointer = (function_exists('is_null') ? $i : $meta->name);
1180 // garvin: See if this column should get highlight because it's used in the
1181 // where-query.
1182 if (isset($highlight_columns) && (isset($highlight_columns[$meta->name]) || isset($highlight_columns[PMA_backquote($meta->name)]))) {
1183 $condition_field = true;
1184 } else {
1185 $condition_field = false;
1188 $mouse_events = '';
1189 if ($_SESSION['userconf']['disp_direction'] == 'vertical' && (!isset($GLOBALS['printview']) || ($GLOBALS['printview'] != '1'))) {
1190 if ($GLOBALS['cfg']['BrowsePointerEnable'] == true) {
1191 $mouse_events .= ' onmouseover="setVerticalPointer(this, ' . $row_no . ', \'over\', \'odd\', \'even\', \'hover\', \'marked\');"'
1192 . ' onmouseout="setVerticalPointer(this, ' . $row_no . ', \'out\', \'odd\', \'even\', \'hover\', \'marked\');" ';
1194 if ($GLOBALS['cfg']['BrowseMarkerEnable'] == true) {
1195 $mouse_events .= ' onmousedown="setVerticalPointer(this, ' . $row_no . ', \'click\', \'odd\', \'even\', \'hover\', \'marked\'); setCheckboxColumn(\'id_rows_to_delete' . $row_no . '\');" ';
1196 } else {
1197 $mouse_events .= ' onmousedown="setCheckboxColumn(\'id_rows_to_delete' . $row_no . '\');" ';
1199 }// end if
1201 // garvin: Wrap MIME-transformations. [MIME]
1202 $default_function = 'default_function'; // default_function
1203 $transform_function = $default_function;
1204 $transform_options = array();
1206 if ($GLOBALS['cfgRelation']['mimework'] && $GLOBALS['cfg']['BrowseMIME']) {
1208 if (isset($GLOBALS['mime_map'][$meta->name]['mimetype']) && isset($GLOBALS['mime_map'][$meta->name]['transformation']) && !empty($GLOBALS['mime_map'][$meta->name]['transformation'])) {
1209 $include_file = PMA_sanitizeTransformationFile($GLOBALS['mime_map'][$meta->name]['transformation']);
1211 if (file_exists('./libraries/transformations/' . $include_file)) {
1212 $transformfunction_name = preg_replace('@(\.inc\.php3?)$@i', '', $GLOBALS['mime_map'][$meta->name]['transformation']);
1214 require_once './libraries/transformations/' . $include_file;
1216 if (function_exists('PMA_transformation_' . $transformfunction_name)) {
1217 $transform_function = 'PMA_transformation_' . $transformfunction_name;
1218 $transform_options = PMA_transformation_getOptions((isset($GLOBALS['mime_map'][$meta->name]['transformation_options']) ? $GLOBALS['mime_map'][$meta->name]['transformation_options'] : ''));
1219 $meta->mimetype = str_replace('_', '/', $GLOBALS['mime_map'][$meta->name]['mimetype']);
1221 } // end if file_exists
1222 } // end if transformation is set
1223 } // end if mime/transformation works.
1225 $transform_options['wrapper_link'] = '?'
1226 . (isset($url_query) ? $url_query : '')
1227 . '&amp;primary_key=' . (isset($unique_condition) ? $unique_condition : '')
1228 . '&amp;sql_query=' . (empty($sql_query) ? '' : urlencode($url_sql_query))
1229 . '&amp;goto=' . (isset($sql_goto) ? urlencode($lnk_goto) : '')
1230 . '&amp;transform_key=' . urlencode($meta->name);
1233 // n u m e r i c
1234 if ($meta->numeric == 1) {
1236 // lem9: if two fields have the same name (this is possible
1237 // with self-join queries, for example), using $meta->name
1238 // will show both fields NULL even if only one is NULL,
1239 // so use the $pointer
1240 // (works only if function_exists('is_null')
1241 // PS: why not always work with the number ($i), since
1242 // the default second parameter of
1243 // mysql_fetch_array() is MYSQL_BOTH, so we always get
1244 // associative and numeric indices?
1246 if (!isset($row[$i]) || is_null($row[$i])) {
1247 $vertical_display['data'][$row_no][$i] = ' <td align="right"' . $mouse_events . ' class="' . $class . ($condition_field ? ' condition' : '') . '"><i>NULL</i></td>' . "\n";
1248 } elseif ($row[$i] != '') {
1249 $vertical_display['data'][$row_no][$i] = ' <td align="right"' . $mouse_events . ' class="' . $class . ($condition_field ? ' condition' : '') . ' nowrap">';
1251 if (isset($analyzed_sql[0]['select_expr']) && is_array($analyzed_sql[0]['select_expr'])) {
1252 foreach ($analyzed_sql[0]['select_expr'] AS $select_expr_position => $select_expr) {
1253 $alias = $analyzed_sql[0]['select_expr'][$select_expr_position]['alias'];
1254 if (isset($alias) && strlen($alias)) {
1255 $true_column = $analyzed_sql[0]['select_expr'][$select_expr_position]['column'];
1256 if ($alias == $meta->name) {
1257 $meta->name = $true_column;
1258 } // end if
1259 } // end if
1260 } // end while
1263 if (isset($map[$meta->name])) {
1264 // Field to display from the foreign table?
1265 if (isset($map[$meta->name][2]) && strlen($map[$meta->name][2])) {
1266 $dispsql = 'SELECT ' . PMA_backquote($map[$meta->name][2])
1267 . ' FROM ' . PMA_backquote($map[$meta->name][3]) . '.' . PMA_backquote($map[$meta->name][0])
1268 . ' WHERE ' . PMA_backquote($map[$meta->name][1])
1269 . ' = ' . $row[$i];
1270 $dispresult = PMA_DBI_try_query($dispsql, null, PMA_DBI_QUERY_STORE);
1271 if ($dispresult && PMA_DBI_num_rows($dispresult) > 0) {
1272 list($dispval) = PMA_DBI_fetch_row($dispresult, 0);
1273 } else {
1274 $dispval = $GLOBALS['strLinkNotFound'];
1276 @PMA_DBI_free_result($dispresult);
1277 } else {
1278 $dispval = '';
1279 } // end if... else...
1281 if (isset($GLOBALS['printview']) && $GLOBALS['printview'] == '1') {
1282 $vertical_display['data'][$row_no][$i] .= ($transform_function != $default_function ? $transform_function($row[$i], $transform_options, $meta) : $transform_function($row[$i], array(), $meta)) . ' <code>[-&gt;' . $dispval . ']</code>';
1283 } else {
1284 $title = (!empty($dispval))? ' title="' . htmlspecialchars($dispval) . '"' : '';
1286 $vertical_display['data'][$row_no][$i] .= '<a href="sql.php?'
1287 . PMA_generate_common_url($map[$meta->name][3], $map[$meta->name][0])
1288 . '&amp;pos=0'
1289 . '&amp;sql_query=' . urlencode('SELECT * FROM ' . PMA_backquote($map[$meta->name][0]) . ' WHERE ' . PMA_backquote($map[$meta->name][1]) . ' = ' . $row[$i]) . '"' . $title . '>'
1290 . ($transform_function != $default_function ? $transform_function($row[$i], $transform_options, $meta) : $transform_function($row[$i], array(), $meta)) . '</a>';
1292 } else {
1293 $vertical_display['data'][$row_no][$i] .= ($transform_function != $default_function ? $transform_function($row[$i], $transform_options, $meta) : $transform_function($row[$i], array(), $meta));
1295 $vertical_display['data'][$row_no][$i] .= '</td>' . "\n";
1296 } else {
1297 $vertical_display['data'][$row_no][$i] = ' <td align="right"' . $mouse_events . ' class="' . $class . ' nowrap' . ($condition_field ? ' condition' : '') . '">&nbsp;</td>' . "\n";
1300 // b l o b
1302 } elseif ($GLOBALS['cfg']['ShowBlob'] == false && stristr($meta->type, 'BLOB')) {
1303 // loic1 : PMA_mysql_fetch_fields returns BLOB in place of
1304 // TEXT fields type, however TEXT fields must be displayed
1305 // even if $GLOBALS['cfg']['ShowBlob'] is false -> get the true type
1306 // of the fields.
1307 $field_flags = PMA_DBI_field_flags($dt_result, $i);
1308 if (stristr($field_flags, 'BINARY')) {
1309 $blobtext = PMA_handle_non_printable_contents('BLOB', (isset($row[$i]) ? $row[$i] : ''), $transform_function, $transform_options, $default_function, $meta);
1310 $vertical_display['data'][$row_no][$i] = ' <td align="left"' . $mouse_events . ' class="' . $class . ($condition_field ? ' condition' : '') . '">' . $blobtext . '</td>';
1311 unset($blobtext);
1312 } else {
1313 if (!isset($row[$i]) || is_null($row[$i])) {
1314 $vertical_display['data'][$row_no][$i] = ' <td' . $mouse_events . ' class="' . $class . ($condition_field ? ' condition' : '') . '"><i>NULL</i></td>' . "\n";
1315 } elseif ($row[$i] != '') {
1316 // garvin: if a transform function for blob is set, none of these replacements will be made
1317 if (PMA_strlen($row[$i]) > $GLOBALS['cfg']['LimitChars'] && ! $_SESSION['userconf']['dontlimitchars']) {
1318 $row[$i] = PMA_substr($row[$i], 0, $GLOBALS['cfg']['LimitChars']) . '...';
1320 // loic1: displays all space characters, 4 space
1321 // characters for tabulations and <cr>/<lf>
1322 $row[$i] = ($default_function != $transform_function ? $transform_function($row[$i], $transform_options, $meta) : $default_function($row[$i], array(), $meta));
1324 $vertical_display['data'][$row_no][$i] = ' <td' . $mouse_events . ' class="' . $class . ($condition_field ? ' condition' : '') . '">' . $row[$i] . '</td>' . "\n";
1325 } else {
1326 $vertical_display['data'][$row_no][$i] = ' <td' . $mouse_events . ' class="' . $class . ($condition_field ? ' condition' : '') . '">&nbsp;</td>' . "\n";
1329 } else {
1330 if (!isset($row[$i]) || is_null($row[$i])) {
1331 $vertical_display['data'][$row_no][$i] = ' <td' . $mouse_events . ' class="' . $class . ($condition_field ? ' condition' : '') . '"><i>NULL</i></td>' . "\n";
1332 } elseif ($row[$i] != '') {
1333 // loic1: support blanks in the key
1334 $relation_id = $row[$i];
1336 // nijel: Cut all fields to $GLOBALS['cfg']['LimitChars']
1337 // lem9: (unless it's a link-type transformation)
1338 if (PMA_strlen($row[$i]) > $GLOBALS['cfg']['LimitChars'] && ! $_SESSION['userconf']['dontlimitchars'] && !strpos($transform_function, 'link') === true) {
1339 $row[$i] = PMA_substr($row[$i], 0, $GLOBALS['cfg']['LimitChars']) . '...';
1342 // loic1: displays special characters from binaries
1343 $field_flags = PMA_DBI_field_flags($dt_result, $i);
1344 if (isset($meta->_type) && $meta->_type === MYSQLI_TYPE_BIT) {
1345 $row[$i] = PMA_printable_bit_value($row[$i], $meta->length);
1346 } elseif (stristr($field_flags, 'BINARY')) {
1347 $row[$i] = PMA_handle_non_printable_contents('BINARY', $row[$i], $transform_function, $transform_options, $default_function, $meta);
1349 // loic1: displays all space characters, 4 space
1350 // characters for tabulations and <cr>/<lf>
1351 else {
1352 $row[$i] = ($default_function != $transform_function ? $transform_function($row[$i], $transform_options, $meta) : $default_function($row[$i], array(), $meta));
1355 // garvin: transform functions may enable no-wrapping:
1356 $function_nowrap = $transform_function . '_nowrap';
1357 $bool_nowrap = (($default_function != $transform_function && function_exists($function_nowrap)) ? $function_nowrap($transform_options) : false);
1359 // loic1: do not wrap if date field type
1360 $nowrap = ((preg_match('@DATE|TIME@i', $meta->type) || $bool_nowrap) ? ' nowrap' : '');
1361 $vertical_display['data'][$row_no][$i] = ' <td' . $mouse_events . ' class="' . $class . $nowrap . ($condition_field ? ' condition' : '') . '">';
1363 if (isset($analyzed_sql[0]['select_expr']) && is_array($analyzed_sql[0]['select_expr'])) {
1364 foreach ($analyzed_sql[0]['select_expr'] AS $select_expr_position => $select_expr) {
1365 $alias = $analyzed_sql[0]['select_expr'][$select_expr_position]['alias'];
1366 if (isset($alias) && strlen($alias)) {
1367 $true_column = $analyzed_sql[0]['select_expr'][$select_expr_position]['column'];
1368 if ($alias == $meta->name) {
1369 $meta->name = $true_column;
1370 } // end if
1371 } // end if
1372 } // end while
1375 if (isset($map[$meta->name])) {
1376 // Field to display from the foreign table?
1377 if (isset($map[$meta->name][2]) && strlen($map[$meta->name][2])) {
1378 $dispsql = 'SELECT ' . PMA_backquote($map[$meta->name][2])
1379 . ' FROM ' . PMA_backquote($map[$meta->name][3]) . '.' . PMA_backquote($map[$meta->name][0])
1380 . ' WHERE ' . PMA_backquote($map[$meta->name][1])
1381 . ' = \'' . PMA_sqlAddslashes($row[$i]) . '\'';
1382 $dispresult = PMA_DBI_try_query($dispsql, null, PMA_DBI_QUERY_STORE);
1383 if ($dispresult && PMA_DBI_num_rows($dispresult) > 0) {
1384 list($dispval) = PMA_DBI_fetch_row($dispresult);
1385 @PMA_DBI_free_result($dispresult);
1386 } else {
1387 $dispval = $GLOBALS['strLinkNotFound'];
1389 } else {
1390 $dispval = '';
1392 $title = (!empty($dispval))? ' title="' . htmlspecialchars($dispval) . '"' : '';
1394 $vertical_display['data'][$row_no][$i] .= '<a href="sql.php?'
1395 . PMA_generate_common_url($map[$meta->name][3], $map[$meta->name][0])
1396 . '&amp;pos=0'
1397 . '&amp;sql_query=' . urlencode('SELECT * FROM ' . PMA_backquote($map[$meta->name][0]) . ' WHERE ' . PMA_backquote($map[$meta->name][1]) . ' = \'' . PMA_sqlAddslashes($relation_id) . '\'') . '"' . $title . '>'
1398 . $row[$i] . '</a>';
1399 } else {
1400 $vertical_display['data'][$row_no][$i] .= $row[$i];
1402 $vertical_display['data'][$row_no][$i] .= '</td>' . "\n";
1403 } else {
1404 $vertical_display['data'][$row_no][$i] = ' <td' . $mouse_events . ' class="' . $class . ($condition_field ? ' condition' : '') . '">&nbsp;</td>' . "\n";
1408 // lem9: output stored cell
1409 if ($_SESSION['userconf']['disp_direction'] == 'horizontal'
1410 || $_SESSION['userconf']['disp_direction'] == 'horizontalflipped') {
1411 echo $vertical_display['data'][$row_no][$i];
1414 if (isset($vertical_display['rowdata'][$i][$row_no])) {
1415 $vertical_display['rowdata'][$i][$row_no] .= $vertical_display['data'][$row_no][$i];
1416 } else {
1417 $vertical_display['rowdata'][$i][$row_no] = $vertical_display['data'][$row_no][$i];
1419 } // end for (2)
1421 // 3. Displays the modify/delete links on the right if required
1422 if ($GLOBALS['cfg']['ModifyDeleteAtRight']
1423 && ($_SESSION['userconf']['disp_direction'] == 'horizontal'
1424 || $_SESSION['userconf']['disp_direction'] == 'horizontalflipped')) {
1425 $doWriteModifyAt = 'right';
1426 require './libraries/display_tbl_links.lib.php';
1427 } // end if (3)
1429 if ($_SESSION['userconf']['disp_direction'] == 'horizontal'
1430 || $_SESSION['userconf']['disp_direction'] == 'horizontalflipped') {
1432 </tr>
1433 <?php
1434 } // end if
1436 // 4. Gather links of del_urls and edit_urls in an array for later
1437 // output
1438 if (!isset($vertical_display['edit'][$row_no])) {
1439 $vertical_display['edit'][$row_no] = '';
1440 $vertical_display['delete'][$row_no] = '';
1441 $vertical_display['row_delete'][$row_no] = '';
1444 $column_style_vertical = '';
1445 if ($GLOBALS['cfg']['BrowsePointerEnable'] == true) {
1446 $column_style_vertical .= ' onmouseover="setVerticalPointer(this, ' . $row_no . ', \'over\', \'odd\', \'even\', \'hover\', \'marked\');"'
1447 . ' onmouseout="setVerticalPointer(this, ' . $row_no . ', \'out\', \'odd\', \'even\', \'hover\', \'marked\');"';
1449 $column_marker_vertical = '';
1450 if ($GLOBALS['cfg']['BrowseMarkerEnable'] == true) {
1451 $column_marker_vertical .= 'setVerticalPointer(this, ' . $row_no . ', \'click\', \'odd\', \'even\', \'hover\', \'marked\');';
1454 if (!empty($del_url) && $is_display['del_lnk'] != 'kp') {
1455 $vertical_display['row_delete'][$row_no] .= ' <td align="center" class="' . $class . '" ' . $column_style_vertical . '>' . "\n"
1456 . ' <input type="checkbox" id="id_rows_to_delete' . $row_no . '[%_PMA_CHECKBOX_DIR_%]" name="rows_to_delete[' . $unique_condition . ']"'
1457 . ' onclick="' . $column_marker_vertical . 'copyCheckboxesRange(\'rowsDeleteForm\', \'id_rows_to_delete' . $row_no . '\',\'[%_PMA_CHECKBOX_DIR_%]\');"'
1458 . ' value="' . $del_query . '" ' . (isset($GLOBALS['checkall']) ? 'checked="checked"' : '') . ' />' . "\n"
1459 . ' </td>' . "\n";
1460 } else {
1461 unset($vertical_display['row_delete'][$row_no]);
1464 if (isset($edit_url)) {
1465 $vertical_display['edit'][$row_no] .= ' <td align="center" class="' . $class . '" ' . $column_style_vertical . '>' . "\n"
1466 . PMA_linkOrButton($edit_url, $edit_str, array(), false)
1467 . $bookmark_go
1468 . ' </td>' . "\n";
1469 } else {
1470 unset($vertical_display['edit'][$row_no]);
1473 if (isset($del_url)) {
1474 $vertical_display['delete'][$row_no] .= ' <td align="center" class="' . $class . '" ' . $column_style_vertical . '>' . "\n"
1475 . PMA_linkOrButton($del_url, $del_str, (isset($js_conf) ? $js_conf : ''), false)
1476 . ' </td>' . "\n";
1477 } else {
1478 unset($vertical_display['delete'][$row_no]);
1481 echo (($_SESSION['userconf']['disp_direction'] == 'horizontal' || $_SESSION['userconf']['disp_direction'] == 'horizontalflipped') ? "\n" : '');
1482 $row_no++;
1483 } // end while
1485 if (isset($url_query)) {
1486 $GLOBALS['url_query'] = $url_query;
1489 return true;
1490 } // end of the 'PMA_displayTableBody()' function
1494 * Do display the result table with the vertical direction mode.
1495 * Credits for this feature goes to Garvin Hicking <hicking@faktor-e.de>.
1497 * @return boolean always true
1499 * @uses $_SESSION['userconf']['repeat_cells']
1500 * @global array $vertical_display the information to display
1502 * @access private
1504 * @see PMA_displayTable()
1506 function PMA_displayVerticalTable()
1508 global $vertical_display;
1510 // Displays "multi row delete" link at top if required
1511 if ($GLOBALS['cfg']['ModifyDeleteAtLeft'] && is_array($vertical_display['row_delete']) && (count($vertical_display['row_delete']) > 0 || !empty($vertical_display['textbtn']))) {
1512 echo '<tr>' . "\n";
1513 echo $vertical_display['textbtn'];
1514 $foo_counter = 0;
1515 foreach ($vertical_display['row_delete'] as $val) {
1516 if (($foo_counter != 0) && ($_SESSION['userconf']['repeat_cells'] != 0) && !($foo_counter % $_SESSION['userconf']['repeat_cells'])) {
1517 echo '<th>&nbsp;</th>' . "\n";
1520 echo str_replace('[%_PMA_CHECKBOX_DIR_%]', '', $val);
1521 $foo_counter++;
1522 } // end while
1523 echo '</tr>' . "\n";
1524 } // end if
1526 // Displays "edit" link at top if required
1527 if ($GLOBALS['cfg']['ModifyDeleteAtLeft'] && is_array($vertical_display['edit']) && (count($vertical_display['edit']) > 0 || !empty($vertical_display['textbtn']))) {
1528 echo '<tr>' . "\n";
1529 if (!is_array($vertical_display['row_delete'])) {
1530 echo $vertical_display['textbtn'];
1532 $foo_counter = 0;
1533 foreach ($vertical_display['edit'] as $val) {
1534 if (($foo_counter != 0) && ($_SESSION['userconf']['repeat_cells'] != 0) && !($foo_counter % $_SESSION['userconf']['repeat_cells'])) {
1535 echo ' <th>&nbsp;</th>' . "\n";
1538 echo $val;
1539 $foo_counter++;
1540 } // end while
1541 echo '</tr>' . "\n";
1542 } // end if
1544 // Displays "delete" link at top if required
1545 if ($GLOBALS['cfg']['ModifyDeleteAtLeft'] && is_array($vertical_display['delete']) && (count($vertical_display['delete']) > 0 || !empty($vertical_display['textbtn']))) {
1546 echo '<tr>' . "\n";
1547 if (!is_array($vertical_display['edit']) && !is_array($vertical_display['row_delete'])) {
1548 echo $vertical_display['textbtn'];
1550 $foo_counter = 0;
1551 foreach ($vertical_display['delete'] as $val) {
1552 if (($foo_counter != 0) && ($_SESSION['userconf']['repeat_cells'] != 0) && !($foo_counter % $_SESSION['userconf']['repeat_cells'])) {
1553 echo '<th>&nbsp;</th>' . "\n";
1556 echo $val;
1557 $foo_counter++;
1558 } // end while
1559 echo '</tr>' . "\n";
1560 } // end if
1562 // Displays data
1563 foreach ($vertical_display['desc'] AS $key => $val) {
1565 echo '<tr>' . "\n";
1566 echo $val;
1568 $foo_counter = 0;
1569 foreach ($vertical_display['rowdata'][$key] as $subval) {
1570 if (($foo_counter != 0) && ($_SESSION['userconf']['repeat_cells'] != 0) and !($foo_counter % $_SESSION['userconf']['repeat_cells'])) {
1571 echo $val;
1574 echo $subval;
1575 $foo_counter++;
1576 } // end while
1578 echo '</tr>' . "\n";
1579 } // end while
1581 // Displays "multi row delete" link at bottom if required
1582 if ($GLOBALS['cfg']['ModifyDeleteAtRight'] && is_array($vertical_display['row_delete']) && (count($vertical_display['row_delete']) > 0 || !empty($vertical_display['textbtn']))) {
1583 echo '<tr>' . "\n";
1584 echo $vertical_display['textbtn'];
1585 $foo_counter = 0;
1586 foreach ($vertical_display['row_delete'] as $val) {
1587 if (($foo_counter != 0) && ($_SESSION['userconf']['repeat_cells'] != 0) && !($foo_counter % $_SESSION['userconf']['repeat_cells'])) {
1588 echo '<th>&nbsp;</th>' . "\n";
1591 echo str_replace('[%_PMA_CHECKBOX_DIR_%]', 'r', $val);
1592 $foo_counter++;
1593 } // end while
1594 echo '</tr>' . "\n";
1595 } // end if
1597 // Displays "edit" link at bottom if required
1598 if ($GLOBALS['cfg']['ModifyDeleteAtRight'] && is_array($vertical_display['edit']) && (count($vertical_display['edit']) > 0 || !empty($vertical_display['textbtn']))) {
1599 echo '<tr>' . "\n";
1600 if (!is_array($vertical_display['row_delete'])) {
1601 echo $vertical_display['textbtn'];
1603 $foo_counter = 0;
1604 foreach ($vertical_display['edit'] as $val) {
1605 if (($foo_counter != 0) && ($_SESSION['userconf']['repeat_cells'] != 0) && !($foo_counter % $_SESSION['userconf']['repeat_cells'])) {
1606 echo '<th>&nbsp;</th>' . "\n";
1609 echo $val;
1610 $foo_counter++;
1611 } // end while
1612 echo '</tr>' . "\n";
1613 } // end if
1615 // Displays "delete" link at bottom if required
1616 if ($GLOBALS['cfg']['ModifyDeleteAtRight'] && is_array($vertical_display['delete']) && (count($vertical_display['delete']) > 0 || !empty($vertical_display['textbtn']))) {
1617 echo '<tr>' . "\n";
1618 if (!is_array($vertical_display['edit']) && !is_array($vertical_display['row_delete'])) {
1619 echo $vertical_display['textbtn'];
1621 $foo_counter = 0;
1622 foreach ($vertical_display['delete'] as $val) {
1623 if (($foo_counter != 0) && ($_SESSION['userconf']['repeat_cells'] != 0) && !($foo_counter % $_SESSION['userconf']['repeat_cells'])) {
1624 echo '<th>&nbsp;</th>' . "\n";
1627 echo $val;
1628 $foo_counter++;
1629 } // end while
1630 echo '</tr>' . "\n";
1633 return true;
1634 } // end of the 'PMA_displayVerticalTable' function
1638 * @uses $_SESSION['userconf']['disp_direction']
1639 * @uses $_REQUEST['disp_direction']
1640 * @uses $GLOBALS['cfg']['DefaultDisplay']
1641 * @uses $_SESSION['userconf']['repeat_cells']
1642 * @uses $_REQUEST['repeat_cells']
1643 * @uses $GLOBALS['cfg']['RepeatCells']
1644 * @uses $_SESSION['userconf']['max_rows']
1645 * @uses $_REQUEST['session_max_rows']
1646 * @uses $GLOBALS['cfg']['MaxRows']
1647 * @uses $_SESSION['userconf']['pos']
1648 * @uses $_REQUEST['pos']
1649 * @uses $_SESSION['userconf']['dontlimitchars']
1650 * @uses $_REQUEST['dontlimitchars']
1651 * @uses PMA_isValid()
1652 * @uses $GLOBALS['sql_query']
1653 * @todo make maximum remembered queries configurable
1654 * @todo move/split into SQL class!?
1655 * @todo currently this is called twice unnecessary
1656 * @todo ignore LIMIT and ORDER in query!?
1658 function PMA_displayTable_checkConfigParams()
1660 $sql_key = md5($GLOBALS['sql_query']);
1662 $_SESSION['userconf']['query'][$sql_key]['sql'] = $GLOBALS['sql_query'];
1664 if (PMA_isValid($_REQUEST['disp_direction'], array('horizontal', 'vertical', 'horizontalflipped'))) {
1665 $_SESSION['userconf']['query'][$sql_key]['disp_direction'] = $_REQUEST['disp_direction'];
1666 unset($_REQUEST['disp_direction']);
1667 } elseif (empty($_SESSION['userconf']['query'][$sql_key]['disp_direction'])) {
1668 $_SESSION['userconf']['query'][$sql_key]['disp_direction'] = $GLOBALS['cfg']['DefaultDisplay'];
1671 if (PMA_isValid($_REQUEST['repeat_cells'], 'numeric')) {
1672 $_SESSION['userconf']['query'][$sql_key]['repeat_cells'] = $_REQUEST['repeat_cells'];
1673 unset($_REQUEST['repeat_cells']);
1674 } elseif (empty($_SESSION['userconf']['query'][$sql_key]['repeat_cells'])) {
1675 $_SESSION['userconf']['query'][$sql_key]['repeat_cells'] = $GLOBALS['cfg']['RepeatCells'];
1678 if (PMA_isValid($_REQUEST['session_max_rows'], 'numeric') || $_REQUEST['session_max_rows'] == 'all') {
1679 $_SESSION['userconf']['query'][$sql_key]['max_rows'] = $_REQUEST['session_max_rows'];
1680 unset($_REQUEST['session_max_rows']);
1681 } elseif (empty($_SESSION['userconf']['query'][$sql_key]['max_rows'])) {
1682 $_SESSION['userconf']['query'][$sql_key]['max_rows'] = $GLOBALS['cfg']['MaxRows'];
1685 if (PMA_isValid($_REQUEST['pos'], 'numeric')) {
1686 $_SESSION['userconf']['query'][$sql_key]['pos'] = $_REQUEST['pos'];
1687 unset($_REQUEST['pos']);
1688 } elseif (empty($_SESSION['userconf']['query'][$sql_key]['pos'])) {
1689 $_SESSION['userconf']['query'][$sql_key]['pos'] = 0;
1692 if (PMA_isValid($_REQUEST['dontlimitchars'], array('0', '1'))) {
1693 $_SESSION['userconf']['query'][$sql_key]['dontlimitchars'] = (int) $_REQUEST['dontlimitchars'];
1694 unset($_REQUEST['dontlimitchars']);
1695 } elseif (empty($_SESSION['userconf']['query'][$sql_key]['dontlimitchars'])) {
1696 $_SESSION['userconf']['query'][$sql_key]['dontlimitchars'] = 0;
1699 // move current query to the last position, to be removed last
1700 // so only least executed query will be removed if maximum remembered queries
1701 // limit is reached
1702 $tmp = $_SESSION['userconf']['query'][$sql_key];
1703 unset($_SESSION['userconf']['query'][$sql_key]);
1704 $_SESSION['userconf']['query'][$sql_key] = $tmp;
1706 // do not exceed a maximum number of queries to remember
1707 if (count($_SESSION['userconf']['query']) > 10) {
1708 array_shift($_SESSION['userconf']['query']);
1709 //echo 'deleting one element ...';
1712 // populate query configuration
1713 $_SESSION['userconf']['dontlimitchars'] = $_SESSION['userconf']['query'][$sql_key]['dontlimitchars'];
1714 $_SESSION['userconf']['pos'] = $_SESSION['userconf']['query'][$sql_key]['pos'];
1715 $_SESSION['userconf']['max_rows'] = $_SESSION['userconf']['query'][$sql_key]['max_rows'];
1716 $_SESSION['userconf']['repeat_cells'] = $_SESSION['userconf']['query'][$sql_key]['repeat_cells'];
1717 $_SESSION['userconf']['disp_direction'] = $_SESSION['userconf']['query'][$sql_key]['disp_direction'];
1720 * debugging
1721 echo '<pre>';
1722 var_dump($_SESSION['userconf']);
1723 echo '</pre>';
1728 * Displays a table of results returned by a SQL query.
1729 * This function is called by the "sql.php" script.
1731 * @param integer the link id associated to the query which results have
1732 * to be displayed
1733 * @param array the display mode
1734 * @param array the analyzed query
1736 * @uses $_SESSION['userconf']['pos']
1737 * @global string $db the database name
1738 * @global string $table the table name
1739 * @global string $goto the URL to go back in case of errors
1740 * @global string $sql_query the current SQL query
1741 * @global integer $num_rows the total number of rows returned by the
1742 * SQL query
1743 * @global integer $unlim_num_rows the total number of rows returned by the
1744 * SQL query without any programmatically
1745 * appended "LIMIT" clause
1746 * @global array $fields_meta the list of fields properties
1747 * @global integer $fields_cnt the total number of fields returned by
1748 * the SQL query
1749 * @global array $vertical_display informations used with vertical display
1750 * mode
1751 * @global array $highlight_columns column names to highlight
1752 * @global array $cfgRelation the relation settings
1754 * @access private
1756 * @see PMA_showMessage(), PMA_setDisplayMode(),
1757 * PMA_displayTableNavigation(), PMA_displayTableHeaders(),
1758 * PMA_displayTableBody(), PMA_displayResultsOperations()
1760 function PMA_displayTable(&$dt_result, &$the_disp_mode, $analyzed_sql)
1762 global $db, $table, $goto;
1763 global $sql_query, $num_rows, $unlim_num_rows, $fields_meta, $fields_cnt;
1764 global $vertical_display, $highlight_columns;
1765 global $cfgRelation;
1766 global $showtable;
1768 PMA_displayTable_checkConfigParams();
1771 * @todo move this to a central place
1772 * @todo for other future table types
1774 $is_innodb = (isset($showtable['Type']) && $showtable['Type'] == 'InnoDB');
1776 if ($is_innodb
1777 && ! isset($analyzed_sql[0]['queryflags']['union'])
1778 && ! isset($analyzed_sql[0]['table_ref'][1]['table_name'])
1779 && (empty($analyzed_sql[0]['where_clause'])
1780 || $analyzed_sql[0]['where_clause'] == '1 ')) {
1781 // "j u s t b r o w s i n g"
1782 $pre_count = '~';
1783 $after_count = '[sup]1[/sup]';
1784 } else {
1785 $pre_count = '';
1786 $after_count = '';
1789 // 1. ----- Prepares the work -----
1791 // 1.1 Gets the informations about which functionalities should be
1792 // displayed
1793 $total = '';
1794 $is_display = PMA_setDisplayMode($the_disp_mode, $total);
1796 // 1.2 Defines offsets for the next and previous pages
1797 if ($is_display['nav_bar'] == '1') {
1798 if ($_SESSION['userconf']['max_rows'] == 'all') {
1799 $pos_next = 0;
1800 $pos_prev = 0;
1801 } else {
1802 $pos_next = $_SESSION['userconf']['pos'] + $_SESSION['userconf']['max_rows'];
1803 $pos_prev = $_SESSION['userconf']['pos'] - $_SESSION['userconf']['max_rows'];
1804 if ($pos_prev < 0) {
1805 $pos_prev = 0;
1808 } // end if
1810 // 1.3 URL-encodes the query to use in input form fields
1811 $encoded_sql_query = urlencode($sql_query);
1813 // 2. ----- Displays the top of the page -----
1815 // 2.1 Displays a messages with position informations
1816 if ($is_display['nav_bar'] == '1' && isset($pos_next)) {
1817 if (isset($unlim_num_rows) && $unlim_num_rows != $total) {
1818 $selectstring = ', ' . $unlim_num_rows . ' ' . $GLOBALS['strSelectNumRows'];
1819 } else {
1820 $selectstring = '';
1822 $last_shown_rec = ($_SESSION['userconf']['max_rows'] == 'all' || $pos_next > $total)
1823 ? $total - 1
1824 : $pos_next - 1;
1825 PMA_showMessage($GLOBALS['strShowingRecords'] . ' ' . $_SESSION['userconf']['pos'] . ' - ' . $last_shown_rec . ' (' . $pre_count . PMA_formatNumber($total, 0) . $after_count . ' ' . $GLOBALS['strTotal'] . $selectstring . ', ' . sprintf($GLOBALS['strQueryTime'], $GLOBALS['querytime']) . ')');
1827 if (PMA_Table::isView($db, $table) && $total == $GLOBALS['cfg']['MaxExactCount']) {
1828 echo '<div class="notice">' . "\n";
1829 echo PMA_sanitize(sprintf($GLOBALS['strViewMaxExactCount'], PMA_formatNumber($GLOBALS['cfg']['MaxExactCount'], 0), '[a@./Documentation.html#cfg_MaxExactCount@_blank]', '[/a]')) . "\n";
1830 echo '</div>' . "\n";
1832 if ($pre_count) {
1833 echo '<div class="notice">' . "\n";
1834 echo '<sup>1</sup>' . PMA_sanitize($GLOBALS['strApproximateCount']) . "\n";
1835 echo '</div>' . "\n";
1838 } elseif (!isset($GLOBALS['printview']) || $GLOBALS['printview'] != '1') {
1839 PMA_showMessage($GLOBALS['strSQLQuery']);
1842 // 2.3 Displays the navigation bars
1843 if (! strlen($table)) {
1844 if (isset($analyzed_sql[0]['query_type'])
1845 && $analyzed_sql[0]['query_type'] == 'SELECT') {
1846 // table does not always contain a real table name,
1847 // for example in MySQL 5.0.x, the query SHOW STATUS
1848 // returns STATUS as a table name
1849 $table = $fields_meta[0]->table;
1850 } else {
1851 $table = '';
1855 if ($is_display['nav_bar'] == '1') {
1856 PMA_displayTableNavigation($pos_next, $pos_prev, $sql_query);
1857 echo "\n";
1858 } elseif (!isset($GLOBALS['printview']) || $GLOBALS['printview'] != '1') {
1859 echo "\n" . '<br /><br />' . "\n";
1862 // 2b ----- Get field references from Database -----
1863 // (see the 'relation' configuration variable)
1864 // loic1, 2002-03-02: extended to php3
1866 // initialize map
1867 $map = array();
1869 // find tables
1870 $target=array();
1871 if (isset($analyzed_sql[0]['table_ref']) && is_array($analyzed_sql[0]['table_ref'])) {
1872 foreach ($analyzed_sql[0]['table_ref'] AS $table_ref_position => $table_ref) {
1873 $target[] = $analyzed_sql[0]['table_ref'][$table_ref_position]['table_true_name'];
1876 $tabs = '(\'' . join('\',\'', $target) . '\')';
1878 if ($cfgRelation['displaywork']) {
1879 if (! strlen($table)) {
1880 $exist_rel = false;
1881 } else {
1882 $exist_rel = PMA_getForeigners($db, $table, '', 'both');
1883 if ($exist_rel) {
1884 foreach ($exist_rel AS $master_field => $rel) {
1885 $display_field = PMA_getDisplayField($rel['foreign_db'], $rel['foreign_table']);
1886 $map[$master_field] = array($rel['foreign_table'],
1887 $rel['foreign_field'],
1888 $display_field,
1889 $rel['foreign_db']);
1890 } // end while
1891 } // end if
1892 } // end if
1893 } // end if
1894 // end 2b
1896 // 3. ----- Displays the results table -----
1897 PMA_displayTableHeaders($is_display, $fields_meta, $fields_cnt, $analyzed_sql);
1898 $url_query='';
1899 echo '<tbody>' . "\n";
1900 PMA_displayTableBody($dt_result, $is_display, $map, $analyzed_sql);
1901 // vertical output case
1902 if ($_SESSION['userconf']['disp_direction'] == 'vertical') {
1903 PMA_displayVerticalTable();
1904 } // end if
1905 unset($vertical_display);
1906 echo '</tbody>' . "\n";
1908 </table>
1910 <?php
1911 // 4. ----- Displays the link for multi-fields delete
1913 if ($is_display['del_lnk'] == 'dr' && $is_display['del_lnk'] != 'kp') {
1915 $delete_text = $is_display['del_lnk'] == 'dr' ? $GLOBALS['strDelete'] : $GLOBALS['strKill'];
1917 $uncheckall_url = 'sql.php?'
1918 . PMA_generate_common_url($db, $table)
1919 . '&amp;sql_query=' . urlencode($sql_query)
1920 . '&amp;goto=' . $goto;
1921 $checkall_url = $uncheckall_url . '&amp;checkall=1';
1923 if ($_SESSION['userconf']['disp_direction'] == 'vertical') {
1924 $checkall_params['onclick'] = 'if (setCheckboxes(\'rowsDeleteForm\', true)) return false;';
1925 $uncheckall_params['onclick'] = 'if (setCheckboxes(\'rowsDeleteForm\', false)) return false;';
1926 } else {
1927 $checkall_params['onclick'] = 'if (markAllRows(\'rowsDeleteForm\')) return false;';
1928 $uncheckall_params['onclick'] = 'if (unMarkAllRows(\'rowsDeleteForm\')) return false;';
1930 $checkall_link = PMA_linkOrButton($checkall_url, $GLOBALS['strCheckAll'], $checkall_params, false);
1931 $uncheckall_link = PMA_linkOrButton($uncheckall_url, $GLOBALS['strUncheckAll'], $uncheckall_params, false);
1932 if ($_SESSION['userconf']['disp_direction'] != 'vertical') {
1933 echo '<img class="selectallarrow" width="38" height="22"'
1934 .' src="' . $GLOBALS['pmaThemeImage'] . 'arrow_' . $GLOBALS['text_dir'] . '.png' . '"'
1935 .' alt="' . $GLOBALS['strWithChecked'] . '" />';
1937 echo $checkall_link . "\n"
1938 .' / ' . "\n"
1939 .$uncheckall_link . "\n"
1940 .'<i>' . $GLOBALS['strWithChecked'] . '</i>' . "\n";
1942 if ($GLOBALS['cfg']['PropertiesIconic']) {
1943 PMA_buttonOrImage('submit_mult', 'mult_submit',
1944 'submit_mult_change', $GLOBALS['strChange'], 'b_edit.png');
1945 PMA_buttonOrImage('submit_mult', 'mult_submit',
1946 'submit_mult_delete', $delete_text, 'b_drop.png');
1947 if ($analyzed_sql[0]['querytype'] == 'SELECT') {
1948 PMA_buttonOrImage('submit_mult', 'mult_submit',
1949 'submit_mult_export', $GLOBALS['strExport'],
1950 'b_tblexport.png');
1952 echo "\n";
1953 } else {
1954 echo ' <input type="submit" name="submit_mult"'
1955 .' value="' . htmlspecialchars($GLOBALS['strEdit']) . '"'
1956 .' title="' . $GLOBALS['strEdit'] . '" />' . "\n";
1957 echo ' <input type="submit" name="submit_mult"'
1958 .' value="' . htmlspecialchars($delete_text) . '"'
1959 .' title="' . $delete_text . '" />' . "\n";
1960 if ($analyzed_sql[0]['querytype'] == 'SELECT') {
1961 echo ' <input type="submit" name="submit_mult"'
1962 .' value="' . htmlspecialchars($GLOBALS['strExport']) . '"'
1963 .' title="' . $GLOBALS['strExport'] . '" />' . "\n";
1966 echo '<input type="hidden" name="sql_query"'
1967 .' value="' . htmlspecialchars($sql_query) . '" />' . "\n";
1968 echo '<input type="hidden" name="url_query"'
1969 .' value="' . $GLOBALS['url_query'] . '" />' . "\n";
1970 echo '</form>' . "\n";
1973 // 5. ----- Displays the navigation bar at the bottom if required -----
1975 if ($is_display['nav_bar'] == '1') {
1976 echo '<br />' . "\n";
1977 PMA_displayTableNavigation($pos_next, $pos_prev, $sql_query);
1978 } elseif (!isset($GLOBALS['printview']) || $GLOBALS['printview'] != '1') {
1979 echo "\n" . '<br /><br />' . "\n";
1982 // 6. ----- Displays "Query results operations"
1983 if (!isset($GLOBALS['printview']) || $GLOBALS['printview'] != '1') {
1984 PMA_displayResultsOperations($the_disp_mode, $analyzed_sql);
1986 } // end of the 'PMA_displayTable()' function
1988 function default_function($buffer) {
1989 $buffer = htmlspecialchars($buffer);
1990 $buffer = str_replace("\011", ' &nbsp;&nbsp;&nbsp;',
1991 str_replace(' ', ' &nbsp;', $buffer));
1992 $buffer = preg_replace("@((\015\012)|(\015)|(\012))@", '<br />', $buffer);
1994 return $buffer;
1998 * Displays operations that are available on results.
2000 * @param array the display mode
2001 * @param array the analyzed query
2003 * @uses $_SESSION['userconf']['pos']
2004 * @uses $_SESSION['userconf']['dontlimitchars']
2005 * @global string $db the database name
2006 * @global string $table the table name
2007 * @global string $sql_query the current SQL query
2008 * @global integer $unlim_num_rows the total number of rows returned by the
2009 * SQL query without any programmatically
2010 * appended "LIMIT" clause
2012 * @access private
2014 * @see PMA_showMessage(), PMA_setDisplayMode(),
2015 * PMA_displayTableNavigation(), PMA_displayTableHeaders(),
2016 * PMA_displayTableBody(), PMA_displayResultsOperations()
2018 function PMA_displayResultsOperations($the_disp_mode, $analyzed_sql) {
2019 global $db, $table, $sql_query, $unlim_num_rows;
2021 $header_shown = FALSE;
2022 $header = '<fieldset><legend>' . $GLOBALS['strQueryResultsOperations'] . '</legend>';
2024 if ($the_disp_mode[6] == '1' || $the_disp_mode[9] == '1') {
2025 // Displays "printable view" link if required
2026 if ($the_disp_mode[9] == '1') {
2028 if (!$header_shown) {
2029 echo $header;
2030 $header_shown = TRUE;
2033 $url_query = '?'
2034 . PMA_generate_common_url($db, $table)
2035 . '&amp;printview=1'
2036 . '&amp;sql_query=' . urlencode($sql_query);
2037 echo ' <!-- Print view -->' . "\n";
2038 echo PMA_linkOrButton(
2039 'sql.php' . $url_query,
2040 ($GLOBALS['cfg']['PropertiesIconic'] ? '<img class="icon" src="' . $GLOBALS['pmaThemeImage'] . 'b_print.png" height="16" width="16" alt="' . $GLOBALS['strPrintView'] . '"/>' : '') . $GLOBALS['strPrintView'],
2041 '', true, true, 'print_view') . "\n";
2043 if (! $_SESSION['userconf']['dontlimitchars']) {
2044 echo ' &nbsp;&nbsp;' . "\n";
2045 echo PMA_linkOrButton(
2046 'sql.php' . $url_query . '&amp;dontlimitchars=1',
2047 ($GLOBALS['cfg']['PropertiesIconic'] ? '<img class="icon" src="' . $GLOBALS['pmaThemeImage'] . 'b_print.png" height="16" width="16" alt="' . $GLOBALS['strPrintViewFull'] . '"/>' : '') . $GLOBALS['strPrintViewFull'],
2048 '', true, true, 'print_view') . "\n";
2050 } // end displays "printable view"
2052 echo "\n";
2055 // Export link
2056 // (the url_query has extra parameters that won't be used to export)
2057 // (the single_table parameter is used in display_export.lib.php
2058 // to hide the SQL and the structure export dialogs)
2059 // If the parser found a PROCEDURE clause
2060 // (most probably PROCEDURE ANALYSE()) it makes no sense to
2061 // display the Export link).
2063 if (isset($analyzed_sql[0]) && $analyzed_sql[0]['querytype'] == 'SELECT' && !isset($printview) && ! isset($analyzed_sql[0]['queryflags']['procedure'])) {
2064 if (isset($analyzed_sql[0]['table_ref'][0]['table_true_name']) && !isset($analyzed_sql[0]['table_ref'][1]['table_true_name'])) {
2065 $single_table = '&amp;single_table=true';
2066 } else {
2067 $single_table = '';
2069 if (!$header_shown) {
2070 echo $header;
2071 $header_shown = TRUE;
2073 echo ' <!-- Export -->' . "\n";
2074 echo ' &nbsp;&nbsp;' . "\n";
2075 echo PMA_linkOrButton(
2076 'tbl_export.php' . $url_query . '&amp;unlim_num_rows=' . $unlim_num_rows . $single_table,
2077 ($GLOBALS['cfg']['PropertiesIconic'] ? '<img class="icon" src="' . $GLOBALS['pmaThemeImage'] . 'b_tblexport.png" height="16" width="16" alt="' . $GLOBALS['strExport'] . '" />' : '') . $GLOBALS['strExport'],
2078 '', true, true, '') . "\n";
2081 // CREATE VIEW
2084 * @todo detect privileges to create a view
2085 * (but see 2006-01-19 note in display_create_table.lib.php,
2086 * I think we cannot detect db-specific privileges reliably)
2087 * Note: we don't display a Create view link if we found a PROCEDURE clause
2089 if (PMA_MYSQL_INT_VERSION >= 50000 && ! isset($analyzed_sql[0]['queryflags']['procedure'])) {
2090 if (!$header_shown) {
2091 echo $header;
2092 $header_shown = TRUE;
2094 echo ' <!-- Create View -->' . "\n";
2095 echo ' &nbsp;&nbsp;' . "\n";
2096 echo PMA_linkOrButton(
2097 'view_create.php' . $url_query,
2098 ($GLOBALS['cfg']['PropertiesIconic'] ? '<img class="icon" src="' . $GLOBALS['pmaThemeImage'] . 'b_views.png" height="16" width="16" alt="CREATE VIEW" />' : '') . 'CREATE VIEW',
2099 '', true, true, '') . "\n";
2102 if ($header_shown) {
2103 echo '</fieldset><br />';
2108 * Verifies what to do with non-printable contents (binary or BLOB)
2109 * in Browse mode.
2111 * @uses is_null()
2112 * @uses isset()
2113 * @uses strlen()
2114 * @uses PMA_formatByteDown()
2115 * @uses strpos()
2116 * @param string $category BLOB|BINARY
2117 * @param string $content the binary content
2118 * @param string $transform_function
2119 * @param string $transform_options
2120 * @param string $default_function
2121 * @param object $meta the meta-information about this field
2122 * @return mixed string or float
2124 function PMA_handle_non_printable_contents($category, $content, $transform_function, $transform_options, $default_function, $meta) {
2125 $result = '[' . $category;
2126 if (is_null($content)) {
2127 $result .= ' - NULL';
2128 $size = 0;
2129 } elseif (isset($content)) {
2130 $size = strlen($content);
2131 $display_size = PMA_formatByteDown($size, 3, 1);
2132 $result .= ' - '. $display_size[0] . $display_size[1];
2135 $result .= ']';
2136 if (strpos($transform_function, 'octetstream')) {
2137 $result = $content;
2139 if ($size > 0) {
2140 $result = ($default_function != $transform_function ? $transform_function($result, $transform_options, $meta) : $default_function($result, array(), $meta));
2142 return($result);