tbl_zoom_select.php 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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.inc.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. $scripts->addFile('jqplot/jquery.jqplot.js');
  23. $scripts->addFile('jqplot/plugins/jqplot.canvasTextRenderer.js');
  24. $scripts->addFile('jqplot/plugins/jqplot.canvasAxisLabelRenderer.js');
  25. $scripts->addFile('jqplot/plugins/jqplot.dateAxisRenderer.js');
  26. $scripts->addFile('jqplot/plugins/jqplot.highlighter.js');
  27. $scripts->addFile('jqplot/plugins/jqplot.cursor.js');
  28. $scripts->addFile('canvg/canvg.js');
  29. $scripts->addFile('jquery/jquery-ui-timepicker-addon.js');
  30. $scripts->addFile('tbl_zoom_plot_jqplot.js');
  31. $table_search = new PMA_TableSearch($db, $table, "zoom");
  32. /**
  33. * Handle AJAX request for data row on point select
  34. * @var post_params Object containing parameters for the POST request
  35. */
  36. if (isset($_REQUEST['get_data_row']) && $_REQUEST['get_data_row'] == true) {
  37. $extra_data = array();
  38. $row_info_query = 'SELECT * FROM `' . $_REQUEST['db'] . '`.`'
  39. . $_REQUEST['table'] . '` WHERE ' . $_REQUEST['where_clause'];
  40. $result = $GLOBALS['dbi']->query(
  41. $row_info_query . ";", null, PMA_DatabaseInterface::QUERY_STORE
  42. );
  43. $fields_meta = $GLOBALS['dbi']->getFieldsMeta($result);
  44. while ($row = $GLOBALS['dbi']->fetchAssoc($result)) {
  45. // for bit fields we need to convert them to printable form
  46. $i = 0;
  47. foreach ($row as $col => $val) {
  48. if ($fields_meta[$i]->type == 'bit') {
  49. $row[$col] = PMA_Util::printableBitValue(
  50. $val, $fields_meta[$i]->length
  51. );
  52. }
  53. $i++;
  54. }
  55. $extra_data['row_info'] = $row;
  56. }
  57. PMA_Response::getInstance()->addJSON($extra_data);
  58. exit;
  59. }
  60. /**
  61. * Handle AJAX request for changing field information
  62. * (value,collation,operators,field values) in input form
  63. * @var post_params Object containing parameters for the POST request
  64. */
  65. if (isset($_REQUEST['change_tbl_info']) && $_REQUEST['change_tbl_info'] == true) {
  66. $response = PMA_Response::getInstance();
  67. $field = $_REQUEST['field'];
  68. if ($field == 'pma_null') {
  69. $response->addJSON('field_type', '');
  70. $response->addJSON('field_collation', '');
  71. $response->addJSON('field_operators', '');
  72. $response->addJSON('field_value', '');
  73. exit;
  74. }
  75. $key = array_search($field, $table_search->getColumnNames());
  76. $properties = $table_search->getColumnProperties($_REQUEST['it'], $key);
  77. $response->addJSON('field_type', $properties['type']);
  78. $response->addJSON('field_collation', $properties['collation']);
  79. $response->addJSON('field_operators', $properties['func']);
  80. $response->addJSON('field_value', $properties['value']);
  81. exit;
  82. }
  83. // Gets some core libraries
  84. require_once './libraries/tbl_common.inc.php';
  85. $url_query .= '&amp;goto=tbl_select.php&amp;back=tbl_select.php';
  86. // Gets tables informations
  87. require_once './libraries/tbl_info.inc.php';
  88. if (! isset($goto)) {
  89. $goto = $GLOBALS['cfg']['DefaultTabTable'];
  90. }
  91. // Defines the url to return to in case of error in the next sql statement
  92. $err_url = $goto . '?' . PMA_URL_getCommon($db, $table);
  93. //Set default datalabel if not selected
  94. if ( !isset($_POST['zoom_submit']) || $_POST['dataLabel'] == '') {
  95. $dataLabel = PMA_getDisplayField($db, $table);
  96. } else {
  97. $dataLabel = $_POST['dataLabel'];
  98. }
  99. // Displays the zoom search form
  100. $response->addHTML($table_search->getSecondaryTabs());
  101. $response->addHTML($table_search->getSelectionForm($goto, $dataLabel));
  102. /*
  103. * Handle the input criteria and generate the query result
  104. * Form for displaying query results
  105. */
  106. if (isset($_POST['zoom_submit'])
  107. && $_POST['criteriaColumnNames'][0] != 'pma_null'
  108. && $_POST['criteriaColumnNames'][1] != 'pma_null'
  109. && $_POST['criteriaColumnNames'][0] != $_POST['criteriaColumnNames'][1]
  110. ) {
  111. //Query generation part
  112. $sql_query = $table_search->buildSqlQuery();
  113. $sql_query .= ' LIMIT ' . $_POST['maxPlotLimit'];
  114. //Query execution part
  115. $result = $GLOBALS['dbi']->query(
  116. $sql_query . ";", null, PMA_DatabaseInterface::QUERY_STORE
  117. );
  118. $fields_meta = $GLOBALS['dbi']->getFieldsMeta($result);
  119. while ($row = $GLOBALS['dbi']->fetchAssoc($result)) {
  120. //Need a row with indexes as 0,1,2 for the getUniqueCondition
  121. // hence using a temporary array
  122. $tmpRow = array();
  123. foreach ($row as $val) {
  124. $tmpRow[] = $val;
  125. }
  126. //Get unique conditon on each row (will be needed for row update)
  127. $uniqueCondition = PMA_Util::getUniqueCondition(
  128. $result, count($table_search->getColumnNames()), $fields_meta, $tmpRow,
  129. true
  130. );
  131. //Append it to row array as where_clause
  132. $row['where_clause'] = $uniqueCondition[0];
  133. $tmpData = array(
  134. $_POST['criteriaColumnNames'][0] =>
  135. $row[$_POST['criteriaColumnNames'][0]],
  136. $_POST['criteriaColumnNames'][1] =>
  137. $row[$_POST['criteriaColumnNames'][1]],
  138. 'where_clause' => $uniqueCondition[0]
  139. );
  140. $tmpData[$dataLabel] = ($dataLabel) ? $row[$dataLabel] : '';
  141. $data[] = $tmpData;
  142. }
  143. unset($tmpData);
  144. //Displays form for point data and scatter plot
  145. $response->addHTML($table_search->getZoomResultsForm($goto, $data));
  146. }
  147. ?>