diff --git a/web/problemset.php b/web/problemset.php index 9e00d0d..0c1e41d 100644 --- a/web/problemset.php +++ b/web/problemset.php @@ -41,9 +41,18 @@ $postfix = ""; $filter_sql = ""; $limit_sql = ""; $order_by = " order by problem_id "; +$filter_params = array(); +$hardness = 0; +if (isset($_GET['hardness'])) { + $hardness = intval($_GET['hardness']); + if ($hardness < 1 || $hardness > 8) + $hardness = 0; +} if (isset($_GET['search']) && trim($_GET['search']) != "") { $search = "%" . ($_GET['search']) . "%"; $filter_sql = " ( title like ? or source like ?)"; + $filter_params[] = $search; + $filter_params[] = $search; $limit_sql = " LIMIT " . ($page - 1) * $page_cnt . "," . $page_cnt; $postfix = "&search=" . urlencode($_GET['search']); } else if (isset($_GET['list']) && trim($_GET['list'] != "")) { @@ -61,6 +70,11 @@ if (isset($_GET['search']) && trim($_GET['search']) != "") { $filter_sql = " 1"; $limit_sql = " LIMIT " . ($page - 1) * $page_cnt . "," . $page_cnt; } +if ($hardness > 0) { + $filter_sql .= " and hardness=?"; + $filter_params[] = $hardness; + $postfix .= "&hardness=" . $hardness; +} //all submit //all acc @@ -103,10 +117,10 @@ pdo_query("SET sort_buffer_size = 1024*1024"); // Out of sort memory, consider $sql = "SELECT `problem_id`,`title`,`source`,`submit`,`accepted`,defunct FROM problem A WHERE $filter_sql $order_by $limit_sql "; $count_sql = "SELECT count(1) from problem where $filter_sql "; //echo htmlentities( $sql); -if (isset($_GET['search']) && trim($_GET['search']) != "") { - $total = pdo_query($count_sql, $search, $search); +if (count($filter_params) > 0) { + $total = pdo_query($count_sql, ...$filter_params); $cnt = $total[0][0] / $page_cnt; - $result = pdo_query($sql, $search, $search); + $result = pdo_query($sql, ...$filter_params); } else { $total = mysql_query_cache($count_sql); $cnt = $total[0][0] / $page_cnt; diff --git a/web/template/syzoj/problemset.php b/web/template/syzoj/problemset.php index d5fadf9..e669e13 100644 --- a/web/template/syzoj/problemset.php +++ b/web/template/syzoj/problemset.php @@ -6,41 +6,48 @@