PageRenderTime 50ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 1ms

/pma/libraries/display_tbl.lib.php

https://bitbucket.org/StasPiv/playzone
PHP | 2316 lines | 1527 code | 238 blank | 551 comment | 622 complexity | b74bfdb4cbd90be77285bdfcee93f5db MD5 | raw file
Possible License(s): Apache-2.0, BSD-3-Clause, GPL-2.0, LGPL-2.1

Large files files are truncated, but you can click here to view the full file

  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. * @version $Id: display_tbl.lib.php 12390 2009-05-04 16:05:24Z lem9 $
  7. * @package phpMyAdmin
  8. */
  9. /**
  10. *
  11. */
  12. require_once './libraries/Table.class.php';
  13. require_once './libraries/Index.class.php';
  14. /**
  15. * Defines the display mode to use for the results of a SQL query
  16. *
  17. * It uses a synthetic string that contains all the required informations.
  18. * In this string:
  19. * - the first two characters stand for the action to do while
  20. * clicking on the "edit" link (e.g. 'ur' for update a row, 'nn' for no
  21. * edit link...);
  22. * - the next two characters stand for the action to do while
  23. * clicking on the "delete" link (e.g. 'kp' for kill a process, 'nn' for
  24. * no delete link...);
  25. * - the next characters are boolean values (1/0) and respectively stand
  26. * for sorting links, navigation bar, "insert a new row" link, the
  27. * bookmark feature, the expand/collapse text/blob fields button and
  28. * the "display printable view" option.
  29. * Of course '0'/'1' means the feature won't/will be enabled.
  30. *
  31. * @param string the synthetic value for display_mode (see a few
  32. * lines above for explanations)
  33. * @param integer the total number of rows returned by the SQL query
  34. * without any programmatically appended "LIMIT" clause
  35. * (just a copy of $unlim_num_rows if it exists, else
  36. * computed inside this function)
  37. *
  38. * @return array an array with explicit indexes for all the display
  39. * elements
  40. *
  41. * @global string the database name
  42. * @global string the table name
  43. * @global integer the total number of rows returned by the SQL query
  44. * without any programmatically appended "LIMIT" clause
  45. * @global array the properties of the fields returned by the query
  46. * @global string the URL to return to in case of error in a SQL
  47. * statement
  48. *
  49. * @access private
  50. *
  51. * @see PMA_displayTable()
  52. */
  53. function PMA_setDisplayMode(&$the_disp_mode, &$the_total)
  54. {
  55. global $db, $table;
  56. global $unlim_num_rows, $fields_meta;
  57. global $err_url;
  58. // 1. Initializes the $do_display array
  59. $do_display = array();
  60. $do_display['edit_lnk'] = $the_disp_mode[0] . $the_disp_mode[1];
  61. $do_display['del_lnk'] = $the_disp_mode[2] . $the_disp_mode[3];
  62. $do_display['sort_lnk'] = (string) $the_disp_mode[4];
  63. $do_display['nav_bar'] = (string) $the_disp_mode[5];
  64. $do_display['ins_row'] = (string) $the_disp_mode[6];
  65. $do_display['bkm_form'] = (string) $the_disp_mode[7];
  66. $do_display['text_btn'] = (string) $the_disp_mode[8];
  67. $do_display['pview_lnk'] = (string) $the_disp_mode[9];
  68. // 2. Display mode is not "false for all elements" -> updates the
  69. // display mode
  70. if ($the_disp_mode != 'nnnn000000') {
  71. // 2.0 Print view -> set all elements to false!
  72. if (isset($GLOBALS['printview']) && $GLOBALS['printview'] == '1') {
  73. $do_display['edit_lnk'] = 'nn'; // no edit link
  74. $do_display['del_lnk'] = 'nn'; // no delete link
  75. $do_display['sort_lnk'] = (string) '0';
  76. $do_display['nav_bar'] = (string) '0';
  77. $do_display['ins_row'] = (string) '0';
  78. $do_display['bkm_form'] = (string) '0';
  79. $do_display['text_btn'] = (string) '0';
  80. $do_display['pview_lnk'] = (string) '0';
  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. elseif ($GLOBALS['is_count'] || $GLOBALS['is_analyse'] || $GLOBALS['is_maint'] || $GLOBALS['is_explain']) {
  86. $do_display['edit_lnk'] = 'nn'; // no edit link
  87. $do_display['del_lnk'] = 'nn'; // no delete link
  88. $do_display['sort_lnk'] = (string) '0';
  89. $do_display['nav_bar'] = (string) '0';
  90. $do_display['ins_row'] = (string) '0';
  91. $do_display['bkm_form'] = (string) '1';
  92. if ($GLOBALS['is_maint']) {
  93. $do_display['text_btn'] = (string) '1';
  94. } else {
  95. $do_display['text_btn'] = (string) '0';
  96. }
  97. $do_display['pview_lnk'] = (string) '1';
  98. }
  99. // 2.2 Statement is a "SHOW..."
  100. elseif ($GLOBALS['is_show']) {
  101. /**
  102. * 2.2.1
  103. * @todo defines edit/delete links depending on show statement
  104. */
  105. $tmp = preg_match('@^SHOW[[:space:]]+(VARIABLES|(FULL[[:space:]]+)?PROCESSLIST|STATUS|TABLE|GRANTS|CREATE|LOGS|DATABASES|FIELDS)@i', $GLOBALS['sql_query'], $which);
  106. if (isset($which[1]) && strpos(' ' . strtoupper($which[1]), 'PROCESSLIST') > 0) {
  107. $do_display['edit_lnk'] = 'nn'; // no edit link
  108. $do_display['del_lnk'] = 'kp'; // "kill process" type edit link
  109. } else {
  110. // Default case -> no links
  111. $do_display['edit_lnk'] = 'nn'; // no edit link
  112. $do_display['del_lnk'] = 'nn'; // no delete link
  113. }
  114. // 2.2.2 Other settings
  115. $do_display['sort_lnk'] = (string) '0';
  116. $do_display['nav_bar'] = (string) '0';
  117. $do_display['ins_row'] = (string) '0';
  118. $do_display['bkm_form'] = (string) '1';
  119. $do_display['text_btn'] = (string) '1';
  120. $do_display['pview_lnk'] = (string) '1';
  121. }
  122. // 2.3 Other statements (ie "SELECT" ones) -> updates
  123. // $do_display['edit_lnk'], $do_display['del_lnk'] and
  124. // $do_display['text_btn'] (keeps other default values)
  125. else {
  126. $prev_table = $fields_meta[0]->table;
  127. $do_display['text_btn'] = (string) '1';
  128. for ($i = 0; $i < $GLOBALS['fields_cnt']; $i++) {
  129. $is_link = ($do_display['edit_lnk'] != 'nn'
  130. || $do_display['del_lnk'] != 'nn'
  131. || $do_display['sort_lnk'] != '0'
  132. || $do_display['ins_row'] != '0');
  133. // 2.3.2 Displays edit/delete/sort/insert links?
  134. if ($is_link
  135. && ($fields_meta[$i]->table == '' || $fields_meta[$i]->table != $prev_table)) {
  136. $do_display['edit_lnk'] = 'nn'; // don't display links
  137. $do_display['del_lnk'] = 'nn';
  138. /**
  139. * @todo May be problematic with same fields names in two joined table.
  140. */
  141. // $do_display['sort_lnk'] = (string) '0';
  142. $do_display['ins_row'] = (string) '0';
  143. if ($do_display['text_btn'] == '1') {
  144. break;
  145. }
  146. } // end if (2.3.2)
  147. // 2.3.3 Always display print view link
  148. $do_display['pview_lnk'] = (string) '1';
  149. $prev_table = $fields_meta[$i]->table;
  150. } // end for
  151. } // end if..elseif...else (2.1 -> 2.3)
  152. } // end if (2)
  153. // 3. Gets the total number of rows if it is unknown
  154. if (isset($unlim_num_rows) && $unlim_num_rows != '') {
  155. $the_total = $unlim_num_rows;
  156. } elseif (($do_display['nav_bar'] == '1' || $do_display['sort_lnk'] == '1')
  157. && (strlen($db) && !empty($table))) {
  158. $the_total = PMA_Table::countRecords($db, $table, true);
  159. }
  160. // 4. If navigation bar or sorting fields names URLs should be
  161. // displayed but there is only one row, change these settings to
  162. // false
  163. if ($do_display['nav_bar'] == '1' || $do_display['sort_lnk'] == '1') {
  164. // - Do not display sort links if less than 2 rows.
  165. // - For a VIEW we (probably) did not count the number of rows
  166. // so don't test this number here, it would remove the possibility
  167. // of sorting VIEW results.
  168. if (isset($unlim_num_rows) && $unlim_num_rows < 2 && ! PMA_Table::isView($db, $table)) {
  169. // garvin: force display of navbar for vertical/horizontal display-choice.
  170. // $do_display['nav_bar'] = (string) '0';
  171. $do_display['sort_lnk'] = (string) '0';
  172. }
  173. } // end if (3)
  174. // 5. Updates the synthetic var
  175. $the_disp_mode = join('', $do_display);
  176. return $do_display;
  177. } // end of the 'PMA_setDisplayMode()' function
  178. /**
  179. * Displays a navigation bar to browse among the results of a SQL query
  180. *
  181. * @uses $_SESSION['userconf']['disp_direction']
  182. * @uses $_SESSION['userconf']['repeat_cells']
  183. * @uses $_SESSION['userconf']['max_rows']
  184. * @uses $_SESSION['userconf']['pos']
  185. * @param integer the offset for the "next" page
  186. * @param integer the offset for the "previous" page
  187. * @param string the URL-encoded query
  188. *
  189. * @global string $db the database name
  190. * @global string $table the table name
  191. * @global string $goto the URL to go back in case of errors
  192. * @global integer $num_rows the total number of rows returned by the
  193. * SQL query
  194. * @global integer $unlim_num_rows the total number of rows returned by the
  195. * SQL any programmatically appended "LIMIT" clause
  196. * @global boolean $is_innodb whether its InnoDB or not
  197. * @global array $showtable table definitions
  198. *
  199. * @access private
  200. *
  201. * @see PMA_displayTable()
  202. */
  203. function PMA_displayTableNavigation($pos_next, $pos_prev, $sql_query)
  204. {
  205. global $db, $table, $goto;
  206. global $num_rows, $unlim_num_rows;
  207. global $is_innodb;
  208. global $showtable;
  209. // here, using htmlentities() would cause problems if the query
  210. // contains accented characters
  211. $html_sql_query = htmlspecialchars($sql_query);
  212. /**
  213. * @todo move this to a central place
  214. * @todo for other future table types
  215. */
  216. $is_innodb = (isset($showtable['Type']) && $showtable['Type'] == 'InnoDB');
  217. ?>
  218. <!-- Navigation bar -->
  219. <table border="0" cellpadding="2" cellspacing="0">
  220. <tr>
  221. <?php
  222. // Move to the beginning or to the previous page
  223. if ($_SESSION['userconf']['pos'] && $_SESSION['userconf']['max_rows'] != 'all') {
  224. // loic1: patch #474210 from Gosha Sakovich - part 1
  225. if ($GLOBALS['cfg']['NavigationBarIconic']) {
  226. $caption1 = '&lt;&lt;';
  227. $caption2 = ' &lt; ';
  228. $title1 = ' title="' . $GLOBALS['strPos1'] . '"';
  229. $title2 = ' title="' . $GLOBALS['strPrevious'] . '"';
  230. } else {
  231. $caption1 = $GLOBALS['strPos1'] . ' &lt;&lt;';
  232. $caption2 = $GLOBALS['strPrevious'] . ' &lt;';
  233. $title1 = '';
  234. $title2 = '';
  235. } // end if... else...
  236. ?>
  237. <td>
  238. <form action="sql.php" method="post">
  239. <?php echo PMA_generate_common_hidden_inputs($db, $table); ?>
  240. <input type="hidden" name="sql_query" value="<?php echo $html_sql_query; ?>" />
  241. <input type="hidden" name="pos" value="0" />
  242. <input type="hidden" name="goto" value="<?php echo $goto; ?>" />
  243. <input type="submit" name="navig" value="<?php echo $caption1; ?>"<?php echo $title1; ?> />
  244. </form>
  245. </td>
  246. <td>
  247. <form action="sql.php" method="post">
  248. <?php echo PMA_generate_common_hidden_inputs($db, $table); ?>
  249. <input type="hidden" name="sql_query" value="<?php echo $html_sql_query; ?>" />
  250. <input type="hidden" name="pos" value="<?php echo $pos_prev; ?>" />
  251. <input type="hidden" name="goto" value="<?php echo $goto; ?>" />
  252. <input type="submit" name="navig" value="<?php echo $caption2; ?>"<?php echo $title2; ?> />
  253. </form>
  254. </td>
  255. <?php
  256. } // end move back
  257. ?>
  258. <td>
  259. &nbsp;&nbsp;&nbsp;
  260. </td>
  261. <td align="center">
  262. <?php // if displaying a VIEW, $unlim_num_rows could be zero because
  263. // of $cfg['MaxExactCountViews']; in this case, avoid passing
  264. // the 5th parameter to checkFormElementInRange()
  265. // (this means we can't validate the upper limit ?>
  266. <form action="sql.php" method="post"
  267. onsubmit="return (checkFormElementInRange(this, 'session_max_rows', '<?php echo str_replace('\'', '\\\'', $GLOBALS['strInvalidRowNumber']); ?>', 1) &amp;&amp; checkFormElementInRange(this, 'pos', '<?php echo str_replace('\'', '\\\'', $GLOBALS['strInvalidRowNumber']); ?>', 0<?php echo $unlim_num_rows > 0 ? ',' . $unlim_num_rows - 1 : ''; ?>))">
  268. <?php echo PMA_generate_common_hidden_inputs($db, $table); ?>
  269. <input type="hidden" name="sql_query" value="<?php echo $html_sql_query; ?>" />
  270. <input type="hidden" name="goto" value="<?php echo $goto; ?>" />
  271. <input type="submit" name="navig" value="<?php echo $GLOBALS['strShow']; ?> :" />
  272. <input type="text" name="session_max_rows" size="3" value="<?php echo (($_SESSION['userconf']['max_rows'] != 'all') ? $_SESSION['userconf']['max_rows'] : $GLOBALS['cfg']['MaxRows']); ?>" class="textfield" onfocus="this.select()" />
  273. <?php echo $GLOBALS['strRowsFrom'] . "\n"; ?>
  274. <input type="text" name="pos" size="6" value="<?php echo (($pos_next >= $unlim_num_rows) ? 0 : $pos_next); ?>" class="textfield" onfocus="this.select()" />
  275. <br />
  276. <?php
  277. // Display mode (horizontal/vertical and repeat headers)
  278. $param1 = ' <select name="disp_direction">' . "\n"
  279. . ' <option value="horizontal"' . (($_SESSION['userconf']['disp_direction'] == 'horizontal') ? ' selected="selected"': '') . '>' . $GLOBALS['strRowsModeHorizontal'] . '</option>' . "\n"
  280. . ' <option value="horizontalflipped"' . (($_SESSION['userconf']['disp_direction'] == 'horizontalflipped') ? ' selected="selected"': '') . '>' . $GLOBALS['strRowsModeFlippedHorizontal'] . '</option>' . "\n"
  281. . ' <option value="vertical"' . (($_SESSION['userconf']['disp_direction'] == 'vertical') ? ' selected="selected"': '') . '>' . $GLOBALS['strRowsModeVertical'] . '</option>' . "\n"
  282. . ' </select>' . "\n"
  283. . ' ';
  284. $param2 = ' <input type="text" size="3" name="repeat_cells" value="' . $_SESSION['userconf']['repeat_cells'] . '" class="textfield" />' . "\n"
  285. . ' ';
  286. echo ' ' . sprintf($GLOBALS['strRowsModeOptions'], "\n" . $param1, "\n" . $param2) . "\n";
  287. ?>
  288. </form>
  289. </td>
  290. <td>
  291. &nbsp;&nbsp;&nbsp;
  292. </td>
  293. <?php
  294. // Move to the next page or to the last one
  295. if (($_SESSION['userconf']['pos'] + $_SESSION['userconf']['max_rows'] < $unlim_num_rows) && $num_rows >= $_SESSION['userconf']['max_rows']
  296. && $_SESSION['userconf']['max_rows'] != 'all') {
  297. // loic1: patch #474210 from Gosha Sakovich - part 2
  298. if ($GLOBALS['cfg']['NavigationBarIconic']) {
  299. $caption3 = ' &gt; ';
  300. $caption4 = '&gt;&gt;';
  301. $title3 = ' title="' . $GLOBALS['strNext'] . '"';
  302. $title4 = ' title="' . $GLOBALS['strEnd'] . '"';
  303. } else {
  304. $caption3 = '&gt; ' . $GLOBALS['strNext'];
  305. $caption4 = '&gt;&gt; ' . $GLOBALS['strEnd'];
  306. $title3 = '';
  307. $title4 = '';
  308. } // end if... else...
  309. echo "\n";
  310. ?>
  311. <td>
  312. <form action="sql.php" method="post">
  313. <?php echo PMA_generate_common_hidden_inputs($db, $table); ?>
  314. <input type="hidden" name="sql_query" value="<?php echo $html_sql_query; ?>" />
  315. <input type="hidden" name="pos" value="<?php echo $pos_next; ?>" />
  316. <input type="hidden" name="goto" value="<?php echo $goto; ?>" />
  317. <input type="submit" name="navig" value="<?php echo $caption3; ?>"<?php echo $title3; ?> />
  318. </form>
  319. </td>
  320. <td>
  321. <form action="sql.php" method="post"
  322. onsubmit="return <?php echo (($_SESSION['userconf']['pos'] + $_SESSION['userconf']['max_rows'] < $unlim_num_rows && $num_rows >= $_SESSION['userconf']['max_rows']) ? 'true' : 'false'); ?>">
  323. <?php echo PMA_generate_common_hidden_inputs($db, $table); ?>
  324. <input type="hidden" name="sql_query" value="<?php echo $html_sql_query; ?>" />
  325. <input type="hidden" name="pos" value="<?php echo @((ceil($unlim_num_rows / $_SESSION['userconf']['max_rows'])- 1) * $_SESSION['userconf']['max_rows']); ?>" />
  326. <?php
  327. if ($is_innodb && $unlim_num_rows > $GLOBALS['cfg']['MaxExactCount']) {
  328. echo '<input type="hidden" name="find_real_end" value="1" />' . "\n";
  329. // no backquote around this message
  330. $onclick = ' onclick="return confirmAction(\'' . PMA_jsFormat($GLOBALS['strLongOperation'], false) . '\')"';
  331. }
  332. ?>
  333. <input type="hidden" name="goto" value="<?php echo $goto; ?>" />
  334. <input type="submit" name="navig" value="<?php echo $caption4; ?>"<?php echo $title4; ?> <?php echo (empty($onclick) ? '' : $onclick); ?>/>
  335. </form>
  336. </td>
  337. <?php
  338. } // end move toward
  339. //page redirection
  340. // (unless we are showing all records)
  341. if ('all' != $_SESSION['userconf']['max_rows']) { //if1
  342. $pageNow = @floor($_SESSION['userconf']['pos'] / $_SESSION['userconf']['max_rows']) + 1;
  343. $nbTotalPage = @ceil($unlim_num_rows / $_SESSION['userconf']['max_rows']);
  344. if ($nbTotalPage > 1){ //if2
  345. ?>
  346. <td>
  347. &nbsp;&nbsp;&nbsp;
  348. </td>
  349. <td>
  350. <?php //<form> for keep the form alignment of button < and << ?>
  351. <form action="none">
  352. <?php
  353. $_url_params = array(
  354. 'db' => $db,
  355. 'table' => $table,
  356. 'sql_query' => $sql_query,
  357. 'goto' => $goto,
  358. );
  359. echo PMA_pageselector(
  360. 'sql.php' . PMA_generate_common_url($_url_params) . PMA_get_arg_separator('js'),
  361. $_SESSION['userconf']['max_rows'],
  362. $pageNow,
  363. $nbTotalPage,
  364. 200,
  365. 5,
  366. 5,
  367. 20,
  368. 10,
  369. $GLOBALS['strPageNumber']
  370. );
  371. ?>
  372. </form>
  373. </td>
  374. <?php
  375. } //_if2
  376. } //_if1
  377. // Display the "Show all" button if allowed
  378. if ($GLOBALS['cfg']['ShowAll'] && ($num_rows < $unlim_num_rows)) {
  379. echo "\n";
  380. ?>
  381. <td>
  382. &nbsp;&nbsp;&nbsp;
  383. </td>
  384. <td>
  385. <form action="sql.php" method="post">
  386. <?php echo PMA_generate_common_hidden_inputs($db, $table); ?>
  387. <input type="hidden" name="sql_query" value="<?php echo $html_sql_query; ?>" />
  388. <input type="hidden" name="pos" value="0" />
  389. <input type="hidden" name="session_max_rows" value="all" />
  390. <input type="hidden" name="goto" value="<?php echo $goto; ?>" />
  391. <input type="submit" name="navig" value="<?php echo $GLOBALS['strShowAll']; ?>" />
  392. </form>
  393. </td>
  394. <?php
  395. } // end show all
  396. echo "\n";
  397. ?>
  398. </tr>
  399. </table>
  400. <?php
  401. } // end of the 'PMA_displayTableNavigation()' function
  402. /**
  403. * Displays the headers of the results table
  404. *
  405. * @uses $_SESSION['userconf']['disp_direction']
  406. * @uses $_SESSION['userconf']['repeat_cells']
  407. * @uses $_SESSION['userconf']['max_rows']
  408. * @uses $_SESSION['userconf']['display_text']
  409. * @uses $_SESSION['userconf']['display_binary']
  410. * @param array which elements to display
  411. * @param array the list of fields properties
  412. * @param integer the total number of fields returned by the SQL query
  413. * @param array the analyzed query
  414. *
  415. * @return boolean always true
  416. *
  417. * @global string $db the database name
  418. * @global string $table the table name
  419. * @global string $goto the URL to go back in case of errors
  420. * @global string $sql_query the SQL query
  421. * @global integer $num_rows the total number of rows returned by the
  422. * SQL query
  423. * @global array $vertical_display informations used with vertical display
  424. * mode
  425. *
  426. * @access private
  427. *
  428. * @see PMA_displayTable()
  429. */
  430. function PMA_displayTableHeaders(&$is_display, &$fields_meta, $fields_cnt = 0, $analyzed_sql = '', $sort_expression, $sort_expression_nodirection, $sort_direction)
  431. {
  432. global $db, $table, $goto;
  433. global $sql_query, $num_rows;
  434. global $vertical_display, $highlight_columns;
  435. if ($analyzed_sql == '') {
  436. $analyzed_sql = array();
  437. }
  438. // can the result be sorted?
  439. if ($is_display['sort_lnk'] == '1') {
  440. // Just as fallback
  441. $unsorted_sql_query = $sql_query;
  442. if (isset($analyzed_sql[0]['unsorted_query'])) {
  443. $unsorted_sql_query = $analyzed_sql[0]['unsorted_query'];
  444. }
  445. // Handles the case of multiple clicks on a column's header
  446. // which would add many spaces before "ORDER BY" in the
  447. // generated query.
  448. $unsorted_sql_query = trim($unsorted_sql_query);
  449. // sorting by indexes, only if it makes sense (only one table ref)
  450. if (isset($analyzed_sql) && isset($analyzed_sql[0]) &&
  451. isset($analyzed_sql[0]['querytype']) && $analyzed_sql[0]['querytype'] == 'SELECT' &&
  452. isset($analyzed_sql[0]['table_ref']) && count($analyzed_sql[0]['table_ref']) == 1) {
  453. // grab indexes data:
  454. $indexes = PMA_Index::getFromTable($table, $db);
  455. // do we have any index?
  456. if ($indexes) {
  457. if ($_SESSION['userconf']['disp_direction'] == 'horizontal'
  458. || $_SESSION['userconf']['disp_direction'] == 'horizontalflipped') {
  459. $span = $fields_cnt;
  460. if ($is_display['edit_lnk'] != 'nn') {
  461. $span++;
  462. }
  463. if ($is_display['del_lnk'] != 'nn') {
  464. $span++;
  465. }
  466. if ($is_display['del_lnk'] != 'kp' && $is_display['del_lnk'] != 'nn') {
  467. $span++;
  468. }
  469. } else {
  470. $span = $num_rows + floor($num_rows/$_SESSION['userconf']['repeat_cells']) + 1;
  471. }
  472. echo '<form action="sql.php" method="post">' . "\n";
  473. echo PMA_generate_common_hidden_inputs($db, $table);
  474. echo $GLOBALS['strSortByKey'] . ': <select name="sql_query" onchange="this.form.submit();">' . "\n";
  475. $used_index = false;
  476. $local_order = (isset($sort_expression) ? $sort_expression : '');
  477. foreach ($indexes as $index) {
  478. $asc_sort = '`' . implode('` ASC, `', array_keys($index->getColumns())) . '` ASC';
  479. $desc_sort = '`' . implode('` DESC, `', array_keys($index->getColumns())) . '` DESC';
  480. $used_index = $used_index || $local_order == $asc_sort || $local_order == $desc_sort;
  481. echo '<option value="'
  482. . htmlspecialchars($unsorted_sql_query . ' ORDER BY ' . $asc_sort)
  483. . '"' . ($local_order == $asc_sort ? ' selected="selected"' : '')
  484. . '>' . htmlspecialchars($index->getName()) . ' ('
  485. . $GLOBALS['strAscending'] . ')</option>';
  486. echo '<option value="'
  487. . htmlspecialchars($unsorted_sql_query . ' ORDER BY ' . $desc_sort)
  488. . '"' . ($local_order == $desc_sort ? ' selected="selected"' : '')
  489. . '>' . htmlspecialchars($index->getName()) . ' ('
  490. . $GLOBALS['strDescending'] . ')</option>';
  491. }
  492. echo '<option value="' . htmlspecialchars($unsorted_sql_query) . '"' . ($used_index ? '' : ' selected="selected"') . '>' . $GLOBALS['strNone'] . '</option>';
  493. echo '</select>' . "\n";
  494. echo '<noscript><input type="submit" value="' . $GLOBALS['strGo'] . '" /></noscript>';
  495. echo '</form>' . "\n";
  496. }
  497. }
  498. }
  499. $vertical_display['emptypre'] = 0;
  500. $vertical_display['emptyafter'] = 0;
  501. $vertical_display['textbtn'] = '';
  502. // Display options (if we are not in print view)
  503. if (! (isset($GLOBALS['printview']) && $GLOBALS['printview'] == '1')) {
  504. echo '<form method="post" action="sql.php" name="displayOptionsForm" id="displayOptionsForm">';
  505. $url_params = array(
  506. 'db' => $db,
  507. 'table' => $table,
  508. 'sql_query' => $sql_query,
  509. 'goto' => $goto,
  510. 'display_options_form' => 1
  511. );
  512. echo PMA_generate_common_hidden_inputs($url_params);
  513. echo '<br />';
  514. PMA_generate_slider_effect('displayoptions',$GLOBALS['strOptions']);
  515. echo '<fieldset>';
  516. echo '<div class="formelement">';
  517. $choices = array(
  518. 'P' => $GLOBALS['strPartialText'],
  519. 'F' => $GLOBALS['strFullText']
  520. );
  521. PMA_generate_html_radio('display_text', $choices, $_SESSION['userconf']['display_text']);
  522. echo '</div>';
  523. if ($GLOBALS['cfgRelation']['relwork'] && $GLOBALS['cfgRelation']['displaywork']) {
  524. echo '<div class="formelement">';
  525. $choices = array(
  526. 'K' => $GLOBALS['strRelationalKey'],
  527. 'D' => $GLOBALS['strRelationalDisplayField']
  528. );
  529. PMA_generate_html_radio('relational_display', $choices, $_SESSION['userconf']['relational_display']);
  530. echo '</div>';
  531. }
  532. echo '<div class="formelement">';
  533. PMA_generate_html_checkbox('display_binary', $GLOBALS['strShowBinaryContents'], ! empty($_SESSION['userconf']['display_binary']), false);
  534. echo '<br />';
  535. PMA_generate_html_checkbox('display_blob', $GLOBALS['strShowBLOBContents'], ! empty($_SESSION['userconf']['display_blob']), false);
  536. echo '</div>';
  537. // I would have preferred to name this "display_transformation".
  538. // This is the only way I found to be able to keep this setting sticky
  539. // per SQL query, and at the same time have a default that displays
  540. // the transformations.
  541. echo '<div class="formelement">';
  542. PMA_generate_html_checkbox('hide_transformation', $GLOBALS['strHide'] . ' ' . $GLOBALS['strMIME_transformation'], ! empty($_SESSION['userconf']['hide_transformation']), false);
  543. echo '</div>';
  544. echo '<div class="clearfloat"></div>';
  545. echo '</fieldset>';
  546. echo '<fieldset class="tblFooters">';
  547. echo '<input type="submit" value="' . $GLOBALS['strGo'] . '" />';
  548. echo '</fieldset>';
  549. echo '</div>';
  550. echo '</form>';
  551. }
  552. // Start of form for multi-rows edit/delete/export
  553. if ($is_display['del_lnk'] == 'dr' || $is_display['del_lnk'] == 'kp') {
  554. echo '<form method="post" action="tbl_row_action.php" name="rowsDeleteForm" id="rowsDeleteForm">' . "\n";
  555. echo PMA_generate_common_hidden_inputs($db, $table, 1);
  556. echo '<input type="hidden" name="goto" value="sql.php" />' . "\n";
  557. }
  558. echo '<table id="table_results" class="data">' . "\n";
  559. if ($_SESSION['userconf']['disp_direction'] == 'horizontal'
  560. || $_SESSION['userconf']['disp_direction'] == 'horizontalflipped') {
  561. echo '<thead><tr>' . "\n";
  562. }
  563. // 1. Displays the full/partial text button (part 1)...
  564. if ($_SESSION['userconf']['disp_direction'] == 'horizontal'
  565. || $_SESSION['userconf']['disp_direction'] == 'horizontalflipped') {
  566. $colspan = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn')
  567. ? ' colspan="3"'
  568. : '';
  569. } else {
  570. $rowspan = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn')
  571. ? ' rowspan="3"'
  572. : '';
  573. }
  574. // ... before the result table
  575. if (($is_display['edit_lnk'] == 'nn' && $is_display['del_lnk'] == 'nn')
  576. && $is_display['text_btn'] == '1') {
  577. $vertical_display['emptypre'] = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn') ? 3 : 0;
  578. if ($_SESSION['userconf']['disp_direction'] == 'horizontal'
  579. || $_SESSION['userconf']['disp_direction'] == 'horizontalflipped') {
  580. ?>
  581. <th colspan="<?php echo $fields_cnt; ?>"></th>
  582. </tr>
  583. <tr>
  584. <?php
  585. } // end horizontal/horizontalflipped mode
  586. else {
  587. ?>
  588. <tr>
  589. <th colspan="<?php echo $num_rows + floor($num_rows/$_SESSION['userconf']['repeat_cells']) + 1; ?>"></th>
  590. </tr>
  591. <?php
  592. } // end vertical mode
  593. }
  594. // ... at the left column of the result table header if possible
  595. // and required
  596. elseif ($GLOBALS['cfg']['ModifyDeleteAtLeft'] && $is_display['text_btn'] == '1') {
  597. $vertical_display['emptypre'] = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn') ? 3 : 0;
  598. if ($_SESSION['userconf']['disp_direction'] == 'horizontal'
  599. || $_SESSION['userconf']['disp_direction'] == 'horizontalflipped') {
  600. ?>
  601. <th <?php echo $colspan; ?>></th>
  602. <?php
  603. } // end horizontal/horizontalflipped mode
  604. else {
  605. $vertical_display['textbtn'] = ' <th ' . $rowspan . ' valign="middle">' . "\n"
  606. . ' ' . "\n"
  607. . ' </th>' . "\n";
  608. } // end vertical mode
  609. }
  610. // ... elseif no button, displays empty(ies) col(s) if required
  611. elseif ($GLOBALS['cfg']['ModifyDeleteAtLeft']
  612. && ($is_display['edit_lnk'] != 'nn' || $is_display['del_lnk'] != 'nn')) {
  613. $vertical_display['emptypre'] = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn') ? 3 : 0;
  614. if ($_SESSION['userconf']['disp_direction'] == 'horizontal'
  615. || $_SESSION['userconf']['disp_direction'] == 'horizontalflipped') {
  616. ?>
  617. <td<?php echo $colspan; ?>></td>
  618. <?php
  619. } // end horizontal/horizontalfipped mode
  620. else {
  621. $vertical_display['textbtn'] = ' <td' . $rowspan . '></td>' . "\n";
  622. } // end vertical mode
  623. }
  624. // 2. Displays the fields' name
  625. // 2.0 If sorting links should be used, checks if the query is a "JOIN"
  626. // statement (see 2.1.3)
  627. // 2.0.1 Prepare Display column comments if enabled ($GLOBALS['cfg']['ShowBrowseComments']).
  628. // Do not show comments, if using horizontalflipped mode, because of space usage
  629. if ($GLOBALS['cfg']['ShowBrowseComments']
  630. && $_SESSION['userconf']['disp_direction'] != 'horizontalflipped') {
  631. $comments_map = array();
  632. if (isset($analyzed_sql[0]) && is_array($analyzed_sql[0])) {
  633. foreach ($analyzed_sql[0]['table_ref'] as $tbl) {
  634. $tb = $tbl['table_true_name'];
  635. $comments_map[$tb] = PMA_getComments($db, $tb);
  636. unset($tb);
  637. }
  638. }
  639. }
  640. if ($GLOBALS['cfgRelation']['commwork'] && $GLOBALS['cfgRelation']['mimework'] && $GLOBALS['cfg']['BrowseMIME'] && ! $_SESSION['userconf']['hide_transformation']) {
  641. require_once './libraries/transformations.lib.php';
  642. $GLOBALS['mime_map'] = PMA_getMIME($db, $table);
  643. }
  644. if ($is_display['sort_lnk'] == '1') {
  645. $select_expr = $analyzed_sql[0]['select_expr_clause'];
  646. }
  647. // garvin: See if we have to highlight any header fields of a WHERE query.
  648. // Uses SQL-Parser results.
  649. $highlight_columns = array();
  650. if (isset($analyzed_sql) && isset($analyzed_sql[0]) &&
  651. isset($analyzed_sql[0]['where_clause_identifiers'])) {
  652. $wi = 0;
  653. if (isset($analyzed_sql[0]['where_clause_identifiers']) && is_array($analyzed_sql[0]['where_clause_identifiers'])) {
  654. foreach ($analyzed_sql[0]['where_clause_identifiers'] AS $wci_nr => $wci) {
  655. $highlight_columns[$wci] = 'true';
  656. }
  657. }
  658. }
  659. for ($i = 0; $i < $fields_cnt; $i++) {
  660. // garvin: See if this column should get highlight because it's used in the
  661. // where-query.
  662. if (isset($highlight_columns[$fields_meta[$i]->name]) || isset($highlight_columns[PMA_backquote($fields_meta[$i]->name)])) {
  663. $condition_field = true;
  664. } else {
  665. $condition_field = false;
  666. }
  667. // 2.0 Prepare comment-HTML-wrappers for each row, if defined/enabled.
  668. if (isset($comments_map) &&
  669. isset($comments_map[$fields_meta[$i]->table]) &&
  670. isset($comments_map[$fields_meta[$i]->table][$fields_meta[$i]->name])) {
  671. $comments = '<span class="tblcomment">' . htmlspecialchars($comments_map[$fields_meta[$i]->table][$fields_meta[$i]->name]) . '</span>';
  672. } else {
  673. $comments = '';
  674. }
  675. // 2.1 Results can be sorted
  676. if ($is_display['sort_lnk'] == '1') {
  677. // 2.1.1 Checks if the table name is required; it's the case
  678. // for a query with a "JOIN" statement and if the column
  679. // isn't aliased, or in queries like
  680. // SELECT `1`.`master_field` , `2`.`master_field`
  681. // FROM `PMA_relation` AS `1` , `PMA_relation` AS `2`
  682. if (isset($fields_meta[$i]->table) && strlen($fields_meta[$i]->table)) {
  683. $sort_tbl = PMA_backquote($fields_meta[$i]->table) . '.';
  684. } else {
  685. $sort_tbl = '';
  686. }
  687. // 2.1.2 Checks if the current column is used to sort the
  688. // results
  689. // the orgname member does not exist for all MySQL versions
  690. // but if found, it's the one on which to sort
  691. $name_to_use_in_sort = $fields_meta[$i]->name;
  692. if (isset($fields_meta[$i]->orgname) && strlen($fields_meta[$i]->orgname)) {
  693. $name_to_use_in_sort = $fields_meta[$i]->orgname;
  694. }
  695. // $name_to_use_in_sort might contain a space due to
  696. // formatting of function expressions like "COUNT(name )"
  697. // so we remove the space in this situation
  698. $name_to_use_in_sort = str_replace(' )', ')', $name_to_use_in_sort);
  699. if (empty($sort_expression)) {
  700. $is_in_sort = false;
  701. } else {
  702. // field name may be preceded by a space, or any number
  703. // of characters followed by a dot (tablename.fieldname)
  704. // so do a direct comparison
  705. // for the sort expression (avoids problems with queries
  706. // like "SELECT id, count(id)..." and clicking to sort
  707. // on id or on count(id))
  708. if (strpos($sort_expression_nodirection, $sort_tbl) === false) {
  709. $sort_expression_nodirection = $sort_tbl . $sort_expression_nodirection;
  710. }
  711. $is_in_sort = (str_replace('`', '', $sort_tbl) . $name_to_use_in_sort == str_replace('`', '', $sort_expression_nodirection) ? true : false);
  712. }
  713. // 2.1.3 Check the field name for a bracket.
  714. // If it contains one, it's probably a function column
  715. // like 'COUNT(`field`)'
  716. if (strpos($name_to_use_in_sort, '(') !== false) {
  717. $sort_order = ' ORDER BY ' . $name_to_use_in_sort . ' ';
  718. } else {
  719. $sort_order = ' ORDER BY ' . $sort_tbl . PMA_backquote($name_to_use_in_sort) . ' ';
  720. }
  721. unset($name_to_use_in_sort);
  722. // 2.1.4 Do define the sorting URL
  723. if (! $is_in_sort) {
  724. // loic1: patch #455484 ("Smart" order)
  725. $GLOBALS['cfg']['Order'] = strtoupper($GLOBALS['cfg']['Order']);
  726. if ($GLOBALS['cfg']['Order'] === 'SMART') {
  727. $sort_order .= (preg_match('@time|date@i', $fields_meta[$i]->type)) ? 'DESC' : 'ASC';
  728. } else {
  729. $sort_order .= $GLOBALS['cfg']['Order'];
  730. }
  731. $order_img = '';
  732. } elseif ('DESC' == $sort_direction) {
  733. $sort_order .= ' ASC';
  734. $order_img = ' <img class="icon" src="' . $GLOBALS['pmaThemeImage'] . 's_desc.png" width="11" height="9" alt="'. $GLOBALS['strDescending'] . '" title="'. $GLOBALS['strDescending'] . '" id="soimg' . $i . '" />';
  735. } else {
  736. $sort_order .= ' DESC';
  737. $order_img = ' <img class="icon" src="' . $GLOBALS['pmaThemeImage'] . 's_asc.png" width="11" height="9" alt="'. $GLOBALS['strAscending'] . '" title="'. $GLOBALS['strAscending'] . '" id="soimg' . $i . '" />';
  738. }
  739. if (preg_match('@(.*)([[:space:]](LIMIT (.*)|PROCEDURE (.*)|FOR UPDATE|LOCK IN SHARE MODE))@i', $unsorted_sql_query, $regs3)) {
  740. $sorted_sql_query = $regs3[1] . $sort_order . $regs3[2];
  741. } else {
  742. $sorted_sql_query = $unsorted_sql_query . $sort_order;
  743. }
  744. $_url_params = array(
  745. 'db' => $db,
  746. 'table' => $table,
  747. 'sql_query' => $sorted_sql_query,
  748. );
  749. $order_url = 'sql.php' . PMA_generate_common_url($_url_params);
  750. // 2.1.5 Displays the sorting URL
  751. // added 20004-06-09: Michael Keck <mail@michaelkeck.de>
  752. // enable sort order swapping for image
  753. $order_link_params = array();
  754. if (isset($order_img) && $order_img!='') {
  755. if (strstr($order_img, 'asc')) {
  756. $order_link_params['onmouseover'] = 'if(document.getElementById(\'soimg' . $i . '\')){ document.getElementById(\'soimg' . $i . '\').src=\'' . $GLOBALS['pmaThemeImage'] . 's_desc.png\'; }';
  757. $order_link_params['onmouseout'] = 'if(document.getElementById(\'soimg' . $i . '\')){ document.getElementById(\'soimg' . $i . '\').src=\'' . $GLOBALS['pmaThemeImage'] . 's_asc.png\'; }';
  758. } elseif (strstr($order_img, 'desc')) {
  759. $order_link_params['onmouseover'] = 'if(document.getElementById(\'soimg' . $i . '\')){ document.getElementById(\'soimg' . $i . '\').src=\'' . $GLOBALS['pmaThemeImage'] . 's_asc.png\'; }';
  760. $order_link_params['onmouseout'] = 'if(document.getElementById(\'soimg' . $i . '\')){ document.getElementById(\'soimg' . $i . '\').src=\'' . $GLOBALS['pmaThemeImage'] . 's_desc.png\'; }';
  761. }
  762. }
  763. if ($_SESSION['userconf']['disp_direction'] == 'horizontalflipped'
  764. && $GLOBALS['cfg']['HeaderFlipType'] == 'css') {
  765. $order_link_params['style'] = 'direction: ltr; writing-mode: tb-rl;';
  766. }
  767. $order_link_params['title'] = $GLOBALS['strSort'];
  768. $order_link_content = ($_SESSION['userconf']['disp_direction'] == 'horizontalflipped' && $GLOBALS['cfg']['HeaderFlipType'] == 'fake' ? PMA_flipstring(htmlspecialchars($fields_meta[$i]->name), "<br />\n") : htmlspecialchars($fields_meta[$i]->name));
  769. $order_link = PMA_linkOrButton($order_url, $order_link_content . $order_img, $order_link_params, false, true);
  770. if ($_SESSION['userconf']['disp_direction'] == 'horizontal'
  771. || $_SESSION['userconf']['disp_direction'] == 'horizontalflipped') {
  772. echo '<th';
  773. if ($condition_field) {
  774. echo ' class="condition"';
  775. }
  776. if ($_SESSION['userconf']['disp_direction'] == 'horizontalflipped') {
  777. echo ' valign="bottom"';
  778. }
  779. echo '>' . $order_link . $comments . '</th>';
  780. }
  781. $vertical_display['desc'][] = ' <th '
  782. . ($condition_field ? ' class="condition"' : '') . '>' . "\n"
  783. . $order_link . $comments . ' </th>' . "\n";
  784. } // end if (2.1)
  785. // 2.2 Results can't be sorted
  786. else {
  787. if ($_SESSION['userconf']['disp_direction'] == 'horizontal'
  788. || $_SESSION['userconf']['disp_direction'] == 'horizontalflipped') {
  789. echo '<th';
  790. if ($condition_field) {
  791. echo ' class="condition"';
  792. }
  793. if ($_SESSION['userconf']['disp_direction'] == 'horizontalflipped') {
  794. echo ' valign="bottom"';
  795. }
  796. if ($_SESSION['userconf']['disp_direction'] == 'horizontalflipped'
  797. && $GLOBALS['cfg']['HeaderFlipType'] == 'css') {
  798. echo ' style="direction: ltr; writing-mode: tb-rl;"';
  799. }
  800. echo '>';
  801. if ($_SESSION['userconf']['disp_direction'] == 'horizontalflipped'
  802. && $GLOBALS['cfg']['HeaderFlipType'] == 'fake') {
  803. echo PMA_flipstring(htmlspecialchars($fields_meta[$i]->name), '<br />');
  804. } else {
  805. echo htmlspecialchars($fields_meta[$i]->name);
  806. }
  807. echo "\n" . $comments . '</th>';
  808. }
  809. $vertical_display['desc'][] = ' <th '
  810. . ($condition_field ? ' class="condition"' : '') . '>' . "\n"
  811. . ' ' . htmlspecialchars($fields_meta[$i]->name) . "\n"
  812. . $comments . ' </th>';
  813. } // end else (2.2)
  814. } // end for
  815. // 3. Displays the needed checkboxes at the right
  816. // column of the result table header if possible and required...
  817. if ($GLOBALS['cfg']['ModifyDeleteAtRight']
  818. && ($is_display['edit_lnk'] != 'nn' || $is_display['del_lnk'] != 'nn')
  819. && $is_display['text_btn'] == '1') {
  820. $vertical_display['emptyafter'] = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn') ? 3 : 1;
  821. if ($_SESSION['userconf']['disp_direction'] == 'horizontal'
  822. || $_SESSION['userconf']['disp_direction'] == 'horizontalflipped') {
  823. echo "\n";
  824. ?>
  825. <th <?php echo $colspan; ?>>
  826. </th>
  827. <?php
  828. } // end horizontal/horizontalflipped mode
  829. else {
  830. $vertical_display['textbtn'] = ' <th ' . $rowspan . ' valign="middle">' . "\n"
  831. . ' ' . "\n"
  832. . ' </th>' . "\n";
  833. } // end vertical mode
  834. }
  835. // ... elseif no button, displays empty columns if required
  836. // (unless coming from Browse mode print view)
  837. elseif ($GLOBALS['cfg']['ModifyDeleteAtRight']
  838. && ($is_display['edit_lnk'] == 'nn' && $is_display['del_lnk'] == 'nn')
  839. && (!$GLOBALS['is_header_sent'])) {
  840. $vertical_display['emptyafter'] = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn') ? 3 : 1;
  841. if ($_SESSION['userconf']['disp_direction'] == 'horizontal'
  842. || $_SESSION['userconf']['disp_direction'] == 'horizontalflipped') {
  843. echo "\n";
  844. ?>
  845. <td<?php echo $colspan; ?>></td>
  846. <?php
  847. } // end horizontal/horizontalflipped mode
  848. else {
  849. $vertical_display['textbtn'] = ' <td' . $rowspan . '></td>' . "\n";
  850. } // end vertical mode
  851. }
  852. if ($_SESSION['userconf']['disp_direction'] == 'horizontal'
  853. || $_SESSION['userconf']['disp_direction'] == 'horizontalflipped') {
  854. ?>
  855. </tr>
  856. </thead>
  857. <?php
  858. }
  859. return true;
  860. } // end of the 'PMA_displayTableHeaders()' function
  861. /**
  862. * Displays the body of the results table
  863. *
  864. * @uses $_SESSION['userconf']['disp_direction']
  865. * @uses $_SESSION['userconf']['repeat_cells']
  866. * @uses $_SESSION['userconf']['max_rows']
  867. * @uses $_SESSION['userconf']['display_text']
  868. * @uses $_SESSION['userconf']['display_binary']
  869. * @uses $_SESSION['userconf']['display_blob']
  870. * @param integer the link id associated to the query which results have
  871. * to be displayed
  872. * @param array which elements to display
  873. * @param array the list of relations
  874. * @param array the analyzed query
  875. *
  876. * @return boolean always true
  877. *
  878. * @global string $db the database name
  879. * @global string $table the table name
  880. * @global string $goto the URL to go back in case of errors
  881. * @global string $sql_query the SQL query
  882. * @global array $fields_meta the list of fields properties
  883. * @global integer $fields_cnt the total number of fields returned by
  884. * the SQL query
  885. * @global array $vertical_display informations used with vertical display
  886. * mode
  887. * @global array $highlight_columns column names to highlight
  888. * @global array $row current row data
  889. *
  890. * @access private
  891. *
  892. * @see PMA_displayTable()
  893. */
  894. function PMA_displayTableBody(&$dt_result, &$is_display, $map, $analyzed_sql) {
  895. global $db, $table, $goto;
  896. global $sql_query, $fields_meta, $fields_cnt;
  897. global $vertical_display, $highlight_columns;
  898. global $row; // mostly because of browser transformations, to make the row-data accessible in a plugin
  899. $url_sql_query = $sql_query;
  900. // query without conditions to shorten URLs when needed, 200 is just
  901. // guess, it should depend on remaining URL length
  902. if (isset($analyzed_sql) && isset($analyzed_sql[0]) &&
  903. isset($analyzed_sql[0]['querytype']) && $analyzed_sql[0]['querytype'] == 'SELECT' &&
  904. strlen($sql_query) > 200) {
  905. $url_sql_query = 'SELECT ';
  906. if (isset($analyzed_sql[0]['queryflags']['distinct'])) {
  907. $url_sql_query .= ' DISTINCT ';
  908. }
  909. $url_sql_query .= $analyzed_sql[0]['select_expr_clause'];
  910. if (!empty($analyzed_sql[0]['from_clause'])) {
  911. $url_sql_query .= ' FROM ' . $analyzed_sql[0]['from_clause'];
  912. }
  913. }
  914. if (!is_array($map)) {
  915. $map = array();
  916. }
  917. $row_no = 0;
  918. $vertical_display['edit'] = array();
  919. $vertical_display['delete'] = array();
  920. $vertical_display['data'] = array();
  921. $vertical_display['row_delete'] = array();
  922. // Correction University of Virginia 19991216 in the while below
  923. // Previous code assumed that all tables have keys, specifically that
  924. // the phpMyAdmin GUI should support row delete/edit only for such
  925. // tables.
  926. // Although always using keys is arguably the prescribed way of
  927. // defining a relational table, it is not required. This will in
  928. // particular be violated by the novice.
  929. // We want to encourage phpMyAdmin usage by such novices. So the code
  930. // below has been changed to conditionally work as before when the
  931. // table being displayed has one or more keys; but to display
  932. // delete/edit options correctly for tables without keys.
  933. $odd_row = true;
  934. while ($row = PMA_DBI_fetch_row($dt_result)) {
  935. // lem9: "vertical display" mode stuff
  936. if ($row_no != 0 && $_SESSION['userconf']['repeat_cells'] != 0 && !($row_no % $_SESSION['userconf']['repeat_cells'])
  937. && ($_SESSION['userconf']['disp_direction'] == 'horizontal'
  938. || $_SESSION['userconf']['disp_direction'] == 'horizontalflipped'))
  939. {
  940. echo '<tr>' . "\n";
  941. if ($vertical_display['emptypre'] > 0) {
  942. echo ' <th colspan="' . $vertical_display['emptypre'] . '">' . "\n"
  943. .' &nbsp;</th>' . "\n";
  944. }
  945. foreach ($vertical_display['desc'] as $val) {
  946. echo $val;
  947. }
  948. if ($vertical_display['emptyafter'] > 0) {
  949. echo ' <th colspan="' . $vertical_display['emptyafter'] . '">' . "\n"
  950. .' &nbsp;</th>' . "\n";
  951. }
  952. echo '</tr>' . "\n";
  953. } // end if
  954. $class = $odd_row ? 'odd' : 'even';
  955. $odd_row = ! $odd_row;
  956. if ($_SESSION['userconf']['disp_direction'] == 'horizontal'
  957. || $_SESSION['userconf']['disp_direction'] == 'horizontalflipped') {
  958. // loic1: pointer code part
  959. echo ' <tr class="' . $class . '">' . "\n";
  960. $class = '';
  961. }
  962. // 1. Prepares the row (gets primary keys to use)
  963. // 1.1 Results from a "SELECT" statement -> builds the
  964. // "primary" key to use in links
  965. /**
  966. * @todo $unique_condition could be empty, for example a table
  967. * with only one field and it's a BLOB; in this case,
  968. * avoid to display the delete and edit links
  969. */
  970. $unique_condition = PMA_getUniqueCondition($dt_result, $fields_cnt, $fields_meta, $row);
  971. $unique_condition_html = urlencode($unique_condition);
  972. // 1.2 Defines the URLs for the modify/delete link(s)
  973. if ($is_display['edit_lnk'] != 'nn' || $is_display['del_lnk'] != 'nn') {
  974. // We need to copy the value or else the == 'both' check will always return true
  975. if ($GLOBALS['cfg']['PropertiesIconic'] === 'both') {
  976. $iconic_spacer = '<div class="nowrap">';
  977. } else {
  978. $iconic_spacer = '';
  979. }
  980. // 1.2.1 Modify link(s)
  981. if ($is_display['edit_lnk'] == 'ur') { // update row case
  982. $_url_params = array(
  983. 'db' => $db,
  984. 'table' => $table,
  985. 'primary_key' => $unique_condition,
  986. 'sql_query' => $url_sql_query,
  987. 'goto' => 'sql.php',
  988. );
  989. $edit_url = 'tbl_change.php' . PMA_generate_common_url($_url_params);
  990. $edit_str = PMA_getIcon('b_edit.png',

Large files files are truncated, but you can click here to view the full file