Translated using Weblate (Polish)
[phpmyadmin.git] / tbl_zoom_select.php
blob2c6a12344b9de7d5b000a90aa5d14d53d901a418
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.lib.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 /**
39 * Sets globals from $_POST
41 $post_params = array(
42 'dataLabel',
43 'maxPlotLimit',
44 'zoom_submit'
46 foreach ($post_params as $one_post_param) {
47 if (isset($_POST[$one_post_param])) {
48 $GLOBALS[$one_post_param] = $_POST[$one_post_param];
52 $table_search = new PMA_TableSearch($db, $table, "zoom");
54 /**
55 * Handle AJAX request for data row on point select
56 * @var post_params Object containing parameters for the POST request
59 if (isset($_REQUEST['get_data_row']) && $_REQUEST['get_data_row'] == true) {
60 $extra_data = array();
61 $row_info_query = 'SELECT * FROM `' . $_REQUEST['db'] . '`.`'
62 . $_REQUEST['table'] . '` WHERE ' . $_REQUEST['where_clause'];
63 $result = PMA_DBI_query($row_info_query . ";", null, PMA_DBI_QUERY_STORE);
64 $fields_meta = PMA_DBI_get_fields_meta($result);
65 while ($row = PMA_DBI_fetch_assoc($result)) {
66 // for bit fields we need to convert them to printable form
67 $i = 0;
68 foreach ($row as $col => $val) {
69 if ($fields_meta[$i]->type == 'bit') {
70 $row[$col] = PMA_Util::printableBitValue($val, $fields_meta[$i]->length);
72 $i++;
74 $extra_data['row_info'] = $row;
76 PMA_Response::getInstance()->addJSON($extra_data);
77 exit;
80 /**
81 * Handle AJAX request for changing field information
82 * (value,collation,operators,field values) in input form
83 * @var post_params Object containing parameters for the POST request
86 if (isset($_REQUEST['change_tbl_info']) && $_REQUEST['change_tbl_info'] == true) {
87 $response = PMA_Response::getInstance();
88 $field = $_REQUEST['field'];
89 if ($field == 'pma_null') {
90 $response->addJSON('field_type', '');
91 $response->addJSON('field_collation', '');
92 $response->addJSON('field_operators', '');
93 $response->addJSON('field_value', '');
94 exit;
96 $key = array_search($field, $table_search->getColumnNames());
97 $properties = $table_search->getColumnProperties($_REQUEST['it'], $key);
98 $response->addJSON('field_type', $properties['type']);
99 $response->addJSON('field_collation', $properties['collation']);
100 $response->addJSON('field_operators', $properties['func']);
101 $response->addJSON('field_value', $properties['value']);
102 exit;
105 // Gets some core libraries
106 require_once './libraries/tbl_common.inc.php';
107 $url_query .= '&amp;goto=tbl_select.php&amp;back=tbl_select.php';
109 // Gets tables informations
110 require_once './libraries/tbl_info.inc.php';
112 if (! isset($goto)) {
113 $goto = $GLOBALS['cfg']['DefaultTabTable'];
115 // Defines the url to return to in case of error in the next sql statement
116 $err_url = $goto . '?' . PMA_generate_common_url($db, $table);
118 //Set default datalabel if not selected
119 if ( !isset($_POST['zoom_submit']) || $_POST['dataLabel'] == '') {
120 $dataLabel = PMA_getDisplayField($db, $table);
123 // Displays the zoom search form
124 $response->addHTML($table_search->getSelectionForm($goto, $dataLabel));
127 * Handle the input criteria and generate the query result
128 * Form for displaying query results
130 if (isset($zoom_submit)
131 && $_POST['criteriaColumnNames'][0] != 'pma_null'
132 && $_POST['criteriaColumnNames'][1] != 'pma_null'
133 && $_POST['criteriaColumnNames'][0] != $_POST['criteriaColumnNames'][1]
135 //Query generation part
136 $sql_query = $table_search->buildSqlQuery();
137 $sql_query .= ' LIMIT ' . $maxPlotLimit;
139 //Query execution part
140 $result = PMA_DBI_query($sql_query . ";", null, PMA_DBI_QUERY_STORE);
141 $fields_meta = PMA_DBI_get_fields_meta($result);
142 while ($row = PMA_DBI_fetch_assoc($result)) {
143 //Need a row with indexes as 0,1,2 for the getUniqueCondition
144 // hence using a temporary array
145 $tmpRow = array();
146 foreach ($row as $val) {
147 $tmpRow[] = $val;
149 //Get unique conditon on each row (will be needed for row update)
150 $uniqueCondition = PMA_Util::getUniqueCondition(
151 $result, count($table_search->getColumnNames()), $fields_meta, $tmpRow,
152 true
154 //Append it to row array as where_clause
155 $row['where_clause'] = $uniqueCondition[0];
157 $tmpData = array(
158 $_POST['criteriaColumnNames'][0] => $row[$_POST['criteriaColumnNames'][0]],
159 $_POST['criteriaColumnNames'][1] => $row[$_POST['criteriaColumnNames'][1]],
160 'where_clause' => $uniqueCondition[0]
162 $tmpData[$dataLabel] = ($dataLabel) ? $row[$dataLabel] : '';
163 $data[] = $tmpData;
165 unset($tmpData);
167 //Displays form for point data and scatter plot
168 $response->addHTML($table_search->getZoomResultsForm($goto, $data));