very minor mod to previous Direct Messaging update commit
[openemr.git] / phpmyadmin / tbl_zoom_select.php
blobf2ab6e6b41d17d7a96c30d737ad81d99942491f1
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 $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 /**
40 * Sets globals from $_POST
42 $post_params = array(
43 'dataLabel',
44 'maxPlotLimit',
45 'zoom_submit'
47 foreach ($post_params as $one_post_param) {
48 if (isset($_POST[$one_post_param])) {
49 $GLOBALS[$one_post_param] = $_POST[$one_post_param];
53 $table_search = new PMA_TableSearch($db, $table, "zoom");
55 /**
56 * Handle AJAX request for data row on point select
57 * @var post_params Object containing parameters for the POST request
60 if (isset($_REQUEST['get_data_row']) && $_REQUEST['get_data_row'] == true) {
61 $extra_data = array();
62 $row_info_query = 'SELECT * FROM `' . $_REQUEST['db'] . '`.`'
63 . $_REQUEST['table'] . '` WHERE ' . $_REQUEST['where_clause'];
64 $result = PMA_DBI_query($row_info_query . ";", null, PMA_DBI_QUERY_STORE);
65 $fields_meta = PMA_DBI_get_fields_meta($result);
66 while ($row = PMA_DBI_fetch_assoc($result)) {
67 // for bit fields we need to convert them to printable form
68 $i = 0;
69 foreach ($row as $col => $val) {
70 if ($fields_meta[$i]->type == 'bit') {
71 $row[$col] = PMA_Util::printableBitValue($val, $fields_meta[$i]->length);
73 $i++;
75 $extra_data['row_info'] = $row;
77 PMA_Response::getInstance()->addJSON($extra_data);
78 exit;
81 /**
82 * Handle AJAX request for changing field information
83 * (value,collation,operators,field values) in input form
84 * @var post_params Object containing parameters for the POST request
87 if (isset($_REQUEST['change_tbl_info']) && $_REQUEST['change_tbl_info'] == true) {
88 $response = PMA_Response::getInstance();
89 $field = $_REQUEST['field'];
90 if ($field == 'pma_null') {
91 $response->addJSON('field_type', '');
92 $response->addJSON('field_collation', '');
93 $response->addJSON('field_operators', '');
94 $response->addJSON('field_value', '');
95 exit;
97 $key = array_search($field, $table_search->getColumnNames());
98 $properties = $table_search->getColumnProperties($_REQUEST['it'], $key);
99 $response->addJSON('field_type', $properties['type']);
100 $response->addJSON('field_collation', $properties['collation']);
101 $response->addJSON('field_operators', $properties['func']);
102 $response->addJSON('field_value', $properties['value']);
103 exit;
106 // Gets some core libraries
107 require_once './libraries/tbl_common.inc.php';
108 $url_query .= '&amp;goto=tbl_select.php&amp;back=tbl_select.php';
110 // Gets tables informations
111 require_once './libraries/tbl_info.inc.php';
113 if (! isset($goto)) {
114 $goto = $GLOBALS['cfg']['DefaultTabTable'];
116 // Defines the url to return to in case of error in the next sql statement
117 $err_url = $goto . '?' . PMA_generate_common_url($db, $table);
119 //Set default datalabel if not selected
120 if ( !isset($_POST['zoom_submit']) || $_POST['dataLabel'] == '') {
121 $dataLabel = PMA_getDisplayField($db, $table);
124 // Displays the zoom search form
125 $response->addHTML($table_search->getSelectionForm($goto, $dataLabel));
128 * Handle the input criteria and generate the query result
129 * Form for displaying query results
131 if (isset($zoom_submit)
132 && $_POST['criteriaColumnNames'][0] != 'pma_null'
133 && $_POST['criteriaColumnNames'][1] != 'pma_null'
134 && $_POST['criteriaColumnNames'][0] != $_POST['criteriaColumnNames'][1]
136 //Query generation part
137 $sql_query = $table_search->buildSqlQuery();
138 $sql_query .= ' LIMIT ' . $maxPlotLimit;
140 //Query execution part
141 $result = PMA_DBI_query($sql_query . ";", null, PMA_DBI_QUERY_STORE);
142 $fields_meta = PMA_DBI_get_fields_meta($result);
143 while ($row = PMA_DBI_fetch_assoc($result)) {
144 //Need a row with indexes as 0,1,2 for the getUniqueCondition
145 // hence using a temporary array
146 $tmpRow = array();
147 foreach ($row as $val) {
148 $tmpRow[] = $val;
150 //Get unique conditon on each row (will be needed for row update)
151 $uniqueCondition = PMA_Util::getUniqueCondition(
152 $result, count($table_search->getColumnNames()), $fields_meta, $tmpRow,
153 true
155 //Append it to row array as where_clause
156 $row['where_clause'] = $uniqueCondition[0];
158 $tmpData = array(
159 $_POST['criteriaColumnNames'][0] => $row[$_POST['criteriaColumnNames'][0]],
160 $_POST['criteriaColumnNames'][1] => $row[$_POST['criteriaColumnNames'][1]],
161 'where_clause' => $uniqueCondition[0]
163 $tmpData[$dataLabel] = ($dataLabel) ? $row[$dataLabel] : '';
164 $data[] = $tmpData;
166 unset($tmpData);
168 //Displays form for point data and scatter plot
169 $response->addHTML($table_search->getZoomResultsForm($goto, $data));