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