Translated using Weblate (Indonesian)
[phpmyadmin.git] / tbl_zoom_select.php
blob881ebeff416e4089e19622898b03ca36cdd59eba
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');
34 $table_search = new PMA_TableSearch($db, $table, "zoom");
36 /**
37 * Handle AJAX request for data row on point select
38 * @var post_params Object containing parameters for the POST request
41 if (isset($_REQUEST['get_data_row']) && $_REQUEST['get_data_row'] == true) {
42 $extra_data = array();
43 $row_info_query = 'SELECT * FROM `' . $_REQUEST['db'] . '`.`'
44 . $_REQUEST['table'] . '` WHERE ' . $_REQUEST['where_clause'];
45 $result = $GLOBALS['dbi']->query(
46 $row_info_query . ";", null, PMA_DatabaseInterface::QUERY_STORE
48 $fields_meta = $GLOBALS['dbi']->getFieldsMeta($result);
49 while ($row = $GLOBALS['dbi']->fetchAssoc($result)) {
50 // for bit fields we need to convert them to printable form
51 $i = 0;
52 foreach ($row as $col => $val) {
53 if ($fields_meta[$i]->type == 'bit') {
54 $row[$col] = PMA_Util::printableBitValue(
55 $val, $fields_meta[$i]->length
58 $i++;
60 $extra_data['row_info'] = $row;
62 PMA_Response::getInstance()->addJSON($extra_data);
63 exit;
66 /**
67 * Handle AJAX request for changing field information
68 * (value,collation,operators,field values) in input form
69 * @var post_params Object containing parameters for the POST request
72 if (isset($_REQUEST['change_tbl_info']) && $_REQUEST['change_tbl_info'] == true) {
73 $response = PMA_Response::getInstance();
74 $field = $_REQUEST['field'];
75 if ($field == 'pma_null') {
76 $response->addJSON('field_type', '');
77 $response->addJSON('field_collation', '');
78 $response->addJSON('field_operators', '');
79 $response->addJSON('field_value', '');
80 exit;
82 $key = array_search($field, $table_search->getColumnNames());
83 $properties = $table_search->getColumnProperties($_REQUEST['it'], $key);
84 $response->addJSON('field_type', htmlspecialchars($properties['type']));
85 $response->addJSON('field_collation', $properties['collation']);
86 $response->addJSON('field_operators', $properties['func']);
87 $response->addJSON('field_value', $properties['value']);
88 exit;
91 // Gets some core libraries
92 require_once './libraries/tbl_common.inc.php';
93 $url_query .= '&amp;goto=tbl_select.php&amp;back=tbl_select.php';
95 // Gets tables informations
96 require_once './libraries/tbl_info.inc.php';
98 if (! isset($goto)) {
99 $goto = $GLOBALS['cfg']['DefaultTabTable'];
101 // Defines the url to return to in case of error in the next sql statement
102 $err_url = $goto . PMA_URL_getCommon(array('db' => $db, 'table' => $table));
104 //Set default datalabel if not selected
105 if ( !isset($_POST['zoom_submit']) || $_POST['dataLabel'] == '') {
106 $dataLabel = PMA_getDisplayField($db, $table);
107 } else {
108 $dataLabel = $_POST['dataLabel'];
111 // Displays the zoom search form
112 $response->addHTML($table_search->getSecondaryTabs());
113 $response->addHTML($table_search->getSelectionForm($goto, $dataLabel));
116 * Handle the input criteria and generate the query result
117 * Form for displaying query results
119 if (isset($_POST['zoom_submit'])
120 && $_POST['criteriaColumnNames'][0] != 'pma_null'
121 && $_POST['criteriaColumnNames'][1] != 'pma_null'
122 && $_POST['criteriaColumnNames'][0] != $_POST['criteriaColumnNames'][1]
124 //Query generation part
125 $sql_query = $table_search->buildSqlQuery();
126 $sql_query .= ' LIMIT ' . $_POST['maxPlotLimit'];
128 //Query execution part
129 $result = $GLOBALS['dbi']->query(
130 $sql_query . ";", null, PMA_DatabaseInterface::QUERY_STORE
132 $fields_meta = $GLOBALS['dbi']->getFieldsMeta($result);
133 $data = array();
134 while ($row = $GLOBALS['dbi']->fetchAssoc($result)) {
135 //Need a row with indexes as 0,1,2 for the getUniqueCondition
136 // hence using a temporary array
137 $tmpRow = array();
138 foreach ($row as $val) {
139 $tmpRow[] = $val;
141 //Get unique condition on each row (will be needed for row update)
142 $uniqueCondition = PMA_Util::getUniqueCondition(
143 $result, count($table_search->getColumnNames()), $fields_meta, $tmpRow,
144 true
146 //Append it to row array as where_clause
147 $row['where_clause'] = $uniqueCondition[0];
149 $tmpData = array(
150 $_POST['criteriaColumnNames'][0] =>
151 $row[$_POST['criteriaColumnNames'][0]],
152 $_POST['criteriaColumnNames'][1] =>
153 $row[$_POST['criteriaColumnNames'][1]],
154 'where_clause' => $uniqueCondition[0]
156 $tmpData[$dataLabel] = ($dataLabel) ? $row[$dataLabel] : '';
157 $data[] = $tmpData;
159 unset($tmpData);
161 //Displays form for point data and scatter plot
162 $response->addHTML($table_search->getZoomResultsForm($goto, $data));