PageRenderTime 97ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

/phpMyAdmin/libraries/display_tbl.lib.php

https://bitbucket.org/izubizarreta/https-bitbucket.org-bityvip
PHP | 3032 lines | 2005 code | 296 blank | 731 comment | 805 complexity | b1192d9b97f18248da9ad85cef982a2c MD5 | raw file
Possible License(s): LGPL-3.0, LGPL-2.0, JSON, GPL-2.0, BSD-3-Clause, LGPL-2.1, MIT
  1. <?php
  2. /* vim: set expandtab sw=4 ts=4 sts=4: */
  3. /**
  4. * library for displaying table with results from all sort of select queries
  5. *
  6. * @package PhpMyAdmin
  7. */
  8. /**
  9. *
  10. */
  11. require_once './libraries/Index.class.php';
  12. /**
  13. * Defines the display mode to use for the results of a SQL query
  14. *
  15. * It uses a synthetic string that contains all the required informations.
  16. * In this string:
  17. * - the first two characters stand for the action to do while
  18. * clicking on the "edit" link (e.g. 'ur' for update a row, 'nn' for no
  19. * edit link...);
  20. * - the next two characters stand for the action to do while
  21. * clicking on the "delete" link (e.g. 'kp' for kill a process, 'nn' for
  22. * no delete link...);
  23. * - the next characters are boolean values (1/0) and respectively stand
  24. * for sorting links, navigation bar, "insert a new row" link, the
  25. * bookmark feature, the expand/collapse text/blob fields button and
  26. * the "display printable view" option.
  27. * Of course '0'/'1' means the feature won't/will be enabled.
  28. *
  29. * @param string &$the_disp_mode the synthetic value for display_mode (see a few
  30. * lines above for explanations)
  31. * @param integer &$the_total the total number of rows returned by the SQL query
  32. * without any programmatically appended "LIMIT" clause
  33. * (just a copy of $unlim_num_rows if it exists, else
  34. * computed inside this function)
  35. *
  36. * @return array an array with explicit indexes for all the display
  37. * elements
  38. *
  39. * @global string the database name
  40. * @global string the table name
  41. * @global integer the total number of rows returned by the SQL query
  42. * without any programmatically appended "LIMIT" clause
  43. * @global array the properties of the fields returned by the query
  44. * @global string the URL to return to in case of error in a SQL
  45. * statement
  46. *
  47. * @access private
  48. *
  49. * @see PMA_displayTable()
  50. */
  51. function PMA_setDisplayMode(&$the_disp_mode, &$the_total)
  52. {
  53. global $db, $table;
  54. global $unlim_num_rows, $fields_meta;
  55. global $err_url;
  56. // 1. Initializes the $do_display array
  57. $do_display = array();
  58. $do_display['edit_lnk'] = $the_disp_mode[0] . $the_disp_mode[1];
  59. $do_display['del_lnk'] = $the_disp_mode[2] . $the_disp_mode[3];
  60. $do_display['sort_lnk'] = (string) $the_disp_mode[4];
  61. $do_display['nav_bar'] = (string) $the_disp_mode[5];
  62. $do_display['ins_row'] = (string) $the_disp_mode[6];
  63. $do_display['bkm_form'] = (string) $the_disp_mode[7];
  64. $do_display['text_btn'] = (string) $the_disp_mode[8];
  65. $do_display['pview_lnk'] = (string) $the_disp_mode[9];
  66. // 2. Display mode is not "false for all elements" -> updates the
  67. // display mode
  68. if ($the_disp_mode != 'nnnn000000') {
  69. if (isset($GLOBALS['printview']) && $GLOBALS['printview'] == '1') {
  70. // 2.0 Print view -> set all elements to false!
  71. $do_display['edit_lnk'] = 'nn'; // no edit link
  72. $do_display['del_lnk'] = 'nn'; // no delete link
  73. $do_display['sort_lnk'] = (string) '0';
  74. $do_display['nav_bar'] = (string) '0';
  75. $do_display['ins_row'] = (string) '0';
  76. $do_display['bkm_form'] = (string) '0';
  77. $do_display['text_btn'] = (string) '0';
  78. $do_display['pview_lnk'] = (string) '0';
  79. } elseif ($GLOBALS['is_count'] || $GLOBALS['is_analyse']
  80. || $GLOBALS['is_maint'] || $GLOBALS['is_explain']
  81. ) {
  82. // 2.1 Statement is a "SELECT COUNT", a
  83. // "CHECK/ANALYZE/REPAIR/OPTIMIZE", an "EXPLAIN" one or
  84. // contains a "PROC ANALYSE" part
  85. $do_display['edit_lnk'] = 'nn'; // no edit link
  86. $do_display['del_lnk'] = 'nn'; // no delete link
  87. $do_display['sort_lnk'] = (string) '0';
  88. $do_display['nav_bar'] = (string) '0';
  89. $do_display['ins_row'] = (string) '0';
  90. $do_display['bkm_form'] = (string) '1';
  91. if ($GLOBALS['is_maint']) {
  92. $do_display['text_btn'] = (string) '1';
  93. } else {
  94. $do_display['text_btn'] = (string) '0';
  95. }
  96. $do_display['pview_lnk'] = (string) '1';
  97. } elseif ($GLOBALS['is_show']) {
  98. // 2.2 Statement is a "SHOW..."
  99. /**
  100. * 2.2.1
  101. * @todo defines edit/delete links depending on show statement
  102. */
  103. $tmp = preg_match('@^SHOW[[:space:]]+(VARIABLES|(FULL[[:space:]]+)?PROCESSLIST|STATUS|TABLE|GRANTS|CREATE|LOGS|DATABASES|FIELDS)@i', $GLOBALS['sql_query'], $which);
  104. if (isset($which[1]) && strpos(' ' . strtoupper($which[1]), 'PROCESSLIST') > 0) {
  105. $do_display['edit_lnk'] = 'nn'; // no edit link
  106. $do_display['del_lnk'] = 'kp'; // "kill process" type edit link
  107. } else {
  108. // Default case -> no links
  109. $do_display['edit_lnk'] = 'nn'; // no edit link
  110. $do_display['del_lnk'] = 'nn'; // no delete link
  111. }
  112. // 2.2.2 Other settings
  113. $do_display['sort_lnk'] = (string) '0';
  114. $do_display['nav_bar'] = (string) '0';
  115. $do_display['ins_row'] = (string) '0';
  116. $do_display['bkm_form'] = (string) '1';
  117. $do_display['text_btn'] = (string) '1';
  118. $do_display['pview_lnk'] = (string) '1';
  119. } else {
  120. // 2.3 Other statements (ie "SELECT" ones) -> updates
  121. // $do_display['edit_lnk'], $do_display['del_lnk'] and
  122. // $do_display['text_btn'] (keeps other default values)
  123. $prev_table = $fields_meta[0]->table;
  124. $do_display['text_btn'] = (string) '1';
  125. for ($i = 0; $i < $GLOBALS['fields_cnt']; $i++) {
  126. $is_link = ($do_display['edit_lnk'] != 'nn'
  127. || $do_display['del_lnk'] != 'nn'
  128. || $do_display['sort_lnk'] != '0'
  129. || $do_display['ins_row'] != '0');
  130. // 2.3.2 Displays edit/delete/sort/insert links?
  131. if ($is_link
  132. && ($fields_meta[$i]->table == '' || $fields_meta[$i]->table != $prev_table)
  133. ) {
  134. $do_display['edit_lnk'] = 'nn'; // don't display links
  135. $do_display['del_lnk'] = 'nn';
  136. /**
  137. * @todo May be problematic with same fields names in two joined table.
  138. */
  139. // $do_display['sort_lnk'] = (string) '0';
  140. $do_display['ins_row'] = (string) '0';
  141. if ($do_display['text_btn'] == '1') {
  142. break;
  143. }
  144. } // end if (2.3.2)
  145. // 2.3.3 Always display print view link
  146. $do_display['pview_lnk'] = (string) '1';
  147. $prev_table = $fields_meta[$i]->table;
  148. } // end for
  149. } // end if..elseif...else (2.1 -> 2.3)
  150. } // end if (2)
  151. // 3. Gets the total number of rows if it is unknown
  152. if (isset($unlim_num_rows) && $unlim_num_rows != '') {
  153. $the_total = $unlim_num_rows;
  154. } elseif (($do_display['nav_bar'] == '1' || $do_display['sort_lnk'] == '1')
  155. && (strlen($db) && !empty($table))) {
  156. $the_total = PMA_Table::countRecords($db, $table);
  157. }
  158. // 4. If navigation bar or sorting fields names URLs should be
  159. // displayed but there is only one row, change these settings to
  160. // false
  161. if ($do_display['nav_bar'] == '1' || $do_display['sort_lnk'] == '1') {
  162. // - Do not display sort links if less than 2 rows.
  163. // - For a VIEW we (probably) did not count the number of rows
  164. // so don't test this number here, it would remove the possibility
  165. // of sorting VIEW results.
  166. if (isset($unlim_num_rows) && $unlim_num_rows < 2 && ! PMA_Table::isView($db, $table)) {
  167. // force display of navbar for vertical/horizontal display-choice.
  168. // $do_display['nav_bar'] = (string) '0';
  169. $do_display['sort_lnk'] = (string) '0';
  170. }
  171. } // end if (3)
  172. // 5. Updates the synthetic var
  173. $the_disp_mode = join('', $do_display);
  174. return $do_display;
  175. } // end of the 'PMA_setDisplayMode()' function
  176. /**
  177. * Return true if we are executing a query in the form of
  178. * "SELECT * FROM <a table> ..."
  179. *
  180. * @return boolean
  181. */
  182. function PMA_isSelect()
  183. {
  184. // global variables set from sql.php
  185. global $is_count, $is_export, $is_func, $is_analyse;
  186. global $analyzed_sql;
  187. return ! ($is_count || $is_export || $is_func || $is_analyse)
  188. && count($analyzed_sql[0]['select_expr']) == 0
  189. && isset($analyzed_sql[0]['queryflags']['select_from'])
  190. && count($analyzed_sql[0]['table_ref']) == 1;
  191. }
  192. /**
  193. * Displays a navigation button
  194. *
  195. * @param string $caption iconic caption for button
  196. * @param string $title text for button
  197. * @param integer $pos position for next query
  198. * @param string $html_sql_query query ready for display
  199. * @param string $onsubmit optional onsubmit clause
  200. * @param string $input_for_real_end optional hidden field for special treatment
  201. * @param string $onclick optional onclick clause
  202. *
  203. * @return nothing
  204. *
  205. * @global string $db the database name
  206. * @global string $table the table name
  207. * @global string $goto the URL to go back in case of errors
  208. *
  209. * @access private
  210. *
  211. * @see PMA_displayTableNavigation()
  212. */
  213. function PMA_displayTableNavigationOneButton($caption, $title, $pos, $html_sql_query, $onsubmit = '', $input_for_real_end = '', $onclick = '')
  214. {
  215. global $db, $table, $goto;
  216. $caption_output = '';
  217. // for true or 'both'
  218. if ($GLOBALS['cfg']['NavigationBarIconic']) {
  219. $caption_output .= $caption;
  220. }
  221. // for false or 'both'
  222. if (false === $GLOBALS['cfg']['NavigationBarIconic'] || 'both' === $GLOBALS['cfg']['NavigationBarIconic']) {
  223. $caption_output .= '&nbsp;' . $title;
  224. }
  225. $title_output = ' title="' . $title . '"';
  226. ?>
  227. <td>
  228. <form action="sql.php" method="post" <?php echo $onsubmit; ?>>
  229. <?php echo PMA_generate_common_hidden_inputs($db, $table); ?>
  230. <input type="hidden" name="sql_query" value="<?php echo $html_sql_query; ?>" />
  231. <input type="hidden" name="pos" value="<?php echo $pos; ?>" />
  232. <input type="hidden" name="goto" value="<?php echo $goto; ?>" />
  233. <?php echo $input_for_real_end; ?>
  234. <input type="submit" name="navig" <?php echo ($GLOBALS['cfg']['AjaxEnable'] ? ' class="ajax" ' : '' ); ?> value="<?php echo $caption_output; ?>"<?php echo $title_output . $onclick; ?> />
  235. </form>
  236. </td>
  237. <?php
  238. } // end function PMA_displayTableNavigationOneButton()
  239. /**
  240. * Displays a navigation bar to browse among the results of a SQL query
  241. *
  242. * @param integer $pos_next the offset for the "next" page
  243. * @param integer $pos_prev the offset for the "previous" page
  244. * @param string $sql_query the URL-encoded query
  245. * @param string $id_for_direction_dropdown the id for the direction dropdown
  246. *
  247. * @return nothing
  248. *
  249. * @global string $db the database name
  250. * @global string $table the table name
  251. * @global string $goto the URL to go back in case of errors
  252. * @global integer $num_rows the total number of rows returned by the
  253. * SQL query
  254. * @global integer $unlim_num_rows the total number of rows returned by the
  255. * SQL any programmatically appended "LIMIT" clause
  256. * @global boolean $is_innodb whether its InnoDB or not
  257. * @global array $showtable table definitions
  258. *
  259. * @access private
  260. *
  261. * @see PMA_displayTable()
  262. */
  263. function PMA_displayTableNavigation($pos_next, $pos_prev, $sql_query, $id_for_direction_dropdown)
  264. {
  265. global $db, $table, $goto;
  266. global $num_rows, $unlim_num_rows;
  267. global $is_innodb;
  268. global $showtable;
  269. // here, using htmlentities() would cause problems if the query
  270. // contains accented characters
  271. $html_sql_query = htmlspecialchars($sql_query);
  272. /**
  273. * @todo move this to a central place
  274. * @todo for other future table types
  275. */
  276. $is_innodb = (isset($showtable['Type']) && $showtable['Type'] == 'InnoDB');
  277. ?>
  278. <!-- Navigation bar -->
  279. <table border="0" cellpadding="0" cellspacing="0" class="navigation">
  280. <tr>
  281. <td class="navigation_separator"></td>
  282. <?php
  283. // Move to the beginning or to the previous page
  284. if ($_SESSION['tmp_user_values']['pos'] && $_SESSION['tmp_user_values']['max_rows'] != 'all') {
  285. PMA_displayTableNavigationOneButton('&lt;&lt;', _pgettext('First page', 'Begin'), 0, $html_sql_query);
  286. PMA_displayTableNavigationOneButton('&lt;', _pgettext('Previous page', 'Previous'), $pos_prev, $html_sql_query);
  287. } // end move back
  288. $nbTotalPage = 1;
  289. //page redirection
  290. // (unless we are showing all records)
  291. if ('all' != $_SESSION['tmp_user_values']['max_rows']) { //if1
  292. $pageNow = @floor($_SESSION['tmp_user_values']['pos'] / $_SESSION['tmp_user_values']['max_rows']) + 1;
  293. $nbTotalPage = @ceil($unlim_num_rows / $_SESSION['tmp_user_values']['max_rows']);
  294. if ($nbTotalPage > 1) { //if2
  295. ?>
  296. <td>
  297. <?php
  298. $_url_params = array(
  299. 'db' => $db,
  300. 'table' => $table,
  301. 'sql_query' => $sql_query,
  302. 'goto' => $goto,
  303. );
  304. //<form> to keep the form alignment of button < and <<
  305. // and also to know what to execute when the selector changes
  306. echo '<form action="sql.php' . PMA_generate_common_url($_url_params). '" method="post">';
  307. echo PMA_pageselector(
  308. $_SESSION['tmp_user_values']['max_rows'],
  309. $pageNow,
  310. $nbTotalPage,
  311. 200,
  312. 5,
  313. 5,
  314. 20,
  315. 10
  316. );
  317. ?>
  318. </form>
  319. </td>
  320. <?php
  321. } //_if2
  322. } //_if1
  323. // Display the "Show all" button if allowed
  324. if (($num_rows < $unlim_num_rows) && ($GLOBALS['cfg']['ShowAll'] || ($GLOBALS['cfg']['MaxRows'] * 5 >= $unlim_num_rows))) {
  325. echo "\n";
  326. ?>
  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="0" />
  332. <input type="hidden" name="session_max_rows" value="all" />
  333. <input type="hidden" name="goto" value="<?php echo $goto; ?>" />
  334. <input type="submit" name="navig" value="<?php echo __('Show all'); ?>" />
  335. </form>
  336. </td>
  337. <?php
  338. } // end show all
  339. // Move to the next page or to the last one
  340. if (($_SESSION['tmp_user_values']['pos'] + $_SESSION['tmp_user_values']['max_rows'] < $unlim_num_rows)
  341. && $num_rows >= $_SESSION['tmp_user_values']['max_rows']
  342. && $_SESSION['tmp_user_values']['max_rows'] != 'all'
  343. ) {
  344. // display the Next button
  345. PMA_displayTableNavigationOneButton(
  346. '&gt;',
  347. _pgettext('Next page', 'Next'),
  348. $pos_next,
  349. $html_sql_query
  350. );
  351. // prepare some options for the End button
  352. if ($is_innodb && $unlim_num_rows > $GLOBALS['cfg']['MaxExactCount']) {
  353. $input_for_real_end = '<input id="real_end_input" type="hidden" name="find_real_end" value="1" />';
  354. // no backquote around this message
  355. $onclick = '';
  356. } else {
  357. $input_for_real_end = $onclick = '';
  358. }
  359. // display the End button
  360. PMA_displayTableNavigationOneButton(
  361. '&gt;&gt;',
  362. _pgettext('Last page', 'End'),
  363. @((ceil($unlim_num_rows / $_SESSION['tmp_user_values']['max_rows'])- 1) * $_SESSION['tmp_user_values']['max_rows']),
  364. $html_sql_query,
  365. 'onsubmit="return ' . (($_SESSION['tmp_user_values']['pos'] + $_SESSION['tmp_user_values']['max_rows'] < $unlim_num_rows && $num_rows >= $_SESSION['tmp_user_values']['max_rows']) ? 'true' : 'false') . '"',
  366. $input_for_real_end,
  367. $onclick
  368. );
  369. } // end move toward
  370. // show separator if pagination happen
  371. if ($nbTotalPage > 1) {
  372. echo '<td><div class="navigation_separator">|</div></td>';
  373. }
  374. ?>
  375. <td>
  376. <div class="save_edited hide">
  377. <input type="submit" value="<?php echo __('Save edited data'); ?>" />
  378. <div class="navigation_separator">|</div>
  379. </div>
  380. </td>
  381. <td>
  382. <div class="restore_column hide">
  383. <input type="submit" value="<?php echo __('Restore column order'); ?>" />
  384. <div class="navigation_separator">|</div>
  385. </div>
  386. </td>
  387. <?php // if displaying a VIEW, $unlim_num_rows could be zero because
  388. // of $cfg['MaxExactCountViews']; in this case, avoid passing
  389. // the 5th parameter to checkFormElementInRange()
  390. // (this means we can't validate the upper limit ?>
  391. <td class="navigation_goto">
  392. <form action="sql.php" method="post"
  393. onsubmit="return (checkFormElementInRange(this, 'session_max_rows', '<?php echo str_replace('\'', '\\\'', __('%d is not valid row number.')); ?>', 1) &amp;&amp; checkFormElementInRange(this, 'pos', '<?php echo str_replace('\'', '\\\'', __('%d is not valid row number.')); ?>', 0<?php echo $unlim_num_rows > 0 ? ',' . $unlim_num_rows - 1 : ''; ?>))">
  394. <?php echo PMA_generate_common_hidden_inputs($db, $table); ?>
  395. <input type="hidden" name="sql_query" value="<?php echo $html_sql_query; ?>" />
  396. <input type="hidden" name="goto" value="<?php echo $goto; ?>" />
  397. <input type="submit" name="navig" <?php echo ($GLOBALS['cfg']['AjaxEnable'] ? ' class="ajax"' : ''); ?> value="<?php echo __('Show'); ?> :" />
  398. <?php echo __('Start row') . ': ' . "\n"; ?>
  399. <input type="text" name="pos" size="3" value="<?php echo (($pos_next >= $unlim_num_rows) ? 0 : $pos_next); ?>" class="textfield" onfocus="this.select()" />
  400. <?php echo __('Number of rows') . ': ' . "\n"; ?>
  401. <input type="text" name="session_max_rows" size="3" value="<?php echo (($_SESSION['tmp_user_values']['max_rows'] != 'all') ? $_SESSION['tmp_user_values']['max_rows'] : $GLOBALS['cfg']['MaxRows']); ?>" class="textfield" onfocus="this.select()" />
  402. <?php
  403. if ($GLOBALS['cfg']['ShowDisplayDirection']) {
  404. // Display mode (horizontal/vertical and repeat headers)
  405. echo __('Mode') . ': ' . "\n";
  406. $choices = array(
  407. 'horizontal' => __('horizontal'),
  408. 'horizontalflipped' => __('horizontal (rotated headers)'),
  409. 'vertical' => __('vertical'));
  410. echo PMA_generate_html_dropdown('disp_direction', $choices, $_SESSION['tmp_user_values']['disp_direction'], $id_for_direction_dropdown);
  411. unset($choices);
  412. }
  413. printf(
  414. __('Headers every %s rows'),
  415. '<input type="text" size="3" name="repeat_cells" value="' . $_SESSION['tmp_user_values']['repeat_cells'] . '" class="textfield" />'
  416. );
  417. echo "\n";
  418. ?>
  419. </form>
  420. </td>
  421. <td class="navigation_separator"></td>
  422. </tr>
  423. </table>
  424. <?php
  425. } // end of the 'PMA_displayTableNavigation()' function
  426. /**
  427. * Displays the headers of the results table
  428. *
  429. * @param array &$is_display which elements to display
  430. * @param array &$fields_meta the list of fields properties
  431. * @param integer $fields_cnt the total number of fields returned by the SQL query
  432. * @param array $analyzed_sql the analyzed query
  433. * @param string $sort_expression sort expression
  434. * @param string $sort_expression_nodirection sort expression without direction
  435. * @param string $sort_direction sort direction
  436. *
  437. * @return boolean $clause_is_unique
  438. *
  439. * @global string $db the database name
  440. * @global string $table the table name
  441. * @global string $goto the URL to go back in case of errors
  442. * @global string $sql_query the SQL query
  443. * @global integer $num_rows the total number of rows returned by the
  444. * SQL query
  445. * @global array $vertical_display informations used with vertical display
  446. * mode
  447. *
  448. * @access private
  449. *
  450. * @see PMA_displayTable()
  451. */
  452. function PMA_displayTableHeaders(&$is_display, &$fields_meta, $fields_cnt = 0, $analyzed_sql = '', $sort_expression, $sort_expression_nodirection, $sort_direction)
  453. {
  454. global $db, $table, $goto;
  455. global $sql_query, $num_rows;
  456. global $vertical_display, $highlight_columns;
  457. // required to generate sort links that will remember whether the
  458. // "Show all" button has been clicked
  459. $sql_md5 = md5($GLOBALS['sql_query']);
  460. $session_max_rows = $_SESSION['tmp_user_values']['query'][$sql_md5]['max_rows'];
  461. if ($analyzed_sql == '') {
  462. $analyzed_sql = array();
  463. }
  464. // can the result be sorted?
  465. if ($is_display['sort_lnk'] == '1') {
  466. // Just as fallback
  467. $unsorted_sql_query = $sql_query;
  468. if (isset($analyzed_sql[0]['unsorted_query'])) {
  469. $unsorted_sql_query = $analyzed_sql[0]['unsorted_query'];
  470. }
  471. // Handles the case of multiple clicks on a column's header
  472. // which would add many spaces before "ORDER BY" in the
  473. // generated query.
  474. $unsorted_sql_query = trim($unsorted_sql_query);
  475. // sorting by indexes, only if it makes sense (only one table ref)
  476. if (isset($analyzed_sql)
  477. && isset($analyzed_sql[0])
  478. && isset($analyzed_sql[0]['querytype'])
  479. && $analyzed_sql[0]['querytype'] == 'SELECT'
  480. && isset($analyzed_sql[0]['table_ref'])
  481. && count($analyzed_sql[0]['table_ref']) == 1
  482. ) {
  483. // grab indexes data:
  484. $indexes = PMA_Index::getFromTable($table, $db);
  485. // do we have any index?
  486. if ($indexes) {
  487. if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
  488. || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped'
  489. ) {
  490. $span = $fields_cnt;
  491. if ($is_display['edit_lnk'] != 'nn') {
  492. $span++;
  493. }
  494. if ($is_display['del_lnk'] != 'nn') {
  495. $span++;
  496. }
  497. if ($is_display['del_lnk'] != 'kp' && $is_display['del_lnk'] != 'nn') {
  498. $span++;
  499. }
  500. } else {
  501. $span = $num_rows + floor($num_rows/$_SESSION['tmp_user_values']['repeat_cells']) + 1;
  502. }
  503. echo '<form action="sql.php" method="post">' . "\n";
  504. echo PMA_generate_common_hidden_inputs($db, $table);
  505. echo __('Sort by key') . ': <select name="sql_query" class="autosubmit">' . "\n";
  506. $used_index = false;
  507. $local_order = (isset($sort_expression) ? $sort_expression : '');
  508. foreach ($indexes as $index) {
  509. $asc_sort = '`' . implode('` ASC, `', array_keys($index->getColumns())) . '` ASC';
  510. $desc_sort = '`' . implode('` DESC, `', array_keys($index->getColumns())) . '` DESC';
  511. $used_index = $used_index || $local_order == $asc_sort || $local_order == $desc_sort;
  512. if (preg_match('@(.*)([[:space:]](LIMIT (.*)|PROCEDURE (.*)|FOR UPDATE|LOCK IN SHARE MODE))@is', $unsorted_sql_query, $my_reg)) {
  513. $unsorted_sql_query_first_part = $my_reg[1];
  514. $unsorted_sql_query_second_part = $my_reg[2];
  515. } else {
  516. $unsorted_sql_query_first_part = $unsorted_sql_query;
  517. $unsorted_sql_query_second_part = '';
  518. }
  519. echo '<option value="'
  520. . htmlspecialchars($unsorted_sql_query_first_part . "\n" . ' ORDER BY ' . $asc_sort . $unsorted_sql_query_second_part)
  521. . '"' . ($local_order == $asc_sort ? ' selected="selected"' : '')
  522. . '>' . htmlspecialchars($index->getName()) . ' ('
  523. . __('Ascending') . ')</option>';
  524. echo '<option value="'
  525. . htmlspecialchars($unsorted_sql_query_first_part . "\n" . ' ORDER BY ' . $desc_sort . $unsorted_sql_query_second_part)
  526. . '"' . ($local_order == $desc_sort ? ' selected="selected"' : '')
  527. . '>' . htmlspecialchars($index->getName()) . ' ('
  528. . __('Descending') . ')</option>';
  529. }
  530. echo '<option value="' . htmlspecialchars($unsorted_sql_query) . '"' . ($used_index ? '' : ' selected="selected"') . '>' . __('None') . '</option>';
  531. echo '</select>' . "\n";
  532. echo '<noscript><input type="submit" value="' . __('Go') . '" /></noscript>';
  533. echo '</form>' . "\n";
  534. }
  535. }
  536. }
  537. // Output data needed for grid editing
  538. echo '<input id="save_cells_at_once" type="hidden" value="' . $GLOBALS['cfg']['SaveCellsAtOnce'] . '" />';
  539. echo '<div class="common_hidden_inputs">';
  540. echo PMA_generate_common_hidden_inputs($db, $table);
  541. echo '</div>';
  542. // Output data needed for column reordering and show/hide column
  543. if (PMA_isSelect()) {
  544. // generate the column order, if it is set
  545. $pmatable = new PMA_Table($GLOBALS['table'], $GLOBALS['db']);
  546. $col_order = $pmatable->getUiProp(PMA_Table::PROP_COLUMN_ORDER);
  547. if ($col_order) {
  548. echo '<input id="col_order" type="hidden" value="' . implode(',', $col_order) . '" />';
  549. }
  550. $col_visib = $pmatable->getUiProp(PMA_Table::PROP_COLUMN_VISIB);
  551. if ($col_visib) {
  552. echo '<input id="col_visib" type="hidden" value="' . implode(',', $col_visib) . '" />';
  553. }
  554. // generate table create time
  555. if (! PMA_Table::isView($GLOBALS['table'], $GLOBALS['db'])) {
  556. echo '<input id="table_create_time" type="hidden" value="' .
  557. PMA_Table::sGetStatusInfo($GLOBALS['db'], $GLOBALS['table'], 'Create_time') . '" />';
  558. }
  559. }
  560. $vertical_display['emptypre'] = 0;
  561. $vertical_display['emptyafter'] = 0;
  562. $vertical_display['textbtn'] = '';
  563. // Display options (if we are not in print view)
  564. if (! (isset($GLOBALS['printview']) && $GLOBALS['printview'] == '1')) {
  565. echo '<form method="post" action="sql.php" name="displayOptionsForm" id="displayOptionsForm"';
  566. if ($GLOBALS['cfg']['AjaxEnable']) {
  567. echo ' class="ajax" ';
  568. }
  569. echo '>';
  570. $url_params = array(
  571. 'db' => $db,
  572. 'table' => $table,
  573. 'sql_query' => $sql_query,
  574. 'goto' => $goto,
  575. 'display_options_form' => 1
  576. );
  577. echo PMA_generate_common_hidden_inputs($url_params);
  578. echo '<br />';
  579. PMA_generate_slider_effect('displayoptions', __('Options'));
  580. echo '<fieldset>';
  581. echo '<div class="formelement">';
  582. $choices = array(
  583. 'P' => __('Partial texts'),
  584. 'F' => __('Full texts')
  585. );
  586. PMA_display_html_radio('display_text', $choices, $_SESSION['tmp_user_values']['display_text']);
  587. echo '</div>';
  588. // prepare full/partial text button or link
  589. $url_params_full_text = array(
  590. 'db' => $db,
  591. 'table' => $table,
  592. 'sql_query' => $sql_query,
  593. 'goto' => $goto,
  594. 'full_text_button' => 1
  595. );
  596. if ($_SESSION['tmp_user_values']['display_text']=='F') {
  597. // currently in fulltext mode so show the opposite link
  598. $tmp_image_file = $GLOBALS['pmaThemeImage'] . 's_partialtext.png';
  599. $tmp_txt = __('Partial texts');
  600. $url_params_full_text['display_text'] = 'P';
  601. } else {
  602. $tmp_image_file = $GLOBALS['pmaThemeImage'] . 's_fulltext.png';
  603. $tmp_txt = __('Full texts');
  604. $url_params_full_text['display_text'] = 'F';
  605. }
  606. $tmp_image = '<img class="fulltext" src="' . $tmp_image_file . '" alt="' . $tmp_txt . '" title="' . $tmp_txt . '" />';
  607. $tmp_url = 'sql.php' . PMA_generate_common_url($url_params_full_text);
  608. $full_or_partial_text_link = PMA_linkOrButton($tmp_url, $tmp_image, array(), false);
  609. unset($tmp_image_file, $tmp_txt, $tmp_url, $tmp_image);
  610. if ($GLOBALS['cfgRelation']['relwork'] && $GLOBALS['cfgRelation']['displaywork']) {
  611. echo '<div class="formelement">';
  612. $choices = array(
  613. 'K' => __('Relational key'),
  614. 'D' => __('Relational display column')
  615. );
  616. PMA_display_html_radio('relational_display', $choices, $_SESSION['tmp_user_values']['relational_display']);
  617. echo '</div>';
  618. }
  619. echo '<div class="formelement">';
  620. PMA_display_html_checkbox('display_binary', __('Show binary contents'), ! empty($_SESSION['tmp_user_values']['display_binary']), false);
  621. echo '<br />';
  622. PMA_display_html_checkbox('display_blob', __('Show BLOB contents'), ! empty($_SESSION['tmp_user_values']['display_blob']), false);
  623. echo '<br />';
  624. PMA_display_html_checkbox('display_binary_as_hex', __('Show binary contents as HEX'), ! empty($_SESSION['tmp_user_values']['display_binary_as_hex']), false);
  625. echo '</div>';
  626. // I would have preferred to name this "display_transformation".
  627. // This is the only way I found to be able to keep this setting sticky
  628. // per SQL query, and at the same time have a default that displays
  629. // the transformations.
  630. echo '<div class="formelement">';
  631. PMA_display_html_checkbox('hide_transformation', __('Hide browser transformation'), ! empty($_SESSION['tmp_user_values']['hide_transformation']), false);
  632. echo '</div>';
  633. if (! PMA_DRIZZLE) {
  634. echo '<div class="formelement">';
  635. $choices = array(
  636. 'GEOM' => __('Geometry'),
  637. 'WKT' => __('Well Known Text'),
  638. 'WKB' => __('Well Known Binary')
  639. );
  640. PMA_display_html_radio('geometry_display', $choices, $_SESSION['tmp_user_values']['geometry_display']);
  641. echo '</div>';
  642. }
  643. echo '<div class="clearfloat"></div>';
  644. echo '</fieldset>';
  645. echo '<fieldset class="tblFooters">';
  646. echo '<input type="submit" value="' . __('Go') . '" />';
  647. echo '</fieldset>';
  648. echo '</div>';
  649. echo '</form>';
  650. }
  651. // Start of form for multi-rows edit/delete/export
  652. if ($is_display['del_lnk'] == 'dr' || $is_display['del_lnk'] == 'kp') {
  653. echo '<form method="post" action="tbl_row_action.php" name="resultsForm" id="resultsForm"';
  654. if ($GLOBALS['cfg']['AjaxEnable']) {
  655. echo ' class="ajax" ';
  656. }
  657. echo '>' . "\n";
  658. echo PMA_generate_common_hidden_inputs($db, $table, 1);
  659. echo '<input type="hidden" name="goto" value="sql.php" />' . "\n";
  660. }
  661. echo '<table id="table_results" class="data';
  662. if ($GLOBALS['cfg']['AjaxEnable']) {
  663. echo ' ajax';
  664. }
  665. echo '">' . "\n";
  666. if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
  667. || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped'
  668. ) {
  669. echo '<thead><tr>' . "\n";
  670. }
  671. // 1. Displays the full/partial text button (part 1)...
  672. if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
  673. || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped'
  674. ) {
  675. $colspan = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn')
  676. ? ' colspan="4"'
  677. : '';
  678. } else {
  679. $rowspan = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn')
  680. ? ' rowspan="4"'
  681. : '';
  682. }
  683. // ... before the result table
  684. if (($is_display['edit_lnk'] == 'nn' && $is_display['del_lnk'] == 'nn')
  685. && $is_display['text_btn'] == '1'
  686. ) {
  687. $vertical_display['emptypre'] = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn') ? 4 : 0;
  688. if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
  689. || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped'
  690. ) {
  691. ?>
  692. <th colspan="<?php echo $fields_cnt; ?>"></th>
  693. </tr>
  694. <tr>
  695. <?php
  696. // end horizontal/horizontalflipped mode
  697. } else {
  698. ?>
  699. <tr>
  700. <th colspan="<?php echo $num_rows + floor($num_rows/$_SESSION['tmp_user_values']['repeat_cells']) + 1; ?>"></th>
  701. </tr>
  702. <?php
  703. } // end vertical mode
  704. }
  705. // ... at the left column of the result table header if possible
  706. // and required
  707. elseif (($GLOBALS['cfg']['RowActionLinks'] == 'left' || $GLOBALS['cfg']['RowActionLinks'] == 'both')
  708. && $is_display['text_btn'] == '1'
  709. ) {
  710. $vertical_display['emptypre'] = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn') ? 4 : 0;
  711. if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
  712. || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped'
  713. ) {
  714. ?>
  715. <th <?php echo $colspan; ?>><?php echo $full_or_partial_text_link;?></th>
  716. <?php
  717. // end horizontal/horizontalflipped mode
  718. } else {
  719. $vertical_display['textbtn'] = ' <th ' . $rowspan . ' valign="middle">' . "\n"
  720. . ' ' . "\n"
  721. . ' </th>' . "\n";
  722. } // end vertical mode
  723. }
  724. // ... elseif no button, displays empty(ies) col(s) if required
  725. elseif (($GLOBALS['cfg']['RowActionLinks'] == 'left' || $GLOBALS['cfg']['RowActionLinks'] == 'both')
  726. && ($is_display['edit_lnk'] != 'nn' || $is_display['del_lnk'] != 'nn')) {
  727. $vertical_display['emptypre'] = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn') ? 4 : 0;
  728. if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
  729. || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped'
  730. ) {
  731. ?>
  732. <td<?php echo $colspan; ?>></td>
  733. <?php
  734. // end horizontal/horizontalfipped mode
  735. } else {
  736. $vertical_display['textbtn'] = ' <td' . $rowspan . '></td>' . "\n";
  737. } // end vertical mode
  738. }
  739. // ... elseif display an empty column if the actions links are disabled to match the rest of the table
  740. elseif ($GLOBALS['cfg']['RowActionLinks'] == 'none'
  741. && ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal' || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped')
  742. ) {
  743. echo '<th></th>';
  744. }
  745. // 2. Displays the fields' name
  746. // 2.0 If sorting links should be used, checks if the query is a "JOIN"
  747. // statement (see 2.1.3)
  748. // 2.0.1 Prepare Display column comments if enabled ($GLOBALS['cfg']['ShowBrowseComments']).
  749. // Do not show comments, if using horizontalflipped mode, because of space usage
  750. if ($GLOBALS['cfg']['ShowBrowseComments']
  751. && $_SESSION['tmp_user_values']['disp_direction'] != 'horizontalflipped'
  752. ) {
  753. $comments_map = array();
  754. if (isset($analyzed_sql[0]) && is_array($analyzed_sql[0])) {
  755. foreach ($analyzed_sql[0]['table_ref'] as $tbl) {
  756. $tb = $tbl['table_true_name'];
  757. $comments_map[$tb] = PMA_getComments($db, $tb);
  758. unset($tb);
  759. }
  760. }
  761. }
  762. if ($GLOBALS['cfgRelation']['commwork'] && $GLOBALS['cfgRelation']['mimework'] && $GLOBALS['cfg']['BrowseMIME'] && ! $_SESSION['tmp_user_values']['hide_transformation']) {
  763. include_once './libraries/transformations.lib.php';
  764. $GLOBALS['mime_map'] = PMA_getMIME($db, $table);
  765. }
  766. // See if we have to highlight any header fields of a WHERE query.
  767. // Uses SQL-Parser results.
  768. $highlight_columns = array();
  769. if (isset($analyzed_sql) && isset($analyzed_sql[0])
  770. && isset($analyzed_sql[0]['where_clause_identifiers'])
  771. ) {
  772. $wi = 0;
  773. if (isset($analyzed_sql[0]['where_clause_identifiers']) && is_array($analyzed_sql[0]['where_clause_identifiers'])) {
  774. foreach ($analyzed_sql[0]['where_clause_identifiers'] AS $wci_nr => $wci) {
  775. $highlight_columns[$wci] = 'true';
  776. }
  777. }
  778. }
  779. if (PMA_isSelect()) {
  780. // prepare to get the column order, if available
  781. $pmatable = new PMA_Table($GLOBALS['table'], $GLOBALS['db']);
  782. $col_order = $pmatable->getUiProp(PMA_Table::PROP_COLUMN_ORDER);
  783. $col_visib = $pmatable->getUiProp(PMA_Table::PROP_COLUMN_VISIB);
  784. } else {
  785. $col_order = false;
  786. $col_visib = false;
  787. }
  788. for ($j = 0; $j < $fields_cnt; $j++) {
  789. // assign $i with appropriate column order
  790. $i = $col_order ? $col_order[$j] : $j;
  791. // See if this column should get highlight because it's used in the
  792. // where-query.
  793. if (isset($highlight_columns[$fields_meta[$i]->name]) || isset($highlight_columns[PMA_backquote($fields_meta[$i]->name)])) {
  794. $condition_field = true;
  795. } else {
  796. $condition_field = false;
  797. }
  798. // 2.0 Prepare comment-HTML-wrappers for each row, if defined/enabled.
  799. if (isset($comments_map)
  800. && isset($comments_map[$fields_meta[$i]->table])
  801. && isset($comments_map[$fields_meta[$i]->table][$fields_meta[$i]->name])
  802. ) {
  803. $comments = '<span class="tblcomment">' . htmlspecialchars($comments_map[$fields_meta[$i]->table][$fields_meta[$i]->name]) . '</span>';
  804. } else {
  805. $comments = '';
  806. }
  807. // 2.1 Results can be sorted
  808. if ($is_display['sort_lnk'] == '1') {
  809. // 2.1.1 Checks if the table name is required; it's the case
  810. // for a query with a "JOIN" statement and if the column
  811. // isn't aliased, or in queries like
  812. // SELECT `1`.`master_field` , `2`.`master_field`
  813. // FROM `PMA_relation` AS `1` , `PMA_relation` AS `2`
  814. if (isset($fields_meta[$i]->table) && strlen($fields_meta[$i]->table)) {
  815. $sort_tbl = PMA_backquote($fields_meta[$i]->table) . '.';
  816. } else {
  817. $sort_tbl = '';
  818. }
  819. // 2.1.2 Checks if the current column is used to sort the
  820. // results
  821. // the orgname member does not exist for all MySQL versions
  822. // but if found, it's the one on which to sort
  823. $name_to_use_in_sort = $fields_meta[$i]->name;
  824. $is_orgname = false;
  825. if (isset($fields_meta[$i]->orgname) && strlen($fields_meta[$i]->orgname)) {
  826. $name_to_use_in_sort = $fields_meta[$i]->orgname;
  827. $is_orgname = true;
  828. }
  829. // $name_to_use_in_sort might contain a space due to
  830. // formatting of function expressions like "COUNT(name )"
  831. // so we remove the space in this situation
  832. $name_to_use_in_sort = str_replace(' )', ')', $name_to_use_in_sort);
  833. if (empty($sort_expression)) {
  834. $is_in_sort = false;
  835. } else {
  836. // Field name may be preceded by a space, or any number
  837. // of characters followed by a dot (tablename.fieldname)
  838. // so do a direct comparison for the sort expression;
  839. // this avoids problems with queries like
  840. // "SELECT id, count(id)..." and clicking to sort
  841. // on id or on count(id).
  842. // Another query to test this:
  843. // SELECT p.*, FROM_UNIXTIME(p.temps) FROM mytable AS p
  844. // (and try clicking on each column's header twice)
  845. if (! empty($sort_tbl)
  846. && strpos($sort_expression_nodirection, $sort_tbl) === false
  847. && strpos($sort_expression_nodirection, '(') === false
  848. ) {
  849. $sort_expression_nodirection = $sort_tbl . $sort_expression_nodirection;
  850. }
  851. $is_in_sort = (str_replace('`', '', $sort_tbl) . $name_to_use_in_sort == str_replace('`', '', $sort_expression_nodirection) ? true : false);
  852. }
  853. // 2.1.3 Check the field name for a bracket.
  854. // If it contains one, it's probably a function column
  855. // like 'COUNT(`field`)'
  856. // It still might be a column name of a view. See bug #3383711
  857. // Check is_orgname.
  858. if (strpos($name_to_use_in_sort, '(') !== false && ! $is_orgname) {
  859. $sort_order = "\n" . 'ORDER BY ' . $name_to_use_in_sort . ' ';
  860. } else {
  861. $sort_order = "\n" . 'ORDER BY ' . $sort_tbl . PMA_backquote($name_to_use_in_sort) . ' ';
  862. }
  863. unset($name_to_use_in_sort);
  864. unset($is_orgname);
  865. // 2.1.4 Do define the sorting URL
  866. if (! $is_in_sort) {
  867. // patch #455484 ("Smart" order)
  868. $GLOBALS['cfg']['Order'] = strtoupper($GLOBALS['cfg']['Order']);
  869. if ($GLOBALS['cfg']['Order'] === 'SMART') {
  870. $sort_order .= (preg_match('@time|date@i', $fields_meta[$i]->type)) ? 'DESC' : 'ASC';
  871. } else {
  872. $sort_order .= $GLOBALS['cfg']['Order'];
  873. }
  874. $order_img = '';
  875. } elseif ('DESC' == $sort_direction) {
  876. $sort_order .= ' ASC';
  877. $order_img = ' ' . PMA_getImage('s_desc.png', __('Descending'), array('class' => "soimg$i", 'title' => ''));
  878. $order_img .= ' ' . PMA_getImage('s_asc.png', __('Ascending'), array('class' => "soimg$i hide", 'title' => ''));
  879. } else {
  880. $sort_order .= ' DESC';
  881. $order_img = ' ' . PMA_getImage('s_asc.png', __('Ascending'), array('class' => "soimg$i", 'title' => ''));
  882. $order_img .= ' ' . PMA_getImage('s_desc.png', __('Descending'), array('class' => "soimg$i hide", 'title' => ''));
  883. }
  884. if (preg_match('@(.*)([[:space:]](LIMIT (.*)|PROCEDURE (.*)|FOR UPDATE|LOCK IN SHARE MODE))@is', $unsorted_sql_query, $regs3)) {
  885. $sorted_sql_query = $regs3[1] . $sort_order . $regs3[2];
  886. } else {
  887. $sorted_sql_query = $unsorted_sql_query . $sort_order;
  888. }
  889. $_url_params = array(
  890. 'db' => $db,
  891. 'table' => $table,
  892. 'sql_query' => $sorted_sql_query,
  893. 'session_max_rows' => $session_max_rows
  894. );
  895. $order_url = 'sql.php' . PMA_generate_common_url($_url_params);
  896. // 2.1.5 Displays the sorting URL
  897. // enable sort order swapping for image
  898. $order_link_params = array();
  899. if (isset($order_img) && $order_img!='') {
  900. if (strstr($order_img, 'asc')) {
  901. $order_link_params['onmouseover'] = "$('.soimg$i').toggle()";
  902. $order_link_params['onmouseout'] = "$('.soimg$i').toggle()";
  903. } elseif (strstr($order_img, 'desc')) {
  904. $order_link_params['onmouseover'] = "$('.soimg$i').toggle()";
  905. $order_link_params['onmouseout'] = "$('.soimg$i').toggle()";
  906. }
  907. }
  908. if ($GLOBALS['cfg']['HeaderFlipType'] == 'auto') {
  909. if (PMA_USR_BROWSER_AGENT == 'IE') {
  910. $GLOBALS['cfg']['HeaderFlipType'] = 'css';
  911. } else {
  912. $GLOBALS['cfg']['HeaderFlipType'] = 'fake';
  913. }
  914. }
  915. if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped'
  916. && $GLOBALS['cfg']['HeaderFlipType'] == 'css'
  917. ) {
  918. $order_link_params['style'] = 'direction: ltr; writing-mode: tb-rl;';
  919. }
  920. $order_link_params['title'] = __('Sort');
  921. $order_link_content = ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped' && $GLOBALS['cfg']['HeaderFlipType'] == 'fake' ? PMA_flipstring(htmlspecialchars($fields_meta[$i]->name), "<br />\n") : htmlspecialchars($fields_meta[$i]->name));
  922. $order_link = PMA_linkOrButton($order_url, $order_link_content . $order_img, $order_link_params, false, true);
  923. if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
  924. || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped'
  925. ) {
  926. echo '<th';
  927. $th_class = array();
  928. $th_class[] = 'draggable';
  929. if ($col_visib && !$col_visib[$j]) {
  930. $th_class[] = 'hide';
  931. }
  932. if ($condition_field) {
  933. $th_class[] = 'condition';
  934. }
  935. $th_class[] = 'column_heading';
  936. if ($GLOBALS['cfg']['BrowsePointerEnable'] == true) {
  937. $th_class[] = 'pointer';
  938. }
  939. if ($GLOBALS['cfg']['BrowseMarkerEnable'] == true) {
  940. $th_class[] = 'marker';
  941. }
  942. echo ' class="' . implode(' ', $th_class) . '"';
  943. if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') {
  944. echo ' valign="bottom"';
  945. }
  946. echo '>' . $order_link . $comments . '</th>';
  947. }
  948. $vertical_display['desc'][] = ' <th '
  949. . 'class="draggable'
  950. . ($condition_field ? ' condition' : '')
  951. . '">' . "\n"
  952. . $order_link . $comments . ' </th>' . "\n";
  953. } // end if (2.1)
  954. // 2.2 Results can't be sorted
  955. else {
  956. if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
  957. || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped'
  958. ) {
  959. echo '<th';
  960. $th_class = array();
  961. $th_class[] = 'draggable';
  962. if ($col_visib && !$col_visib[$j]) {
  963. $th_class[] = 'hide';
  964. }
  965. if ($condition_field) {
  966. $th_class[] = 'condition';
  967. }
  968. echo ' class="' . implode(' ', $th_class) . '"';
  969. if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') {
  970. echo ' valign="bottom"';
  971. }
  972. if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped'
  973. && $GLOBALS['cfg']['HeaderFlipType'] == 'css'
  974. ) {
  975. echo ' style="direction: ltr; writing-mode: tb-rl;"';
  976. }
  977. echo '>';
  978. if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped'
  979. && $GLOBALS['cfg']['HeaderFlipType'] == 'fake'
  980. ) {
  981. echo PMA_flipstring(htmlspecialchars($fields_meta[$i]->name), '<br />');
  982. } else {
  983. echo htmlspecialchars($fields_meta[$i]->name);
  984. }
  985. echo "\n" . $comments . '</th>';
  986. }
  987. $vertical_display['desc'][] = ' <th '
  988. . 'class="draggable'
  989. . ($condition_field ? ' condition"' : '')
  990. . '">' . "\n"
  991. . ' ' . htmlspecialchars($fields_meta[$i]->name) . "\n"
  992. . $comments . ' </th>';
  993. } // end else (2.2)
  994. } // end for
  995. // 3. Displays the needed checkboxes at the right
  996. // column of the result table header if possible and required...
  997. if (($GLOBALS['cfg']['RowActionLinks'] == 'right' || $GLOBALS['cfg']['RowActionLinks'] == 'both')
  998. && ($is_display['edit_lnk'] != 'nn' || $is_display['del_lnk'] != 'nn')
  999. && $is_display['text_btn'] == '1'
  1000. ) {
  1001. $vertical_display['emptyafter'] = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn') ? 4 : 1;
  1002. if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
  1003. || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped'
  1004. ) {
  1005. echo "\n";
  1006. ?>
  1007. <th <?php echo $colspan; ?>><?php echo $full_or_partial_text_link;?>
  1008. </th>
  1009. <?php
  1010. // end horizontal/horizontalflipped mode
  1011. } else {
  1012. $vertical_display['textbtn'] = ' <th ' . $rowspan . ' valign="middle">' . "\n"
  1013. . ' ' . "\n"
  1014. . ' </th>' . "\n";
  1015. } // end vertical mode
  1016. }
  1017. // ... elseif no button, displays empty columns if required
  1018. // (unless coming from Browse mode print view)
  1019. elseif (($GLOBALS['cfg']['RowActionLinks'] == 'left' || $GLOBALS['cfg']['RowActionLinks'] == 'both')
  1020. && ($is_display['edit_lnk'] == 'nn' && $is_display['del_lnk'] == 'nn')
  1021. && (! $GLOBALS['is_header_sent'])
  1022. ) {
  1023. $vertical_display['emptyafter'] = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn') ? 4 : 1;
  1024. if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
  1025. || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped'
  1026. ) {
  1027. echo "\n";
  1028. ?>
  1029. <td<?php echo $colspan; ?>></td>
  1030. <?php
  1031. // end horizontal/horizontalflipped mode
  1032. } else {
  1033. $vertical_display['textbtn'] = ' <td' . $rowspan . '></td>' . "\n";
  1034. } // end vertical mode
  1035. }
  1036. if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
  1037. || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped'
  1038. ) {
  1039. ?>
  1040. </tr>
  1041. </thead>
  1042. <?php
  1043. }
  1044. return true;
  1045. } // end of the 'PMA_displayTableHeaders()' function
  1046. /**
  1047. * Prepares the display for a value
  1048. *
  1049. * @param string $class class of table cell
  1050. * @param bool $condition_field whether to add CSS class condition
  1051. * @param string $value value to display
  1052. *
  1053. * @return string the td
  1054. */
  1055. function PMA_buildValueDisplay($class, $condition_field, $value)
  1056. {
  1057. return '<td align="left"' . ' class="' . $class . ($condition_field ? ' condition' : '') . '">' . $value . '</td>';
  1058. }
  1059. /**
  1060. * Prepares the display for a null value
  1061. *
  1062. * @param string $class class of table cell
  1063. * @param bool $condition_field whether to add CSS class condition
  1064. * @param object $meta the meta-information about this field
  1065. * @param string $align cell allignment
  1066. *
  1067. * @return string the td
  1068. */
  1069. function PMA_buildNullDisplay($class, $condition_field, $meta, $align = '')
  1070. {
  1071. // the null class is needed for grid editing
  1072. return '<td ' . $align . ' class="' . PMA_addClass($class, $condition_field, $meta, '') . ' null"><i>NULL</i></td>';
  1073. }
  1074. /**
  1075. * Prepares the display for an empty value
  1076. *
  1077. * @param string $class class of table cell
  1078. * @param bool $condition_field whether to add CSS class condition
  1079. * @param object $meta the meta-information about this field
  1080. * @param string $align cell allignment
  1081. *
  1082. * @return string the td
  1083. */
  1084. function PMA_buildEmptyDisplay($class, $condition_field, $meta, $align = '')
  1085. {
  1086. $nowrap = ' nowrap';
  1087. return '<td ' . $align . ' class="' . PMA_addClass($class, $condition_field, $meta, $nowrap) . '"></td>';
  1088. }
  1089. /**
  1090. * Adds the relavant classes.
  1091. *
  1092. * @param string $class class of table cell
  1093. * @param bool $condition_field whether to add CSS class condition
  1094. * @param object $meta the meta-information about this field
  1095. * @param string $nowrap avoid wrapping
  1096. * @param bool $is_field_truncated is field truncated (display ...)
  1097. * @param string $transform_function transformation function
  1098. * @param string $default_function default transformation function
  1099. *
  1100. * @return string the list of classes
  1101. */
  1102. function PMA_addClass($class, $condition_field, $meta, $nowrap, $is_field_truncated = false, $transform_function = '', $default_function = '')
  1103. {
  1104. // Define classes to be added to this data field based on the type of data
  1105. $enum_class = '';
  1106. if (strpos($meta->flags, 'enum') !== false) {
  1107. $enum_class = ' enum';
  1108. }
  1109. $set_class = '';
  1110. if (strpos($meta->flags, 'set') !== false) {
  1111. $set_class = ' set';
  1112. }
  1113. $bit_class = '';
  1114. if (strpos($meta->type, 'bit') !== false) {
  1115. $bit_class = ' bit';
  1116. }
  1117. $mime_type_class = '';
  1118. if (isset($meta->mimetype)) {
  1119. $mime_type_class = ' ' . preg_replace('/\//', '_', $meta->mimetype);
  1120. }
  1121. $result = $class . ($condition_field ? ' condition' : '') . $nowrap
  1122. . ' ' . ($is_field_truncated ? ' truncated' : '')
  1123. . ($transform_function != $default_function ? ' transformed' : '')
  1124. . $enum_class . $set_class . $bit_class . $mime_type_class;
  1125. return $result;
  1126. }
  1127. /**
  1128. * Displays the body of the results table
  1129. *
  1130. * @param integer &$dt_result the link id associated to the query which results have
  1131. * to be displayed
  1132. * @param array &$is_display which elements to display
  1133. * @param array $map the list of relations
  1134. * @param array $analyzed_sql the analyzed query
  1135. *
  1136. * @return boolean always true
  1137. *
  1138. * @global string $db the database name
  1139. * @global string $table the table name
  1140. * @global string $goto the URL to go back in case of errors
  1141. * @global string $sql_query the SQL query
  1142. * @global array $fields_meta the list of fields properties
  1143. * @global integer $fields_cnt the total number of fields returned by
  1144. * the SQL query
  1145. * @global array $vertical_display informations used with vertical display
  1146. * mode
  1147. * @global array $highlight_columns column names to highlight
  1148. * @global array $row current row data
  1149. *
  1150. * @access private
  1151. *
  1152. * @see PMA_displayTable()
  1153. */
  1154. function PMA_displayTableBody(&$dt_result, &$is_display, $map, $analyzed_sql)
  1155. {
  1156. global $db, $table, $goto;
  1157. global $sql_query, $fields_meta, $fields_cnt;
  1158. global $vertical_display, $highlight_columns;
  1159. global $row; // mostly because of browser transformations, to make the row-data accessible in a plugin
  1160. $url_sql_query = $sql_query;
  1161. // query without conditions to shorten URLs when needed, 200 is just
  1162. // guess, it should depend on remaining URL length
  1163. if (isset($analyzed_sql)
  1164. && isset($analyzed_sql[0])
  1165. && isset($analyzed_sql[0]['querytype'])
  1166. && $analyzed_sql[0]['querytype'] == 'SELECT'
  1167. && strlen($sql_query) > 200
  1168. ) {
  1169. $url_sql_query = 'SELECT ';
  1170. if (isset($analyzed_sql[0]['queryflags']['distinct'])) {
  1171. $url_sql_query .= ' DISTINCT ';
  1172. }
  1173. $url_sql_query .= $analyzed_sql[0]['select_expr_clause'];
  1174. if (!empty($analyzed_sql[0]['from_clause'])) {
  1175. $url_sql_query .= ' FROM ' . $analyzed_sql[0]['from_clause'];
  1176. }
  1177. }
  1178. if (! is_array($map)) {
  1179. $map = array();
  1180. }
  1181. $row_no = 0;
  1182. $vertical_display['edit'] = array();
  1183. $vertical_display['copy'] = array();
  1184. $vertical_display['delete'] = array();
  1185. $vertical_display['data'] = array();
  1186. $vertical_display['row_delete'] = array();
  1187. // name of the class added to all grid editable elements
  1188. $grid_edit_class = 'grid_edit';
  1189. // prepare to get the column order, if available
  1190. if (PMA_isSelect()) {
  1191. $pmatable = new PMA_Table($GLOBALS['table'], $GLOBALS['db']);
  1192. $col_order = $pmatable->getUiProp(PMA_Table::PROP_COLUMN_ORDER);
  1193. $col_visib = $pmatable->getUiProp(PMA_Table::PROP_COLUMN_VISIB);
  1194. } else {
  1195. $col_order = false;
  1196. $col_visib = false;
  1197. }
  1198. // Correction University of Virginia 19991216 in the while below
  1199. // Previous code assumed that all tables have keys, specifically that
  1200. // the phpMyAdmin GUI should support row delete/edit only for such
  1201. // tables.
  1202. // Although always using keys is arguably the prescribed way of
  1203. // defining a relational table, it is not required. This will in
  1204. // particular be violated by the novice.
  1205. // We want to encourage phpMyAdmin usage by such novices. So the code
  1206. // below has been changed to conditionally work as before when the
  1207. // table being displayed has one or more keys; but to display
  1208. // delete/edit options correctly for tables without keys.
  1209. $odd_row = true;
  1210. while ($row = PMA_DBI_fetch_row($dt_result)) {
  1211. // "vertical display" mode stuff
  1212. if ($row_no != 0 && $_SESSION['tmp_user_values']['repeat_cells'] != 0
  1213. && !($row_no % $_SESSION['tmp_user_values']['repeat_cells'])
  1214. && ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
  1215. || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped')
  1216. ) {
  1217. echo '<tr>' . "\n";
  1218. if ($vertical_display['emptypre'] > 0) {
  1219. echo ' <th colspan="' . $vertical_display['emptypre'] . '">' . "\n"
  1220. .' &nbsp;</th>' . "\n";
  1221. } else if ($GLOBALS['cfg']['RowActionLinks'] == 'none') {
  1222. echo ' <th></th>' . "\n";
  1223. }
  1224. foreach ($vertical_display['desc'] as $val) {
  1225. echo $val;
  1226. }
  1227. if ($vertical_display['emptyafter'] > 0) {
  1228. echo ' <th colspan="' . $vertical_display['emptyafter'] . '">' . "\n"
  1229. .' &nbsp;</th>' . "\n";
  1230. }
  1231. echo '</tr>' . "\n";
  1232. } // end if
  1233. $alternating_color_class = ($odd_row ? 'odd' : 'even');
  1234. $odd_row = ! $odd_row;
  1235. if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
  1236. || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped'
  1237. ) {
  1238. // pointer code part
  1239. echo '<tr class="' . $alternating_color_class . '">';
  1240. }
  1241. // 1. Prepares the row
  1242. // 1.1 Results from a "SELECT" statement -> builds the
  1243. // WHERE clause to use in links (a unique key if possible)
  1244. /**
  1245. * @todo $where_clause could be empty, for example a table
  1246. * with only one field and it's a BLOB; in this case,
  1247. * avoid to display the delete and edit links
  1248. */
  1249. list($where_clause, $clause_is_unique, $condition_array) = PMA_getUniqueCondition($dt_result, $fields_cnt, $fields_meta, $row);
  1250. $where_clause_html = urlencode($where_clause);
  1251. // 1.2 Defines the URLs for the modify/delete link(s)
  1252. if ($is_display['edit_lnk'] != 'nn' || $is_display['del_lnk'] != 'nn') {
  1253. // We need to copy the value or else the == 'both' check will always return true
  1254. if ($GLOBALS['cfg']['PropertiesIconic'] === 'both') {
  1255. $iconic_spacer = '<div class="nowrap">';
  1256. } else {
  1257. $iconic_spacer = '';
  1258. }
  1259. // 1.2.1 Modify link(s)
  1260. if ($is_display['edit_lnk'] == 'ur') { // update row case
  1261. $_url_params = array(
  1262. 'db' => $db,
  1263. 'table' => $table,
  1264. 'where_clause' => $where_clause,
  1265. 'clause_is_unique' => $clause_is_unique,
  1266. 'sql_query' => $url_sql_query,
  1267. 'goto' => 'sql.php',
  1268. );
  1269. $edit_url = 'tbl_change.php' . PMA_generate_common_url($_url_params + array('default_action' => 'update'));
  1270. $copy_url = 'tbl_change.php' . PMA_generate_common_url($_url_params + array('default_action' => 'insert'));
  1271. $edit_str = PMA_getIcon('b_edit.png', __('Edit'));
  1272. $copy_str = PMA_getIcon('b_insrow.png', __('Copy'));
  1273. // Class definitions required for grid editing jQuery scripts
  1274. $edit_anchor_class = "edit_row_anchor";
  1275. if ( $clause_is_unique == 0) {
  1276. $edit_anchor_class .= ' nonunique';
  1277. }
  1278. } // end if (1.2.1)
  1279. // 1.2.2 Delete/Kill link(s)
  1280. if ($is_display['del_lnk'] == 'dr') { // delete row case
  1281. $_url_params = array(
  1282. 'db' => $db,
  1283. 'table' => $table,
  1284. 'sql_query' => $url_sql_query,
  1285. 'message_to_show' => __('The row has been deleted'),
  1286. 'goto' => (empty($goto) ? 'tbl_sql.php' : $goto),
  1287. );
  1288. $lnk_goto = 'sql.php' . PMA_generate_common_url($_url_params, 'text');
  1289. $del_query = 'DELETE FROM ' . PMA_backquote($db) . '.' . PMA_backquote($table)
  1290. . ' WHERE ' . $where_clause . ($clause_is_unique ? '' : ' LIMIT 1');
  1291. $_url_params = array(
  1292. 'db' => $db,
  1293. 'table' => $table,
  1294. 'sql_query' => $del_query,
  1295. 'message_to_show' => __('The row has been deleted'),
  1296. 'goto' => $lnk_goto,
  1297. );
  1298. $del_url = 'sql.php' . PMA_generate_common_url($_url_params);
  1299. $js_conf = 'DELETE FROM ' . PMA_jsFormat($db) . '.' . PMA_jsFormat($table)
  1300. . ' WHERE ' . PMA_jsFormat($where_clause, false)
  1301. . ($clause_is_unique ? '' : ' LIMIT 1');
  1302. $del_str = PMA_getIcon('b_drop.png', __('Delete'));
  1303. } elseif ($is_display['del_lnk'] == 'kp') { // kill process case
  1304. $_url_params = array(
  1305. 'db' => $db,
  1306. 'table' => $table,
  1307. 'sql_query' => $url_sql_query,
  1308. 'goto' => 'main.php',
  1309. );
  1310. $lnk_goto = 'sql.php' . PMA_generate_common_url($_url_params, 'text');
  1311. $_url_params = array(
  1312. 'db' => 'mysql',
  1313. 'sql_query' => 'KILL ' . $row[0],
  1314. 'goto' => $lnk_goto,
  1315. );
  1316. $del_url = 'sql.php' . PMA_generate_common_url($_url_params);
  1317. $del_query = 'KILL ' . $row[0];
  1318. $js_conf = 'KILL ' . $row[0];
  1319. $del_str = PMA_getIcon('b_drop.png', __('Kill'));
  1320. } // end if (1.2.2)
  1321. // 1.3 Displays the links at left if required
  1322. if (($GLOBALS['cfg']['RowActionLinks'] == 'left' || $GLOBALS['cfg']['RowActionLinks'] == 'both')
  1323. && ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
  1324. || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped')
  1325. ) {
  1326. if (! isset($js_conf)) {
  1327. $js_conf = '';
  1328. }
  1329. echo PMA_generateCheckboxAndLinks('left', $del_url, $is_display, $row_no, $where_clause, $where_clause_html, $condition_array, $del_query, 'l', $edit_url, $copy_url, $edit_anchor_class, $edit_str, $copy_str, $del_str, $js_conf);
  1330. } elseif (($GLOBALS['cfg']['RowActionLinks'] == 'none')
  1331. && ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
  1332. || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped')
  1333. ) {
  1334. if (! isset($js_conf)) {
  1335. $js_conf = '';
  1336. }
  1337. echo PMA_generateCheckboxAndLinks('none', $del_url, $is_display, $row_no, $where_clause, $where_clause_html, $condition_array, $del_query, 'l', $edit_url, $copy_url, $edit_anchor_class, $edit_str, $copy_str, $del_str, $js_conf);
  1338. } // end if (1.3)
  1339. } // end if (1)
  1340. // 2. Displays the rows' values
  1341. for ($j = 0; $j < $fields_cnt; ++$j) {
  1342. // assign $i with appropriate column order
  1343. $i = $col_order ? $col_order[$j] : $j;
  1344. $meta = $fields_meta[$i];
  1345. $not_null_class = $meta->not_null ? 'not_null' : '';
  1346. $relation_class = isset($map[$meta->name]) ? 'relation' : '';
  1347. $hide_class = ($col_visib && !$col_visib[$j] &&
  1348. // hide per <td> only if the display direction is not vertical
  1349. $_SESSION['tmp_user_values']['disp_direction'] != 'vertical') ? 'hide' : '';
  1350. // handle datetime-related class, for grid editing
  1351. if (substr($meta->type, 0, 9) == 'timestamp' || $meta->type == 'datetime') {
  1352. $field_type_class = 'datetimefield';
  1353. } else if ($meta->type == 'date') {
  1354. $field_type_class = 'datefield';
  1355. } else {
  1356. $field_type_class = '';
  1357. }
  1358. $pointer = $i;
  1359. $is_field_truncated = false;
  1360. //If the previous column had blob data, we need to reset the class
  1361. // to $inline_edit_class
  1362. $class = 'data ' . $grid_edit_class . ' ' . $not_null_class . ' ' . $relation_class . ' ' . $hide_class . ' ' . $field_type_class; //' ' . $alternating_color_class .
  1363. // See if this column should get highlight because it's used in the
  1364. // where-query.
  1365. if (isset($highlight_columns) && (isset($highlight_columns[$meta->name]) || isset($highlight_columns[PMA_backquote($meta->name)]))) {
  1366. $condition_field = true;
  1367. } else {
  1368. $condition_field = false;
  1369. }
  1370. if ($_SESSION['tmp_user_values']['disp_direction'] == 'vertical' && (! isset($GLOBALS['printview']) || ($GLOBALS['printview'] != '1'))) {
  1371. // the row number corresponds to a data row, not HTML table row
  1372. $class .= ' row_' . $row_no;
  1373. if ($GLOBALS['cfg']['BrowsePointerEnable'] == true) {
  1374. $class .= ' vpointer';
  1375. }
  1376. if ($GLOBALS['cfg']['BrowseMarkerEnable'] == true) {
  1377. $class .= ' vmarker';
  1378. }
  1379. }// end if
  1380. // Wrap MIME-transformations. [MIME]
  1381. $default_function = 'default_function'; // default_function
  1382. $transform_function = $default_function;
  1383. $transform_options = array();
  1384. if ($GLOBALS['cfgRelation']['mimework'] && $GLOBALS['cfg']['BrowseMIME']) {
  1385. if (isset($GLOBALS['mime_map'][$meta->name]['mimetype']) && isset($GLOBALS['mime_map'][$meta->name]['transformation']) && !empty($GLOBALS['mime_map'][$meta->name]['transformation'])) {
  1386. $include_file = PMA_securePath($GLOBALS['mime_map'][$meta->name]['transformation']);
  1387. if (file_exists('./libraries/transformations/' . $include_file)) {
  1388. $transformfunction_name = str_replace('.inc.php', '', $GLOBALS['mime_map'][$meta->name]['transformation']);
  1389. include_once './libraries/transformations/' . $include_file;
  1390. if (function_exists('PMA_transformation_' . $transformfunction_name)) {
  1391. $transform_function = 'PMA_transformation_' . $transformfunction_name;
  1392. $transform_options = PMA_transformation_getOptions((isset($GLOBALS['mime_map'][$meta->name]['transformation_options']) ? $GLOBALS['mime_map'][$meta->name]['transformation_options'] : ''));
  1393. $meta->mimetype = str_replace('_', '/', $GLOBALS['mime_map'][$meta->name]['mimetype']);
  1394. }
  1395. } // end if file_exists
  1396. } // end if transformation is set
  1397. } // end if mime/transformation works.
  1398. $_url_params = array(
  1399. 'db' => $db,
  1400. 'table' => $table,
  1401. 'where_clause' => $where_clause,
  1402. 'transform_key' => $meta->name,
  1403. );
  1404. if (! empty($sql_query)) {
  1405. $_url_params['sql_query'] = $url_sql_query;
  1406. }
  1407. $transform_options['wrapper_link'] = PMA_generate_common_url($_url_params);
  1408. // n u m e r i c
  1409. if ($meta->numeric == 1) {
  1410. // if two fields have the same name (this is possible
  1411. // with self-join queries, for example), using $meta->name
  1412. // will show both fields NULL even if only one is NULL,
  1413. // so use the $pointer
  1414. if (! isset($row[$i]) || is_null($row[$i])) {
  1415. $vertical_display['data'][$row_no][$i] = PMA_buildNullDisplay($class, $condition_field, $meta, 'align="right"');
  1416. } elseif ($row[$i] != '') {
  1417. $nowrap = ' nowrap';
  1418. $where_comparison = ' = ' . $row[$i];
  1419. $vertical_display['data'][$row_no][$i] = '<td align="right"' . PMA_prepare_row_data($class, $condition_field, $analyzed_sql, $meta, $map, $row[$i], $transform_function, $default_function, $nowrap, $where_comparison, $transform_options, $is_field_truncated);
  1420. } else {
  1421. $vertical_display['data'][$row_no][$i] = PMA_buildEmptyDisplay($class, $condition_field, $meta, 'align="right"');
  1422. }
  1423. // b l o b
  1424. } elseif (stristr($meta->type, 'BLOB')) {
  1425. // PMA_mysql_fetch_fields returns BLOB in place of
  1426. // TEXT fields type so we have to ensure it's really a BLOB
  1427. $field_flags = PMA_DBI_field_flags($dt_result, $i);
  1428. if (stristr($field_flags, 'BINARY')) {
  1429. // remove 'grid_edit' from $class as we can't edit binary data.
  1430. $class = str_replace('grid_edit', '', $class);
  1431. if (! isset($row[$i]) || is_null($row[$i])) {
  1432. $vertical_display['data'][$row_no][$i] = PMA_buildNullDisplay($class, $condition_field, $meta);
  1433. } else {
  1434. // for blobstreaming
  1435. // if valid BS reference exists
  1436. if (PMA_BS_IsPBMSReference($row[$i], $db)) {
  1437. $blobtext = PMA_BS_CreateReferenceLink($row[$i], $db);
  1438. } else {
  1439. $blobtext = PMA_handle_non_printable_contents('BLOB', (isset($row[$i]) ? $row[$i] : ''), $transform_function, $transform_options, $default_function, $meta, $_url_params);
  1440. }
  1441. $vertical_display['data'][$row_no][$i] = PMA_buildValueDisplay($class, $condition_field, $blobtext);
  1442. unset($blobtext);
  1443. }
  1444. // not binary:
  1445. } else {
  1446. if (! isset($row[$i]) || is_null($row[$i])) {
  1447. $vertical_display['data'][$row_no][$i] = PMA_buildNullDisplay($class, $condition_field, $meta);
  1448. } elseif ($row[$i] != '') {
  1449. // if a transform function for blob is set, none of these replacements will be made
  1450. if (PMA_strlen($row[$i]) > $GLOBALS['cfg']['LimitChars'] && $_SESSION['tmp_user_values']['display_text'] == 'P') {
  1451. $row[$i] = PMA_substr($row[$i], 0, $GLOBALS['cfg']['LimitChars']) . '...';
  1452. $is_field_truncated = true;
  1453. }
  1454. // displays all space characters, 4 space
  1455. // characters for tabulations and <cr>/<lf>
  1456. $row[$i] = ($default_function != $transform_function ? $transform_function($row[$i], $transform_options, $meta) : $default_function($row[$i], array(), $meta));
  1457. if ($is_field_truncated) {
  1458. $class .= ' truncated';
  1459. }
  1460. $vertical_display['data'][$row_no][$i] = PMA_buildValueDisplay($class, $condition_field, $row[$i]);
  1461. } else {
  1462. $vertical_display['data'][$row_no][$i] = PMA_buildEmptyDisplay($class, $condition_field, $meta);
  1463. }
  1464. }
  1465. // g e o m e t r y
  1466. } elseif ($meta->type == 'geometry') {
  1467. // Remove 'grid_edit' from $class as we do not allow to inline-edit geometry data.
  1468. $class = str_replace('grid_edit', '', $class);
  1469. if (! isset($row[$i]) || is_null($row[$i])) {
  1470. $vertical_display['data'][$row_no][$i] = PMA_buildNullDisplay($class, $condition_field, $meta);
  1471. } elseif ($row[$i] != '') {
  1472. // Display as [GEOMETRY - (size)]
  1473. if ('GEOM' == $_SESSION['tmp_user_values']['geometry_display']) {
  1474. $geometry_text = PMA_handle_non_printable_contents(
  1475. 'GEOMETRY', (isset($row[$i]) ? $row[$i] : ''), $transform_function,
  1476. $transform_options, $default_function, $meta
  1477. );
  1478. $vertical_display['data'][$row_no][$i] = PMA_buildValueDisplay(
  1479. $class, $condition_field, $geometry_text
  1480. );
  1481. // Display in Well Known Text(WKT) format.
  1482. } elseif ('WKT' == $_SESSION['tmp_user_values']['geometry_display']) {
  1483. $where_comparison = ' = ' . $row[$i];
  1484. // Convert to WKT format
  1485. $wktval = PMA_asWKT($row[$i]);
  1486. if (PMA_strlen($wktval) > $GLOBALS['cfg']['LimitChars']
  1487. && $_SESSION['tmp_user_values']['display_text'] == 'P'
  1488. ) {
  1489. $wktval = PMA_substr($wktval, 0, $GLOBALS['cfg']['LimitChars']) . '...';
  1490. $is_field_truncated = true;
  1491. }
  1492. $vertical_display['data'][$row_no][$i] = '<td ' . PMA_prepare_row_data(
  1493. $class, $condition_field, $analyzed_sql, $meta, $map, $wktval, $transform_function,
  1494. $default_function, '', $where_comparison, $transform_options, $is_field_truncated
  1495. );
  1496. // Display in Well Known Binary(WKB) format.
  1497. } else {
  1498. if ($_SESSION['tmp_user_values']['display_binary']) {
  1499. $where_comparison = ' = ' . $row[$i];
  1500. if ($_SESSION['tmp_user_values']['display_binary_as_hex']
  1501. && PMA_contains_nonprintable_ascii($row[$i])
  1502. ) {
  1503. $wkbval = PMA_substr(bin2hex($row[$i]), 8);
  1504. } else {
  1505. $wkbval = htmlspecialchars(PMA_replace_binary_contents($row[$i]));
  1506. }
  1507. if (PMA_strlen($wkbval) > $GLOBALS['cfg']['LimitChars']
  1508. && $_SESSION['tmp_user_values']['display_text'] == 'P'
  1509. ) {
  1510. $wkbval = PMA_substr($wkbval, 0, $GLOBALS['cfg']['LimitChars']) . '...';
  1511. $is_field_truncated = true;
  1512. }
  1513. $vertical_display['data'][$row_no][$i] = '<td ' . PMA_prepare_row_data(
  1514. $class, $condition_field, $analyzed_sql, $meta, $map, $wkbval, $transform_function,
  1515. $default_function, '', $where_comparison, $transform_options, $is_field_truncated
  1516. );
  1517. } else {
  1518. $wkbval = PMA_handle_non_printable_contents(
  1519. 'BINARY', $row[$i], $transform_function, $transform_options, $default_function, $meta, $_url_params
  1520. );
  1521. $vertical_display['data'][$row_no][$i] = PMA_buildValueDisplay($class, $condition_field, $wkbval);
  1522. }
  1523. }
  1524. } else {
  1525. $vertical_display['data'][$row_no][$i] = PMA_buildEmptyDisplay($class, $condition_field, $meta);
  1526. }
  1527. // n o t n u m e r i c a n d n o t B L O B
  1528. } else {
  1529. if (! isset($row[$i]) || is_null($row[$i])) {
  1530. $vertical_display['data'][$row_no][$i] = PMA_buildNullDisplay($class, $condition_field, $meta);
  1531. } elseif ($row[$i] != '') {
  1532. // support blanks in the key
  1533. $relation_id = $row[$i];
  1534. // Cut all fields to $GLOBALS['cfg']['LimitChars']
  1535. // (unless it's a link-type transformation)
  1536. if (PMA_strlen($row[$i]) > $GLOBALS['cfg']['LimitChars'] && $_SESSION['tmp_user_values']['display_text'] == 'P' && !strpos($transform_function, 'link') === true) {
  1537. $row[$i] = PMA_substr($row[$i], 0, $GLOBALS['cfg']['LimitChars']) . '...';
  1538. $is_field_truncated = true;
  1539. }
  1540. // displays special characters from binaries
  1541. $field_flags = PMA_DBI_field_flags($dt_result, $i);
  1542. $formatted = false;
  1543. if (isset($meta->_type) && $meta->_type === MYSQLI_TYPE_BIT) {
  1544. $row[$i] = PMA_printable_bit_value($row[$i], $meta->length);
  1545. // some results of PROCEDURE ANALYSE() are reported as
  1546. // being BINARY but they are quite readable,
  1547. // so don't treat them as BINARY
  1548. } elseif (stristr($field_flags, 'BINARY') && $meta->type == 'string' && !(isset($GLOBALS['is_analyse']) && $GLOBALS['is_analyse'])) {
  1549. if ($_SESSION['tmp_user_values']['display_binary']) {
  1550. // user asked to see the real contents of BINARY
  1551. // fields
  1552. if ($_SESSION['tmp_user_values']['display_binary_as_hex'] && PMA_contains_nonprintable_ascii($row[$i])) {
  1553. $row[$i] = bin2hex($row[$i]);
  1554. } else {
  1555. $row[$i] = htmlspecialchars(PMA_replace_binary_contents($row[$i]));
  1556. }
  1557. } else {
  1558. // we show the BINARY message and field's size
  1559. // (or maybe use a transformation)
  1560. $row[$i] = PMA_handle_non_printable_contents('BINARY', $row[$i], $transform_function, $transform_options, $default_function, $meta, $_url_params);
  1561. $formatted = true;
  1562. }
  1563. }
  1564. if ($formatted) {
  1565. $vertical_display['data'][$row_no][$i] = PMA_buildValueDisplay($class, $condition_field, $row[$i]);
  1566. } else {
  1567. // transform functions may enable no-wrapping:
  1568. $function_nowrap = $transform_function . '_nowrap';
  1569. $bool_nowrap = (($default_function != $transform_function && function_exists($function_nowrap)) ? $function_nowrap($transform_options) : false);
  1570. // do not wrap if date field type
  1571. $nowrap = ((preg_match('@DATE|TIME@i', $meta->type) || $bool_nowrap) ? ' nowrap' : '');
  1572. $where_comparison = ' = \'' . PMA_sqlAddSlashes($row[$i]) . '\'';
  1573. $vertical_display['data'][$row_no][$i] = '<td ' . PMA_prepare_row_data($class, $condition_field, $analyzed_sql, $meta, $map, $row[$i], $transform_function, $default_function, $nowrap, $where_comparison, $transform_options, $is_field_truncated);
  1574. }
  1575. } else {
  1576. $vertical_display['data'][$row_no][$i] = PMA_buildEmptyDisplay($class, $condition_field, $meta);
  1577. }
  1578. }
  1579. // output stored cell
  1580. if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
  1581. || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped'
  1582. ) {
  1583. echo $vertical_display['data'][$row_no][$i];
  1584. }
  1585. if (isset($vertical_display['rowdata'][$i][$row_no])) {
  1586. $vertical_display['rowdata'][$i][$row_no] .= $vertical_display['data'][$row_no][$i];
  1587. } else {
  1588. $vertical_display['rowdata'][$i][$row_no] = $vertical_display['data'][$row_no][$i];
  1589. }
  1590. } // end for (2)
  1591. // 3. Displays the modify/delete links on the right if required
  1592. if (($GLOBALS['cfg']['RowActionLinks'] == 'right' || $GLOBALS['cfg']['RowActionLinks'] == 'both')
  1593. && ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
  1594. || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped')
  1595. ) {
  1596. if (! isset($js_conf)) {
  1597. $js_conf = '';
  1598. }
  1599. echo PMA_generateCheckboxAndLinks('right', $del_url, $is_display, $row_no, $where_clause, $where_clause_html, $condition_array, $del_query, 'r', $edit_url, $copy_url, $edit_anchor_class, $edit_str, $copy_str, $del_str, $js_conf);
  1600. } // end if (3)
  1601. if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal'
  1602. || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped'
  1603. ) {
  1604. ?>
  1605. </tr>
  1606. <?php
  1607. } // end if
  1608. // 4. Gather links of del_urls and edit_urls in an array for later
  1609. // output
  1610. if (! isset($vertical_display['edit'][$row_no])) {
  1611. $vertical_display['edit'][$row_no] = '';
  1612. $vertical_display['copy'][$row_no] = '';
  1613. $vertical_display['delete'][$row_no] = '';
  1614. $vertical_display['row_delete'][$row_no] = '';
  1615. }
  1616. $vertical_class = ' row_' . $row_no;
  1617. if ($GLOBALS['cfg']['BrowsePointerEnable'] == true) {
  1618. $vertical_class .= ' vpointer';
  1619. }
  1620. if ($GLOBALS['cfg']['BrowseMarkerEnable'] == true) {
  1621. $vertical_class .= ' vmarker';
  1622. }
  1623. if (!empty($del_url) && $is_display['del_lnk'] != 'kp') {
  1624. $vertical_display['row_delete'][$row_no] .= PMA_generateCheckboxForMulti($del_url, $is_display, $row_no, $where_clause_html, $condition_array, $del_query, '[%_PMA_CHECKBOX_DIR_%]', $alternating_color_class . $vertical_class);
  1625. } else {
  1626. unset($vertical_display['row_delete'][$row_no]);
  1627. }
  1628. if (isset($edit_url)) {
  1629. $vertical_display['edit'][$row_no] .= PMA_generateEditLink($edit_url, $alternating_color_class . ' ' . $edit_anchor_class . $vertical_class, $edit_str, $where_clause, $where_clause_html);
  1630. } else {
  1631. unset($vertical_display['edit'][$row_no]);
  1632. }
  1633. if (isset($copy_url)) {
  1634. $vertical_display['copy'][$row_no] .= PMA_generateCopyLink($copy_url, $copy_str, $where_clause, $where_clause_html, $alternating_color_class . $vertical_class);
  1635. } else {
  1636. unset($vertical_display['copy'][$row_no]);
  1637. }
  1638. if (isset($del_url)) {
  1639. if (! isset($js_conf)) {
  1640. $js_conf = '';
  1641. }
  1642. $vertical_display['delete'][$row_no] .= PMA_generateDeleteLink($del_url, $del_str, $js_conf, $alternating_color_class . $vertical_class);
  1643. } else {
  1644. unset($vertical_display['delete'][$row_no]);
  1645. }
  1646. echo (($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal' || $_SESSION['tmp_user_values']['disp_direction'] == 'horizontalflipped') ? "\n" : '');
  1647. $row_no++;
  1648. } // end while
  1649. // this is needed by PMA_displayTable() to generate the proper param
  1650. // in the multi-edit and multi-delete form
  1651. return $clause_is_unique;
  1652. } // end of the 'PMA_displayTableBody()' function
  1653. /**
  1654. * Do display the result table with the vertical direction mode.
  1655. *
  1656. * @return boolean always true
  1657. *
  1658. * @global array $vertical_display the information to display
  1659. *
  1660. * @access private
  1661. *
  1662. * @see PMA_displayTable()
  1663. */
  1664. function PMA_displayVerticalTable()
  1665. {
  1666. global $vertical_display;
  1667. // Displays "multi row delete" link at top if required
  1668. if ($GLOBALS['cfg']['RowActionLinks'] != 'right'
  1669. && is_array($vertical_display['row_delete'])
  1670. && (count($vertical_display['row_delete']) > 0 || !empty($vertical_display['textbtn']))
  1671. ) {
  1672. echo '<tr>' . "\n";
  1673. if ($GLOBALS['cfg']['RowActionLinks'] == 'none') {
  1674. // if we are not showing the RowActionLinks, then we need to show the Multi-Row-Action checkboxes
  1675. echo '<th></th>' . "\n";
  1676. }
  1677. echo $vertical_display['textbtn'];
  1678. $cell_displayed = 0;
  1679. foreach ($vertical_display['row_delete'] as $val) {
  1680. if (($cell_displayed != 0) && ($_SESSION['tmp_user_values']['repeat_cells'] != 0) && !($cell_displayed % $_SESSION['tmp_user_values']['repeat_cells'])) {
  1681. echo '<th' .
  1682. (($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn') ? ' rowspan="4"' : '') .
  1683. '></th>' . "\n";
  1684. }
  1685. echo str_replace('[%_PMA_CHECKBOX_DIR_%]', '_left', $val);
  1686. $cell_displayed++;
  1687. } // end while
  1688. echo '</tr>' . "\n";
  1689. } // end if
  1690. // Displays "edit" link at top if required
  1691. if (($GLOBALS['cfg']['RowActionLinks'] == 'left' || $GLOBALS['cfg']['RowActionLinks'] == 'both')
  1692. && is_array($vertical_display['edit'])
  1693. && (count($vertical_display['edit']) > 0 || !empty($vertical_display['textbtn']))
  1694. ) {
  1695. echo '<tr>' . "\n";
  1696. if (! is_array($vertical_display['row_delete'])) {
  1697. echo $vertical_display['textbtn'];
  1698. }
  1699. foreach ($vertical_display['edit'] as $val) {
  1700. echo $val;
  1701. } // end while
  1702. echo '</tr>' . "\n";
  1703. } // end if
  1704. // Displays "copy" link at top if required
  1705. if (($GLOBALS['cfg']['RowActionLinks'] == 'left' || $GLOBALS['cfg']['RowActionLinks'] == 'both')
  1706. && is_array($vertical_display['copy'])
  1707. && (count($vertical_display['copy']) > 0 || !empty($vertical_display['textbtn']))
  1708. ) {
  1709. echo '<tr>' . "\n";
  1710. if (! is_array($vertical_display['row_delete'])) {
  1711. echo $vertical_display['textbtn'];
  1712. }
  1713. foreach ($vertical_display['copy'] as $val) {
  1714. echo $val;
  1715. } // end while
  1716. echo '</tr>' . "\n";
  1717. } // end if
  1718. // Displays "delete" link at top if required
  1719. if (($GLOBALS['cfg']['RowActionLinks'] == 'left' || $GLOBALS['cfg']['RowActionLinks'] == 'both')
  1720. && is_array($vertical_display['delete'])
  1721. && (count($vertical_display['delete']) > 0 || !empty($vertical_display['textbtn']))
  1722. ) {
  1723. echo '<tr>' . "\n";
  1724. if (! is_array($vertical_display['edit']) && ! is_array($vertical_display['row_delete'])) {
  1725. echo $vertical_display['textbtn'];
  1726. }
  1727. foreach ($vertical_display['delete'] as $val) {
  1728. echo $val;
  1729. } // end while
  1730. echo '</tr>' . "\n";
  1731. } // end if
  1732. if (PMA_isSelect()) {
  1733. // prepare to get the column order, if available
  1734. $pmatable = new PMA_Table($GLOBALS['table'], $GLOBALS['db']);
  1735. $col_order = $pmatable->getUiProp(PMA_Table::PROP_COLUMN_ORDER);
  1736. $col_visib = $pmatable->getUiProp(PMA_Table::PROP_COLUMN_VISIB);
  1737. } else {
  1738. $col_order = false;
  1739. $col_visib = false;
  1740. }
  1741. // Displays data
  1742. foreach ($vertical_display['desc'] AS $j => $val) {
  1743. // assign appropriate key with current column order
  1744. $key = $col_order ? $col_order[$j] : $j;
  1745. echo '<tr' . (($col_visib && !$col_visib[$j]) ? ' class="hide"' : '') . '>' . "\n";
  1746. echo $val;
  1747. $cell_displayed = 0;
  1748. foreach ($vertical_display['rowdata'][$key] as $subval) {
  1749. if (($cell_displayed != 0) && ($_SESSION['tmp_user_values']['repeat_cells'] != 0) and !($cell_displayed % $_SESSION['tmp_user_values']['repeat_cells'])) {
  1750. echo $val;
  1751. }
  1752. echo $subval;
  1753. $cell_displayed++;
  1754. } // end while
  1755. echo '</tr>' . "\n";
  1756. } // end while
  1757. // Displays "multi row delete" link at bottom if required
  1758. if (($GLOBALS['cfg']['RowActionLinks'] == 'right' || $GLOBALS['cfg']['RowActionLinks'] == 'both')
  1759. && is_array($vertical_display['row_delete'])
  1760. && (count($vertical_display['row_delete']) > 0 || !empty($vertical_display['textbtn']))
  1761. ) {
  1762. echo '<tr>' . "\n";
  1763. echo $vertical_display['textbtn'];
  1764. $cell_displayed = 0;
  1765. foreach ($vertical_display['row_delete'] as $val) {
  1766. if (($cell_displayed != 0) && ($_SESSION['tmp_user_values']['repeat_cells'] != 0) && !($cell_displayed % $_SESSION['tmp_user_values']['repeat_cells'])) {
  1767. echo '<th' .
  1768. (($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn') ? ' rowspan="4"' : '') .
  1769. '></th>' . "\n";
  1770. }
  1771. echo str_replace('[%_PMA_CHECKBOX_DIR_%]', '_right', $val);
  1772. $cell_displayed++;
  1773. } // end while
  1774. echo '</tr>' . "\n";
  1775. } // end if
  1776. // Displays "edit" link at bottom if required
  1777. if (($GLOBALS['cfg']['RowActionLinks'] == 'right' || $GLOBALS['cfg']['RowActionLinks'] == 'both')
  1778. && is_array($vertical_display['edit'])
  1779. && (count($vertical_display['edit']) > 0 || !empty($vertical_display['textbtn']))
  1780. ) {
  1781. echo '<tr>' . "\n";
  1782. if (! is_array($vertical_display['row_delete'])) {
  1783. echo $vertical_display['textbtn'];
  1784. }
  1785. foreach ($vertical_display['edit'] as $val) {
  1786. echo $val;
  1787. } // end while
  1788. echo '</tr>' . "\n";
  1789. } // end if
  1790. // Displays "copy" link at bottom if required
  1791. if (($GLOBALS['cfg']['RowActionLinks'] == 'right' || $GLOBALS['cfg']['RowActionLinks'] == 'both')
  1792. && is_array($vertical_display['copy'])
  1793. && (count($vertical_display['copy']) > 0 || !empty($vertical_display['textbtn']))
  1794. ) {
  1795. echo '<tr>' . "\n";
  1796. if (! is_array($vertical_display['row_delete'])) {
  1797. echo $vertical_display['textbtn'];
  1798. }
  1799. foreach ($vertical_display['copy'] as $val) {
  1800. echo $val;
  1801. } // end while
  1802. echo '</tr>' . "\n";
  1803. } // end if
  1804. // Displays "delete" link at bottom if required
  1805. if (($GLOBALS['cfg']['RowActionLinks'] == 'right' || $GLOBALS['cfg']['RowActionLinks'] == 'both')
  1806. && is_array($vertical_display['delete'])
  1807. && (count($vertical_display['delete']) > 0 || !empty($vertical_display['textbtn']))
  1808. ) {
  1809. echo '<tr>' . "\n";
  1810. if (! is_array($vertical_display['edit']) && ! is_array($vertical_display['row_delete'])) {
  1811. echo $vertical_display['textbtn'];
  1812. }
  1813. foreach ($vertical_display['delete'] as $val) {
  1814. echo $val;
  1815. } // end while
  1816. echo '</tr>' . "\n";
  1817. }
  1818. return true;
  1819. } // end of the 'PMA_displayVerticalTable' function
  1820. /**
  1821. * Checks the posted options for viewing query resutls
  1822. * and sets appropriate values in the session.
  1823. *
  1824. * @todo make maximum remembered queries configurable
  1825. * @todo move/split into SQL class!?
  1826. * @todo currently this is called twice unnecessary
  1827. * @todo ignore LIMIT and ORDER in query!?
  1828. *
  1829. * @return nothing
  1830. */
  1831. function PMA_displayTable_checkConfigParams()
  1832. {
  1833. $sql_md5 = md5($GLOBALS['sql_query']);
  1834. $_SESSION['tmp_user_values']['query'][$sql_md5]['sql'] = $GLOBALS['sql_query'];
  1835. if (PMA_isValid($_REQUEST['disp_direction'], array('horizontal', 'vertical', 'horizontalflipped'))) {
  1836. $_SESSION['tmp_user_values']['query'][$sql_md5]['disp_direction'] = $_REQUEST['disp_direction'];
  1837. unset($_REQUEST['disp_direction']);
  1838. } elseif (empty($_SESSION['tmp_user_values']['query'][$sql_md5]['disp_direction'])) {
  1839. $_SESSION['tmp_user_values']['query'][$sql_md5]['disp_direction'] = $GLOBALS['cfg']['DefaultDisplay'];
  1840. }
  1841. if (PMA_isValid($_REQUEST['repeat_cells'], 'numeric')) {
  1842. $_SESSION['tmp_user_values']['query'][$sql_md5]['repeat_cells'] = $_REQUEST['repeat_cells'];
  1843. unset($_REQUEST['repeat_cells']);
  1844. } elseif (empty($_SESSION['tmp_user_values']['query'][$sql_md5]['repeat_cells'])) {
  1845. $_SESSION['tmp_user_values']['query'][$sql_md5]['repeat_cells'] = $GLOBALS['cfg']['RepeatCells'];
  1846. }
  1847. // as this is a form value, the type is always string so we cannot
  1848. // use PMA_isValid($_REQUEST['session_max_rows'], 'integer')
  1849. if ((PMA_isValid($_REQUEST['session_max_rows'], 'numeric')
  1850. && (int) $_REQUEST['session_max_rows'] == $_REQUEST['session_max_rows'])
  1851. || $_REQUEST['session_max_rows'] == 'all'
  1852. ) {
  1853. $_SESSION['tmp_user_values']['query'][$sql_md5]['max_rows'] = $_REQUEST['session_max_rows'];
  1854. unset($_REQUEST['session_max_rows']);
  1855. } elseif (empty($_SESSION['tmp_user_values']['query'][$sql_md5]['max_rows'])) {
  1856. $_SESSION['tmp_user_values']['query'][$sql_md5]['max_rows'] = $GLOBALS['cfg']['MaxRows'];
  1857. }
  1858. if (PMA_isValid($_REQUEST['pos'], 'numeric')) {
  1859. $_SESSION['tmp_user_values']['query'][$sql_md5]['pos'] = $_REQUEST['pos'];
  1860. unset($_REQUEST['pos']);
  1861. } elseif (empty($_SESSION['tmp_user_values']['query'][$sql_md5]['pos'])) {
  1862. $_SESSION['tmp_user_values']['query'][$sql_md5]['pos'] = 0;
  1863. }
  1864. if (PMA_isValid($_REQUEST['display_text'], array('P', 'F'))) {
  1865. $_SESSION['tmp_user_values']['query'][$sql_md5]['display_text'] = $_REQUEST['display_text'];
  1866. unset($_REQUEST['display_text']);
  1867. } elseif (empty($_SESSION['tmp_user_values']['query'][$sql_md5]['display_text'])) {
  1868. $_SESSION['tmp_user_values']['query'][$sql_md5]['display_text'] = 'P';
  1869. }
  1870. if (PMA_isValid($_REQUEST['relational_display'], array('K', 'D'))) {
  1871. $_SESSION['tmp_user_values']['query'][$sql_md5]['relational_display'] = $_REQUEST['relational_display'];
  1872. unset($_REQUEST['relational_display']);
  1873. } elseif (empty($_SESSION['tmp_user_values']['query'][$sql_md5]['relational_display'])) {
  1874. $_SESSION['tmp_user_values']['query'][$sql_md5]['relational_display'] = 'K';
  1875. }
  1876. if (PMA_isValid($_REQUEST['geometry_display'], array('WKT', 'WKB', 'GEOM'))) {
  1877. $_SESSION['tmp_user_values']['query'][$sql_md5]['geometry_display'] = $_REQUEST['geometry_display'];
  1878. unset($_REQUEST['geometry_display']);
  1879. } elseif (empty($_SESSION['tmp_user_values']['query'][$sql_md5]['geometry_display'])) {
  1880. $_SESSION['tmp_user_values']['query'][$sql_md5]['geometry_display'] = 'GEOM';
  1881. }
  1882. if (isset($_REQUEST['display_binary'])) {
  1883. $_SESSION['tmp_user_values']['query'][$sql_md5]['display_binary'] = true;
  1884. unset($_REQUEST['display_binary']);
  1885. } elseif (isset($_REQUEST['display_options_form'])) {
  1886. // we know that the checkbox was unchecked
  1887. unset($_SESSION['tmp_user_values']['query'][$sql_md5]['display_binary']);
  1888. } elseif (isset($_REQUEST['full_text_button'])) {
  1889. // do nothing to keep the value that is there in the session
  1890. } else {
  1891. // selected by default because some operations like OPTIMIZE TABLE
  1892. // and all queries involving functions return "binary" contents,
  1893. // according to low-level field flags
  1894. $_SESSION['tmp_user_values']['query'][$sql_md5]['display_binary'] = true;
  1895. }
  1896. if (isset($_REQUEST['display_binary_as_hex'])) {
  1897. $_SESSION['tmp_user_values']['query'][$sql_md5]['display_binary_as_hex'] = true;
  1898. unset($_REQUEST['display_binary_as_hex']);
  1899. } elseif (isset($_REQUEST['display_options_form'])) {
  1900. // we know that the checkbox was unchecked
  1901. unset($_SESSION['tmp_user_values']['query'][$sql_md5]['display_binary_as_hex']);
  1902. } elseif (isset($_REQUEST['full_text_button'])) {
  1903. // do nothing to keep the value that is there in the session
  1904. } else {
  1905. // display_binary_as_hex config option
  1906. if (isset($GLOBALS['cfg']['DisplayBinaryAsHex']) && true === $GLOBALS['cfg']['DisplayBinaryAsHex']) {
  1907. $_SESSION['tmp_user_values']['query'][$sql_md5]['display_binary_as_hex'] = true;
  1908. }
  1909. }
  1910. if (isset($_REQUEST['display_blob'])) {
  1911. $_SESSION['tmp_user_values']['query'][$sql_md5]['display_blob'] = true;
  1912. unset($_REQUEST['display_blob']);
  1913. } elseif (isset($_REQUEST['display_options_form'])) {
  1914. // we know that the checkbox was unchecked
  1915. unset($_SESSION['tmp_user_values']['query'][$sql_md5]['display_blob']);
  1916. }
  1917. if (isset($_REQUEST['hide_transformation'])) {
  1918. $_SESSION['tmp_user_values']['query'][$sql_md5]['hide_transformation'] = true;
  1919. unset($_REQUEST['hide_transformation']);
  1920. } elseif (isset($_REQUEST['display_options_form'])) {
  1921. // we know that the checkbox was unchecked
  1922. unset($_SESSION['tmp_user_values']['query'][$sql_md5]['hide_transformation']);
  1923. }
  1924. // move current query to the last position, to be removed last
  1925. // so only least executed query will be removed if maximum remembered queries
  1926. // limit is reached
  1927. $tmp = $_SESSION['tmp_user_values']['query'][$sql_md5];
  1928. unset($_SESSION['tmp_user_values']['query'][$sql_md5]);
  1929. $_SESSION['tmp_user_values']['query'][$sql_md5] = $tmp;
  1930. // do not exceed a maximum number of queries to remember
  1931. if (count($_SESSION['tmp_user_values']['query']) > 10) {
  1932. array_shift($_SESSION['tmp_user_values']['query']);
  1933. //echo 'deleting one element ...';
  1934. }
  1935. // populate query configuration
  1936. $_SESSION['tmp_user_values']['display_text'] = $_SESSION['tmp_user_values']['query'][$sql_md5]['display_text'];
  1937. $_SESSION['tmp_user_values']['relational_display'] = $_SESSION['tmp_user_values']['query'][$sql_md5]['relational_display'];
  1938. $_SESSION['tmp_user_values']['geometry_display'] = $_SESSION['tmp_user_values']['query'][$sql_md5]['geometry_display'];
  1939. $_SESSION['tmp_user_values']['display_binary'] = isset($_SESSION['tmp_user_values']['query'][$sql_md5]['display_binary']) ? true : false;
  1940. $_SESSION['tmp_user_values']['display_binary_as_hex'] = isset($_SESSION['tmp_user_values']['query'][$sql_md5]['display_binary_as_hex']) ? true : false;
  1941. $_SESSION['tmp_user_values']['display_blob'] = isset($_SESSION['tmp_user_values']['query'][$sql_md5]['display_blob']) ? true : false;
  1942. $_SESSION['tmp_user_values']['hide_transformation'] = isset($_SESSION['tmp_user_values']['query'][$sql_md5]['hide_transformation']) ? true : false;
  1943. $_SESSION['tmp_user_values']['pos'] = $_SESSION['tmp_user_values']['query'][$sql_md5]['pos'];
  1944. $_SESSION['tmp_user_values']['max_rows'] = $_SESSION['tmp_user_values']['query'][$sql_md5]['max_rows'];
  1945. $_SESSION['tmp_user_values']['repeat_cells'] = $_SESSION['tmp_user_values']['query'][$sql_md5]['repeat_cells'];
  1946. $_SESSION['tmp_user_values']['disp_direction'] = $_SESSION['tmp_user_values']['query'][$sql_md5]['disp_direction'];
  1947. /*
  1948. * debugging
  1949. echo '<pre>';
  1950. var_dump($_SESSION['tmp_user_values']);
  1951. echo '</pre>';
  1952. */
  1953. }
  1954. /**
  1955. * Displays a table of results returned by a SQL query.
  1956. * This function is called by the "sql.php" script.
  1957. *
  1958. * @param integer &$dt_result the link id associated to the query which results have
  1959. * to be displayed
  1960. * @param array &$the_disp_mode the display mode
  1961. * @param array $analyzed_sql the analyzed query
  1962. *
  1963. * @global string $db the database name
  1964. * @global string $table the table name
  1965. * @global string $goto the URL to go back in case of errors
  1966. * @global string $sql_query the current SQL query
  1967. * @global integer $num_rows the total number of rows returned by the
  1968. * SQL query
  1969. * @global integer $unlim_num_rows the total number of rows returned by the
  1970. * SQL query without any programmatically
  1971. * appended "LIMIT" clause
  1972. * @global array $fields_meta the list of fields properties
  1973. * @global integer $fields_cnt the total number of fields returned by
  1974. * the SQL query
  1975. * @global array $vertical_display informations used with vertical display
  1976. * mode
  1977. * @global array $highlight_columns column names to highlight
  1978. * @global array $cfgRelation the relation settings
  1979. * @global array $showtable table definitions
  1980. *
  1981. * @access private
  1982. *
  1983. * @see PMA_showMessage(), PMA_setDisplayMode(),
  1984. * PMA_displayTableNavigation(), PMA_displayTableHeaders(),
  1985. * PMA_displayTableBody(), PMA_displayResultsOperations()
  1986. *
  1987. * @return nothing
  1988. */
  1989. function PMA_displayTable(&$dt_result, &$the_disp_mode, $analyzed_sql)
  1990. {
  1991. global $db, $table, $goto;
  1992. global $sql_query, $num_rows, $unlim_num_rows, $fields_meta, $fields_cnt;
  1993. global $vertical_display, $highlight_columns;
  1994. global $cfgRelation;
  1995. global $showtable;
  1996. // why was this called here? (already called from sql.php)
  1997. //PMA_displayTable_checkConfigParams();
  1998. /**
  1999. * @todo move this to a central place
  2000. * @todo for other future table types
  2001. */
  2002. $is_innodb = (isset($showtable['Type']) && $showtable['Type'] == 'InnoDB');
  2003. if ($is_innodb
  2004. && ! isset($analyzed_sql[0]['queryflags']['union'])
  2005. && ! isset($analyzed_sql[0]['table_ref'][1]['table_name'])
  2006. && (empty($analyzed_sql[0]['where_clause']) || $analyzed_sql[0]['where_clause'] == '1 ')
  2007. ) {
  2008. // "j u s t b r o w s i n g"
  2009. $pre_count = '~';
  2010. $after_count = PMA_showHint(PMA_sanitize(__('May be approximate. See [a@./Documentation.html#faq3_11@Documentation]FAQ 3.11[/a]')));
  2011. } else {
  2012. $pre_count = '';
  2013. $after_count = '';
  2014. }
  2015. // 1. ----- Prepares the work -----
  2016. // 1.1 Gets the informations about which functionalities should be
  2017. // displayed
  2018. $total = '';
  2019. $is_display = PMA_setDisplayMode($the_disp_mode, $total);
  2020. // 1.2 Defines offsets for the next and previous pages
  2021. if ($is_display['nav_bar'] == '1') {
  2022. if ($_SESSION['tmp_user_values']['max_rows'] == 'all') {
  2023. $pos_next = 0;
  2024. $pos_prev = 0;
  2025. } else {
  2026. $pos_next = $_SESSION['tmp_user_values']['pos'] + $_SESSION['tmp_user_values']['max_rows'];
  2027. $pos_prev = $_SESSION['tmp_user_values']['pos'] - $_SESSION['tmp_user_values']['max_rows'];
  2028. if ($pos_prev < 0) {
  2029. $pos_prev = 0;
  2030. }
  2031. }
  2032. } // end if
  2033. // 1.3 Find the sort expression
  2034. // we need $sort_expression and $sort_expression_nodirection
  2035. // even if there are many table references
  2036. if (! empty($analyzed_sql[0]['order_by_clause'])) {
  2037. $sort_expression = trim(str_replace(' ', ' ', $analyzed_sql[0]['order_by_clause']));
  2038. /**
  2039. * Get rid of ASC|DESC
  2040. */
  2041. preg_match('@(.*)([[:space:]]*(ASC|DESC))@si', $sort_expression, $matches);
  2042. $sort_expression_nodirection = isset($matches[1]) ? trim($matches[1]) : $sort_expression;
  2043. $sort_direction = isset($matches[2]) ? trim($matches[2]) : '';
  2044. unset($matches);
  2045. } else {
  2046. $sort_expression = $sort_expression_nodirection = $sort_direction = '';
  2047. }
  2048. // 1.4 Prepares display of first and last value of the sorted column
  2049. if (! empty($sort_expression_nodirection)) {
  2050. if (strpos($sort_expression_nodirection, '.') === false) {
  2051. $sort_table = $table;
  2052. $sort_column = $sort_expression_nodirection;
  2053. } else {
  2054. list($sort_table, $sort_column) = explode('.', $sort_expression_nodirection);
  2055. }
  2056. $sort_table = PMA_unQuote($sort_table);
  2057. $sort_column = PMA_unQuote($sort_column);
  2058. // find the sorted column index in row result
  2059. // (this might be a multi-table query)
  2060. $sorted_column_index = false;
  2061. foreach ($fields_meta as $key => $meta) {
  2062. if ($meta->table == $sort_table && $meta->name == $sort_column) {
  2063. $sorted_column_index = $key;
  2064. break;
  2065. }
  2066. }
  2067. if ($sorted_column_index !== false) {
  2068. // fetch first row of the result set
  2069. $row = PMA_DBI_fetch_row($dt_result);
  2070. // initializing default arguments
  2071. $default_function = 'default_function';
  2072. $transform_function = $default_function;
  2073. $transform_options = array();
  2074. // check for non printable sorted row data
  2075. $meta = $fields_meta[$sorted_column_index];
  2076. if (stristr($meta->type, 'BLOB') || $meta->type == 'geometry') {
  2077. $column_for_first_row = PMA_handle_non_printable_contents($meta->type, $row[$sorted_column_index], $transform_function, $transform_options, $default_function, $meta, null);
  2078. } else {
  2079. $column_for_first_row = $row[$sorted_column_index];
  2080. }
  2081. $column_for_first_row = strtoupper(substr($column_for_first_row, 0, $GLOBALS['cfg']['LimitChars']));
  2082. // fetch last row of the result set
  2083. PMA_DBI_data_seek($dt_result, $num_rows - 1);
  2084. $row = PMA_DBI_fetch_row($dt_result);
  2085. // check for non printable sorted row data
  2086. $meta = $fields_meta[$sorted_column_index];
  2087. if (stristr($meta->type, 'BLOB') || $meta->type == 'geometry') {
  2088. $column_for_last_row = PMA_handle_non_printable_contents($meta->type, $row[$sorted_column_index], $transform_function, $transform_options, $default_function, $meta, null);
  2089. } else {
  2090. $column_for_last_row = $row[$sorted_column_index];
  2091. }
  2092. $column_for_last_row = strtoupper(substr($column_for_last_row, 0, $GLOBALS['cfg']['LimitChars']));
  2093. // reset to first row for the loop in PMA_displayTableBody()
  2094. PMA_DBI_data_seek($dt_result, 0);
  2095. // we could also use here $sort_expression_nodirection
  2096. $sorted_column_message = ' [' . htmlspecialchars($sort_column) . ': <strong>' . htmlspecialchars($column_for_first_row) . ' - ' . htmlspecialchars($column_for_last_row) . '</strong>]';
  2097. unset($row, $column_for_first_row, $column_for_last_row, $meta, $default_function, $transform_function, $transform_options);
  2098. }
  2099. unset($sorted_column_index, $sort_table, $sort_column);
  2100. }
  2101. // 2. ----- Displays the top of the page -----
  2102. // 2.1 Displays a messages with position informations
  2103. if ($is_display['nav_bar'] == '1' && isset($pos_next)) {
  2104. if (isset($unlim_num_rows) && $unlim_num_rows != $total) {
  2105. $selectstring = ', ' . $unlim_num_rows . ' ' . __('in query');
  2106. } else {
  2107. $selectstring = '';
  2108. }
  2109. if (! empty($analyzed_sql[0]['limit_clause'])) {
  2110. $limit_data = PMA_analyzeLimitClause($analyzed_sql[0]['limit_clause']);
  2111. $first_shown_rec = $limit_data['start'];
  2112. if ($limit_data['length'] < $total) {
  2113. $last_shown_rec = $limit_data['start'] + $limit_data['length'] - 1;
  2114. } else {
  2115. $last_shown_rec = $limit_data['start'] + $total - 1;
  2116. }
  2117. } elseif ($_SESSION['tmp_user_values']['max_rows'] == 'all' || $pos_next > $total) {
  2118. $first_shown_rec = $_SESSION['tmp_user_values']['pos'];
  2119. $last_shown_rec = $total - 1;
  2120. } else {
  2121. $first_shown_rec = $_SESSION['tmp_user_values']['pos'];
  2122. $last_shown_rec = $pos_next - 1;
  2123. }
  2124. if (PMA_Table::isView($db, $table)
  2125. && $total == $GLOBALS['cfg']['MaxExactCountViews']
  2126. ) {
  2127. $message = PMA_Message::notice(__('This view has at least this number of rows. Please refer to %sdocumentation%s.'));
  2128. $message->addParam('[a@./Documentation.html#cfg_MaxExactCount@_blank]');
  2129. $message->addParam('[/a]');
  2130. $message_view_warning = PMA_showHint($message);
  2131. } else {
  2132. $message_view_warning = false;
  2133. }
  2134. $message = PMA_Message::success(__('Showing rows'));
  2135. $message->addMessage($first_shown_rec);
  2136. if ($message_view_warning) {
  2137. $message->addMessage('...', ' - ');
  2138. $message->addMessage($message_view_warning);
  2139. $message->addMessage('(');
  2140. } else {
  2141. $message->addMessage($last_shown_rec, ' - ');
  2142. $message->addMessage(' (');
  2143. $message->addMessage($pre_count . PMA_formatNumber($total, 0));
  2144. $message->addString(__('total'));
  2145. if (!empty($after_count)) {
  2146. $message->addMessage($after_count);
  2147. }
  2148. $message->addMessage($selectstring, '');
  2149. $message->addMessage(', ', '');
  2150. }
  2151. $messagge_qt = PMA_Message::notice(__('Query took %01.4f sec'));
  2152. $messagge_qt->addParam($GLOBALS['querytime']);
  2153. $message->addMessage($messagge_qt, '');
  2154. $message->addMessage(')', '');
  2155. $message->addMessage(isset($sorted_column_message) ? $sorted_column_message : '', '');
  2156. PMA_showMessage($message, $sql_query, 'success');
  2157. } elseif (! isset($GLOBALS['printview']) || $GLOBALS['printview'] != '1') {
  2158. PMA_showMessage(__('Your SQL query has been executed successfully'), $sql_query, 'success');
  2159. }
  2160. // 2.3 Displays the navigation bars
  2161. if (! strlen($table)) {
  2162. if (isset($analyzed_sql[0]['query_type'])
  2163. && $analyzed_sql[0]['query_type'] == 'SELECT'
  2164. ) {
  2165. // table does not always contain a real table name,
  2166. // for example in MySQL 5.0.x, the query SHOW STATUS
  2167. // returns STATUS as a table name
  2168. $table = $fields_meta[0]->table;
  2169. } else {
  2170. $table = '';
  2171. }
  2172. }
  2173. if ($is_display['nav_bar'] == '1' && empty($analyzed_sql[0]['limit_clause'])) {
  2174. PMA_displayTableNavigation($pos_next, $pos_prev, $sql_query, 'top_direction_dropdown');
  2175. echo "\n";
  2176. } elseif (! isset($GLOBALS['printview']) || $GLOBALS['printview'] != '1') {
  2177. echo "\n" . '<br /><br />' . "\n";
  2178. }
  2179. // 2b ----- Get field references from Database -----
  2180. // (see the 'relation' configuration variable)
  2181. // initialize map
  2182. $map = array();
  2183. // find tables
  2184. $target=array();
  2185. if (isset($analyzed_sql[0]['table_ref']) && is_array($analyzed_sql[0]['table_ref'])) {
  2186. foreach ($analyzed_sql[0]['table_ref'] AS $table_ref_position => $table_ref) {
  2187. $target[] = $analyzed_sql[0]['table_ref'][$table_ref_position]['table_true_name'];
  2188. }
  2189. }
  2190. $tabs = '(\'' . join('\',\'', $target) . '\')';
  2191. if (! strlen($table)) {
  2192. $exist_rel = false;
  2193. } else {
  2194. // To be able to later display a link to the related table,
  2195. // we verify both types of relations: either those that are
  2196. // native foreign keys or those defined in the phpMyAdmin
  2197. // configuration storage. If no PMA storage, we won't be able
  2198. // to use the "column to display" notion (for example show
  2199. // the name related to a numeric id).
  2200. $exist_rel = PMA_getForeigners($db, $table, '', 'both');
  2201. if ($exist_rel) {
  2202. foreach ($exist_rel AS $master_field => $rel) {
  2203. $display_field = PMA_getDisplayField($rel['foreign_db'], $rel['foreign_table']);
  2204. $map[$master_field] = array($rel['foreign_table'],
  2205. $rel['foreign_field'],
  2206. $display_field,
  2207. $rel['foreign_db']);
  2208. } // end while
  2209. } // end if
  2210. } // end if
  2211. // end 2b
  2212. // 3. ----- Displays the results table -----
  2213. PMA_displayTableHeaders($is_display, $fields_meta, $fields_cnt, $analyzed_sql, $sort_expression, $sort_expression_nodirection, $sort_direction);
  2214. $url_query = '';
  2215. echo '<tbody>' . "\n";
  2216. $clause_is_unique = PMA_displayTableBody($dt_result, $is_display, $map, $analyzed_sql);
  2217. // vertical output case
  2218. if ($_SESSION['tmp_user_values']['disp_direction'] == 'vertical') {
  2219. PMA_displayVerticalTable();
  2220. } // end if
  2221. unset($vertical_display);
  2222. echo '</tbody>' . "\n";
  2223. ?>
  2224. </table>
  2225. <?php
  2226. // 4. ----- Displays the link for multi-fields edit and delete
  2227. if ($is_display['del_lnk'] == 'dr' && $is_display['del_lnk'] != 'kp') {
  2228. $delete_text = $is_display['del_lnk'] == 'dr' ? __('Delete') : __('Kill');
  2229. $_url_params = array(
  2230. 'db' => $db,
  2231. 'table' => $table,
  2232. 'sql_query' => $sql_query,
  2233. 'goto' => $goto,
  2234. );
  2235. $uncheckall_url = 'sql.php' . PMA_generate_common_url($_url_params);
  2236. $_url_params['checkall'] = '1';
  2237. $checkall_url = 'sql.php' . PMA_generate_common_url($_url_params);
  2238. if ($_SESSION['tmp_user_values']['disp_direction'] == 'vertical') {
  2239. $checkall_params['onclick'] = 'if (setCheckboxes(\'resultsForm\', true)) return false;';
  2240. $uncheckall_params['onclick'] = 'if (setCheckboxes(\'resultsForm\', false)) return false;';
  2241. } else {
  2242. $checkall_params['onclick'] = 'if (markAllRows(\'resultsForm\')) return false;';
  2243. $uncheckall_params['onclick'] = 'if (unMarkAllRows(\'resultsForm\')) return false;';
  2244. }
  2245. $checkall_link = PMA_linkOrButton($checkall_url, __('Check All'), $checkall_params, false);
  2246. $uncheckall_link = PMA_linkOrButton($uncheckall_url, __('Uncheck All'), $uncheckall_params, false);
  2247. if ($_SESSION['tmp_user_values']['disp_direction'] != 'vertical') {
  2248. echo '<img class="selectallarrow" width="38" height="22"'
  2249. .' src="' . $GLOBALS['pmaThemeImage'] . 'arrow_' . $GLOBALS['text_dir'] . '.png' . '"'
  2250. .' alt="' . __('With selected:') . '" />';
  2251. }
  2252. echo $checkall_link . "\n"
  2253. .' / ' . "\n"
  2254. .$uncheckall_link . "\n"
  2255. .'<i>' . __('With selected:') . '</i>' . "\n";
  2256. PMA_buttonOrImage(
  2257. 'submit_mult', 'mult_submit', 'submit_mult_change',
  2258. __('Change'), 'b_edit.png', 'edit'
  2259. );
  2260. PMA_buttonOrImage(
  2261. 'submit_mult', 'mult_submit', 'submit_mult_delete',
  2262. $delete_text, 'b_drop.png', 'delete'
  2263. );
  2264. if (isset($analyzed_sql[0]) && $analyzed_sql[0]['querytype'] == 'SELECT') {
  2265. PMA_buttonOrImage(
  2266. 'submit_mult', 'mult_submit', 'submit_mult_export',
  2267. __('Export'), 'b_tblexport.png', 'export'
  2268. );
  2269. }
  2270. echo "\n";
  2271. echo '<input type="hidden" name="sql_query"'
  2272. .' value="' . htmlspecialchars($sql_query) . '" />' . "\n";
  2273. if (! empty($GLOBALS['url_query'])) {
  2274. echo '<input type="hidden" name="url_query"'
  2275. .' value="' . $GLOBALS['url_query'] . '" />' . "\n";
  2276. }
  2277. echo '<input type="hidden" name="clause_is_unique"'
  2278. .' value="' . $clause_is_unique . '" />' . "\n";
  2279. echo '</form>' . "\n";
  2280. }
  2281. // 5. ----- Displays the navigation bar at the bottom if required -----
  2282. if ($is_display['nav_bar'] == '1' && empty($analyzed_sql[0]['limit_clause'])) {
  2283. echo '<br />' . "\n";
  2284. PMA_displayTableNavigation($pos_next, $pos_prev, $sql_query, 'bottom_direction_dropdown');
  2285. } elseif (! isset($GLOBALS['printview']) || $GLOBALS['printview'] != '1') {
  2286. echo "\n" . '<br /><br />' . "\n";
  2287. }
  2288. // 6. ----- Displays "Query results operations"
  2289. if (! isset($GLOBALS['printview']) || $GLOBALS['printview'] != '1') {
  2290. PMA_displayResultsOperations($the_disp_mode, $analyzed_sql);
  2291. }
  2292. } // end of the 'PMA_displayTable()' function
  2293. function default_function($buffer)
  2294. {
  2295. $buffer = htmlspecialchars($buffer);
  2296. $buffer = str_replace("\011", ' &nbsp;&nbsp;&nbsp;', str_replace(' ', ' &nbsp;', $buffer));
  2297. $buffer = preg_replace("@((\015\012)|(\015)|(\012))@", '<br />', $buffer);
  2298. return $buffer;
  2299. }
  2300. /**
  2301. * Displays operations that are available on results.
  2302. *
  2303. * @param array $the_disp_mode the display mode
  2304. * @param array $analyzed_sql the analyzed query
  2305. *
  2306. * @global string $db the database name
  2307. * @global string $table the table name
  2308. * @global string $sql_query the current SQL query
  2309. * @global integer $unlim_num_rows the total number of rows returned by the
  2310. * SQL query without any programmatically
  2311. * appended "LIMIT" clause
  2312. *
  2313. * @access private
  2314. *
  2315. * @see PMA_showMessage(), PMA_setDisplayMode(),
  2316. * PMA_displayTableNavigation(), PMA_displayTableHeaders(),
  2317. * PMA_displayTableBody(), PMA_displayResultsOperations()
  2318. *
  2319. * @return nothing
  2320. */
  2321. function PMA_displayResultsOperations($the_disp_mode, $analyzed_sql)
  2322. {
  2323. global $db, $table, $sql_query, $unlim_num_rows, $fields_meta;
  2324. $header_shown = false;
  2325. $header = '<fieldset><legend>' . __('Query results operations') . '</legend>';
  2326. if ($the_disp_mode[6] == '1' || $the_disp_mode[9] == '1') {
  2327. // Displays "printable view" link if required
  2328. if ($the_disp_mode[9] == '1') {
  2329. if (!$header_shown) {
  2330. echo $header;
  2331. $header_shown = true;
  2332. }
  2333. $_url_params = array(
  2334. 'db' => $db,
  2335. 'table' => $table,
  2336. 'printview' => '1',
  2337. 'sql_query' => $sql_query,
  2338. );
  2339. $url_query = PMA_generate_common_url($_url_params);
  2340. echo PMA_linkOrButton(
  2341. 'sql.php' . $url_query,
  2342. PMA_getIcon('b_print.png', __('Print view'), true),
  2343. '', true, true, 'print_view'
  2344. ) . "\n";
  2345. if ($_SESSION['tmp_user_values']['display_text']) {
  2346. $_url_params['display_text'] = 'F';
  2347. echo PMA_linkOrButton(
  2348. 'sql.php' . PMA_generate_common_url($_url_params),
  2349. PMA_getIcon('b_print.png', __('Print view (with full texts)'), true),
  2350. '', true, true, 'print_view'
  2351. ) . "\n";
  2352. unset($_url_params['display_text']);
  2353. }
  2354. } // end displays "printable view"
  2355. }
  2356. // Export link
  2357. // (the url_query has extra parameters that won't be used to export)
  2358. // (the single_table parameter is used in display_export.lib.php
  2359. // to hide the SQL and the structure export dialogs)
  2360. // If the parser found a PROCEDURE clause
  2361. // (most probably PROCEDURE ANALYSE()) it makes no sense to
  2362. // display the Export link).
  2363. if (isset($analyzed_sql[0]) && $analyzed_sql[0]['querytype'] == 'SELECT' && ! isset($printview) && ! isset($analyzed_sql[0]['queryflags']['procedure'])) {
  2364. if (isset($analyzed_sql[0]['table_ref'][0]['table_true_name']) && ! isset($analyzed_sql[0]['table_ref'][1]['table_true_name'])) {
  2365. $_url_params['single_table'] = 'true';
  2366. }
  2367. if (!$header_shown) {
  2368. echo $header;
  2369. $header_shown = true;
  2370. }
  2371. $_url_params['unlim_num_rows'] = $unlim_num_rows;
  2372. /**
  2373. * At this point we don't know the table name; this can happen
  2374. * for example with a query like
  2375. * SELECT bike_code FROM (SELECT bike_code FROM bikes) tmp
  2376. * As a workaround we set in the table parameter the name of the
  2377. * first table of this database, so that tbl_export.php and
  2378. * the script it calls do not fail
  2379. */
  2380. if (empty($_url_params['table']) && !empty($_url_params['db'])) {
  2381. $_url_params['table'] = PMA_DBI_fetch_value("SHOW TABLES");
  2382. /* No result (probably no database selected) */
  2383. if ($_url_params['table'] === false) {
  2384. unset($_url_params['table']);
  2385. }
  2386. }
  2387. echo PMA_linkOrButton(
  2388. 'tbl_export.php' . PMA_generate_common_url($_url_params),
  2389. PMA_getIcon('b_tblexport.png', __('Export'), true),
  2390. '', true, true, ''
  2391. ) . "\n";
  2392. // show chart
  2393. echo PMA_linkOrButton(
  2394. 'tbl_chart.php' . PMA_generate_common_url($_url_params),
  2395. PMA_getIcon('b_chart.png', __('Display chart'), true),
  2396. '', true, true, ''
  2397. ) . "\n";
  2398. // show GIS chart
  2399. $geometry_found = false;
  2400. // If atleast one geometry field is found
  2401. foreach ($fields_meta as $meta) {
  2402. if ($meta->type == 'geometry') {
  2403. $geometry_found = true;
  2404. break;
  2405. }
  2406. }
  2407. if ($geometry_found) {
  2408. echo PMA_linkOrButton(
  2409. 'tbl_gis_visualization.php' . PMA_generate_common_url($_url_params),
  2410. PMA_getIcon('b_globe.gif', __('Visualize GIS data'), true),
  2411. '', true, true, ''
  2412. ) . "\n";
  2413. }
  2414. }
  2415. // CREATE VIEW
  2416. /**
  2417. *
  2418. * @todo detect privileges to create a view
  2419. * (but see 2006-01-19 note in display_create_table.lib.php,
  2420. * I think we cannot detect db-specific privileges reliably)
  2421. * Note: we don't display a Create view link if we found a PROCEDURE clause
  2422. */
  2423. if (!$header_shown) {
  2424. echo $header;
  2425. $header_shown = true;
  2426. }
  2427. if (!PMA_DRIZZLE && !isset($analyzed_sql[0]['queryflags']['procedure'])) {
  2428. echo PMA_linkOrButton(
  2429. 'view_create.php' . $url_query,
  2430. PMA_getIcon('b_views.png', __('Create view'), true),
  2431. '', true, true, ''
  2432. ) . "\n";
  2433. }
  2434. if ($header_shown) {
  2435. echo '</fieldset><br />';
  2436. }
  2437. }
  2438. /**
  2439. * Verifies what to do with non-printable contents (binary or BLOB)
  2440. * in Browse mode.
  2441. *
  2442. * @param string $category BLOB|BINARY|GEOMETRY
  2443. * @param string $content the binary content
  2444. * @param string $transform_function transformation function
  2445. * @param string $transform_options transformation parameters
  2446. * @param string $default_function default transformation function
  2447. * @param object $meta the meta-information about this field
  2448. * @param array $url_params parameters that should go to the download link
  2449. *
  2450. * @return mixed string or float
  2451. */
  2452. function PMA_handle_non_printable_contents($category, $content, $transform_function, $transform_options, $default_function, $meta, $url_params = array())
  2453. {
  2454. $result = '[' . $category;
  2455. if (is_null($content)) {
  2456. $result .= ' - NULL';
  2457. $size = 0;
  2458. } elseif (isset($content)) {
  2459. $size = strlen($content);
  2460. $display_size = PMA_formatByteDown($size, 3, 1);
  2461. $result .= ' - '. $display_size[0] . ' ' . $display_size[1];
  2462. }
  2463. $result .= ']';
  2464. if (strpos($transform_function, 'octetstream')) {
  2465. $result = $content;
  2466. }
  2467. if ($size > 0) {
  2468. if ($default_function != $transform_function) {
  2469. $result = $transform_function($result, $transform_options, $meta);
  2470. } else {
  2471. $result = $default_function($result, array(), $meta);
  2472. if (stristr($meta->type, 'BLOB') && $_SESSION['tmp_user_values']['display_blob']) {
  2473. // in this case, restart from the original $content
  2474. $result = htmlspecialchars(PMA_replace_binary_contents($content));
  2475. }
  2476. /* Create link to download */
  2477. if (count($url_params) > 0) {
  2478. $result = '<a href="tbl_get_field.php' . PMA_generate_common_url($url_params) . '">' . $result . '</a>';
  2479. }
  2480. }
  2481. }
  2482. return($result);
  2483. }
  2484. /**
  2485. * Prepares the displayable content of a data cell in Browse mode,
  2486. * taking into account foreign key description field and transformations
  2487. *
  2488. * @param string $class css classes for the td element
  2489. * @param bool $condition_field whether the column is a part of the where clause
  2490. * @param string $analyzed_sql the analyzed query
  2491. * @param object $meta the meta-information about this field
  2492. * @param array $map the list of relations
  2493. * @param string $data data
  2494. * @param string $transform_function transformation function
  2495. * @param string $default_function default function
  2496. * @param string $nowrap 'nowrap' if the content should not be wrapped
  2497. * @param string $where_comparison data for the where cluase
  2498. * @param array $transform_options array of options for transformation
  2499. * @param bool $is_field_truncated whether the field is truncated
  2500. *
  2501. * @return string formatted data
  2502. */
  2503. function PMA_prepare_row_data($class, $condition_field, $analyzed_sql, $meta, $map, $data, $transform_function, $default_function, $nowrap, $where_comparison, $transform_options, $is_field_truncated )
  2504. {
  2505. $result = ' class="' . PMA_addClass($class, $condition_field, $meta, $nowrap, $is_field_truncated, $transform_function, $default_function) . '">';
  2506. if (isset($analyzed_sql[0]['select_expr']) && is_array($analyzed_sql[0]['select_expr'])) {
  2507. foreach ($analyzed_sql[0]['select_expr'] AS $select_expr_position => $select_expr) {
  2508. $alias = $analyzed_sql[0]['select_expr'][$select_expr_position]['alias'];
  2509. if (isset($alias) && strlen($alias)) {
  2510. $true_column = $analyzed_sql[0]['select_expr'][$select_expr_position]['column'];
  2511. if ($alias == $meta->name) {
  2512. // this change in the parameter does not matter
  2513. // outside of the function
  2514. $meta->name = $true_column;
  2515. } // end if
  2516. } // end if
  2517. } // end foreach
  2518. } // end if
  2519. if (isset($map[$meta->name])) {
  2520. // Field to display from the foreign table?
  2521. if (isset($map[$meta->name][2]) && strlen($map[$meta->name][2])) {
  2522. $dispsql = 'SELECT ' . PMA_backquote($map[$meta->name][2])
  2523. . ' FROM ' . PMA_backquote($map[$meta->name][3])
  2524. . '.' . PMA_backquote($map[$meta->name][0])
  2525. . ' WHERE ' . PMA_backquote($map[$meta->name][1])
  2526. . $where_comparison;
  2527. $dispresult = PMA_DBI_try_query($dispsql, null, PMA_DBI_QUERY_STORE);
  2528. if ($dispresult && PMA_DBI_num_rows($dispresult) > 0) {
  2529. list($dispval) = PMA_DBI_fetch_row($dispresult, 0);
  2530. } else {
  2531. $dispval = __('Link not found');
  2532. }
  2533. @PMA_DBI_free_result($dispresult);
  2534. } else {
  2535. $dispval = '';
  2536. } // end if... else...
  2537. if (isset($GLOBALS['printview']) && $GLOBALS['printview'] == '1') {
  2538. $result .= ($transform_function != $default_function ? $transform_function($data, $transform_options, $meta) : $transform_function($data, array(), $meta)) . ' <code>[-&gt;' . $dispval . ']</code>';
  2539. } else {
  2540. if ('K' == $_SESSION['tmp_user_values']['relational_display']) {
  2541. // user chose "relational key" in the display options, so
  2542. // the title contains the display field
  2543. $title = (! empty($dispval))? ' title="' . htmlspecialchars($dispval) . '"' : '';
  2544. } else {
  2545. $title = ' title="' . htmlspecialchars($data) . '"';
  2546. }
  2547. $_url_params = array(
  2548. 'db' => $map[$meta->name][3],
  2549. 'table' => $map[$meta->name][0],
  2550. 'pos' => '0',
  2551. 'sql_query' => 'SELECT * FROM '
  2552. . PMA_backquote($map[$meta->name][3]) . '.' . PMA_backquote($map[$meta->name][0])
  2553. . ' WHERE ' . PMA_backquote($map[$meta->name][1])
  2554. . $where_comparison,
  2555. );
  2556. $result .= '<a href="sql.php' . PMA_generate_common_url($_url_params)
  2557. . '"' . $title . '>';
  2558. if ($transform_function != $default_function) {
  2559. // always apply a transformation on the real data,
  2560. // not on the display field
  2561. $result .= $transform_function($data, $transform_options, $meta);
  2562. } else {
  2563. if ('D' == $_SESSION['tmp_user_values']['relational_display']) {
  2564. // user chose "relational display field" in the
  2565. // display options, so show display field in the cell
  2566. $result .= $transform_function($dispval, array(), $meta);
  2567. } else {
  2568. // otherwise display data in the cell
  2569. $result .= $transform_function($data, array(), $meta);
  2570. }
  2571. }
  2572. $result .= '</a>';
  2573. }
  2574. } else {
  2575. $result .= ($transform_function != $default_function ? $transform_function($data, $transform_options, $meta) : $transform_function($data, array(), $meta));
  2576. }
  2577. $result .= '</td>' . "\n";
  2578. return $result;
  2579. }
  2580. /**
  2581. * Generates a checkbox for multi-row submits
  2582. *
  2583. * @param string $del_url delete url
  2584. * @param array $is_display array with explicit indexes for all the display elements
  2585. * @param string $row_no the row number
  2586. * @param string $where_clause_html url encoded where cluase
  2587. * @param array $condition_array array of conditions in the where cluase
  2588. * @param string $del_query delete query
  2589. * @param string $id_suffix suffix for the id
  2590. * @param string $class css classes for the td element
  2591. *
  2592. * @return string the generated HTML
  2593. */
  2594. function PMA_generateCheckboxForMulti($del_url, $is_display, $row_no, $where_clause_html, $condition_array, $del_query, $id_suffix, $class)
  2595. {
  2596. $ret = '';
  2597. if (! empty($del_url) && $is_display['del_lnk'] != 'kp') {
  2598. $ret .= '<td ';
  2599. if (! empty($class)) {
  2600. $ret .= 'class="' . $class . '"';
  2601. }
  2602. $ret .= ' align="center">'
  2603. . '<input type="checkbox" id="id_rows_to_delete' . $row_no . $id_suffix . '" name="rows_to_delete[' . $where_clause_html . ']"'
  2604. . ' class="multi_checkbox"'
  2605. . ' value="' . htmlspecialchars($del_query) . '" ' . (isset($GLOBALS['checkall']) ? 'checked="checked"' : '') . ' />'
  2606. . '<input type="hidden" class="condition_array" value="' . htmlspecialchars(json_encode($condition_array)) . '" />'
  2607. . ' </td>';
  2608. }
  2609. return $ret;
  2610. }
  2611. /**
  2612. * Generates an Edit link
  2613. *
  2614. * @param string $edit_url edit url
  2615. * @param string $class css classes for td element
  2616. * @param string $edit_str text for the edit link
  2617. * @param string $where_clause where cluase
  2618. * @param string $where_clause_html url encoded where cluase
  2619. *
  2620. * @return string the generated HTML
  2621. */
  2622. function PMA_generateEditLink($edit_url, $class, $edit_str, $where_clause, $where_clause_html)
  2623. {
  2624. $ret = '';
  2625. if (! empty($edit_url)) {
  2626. $ret .= '<td class="' . $class . '" align="center" ' . ' ><span class="nowrap">'
  2627. . PMA_linkOrButton($edit_url, $edit_str, array(), false);
  2628. /*
  2629. * Where clause for selecting this row uniquely is provided as
  2630. * a hidden input. Used by jQuery scripts for handling grid editing
  2631. */
  2632. if (! empty($where_clause)) {
  2633. $ret .= '<input type="hidden" class="where_clause" value ="' . $where_clause_html . '" />';
  2634. }
  2635. $ret .= '</span></td>';
  2636. }
  2637. return $ret;
  2638. }
  2639. /**
  2640. * Generates an Copy link
  2641. *
  2642. * @param string $copy_url copy url
  2643. * @param string $copy_str text for the copy link
  2644. * @param string $where_clause where clause
  2645. * @param string $where_clause_html url encoded where cluase
  2646. * @param string $class css classes for the td element
  2647. *
  2648. * @return string the generated HTML
  2649. */
  2650. function PMA_generateCopyLink($copy_url, $copy_str, $where_clause, $where_clause_html, $class)
  2651. {
  2652. $ret = '';
  2653. if (! empty($copy_url)) {
  2654. $ret .= '<td ';
  2655. if (! empty($class)) {
  2656. $ret .= 'class="' . $class . '" ';
  2657. }
  2658. $ret .= 'align="center" ' . ' ><span class="nowrap">'
  2659. . PMA_linkOrButton($copy_url, $copy_str, array(), false);
  2660. /*
  2661. * Where clause for selecting this row uniquely is provided as
  2662. * a hidden input. Used by jQuery scripts for handling grid editing
  2663. */
  2664. if (! empty($where_clause)) {
  2665. $ret .= '<input type="hidden" class="where_clause" value ="' . $where_clause_html . '" />';
  2666. }
  2667. $ret .= '</span></td>';
  2668. }
  2669. return $ret;
  2670. }
  2671. /**
  2672. * Generates a Delete link
  2673. *
  2674. * @param string $del_url delete url
  2675. * @param string $del_str text for the delete link
  2676. * @param string $js_conf text for the JS confirmation
  2677. * @param string $class css classes for the td element
  2678. *
  2679. * @return string the generated HTML
  2680. */
  2681. function PMA_generateDeleteLink($del_url, $del_str, $js_conf, $class)
  2682. {
  2683. $ret = '';
  2684. if (! empty($del_url)) {
  2685. $ret .= '<td ';
  2686. if (! empty($class)) {
  2687. $ret .= 'class="' . $class . '" ';
  2688. }
  2689. $ret .= 'align="center" ' . ' >'
  2690. . PMA_linkOrButton($del_url, $del_str, $js_conf, false)
  2691. . '</td>';
  2692. }
  2693. return $ret;
  2694. }
  2695. /**
  2696. * Generates checkbox and links at some position (left or right)
  2697. * (only called for horizontal mode)
  2698. *
  2699. * @param string $position the position of the checkbox and links
  2700. * @param string $del_url delete url
  2701. * @param array $is_display array with explicit indexes for all the display elements
  2702. * @param string $row_no row number
  2703. * @param string $where_clause where clause
  2704. * @param string $where_clause_html url encoded where cluase
  2705. * @param array $condition_array array of conditions in the where cluase
  2706. * @param string $del_query delete query
  2707. * @param string $id_suffix suffix for the id
  2708. * @param string $edit_url edit url
  2709. * @param string $copy_url copy url
  2710. * @param string $class css classes for the td elements
  2711. * @param string $edit_str text for the edit link
  2712. * @param string $copy_str text for the copy link
  2713. * @param string $del_str text for the delete link
  2714. * @param string $js_conf text for the JS confirmation
  2715. *
  2716. * @return string the generated HTML
  2717. */
  2718. function PMA_generateCheckboxAndLinks($position, $del_url, $is_display, $row_no, $where_clause, $where_clause_html, $condition_array, $del_query, $id_suffix, $edit_url, $copy_url, $class, $edit_str, $copy_str, $del_str, $js_conf)
  2719. {
  2720. $ret = '';
  2721. if ($position == 'left') {
  2722. $ret .= PMA_generateCheckboxForMulti($del_url, $is_display, $row_no, $where_clause_html, $condition_array, $del_query, $id_suffix = '_left', '', '', '');
  2723. $ret .= PMA_generateEditLink($edit_url, $class, $edit_str, $where_clause, $where_clause_html, '');
  2724. $ret .= PMA_generateCopyLink($copy_url, $copy_str, $where_clause, $where_clause_html, '');
  2725. $ret .= PMA_generateDeleteLink($del_url, $del_str, $js_conf, '', '');
  2726. } elseif ($position == 'right') {
  2727. $ret .= PMA_generateDeleteLink($del_url, $del_str, $js_conf, '', '');
  2728. $ret .= PMA_generateCopyLink($copy_url, $copy_str, $where_clause, $where_clause_html, '');
  2729. $ret .= PMA_generateEditLink($edit_url, $class, $edit_str, $where_clause, $where_clause_html, '');
  2730. $ret .= PMA_generateCheckboxForMulti($del_url, $is_display, $row_no, $where_clause_html, $condition_array, $del_query, $id_suffix = '_right', '', '', '');
  2731. } else { // $position == 'none'
  2732. $ret .= PMA_generateCheckboxForMulti($del_url, $is_display, $row_no, $where_clause_html, $condition_array, $del_query, $id_suffix = '_left', '', '', '');
  2733. }
  2734. return $ret;
  2735. }
  2736. ?>