diff --git a/db_search.php b/db_search.php index 1222e42d41..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,78 +199,134 @@ if (isset($_REQUEST['submit_search'])) { return $sql; } // end of the "PMA_getSearchSqls()" function + $response->addHTML( + PMA_dbSearchGetSearchResults( + $tables_selected, $searched, $option_str, + $search_str, $search_option, (! empty($field_str) ? $field_str : '') + ) + ); +} // 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 + * @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 for search 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" - . '' . "\n" - . '
' . "\n" + $html_output .= '
' + . '' + . '' . "\n"; + ) + . ''; $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( $each_table, (! empty($field_str) ? $field_str : ''), $search_str, $search_option ); - // Executes the "COUNT" statement $res_cnt = PMA_DBI_fetch_value($newsearchsqls['select_count']); $num_search_result_total += $res_cnt; - - $sql_query .= $newsearchsqls['select_count']; - - echo '' - . '\n"; - - if ($res_cnt > 0) { - $this_url_params['sql_query'] = $newsearchsqls['select_fields']; - $browse_result_path = 'sql.php' . PMA_generate_common_url($this_url_params); - ?> - - - -  ' . "\n" - .'' . "\n"; - }// end if else + $html_output .= PMA_dbSearchGetResultsRow( + $each_table, $newsearchsqls, $odd_row + ); $odd_row = ! $odd_row; - echo '' . "\n"; } // end for - - echo '
' . sprintf( __('Search results for "%s" %s:'), $searched, $option_str - ) . "\n" - . '
' . sprintf( - _ngettext('%1$s match inside table %2$s', '%1$s matches inside table %2$s', $res_cnt), - $res_cnt, htmlspecialchars($each_table) - ) . "  
' . "\n"; + $html_output .= '
'; 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; +} + +/** + * 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 @@ -278,96 +334,131 @@ if (isset($_REQUEST['submit_search'])) { if ($GLOBALS['is_ajax_request'] == true) { exit; } else { - echo '
';//end searchresults div + $response->addHTML('
');//end searchresults div } /** - * 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 */ -?> - -
method="post" action="db_search.php" name="db_search"> - -
- +function PMA_dbSearchGetSelectionForm($searched, $search_option, $tables_names_only, + $tables_selected, $url_params, $field_str = null +) { + $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 .= ''; + $html_output .= ''; + $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') . PMA_showHint(__('Words are separated by a space character (" ").')), + '2' => __('all words') . PMA_showHint(__('Words are separated by a space character (" ").')), + '3' => __('the exact phrase'), + '4' => __('as regular expression') . ' ' . PMA_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 .= PMA_getRadioFields( + 'search_option', $choices, $search_option, true, false + ); + $html_output .= '
' . __('Inside tables:') . ''; + $html_output .= ''; + $alter_select + = '' . __('Select All') . '' + . ' / ' + . '' . __('Unselect All') . ''; + $html_output .= '
' . $alter_select . '
' . __('Inside column:') . '
'; + $html_output .= '
'; + $html_output .= '
'; + $html_output .= ''; + $html_output .= '
'; + $html_output .= ''; + $html_output .= getResultDivs(); + + return $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; +} -$choices = array( - '1' => __('at least one of the words') . PMA_showHint(__('Words are separated by a space character (" ").')), - '2' => __('all words') . PMA_showHint(__('Words are separated by a space character (" ").')), - '3' => __('the exact phrase'), - '4' => __('as regular expression') . ' ' . PMA_showMySQLDocu('Regexp', 'Regexp') +$response->addHTML( + PMA_dbSearchGetSelectionForm( + $searched, $search_option, $tables_names_only, $tables_selected, $url_params, + (! empty($field_str) ? $field_str : '') + ) ); -// 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 -echo PMA_getRadioFields('search_option', $choices, $search_option, true, false); -unset($choices); - ?> -
- -' . "\n"; -foreach ($tables_names_only as $each_table) { - if (in_array($each_table, $tables_selected)) { - $is_selected = ' selected="selected"'; - } else { - $is_selected = ''; - } - - echo ' ' . "\n"; -} // end while - -echo ' ' . "\n"; -$alter_select - = '' . __('Select All') . '' - . ' / ' - . '' . __('Unselect All') . ''; ?> -
-
-
-
-
- -
- - - -
- -
-
- -
-
-
- -
- - -