tbl_zoom_select.php 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. <?php
  2. /* vim: set expandtab sw=4 ts=4 sts=4: */
  3. /**
  4. * Handles table zoom search tab
  5. *
  6. * display table zoom search form, create SQL queries from form data
  7. *
  8. * @package PhpMyAdmin
  9. */
  10. /**
  11. * Gets some core libraries
  12. */
  13. require_once './libraries/common.inc.php';
  14. require_once './libraries/mysql_charsets.lib.php';
  15. require_once './libraries/TableSearch.class.php';
  16. require_once './libraries/tbl_info.inc.php';
  17. $response = PMA_Response::getInstance();
  18. $header = $response->getHeader();
  19. $scripts = $header->getScripts();
  20. $scripts->addFile('makegrid.js');
  21. $scripts->addFile('sql.js');
  22. /* < IE 9 doesn't support canvas natively */
  23. if (PMA_USR_BROWSER_AGENT == 'IE' && PMA_USR_BROWSER_VER < 9) {
  24. $scripts->addFile('canvg/flashcanvas.js');
  25. }
  26. $scripts->addFile('jqplot/jquery.jqplot.js');
  27. $scripts->addFile('jqplot/plugins/jqplot.canvasTextRenderer.js');
  28. $scripts->addFile('jqplot/plugins/jqplot.canvasAxisLabelRenderer.js');
  29. $scripts->addFile('jqplot/plugins/jqplot.dateAxisRenderer.js');
  30. $scripts->addFile('jqplot/plugins/jqplot.highlighter.js');
  31. $scripts->addFile('jqplot/plugins/jqplot.cursor.js');
  32. $scripts->addFile('canvg/canvg.js');
  33. $scripts->addFile('jquery/jquery-ui-timepicker-addon.js');
  34. $scripts->addFile('tbl_zoom_plot_jqplot.js');
  35. /**
  36. * Sets globals from $_POST
  37. */
  38. $post_params = array(
  39. 'dataLabel',
  40. 'maxPlotLimit',
  41. 'zoom_submit'
  42. );
  43. foreach ($post_params as $one_post_param) {
  44. if (isset($_POST[$one_post_param])) {
  45. $GLOBALS[$one_post_param] = $_POST[$one_post_param];
  46. }
  47. }
  48. $table_search = new PMA_TableSearch($db, $table, "zoom");
  49. /**
  50. * Handle AJAX request for data row on point select
  51. * @var post_params Object containing parameters for the POST request
  52. */
  53. if (isset($_REQUEST['get_data_row']) && $_REQUEST['get_data_row'] == true) {
  54. $extra_data = array();
  55. $row_info_query = 'SELECT * FROM `' . $_REQUEST['db'] . '`.`'
  56. . $_REQUEST['table'] . '` WHERE ' . $_REQUEST['where_clause'];
  57. $result = PMA_DBI_query($row_info_query . ";", null, PMA_DBI_QUERY_STORE);
  58. $fields_meta = PMA_DBI_get_fields_meta($result);
  59. while ($row = PMA_DBI_fetch_assoc($result)) {
  60. // for bit fields we need to convert them to printable form
  61. $i = 0;
  62. foreach ($row as $col => $val) {
  63. if ($fields_meta[$i]->type == 'bit') {
  64. $row[$col] = PMA_Util::printableBitValue($val, $fields_meta[$i]->length);
  65. }
  66. $i++;
  67. }
  68. $extra_data['row_info'] = $row;
  69. }
  70. PMA_Response::getInstance()->addJSON($extra_data);
  71. exit;
  72. }
  73. /**
  74. * Handle AJAX request for changing field information
  75. * (value,collation,operators,field values) in input form
  76. * @var post_params Object containing parameters for the POST request
  77. */
  78. if (isset($_REQUEST['change_tbl_info']) && $_REQUEST['change_tbl_info'] == true) {
  79. $response = PMA_Response::getInstance();
  80. $field = $_REQUEST['field'];
  81. if ($field == 'pma_null') {
  82. $response->addJSON('field_type', '');
  83. $response->addJSON('field_collation', '');
  84. $response->addJSON('field_operators', '');
  85. $response->addJSON('field_value', '');
  86. exit;
  87. }
  88. $key = array_search($field, $table_search->getColumnNames());
  89. $search_index = 0;
  90. if (PMA_isValid($_REQUEST['it'], 'integer')) {
  91. $search_index = $_REQUEST['it'];
  92. }
  93. $properties = $table_search->getColumnProperties($search_index, $key);
  94. $response->addJSON('field_type', htmlspecialchars($properties['type']));
  95. $response->addJSON('field_collation', $properties['collation']);
  96. $response->addJSON('field_operators', $properties['func']);
  97. $response->addJSON('field_value', $properties['value']);
  98. exit;
  99. }
  100. // Gets some core libraries
  101. require_once './libraries/tbl_common.inc.php';
  102. $url_query .= '&amp;goto=tbl_select.php&amp;back=tbl_select.php';
  103. // Gets tables informations
  104. require_once './libraries/tbl_info.inc.php';
  105. if (! isset($goto)) {
  106. $goto = $GLOBALS['cfg']['DefaultTabTable'];
  107. }
  108. // Defines the url to return to in case of error in the next sql statement
  109. $err_url = $goto . '?' . PMA_generate_common_url($db, $table);
  110. //Set default datalabel if not selected
  111. if ( !isset($_POST['zoom_submit']) || $_POST['dataLabel'] == '') {
  112. $dataLabel = PMA_getDisplayField($db, $table);
  113. }
  114. // Displays the zoom search form
  115. $response->addHTML($table_search->getSelectionForm($goto, $dataLabel));
  116. /*
  117. * Handle the input criteria and generate the query result
  118. * Form for displaying query results
  119. */
  120. if (isset($zoom_submit)
  121. && $_POST['criteriaColumnNames'][0] != 'pma_null'
  122. && $_POST['criteriaColumnNames'][1] != 'pma_null'
  123. && $_POST['criteriaColumnNames'][0] != $_POST['criteriaColumnNames'][1]
  124. ) {
  125. //Query generation part
  126. $sql_query = $table_search->buildSqlQuery();
  127. $sql_query .= ' LIMIT ' . $maxPlotLimit;
  128. //Query execution part
  129. $result = PMA_DBI_query($sql_query . ";", null, PMA_DBI_QUERY_STORE);
  130. $fields_meta = PMA_DBI_get_fields_meta($result);
  131. while ($row = PMA_DBI_fetch_assoc($result)) {
  132. //Need a row with indexes as 0,1,2 for the getUniqueCondition
  133. // hence using a temporary array
  134. $tmpRow = array();
  135. foreach ($row as $val) {
  136. $tmpRow[] = $val;
  137. }
  138. //Get unique conditon on each row (will be needed for row update)
  139. $uniqueCondition = PMA_Util::getUniqueCondition(
  140. $result, count($table_search->getColumnNames()), $fields_meta, $tmpRow,
  141. true
  142. );
  143. //Append it to row array as where_clause
  144. $row['where_clause'] = $uniqueCondition[0];
  145. $tmpData = array(
  146. $_POST['criteriaColumnNames'][0] => $row[$_POST['criteriaColumnNames'][0]],
  147. $_POST['criteriaColumnNames'][1] => $row[$_POST['criteriaColumnNames'][1]],
  148. 'where_clause' => $uniqueCondition[0]
  149. );
  150. $tmpData[$dataLabel] = ($dataLabel) ? $row[$dataLabel] : '';
  151. $data[] = $tmpData;
  152. }
  153. unset($tmpData);
  154. //Displays form for point data and scatter plot
  155. $response->addHTML($table_search->getZoomResultsForm($goto, $data));
  156. }
  157. ?>