diff options
author | Chanaka Indrajith <pe.chanaka.ck@gmail.com> | 2012-06-27 20:23:59 +0400 |
---|---|---|
committer | Chanaka Indrajith <pe.chanaka.ck@gmail.com> | 2012-06-27 20:23:59 +0400 |
commit | 39d37fafcce29160c4dfe6ef7696de19bebb1d18 (patch) | |
tree | 3f6b5030d805fb3d5ccbdcf10ab680e7cd12dffa /db_search.php | |
parent | 1cc49d32d94d8981e427a32900dc61ae6ec90149 (diff) | |
parent | f2057c47511c6b3c7d75b167c5abcaab1695675b (diff) |
Resolved conflicts
Diffstat (limited to 'db_search.php')
-rw-r--r-- | db_search.php | 358 |
1 files changed, 225 insertions, 133 deletions
diff --git a/db_search.php b/db_search.php index 1a2f2b9e56..f6606ba910 100644 --- a/db_search.php +++ b/db_search.php @@ -103,7 +103,7 @@ $sub_part = ''; if ( $GLOBALS['is_ajax_request'] != true) { include 'libraries/db_info.inc.php'; - echo '<div id="searchresults">'; + $response->addHTML('<div id="searchresults">'); } /** @@ -200,78 +200,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 '<br />' . "\n" - . '<table class="data">' . "\n" - . '<caption class="tblHeaders">' . "\n" + $html_output .= '<br />' + . '<table class="data">' + . '<caption class="tblHeaders">' . sprintf( __('Search results for "<i>%s</i>" %s:'), $searched, $option_str - ) . "\n" - . '</caption>' . "\n"; + ) + . '</caption>'; $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 '<tr class="noclick ' . ($odd_row ? 'odd' : 'even') . '">' - . '<td>' . sprintf( - _ngettext('%1$s match inside table <i>%2$s</i>', '%1$s matches inside table <i>%2$s</i>', $res_cnt), - $res_cnt, htmlspecialchars($each_table) - ) . "</td>\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); - ?> - <td> <a name="browse_search" href="<?php echo $browse_result_path; ?>" onclick="loadResult('<?php echo $browse_result_path ?> ',' <?php echo $each_table?> ' , '<?php echo PMA_generate_common_url($GLOBALS['db'], $each_table)?>','<?php echo ($GLOBALS['cfg']['AjaxEnable']); ?>');return false;" ><?php echo __('Browse') ?></a> </td> - <?php - $this_url_params['sql_query'] = $newsearchsqls['delete']; - $delete_result_path = 'sql.php' . PMA_generate_common_url($this_url_params); - ?> - <td> <a name="delete_search" href="<?php echo $delete_result_path; ?>" onclick="deleteResult('<?php echo $delete_result_path ?>' , ' <?php printf(__('Delete the matches for the %s table?'), htmlspecialchars($each_table)); ?>','<?php echo ($GLOBALS['cfg']['AjaxEnable']); ?>');return false;" ><?php echo __('Delete') ?></a> </td> - <?php - } else { - echo '<td> </td>' . "\n" - .'<td> </td>' . "\n"; - }// end if else + $html_output .= PMA_dbSearchGetResultsRow( + $each_table, $newsearchsqls, $odd_row + ); $odd_row = ! $odd_row; - echo '</tr>' . "\n"; } // end for - - echo '</table>' . "\n"; + $html_output .= '</table>'; if (count($tables_selected) > 1) { - echo '<p>' . sprintf( - _ngettext('<b>Total:</b> <i>%s</i> match', '<b>Total:</b> <i>%s</i> matches', $num_search_result_total), + $html_output .= '<p>'; + $html_output .= sprintf( + _ngettext( + '<b>Total:</b> <i>%s</i> match', + '<b>Total:</b> <i>%s</i> matches', + $num_search_result_total + ), $num_search_result_total - ) . '</p>' . "\n"; + ); + $html_output .= '</p>'; } -} // 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 = '<tr class="noclick ' . ($odd_row ? 'odd' : 'even') . '">'; + $html_output .= '<td>'; + $html_output .= sprintf( + _ngettext( + '%1$s match in <strong>%2$s</strong>', + '%1$s matches in <strong>%2$s</strong>', $res_cnt + ), + $res_cnt, htmlspecialchars($each_table) + ); + $html_output .= '</td>'; + + 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 .= '<td><a name="browse_search" href="' + . $browse_result_path . '" onclick="loadResult(\'' + . $browse_result_path . '\',\'' . $each_table . '\',\'' + . PMA_generate_common_url($GLOBALS['db'], $each_table) . '\',\'' + . ($GLOBALS['cfg']['AjaxEnable']) .'\');return false;" >' + . __('Browse') . '</a></td>'; + $this_url_params['sql_query'] = $newsearchsqls['delete']; + $delete_result_path = 'sql.php' . PMA_generate_common_url($this_url_params); + $html_output .= '<td><a name="delete_search" href="' + . $delete_result_path . '" onclick="deleteResult(\'' + . $delete_result_path . '\' , \'' + . sprintf( + __('Delete the matches for the %s table?'), + htmlspecialchars($each_table) + ) + . '\',\'' . ($GLOBALS['cfg']['AjaxEnable']) . '\');return false;">' + . __('Delete') . '</a></td>'; + } else { + $html_output .= '<td> </td>' + .'<td> </td>'; + }// end if else + $html_output .= '</tr>'; + return $html_output; +} /** * If we are in an Ajax request, we need to exit after displaying all the HTML @@ -279,98 +335,134 @@ if (isset($_REQUEST['submit_search'])) { if ($GLOBALS['is_ajax_request'] == true) { exit; } else { - echo '</div>';//end searchresults div + $response->addHTML('</div>');//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 */ -?> -<a id="db_search"></a> -<form id="db_search_form"<?php echo ($GLOBALS['cfg']['AjaxEnable'] ? ' class="ajax"' : ''); ?> method="post" action="db_search.php" name="db_search"> -<?php echo PMA_generate_common_hidden_inputs($GLOBALS['db']); ?> -<fieldset> - <legend><?php echo __('Search in database'); ?></legend> - - <table class="formlayout"> - <tr><td><?php echo __('Words or values to search for (wildcard: "%"):'); ?></td> - <td><input type="text" name="search_str" size="60" - value="<?php echo $searched; ?>" /></td> - </tr> - <tr><td class="right vtop"> - <?php echo __('Find:'); ?></td> - <td><?php - -$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 -echo $common_functions->getRadioFields( - 'search_option', $choices, $search_option, true, false -); -unset($choices); - ?> - </td> - </tr> - <tr><td class="right vtop"> - <?php echo __('Inside tables:'); ?></td> - <td rowspan="2"> -<?php -echo ' <select name="table_select[]" size="6" multiple="multiple">' . "\n"; -foreach ($tables_names_only as $each_table) { - if (in_array($each_table, $tables_selected)) { - $is_selected = ' selected="selected"'; - } else { - $is_selected = ''; - } +function PMA_dbSearchGetSelectionForm($searched, $search_option, $tables_names_only, + $tables_selected, $url_params, $field_str = null +) { + + $common_functions = PMA_CommonFunctions::getInstance(); + + $html_output = '<a id="db_search"></a>'; + $html_output .= '<form id="db_search_form"' + . ($GLOBALS['cfg']['AjaxEnable'] ? ' class="ajax"' : '') + . ' method="post" action="db_search.php" name="db_search">'; + $html_output .= PMA_generate_common_hidden_inputs($GLOBALS['db']); + $html_output .= '<fieldset>'; + // set legend caption + $html_output .= '<legend>' . __('Search in database') . '</legend>'; + $html_output .= '<table class="formlayout">'; + // inputbox for search phrase + $html_output .= '<tr>'; + $html_output .= '<td>' . __('Words or values to search for (wildcard: "%"):') + . '</td>'; + $html_output .= '<td><input type="text" name="search_str" size="60"' + . ' value="' . $searched . '" /></td>'; + $html_output .= '</tr>'; + // choices for types of search + $html_output .= '<tr>'; + $html_output .= '<td class="right vtop">' . __('Find:') . '</td>'; + $html_output .= '<td>'; + $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( + 'search_option', $choices, $search_option, true, false + ); + $html_output .= '</td></tr>'; + // displays table names as select options + $html_output .= '<tr>'; + $html_output .= '<td class="right vtop">' . __('Inside tables:') . '</td>'; + $html_output .= '<td rowspan="2">'; + $html_output .= '<select name="table_select[]" size="6" multiple="multiple">'; + foreach ($tables_names_only as $each_table) { + if (in_array($each_table, $tables_selected)) { + $is_selected = ' selected="selected"'; + } else { + $is_selected = ''; + } + $html_output .= '<option value="' . htmlspecialchars($each_table) . '"' + . $is_selected . '>' + . str_replace(' ', ' ', htmlspecialchars($each_table)) + . '</option>'; + } // end for + $html_output .= '</select>'; + $alter_select + = '<a href="db_search.php' . PMA_generate_common_url(array_merge($url_params, array('selectall' => 1))) . '#db_search"' + . ' onclick="setSelectOptions(\'db_search\', \'table_select[]\', true); return false;">' . __('Select All') . '</a>' + . ' / ' + . '<a href="db_search.php' . PMA_generate_common_url(array_merge($url_params, array('unselectall' => 1))) . '#db_search"' + . ' onclick="setSelectOptions(\'db_search\', \'table_select[]\', false); return false;">' . __('Unselect All') . '</a>'; + $html_output .= '</td></tr>'; + $html_output .= '<tr><td class="right vbottom">' . $alter_select . '</td></tr>'; + $html_output .= '<tr>'; + $html_output .= '<td class="right">' . __('Inside column:') . '</td>'; + $html_output .= '<td><input type="text" name="field_str" size="60"' + . 'value="' . (! empty($field_str) ? htmlspecialchars($field_str) : '') + . '" /></td>'; + $html_output .= '</tr>'; + $html_output .= '</table>'; + $html_output .= '</fieldset>'; + $html_output .= '<fieldset class="tblFooters">'; + $html_output .= '<input type="submit" name="submit_search" value="' + . __('Go') . '" id="buttonGo" />'; + $html_output .= '</fieldset>'; + $html_output .= '</form>'; + $html_output .= getResultDivs(); + + return $html_output; +} - echo ' <option value="' . htmlspecialchars($each_table) . '"' - . $is_selected . '>' - . str_replace(' ', ' ', htmlspecialchars($each_table)) . '</option>' . "\n"; -} // end while - -echo ' </select>' . "\n"; -$alter_select - = '<a href="db_search.php' . PMA_generate_common_url(array_merge($url_params, array('selectall' => 1))) . '#db_search"' - . ' onclick="setSelectOptions(\'db_search\', \'table_select[]\', true); return false;">' . __('Select All') . '</a>' - . ' / ' - . '<a href="db_search.php' . PMA_generate_common_url(array_merge($url_params, array('unselectall' => 1))) . '#db_search"' - . ' onclick="setSelectOptions(\'db_search\', \'table_select[]\', false); return false;">' . __('Unselect All') . '</a>'; -?> - </td> - </tr> - <tr><td class="right vbottom"> - <?php echo $alter_select; ?></td> - </tr> - <tr><td class="right"> - <?php echo __('Inside column:'); ?></td> - <td><input type="text" name="field_str" size="60" - value="<?php echo ! empty($field_str) ? htmlspecialchars($field_str) : ''; ?>" /></td> - </tr> - </table> -</fieldset> -<fieldset class="tblFooters"> - <input type="submit" name="submit_search" value="<?php echo __('Go'); ?>" - id="buttonGo" /> -</fieldset> -</form> - -<!-- These two table-image and table-link elements display the table name in browse search results --> -<div id='table-info'> -<a class="item" id="table-link" ></a> -</div> -<div id="browse-results"> -<!-- this browse-results div is used to load the browse and delete results in the db search --> -</div> -<br class="clearfloat" /> -<div id="sqlqueryform"> -<!-- this sqlqueryform div is used to load the delete form in the db search --> -</div> -<!-- toggle query box link--> -<a id="togglequerybox"></a> +/** + * Provides div tags for browsing search results and sql query form. + * + * @return string div tags + */ +function getResultDivs() +{ + $html_output = '<!-- These two table-image and table-link elements display' + . ' the table name in browse search results -->'; + $html_output .= '<div id="table-info">'; + $html_output .= '<a class="item" id="table-link" ></a>'; + $html_output .= '</div>'; + // div for browsing results + $html_output .= '<div id="browse-results">'; + $html_output .= '<!-- this browse-results div is used to load the browse and delete' + . ' results in the db search -->'; + $html_output .= '</div>'; + $html_output .= '<br class="clearfloat" />'; + $html_output .= '<div id="sqlqueryform">'; + $html_output .= '<!-- this sqlqueryform div is used to load the delete form in' + . ' the db search -->'; + $html_output .= '</div>'; + $html_output .= '<!-- toggle query box link-->'; + $html_output .= '<a id="togglequerybox"></a>'; + return $html_output; +} +$response->addHTML( + PMA_dbSearchGetSelectionForm( + $searched, $search_option, $tables_names_only, $tables_selected, $url_params, + (! empty($field_str) ? $field_str : '') + ) +); +?> |