Merge remote-tracking branch 'origin/master'
[phpmyadmin.git] / tbl_zoom_select.php
blobb08da2055bdc47a8b586f0e5b557818559ce64fb
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($val, $fields_meta[$i]->length);
60 $i++;
62 $extra_data['row_info'] = $row;
64 PMA_Response::getInstance()->addJSON($extra_data);
65 exit;
68 /**
69 * Handle AJAX request for changing field information
70 * (value,collation,operators,field values) in input form
71 * @var post_params Object containing parameters for the POST request
74 if (isset($_REQUEST['change_tbl_info']) && $_REQUEST['change_tbl_info'] == true) {
75 $response = PMA_Response::getInstance();
76 $field = $_REQUEST['field'];
77 if ($field == 'pma_null') {
78 $response->addJSON('field_type', '');
79 $response->addJSON('field_collation', '');
80 $response->addJSON('field_operators', '');
81 $response->addJSON('field_value', '');
82 exit;
84 $key = array_search($field, $table_search->getColumnNames());
85 $properties = $table_search->getColumnProperties($_REQUEST['it'], $key);
86 $response->addJSON('field_type', $properties['type']);
87 $response->addJSON('field_collation', $properties['collation']);
88 $response->addJSON('field_operators', $properties['func']);
89 $response->addJSON('field_value', $properties['value']);
90 exit;
93 // Gets some core libraries
94 require_once './libraries/tbl_common.inc.php';
95 $url_query .= '&amp;goto=tbl_select.php&amp;back=tbl_select.php';
97 // Gets tables informations
98 require_once './libraries/tbl_info.inc.php';
100 if (! isset($goto)) {
101 $goto = $GLOBALS['cfg']['DefaultTabTable'];
103 // Defines the url to return to in case of error in the next sql statement
104 $err_url = $goto . '?' . PMA_generate_common_url($db, $table);
106 //Set default datalabel if not selected
107 if ( !isset($_POST['zoom_submit']) || $_POST['dataLabel'] == '') {
108 $dataLabel = PMA_getDisplayField($db, $table);
109 } else {
110 $dataLabel = $_POST['dataLabel'];
113 // Displays the zoom search form
114 $response->addHTML($table_search->getSecondaryTabs());
115 $response->addHTML($table_search->getSelectionForm($goto, $dataLabel));
118 * Handle the input criteria and generate the query result
119 * Form for displaying query results
121 if (isset($_POST['zoom_submit'])
122 && $_POST['criteriaColumnNames'][0] != 'pma_null'
123 && $_POST['criteriaColumnNames'][1] != 'pma_null'
124 && $_POST['criteriaColumnNames'][0] != $_POST['criteriaColumnNames'][1]
126 //Query generation part
127 $sql_query = $table_search->buildSqlQuery();
128 $sql_query .= ' LIMIT ' . $_POST['maxPlotLimit'];
130 //Query execution part
131 $result = $GLOBALS['dbi']->query(
132 $sql_query . ";", null, PMA_DatabaseInterface::QUERY_STORE
134 $fields_meta = $GLOBALS['dbi']->getFieldsMeta($result);
135 while ($row = $GLOBALS['dbi']->fetchAssoc($result)) {
136 //Need a row with indexes as 0,1,2 for the getUniqueCondition
137 // hence using a temporary array
138 $tmpRow = array();
139 foreach ($row as $val) {
140 $tmpRow[] = $val;
142 //Get unique conditon on each row (will be needed for row update)
143 $uniqueCondition = PMA_Util::getUniqueCondition(
144 $result, count($table_search->getColumnNames()), $fields_meta, $tmpRow,
145 true
147 //Append it to row array as where_clause
148 $row['where_clause'] = $uniqueCondition[0];
150 $tmpData = array(
151 $_POST['criteriaColumnNames'][0] => $row[$_POST['criteriaColumnNames'][0]],
152 $_POST['criteriaColumnNames'][1] => $row[$_POST['criteriaColumnNames'][1]],
153 'where_clause' => $uniqueCondition[0]
155 $tmpData[$dataLabel] = ($dataLabel) ? $row[$dataLabel] : '';
156 $data[] = $tmpData;
158 unset($tmpData);
160 //Displays form for point data and scatter plot
161 $response->addHTML($table_search->getZoomResultsForm($goto, $data));