Skip to content

Commit

Permalink
feat: 新增管理员管理AI模块
Browse files Browse the repository at this point in the history
  • Loading branch information
daizeyao committed Dec 16, 2024
1 parent 0079e9a commit 78a45e2
Show file tree
Hide file tree
Showing 12 changed files with 199 additions and 206 deletions.
21 changes: 11 additions & 10 deletions scripts/db.sql
Original file line number Diff line number Diff line change
Expand Up @@ -218,26 +218,27 @@ LOCK TABLES `custominput` WRITE;
UNLOCK TABLES;

--
-- Table structure for table `dailydetails`
-- Table structure for table `more_settings`
--

DROP TABLE IF EXISTS `dailydetails`;
DROP TABLE IF EXISTS `more_settings`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8mb4 */;
CREATE TABLE `dailydetails` (
CREATE TABLE `more_settings` (
`start_time` date NOT NULL,
`end_time` date NOT NULL
`end_time` date NOT NULL,
`ai_model` tinyint(1) NOT NULL DEFAULT '0'
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `dailydetails`
-- Dumping data for table `more_settings`
--

LOCK TABLES `dailydetails` WRITE;
/*!40000 ALTER TABLE `dailydetails` DISABLE KEYS */;
INSERT INTO `dailydetails` VALUES ('2023-09-01','2024-02-01');
/*!40000 ALTER TABLE `dailydetails` ENABLE KEYS */;
LOCK TABLES `more_settings` WRITE;
/*!40000 ALTER TABLE `more_settings` DISABLE KEYS */;
INSERT INTO `more_settings` VALUES ('2023-09-01','2024-02-01', 0);
/*!40000 ALTER TABLE `more_settings` ENABLE KEYS */;
UNLOCK TABLES;

--
Expand Down Expand Up @@ -572,7 +573,7 @@ CREATE TABLE `privilege_distribution` (
`watch_solution_video` tinyint(4) DEFAULT NULL,
`manage_gptcode` tinyint(4) DEFAULT NULL,
`manage_tag` tinyint(4) DEFAULT NULL,
`set_dailydetails` tinyint(4) DEFAULT NULL,
`set_more_settings` tinyint(4) DEFAULT NULL,
PRIMARY KEY (`group_name`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 ROW_FORMAT=COMPACT;
/*!40101 SET character_set_client = @saved_cs_client */;
Expand Down
27 changes: 27 additions & 0 deletions scripts/db_change.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
DROP TABLE IF EXISTS `dailydetails`;

--
-- Table structure for table `more_settings`
--

DROP TABLE IF EXISTS `more_settings`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8mb4 */;
CREATE TABLE `more_settings` (
`start_time` date NOT NULL,
`end_time` date NOT NULL,
`ai_model` tinyint(1) NOT NULL DEFAULT '0'
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `more_settings`
--

LOCK TABLES `more_settings` WRITE;
INSERT INTO `more_settings` VALUES ('2023-09-01','2024-02-01', 0);
UNLOCK TABLES;


ALTER TABLE `privilege_distribution`
CHANGE COLUMN `set_dailydetails` `set_more_settings` tinyint(4) DEFAULT NULL;
11 changes: 6 additions & 5 deletions web/OJ/admin/admin-header.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<body>


<?php
<?php
require_once $_SERVER['DOCUMENT_ROOT']."/OJ/include/db_info.inc.php";
global $mysqli;
if (!HAS_PRI('enter_admin_page')) {
Expand Down Expand Up @@ -113,7 +113,7 @@
$html_li .= "<li><a href='/OJ/admin/team_import.php'>Team Import</a></li>";
$html_li .= "<li><a href='/OJ/admin/team_import_bypassword.php'>Team Import(By Password)</a></li>";
}

if($html_li!=""){
echo<<<sss
<li class="dropdown">
Expand Down Expand Up @@ -144,8 +144,6 @@
sss;
}

if(HAS_PRI("set_dailydetails")) echo "<li><a href='/OJ/admin/set_dailydetails.php'>Daily details</a></li>";

$html_li="";
$html_li .= "<li><a href='/OJ/admin/privilege_list.php'>Privilege List</a></li>";
if(HAS_PRI("edit_privilege_group")){
Expand Down Expand Up @@ -182,9 +180,12 @@
</li>
sss;
}
if(HAS_PRI("set_more_settings")) {
echo "<li><a href='/OJ/admin/more_settings.php'>More Settings</a></li>";
}
?>
</ul> <!-- nav navbar-nav -->
</div><!-- collapse navbar-collapse -->
</div>
</nav>
<div class="container-fluid">
<div class="container-fluid">
86 changes: 86 additions & 0 deletions web/OJ/admin/more_settings.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
<?php require("admin-header.php");

if (!HAS_PRI("set_more_settings")) {
echo "Permission denied!";
exit(1);
}
?>

<?php
if (isset($_POST['update_daily_details'])) {
$start_date = $_POST['start_date'];
$end_date = $_POST['end_date'];

if (strtotime($start_date) > strtotime($end_date)) {
echo "时间不合法";
exit(1);
}

$sql = "UPDATE more_settings SET start_time = '$start_date', end_time = '$end_date'";
$mysqli->query($sql);
}
if (isset($_POST['update_ai_module'])) {
$ai_module = isset($_POST['ai_module']) ? 1 : 0;
$sql = "UPDATE more_settings SET ai_model = $ai_module";
$mysqli->query($sql);
}
?>

<?php
$now_year = date("Y");
$display_year_cnt = 7;

$sql = "SELECT * FROM more_settings";
$res = $mysqli->query($sql);
$row = $res->fetch_assoc();

$start_date = date("Y-m-d", strtotime($row['start_time']));
$end_date = date("Y-m-d", strtotime($row['end_time']));
$ai_module = $row['ai_model'];
?>
<style>
.form-group-warp {
margin: 20px;
padding: 20px;
background-color: rgb(223, 223, 223);
}

.am-form-group {
display: flex !important;
flex-direction: row;
align-items: center;
justify-content: center;
gap: 10px;

label {
font-size: 16px;
line-height: 16px;
margin: 0;
}
}
</style>
<div class="form-group-warp">
<form class="am-form am-form-inline" action='more_settings.php' method="POST" style="display: flex; gap: 20px;margin: 0;">
<div class="am-form-group">
<label for="start_date">开始日期:</label>
<input type="date" style="width: 150px;" name="start_date" value="<?php echo $start_date; ?>">
</div>
<div class="am-form-group">
<label for="end_date">结束日期:</label>
<input type="date" style="width: 150px;" name="end_date" value="<?php echo $end_date; ?>">
</div>
<button type="submit" name="update_daily_details" class="am-btn am-btn-primary">更新</button>
</form>
</div>
<div class="form-group-warp">
<form class="am-form am-form-inline" action='more_settings.php' method="POST" style="display: flex; gap: 20px;margin: 0;">
<div class="am-form-group">
<label for="start_date">是否开放AI模块:</label>
<input type="checkbox" name="ai_module" style="width: 16px; height: 16px;" <?php echo $ai_module ? 'checked' : ''; ?>>
</div>
<button type="submit" name="update_ai_module" class="am-btn am-btn-primary">更新</button>
</form>
</div>
<?php
require_once("admin-footer.php")
?>
4 changes: 2 additions & 2 deletions web/OJ/admin/privilege_distribution.php
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@
manage_tag
</li>
<li>
set_dailydetails
set_more_settings
</li>
</ul>
</div><!--well-->
Expand All @@ -253,4 +253,4 @@
?>
<script type="text/javascript">
$('#pri_tag a:first').tab('show'); // Select first tab
</script>
</script>
174 changes: 0 additions & 174 deletions web/OJ/admin/set_dailydetails.php

This file was deleted.

Loading

0 comments on commit 78a45e2

Please sign in to comment.