feat: add a simple search box on problem set page

Add a search box on problem set page. Only uses a simple algorithm, you can't use it like Google. You can search one or some of the words in the title.

NOTICE: The style of the sarch box may have some problems. when you turn the window into mobile mode, the search box will not be at the center of the page. Hope someone can make it better.
This commit is contained in:
MascoSkray 2017-06-01 10:29:17 +08:00
parent 866d70b5b8
commit e1b17aa3ca
No known key found for this signature in database
GPG Key ID: 6ABABD8325167A2E

View File

@ -56,6 +56,7 @@ EOD;
$cond = array(); $cond = array();
$search_tag = null; $search_tag = null;
$search_word = $_GET["search"];
$cur_tab = isset($_GET['tab']) ? $_GET['tab'] : 'all'; $cur_tab = isset($_GET['tab']) ? $_GET['tab'] : 'all';
if ($cur_tab == 'template') { if ($cur_tab == 'template') {
@ -67,6 +68,9 @@ EOD;
if ($search_tag) { if ($search_tag) {
$cond[] = "'".DB::escape($search_tag)."' in (select tag from problems_tags where problems_tags.problem_id = problems.id)"; $cond[] = "'".DB::escape($search_tag)."' in (select tag from problems_tags where problems_tags.problem_id = problems.id)";
} }
if($search_word) {
$cond[]="title like '%".$search_word."%' or id like '%".$search_word."%'";
}
if ($cond) { if ($cond) {
$cond = join($cond, ' and '); $cond = join($cond, ' and ');
@ -132,8 +136,20 @@ EOD;
<?= HTML::tablist($tabs_info, $cur_tab, 'nav-pills') ?> <?= HTML::tablist($tabs_info, $cur_tab, 'nav-pills') ?>
</div> </div>
<div class="col-sm-4 col-sm-push-4 checkbox text-right"> <div class="col-sm-4 col-sm-push-4 checkbox text-right">
<label class="checkbox-inline" for="input-show_tags_mode"><input type="checkbox" id="input-show_tags_mode" <?= isset($_COOKIE['show_tags_mode']) ? 'checked="checked" ': ''?>/> <?= UOJLocale::get('problems::show tags') ?></label> <label class="checkbox-inline" for="input-show_tags_mode">
<label class="checkbox-inline" for="input-show_submit_mode"><input type="checkbox" id="input-show_submit_mode" <?= isset($_COOKIE['show_submit_mode']) ? 'checked="checked" ': ''?>/> <?= UOJLocale::get('problems::show statistics') ?></label> <input type="checkbox" id="input-show_tags_mode" <?= isset($_COOKIE['show_tags_mode']) ? 'checked="checked" ': ''?>/> <?= UOJLocale::get('problems::show tags') ?>
</label>
<label class="checkbox-inline" for="input-show_submit_mode">
<input type="checkbox" id="input-show_submit_mode" <?= isset($_COOKIE['show_submit_mode']) ? 'checked="checked" ': ''?>/> <?= UOJLocale::get('problems::show statistics') ?>
</label>
</div>
<div class="col-sm-4 col-sm-pull-4 input-group">
<form id="form-search" class="form-inline" method="get">
<span class="input-group-btn">
<input type="text" class="form-control" name="search" placeholder="<?= UOJLocale::get('search')?>" />
<button type="submit" id="submit-search" class="btn btn-info btn-search"><span class="glyphicon glyphicon-search"></span></button>
</span>
</form>
</div> </div>
<div class="col-sm-4 col-sm-pull-4"> <div class="col-sm-4 col-sm-pull-4">
<?php echo $pag->pagination(); ?> <?php echo $pag->pagination(); ?>
@ -168,6 +184,10 @@ $('#input-show_submit_mode').click(function() {
foreach ($pag->get() as $idx => $row) { foreach ($pag->get() as $idx => $row) {
echoProblem($row); echoProblem($row);
echo "\n";
}
if ($pag->isEmpty()) {
echo '<tr><td class="text-center" colspan="233">'.UOJLocale::get('none').'</td></tr>';
} }
echo '</tbody>'; echo '</tbody>';