Skip to content

Commit

Permalink
little cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
BLumia committed Mar 10, 2017
1 parent b9cbbd3 commit c9f9d0d
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 60 deletions.
70 changes: 23 additions & 47 deletions api/ajax_problemset.php
Expand Up @@ -7,6 +7,7 @@
$ON_ADMIN_PAGE="Yap";
require_once("../include/setting_oj.inc.php");
require_once("../include/common_functions.inc.php");
require_once('../include/user_check_functions.php');

//Prepare
$p=isset($_GET['p']) ? $_GET['p'] : 1;
Expand All @@ -16,6 +17,16 @@
$curTime=strftime("%Y-%m-%d %H:%M",time());
$isProblemManager = isset($_SESSION['administrator']);

$sql=$pdo->prepare("SELECT max(`problem_id`) as upid FROM `problem`");
$sql->execute();
$maxProbID=$sql->fetch(PDO::FETCH_ASSOC);
$maxProbID=intval($maxProbID['upid']);
$minProbID=1000;

$pstart = $minProbID + ($p-1)*$PAGE_ITEMS;
$pend = $pstart + $PAGE_ITEMS;
$pageCnt = ($maxProbID - $minProbID) / $PAGE_ITEMS + 1;

//Challenged Problems
if(isset($_SESSION['user_id'])) {
$sql=$pdo->prepare("SELECT `problem_id` FROM `solution` WHERE `user_id`='{$_SESSION['user_id']}' group by `problem_id`"); //All
Expand All @@ -40,15 +51,22 @@
SELECT `contest_id` FROM `contest` WHERE
(`end_time`>'{$curTime}' OR private=1) AND `defunct`='N'
)";
$common_filter = "`problem_id`>='{$front}' AND `problem_id`<'{$tail}'";
//Keyword
if(isset($_GET['wd']) && trim($_GET['wd'])!="") {
$search = pdo_real_escape_string(urldecode($_GET['wd']), $pdo);
$common_filter = " ( title LIKE '%{$search}%' OR source LIKE '%{$search}%') ";
$totalCount = 1; // all search result in one page
} else {
$common_filter = "`problem_id`>='{$front}' AND `problem_id`<'{$tail}'";
}

if (!$isProblemManager) {
$sql=$pdo->prepare("SELECT * FROM problem WHERE `defunct`='N' AND {$common_filter} AND `problem_id` NOT IN({$any_running_contest})");
$sql=$pdo->prepare("SELECT `problem_id`,`title`,`source`,`submit`,`accepted`,`defunct` FROM `problem` WHERE `defunct`='N' AND {$common_filter} AND `problem_id` NOT IN({$any_running_contest})");
} else {
$sql=$pdo->prepare("select * from problem WHERE {$common_filter}");// limit $front,$PAGE_ITEMS
$sql=$pdo->prepare("SELECT `problem_id`,`title`,`source`,`submit`,`accepted`,`defunct` FROM `problem` WHERE {$common_filter}");// limit $front,$PAGE_ITEMS
}
$sql->execute();
$problemList=$sql->fetchAll(PDO::FETCH_ASSOC);
//$problemCount=count($problemList);

//Which problem is under a running contest
if ($isProblemManager) {
Expand All @@ -60,48 +78,6 @@
}
}

//Finally the output
foreach ($problemList as $row) { //problem list ------------
fire(501, "Not yet avaliable api");
?>
<tr>
<?php
if ($row['submit'] == 0) {
$pctText = "N/A";
$procBarNum = 0;
$pctNum = 0;
} else {
$pctNum = ($row['accepted']/$row['submit'])*100;
$procBarNum = (1-($row['accepted']/$row['submit']))*100;
$pctText = sprintf("%.2f%%",$pctNum);
}
?>
<td>
<?php
if ($row['defunct'] == 'Y') echo "<i class='fa fa-lock'></i>";
if (isset($probIDUCList[$row['problem_id']])) echo "<i class='fa fa-clock-o'></i>";
if (isset($probStatusList[$row['problem_id']])) {
$thisProbState = $probStatusList[$row['problem_id']];
switch($thisProbState) {
case "accepted":
echo "<i style='color: green;' class='fa fa-check'></i>";
break;
default:
echo "<i style='color: yellow;' class='fa fa-dot-circle-o'></i>";
break;
}
}
?>
</td>
<td><?php echo $row['problem_id'];?></td>
<td>
<a href="problem.php?pid=<?php echo $row['problem_id'];?>"><?php echo $row['title'];?></a>
<div class="tr-tag">
<span>搜索</span>
</div>
</td>
<td><div class="progress maxwidth150px"><div class="progress-bar" style="width:<?php echo $procBarNum;?>%;"></div></div></td>
<td><?php echo utf8_substr($row['source'],0,14);?></td>
<td>(<?php echo $row['accepted']." / ".$row['submit'];?>) <?php echo $pctText;?></td>
</tr>
<?php } ?>

13 changes: 2 additions & 11 deletions error_view.php
@@ -1,12 +1,5 @@
<?php session_start(); ?>
<!DOCTYPE html>
<html>
<head>
<?php require_once('./include/common_head.inc.php'); ?>
<title>Error Viewer</title>
</head>

<?php
<?php
session_start();
//Vars
require_once('./include/setting_oj.inc.php');
require_once('./include/common_const.inc.php');
Expand Down Expand Up @@ -60,5 +53,3 @@
//Page Includes
require("./pages/error_view.php");
?>

</html>
1 change: 1 addition & 0 deletions language/english.inc.php
Expand Up @@ -19,6 +19,7 @@
const L_PREV_PAGE= "Previous Page";
const L_NEXT_PAGE= "Next Page";
const L_SRC_VIEW= "View Source";
const L_ERR_VIEW= "Error Details";
/*********** Problem Description ***********/
const L_TITLE = "Title";
const L_DESC = "Description";
Expand Down
1 change: 1 addition & 0 deletions language/schinese.inc.php
Expand Up @@ -19,6 +19,7 @@
const L_PREV_PAGE= "上一页";
const L_NEXT_PAGE= "下一页";
const L_SRC_VIEW= "查看代码";
const L_ERR_VIEW= "错误详情";
/*********** Problem Description ***********/
const L_TITLE = "标题";
const L_DESC = "描述";
Expand Down
10 changes: 8 additions & 2 deletions pages/error_view.php
@@ -1,4 +1,9 @@

<!DOCTYPE html>
<html>
<head>
<?php require_once('./include/common_head.inc.php'); ?>
<title><?php echo L_ERR_VIEW." - {$OJ_NAME}";?></title>
</head>
<body>
<?php require("./pages/components/navbar.php");?>
<div class="container">
Expand Down Expand Up @@ -39,4 +44,5 @@
})
</script>

</body>
</body>
</html>

0 comments on commit c9f9d0d

Please sign in to comment.