Translated using Weblate (Dutch)
[phpmyadmin.git] / tbl_zoom_select.php
blob2f0e738abd2b9052234ba7649d79064ecad275f7
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('jqplot/jquery.jqplot.js');
25 $scripts->addFile('jqplot/plugins/jqplot.canvasTextRenderer.js');
26 $scripts->addFile('jqplot/plugins/jqplot.canvasAxisLabelRenderer.js');
27 $scripts->addFile('jqplot/plugins/jqplot.dateAxisRenderer.js');
28 $scripts->addFile('jqplot/plugins/jqplot.highlighter.js');
29 $scripts->addFile('jqplot/plugins/jqplot.cursor.js');
30 $scripts->addFile('canvg/canvg.js');
31 $scripts->addFile('jquery/jquery-ui-timepicker-addon.js');
32 $scripts->addFile('tbl_zoom_plot_jqplot.js');
33 $scripts->addFile('tbl_change.js');
35 $table_search = new PMA_TableSearch($db, $table, "zoom");
37 /**
38 * Handle AJAX request for data row on point select
39 * @var post_params Object containing parameters for the POST request
42 if (isset($_REQUEST['get_data_row']) && $_REQUEST['get_data_row'] == true) {
43 $extra_data = array();
44 $row_info_query = 'SELECT * FROM `' . $_REQUEST['db'] . '`.`'
45 . $_REQUEST['table'] . '` WHERE ' . $_REQUEST['where_clause'];
46 $result = $GLOBALS['dbi']->query(
47 $row_info_query . ";", null, PMA_DatabaseInterface::QUERY_STORE
49 $fields_meta = $GLOBALS['dbi']->getFieldsMeta($result);
50 while ($row = $GLOBALS['dbi']->fetchAssoc($result)) {
51 // for bit fields we need to convert them to printable form
52 $i = 0;
53 foreach ($row as $col => $val) {
54 if ($fields_meta[$i]->type == 'bit') {
55 $row[$col] = PMA_Util::printableBitValue(
56 $val, $fields_meta[$i]->length
59 $i++;
61 $extra_data['row_info'] = $row;
63 PMA_Response::getInstance()->addJSON($extra_data);
64 exit;
67 /**
68 * Handle AJAX request for changing field information
69 * (value,collation,operators,field values) in input form
70 * @var post_params Object containing parameters for the POST request
73 if (isset($_REQUEST['change_tbl_info']) && $_REQUEST['change_tbl_info'] == true) {
74 $response = PMA_Response::getInstance();
75 $field = $_REQUEST['field'];
76 if ($field == 'pma_null') {
77 $response->addJSON('field_type', '');
78 $response->addJSON('field_collation', '');
79 $response->addJSON('field_operators', '');
80 $response->addJSON('field_value', '');
81 exit;
83 $key = array_search($field, $table_search->getColumnNames());
84 $properties = $table_search->getColumnProperties($_REQUEST['it'], $key);
85 $response->addJSON('field_type', htmlspecialchars($properties['type']));
86 $response->addJSON('field_collation', $properties['collation']);
87 $response->addJSON('field_operators', $properties['func']);
88 $response->addJSON('field_value', $properties['value']);
89 exit;
92 // Gets some core libraries
93 require_once './libraries/tbl_common.inc.php';
94 $url_query .= '&amp;goto=tbl_select.php&amp;back=tbl_select.php';
96 // Gets tables informations
97 require_once './libraries/tbl_info.inc.php';
99 if (! isset($goto)) {
100 $goto = $GLOBALS['cfg']['DefaultTabTable'];
102 // Defines the url to return to in case of error in the next sql statement
103 $err_url = $goto . PMA_URL_getCommon(array('db' => $db, 'table' => $table));
105 //Set default datalabel if not selected
106 if (!isset($_POST['zoom_submit']) || $_POST['dataLabel'] == '') {
107 $dataLabel = PMA_getDisplayField($db, $table);
108 } else {
109 $dataLabel = $_POST['dataLabel'];
112 // Displays the zoom search form
113 $response->addHTML($table_search->getSecondaryTabs());
114 $response->addHTML($table_search->getSelectionForm($goto, $dataLabel));
117 * Handle the input criteria and generate the query result
118 * Form for displaying query results
120 if (isset($_POST['zoom_submit'])
121 && $_POST['criteriaColumnNames'][0] != 'pma_null'
122 && $_POST['criteriaColumnNames'][1] != 'pma_null'
123 && $_POST['criteriaColumnNames'][0] != $_POST['criteriaColumnNames'][1]
125 //Query generation part
126 $sql_query = $table_search->buildSqlQuery();
127 $sql_query .= ' LIMIT ' . $_POST['maxPlotLimit'];
129 //Query execution part
130 $result = $GLOBALS['dbi']->query(
131 $sql_query . ";", null, PMA_DatabaseInterface::QUERY_STORE
133 $fields_meta = $GLOBALS['dbi']->getFieldsMeta($result);
134 $data = array();
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 condition 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] =>
152 $row[$_POST['criteriaColumnNames'][0]],
153 $_POST['criteriaColumnNames'][1] =>
154 $row[$_POST['criteriaColumnNames'][1]],
155 'where_clause' => $uniqueCondition[0]
157 $tmpData[$dataLabel] = ($dataLabel) ? $row[$dataLabel] : '';
158 $data[] = $tmpData;
160 unset($tmpData);
162 //Displays form for point data and scatter plot
163 $response->addHTML($table_search->getZoomResultsForm($goto, $data));