2 /* vim: set expandtab sw=4 ts=4 sts=4: */
4 * Handles table zoom search tab
6 * display table zoom search form, create SQL queries from form data
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");
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
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
61 $extra_data['row_info'] = $row;
63 PMA_Response
::getInstance()->addJSON($extra_data);
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', '');
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']);
92 // Gets some core libraries
93 require_once './libraries/tbl_common.inc.php';
94 $url_query .= '&goto=tbl_select.php&back=tbl_select.php';
96 // Gets tables informations
97 require_once './libraries/tbl_info.inc.php';
100 $goto = PMA_Util
::getScriptNameForOption(
101 $GLOBALS['cfg']['DefaultTabTable'], 'table'
104 // Defines the url to return to in case of error in the next sql statement
105 $err_url = $goto . PMA_URL_getCommon(array('db' => $db, 'table' => $table));
107 //Set default datalabel if not selected
108 if (!isset($_POST['zoom_submit']) ||
$_POST['dataLabel'] == '') {
109 $dataLabel = PMA_getDisplayField($db, $table);
111 $dataLabel = $_POST['dataLabel'];
114 // Displays the zoom search form
115 $response->addHTML($table_search->getSecondaryTabs());
116 $response->addHTML($table_search->getSelectionForm($goto, $dataLabel));
119 * Handle the input criteria and generate the query result
120 * Form for displaying query results
122 if (isset($_POST['zoom_submit'])
123 && $_POST['criteriaColumnNames'][0] != 'pma_null'
124 && $_POST['criteriaColumnNames'][1] != 'pma_null'
125 && $_POST['criteriaColumnNames'][0] != $_POST['criteriaColumnNames'][1]
127 //Query generation part
128 $sql_query = $table_search->buildSqlQuery();
129 $sql_query .= ' LIMIT ' . $_POST['maxPlotLimit'];
131 //Query execution part
132 $result = $GLOBALS['dbi']->query(
133 $sql_query . ";", null, PMA_DatabaseInterface
::QUERY_STORE
135 $fields_meta = $GLOBALS['dbi']->getFieldsMeta($result);
137 while ($row = $GLOBALS['dbi']->fetchAssoc($result)) {
138 //Need a row with indexes as 0,1,2 for the getUniqueCondition
139 // hence using a temporary array
141 foreach ($row as $val) {
144 //Get unique condition on each row (will be needed for row update)
145 $uniqueCondition = PMA_Util
::getUniqueCondition(
146 $result, count($table_search->getColumnNames()), $fields_meta, $tmpRow,
149 //Append it to row array as where_clause
150 $row['where_clause'] = $uniqueCondition[0];
153 $_POST['criteriaColumnNames'][0] =>
154 $row[$_POST['criteriaColumnNames'][0]],
155 $_POST['criteriaColumnNames'][1] =>
156 $row[$_POST['criteriaColumnNames'][1]],
157 'where_clause' => $uniqueCondition[0]
159 $tmpData[$dataLabel] = ($dataLabel) ?
$row[$dataLabel] : '';
164 //Displays form for point data and scatter plot
165 $response->addHTML($table_search->getZoomResultsForm($goto, $data));