sorry, wrong version checked in
[phpmyadmin/arisferyanto.git] / libraries / display_tbl.lib.php
blob7960d8a239ca413527513649b7016b2e6c261eb4
1 <?php
2 /* $Id$ */
3 // vim: expandtab sw=4 ts=4 sts=4:
5 /**
6 * Set of functions used to display the records returned by a sql query
7 */
9 /**
10 * Defines the display mode to use for the results of a sql query
12 * It uses a synthetic string that contains all the required informations.
13 * In this string:
14 * - the first two characters stand for the action to do while
15 * clicking on the "edit" link (eg 'ur' for update a row, 'nn' for no
16 * edit link...);
17 * - the next two characters stand for the action to do while
18 * clicking on the "delete" link (eg 'kp' for kill a process, 'nn' for
19 * no delete link...);
20 * - the next characters are boolean values (1/0) and respectively stand
21 * for sorting links, navigation bar, "insert a new row" link, the
22 * bookmark feature, the expand/collapse text/blob fields button and
23 * the "display printable view" option.
24 * Of course '0'/'1' means the feature won't/will be enabled.
26 * @param string the synthetic value for display_mode (see ยง1 a few
27 * lines above for explanations)
28 * @param integer the total number of rows returned by the sql query
29 * without any programmatically appended "LIMIT" clause
30 * (just a copy of $unlim_num_rows if it exists, else
31 * computed inside this function)
33 * @return array an array with explicit indexes for all the display
34 * elements
36 * @global string the database name
37 * @global string the table name
38 * @global integer the total number of rows returned by the sql query
39 * without any programmatically appended "LIMIT" clause
40 * @global array the properties of the fields returned by the query
41 * @global string the url to return to in case of error in a sql
42 * statement
44 * @access private
46 * @see PMA_displayTable()
48 function PMA_setDisplayMode(&$the_disp_mode, &$the_total)
50 global $db, $table;
51 global $unlim_num_rows, $fields_meta;
52 global $err_url;
54 // 1. Initializes the $do_display array
55 $do_display = array();
56 $do_display['edit_lnk'] = $the_disp_mode[0] . $the_disp_mode[1];
57 $do_display['del_lnk'] = $the_disp_mode[2] . $the_disp_mode[3];
58 $do_display['sort_lnk'] = (string) $the_disp_mode[4];
59 $do_display['nav_bar'] = (string) $the_disp_mode[5];
60 $do_display['ins_row'] = (string) $the_disp_mode[6];
61 $do_display['bkm_form'] = (string) $the_disp_mode[7];
62 $do_display['text_btn'] = (string) $the_disp_mode[8];
63 $do_display['pview_lnk'] = (string) $the_disp_mode[9];
65 // 2. Display mode is not "false for all elements" -> updates the
66 // display mode
67 if ($the_disp_mode != 'nnnn000000') {
68 // 2.0 Print view -> set all elements to FALSE!
69 if (isset($GLOBALS['printview']) && $GLOBALS['printview'] == '1') {
70 $do_display['edit_lnk'] = 'nn'; // no edit link
71 $do_display['del_lnk'] = 'nn'; // no delete link
72 $do_display['sort_lnk'] = (string) '0';
73 $do_display['nav_bar'] = (string) '0';
74 $do_display['ins_row'] = (string) '0';
75 $do_display['bkm_form'] = (string) '0';
76 $do_display['text_btn'] = (string) '0';
77 $do_display['pview_lnk'] = (string) '0';
79 // 2.1 Statement is a "SELECT COUNT", a
80 // "CHECK/ANALYZE/REPAIR/OPTIMIZE", an "EXPLAIN" one or
81 // contains a "PROC ANALYSE" part
82 else if ($GLOBALS['is_count'] || $GLOBALS['is_analyse'] || $GLOBALS['is_maint'] || $GLOBALS['is_explain']) {
83 $do_display['edit_lnk'] = 'nn'; // no edit link
84 $do_display['del_lnk'] = 'nn'; // no delete link
85 $do_display['sort_lnk'] = (string) '0';
86 $do_display['nav_bar'] = (string) '0';
87 $do_display['ins_row'] = (string) '0';
88 $do_display['bkm_form'] = (string) '1';
89 if ($GLOBALS['is_analyse']) {
90 $do_display['text_btn'] = (string) '1';
91 } else {
92 $do_display['text_btn'] = (string) '0';
94 $do_display['pview_lnk'] = (string) '1';
96 // 2.2 Statement is a "SHOW..."
97 else if ($GLOBALS['is_show']) {
98 // 2.2.1 TODO : defines edit/delete links depending on show statement
99 $tmp = preg_match('@^SHOW[[:space:]]+(VARIABLES|(FULL[[:space:]]+)?PROCESSLIST|STATUS|TABLE|GRANTS|CREATE|LOGS|DATABASES|FIELDS)@i', $GLOBALS['sql_query'], $which = array() );
100 if (isset($which[1]) && strpos(' ' . strtoupper($which[1]), 'PROCESSLIST') > 0) {
101 $do_display['edit_lnk'] = 'nn'; // no edit link
102 $do_display['del_lnk'] = 'kp'; // "kill process" type edit link
104 else {
105 // Default case -> no links
106 $do_display['edit_lnk'] = 'nn'; // no edit link
107 $do_display['del_lnk'] = 'nn'; // no delete link
109 // 2.2.2 Other settings
110 $do_display['sort_lnk'] = (string) '0';
111 $do_display['nav_bar'] = (string) '0';
112 $do_display['ins_row'] = (string) '0';
113 $do_display['bkm_form'] = (string) '1';
114 $do_display['text_btn'] = (string) '1';
115 $do_display['pview_lnk'] = (string) '1';
117 // 2.3 Other statements (ie "SELECT" ones) -> updates
118 // $do_display['edit_lnk'], $do_display['del_lnk'] and
119 // $do_display['text_btn'] (keeps other default values)
120 else {
121 $prev_table = $fields_meta[0]->table;
122 $do_display['text_btn'] = (string) '1';
123 for ($i = 0; $i < $GLOBALS['fields_cnt']; $i++) {
124 $is_link = ($do_display['edit_lnk'] != 'nn'
125 || $do_display['del_lnk'] != 'nn'
126 || $do_display['sort_lnk'] != '0'
127 || $do_display['ins_row'] != '0');
128 // 2.3.2 Displays edit/delete/sort/insert links?
129 if ($is_link
130 && ($fields_meta[$i]->table == '' || $fields_meta[$i]->table != $prev_table)) {
131 $do_display['edit_lnk'] = 'nn'; // don't display links
132 $do_display['del_lnk'] = 'nn';
133 // TODO: May be problematic with same fields names in
134 // two joined table.
135 // $do_display['sort_lnk'] = (string) '0';
136 $do_display['ins_row'] = (string) '0';
137 if ($do_display['text_btn'] == '1') {
138 break;
140 } // end if (2.3.2)
141 // 2.3.3 Always display print view link
142 $do_display['pview_lnk'] = (string) '1';
143 $prev_table = $fields_meta[$i]->table;
144 } // end for
145 } // end if..elseif...else (2.1 -> 2.3)
146 } // end if (2)
148 // 3. Gets the total number of rows if it is unknown
149 if (isset($unlim_num_rows) && $unlim_num_rows != '') {
150 $the_total = $unlim_num_rows;
152 else if (($do_display['nav_bar'] == '1' || $do_display['sort_lnk'] == '1')
153 && (!empty($db) && !empty($table))) {
154 $the_total = PMA_countRecords($db, $table, TRUE);
157 // 4. If navigation bar or sorting fields names urls should be
158 // displayed but there is only one row, change these settings to
159 // false
160 if ($do_display['nav_bar'] == '1' || $do_display['sort_lnk'] == '1') {
162 if (isset($unlim_num_rows) && $unlim_num_rows < 2) {
163 // garvin: force display of navbar for vertical/horizontal display-choice.
164 // $do_display['nav_bar'] = (string) '0';
165 $do_display['sort_lnk'] = (string) '0';
168 } // end if (3)
170 // 5. Updates the synthetic var
171 $the_disp_mode = join('', $do_display);
173 return $do_display;
174 } // end of the 'PMA_setDisplayMode()' function
178 * Displays a navigation bar to browse among the results of a sql query
180 * @param integer the offset for the "next" page
181 * @param integer the offset for the "previous" page
182 * @param string the url-encoded query
184 * @global string $db the database name
185 * @global string $table the table name
186 * @global string $goto the url to go back in case of errors
187 * @global boolean $dontlimitchars whether to limit the number of displayed
188 * characters of text type fields or not
189 * @global integer $num_rows the total number of rows returned by the
190 * sql query
191 * @global integer $unlim_num_rows the total number of rows returned by the
192 * sql any programmatically appended "LIMIT" clause
193 * @global integer $pos the current position in results
194 * @global mixed $session_max_rows the maximum number of rows per page
195 * ('all' = no limit)
196 * @global string $disp_direction the display mode
197 * (horizontal / vertical / horizontalflipped)
198 * @global integer $repeat_cells the number of row to display between two
199 * table headers
200 * @global boolean $is_innodb whether its InnoDB or not
201 * @global array $showtable table definitions
203 * @access private
205 * @see PMA_displayTable()
207 function PMA_displayTableNavigation($pos_next, $pos_prev, $encoded_query)
209 global $db, $table, $goto, $dontlimitchars;
210 global $num_rows, $unlim_num_rows, $pos, $session_max_rows;
211 global $disp_direction, $repeat_cells;
212 global $is_innodb;
213 global $showtable;
215 // FIXME: move this to a central place
216 // FIXME: for other future table types
217 $is_innodb = (isset($showtable['Type']) && $showtable['Type'] == 'InnoDB');
221 <!-- Navigation bar -->
222 <table border="0" cellpadding="2" cellspacing="0">
223 <tr>
224 <?php
225 // Move to the beginning or to the previous page
226 if ($pos > 0 && $session_max_rows != 'all') {
227 // loic1: patch #474210 from Gosha Sakovich - part 1
228 if ($GLOBALS['cfg']['NavigationBarIconic']) {
229 $caption1 = '&lt;&lt;';
230 $caption2 = ' &lt; ';
231 $title1 = ' title="' . $GLOBALS['strPos1'] . '"';
232 $title2 = ' title="' . $GLOBALS['strPrevious'] . '"';
233 } else {
234 $caption1 = $GLOBALS['strPos1'] . ' &lt;&lt;';
235 $caption2 = $GLOBALS['strPrevious'] . ' &lt;';
236 $title1 = '';
237 $title2 = '';
238 } // end if... else...
240 <td>
241 <form action="sql.php" method="post">
242 <?php echo PMA_generate_common_hidden_inputs($db, $table); ?>
243 <input type="hidden" name="sql_query" value="<?php echo $encoded_query; ?>" />
244 <input type="hidden" name="pos" value="0" />
245 <input type="hidden" name="session_max_rows" value="<?php echo $session_max_rows; ?>" />
246 <input type="hidden" name="disp_direction" value="<?php echo $disp_direction; ?>" />
247 <input type="hidden" name="repeat_cells" value="<?php echo $repeat_cells; ?>" />
248 <input type="hidden" name="goto" value="<?php echo $goto; ?>" />
249 <input type="hidden" name="dontlimitchars" value="<?php echo $dontlimitchars; ?>" />
250 <input type="submit" name="navig" value="<?php echo $caption1; ?>"<?php echo $title1; ?> />
251 </form>
252 </td>
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 $encoded_query; ?>" />
257 <input type="hidden" name="pos" value="<?php echo $pos_prev; ?>" />
258 <input type="hidden" name="session_max_rows" value="<?php echo $session_max_rows; ?>" />
259 <input type="hidden" name="disp_direction" value="<?php echo $disp_direction; ?>" />
260 <input type="hidden" name="repeat_cells" value="<?php echo $repeat_cells; ?>" />
261 <input type="hidden" name="goto" value="<?php echo $goto; ?>" />
262 <input type="hidden" name="dontlimitchars" value="<?php echo $dontlimitchars; ?>" />
263 <input type="submit" name="navig" value="<?php echo $caption2; ?>"<?php echo $title2; ?> />
264 </form>
265 </td>
266 <?php
267 } // end move back
269 <td>
270 &nbsp;&nbsp;&nbsp;
271 </td>
272 <td align="center">
273 <form action="sql.php" method="post"
274 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 - 1; ?>))">
275 <?php echo PMA_generate_common_hidden_inputs($db, $table); ?>
276 <input type="hidden" name="sql_query" value="<?php echo $encoded_query; ?>" />
277 <input type="hidden" name="goto" value="<?php echo $goto; ?>" />
278 <input type="hidden" name="dontlimitchars" value="<?php echo $dontlimitchars; ?>" />
279 <input type="submit" name="navig" value="<?php echo $GLOBALS['strShow']; ?> :" />
280 <input type="text" name="session_max_rows" size="3" value="<?php echo (($session_max_rows != 'all') ? $session_max_rows : $GLOBALS['cfg']['MaxRows']); ?>" class="textfield" onfocus="this.select()" />
281 <?php echo $GLOBALS['strRowsFrom'] . "\n"; ?>
282 <input type="text" name="pos" size="6" value="<?php echo (($pos_next >= $unlim_num_rows) ? 0 : $pos_next); ?>" class="textfield" onfocus="this.select()" />
283 <br />
284 <?php
285 // Display mode (horizontal/vertical and repeat headers)
286 $param1 = ' <select name="disp_direction">' . "\n"
287 . ' <option value="horizontal"' . (($disp_direction == 'horizontal') ? ' selected="selected"': '') . '>' . $GLOBALS['strRowsModeHorizontal'] . '</option>' . "\n"
288 . ' <option value="horizontalflipped"' . (($disp_direction == 'horizontalflipped') ? ' selected="selected"': '') . '>' . $GLOBALS['strRowsModeFlippedHorizontal'] . '</option>' . "\n"
289 . ' <option value="vertical"' . (($disp_direction == 'vertical') ? ' selected="selected"': '') . '>' . $GLOBALS['strRowsModeVertical'] . '</option>' . "\n"
290 . ' </select>' . "\n"
291 . ' ';
292 $param2 = ' <input type="text" size="3" name="repeat_cells" value="' . $repeat_cells . '" class="textfield" />' . "\n"
293 . ' ';
294 echo ' ' . sprintf($GLOBALS['strRowsModeOptions'], "\n" . $param1, "\n" . $param2) . "\n";
296 </form>
297 </td>
298 <td>
299 &nbsp;&nbsp;&nbsp;
300 </td>
301 <?php
302 // Move to the next page or to the last one
303 if (($pos + $session_max_rows < $unlim_num_rows) && $num_rows >= $session_max_rows
304 && $session_max_rows != 'all') {
305 // loic1: patch #474210 from Gosha Sakovich - part 2
306 if ($GLOBALS['cfg']['NavigationBarIconic']) {
307 $caption3 = ' &gt; ';
308 $caption4 = '&gt;&gt;';
309 $title3 = ' title="' . $GLOBALS['strNext'] . '"';
310 $title4 = ' title="' . $GLOBALS['strEnd'] . '"';
311 } else {
312 $caption3 = '&gt; ' . $GLOBALS['strNext'];
313 $caption4 = '&gt;&gt; ' . $GLOBALS['strEnd'];
314 $title3 = '';
315 $title4 = '';
316 } // end if... else...
317 echo "\n";
319 <td>
320 <form action="sql.php" method="post">
321 <?php echo PMA_generate_common_hidden_inputs($db, $table); ?>
322 <input type="hidden" name="sql_query" value="<?php echo $encoded_query; ?>" />
323 <input type="hidden" name="pos" value="<?php echo $pos_next; ?>" />
324 <input type="hidden" name="session_max_rows" value="<?php echo $session_max_rows; ?>" />
325 <input type="hidden" name="disp_direction" value="<?php echo $disp_direction; ?>" />
326 <input type="hidden" name="repeat_cells" value="<?php echo $repeat_cells; ?>" />
327 <input type="hidden" name="goto" value="<?php echo $goto; ?>" />
328 <input type="hidden" name="dontlimitchars" value="<?php echo $dontlimitchars; ?>" />
329 <input type="submit" name="navig" value="<?php echo $caption3; ?>"<?php echo $title3; ?> />
330 </form>
331 </td>
332 <td>
333 <form action="sql.php" method="post"
334 onsubmit="return <?php echo (($pos + $session_max_rows < $unlim_num_rows && $num_rows >= $session_max_rows) ? 'true' : 'false'); ?>">
335 <?php echo PMA_generate_common_hidden_inputs($db, $table); ?>
336 <input type="hidden" name="sql_query" value="<?php echo $encoded_query; ?>" />
337 <input type="hidden" name="pos" value="<?php echo @((ceil($unlim_num_rows / $session_max_rows)- 1) * $session_max_rows); ?>" />
338 <?php
339 if ($is_innodb && $unlim_num_rows > $GLOBALS['cfg']['MaxExactCount']) {
340 echo '<input type="hidden" name="find_real_end" value="1" />' . "\n";
341 // no backquote around this message
342 $onclick = ' onclick="return confirmAction(\'' . PMA_jsFormat($GLOBALS['strLongOperation'], FALSE) . '\')"';
345 <input type="hidden" name="session_max_rows" value="<?php echo $session_max_rows; ?>" />
346 <input type="hidden" name="disp_direction" value="<?php echo $disp_direction; ?>" />
347 <input type="hidden" name="repeat_cells" value="<?php echo $repeat_cells; ?>" />
348 <input type="hidden" name="goto" value="<?php echo $goto; ?>" />
349 <input type="hidden" name="dontlimitchars" value="<?php echo $dontlimitchars; ?>" />
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 $pageNow = @floor($pos / $session_max_rows) + 1;
359 $nbTotalPage = @ceil($unlim_num_rows / $session_max_rows);
361 if ($nbTotalPage > 1){ //if1
363 <td>
364 &nbsp;&nbsp;&nbsp;
365 </td>
366 <td>
367 <?php //<form> for keep the form alignment of button < and << ?>
368 <form>
369 <?php echo PMA_pageselector(
370 'sql.php?sql_query=' . $encoded_query .
371 '&amp;session_max_rows=' . $session_max_rows .
372 '&amp;disp_direction=' . $disp_direction .
373 '&amp;repeat_cells=' . $repeat_cells .
374 '&amp;goto=' . $goto .
375 '&amp;dontlimitchars=' . $dontlimitchars .
376 '&amp;' . PMA_generate_common_url($db, $table) .
377 '&amp;',
378 $session_max_rows,
379 $pageNow,
380 $nbTotalPage
383 </form>
384 </td>
385 <?php
386 } //_if1
389 // Show all the records if allowed
390 if ($GLOBALS['cfg']['ShowAll'] && ($num_rows < $unlim_num_rows)) {
391 echo "\n";
393 <td>
394 &nbsp;&nbsp;&nbsp;
395 </td>
396 <td>
397 <form action="sql.php" method="post">
398 <?php echo PMA_generate_common_hidden_inputs($db, $table); ?>
399 <input type="hidden" name="sql_query" value="<?php echo $encoded_query; ?>" />
400 <input type="hidden" name="pos" value="0" />
401 <input type="hidden" name="session_max_rows" value="all" />
402 <input type="hidden" name="disp_direction" value="<?php echo $disp_direction; ?>" />
403 <input type="hidden" name="repeat_cells" value="<?php echo $repeat_cells; ?>" />
404 <input type="hidden" name="goto" value="<?php echo $goto; ?>" />
405 <input type="hidden" name="dontlimitchars" value="<?php echo $dontlimitchars; ?>" />
406 <input type="submit" name="navig" value="<?php echo $GLOBALS['strShowAll']; ?>" />
407 </form>
408 </td>
409 <?php
410 } // end show all
411 echo "\n";
413 </tr>
414 </table>
416 <?php
417 } // end of the 'PMA_displayTableNavigation()' function
421 * Displays the headers of the results table
423 * @param array which elements to display
424 * @param array the list of fields properties
425 * @param integer the total number of fields returned by the sql query
426 * @param array the analyzed query
428 * @return boolean always true
430 * @global string $db the database name
431 * @global string $table the table name
432 * @global string $goto the url to go back in case of errors
433 * @global boolean $dontlimitchars whether to limit the number of displayed
434 * characters of text type fields or not
435 * @global string $sql_query the sql query
436 * @global integer $num_rows the total number of rows returned by the
437 * sql query
438 * @global integer $pos the current position in results
439 * @global integer $session_max_rows the maximum number of rows per page
440 * @global array $vertical_display informations used with vertical display
441 * mode
442 * @global string $disp_direction the display mode
443 * (horizontal/vertical/horizontalflipped)
444 * @global integer $repeat_cellsthe number of row to display between two
445 * table headers
447 * @access private
449 * @see PMA_displayTable()
451 function PMA_displayTableHeaders(&$is_display, &$fields_meta, $fields_cnt = 0, $analyzed_sql = '')
453 global $db, $table, $goto, $dontlimitchars;
454 global $sql_query, $num_rows, $pos, $session_max_rows;
455 global $vertical_display, $disp_direction, $repeat_cells, $highlight_columns;
457 if ($analyzed_sql == '') {
458 $analyzed_sql = array();
461 // can the result be sorted?
462 if ($is_display['sort_lnk'] == '1') {
464 // Just as fallback
465 $unsorted_sql_query = $sql_query;
466 if (isset($analyzed_sql[0]['unsorted_query'])) {
467 $unsorted_sql_query = $analyzed_sql[0]['unsorted_query'];
470 // we need $sort_expression and $sort_expression_nodir
471 // even if there are many table references
473 $sort_expression = trim(str_replace(' ', ' ',$analyzed_sql[0]['order_by_clause']));
475 // Get rid of ASC|DESC (TODO: analyzer)
476 preg_match('@(.*)([[:space:]]*(ASC|DESC))@si',$sort_expression,$matches = array());
477 $sort_expression_nodir = isset($matches[1]) ? trim($matches[1]) : $sort_expression;
479 // sorting by indexes, only if it makes sense (only one table ref)
480 if (isset($analyzed_sql) && isset($analyzed_sql[0]) &&
481 isset($analyzed_sql[0]['querytype']) && $analyzed_sql[0]['querytype'] == 'SELECT' &&
482 isset($analyzed_sql[0]['table_ref']) && count($analyzed_sql[0]['table_ref']) == 1) {
484 // grab indexes data:
485 PMA_DBI_select_db($db);
486 if (!defined('PMA_IDX_INCLUDED')) {
487 $ret_keys = PMA_get_indexes($table);
490 $prev_index = '';
491 foreach ($ret_keys as $row) {
493 if ($row['Key_name'] != $prev_index ){
494 $indexes[] = $row['Key_name'];
495 $prev_index = $row['Key_name'];
497 $indexes_info[$row['Key_name']]['Sequences'][] = $row['Seq_in_index'];
498 $indexes_info[$row['Key_name']]['Non_unique'] = $row['Non_unique'];
499 if (isset($row['Cardinality'])) {
500 $indexes_info[$row['Key_name']]['Cardinality'] = $row['Cardinality'];
502 // I don't know what does the following column mean....
503 // $indexes_info[$row['Key_name']]['Packed'] = $row['Packed'];
504 $indexes_info[$row['Key_name']]['Comment'] = (isset($row['Comment']))
505 ? $row['Comment']
506 : '';
507 $indexes_info[$row['Key_name']]['Index_type'] = (isset($row['Index_type']))
508 ? $row['Index_type']
509 : '';
511 $indexes_data[$row['Key_name']][$row['Seq_in_index']]['Column_name'] = $row['Column_name'];
512 if (isset($row['Sub_part'])) {
513 $indexes_data[$row['Key_name']][$row['Seq_in_index']]['Sub_part'] = $row['Sub_part'];
515 } // end while
517 // do we have any index?
518 if (isset($indexes_data)) {
520 if ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped') {
521 $span = $fields_cnt;
522 if ($is_display['edit_lnk'] != 'nn') $span++;
523 if ($is_display['del_lnk'] != 'nn') $span++;
524 if ($is_display['del_lnk'] != 'kp' && $is_display['del_lnk'] != 'nn') $span++;
525 } else {
526 $span = $num_rows + floor($num_rows/$repeat_cells) + 1;
529 echo '<form action="sql.php" method="post">' . "\n";
530 echo PMA_generate_common_hidden_inputs($db, $table, 5);
531 echo '<input type="hidden" name="pos" value="' . $pos . '" />' . "\n";
532 echo '<input type="hidden" name="session_max_rows" value="' . $session_max_rows . '" />' . "\n";
533 echo '<input type="hidden" name="disp_direction" value="' . $disp_direction . '" />' . "\n";
534 echo '<input type="hidden" name="repeat_cells" value="' . $repeat_cells . '" />' . "\n";
535 echo '<input type="hidden" name="dontlimitchars" value="' . $dontlimitchars . '" />' . "\n";
536 echo $GLOBALS['strSortByKey'] . ': <select name="sql_query">' . "\n";
537 $used_index = false;
538 $local_order = (isset($sort_expression) ? $sort_expression : '');
539 foreach ($indexes_data AS $key => $val) {
540 $asc_sort = '';
541 $desc_sort = '';
542 foreach ($val AS $key2 => $val2) {
543 $asc_sort .= PMA_backquote($val2['Column_name']) . ' ASC , ';
544 $desc_sort .= PMA_backquote($val2['Column_name']) . ' DESC , ';
546 $asc_sort = substr($asc_sort, 0, -3);
547 $desc_sort = substr($desc_sort, 0, -3);
548 $used_index = $used_index || $local_order == $asc_sort || $local_order == $desc_sort;
549 echo '<option value="' . htmlspecialchars($unsorted_sql_query . ' ORDER BY ' . $asc_sort) . '"' . ($local_order == $asc_sort ? ' selected="selected"' : '') . '>' . htmlspecialchars($key) . ' (' . $GLOBALS['strAscending'] . ')</option>';
550 echo "\n";
551 echo '<option value="' . htmlspecialchars($unsorted_sql_query . ' ORDER BY ' . $desc_sort) . '"' . ($local_order == $desc_sort ? ' selected="selected"' : '') . '>' . htmlspecialchars($key) . ' (' . $GLOBALS['strDescending'] . ')</option>';
552 echo "\n";
554 echo '<option value="' . htmlspecialchars($unsorted_sql_query) . '"' . ($used_index ? '' : ' selected="selected"' ) . '>' . $GLOBALS['strNone'] . '</option>';
555 echo "\n";
556 echo '</select>' . "\n";
557 echo '<input type="submit" value="' . $GLOBALS['strGo'] . '" />';
558 echo "\n";
559 echo '</form>' . "\n";
565 $vertical_display['emptypre'] = 0;
566 $vertical_display['emptyafter'] = 0;
567 $vertical_display['textbtn'] = '';
570 // Start of form for multi-rows delete
572 if ($is_display['del_lnk'] == 'dr' || $is_display['del_lnk'] == 'kp' ) {
573 echo '<form method="post" action="tbl_row_action.php" name="rowsDeleteForm" id="rowsDeleteForm">' . "\n";
574 echo PMA_generate_common_hidden_inputs($db, $table, 1);
575 echo '<input type="hidden" name="disp_direction" value="' . $disp_direction . '" />' . "\n";
576 echo '<input type="hidden" name="repeat_cells" value="' . $repeat_cells . '" />' . "\n";
577 echo '<input type="hidden" name="dontlimitchars" value="' . $dontlimitchars . '" />' . "\n";
578 echo '<input type="hidden" name="pos" value="' . $pos . '" />' . "\n";
579 echo '<input type="hidden" name="session_max_rows" value="' . $session_max_rows . '" />' . "\n";
580 echo '<input type="hidden" name="goto" value="sql.php" />' . "\n";
583 echo '<table id="table_results" class="data">' . "\n";
584 if ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped') {
585 echo '<thead><tr>' . "\n";
588 // 1. Displays the full/partial text button (part 1)...
589 if ($disp_direction == 'horizontal' || $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 $text_url = 'sql.php?'
599 . PMA_generate_common_url($db, $table)
600 . '&amp;sql_query=' . urlencode($sql_query)
601 . '&amp;session_max_rows=' . $session_max_rows
602 . '&amp;pos=' . $pos
603 . '&amp;disp_direction=' . $disp_direction
604 . '&amp;repeat_cells=' . $repeat_cells
605 . '&amp;goto=' . $goto
606 . '&amp;dontlimitchars=' . (($dontlimitchars) ? 0 : 1);
607 $text_message = '<img class="fulltext" src="' . $GLOBALS['pmaThemeImage'] . 's_'.($dontlimitchars ? 'partialtext' : 'fulltext') . '.png" width="50" height="20" alt="' . ($dontlimitchars ? $GLOBALS['strPartialText'] : $GLOBALS['strFullText']) . '" title="' . ($dontlimitchars ? $GLOBALS['strPartialText'] : $GLOBALS['strFullText']) . '" />';
608 $text_link = PMA_linkOrButton( $text_url, $text_message, array(), false );
610 // ... before the result table
611 if (($is_display['edit_lnk'] == 'nn' && $is_display['del_lnk'] == 'nn')
612 && $is_display['text_btn'] == '1') {
613 $vertical_display['emptypre'] = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn') ? 3 : 0;
614 if ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped') {
616 <th colspan="<?php echo $fields_cnt; ?>"><?php echo $text_link; ?></th>
617 </tr>
618 <tr>
619 <?php
620 } // end horizontal/horizontalflipped mode
621 else {
623 <tr>
624 <th colspan="<?php echo $num_rows + floor($num_rows/$repeat_cells) + 1; ?>">
625 <?php echo $text_link; ?></th>
626 </tr>
627 <?php
628 } // end vertical mode
631 // ... at the left column of the result table header if possible
632 // and required
633 elseif ($GLOBALS['cfg']['ModifyDeleteAtLeft'] && $is_display['text_btn'] == '1') {
634 $vertical_display['emptypre'] = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn') ? 3 : 0;
635 if ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped') {
637 <th <?php echo $colspan; ?>><?php echo $text_link; ?></th>
638 <?php
639 } // end horizontal/horizontalflipped mode
640 else {
641 $vertical_display['textbtn'] = ' <th ' . $rowspan . ' valign="middle">' . "\n"
642 . ' ' . $text_link . "\n"
643 . ' </th>' . "\n";
644 } // end vertical mode
647 // ... else if no button, displays empty(ies) col(s) if required
648 elseif ($GLOBALS['cfg']['ModifyDeleteAtLeft']
649 && ($is_display['edit_lnk'] != 'nn' || $is_display['del_lnk'] != 'nn')) {
650 $vertical_display['emptypre'] = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn') ? 3 : 0;
651 if ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped') {
653 <td<?php echo $colspan; ?>></td>
654 <?php
655 } // end horizontal/horizontalfipped mode
656 else {
657 $vertical_display['textbtn'] = ' <td' . $rowspan . '></td>' . "\n";
658 } // end vertical mode
661 // 2. Displays the fields' name
662 // 2.0 If sorting links should be used, checks if the query is a "JOIN"
663 // statement (see 2.1.3)
665 // 2.0.1 Prepare Display column comments if enabled ($GLOBALS['cfg']['ShowBrowseComments']).
666 // Do not show comments, if using horizontalflipped mode, because of space usage
667 if ($GLOBALS['cfg']['ShowBrowseComments'] && $GLOBALS['cfgRelation']['commwork'] && $disp_direction != 'horizontalflipped') {
668 $comments_map = array();
669 foreach ($analyzed_sql[0]['table_ref'] as $tbl) {
671 $tb = $tbl['table_true_name'];
673 $comments_map[$tb] = PMA_getComments($db, $tb);
677 if ($GLOBALS['cfgRelation']['commwork'] && $GLOBALS['cfgRelation']['mimework'] && $GLOBALS['cfg']['BrowseMIME']) {
678 require_once('./libraries/transformations.lib.php');
679 $GLOBALS['mime_map'] = PMA_getMIME($db, $table);
682 if ($is_display['sort_lnk'] == '1') {
683 //$is_join = preg_match('@(.*)[[:space:]]+FROM[[:space:]]+.*[[:space:]]+JOIN@im', $sql_query, $select_stt);
684 $is_join = (isset($analyzed_sql[0]['queryflags']['join']) ?TRUE:FALSE);
685 $select_expr = $analyzed_sql[0]['select_expr_clause'];
686 } else {
687 $is_join = FALSE;
690 // garvin: See if we have to highlight any header fields of a WHERE query.
691 // Uses SQL-Parser results.
692 $highlight_columns = array();
693 if (isset($analyzed_sql) && isset($analyzed_sql[0]) &&
694 isset($analyzed_sql[0]['where_clause_identifiers'])) {
696 $wi = 0;
697 if (isset($analyzed_sql[0]['where_clause_identifiers']) && is_array($analyzed_sql[0]['where_clause_identifiers'])) {
698 foreach ($analyzed_sql[0]['where_clause_identifiers'] AS $wci_nr => $wci) {
699 $highlight_columns[$wci] = 'true';
704 for ($i = 0; $i < $fields_cnt; $i++) {
705 // garvin: See if this column should get highlight because it's used in the
706 // where-query.
707 if (isset($highlight_columns[$fields_meta[$i]->name]) || isset($highlight_columns[PMA_backquote($fields_meta[$i]->name)])) {
708 $column_style = 'style="border: 1px solid ' . $GLOBALS['cfg']['BrowseMarkerColor'] . '"';
709 } else {
710 $column_style = '';
713 // 2.0 Prepare comment-HTML-wrappers for each row, if defined/enabled.
714 if (isset($comments_map) &&
715 isset($comments_map[$fields_meta[$i]->table]) &&
716 isset($comments_map[$fields_meta[$i]->table][$fields_meta[$i]->name])) {
717 $comments = '<span class="tblcomment">' . htmlspecialchars($comments_map[$fields_meta[$i]->table][$fields_meta[$i]->name]) . '</span>';
718 } else {
719 $comments = '';
722 // 2.1 Results can be sorted
723 if ($is_display['sort_lnk'] == '1') {
725 // 2.1.1 Checks if the table name is required; it's the case
726 // for a query with a "JOIN" statement and if the column
727 // isn't aliased, or in queries like
728 // SELECT `1`.`master_field` , `2`.`master_field`
729 // FROM `PMA_relation` AS `1` , `PMA_relation` AS `2`
731 if (($is_join
732 && !preg_match('~([^[:space:],]|`[^`]`)[[:space:]]+(as[[:space:]]+)?' . strtr($fields_meta[$i]->name, array('[' => '\\[', '~' => '\\~', '\\' => '\\\\')) . '~i', $select_expr, $parts = array()))
733 || ( isset($analyzed_sql[0]['select_expr'][$i]['expr'])
734 && isset($analyzed_sql[0]['select_expr'][$i]['column'])
735 && $analyzed_sql[0]['select_expr'][$i]['expr'] !=
736 $analyzed_sql[0]['select_expr'][$i]['column']
737 && !empty($fields_meta[$i]->table)) ) {
738 $sort_tbl = PMA_backquote($fields_meta[$i]->table) . ' . ';
739 } else {
740 $sort_tbl = '';
742 // 2.1.2 Checks if the current column is used to sort the
743 // results
744 if (empty($sort_expression)) {
745 $is_in_sort = FALSE;
746 } else {
747 // field name may be preceded by a space, or any number
748 // of characters followed by a dot (tablename.fieldname)
749 // so do a direct comparison
750 // for the sort expression (avoids problems with queries
751 // like "SELECT id, count(id)..." and clicking to sort
752 // on id or on count(id) )
753 $is_in_sort = ($sort_tbl . PMA_backquote($fields_meta[$i]->name) == $sort_expression_nodir ? TRUE : FALSE);
755 // 2.1.3 Check the field name for backquotes.
756 // If it contains some, it's probably a function column
757 // like 'COUNT(`field`)'
758 if (strpos(' ' . $fields_meta[$i]->name, '`') > 0) {
759 $sort_order = ' ORDER BY \'' . $fields_meta[$i]->name . '\' ';
760 } else {
761 $sort_order = ' ORDER BY ' . $sort_tbl . PMA_backquote($fields_meta[$i]->name) . ' ';
764 // 2.1.4 Do define the sorting url
765 if (!$is_in_sort) {
766 // loic1: patch #455484 ("Smart" order)
767 $GLOBALS['cfg']['Order'] = strtoupper($GLOBALS['cfg']['Order']);
768 if ($GLOBALS['cfg']['Order'] == 'SMART') {
769 $GLOBALS['cfg']['Order'] = (preg_match('@time|date@i', $fields_meta[$i]->type)) ? 'DESC' : 'ASC';
771 $sort_order .= $GLOBALS['cfg']['Order'];
772 $order_img = '';
773 } elseif (preg_match('@[[:space:]]ASC$@i', $sort_expression)) {
774 $sort_order .= ' DESC';
775 $order_img = ' <img class="icon" src="' . $GLOBALS['pmaThemeImage'] . 's_asc.png" width="11" height="9" alt="'. $GLOBALS['strAscending'] . '" title="'. $GLOBALS['strAscending'] . '" id="soimg' . $i . '" />';
776 } elseif (preg_match('@[[:space:]]DESC$@i', $sort_expression)) {
777 $sort_order .= ' ASC';
778 $order_img = ' <img class="icon" src="' . $GLOBALS['pmaThemeImage'] . 's_desc.png" width="11" height="9" alt="'. $GLOBALS['strDescending'] . '" title="'. $GLOBALS['strDescending'] . '" id="soimg' . $i . '" />';
779 } else {
780 $sort_order .= ' DESC';
781 $order_img = ' <img class="icon" src="' . $GLOBALS['pmaThemeImage'] . 's_asc.png" width="11" height="9" alt="'. $GLOBALS['strAscending'] . '" title="'. $GLOBALS['strAscending'] . '" id="soimg' . $i . '" />';
784 if (preg_match('@(.*)([[:space:]](LIMIT (.*)|PROCEDURE (.*)|FOR UPDATE|LOCK IN SHARE MODE))@i', $unsorted_sql_query, $regs3 = array())) {
785 $sorted_sql_query = $regs3[1] . $sort_order . $regs3[2];
786 } else {
787 $sorted_sql_query = $unsorted_sql_query . $sort_order;
789 $url_query = PMA_generate_common_url($db, $table)
790 . '&amp;pos=' . $pos
791 . '&amp;session_max_rows=' . $session_max_rows
792 . '&amp;disp_direction=' . $disp_direction
793 . '&amp;repeat_cells=' . $repeat_cells
794 . '&amp;dontlimitchars=' . $dontlimitchars
795 . '&amp;sql_query=' . urlencode($sorted_sql_query);
796 $order_url = 'sql.php?' . $url_query;
798 // 2.1.5 Displays the sorting url
799 // added 20004-06-09: Michael Keck <mail@michaelkeck.de>
800 // enable sord order swapping for image
801 $order_link_params = array();
802 if (isset($order_img) && $order_img!='') {
803 if (strstr($order_img,'asc')) {
804 $order_link_params['onmouseover'] = 'if(document.getElementById(\'soimg' . $i . '\')){ document.getElementById(\'soimg' . $i . '\').src=\'' . $GLOBALS['pmaThemeImage'] . 's_desc.png\'; }';
805 $order_link_params['onmouseout'] = 'if(document.getElementById(\'soimg' . $i . '\')){ document.getElementById(\'soimg' . $i . '\').src=\'' . $GLOBALS['pmaThemeImage'] . 's_asc.png\'; }';
806 } else if (strstr($order_img,'desc')) {
807 $order_link_params['onmouseover'] = 'if(document.getElementById(\'soimg' . $i . '\')){ document.getElementById(\'soimg' . $i . '\').src=\'' . $GLOBALS['pmaThemeImage'] . 's_asc.png\'; }';
808 $order_link_params['onmouseout'] = 'if(document.getElementById(\'soimg' . $i . '\')){ document.getElementById(\'soimg' . $i . '\').src=\'' . $GLOBALS['pmaThemeImage'] . 's_desc.png\'; }';
811 if ( $disp_direction == 'horizontalflipped'
812 && $GLOBALS['cfg']['HeaderFlipType'] == 'css' ) {
813 $order_link_params['style'] = 'direction: ltr; writing-mode: tb-rl;';
815 $order_link_params['title'] = $GLOBALS['strSort'];
816 $order_link_content = ($disp_direction == 'horizontalflipped' && $GLOBALS['cfg']['HeaderFlipType'] == 'fake' ? PMA_flipstring(htmlspecialchars($fields_meta[$i]->name), "<br />\n") : htmlspecialchars($fields_meta[$i]->name));
817 $order_link = PMA_linkOrButton( $order_url, $order_link_content . $order_img, $order_link_params, false, true );
819 if ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped') {
821 <th <?php echo $column_style; ?> <?php if ($disp_direction == 'horizontalflipped') echo 'valign="bottom"'; ?>>
822 <?php echo $order_link; ?>
823 <?php echo $comments; ?>
824 </th>
825 <?php
827 $vertical_display['desc'][] = ' <th ' . $column_style . '>' . "\n"
828 . $order_link
829 . $comments
830 . ' </th>' . "\n";
831 } // end if (2.1)
833 // 2.2 Results can't be sorted
834 else {
835 if ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped') {
837 <th <?php echo $column_style; ?> <?php if ($disp_direction == 'horizontalflipped') echo 'valign="bottom"'; ?> <?php echo ($disp_direction == 'horizontalflipped' && $GLOBALS['cfg']['HeaderFlipType'] == 'css' ? 'style="direction: ltr; writing-mode: tb-rl;"' : ''); ?>>
838 <?php echo ($disp_direction == 'horizontalflipped' && $GLOBALS['cfg']['HeaderFlipType'] == 'fake'? PMA_flipstring(htmlspecialchars($fields_meta[$i]->name), "<br />\n") : htmlspecialchars($fields_meta[$i]->name)) . "\n"; ?>
839 <?php echo $comments; ?>
840 </th>
841 <?php
843 $vertical_display['desc'][] = ' <th ' . $column_style . '>' . "\n"
844 . ' ' . htmlspecialchars($fields_meta[$i]->name) . "\n"
845 . $comments
846 . ' </th>';
847 } // end else (2.2)
848 } // end for
850 // 3. Displays the full/partial text button (part 2) at the right
851 // column of the result table header if possible and required...
852 if ($GLOBALS['cfg']['ModifyDeleteAtRight']
853 && ($is_display['edit_lnk'] != 'nn' || $is_display['del_lnk'] != 'nn')
854 && $is_display['text_btn'] == '1') {
855 $vertical_display['emptyafter'] = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn') ? 3 : 1;
856 if ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped') {
857 echo "\n";
859 <th <?php echo $colspan; ?>>
860 <?php echo $text_link; ?>
861 </th>
862 <?php
863 } // end horizontal/horizontalflipped mode
864 else {
865 $vertical_display['textbtn'] = ' <th ' . $rowspan . ' valign="middle">' . "\n"
866 . ' ' . $text_link . "\n"
867 . ' </th>' . "\n";
868 } // end vertical mode
871 // ... else if no button, displays empty cols if required
872 // (unless coming from Browse mode print view)
873 else if ($GLOBALS['cfg']['ModifyDeleteAtRight']
874 && ($is_display['edit_lnk'] == 'nn' && $is_display['del_lnk'] == 'nn')
875 && (!$GLOBALS['is_header_sent'])) {
876 $vertical_display['emptyafter'] = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn') ? 3 : 1;
877 if ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped') {
878 echo "\n";
880 <td<?php echo $colspan; ?>></td>
881 <?php
882 } // end horizontal/horizontalflipped mode
883 else {
884 $vertical_display['textbtn'] = ' <td' . $rowspan . '></td>' . "\n";
885 } // end vertical mode
888 if ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped') {
890 </tr>
891 </thead>
892 <?php
895 return TRUE;
896 } // end of the 'PMA_displayTableHeaders()' function
901 * Displays the body of the results table
903 * @param integer the link id associated to the query which results have
904 * to be displayed
905 * @param array which elements to display
906 * @param array the list of relations
907 * @param array the analyzed query
909 * @return boolean always true
911 * @global string $db the database name
912 * @global string $table the table name
913 * @global string $goto the url to go back in case of errors
914 * @global boolean $dontlimitchars whether to limit the number of displayed
915 * characters of text type fields or not
916 * @global string $sql_query the sql query
917 * @global integer $pos the current position in results
918 * @global integer $session_max_rows the maximum number of rows per page
919 * @global array $fields_meta the list of fields properties
920 * @global integer $fields_cnt the total number of fields returned by
921 * the sql query
922 * @global array $vertical_display informations used with vertical display
923 * mode
924 * @global string $disp_direction the display mode
925 * (horizontal/vertical/horizontalflipped)
926 * @global integer $repeat_cells the number of row to display between two
927 * table headers
928 * @global array $highlight_columns collumn names to highlight
929 * @gloabl array $row current row data
931 * @access private
933 * @see PMA_displayTable()
935 function PMA_displayTableBody(&$dt_result, &$is_display, $map, $analyzed_sql) {
936 global $db, $table, $goto, $dontlimitchars;
937 global $sql_query, $pos, $session_max_rows, $fields_meta, $fields_cnt;
938 global $vertical_display, $disp_direction, $repeat_cells, $highlight_columns;
939 global $row; // mostly because of browser transformations, to make the row-data accessible in a plugin
941 $url_sql_query = $sql_query;
943 // query without conditions to shorten urls when needed, 200 is just
944 // guess, it should depend on remaining url length
946 if (isset($analyzed_sql) && isset($analyzed_sql[0]) &&
947 isset($analyzed_sql[0]['querytype']) && $analyzed_sql[0]['querytype'] == 'SELECT' &&
948 strlen($sql_query) > 200) {
950 $url_sql_query = 'SELECT ';
951 if (isset($analyzed_sql[0]['queryflags']['distinct'])) {
952 $url_sql_query .= ' DISTINCT ';
954 $url_sql_query .= $analyzed_sql[0]['select_expr_clause'];
955 if (!empty($analyzed_sql[0]['from_clause'])) {
956 $url_sql_query .= ' FROM ' . $analyzed_sql[0]['from_clause'];
960 if (!is_array($map)) {
961 $map = array();
963 $row_no = 0;
964 $vertical_display['edit'] = array();
965 $vertical_display['delete'] = array();
966 $vertical_display['data'] = array();
967 $vertical_display['row_delete'] = array();
969 // Correction uva 19991216 in the while below
970 // Previous code assumed that all tables have keys, specifically that
971 // the phpMyAdmin GUI should support row delete/edit only for such
972 // tables.
973 // Although always using keys is arguably the prescribed way of
974 // defining a relational table, it is not required. This will in
975 // particular be violated by the novice.
976 // We want to encourage phpMyAdmin usage by such novices. So the code
977 // below has been changed to conditionally work as before when the
978 // table being displayed has one or more keys; but to display
979 // delete/edit options correctly for tables without keys.
981 // loic1: use 'PMA_mysql_fetch_array' rather than 'PMA_mysql_fetch_row'
982 // to get the NULL values
984 // rabus: This function needs a little rework.
985 // Using MYSQL_BOTH just pollutes the memory!
987 // ne0x: Use function PMA_DBI_fetch_array() due to mysqli
988 // compatibility. Now this function is wrapped.
990 $odd_row = true;
991 while ($row = PMA_DBI_fetch_row($dt_result)) {
992 // lem9: "vertical display" mode stuff
993 if ( $row_no != 0 && $repeat_cells != 0 && !($row_no % $repeat_cells)
994 && ( $disp_direction == 'horizontal'
995 || $disp_direction == 'horizontalflipped') )
997 echo '<tr>' . "\n";
998 if ( $vertical_display['emptypre'] > 0 ) {
999 echo ' <th colspan="' . $vertical_display['emptypre'] . '">' . "\n"
1000 .' &nbsp;</th>' . "\n";
1003 foreach ( $vertical_display['desc'] as $val ) {
1004 echo $val;
1007 if ( $vertical_display['emptyafter'] > 0 ) {
1008 echo ' <th colspan="' . $vertical_display['emptyafter'] . '">' . "\n"
1009 .' &nbsp;</th>' . "\n";
1011 echo '</tr>' . "\n";
1012 } // end if
1014 if ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped') {
1015 // loic1: pointer code part
1016 echo ' <tr class="' . ( $odd_row ? 'odd' : 'even' ) . '">' . "\n";
1017 $odd_row = ! $odd_row;
1018 $bgcolor = '';
1019 } elseif (isset($GLOBALS['printview']) && ($GLOBALS['printview'] == '1')) {
1020 $bgcolor = ' bgcolor="#ffffff" ';
1021 } else {
1022 $bgcolor = ' bgcolor="' . ($row_no % 2 ? $GLOBALS['cfg']['BgcolorOne'] : $GLOBALS['cfg']['BgcolorTwo'] ) . '" ';
1026 // 1. Prepares the row (gets primary keys to use)
1027 // 1.1 Results from a "SELECT" statement -> builds the
1028 // "primary" key to use in links
1029 $uva_condition = urlencode(PMA_getUvaCondition($dt_result, $fields_cnt, $fields_meta, $row));
1031 // 1.2 Defines the urls for the modify/delete link(s)
1032 $url_query = PMA_generate_common_url($db, $table)
1033 . '&amp;pos=' . $pos
1034 . '&amp;session_max_rows=' . $session_max_rows
1035 . '&amp;disp_direction=' . $disp_direction
1036 . '&amp;repeat_cells=' . $repeat_cells
1037 . '&amp;dontlimitchars=' . $dontlimitchars;
1039 if ($is_display['edit_lnk'] != 'nn' || $is_display['del_lnk'] != 'nn') {
1040 // We need to copy the value or else the == 'both' check will always return true
1042 if ($GLOBALS['cfg']['PropertiesIconic'] === 'both') {
1043 $iconic_spacer = '<div class="nowrap">';
1044 } else {
1045 $iconic_spacer = '';
1048 // 1.2.1 Modify link(s)
1049 if ($is_display['edit_lnk'] == 'ur') { // update row case
1050 $lnk_goto = 'sql.php';
1052 $edit_url = 'tbl_change.php'
1053 . '?' . $url_query
1054 . '&amp;primary_key=' . $uva_condition
1055 . '&amp;sql_query=' . urlencode($url_sql_query)
1056 . '&amp;goto=' . urlencode($lnk_goto);
1057 if ($GLOBALS['cfg']['PropertiesIconic'] === FALSE) {
1058 $edit_str = $GLOBALS['strEdit'];
1059 } else {
1060 $edit_str = $iconic_spacer . '<img class="icon" width="16" height="16" src="' . $GLOBALS['pmaThemeImage'] . 'b_edit.png" alt="' . $GLOBALS['strEdit'] . '" title="' . $GLOBALS['strEdit'] . '" />';
1061 if ($GLOBALS['cfg']['PropertiesIconic'] === 'both') {
1062 $edit_str .= ' ' . $GLOBALS['strEdit'] . '</div>';
1065 } // end if (1.2.1)
1067 if ($table == $GLOBALS['cfg']['Bookmark']['table'] && $db == $GLOBALS['cfg']['Bookmark']['db'] && isset($row[1]) && isset($row[0])) {
1068 $bookmark_go = '<a href="import.php?'
1069 . PMA_generate_common_url($row[1], '')
1070 . '&amp;id_bookmark=' . $row[0]
1071 . '&amp;action_bookmark=0'
1072 . '&amp;action_bookmark_all=1'
1073 . '&amp;SQL=' . $GLOBALS['strExecuteBookmarked']
1074 .' " title="' . $GLOBALS['strExecuteBookmarked'] . '">';
1076 if ($GLOBALS['cfg']['PropertiesIconic'] === FALSE) {
1077 $bookmark_go .= $GLOBALS['strExecuteBookmarked'];
1078 } else {
1079 $bookmark_go .= $iconic_spacer . '<img class="icon" width="16" height="16" src="' . $GLOBALS['pmaThemeImage'] . 'b_bookmark.png" alt="' . $GLOBALS['strExecuteBookmarked'] . '" title="' . $GLOBALS['strExecuteBookmarked'] . '" />';
1080 if ($GLOBALS['cfg']['PropertiesIconic'] === 'both') {
1081 $bookmark_go .= ' ' . $GLOBALS['strExecuteBookmarked'] . '</div>';
1085 $bookmark_go .= '</a>';
1086 } else {
1087 $bookmark_go = '';
1090 // 1.2.2 Delete/Kill link(s)
1091 if ($is_display['del_lnk'] == 'dr') { // delete row case
1092 $lnk_goto = 'sql.php'
1093 . '?' . str_replace('&amp;', '&', $url_query)
1094 . '&sql_query=' . urlencode($url_sql_query)
1095 . '&zero_rows=' . urlencode(htmlspecialchars($GLOBALS['strDeleted']))
1096 . '&goto=' . (empty($goto) ? 'tbl_properties.php' : $goto);
1097 $del_query = urlencode('DELETE FROM ' . PMA_backquote($table) . ' WHERE') . $uva_condition . '+LIMIT+1';
1098 $del_url = 'sql.php'
1099 . '?' . $url_query
1100 . '&amp;sql_query=' . $del_query
1101 . '&amp;zero_rows=' . urlencode(htmlspecialchars($GLOBALS['strDeleted']))
1102 . '&amp;goto=' . urlencode($lnk_goto);
1103 $js_conf = 'DELETE FROM ' . PMA_jsFormat($table)
1104 . ' WHERE ' . trim(PMA_jsFormat(urldecode($uva_condition), FALSE))
1105 . ' LIMIT 1';
1106 if ($GLOBALS['cfg']['PropertiesIconic'] === FALSE) {
1107 $del_str = $GLOBALS['strDelete'];
1108 } else {
1109 $del_str = $iconic_spacer . '<img class="icon" width="16" height="16" src="' . $GLOBALS['pmaThemeImage'] . 'b_drop.png" alt="' . $GLOBALS['strDelete'] . '" title="' . $GLOBALS['strDelete'] . '" />';
1110 if ($GLOBALS['cfg']['PropertiesIconic'] === 'both') {
1111 $del_str .= ' ' . $GLOBALS['strDelete'] . '</div>';
1114 } else if ($is_display['del_lnk'] == 'kp') { // kill process case
1115 $lnk_goto = 'sql.php'
1116 . '?' . str_replace('&amp;', '&', $url_query)
1117 . '&sql_query=' . urlencode($url_sql_query)
1118 . '&goto=main.php';
1119 $del_url = 'sql.php?'
1120 . PMA_generate_common_url('mysql')
1121 . '&amp;sql_query=' . urlencode('KILL ' . $row[0])
1122 . '&amp;goto=' . urlencode($lnk_goto);
1123 $del_query = urlencode('KILL ' . $row[0]);
1124 $js_conf = 'KILL ' . $row[0];
1125 if ($GLOBALS['cfg']['PropertiesIconic'] === FALSE) {
1126 $del_str = $GLOBALS['strKill'];
1127 } else {
1128 $del_str = $iconic_spacer . '<img class="icon" width="16" height="16" src="' . $GLOBALS['pmaThemeImage'] . 'b_drop.png" alt="' . $GLOBALS['strKill'] . '" title="' . $GLOBALS['strKill'] . '" />';
1129 if ($GLOBALS['cfg']['PropertiesIconic'] === 'both') {
1130 $del_str .= ' ' . $GLOBALS['strKill'] . '</div>';
1133 } // end if (1.2.2)
1135 // 1.3 Displays the links at left if required
1136 if ($GLOBALS['cfg']['ModifyDeleteAtLeft']
1137 && ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped')) {
1138 $doWriteModifyAt = 'left';
1139 require('./libraries/display_tbl_links.lib.php');
1140 } // end if (1.3)
1141 } // end if (1)
1143 // 2. Displays the rows' values
1144 for ($i = 0; $i < $fields_cnt; ++$i) {
1145 $meta = $fields_meta[$i];
1146 // loic1: To fix bug #474943 under php4, the row pointer will
1147 // depend on whether the "is_null" php4 function is
1148 // available or not
1149 $pointer = (function_exists('is_null') ? $i : $meta->name);
1150 // garvin: See if this column should get highlight because it's used in the
1151 // where-query.
1152 if (isset($highlight_columns) && (isset($highlight_columns[$meta->name]) || isset($highlight_columns[PMA_backquote($meta->name)]))) {
1153 $column_style = ' style="border: 1px solid ' . $GLOBALS['cfg']['BrowseMarkerColor'] . '" ';
1154 } else {
1155 $column_style = '';
1158 if ($disp_direction == 'vertical' && (!isset($GLOBALS['printview']) || ($GLOBALS['printview'] != '1'))) {
1159 if ($GLOBALS['cfg']['BrowsePointerColor'] == TRUE) {
1160 $column_style .= ' onmouseover="setVerticalPointer(this, ' . $row_no . ', \'over\', \'' . $GLOBALS['cfg']['BgcolorOne'] . '\', \'' . $GLOBALS['cfg']['BgcolorTwo'] . '\', \'' . $GLOBALS['cfg']['BrowsePointerColor'] . '\', \'' . $GLOBALS['cfg']['BrowseMarkerColor'] . '\');"'
1161 . ' onmouseout="setVerticalPointer(this, ' . $row_no . ', \'out\', \'' . $GLOBALS['cfg']['BgcolorOne'] . '\', \'' . $GLOBALS['cfg']['BgcolorTwo'] . '\', \'' . $GLOBALS['cfg']['BrowsePointerColor'] . '\', \'' . $GLOBALS['cfg']['BrowseMarkerColor'] . '\');" ';
1163 if ($GLOBALS['cfg']['BrowseMarkerEnable'] == TRUE) {
1164 $column_style .= ' onmousedown="setVerticalPointer(this, ' . $row_no . ', \'click\', \'' . $GLOBALS['cfg']['BgcolorOne'] . '\', \'' . $GLOBALS['cfg']['BgcolorTwo'] . '\', \'' . $GLOBALS['cfg']['BrowsePointerColor'] . '\', \'' . $GLOBALS['cfg']['BrowseMarkerColor'] . '\'); setCheckboxColumn(\'id_rows_to_delete' . $row_no . '\');" ';
1165 } else {
1166 $column_style .= ' onmousedown="setCheckboxColumn(\'id_rows_to_delete' . $row_no . '\');" ';
1168 }// end if
1170 // garvin: Wrap MIME-transformations. [MIME]
1171 $default_function = 'default_function'; // default_function
1172 $transform_function = $default_function;
1173 $transform_options = array();
1175 if ($GLOBALS['cfgRelation']['mimework'] && $GLOBALS['cfg']['BrowseMIME']) {
1177 if (isset($GLOBALS['mime_map'][$meta->name]['mimetype']) && isset($GLOBALS['mime_map'][$meta->name]['transformation']) && !empty($GLOBALS['mime_map'][$meta->name]['transformation'])) {
1178 $include_file = PMA_sanitizeTransformationFile($GLOBALS['mime_map'][$meta->name]['transformation']);
1180 if (file_exists('./libraries/transformations/' . $include_file)) {
1181 $transformfunction_name = preg_replace('@(\.inc\.php3?)$@i', '', $GLOBALS['mime_map'][$meta->name]['transformation']);
1183 require_once('./libraries/transformations/' . $include_file);
1185 if (function_exists('PMA_transformation_' . $transformfunction_name)) {
1186 $transform_function = 'PMA_transformation_' . $transformfunction_name;
1187 $transform_options = PMA_transformation_getOptions((isset($GLOBALS['mime_map'][$meta->name]['transformation_options']) ? $GLOBALS['mime_map'][$meta->name]['transformation_options'] : ''));
1188 $meta->mimetype = str_replace('_', '/', $GLOBALS['mime_map'][$meta->name]['mimetype']);
1190 } // end if file_exists
1191 } // end if transformation is set
1192 } // end if mime/transformation works.
1194 $transform_options['wrapper_link'] = '?'
1195 . (isset($url_query) ? $url_query : '')
1196 . '&amp;primary_key=' . (isset($uva_condition) ? $uva_condition : '')
1197 . '&amp;sql_query=' . (isset($sql_query) ? urlencode($url_sql_query) : '')
1198 . '&amp;goto=' . (isset($sql_goto) ? urlencode($lnk_goto) : '')
1199 . '&amp;transform_key=' . urlencode($meta->name);
1202 // n u m e r i c
1203 if ($meta->numeric == 1) {
1206 // lem9: if two fields have the same name (this is possible
1207 // with self-join queries, for example), using $meta->name
1208 // will show both fields NULL even if only one is NULL,
1209 // so use the $pointer
1210 // (works only if function_exists('is_null')
1211 // PS: why not always work with the number ($i), since
1212 // the default second parameter of
1213 // mysql_fetch_array() is MYSQL_BOTH, so we always get
1214 // associative and numeric indices?
1216 //if (!isset($row[$meta->name])
1217 if (!isset($row[$i]) || is_null($row[$i])) {
1218 $vertical_display['data'][$row_no][$i] = ' <td align="right"' . $column_style . $bgcolor . '><i>NULL</i></td>' . "\n";
1219 } else if ($row[$i] != '') {
1220 $vertical_display['data'][$row_no][$i] = ' <td align="right"' . $column_style . $bgcolor . ' class="nowrap">';
1222 if (isset($analyzed_sql[0]['select_expr']) && is_array($analyzed_sql[0]['select_expr'])) {
1223 foreach ($analyzed_sql[0]['select_expr'] AS $select_expr_position => $select_expr) {
1224 $alias = $analyzed_sql[0]['select_expr'][$select_expr_position]['alias'];
1225 if (!empty($alias)) {
1226 $true_column = $analyzed_sql[0]['select_expr'][$select_expr_position]['column'];
1227 if ($alias == $meta->name) {
1228 $meta->name = $true_column;
1229 } // end if
1230 } // end if
1231 } // end while
1234 if (isset($map[$meta->name])) {
1235 // Field to display from the foreign table?
1236 if (!empty($map[$meta->name][2])) {
1237 $dispsql = 'SELECT ' . PMA_backquote($map[$meta->name][2])
1238 . ' FROM ' . PMA_backquote($map[$meta->name][3]) . '.' . PMA_backquote($map[$meta->name][0])
1239 . ' WHERE ' . PMA_backquote($map[$meta->name][1])
1240 . ' = ' . $row[$i];
1241 $dispresult = PMA_DBI_try_query($dispsql, NULL, PMA_DBI_QUERY_STORE);
1242 if ($dispresult && PMA_DBI_num_rows($dispresult) > 0) {
1243 list($dispval) = PMA_DBI_fetch_row($dispresult, 0);
1245 else {
1246 $dispval = $GLOBALS['strLinkNotFound'];
1248 @PMA_DBI_free_result($dispresult);
1250 else {
1251 $dispval = '';
1252 } // end if... else...
1254 if (isset($GLOBALS['printview']) && $GLOBALS['printview'] == '1') {
1255 $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>';
1256 } else {
1257 $title = (!empty($dispval))? ' title="' . htmlspecialchars($dispval) . '"' : '';
1259 $vertical_display['data'][$row_no][$i] .= '<a href="sql.php?'
1260 . PMA_generate_common_url($map[$meta->name][3], $map[$meta->name][0])
1261 . '&amp;pos=0&amp;session_max_rows=' . $session_max_rows . '&amp;dontlimitchars=' . $dontlimitchars
1262 . '&amp;sql_query=' . urlencode('SELECT * FROM ' . PMA_backquote($map[$meta->name][0]) . ' WHERE ' . PMA_backquote($map[$meta->name][1]) . ' = ' . $row[$i]) . '"' . $title . '>'
1263 . ($transform_function != $default_function ? $transform_function($row[$i], $transform_options, $meta) : $transform_function($row[$i], array(), $meta)) . '</a>';
1265 } else {
1266 $vertical_display['data'][$row_no][$i] .= ($transform_function != $default_function ? $transform_function($row[$i], $transform_options, $meta) : $transform_function($row[$i], array(), $meta));
1268 $vertical_display['data'][$row_no][$i] .= '</td>' . "\n";
1269 } else {
1270 $vertical_display['data'][$row_no][$i] = ' <td align="right"' . $column_style . $bgcolor . ' class="nowrap">&nbsp;</td>' . "\n";
1273 // b l o b
1275 } else if ($GLOBALS['cfg']['ShowBlob'] == FALSE && stristr($meta->type, 'BLOB')) {
1276 // loic1 : PMA_mysql_fetch_fields returns BLOB in place of
1277 // TEXT fields type, however TEXT fields must be displayed
1278 // even if $GLOBALS['cfg']['ShowBlob'] is false -> get the true type
1279 // of the fields.
1280 $field_flags = PMA_DBI_field_flags($dt_result, $i);
1281 if (stristr($field_flags, 'BINARY')) {
1282 $blobtext = '[BLOB';
1283 if (!isset($row[$i]) || is_null($row[$i])) {
1284 $blobtext .= ' - NULL';
1285 } elseif (isset($row[$i])) {
1286 $blob_size = PMA_formatByteDown(strlen($row[$i]), 3, 1);
1287 $blobtext .= ' - '. $blob_size [0] . ' ' . $blob_size[1];
1288 unset($blob_size);
1291 $blobtext .= ']';
1292 $blobtext = ($default_function != $transform_function ? $transform_function($blobtext, $transform_options, $meta) : $default_function($blobtext, array(), $meta));
1294 $vertical_display['data'][$row_no][$i] = ' <td align="center"' . $column_style . $bgcolor . '>' . $blobtext . '</td>';
1295 } else {
1296 if (!isset($row[$i]) || is_null($row[$i])) {
1297 $vertical_display['data'][$row_no][$i] = ' <td' . $column_style . $bgcolor . '><i>NULL</i></td>' . "\n";
1298 } else if ($row[$i] != '') {
1299 // garvin: if a transform function for blob is set, none of these replacements will be made
1300 if (PMA_strlen($row[$i]) > $GLOBALS['cfg']['LimitChars'] && ($dontlimitchars != 1)) {
1301 $row[$i] = PMA_substr($row[$i], 0, $GLOBALS['cfg']['LimitChars']) . '...';
1303 // loic1: displays all space characters, 4 space
1304 // characters for tabulations and <cr>/<lf>
1305 $row[$i] = ($default_function != $transform_function ? $transform_function($row[$i], $transform_options, $meta) : $default_function($row[$i], array(), $meta));
1307 $vertical_display['data'][$row_no][$i] = ' <td' . $column_style . $bgcolor . '>' . $row[$i] . '</td>' . "\n";
1308 } else {
1309 $vertical_display['data'][$row_no][$i] = ' <td' . $column_style . $bgcolor . '>&nbsp;</td>' . "\n";
1312 } else {
1313 if (!isset($row[$i]) || is_null($row[$i])) {
1314 $vertical_display['data'][$row_no][$i] = ' <td' . $column_style . $bgcolor . '><i>NULL</i></td>' . "\n";
1315 } else if ($row[$i] != '') {
1316 // loic1: support blanks in the key
1317 $relation_id = $row[$i];
1319 // nijel: Cut all fields to $GLOBALS['cfg']['LimitChars']
1320 if (PMA_strlen($row[$i]) > $GLOBALS['cfg']['LimitChars'] && ($dontlimitchars != 1)) {
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 (stristr($field_flags, 'BINARY')) {
1327 $row[$i] = str_replace("\x00", '\0', $row[$i]);
1328 $row[$i] = str_replace("\x08", '\b', $row[$i]);
1329 $row[$i] = str_replace("\x0a", '\n', $row[$i]);
1330 $row[$i] = str_replace("\x0d", '\r', $row[$i]);
1331 $row[$i] = str_replace("\x1a", '\Z', $row[$i]);
1332 $row[$i] = ($default_function != $transform_function ? $transform_function($row[$i], $transform_options, $meta) : $default_function($row[$i], array(), $meta));
1334 // loic1: displays all space characters, 4 space
1335 // characters for tabulations and <cr>/<lf>
1336 else {
1337 $row[$i] = ($default_function != $transform_function ? $transform_function($row[$i], $transform_options, $meta) : $default_function($row[$i], array(), $meta));
1340 // garvin: transform functions may enable nowrapping:
1341 $function_nowrap = $transform_function . '_nowrap';
1342 $bool_nowrap = (($default_function != $transform_function && function_exists($function_nowrap)) ? $function_nowrap($transform_options) : false);
1344 // loic1: do not wrap if date field type
1345 $nowrap = ((preg_match('@DATE|TIME@i', $meta->type) || $bool_nowrap) ? ' nowrap="nowrap"' : '');
1346 $vertical_display['data'][$row_no][$i] = ' <td' . $column_style . $bgcolor . $nowrap . '>';
1348 if (isset($analyzed_sql[0]['select_expr']) && is_array($analyzed_sql[0]['select_expr'])) {
1349 foreach ($analyzed_sql[0]['select_expr'] AS $select_expr_position => $select_expr) {
1350 $alias = $analyzed_sql[0]['select_expr'][$select_expr_position]['alias'];
1351 if (!empty($alias)) {
1352 $true_column = $analyzed_sql[0]['select_expr'][$select_expr_position]['column'];
1353 if ($alias == $meta->name) {
1354 $meta->name = $true_column;
1355 } // end if
1356 } // end if
1357 } // end while
1360 if (isset($map[$meta->name])) {
1361 // Field to display from the foreign table?
1362 if (!empty($map[$meta->name][2])) {
1363 $dispsql = 'SELECT ' . PMA_backquote($map[$meta->name][2])
1364 . ' FROM ' . PMA_backquote($map[$meta->name][3]) . '.' . PMA_backquote($map[$meta->name][0])
1365 . ' WHERE ' . PMA_backquote($map[$meta->name][1])
1366 . ' = \'' . PMA_sqlAddslashes($row[$i]) . '\'';
1367 $dispresult = PMA_DBI_try_query($dispsql, NULL, PMA_DBI_QUERY_STORE);
1368 if ($dispresult && PMA_DBI_num_rows($dispresult) > 0) {
1369 list($dispval) = PMA_DBI_fetch_row($dispresult);
1370 @PMA_DBI_free_result($dispresult);
1372 else {
1373 $dispval = $GLOBALS['strLinkNotFound'];
1376 else {
1377 $dispval = '';
1379 $title = (!empty($dispval))? ' title="' . htmlspecialchars($dispval) . '"' : '';
1381 $vertical_display['data'][$row_no][$i] .= '<a href="sql.php?'
1382 . PMA_generate_common_url($map[$meta->name][3], $map[$meta->name][0])
1383 . '&amp;pos=0&amp;session_max_rows=' . $session_max_rows . '&amp;dontlimitchars=' . $dontlimitchars
1384 . '&amp;sql_query=' . urlencode('SELECT * FROM ' . PMA_backquote($map[$meta->name][0]) . ' WHERE ' . PMA_backquote($map[$meta->name][1]) . ' = \'' . PMA_sqlAddslashes($relation_id) . '\'') . '"' . $title . '>'
1385 . $row[$i] . '</a>';
1386 } else {
1387 $vertical_display['data'][$row_no][$i] .= $row[$i];
1389 $vertical_display['data'][$row_no][$i] .= '</td>' . "\n";
1390 } else {
1391 $vertical_display['data'][$row_no][$i] = ' <td' . $column_style . $bgcolor . '>&nbsp;</td>' . "\n";
1395 // lem9: output stored cell
1396 if ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped') {
1397 echo $vertical_display['data'][$row_no][$i];
1400 if (isset($vertical_display['rowdata'][$i][$row_no])) {
1401 $vertical_display['rowdata'][$i][$row_no] .= $vertical_display['data'][$row_no][$i];
1402 } else {
1403 $vertical_display['rowdata'][$i][$row_no] = $vertical_display['data'][$row_no][$i];
1405 } // end for (2)
1407 // 3. Displays the modify/delete links on the right if required
1408 if ($GLOBALS['cfg']['ModifyDeleteAtRight']
1409 && ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped')) {
1410 $doWriteModifyAt = 'right';
1411 require('./libraries/display_tbl_links.lib.php');
1412 } // end if (3)
1414 if ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped') {
1416 </tr>
1417 <?php
1418 } // end if
1420 // 4. Gather links of del_urls and edit_urls in an array for later
1421 // output
1422 if (!isset($vertical_display['edit'][$row_no])) {
1423 $vertical_display['edit'][$row_no] = '';
1424 $vertical_display['delete'][$row_no] = '';
1425 $vertical_display['row_delete'][$row_no] = '';
1428 $column_style_vertical = '';
1429 if ($GLOBALS['cfg']['BrowsePointerEnable'] == TRUE) {
1430 $column_style_vertical .= ' onmouseover="setVerticalPointer(this, ' . $row_no . ', \'over\', \'' . $GLOBALS['cfg']['BgcolorOne'] . '\', \'' . $GLOBALS['cfg']['BgcolorTwo'] . '\', \'' . $GLOBALS['cfg']['BrowsePointerColor'] . '\', \'' . $GLOBALS['cfg']['BrowseMarkerColor'] . '\');"'
1431 . ' onmouseout="setVerticalPointer(this, ' . $row_no . ', \'out\', \'' . $GLOBALS['cfg']['BgcolorOne'] . '\', \'' . $GLOBALS['cfg']['BgcolorTwo'] . '\', \'' . $GLOBALS['cfg']['BrowsePointerColor'] . '\', \'' . $GLOBALS['cfg']['BrowseMarkerColor'] . '\');"';
1433 $column_marker_vertical = '';
1434 if ($GLOBALS['cfg']['BrowseMarkerEnable'] == TRUE) {
1435 $column_marker_vertical .= 'setVerticalPointer(this, ' . $row_no . ', \'click\', \'' . $GLOBALS['cfg']['BgcolorOne'] . '\', \'' . $GLOBALS['cfg']['BgcolorTwo'] . '\', \'' . $GLOBALS['cfg']['BrowsePointerColor'] . '\', \'' . $GLOBALS['cfg']['BrowseMarkerColor'] . '\');';
1438 if (!empty($del_url) && $is_display['del_lnk'] != 'kp') {
1439 $vertical_display['row_delete'][$row_no] .= ' <td align="center" ' . $bgcolor . $column_style_vertical . '>' . "\n"
1440 . ' <input type="checkbox" id="id_rows_to_delete' . $row_no . '[%_PMA_CHECKBOX_DIR_%]" name="rows_to_delete[' . $uva_condition . ']"'
1441 . ' onclick="' . $column_marker_vertical . 'copyCheckboxesRange(\'rowsDeleteForm\', \'id_rows_to_delete' . $row_no . '\',\'[%_PMA_CHECKBOX_DIR_%]\');"'
1442 . ' value="' . $del_query . '" ' . (isset($GLOBALS['checkall']) ? 'checked="checked"' : '') . ' />' . "\n"
1443 . ' </td>' . "\n";
1444 } else {
1445 unset($vertical_display['row_delete'][$row_no]);
1448 if (isset($edit_url)) {
1449 $vertical_display['edit'][$row_no] .= ' <td align="center"' . $bgcolor . $column_style_vertical . '>' . "\n"
1450 . PMA_linkOrButton($edit_url, $edit_str, array(), FALSE)
1451 . $bookmark_go
1452 . ' </td>' . "\n";
1453 } else {
1454 unset($vertical_display['edit'][$row_no]);
1457 if (isset($del_url)) {
1458 $vertical_display['delete'][$row_no] .= ' <td align="center"' . $bgcolor . $column_style_vertical . '>' . "\n"
1459 . PMA_linkOrButton($del_url, $del_str, (isset($js_conf) ? $js_conf : ''), FALSE)
1460 . ' </td>' . "\n";
1461 } else {
1462 unset($vertical_display['delete'][$row_no]);
1465 echo (($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped') ? "\n" : '');
1466 $row_no++;
1467 } // end while
1469 if (isset($url_query)) {
1470 $GLOBALS['url_query'] = $url_query;
1473 return TRUE;
1474 } // end of the 'PMA_displayTableBody()' function
1478 * Do display the result table with the vertical direction mode.
1479 * Credits for this feature goes to Garvin Hicking <hicking@faktor-e.de>.
1481 * @return boolean always true
1483 * @global array $vertical_display the information to display
1484 * @global integer $repeat_cells the number of row to display between two
1485 * table headers
1487 * @access private
1489 * @see PMA_displayTable()
1491 function PMA_displayVerticalTable()
1493 global $vertical_display, $repeat_cells;
1495 // Displays "multi row delete" link at top if required
1496 if ($GLOBALS['cfg']['ModifyDeleteAtLeft'] && is_array($vertical_display['row_delete']) && (count($vertical_display['row_delete']) > 0 || !empty($vertical_display['textbtn']))) {
1497 echo '<tr>' . "\n";
1498 echo $vertical_display['textbtn'];
1499 $foo_counter = 0;
1500 foreach ($vertical_display['row_delete'] as $val) {
1501 if (($foo_counter != 0) && ($repeat_cells != 0) && !($foo_counter % $repeat_cells)) {
1502 echo '<th>&nbsp;</th>' . "\n";
1505 echo str_replace('[%_PMA_CHECKBOX_DIR_%]', '', $val);
1506 $foo_counter++;
1507 } // end while
1508 echo '</tr>' . "\n";
1509 } // end if
1511 // Displays "edit" link at top if required
1512 if ($GLOBALS['cfg']['ModifyDeleteAtLeft'] && is_array($vertical_display['edit']) && (count($vertical_display['edit']) > 0 || !empty($vertical_display['textbtn']))) {
1513 echo '<tr>' . "\n";
1514 if (!is_array($vertical_display['row_delete'])) {
1515 echo $vertical_display['textbtn'];
1517 $foo_counter = 0;
1518 foreach ($vertical_display['edit'] as $val) {
1519 if (($foo_counter != 0) && ($repeat_cells != 0) && !($foo_counter % $repeat_cells)) {
1520 echo ' <th>&nbsp;</th>' . "\n";
1523 echo $val;
1524 $foo_counter++;
1525 } // end while
1526 echo '</tr>' . "\n";
1527 } // end if
1529 // Displays "delete" link at top if required
1530 if ($GLOBALS['cfg']['ModifyDeleteAtLeft'] && is_array($vertical_display['delete']) && (count($vertical_display['delete']) > 0 || !empty($vertical_display['textbtn']))) {
1531 echo '<tr>' . "\n";
1532 if (!is_array($vertical_display['edit']) && !is_array($vertical_display['row_delete'])) {
1533 echo $vertical_display['textbtn'];
1535 $foo_counter = 0;
1536 foreach ($vertical_display['delete'] as $val) {
1537 if (($foo_counter != 0) && ($repeat_cells != 0) && !($foo_counter % $repeat_cells)) {
1538 echo '<th>&nbsp;</th>' . "\n";
1541 echo $val;
1542 $foo_counter++;
1543 } // end while
1544 echo '</tr>' . "\n";
1545 } // end if
1547 // Displays data
1548 foreach ($vertical_display['desc'] AS $key => $val) {
1550 echo '<tr>' . "\n";
1551 echo $val;
1553 $foo_counter = 0;
1554 foreach ($vertical_display['rowdata'][$key] as $subval) {
1555 if (($foo_counter != 0) && ($repeat_cells != 0) and !($foo_counter % $repeat_cells)) {
1556 echo $val;
1559 echo $subval;
1560 $foo_counter++;
1561 } // end while
1563 echo '</tr>' . "\n";
1564 } // end while
1566 // Displays "multi row delete" link at bottom if required
1567 if ($GLOBALS['cfg']['ModifyDeleteAtRight'] && is_array($vertical_display['row_delete']) && (count($vertical_display['row_delete']) > 0 || !empty($vertical_display['textbtn']))) {
1568 echo '<tr>' . "\n";
1569 echo $vertical_display['textbtn'];
1570 $foo_counter = 0;
1571 foreach ($vertical_display['row_delete'] as $val) {
1572 if (($foo_counter != 0) && ($repeat_cells != 0) && !($foo_counter % $repeat_cells)) {
1573 echo '<th>&nbsp;</th>' . "\n";
1576 echo str_replace('[%_PMA_CHECKBOX_DIR_%]', 'r', $val);
1577 $foo_counter++;
1578 } // end while
1579 echo '</tr>' . "\n";
1580 } // end if
1582 // Displays "edit" link at bottom if required
1583 if ($GLOBALS['cfg']['ModifyDeleteAtRight'] && is_array($vertical_display['edit']) && (count($vertical_display['edit']) > 0 || !empty($vertical_display['textbtn']))) {
1584 echo '<tr>' . "\n";
1585 if (!is_array($vertical_display['row_delete'])) {
1586 echo $vertical_display['textbtn'];
1588 $foo_counter = 0;
1589 foreach ($vertical_display['edit'] as $val) {
1590 if (($foo_counter != 0) && ($repeat_cells != 0) && !($foo_counter % $repeat_cells)) {
1591 echo '<th>&nbsp;</th>' . "\n";
1594 echo $val;
1595 $foo_counter++;
1596 } // end while
1597 echo '</tr>' . "\n";
1598 } // end if
1600 // Displays "delete" link at bottom if required
1601 if ($GLOBALS['cfg']['ModifyDeleteAtRight'] && is_array($vertical_display['delete']) && (count($vertical_display['delete']) > 0 || !empty($vertical_display['textbtn']))) {
1602 echo '<tr>' . "\n";
1603 if (!is_array($vertical_display['edit']) && !is_array($vertical_display['row_delete'])) {
1604 echo $vertical_display['textbtn'];
1606 $foo_counter = 0;
1607 foreach ($vertical_display['delete'] as $val) {
1608 if (($foo_counter != 0) && ($repeat_cells != 0) && !($foo_counter % $repeat_cells)) {
1609 echo '<th>&nbsp;</th>' . "\n";
1612 echo $val;
1613 $foo_counter++;
1614 } // end while
1615 echo '</tr>' . "\n";
1618 return TRUE;
1619 } // end of the 'PMA_displayVerticalTable' function
1623 * Displays a table of results returned by a sql query.
1624 * This function is called by the "sql.php" script.
1626 * @param integer the link id associated to the query which results have
1627 * to be displayed
1628 * @param array the display mode
1629 * @param array the analyzed query
1631 * @global string $db the database name
1632 * @global string $table the table name
1633 * @global string $goto the url to go back in case of errors
1634 * @global boolean $dontlimitchars whether to limit the number of displayed
1635 * characters of text type fields or not
1636 * @global string $sql_query the current sql query
1637 * @global integer $num_rows the total number of rows returned by the
1638 * sql query
1639 * @global integer $unlim_num_rows the total number of rows returned by the
1640 * sql query without any programmatically
1641 * appended "LIMIT" clause
1642 * @global integer $pos the current postion of the first record
1643 * to be displayed
1644 * @global array $fields_meta the list of fields properties
1645 * @global integer $fields_cnt the total number of fields returned by
1646 * the sql query
1647 * @global array $vertical_display informations used with vertical display
1648 * mode
1649 * @global string $disp_direction the display mode
1650 * (horizontal/vertical/horizontalflipped)
1651 * @global integer $repeat_cells the number of row to display between two
1652 * table headers
1653 * @global array $highlight_columns collumn names to highlight
1654 * @global array $cfgRelation the relation settings
1656 * @access private
1658 * @see PMA_showMessage(), PMA_setDisplayMode(),
1659 * PMA_displayTableNavigation(), PMA_displayTableHeaders(),
1660 * PMA_displayTableBody()
1662 function PMA_displayTable(&$dt_result, &$the_disp_mode, $analyzed_sql)
1664 global $db, $table, $goto, $dontlimitchars;
1665 global $sql_query, $num_rows, $unlim_num_rows, $pos, $fields_meta, $fields_cnt;
1666 global $vertical_display, $disp_direction, $repeat_cells, $highlight_columns;
1667 global $cfgRelation;
1669 // 1. ----- Prepares the work -----
1671 // 1.1 Gets the informations about which functionnalities should be
1672 // displayed
1673 $total = '';
1674 $is_display = PMA_setDisplayMode($the_disp_mode, $total);
1675 if ($total == '') {
1676 unset($total);
1679 // 1.2 Defines offsets for the next and previous pages
1680 if ($is_display['nav_bar'] == '1') {
1681 if (!isset($pos)) {
1682 $pos = 0;
1684 if ($GLOBALS['session_max_rows'] == 'all') {
1685 $pos_next = 0;
1686 $pos_prev = 0;
1687 } else {
1688 $pos_next = $pos + $GLOBALS['cfg']['MaxRows'];
1689 $pos_prev = $pos - $GLOBALS['cfg']['MaxRows'];
1690 if ($pos_prev < 0) {
1691 $pos_prev = 0;
1694 } // end if
1696 // 1.3 Urlencodes the query to use in input form fields
1697 $encoded_sql_query = urlencode($sql_query);
1699 // 2. ----- Displays the top of the page -----
1701 // 2.1 Displays a messages with position informations
1702 if ($is_display['nav_bar'] == '1' && isset($pos_next)) {
1703 if (isset($unlim_num_rows) && $unlim_num_rows != $total) {
1704 $selectstring = ', ' . $unlim_num_rows . ' ' . $GLOBALS['strSelectNumRows'];
1705 } else {
1706 $selectstring = '';
1708 $last_shown_rec = ($GLOBALS['session_max_rows'] == 'all' || $pos_next > $total)
1709 ? $total - 1
1710 : $pos_next - 1;
1711 PMA_showMessage($GLOBALS['strShowingRecords'] . " $pos - $last_shown_rec (" . PMA_formatNumber( $total, 0 ) . ' ' . $GLOBALS['strTotal'] . $selectstring . ', ' . sprintf($GLOBALS['strQueryTime'], $GLOBALS['querytime']) . ')');
1712 } else if (!isset($GLOBALS['printview']) || $GLOBALS['printview'] != '1') {
1713 PMA_showMessage($GLOBALS['strSQLQuery']);
1716 // 2.3 Displays the navigation bars
1717 if (!isset($table) || strlen(trim($table)) == 0) {
1718 if (isset($analyzed_sql[0]['query_type'])
1719 && $analyzed_sql[0]['query_type'] == 'SELECT') {
1720 // table does not always contain a real table name,
1721 // for example in MySQL 5.0.x, the query SHOW STATUS
1722 // returns STATUS as a table name
1723 $table = $fields_meta[0]->table;
1724 } else {
1725 $table = '';
1728 if ($is_display['nav_bar'] == '1') {
1729 PMA_displayTableNavigation($pos_next, $pos_prev, $encoded_sql_query);
1730 echo "\n";
1731 } else if (!isset($GLOBALS['printview']) || $GLOBALS['printview'] != '1') {
1732 echo "\n" . '<br /><br />' . "\n";
1735 // 2b ----- Get field references from Database -----
1736 // (see the 'relation' config variable)
1737 // loic1, 2002-03-02: extended to php3
1739 // init map
1740 $map = array();
1742 // find tables
1743 $target=array();
1744 if (isset($analyzed_sql[0]['table_ref']) && is_array($analyzed_sql[0]['table_ref'])) {
1745 foreach ($analyzed_sql[0]['table_ref'] AS $table_ref_position => $table_ref) {
1746 $target[] = $analyzed_sql[0]['table_ref'][$table_ref_position]['table_true_name'];
1749 $tabs = '(\'' . join('\',\'', $target) . '\')';
1751 if ($cfgRelation['displaywork']) {
1752 if (empty($table)) {
1753 $exist_rel = FALSE;
1754 } else {
1755 $exist_rel = PMA_getForeigners($db, $table, '', 'both');
1756 if ($exist_rel) {
1757 foreach ($exist_rel AS $master_field => $rel) {
1758 $display_field = PMA_getDisplayField($rel['foreign_db'],$rel['foreign_table']);
1759 $map[$master_field] = array($rel['foreign_table'],
1760 $rel['foreign_field'],
1761 $display_field,
1762 $rel['foreign_db']);
1763 } // end while
1764 } // end if
1765 } // end if
1766 } // end if
1767 // end 2b
1769 // 3. ----- Displays the results table -----
1770 PMA_displayTableHeaders($is_display, $fields_meta, $fields_cnt, $analyzed_sql);
1771 $url_query='';
1772 echo '<tbody>' . "\n";
1773 PMA_displayTableBody($dt_result, $is_display, $map, $analyzed_sql);
1774 echo '</tbody>' . "\n";
1775 // vertical output case
1776 if ($disp_direction == 'vertical') {
1777 PMA_displayVerticalTable();
1778 } // end if
1779 unset($vertical_display);
1781 </table>
1783 <?php
1784 // 4. ----- Displays the link for multi-fields delete
1786 if ($is_display['del_lnk'] == 'dr' && $is_display['del_lnk'] != 'kp') {
1788 $delete_text = $is_display['del_lnk'] == 'dr' ? $GLOBALS['strDelete'] : $GLOBALS['strKill'];
1790 $uncheckall_url = 'sql.php?'
1791 . PMA_generate_common_url($db, $table)
1792 . '&amp;sql_query=' . urlencode($sql_query)
1793 . '&amp;pos=' . $pos
1794 . '&amp;session_max_rows=' . $GLOBALS['session_max_rows']
1795 . '&amp;pos=' . $pos
1796 . '&amp;disp_direction=' . $disp_direction
1797 . '&amp;repeat_cells=' . $repeat_cells
1798 . '&amp;goto=' . $goto
1799 . '&amp;dontlimitchars=' . $dontlimitchars;
1800 $checkall_url = $uncheckall_url . '&amp;checkall=1';
1802 if ( $disp_direction == 'vertical' ) {
1803 $checkall_params['onclick'] = 'if ( setCheckboxes(\'rowsDeleteForm\', true) ) return false;';
1804 $uncheckall_params['onclick'] = 'if ( setCheckboxes(\'rowsDeleteForm\', false) ) return false;';
1805 } else {
1806 $checkall_params['onclick'] = 'if ( markAllRows(\'rowsDeleteForm\') ) return false;';
1807 $uncheckall_params['onclick'] = 'if ( unMarkAllRows(\'rowsDeleteForm\') ) return false;';
1809 $checkall_link = PMA_linkOrButton( $checkall_url, $GLOBALS['strCheckAll'], $checkall_params, false );
1810 $uncheckall_link = PMA_linkOrButton( $uncheckall_url, $GLOBALS['strUncheckAll'], $uncheckall_params, false );
1811 if ( $disp_direction != 'vertical' ) {
1812 echo '<img class="selectallarrow" width="38" height="22"'
1813 .' src="' . $GLOBALS['pmaThemeImage'] . 'arrow_' . $GLOBALS['text_dir'] . '.png' . '"'
1814 .' alt="' . $GLOBALS['strWithChecked'] . '" />';
1816 echo $checkall_link . "\n"
1817 .' / ' . "\n"
1818 .$uncheckall_link . "\n"
1819 .'<i>' . $GLOBALS['strWithChecked'] . '</i>' . "\n";
1821 if ( $GLOBALS['cfg']['PropertiesIconic'] ) {
1822 PMA_buttonOrImage('submit_mult', 'mult_submit',
1823 'submit_mult_change', $GLOBALS['strChange'], 'b_edit.png');
1824 PMA_buttonOrImage('submit_mult', 'mult_submit',
1825 'submit_mult_delete', $delete_text, 'b_drop.png');
1826 if ($analyzed_sql[0]['querytype'] == 'SELECT') {
1827 PMA_buttonOrImage('submit_mult', 'mult_submit',
1828 'submit_mult_export', $GLOBALS['strExport'],
1829 'b_tblexport.png');
1831 echo "\n";
1832 } else {
1833 echo ' <input type="submit" name="submit_mult"'
1834 .' value="' . htmlspecialchars($GLOBALS['strEdit']) . '"'
1835 .' title="' . $GLOBALS['strEdit'] . '" />' . "\n";
1836 echo ' <input type="submit" name="submit_mult"'
1837 .' value="' . htmlspecialchars($delete_text) . '"'
1838 .' title="' . $delete_text . '" />' . "\n";
1839 if ($analyzed_sql[0]['querytype'] == 'SELECT') {
1840 echo ' <input type="submit" name="submit_mult"'
1841 .' value="' . htmlspecialchars($GLOBALS['strExport']) . '"'
1842 .' title="' . $GLOBALS['strExport'] . '" />' . "\n";
1845 echo '<input type="hidden" name="sql_query"'
1846 .' value="' . htmlspecialchars($sql_query) . '" />' . "\n";
1847 echo '<input type="hidden" name="pos" value="' . $pos . '" />' . "\n";
1848 echo '<input type="hidden" name="url_query"'
1849 .' value="' . $GLOBALS['url_query'] . '" />' . "\n";
1850 echo '</form>' . "\n";
1853 // 5. ----- Displays the navigation bar at the bottom if required -----
1855 if ($is_display['nav_bar'] == '1') {
1856 echo '<br />' . "\n";
1857 PMA_displayTableNavigation($pos_next, $pos_prev, $encoded_sql_query);
1858 } else if (!isset($GLOBALS['printview']) || $GLOBALS['printview'] != '1') {
1859 echo "\n" . '<br /><br />' . "\n";
1861 } // end of the 'PMA_displayTable()' function
1863 function default_function($buffer) {
1864 $buffer = htmlspecialchars($buffer);
1865 $buffer = str_replace("\011", ' &nbsp;&nbsp;&nbsp;',
1866 str_replace(' ', ' &nbsp;', $buffer));
1867 $buffer = preg_replace("@((\015\012)|(\015)|(\012))@", '<br />', $buffer);
1869 return $buffer;