Skip to content

Commit

Permalink
上线里程碑功能,修复了一些已知bug (hznuoj-dev#13)
Browse files Browse the repository at this point in the history
hznuoj2.7.1
  • Loading branch information
daizeyao committed Mar 25, 2024
1 parent 507e4fe commit 28d9646
Show file tree
Hide file tree
Showing 17 changed files with 1,334 additions and 388 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v0.0.9
v2.7.0
2 changes: 1 addition & 1 deletion scripts/db.sql
Original file line number Diff line number Diff line change
Expand Up @@ -1106,7 +1106,7 @@ CREATE TABLE `users` (

LOCK TABLES `users` WRITE;
/*!40000 ALTER TABLE `users` DISABLE KEYS */;
INSERT INTO `users` VALUES ('admin','','[email protected]',1,1,'N','::1','2019-03-12 16:34:09',1,NULL,1,'d4er+qiVZNXCikHfG0m35WtRNHNkNzRl','2019-03-12 16:34:09','','admin','','其它','斗之气五段',100.00,'#b6b6b6',NULL,NULL,NULL,NULL,NULL,0,0,NULL);
INSERT INTO `users` VALUES ('admin','','[email protected]',1,1,'N','::1','2019-03-12 16:34:09',1,NULL,1,'3h3WmOGmnb9jZpHcKBU3t+VpcJFhYjQx','2019-03-12 16:34:09','','admin','','其它','斗之气五段',100.00,'#b6b6b6',NULL,NULL,NULL,NULL,NULL,0,0,NULL);
/*!40000 ALTER TABLE `users` ENABLE KEYS */;
UNLOCK TABLES;

Expand Down
155 changes: 0 additions & 155 deletions scripts/dbforadd2.2.sql

This file was deleted.

55 changes: 31 additions & 24 deletions web/OJ/admin/problem_edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
require_once("error.php");
exit(0);
}

$sql="SELECT input, output, show_after FROM problem_samples WHERE problem_id='$pid' ORDER BY sample_id";
$res=$mysqli->query($sql);
$samples=array();
Expand Down Expand Up @@ -89,7 +89,7 @@
echo "</oition>";
}
}

?>
</select>
</div>
Expand Down Expand Up @@ -171,7 +171,7 @@
<button id="remove_sample" class="btn btn-danger btn-sm btn-block">Remove the last sample</button>
<button id="add_sample" class="btn btn-primary btn-sm btn-block">Add a sapmple</button>
</div>

</div>
</div>
<div class="form-group">
Expand Down Expand Up @@ -229,7 +229,7 @@
<label for="" class="col-sm-2 control-label">Tag</label>

<div class="col-sm-10">
<button id="showtag" class="btn btn-default btn-sm btn-block">Tag(s)</button>
<button id="showtag" class="btn btn-default btn-sm btn-block">Tag(s) 请从已有tag中选择</button>
<div id="tag" style="padding: 10px; border: 1px solid #ccc; margin-top: 10px;">
<div id="tag_list" style="margin-bottom: 10px;">
<ul class="tag-items">
Expand Down Expand Up @@ -260,10 +260,10 @@
<button class="btn btn-primary btn-sm btn-block" id="add-tag" style="margin-top: 10px;">添加</button>
</div>
</div>
</div>

</div>




<hr/>
<div class="form-group">
<label for="" class="col-sm-2 control-label">Author</label>
Expand Down Expand Up @@ -374,35 +374,35 @@
$path=$OJ_DATA."/$id/sample".$i.".in";
if(file_exists($path)) $success=unlink($path);
//echo "<pre>remove $path:$success</pre>";

$path=$OJ_DATA."/$id/sample".$i.".out";
if(file_exists($path)) $success=unlink($path);
//echo "<pre>remove $path:$success</pre>";
}
if(isset($_POST['add_problem_mod'])){
$id=addproblem($problemset, $title, $time_limit, $memory_limit, $description, $input, $output, $hint, $author, $source, $spj, $OJ_DATA );
mkdir($OJ_DATA."/$id");
}
}
$sql="DELETE FROM problem_samples WHERE problem_id=$id";
$mysqli->query($sql);
if($sample_inputs){
foreach ($sample_inputs as $key => $sample_input) {
$sample_input=preg_replace("/(\r\n)/","\n",$sample_input);
$sample_output=preg_replace("/(\r\n)/","\n",$sample_outputs[$key]);
if($sample_input=="" && $sample_output=="")continue;

//don't auto generate sample files if is SPJ
if(!$spj) {
$fp=fopen($OJ_DATA."/$id/sample".$key.".in","w");
fputs($fp,$sample_input);
fclose($fp);
//echo "<pre>create: ".$OJ_DATA."/$id/sample".$key.".in"."</pre>";

$fp=fopen($OJ_DATA."/$id/sample".$key.".out","w");
fputs($fp,preg_replace("/(\r\n)/","\n",$sample_output));
fclose($fp);
}

$sample_input=$mysqli->real_escape_string($sample_input);
$sample_output=$mysqli->real_escape_string($sample_output);
$sql=<<<SQL
Expand Down Expand Up @@ -440,13 +440,20 @@
$stmt->execute();
$stmt->close();

// 添加新的标签
$stmt = $mysqli->prepare("INSERT INTO problem_tag (problem_id, tag) VALUES (?, ?)");
// 添加新的标签,不属于已有tag的不添加
$stmt_check = $mysqli->prepare("SELECT * FROM all_problem_tag WHERE tag = ?");
$stmt_insert = $mysqli->prepare("INSERT INTO problem_tag (problem_id, tag) VALUES (?, ?)");

foreach ($tags as $tag) {
$stmt->bind_param('is', $id, $tag);
$stmt->execute();
}
$stmt_check->bind_param('s', $tag);
$stmt_check->execute();
$result = $stmt_check->get_result();

if ($result->num_rows > 0) {
$stmt_insert->bind_param('is', $id, $tag);
$stmt_insert->execute();
}
}

if(isset($_POST['add_problem_mod'])){
$_SESSION["p$id"]=true;
Expand Down Expand Up @@ -524,17 +531,17 @@
$('#add-tag').click(function(e) {
e.preventDefault();
var tag = $('#id_staff-display').val();

// 检查标签是否已经存在
var exists = $('#tag_list .tag-item span').filter(function() {
return $(this).text() === tag;
}).length > 0;
if (!exists) {
$('#tag_list .tag-items').append('<li class="tag-item"><span>' + tag + '</span><i class="tag-item-del">x</i></li>');
updateTagsInput();

if (!exists && tag != "") {
$('#tag_list .tag-items').append('<li class="tag-item"><span>' + tag + '</span><i class="tag-item-del">x</i></li>');
updateTagsInput();
}

$('#id_staff-display').val('');
});

Expand All @@ -551,7 +558,7 @@ function updateTagsInput() {
}).get().join(',');
$('#id_tags').val(tags);
}

updateTagsInput();
});
</script>
Expand Down
29 changes: 20 additions & 9 deletions web/OJ/admin/tag_del.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,29 @@
if (isset($_POST['deltag'])) {
$tag = $_POST['deltag'];

// 删除标签
$stmt = $mysqli->prepare("DELETE FROM all_problem_tag WHERE tag = ?");
$stmt->bind_param('s', $tag);
$stmt->execute();
try {
// 从all_problem_tag删除标签
$stmt = $mysqli->prepare("DELETE FROM all_problem_tag WHERE tag = ?");
$stmt->bind_param('s', $tag);
$stmt->execute();

if ($stmt->affected_rows > 0) {
echo 'Tag deleted successfully';
} else {
echo 'No tag found';
// 从problem_tag删除相应的记录
$stmt = $mysqli->prepare("DELETE FROM problem_tag WHERE tag = ?");
$stmt->bind_param('s', $tag);
$stmt->execute();

// 如果没有抛出异常,提交事务
$mysqli->commit();

echo '成功删除标签和相应的记录';
} catch (Exception $e) {
// 抛出了异常
// 我们必须回滚事务
$mysqli->rollback();

echo '删除标签和相应记录时出错: ', $e->getMessage();
}

$stmt->close();
$mysqli->close();
}
?>
9 changes: 7 additions & 2 deletions web/OJ/admin/tag_manage.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,18 @@
// require_once("../include/check_post_key.php");
$tag = $_POST['addtag'];

if ($tag == "") {
echo ("Tag empty!");
exit(1);
}

$stmt = $mysqli->prepare("SELECT * FROM all_problem_tag WHERE tag = ?");
$stmt->bind_param('s', $tag);
$stmt->execute();
$result = $stmt->get_result();

if ($result->num_rows > 0) {
echo ("Tag exists");
echo ("Tag exists!");
exit(1);
} else {
$stmt = $mysqli->prepare("INSERT INTO all_problem_tag (tag) VALUES (?)");
Expand Down Expand Up @@ -122,4 +127,4 @@ function deleteTagFromDatabase(tagName) {

<?php
require_once("admin-footer.php")
?>
?>
Loading

0 comments on commit 28d9646

Please sign in to comment.