Skip to content

Commit

Permalink
Remove HTML-PHP mix used for displaying db search form
Browse files Browse the repository at this point in the history
  • Loading branch information
atul516 committed Jun 19, 2012
1 parent 6db3d79 commit 48d9cf9
Showing 1 changed file with 119 additions and 86 deletions.
205 changes: 119 additions & 86 deletions db_search.php
Expand Up @@ -282,92 +282,125 @@ function PMA_getSearchSqls($table, $field, $search_str, $search_option)
}

/**
* 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') . 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
echo PMA_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
) {
$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') . 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 .= '</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(' ', '&nbsp;', 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>'
. '&nbsp;/&nbsp;'
. '<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(' ', '&nbsp;', 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>'
. '&nbsp;/&nbsp;'
. '<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;
}

echo PMA_dbSearchGetSelectionForm(
$searched, $search_option, $tables_names_only, $tables_selected, $url_params,
(! empty($field_str) ? $field_str : '')
);
?>

0 comments on commit 48d9cf9

Please sign in to comment.