From 48d9cf9f8b21831ff27dc81a04fe33d8aa102cb8 Mon Sep 17 00:00:00 2001
From: Atul Pratap Singh
Date: Wed, 20 Jun 2012 00:00:26 +0530
Subject: [PATCH 1/5] Remove HTML-PHP mix used for displaying db search form
---
db_search.php | 201 +++++++++++++++++++++++++++++---------------------
1 file changed, 117 insertions(+), 84 deletions(-)
diff --git a/db_search.php b/db_search.php
index 1222e42d41..e7b8015a40 100644
--- a/db_search.php
+++ b/db_search.php
@@ -282,92 +282,125 @@ if ($GLOBALS['is_ajax_request'] == true) {
}
/**
- * 2. Displays the main search form
+ * Provides the main search form's html
+ *
+ * @param string $searched Keyword/Regular expression to be searched
+ * @param integer $search_option Type of search (one word, phrase etc.)
+ * @param array $tables_names_only Names of all tables
+ * @param array $tables_selected Tables on which search is to be performed
+ * @param array $url_params URL parameters
+ * @param string $field_str Restrict the search to this field
+ *
+ * @return string HTML for selection form
*/
-?>
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
From 0435de02c7aeee007ce5952ef9d9c430b790c6ce Mon Sep 17 00:00:00 2001
From: Atul Pratap Singh
Date: Tue, 26 Jun 2012 00:00:29 +0530
Subject: [PATCH 2/5] Form function for displaying search results
---
db_search.php | 102 ++++++++++++++++++++++++++++++++++----------------
1 file changed, 69 insertions(+), 33 deletions(-)
diff --git a/db_search.php b/db_search.php
index e7b8015a40..fabb440969 100644
--- a/db_search.php
+++ b/db_search.php
@@ -199,27 +199,45 @@ if (isset($_REQUEST['submit_search'])) {
return $sql;
} // end of the "PMA_getSearchSqls()" function
+ echo PMA_dbSearchGetSearchResults(
+ $tables_selected, $searched, $option_str,
+ $search_str, $search_option, (! empty($field_str) ? $field_str : '')
+ );
+} // end 1.
-
- /**
- * Displays the results
- */
+/**
+ * Displays the results
+ *
+ * @param array $tables_selected Tables on which search is to be performed
+ * @param string $searched The search word/phrase/regexp
+ * @param string $option_str Type of search
+ * @param string $search_str the string to search
+ * @param integer $search_option type of search
+ * (1 -> 1 word at least, 2 -> all words,
+ * 3 -> exact string, 4 -> regexp)
+ * @param string $field_str Restrict the search to this field
+ *
+ * @return string HTML results *
+ */
+function PMA_dbSearchGetSearchResults($tables_selected, $searched, $option_str,
+ $search_str, $search_option, $field_str = null
+) {
$this_url_params = array(
'db' => $GLOBALS['db'],
'goto' => 'db_sql.php',
'pos' => 0,
'is_js_confirmed' => 0,
);
-
+ $html_output = '';
// Displays search string
- echo '
' . "\n"
- . '';
if (count($tables_selected) > 1) {
- echo '' . sprintf(
- _ngettext('Total: %s match', 'Total: %s matches', $num_search_result_total),
+ $html_output .= '
';
+ $html_output .= sprintf(
+ _ngettext(
+ 'Total: %s match',
+ 'Total: %s matches',
+ $num_search_result_total
+ ),
$num_search_result_total
- ) . '
' . "\n";
+ );
+ $html_output .= '
';
}
-} // end 1.
+ return $html_output;
+}
/**
* If we are in an Ajax request, we need to exit after displaying all the HTML
From 98c8b308b8806b7b16a10132faf657af28c58356 Mon Sep 17 00:00:00 2001
From: Atul Pratap Singh
Date: Tue, 26 Jun 2012 00:26:51 +0530
Subject: [PATCH 3/5] Fix typo in doc comments
---
db_search.php | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/db_search.php b/db_search.php
index fabb440969..39c7330b90 100644
--- a/db_search.php
+++ b/db_search.php
@@ -206,7 +206,7 @@ if (isset($_REQUEST['submit_search'])) {
} // end 1.
/**
- * Displays the results
+ * Displays database search results
*
* @param array $tables_selected Tables on which search is to be performed
* @param string $searched The search word/phrase/regexp
@@ -217,7 +217,7 @@ if (isset($_REQUEST['submit_search'])) {
* 3 -> exact string, 4 -> regexp)
* @param string $field_str Restrict the search to this field
*
- * @return string HTML results *
+ * @return string HTML for search results
*/
function PMA_dbSearchGetSearchResults($tables_selected, $searched, $option_str,
$search_str, $search_option, $field_str = null
From 46a4b693d4859a7c8d7d1d5c75564f6102a79bee Mon Sep 17 00:00:00 2001
From: Atul Pratap Singh
Date: Tue, 26 Jun 2012 02:01:00 +0530
Subject: [PATCH 4/5] Slice PMA_dbSearchGetResultsRow out of
PMA_dbSearchGetSearchResults
---
db_search.php | 94 ++++++++++++++++++++++++++++++---------------------
1 file changed, 56 insertions(+), 38 deletions(-)
diff --git a/db_search.php b/db_search.php
index 39c7330b90..e494be1e64 100644
--- a/db_search.php
+++ b/db_search.php
@@ -241,7 +241,7 @@ function PMA_dbSearchGetSearchResults($tables_selected, $searched, $option_str,
$num_search_result_total = 0;
$odd_row = true;
-
+ // For each table selected as search criteria
foreach ($tables_selected as $each_table) {
// Gets the SQL statements
$newsearchsqls = PMA_getSearchSqls(
@@ -251,46 +251,11 @@ function PMA_dbSearchGetSearchResults($tables_selected, $searched, $option_str,
// Executes the "COUNT" statement
$res_cnt = PMA_DBI_fetch_value($newsearchsqls['select_count']);
$num_search_result_total += $res_cnt;
-
- $html_output .= '';
- $html_output .= '| ';
- $html_output .= sprintf(
- _ngettext(
- '%1$s match inside table %2$s',
- '%1$s matches inside table %2$s', $res_cnt
- ),
- $res_cnt, htmlspecialchars($each_table)
+ $html_output .= PMA_dbSearchGetResultsRow(
+ $each_table, $newsearchsqls, $odd_row
);
- $html_output .= ' | ';
-
- if ($res_cnt > 0) {
- $this_url_params['sql_query'] = $newsearchsqls['select_fields'];
- $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
$odd_row = ! $odd_row;
- $html_output .= '
';
} // end for
-
$html_output .= '';
if (count($tables_selected) > 1) {
@@ -308,6 +273,59 @@ function PMA_dbSearchGetSearchResults($tables_selected, $searched, $option_str,
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)
+{
+ $res_cnt = PMA_DBI_fetch_value($newsearchsqls['select_count']);
+ // Start forming search results row
+ $html_output = '';
+ $html_output .= '| ';
+ $html_output .= sprintf(
+ _ngettext(
+ '%1$s match inside table %2$s',
+ '%1$s matches inside table %2$s', $res_cnt
+ ),
+ $res_cnt, htmlspecialchars($each_table)
+ );
+ $html_output .= ' | ';
+
+ if ($res_cnt > 0) {
+ $this_url_params['sql_query'] = $newsearchsqls['select_fields'];
+ $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;
+}
+
/**
* If we are in an Ajax request, we need to exit after displaying all the HTML
*/
From bcd4a8c20d950b14f70d55cb32bb91801a7f4992 Mon Sep 17 00:00:00 2001
From: Atul Pratap Singh
Date: Tue, 26 Jun 2012 02:24:37 +0530
Subject: [PATCH 5/5] Use new way of generating content in db_search.php
---
db_search.php | 20 ++++++++++++--------
1 file changed, 12 insertions(+), 8 deletions(-)
diff --git a/db_search.php b/db_search.php
index e494be1e64..bd937ef45a 100644
--- a/db_search.php
+++ b/db_search.php
@@ -102,7 +102,7 @@ $sub_part = '';
if ( $GLOBALS['is_ajax_request'] != true) {
include 'libraries/db_info.inc.php';
- echo '';
+ $response->addHTML('
');
}
/**
@@ -199,9 +199,11 @@ if (isset($_REQUEST['submit_search'])) {
return $sql;
} // end of the "PMA_getSearchSqls()" function
- echo PMA_dbSearchGetSearchResults(
- $tables_selected, $searched, $option_str,
- $search_str, $search_option, (! empty($field_str) ? $field_str : '')
+ $response->addHTML(
+ PMA_dbSearchGetSearchResults(
+ $tables_selected, $searched, $option_str,
+ $search_str, $search_option, (! empty($field_str) ? $field_str : '')
+ )
);
} // end 1.
@@ -332,7 +334,7 @@ function PMA_dbSearchGetResultsRow($each_table, $newsearchsqls, $odd_row)
if ($GLOBALS['is_ajax_request'] == true) {
exit;
} else {
- echo '
';//end searchresults div
+ $response->addHTML('
');//end searchresults div
}
/**
@@ -453,8 +455,10 @@ function getResultDivs()
return $html_output;
}
-echo PMA_dbSearchGetSelectionForm(
- $searched, $search_option, $tables_names_only, $tables_selected, $url_params,
- (! empty($field_str) ? $field_str : '')
+$response->addHTML(
+ PMA_dbSearchGetSelectionForm(
+ $searched, $search_option, $tables_names_only, $tables_selected, $url_params,
+ (! empty($field_str) ? $field_str : '')
+ )
);
?>