From 060fe233c2acaca3d045c012c2bb466645f1d21e Mon Sep 17 00:00:00 2001 From: Atul Pratap Singh Date: Wed, 4 Jul 2012 11:27:37 +0530 Subject: [PATCH 01/24] Remove some HTML-PHP mix and form function for column names row --- db_qbe.php | 98 +++++++++++++++++++++++++++++++----------------------- 1 file changed, 56 insertions(+), 42 deletions(-) diff --git a/db_qbe.php b/db_qbe.php index 0f5d9054f1..258182af1c 100644 --- a/db_qbe.php +++ b/db_qbe.php @@ -140,32 +140,65 @@ $realwidth = $form_column_width . 'ex'; */ /** - * Enter description here... + * Provides select options list containing column names * - * @param array $columns - * @param integer $column_number - * @param string $selected + * @param array $columns All Column Names + * @param integer $column_number Column Number (0,1,2) or more + * @param string $selected Selected criteria column name + * + * @return HTML for select options */ function showColumnSelectCell($columns, $column_number, $selected = '') { - ?> - - '; + $html_output .= ''; foreach ($columns as $column) { - if ($column === $selected) { - $sel = ' selected="selected"'; - } else { - $sel = ''; - } - echo '' . "\n"; + $html_output .= ''; } - ?> - - - '; + $html_output .= ''; + return $html_output; +} + +/** + * Provides search form's row containing column select options + * + * @param array $criteria_column_count + * @param integer $columns + * @param string $ins_col + * @param string $del_col + * + * @return HTML for search table's roe + */ +function PMA_dbQbegetColumnNamesRow( + $criteria_column_count, $columns, $ins_col = null, $del_col = null +) { + $html_output = ''; + $html_output .= '' . __('Column') . ':'; + $z = 0; + for ($column_index = 0; $column_index < $criteria_column_count; $column_index++) + { + if (isset($ins_col[$column_index]) && $ins_col[$column_index] == 'on') { + $html_output .= showColumnSelectCell($columns, $z); + $z++; + } + if (! empty($del_col) && isset($del_col[$column_index]) && $del_col[$column_index] == 'on') { + continue; + } + $selected = ''; + if (isset($_REQUEST['Field'][$column_index])) { + $selected = $_REQUEST['Field'][$column_index]; + $curField[$z] = $_REQUEST['Field'][$column_index]; + } + $html_output .= showColumnSelectCell($columns, $z, $selected); + $z++; + } // end for + $html_output .= ''; + return $html_output; } if ($cfgRelation['designerwork']) { @@ -187,30 +220,11 @@ if ($cfgRelation['designerwork']) {
- - - From 38b10f042cda97435a3d90b697202c943eda448e Mon Sep 17 00:00:00 2001 From: Atul Pratap Singh Date: Wed, 4 Jul 2012 14:54:43 +0530 Subject: [PATCH 02/24] Use global REQUEST variable at some places, fixes previously filled criteria display --- db_qbe.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/db_qbe.php b/db_qbe.php index 258182af1c..01f6638828 100644 --- a/db_qbe.php +++ b/db_qbe.php @@ -265,16 +265,16 @@ for ($x = 0; $x < $col; $x++) { $Sort[$x] = ''; } //end if - if (isset($Sort[$x]) && $Sort[$x] == 'ASC') { - $curSort[$z] = $Sort[$x]; + if (isset($_REQUEST['Sort'][$x]) && $_REQUEST['Sort'][$x] == 'ASC') { + $curSort[$z] = $_REQUEST['Sort'][$x]; $sel = ' selected="selected"'; } else { $sel = ''; } // end if echo ' '; echo '' . "\n"; - if (isset($Sort[$x]) && $Sort[$x] == 'DESC') { - $curSort[$z] = $Sort[$x]; + if (isset($_REQUEST['Sort'][$x]) && $_REQUEST['Sort'][$x] == 'DESC') { + $curSort[$z] = $_REQUEST['Sort'][$x]; $sel = ' selected="selected"'; } else { $sel = ''; @@ -310,9 +310,9 @@ for ($x = 0; $x < $col; $x++) { if (! empty($del_col) && isset($del_col[$x]) && $del_col[$x] == 'on') { continue; } - if (isset($Show[$x])) { + if (isset($_REQUEST['Show'][$x])) { $checked = ' checked="checked"'; - $curShow[$z] = $Show[$x]; + $curShow[$z] = $_REQUEST['Show'][$x]; } else { $checked = ''; } From 9ccd70651f86d6233f63ff4cc33f7b8b6fdd10ad Mon Sep 17 00:00:00 2001 From: Atul Pratap Singh Date: Wed, 4 Jul 2012 16:01:28 +0530 Subject: [PATCH 03/24] Form functions for displaying sorting options list --- db_qbe.php | 148 +++++++++++++++++++++++++++++------------------------ 1 file changed, 81 insertions(+), 67 deletions(-) diff --git a/db_qbe.php b/db_qbe.php index 01f6638828..24b8097677 100644 --- a/db_qbe.php +++ b/db_qbe.php @@ -164,6 +164,50 @@ function showColumnSelectCell($columns, $column_number, $selected = '') return $html_output; } +/** + * Provides select options list containing sort options (ASC/DESC) + * + * @param integer $column_number Column Number (0,1,2) or more + * @param string $realwidth + * + * @return HTML for select options + */ +function getSortSelectCell($column_number, $realwidth) +{ + $html_output = ''; + return $html_output; +} + /** * Provides search form's row containing column select options * @@ -172,7 +216,7 @@ function showColumnSelectCell($columns, $column_number, $selected = '') * @param string $ins_col * @param string $del_col * - * @return HTML for search table's roe + * @return HTML for search table's row */ function PMA_dbQbegetColumnNamesRow( $criteria_column_count, $columns, $ins_col = null, $del_col = null @@ -201,6 +245,39 @@ function PMA_dbQbegetColumnNamesRow( return $html_output; } +/** + * Provides search form's row containing sort(ASC/DESC) select options + * + * @param array $criteria_column_count + * @param string $realwidth + * @param string $ins_col + * @param string $del_col + * + * @return HTML for search table's row + */ +function PMA_dbQbegetSortRow( + $criteria_column_count, $realwidth, $ins_col = null, $del_col = null +) { + $html_output = ''; + $html_output .= ''; + $z = 0; + for ($column_index = 0; $column_index < $criteria_column_count; $column_index++) + { + if (! empty($ins_col) && isset($ins_col[$column_index]) && $ins_col[$column_index] == 'on') { + $html_output .= getSortSelectCell($z, $realwidth); + $z++; + } // end if + + if (! empty($del_col) && isset($del_col[$column_index]) && $del_col[$column_index] == 'on') { + continue; + } + $html_output .= getSortSelectCell($column_index, $realwidth); + $z++; + } // end for + $html_output .= ''; + return $html_output; +} + if ($cfgRelation['designerwork']) { $url = 'pmd_general.php' . PMA_generate_common_url( array_merge( @@ -224,73 +301,10 @@ if ($cfgRelation['designerwork']) { echo PMA_dbQbegetColumnNamesRow( $col, $fld, $ins_col, $del_col ); +echo PMA_dbQbegetSortRow( + $col, $realwidth, $ins_col, $del_col +); ?> - - - - - - - - - - - From 408baf94019d9caf0657b3f90754007c6961aff0 Mon Sep 17 00:00:00 2001 From: Atul Pratap Singh Date: Wed, 4 Jul 2012 16:06:58 +0530 Subject: [PATCH 04/24] Fix some doc comments --- db_qbe.php | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/db_qbe.php b/db_qbe.php index 24b8097677..3150ab706d 100644 --- a/db_qbe.php +++ b/db_qbe.php @@ -168,7 +168,7 @@ function showColumnSelectCell($columns, $column_number, $selected = '') * Provides select options list containing sort options (ASC/DESC) * * @param integer $column_number Column Number (0,1,2) or more - * @param string $realwidth + * @param string $realwidth Largest column width found * * @return HTML for select options */ @@ -211,10 +211,10 @@ function getSortSelectCell($column_number, $realwidth) /** * Provides search form's row containing column select options * - * @param array $criteria_column_count - * @param integer $columns - * @param string $ins_col - * @param string $del_col + * @param array $criteria_column_count Number of criteria columns + * @param integer $columns All column names + * @param string $ins_col If a new criteria column is needed + * @param string $del_col If a criteria column is to be deleted * * @return HTML for search table's row */ @@ -248,10 +248,10 @@ function PMA_dbQbegetColumnNamesRow( /** * Provides search form's row containing sort(ASC/DESC) select options * - * @param array $criteria_column_count - * @param string $realwidth - * @param string $ins_col - * @param string $del_col + * @param array $criteria_column_count Number of criteria columns + * @param string $realwidth Largest column width found + * @param string $ins_col If a new criteria column is needed + * @param string $del_col If a criteria column is to be deleted * * @return HTML for search table's row */ From 18afed10a8c941b9a2ccac5e0ca3b5dd8afaaf16 Mon Sep 17 00:00:00 2001 From: Atul Pratap Singh Date: Wed, 4 Jul 2012 16:25:36 +0530 Subject: [PATCH 05/24] Fix selected criteria display while inserting/deleting new column --- db_qbe.php | 55 +++++++++++++++++++++++++++++------------------------- 1 file changed, 30 insertions(+), 25 deletions(-) diff --git a/db_qbe.php b/db_qbe.php index 3150ab706d..31254ef7f5 100644 --- a/db_qbe.php +++ b/db_qbe.php @@ -169,39 +169,21 @@ function showColumnSelectCell($columns, $column_number, $selected = '') * * @param integer $column_number Column Number (0,1,2) or more * @param string $realwidth Largest column width found + * @param string $asc_selected Selected criteria 'Ascending' + * @param string $desc_selected Selected criteria 'Descending' * * @return HTML for select options */ -function getSortSelectCell($column_number, $realwidth) +function getSortSelectCell($column_number, $realwidth, $asc_selected = '', + $desc_selected = '') { $html_output = ''; @@ -271,7 +253,30 @@ function PMA_dbQbegetSortRow( if (! empty($del_col) && isset($del_col[$column_index]) && $del_col[$column_index] == 'on') { continue; } - $html_output .= getSortSelectCell($column_index, $realwidth); + // If they have chosen all fields using the * selector, + // then sorting is not available, Fix for Bug #570698 + if (isset($_REQUEST['Sort'][$column_index]) && isset($_REQUEST['Field'][$column_index]) + && substr($_REQUEST['Field'][$column_index], -2) == '.*' + ) { + $_REQUEST['Sort'][$column_index] = ''; + } //end if + // Set asc_selected + if (isset($_REQUEST['Sort'][$column_index]) && $_REQUEST['Sort'][$column_index] == 'ASC') { + $curSort[$z] = $_REQUEST['Sort'][$column_index]; + $asc_selected = ' selected="selected"'; + } else { + $asc_selected = ''; + } // end if + // Set desc selected + if (isset($_REQUEST['Sort'][$column_index]) && $_REQUEST['Sort'][$column_index] == 'DESC') { + $curSort[$z] = $_REQUEST['Sort'][$column_index]; + $desc_selected = ' selected="selected"'; + } else { + $desc_selected = ''; + } // end if + $html_output .= getSortSelectCell( + $z, $realwidth, $asc_selected, $desc_selected + ); $z++; } // end for $html_output .= ''; From 75a644c1e956965d8b19ecf2168b8b5ca7a328cc Mon Sep 17 00:00:00 2001 From: Atul Pratap Singh Date: Thu, 5 Jul 2012 07:34:34 +0530 Subject: [PATCH 06/24] Form function to display show checkboxes --- db_qbe.php | 80 ++++++++++++++++++++++++++++++------------------------ 1 file changed, 45 insertions(+), 35 deletions(-) diff --git a/db_qbe.php b/db_qbe.php index b68ce50612..c574f79eac 100644 --- a/db_qbe.php +++ b/db_qbe.php @@ -313,6 +313,48 @@ function PMA_dbQbegetSortRow( return $html_output; } +/** + * Provides search form's row containing SHOW checkboxes + * + * @param array $criteria_column_count Number of criteria columns + * @param string $ins_col If a new criteria column is needed + * @param string $del_col If a criteria column is to be deleted + * + * @return HTML for search table's row + */ +function PMA_dbQbegetShowRow( + $criteria_column_count, $ins_col = null, $del_col = null +) { + $html_output = ''; + $html_output .= ''; + $z = 0; + for ($column_index = 0; $column_index < $criteria_column_count; $column_index++) + { + if (! empty($ins_col) && isset($ins_col[$column_index]) && $ins_col[$column_index] == 'on') { + $html_output .= ''; + $z++; + } // end if + if (! empty($del_col) && isset($del_col[$column_index]) && $del_col[$column_index] == 'on') { + continue; + } + if (isset($_REQUEST['Show'][$column_index])) { + $checked = ' checked="checked"'; + $curShow[$z] = $_REQUEST['Show'][$column_index]; + } else { + $checked = ''; + } + $html_output .= ''; + $z++; + } // end for + $html_output .= ''; + return $html_output; +} + if ($cfgRelation['designerwork']) { $url = 'pmd_general.php' . PMA_generate_common_url( array_merge( @@ -339,42 +381,10 @@ echo PMA_dbQbegetColumnNamesRow( echo PMA_dbQbegetSortRow( $col, $realwidth, $ins_col, $del_col ); +echo PMA_dbQbegetShowRow( + $col, $ins_col, $del_col +); ?> - - - - - - - - - From 270ab5e2254b0ca03954ffe3949efc1ef419a3dc Mon Sep 17 00:00:00 2001 From: Atul Pratap Singh Date: Thu, 5 Jul 2012 07:55:13 +0530 Subject: [PATCH 07/24] Form function for displaying criteria inputboxes --- db_qbe.php | 99 ++++++++++++++++++++++++++++++++---------------------- 1 file changed, 58 insertions(+), 41 deletions(-) diff --git a/db_qbe.php b/db_qbe.php index c574f79eac..714d86c44f 100644 --- a/db_qbe.php +++ b/db_qbe.php @@ -355,6 +355,61 @@ function PMA_dbQbegetShowRow( return $html_output; } +/** + * Provides search form's row containing criteria Inputboxes + * + * @param array $criteria_column_count Number of criteria columns + * @param string $realwidth Largest column width found + * @param string $criteria Already Filled criteria + * @param string $prev_criteria Previously filled criteria(hidden form field) + * @param string $ins_col If a new criteria column is needed + * @param string $del_col If a criteria column is to be deleted + * + * @return HTML for search table's row + */ +function PMA_dbQbegetCriteriaInputboxRow( + $criteria_column_count, $realwidth, $criteria, $prev_criteria, + $ins_col = null, $del_col = null +) { + $html_output = ''; + $html_output .= ''; + $z = 0; + for ($column_index = 0; $column_index < $criteria_column_count; $column_index++) + { + if (! empty($ins_col) && isset($ins_col[$column_index]) && $ins_col[$column_index] == 'on') { + $html_output .= ''; + $z++; + } // end if + if (! empty($del_col) && isset($del_col[$column_index]) && $del_col[$column_index] == 'on') { + continue; + } + if (isset($criteria[$column_index])) { + $tmp_criteria = $criteria[$column_index]; + } + if ((empty($prev_criteria) || ! isset($prev_criteria[$column_index])) + || $prev_criteria[$column_index] != htmlspecialchars($tmp_criteria) + ) { + $curCriteria[$z] = $tmp_criteria; + } else { + $curCriteria[$z] = $prev_criteria[$column_index]; + } + $html_output .= ''; + $z++; + } // end for + $html_output .= ''; + return $html_output; +} + if ($cfgRelation['designerwork']) { $url = 'pmd_general.php' . PMA_generate_common_url( array_merge( @@ -384,49 +439,11 @@ echo PMA_dbQbegetSortRow( echo PMA_dbQbegetShowRow( $col, $ins_col, $del_col ); +echo PMA_dbQbegetCriteriaInputboxRow( + $col, $realwidth, $criteria, $prev_criteria, $ins_col, $del_col +); ?> - - - - - - - - - - Date: Thu, 5 Jul 2012 08:25:23 +0530 Subject: [PATCH 08/24] Form function to display search table footer elements --- db_qbe.php | 78 +++++++++++++++++++++++++++++++++--------------------- 1 file changed, 48 insertions(+), 30 deletions(-) diff --git a/db_qbe.php b/db_qbe.php index 714d86c44f..efe1ab29d0 100644 --- a/db_qbe.php +++ b/db_qbe.php @@ -410,6 +410,50 @@ function PMA_dbQbegetCriteriaInputboxRow( return $html_output; } +/** + * Provides footer options for adding/deleting row/columns + * + * @param string $type Whether row or column + * + * @return HTML for footer options + */ +function PMA_dbQbeGetFootersOptions($type) +{ + $html_output = '
'; + $html_output .= (($type == 'row') + ? __('Add/Delete criteria rows') : __('Add/Delete columns')); + $html_output .= ':'; + $html_output .= '
'; + return $html_output; +} + +/** + * Provides search form table's footer options + * + * @return HTML for table footer + */ +function PMA_dbQbeGetTableFooters() +{ + $html_output = '
'; + $html_output .= PMA_dbQbeGetFootersOptions("row"); + $html_output .= PMA_dbQbeGetFootersOptions("column"); + $html_output .= '
'; + $html_output .= ''; + $html_output .= '
'; + $html_output .= '
'; + return $html_output; +} + if ($cfgRelation['designerwork']) { $url = 'pmd_general.php' . PMA_generate_common_url( array_merge( @@ -686,36 +730,10 @@ $url_params['rows'] = $w; echo PMA_generate_common_hidden_inputs($url_params); ?> -
-
- : - -
-
- : - -
- -
- -
-
+ +
From f5d15946f3d02156d86f50a63fd521de746d0bea Mon Sep 17 00:00:00 2001 From: Atul Pratap Singh Date: Fri, 6 Jul 2012 00:00:12 +0530 Subject: [PATCH 09/24] Form function to display tables select list --- db_qbe.php | 59 +++++++++++++++++++++++++++++++----------------------- 1 file changed, 34 insertions(+), 25 deletions(-) diff --git a/db_qbe.php b/db_qbe.php index efe1ab29d0..6e8d9b6823 100644 --- a/db_qbe.php +++ b/db_qbe.php @@ -454,6 +454,39 @@ function PMA_dbQbeGetTableFooters() return $html_output; } +/** + * Provides a select list of database tables + * + * @param array $table_names Names of all the tables + * + * @return HTML for table select list + */ +function PMA_dbQbeGetTablesList($table_names) +{ + $html_output = '
'; + $html_output .= '
'; + $html_output .= '' . __('Use Tables') . ''; + // Build the options list for each table name + $options = ''; + $numTableListOptions = 0; + foreach ($table_names as $key => $val) { + $options .= ''; + $numTableListOptions++; + } + $html_output .= ''; + $html_output .= '
'; + $html_output .= '
'; + $html_output .= ''; + $html_output .= '
'; + $html_output .= '
'; + return $html_output; +} + if ($cfgRelation['designerwork']) { $url = 'pmd_general.php' . PMA_generate_common_url( array_merge( @@ -720,8 +753,6 @@ for ($x = 0; $x < $col; $x++) { ?>
:
'; + $html_output .= ''; + $html_output .= '
' . __('Sort') . ':
: - - - -
:'; $html_output .= ''; $html_output .= '
' . __('Show') . ':'; + $html_output .= ''; + $html_output .= ''; + $html_output .= ''; + $html_output .= '
: - - - /> -
' . __('Criteria') . ':'; + $html_output .= ''; + $html_output .= ''; + $html_output .= ''; + $html_output .= ''; + $html_output .= '
: - - - - -
- - -
-
- - $val) { - $options .= ' '; - $options .= '' . "\n"; - $numTableListOptions++; -} -?> - -
-
- -
-
-
%s:'), $common_functions->getDbLink($db)); ?> From 2b9fbc4b84882f26d68ac7eb5bc57da49667eb23 Mon Sep 17 00:00:00 2001 From: Atul Pratap Singh Date: Fri, 6 Jul 2012 08:00:16 +0530 Subject: [PATCH 10/24] Use globals to build SQL query for now --- db_qbe.php | 71 +++++++++++++++++++++++++++++++++--------------------- 1 file changed, 44 insertions(+), 27 deletions(-) diff --git a/db_qbe.php b/db_qbe.php index 6e8d9b6823..16f19345e8 100644 --- a/db_qbe.php +++ b/db_qbe.php @@ -40,6 +40,15 @@ foreach (array_keys($_POST) as $post_key) { } } } +/** + * Initialize some more global variables + */ +$GLOBALS['curField'] = array(); +$GLOBALS['curSort'] = array(); +$GLOBALS['curShow'] = array(); +$GLOBALS['curCriteria'] = array(); +$GLOBALS['curAndOrRow'] = array(); +$GLOBALS['curAndOrCol'] = array(); /** * Gets the relation settings @@ -248,7 +257,7 @@ function PMA_dbQbegetColumnNamesRow( $selected = ''; if (isset($_REQUEST['Field'][$column_index])) { $selected = $_REQUEST['Field'][$column_index]; - $curField[$z] = $_REQUEST['Field'][$column_index]; + $GLOBALS['curField'][$z] = $_REQUEST['Field'][$column_index]; } $html_output .= showColumnSelectCell($columns, $z, $selected); $z++; @@ -292,14 +301,14 @@ function PMA_dbQbegetSortRow( } //end if // Set asc_selected if (isset($_REQUEST['Sort'][$column_index]) && $_REQUEST['Sort'][$column_index] == 'ASC') { - $curSort[$z] = $_REQUEST['Sort'][$column_index]; + $GLOBALS['curSort'][$z] = $_REQUEST['Sort'][$column_index]; $asc_selected = ' selected="selected"'; } else { $asc_selected = ''; } // end if // Set desc selected if (isset($_REQUEST['Sort'][$column_index]) && $_REQUEST['Sort'][$column_index] == 'DESC') { - $curSort[$z] = $_REQUEST['Sort'][$column_index]; + $GLOBALS['curSort'][$z] = $_REQUEST['Sort'][$column_index]; $desc_selected = ' selected="selected"'; } else { $desc_selected = ''; @@ -341,7 +350,7 @@ function PMA_dbQbegetShowRow( } if (isset($_REQUEST['Show'][$column_index])) { $checked = ' checked="checked"'; - $curShow[$z] = $_REQUEST['Show'][$column_index]; + $GLOBALS['curShow'][$z] = $_REQUEST['Show'][$column_index]; } else { $checked = ''; } @@ -393,13 +402,13 @@ function PMA_dbQbegetCriteriaInputboxRow( if ((empty($prev_criteria) || ! isset($prev_criteria[$column_index])) || $prev_criteria[$column_index] != htmlspecialchars($tmp_criteria) ) { - $curCriteria[$z] = $tmp_criteria; + $GLOBALS['curCriteria'][$z] = $tmp_criteria; } else { - $curCriteria[$z] = $prev_criteria[$column_index]; + $GLOBALS['curCriteria'][$z] = $prev_criteria[$column_index]; } $html_output .= ''; $html_output .= ''; + . ' value="' . htmlspecialchars($GLOBALS['curCriteria'][$z]) . '" />'; $html_output .= ''; @@ -601,7 +610,7 @@ for ($y = 0; $y <= $row; $y++) { } if (isset($and_or_row[$y])) { - $curAndOrRow[$w] = $and_or_row[$y]; + $GLOBALS['curAndOrRow'][$w] = $and_or_row[$y]; } if (isset($and_or_row[$y]) && $and_or_row[$y] == 'and') { $chk['and'] = ' checked="checked"'; @@ -695,7 +704,7 @@ for ($y = 0; $y <= $row; $y++) { $z = 0; for ($x = 0; $x < $col; $x++) { if (! empty($ins_col) && isset($ins_col[$x]) && $ins_col[$x] == 'on') { - $curAndOrCol[$z] = $and_or_col[$y]; + $GLOBALS['curAndOrCol'][$z] = $and_or_col[$y]; if ($and_or_col[$z] == 'or') { $chk['or'] = ' checked="checked"'; $chk['and'] = ''; @@ -725,7 +734,7 @@ for ($x = 0; $x < $col; $x++) { } if (isset($and_or_col[$y])) { - $curAndOrCol[$z] = $and_or_col[$y]; + $GLOBALS['curAndOrCol'][$z] = $and_or_col[$y]; } if (isset($and_or_col[$z]) && $and_or_col[$z] == 'or') { $chk['or'] = ' checked="checked"'; @@ -781,11 +790,14 @@ if (! isset($qry_select)) { $qry_select = ''; } for ($x = 0; $x < $col; $x++) { - if (! empty($curField[$x]) && isset($curShow[$x]) && $curShow[$x] == 'on') { + if (! empty($GLOBALS['curField'][$x]) + && isset($GLOBALS['curShow'][$x]) + && $GLOBALS['curShow'][$x] == 'on') + { if ($last_select) { $qry_select .= ', '; } - $qry_select .= $curField[$x]; + $qry_select .= $GLOBALS['curField'][$x]; $last_select = 1; } } // end for @@ -988,11 +1000,16 @@ if (! empty($qry_from)) { $qry_where = ''; $criteria_cnt = 0; for ($x = 0; $x < $col; $x++) { - if (! empty($curField[$x]) && ! empty($curCriteria[$x]) && $x && isset($last_where) && isset($curAndOrCol)) { - $qry_where .= ' ' . strtoupper($curAndOrCol[$last_where]) . ' '; + if (! empty($GLOBALS['curField'][$x]) + && ! empty($GLOBALS['curCriteria'][$x]) + && $x + && isset($last_where) + && isset($GLOBALS['curAndOrCol'])) { + $qry_where .= ' ' . strtoupper($GLOBALS['curAndOrCol'][$last_where]) . ' '; } - if (! empty($curField[$x]) && ! empty($curCriteria[$x])) { - $qry_where .= '(' . $curField[$x] . ' ' . $curCriteria[$x] . ')'; + if (! empty($GLOBALS['curField'][$x]) && ! empty($GLOBALS['curCriteria'][$x])) { + $qry_where .= '(' . $GLOBALS['curField'][$x] . ' ' + . $GLOBALS['curCriteria'][$x] . ')'; $last_where = $x; $criteria_cnt++; } @@ -1001,19 +1018,19 @@ if ($criteria_cnt > 1) { $qry_where = '(' . $qry_where . ')'; } // OR rows ${'cur' . $or}[$x] -if (! isset($curAndOrRow)) { - $curAndOrRow = array(); +if (! isset($GLOBALS['curAndOrRow'])) { + $GLOBALS['curAndOrRow'] = array(); } for ($y = 0; $y <= $row; $y++) { $criteria_cnt = 0; $qry_orwhere = ''; $last_orwhere = ''; for ($x = 0; $x < $col; $x++) { - if (! empty($curField[$x]) && ! empty(${'curOr' . $y}[$x]) && $x) { - $qry_orwhere .= ' ' . strtoupper($curAndOrCol[$last_orwhere]) . ' '; + if (! empty($GLOBALS['curField'][$x]) && ! empty(${'curOr' . $y}[$x]) && $x) { + $qry_orwhere .= ' ' . strtoupper($GLOBALS['curAndOrCol'][$last_orwhere]) . ' '; } - if (! empty($curField[$x]) && ! empty(${'curOr' . $y}[$x])) { - $qry_orwhere .= '(' . $curField[$x] + if (! empty($GLOBALS['curField'][$x]) && ! empty(${'curOr' . $y}[$x])) { + $qry_orwhere .= '(' . $GLOBALS['curField'][$x] . ' ' . ${'curOr' . $y}[$x] . ')'; @@ -1026,7 +1043,7 @@ for ($y = 0; $y <= $row; $y++) { } if (! empty($qry_orwhere)) { $qry_where .= "\n" - . strtoupper(isset($curAndOrRow[$y]) ? $curAndOrRow[$y] . ' ' : '') + . strtoupper(isset($GLOBALS['curAndOrRow'][$y]) ? $GLOBALS['curAndOrRow'][$y] . ' ' : '') . $qry_orwhere; } // end if } // end for @@ -1042,15 +1059,15 @@ if (! isset($qry_orderby)) { $qry_orderby = ''; } for ($x = 0; $x < $col; $x++) { - if ($last_orderby && $x && ! empty($curField[$x]) && ! empty($curSort[$x])) { + if ($last_orderby && $x && ! empty($GLOBALS['curField'][$x]) && ! empty($GLOBALS['curSort'][$x])) { $qry_orderby .= ', '; } - if (! empty($curField[$x]) && ! empty($curSort[$x])) { + if (! empty($GLOBALS['curField'][$x]) && ! empty($GLOBALS['curSort'][$x])) { // if they have chosen all fields using the * selector, // then sorting is not available // Fix for Bug #570698 - if (substr($curField[$x], -2) != '.*') { - $qry_orderby .= $curField[$x] . ' ' . $curSort[$x]; + if (substr($GLOBALS['curField'][$x], -2) != '.*') { + $qry_orderby .= $GLOBALS['curField'][$x] . ' ' . $GLOBALS['curSort'][$x]; $last_orderby = 1; } } From 74f5144389c97b3b90cc2c2289d0949860b70b18 Mon Sep 17 00:00:00 2001 From: Atul Pratap Singh Date: Fri, 6 Jul 2012 20:28:23 +0530 Subject: [PATCH 11/24] Form functions for column modification options, fixes already set criteria display too --- db_qbe.php | 138 +++++++++++++++++++++++++++++------------------------ 1 file changed, 76 insertions(+), 62 deletions(-) diff --git a/db_qbe.php b/db_qbe.php index 16f19345e8..7ed278204b 100644 --- a/db_qbe.php +++ b/db_qbe.php @@ -496,6 +496,78 @@ function PMA_dbQbeGetTablesList($table_names) return $html_output; } +/** + * Provides And/Or modification cell along with Insert/Delete options + * (For modifying search form's table columns) + * + * @param integer $column_number Column Number (0,1,2) or more + * @param array $selected Selected criteria column name + * + * @return HTML for modification cell + */ +function PMA_dbQbeGetAndOrColCell($column_number, $selected = null) +{ + $html_output = ''; + $html_output .= '' . __('Or') . ':'; + $html_output .= ''; + $html_output .= '  ' . __('And') . ':'; + $html_output .= ''; + $html_output .= '
' . __('Ins'); + $html_output .= ''; + $html_output .= '  ' . __('Del'); + $html_output .= ''; + $html_output .= ''; + return $html_output; +} + +/** + * Provides search form's row containing column modifications options + * (For modifying search form's table columns) + * + * @param array $criteria_column_count Number of criteria columns + * @param string $realwidth Largest column width found + * @param string $criteria Already Filled criteria + * @param string $prev_criteria Previously filled criteria(hidden form field) + * @param string $ins_col If a new criteria column is needed + * @param string $del_col If a criteria column is to be deleted + * + * @return HTML for search table's row + */ +function PMA_dbQbeGetModifyColumnsRow($criteria_column_count, $and_or_col, + $ins_col = null, $del_col = null +) { + $html_output = ''; + $html_output .= '' . __('Modify') . ':'; + $z = 0; + for ($x = 0; $x < $criteria_column_count; $x++) { + if (! empty($ins_col) && isset($ins_col[$x]) && $ins_col[$x] == 'on') { + $html_output .= PMA_dbQbeGetAndOrColCell($z); + $z++; + } // end if + + if (! empty($del_col) && isset($del_col[$x]) && $del_col[$x] == 'on') { + continue; + } + + if (isset($and_or_col[$x])) { + $GLOBALS['curAndOrCol'][$z] = $and_or_col[$x]; + } + if (isset($and_or_col[$x]) && $and_or_col[$x] == 'or') { + $chk['or'] = ' checked="checked"'; + $chk['and'] = ''; + } else { + $chk['and'] = ' checked="checked"'; + $chk['or'] = ''; + } + $html_output .= PMA_dbQbeGetAndOrColCell($z, $chk); + $z++; + } // end for + $html_output .= ''; + return $html_output; +} + if ($cfgRelation['designerwork']) { $url = 'pmd_general.php' . PMA_generate_common_url( array_merge( @@ -697,70 +769,12 @@ for ($y = 0; $y <= $row; $y++) { $odd_row =! $odd_row; } // end for ?> - - - : + - - : - /> -   : - /> -
- - -    - - - - - : - /> -   : - /> -
- - -    - - - - Date: Sat, 7 Jul 2012 12:49:05 +0530 Subject: [PATCH 12/24] Fix wrong function call --- libraries/TableSearch.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/TableSearch.class.php b/libraries/TableSearch.class.php index df4cc2c69f..1ac3b8f830 100644 --- a/libraries/TableSearch.class.php +++ b/libraries/TableSearch.class.php @@ -132,7 +132,7 @@ class PMA_TableSearch $this->_geomColumnFlag = false; $this->_foreigners = array(); // Loads table's information - $this->_loadTableInfo($this->_db, $this->_table); + $this->_loadTableInfo(); } /** From 65a3dbbeda1bde2b7ff1b04a462cbd7e6202d45e Mon Sep 17 00:00:00 2001 From: Atul Pratap Singh Date: Sat, 7 Jul 2012 13:32:15 +0530 Subject: [PATCH 13/24] Fix doc comments --- libraries/TableSearch.class.php | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/libraries/TableSearch.class.php b/libraries/TableSearch.class.php index 1ac3b8f830..5c96dd6c0f 100644 --- a/libraries/TableSearch.class.php +++ b/libraries/TableSearch.class.php @@ -118,7 +118,6 @@ class PMA_TableSearch * @param string $table Table name * @param string $searchType Whether normal or zoom search * - * @return New PMA_TableSearch */ public function __construct($db, $table, $searchType) { @@ -149,8 +148,6 @@ class PMA_TableSearch * Gets all the columns of a table along with their types, collations * and whether null or not. * - * @return array Array containing the column list, column types, collations - * and null constraint */ private function _loadTableInfo() { @@ -396,7 +393,7 @@ EOT; * @param bool $in_fbs Whether we are in 'function based search' * @param bool $in_zoom_search_edit Whether we are in zoom search edit * - * @return string HTML content for viewing foreing data and elements + * @return string HTML content for viewing foreign data and elements * for search criteria input. */ private function _getInputbox($foreignData, $column_name, $column_type, @@ -456,7 +453,7 @@ EOT; * Return the where clause in case column's type is ENUM. * * @param mixed $criteriaValues Search criteria input - * @param string $func_type Search fucntion/operator + * @param string $func_type Search function/operator * * @return string part of where clause. */ @@ -501,7 +498,7 @@ EOT; * * @param mixed $criteriaValues Search criteria input * @param string $names Name of the column on which search is submitted - * @param string $func_type Search fucntion/operator + * @param string $func_type Search function/operator * @param bool $geom_func Whether geometry functions should be applied * * @return string part of where clause. @@ -556,7 +553,7 @@ EOT; * @param string $names Name of the column on which search is submitted * @param string $types Type of the field * @param string $collations Field collation - * @param string $func_type Search fucntion/operator + * @param string $func_type Search function/operator * @param bool $unaryFlag Whether operator unary or not * @param bool $geom_func Whether geometry functions should be applied * From df0658b169dcdf5e61f4e030562767e355a65f67 Mon Sep 17 00:00:00 2001 From: Atul Pratap Singh Date: Sat, 7 Jul 2012 13:35:21 +0530 Subject: [PATCH 14/24] Make libraries/DbSearch.class.php for handling Database search --- libraries/DbSearch.class.php | 175 +++++++++++++++++++++++++++++++++++ 1 file changed, 175 insertions(+) create mode 100644 libraries/DbSearch.class.php diff --git a/libraries/DbSearch.class.php b/libraries/DbSearch.class.php new file mode 100644 index 0000000000..52653e5067 --- /dev/null +++ b/libraries/DbSearch.class.php @@ -0,0 +1,175 @@ +_db = $db; + // Sets criteria parameters + $this->_setSearchParams(); + } + + /** + * Set CommmonFunctions + * + * @param PMA_CommonFunctions $commonFunctions + * + * @return void + */ + public function setCommonFunctions(PMA_CommonFunctions $commonFunctions) + { + $this->_common_functions = $commonFunctions; + } + + + /** + * Get CommmonFunctions + * + * @return CommonFunctions object + */ + public function getCommonFunctions() + { + if (is_null($this->_common_functions)) { + $this->_common_functions = PMA_CommonFunctions::getInstance(); + } + return $this->_common_functions; + } + + /** + * Sets search parameters + * + */ + private function _setSearchParams() + { + $this->_tables_names_only = PMA_DBI_get_tables($this->_db); + + $this->_searchTypes = array( + '1' => __('at least one of the words'), + '2' => __('all words'), + '3' => __('the exact phrase'), + '4' => __('as regular expression'), + ); + + if (empty($_REQUEST['criteriaSearchType']) + || ! is_string($_REQUEST['criteriaSearchType']) + || ! array_key_exists($_REQUEST['criteriaSearchType'], $searchTypes) + ) { + $this->_criteriaSearchType = 1; + unset($_REQUEST['submit_search']); + } else { + $this->_criteriaSearchType = (int) $_REQUEST['criteriaSearchType']; + $this->_searchTypeDescription = $this->_searchTypes[$_REQUEST['criteriaSearchType']]; + } + + if (empty($_REQUEST['criteriaSearchString']) + || ! is_string($_REQUEST['criteriaSearchString']) + ) { + $this->_criteriaSearchString = ''; + unset($_REQUEST['submit_search']); + } else { + $this->_criteriaSearchString = $_REQUEST['criteriaSearchString']; + } + + $this->_criteriaTables = array(); + if (empty($_REQUEST['criteriaTables']) || ! is_array($_REQUEST['criteriaTables'])) { + unset($_REQUEST['submit_search']); + } elseif (! isset($_REQUEST['selectall']) && ! isset($_REQUEST['unselectall'])) { + $this->_criteriaTables = array_intersect( + $_REQUEST['criteriaTables'], $this->_tables_names_only + ); + } + + if (isset($_REQUEST['selectall'])) { + $this->_criteriaTables = $this->_tables_names_only; + } elseif (isset($_REQUEST['unselectall'])) { + $this->_criteriaTables = array(); + } + + if (empty($_REQUEST['criteriaColumnName']) + || ! is_string($_REQUEST['criteriaColumnName']) + ) { + unset($this->_criteriaColumnName); + } else { + $this->_criteriaColumnName = $common_functions->sqlAddSlashes( + $_REQUEST['criteriaColumnName'], true + ); + } + } +} From 9315294d8f5d915c08ce6ab80d63e57ad4a76ea6 Mon Sep 17 00:00:00 2001 From: Atul Pratap Singh Date: Sat, 7 Jul 2012 14:28:48 +0530 Subject: [PATCH 15/24] Add existing functions to PMA_DbSearch with required modifications --- libraries/DbSearch.class.php | 349 ++++++++++++++++++++++++++++++++++- 1 file changed, 348 insertions(+), 1 deletion(-) diff --git a/libraries/DbSearch.class.php b/libraries/DbSearch.class.php index 52653e5067..60f24855c0 100644 --- a/libraries/DbSearch.class.php +++ b/libraries/DbSearch.class.php @@ -66,7 +66,7 @@ class PMA_DbSearch */ private $_criteriaTables; /** - * Column names to search for + * Restrict the search to this column * * @access private * @var string @@ -172,4 +172,351 @@ class PMA_DbSearch ); } } + + /** + * Builds the SQL search query + * + * @param string $table The table name + * + * @return array 3 SQL querys (for count, display and delete results) + * + * @todo can we make use of fulltextsearch IN BOOLEAN MODE for this? + * PMA_backquote + * PMA_DBI_free_result + * PMA_DBI_fetch_assoc + * $GLOBALS['db'] + * explode + * count + * strlen + */ + private function _getSearchSqls($table) + { + $common_functions = PMA_CommonFunctions::getInstance(); + // Statement types + $sqlstr_select = 'SELECT'; + $sqlstr_delete = 'DELETE'; + // Table to use + $sqlstr_from = ' FROM ' + . $common_functions->backquote($GLOBALS['db']) . '.' + . $common_functions->backquote($table); + // Gets where clause for the query + $where_clause = $this->_getWhereClause($table); + // Builds complete queries + $sql['select_columns'] = $sqlstr_select . ' * ' . $sqlstr_from . $where_clause; + // here, I think we need to still use the COUNT clause, even for + // VIEWs, anyway we have a WHERE clause that should limit results + $sql['select_count'] = $sqlstr_select . ' COUNT(*) AS `count`' + . $sqlstr_from . $where_clause; + $sql['delete'] = $sqlstr_delete . $sqlstr_from . $where_clause; + + return $sql; + } + + /** + * Provides where clause for bulding SQL query + * + * @param string $table The table name + * + * @return string The generated where clause + */ + private function _getWhereClause($table) + { + $common_functions = PMA_CommonFunctions::getInstance(); + $where_clause = ''; + // Columns to select + $allColumns = PMA_DBI_get_columns($GLOBALS['db'], $table); + $likeClauses = array(); + // Based on search type, decide like/regex & '%'/'' + $like_or_regex = (($this->_criteriaSearchType == 4) ? 'REGEXP' : 'LIKE'); + $automatic_wildcard = (($this->_criteriaSearchType < 3) ? '%' : ''); + // For "as regular expression" (search option 4), LIKE won't be used + // Usage example: If user is seaching for a literal $ in a regexp search, + // he should enter \$ as the value. + $this->_criteriaSearchString = $common_functions->sqlAddSlashes( + $this->_criteriaSearchString, ($this->_criteriaSearchType == 4 ? false : true) + ); + // Extract search words or pattern + $search_words = (($this->_criteriaSearchType > 2) + ? array($this->_criteriaSearchString) : explode(' ', $this->_criteriaSearchString)); + + foreach ($search_words as $search_word) { + // Eliminates empty values + if (strlen($search_word) === 0) { + continue; + } + $likeClausesPerColumn = array(); + // for each column in the table + foreach ($allColumns as $column) { + if (! isset($this->_criteriaColumnName) + || strlen($this->_criteriaColumnName) == 0 + || $column['Field'] == $this->_criteriaColumnName + ) { + // Drizzle has no CONVERT and all text columns are UTF-8 + $column = ((PMA_DRIZZLE) + ? $common_functions->backquote($column['Field']) + : 'CONVERT(' . $common_functions->backquote($column['Field']) + . ' USING utf8)'); + $likeClausesPerColumn[] = $column . ' ' . $like_or_regex . ' ' + . "'" + . $automatic_wildcard . $search_word . $automatic_wildcard + . "'"; + } + } // end for + if (count($likeClausesPerColumn) > 0) { + $likeClauses[] = implode(' OR ', $likeClausesPerColumn); + } + } // end for + // Use 'OR' if 'at least one word' is to be searched, else use 'AND' + $implode_str = ($this->_criteriaSearchType == 1 ? ' OR ' : ' AND '); + if ( empty($likeClauses)) { + // this could happen when the "inside column" does not exist + // in any selected tables + $where_clause = ' WHERE FALSE'; + } else { + $where_clause = ' WHERE (' + . implode(') ' . $implode_str . ' (', $likeClauses) + . ')'; + } + return $where_clause; + } + + /** + * Displays database search results + * + * @return string HTML for search results + */ + public function getSearchResults() + { + $html_output = ''; + // Displays search string + $html_output .= '
' + . '' + . ''; + + $num_search_result_total = 0; + $odd_row = true; + // For each table selected as search criteria + foreach ($this->_criteriaTables as $each_table) { + // Gets the SQL statements + $newsearchsqls = $this->_getSearchSqls($each_table); + // Executes the "COUNT" statement + $res_cnt = PMA_DBI_fetch_value($newsearchsqls['select_count']); + $num_search_result_total += $res_cnt; + // Gets the result row's HTML for a table + $html_output .= $this->_getResultsRow( + $each_table, $newsearchsqls, $odd_row + ); + $odd_row = ! $odd_row; + } // end for + $html_output .= '
' + . sprintf( + __('Search results for "%s" %s:'), + htmlspecialchars($this->_criteriaSearchString), + $this->_searchTypeDescription + ) + . '
'; + // Displays total number of matches + if (count($criteriaTables) > 1) { + $html_output .= '

'; + $html_output .= sprintf( + _ngettext( + 'Total: %s match', + 'Total: %s matches', + $num_search_result_total + ), + $num_search_result_total + ); + $html_output .= '

'; + } + return $html_output; + } + + /** + * Provides search results row with browse/delete links. + * (for a table) + * + * @param string $each_table Tables on which search is to be performed + * @param array $newsearchsqls Contains SQL queries + * @param bool $odd_row For displaying contrasting table rows + * + * @return string HTML row + */ + private function _getResultsRow($each_table, $newsearchsqls, $odd_row) + { + $this_url_params = array( + 'db' => $GLOBALS['db'], + 'goto' => 'db_sql.php', + 'pos' => 0, + 'is_js_confirmed' => 0, + ); + $res_cnt = PMA_DBI_fetch_value($newsearchsqls['select_count']); + // Start forming search results row + $html_output = ''; + // Displays results count for a table + $html_output .= ''; + $html_output .= sprintf( + _ngettext( + '%1$s match in %2$s', + '%1$s matches in %2$s', $res_cnt + ), + $res_cnt, htmlspecialchars($each_table) + ); + $html_output .= ''; + // Displays browse/delete link if result count > 0 + if ($res_cnt > 0) { + $this_url_params['sql_query'] = $newsearchsqls['select_columns']; + $browse_result_path = 'sql.php' . PMA_generate_common_url($this_url_params); + $html_output .= '' + . __('Browse') . ''; + $this_url_params['sql_query'] = $newsearchsqls['delete']; + $delete_result_path = 'sql.php' . PMA_generate_common_url($this_url_params); + $html_output .= '' + . __('Delete') . ''; + } else { + $html_output .= ' ' + .' '; + }// end if else + $html_output .= ''; + return $html_output; + } + + /** + * Provides the main search form's html + * + * @param array $url_params URL parameters + * + * @return string HTML for selection form + */ + public function getSelectionForm($url_params) + { + $common_functions = PMA_CommonFunctions::getInstance(); + $html_output = ''; + $html_output .= ''; + $html_output .= PMA_generate_common_hidden_inputs($GLOBALS['db']); + $html_output .= '
'; + // set legend caption + $html_output .= '' . __('Search in database') . ''; + $html_output .= ''; + // inputbox for search phrase + $html_output .= ''; + $html_output .= ''; + $html_output .= ''; + $html_output .= ''; + // choices for types of search + $html_output .= ''; + $html_output .= ''; + $html_output .= ''; + // displays table names as select options + $html_output .= ''; + $html_output .= ''; + $html_output .= ''; + // Displays 'select all' and 'unselect all' links + $alter_select = '' + . __('Select All') . '  / '; + $alter_select .= '' + . __('Unselect All') . ''; + $html_output .= ''; + // Inputbox for column name entry + $html_output .= ''; + $html_output .= ''; + $html_output .= ''; + $html_output .= ''; + $html_output .= '
' . __('Words or values to search for (wildcard: "%"):') + . '
' . __('Find:') . ''; + $choices = array( + '1' => __('at least one of the words') + . $common_functions->showHint( + __('Words are separated by a space character (" ").') + ), + '2' => __('all words') + . $common_functions->showHint( + __('Words are separated by a space character (" ").') + ), + '3' => __('the exact phrase'), + '4' => __('as regular expression') + . ' ' . $common_functions->showMySQLDocu('Regexp', 'Regexp') + ); + // 4th parameter set to true to add line breaks + // 5th parameter set to false to avoid htmlspecialchars() escaping in the label + // since we have some HTML in some labels + $html_output .= $common_functions->getRadioFields( + 'criteriaSearchType', $choices, $this->_criteriaSearchType, true, false + ); + $html_output .= '
' . __('Inside tables:') . ''; + $html_output .= ''; + $html_output .= '
' . $alter_select . '
' . __('Inside column:') . '
'; + $html_output .= '
'; + $html_output .= '
'; + $html_output .= ''; + $html_output .= '
'; + $html_output .= ''; + $html_output .= $this->_getResultDivs(); + + return $html_output; + } + + /** + * Provides div tags for browsing search results and sql query form. + * + * @return string div tags + */ + private function _getResultDivs() + { + $html_output = ''; + $html_output .= '
'; + $html_output .= ''; + $html_output .= '
'; + // div for browsing results + $html_output .= '
'; + $html_output .= ''; + $html_output .= '
'; + $html_output .= '
'; + $html_output .= '
'; + $html_output .= ''; + $html_output .= '
'; + $html_output .= ''; + $html_output .= ''; + return $html_output; + } } From d52321a90ccfce426893423053e77e6f74760d72 Mon Sep 17 00:00:00 2001 From: Atul Pratap Singh Date: Sat, 7 Jul 2012 15:04:15 +0530 Subject: [PATCH 16/24] Use current object reference to point to PMA_CommonFunctions object --- libraries/DbSearch.class.php | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/libraries/DbSearch.class.php b/libraries/DbSearch.class.php index 60f24855c0..2096b5f3d1 100644 --- a/libraries/DbSearch.class.php +++ b/libraries/DbSearch.class.php @@ -72,6 +72,13 @@ class PMA_DbSearch * @var string */ private $_criteriaColumnName; + /** + * PMA_CommonFunctions object + * + * @access private + * @var object + */ + private $_common_functions; /** * Public Constructor @@ -167,7 +174,7 @@ class PMA_DbSearch ) { unset($this->_criteriaColumnName); } else { - $this->_criteriaColumnName = $common_functions->sqlAddSlashes( + $this->_criteriaColumnName = $this->getCommonFunctions()->sqlAddSlashes( $_REQUEST['criteriaColumnName'], true ); } @@ -191,14 +198,13 @@ class PMA_DbSearch */ private function _getSearchSqls($table) { - $common_functions = PMA_CommonFunctions::getInstance(); // Statement types $sqlstr_select = 'SELECT'; $sqlstr_delete = 'DELETE'; // Table to use $sqlstr_from = ' FROM ' - . $common_functions->backquote($GLOBALS['db']) . '.' - . $common_functions->backquote($table); + . $this->getCommonFunctions()->backquote($GLOBALS['db']) . '.' + . $this->getCommonFunctions()->backquote($table); // Gets where clause for the query $where_clause = $this->_getWhereClause($table); // Builds complete queries @@ -221,7 +227,6 @@ class PMA_DbSearch */ private function _getWhereClause($table) { - $common_functions = PMA_CommonFunctions::getInstance(); $where_clause = ''; // Columns to select $allColumns = PMA_DBI_get_columns($GLOBALS['db'], $table); @@ -232,7 +237,7 @@ class PMA_DbSearch // For "as regular expression" (search option 4), LIKE won't be used // Usage example: If user is seaching for a literal $ in a regexp search, // he should enter \$ as the value. - $this->_criteriaSearchString = $common_functions->sqlAddSlashes( + $this->_criteriaSearchString = $this->getCommonFunctions()->sqlAddSlashes( $this->_criteriaSearchString, ($this->_criteriaSearchType == 4 ? false : true) ); // Extract search words or pattern @@ -253,8 +258,8 @@ class PMA_DbSearch ) { // Drizzle has no CONVERT and all text columns are UTF-8 $column = ((PMA_DRIZZLE) - ? $common_functions->backquote($column['Field']) - : 'CONVERT(' . $common_functions->backquote($column['Field']) + ? $this->getCommonFunctions()->backquote($column['Field']) + : 'CONVERT(' . $this->getCommonFunctions()->backquote($column['Field']) . ' USING utf8)'); $likeClausesPerColumn[] = $column . ' ' . $like_or_regex . ' ' . "'" @@ -400,7 +405,6 @@ class PMA_DbSearch */ public function getSelectionForm($url_params) { - $common_functions = PMA_CommonFunctions::getInstance(); $html_output = ''; $html_output .= '
__('at least one of the words') - . $common_functions->showHint( + . $this->getCommonFunctions()->showHint( __('Words are separated by a space character (" ").') ), '2' => __('all words') - . $common_functions->showHint( + . $this->getCommonFunctions()->showHint( __('Words are separated by a space character (" ").') ), '3' => __('the exact phrase'), '4' => __('as regular expression') - . ' ' . $common_functions->showMySQLDocu('Regexp', 'Regexp') + . ' ' . $this->getCommonFunctions()->showMySQLDocu('Regexp', 'Regexp') ); // 4th parameter set to true to add line breaks // 5th parameter set to false to avoid htmlspecialchars() escaping in the label // since we have some HTML in some labels - $html_output .= $common_functions->getRadioFields( + $html_output .= $this->getCommonFunctions()->getRadioFields( 'criteriaSearchType', $choices, $this->_criteriaSearchType, true, false ); $html_output .= ''; From 01bcab27822e981e9f4c516d0a456774bb6dfad3 Mon Sep 17 00:00:00 2001 From: Atul Pratap Singh Date: Sat, 7 Jul 2012 16:12:49 +0530 Subject: [PATCH 17/24] Use PMA_DbSearch in db_search.php --- db_search.php | 106 +++++------------------------------ libraries/DbSearch.class.php | 4 +- 2 files changed, 15 insertions(+), 95 deletions(-) diff --git a/db_search.php b/db_search.php index 07de04675d..1aa3ea4037 100644 --- a/db_search.php +++ b/db_search.php @@ -9,10 +9,10 @@ */ /** - * + * Gets some core libraries */ require_once 'libraries/common.inc.php'; -require_once 'libraries/db_search.lib.php'; +require_once 'libraries/DbSearch.class.php'; $response = PMA_Response::getInstance(); $header = $response->getHeader(); @@ -21,119 +21,39 @@ $scripts->addFile('db_search.js'); $scripts->addFile('sql.js'); $scripts->addFile('makegrid.js'); $scripts->addFile('jquery/timepicker.js'); -$common_functions = PMA_CommonFunctions::getInstance(); -/** - * Gets some core libraries and send headers - */ require 'libraries/db_common.inc.php'; -/** - * init - */ // If config variable $GLOBALS['cfg']['Usedbsearch'] is on false : exit. if (! $GLOBALS['cfg']['UseDbSearch']) { - $common_functions->mysqlDie(__('Access denied'), '', false, $err_url); + PMA_CommonFunctions::getInstance()->mysqlDie( + __('Access denied'), '', false, $err_url + ); } // end if $url_query .= '&goto=db_search.php'; $url_params['goto'] = 'db_search.php'; -/** - * @global array list of tables from the current database - * but do not clash with $tables coming from db_info.inc.php - */ -$tables_names_only = PMA_DBI_get_tables($GLOBALS['db']); - -$searchTypes = array( - '1' => __('at least one of the words'), - '2' => __('all words'), - '3' => __('the exact phrase'), - '4' => __('as regular expression'), -); - -if (empty($_REQUEST['criteriaSearchType']) - || ! is_string($_REQUEST['criteriaSearchType']) - || ! array_key_exists($_REQUEST['criteriaSearchType'], $searchTypes) -) { - $criteriaSearchType = 1; - unset($_REQUEST['submit_search']); -} else { - $criteriaSearchType = (int) $_REQUEST['criteriaSearchType']; - $searchTypeDescription = $searchTypes[$_REQUEST['criteriaSearchType']]; -} - -if (empty($_REQUEST['criteriaSearchString']) - || ! is_string($_REQUEST['criteriaSearchString']) -) { - $criteriaSearchString = ''; - unset($_REQUEST['submit_search']); -} else { - $criteriaSearchString = $_REQUEST['criteriaSearchString']; -} - -$criteriaTables = array(); -if (empty($_REQUEST['criteriaTables']) || ! is_array($_REQUEST['criteriaTables'])) { - unset($_REQUEST['submit_search']); -} elseif (! isset($_REQUEST['selectall']) && ! isset($_REQUEST['unselectall'])) { - $criteriaTables = array_intersect( - $_REQUEST['criteriaTables'], $tables_names_only - ); -} - -if (isset($_REQUEST['selectall'])) { - $criteriaTables = $tables_names_only; -} elseif (isset($_REQUEST['unselectall'])) { - $criteriaTables = array(); -} - -if (empty($_REQUEST['criteriaColumnName']) - || ! is_string($_REQUEST['criteriaColumnName']) -) { - unset($criteriaColumnName); -} else { - $criteriaColumnName = $common_functions->sqlAddSlashes( - $_REQUEST['criteriaColumnName'], true - ); -} - -/** - * Displays top links if we are not in an Ajax request - */ -$sub_part = ''; +// Create a database search instance +$db_search = new PMA_DbSearch($GLOBALS['db']); +// Displays top links if we are not in an Ajax request if ( $GLOBALS['is_ajax_request'] != true) { include 'libraries/db_info.inc.php'; $response->addHTML('
'); } -/** - * Main search form has been submitted - */ +// Main search form has been submitted, get results if (isset($_REQUEST['submit_search'])) { - $response->addHTML( - PMA_dbSearchGetSearchResults( - $criteriaTables, $searchTypeDescription, - $criteriaSearchString, $criteriaSearchType, - (! empty($criteriaColumnName) ? $criteriaColumnName : '') - ) - ); + $response->addHTML($db_search->getSearchResults()); } -/** - * If we are in an Ajax request, we need to exit after displaying all the HTML - */ +// If we are in an Ajax request, we need to exit after displaying all the HTML if ($GLOBALS['is_ajax_request'] == true) { exit; } else { $response->addHTML('
');//end searchresults div } -// Add search form -$response->addHTML( - PMA_dbSearchGetSelectionForm( - $criteriaSearchString, $criteriaSearchType, $tables_names_only, - $criteriaTables, $url_params, - (! empty($criteriaColumnName) ? $criteriaColumnName : '') - ) -); +// Add search form to response +$response->addHTML($db_search->getSelectionForm($url_params)); ?> diff --git a/libraries/DbSearch.class.php b/libraries/DbSearch.class.php index 2096b5f3d1..8e7f14cf0b 100644 --- a/libraries/DbSearch.class.php +++ b/libraries/DbSearch.class.php @@ -136,7 +136,7 @@ class PMA_DbSearch if (empty($_REQUEST['criteriaSearchType']) || ! is_string($_REQUEST['criteriaSearchType']) - || ! array_key_exists($_REQUEST['criteriaSearchType'], $searchTypes) + || ! array_key_exists($_REQUEST['criteriaSearchType'], $this->_searchTypes) ) { $this->_criteriaSearchType = 1; unset($_REQUEST['submit_search']); @@ -321,7 +321,7 @@ class PMA_DbSearch } // end for $html_output .= ''; // Displays total number of matches - if (count($criteriaTables) > 1) { + if (count($this->_criteriaTables) > 1) { $html_output .= '

'; $html_output .= sprintf( _ngettext( From c453d2b47ea18f8c78ca892e228c96a2ffceb101 Mon Sep 17 00:00:00 2001 From: Atul Pratap Singh Date: Sat, 7 Jul 2012 16:19:17 +0530 Subject: [PATCH 18/24] Deleted libraries/db_search.lib.php --- libraries/db_search.lib.php | 389 ------------------------------------ 1 file changed, 389 deletions(-) delete mode 100644 libraries/db_search.lib.php diff --git a/libraries/db_search.lib.php b/libraries/db_search.lib.php deleted file mode 100644 index 5720246dc1..0000000000 --- a/libraries/db_search.lib.php +++ /dev/null @@ -1,389 +0,0 @@ - 1 word at least, 2 -> all words, - * 3 -> exact string, 4 -> regexp) - * - * @return array 3 SQL querys (for count, display and delete results) - * - * @todo can we make use of fulltextsearch IN BOOLEAN MODE for this? - * PMA_backquote - * PMA_DBI_free_result - * PMA_DBI_fetch_assoc - * $GLOBALS['db'] - * explode - * count - * strlen - */ -function PMA_getSearchSqls($table, $criteriaColumnName, $criteriaSearchString, - $criteriaSearchType -) { - $common_functions = PMA_CommonFunctions::getInstance(); - // Statement types - $sqlstr_select = 'SELECT'; - $sqlstr_delete = 'DELETE'; - // Table to use - $sqlstr_from = ' FROM ' - . $common_functions->backquote($GLOBALS['db']) . '.' - . $common_functions->backquote($table); - // Gets where clause for the query - $where_clause = PMA_dbSearchGetWhereClause( - $table, $criteriaSearchString, $criteriaSearchType, $criteriaColumnName - ); - // Builds complete queries - $sql['select_columns'] = $sqlstr_select . ' * ' . $sqlstr_from . $where_clause; - // here, I think we need to still use the COUNT clause, even for - // VIEWs, anyway we have a WHERE clause that should limit results - $sql['select_count'] = $sqlstr_select . ' COUNT(*) AS `count`' - . $sqlstr_from . $where_clause; - $sql['delete'] = $sqlstr_delete . $sqlstr_from . $where_clause; - - return $sql; -} - -/** - * Provides where clause for bulding SQL query - * - * @param string $table The table name - * @param integer $criteriaSearchString The search word/phrase/regexp to be searched - * @param integer $criteriaSearchType Type of search - * (1 -> 1 word at least, 2 -> all words, - * 3 -> exact string, 4 -> regexp) - * @param string $criteriaColumnName Restrict the search to this column - * - * @return string The generated where clause - */ -function PMA_dbSearchGetWhereClause($table, $criteriaSearchString, - $criteriaSearchType, $criteriaColumnName -) { - $common_functions = PMA_CommonFunctions::getInstance(); - $where_clause = ''; - // Columns to select - $allColumns = PMA_DBI_get_columns($GLOBALS['db'], $table); - $likeClauses = array(); - // Based on search type, decide like/regex & '%'/'' - $like_or_regex = (($criteriaSearchType == 4) ? 'REGEXP' : 'LIKE'); - $automatic_wildcard = (($criteriaSearchType < 3) ? '%' : ''); - // For "as regular expression" (search option 4), LIKE won't be used - // Usage example: If user is seaching for a literal $ in a regexp search, - // he should enter \$ as the value. - $criteriaSearchString = $common_functions->sqlAddSlashes( - $criteriaSearchString, ($criteriaSearchType == 4 ? false : true) - ); - // Extract search words or pattern - $search_words = (($criteriaSearchType > 2) - ? array($criteriaSearchString) : explode(' ', $criteriaSearchString)); - - foreach ($search_words as $search_word) { - // Eliminates empty values - if (strlen($search_word) === 0) { - continue; - } - $likeClausesPerColumn = array(); - // for each column in the table - foreach ($allColumns as $column) { - if (! isset($criteriaColumnName) - || strlen($criteriaColumnName) == 0 - || $column['Field'] == $criteriaColumnName - ) { - // Drizzle has no CONVERT and all text columns are UTF-8 - $column = ((PMA_DRIZZLE) - ? $common_functions->backquote($column['Field']) - : 'CONVERT(' . $common_functions->backquote($column['Field']) - . ' USING utf8)'); - $likeClausesPerColumn[] = $column . ' ' . $like_or_regex . ' ' - . "'" - . $automatic_wildcard . $search_word . $automatic_wildcard - . "'"; - } - } // end for - if (count($likeClausesPerColumn) > 0) { - $likeClauses[] = implode(' OR ', $likeClausesPerColumn); - } - } // end for - // Use 'OR' if 'at least one word' is to be searched, else use 'AND' - $implode_str = ($criteriaSearchType == 1 ? ' OR ' : ' AND '); - if ( empty($likeClauses)) { - // this could happen when the "inside column" does not exist - // in any selected tables - $where_clause = ' WHERE FALSE'; - } else { - $where_clause = ' WHERE (' - . implode(') ' . $implode_str . ' (', $likeClauses) - . ')'; - } - return $where_clause; -} - -/** - * Displays database search results - * - * @param array $criteriaTables Tables on which search is to be performed - * @param string $searchTypeDescription Description for search type - * @param string $criteriaSearchString The search word/phrase/regexp to be searched - * @param integer $criteriaSearchType Type of search - * (1 -> 1 word at least, 2 -> all words, - * 3 -> exact string, 4 -> regexp) - * @param string $criteriaColumnName Restrict the search to this column - * - * @return string HTML for search results - */ -function PMA_dbSearchGetSearchResults($criteriaTables, $searchTypeDescription, - $criteriaSearchString, $criteriaSearchType, $criteriaColumnName = null -) { - $html_output = ''; - // Displays search string - $html_output .= '
' - . '' - . ''; - - $num_search_result_total = 0; - $odd_row = true; - // For each table selected as search criteria - foreach ($criteriaTables as $each_table) { - // Gets the SQL statements - $newsearchsqls = PMA_getSearchSqls( - $each_table, (! empty($criteriaColumnName) ? $criteriaColumnName : ''), - $criteriaSearchString, $criteriaSearchType - ); - // Executes the "COUNT" statement - $res_cnt = PMA_DBI_fetch_value($newsearchsqls['select_count']); - $num_search_result_total += $res_cnt; - // Gets the result row's HTML for a table - $html_output .= PMA_dbSearchGetResultsRow( - $each_table, $newsearchsqls, $odd_row - ); - $odd_row = ! $odd_row; - } // end for - $html_output .= '
' - . sprintf( - __('Search results for "%s" %s:'), - htmlspecialchars($criteriaSearchString), $searchTypeDescription - ) - . '
'; - // Displays total number of matches - if (count($criteriaTables) > 1) { - $html_output .= '

'; - $html_output .= sprintf( - _ngettext( - 'Total: %s match', - 'Total: %s matches', - $num_search_result_total - ), - $num_search_result_total - ); - $html_output .= '

'; - } - return $html_output; -} - -/** - * Provides search results row with browse/delete links. - * (for a table) - * - * @param string $each_table Tables on which search is to be performed - * @param array $newsearchsqls Contains SQL queries - * @param bool $odd_row For displaying contrasting table rows - * - * @return string HTML row - */ -function PMA_dbSearchGetResultsRow($each_table, $newsearchsqls, $odd_row) -{ - $this_url_params = array( - 'db' => $GLOBALS['db'], - 'goto' => 'db_sql.php', - 'pos' => 0, - 'is_js_confirmed' => 0, - ); - $res_cnt = PMA_DBI_fetch_value($newsearchsqls['select_count']); - // Start forming search results row - $html_output = ''; - // Displays results count for a table - $html_output .= ''; - $html_output .= sprintf( - _ngettext( - '%1$s match in %2$s', - '%1$s matches in %2$s', $res_cnt - ), - $res_cnt, htmlspecialchars($each_table) - ); - $html_output .= ''; - // Displays browse/delete link if result count > 0 - if ($res_cnt > 0) { - $this_url_params['sql_query'] = $newsearchsqls['select_columns']; - $browse_result_path = 'sql.php' . PMA_generate_common_url($this_url_params); - $html_output .= '' - . __('Browse') . ''; - $this_url_params['sql_query'] = $newsearchsqls['delete']; - $delete_result_path = 'sql.php' . PMA_generate_common_url($this_url_params); - $html_output .= '' - . __('Delete') . ''; - } else { - $html_output .= ' ' - .' '; - }// end if else - $html_output .= ''; - return $html_output; -} - -/** - * Provides the main search form's html - * - * @param string $criteriaSearchString Keyword/Regular expression earlier entered - * @param integer $criteriaSearchType Type of search (one word, phrase etc.) - * @param array $tables_names_only Names of all tables - * @param array $criteriaTables Tables on which search is to be performed - * @param array $url_params URL parameters - * @param string $criteriaColumnName Restrict the search to this column - * - * @return string HTML for selection form - */ -function PMA_dbSearchGetSelectionForm($criteriaSearchString, $criteriaSearchType, - $tables_names_only, $criteriaTables, $url_params, $criteriaColumnName = null -) { - $common_functions = PMA_CommonFunctions::getInstance(); - $html_output = ''; - $html_output .= ''; - $html_output .= PMA_generate_common_hidden_inputs($GLOBALS['db']); - $html_output .= '
'; - // set legend caption - $html_output .= '' . __('Search in database') . ''; - $html_output .= ''; - // inputbox for search phrase - $html_output .= ''; - $html_output .= ''; - $html_output .= ''; - $html_output .= ''; - // choices for types of search - $html_output .= ''; - $html_output .= ''; - $html_output .= ''; - // displays table names as select options - $html_output .= ''; - $html_output .= ''; - $html_output .= ''; - // Displays 'select all' and 'unselect all' links - $alter_select = '' - . __('Select All') . '  / '; - $alter_select .= '' - . __('Unselect All') . ''; - $html_output .= ''; - // Inputbox for column name entry - $html_output .= ''; - $html_output .= ''; - $html_output .= ''; - $html_output .= ''; - $html_output .= '
' . __('Words or values to search for (wildcard: "%"):') - . '
' . __('Find:') . ''; - $choices = array( - '1' => __('at least one of the words') - . $common_functions->showHint( - __('Words are separated by a space character (" ").') - ), - '2' => __('all words') - . $common_functions->showHint( - __('Words are separated by a space character (" ").') - ), - '3' => __('the exact phrase'), - '4' => __('as regular expression') - . ' ' . $common_functions->showMySQLDocu('Regexp', 'Regexp') - ); - // 4th parameter set to true to add line breaks - // 5th parameter set to false to avoid htmlspecialchars() escaping in the label - // since we have some HTML in some labels - $html_output .= $common_functions->getRadioFields( - 'criteriaSearchType', $choices, $criteriaSearchType, true, false - ); - $html_output .= '
' . __('Inside tables:') . ''; - $html_output .= ''; - $html_output .= '
' . $alter_select . '
' . __('Inside column:') . '
'; - $html_output .= '
'; - $html_output .= '
'; - $html_output .= ''; - $html_output .= '
'; - $html_output .= ''; - $html_output .= getResultDivs(); - - return $html_output; -} - -/** - * Provides div tags for browsing search results and sql query form. - * - * @return string div tags - */ -function getResultDivs() -{ - $html_output = ''; - $html_output .= '
'; - $html_output .= ''; - $html_output .= '
'; - // div for browsing results - $html_output .= '
'; - $html_output .= ''; - $html_output .= '
'; - $html_output .= '
'; - $html_output .= '
'; - $html_output .= ''; - $html_output .= '
'; - $html_output .= ''; - $html_output .= ''; - return $html_output; -} -?> From c03538c1ed551033cec474e8176797dbecc946af Mon Sep 17 00:00:00 2001 From: Marc Delisle Date: Sat, 7 Jul 2012 09:09:51 -0400 Subject: [PATCH 19/24] 3.5.2 release --- ChangeLog | 2 +- Documentation.html | 4 ++-- README | 2 +- libraries/Config.class.php | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index cc62eb36ad..9f0581e090 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,7 +1,7 @@ phpMyAdmin - ChangeLog ====================== -3.5.2.0 (not yet released) +3.5.2.0 (2012-07-07) - bug #3521416 [interface] JS error when editing index - bug #3521313 [core] Call to undefined function __() - bug #3521016 [edit] NOW() function incorrectly selected diff --git a/Documentation.html b/Documentation.html index 883633e09e..b2d63dd03f 100644 --- a/Documentation.html +++ b/Documentation.html @@ -9,7 +9,7 @@ vim: expandtab ts=4 sw=4 sts=4 tw=78 - phpMyAdmin 3.5.2-rc1 - Documentation + phpMyAdmin 3.5.2 - Documentation @@ -17,7 +17,7 @@ vim: expandtab ts=4 sw=4 sts=4 tw=78 diff --git a/README b/README index d5ac5fba3b..64abf10474 100644 --- a/README +++ b/README @@ -1,7 +1,7 @@ phpMyAdmin - Readme =================== -Version 3.5.2-rc1 +Version 3.5.2 A set of PHP-scripts to manage MySQL over the web. diff --git a/libraries/Config.class.php b/libraries/Config.class.php index 25b34c6d25..dd37bb241f 100644 --- a/libraries/Config.class.php +++ b/libraries/Config.class.php @@ -98,7 +98,7 @@ class PMA_Config */ function checkSystem() { - $this->set('PMA_VERSION', '3.5.2-rc1'); + $this->set('PMA_VERSION', '3.5.2'); /** * @deprecated */ From 3ecfb9f36ad7542eed2eb3c2fa577994b315923f Mon Sep 17 00:00:00 2001 From: Marc Delisle Date: Sat, 7 Jul 2012 09:22:22 -0400 Subject: [PATCH 20/24] 3.5.2 release --- ChangeLog | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index d2c1ffe0a9..5d67bba906 100644 --- a/ChangeLog +++ b/ChangeLog @@ -7,7 +7,7 @@ phpMyAdmin - ChangeLog - bug #3527531 [interface] GC-maxlifetime warning incorrectly displayed - bug #3526916 [interface] Search fails with JS error when tooltips disabled -3.5.2.0 (not yet released) +3.5.2.0 (2012-07-07) - bug #3521416 [interface] JS error when editing index - bug #3521313 [core] Call to undefined function __() - bug #3521016 [edit] NOW() function incorrectly selected From dca620c86b2037ed03bf3ab2d3c355de0fbfcd87 Mon Sep 17 00:00:00 2001 From: Marc Delisle Date: Sat, 7 Jul 2012 10:58:49 -0400 Subject: [PATCH 21/24] Improve comments --- db_search.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/db_search.php b/db_search.php index 1aa3ea4037..dcb18eb701 100644 --- a/db_search.php +++ b/db_search.php @@ -36,7 +36,7 @@ $url_params['goto'] = 'db_search.php'; // Create a database search instance $db_search = new PMA_DbSearch($GLOBALS['db']); -// Displays top links if we are not in an Ajax request +// Display top links if we are not in an Ajax request if ( $GLOBALS['is_ajax_request'] != true) { include 'libraries/db_info.inc.php'; $response->addHTML('
'); @@ -54,6 +54,6 @@ if ($GLOBALS['is_ajax_request'] == true) { $response->addHTML('
');//end searchresults div } -// Add search form to response +// Display the search form $response->addHTML($db_search->getSelectionForm($url_params)); ?> From 981ffee92b153881615527d38249f5c2713cfb00 Mon Sep 17 00:00:00 2001 From: Madhura Jayaratne Date: Sat, 7 Jul 2012 22:25:31 +0530 Subject: [PATCH 22/24] Coding style fixes - long lines --- libraries/gis/pma_gis_multilinestring.php | 22 ++++++----- libraries/gis/pma_gis_multipolygon.php | 47 +++++++++++++---------- libraries/gis/pma_gis_polygon.php | 9 +++-- libraries/gis/pma_gis_visualization.php | 14 ++++--- 4 files changed, 53 insertions(+), 39 deletions(-) diff --git a/libraries/gis/pma_gis_multilinestring.php b/libraries/gis/pma_gis_multilinestring.php index 0f49a0c197..ce4a0c94a1 100644 --- a/libraries/gis/pma_gis_multilinestring.php +++ b/libraries/gis/pma_gis_multilinestring.php @@ -270,26 +270,28 @@ class PMA_GIS_Multilinestring extends PMA_GIS_Geometry */ public function generateWkt($gis_data, $index, $empty = '') { - $no_of_lines = isset($gis_data[$index]['MULTILINESTRING']['no_of_lines']) - ? $gis_data[$index]['MULTILINESTRING']['no_of_lines'] : 1; + $data_row = $gis_data[$index]['MULTILINESTRING']; + + $no_of_lines = isset($data_row['no_of_lines']) + ? $data_row['no_of_lines'] : 1; if ($no_of_lines < 1) { $no_of_lines = 1; } $wkt = 'MULTILINESTRING('; for ($i = 0; $i < $no_of_lines; $i++) { - $no_of_points = isset($gis_data[$index]['MULTILINESTRING'][$i]['no_of_points']) - ? $gis_data[$index]['MULTILINESTRING'][$i]['no_of_points'] : 2; + $no_of_points = isset($data_row[$i]['no_of_points']) + ? $data_row[$i]['no_of_points'] : 2; if ($no_of_points < 2) { $no_of_points = 2; } $wkt .= '('; for ($j = 0; $j < $no_of_points; $j++) { - $wkt .= ((isset($gis_data[$index]['MULTILINESTRING'][$i][$j]['x']) - && trim($gis_data[$index]['MULTILINESTRING'][$i][$j]['x']) != '') - ? $gis_data[$index]['MULTILINESTRING'][$i][$j]['x'] : $empty) - . ' ' . ((isset($gis_data[$index]['MULTILINESTRING'][$i][$j]['y']) - && trim($gis_data[$index]['MULTILINESTRING'][$i][$j]['y']) != '') - ? $gis_data[$index]['MULTILINESTRING'][$i][$j]['y'] : $empty) . ','; + $wkt .= ((isset($data_row[$i][$j]['x']) + && trim($data_row[$i][$j]['x']) != '') + ? $data_row[$i][$j]['x'] : $empty) + . ' ' . ((isset($data_row[$i][$j]['y']) + && trim($data_row[$i][$j]['y']) != '') + ? $data_row[$i][$j]['y'] : $empty) . ','; } $wkt = substr($wkt, 0, strlen($wkt) - 1); $wkt .= '),'; diff --git a/libraries/gis/pma_gis_multipolygon.php b/libraries/gis/pma_gis_multipolygon.php index ffeb7621fb..a8c8241524 100644 --- a/libraries/gis/pma_gis_multipolygon.php +++ b/libraries/gis/pma_gis_multipolygon.php @@ -338,33 +338,36 @@ class PMA_GIS_Multipolygon extends PMA_GIS_Geometry */ public function generateWkt($gis_data, $index, $empty = '') { - $no_of_polygons = isset($gis_data[$index]['MULTIPOLYGON']['no_of_polygons']) - ? $gis_data[$index]['MULTIPOLYGON']['no_of_polygons'] : 1; + $data_row = $gis_data[$index]['MULTIPOLYGON']; + + $no_of_polygons = isset($data_row['no_of_polygons']) + ? $data_row['no_of_polygons'] : 1; if ($no_of_polygons < 1) { $no_of_polygons = 1; } + $wkt = 'MULTIPOLYGON('; for ($k = 0; $k < $no_of_polygons; $k++) { - $no_of_lines = isset($gis_data[$index]['MULTIPOLYGON'][$k]['no_of_lines']) - ? $gis_data[$index]['MULTIPOLYGON'][$k]['no_of_lines'] : 1; + $no_of_lines = isset($data_row[$k]['no_of_lines']) + ? $data_row[$k]['no_of_lines'] : 1; if ($no_of_lines < 1) { $no_of_lines = 1; } $wkt .= '('; for ($i = 0; $i < $no_of_lines; $i++) { - $no_of_points = isset($gis_data[$index]['MULTIPOLYGON'][$k][$i]['no_of_points']) - ? $gis_data[$index]['MULTIPOLYGON'][$k][$i]['no_of_points'] : 4; + $no_of_points = isset($data_row[$k][$i]['no_of_points']) + ? $data_row[$k][$i]['no_of_points'] : 4; if ($no_of_points < 4) { $no_of_points = 4; } $wkt .= '('; for ($j = 0; $j < $no_of_points; $j++) { - $wkt .= ((isset($gis_data[$index]['MULTIPOLYGON'][$k][$i][$j]['x']) - && trim($gis_data[$index]['MULTIPOLYGON'][$k][$i][$j]['x']) != '') - ? $gis_data[$index]['MULTIPOLYGON'][$k][$i][$j]['x'] : $empty) - . ' ' . ((isset($gis_data[$index]['MULTIPOLYGON'][$k][$i][$j]['y']) - && trim($gis_data[$index]['MULTIPOLYGON'][$k][$i][$j]['y']) != '') - ? $gis_data[$index]['MULTIPOLYGON'][$k][$i][$j]['y'] : $empty) .','; + $wkt .= ((isset($data_row[$k][$i][$j]['x']) + && trim($data_row[$k][$i][$j]['x']) != '') + ? $data_row[$k][$i][$j]['x'] : $empty) + . ' ' . ((isset($data_row[$k][$i][$j]['y']) + && trim($data_row[$k][$i][$j]['y']) != '') + ? $data_row[$k][$i][$j]['y'] : $empty) .','; } $wkt = substr($wkt, 0, strlen($wkt) - 1); $wkt .= '),'; @@ -484,32 +487,34 @@ class PMA_GIS_Multipolygon extends PMA_GIS_Geometry $multipolygon = substr($wkt, 15, (strlen($wkt) - 18)); // Seperate each polygon $polygons = explode(")),((", $multipolygon); - $params[$index]['MULTIPOLYGON']['no_of_polygons'] = count($polygons); + + $param_row =& $params[$index]['MULTIPOLYGON']; + $param_row['no_of_polygons'] = count($polygons); $k = 0; foreach ($polygons as $polygon) { // If the polygon doesnt have an inner polygon if (strpos($polygon, "),(") === false) { - $params[$index]['MULTIPOLYGON'][$k]['no_of_lines'] = 1; + $param_row[$k]['no_of_lines'] = 1; $points_arr = $this->extractPoints($polygon, null); $no_of_points = count($points_arr); - $params[$index]['MULTIPOLYGON'][$k][0]['no_of_points'] = $no_of_points; + $param_row[$k][0]['no_of_points'] = $no_of_points; for ($i = 0; $i < $no_of_points; $i++) { - $params[$index]['MULTIPOLYGON'][$k][0][$i]['x'] = $points_arr[$i][0]; - $params[$index]['MULTIPOLYGON'][$k][0][$i]['y'] = $points_arr[$i][1]; + $param_row[$k][0][$i]['x'] = $points_arr[$i][0]; + $param_row[$k][0][$i]['y'] = $points_arr[$i][1]; } } else { // Seperate outer and inner polygons $parts = explode("),(", $polygon); - $params[$index]['MULTIPOLYGON'][$k]['no_of_lines'] = count($parts); + $param_row[$k]['no_of_lines'] = count($parts); $j = 0; foreach ($parts as $ring) { $points_arr = $this->extractPoints($ring, null); $no_of_points = count($points_arr); - $params[$index]['MULTIPOLYGON'][$k][$j]['no_of_points'] = $no_of_points; + $param_row[$k][$j]['no_of_points'] = $no_of_points; for ($i = 0; $i < $no_of_points; $i++) { - $params[$index]['MULTIPOLYGON'][$k][$j][$i]['x'] = $points_arr[$i][0]; - $params[$index]['MULTIPOLYGON'][$k][$j][$i]['y'] = $points_arr[$i][1]; + $param_row[$k][$j][$i]['x'] = $points_arr[$i][0]; + $param_row[$k][$j][$i]['y'] = $points_arr[$i][1]; } $j++; } diff --git a/libraries/gis/pma_gis_polygon.php b/libraries/gis/pma_gis_polygon.php index 09bc6b8a14..e090392524 100644 --- a/libraries/gis/pma_gis_polygon.php +++ b/libraries/gis/pma_gis_polygon.php @@ -451,9 +451,9 @@ class PMA_GIS_Polygon extends PMA_GIS_Geometry */ public static function getPointOnSurface($ring) { - + $common_functions = PMA_CommonFunctions::getInstance(); - + // Find two consecutive distinct points. for ($i = 0; $i < count($ring) - 1; $i++) { if ($ring[$i]['y'] != $ring[$i + 1]['y']) { @@ -475,7 +475,10 @@ class PMA_GIS_Polygon extends PMA_GIS_Geometry // Always keep $epsilon < 1 to go with the reduction logic down here $epsilon = 0.1; - $denominator = sqrt($common_functions->pow(($y1 - $y0), 2) + $common_functions->pow(($x0 - $x1), 2)); + $denominator = sqrt( + $common_functions->pow(($y1 - $y0), 2) + + $common_functions->pow(($x0 - $x1), 2) + ); $pointA = array(); $pointB = array(); while (true) { diff --git a/libraries/gis/pma_gis_visualization.php b/libraries/gis/pma_gis_visualization.php index df739159dd..7de1d469e7 100644 --- a/libraries/gis/pma_gis_visualization.php +++ b/libraries/gis/pma_gis_visualization.php @@ -295,15 +295,19 @@ class PMA_GIS_Visualization . 'units: "m",' . 'numZoomLevels: 18,' . 'maxResolution: 156543.0339,' - . 'maxExtent: new OpenLayers.Bounds(-20037508, -20037508, 20037508, 20037508),' - . 'restrictedExtent: new OpenLayers.Bounds(-20037508, -20037508, 20037508, 20037508)' + . 'maxExtent: new OpenLayers.Bounds(' + . '-20037508, -20037508, 20037508, 20037508),' + . 'restrictedExtent: new OpenLayers.Bounds(' + . '-20037508, -20037508, 20037508, 20037508)' . '};' . 'var map = new OpenLayers.Map("openlayersmap", options);' - . 'var layerNone = new OpenLayers.Layer.Boxes("None", {isBaseLayer: true});' + . 'var layerNone = new OpenLayers.Layer.Boxes(' + . '"None", {isBaseLayer: true});' . 'var layerMapnik = new OpenLayers.Layer.OSM.Mapnik("Mapnik");' - . 'var layerOsmarender = new OpenLayers.Layer.OSM.Osmarender("Osmarender");' + . 'var layerOsmarender = new OpenLayers.Layer.OSM.Osmarender(' + . '"Osmarender");' . 'var layerCycleMap = new OpenLayers.Layer.OSM.CycleMap("CycleMap");' - . 'map.addLayers([layerMapnik, layerOsmarender, layerCycleMap, layerNone]);' + . 'map.addLayers([layerMapnik,layerOsmarender,layerCycleMap,layerNone]);' . 'var vectorLayer = new OpenLayers.Layer.Vector("Data");' . 'var bound;'; $output .= $this->_prepareDataSet($this->_data, $scale_data, 'ol', ''); From fb39a90f74f5205fe7d4e907ef335b6bdd9d0631 Mon Sep 17 00:00:00 2001 From: Madhura Jayaratne Date: Sat, 7 Jul 2012 22:53:06 +0530 Subject: [PATCH 23/24] Fix undefined variable, Remove redundant code --- libraries/insert_edit.lib.php | 46 ++++++++++++----------------------- 1 file changed, 15 insertions(+), 31 deletions(-) diff --git a/libraries/insert_edit.lib.php b/libraries/insert_edit.lib.php index 7176e113a2..dbbabebd05 100644 --- a/libraries/insert_edit.lib.php +++ b/libraries/insert_edit.lib.php @@ -705,7 +705,7 @@ function PMA_getValueColumn($column, $backup_field, $column_name_appendix, } if (in_array($column['pma_type'], $gis_data_types)) { - $html_output .= PMA_getHTMLforGisDataTypes($current_row, $column); + $html_output .= PMA_getHTMLforGisDataTypes(); } return $html_output; @@ -1190,7 +1190,7 @@ function PMA_getSelectOptionForUpload($vkey, $column) $files = PMA_getFileSelectOptions( PMA_CommonFunctions::getInstance()->userDir($GLOBALS['cfg']['UploadDir']) ); - + if ($files === false) { return '' . __('Error') . '
' . "\n" . __('The directory you set for upload work cannot be reached') . "\n"; @@ -1357,27 +1357,11 @@ function PMA_getColumnSize($column, $extracted_columnspec) /** * Get HTML for gis data types * - * @param string $current_row row description - * @param array $column description of column in given table - * - * @return string an html snippet + * @return string an html snippet */ -function PMA_getHTMLforGisDataTypes($current_row, $column) +function PMA_getHTMLforGisDataTypes() { - $common_functions = PMA_CommonFunctions::getInstance(); - $data_val = isset($current_row[$column['Field']]) - ? $current_row[$column['Field']] - : ''; - - $_url_params = array( - 'field' => $column['Field_title'], - 'value' => $data_val, - ); - if ($column['pma_type'] != 'geometry') { - $_url_params = $_url_params - + array('gis_data[gis_type]' => strtoupper($column['pma_type'])); - } $edit_str = $common_functions->getIcon('b_edit.png', __('Edit/Insert')); return '' . $common_functions->linkOrButton( @@ -1629,7 +1613,7 @@ function PMA_getSpecialCharsAndBackupFieldForExistingRow( $current_row, $column, $extracted_columnspec, $real_null_value, $gis_data_types, $column_name_appendix ) { - + $common_functions = PMA_CommonFunctions::getInstance(); $special_chars_encoded = ''; // (we are editing) @@ -1806,12 +1790,12 @@ function PMA_isInsertRow() */ function PMA_setSessionForEditNext($one_where_clause) { - + $common_functions = PMA_CommonFunctions::getInstance(); $local_query = 'SELECT * FROM ' . $common_functions->backquote($GLOBALS['db']) . '.' . $common_functions->backquote($GLOBALS['table']) . ' WHERE ' . str_replace('` =', '` >', $one_where_clause) . ' LIMIT 1;'; - + $res = PMA_DBI_query($local_query); $row = PMA_DBI_fetch_row($res); $meta = PMA_DBI_get_fields_meta($res); @@ -2007,9 +1991,9 @@ function PMA_getWarningMessages() function PMA_getDisplayValueForForeignTableColumn($where_comparison, $relation_field_value, $map, $relation_field ) { - + $common_functions = PMA_CommonFunctions::getInstance(); - + $display_field = PMA_getDisplayField( $map[$relation_field]['foreign_db'], $map[$relation_field]['foreign_table'] @@ -2046,9 +2030,9 @@ function PMA_getDisplayValueForForeignTableColumn($where_comparison, function PMA_getLinkForRelationalDisplayField($map, $relation_field, $where_comparison, $dispval, $relation_field_value ) { - + $common_functions = PMA_CommonFunctions::getInstance(); - + if ('K' == $_SESSION['tmp_user_values']['relational_display']) { // user chose "relational key" in the display options, so // the title contains the display field @@ -2200,9 +2184,9 @@ function PMA_getQueryValuesForInsertAndUpdateInMultipleEdit($multi_edit_columns_ $multi_edit_funcs,$is_insert, $query_values, $query_fields, $current_value_as_an_array, $value_sets, $key, $multi_edit_columns_null_prev ) { - + $common_functions = PMA_CommonFunctions::getInstance(); - + // i n s e r t if ($is_insert) { // no need to add column into the valuelist @@ -2266,9 +2250,9 @@ function PMA_getCurrentValueForDifferentTypes($possibly_uploaded_val, $key, $rownumber, $multi_edit_columns_name, $multi_edit_columns_null, $multi_edit_columns_null_prev, $is_insert, $using_key, $where_clause, $table ) { - + $common_functions = PMA_CommonFunctions::getInstance(); - + // Fetch the current values of a row to use in case we have a protected field if ($is_insert && $using_key && isset($multi_edit_columns_type) From 3643ed0a848f0c6876f3163977f8902352349eea Mon Sep 17 00:00:00 2001 From: Madhura Jayaratne Date: Sat, 7 Jul 2012 23:17:54 +0530 Subject: [PATCH 24/24] PMA_printable_bit_value no longer exists --- libraries/insert_edit.lib.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/insert_edit.lib.php b/libraries/insert_edit.lib.php index dbbabebd05..2f17f20db0 100644 --- a/libraries/insert_edit.lib.php +++ b/libraries/insert_edit.lib.php @@ -1623,7 +1623,7 @@ function PMA_getSpecialCharsAndBackupFieldForExistingRow( $special_chars = ''; $data = $current_row[$column['Field']]; } elseif ($column['True_Type'] == 'bit') { - $special_chars = PMA_printable_bit_value( + $special_chars = $common_functions->printableBitValue( $current_row[$column['Field']], $extracted_columnspec['spec_in_brackets'] ); } elseif (in_array($column['True_Type'], $gis_data_types)) {