Merge remote-tracking branch 'origin/QA_4_0'
[phpmyadmin/aamir.git] / tbl_zoom_select.php
blob29d454666546d2be163602b3a3c3810b3efeb8d2
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 $scripts->addFile('date.js');
25 /* < IE 9 doesn't support canvas natively */
26 if (PMA_USR_BROWSER_AGENT == 'IE' && PMA_USR_BROWSER_VER < 9) {
27 $scripts->addFile('canvg/flashcanvas.js');
29 $scripts->addFile('jqplot/jquery.jqplot.js');
30 $scripts->addFile('jqplot/plugins/jqplot.canvasTextRenderer.js');
31 $scripts->addFile('jqplot/plugins/jqplot.canvasAxisLabelRenderer.js');
32 $scripts->addFile('jqplot/plugins/jqplot.dateAxisRenderer.js');
33 $scripts->addFile('jqplot/plugins/jqplot.highlighter.js');
34 $scripts->addFile('jqplot/plugins/jqplot.cursor.js');
35 $scripts->addFile('canvg/canvg.js');
36 $scripts->addFile('jquery/jquery-ui-timepicker-addon.js');
37 $scripts->addFile('tbl_zoom_plot_jqplot.js');
39 $table_search = new PMA_TableSearch($db, $table, "zoom");
41 /**
42 * Handle AJAX request for data row on point select
43 * @var post_params Object containing parameters for the POST request
46 if (isset($_REQUEST['get_data_row']) && $_REQUEST['get_data_row'] == true) {
47 $extra_data = array();
48 $row_info_query = 'SELECT * FROM `' . $_REQUEST['db'] . '`.`'
49 . $_REQUEST['table'] . '` WHERE ' . $_REQUEST['where_clause'];
50 $result = $GLOBALS['dbi']->query(
51 $row_info_query . ";", null, PMA_DatabaseInterface::QUERY_STORE
53 $fields_meta = $GLOBALS['dbi']->getFieldsMeta($result);
54 while ($row = $GLOBALS['dbi']->fetchAssoc($result)) {
55 // for bit fields we need to convert them to printable form
56 $i = 0;
57 foreach ($row as $col => $val) {
58 if ($fields_meta[$i]->type == 'bit') {
59 $row[$col] = PMA_Util::printableBitValue($val, $fields_meta[$i]->length);
61 $i++;
63 $extra_data['row_info'] = $row;
65 PMA_Response::getInstance()->addJSON($extra_data);
66 exit;
69 /**
70 * Handle AJAX request for changing field information
71 * (value,collation,operators,field values) in input form
72 * @var post_params Object containing parameters for the POST request
75 if (isset($_REQUEST['change_tbl_info']) && $_REQUEST['change_tbl_info'] == true) {
76 $response = PMA_Response::getInstance();
77 $field = $_REQUEST['field'];
78 if ($field == 'pma_null') {
79 $response->addJSON('field_type', '');
80 $response->addJSON('field_collation', '');
81 $response->addJSON('field_operators', '');
82 $response->addJSON('field_value', '');
83 exit;
85 $key = array_search($field, $table_search->getColumnNames());
86 $properties = $table_search->getColumnProperties($_REQUEST['it'], $key);
87 $response->addJSON('field_type', $properties['type']);
88 $response->addJSON('field_collation', $properties['collation']);
89 $response->addJSON('field_operators', $properties['func']);
90 $response->addJSON('field_value', $properties['value']);
91 exit;
94 // Gets some core libraries
95 require_once './libraries/tbl_common.inc.php';
96 $url_query .= '&amp;goto=tbl_select.php&amp;back=tbl_select.php';
98 // Gets tables informations
99 require_once './libraries/tbl_info.inc.php';
101 if (! isset($goto)) {
102 $goto = $GLOBALS['cfg']['DefaultTabTable'];
104 // Defines the url to return to in case of error in the next sql statement
105 $err_url = $goto . '?' . PMA_generate_common_url($db, $table);
107 //Set default datalabel if not selected
108 if ( !isset($_POST['zoom_submit']) || $_POST['dataLabel'] == '') {
109 $dataLabel = PMA_getDisplayField($db, $table);
110 } else {
111 $dataLabel = $_POST['dataLabel'];
114 // Displays the zoom search form
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));