From 70167fed52368079d1cbffd445514480f29d9ff3 Mon Sep 17 00:00:00 2001 From: Ammar Yasir Date: Wed, 1 Jun 2011 01:22:31 +0530 Subject: [PATCH] Made suggested change to tbl_select.php and tbl_zoom_select.php --- js/tbl_select.js | 10 +- libraries/tbl_select.lib.php | 272 +++++++++++++++++------------------ tbl_select.php | 6 +- tbl_zoom_select.php | 180 ++++++++++++----------- 4 files changed, 228 insertions(+), 240 deletions(-) diff --git a/js/tbl_select.js b/js/tbl_select.js index a66920d1a3..1442bbe46b 100644 --- a/js/tbl_select.js +++ b/js/tbl_select.js @@ -22,13 +22,9 @@ $(document).ready(function() { cache: 'false' }); - /*if($('#id_flag').val()==2) - { - $('#tbl_search_form').hide(); - $('#zoom_search_form').show(); - - }*/ - + /** + * Form submit on field change + */ $('#tableid_0').change(function() { $('#zoom_search_form').submit(); }) diff --git a/libraries/tbl_select.lib.php b/libraries/tbl_select.lib.php index 6f301429bc..a78404b421 100644 --- a/libraries/tbl_select.lib.php +++ b/libraries/tbl_select.lib.php @@ -11,8 +11,6 @@ require_once 'url_generating.lib.php'; - - /** * PMA_tbl_setTitle() sets the title for foreign keys display link * @@ -23,14 +21,14 @@ require_once 'url_generating.lib.php'; */ function PMA_tbl_setTitle($propertiesIconic,$pmaThemeImage){ - if ($propertiesIconic == true) { - $str = '' . __('Browse foreign values') . ''; + if ($propertiesIconic == true) { + $str = '' . __('Browse foreign values') . ''; - if ($propertiesIconic === 'both') { - $str .= __('Browse foreign values'); - return $str; + if ($propertiesIconic === 'both') { + $str .= __('Browse foreign values'); + return $str; } } else { return __('Browse foreign values'); @@ -108,7 +106,7 @@ function PMA_tbl_getFields($table,$db) { function PMA_tbl_setTableHeader(){ return ' - ' . __('Column') . ' + ' . __('Column') . ' ' . __('Type') . ' ' . __('Collation') . ' ' . __('Operator') . ' @@ -127,20 +125,20 @@ return ' function PMA_tbl_getSubTabs(){ - $subtabs = array(); + $subtabs = array(); - $subtabs['search']['icon'] = 'b_search.png'; - $subtabs['search']['text'] = __('Table Search'); - $subtabs['search']['link'] = 'tbl_select.php'; - $subtabs['search']['id'] = 'tbl_search_id'; - $subtabs['search']['args']['pos'] = 0; + $subtabs['search']['icon'] = 'b_search.png'; + $subtabs['search']['text'] = __('Table Search'); + $subtabs['search']['link'] = 'tbl_select.php'; + $subtabs['search']['id'] = 'tbl_search_id'; + $subtabs['search']['args']['pos'] = 0; - $subtabs['zoom']['icon'] = 'b_props.png'; - $subtabs['zoom']['link'] = 'tbl_zoom_select.php'; - $subtabs['zoom']['text'] = __('Zoom Search'); - $subtabs['zoom']['id'] = 'zoom_search_id'; + $subtabs['zoom']['icon'] = 'b_props.png'; + $subtabs['zoom']['link'] = 'tbl_zoom_select.php'; + $subtabs['zoom']['text'] = __('Zoom Search'); + $subtabs['zoom']['id'] = 'zoom_search_id'; - return $subtabs; + return $subtabs; } @@ -173,47 +171,46 @@ function PMA_tbl_getSubTabs(){ function PMA_getForeignFields_Values($foreigners, $foreignData, $field, $tbl_fields_type, $i, $db, $table,$titles,$foreignMaxLimit, $fields){ - $str = ''; + $str = ''; - if ($foreigners && isset($foreigners[$field]) && is_array($foreignData['disp_row'])) { + if ($foreigners && isset($foreigners[$field]) && is_array($foreignData['disp_row'])) { - // f o r e i g n k e y s - $str .= ' ' . "\n"; + // go back to first row + // here, the 4th parameter is empty because there is no current + // value of data for the dropdown (the search page initial values + // are displayed empty) + $str .= PMA_foreignDropdown($foreignData['disp_row'], + $foreignData['foreign_field'], + $foreignData['foreign_display'], + '', $foreignMaxLimit); + $str .= ' ' . "\n"; + } + elseif ($foreignData['foreign_link'] == true) { - // here, the 4th parameter is empty because there is no current - // value of data for the dropdown (the search page initial values - // are displayed empty) - $str .= PMA_foreignDropdown($foreignData['disp_row'], - $foreignData['foreign_field'], - $foreignData['foreign_display'], - '', $foreignMaxLimit); - $str .= ' ' . "\n"; - } elseif ($foreignData['foreign_link'] == true) { - - $str .= '' ; ?> + $str .= '' ; ?> - '; - // '; + // ' . str_replace("'", "\'", $titles['Browse']) . '\');'; - // ]] - $str .= ''; - ?> - ' . "\n"; + $str .= '' . PMA_generate_common_url($db, $table) . '&field=' . urlencode($field) . '&fieldkey=' . $i . '">' . str_replace("'", "\'", $titles['Browse']) . '\');'; + // ]] + $str .= ''; + } + elseif (strncasecmp($tbl_fields_type[$i], 'enum', 4) == 0) { + // e n u m s + $enum_value=explode(', ', str_replace("'", '', substr($tbl_fields_type[$i], 5, -1))); + $cnt_enum_value = count($enum_value); + $str .= '' . "\n"; - } else { - // o t h e r c a s e s - $the_class = 'textfield'; - $type = $tbl_fields_type[$i]; - if ($type == 'date') { - $the_class .= ' datefield'; - } elseif ($type == 'datetime' || substr($type, 0, 9) == 'timestamp') { - $the_class .= ' datetimefield'; - } - if(isset($fields[$i]) && is_string($fields[$i])){ - $str .= ' ' . "\n"; - } - else{ - $str .= ' ' . "\n"; - } - }; - return $str; + $str .= ' ' . "\n"; + } + else { + // o t h e r c a s e s + $the_class = 'textfield'; + $type = $tbl_fields_type[$i]; + if ($type == 'date') { + $the_class .= ' datefield'; + } elseif ($type == 'datetime' || substr($type, 0, 9) == 'timestamp') { + $the_class .= ' datetimefield'; + } + if(isset($fields[$i]) && is_string($fields[$i])){ + $str .= ' ' . "\n"; + } + else{ + $str .= ' ' . "\n"; + } + }; + return $str; } @@ -271,79 +269,79 @@ EOT; function PMA_tbl_search_getWhereClause($fields, $names, $types, $collations, $func_type, $unaryFlag){ - $w = ''; - if($unaryFlag){ - $fields = ''; - $w = PMA_backquote($names) . ' ' . $func_type; + $w = ''; + if($unaryFlag){ + $fields = ''; + $w = PMA_backquote($names) . ' ' . $func_type; - } elseif (strncasecmp($types, 'enum', 4) == 0) { - if (!empty($fields)) { - if (! is_array($fields)) { - $fields = explode(',', $fields); - } - $enum_selected_count = count($fields); - if ($func_type == '=' && $enum_selected_count > 1) { - $func_type = 'IN'; - $parens_open = '('; - $parens_close = ')'; + } elseif (strncasecmp($types, 'enum', 4) == 0) { + if (!empty($fields)) { + if (! is_array($fields)) { + $fields = explode(',', $fields); + } + $enum_selected_count = count($fields); + if ($func_type == '=' && $enum_selected_count > 1) { + $func_type = 'IN'; + $parens_open = '('; + $parens_close = ')'; - } elseif ($func_type == '!=' && $enum_selected_count > 1) { - $func_type = 'NOT IN'; - $parens_open = '('; - $parens_close = ')'; + } elseif ($func_type == '!=' && $enum_selected_count > 1) { + $func_type = 'NOT IN'; + $parens_open = '('; + $parens_close = ')'; - } else { - $parens_open = ''; - $parens_close = ''; - } - $enum_where = '\'' . PMA_sqlAddslashes($fields[0]) . '\''; - for ($e = 1; $e < $enum_selected_count; $e++) { - $enum_where .= ', \'' . PMA_sqlAddslashes($fields[$e]) . '\''; - } + } else { + $parens_open = ''; + $parens_close = ''; + } + $enum_where = '\'' . PMA_sqlAddslashes($fields[0]) . '\''; + for ($e = 1; $e < $enum_selected_count; $e++) { + $enum_where .= ', \'' . PMA_sqlAddslashes($fields[$e]) . '\''; + } - $w = PMA_backquote($names) . ' ' . $func_type . ' ' . $parens_open . $enum_where . $parens_close; - } + $w = PMA_backquote($names) . ' ' . $func_type . ' ' . $parens_open . $enum_where . $parens_close; + } - } elseif ($fields != '') { - // For these types we quote the value. Even if it's another type (like INT), - // for a LIKE we always quote the value. MySQL converts strings to numbers - // and numbers to strings as necessary during the comparison - if (preg_match('@char|binary|blob|text|set|date|time|year@i', $types) || strpos(' ' . $func_type, 'LIKE')) { - $quot = '\''; - } else { - $quot = ''; - } + } elseif ($fields != '') { + // For these types we quote the value. Even if it's another type (like INT), + // for a LIKE we always quote the value. MySQL converts strings to numbers + // and numbers to strings as necessary during the comparison + if (preg_match('@char|binary|blob|text|set|date|time|year@i', $types) || strpos(' ' . $func_type, 'LIKE')) { + $quot = '\''; + } else { + $quot = ''; + } - // LIKE %...% - if ($func_type == 'LIKE %...%') { - $func_type = 'LIKE'; - $fields = '%' . $fields . '%'; - } - if ($func_type == 'REGEXP ^...$') { - $func_type = 'REGEXP'; - $fields = '^' . $fields . '$'; - } + // LIKE %...% + if ($func_type == 'LIKE %...%') { + $func_type = 'LIKE'; + $fields = '%' . $fields . '%'; + } + if ($func_type == 'REGEXP ^...$') { + $func_type = 'REGEXP'; + $fields = '^' . $fields . '$'; + } - if ($func_type == 'IN (...)' || $func_type == 'NOT IN (...)' || $func_type == 'BETWEEN' || $func_type == 'NOT BETWEEN') { - $func_type = str_replace(' (...)', '', $func_type); + if ($func_type == 'IN (...)' || $func_type == 'NOT IN (...)' || $func_type == 'BETWEEN' || $func_type == 'NOT BETWEEN') { + $func_type = str_replace(' (...)', '', $func_type); - // quote values one by one - $values = explode(',', $fields); - foreach ($values as &$value) - $value = $quot . PMA_sqlAddslashes(trim($value)) . $quot; + // quote values one by one + $values = explode(',', $fields); + foreach ($values as &$value) + $value = $quot . PMA_sqlAddslashes(trim($value)) . $quot; - if ($func_type == 'BETWEEN' || $func_type == 'NOT BETWEEN') - $w = PMA_backquote($names) . ' ' . $func_type . ' ' . (isset($values[0]) ? $values[0] : '') . ' AND ' . (isset($values[1]) ? $values[1] : ''); - else - $w = PMA_backquote($names) . ' ' . $func_type . ' (' . implode(',', $values) . ')'; - } - else { - $w = PMA_backquote($names) . ' ' . $func_type . ' ' . $quot . PMA_sqlAddslashes($fields) . $quot;; - } + if ($func_type == 'BETWEEN' || $func_type == 'NOT BETWEEN') + $w = PMA_backquote($names) . ' ' . $func_type . ' ' . (isset($values[0]) ? $values[0] : '') . ' AND ' . (isset($values[1]) ? $values[1] : ''); + else + $w = PMA_backquote($names) . ' ' . $func_type . ' (' . implode(',', $values) . ')'; + } + else { + $w = PMA_backquote($names) . ' ' . $func_type . ' ' . $quot . PMA_sqlAddslashes($fields) . $quot;; + } - } // end if + } // end if - return $w; + return $w; } ?> diff --git a/tbl_select.php b/tbl_select.php index ee89c13c64..cbd697e32c 100644 --- a/tbl_select.php +++ b/tbl_select.php @@ -51,11 +51,7 @@ if (! isset($param) || $param[0] == '') { // Gets the list and number of fields - $fields_array = PMA_tbl_getFields($table,$db); - $fields_list = $fields_array[0]; - $fields_type = $fields_array[1]; - $fields_collation = $fields_array[2]; - $fields_null = $fields_array[3]; + list($fields_list, $fields_type, $fields_collation, $fields_null) = PMA_tbl_getFields($table,$db); $fields_cnt = count($fields_list); // retrieve keys into foreign fields, if any diff --git a/tbl_zoom_select.php b/tbl_zoom_select.php index fb85ab40fa..91b8c3d5b8 100644 --- a/tbl_zoom_select.php +++ b/tbl_zoom_select.php @@ -48,22 +48,15 @@ if (! isset($zoom_submit)) { // Gets the list and number of fields - $fields_array = PMA_tbl_getFields($table,$db); - $fields_list = $fields_array[0]; - $fields_type = $fields_array[1]; - $fields_collation = $fields_array[2]; - $fields_null = $fields_array[3]; + list($fields_list, $fields_type, $fields_collation, $fields_null) = PMA_tbl_getFields($table,$db); $fields_cnt = count($fields_list); - // retrieve keys into foreign fields, if any // check also foreigners even if relwork is FALSE (to get // foreign keys from innodb) $foreigners = PMA_getForeigners($db, $table); $flag = 1; - $tbl_fields_type =array(); - $tbl_fields_collation =array(); - $tbl_fields_null =array(); + $tbl_fields_type = $tbl_fields_collation = $tbl_fields_null = array(); ?>
@@ -79,19 +72,19 @@ echo PMA_generate_html_tabs(PMA_tbl_getSubTabs(), $url_params); if(isset($inputs) && ($inputs[0] != __('pma_null') || $inputs[1] != __('pma_null'))) { - $flag = 2; - for($i = 0 ; $i < 2 ; $i++) - { - if($inputs[$i] != __('pma_null')) - { - $key = array_search($inputs[$i],$fields_list); - $tbl_fields_type[$i] = $fields_type[$key]; - $tbl_fields_collation[$i] = $fields_collation[$key]; - $tbl_fields_null[$i] = $fields_null[$key]; - } - + $flag = 2; + for($i = 0 ; $i < 2 ; $i++) + { + if($inputs[$i] != __('pma_null')) + { + $key = array_search($inputs[$i],$fields_list); + $tbl_fields_type[$i] = $fields_type[$key]; + $tbl_fields_collation[$i] = $fields_collation[$key]; + $tbl_fields_null[$i] = $fields_null[$key]; } + } + } ?> @@ -110,21 +103,21 @@ if(isset($inputs) && ($inputs[0] != __('pma_null') || $inputs[1] != __('pma_null @@ -132,56 +125,61 @@ if(isset($inputs) && ($inputs[0] != __('pma_null') || $inputs[1] != __('pma_null - + + + - - - - - + else{ ?> + + + + + + + @@ -211,31 +209,31 @@ else { // Unlike tbl_search page this part builds two queries, Query1 for the search criteria on 1st column and Query2 for the other column. This has to be done because user can select two same columns having different criteria. - for($i = 0 ;$i<2;$i++){ + for($i = 0 ; $i < 2 ; $i++){ - $sql_query = 'SELECT '; + $sql_query = 'SELECT '; - // Add the colums to be selected + // Add the colums to be selected - $sql_query .= PMA_backquote($inputs[$i]); + $sql_query .= PMA_backquote($inputs[$i]); - //Add the table + //Add the table - $sql_query .= ' FROM ' . PMA_backquote($table); + $sql_query .= ' FROM ' . PMA_backquote($table); - // The where clause - $charsets = array(); - $cnt_func = count($zoomFunc[$i]); - reset($zoomFunc[$i]); - $func_type = $zoomFunc[$i]; - list($charsets[$i]) = explode('_', $collations[$i]); - $unaryFlag = (isset($GLOBALS['cfg']['UnaryOperators'][$func_type]) && $GLOBALS['cfg']['UnaryOperators'][$func_type] == 1) ? true : false; - $w = PMA_tbl_search_getWhereClause($fields[$i],$inputs[$i], $types[$i], $collations[$i], $func_type, $unaryFlag); - if ($w != '') { - $sql_query .= ' WHERE ' . $w; - } - print $sql_query."
"; - } + // The where clause + $charsets = array(); + $cnt_func = count($zoomFunc[$i]); + reset($zoomFunc[$i]); + $func_type = $zoomFunc[$i]; + list($charsets[$i]) = explode('_', $collations[$i]); + $unaryFlag = (isset($GLOBALS['cfg']['UnaryOperators'][$func_type]) && $GLOBALS['cfg']['UnaryOperators'][$func_type] == 1) ? true : false; + $w = PMA_tbl_search_getWhereClause($fields[$i],$inputs[$i], $types[$i], $collations[$i], $func_type, $unaryFlag); + if ($w != '') { + $sql_query .= ' WHERE ' . $w; + } + print $sql_query."
"; + } } ?>