mirror of
https://github.com/renbaoshuo/S2OJ.git
synced 2024-11-25 21:58:41 +00:00
refactor: sync code from uoj.ac (#14)
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
commit
61aebec03e
16
.github/workflows/test.yml
vendored
16
.github/workflows/test.yml
vendored
@ -1,16 +0,0 @@
|
||||
name: Lint & Test
|
||||
|
||||
on:
|
||||
- push
|
||||
- pull_request
|
||||
|
||||
jobs:
|
||||
php-cs-fixer:
|
||||
name: PHP-CS-Fixer
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: PHP-CS-Fixer
|
||||
uses: docker://oskarstark/php-cs-fixer-ga
|
||||
with:
|
||||
args: --config=./web/.php-cs-fixer.php --diff --dry-run
|
16
.vscode/c_cpp_properties.json
vendored
Normal file
16
.vscode/c_cpp_properties.json
vendored
Normal file
@ -0,0 +1,16 @@
|
||||
{
|
||||
"configurations": [
|
||||
{
|
||||
"name": "Linux",
|
||||
"includePath": [
|
||||
"${workspaceFolder}/**"
|
||||
],
|
||||
"defines": [],
|
||||
"compilerPath": "/usr/bin/gcc",
|
||||
"cStandard": "c17",
|
||||
"cppStandard": "c++17",
|
||||
"intelliSenseMode": "linux-gcc-x64"
|
||||
}
|
||||
],
|
||||
"version": 4
|
||||
}
|
4
.vscode/settings.json
vendored
Normal file
4
.vscode/settings.json
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
{
|
||||
"intelephense.format.braces": "k&r",
|
||||
"intelephense.completion.triggerParameterHints": false
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
FROM mysql:5.7
|
||||
FROM mysql:8.0
|
||||
|
||||
ADD . /opt/uoj_db
|
||||
WORKDIR /opt/uoj_db
|
||||
|
@ -1,2 +1,2 @@
|
||||
USE `app_uoj233`;
|
||||
insert into judger_info (judger_name, password, ip) values ('compose_judger', '_judger_password_', 'uoj-judger');
|
||||
insert into judger_info (judger_name, password, ip, display_name, description) values ('compose_judger', '_judger_password_', 'uoj-judger', '内建 Judger', '');
|
||||
|
@ -30,18 +30,18 @@ USE `app_uoj233`;
|
||||
/*!40101 SET @saved_cs_client = @@character_set_client */;
|
||||
/*!40101 SET character_set_client = utf8mb4 */;
|
||||
CREATE TABLE `best_ac_submissions` (
|
||||
`problem_id` int(11) NOT NULL,
|
||||
`problem_id` int NOT NULL,
|
||||
`submitter` varchar(20) COLLATE utf8mb4_unicode_ci NOT NULL,
|
||||
`submission_id` int(11) NOT NULL,
|
||||
`used_time` int(11) NOT NULL,
|
||||
`used_memory` int(11) NOT NULL,
|
||||
`tot_size` int(11) NOT NULL,
|
||||
`shortest_id` int(11) NOT NULL,
|
||||
`shortest_used_time` int(11) NOT NULL,
|
||||
`shortest_used_memory` int(11) NOT NULL,
|
||||
`shortest_tot_size` int(11) NOT NULL,
|
||||
`submission_id` int NOT NULL,
|
||||
`used_time` int NOT NULL,
|
||||
`used_memory` int NOT NULL,
|
||||
`tot_size` int NOT NULL,
|
||||
`shortest_id` int NOT NULL,
|
||||
`shortest_used_time` int NOT NULL,
|
||||
`shortest_used_memory` int NOT NULL,
|
||||
`shortest_tot_size` int NOT NULL,
|
||||
PRIMARY KEY (`problem_id`,`submitter`)
|
||||
) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci TABLESPACE `innodb_system`;
|
||||
/*!40101 SET character_set_client = @saved_cs_client */;
|
||||
|
||||
--
|
||||
@ -60,16 +60,20 @@ UNLOCK TABLES;
|
||||
/*!40101 SET @saved_cs_client = @@character_set_client */;
|
||||
/*!40101 SET character_set_client = utf8mb4 */;
|
||||
CREATE TABLE `blogs` (
|
||||
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`id` int NOT NULL AUTO_INCREMENT,
|
||||
`title` text COLLATE utf8mb4_unicode_ci NOT NULL,
|
||||
`content` mediumtext COLLATE utf8mb4_unicode_ci NOT NULL,
|
||||
`content` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
|
||||
`post_time` datetime NOT NULL,
|
||||
`active_time` datetime NOT NULL,
|
||||
`poster` varchar(20) COLLATE utf8mb4_unicode_ci NOT NULL,
|
||||
`content_md` mediumtext COLLATE utf8mb4_unicode_ci NOT NULL,
|
||||
`zan` int(11) NOT NULL,
|
||||
`content_md` longtext COLLATE utf8mb4_unicode_ci NOT NULL,
|
||||
`zan` int NOT NULL DEFAULT '0',
|
||||
`is_hidden` tinyint(1) NOT NULL,
|
||||
`type` char(1) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'B',
|
||||
PRIMARY KEY (`id`)
|
||||
PRIMARY KEY (`id`),
|
||||
KEY `post_time` (`post_time`),
|
||||
KEY `active_time` (`active_time`),
|
||||
KEY `poster` (`poster`,`is_hidden`)
|
||||
) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||
/*!40101 SET character_set_client = @saved_cs_client */;
|
||||
|
||||
@ -89,14 +93,19 @@ UNLOCK TABLES;
|
||||
/*!40101 SET @saved_cs_client = @@character_set_client */;
|
||||
/*!40101 SET character_set_client = utf8mb4 */;
|
||||
CREATE TABLE `blogs_comments` (
|
||||
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`blog_id` int(11) NOT NULL,
|
||||
`id` int NOT NULL AUTO_INCREMENT,
|
||||
`blog_id` int NOT NULL,
|
||||
`content` text COLLATE utf8mb4_unicode_ci NOT NULL,
|
||||
`post_time` datetime NOT NULL,
|
||||
`poster` varchar(20) COLLATE utf8mb4_unicode_ci NOT NULL,
|
||||
`zan` int(11) NOT NULL,
|
||||
`reply_id` int(11) NOT NULL,
|
||||
PRIMARY KEY (`id`)
|
||||
`zan` int NOT NULL,
|
||||
`reply_id` int NOT NULL,
|
||||
`is_hidden` tinyint(1) NOT NULL DEFAULT '0',
|
||||
`reason_to_hide` varchar(10000) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '',
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `reply_id` (`reply_id`,`id`),
|
||||
KEY `blog_id` (`blog_id`,`post_time`),
|
||||
KEY `blog_id_2` (`blog_id`,`reply_id`)
|
||||
) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||
/*!40101 SET character_set_client = @saved_cs_client */;
|
||||
|
||||
@ -116,8 +125,8 @@ UNLOCK TABLES;
|
||||
/*!40101 SET @saved_cs_client = @@character_set_client */;
|
||||
/*!40101 SET character_set_client = utf8mb4 */;
|
||||
CREATE TABLE `blogs_tags` (
|
||||
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`blog_id` int(11) NOT NULL,
|
||||
`id` int NOT NULL AUTO_INCREMENT,
|
||||
`blog_id` int NOT NULL,
|
||||
`tag` varchar(30) NOT NULL,
|
||||
PRIMARY KEY (`id`),
|
||||
KEY `blog_id` (`blog_id`),
|
||||
@ -143,8 +152,8 @@ UNLOCK TABLES;
|
||||
CREATE TABLE `click_zans` (
|
||||
`type` char(2) COLLATE utf8mb4_unicode_ci NOT NULL,
|
||||
`username` varchar(20) COLLATE utf8mb4_unicode_ci NOT NULL,
|
||||
`target_id` int(11) NOT NULL,
|
||||
`val` tinyint(4) NOT NULL DEFAULT '1',
|
||||
`target_id` int NOT NULL,
|
||||
`val` tinyint NOT NULL DEFAULT '1',
|
||||
PRIMARY KEY (`type`,`target_id`,`username`)
|
||||
) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||
/*!40101 SET character_set_client = @saved_cs_client */;
|
||||
@ -165,15 +174,17 @@ UNLOCK TABLES;
|
||||
/*!40101 SET @saved_cs_client = @@character_set_client */;
|
||||
/*!40101 SET character_set_client = utf8mb4 */;
|
||||
CREATE TABLE `contests` (
|
||||
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`name` varchar(50) NOT NULL,
|
||||
`id` int NOT NULL AUTO_INCREMENT,
|
||||
`name` varchar(50) COLLATE utf8mb4_unicode_ci NOT NULL,
|
||||
`start_time` datetime NOT NULL,
|
||||
`last_min` int(11) NOT NULL,
|
||||
`player_num` int(11) NOT NULL,
|
||||
`status` varchar(50) NOT NULL,
|
||||
`extra_config` varchar(200) NOT NULL,
|
||||
`zan` int(11) NOT NULL,
|
||||
PRIMARY KEY (`id`)
|
||||
`end_time` datetime GENERATED ALWAYS AS ((`start_time` + interval `last_min` minute)) VIRTUAL NOT NULL,
|
||||
`last_min` int NOT NULL,
|
||||
`player_num` int NOT NULL DEFAULT '0',
|
||||
`status` varchar(50) COLLATE utf8mb4_unicode_ci NOT NULL,
|
||||
`extra_config` varchar(1000) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '{}',
|
||||
`zan` int NOT NULL DEFAULT '0',
|
||||
PRIMARY KEY (`id`),
|
||||
KEY `status` (`status`,`id`) USING BTREE
|
||||
) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4;
|
||||
/*!40101 SET character_set_client = @saved_cs_client */;
|
||||
|
||||
@ -193,15 +204,17 @@ UNLOCK TABLES;
|
||||
/*!40101 SET @saved_cs_client = @@character_set_client */;
|
||||
/*!40101 SET character_set_client = utf8mb4 */;
|
||||
CREATE TABLE `contests_asks` (
|
||||
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`contest_id` int(11) NOT NULL,
|
||||
`id` int NOT NULL AUTO_INCREMENT,
|
||||
`contest_id` int NOT NULL,
|
||||
`username` varchar(20) COLLATE utf8mb4_unicode_ci NOT NULL,
|
||||
`question` text NOT NULL,
|
||||
`answer` text NOT NULL,
|
||||
`post_time` datetime NOT NULL,
|
||||
`reply_time` datetime NOT NULL,
|
||||
`is_hidden` tinyint(1) DEFAULT '0',
|
||||
PRIMARY KEY (`id`)
|
||||
PRIMARY KEY (`id`),
|
||||
KEY `contest_id` (`contest_id`,`is_hidden`,`username`) USING BTREE,
|
||||
KEY `username` (`username`,`contest_id`) USING BTREE
|
||||
) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4;
|
||||
/*!40101 SET character_set_client = @saved_cs_client */;
|
||||
|
||||
@ -221,7 +234,7 @@ UNLOCK TABLES;
|
||||
/*!40101 SET @saved_cs_client = @@character_set_client */;
|
||||
/*!40101 SET character_set_client = utf8mb4 */;
|
||||
CREATE TABLE `contests_notice` (
|
||||
`contest_id` int(11) NOT NULL,
|
||||
`contest_id` int NOT NULL,
|
||||
`title` varchar(30) NOT NULL,
|
||||
`content` varchar(500) NOT NULL,
|
||||
`time` datetime NOT NULL,
|
||||
@ -246,7 +259,7 @@ UNLOCK TABLES;
|
||||
/*!40101 SET character_set_client = utf8mb4 */;
|
||||
CREATE TABLE `contests_permissions` (
|
||||
`username` varchar(20) COLLATE utf8mb4_unicode_ci NOT NULL,
|
||||
`contest_id` int(11) NOT NULL,
|
||||
`contest_id` int NOT NULL,
|
||||
PRIMARY KEY (`username`,`contest_id`)
|
||||
) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4;
|
||||
/*!40101 SET character_set_client = @saved_cs_client */;
|
||||
@ -267,10 +280,11 @@ UNLOCK TABLES;
|
||||
/*!40101 SET @saved_cs_client = @@character_set_client */;
|
||||
/*!40101 SET character_set_client = utf8mb4 */;
|
||||
CREATE TABLE `contests_problems` (
|
||||
`problem_id` int(11) NOT NULL,
|
||||
`contest_id` int(11) NOT NULL,
|
||||
`dfn` int(11) NOT NULL DEFAULT 0,
|
||||
PRIMARY KEY (`problem_id`,`contest_id`)
|
||||
`problem_id` int NOT NULL,
|
||||
`contest_id` int NOT NULL,
|
||||
`level` int NOT NULL DEFAULT 0,
|
||||
PRIMARY KEY (`problem_id`,`contest_id`),
|
||||
KEY `contest_id` (`contest_id`,`problem_id`)
|
||||
) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4;
|
||||
/*!40101 SET character_set_client = @saved_cs_client */;
|
||||
|
||||
@ -291,9 +305,9 @@ UNLOCK TABLES;
|
||||
/*!40101 SET character_set_client = utf8mb4 */;
|
||||
CREATE TABLE `contests_registrants` (
|
||||
`username` varchar(20) COLLATE utf8mb4_unicode_ci NOT NULL,
|
||||
`contest_id` int(11) NOT NULL,
|
||||
`contest_id` int NOT NULL,
|
||||
`has_participated` tinyint(1) NOT NULL,
|
||||
`rank` int(11) NOT NULL,
|
||||
`final_rank` int NOT NULL,
|
||||
PRIMARY KEY (`contest_id`,`username`)
|
||||
) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4;
|
||||
/*!40101 SET character_set_client = @saved_cs_client */;
|
||||
@ -314,12 +328,14 @@ UNLOCK TABLES;
|
||||
/*!40101 SET @saved_cs_client = @@character_set_client */;
|
||||
/*!40101 SET character_set_client = utf8mb4 */;
|
||||
CREATE TABLE `contests_submissions` (
|
||||
`contest_id` int(11) NOT NULL,
|
||||
`contest_id` int NOT NULL,
|
||||
`submitter` varchar(20) NOT NULL,
|
||||
`problem_id` int(11) NOT NULL,
|
||||
`submission_id` int(11) NOT NULL,
|
||||
`score` int(11) NOT NULL,
|
||||
`penalty` int(11) NOT NULL,
|
||||
`problem_id` int NOT NULL,
|
||||
`submission_id` int NOT NULL,
|
||||
`score` int NOT NULL,
|
||||
`penalty` int NOT NULL,
|
||||
`cnt` int DEFAULT NULL,
|
||||
`n_failures` int DEFAULT NULL,
|
||||
PRIMARY KEY (`contest_id`,`submitter`,`problem_id`)
|
||||
) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4;
|
||||
/*!40101 SET character_set_client = @saved_cs_client */;
|
||||
@ -340,11 +356,13 @@ UNLOCK TABLES;
|
||||
/*!40101 SET @saved_cs_client = @@character_set_client */;
|
||||
/*!40101 SET character_set_client = utf8mb4 */;
|
||||
CREATE TABLE `contests_reviews` (
|
||||
`contest_id` int(11) NOT NULL,
|
||||
`problem_id` int(11) NOT NULL DEFAULT 0,
|
||||
`contest_id` int NOT NULL,
|
||||
`problem_id` int NOT NULL DEFAULT 0,
|
||||
`poster` varchar(20) NOT NULL,
|
||||
`content` text NOT NULL,
|
||||
PRIMARY KEY (`contest_id`,`problem_id`,`poster`)
|
||||
PRIMARY KEY (`contest_id`,`problem_id`,`poster`),
|
||||
KEY `contest_id` (`contest_id`,`problem_id`),
|
||||
KEY `poster` (`poster`)
|
||||
) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4;
|
||||
/*!40101 SET character_set_client = @saved_cs_client */;
|
||||
|
||||
@ -364,7 +382,7 @@ UNLOCK TABLES;
|
||||
/*!40101 SET @saved_cs_client = @@character_set_client */;
|
||||
/*!40101 SET character_set_client = utf8mb4 */;
|
||||
CREATE TABLE `countdowns` (
|
||||
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
|
||||
`id` int UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
`title` text NOT NULL,
|
||||
`end_time` datetime NOT NULL,
|
||||
PRIMARY KEY (`id`)
|
||||
@ -387,8 +405,8 @@ UNLOCK TABLES;
|
||||
/*!40101 SET @saved_cs_client = @@character_set_client */;
|
||||
/*!40101 SET character_set_client = utf8mb4 */;
|
||||
CREATE TABLE `custom_test_submissions` (
|
||||
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
|
||||
`problem_id` int(10) unsigned NOT NULL,
|
||||
`id` int UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
`problem_id` int UNSIGNED NOT NULL,
|
||||
`submit_time` datetime NOT NULL,
|
||||
`submitter` varchar(20) NOT NULL,
|
||||
`content` text NOT NULL,
|
||||
@ -396,8 +414,10 @@ CREATE TABLE `custom_test_submissions` (
|
||||
`result` blob NOT NULL,
|
||||
`status` varchar(20) NOT NULL,
|
||||
`status_details` varchar(100) NOT NULL,
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4;
|
||||
PRIMARY KEY (`id`),
|
||||
KEY `submitter` (`submitter`,`problem_id`,`id`),
|
||||
KEY `judge_time` (`judge_time`,`id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||
/*!40101 SET character_set_client = @saved_cs_client */;
|
||||
|
||||
--
|
||||
@ -416,10 +436,10 @@ UNLOCK TABLES;
|
||||
/*!40101 SET @saved_cs_client = @@character_set_client */;
|
||||
/*!40101 SET character_set_client = utf8mb4 */;
|
||||
CREATE TABLE `friend_links` (
|
||||
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
|
||||
`id` int unsigned NOT NULL AUTO_INCREMENT,
|
||||
`title` varchar(40) NOT NULL,
|
||||
`url` varchar(100) NOT NULL,
|
||||
`level` int(10) NOT NULL DEFAULT 10,
|
||||
`level` int NOT NULL DEFAULT 10,
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4;
|
||||
/*!40101 SET character_set_client = @saved_cs_client */;
|
||||
@ -440,7 +460,7 @@ UNLOCK TABLES;
|
||||
/*!40101 SET @saved_cs_client = @@character_set_client */;
|
||||
/*!40101 SET character_set_client = utf8mb4 */;
|
||||
CREATE TABLE `groups` (
|
||||
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`id` int NOT NULL AUTO_INCREMENT,
|
||||
`title` text NOT NULL,
|
||||
`announcement` text NOT NULL DEFAULT '',
|
||||
`is_hidden` tinyint(1) NOT NULL DEFAULT 0,
|
||||
@ -455,10 +475,11 @@ CREATE TABLE `groups` (
|
||||
/*!40101 SET @saved_cs_client = @@character_set_client */;
|
||||
/*!40101 SET character_set_client = utf8mb4 */;
|
||||
CREATE TABLE `groups_assignments` (
|
||||
`group_id` int(11) NOT NULL,
|
||||
`list_id` int(11) NOT NULL,
|
||||
`group_id` int NOT NULL,
|
||||
`list_id` int NOT NULL,
|
||||
`end_time` datetime NOT NULL,
|
||||
PRIMARY KEY (`group_id`, `list_id`)
|
||||
PRIMARY KEY (`group_id`, `list_id`),
|
||||
KEY `list_id` (`list_id`,`group_id`)
|
||||
) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4;
|
||||
/*!40101 SET character_set_client = @saved_cs_client */;
|
||||
|
||||
@ -469,9 +490,11 @@ CREATE TABLE `groups_assignments` (
|
||||
/*!40101 SET @saved_cs_client = @@character_set_client */;
|
||||
/*!40101 SET character_set_client = utf8mb4 */;
|
||||
CREATE TABLE `groups_users` (
|
||||
`group_id` int(11) NOT NULL,
|
||||
`group_id` int NOT NULL,
|
||||
`username` varchar(20) COLLATE utf8mb4_unicode_ci NOT NULL,
|
||||
PRIMARY KEY (`group_id`, `username`)
|
||||
PRIMARY KEY (`group_id`, `username`),
|
||||
KEY `group_id` (`group_id`, `username`),
|
||||
KEY `username` (`username`, `group_id`)
|
||||
) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4;
|
||||
/*!40101 SET character_set_client = @saved_cs_client */;
|
||||
|
||||
@ -482,23 +505,26 @@ CREATE TABLE `groups_users` (
|
||||
/*!40101 SET @saved_cs_client = @@character_set_client */;
|
||||
/*!40101 SET character_set_client = utf8mb4 */;
|
||||
CREATE TABLE `hacks` (
|
||||
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
|
||||
`problem_id` int(10) unsigned NOT NULL,
|
||||
`contest_id` int(10) unsigned DEFAULT NULL,
|
||||
`submission_id` int(10) unsigned NOT NULL,
|
||||
`hacker` varchar(20) NOT NULL,
|
||||
`owner` varchar(20) NOT NULL,
|
||||
`input` varchar(150) NOT NULL,
|
||||
`input_type` char(20) NOT NULL,
|
||||
`id` int UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
`problem_id` int UNSIGNED NOT NULL,
|
||||
`contest_id` int UNSIGNED DEFAULT NULL,
|
||||
`submission_id` int UNSIGNED NOT NULL,
|
||||
`hacker` varchar(20) COLLATE utf8mb4_unicode_ci NOT NULL,
|
||||
`owner` varchar(20) COLLATE utf8mb4_unicode_ci NOT NULL,
|
||||
`input` varchar(150) COLLATE utf8mb4_unicode_ci NOT NULL,
|
||||
`input_type` char(20) COLLATE utf8mb4_unicode_ci NOT NULL,
|
||||
`submit_time` datetime NOT NULL,
|
||||
`judge_time` datetime DEFAULT NULL,
|
||||
`success` tinyint(1) DEFAULT NULL,
|
||||
`status` varchar(20) COLLATE utf8mb4_unicode_ci NOT NULL,
|
||||
`details` blob NOT NULL,
|
||||
`is_hidden` tinyint(1) NOT NULL,
|
||||
PRIMARY KEY (`id`),
|
||||
KEY `submission_id` (`submission_id`),
|
||||
KEY `is_hidden` (`is_hidden`,`problem_id`)
|
||||
) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4;
|
||||
KEY `is_hidden` (`is_hidden`,`problem_id`),
|
||||
KEY `status` (`status`),
|
||||
KEY `judge_time` (`judge_time`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||
/*!40101 SET character_set_client = @saved_cs_client */;
|
||||
|
||||
--
|
||||
@ -539,11 +565,14 @@ UNLOCK TABLES;
|
||||
/*!40101 SET @saved_cs_client = @@character_set_client */;
|
||||
/*!40101 SET character_set_client = utf8mb4 */;
|
||||
CREATE TABLE `judger_info` (
|
||||
`judger_name` varchar(50) NOT NULL,
|
||||
`password` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL,
|
||||
`ip` char(20) NOT NULL,
|
||||
`judger_name` varchar(50) COLLATE utf8mb4_unicode_ci NOT NULL,
|
||||
`password` varchar(50) COLLATE utf8mb4_unicode_ci NOT NULL,
|
||||
`ip` char(20) COLLATE utf8mb4_unicode_ci NOT NULL,
|
||||
`enabled` tinyint(1) NOT NULL DEFAULT '1',
|
||||
`display_name` varchar(50) COLLATE utf8mb4_unicode_ci NOT NULL,
|
||||
`description` mediumtext COLLATE utf8mb4_unicode_ci NOT NULL,
|
||||
PRIMARY KEY (`judger_name`)
|
||||
) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4;
|
||||
) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||
/*!40101 SET character_set_client = @saved_cs_client */;
|
||||
|
||||
--
|
||||
@ -555,6 +584,26 @@ LOCK TABLES `judger_info` WRITE;
|
||||
/*!40000 ALTER TABLE `judger_info` ENABLE KEYS */;
|
||||
UNLOCK TABLES;
|
||||
|
||||
--
|
||||
-- Table structure for table `meta`
|
||||
--
|
||||
|
||||
CREATE TABLE `meta` (
|
||||
`name` varchar(100) COLLATE utf8mb4_unicode_ci NOT NULL,
|
||||
`value` json NOT NULL,
|
||||
`updated_at` datetime NOT NULL ON UPDATE CURRENT_TIMESTAMP,
|
||||
PRIMARY KEY (`name`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||
|
||||
--
|
||||
-- Dumping data for table `meta`
|
||||
--
|
||||
|
||||
LOCK TABLES `meta` WRITE;
|
||||
/*!40000 ALTER TABLE `meta` DISABLE KEYS */;
|
||||
/*!40000 ALTER TABLE `meta` ENABLE KEYS */;
|
||||
UNLOCK TABLES;
|
||||
|
||||
--
|
||||
-- Table structure for table `problems`
|
||||
--
|
||||
@ -562,18 +611,20 @@ UNLOCK TABLES;
|
||||
/*!40101 SET @saved_cs_client = @@character_set_client */;
|
||||
/*!40101 SET character_set_client = utf8mb4 */;
|
||||
CREATE TABLE `problems` (
|
||||
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
|
||||
`title` text NOT NULL,
|
||||
`id` int unsigned NOT NULL AUTO_INCREMENT,
|
||||
`title` text COLLATE utf8mb4_unicode_ci NOT NULL,
|
||||
`uploader` varchar(20) COLLATE utf8mb4_unicode_ci NOT NULL,
|
||||
`is_hidden` tinyint(1) NOT NULL DEFAULT '0',
|
||||
`submission_requirement` text,
|
||||
`submission_requirement` mediumtext COLLATE utf8mb4_unicode_ci,
|
||||
`hackable` tinyint(1) NOT NULL DEFAULT '0',
|
||||
`extra_config` varchar(500) NOT NULL DEFAULT '{"view_content_type":"ALL","view_details_type":"ALL"}',
|
||||
`extra_config` varchar(500) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '{"view_content_type":"ALL","view_details_type":"ALL"}',
|
||||
`zan` int(11) NOT NULL DEFAULT '0',
|
||||
`ac_num` int(11) NOT NULL DEFAULT '0',
|
||||
`submit_num` int(11) NOT NULL DEFAULT '0',
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4;
|
||||
`assigned_to_judger` varchar(50) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'any',
|
||||
PRIMARY KEY (`id`),
|
||||
KEY `assigned_to_judger` (`assigned_to_judger`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci TABLESPACE `innodb_system`;
|
||||
/*!40101 SET character_set_client = @saved_cs_client */;
|
||||
|
||||
--
|
||||
@ -592,11 +643,11 @@ UNLOCK TABLES;
|
||||
/*!40101 SET @saved_cs_client = @@character_set_client */;
|
||||
/*!40101 SET character_set_client = utf8mb4 */;
|
||||
CREATE TABLE `problems_contents` (
|
||||
`id` int(11) NOT NULL,
|
||||
`statement` mediumtext NOT NULL,
|
||||
`statement_md` mediumtext NOT NULL,
|
||||
`id` int NOT NULL,
|
||||
`statement` longtext COLLATE utf8mb4_unicode_ci NOT NULL,
|
||||
`statement_md` longtext COLLATE utf8mb4_unicode_ci NOT NULL,
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4;
|
||||
) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||
/*!40101 SET character_set_client = @saved_cs_client */;
|
||||
|
||||
--
|
||||
@ -616,9 +667,10 @@ UNLOCK TABLES;
|
||||
/*!40101 SET character_set_client = utf8mb4 */;
|
||||
CREATE TABLE `problems_permissions` (
|
||||
`username` varchar(20) COLLATE utf8mb4_unicode_ci NOT NULL,
|
||||
`problem_id` int(11) NOT NULL,
|
||||
PRIMARY KEY (`username`,`problem_id`)
|
||||
) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4;
|
||||
`problem_id` int NOT NULL,
|
||||
PRIMARY KEY (`username`,`problem_id`),
|
||||
KEY `problem_id` (`problem_id`)
|
||||
) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||
/*!40101 SET character_set_client = @saved_cs_client */;
|
||||
|
||||
--
|
||||
@ -637,9 +689,10 @@ UNLOCK TABLES;
|
||||
/*!40101 SET @saved_cs_client = @@character_set_client */;
|
||||
/*!40101 SET character_set_client = utf8mb4 */;
|
||||
CREATE TABLE `problems_solutions` (
|
||||
`problem_id` int(11) NOT NULL,
|
||||
`blog_id` int(11) NOT NULL,
|
||||
PRIMARY KEY (`problem_id`, `blog_id`)
|
||||
`problem_id` int NOT NULL,
|
||||
`blog_id` int NOT NULL,
|
||||
PRIMARY KEY (`problem_id`, `blog_id`),
|
||||
KEY `problem_id` (`problem_id`)
|
||||
) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4;
|
||||
/*!40101 SET character_set_client = @saved_cs_client */;
|
||||
|
||||
@ -659,8 +712,8 @@ UNLOCK TABLES;
|
||||
/*!40101 SET @saved_cs_client = @@character_set_client */;
|
||||
/*!40101 SET character_set_client = utf8mb4 */;
|
||||
CREATE TABLE `problems_tags` (
|
||||
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`problem_id` int(11) NOT NULL,
|
||||
`id` int NOT NULL AUTO_INCREMENT,
|
||||
`problem_id` int NOT NULL,
|
||||
`tag` varchar(30) NOT NULL,
|
||||
PRIMARY KEY (`id`),
|
||||
KEY `problem_id` (`problem_id`),
|
||||
@ -684,7 +737,7 @@ UNLOCK TABLES;
|
||||
/*!40101 SET @saved_cs_client = @@character_set_client */;
|
||||
/*!40101 SET character_set_client = utf8mb4 */;
|
||||
CREATE TABLE `lists` (
|
||||
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`id` int NOT NULL AUTO_INCREMENT,
|
||||
`title` text NOT NULL,
|
||||
`description` text NOT NULL DEFAULT '',
|
||||
`is_hidden` tinyint(1) NOT NULL DEFAULT '0',
|
||||
@ -699,9 +752,10 @@ CREATE TABLE `lists` (
|
||||
/*!40101 SET @saved_cs_client = @@character_set_client */;
|
||||
/*!40101 SET character_set_client = utf8mb4 */;
|
||||
CREATE TABLE `lists_problems` (
|
||||
`list_id` int(11) NOT NULL,
|
||||
`problem_id` int(11) NOT NULL,
|
||||
PRIMARY KEY (`list_id`, `problem_id`)
|
||||
`list_id` int NOT NULL,
|
||||
`problem_id` int NOT NULL,
|
||||
PRIMARY KEY (`list_id`, `problem_id`),
|
||||
KEY `list_id` (`list_id`)
|
||||
) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4;
|
||||
/*!40101 SET character_set_client = @saved_cs_client */;
|
||||
|
||||
@ -712,8 +766,8 @@ CREATE TABLE `lists_problems` (
|
||||
/*!40101 SET @saved_cs_client = @@character_set_client */;
|
||||
/*!40101 SET character_set_client = utf8mb4 */;
|
||||
CREATE TABLE `lists_tags` (
|
||||
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`list_id` int(11) NOT NULL,
|
||||
`id` int NOT NULL AUTO_INCREMENT,
|
||||
`list_id` int NOT NULL,
|
||||
`tag` varchar(30) NOT NULL,
|
||||
PRIMARY KEY (`id`),
|
||||
KEY `list_id` (`list_id`),
|
||||
@ -728,14 +782,14 @@ CREATE TABLE `lists_tags` (
|
||||
/*!40101 SET @saved_cs_client = @@character_set_client */;
|
||||
/*!40101 SET character_set_client = utf8mb4 */;
|
||||
CREATE TABLE `search_requests` (
|
||||
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`id` int NOT NULL AUTO_INCREMENT,
|
||||
`created_at` datetime NOT NULL,
|
||||
`remote_addr` varchar(50) NOT NULL,
|
||||
`type` enum('search','autocomplete') NOT NULL,
|
||||
`cache_id` int(11) NOT NULL,
|
||||
`q` varchar(100) NOT NULL,
|
||||
`content` text NOT NULL,
|
||||
`result` mediumtext NOT NULL,
|
||||
`remote_addr` varchar(50) COLLATE utf8mb4_unicode_ci NOT NULL,
|
||||
`type` enum('search','autocomplete') COLLATE utf8mb4_unicode_ci NOT NULL,
|
||||
`cache_id` int NOT NULL,
|
||||
`q` varchar(100) COLLATE utf8mb4_unicode_ci NOT NULL,
|
||||
`content` mediumtext COLLATE utf8mb4_unicode_ci NOT NULL,
|
||||
`result` json NOT NULL,
|
||||
PRIMARY KEY (`id`),
|
||||
KEY `remote_addr` (`remote_addr`,`created_at`),
|
||||
KEY `created_at` (`created_at`)
|
||||
@ -758,27 +812,42 @@ UNLOCK TABLES;
|
||||
/*!40101 SET @saved_cs_client = @@character_set_client */;
|
||||
/*!40101 SET character_set_client = utf8mb4 */;
|
||||
CREATE TABLE `submissions` (
|
||||
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
|
||||
`problem_id` int(10) unsigned NOT NULL,
|
||||
`contest_id` int(10) unsigned DEFAULT NULL,
|
||||
`id` int UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
`problem_id` int UNSIGNED NOT NULL,
|
||||
`contest_id` int UNSIGNED DEFAULT NULL,
|
||||
`submit_time` datetime NOT NULL,
|
||||
`submitter` varchar(20) NOT NULL,
|
||||
`content` text NOT NULL,
|
||||
`language` varchar(15) NOT NULL,
|
||||
`tot_size` int(11) NOT NULL,
|
||||
`submitter` varchar(20) COLLATE utf8mb4_unicode_ci NOT NULL,
|
||||
`content` mediumtext COLLATE utf8mb4_unicode_ci NOT NULL,
|
||||
`language` varchar(15) COLLATE utf8mb4_unicode_ci NOT NULL,
|
||||
`tot_size` int NOT NULL,
|
||||
`judge_reason` varchar(1024) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '',
|
||||
`judge_time` datetime DEFAULT NULL,
|
||||
`result` blob NOT NULL,
|
||||
`status` varchar(20) NOT NULL,
|
||||
`result_error` varchar(20) DEFAULT NULL,
|
||||
`score` int(11) DEFAULT NULL,
|
||||
`used_time` int(11) NOT NULL DEFAULT '0',
|
||||
`used_memory` int(11) NOT NULL DEFAULT '0',
|
||||
`judger` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '',
|
||||
`result` mediumblob NOT NULL,
|
||||
`status` varchar(20) COLLATE utf8mb4_unicode_ci NOT NULL,
|
||||
`result_error` varchar(20) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
|
||||
`score` int DEFAULT NULL,
|
||||
`hide_score_to_others` tinyint(1) NOT NULL DEFAULT '0',
|
||||
`hidden_score` int DEFAULT NULL,
|
||||
`used_time` int NOT NULL DEFAULT '0',
|
||||
`used_memory` int NOT NULL DEFAULT '0',
|
||||
`is_hidden` tinyint(1) NOT NULL,
|
||||
`status_details` varchar(100) NOT NULL,
|
||||
`status_details` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '',
|
||||
PRIMARY KEY (`id`),
|
||||
KEY `is_hidden` (`is_hidden`,`problem_id`),
|
||||
KEY `score` (`problem_id`, `submitter`, `score`)
|
||||
) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4;
|
||||
KEY `status` (`status`,`id`),
|
||||
KEY `result_error` (`result_error`),
|
||||
KEY `problem_id` (`problem_id`,`id`),
|
||||
KEY `language` (`language`,`id`),
|
||||
KEY `language2` (`is_hidden`,`language`,`id`),
|
||||
KEY `user_score` (`problem_id`,`submitter`,`score`,`id`),
|
||||
KEY `problem_id2` (`is_hidden`,`problem_id`,`id`),
|
||||
KEY `id2` (`is_hidden`,`id`),
|
||||
KEY `problem_score2` (`is_hidden`,`problem_id`,`score`,`id`),
|
||||
KEY `contest_submission_status` (`contest_id`,`status`),
|
||||
KEY `submitter2` (`is_hidden`,`submitter`,`id`),
|
||||
KEY `submitter` (`submitter`,`id`) USING BTREE,
|
||||
KEY `contest_id` (`contest_id`,`is_hidden`) USING BTREE
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||
/*!40101 SET character_set_client = @saved_cs_client */;
|
||||
|
||||
--
|
||||
@ -790,6 +859,83 @@ LOCK TABLES `submissions` WRITE;
|
||||
/*!40000 ALTER TABLE `submissions` ENABLE KEYS */;
|
||||
UNLOCK TABLES;
|
||||
|
||||
--
|
||||
-- Table structure for table `submissions_history`
|
||||
--
|
||||
|
||||
CREATE TABLE `submissions_history` (
|
||||
`id` int UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
`submission_id` int UNSIGNED NOT NULL,
|
||||
`judge_reason` varchar(1024) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '',
|
||||
`judge_time` datetime DEFAULT NULL,
|
||||
`judger` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '',
|
||||
`result` mediumblob NOT NULL,
|
||||
`status` varchar(20) COLLATE utf8mb4_unicode_ci NOT NULL,
|
||||
`status_details` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '',
|
||||
`result_error` varchar(20) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
|
||||
`score` int DEFAULT NULL,
|
||||
`used_time` int NOT NULL DEFAULT '0',
|
||||
`used_memory` int NOT NULL DEFAULT '0',
|
||||
`major` tinyint(1) NOT NULL,
|
||||
PRIMARY KEY (`id`),
|
||||
KEY `submission_judge_time` (`submission_id`,`judge_time`,`id`),
|
||||
KEY `submission` (`submission_id`,`id`),
|
||||
KEY `status_major` (`status`,`major`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||
|
||||
--
|
||||
-- Dumping data for table `submissions_history`
|
||||
--
|
||||
|
||||
LOCK TABLES `submissions_history` WRITE;
|
||||
/*!40000 ALTER TABLE `submissions_history` DISABLE KEYS */;
|
||||
/*!40000 ALTER TABLE `submissions_history` ENABLE KEYS */;
|
||||
UNLOCK TABLES;
|
||||
|
||||
--
|
||||
-- Table structure for table `system_updates`
|
||||
--
|
||||
|
||||
CREATE TABLE `system_updates` (
|
||||
`id` int UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
`time` datetime NOT NULL,
|
||||
`type` varchar(20) COLLATE utf8mb4_unicode_ci NOT NULL,
|
||||
`target_id` int UNSIGNED NOT NULL,
|
||||
`message` mediumtext COLLATE utf8mb4_unicode_ci NOT NULL,
|
||||
PRIMARY KEY (`id`),
|
||||
KEY `type_id_time` (`type`,`target_id`,`time`),
|
||||
KEY `type_time` (`type`,`time`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||
|
||||
--
|
||||
-- Dumping data for table `system_updates`
|
||||
--
|
||||
|
||||
LOCK TABLES `system_updates` WRITE;
|
||||
/*!40000 ALTER TABLE `system_updates` DISABLE KEYS */;
|
||||
/*!40000 ALTER TABLE `system_updates` ENABLE KEYS */;
|
||||
UNLOCK TABLES;
|
||||
|
||||
--
|
||||
-- Table structure for table `upgrades`
|
||||
--
|
||||
|
||||
CREATE TABLE `upgrades` (
|
||||
`name` varchar(50) COLLATE utf8mb4_unicode_ci NOT NULL,
|
||||
`status` enum('up','down') COLLATE utf8mb4_unicode_ci DEFAULT NULL,
|
||||
`updated_at` datetime NOT NULL,
|
||||
PRIMARY KEY (`name`)
|
||||
) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||
|
||||
--
|
||||
-- Dumping data for table `upgrades`
|
||||
--
|
||||
|
||||
LOCK TABLES `upgrades` WRITE;
|
||||
/*!40000 ALTER TABLE `upgrades` DISABLE KEYS */;
|
||||
/*!40000 ALTER TABLE `upgrades` ENABLE KEYS */;
|
||||
UNLOCK TABLES;
|
||||
|
||||
--
|
||||
-- Table structure for table `user_info`
|
||||
--
|
||||
@ -797,32 +943,29 @@ UNLOCK TABLES;
|
||||
/*!40101 SET @saved_cs_client = @@character_set_client */;
|
||||
/*!40101 SET character_set_client = utf8mb4 */;
|
||||
CREATE TABLE `user_info` (
|
||||
`usergroup` char(1) NOT NULL DEFAULT 'U',
|
||||
`usergroup` char(1) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'U',
|
||||
`username` varchar(20) COLLATE utf8mb4_unicode_ci NOT NULL,
|
||||
`usertype` varchar(250) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'student',
|
||||
`realname` varchar(30) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '',
|
||||
`school` varchar(50) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '',
|
||||
`usertype` varchar(250) NOT NULL DEFAULT 'student',
|
||||
`email` varchar(50) NOT NULL,
|
||||
`password` char(32) NOT NULL,
|
||||
`svn_password` char(10) NOT NULL,
|
||||
`qq` bigint(20) NOT NULL,
|
||||
`sex` char(1) NOT NULL DEFAULT 'U',
|
||||
`ac_num` int(11) NOT NULL,
|
||||
`email` varchar(50) COLLATE utf8mb4_unicode_ci NOT NULL,
|
||||
`password` char(32) COLLATE utf8mb4_unicode_ci NOT NULL,
|
||||
`svn_password` char(10) COLLATE utf8mb4_unicode_ci NOT NULL,
|
||||
`qq` bigint NOT NULL DEFAULT '0',
|
||||
`sex` char(1) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'U',
|
||||
`ac_num` int NOT NULL DEFAULT 0,
|
||||
`register_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
`remote_addr` varchar(50) NOT NULL,
|
||||
`http_x_forwarded_for` varchar(50) NOT NULL,
|
||||
`remember_token` char(60) NOT NULL,
|
||||
`motto` varchar(200) NOT NULL,
|
||||
`last_login` timestamp NOT NULL DEFAULT 0,
|
||||
`last_visited` timestamp NOT NULL DEFAULT 0,
|
||||
`images_size_limit` int(11) UNSIGNED NOT NULL DEFAULT 104857600, /* 100 MiB */
|
||||
`codeforces_handle` varchar(20) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '',
|
||||
`github` varchar(20) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '',
|
||||
`website` varchar(50) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '',
|
||||
`avatar_source` varchar(10) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'gravatar',
|
||||
`last_login_time` datetime DEFAULT CURRENT_TIMESTAMP,
|
||||
`last_visit_time` datetime DEFAULT CURRENT_TIMESTAMP,
|
||||
`expiration_time` datetime DEFAULT NULL,
|
||||
`remote_addr` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '',
|
||||
`http_x_forwarded_for` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '',
|
||||
`remember_token` char(60) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '',
|
||||
`motto` varchar(200) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '',
|
||||
`extra` json NOT NULL,
|
||||
PRIMARY KEY (`username`),
|
||||
KEY `ac_num` (`ac_num`,`username`)
|
||||
) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4;
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||
/*!40101 SET character_set_client = @saved_cs_client */;
|
||||
|
||||
--
|
||||
@ -841,13 +984,13 @@ UNLOCK TABLES;
|
||||
/*!40101 SET @saved_cs_client = @@character_set_client */;
|
||||
/*!40101 SET character_set_client = utf8mb4 */;
|
||||
CREATE TABLE `users_images` (
|
||||
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
|
||||
`id` int UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
`path` varchar(100) NOT NULL,
|
||||
`uploader` varchar(20) NOT NULL,
|
||||
`width` int(11) NOT NULL,
|
||||
`height` int(11) NOT NULL,
|
||||
`width` int NOT NULL,
|
||||
`height` int NOT NULL,
|
||||
`upload_time` datetime NOT NULL,
|
||||
`size` int(11) NOT NULL,
|
||||
`size` int NOT NULL,
|
||||
`hash` varchar(100) NOT NULL,
|
||||
PRIMARY KEY (`id`),
|
||||
KEY `uploader` (`uploader`),
|
||||
@ -874,13 +1017,16 @@ UNLOCK TABLES;
|
||||
/*!40101 SET @saved_cs_client = @@character_set_client */;
|
||||
/*!40101 SET character_set_client = utf8mb4 */;
|
||||
CREATE TABLE `user_msg` (
|
||||
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
|
||||
`id` int UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
`sender` varchar(20) NOT NULL,
|
||||
`receiver` varchar(20) NOT NULL,
|
||||
`message` varchar(5000) NOT NULL,
|
||||
`send_time` datetime NOT NULL,
|
||||
`read_time` datetime DEFAULT NULL,
|
||||
PRIMARY KEY (`id`)
|
||||
PRIMARY KEY (`id`),
|
||||
KEY `sender` (`sender`),
|
||||
KEY `receiver` (`receiver`),
|
||||
KEY `read_time` (`receiver`,`read_time`) USING BTREE
|
||||
) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4;
|
||||
/*!40101 SET character_set_client = @saved_cs_client */;
|
||||
|
||||
@ -900,13 +1046,14 @@ UNLOCK TABLES;
|
||||
/*!40101 SET @saved_cs_client = @@character_set_client */;
|
||||
/*!40101 SET character_set_client = utf8mb4 */;
|
||||
CREATE TABLE `user_system_msg` (
|
||||
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`id` int NOT NULL AUTO_INCREMENT,
|
||||
`title` varchar(100) COLLATE utf8mb4_unicode_ci NOT NULL,
|
||||
`content` text COLLATE utf8mb4_unicode_ci NOT NULL,
|
||||
`receiver` varchar(20) COLLATE utf8mb4_unicode_ci NOT NULL,
|
||||
`send_time` datetime NOT NULL,
|
||||
`read_time` datetime DEFAULT NULL,
|
||||
PRIMARY KEY (`id`)
|
||||
PRIMARY KEY (`id`),
|
||||
KEY `receiver` (`receiver`,`read_time`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||
/*!40101 SET character_set_client = @saved_cs_client */;
|
||||
|
||||
|
@ -24,6 +24,8 @@ services:
|
||||
build:
|
||||
context: ./judger/
|
||||
dockerfile: Dockerfile
|
||||
args:
|
||||
- USE_MIRROR=1
|
||||
container_name: uoj-judger
|
||||
restart: always
|
||||
stdin_open: true
|
||||
@ -44,6 +46,8 @@ services:
|
||||
build:
|
||||
context: ./
|
||||
dockerfile: web/Dockerfile
|
||||
args:
|
||||
- USE_MIRROR=1
|
||||
container_name: uoj-web
|
||||
restart: always
|
||||
stdin_open: true
|
||||
|
@ -1,15 +1,24 @@
|
||||
FROM ubuntu:22.04
|
||||
|
||||
ARG CLONE_ADDFLAG
|
||||
ARG USE_MIRROR
|
||||
ENV USE_MIRROR $USE_MIRROR
|
||||
SHELL ["/bin/bash", "-c"]
|
||||
|
||||
ENV DEBIAN_FRONTEND=noninteractive
|
||||
RUN apt-get update && apt-get install -y vim ntp zip unzip curl wget build-essential fp-compiler python2.7 python3.10 python3-requests libseccomp-dev openjdk-8-jdk openjdk-11-jdk openjdk-17-jdk
|
||||
ENV PKGS="vim ntp zip unzip curl wget build-essential fp-compiler python2.7 python3.10 python3-requests libseccomp-dev openjdk-8-jdk openjdk-11-jdk openjdk-17-jdk"
|
||||
RUN if [[ "$USE_MIRROR" == "1" ]]; then\
|
||||
sed -i "s@http://.*archive.ubuntu.com@http://mirrors.tuna.tsinghua.edu.cn@g" /etc/apt/sources.list &&\
|
||||
sed -i "s@http://.*security.ubuntu.com@http://mirrors.tuna.tsinghua.edu.cn@g" /etc/apt/sources.list ;\
|
||||
fi &&\
|
||||
apt-get update &&\
|
||||
(apt-get install -y --allow-unauthenticated --no-install-recommends -o Dpkg::Options::="--force-overwrite" -o APT::Acquire::Retries="30" --fix-missing $PKGS || apt --fix-broken install -y || apt-get install -y --allow-unauthenticated --no-install-recommends -o Dpkg::Options::="--force-overwrite" -o APT::Acquire::Retries="30" --fix-missing $PKGS)
|
||||
|
||||
ADD . /opt/uoj_judger
|
||||
WORKDIR /opt/uoj_judger
|
||||
|
||||
# Install environment and set startup script
|
||||
RUN sh install.sh -p && echo "\
|
||||
RUN sh install.sh -p && echo -e "\
|
||||
#!/bin/sh\n\
|
||||
if [ ! -f \"/opt/uoj_judger/.conf.json\" ]; then\n\
|
||||
cd /opt/uoj_judger && sh install.sh -i\n\
|
||||
|
@ -35,12 +35,15 @@ const std::vector<std::pair<const char *, const char *>> suffix_search_list = {
|
||||
{".code" , "" },
|
||||
{"20.cpp" , "C++20" },
|
||||
{"17.cpp" , "C++17" },
|
||||
{"14.cpp" , "C++14" },
|
||||
{"14.cpp" , "C++" },
|
||||
{"11.cpp" , "C++11" },
|
||||
{"03.cpp" , "C++03" },
|
||||
{"98.cpp" , "C++98" },
|
||||
{".cpp" , "C++" },
|
||||
{".c" , "C" },
|
||||
{".pas" , "Pascal" },
|
||||
{"2.7.py" , "Python2.7"},
|
||||
{"2.py" , "Python2.7"},
|
||||
{".py" , "Python3" },
|
||||
{"7.java" , "Java7" },
|
||||
{"8.java" , "Java8" },
|
||||
|
@ -1,18 +1,30 @@
|
||||
FROM ubuntu:22.04
|
||||
|
||||
ARG CLONE_ADDFLAG
|
||||
ARG USE_MIRROR
|
||||
ENV USE_MIRROR $USE_MIRROR
|
||||
SHELL ["/bin/bash", "-c"]
|
||||
|
||||
ENV DEBIAN_FRONTEND=noninteractive
|
||||
RUN dpkg -s gnupg 2>/dev/null || (apt-get update && apt-get install -y gnupg) &&\
|
||||
echo "deb http://ppa.launchpad.net/ondrej/php/ubuntu jammy main" | tee /etc/apt/sources.list.d/ondrej-php.list && apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 4F4EA0AAE5267A6C &&\
|
||||
apt-get update --allow-unauthenticated &&\
|
||||
apt-get install -y --allow-unauthenticated -o Dpkg::Options::="--force-overwrite" php7.4 php7.4-yaml php7.4-xml php7.4-dev php7.4-zip php7.4-mysql php7.4-mbstring php7.4-gd php7.4-imagick libseccomp-dev git vim ntp zip unzip curl wget libapache2-mod-xsendfile mysql-server php-pear cmake fp-compiler re2c libyaml-dev python2.7 python3.10 python3-requests openjdk-8-jdk openjdk-11-jdk openjdk-17-jdk
|
||||
ENV PKGS="php7.4 php7.4-yaml php7.4-xml php7.4-dev php7.4-zip php7.4-mysql php7.4-mbstring php7.4-gd php7.4-imagick libseccomp-dev git vim ntp zip unzip curl wget apache2 libapache2-mod-xsendfile php-pear mysql-client build-essential fp-compiler re2c libseccomp-dev libyaml-dev python2.7 python3.10 python3-requests openjdk-8-jdk openjdk-11-jdk openjdk-17-jdk"
|
||||
RUN if [[ "$USE_MIRROR" == "1" ]]; then\
|
||||
sed -i "s@http://.*archive.ubuntu.com@https://mirrors.aliyun.com@g" /etc/apt/sources.list &&\
|
||||
sed -i "s@http://.*security.ubuntu.com@https://mirrors.aliyun.com@g" /etc/apt/sources.list ;\
|
||||
fi &&\
|
||||
apt-get -o "Acquire::https::Verify-Peer=false" update && apt-get -o "Acquire::https::Verify-Peer=false" install -y --no-install-recommends gnupg ca-certificates &&\
|
||||
echo "deb http://ppa.launchpad.net/ondrej/php/ubuntu jammy main" | tee /etc/apt/sources.list.d/ondrej-php.list && apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 4F4EA0AAE5267A6C &&\
|
||||
if [[ "$USE_MIRROR" == "1" ]]; then\
|
||||
find /etc/apt/sources.list.d/ -type f -name "*.list" -exec sed -i.bak -r 's#deb(-src)?\s*http(s)?://ppa.launchpad.net#deb\1 https://launchpad.proxy.ustclug.org#ig' {} \; &&\
|
||||
find /etc/apt/sources.list.d/ -type f -name "*.list" -exec sed -i.bak -r 's#deb(-src)?\s*http(s)?://ppa.launchpadcontent.net#deb\1 https://launchpad.proxy.ustclug.org#ig' {} \; ;\
|
||||
fi &&\
|
||||
apt-get update --allow-unauthenticated &&\
|
||||
(apt-get install -y --allow-unauthenticated --no-install-recommends -o Dpkg::Options::="--force-overwrite" -o APT::Acquire::Retries="30" --fix-missing $PKGS || apt-get install --fix-broken -y -o APT::Acquire::Retries="30")
|
||||
|
||||
ADD . /opt/uoj
|
||||
WORKDIR /opt/uoj
|
||||
|
||||
# Install environment and set startup script
|
||||
RUN sh web/install.sh -p && echo "\
|
||||
RUN sh web/install.sh -p && echo -e "\
|
||||
#!/bin/sh\n\
|
||||
if [ ! -f \"/var/uoj_data/.UOJSetupDone\" ]; then\n\
|
||||
cd /opt/uoj/web && sh install.sh -i\n\
|
||||
|
@ -21,12 +21,12 @@ return [
|
||||
'main' => [
|
||||
'protocol' => 'http',
|
||||
'host' => '_httpHost_',
|
||||
'port' => 80
|
||||
'port' => '80/443'
|
||||
],
|
||||
'blog' => [
|
||||
'protocol' => 'http',
|
||||
'host' => '_httpHost_',
|
||||
'port' => 80
|
||||
'port' => '80/443'
|
||||
]
|
||||
],
|
||||
'security' => [
|
||||
@ -54,7 +54,6 @@ return [
|
||||
],
|
||||
'switch' => [
|
||||
'blog-domain-mode' => 3,
|
||||
'force-login' => true,
|
||||
'open-register' => false
|
||||
]
|
||||
];
|
||||
|
@ -1,22 +1,17 @@
|
||||
<?php
|
||||
if (!Auth::check()) {
|
||||
redirectToLogin();
|
||||
}
|
||||
requireLib('bootstrap5');
|
||||
requirePHPLib('form');
|
||||
|
||||
if (!isNormalUser($myUser)) {
|
||||
become403Page();
|
||||
}
|
||||
Auth::check() || redirectToLogin();
|
||||
isSuperUser(Auth::user()) || UOJResponse::page403();
|
||||
|
||||
requireLib('bootstrap5');
|
||||
requirePHPLib('form');
|
||||
|
||||
if (!isSuperUser($myUser)) {
|
||||
become403Page();
|
||||
}
|
||||
$time_form = new UOJForm('time');
|
||||
$time_form->addVInput(
|
||||
'name', 'text', '比赛标题', 'New Contest',
|
||||
function($name, &$vdata) {
|
||||
$time_form = new UOJBs4Form('time');
|
||||
$time_form->addVInput(
|
||||
'name',
|
||||
'text',
|
||||
'比赛标题',
|
||||
'New Contest',
|
||||
function ($name, &$vdata) {
|
||||
if ($name == '') {
|
||||
return '标题不能为空';
|
||||
}
|
||||
@ -36,10 +31,13 @@
|
||||
return '';
|
||||
},
|
||||
null
|
||||
);
|
||||
$time_form->addVInput(
|
||||
'start_time', 'text', '开始时间', date("Y-m-d H:i:s"),
|
||||
function($str, &$vdata) {
|
||||
);
|
||||
$time_form->addVInput(
|
||||
'start_time',
|
||||
'text',
|
||||
'开始时间',
|
||||
date("Y-m-d H:i:s"),
|
||||
function ($str, &$vdata) {
|
||||
try {
|
||||
$vdata['start_time'] = new DateTime($str);
|
||||
} catch (Exception $e) {
|
||||
@ -48,10 +46,13 @@
|
||||
return '';
|
||||
},
|
||||
null
|
||||
);
|
||||
$time_form->addVInput(
|
||||
'last_min', 'text', '时长(单位:分钟)', 180,
|
||||
function($str, &$vdata) {
|
||||
);
|
||||
$time_form->addVInput(
|
||||
'last_min',
|
||||
'text',
|
||||
'时长(单位:分钟)',
|
||||
180,
|
||||
function ($str, &$vdata) {
|
||||
if (!validateUInt($str)) {
|
||||
return '必须为一个整数';
|
||||
}
|
||||
@ -61,41 +62,42 @@
|
||||
return '';
|
||||
},
|
||||
null
|
||||
);
|
||||
$time_form->handle = function(&$vdata) {
|
||||
);
|
||||
$time_form->handle = function (&$vdata) {
|
||||
$start_time_str = $vdata['start_time']->format('Y-m-d H:i:s');
|
||||
$esc_name = DB::escape($vdata['name']);
|
||||
$esc_last_min = DB::escape($vdata['last_min']);
|
||||
|
||||
DB::query("insert into contests (name, start_time, last_min, status) values ('$esc_name', '$start_time_str', $esc_last_min, 'unfinished')");
|
||||
};
|
||||
$time_form->succ_href = "/contests";
|
||||
$time_form->runAtServer();
|
||||
?>
|
||||
DB::insert([
|
||||
"insert into contests",
|
||||
"(name, start_time, last_min, status)", "values",
|
||||
DB::tuple([$vdata['name'], $start_time_str, $vdata['last_min'], 'unfinished'])
|
||||
]);
|
||||
};
|
||||
$time_form->succ_href = "/contests";
|
||||
$time_form->runAtServer();
|
||||
?>
|
||||
<?php echoUOJPageHeader('添加比赛') ?>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-lg-9">
|
||||
<!-- left col -->
|
||||
<div class="col-lg-9">
|
||||
<div class="card card-default mb-2">
|
||||
<div class="card-body">
|
||||
|
||||
<div class="card card-default mb-2">
|
||||
<div class="card-body">
|
||||
<h1 class="card-title">添加比赛</h1>
|
||||
|
||||
<h1 class="h2 card-title">添加比赛</h1>
|
||||
<div class="w-full" style="max-width: 400px">
|
||||
<?php $time_form->printHTML(); ?>
|
||||
</div>
|
||||
|
||||
<div class="w-full" style="max-width: 400px">
|
||||
<?php $time_form->printHTML(); ?>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<!-- right col -->
|
||||
<aside class="col-lg-3 mt-3 mt-lg-0">
|
||||
<?php uojIncludeView('sidebar', array()) ?>
|
||||
</aside>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<!-- end left col -->
|
||||
|
||||
<!-- right col -->
|
||||
<aside class="col-lg-3 mt-3 mt-lg-0">
|
||||
<?php uojIncludeView('sidebar') ?>
|
||||
</aside>
|
||||
</div>
|
||||
|
||||
<?php echoUOJPageFooter() ?>
|
||||
|
@ -1,73 +1,57 @@
|
||||
<?php
|
||||
if (!Auth::check() && UOJConfig::$data['switch']['force-login']) {
|
||||
redirectToLogin();
|
||||
}
|
||||
requireLib('bootstrap5');
|
||||
requirePHPLib('form');
|
||||
?>
|
||||
<?php echoUOJPageHeader(UOJLocale::get('announcements')) ?>
|
||||
|
||||
if (!isNormalUser($myUser) && UOJConfig::$data['switch']['force-login']) {
|
||||
become403Page();
|
||||
}
|
||||
<div class="row">
|
||||
<!-- left col -->
|
||||
<div class="col-lg-9">
|
||||
<h1>
|
||||
<?= UOJLocale::get('announcements') ?>
|
||||
</h1>
|
||||
|
||||
requireLib('bootstrap5');
|
||||
requirePHPLib('form');
|
||||
|
||||
function echoBlogCell($blog) {
|
||||
$level = $blog['level'];
|
||||
|
||||
switch ($level) {
|
||||
case 0:
|
||||
$level_str = '';
|
||||
break;
|
||||
case 1:
|
||||
$level_str = '<span style="color:red">[三级置顶]</span> ';
|
||||
break;
|
||||
case 2:
|
||||
$level_str = '<span style="color:red">[二级置顶]</span> ';
|
||||
break;
|
||||
case 3:
|
||||
$level_str = '<span style="color:red">[一级置顶]</span> ';
|
||||
break;
|
||||
}
|
||||
|
||||
echo '<tr>';
|
||||
echo '<td>' . $level_str . getBlogLink($blog['id']) . '</td>';
|
||||
echo '<td>' . getUserLink($blog['poster']) . '</td>';
|
||||
echo '<td>' . $blog['post_time'] . '</td>';
|
||||
echo '</tr>';
|
||||
}
|
||||
$header = <<<EOD
|
||||
<?php
|
||||
echoLongTable(
|
||||
['blogs.id', 'poster', 'title', 'post_time', 'zan', 'level'],
|
||||
'important_blogs, blogs',
|
||||
[
|
||||
'is_hidden' => 0,
|
||||
'important_blogs.blog_id' => DB::raw('blogs.id')
|
||||
],
|
||||
'order by level desc, important_blogs.blog_id desc',
|
||||
<<<EOD
|
||||
<tr>
|
||||
<th width="60%">标题</th>
|
||||
<th width="20%">发表者</th>
|
||||
<th width="20%">发表日期</th>
|
||||
</tr>
|
||||
EOD;
|
||||
$config = [
|
||||
EOD,
|
||||
function ($info) {
|
||||
$blog = new UOJBlog($info);
|
||||
|
||||
echo '<tr>';
|
||||
echo '<td>' . $blog->getLink(['show_level' => true, 'show_new_tag' => true]) . '</td>';
|
||||
echo '<td>' . getUserLink($blog->info['poster']) . '</td>';
|
||||
echo '<td>' . $blog->info['post_time'] . '</td>';
|
||||
echo '</tr>';
|
||||
},
|
||||
[
|
||||
'page_len' => 40,
|
||||
'div_classes' => ['card', 'my-3'],
|
||||
'table_classes' => ['table', 'uoj-table', 'mb-0'],
|
||||
];
|
||||
]
|
||||
);
|
||||
?>
|
||||
<?php echoUOJPageHeader(UOJLocale::get('announcements')) ?>
|
||||
|
||||
<div class="row">
|
||||
<!-- left col -->
|
||||
<div class="col-lg-9">
|
||||
|
||||
<h1 class="h2">
|
||||
<?= UOJLocale::get('announcements') ?>
|
||||
</h1>
|
||||
|
||||
<?php echoLongTable(array('blogs.id', 'poster', 'title', 'post_time', 'zan', 'level'), 'important_blogs, blogs', 'is_hidden = 0 and important_blogs.blog_id = blogs.id', 'order by level desc, important_blogs.blog_id desc', $header, 'echoBlogCell', $config); ?>
|
||||
|
||||
</div>
|
||||
<!-- end left col -->
|
||||
|
||||
<!-- right col -->
|
||||
<aside class="col-lg-3 mt-3 mt-lg-0">
|
||||
<?php uojIncludeView('sidebar', array()) ?>
|
||||
</aside>
|
||||
<!-- end right col -->
|
||||
</div>
|
||||
<!-- end left col -->
|
||||
|
||||
<!-- right col -->
|
||||
<aside class="col-lg-3 mt-3 mt-lg-0">
|
||||
<?php uojIncludeView('sidebar') ?>
|
||||
</aside>
|
||||
<!-- end right col -->
|
||||
</div>
|
||||
|
||||
<?php echoUOJPageFooter() ?>
|
||||
|
@ -1,15 +1,6 @@
|
||||
<?php
|
||||
if (!Auth::check() && UOJConfig::$data['switch']['force-login']) {
|
||||
redirectToLogin();
|
||||
}
|
||||
|
||||
if (!isNormalUser($myUser) && UOJConfig::$data['switch']['force-login']) {
|
||||
become403Page();
|
||||
}
|
||||
Auth::check() || redirectToLogin();
|
||||
UOJBlog::init(UOJRequest::get('id')) || UOJResponse::page404();
|
||||
|
||||
if (!validateUInt($_GET['id']) || !($blog = queryBlog($_GET['id']))) {
|
||||
become404Page();
|
||||
}
|
||||
|
||||
redirectTo(HTML::blog_url($blog['poster'], '/post/'.$_GET['id'] . ($_GET['sub'] ?: '')));
|
||||
?>
|
||||
redirectTo(HTML::blog_url(UOJBlog::info('poster'), '/post/' . UOJBlog::info('id'), ['escape' => false]));
|
||||
|
@ -1,66 +1,63 @@
|
||||
<?php
|
||||
requireLib('bootstrap5');
|
||||
requirePHPLib('form');
|
||||
requireLib('bootstrap5');
|
||||
requirePHPLib('form');
|
||||
|
||||
if (!Auth::check() && UOJConfig::$data['switch']['force-login']) {
|
||||
redirectToLogin();
|
||||
}
|
||||
|
||||
if (!isNormalUser($myUser) && UOJConfig::$data['switch']['force-login']) {
|
||||
become403Page();
|
||||
}
|
||||
?>
|
||||
Auth::check() || redirectToLogin();
|
||||
?>
|
||||
<?php echoUOJPageHeader(UOJLocale::get('blogs')) ?>
|
||||
|
||||
<div class="row">
|
||||
|
||||
<!-- left col -->
|
||||
<div class="col-lg-9">
|
||||
|
||||
<!-- title container -->
|
||||
<div class="d-flex flex-wrap justify-content-between align-items-center">
|
||||
|
||||
<h1 class="h2">
|
||||
<!-- left col -->
|
||||
<div class="col-lg-9">
|
||||
<!-- title container -->
|
||||
<div class="d-flex flex-wrap justify-content-between align-items-center">
|
||||
<h1>
|
||||
<?= UOJLocale::get("blogs overview") ?>
|
||||
</h1>
|
||||
</h1>
|
||||
|
||||
<div class="text-end">
|
||||
<?php if (Auth::check()) : ?>
|
||||
<div class="text-end">
|
||||
<div class="btn-group">
|
||||
<a href="<?= HTML::blog_url(Auth::id(), '/') ?>" class="btn btn-secondary btn-sm">
|
||||
我的博客首页
|
||||
</a>
|
||||
<a href="<?= HTML::blog_url(Auth::id(), '/post/new/write')?>" class="btn btn-primary btn-sm">
|
||||
<a href="<?= HTML::blog_url(Auth::id(), '/post/new/write') ?>" class="btn btn-primary btn-sm">
|
||||
<i class="bi bi-pencil"></i>
|
||||
写新博客
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<!-- end title container -->
|
||||
</div>
|
||||
<?php endif ?>
|
||||
</div>
|
||||
<!-- end title container -->
|
||||
|
||||
<?php
|
||||
echoLongTable(
|
||||
<?php
|
||||
echoLongTable(
|
||||
['id', 'poster', 'title', 'post_time', 'zan', 'is_hidden'],
|
||||
'blogs',
|
||||
isSuperUser($myUser) ? "1" : "is_hidden = 0 or poster = '{$myUser['username']}'",
|
||||
'order by post_time desc',
|
||||
<<<EOD
|
||||
<tr>
|
||||
<th width="60%">标题</th>
|
||||
<th width="20%">发表者</th>
|
||||
<th width="20%">发表日期</th>
|
||||
<th>标题</th>
|
||||
<th style="width:200px">发表者</th>
|
||||
<th style="width:200px">发表日期</th>
|
||||
<th style="width:50px" class="text-center">评价</th>
|
||||
</tr>
|
||||
EOD,
|
||||
function($blog) {
|
||||
function ($info) {
|
||||
$blog = new UOJBlog($info);
|
||||
|
||||
echo '<tr>';
|
||||
echo '<td>';
|
||||
echo getBlogLink($blog['id']);
|
||||
if ($blog['is_hidden']) {
|
||||
echo $blog->getLink();
|
||||
if ($blog->info['is_hidden']) {
|
||||
echo ' <span class="badge text-bg-danger"><i class="bi bi-eye-slash-fill"></i> ', UOJLocale::get('hidden'), '</span> ';
|
||||
}
|
||||
echo '</td>';
|
||||
echo '<td>' . getUserLink($blog['poster']) . '</td>';
|
||||
echo '<td>' . $blog['post_time'] . '</td>';
|
||||
echo '<td>' . getUserLink($blog->info['poster']) . '</td>';
|
||||
echo '<td>' . $blog->info['post_time'] . '</td>';
|
||||
echo '<td class="text-center">' . ClickZans::getCntBlock($blog->info['zan']) . '</td>';
|
||||
echo '</tr>';
|
||||
},
|
||||
[
|
||||
@ -68,16 +65,16 @@ EOD,
|
||||
'div_classes' => ['card', 'my-3', 'table-responsive'],
|
||||
'table_classes' => ['table', 'uoj-table', 'mb-0'],
|
||||
]
|
||||
);
|
||||
);
|
||||
?>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- right col -->
|
||||
<aside class="col-lg-3 mt-3 mt-lg-0">
|
||||
<?php uojIncludeView('sidebar') ?>
|
||||
</aside>
|
||||
<!-- end right col -->
|
||||
<!-- right col -->
|
||||
<aside class="col-lg-3 mt-3 mt-lg-0">
|
||||
<?php uojIncludeView('sidebar') ?>
|
||||
</aside>
|
||||
<!-- end right col -->
|
||||
|
||||
</div>
|
||||
|
||||
|
@ -9,5 +9,3 @@ $_SESSION['phrase'] = $builder->getPhrase();
|
||||
|
||||
header('Content-Type: image/jpeg');
|
||||
$builder->build()->output();
|
||||
|
||||
?>
|
||||
|
3
web/app/controllers/check_notice.php
Normal file
3
web/app/controllers/check_notice.php
Normal file
@ -0,0 +1,3 @@
|
||||
<?php
|
||||
|
||||
die(json_encode(UOJNotice::fetch(UOJTime::str2time(UOJRequest::post('last_time')))));
|
@ -1,69 +1,24 @@
|
||||
<?php
|
||||
function validateZan() {
|
||||
if (!validateUInt($_POST['id'])) {
|
||||
|
||||
function validateZan() {
|
||||
if (!validateUInt($_POST['id']))
|
||||
return false;
|
||||
}
|
||||
if (!validateInt($_POST['delta'])) {
|
||||
if (!validateInt($_POST['delta']))
|
||||
return false;
|
||||
}
|
||||
if ($_POST['delta'] != 1 && $_POST['delta'] != -1) {
|
||||
if ($_POST['delta'] != 1 && $_POST['delta'] != -1)
|
||||
return false;
|
||||
}
|
||||
if ($_POST['type'] != 'B' && $_POST['type'] != 'BC' && $_POST['type'] != 'P' && $_POST['type'] != 'C') {
|
||||
if (!ClickZans::getTable($_POST['type']))
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
if (!validateZan()) {
|
||||
}
|
||||
if (!validateZan()) {
|
||||
die('<div class="text-danger">failed</div>');
|
||||
}
|
||||
if ($myUser == null) {
|
||||
die('<div class="text-danger">please <a href="'.HTML::url('/login').'">log in</a></div>');
|
||||
}
|
||||
}
|
||||
if (!Auth::check()) {
|
||||
die('<div class="text-danger">please <a href="' . HTML::url('/login') . '">log in</a></div>');
|
||||
}
|
||||
if (!ClickZans::canClickZan($_POST['id'], $_POST['type'], Auth::user())) {
|
||||
die('<div class="text-danger">no permission</div>');
|
||||
}
|
||||
|
||||
$id = $_POST['id'];
|
||||
$delta = $_POST['delta'];
|
||||
$type = $_POST['type'];
|
||||
$show_text = isset($_POST['show-text']) && $_POST['show-text'] != 'false';
|
||||
|
||||
switch ($type) {
|
||||
case 'B':
|
||||
$table_name = 'blogs';
|
||||
break;
|
||||
case 'BC':
|
||||
$table_name = 'blogs_comments';
|
||||
break;
|
||||
case 'P':
|
||||
$table_name = 'problems';
|
||||
break;
|
||||
case 'C':
|
||||
$table_name = 'contests';
|
||||
break;
|
||||
}
|
||||
|
||||
$cur = queryZanVal($id, $type, $myUser);
|
||||
|
||||
if ($cur != $delta) {
|
||||
$row = DB::selectFirst("select zan from $table_name where id = $id");
|
||||
if ($row == null) {
|
||||
die('<div class="text-danger">failed</div>');
|
||||
}
|
||||
$cur += $delta;
|
||||
if ($cur == 0) {
|
||||
DB::query("delete from click_zans where username = '{$myUser['username']}' and type = '$type' and target_id = $id");
|
||||
} elseif ($cur != $delta) {
|
||||
DB::query("update click_zans set val = '$cur' where username = '{$myUser['username']}' and type = '$type' and target_id = $id");
|
||||
} else {
|
||||
DB::query("insert into click_zans (username, type, target_id, val) values ('{$myUser['username']}', '$type', $id, $cur)");
|
||||
}
|
||||
$cnt = $row['zan'] + $delta;
|
||||
DB::query("update $table_name set zan = $cnt where id = $id");
|
||||
} else {
|
||||
$row = DB::selectFirst("select zan from $table_name where id = $id");
|
||||
if ($row == null) {
|
||||
die('<div class="text-danger">failed</div>');
|
||||
}
|
||||
$cnt = $row['zan'];
|
||||
}
|
||||
?>
|
||||
<?= getClickZanBlock($type, $id, $cnt, $cur, $show_text) ?>
|
||||
die(ClickZans::click($_POST['id'], $_POST['type'], Auth::user(), $_POST['delta'], $_POST['show-text']));
|
||||
|
@ -1,41 +1,29 @@
|
||||
<?php
|
||||
requireLib('bootstrap5');
|
||||
requirePHPLib('form');
|
||||
requireLib('bootstrap5');
|
||||
requirePHPLib('form');
|
||||
|
||||
if (!validateUInt($_GET['id']) || !($contest = queryContest($_GET['id']))) {
|
||||
become404Page();
|
||||
}
|
||||
Auth::check() || redirectToLogin();
|
||||
UOJContest::init(UOJRequest::get('id')) || UOJResponse::page404();
|
||||
UOJContest::cur()->userCanParticipateNow(Auth::user()) || UOJResponse::page403();
|
||||
UOJContest::cur()->userHasMarkedParticipated(Auth::user()) && redirectTo(UOJContest::cur()->getUri());
|
||||
|
||||
genMoreContestInfo($contest);
|
||||
$confirm_form = new UOJBs4Form('confirm');
|
||||
$confirm_form->submit_button_config['class_str'] = 'btn btn-primary mt-3';
|
||||
$confirm_form->submit_button_config['text'] = '我已核对信息,确认参加比赛';
|
||||
$confirm_form->handle = function () {
|
||||
UOJContest::cur()->markUserAsParticipated(Auth::user());
|
||||
};
|
||||
$confirm_form->succ_href = '/contest/' . UOJContest::info('id');
|
||||
$confirm_form->runAtServer();
|
||||
?>
|
||||
|
||||
if (!Auth::check()) {
|
||||
redirectToLogin();
|
||||
} elseif (!hasRegistered($myUser, $contest)) {
|
||||
redirectTo("/contest/{$contest['id']}/register");
|
||||
} elseif ($contest['cur_progress'] < CONTEST_IN_PROGRESS) {
|
||||
redirectTo('/contests');
|
||||
} elseif (hasParticipated($myUser, $contest) || $contest['cur_progress'] > CONTEST_IN_PROGRESS) {
|
||||
redirectTo("/contest/{$contest['id']}");
|
||||
}
|
||||
|
||||
$confirm_form = new UOJForm('confirm');
|
||||
$confirm_form->submit_button_config['class_str'] = 'btn btn-primary';
|
||||
$confirm_form->submit_button_config['margin_class'] = 'mt-3';
|
||||
$confirm_form->submit_button_config['text'] = '我已核对信息,确认参加比赛';
|
||||
$confirm_form->handle = function() use ($myUser, $contest) {
|
||||
DB::update("update contests_registrants set has_participated = 1 where username = '{$myUser['username']}' and contest_id = {$contest['id']}");
|
||||
};
|
||||
$confirm_form->succ_href = "/contest/{$contest['id']}";
|
||||
$confirm_form->runAtServer();
|
||||
?>
|
||||
|
||||
<?php echoUOJPageHeader('确认参赛 - ' . HTML::stripTags($contest['name'])) ?>
|
||||
<?php echoUOJPageHeader('确认参赛 - ' . UOJContest::info('name')) ?>
|
||||
|
||||
<div class="card mw-100 mx-auto" style="width:800px">
|
||||
<div class="card-body">
|
||||
<h1 class="h2 card-title text-center mb-3">确认参赛</h1>
|
||||
<div class="card-body">
|
||||
<h1 class="card-title text-center mb-3">确认参赛</h1>
|
||||
|
||||
<p class="card-text text-center">您即将参加比赛 “<b><?= $contest['name'] ?></b>”,请在正式参赛前仔细核对以下比赛信息:</p>
|
||||
<p class="card-text text-center">您即将参加比赛 “<b><?= UOJContest::info('name') ?></b>”,请在正式参赛前仔细核对以下比赛信息:</p>
|
||||
|
||||
<div class="table-responsive mx-auto" style="width:500px">
|
||||
<table class="table">
|
||||
@ -48,30 +36,30 @@
|
||||
<tbody>
|
||||
<tr>
|
||||
<td class="text-center">比赛名称</td>
|
||||
<td><?= $contest['name'] ?></td>
|
||||
<td><?= UOJContest::info('name') ?></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="text-center">参赛选手</td>
|
||||
<td><?= getUserLink($myUser['username']) ?></td>
|
||||
<td><?= getUserLink(Auth::id()) ?></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="text-center">开始时间</td>
|
||||
<td><?= $contest['start_time_str'] ?></td>
|
||||
<td><?= UOJContest::info('start_time_str') ?></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="text-center">结束时间</td>
|
||||
<td><?= $contest['end_time_str'] ?></td>
|
||||
<td><?= UOJContest::info('end_time_str') ?></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="text-center">比赛赛制</td>
|
||||
<td><?= $contest['extra_config']['contest_type'] ?: 'OI' ?></td>
|
||||
<td><?= UOJContest::cur()->basicRule() ?></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<?php $confirm_form->printHTML() ?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php echoUOJPageFooter() ?>
|
||||
|
@ -1,65 +1,39 @@
|
||||
<?php
|
||||
requireLib('bootstrap5');
|
||||
requireLib('mathjax');
|
||||
requirePHPLib('form');
|
||||
requireLib('bootstrap5');
|
||||
requireLib('mathjax');
|
||||
requirePHPLib('form');
|
||||
requirePHPLib('judger');
|
||||
|
||||
if (!Auth::check() && UOJConfig::$data['switch']['force-login']) {
|
||||
redirectToLogin();
|
||||
}
|
||||
Auth::check() || redirectToLogin();
|
||||
|
||||
if (!validateUInt($_GET['id']) || !($contest = queryContest($_GET['id']))) {
|
||||
become404Page();
|
||||
}
|
||||
genMoreContestInfo($contest);
|
||||
UOJContest::init(UOJRequest::get('id')) || UOJResponse::page404();
|
||||
UOJContest::cur()->userCanView(Auth::user(), ['ensure' => true, 'check-register' => true]);
|
||||
|
||||
if (!hasContestPermission($myUser, $contest)) {
|
||||
if ($contest['cur_progress'] == CONTEST_NOT_STARTED) {
|
||||
redirectTo("/contest/{$contest['id']}/register");
|
||||
} elseif ($contest['cur_progress'] == CONTEST_IN_PROGRESS) {
|
||||
if (Auth::check()) {
|
||||
if (!hasParticipated($myUser, $contest)) {
|
||||
redirectTo("/contest/{$contest['id']}/confirm");
|
||||
}
|
||||
} else {
|
||||
redirectToLogin();
|
||||
}
|
||||
} else {
|
||||
if (!hasRegistered($myUser, $contest) && !isNormalUser($myUser) && UOJConfig::$data['switch']['force-login']) {
|
||||
become403Page();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if ($contest['cur_progress'] == CONTEST_IN_PROGRESS) {
|
||||
if (hasRegistered($myUser, $contest)) {
|
||||
if (!hasParticipated($myUser, $contest)) {
|
||||
redirectTo("/contest/{$contest['id']}/confirm");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$contest = UOJContest::info();
|
||||
$is_manager = UOJContest::cur()->userCanManage(Auth::user());
|
||||
|
||||
if (isset($_GET['tab'])) {
|
||||
if (isset($_GET['tab'])) {
|
||||
$cur_tab = $_GET['tab'];
|
||||
} else {
|
||||
} else {
|
||||
$cur_tab = 'dashboard';
|
||||
}
|
||||
}
|
||||
|
||||
$tabs_info = array(
|
||||
'dashboard' => array(
|
||||
$tabs_info = [
|
||||
'dashboard' => [
|
||||
'name' => UOJLocale::get('contests::contest dashboard'),
|
||||
'url' => "/contest/{$contest['id']}"
|
||||
),
|
||||
'submissions' => array(
|
||||
],
|
||||
'submissions' => [
|
||||
'name' => UOJLocale::get('contests::contest submissions'),
|
||||
'url' => "/contest/{$contest['id']}/submissions"
|
||||
),
|
||||
'standings' => array(
|
||||
],
|
||||
'standings' => [
|
||||
'name' => UOJLocale::get('contests::contest standings'),
|
||||
'url' => "/contest/{$contest['id']}/standings"
|
||||
),
|
||||
);
|
||||
],
|
||||
];
|
||||
|
||||
if ($contest['cur_progress'] > CONTEST_TESTING) {
|
||||
if ($contest['cur_progress'] > CONTEST_TESTING) {
|
||||
$tabs_info['after_contest_standings'] = array(
|
||||
'name' => UOJLocale::get('contests::after contest standings'),
|
||||
'url' => "/contest/{$contest['id']}/after_contest_standings"
|
||||
@ -68,105 +42,32 @@
|
||||
'name' => UOJLocale::get('contests::contest self reviews'),
|
||||
'url' => "/contest/{$contest['id']}/self_reviews"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (hasContestPermission(Auth::user(), $contest)) {
|
||||
if ($is_manager) {
|
||||
$tabs_info['backstage'] = array(
|
||||
'name' => UOJLocale::get('contests::contest backstage'),
|
||||
'url' => "/contest/{$contest['id']}/backstage"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (!isset($tabs_info[$cur_tab])) {
|
||||
become404Page();
|
||||
}
|
||||
isset($tabs_info[$cur_tab]) || UOJResponse::page404();
|
||||
|
||||
if (isset($_POST['check_notice'])) {
|
||||
$result = DB::query("select * from contests_notice where contest_id = '${contest['id']}' order by time desc limit 10");
|
||||
$ch = array();
|
||||
$flag = false;
|
||||
try {
|
||||
while ($row = DB::fetch($result)) {
|
||||
if (new DateTime($row['time']) > new DateTime($_POST['last_time'])) {
|
||||
$ch[] = $row['title'].': '.$row['content'];
|
||||
}
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
}
|
||||
global $myUser;
|
||||
$result = DB::query("select * from contests_asks where contest_id='${contest['id']}' and username='${myUser['username']}' order by reply_time desc limit 10");
|
||||
try {
|
||||
while ($row = DB::fetch($result)) {
|
||||
if (new DateTime($row['reply_time']) > new DateTime($_POST['last_time'])) {
|
||||
$ch[] = $row['question'].': '.$row['answer'];
|
||||
}
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
}
|
||||
if ($ch) {
|
||||
die(json_encode(array('msg' => $ch, 'time' => UOJTime::$time_now_str)));
|
||||
} else {
|
||||
die(json_encode(array('time' => UOJTime::$time_now_str)));
|
||||
}
|
||||
}
|
||||
|
||||
if (isSuperUser($myUser) || isContestJudger($myUser)) {
|
||||
if (isSuperUser($myUser) || isContestJudger($myUser)) {
|
||||
if (CONTEST_PENDING_FINAL_TEST <= $contest['cur_progress']) {
|
||||
$start_test_form = new UOJForm('start_test');
|
||||
$start_test_form->handle = function() {
|
||||
global $contest;
|
||||
$result = DB::query("select id, problem_id, content from submissions where contest_id = {$contest['id']}");
|
||||
while ($submission = DB::fetch($result, MYSQLI_ASSOC)) {
|
||||
if (!isset($contest['extra_config']["problem_{$submission['problem_id']}"])) {
|
||||
$content = json_decode($submission['content'], true);
|
||||
if (isset($content['final_test_config'])) {
|
||||
$content['config'] = $content['final_test_config'];
|
||||
unset($content['final_test_config']);
|
||||
}
|
||||
if (isset($content['first_test_config'])) {
|
||||
unset($content['first_test_config']);
|
||||
}
|
||||
$esc_content = DB::escape(json_encode($content));
|
||||
DB::update("update submissions set judge_time = NULL, result = '', score = NULL, status = 'Waiting Rejudge', content = '$esc_content' where id = {$submission['id']}");
|
||||
}
|
||||
}
|
||||
DB::query("update contests set status = 'testing' where id = {$contest['id']}");
|
||||
$start_test_form = new UOJBs4Form('start_test');
|
||||
$start_test_form->handle = function () {
|
||||
UOJContest::finalTest();
|
||||
};
|
||||
$start_test_form->submit_button_config['class_str'] = 'btn btn-danger d-block w-100';
|
||||
$start_test_form->submit_button_config['smart_confirm'] = '';
|
||||
if ($contest['cur_progress'] < CONTEST_TESTING) {
|
||||
$start_test_form->submit_button_config['text'] = '开始最终测试';
|
||||
} else {
|
||||
$start_test_form->submit_button_config['text'] = '重新开始最终测试';
|
||||
}
|
||||
|
||||
$start_test_form->submit_button_config['text'] = UOJContest::cur()->labelForFinalTest();
|
||||
$start_test_form->runAtServer();
|
||||
}
|
||||
if ($contest['cur_progress'] >= CONTEST_TESTING) {
|
||||
$publish_result_form = new UOJForm('publish_result');
|
||||
$publish_result_form->handle = function() {
|
||||
// time config
|
||||
set_time_limit(0);
|
||||
ignore_user_abort(true);
|
||||
|
||||
global $contest;
|
||||
$contest_data = queryContestData($contest);
|
||||
$problems_count = DB::selectCount("select count(*) from contests_problems where contest_id = {$contest['id']} order by dfn, problem_id");
|
||||
calcStandings($contest, $contest_data, $score, $standings, true);
|
||||
|
||||
for ($i = 0; $i < count($standings); $i++) {
|
||||
DB::query("update contests_registrants set rank = {$standings[$i][3]} where contest_id = {$contest['id']} and username = '{$standings[$i][2][0]}'");
|
||||
|
||||
$user_link = getUserLink($standings[$i][2][0]);
|
||||
$total_score = $problems_count * 100;
|
||||
$tail = $standings[$i][0] == $total_score ? ',请继续保持!' : ',请继续努力!';
|
||||
$content = <<<EOD
|
||||
<p>{$user_link} 您好:</p>
|
||||
<p>您参与的比赛 <a href="/contest/{$contest['id']}">{$contest['name']}</a> 现已结束,您的成绩为 <a class="uoj-score" data-max="{$total_score}">{$standings[$i][0]}</a>{$tail}</p>
|
||||
EOD;
|
||||
sendSystemMsg($standings[$i][2][0], '比赛成绩公布', $content);
|
||||
}
|
||||
DB::query("update contests set status = 'finished' where id = {$contest['id']}");
|
||||
$publish_result_form = new UOJBs4Form('publish_result');
|
||||
$publish_result_form->handle = function () {
|
||||
UOJContest::announceOfficialResults();
|
||||
};
|
||||
$publish_result_form->submit_button_config['class_str'] = 'btn btn-danger d-block w-100';
|
||||
$publish_result_form->submit_button_config['smart_confirm'] = '';
|
||||
@ -174,13 +75,16 @@ EOD;
|
||||
|
||||
$publish_result_form->runAtServer();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($cur_tab == 'dashboard') {
|
||||
if ($cur_tab == 'dashboard') {
|
||||
if ($contest['cur_progress'] <= CONTEST_IN_PROGRESS) {
|
||||
$post_question = new UOJForm('post_question');
|
||||
$post_question->addVTextArea('qcontent', '问题', '',
|
||||
function($content) {
|
||||
$post_question = new UOJBs4Form('post_question');
|
||||
$post_question->addVTextArea(
|
||||
'qcontent',
|
||||
'问题',
|
||||
'',
|
||||
function ($content, &$vdata) {
|
||||
if (!Auth::check()) {
|
||||
return '您尚未登录';
|
||||
}
|
||||
@ -190,78 +94,107 @@ EOD;
|
||||
if (strlen($content) > 140 * 4) {
|
||||
return '问题太长';
|
||||
}
|
||||
|
||||
$vdata['content'] = HTML::escape($content);
|
||||
|
||||
return '';
|
||||
},
|
||||
null
|
||||
);
|
||||
$post_question->handle = function() {
|
||||
global $contest;
|
||||
$content = DB::escape($_POST['qcontent']);
|
||||
$username = Auth::id();
|
||||
DB::query("insert into contests_asks (contest_id, question, username, post_time, is_hidden) values ('{$contest['id']}', '$content', '$username', now(), 1)");
|
||||
$post_question->handle = function (&$vdata) use ($contest) {
|
||||
DB::insert([
|
||||
"insert into contests_asks",
|
||||
"(contest_id, question, answer, username, post_time, is_hidden)",
|
||||
"values", DB::tuple([$contest['id'], $vdata['content'], '', Auth::id(), DB::now(), 1])
|
||||
]);
|
||||
};
|
||||
$post_question->runAtServer();
|
||||
} else {
|
||||
$post_question = null;
|
||||
}
|
||||
} elseif ($cur_tab == 'backstage') {
|
||||
} elseif ($cur_tab == 'backstage') {
|
||||
if (isSuperUser(Auth::user())) {
|
||||
$post_notice = new UOJForm('post_notice');
|
||||
$post_notice->addVInput('title', 'text', '标题', '',
|
||||
function($title) {
|
||||
$post_notice = new UOJBs4Form('post_notice');
|
||||
$post_notice->addInput(
|
||||
'title',
|
||||
'text',
|
||||
'标题',
|
||||
'',
|
||||
function ($title, &$vdata) {
|
||||
if (!$title) {
|
||||
return '标题不能为空';
|
||||
}
|
||||
|
||||
$vdata['title'] = HTML::escape($title);
|
||||
|
||||
return '';
|
||||
},
|
||||
null
|
||||
);
|
||||
$post_notice->addVTextArea('content', '正文', '',
|
||||
function($content) {
|
||||
$post_notice->addTextArea(
|
||||
'content',
|
||||
'正文',
|
||||
'',
|
||||
function ($content, &$vdata) {
|
||||
if (!$content) {
|
||||
return '公告不能为空';
|
||||
}
|
||||
|
||||
$vdata['content'] = HTML::escape($content);
|
||||
|
||||
return '';
|
||||
},
|
||||
null
|
||||
);
|
||||
$post_notice->handle = function() {
|
||||
global $contest;
|
||||
$title = DB::escape($_POST['title']);
|
||||
$content = DB::escape($_POST['content']);
|
||||
DB::insert("insert into contests_notice (contest_id, title, content, time) values ('{$contest['id']}', '$title', '$content', now())");
|
||||
$post_notice->handle = function (&$vdata) use ($contest) {
|
||||
DB::insert([
|
||||
"insert into contests_notice",
|
||||
"(contest_id, title, content, time)",
|
||||
"values", DB::tuple([$contest['id'], $vdata['title'], $vdata['content'], DB::now()])
|
||||
]);
|
||||
};
|
||||
$post_notice->runAtServer();
|
||||
} else {
|
||||
$post_notice = null;
|
||||
}
|
||||
|
||||
if (hasContestPermission(Auth::user(), $contest)) {
|
||||
$reply_question = new UOJForm('reply_question');
|
||||
$reply_question->addHidden('rid', '0',
|
||||
function($id) {
|
||||
global $contest;
|
||||
|
||||
if ($is_manager) {
|
||||
$reply_question = new UOJBs4Form('reply_question');
|
||||
$reply_question->addHidden(
|
||||
'rid',
|
||||
'0',
|
||||
function ($id, &$vdata) use ($contest) {
|
||||
if (!validateUInt($id)) {
|
||||
return '无效ID';
|
||||
}
|
||||
$q = DB::selectFirst("select * from contests_asks where id = $id");
|
||||
if ($q['contest_id'] != $contest['id']) {
|
||||
$q = DB::selectFirst([
|
||||
"select * from contests_asks",
|
||||
"where", [
|
||||
"id" => $id,
|
||||
"contest_id" => $contest['id']
|
||||
]
|
||||
]);
|
||||
if (!$q) {
|
||||
return '无效ID';
|
||||
}
|
||||
$vdata['id'] = $id;
|
||||
return '';
|
||||
},
|
||||
null
|
||||
);
|
||||
$reply_question->addVSelect('rtype', [
|
||||
'public' => '公开',
|
||||
'public' => '公开(如果该问题反复被不同人提出,或指出了题目中的错误,请选择该项)',
|
||||
'private' => '非公开',
|
||||
'statement' => '请仔细阅读题面(非公开)',
|
||||
'no_comment' => '无可奉告(非公开)',
|
||||
'no_play' => '请认真比赛(非公开)',
|
||||
], '回复类型', 'private');
|
||||
$reply_question->addVTextArea('rcontent', '回复', '',
|
||||
function($content) {
|
||||
$reply_question->addVTextArea(
|
||||
'rcontent',
|
||||
'回复',
|
||||
'',
|
||||
function ($content, &$vdata) {
|
||||
if (!Auth::check()) {
|
||||
return '您尚未登录';
|
||||
}
|
||||
@ -273,13 +206,13 @@ EOD;
|
||||
}
|
||||
break;
|
||||
}
|
||||
$vdata['content'] = HTML::escape($content);
|
||||
return '';
|
||||
},
|
||||
null
|
||||
);
|
||||
$reply_question->handle = function() {
|
||||
global $contest;
|
||||
$content = DB::escape($_POST['rcontent']);
|
||||
$reply_question->handle = function (&$vdata) use ($contest) {
|
||||
$content = $vdata['content'];
|
||||
$is_hidden = 1;
|
||||
switch ($_POST['rtype']) {
|
||||
case 'statement':
|
||||
@ -297,25 +230,48 @@ EOD;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
DB::update("update contests_asks set answer = '$content', reply_time = now(), is_hidden = {$is_hidden} where id = {$_POST['rid']}");
|
||||
DB::update([
|
||||
"update contests_asks",
|
||||
"set", [
|
||||
"answer" => $content,
|
||||
"reply_time" => DB::now(),
|
||||
"is_hidden" => $is_hidden
|
||||
], "where", ["id" => $vdata['id']]
|
||||
]);
|
||||
};
|
||||
$reply_question->runAtServer();
|
||||
} else {
|
||||
$reply_question = null;
|
||||
}
|
||||
} elseif ($cur_tab == 'self_reviews') {
|
||||
if (hasParticipated(Auth::user(), $contest)) {
|
||||
$self_reviews_update_form = new UOJForm('self_review_update');
|
||||
} elseif ($cur_tab == 'self_reviews') {
|
||||
if (UOJContest::cur()->userHasMarkedParticipated(Auth::user())) {
|
||||
$self_reviews_update_form = new UOJBs4Form('self_review_update');
|
||||
$self_reviews_update_form->ctrl_enter_submit = true;
|
||||
|
||||
$contest_problems = DB::selectAll("select problem_id from contests_problems where contest_id = {$contest['id']} order by dfn, problem_id");
|
||||
$contest_problems = DB::selectAll([
|
||||
"select problem_id",
|
||||
"from", "contests_problems",
|
||||
"where", ["contest_id" => $contest['id']],
|
||||
"order by level, problem_id"
|
||||
]);
|
||||
for ($i = 0; $i < count($contest_problems); $i++) {
|
||||
$contest_problems[$i]['problem'] = queryProblemBrief($contest_problems[$i]['problem_id']);
|
||||
$contest_problems[$i]['problem'] = UOJContestProblem::query($contest_problems[$i]['problem_id']);
|
||||
}
|
||||
|
||||
for ($i = 0; $i < count($contest_problems); $i++) {
|
||||
$content = DB::selectFirst("select content from contests_reviews where contest_id = {$contest['id']} and problem_id = {$contest_problems[$i]['problem_id']} and poster = '{$myUser['username']}'")['content'];
|
||||
$self_reviews_update_form->addVTextArea('self_review_update__problem_' . chr(ord('A') + $i), '<b>' . chr(ord('A') + $i) . '</b>: ' . $contest_problems[$i]['problem']['title'], $content,
|
||||
$content = DB::selectFirst([
|
||||
"select content",
|
||||
"from", "contests_reviews",
|
||||
"where", [
|
||||
"contest_id" => $contest['id'],
|
||||
"problem_id" => $contest_problems[$i]['problem_id'],
|
||||
"poster" => Auth::id(),
|
||||
],
|
||||
]);
|
||||
$self_reviews_update_form->addVTextArea(
|
||||
'self_review_update__problem_' . $contest_problems[$i]['problem']->getLetter(),
|
||||
'<b>' . $contest_problems[$i]['problem']->getLetter() . '</b>: ' . $contest_problems[$i]['problem']->info['title'],
|
||||
$content['content'],
|
||||
function ($content) {
|
||||
if (strlen($content) > 200) {
|
||||
return '总结不能超过200字';
|
||||
@ -328,8 +284,19 @@ EOD;
|
||||
);
|
||||
}
|
||||
|
||||
$content = DB::selectFirst("select content from contests_reviews where contest_id = {$contest['id']} and problem_id = -1 and poster = '{$myUser['username']}'")['content'];
|
||||
$self_reviews_update_form->addVTextArea('self_review_update__overall', '比赛总结', $content,
|
||||
$content = DB::selectFirst([
|
||||
"select content",
|
||||
"from", "contests_reviews",
|
||||
"where", [
|
||||
"contest_id" => $contest['id'],
|
||||
"problem_id" => -1,
|
||||
"poster" => Auth::id(),
|
||||
],
|
||||
]);
|
||||
$self_reviews_update_form->addVTextArea(
|
||||
'self_review_update__overall',
|
||||
'比赛总结',
|
||||
$content['content'],
|
||||
function ($content) {
|
||||
if (strlen($content) > 200) {
|
||||
return '总结不能超过200字';
|
||||
@ -341,42 +308,68 @@ EOD;
|
||||
true
|
||||
);
|
||||
|
||||
$self_reviews_update_form->handle = function() {
|
||||
$self_reviews_update_form->handle = function () use ($contest, $contest_problems) {
|
||||
global $contest, $contest_problems, $myUser;
|
||||
|
||||
for ($i = 0; $i < count($contest_problems); $i++) {
|
||||
if (isset($_POST['self_review_update__problem_' . chr(ord('A') + $i)])) {
|
||||
$esc_content = DB::escape($_POST['self_review_update__problem_' . chr(ord('A') + $i)]);
|
||||
if (isset($_POST['self_review_update__problem_' . $contest_problems[$i]['problem']->getLetter()])) {
|
||||
$esc_content = DB::escape($_POST['self_review_update__problem_' . $contest_problems[$i]['problem']->getLetter()]);
|
||||
$problem_id = $contest_problems[$i]['problem_id'];
|
||||
|
||||
DB::query("replace into contests_reviews (contest_id, problem_id, poster, content) values ({$contest['id']}, $problem_id, '{$myUser['username']}', '$esc_content')");
|
||||
DB::query([
|
||||
"replace into contests_reviews",
|
||||
"(contest_id, problem_id, poster, content)",
|
||||
"values", DB::tuple([$contest['id'], $problem_id, Auth::id(), $esc_content]),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($_POST['self_review_update__overall'])) {
|
||||
$esc_content = DB::escape($_POST['self_review_update__overall']);
|
||||
DB::query("replace into contests_reviews (contest_id, problem_id, poster, content) values ({$contest['id']}, -1, '{$myUser['username']}', '$esc_content')");
|
||||
DB::query([
|
||||
"replace into contests_reviews",
|
||||
"(contest_id, problem_id, poster, content)",
|
||||
"values", DB::tuple([$contest['id'], -1, Auth::id(), $esc_content]),
|
||||
]);
|
||||
}
|
||||
};
|
||||
|
||||
$self_reviews_update_form->runAtServer();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function echoDashboard() {
|
||||
global $contest, $post_notice, $post_question, $reply_question;
|
||||
function echoDashboard() {
|
||||
global $contest, $post_question;
|
||||
|
||||
$myname = Auth::id();
|
||||
$contest_problems = DB::selectAll("select contests_problems.problem_id, best_ac_submissions.submission_id from contests_problems left join best_ac_submissions on contests_problems.problem_id = best_ac_submissions.problem_id and submitter = '{$myname}' where contest_id = {$contest['id']} order by contests_problems.dfn, contests_problems.problem_id");
|
||||
$contest_problems = DB::selectAll([
|
||||
"select contests_problems.problem_id, best_ac_submissions.submission_id",
|
||||
"from", "contests_problems", "left join", "best_ac_submissions",
|
||||
"on", [
|
||||
"contests_problems.problem_id" => DB::raw("best_ac_submissions.problem_id"),
|
||||
"best_ac_submissions.submitter" => Auth::id()
|
||||
], "where", ["contest_id" => $contest['id']],
|
||||
"order by contests_problems.level, contests_problems.problem_id"
|
||||
]);
|
||||
|
||||
for ($i = 0; $i < count($contest_problems); $i++) {
|
||||
$contest_problems[$i]['problem'] = queryProblemBrief($contest_problems[$i]['problem_id']);
|
||||
$contest_problems[$i]['problem'] = UOJContestProblem::query($contest_problems[$i]['problem_id']);
|
||||
$contest_problems[$i]['problem']->problem_number = $i;
|
||||
}
|
||||
|
||||
$contest_notice = DB::selectAll("select * from contests_notice where contest_id = {$contest['id']} order by time desc");
|
||||
$contest_notice = DB::selectAll([
|
||||
"select * from contests_notice",
|
||||
"where", ["contest_id" => $contest['id']],
|
||||
"order by time desc"
|
||||
]);
|
||||
|
||||
if (Auth::check()) {
|
||||
$my_questions = DB::selectAll("select * from contests_asks where contest_id = {$contest['id']} and username = '{$myname}' order by post_time desc");
|
||||
$my_questions = DB::selectAll([
|
||||
"select * from contests_asks",
|
||||
"where", [
|
||||
"contest_id" => $contest['id'],
|
||||
"username" => Auth::id()
|
||||
], "order by post_time desc"
|
||||
]);
|
||||
$my_questions_pag = new Paginator([
|
||||
'data' => $my_questions
|
||||
]);
|
||||
@ -385,9 +378,13 @@ EOD;
|
||||
}
|
||||
|
||||
$others_questions_pag = new Paginator([
|
||||
'col_names' => array('*'),
|
||||
'col_names' => ['*'],
|
||||
'table_name' => 'contests_asks',
|
||||
'cond' => "contest_id = {$contest['id']} and username != '{$myname}' and is_hidden = 0",
|
||||
'cond' => [
|
||||
"contest_id" => $contest['id'],
|
||||
["username", "!=", Auth::id()],
|
||||
"is_hidden" => 0
|
||||
],
|
||||
'tail' => 'order by reply_time desc',
|
||||
'page_len' => 10
|
||||
]);
|
||||
@ -398,22 +395,22 @@ EOD;
|
||||
'contest_problems' => $contest_problems,
|
||||
'post_question' => $post_question,
|
||||
'my_questions_pag' => $my_questions_pag,
|
||||
'others_questions_pag' => $others_questions_pag,
|
||||
'others_questions_pag' => $others_questions_pag
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
function echoBackstage() {
|
||||
function echoBackstage() {
|
||||
global $contest, $post_notice, $reply_question;
|
||||
|
||||
$questions_pag = new Paginator([
|
||||
'col_names' => array('*'),
|
||||
'col_names' => ['*'],
|
||||
'table_name' => 'contests_asks',
|
||||
'cond' => "contest_id = {$contest['id']}",
|
||||
'cond' => ["contest_id" => $contest['id']],
|
||||
'tail' => 'order by post_time desc',
|
||||
'page_len' => 50
|
||||
]);
|
||||
|
||||
if ($contest['cur_progress'] < CONTEST_TESTING) {
|
||||
if (UOJContest::cur()->managerCanSeeFinalStandingsTab(Auth::user())) {
|
||||
$contest_data = queryContestData($contest, ['pre_final' => true]);
|
||||
calcStandings($contest, $contest_data, $score, $standings);
|
||||
|
||||
@ -434,94 +431,74 @@ EOD;
|
||||
'questions_pag' => $questions_pag,
|
||||
'standings_data' => $standings_data
|
||||
]);
|
||||
}
|
||||
|
||||
function echoMySubmissions() {
|
||||
$problems = UOJContest::cur()->getProblemIDs();
|
||||
|
||||
$options = [];
|
||||
$options[] = ['value' => 'all', 'text' => '所有题目'];
|
||||
for ($i = 0; $i < count($problems); $i++) {
|
||||
$letter = chr(ord('A') + $i);
|
||||
$options[] = ['value' => $letter, 'text' => "{$letter} 题"];
|
||||
}
|
||||
|
||||
function echoMySubmissions() {
|
||||
global $contest, $myUser;
|
||||
|
||||
$show_all_submissions_status = Cookie::get('show_all_submissions') !== null ? 'checked="checked" ' : '';
|
||||
$show_all_submissions = UOJLocale::get('contests::show all submissions');
|
||||
echo <<<EOD
|
||||
<div class="text-end">
|
||||
<div class="form-check d-inline-block">
|
||||
<input type="checkbox" class="form-check-input" id="input-show_all_submissions" $show_all_submissions_status />
|
||||
<label class="form-check-label" for="input-show_all_submissions">
|
||||
$show_all_submissions
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
<script type="text/javascript">
|
||||
$('#input-show_all_submissions').click(function() {
|
||||
if (this.checked) {
|
||||
$.cookie('show_all_submissions', '');
|
||||
$chosen = UOJRequest::get('p');
|
||||
$problem_id = null;
|
||||
if (strlen($chosen) == 1) {
|
||||
$num = ord($chosen) - ord('A');
|
||||
if (0 <= $num && $num < count($problems)) {
|
||||
$problem_id = $problems[$num];
|
||||
} else {
|
||||
$.removeCookie('show_all_submissions');
|
||||
$chosen = 'all';
|
||||
}
|
||||
location.reload();
|
||||
});
|
||||
</script>
|
||||
EOD;
|
||||
|
||||
$config = array(
|
||||
'judge_time_hidden' => '',
|
||||
'table_config' => array(
|
||||
'div_classes' => array('card', 'mb-3', 'table-responsive'),
|
||||
'table_classes' => array('table', 'mb-0', 'uoj-table', 'text-center')
|
||||
),
|
||||
);
|
||||
|
||||
if (Cookie::get('show_all_submissions') !== null) {
|
||||
echoSubmissionsList("contest_id = {$contest['id']}", 'order by id desc', $config, $myUser);
|
||||
} else {
|
||||
echoSubmissionsList("submitter = '{$myUser['username']}' and contest_id = {$contest['id']}", 'order by id desc', $config, $myUser);
|
||||
}
|
||||
$chosen = 'all';
|
||||
}
|
||||
|
||||
function echoStandings($is_after_contest_query = false) {
|
||||
$conds = ['contest_id' => UOJContest::info('id')];
|
||||
if (Cookie::get('show_all_submissions') === null) {
|
||||
$conds += ['submitter' => Auth::id()];
|
||||
}
|
||||
if ($problem_id !== null) {
|
||||
$conds += ['problem_id' => $problem_id];
|
||||
}
|
||||
|
||||
uojIncludeView('contest-submissions', [
|
||||
'show_all_submissions_status' => Cookie::get('show_all_submissions') !== null,
|
||||
'options' => $options,
|
||||
'chosen' => $chosen,
|
||||
'conds' => $conds
|
||||
]);
|
||||
}
|
||||
|
||||
function echoStandings($is_after_contest_query = false) {
|
||||
global $contest;
|
||||
uojIncludeView('contest-standings', ['contest' => $contest] + UOJContest::cur()->queryResult(['after_contest' => $is_after_contest_query]));
|
||||
}
|
||||
|
||||
function echoSelfReviews() {
|
||||
global $contest;
|
||||
|
||||
$contest_data = queryContestData($contest, array(), $is_after_contest_query);
|
||||
calcStandings($contest, $contest_data, $score, $standings);
|
||||
uojIncludeView('contest-reviews', ['contest' => $contest] + UOJContest::cur()->queryResult());
|
||||
}
|
||||
|
||||
uojIncludeView('contest-standings', [
|
||||
'contest' => $contest,
|
||||
'standings' => $standings,
|
||||
'score' => $score,
|
||||
'contest_data' => $contest_data
|
||||
]);
|
||||
}
|
||||
|
||||
function echoReviews() {
|
||||
global $contest;
|
||||
|
||||
$contest_data = queryContestData($contest, array());
|
||||
calcStandings($contest, $contest_data, $score, $standings, false, true);
|
||||
|
||||
uojIncludeView('contest-standings', [
|
||||
'contest' => $contest,
|
||||
'standings' => $standings,
|
||||
'score' => $score,
|
||||
'contest_data' => $contest_data,
|
||||
'show_self_reviews' => true
|
||||
]);
|
||||
}
|
||||
|
||||
$page_header = HTML::stripTags($contest['name']) . ' - ';
|
||||
?>
|
||||
$page_header = HTML::stripTags($contest['name']) . ' - ';
|
||||
?>
|
||||
<?php echoUOJPageHeader(HTML::stripTags($contest['name']) . ' - ' . $tabs_info[$cur_tab]['name'] . ' - ' . UOJLocale::get('contests::contest')) ?>
|
||||
|
||||
<div class="text-center d-md-none mb-3">
|
||||
<h1 class="h2"><?= $contest['name'] ?></h1>
|
||||
<h1><?= $contest['name'] ?></h1>
|
||||
<div class="small text-muted">
|
||||
<?php if ($contest['cur_progress'] <= CONTEST_NOT_STARTED): ?>
|
||||
<?php if ($contest['cur_progress'] <= CONTEST_NOT_STARTED) : ?>
|
||||
<?= UOJLocale::get('contests::not started') ?>
|
||||
<?php elseif ($contest['cur_progress'] <= CONTEST_IN_PROGRESS): ?>
|
||||
<?php elseif ($contest['cur_progress'] <= CONTEST_IN_PROGRESS) : ?>
|
||||
<?= UOJLocale::get('contests::in progress') ?>
|
||||
<?php elseif ($contest['cur_progress'] <= CONTEST_PENDING_FINAL_TEST): ?>
|
||||
<?php elseif ($contest['cur_progress'] <= CONTEST_PENDING_FINAL_TEST) : ?>
|
||||
<?= UOJLocale::get('contests::pending final test') ?>
|
||||
<?php elseif ($contest['cur_progress'] <= CONTEST_TESTING): ?>
|
||||
<?php elseif ($contest['cur_progress'] <= CONTEST_TESTING) : ?>
|
||||
<?= UOJLocale::get('contests::final testing') ?>
|
||||
<?php else: ?>
|
||||
<?php else : ?>
|
||||
<?= UOJLocale::get('contests::ended') ?>
|
||||
<?php endif ?>
|
||||
</div>
|
||||
@ -529,25 +506,25 @@ EOD;
|
||||
|
||||
|
||||
<div class="row">
|
||||
<?php if ($cur_tab == 'standings' || $cur_tab == 'after_contest_standings' || $cur_tab == 'self_reviews'): ?>
|
||||
<?php if ($cur_tab == 'standings' || $cur_tab == 'after_contest_standings' || $cur_tab == 'self_reviews') : ?>
|
||||
<div class="col-12">
|
||||
<?php else: ?>
|
||||
<?php else : ?>
|
||||
<div class="col-md-9">
|
||||
<?php endif ?>
|
||||
<?= HTML::tablist($tabs_info, $cur_tab, 'nav-pills') ?>
|
||||
<?php if ($cur_tab == 'standings' || $cur_tab == 'after_contest_standings' || $cur_tab == 'self_reviews'): ?>
|
||||
<?php if ($cur_tab == 'standings' || $cur_tab == 'after_contest_standings' || $cur_tab == 'self_reviews') : ?>
|
||||
<div class="d-none d-md-block text-center">
|
||||
<h1 class="h2 mt-2 mb-3"><?= $contest['name'] ?></h1>
|
||||
<h1 class="mt-2 mb-3"><?= $contest['name'] ?></h1>
|
||||
<div class="small text-muted">
|
||||
<?php if ($contest['cur_progress'] <= CONTEST_NOT_STARTED): ?>
|
||||
<?php if ($contest['cur_progress'] <= CONTEST_NOT_STARTED) : ?>
|
||||
<?= UOJLocale::get('contests::not started') ?>
|
||||
<?php elseif ($contest['cur_progress'] <= CONTEST_IN_PROGRESS): ?>
|
||||
<?php elseif ($contest['cur_progress'] <= CONTEST_IN_PROGRESS) : ?>
|
||||
<?= UOJLocale::get('contests::in progress') ?>
|
||||
<?php elseif ($contest['cur_progress'] <= CONTEST_PENDING_FINAL_TEST): ?>
|
||||
<?php elseif ($contest['cur_progress'] <= CONTEST_PENDING_FINAL_TEST) : ?>
|
||||
<?= UOJLocale::get('contests::pending final test') ?>
|
||||
<?php elseif ($contest['cur_progress'] <= CONTEST_TESTING): ?>
|
||||
<?php elseif ($contest['cur_progress'] <= CONTEST_TESTING) : ?>
|
||||
<?= UOJLocale::get('contests::final testing') ?>
|
||||
<?php else: ?>
|
||||
<?php else : ?>
|
||||
<?= UOJLocale::get('contests::ended') ?>
|
||||
<?php endif ?>
|
||||
</div>
|
||||
@ -566,14 +543,14 @@ EOD;
|
||||
} elseif ($cur_tab == 'backstage') {
|
||||
echoBackstage();
|
||||
} elseif ($cur_tab == 'self_reviews') {
|
||||
echoReviews();
|
||||
echoSelfReviews();
|
||||
}
|
||||
?>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php if ($cur_tab == 'standings' || $cur_tab == 'after_contest_standings'): ?>
|
||||
<?php elseif ($cur_tab == 'self_reviews'): ?>
|
||||
<?php if ($cur_tab == 'standings' || $cur_tab == 'after_contest_standings') : ?>
|
||||
<?php elseif ($cur_tab == 'self_reviews') : ?>
|
||||
<?php if (isset($self_reviews_update_form)) : ?>
|
||||
<hr />
|
||||
|
||||
@ -583,87 +560,89 @@ EOD;
|
||||
<?php $self_reviews_update_form->printHTML(); ?>
|
||||
</div>
|
||||
<?php endif ?>
|
||||
<?php else: ?>
|
||||
<?php else : ?>
|
||||
<div class="d-md-none">
|
||||
<hr />
|
||||
</div>
|
||||
<div class="col-md-3">
|
||||
<div class="card card-default mb-2">
|
||||
<div class="card-body">
|
||||
<h3 class="h5 card-title text-center">
|
||||
<h3 class="h4 card-title text-center">
|
||||
<a class="text-decoration-none text-body" href="/contest/<?= $contest['id'] ?>">
|
||||
<?= $contest['name'] ?>
|
||||
</a>
|
||||
</h3>
|
||||
<div class="card-text text-center text-muted">
|
||||
<?php if ($contest['cur_progress'] <= CONTEST_IN_PROGRESS): ?>
|
||||
<?php if ($contest['cur_progress'] <= CONTEST_IN_PROGRESS) : ?>
|
||||
<span id="contest-countdown"></span>
|
||||
<script type="text/javascript">
|
||||
$('#contest-countdown').countdown(<?= $contest['end_time']->getTimestamp() - UOJTime::$time_now->getTimestamp() ?>, function(){}, '1.75rem', false);
|
||||
checkContestNotice(<?= $contest['id'] ?>, '<?= UOJTime::$time_now_str ?>');
|
||||
$('#contest-countdown').countdown(<?= $contest['end_time']->getTimestamp() - UOJTime::$time_now->getTimestamp() ?>, function() {}, '1.75rem', false);
|
||||
</script>
|
||||
<?php elseif ($contest['cur_progress'] <= CONTEST_TESTING): ?>
|
||||
<?php if ($contest['cur_progress'] < CONTEST_TESTING): ?>
|
||||
<?php elseif ($contest['cur_progress'] <= CONTEST_TESTING) : ?>
|
||||
<?php if ($contest['cur_progress'] < CONTEST_TESTING) : ?>
|
||||
<?= UOJLocale::get('contests::contest pending final test') ?>
|
||||
<?php else: ?>
|
||||
<?php else : ?>
|
||||
<?php
|
||||
$total = DB::selectCount("select count(*) from submissions where contest_id = {$contest['id']}");
|
||||
$n_judged = DB::selectCount("select count(*) from submissions where contest_id = {$contest['id']} and status = 'Judged'");
|
||||
$rop = $total == 0 ? 100 : (int)($n_judged / $total * 100);
|
||||
?>
|
||||
<?= UOJLocale::get('contests::contest final testing') ?>
|
||||
<?= UOJLocale::get('contests::final testing') ?>
|
||||
(<?= $rop ?>%)
|
||||
<?php endif ?>
|
||||
<?php else: ?>
|
||||
<?php else : ?>
|
||||
<?= UOJLocale::get('contests::contest ended') ?>
|
||||
<?php endif ?>
|
||||
</div>
|
||||
</div>
|
||||
<div class="card-footer bg-transparent">
|
||||
比赛评价:<?= getClickZanBlock('C', $contest['id'], $contest['zan']) ?>
|
||||
比赛评价:<?= ClickZans::getBlock('C', $contest['id'], $contest['zan']) ?>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php if (!isset($contest['extra_config']['contest_type']) || $contest['extra_config']['contest_type'] == 'OI'): ?>
|
||||
<?php if (UOJContest::cur()->basicRule() === 'OI') : ?>
|
||||
<p>此次比赛为 OI 赛制。</p>
|
||||
<p><strong>注意:比赛时只显示测样例的结果。</strong></p>
|
||||
<?php elseif ($contest['extra_config']['contest_type'] == 'IOI'): ?>
|
||||
<?php elseif (UOJContest::cur()->basicRule() === 'ACM') : ?>
|
||||
<p>此次比赛为 ACM 赛制。</p>
|
||||
<p><strong>封榜时间:<?= $contest['frozen_time']->format('Y-m-d H:i:s') ?></strong></p>
|
||||
<?php elseif (UOJContest::cur()->basicRule() === 'IOI') : ?>
|
||||
<p>此次比赛为 IOI 赛制。</p>
|
||||
<p><strong>注意:比赛时显示测试所有数据的结果,但无法看到详细信息。</strong></p>
|
||||
<p>比赛时显示的得分即最终得分。</p>
|
||||
<?php endif ?>
|
||||
|
||||
<a href="/contest/<?= $contest['id'] ?>/registrants" class="btn btn-secondary d-block mt-2">
|
||||
<?= UOJLocale::get('contests::contest registrants') ?>
|
||||
</a>
|
||||
<?php if (isSuperUser($myUser)): ?>
|
||||
<a href="/contest/<?=$contest['id']?>/manage" class="btn btn-primary d-block mt-2">
|
||||
<?php if (isSuperUser($myUser)) : ?>
|
||||
<a href="/contest/<?= $contest['id'] ?>/manage" class="btn btn-primary d-block mt-2">
|
||||
管理
|
||||
</a>
|
||||
<?php endif ?>
|
||||
<?php if (isset($start_test_form)): ?>
|
||||
<?php if (isset($start_test_form)) : ?>
|
||||
<div class="mt-2">
|
||||
<?php $start_test_form->printHTML(); ?>
|
||||
</div>
|
||||
<?php endif ?>
|
||||
<?php if (isset($publish_result_form)): ?>
|
||||
<?php if (isset($publish_result_form)) : ?>
|
||||
<div class="mt-2">
|
||||
<?php $publish_result_form->printHTML(); ?>
|
||||
</div>
|
||||
<?php endif ?>
|
||||
<?php if ($contest['extra_config']['links']): ?>
|
||||
<?php if ($contest['extra_config']['links']) : ?>
|
||||
<div class="card card-default border-info mt-3">
|
||||
<div class="card-header bg-info">
|
||||
<h3 class="h4 card-title">比赛资料</h3>
|
||||
<h3 class="card-title">比赛资料</h3>
|
||||
</div>
|
||||
<div class="list-group list-group-flush">
|
||||
<?php foreach ($contest['extra_config']['links'] as $link): ?>
|
||||
<a href="/blogs/<?=$link[1]?>" class="list-group-item"><?=$link[0]?></a>
|
||||
<?php foreach ($contest['extra_config']['links'] as $link) : ?>
|
||||
<a href="/blogs/<?= $link[1] ?>" class="list-group-item"><?= $link[0] ?></a>
|
||||
<?php endforeach ?>
|
||||
</div>
|
||||
</div>
|
||||
<?php endif ?>
|
||||
</div>
|
||||
<?php endif ?>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php echoUOJPageFooter() ?>
|
||||
<?php echoUOJPageFooter() ?>
|
||||
|
@ -1,27 +1,19 @@
|
||||
<?php
|
||||
if (!Auth::check()) {
|
||||
redirectToLogin();
|
||||
}
|
||||
requireLib('bootstrap5');
|
||||
requirePHPLib('form');
|
||||
|
||||
requireLib('bootstrap5');
|
||||
requirePHPLib('form');
|
||||
Auth::check() || redirectToLogin();
|
||||
UOJContest::init(UOJRequest::get('id')) || UOJResponse::page404();
|
||||
isSuperUser(Auth::user()) || UOJResponse::page403();
|
||||
$contest = UOJContest::info();
|
||||
|
||||
if (!validateUInt($_GET['id']) || !($contest = queryContest($_GET['id']))) {
|
||||
become404Page();
|
||||
}
|
||||
genMoreContestInfo($contest);
|
||||
|
||||
if (!hasContestPermission($myUser, $contest)) {
|
||||
become403Page();
|
||||
}
|
||||
|
||||
if (isset($_GET['tab'])) {
|
||||
if (isset($_GET['tab'])) {
|
||||
$cur_tab = $_GET['tab'];
|
||||
} else {
|
||||
} else {
|
||||
$cur_tab = 'profile';
|
||||
}
|
||||
}
|
||||
|
||||
$tabs_info = [
|
||||
$tabs_info = [
|
||||
'profile' => [
|
||||
'name' => '基本信息',
|
||||
'url' => "/contest/{$contest['id']}/manage/profile",
|
||||
@ -38,17 +30,20 @@
|
||||
'name' => '其他',
|
||||
'url' => "/contest/{$contest['id']}/manage/others",
|
||||
],
|
||||
];
|
||||
];
|
||||
|
||||
if (!isset($tabs_info[$cur_tab])) {
|
||||
if (!isset($tabs_info[$cur_tab])) {
|
||||
become404Page();
|
||||
}
|
||||
}
|
||||
|
||||
if ($cur_tab == 'profile') {
|
||||
$profile_form = new UOJForm('time');
|
||||
if ($cur_tab == 'profile') {
|
||||
$profile_form = new UOJBs4Form('time');
|
||||
$profile_form->addVInput(
|
||||
'name', 'text', '比赛标题', $contest['name'],
|
||||
function($name, &$vdata) {
|
||||
'name',
|
||||
'text',
|
||||
'比赛标题',
|
||||
$contest['name'],
|
||||
function ($name, &$vdata) {
|
||||
if ($name == '') {
|
||||
return '标题不能为空';
|
||||
}
|
||||
@ -70,8 +65,11 @@
|
||||
null
|
||||
);
|
||||
$profile_form->addVInput(
|
||||
'start_time', 'text', '开始时间', $contest['start_time_str'],
|
||||
function($str, &$vdata) {
|
||||
'start_time',
|
||||
'text',
|
||||
'开始时间',
|
||||
$contest['start_time_str'],
|
||||
function ($str, &$vdata) {
|
||||
try {
|
||||
$vdata['start_time'] = new DateTime($str);
|
||||
} catch (Exception $e) {
|
||||
@ -82,8 +80,11 @@
|
||||
null
|
||||
);
|
||||
$profile_form->addVInput(
|
||||
'last_min', 'text', '时长(单位:分钟)', $contest['last_min'],
|
||||
function($str, &$vdata) {
|
||||
'last_min',
|
||||
'text',
|
||||
'时长(单位:分钟)',
|
||||
$contest['last_min'],
|
||||
function ($str, &$vdata) {
|
||||
if (!validateUInt($str)) {
|
||||
return '必须为一个整数';
|
||||
}
|
||||
@ -94,12 +95,15 @@
|
||||
},
|
||||
null
|
||||
);
|
||||
$profile_form->handle = function(&$vdata) use ($contest) {
|
||||
$start_time_str = $vdata['start_time']->format('Y-m-d H:i:s');
|
||||
$esc_name = DB::escape($vdata['name']);
|
||||
$esc_last_min = DB::escape($vdata['last_min']);
|
||||
|
||||
DB::update("update contests set start_time = '$start_time_str', last_min = {$_POST['last_min']}, name = '$esc_name' where id = {$contest['id']}");
|
||||
$profile_form->handle = function (&$vdata) use ($contest) {
|
||||
DB::update([
|
||||
"update contests",
|
||||
"set", [
|
||||
"name" => $vdata['name'],
|
||||
"start_time" => $vdata['start_time']->format('Y-m-d H:i:s'),
|
||||
"last_min" => $vdata['last_min'],
|
||||
], "where", ["id" => $contest['id']]
|
||||
]);
|
||||
|
||||
dieWithJsonData(['status' => 'success', 'message' => '修改成功']);
|
||||
};
|
||||
@ -123,45 +127,59 @@ function(res) {
|
||||
}
|
||||
EOD);
|
||||
$profile_form->runAtServer();
|
||||
} elseif ($cur_tab == 'problems') {
|
||||
} elseif ($cur_tab == 'problems') {
|
||||
if (isset($_POST['submit-remove_problem']) && $_POST['submit-remove_problem'] == 'remove_problem') {
|
||||
$problem_id = $_POST['problem_id'];
|
||||
$problem = UOJProblem::query($problem_id);
|
||||
|
||||
if (!validateUInt($problem_id)) {
|
||||
dieWithAlert('无效的题目 ID。');
|
||||
if (!$problem) {
|
||||
dieWithAlert('题目不存在');
|
||||
}
|
||||
|
||||
if (!queryProblemBrief($problem_id)) {
|
||||
dieWithAlert('题目不存在。');
|
||||
if (!UOJContest::cur()->hasProblem($problem)) {
|
||||
dieWithAlert('题目不在本场比赛中');
|
||||
}
|
||||
|
||||
if (!DB::selectFirst("SELECT * FROM contests_problems WHERE contest_id = {$contest['id']} AND problem_id = $problem_id")) {
|
||||
dieWithAlert('题目不在比赛中。');
|
||||
}
|
||||
|
||||
DB::delete("DELETE FROM contests_problems WHERE contest_id = {$contest['id']} AND problem_id = $problem_id");
|
||||
DB::delete([
|
||||
"delete from contests_problems",
|
||||
"where", [
|
||||
"contest_id" => $contest['id'],
|
||||
"problem_id" => $problem_id,
|
||||
],
|
||||
]);
|
||||
|
||||
unset($contest['extra_config']["problem_$problem_id"]);
|
||||
$esc_extra_config = DB::escape(json_encode($contest['extra_config']));
|
||||
DB::update("UPDATE `contests` SET extra_config = '$esc_extra_config' WHERE id = {$contest['id']}");
|
||||
unset($contest['extra_config']['bonus']["problem_$problem_id"]);
|
||||
unset($contest['extra_config']['submit_time_limit']["problem_$problem_id"]);
|
||||
|
||||
$esc_extra_config = json_encode($contest['extra_config']);
|
||||
DB::update([
|
||||
"update contests",
|
||||
"set", ["extra_config" => $esc_extra_config],
|
||||
"where", ["id" => $contest['id']]
|
||||
]);
|
||||
|
||||
dieWithAlert('移除成功!');
|
||||
}
|
||||
|
||||
$add_problem_form = new UOJForm('add_problem');
|
||||
$add_problem_form->addVInput('problem_id', 'text', '题目 ID', '',
|
||||
function($problem_id, &$vdata) {
|
||||
if (!validateUInt($problem_id)) {
|
||||
return '无效的题目 ID。';
|
||||
}
|
||||
|
||||
$problem = queryProblemBrief($problem_id);
|
||||
$add_problem_form = new UOJBs4Form('add_problem');
|
||||
$add_problem_form->addVInput(
|
||||
'problem_id',
|
||||
'text',
|
||||
'题目 ID',
|
||||
'',
|
||||
function ($problem_id, &$vdata) {
|
||||
$problem = UOJProblem::query($problem_id);
|
||||
if (!$problem) {
|
||||
return '题目不存在。';
|
||||
}
|
||||
|
||||
if (!hasProblemPermission(Auth::user(), $problem)) {
|
||||
return "无权添加题目 #$problem_id。";
|
||||
if (!$problem->userCanManage(Auth::user())) {
|
||||
return "无权添加此题目。";
|
||||
}
|
||||
|
||||
if (UOJContest::cur()->hasProblem($problem)) {
|
||||
return "题目已经在本场比赛中。";
|
||||
}
|
||||
|
||||
$vdata['problem_id'] = $problem_id;
|
||||
@ -171,24 +189,44 @@ EOD);
|
||||
null
|
||||
);
|
||||
$add_problem_form->addVSelect('judge_config', [
|
||||
'default' => '默认',
|
||||
'sample' => '只测样例',
|
||||
'no-details' => '测试全部数据,但不显示测试点详情',
|
||||
'no-details' => '测试全部数据,对于每个测试点显示得分但不显示详情',
|
||||
'full' => '测试全部数据',
|
||||
], '评测设置', 'sample');
|
||||
$add_problem_form->handle = function(&$vdata) use ($contest) {
|
||||
$dfn = DB::selectFirst("SELECT max(dfn) FROM contests_problems WHERE contest_id = {$contest['id']}")['max(dfn)'] + 1;
|
||||
DB::insert("INSERT INTO `contests_problems` (contest_id, problem_id, dfn) VALUES ({$contest['id']}, '{$vdata['problem_id']}', $dfn)");
|
||||
], '评测设置', 'default');
|
||||
$add_problem_form->addVCheckboxes('bonus', ['0' => '否', '1' => '是'], '是否为 bonus 题(ACM 赛制)', '0');
|
||||
$add_problem_form->handle = function (&$vdata) use ($contest) {
|
||||
$level = DB::selectFirst([
|
||||
"select", "max(level)",
|
||||
"from", "contests_problems",
|
||||
"where", [
|
||||
"contest_id" => $contest['id'],
|
||||
]
|
||||
])["max(level)"];
|
||||
DB::insert([
|
||||
"insert ignore into contests_problems",
|
||||
"(contest_id, problem_id, level)",
|
||||
"values", DB::tuple([$contest['id'], $vdata['problem_id'], $level + 1])
|
||||
]);
|
||||
|
||||
if ($_POST['judge_config'] != 'sample') {
|
||||
$contest['extra_config']["problem_$problem_id"] = $_POST['judge_config'];
|
||||
$esc_extra_config = DB::escape(json_encode($contest['extra_config']));
|
||||
DB::update("UPDATE `contests` SET extra_config = '$esc_extra_config' WHERE id = {$contest['id']}");
|
||||
$judge_type = $_POST['judge_config'];
|
||||
if ($judge_type === 'default') {
|
||||
unset($contest['extra_config']["problem_{$vdata['problem_id']}"]);
|
||||
} else {
|
||||
$contest['extra_config']["problem_{$vdata['problem_id']}"] = $judge_type;
|
||||
}
|
||||
|
||||
$esc_extra_config = json_encode($contest['extra_config']);
|
||||
DB::update([
|
||||
"update contests",
|
||||
"set", ["extra_config" => $esc_extra_config],
|
||||
"where", ["id" => $contest['id']]
|
||||
]);
|
||||
|
||||
dieWithJsonData(['status' => 'success', 'message' => "题目 #{$vdata['problem_id']} 添加成功!"]);
|
||||
};
|
||||
$add_problem_form->submit_button_config['text'] = '添加';
|
||||
$add_problem_form->submit_button_config['margin_class'] = 'mt-3';
|
||||
$add_problem_form->submit_button_config['class_str'] = 'btn btn-secondary mt-3';
|
||||
$add_problem_form->setAjaxSubmit(<<<EOD
|
||||
function(res) {
|
||||
if (res.status === 'success') {
|
||||
@ -209,38 +247,44 @@ function(res) {
|
||||
}
|
||||
EOD);
|
||||
$add_problem_form->runAtServer();
|
||||
} elseif ($cur_tab == 'managers') {
|
||||
} elseif ($cur_tab == 'managers') {
|
||||
if (isset($_POST['submit-remove_manager']) && $_POST['submit-remove_manager'] == 'remove_manager') {
|
||||
$username = $_POST['username'];
|
||||
$user = UOJUser::query($username);
|
||||
|
||||
if (!validateUsername($username)) {
|
||||
dieWithAlert('用户名不合法。');
|
||||
}
|
||||
|
||||
if (!queryUser($username)) {
|
||||
if (!$user) {
|
||||
dieWithAlert('用户不存在。');
|
||||
}
|
||||
|
||||
if (!DB::selectFirst("SELECT * FROM contests_permissions WHERE contest_id = {$contest['id']} AND username = '$username'")) {
|
||||
if (!UOJContest::cur()->userCanManage($user)) {
|
||||
dieWithAlert('用户不是这场比赛的管理员。');
|
||||
}
|
||||
|
||||
DB::delete("DELETE FROM `contests_permissions` WHERE contest_id = ${contest['id']} AND username = '$username'");
|
||||
|
||||
DB::delete([
|
||||
"delete from contests_permissions",
|
||||
"where", [
|
||||
"contest_id" => $contest['id'],
|
||||
"username" => $user['username'],
|
||||
]
|
||||
]);
|
||||
dieWithAlert('移除成功!');
|
||||
}
|
||||
|
||||
$add_manager_form = new UOJForm('add_manager');
|
||||
$add_manager_form->addVInput('username', 'text', '用户名', '',
|
||||
function($username, &$vdata) {
|
||||
if (!validateUsername($username)) {
|
||||
return '用户名不合法';
|
||||
}
|
||||
$add_manager_form = new UOJBs4Form('add_manager');
|
||||
$add_manager_form->addVInput(
|
||||
'username',
|
||||
'text',
|
||||
'用户名',
|
||||
'',
|
||||
function ($username, &$vdata) use ($contest) {
|
||||
$user = UOJUser::query($username);
|
||||
|
||||
if (!queryUser($username)) {
|
||||
if (!$user) {
|
||||
return '用户不存在';
|
||||
}
|
||||
|
||||
if (DB::selectFirst("SELECT * FROM contests_permissions WHERE contest_id = {$contest['id']} AND username = '$username'")) {
|
||||
if (UOJContest::cur()->userCanManage($user)) {
|
||||
return '用户已经是这场比赛的管理员';
|
||||
}
|
||||
|
||||
@ -250,13 +294,17 @@ EOD);
|
||||
},
|
||||
null
|
||||
);
|
||||
$add_manager_form->handle = function(&$vdata) use ($contest) {
|
||||
DB::query("INSERT INTO `contests_permissions` (contest_id, username) VALUES (${contest['id']}, '{$vdata['username']}')");
|
||||
$add_manager_form->handle = function (&$vdata) use ($contest) {
|
||||
DB::insert([
|
||||
"insert into contests_permissions",
|
||||
"(contest_id, username)",
|
||||
"values", DB::tuple([$contest['id'], $vdata['username']])
|
||||
]);
|
||||
|
||||
dieWithJsonData(['status' => 'success', 'message' => '已将用户名为 ' . $vdata['username'] . ' 的用户设置为本场比赛的管理者。']);
|
||||
};
|
||||
$add_manager_form->submit_button_config['text'] = '添加';
|
||||
$add_manager_form->submit_button_config['margin_class'] = 'mt-3';
|
||||
$add_manager_form->submit_button_config['class_str'] = 'btn btn-secondary mt-3';
|
||||
$add_manager_form->setAjaxSubmit(<<<EOD
|
||||
function(res) {
|
||||
if (res.status === 'success') {
|
||||
@ -277,17 +325,20 @@ function(res) {
|
||||
}
|
||||
EOD);
|
||||
$add_manager_form->runAtServer();
|
||||
} elseif ($cur_tab == 'others') {
|
||||
$version_form = new UOJForm('version');
|
||||
} elseif ($cur_tab == 'others') {
|
||||
$version_form = new UOJBs4Form('version');
|
||||
$version_form->addVSelect('standings_version', [
|
||||
'1' => '1',
|
||||
'2' => '2',
|
||||
], '比赛排名版本', $contest['extra_config']['standings_version'] ?: '2');
|
||||
$version_form->handle = function() use ($contest) {
|
||||
], '比赛排名版本', $contest['extra_config']['standings_version']);
|
||||
$version_form->handle = function () use ($contest) {
|
||||
$contest['extra_config']['standings_version'] = $_POST['standings_version'];
|
||||
$esc_extra_config = json_encode($contest['extra_config']);
|
||||
$esc_extra_config = DB::escape($esc_extra_config);
|
||||
DB::update("UPDATE contests SET extra_config = '$esc_extra_config' WHERE id = {$contest['id']}");
|
||||
DB::update([
|
||||
"update contests",
|
||||
"set", ["extra_config" => $esc_extra_config],
|
||||
"where", ["id" => $contest['id']],
|
||||
]);
|
||||
|
||||
dieWithJsonData(['status' => 'success', 'message' => '修改成功']);
|
||||
};
|
||||
@ -312,20 +363,46 @@ function(res) {
|
||||
EOD);
|
||||
$version_form->runAtServer();
|
||||
|
||||
$contest_type_form = new UOJForm('contest_type');
|
||||
$contest_type_form->addVSelect('contest_type', [
|
||||
$rule_form = new UOJBs4Form('basic_rule');
|
||||
$rule_form->addVSelect('basic_rule', [
|
||||
'OI' => 'OI',
|
||||
'IOI' => 'IOI'
|
||||
], '比赛类型', $contest['extra_config']['contest_type'] ?: 'OI');
|
||||
$contest_type_form->handle = function() use ($contest) {
|
||||
$contest['extra_config']['contest_type'] = $_POST['contest_type'];
|
||||
'IOI' => 'IOI',
|
||||
'ACM' => 'ACM',
|
||||
], '比赛类型', $contest['extra_config']['basic_rule']);
|
||||
$rule_form->addVSelect('free_registration', [
|
||||
1 => '所有人都可以自由报名',
|
||||
0 => '只能由管理员帮选手报名'
|
||||
], "报名方式", $contest['extra_config']['free_registration']);
|
||||
$rule_form->addVSelect('individual_or_team', [
|
||||
'individual' => '个人赛',
|
||||
'team' => '团体赛'
|
||||
], "个人赛/团体赛", $contest['extra_config']['individual_or_team']);
|
||||
$rule_form->addVInput(
|
||||
'max_n_submissions_per_problem',
|
||||
'text',
|
||||
'每题最高提交次数(-1 表示不限制)',
|
||||
$contest['extra_config']['max_n_submissions_per_problem'],
|
||||
function ($str) {
|
||||
return !validateUInt($str) && $str !== '-1' ? '必须为一个非负整数或 -1' : '';
|
||||
},
|
||||
null
|
||||
);
|
||||
$rule_form->handle = function () use ($contest) {
|
||||
$contest['extra_config']['basic_rule'] = $_POST['basic_rule'];
|
||||
$contest['extra_config']['free_registration'] = (int)$_POST['free_registration'];
|
||||
$contest['extra_config']['individual_or_team'] = $_POST['individual_or_team'];
|
||||
$contest['extra_config']['max_n_submissions_per_problem'] = (int)$_POST['max_n_submissions_per_problem'];
|
||||
|
||||
$esc_extra_config = json_encode($contest['extra_config']);
|
||||
$esc_extra_config = DB::escape($esc_extra_config);
|
||||
DB::update("UPDATE contests set extra_config = '$esc_extra_config' where id = {$contest['id']}");
|
||||
DB::update([
|
||||
"update contests",
|
||||
"set", ["extra_config" => $esc_extra_config],
|
||||
"where", ["id" => $contest['id']]
|
||||
]);
|
||||
|
||||
dieWithJsonData(['status' => 'success', 'message' => '修改成功']);
|
||||
};
|
||||
$contest_type_form->setAjaxSubmit(<<<EOD
|
||||
$rule_form->setAjaxSubmit(<<<EOD
|
||||
function(res) {
|
||||
if (res.status === 'success') {
|
||||
$('#type-result-alert')
|
||||
@ -344,10 +421,14 @@ function(res) {
|
||||
$(window).scrollTop(0);
|
||||
}
|
||||
EOD);
|
||||
$contest_type_form->runAtServer();
|
||||
$rule_form->runAtServer();
|
||||
|
||||
$blog_link_contests = new UOJForm('blog_link_contests');
|
||||
$blog_link_contests->addVInput('blog_id', 'text', '博客 ID', '',
|
||||
$blog_link_contests = new UOJBs4Form('blog_link_contests');
|
||||
$blog_link_contests->addVInput(
|
||||
'blog_id',
|
||||
'text',
|
||||
'博客 ID',
|
||||
'',
|
||||
function ($blog_id, &$vdata) {
|
||||
if (!validateUInt($blog_id)) {
|
||||
return 'ID 不合法';
|
||||
@ -363,8 +444,12 @@ EOD);
|
||||
},
|
||||
null
|
||||
);
|
||||
$blog_link_contests->addVInput('title', 'text', '名称', '',
|
||||
function($title, &$vdata) {
|
||||
$blog_link_contests->addVInput(
|
||||
'title',
|
||||
'text',
|
||||
'名称',
|
||||
'',
|
||||
function ($title, &$vdata) {
|
||||
if ($title == '') {
|
||||
return '名称不能为空';
|
||||
}
|
||||
@ -388,7 +473,7 @@ EOD);
|
||||
'add' => '添加',
|
||||
'del' => '移除',
|
||||
], '操作类型', '');
|
||||
$blog_link_contests->handle = function($vdata) use ($contest) {
|
||||
$blog_link_contests->handle = function ($vdata) use ($contest) {
|
||||
if ($_POST['op_type'] == 'add') {
|
||||
if (!isset($contest['extra_config']['links'])) {
|
||||
$contest['extra_config']['links'] = [];
|
||||
@ -437,12 +522,12 @@ function(res) {
|
||||
EOD);
|
||||
$blog_link_contests->runAtServer();
|
||||
|
||||
$extra_registration_form = new UOJForm('extra_registration_form');
|
||||
$extra_registration_form = new UOJBs4Form('extra_registration_form');
|
||||
$extra_registration_form->addVCheckboxes('extra_registration', [
|
||||
'0' => '禁止',
|
||||
'1' => '允许'
|
||||
], '是否允许额外报名', isset($contest['extra_config']['extra_registration']) ? $contest['extra_config']['extra_registration'] : '1');
|
||||
$extra_registration_form->handle = function() use ($contest) {
|
||||
$extra_registration_form->handle = function () use ($contest) {
|
||||
$contest['extra_config']['extra_registration'] = $_POST['extra_registration'];
|
||||
$esc_extra_config = DB::escape(json_encode($contest['extra_config']));
|
||||
DB::update("UPDATE contests SET extra_config = '$esc_extra_config' WHERE id = {$contest['id']}");
|
||||
@ -469,38 +554,35 @@ function(res) {
|
||||
}
|
||||
EOD);
|
||||
$extra_registration_form->runAtServer();
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
?>
|
||||
<?php echoUOJPageHeader(HTML::stripTags('比赛管理 - ' . $contest['name'])) ?>
|
||||
<h1 class="h2">
|
||||
<h1>
|
||||
<?= $contest['name'] ?>
|
||||
<small class="fs-5">(ID: <?= $contest['id'] ?>)</small>
|
||||
管理
|
||||
</h1>
|
||||
|
||||
<div class="row mt-4">
|
||||
<!-- left col -->
|
||||
<div class="col-md-3">
|
||||
<!-- left col -->
|
||||
<div class="col-md-3">
|
||||
|
||||
<?= HTML::navListGroup($tabs_info, $cur_tab) ?>
|
||||
<?= HTML::navListGroup($tabs_info, $cur_tab) ?>
|
||||
|
||||
<a
|
||||
class="btn btn-light d-block mt-2 w-100 text-start text-primary"
|
||||
style="--bs-btn-hover-bg: #d3d4d570; --bs-btn-hover-border-color: transparent;"
|
||||
href="<?= HTML::url("/contest/{$contest['id']}") ?>">
|
||||
<a class="btn btn-light d-block mt-2 w-100 text-start text-primary" style="--bs-btn-hover-bg: #d3d4d570; --bs-btn-hover-border-color: transparent;" href="<?= HTML::url("/contest/{$contest['id']}") ?>">
|
||||
<i class="bi bi-arrow-left"></i> 返回
|
||||
</a>
|
||||
</a>
|
||||
|
||||
</div>
|
||||
<!-- end left col -->
|
||||
</div>
|
||||
<!-- end left col -->
|
||||
|
||||
<!-- right col -->
|
||||
<div class="col-md-9">
|
||||
<!-- right col -->
|
||||
<div class="col-md-9">
|
||||
|
||||
<?php if ($cur_tab == 'profile'): ?>
|
||||
<div class="card mt-3 mt-md-0">
|
||||
<div class="card-body">
|
||||
<?php if ($cur_tab == 'profile') : ?>
|
||||
<div class="card mt-3 mt-md-0">
|
||||
<div class="card-body">
|
||||
<div id="result-alert" class="alert" role="alert" style="display: none"></div>
|
||||
<div class="row row-cols-1 row-cols-md-2">
|
||||
<div class="col">
|
||||
@ -513,10 +595,10 @@ EOD);
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<?php elseif ($cur_tab == 'problems'): ?>
|
||||
<div class="card mt-3 mt-md-0">
|
||||
</div>
|
||||
</div>
|
||||
<?php elseif ($cur_tab == 'problems') : ?>
|
||||
<div class="card mt-3 mt-md-0">
|
||||
<div class="card-header">
|
||||
<ul class="nav nav-tabs card-header-tabs" role="tablist">
|
||||
<li class="nav-item">
|
||||
@ -534,7 +616,7 @@ EOD);
|
||||
['*'],
|
||||
'contests_problems',
|
||||
"contest_id = '{$contest['id']}'",
|
||||
'ORDER BY dfn, problem_id',
|
||||
'ORDER BY level, problem_id',
|
||||
<<<EOD
|
||||
<tr>
|
||||
<th style="width:3em">ID</th>
|
||||
@ -543,16 +625,16 @@ EOD);
|
||||
<th style="width:6em">操作</th>
|
||||
</tr>
|
||||
EOD,
|
||||
function($row) {
|
||||
$problem = queryProblemBrief($row['problem_id']);
|
||||
function ($row) {
|
||||
$problem = UOJProblem::query($row['problem_id']);
|
||||
echo '<tr>';
|
||||
echo '<td>', $row['problem_id'], '</td>';
|
||||
echo '<td>', getProblemLink($problem), '</td>';
|
||||
echo '<td>', isset($contest['extra_config']["problem_{$problem['id']}"]) ? $contest['extra_config']["problem_{$problem['id']}"] : 'sample', '</td>';
|
||||
echo '<td>', $problem->getLink(['with' => 'none']), '</td>';
|
||||
echo '<td>', isset($contest['extra_config']["problem_{$problem->info['id']}"]) ? $contest['extra_config']["problem_{$problem->info['id']}"] : 'default', '</td>';
|
||||
echo '<td>';
|
||||
echo '<form class="d-inline-block" method="POST" target="_self" onsubmit=\'return confirm("你确定要将题目 #', $problem['id'], ' 从比赛中移除吗?")\'>';
|
||||
echo '<input type="hidden" name="_token" value="', crsf_token(),'">';
|
||||
echo '<input type="hidden" name="problem_id" value="', $problem['id'], '">';
|
||||
echo '<form class="d-inline-block" method="POST" target="_self" onsubmit=\'return confirm("你确定要将题目 #', $problem->info['id'], ' 从比赛中移除吗?")\'>';
|
||||
echo '<input type="hidden" name="_token" value="', crsf_token(), '">';
|
||||
echo '<input type="hidden" name="problem_id" value="', $problem->info['id'], '">';
|
||||
echo '<button type="submit" class="btn btn-link text-danger text-decoration-none p-0" name="submit-remove_problem" value="remove_problem">移除</button>';
|
||||
echo '</form>';
|
||||
echo '</td>';
|
||||
@ -577,14 +659,15 @@ EOD,
|
||||
<ul class="mt-0">
|
||||
<li>推荐在比赛结束前将题目设置为隐藏。</li>
|
||||
<li>对于「评测设置」选项,一般情况下保持默认(即只测样例)即可。</li>
|
||||
<li>在 ACM 赛制中,如果设置一道题目为 bonus 题,那么获得 100 分后会总罚时会减少 20 分钟,但排名时不会将此题记入该选手通过的题目总数中。</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<?php elseif ($cur_tab == 'managers'): ?>
|
||||
<div class="card mt-3 mt-md-0">
|
||||
</div>
|
||||
<?php elseif ($cur_tab == 'managers') : ?>
|
||||
<div class="card mt-3 mt-md-0">
|
||||
<div class="card-header">
|
||||
<ul class="nav nav-tabs card-header-tabs" role="tablist">
|
||||
<li class="nav-item">
|
||||
@ -644,14 +727,14 @@ EOD,
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<?php elseif ($cur_tab == 'others'): ?>
|
||||
<div class="card mt-3 mt-md-0">
|
||||
</div>
|
||||
</div>
|
||||
<?php elseif ($cur_tab == 'others') : ?>
|
||||
<div class="card mt-3 mt-md-0">
|
||||
<div class="card-header">
|
||||
<ul class="nav nav-tabs card-header-tabs" role="tablist">
|
||||
<li class="nav-item">
|
||||
<a class="nav-link active" href="#type" data-bs-toggle="tab" data-bs-target="#type">赛制管理</a>
|
||||
<a class="nav-link active" href="#type" data-bs-toggle="tab" data-bs-target="#type">规则</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="#standings-version" data-bs-toggle="tab" data-bs-target="#standings-version">排名版本</a>
|
||||
@ -669,12 +752,18 @@ EOD,
|
||||
<div id="type-result-alert" class="alert" role="alert" style="display: none"></div>
|
||||
<div class="row row-cols-1 row-cols-md-2">
|
||||
<div class="col">
|
||||
<?php $contest_type_form->printHTML(); ?>
|
||||
<?php $rule_form->printHTML(); ?>
|
||||
</div>
|
||||
<div class="col mt-3 mt-md-0">
|
||||
<h5>注意事项</h5>
|
||||
<h5>赛制解释</h5>
|
||||
<ul>
|
||||
<li><strong>OI 赛制:</strong> 比赛期间可设置题目只测样例,结束后会进行重测。按最后一次有效提交算分和算罚时。</li>
|
||||
<li><strong>ACM 赛制:</strong> 比赛期间所有题目显示最终测评结果。比赛结束前一小时封榜,比赛时间不足 5 小时则比赛过去五分之四后封榜。一道题的罚时为得分最高的提交的时间,加上在此之前没有使得该题分数增加的提交的次数乘以 20 分钟。</li>
|
||||
<li><strong>IOI 赛制:</strong> 比赛期间所有题目显示最终测评结果。按得分最高的有效提交算分和算罚时。</li>
|
||||
</ul>
|
||||
<h5>常见问题</h5>
|
||||
<ul class="mb-0">
|
||||
<li>目前 S2OJ 支持 OI 和 IOI 赛制。</li>
|
||||
<li>暂无</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
@ -707,6 +796,9 @@ EOD,
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="tab-pane" id="extra-registration">
|
||||
<div id="extra-registration-result-alert" class="alert" role="alert" style="display: none"></div>
|
||||
<div class="row row-cols-1 row-cols-md-2">
|
||||
@ -721,8 +813,6 @@ EOD,
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<?php endif ?>
|
||||
</div>
|
||||
|
@ -1,105 +1,97 @@
|
||||
<?php
|
||||
requireLib('bootstrap5');
|
||||
requirePHPLib('form');
|
||||
requireLib('bootstrap5');
|
||||
requirePHPLib('form');
|
||||
|
||||
if (!Auth::check() && UOJConfig::$data['switch']['force-login']) {
|
||||
redirectToLogin();
|
||||
}
|
||||
Auth::check() || redirectToLogin();
|
||||
UOJContest::init(UOJRequest::get('id')) || UOJResponse::page404();
|
||||
|
||||
if (!isNormalUser($myUser) && UOJConfig::$data['switch']['force-login']) {
|
||||
become403Page();
|
||||
}
|
||||
$contest = UOJContest::info();
|
||||
|
||||
if (!validateUInt($_GET['id']) || !($contest = queryContest($_GET['id']))) {
|
||||
become404Page();
|
||||
}
|
||||
$is_manager = UOJContest::cur()->userCanManage(Auth::user());
|
||||
$show_ip = isSuperUser(Auth::user());
|
||||
|
||||
genMoreContestInfo($contest);
|
||||
if ($is_manager) {
|
||||
$add_new_contestant_form = new UOJBs4Form('add_new_contestant_form');
|
||||
$add_new_contestant_form->addInput(
|
||||
'new_username',
|
||||
'text',
|
||||
'用户名',
|
||||
'',
|
||||
function ($username, &$vdata) {
|
||||
$user = UOJUser::query($username);
|
||||
|
||||
if (isSuperUser($myUser)) {
|
||||
$add_new_contestant_form = new UOJForm('add_new_contestant_form');
|
||||
$add_new_contestant_form->addInput('new_username', 'text', '用户名', '',
|
||||
function ($x) {
|
||||
global $contest;
|
||||
|
||||
if (!validateUsername($x)) {
|
||||
return '用户名不合法';
|
||||
}
|
||||
$user = queryUser($x);
|
||||
if (!$user) {
|
||||
return '用户不存在';
|
||||
}
|
||||
|
||||
if (hasRegistered($user, $contest)) {
|
||||
if (UOJContest::cur()->userHasRegistered($user)) {
|
||||
return '该用户已经报名';
|
||||
}
|
||||
|
||||
$vdata['user'] = $user;
|
||||
|
||||
return '';
|
||||
},
|
||||
null
|
||||
);
|
||||
$add_new_contestant_form->submit_button_config['align'] = 'compressed';
|
||||
$add_new_contestant_form->submit_button_config['text'] = '注册该用户';
|
||||
$add_new_contestant_form->handle = function() {
|
||||
global $contest;
|
||||
|
||||
$username = $_POST['new_username'];
|
||||
|
||||
DB::query("replace into contests_registrants (username, contest_id, has_participated) values ('{$username}', {$contest['id']}, 0)");
|
||||
|
||||
updateContestPlayerNum($contest);
|
||||
$add_new_contestant_form->handle = function (&$vdata) {
|
||||
UOJContest::cur()->userRegister($vdata['user']);
|
||||
};
|
||||
$add_new_contestant_form->runAtServer();
|
||||
|
||||
$add_group_to_contest_form = new UOJForm('add_group_to_contest');
|
||||
$add_group_to_contest_form->addInput('group_id', 'text', '小组 ID', '',
|
||||
function ($x) {
|
||||
global $contest;
|
||||
|
||||
if (!validateUInt($x)) {
|
||||
$add_group_to_contest_form = new UOJBs4Form('add_group_to_contest');
|
||||
$add_group_to_contest_form->addInput(
|
||||
'group_id',
|
||||
'text',
|
||||
'小组 ID',
|
||||
'',
|
||||
function ($group_id, &$vdata) {
|
||||
if (!validateUInt($group_id)) {
|
||||
return '小组 ID 不合法';
|
||||
}
|
||||
$group = queryGroup($x);
|
||||
$group = queryGroup($group_id);
|
||||
if (!$group) {
|
||||
return '小组不存在';
|
||||
}
|
||||
|
||||
$vdata['group_id'] = $group_id;
|
||||
|
||||
return '';
|
||||
},
|
||||
null
|
||||
);
|
||||
$add_group_to_contest_form->submit_button_config['align'] = 'compressed';
|
||||
$add_group_to_contest_form->submit_button_config['text'] = '注册该小组中的用户';
|
||||
$add_group_to_contest_form->handle = function() {
|
||||
global $contest;
|
||||
$group_id = $_POST['group_id'];
|
||||
|
||||
$users = DB::selectAll("select b.username as username from groups_users a inner join user_info b on a.username = b.username where a.group_id = $group_id");
|
||||
$add_group_to_contest_form->handle = function (&$vdata) {
|
||||
$users = queryGroupUsers($vdata['group_id']);
|
||||
|
||||
foreach ($users as $user) {
|
||||
DB::query("replace into contests_registrants (username, contest_id, has_participated) values ('{$user['username']}', {$contest['id']}, 0)");
|
||||
UOJContest::cur()->userRegister($user);
|
||||
}
|
||||
|
||||
updateContestPlayerNum($contest);
|
||||
};
|
||||
$add_group_to_contest_form->runAtServer();
|
||||
|
||||
$remove_user_from_contest_form = new UOJForm('remove_user_from_contest');
|
||||
$remove_user_from_contest_form->addInput('remove_username', 'text', '用户名', '',
|
||||
function ($x) {
|
||||
global $contest;
|
||||
if (!validateUsername($x)) {
|
||||
return '用户名不合法';
|
||||
}
|
||||
$remove_user_from_contest_form = new UOJBs4Form('remove_user_from_contest');
|
||||
$remove_user_from_contest_form->addInput(
|
||||
'remove_username',
|
||||
'text',
|
||||
'用户名',
|
||||
'',
|
||||
function ($username, &$vdata) {
|
||||
$user = UOJUser::query($username);
|
||||
|
||||
$user = queryUser($x);
|
||||
if (!$user) {
|
||||
return '用户不存在';
|
||||
}
|
||||
|
||||
if (!hasRegistered($user, $contest)) {
|
||||
if (!UOJContest::cur()->userHasRegistered($user)) {
|
||||
return '该用户未报名';
|
||||
}
|
||||
|
||||
$vdata['user'] = $user;
|
||||
|
||||
return '';
|
||||
},
|
||||
null
|
||||
@ -107,33 +99,30 @@
|
||||
$remove_user_from_contest_form->submit_button_config['align'] = 'compressed';
|
||||
$remove_user_from_contest_form->submit_button_config['text'] = '移除该用户';
|
||||
$remove_user_from_contest_form->submit_button_config['class_str'] = 'mt-2 btn btn-danger';
|
||||
$remove_user_from_contest_form->handle = function() {
|
||||
global $contest;
|
||||
$username = $_POST['remove_username'];
|
||||
|
||||
DB::query("delete from contests_registrants where username = '{$username}' and contest_id = {$contest['id']}");
|
||||
updateContestPlayerNum($contest);
|
||||
$remove_user_from_contest_form->handle = function (&$vdata) {
|
||||
UOJContest::cur()->userUnregister($vdata['user']);
|
||||
};
|
||||
$remove_user_from_contest_form->runAtServer();
|
||||
|
||||
$force_set_user_participated_form = new UOJForm('force_set_user_participated');
|
||||
$force_set_user_participated_form->addInput('force_set_username', 'text', '用户名', '',
|
||||
function ($x) {
|
||||
global $contest;
|
||||
$force_set_user_participated_form = new UOJBs4Form('force_set_user_participated');
|
||||
$force_set_user_participated_form->addInput(
|
||||
'force_set_username',
|
||||
'text',
|
||||
'用户名',
|
||||
'',
|
||||
function ($username, &$vdata) {
|
||||
$user = UOJUser::query($username);
|
||||
|
||||
if (!validateUsername($x)) {
|
||||
return '用户名不合法';
|
||||
}
|
||||
|
||||
$user = queryUser($x);
|
||||
if (!$user) {
|
||||
return '用户不存在';
|
||||
}
|
||||
|
||||
if (!hasRegistered($user, $contest)) {
|
||||
if (!UOJContest::cur()->userHasRegistered($user)) {
|
||||
return '该用户未报名';
|
||||
}
|
||||
|
||||
$vdata['user'] = $user;
|
||||
|
||||
return '';
|
||||
},
|
||||
null
|
||||
@ -141,30 +130,21 @@
|
||||
$force_set_user_participated_form->submit_button_config['align'] = 'compressed';
|
||||
$force_set_user_participated_form->submit_button_config['text'] = '强制参赛';
|
||||
$force_set_user_participated_form->submit_button_config['class_str'] = 'mt-2 btn btn-warning';
|
||||
$force_set_user_participated_form->handle = function() {
|
||||
global $contest;
|
||||
$username = $_POST['force_set_username'];
|
||||
|
||||
DB::query("update contests_registrants set has_participated = 1 where username = '{$username}' and contest_id = {$contest['id']}");
|
||||
updateContestPlayerNum($contest);
|
||||
$force_set_user_participated_form->handle = function (&$vdata) {
|
||||
UOJContest::cur()->markUserAsParticipated($vdata['user']);
|
||||
};
|
||||
$force_set_user_participated_form->runAtServer();
|
||||
}
|
||||
}
|
||||
|
||||
$has_contest_permission = hasContestPermission($myUser, $contest);
|
||||
$show_ip = $has_contest_permission;
|
||||
|
||||
if ($contest['cur_progress'] == CONTEST_NOT_STARTED) {
|
||||
$iHasRegistered = $myUser != null && hasRegistered($myUser, $contest);
|
||||
if ($contest['cur_progress'] == CONTEST_NOT_STARTED) {
|
||||
$iHasRegistered = UOJContest::cur()->userHasRegistered(Auth::user());
|
||||
|
||||
if ($iHasRegistered) {
|
||||
$unregister_form = new UOJForm('unregister');
|
||||
$unregister_form->handle = function() {
|
||||
global $myUser, $contest;
|
||||
DB::query("delete from contests_registrants where username = '{$myUser['username']}' and contest_id = {$contest['id']}");
|
||||
updateContestPlayerNum($contest);
|
||||
if ($iHasRegistered && UOJContest::cur()->freeRegistration()) {
|
||||
$unregister_form = new UOJBs4Form('unregister');
|
||||
$unregister_form->handle = function () {
|
||||
UOJContest::cur()->userUnregister(Auth::user());
|
||||
};
|
||||
$unregister_form->submit_button_config['align'] = 'right';
|
||||
$unregister_form->submit_button_config['class_str'] = 'btn btn-danger btn-xs';
|
||||
$unregister_form->submit_button_config['text'] = '取消报名';
|
||||
$unregister_form->succ_href = "/contests";
|
||||
@ -172,15 +152,16 @@
|
||||
$unregister_form->runAtServer();
|
||||
}
|
||||
}
|
||||
?>
|
||||
}
|
||||
?>
|
||||
<?php echoUOJPageHeader(HTML::stripTags($contest['name']) . ' - ' . UOJLocale::get('contests::contest registrants')) ?>
|
||||
|
||||
<h1 class="h2 text-center">
|
||||
<h1 class="text-center">
|
||||
<?= $contest['name'] ?>
|
||||
</h1>
|
||||
|
||||
<?php if ($contest['cur_progress'] == CONTEST_NOT_STARTED): ?>
|
||||
<?php if ($iHasRegistered): ?>
|
||||
<?php if ($contest['cur_progress'] == CONTEST_NOT_STARTED) : ?>
|
||||
<?php if ($iHasRegistered) : ?>
|
||||
<div class="row">
|
||||
<div class="col-6">
|
||||
<a class="text-decoration-none text-success">已报名</a>
|
||||
@ -189,40 +170,40 @@
|
||||
<?php $unregister_form->printHTML(); ?>
|
||||
</div>
|
||||
</div>
|
||||
<?php else: ?>
|
||||
<?php else : ?>
|
||||
<div>当前尚未报名,您可以 <a class="text-decoration-none text-danger" href="/contest/<?= $contest['id'] ?>/register">报名</a>。</div>
|
||||
<?php endif ?>
|
||||
<div class="mt-2"></div>
|
||||
<div class="mt-2"></div>
|
||||
<?php endif ?>
|
||||
|
||||
<?php
|
||||
$header_row = '<tr><th>#</th><th>'.UOJLocale::get('username').'</th>';
|
||||
if ($show_ip) {
|
||||
$header_row = '<tr><th>#</th><th>' . UOJLocale::get('username') . '</th>';
|
||||
if ($show_ip) {
|
||||
$header_row .= '<th>remote_addr</th><th>http_x_forwarded_for</th>';
|
||||
}
|
||||
if ($has_contest_permission) {
|
||||
}
|
||||
if ($is_manager) {
|
||||
$header_row .= '<th>是否参赛</th>';
|
||||
}
|
||||
$header_row .= '</tr>';
|
||||
}
|
||||
$header_row .= '</tr>';
|
||||
|
||||
echoLongTable(
|
||||
echoLongTable(
|
||||
['*'],
|
||||
'contests_registrants',
|
||||
"contest_id = {$contest['id']}",
|
||||
['contest_id' => $contest['id']],
|
||||
'order by username desc',
|
||||
$header_row,
|
||||
function($contestant, $num) use ($myUser, $has_contest_permission, $show_ip, $has_participated) {
|
||||
$user = queryUser($contestant['username']);
|
||||
function ($contestant, $num) use ($is_manager, $show_ip) {
|
||||
$user = UOJUser::query($contestant['username']);
|
||||
|
||||
echo '<tr>';
|
||||
echo '<td>'.$num.'</td>';
|
||||
echo '<td>'.getUserLink($contestant['username']).'</td>';
|
||||
echo '<td>' . $num . '</td>';
|
||||
echo '<td>' . getUserLink($user['username']) . '</td>';
|
||||
if ($show_ip) {
|
||||
echo '<td>'.$user['remote_addr'].'</td>';
|
||||
echo '<td>'.$user['http_x_forwarded_for'].'</td>';
|
||||
echo '<td>' . $user['remote_addr'] . '</td>';
|
||||
echo '<td>' . $user['http_x_forwarded_for'] . '</td>';
|
||||
}
|
||||
if ($has_contest_permission) {
|
||||
echo '<td>'.($contestant['has_participated'] ? 'Yes' : 'No').'</td>';
|
||||
if ($is_manager) {
|
||||
echo '<td>' . ($contestant['has_participated'] ? 'Yes' : 'No') . '</td>';
|
||||
}
|
||||
echo '</tr>';
|
||||
},
|
||||
@ -232,21 +213,21 @@
|
||||
'div_classes' => ['table-responsive', 'card', 'mb-3'],
|
||||
'table_classes' => ['table', 'uoj-table', 'mb-0', 'text-center'],
|
||||
]
|
||||
);
|
||||
?>
|
||||
);
|
||||
?>
|
||||
|
||||
<?php
|
||||
if (isset($add_new_contestant_form)) {
|
||||
if (isset($add_new_contestant_form)) {
|
||||
$add_new_contestant_form->printHTML();
|
||||
}
|
||||
if (isset($add_group_to_contest_form)) {
|
||||
}
|
||||
if (isset($add_group_to_contest_form)) {
|
||||
$add_group_to_contest_form->printHTML();
|
||||
}
|
||||
if (isset($remove_user_from_contest_form)) {
|
||||
}
|
||||
if (isset($remove_user_from_contest_form)) {
|
||||
$remove_user_from_contest_form->printHTML();
|
||||
}
|
||||
if (isset($force_set_user_participated_form)) {
|
||||
}
|
||||
if (isset($force_set_user_participated_form)) {
|
||||
$force_set_user_participated_form->printHTML();
|
||||
}
|
||||
?>
|
||||
}
|
||||
?>
|
||||
<?php echoUOJPageFooter() ?>
|
||||
|
@ -1,66 +1,48 @@
|
||||
<?php
|
||||
requireLib('bootstrap5');
|
||||
requirePHPLib('form');
|
||||
requireLib('bootstrap5');
|
||||
requirePHPLib('form');
|
||||
|
||||
if (!validateUInt($_GET['id']) || !($contest = queryContest($_GET['id']))) {
|
||||
become404Page();
|
||||
}
|
||||
genMoreContestInfo($contest);
|
||||
Auth::check() || redirectToLogin();
|
||||
UOJContest::init(UOJRequest::get('id')) || UOJResponse::page404();
|
||||
UOJContest::cur()->userCanRegister(Auth::user(), ['ensure' => true]);
|
||||
|
||||
if (!Auth::check()) {
|
||||
redirectToLogin();
|
||||
} elseif (!isNormalUser($myUser) && UOJConfig::$data['switch']['force-login']) {
|
||||
become403Page();
|
||||
} elseif (hasRegistered($myUser, $contest)) {
|
||||
if ($contest['cur_progress'] < CONTEST_IN_PROGRESS) {
|
||||
redirectTo('/contests');
|
||||
} elseif ($contest['cur_progress'] == CONTEST_IN_PROGRESS) {
|
||||
redirectTo("/contest/{$contest['id']}/confirm");
|
||||
} else {
|
||||
redirectTo("/contest/{$contest['id']}");
|
||||
}
|
||||
} elseif ($contest['cur_progress'] == CONTEST_IN_PROGRESS && !(isset($contest['extra_config']['extra_registration']) ? $contest['extra_config']['extra_registration'] : '1')) {
|
||||
becomeMsgPage('比赛已经开始,不允许报名。');
|
||||
} elseif ($contest['cur_progress'] > CONTEST_IN_PROGRESS) {
|
||||
redirectTo("/contest/{$contest['id']}");
|
||||
}
|
||||
$register_form = new UOJBs4Form('register');
|
||||
$register_form->handle = function () {
|
||||
UOJContest::cur()->userRegister(Auth::user());
|
||||
};
|
||||
$register_form->submit_button_config['class_str'] = 'btn btn-primary';
|
||||
$register_form->submit_button_config['text'] = '我已阅读规则,确认报名比赛';
|
||||
|
||||
$register_form = new UOJForm('register');
|
||||
$register_form->handle = function() use ($myUser, $contest) {
|
||||
DB::query("replace into contests_registrants (username, contest_id, has_participated) values ('{$myUser['username']}', {$contest['id']}, 0)");
|
||||
if (UOJContest::cur()->progress() == CONTEST_IN_PROGRESS) {
|
||||
$register_form->succ_href = '/contest/' . UOJContest::info('id') . '/confirm';
|
||||
} else {
|
||||
$register_form->succ_href = '/contests';
|
||||
}
|
||||
|
||||
updateContestPlayerNum($contest);
|
||||
};
|
||||
$register_form->submit_button_config['class_str'] = 'btn btn-primary';
|
||||
$register_form->submit_button_config['text'] = '我已阅读规则,确认报名比赛';
|
||||
$register_form->runAtServer();
|
||||
?>
|
||||
|
||||
if ($contest['cur_progress'] == CONTEST_IN_PROGRESS) {
|
||||
$register_form->succ_href = "/contest/{$contest['id']}/confirm";
|
||||
} else {
|
||||
$register_form->succ_href = "/contests";
|
||||
}
|
||||
|
||||
$register_form->runAtServer();
|
||||
?>
|
||||
<?php echoUOJPageHeader('报名 - ' . HTML::stripTags($contest['name'])) ?>
|
||||
<?php echoUOJPageHeader('报名 - ' . UOJContest::info('name')) ?>
|
||||
|
||||
<div class="card mw-100 mx-auto" style="width:800px">
|
||||
<div class="card-body">
|
||||
<h1 class="h2 card-title text-center mb-3">比赛规则</h1>
|
||||
<div class="card-body">
|
||||
<h1 class="card-title text-center mb-3">比赛规则</h1>
|
||||
|
||||
<p class="card-text">您即将报名比赛 “<b><?= $contest['name'] ?></b>”,请在报名前仔细阅读以下比赛规则:</p>
|
||||
<p class="card-text">您即将报名比赛 “<b><?= UOJContest::info('name') ?></b>”,请在报名前仔细阅读以下比赛规则:</p>
|
||||
|
||||
<ul>
|
||||
<?php if ($contest['cur_progress'] == CONTEST_IN_PROGRESS): ?>
|
||||
<li class="text-danger">本场比赛正在进行中,将于 <b><?= $contest['end_time_str'] ?></b> 结束。</li>
|
||||
<?php else: ?>
|
||||
<li>本场比赛将于 <b><?= $contest['start_time_str'] ?></b> 开始,并于 <b><?= $contest['end_time_str'] ?></b> 结束。</li>
|
||||
<?php if (UOJContest::cur()->progress() == CONTEST_IN_PROGRESS) : ?>
|
||||
<li class="text-danger">本场比赛正在进行中,将于 <b><?= UOJContest::info('end_time_str') ?></b> 结束。</li>
|
||||
<?php else : ?>
|
||||
<li>本场比赛将于 <b><?= UOJContest::info('start_time_str') ?></b> 开始,并于 <b><?= UOJContest::info('end_time_str') ?></b> 结束。</li>
|
||||
<?php endif ?>
|
||||
<li>比赛开始后点击 “<b>确认参赛</b>” 按钮才会被视为正式参赛,未正式参赛的选手不会显示在排行榜上。</li>
|
||||
<?php if (!isset($contest['extra_config']['contest_type']) || $contest['extra_config']['contest_type'] == 'OI'): ?>
|
||||
<?php if (UOJContest::cur()->basicRule() == 'OI') : ?>
|
||||
<li>本场比赛为 OI 赛制。比赛中途可以提交代码,但 <b>只显示测样例的结果</b>。</li>
|
||||
<?php elseif ($contest['extra_config']['contest_type'] == 'IOI'): ?>
|
||||
<?php elseif (UOJContest::cur()->basicRule() == 'IOI') : ?>
|
||||
<li>本场比赛为 IOI 赛制。比赛时的提交会测试题目的全部数据,但无法查看数据点详情。</li>
|
||||
<?php elseif (UOJContest::cur()->basicRule() == 'ACM') : ?>
|
||||
<li>本场比赛为 ACM 赛制。</li>
|
||||
<?php endif ?>
|
||||
<li>若选手在比赛中多次提交了同一题,则最后按照 <b>最后一次不是 Compile Error 的提交</b> 计算排行。</li>
|
||||
<li>比赛结束后会进行最终测试,最终测试后的排名为最终排名。</li>
|
||||
@ -69,7 +51,7 @@
|
||||
</ul>
|
||||
|
||||
<?php $register_form->printHTML() ?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php echoUOJPageFooter() ?>
|
||||
|
@ -1,106 +1,108 @@
|
||||
<?php
|
||||
requireLib('bootstrap5');
|
||||
requirePHPLib('form');
|
||||
requireLib('bootstrap5');
|
||||
requirePHPLib('form');
|
||||
|
||||
if (!Auth::check() && UOJConfig::$data['switch']['force-login']) {
|
||||
redirectToLogin();
|
||||
}
|
||||
Auth::check() || redirectToLogin();
|
||||
|
||||
$upcoming_contest_name = null;
|
||||
$upcoming_contest_href = null;
|
||||
$rest_second = 1000000;
|
||||
function echoContest($contest) {
|
||||
global $myUser, $upcoming_contest_name, $upcoming_contest_href, $rest_second;
|
||||
$upcoming_contest_name = null;
|
||||
$upcoming_contest_href = null;
|
||||
$rest_second = 1000000;
|
||||
function echoContest($info) {
|
||||
global $upcoming_contest_name, $upcoming_contest_href, $rest_second;
|
||||
|
||||
$contest_name_link = <<<EOD
|
||||
<a class="text-decoration-none" href="/contest/{$contest['id']}">{$contest['name']}</a>
|
||||
EOD;
|
||||
genMoreContestInfo($contest);
|
||||
if ($contest['cur_progress'] == CONTEST_NOT_STARTED) {
|
||||
$cur_rest_second = $contest['start_time']->getTimestamp() - UOJTime::$time_now->getTimestamp();
|
||||
$contest = new UOJContest($info);
|
||||
|
||||
$contest_name_link = '<a class="text-decoration-none" href="/contest/' . $contest->info['id'] . '">' . $contest->info['name'] . '</a>';
|
||||
|
||||
if ($contest->progress() == CONTEST_NOT_STARTED) {
|
||||
$cur_rest_second = $contest->info['start_time']->getTimestamp() - UOJTime::$time_now->getTimestamp();
|
||||
if ($cur_rest_second < $rest_second) {
|
||||
$upcoming_contest_name = $contest['name'];
|
||||
$upcoming_contest_href = "/contest/{$contest['id']}";
|
||||
$upcoming_contest_name = $contest->info['name'];
|
||||
$upcoming_contest_href = '/contest/' . $contest->info['id'];
|
||||
$rest_second = $cur_rest_second;
|
||||
}
|
||||
if ($myUser != null && hasRegistered($myUser, $contest)) {
|
||||
$contest_name_link .= '<sup><a class="text-decoration-none" style="color:green">'.UOJLocale::get('contests::registered').'</a></sup>';
|
||||
if ($contest->userHasRegistered(Auth::user())) {
|
||||
$contest_name_link .= '<sup><a class="text-decoration-none" style="color:green">' . UOJLocale::get('contests::registered') . '</a></sup>';
|
||||
} else {
|
||||
$contest_name_link .= '<sup><a class="text-decoration-none" style="color:red" href="/contest/'.$contest['id'].'/register">'.UOJLocale::get('contests::register').'</a></sup>';
|
||||
$contest_name_link .= '<sup><a class="text-decoration-none" style="color:red" href="/contest/' . $contest->info['id'] . '/register">' . UOJLocale::get('contests::register') . '</a></sup>';
|
||||
}
|
||||
} elseif ($contest['cur_progress'] == CONTEST_IN_PROGRESS) {
|
||||
if (hasRegistered($myUser, $contest)) {
|
||||
$contest_name_link .= '<sup><a class="text-decoration-none" style="color:blue" href="/contest/'.$contest['id'].'">'.UOJLocale::get('contests::in progress').'</a></sup>';
|
||||
} elseif ($contest->progress() == CONTEST_IN_PROGRESS) {
|
||||
if ($contest->allowExtraRegistration() && !$contest->userHasRegistered(Auth::user())) {
|
||||
$contest_name_link .= '<sup><a class="text-decoration-none" style="color:red" href="/contest/' . $contest->info['id'] . '/register">' . UOJLocale::get('contests::register') . ' (' . UOJLocale::get('contests::in progress') . ')' . '</a></sup>';
|
||||
} else {
|
||||
$contest_name_link .= '<sup><a class="text-decoration-none" style="color:blue" href="/contest/'.$contest['id'].'/register">'.UOJLocale::get('contests::in progress').'</a></sup>';
|
||||
$contest_name_link .= '<sup><a class="text-decoration-none" style="color:blue" href="/contest/' . $contest->info['id'] . '">' . UOJLocale::get('contests::in progress') . '</a></sup>';
|
||||
}
|
||||
} elseif ($contest->progress() == CONTEST_FINISHED) {
|
||||
$contest_name_link .= '<sup><a class="text-decoration-none" style="color:grey" href="/contest/' . $contest->info['id'] . '/standings">' . UOJLocale::get('contests::ended') . '</a></sup>';
|
||||
} else {
|
||||
if ($contest->basicRule() == 'OI') {
|
||||
if ($contest->progress() == CONTEST_PENDING_FINAL_TEST) {
|
||||
$contest_name_link .= '<sup><a style="color:blue" href="/contest/' . $contest->info['id'] . '">' . UOJLocale::get('contests::pending final test') . '</a></sup>';
|
||||
} elseif ($contest->progress() == CONTEST_TESTING) {
|
||||
$contest_name_link .= '<sup><a style="color:blue" href="/contest/' . $contest->info['id'] . '">' . UOJLocale::get('contests::final testing') . '</a></sup>';
|
||||
}
|
||||
} elseif ($contest->basicRule() == 'ACM' || $contest->basicRule() == 'IOI') {
|
||||
$contest_name_link .= '<sup><a style="color:blue" href="/contest/' . $contest->info['id'] . '">' . UOJLocale::get('contests::official results to be announced') . '</a></sup>';
|
||||
}
|
||||
} elseif ($contest['cur_progress'] == CONTEST_PENDING_FINAL_TEST) {
|
||||
$contest_name_link .= '<sup><a class="text-decoration-none" style="color:blue" href="/contest/'.$contest['id'].'">'.UOJLocale::get('contests::pending final test').'</a></sup>';
|
||||
} elseif ($contest['cur_progress'] == CONTEST_TESTING) {
|
||||
$contest_name_link .= '<sup><a class="text-decoration-none" style="color:blue" href="/contest/'.$contest['id'].'">'.UOJLocale::get('contests::final testing').'</a></sup>';
|
||||
} elseif ($contest['cur_progress'] == CONTEST_FINISHED) {
|
||||
$contest_name_link .= '<sup><a class="text-decoration-none" style="color:grey" href="/contest/'.$contest['id'].'/standings">'.UOJLocale::get('contests::ended').'</a></sup>';
|
||||
}
|
||||
|
||||
$last_hour = round($contest['last_min'] / 60, 2);
|
||||
|
||||
$click_zan_block = getClickZanBlock('C', $contest['id'], $contest['zan']);
|
||||
$last_hour = round($contest->info['last_min'] / 60, 2);
|
||||
echo '<tr>';
|
||||
echo '<td>', $contest_name_link, '</td>';
|
||||
echo '<td>', '<a class="text-decoration-none" href="'.HTML::timeanddate_url($contest['start_time'], array('duration' => $contest['last_min'])).'">'.$contest['start_time_str'].'</a>', '</td>';
|
||||
echo '<td>', '<a class="text-decoration-none" href="' . HTML::timeanddate_url($contest->info['start_time'], ['duration' => $contest->info['last_min']]) . '">' . $contest->info['start_time_str'] . '</a>', '</td>';
|
||||
echo '<td>', UOJLocale::get('hours', $last_hour), '</td>';
|
||||
echo '<td>', '<a class="text-decoration-none" href="/contest/'.$contest['id'].'/registrants">', '<i class="bi bi-person-fill"></i>', ' ×'.$contest['player_num'].'</a>', '</td>';
|
||||
echo '<td>', '<div class="text-left">'.$click_zan_block.'</div>', '</td>';
|
||||
echo '<td>', '<a class="text-decoration-none" href="/contest/' . $contest->info['id'] . '/registrants">', '<i class="bi bi-person-fill"></i>', ' ×' . $contest->info['player_num'] . '</a>', '</td>';
|
||||
echo '<td>', '<div class="text-left">' . ClickZans::getBlock('C', $contest->info['id'], $contest->info['zan']) . '</div>', '</td>';
|
||||
echo '</tr>';
|
||||
}
|
||||
?>
|
||||
}
|
||||
?>
|
||||
<?php echoUOJPageHeader(UOJLocale::get('contests')) ?>
|
||||
|
||||
<!-- title container -->
|
||||
<div class="d-flex justify-content-between">
|
||||
<h1 class="h2">
|
||||
<h1>
|
||||
<?= UOJLocale::get('contests') ?>
|
||||
</h1>
|
||||
</h1>
|
||||
|
||||
<?php if (isSuperUser($myUser)): ?>
|
||||
<div class="text-end">
|
||||
<?php if (isSuperUser($myUser)) : ?>
|
||||
<div class="text-end">
|
||||
<a href="/contest/new" class="btn btn-primary"><?= UOJLocale::get('contests::add new contest') ?></a>
|
||||
</div>
|
||||
<?php endif ?>
|
||||
</div>
|
||||
<?php endif ?>
|
||||
|
||||
</div>
|
||||
<!-- end title container -->
|
||||
|
||||
<h2 class="h4">
|
||||
<h2>
|
||||
<?= UOJLocale::get('contests::current or upcoming contests') ?>
|
||||
</h2>
|
||||
<?php
|
||||
$table_header = '';
|
||||
$table_header .= '<tr>';
|
||||
$table_header .= '<th>'.UOJLocale::get('contests::contest name').'</th>';
|
||||
$table_header .= '<th style="width:15em;">'.UOJLocale::get('contests::start time').'</th>';
|
||||
$table_header .= '<th style="width:100px;">'.UOJLocale::get('contests::duration').'</th>';
|
||||
$table_header .= '<th style="width:100px;">'.UOJLocale::get('contests::the number of registrants').'</th>';
|
||||
$table_header .= '<th style="width:180px;">'.UOJLocale::get('appraisal').'</th>';
|
||||
$table_header .= '</tr>';
|
||||
$table_header = '';
|
||||
$table_header .= '<tr>';
|
||||
$table_header .= '<th>' . UOJLocale::get('contests::contest name') . '</th>';
|
||||
$table_header .= '<th style="width:15em;">' . UOJLocale::get('contests::start time') . '</th>';
|
||||
$table_header .= '<th style="width:100px;">' . UOJLocale::get('contests::duration') . '</th>';
|
||||
$table_header .= '<th style="width:100px;">' . UOJLocale::get('contests::the number of registrants') . '</th>';
|
||||
$table_header .= '<th style="width:180px;">' . UOJLocale::get('appraisal') . '</th>';
|
||||
$table_header .= '</tr>';
|
||||
|
||||
$table_config = [
|
||||
$table_config = [
|
||||
'page_len' => 40,
|
||||
'div_classes' => ['card', 'mb-3'],
|
||||
'table_classes' => ['table', 'uoj-table', 'mb-0', 'text-center'],
|
||||
];
|
||||
];
|
||||
|
||||
echoLongTable(
|
||||
echoLongTable(
|
||||
['*'],
|
||||
'contests',
|
||||
"status != 'finished'",
|
||||
[["status", "!=", 'finished']],
|
||||
'order by start_time asc, id asc',
|
||||
$table_header,
|
||||
echoContest,
|
||||
'echoContest',
|
||||
$table_config
|
||||
);
|
||||
);
|
||||
|
||||
if ($rest_second <= 86400) {
|
||||
if ($rest_second <= 86400) {
|
||||
$notification = json_encode($upcoming_contest_name . " 已经开始了。是否要跳转到比赛页面?");
|
||||
echo <<<EOD
|
||||
<div class="text-center bot-buffer-lg">
|
||||
@ -115,21 +117,23 @@ $('#contest-countdown').countdown($rest_second, function() {
|
||||
</script>
|
||||
</div>
|
||||
EOD;
|
||||
}
|
||||
?>
|
||||
}
|
||||
?>
|
||||
|
||||
<h2 class="h4">
|
||||
<h2>
|
||||
<?= UOJLocale::get('contests::ended contests') ?>
|
||||
</h2>
|
||||
|
||||
<?php
|
||||
echoLongTable(
|
||||
echoLongTable(
|
||||
['*'],
|
||||
'contests',
|
||||
"status = 'finished'",
|
||||
['status' => 'finished'],
|
||||
'order by start_time desc, id desc',
|
||||
$table_header,
|
||||
echoContest,
|
||||
'echoContest',
|
||||
$table_config
|
||||
);
|
||||
?>
|
||||
);
|
||||
?>
|
||||
|
||||
<?php echoUOJPageFooter() ?>
|
||||
|
@ -1,140 +1,61 @@
|
||||
<?php
|
||||
requirePHPLib('judger');
|
||||
requirePHPLib('judger');
|
||||
|
||||
if (!Auth::check() && UOJConfig::$data['switch']['force-login']) {
|
||||
redirectToLogin();
|
||||
}
|
||||
$auth = false;
|
||||
if (UOJRequest::get('auth') === 'judger') {
|
||||
authenticateJudger() || UOJResponse::page403();
|
||||
$auth = true;
|
||||
} else {
|
||||
Auth::check() || redirectToLogin();
|
||||
}
|
||||
|
||||
if (!isNormalUser($myUser) && UOJConfig::$data['switch']['force-login'] && $_GET['type'] != 'attachment') {
|
||||
become403Page();
|
||||
}
|
||||
|
||||
switch ($_GET['type']) {
|
||||
switch (UOJRequest::get('type')) {
|
||||
case 'attachment':
|
||||
if (!validateUInt($_GET['id']) || !($problem = queryProblemBrief($_GET['id']))) {
|
||||
become404Page();
|
||||
UOJProblem::init(UOJRequest::get('id')) || UOJResponse::page404();
|
||||
if (!$auth) {
|
||||
UOJProblem::cur()->userCanDownloadAttachments(Auth::user()) || UOJResponse::page404();
|
||||
}
|
||||
|
||||
$visible = isProblemVisibleToUser($problem, $myUser);
|
||||
if (!$visible && $myUser != null) {
|
||||
$result = DB::query("select contest_id from contests_problems where problem_id = {$_GET['id']}");
|
||||
while (list($contest_id) = DB::fetch($result, MYSQLI_NUM)) {
|
||||
$contest = queryContest($contest_id);
|
||||
genMoreContestInfo($contest);
|
||||
if ($contest['cur_progress'] != CONTEST_NOT_STARTED && hasRegistered($myUser, $contest) && queryContestProblemRank($contest, $problem)) {
|
||||
$visible = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!$visible) {
|
||||
become404Page();
|
||||
}
|
||||
$file_name = UOJProblem::cur()->getDataFolderPath() . '/download.zip';
|
||||
$download_name = 'problem_' . UOJProblem::info('id') . '_attachment.zip';
|
||||
|
||||
$id = $_GET['id'];
|
||||
|
||||
$file_name = "/var/uoj_data/$id/download.zip";
|
||||
$download_name = "problem_{$id}_attachment.zip";
|
||||
break;
|
||||
|
||||
case 'problem':
|
||||
if (!validateUInt($_GET['id']) || !($problem = queryProblemBrief($_GET['id']))) {
|
||||
become404Page();
|
||||
UOJProblem::init(UOJRequest::get('id')) || UOJResponse::page404();
|
||||
|
||||
if (!$auth) {
|
||||
UOJProblem::cur()->userCanDownloadTestData(Auth::user()) || UOJResponse::page404();
|
||||
}
|
||||
|
||||
if (!hasProblemPermission($myUser, $problem)) {
|
||||
become403Page();
|
||||
}
|
||||
|
||||
$id = $_GET['id'];
|
||||
$file_name = "/var/uoj_data/$id.zip";
|
||||
$download_name = "problem_$id.zip";
|
||||
$file_name = UOJProblem::cur()->getDataZipPath();
|
||||
$download_name = 'problem_' . UOJProblem::info('id') . '.zip';
|
||||
|
||||
break;
|
||||
|
||||
case 'testcase':
|
||||
if (!validateUInt($_GET['id']) || !($problem = queryProblemBrief($_GET['id']))) {
|
||||
become404Page();
|
||||
case 'submission':
|
||||
if (!$auth) {
|
||||
isSuperUser(Auth::user()) || UOJResponse::page404();
|
||||
}
|
||||
|
||||
if (!hasProblemPermission($myUser, $problem)) {
|
||||
become404Page();
|
||||
}
|
||||
|
||||
$id = $_GET['id'];
|
||||
$problem_conf = getUOJConf("/var/uoj_data/$id/problem.conf");
|
||||
|
||||
if ($problem_conf == -1 || $problem_conf == -2) {
|
||||
become404Page();
|
||||
}
|
||||
|
||||
if (!validateUInt($_GET['testcase_id'])) {
|
||||
become404Page();
|
||||
}
|
||||
|
||||
$testcase_id = $_GET['testcase_id'];
|
||||
$testcase_group = isset($_GET['testcase_group']) && $_GET['testcase_group'] == 'extra' ? 'extra' : 'normal';
|
||||
|
||||
if ($testcase_group == 'extra') {
|
||||
$n_ex_tests = getUOJConfVal($problem_conf, 'n_ex_tests', 0);
|
||||
|
||||
if ($testcase_id < 1 || $testcase_id > $n_ex_tests) {
|
||||
become404Page();
|
||||
}
|
||||
|
||||
switch ($_GET['testcase_type']) {
|
||||
case 'input':
|
||||
$file_name = "/var/uoj_data/$id/" . getUOJProblemExtraInputFileName($problem_conf, $testcase_id);
|
||||
$download_name = getUOJProblemExtraInputFileName($problem_conf, $testcase_id);
|
||||
$file_name = UOJContext::storagePath() . "/submission/{$_GET['id']}/{$_GET['rand_str_id']}";
|
||||
$download_name = "submission.zip";
|
||||
break;
|
||||
|
||||
case 'output':
|
||||
$file_name = "/var/uoj_data/$id/" . getUOJProblemExtraOutputFileName($problem_conf, $testcase_id);
|
||||
$download_name = getUOJProblemExtraOutputFileName($problem_conf, $testcase_id);
|
||||
break;
|
||||
|
||||
default:
|
||||
become404Page();
|
||||
case 'tmp':
|
||||
if (!$auth) {
|
||||
isSuperUser(Auth::user()) || UOJResponse::page404();
|
||||
}
|
||||
} else {
|
||||
$n_tests = getUOJConfVal($problem_conf, 'n_tests', 10);
|
||||
|
||||
if ($testcase_id < 1 || $testcase_id > $n_tests) {
|
||||
become404Page();
|
||||
}
|
||||
|
||||
switch ($_GET['testcase_type']) {
|
||||
case 'input':
|
||||
$file_name = "/var/uoj_data/$id/" . getUOJProblemInputFileName($problem_conf, $testcase_id);
|
||||
$download_name = getUOJProblemInputFileName($problem_conf, $testcase_id);
|
||||
break;
|
||||
case 'output':
|
||||
$file_name = "/var/uoj_data/$id/" . getUOJProblemOutputFileName($problem_conf, $testcase_id);
|
||||
$download_name = getUOJProblemOutputFileName($problem_conf, $testcase_id);
|
||||
break;
|
||||
default:
|
||||
become404Page();
|
||||
}
|
||||
}
|
||||
|
||||
$file_name = UOJContext::storagePath() . "/tmp/{$_GET['rand_str_id']}";
|
||||
$download_name = "tmp";
|
||||
break;
|
||||
|
||||
case 'testlib.h':
|
||||
$file_name = "/opt/uoj/judger/uoj_judger/include/testlib.h";
|
||||
$download_name = "testlib.h";
|
||||
$file_name = UOJLocalRun::$judger_include_path . '/testlib.h';
|
||||
$download_name = 'testlib.h';
|
||||
break;
|
||||
|
||||
default:
|
||||
become404Page();
|
||||
}
|
||||
UOJResponse::page404();
|
||||
}
|
||||
|
||||
$finfo = finfo_open(FILEINFO_MIME);
|
||||
$mimetype = finfo_file($finfo, $file_name);
|
||||
if ($mimetype === false) {
|
||||
become404Page();
|
||||
}
|
||||
finfo_close($finfo);
|
||||
|
||||
header("X-Sendfile: $file_name");
|
||||
header("Content-type: $mimetype");
|
||||
header("Content-Disposition: attachment; filename=$download_name");
|
||||
?>
|
||||
UOJResponse::xsendfile($file_name, ['attachment' => $download_name]);
|
||||
|
@ -1,18 +1,17 @@
|
||||
<?php
|
||||
requireLib('bootstrap5');
|
||||
requireLib('hljs');
|
||||
requireLib('mathjax');
|
||||
?>
|
||||
requireLib('bootstrap5');
|
||||
requireLib('hljs');
|
||||
requireLib('mathjax');
|
||||
?>
|
||||
|
||||
<?php echoUOJPageHeader(UOJLocale::get('help')) ?>
|
||||
|
||||
<div class="row">
|
||||
<!-- left col -->
|
||||
<div class="col-lg-9">
|
||||
|
||||
<div class="card card-default">
|
||||
<article class="card-body">
|
||||
<h1 class="h3 card-title mb-3">常见问题及其解答 (FAQ)</h1>
|
||||
<!-- left col -->
|
||||
<div class="col-lg-9">
|
||||
<div class="card card-default">
|
||||
<article class="card-body">
|
||||
<h1 class="h2 card-title mb-3">常见问题及其解答 (FAQ)</h1>
|
||||
|
||||
<h5 class="mt-4"><?= UOJConfig::$data['profile']['oj-name-short'] ?> 是什么</h5>
|
||||
<p class="card-text">
|
||||
@ -107,16 +106,15 @@
|
||||
<p class="card-text">
|
||||
请移步 <a href="https://s2oj.github.io/">S2OJ 使用文档</a>。
|
||||
</p>
|
||||
</article>
|
||||
</div>
|
||||
</article>
|
||||
</div>
|
||||
<!-- end left col -->
|
||||
</div>
|
||||
|
||||
<!-- end left col -->
|
||||
</div>
|
||||
|
||||
<!-- right col -->
|
||||
<aside class="col-lg-3 mt-3 mt-lg-0">
|
||||
<?php uojIncludeView('sidebar', array()) ?>
|
||||
</aside>
|
||||
<!-- right col -->
|
||||
<aside class="col-lg-3 mt-3 mt-lg-0">
|
||||
<?php uojIncludeView('sidebar') ?>
|
||||
</aside>
|
||||
|
||||
</div>
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
<?php
|
||||
requirePHPLib('form');
|
||||
|
||||
$forgot_form = new UOJForm('forgot');
|
||||
$forgot_form = new UOJBs4Form('forgot');
|
||||
$forgot_form->addInput('username', 'text', '用户名', '',
|
||||
function($username, &$vdata) {
|
||||
if (!validateUsername($username)) {
|
||||
|
@ -4,14 +4,10 @@
|
||||
requirePHPLib('judger');
|
||||
requirePHPLib('data');
|
||||
|
||||
if (!Auth::check() && UOJConfig::$data['switch']['force-login']) {
|
||||
if (!Auth::check()) {
|
||||
redirectToLogin();
|
||||
}
|
||||
|
||||
if (!isNormalUser($myUser) && UOJConfig::$data['switch']['force-login']) {
|
||||
become403Page();
|
||||
}
|
||||
|
||||
$group_id = $_GET['id'];
|
||||
if (!validateUInt($group_id) || !($group = queryGroup($group_id))) {
|
||||
become404Page();
|
||||
@ -30,7 +26,7 @@
|
||||
|
||||
<!-- title -->
|
||||
<div class="d-flex justify-content-between">
|
||||
<h1 class="h2">
|
||||
<h1>
|
||||
<?php if ($group['is_hidden']): ?>
|
||||
<span class="fs-5 text-danger">[隐藏]</span>
|
||||
<?php endif ?>
|
||||
@ -51,7 +47,7 @@
|
||||
<!-- main content -->
|
||||
<div class="card mb-3">
|
||||
<div class="card-body">
|
||||
<h2 class="h4">
|
||||
<h2 class="h3">
|
||||
<?= UOJLocale::get('group announcement') ?>
|
||||
</h2>
|
||||
<?php if ($group['announcement']): ?>
|
||||
@ -68,7 +64,7 @@
|
||||
|
||||
<div class="card mb-3">
|
||||
<div class="card-body">
|
||||
<h2 class="card-title h4">
|
||||
<h2 class="card-title h3">
|
||||
<?= UOJLocale::get('news') ?>
|
||||
</h5>
|
||||
<ul class="mb-0">
|
||||
@ -92,7 +88,7 @@
|
||||
|
||||
<div class="card card-default mb-3">
|
||||
<div class="card-body">
|
||||
<h2 class="card-title h4">
|
||||
<h2 class="card-title h3">
|
||||
<?= UOJLocale::get('assignments') ?>
|
||||
</h5>
|
||||
<?php
|
||||
@ -139,7 +135,7 @@ EOD,
|
||||
|
||||
<div class="card card-default mb-3">
|
||||
<div class="card-body">
|
||||
<h2 class="card-title h4">
|
||||
<h2 class="card-title h3">
|
||||
<?= UOJLocale::get('top solver') ?>
|
||||
</h5>
|
||||
<?php echoRanklist([
|
||||
|
@ -1,12 +1,8 @@
|
||||
<?php
|
||||
if (!Auth::check() && UOJConfig::$data['switch']['force-login']) {
|
||||
if (!Auth::check()) {
|
||||
redirectToLogin();
|
||||
}
|
||||
|
||||
if (!isNormalUser($myUser) && UOJConfig::$data['switch']['force-login']) {
|
||||
become403Page();
|
||||
}
|
||||
|
||||
requirePHPLib('form');
|
||||
requireLib('bootstrap5');
|
||||
|
||||
@ -40,7 +36,7 @@
|
||||
<!-- left col -->
|
||||
<div class="col-lg-9">
|
||||
|
||||
<h1 class="h2">
|
||||
<h1>
|
||||
<small class="fs-4">作业:</small><?= $list['title'] ?>
|
||||
</h1>
|
||||
<ul class="mt-3">
|
||||
|
@ -43,7 +43,7 @@
|
||||
}
|
||||
|
||||
if ($cur_tab == 'profile') {
|
||||
$update_profile_form = new UOJForm('update_profile');
|
||||
$update_profile_form = new UOJBs4Form('update_profile');
|
||||
$update_profile_form->addVInput('name', 'text', '名称', $group['title'],
|
||||
function($title, &$vdata) {
|
||||
if ($title == '') {
|
||||
@ -107,7 +107,7 @@ function(res) {
|
||||
$(window).scrollTop(0);
|
||||
}
|
||||
EOD);
|
||||
$update_profile_form->submit_button_config['margin_class'] = 'mt-3';
|
||||
$update_profile_form->submit_button_config['class_str'] = 'btn btn-secondary mt-3';
|
||||
$update_profile_form->submit_button_config['text'] = '更新';
|
||||
$update_profile_form->runAtServer();
|
||||
} elseif ($cur_tab == 'assignments') {
|
||||
@ -127,7 +127,7 @@ EOD);
|
||||
dieWithAlert('移除成功!');
|
||||
}
|
||||
|
||||
$add_new_assignment_form = new UOJForm('add_new_assignment');
|
||||
$add_new_assignment_form = new UOJBs4Form('add_new_assignment');
|
||||
$add_new_assignment_form->addVInput('new_assignment_list_id', 'text', '题单 ID', '',
|
||||
function ($list_id, &$vdata) use ($group) {
|
||||
if (!validateUInt($list_id)) {
|
||||
@ -177,7 +177,7 @@ EOD);
|
||||
'message' => '题单 #' . $vdata['list_id'] . ' 已经被添加到作业列表中,结束时间为 ' . $vdata['end_time']->format('Y-m-d H:i:s') . '。'
|
||||
]);
|
||||
};
|
||||
$add_new_assignment_form->submit_button_config['margin_class'] = 'mt-3';
|
||||
$add_new_assignment_form->submit_button_config['class_str'] = 'btn btn-secondary mt-3';
|
||||
$add_new_assignment_form->submit_button_config['text'] = '添加';
|
||||
$add_new_assignment_form->setAjaxSubmit(<<<EOD
|
||||
function(res) {
|
||||
@ -223,7 +223,7 @@ EOD);
|
||||
dieWithAlert('移除成功!');
|
||||
}
|
||||
|
||||
$add_new_user_form = new UOJForm('add_new_user');
|
||||
$add_new_user_form = new UOJBs4Form('add_new_user');
|
||||
$add_new_user_form->addVInput('new_username', 'text', '用户名', '',
|
||||
function ($username, &$vdata) {
|
||||
global $group_id;
|
||||
@ -246,7 +246,7 @@ EOD);
|
||||
},
|
||||
null
|
||||
);
|
||||
$add_new_user_form->submit_button_config['margin_class'] = 'mt-3';
|
||||
$add_new_user_form->submit_button_config['class_str'] = 'btn btn-secondary mt-3';
|
||||
$add_new_user_form->submit_button_config['text'] = '添加';
|
||||
$add_new_user_form->handle = function(&$vdata) use ($group) {
|
||||
DB::insert("insert into groups_users (group_id, username) values ({$group['id']}, '{$vdata['username']}')");
|
||||
@ -277,7 +277,7 @@ EOD);
|
||||
?>
|
||||
<?php echoUOJPageHeader('管理 - ' . $group['title']); ?>
|
||||
|
||||
<h1 class="h2 d-block d-md-inline-block">
|
||||
<h1 class="d-block d-md-inline-block">
|
||||
<?= $group['title'] ?>
|
||||
<small class="fs-5">(ID: #<?= $group['id'] ?>)</small>
|
||||
管理
|
||||
|
@ -1,20 +1,16 @@
|
||||
<?php
|
||||
requireLib('bootstrap5');
|
||||
requirePHPLib('form');
|
||||
requirePHPLib('judger');
|
||||
requirePHPLib('data');
|
||||
requireLib('bootstrap5');
|
||||
requirePHPLib('form');
|
||||
requirePHPLib('judger');
|
||||
requirePHPLib('data');
|
||||
|
||||
if (!Auth::check() && UOJConfig::$data['switch']['force-login']) {
|
||||
if (!Auth::check()) {
|
||||
redirectToLogin();
|
||||
}
|
||||
}
|
||||
|
||||
if (!isNormalUser($myUser) && UOJConfig::$data['switch']['force-login']) {
|
||||
become403Page();
|
||||
}
|
||||
|
||||
if (isSuperUser($myUser)) {
|
||||
$new_group_form = new UOJForm('new_group');
|
||||
$new_group_form->handle = function() {
|
||||
if (isSuperUser($myUser)) {
|
||||
$new_group_form = new UOJBs4Form('new_group');
|
||||
$new_group_form->handle = function () {
|
||||
DB::query("insert into `groups` (title, is_hidden) values ('新小组', 1)");
|
||||
};
|
||||
$new_group_form->submit_button_config['align'] = 'right';
|
||||
@ -22,33 +18,30 @@
|
||||
$new_group_form->submit_button_config['text'] = UOJLocale::get('add new group');
|
||||
$new_group_form->submit_button_config['smart_confirm'] = '';
|
||||
$new_group_form->runAtServer();
|
||||
}
|
||||
?>
|
||||
}
|
||||
?>
|
||||
|
||||
<?php echoUOJPageHeader(UOJLocale::get('groups')) ?>
|
||||
|
||||
<div class="row">
|
||||
|
||||
<!-- left col -->
|
||||
<div class="col-lg-9">
|
||||
|
||||
<!-- title container -->
|
||||
<div class="d-flex justify-content-between">
|
||||
|
||||
<h1 class="h2">
|
||||
<!-- left col -->
|
||||
<div class="col-lg-9">
|
||||
<!-- title container -->
|
||||
<div class="d-flex justify-content-between">
|
||||
<h1>
|
||||
<?= UOJLocale::get('groups') ?>
|
||||
</h1>
|
||||
</h1>
|
||||
|
||||
<?php if (isset($new_group_form)): ?>
|
||||
<div class="text-end mb-2">
|
||||
<?php if (isset($new_group_form)) : ?>
|
||||
<div class="text-end mb-2">
|
||||
<?php $new_group_form->printHTML(); ?>
|
||||
</div>
|
||||
<?php endif ?>
|
||||
</div>
|
||||
<?php endif ?>
|
||||
|
||||
</div>
|
||||
<!-- end title container -->
|
||||
</div>
|
||||
<!-- end title container -->
|
||||
|
||||
<?php
|
||||
<?php
|
||||
$groups_caption = UOJLocale::get('groups');
|
||||
$users_caption = UOJLocale::get('users count');
|
||||
$header = <<<EOD
|
||||
@ -59,31 +52,39 @@
|
||||
</tr>
|
||||
EOD;
|
||||
|
||||
if (isSuperUser($myUser)) {
|
||||
if (isSuperUser(Auth::user())) {
|
||||
$cond = "1";
|
||||
} else {
|
||||
$cond = 'is_hidden = 0';
|
||||
$cond = ["is_hidden" => false];
|
||||
}
|
||||
|
||||
echoLongTable(
|
||||
['a.id as group_id', 'a.title as title', 'a.is_hidden as is_hidden', 'count(b.username) as user_count'],
|
||||
"`groups` a left join groups_users b on a.id = b.group_id",
|
||||
['id', 'title', 'is_hidden'],
|
||||
"`groups`",
|
||||
$cond,
|
||||
'group by a.id order by a.id asc',
|
||||
'order by id asc',
|
||||
$header,
|
||||
function ($group) use ($myUser) {
|
||||
function ($group) {
|
||||
$users_count = DB::selectCount([
|
||||
"select count(*)",
|
||||
"from", "groups_users",
|
||||
"where", [
|
||||
"group_id" => $group['id'],
|
||||
],
|
||||
]);
|
||||
|
||||
echo '<tr class="text-center">';
|
||||
echo '<td>';
|
||||
echo '#', $group['group_id'], '</td>';
|
||||
echo '#', $group['id'], '</td>';
|
||||
|
||||
echo '<td class="text-start">';
|
||||
echo '<a class="text-decoration-none" href="/group/', $group['group_id'], '">', $group['title'], '</a>';
|
||||
echo '<a class="text-decoration-none" href="/group/', $group['id'], '">', $group['title'], '</a>';
|
||||
if ($group['is_hidden']) {
|
||||
echo ' <span class="badge text-bg-danger"><i class="bi bi-eye-slash-fill"></i> ', UOJLocale::get('hidden'), '</span> ';
|
||||
}
|
||||
echo '</td>';
|
||||
|
||||
echo "<td>{$group['user_count']}</td>";
|
||||
echo "<td>{$users_count}</td>";
|
||||
|
||||
echo '</tr>';
|
||||
},
|
||||
@ -92,19 +93,17 @@ EOD;
|
||||
'div_classes' => ['card', 'my-3'],
|
||||
'table_classes' => ['table', 'uoj-table', 'mb-0'],
|
||||
'head_pagination' => true,
|
||||
'pagination_table' => "`groups`",
|
||||
]
|
||||
);
|
||||
?>
|
||||
<!-- end left col -->
|
||||
</div>
|
||||
|
||||
<!-- end left col -->
|
||||
</div>
|
||||
|
||||
<!-- right col -->
|
||||
<aside class="col-lg-3 mt-3 mt-lg-0">
|
||||
<?php uojIncludeView('sidebar', array()); ?>
|
||||
</aside>
|
||||
|
||||
<!-- right col -->
|
||||
<aside class="col-lg-3 mt-3 mt-lg-0">
|
||||
<?php uojIncludeView('sidebar') ?>
|
||||
</aside>
|
||||
<!-- end right col -->
|
||||
</div>
|
||||
|
||||
<?php echoUOJPageFooter() ?>
|
||||
|
@ -1,101 +1,117 @@
|
||||
<?php
|
||||
requirePHPLib('form');
|
||||
requireLib('bootstrap5');
|
||||
requireLib('hljs');
|
||||
requirePHPLib('form');
|
||||
requirePHPLib('judger');
|
||||
requirePHPLib('data');
|
||||
requireLib('bootstrap5');
|
||||
requireLib('hljs');
|
||||
|
||||
if (!Auth::check() && UOJConfig::$data['switch']['force-login']) {
|
||||
redirectToLogin();
|
||||
}
|
||||
Auth::check() || redirectToLogin();
|
||||
UOJHack::init(UOJRequest::get('id')) || UOJResponse::page404();
|
||||
UOJHack::cur()->setProblem() || UOJResponse::page404();
|
||||
UOJHack::cur()->userCanView(Auth::user(), ['ensure' => true]);
|
||||
|
||||
if (!isNormalUser($myUser) && UOJConfig::$data['switch']['force-login']) {
|
||||
become403Page();
|
||||
}
|
||||
if (UOJHack::cur()->setSubmission()) {
|
||||
UOJHack::cur()->submission->setAsCur();
|
||||
UOJSubmission::cur()->setProblem(['problem' => UOJHack::cur()->problem]) || UOJResponse::page404();
|
||||
UOJSubmission::cur()->userCanView(Auth::user(), ['ensure' => true]);
|
||||
}
|
||||
|
||||
if (!validateUInt($_GET['id']) || !($hack = queryHack($_GET['id']))) {
|
||||
become404Page();
|
||||
}
|
||||
|
||||
$submission = querySubmission($hack['submission_id']);
|
||||
$problem = queryProblemBrief($submission['problem_id']);
|
||||
$problem_extra_config = getProblemExtraConfig($problem);
|
||||
|
||||
if ($submission['contest_id']) {
|
||||
$contest = queryContest($submission['contest_id']);
|
||||
genMoreContestInfo($contest);
|
||||
} else {
|
||||
$contest = null;
|
||||
}
|
||||
|
||||
if (!isHackVisibleToUser($hack, $problem, $myUser)) {
|
||||
become403Page();
|
||||
}
|
||||
|
||||
if (isSuperUser($myUser)) {
|
||||
$delete_form = new UOJForm('delete');
|
||||
$delete_form->handle = function() {
|
||||
global $hack;
|
||||
DB::query("delete from hacks where id = {$hack['id']}");
|
||||
if (UOJHack::cur()->userCanDelete(Auth::user())) {
|
||||
$delete_form = new UOJBs4Form('delete');
|
||||
$delete_form->handle = function () {
|
||||
DB::delete([
|
||||
"delete from hacks",
|
||||
"where", ["id" => UOJHack::info('id')]
|
||||
]);
|
||||
};
|
||||
$delete_form->submit_button_config['class_str'] = 'btn btn-danger';
|
||||
$delete_form->submit_button_config['text'] = '删除此Hack';
|
||||
$delete_form->submit_button_config['align'] = 'right';
|
||||
$delete_form->submit_button_config['text'] = '删除此 Hack';
|
||||
$delete_form->submit_button_config['align'] = 'end';
|
||||
$delete_form->submit_button_config['smart_confirm'] = '';
|
||||
$delete_form->succ_href = "/hacks";
|
||||
$delete_form->runAtServer();
|
||||
}
|
||||
}
|
||||
|
||||
$should_show_content = hasViewPermission($problem_extra_config['view_content_type'], $myUser, $problem, $submission);
|
||||
$should_show_all_details = hasViewPermission($problem_extra_config['view_all_details_type'], $myUser, $problem, $submission);
|
||||
$should_show_details = hasViewPermission($problem_extra_config['view_details_type'], $myUser, $problem, $submission);
|
||||
$should_show_details_to_me = isSuperUser($myUser);
|
||||
if ($hack['success'] === null) {
|
||||
$should_show_all_details = false;
|
||||
}
|
||||
if (!isSubmissionFullVisibleToUser($submission, $contest, $problem, $myUser)
|
||||
|| !isHackFullVisibleToUser($hack, $contest, $problem, $myUser)) {
|
||||
$should_show_content = $should_show_all_details = false;
|
||||
}
|
||||
if (UOJHack::cur()->userCanReview(Auth::user())) {
|
||||
$addex_form = new UOJBs4Form('addex');
|
||||
$addex_form->handle = function () {
|
||||
$input = UOJContext::storagePath() . UOJHack::info('input');
|
||||
$new_in = "{$input}_in";
|
||||
$new_out = "{$input}_out";
|
||||
$reason = null;
|
||||
$err = dataAddHackPoint(UOJHack::cur()->problem->info, $new_in, $new_out, $reason, Auth::user());
|
||||
$err === '' || UOJResponse::message($err);
|
||||
unlink($new_in);
|
||||
unlink($new_out);
|
||||
DB::update([
|
||||
"update hacks",
|
||||
"set", [
|
||||
'status' => 'Judged',
|
||||
], "where", ['id' => UOJHack::info('id')]
|
||||
]);
|
||||
};
|
||||
$addex_form->submit_button_config['class_str'] = 'btn btn-danger mt-3';
|
||||
$addex_form->submit_button_config['text'] = '确认无误,添加到测试数据';
|
||||
$addex_form->submit_button_config['align'] = 'end';
|
||||
$addex_form->submit_button_config['smart_confirm'] = '';
|
||||
$addex_form->succ_href = "/hacks";
|
||||
$addex_form->runAtServer();
|
||||
}
|
||||
|
||||
if ($should_show_all_details) {
|
||||
$perm = UOJHack::cur()->viewerCanSeeComponents(Auth::user());
|
||||
?>
|
||||
<?php echoUOJPageHeader(UOJLocale::get('problems::hack') . ' #' . UOJHack::info('id')) ?>
|
||||
|
||||
<h1>
|
||||
<?= UOJLocale::get('problems::hack') . ' #' . UOJHack::info('id') ?>
|
||||
</h1>
|
||||
|
||||
<?php echoHackListOnlyOne(UOJHack::info(), [], Auth::user()) ?>
|
||||
|
||||
<?php if (UOJHack::cur()->hasJudged()) : ?>
|
||||
<?php if ($perm['high_level_details']) : ?>
|
||||
<div class="card mb-3">
|
||||
<div class="card-header fw-bold">
|
||||
<?= UOJLocale::get('details') ?>
|
||||
</div>
|
||||
<div class="card-body p-0">
|
||||
<?php
|
||||
$styler = new HackDetailsStyler();
|
||||
if (!$should_show_details) {
|
||||
if (!$perm['low_level_details']) {
|
||||
$styler->fade_all_details = true;
|
||||
$styler->show_small_tip = false;
|
||||
}
|
||||
}
|
||||
echoJudgmentDetails(UOJHack::info('details'), $styler, 'details');
|
||||
?>
|
||||
<?php echoUOJPageHeader(UOJLocale::get('problems::hack').' #'.$hack['id']) ?>
|
||||
|
||||
<h1 class="h3">
|
||||
<?= UOJLocale::get('problems::hack').' #'.$hack['id'] ?>
|
||||
</h1>
|
||||
|
||||
<?php echoHackListOnlyOne($hack, array('id_hidden' => ''), $myUser) ?>
|
||||
<?php if ($should_show_all_details): ?>
|
||||
<div class="card border-info mb-3">
|
||||
<div class="card-header bg-info">
|
||||
<h4 class="card-title"><?= UOJLocale::get('details') ?></h4>
|
||||
</div>
|
||||
<?php echoJudgementDetails($hack['details'], $styler, 'details') ?>
|
||||
<?php if ($should_show_details_to_me): ?>
|
||||
<?php if ($styler->fade_all_details): ?>
|
||||
<?php if ($perm['manager_view'] && !$perm['low_level_details']) : ?>
|
||||
<hr />
|
||||
<?php echoHackDetails($hack['details'], 'final_details') ?>
|
||||
<?php endif ?>
|
||||
<h4 class="text-info">全部详细信息(仅管理员可见)</h4>
|
||||
<?php echoHackDetails(UOJHack::info('details'), 'all_details') ?>
|
||||
<?php endif ?>
|
||||
</div>
|
||||
</div>
|
||||
<?php endif ?>
|
||||
<?php endif ?>
|
||||
|
||||
<h2 class="h3">
|
||||
<?= UOJLocale::get('problems::submission').' #'.$submission['id'] ?>
|
||||
<h2 class="mt-3">
|
||||
<?= UOJLocale::get('problems::submission') . ' #' . UOJSubmission::info('id') ?>
|
||||
</h2>
|
||||
|
||||
<?php echoSubmissionsListOnlyOne($submission, array(), $myUser) ?>
|
||||
<?php if ($should_show_content): ?>
|
||||
<?php echoSubmissionContent($submission, getProblemSubmissionRequirement($problem)) ?>
|
||||
<?php if (UOJSubmission::cur()) : ?>
|
||||
<?php UOJSubmission::cur()->echoStatusTable(['show_actual_score' => $perm['score']], Auth::user()) ?>
|
||||
<?php if ($perm['content'] || $perm['manager_view']) : ?>
|
||||
<?php UOJSubmission::cur()->echoContent() ?>
|
||||
<?php endif ?>
|
||||
<?php else : ?>
|
||||
<h3 class="text-danger">提交记录信息损坏</h3>
|
||||
<?php endif ?>
|
||||
|
||||
<?php if (isset($delete_form)): ?>
|
||||
<?php if (isset($delete_form)) : ?>
|
||||
<?php $delete_form->printHTML() ?>
|
||||
<?php endif ?>
|
||||
|
||||
<?php if (isset($addex_form)) : ?>
|
||||
<?php $addex_form->printHTML() ?>
|
||||
<?php endif ?>
|
||||
|
||||
<?php echoUOJPageFooter() ?>
|
||||
|
@ -1,40 +1,34 @@
|
||||
<?php
|
||||
requireLib('bootstrap5');
|
||||
requireLib('bootstrap5');
|
||||
|
||||
if (!Auth::check() && UOJConfig::$data['switch']['force-login']) {
|
||||
redirectToLogin();
|
||||
}
|
||||
Auth::check() || redirectToLogin();
|
||||
|
||||
if (!isNormalUser($myUser) && UOJConfig::$data['switch']['force-login']) {
|
||||
become403Page();
|
||||
}
|
||||
$q_problem_id = isset($_GET['problem_id']) && validateUInt($_GET['problem_id']) ? $_GET['problem_id'] : null;
|
||||
$q_submission_id = isset($_GET['submission_id']) && validateUInt($_GET['submission_id']) ? $_GET['submission_id'] : null;
|
||||
$q_hacker = isset($_GET['hacker']) && validateUsername($_GET['hacker']) ? $_GET['hacker'] : null;
|
||||
$q_owner = isset($_GET['owner']) && validateUsername($_GET['owner']) ? $_GET['owner'] : null;
|
||||
|
||||
$conds = array();
|
||||
$conds = [];
|
||||
if ($q_problem_id != null) {
|
||||
$conds[] = ["problem_id" => $q_problem_id];
|
||||
}
|
||||
if ($q_submission_id != null) {
|
||||
$conds[] = ["submission_id" => $q_submission_id];
|
||||
}
|
||||
if ($q_hacker != null) {
|
||||
$conds[] = ["hacker" => $q_hacker];
|
||||
}
|
||||
if ($q_owner != null) {
|
||||
$conds[] = ["owner" => $q_owner];
|
||||
}
|
||||
|
||||
$q_problem_id = isset($_GET['problem_id']) && validateUInt($_GET['problem_id']) ? $_GET['problem_id'] : null;
|
||||
$q_submission_id = isset($_GET['submission_id']) && validateUInt($_GET['submission_id']) ? $_GET['submission_id'] : null;
|
||||
$q_hacker = isset($_GET['hacker']) && validateUsername($_GET['hacker']) ? $_GET['hacker'] : null;
|
||||
$q_owner = isset($_GET['owner']) && validateUsername($_GET['owner']) ? $_GET['owner'] : null;
|
||||
if ($q_problem_id != null) {
|
||||
$conds[] = "problem_id = $q_problem_id";
|
||||
}
|
||||
if ($q_submission_id != null) {
|
||||
$conds[] = "submission_id = $q_submission_id";
|
||||
}
|
||||
if ($q_hacker != null) {
|
||||
$conds[] = "hacker = '$q_hacker'";
|
||||
}
|
||||
if ($q_owner != null) {
|
||||
$conds[] = "owner = '$q_owner'";
|
||||
}
|
||||
|
||||
$selected_all = ' selected="selected"';
|
||||
$selected_succ ='';
|
||||
$selected_fail ='';
|
||||
if (isset($_GET['status']) && validateUInt($_GET['status'])) {
|
||||
$selected_all = ' selected="selected"';
|
||||
$selected_succ = '';
|
||||
$selected_fail = '';
|
||||
if (isset($_GET['status']) && validateUInt($_GET['status'])) {
|
||||
if ($_GET['status'] == 1) {
|
||||
$selected_all = '';
|
||||
$selected_succ =' selected="selected"';
|
||||
$selected_succ = ' selected="selected"';
|
||||
$conds[] = 'success = 1';
|
||||
}
|
||||
if ($_GET['status'] == 2) {
|
||||
@ -42,19 +36,19 @@
|
||||
$selected_fail = ' selected="selected"';
|
||||
$conds[] = 'success = 0';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($conds) {
|
||||
$cond = join($conds, ' and ');
|
||||
} else {
|
||||
if ($conds) {
|
||||
$cond = $conds;
|
||||
} else {
|
||||
$cond = '1';
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
?>
|
||||
<?php echoUOJPageHeader(UOJLocale::get('hacks')) ?>
|
||||
|
||||
<h1 class="h2">
|
||||
<?= UOJLocale::get('hacks') ?>
|
||||
<h1>
|
||||
<?= UOJLocale::get('hacks') ?>
|
||||
</h1>
|
||||
|
||||
<div class="d-none d-sm-block mb-3">
|
||||
@ -77,7 +71,7 @@
|
||||
</label>
|
||||
<div class="input-group">
|
||||
<input type="text" class="form-control form-control-sm" name="hacker" id="input-hacker" value="<?= $q_hacker ?>" maxlength="20" style="width:10em" />
|
||||
<?php if (Auth::check()): ?>
|
||||
<?php if (Auth::check()) : ?>
|
||||
<a id="my-hacks" href="/hacks?hacker=<?= Auth::id() ?>" class="btn btn-outline-secondary btn-sm">
|
||||
我的
|
||||
</a>
|
||||
@ -97,7 +91,7 @@
|
||||
</label>
|
||||
<div class="input-group">
|
||||
<input type="text" class="form-control form-control-sm" name="owner" id="input-owner" value="<?= $q_owner ?>" maxlength="20" style="width:10em" />
|
||||
<?php if (Auth::check()): ?>
|
||||
<?php if (Auth::check()) : ?>
|
||||
<a id="my-owners" href="/hacks?owner=<?= Auth::id() ?>" class="btn btn-outline-secondary btn-sm">
|
||||
我的
|
||||
</a>
|
||||
@ -116,9 +110,9 @@
|
||||
<?= UOJLocale::get('problems::result') ?>:
|
||||
</label>
|
||||
<select class="form-select form-select-sm" id="input-status" name="status">
|
||||
<option value=""<?= $selected_all?>>All</option>
|
||||
<option value="1"<?= $selected_succ ?>>Success!</option>
|
||||
<option value="2"<?= $selected_fail ?>>Failed.</option>
|
||||
<option value="" <?= $selected_all ?>>All</option>
|
||||
<option value="1" <?= $selected_succ ?>>Success!</option>
|
||||
<option value="2" <?= $selected_fail ?>>Failed.</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="col-auto">
|
||||
@ -129,7 +123,9 @@
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<?php echoHacksList($cond,
|
||||
<?php
|
||||
echoHacksList(
|
||||
$cond,
|
||||
'order by id desc',
|
||||
[
|
||||
'judge_time_hidden' => '',
|
||||
@ -138,7 +134,8 @@
|
||||
'table_classes' => ['table', 'mb-0', 'uoj-table', 'text-center'],
|
||||
],
|
||||
],
|
||||
$myUser);
|
||||
?>
|
||||
Auth::user()
|
||||
);
|
||||
?>
|
||||
|
||||
<?php echoUOJPageFooter() ?>
|
||||
|
@ -1,19 +1,18 @@
|
||||
<?php
|
||||
requireLib('bootstrap5');
|
||||
?>
|
||||
<?php requireLib('bootstrap5') ?>
|
||||
|
||||
<?php echoUOJPageHeader(UOJLocale::get('html to markdown')) ?>
|
||||
|
||||
<h1 class="h2">
|
||||
<h1>
|
||||
<?= UOJLocale::get('html to markdown') ?>
|
||||
</h1>
|
||||
|
||||
<style>
|
||||
#html, #markdown {
|
||||
#html,
|
||||
#markdown {
|
||||
font-family: Cascadia Mono, Ubuntu Mono, Roboto Mono, Jetbrains Mono, Fira Code, Consolas, '思源黑体 Regular', '思源宋体 Light', '宋体', 'Courier New', monospace;
|
||||
width: 100%;
|
||||
min-height: 300px;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
||||
<div class="card">
|
||||
@ -35,11 +34,13 @@
|
||||
<?= HTML::js_src('/js/h2m.js') ?>
|
||||
|
||||
<script>
|
||||
$(document).ready(function() {
|
||||
$(document).ready(function() {
|
||||
$('#html').on('input', function() {
|
||||
$('#markdown').val(h2m($('#html').val(), { converter: 'Gfm' }));
|
||||
$('#markdown').val(h2m($('#html').val(), {
|
||||
converter: 'Gfm'
|
||||
}));
|
||||
});
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
<?php echoUOJPageFooter() ?>
|
||||
|
@ -1,24 +1,23 @@
|
||||
<?php
|
||||
requirePHPLib('form');
|
||||
|
||||
if (!Auth::check() && UOJConfig::$data['switch']['force-login']) {
|
||||
if (!Auth::check()) {
|
||||
become403Page(UOJLocale::get('need login'));
|
||||
}
|
||||
}
|
||||
|
||||
$name = $_GET['image_name'];
|
||||
if (!validateString($name)) {
|
||||
$name = $_GET['image_name'];
|
||||
if (!validateString($name)) {
|
||||
become404Page();
|
||||
}
|
||||
}
|
||||
|
||||
$file_name = UOJContext::storagePath()."/image_hosting/$name.png";
|
||||
$file_name = UOJContext::storagePath() . "/image_hosting/$name.png";
|
||||
|
||||
$finfo = finfo_open(FILEINFO_MIME);
|
||||
$mimetype = finfo_file($finfo, $file_name);
|
||||
if ($mimetype === false) {
|
||||
$finfo = finfo_open(FILEINFO_MIME);
|
||||
$mimetype = finfo_file($finfo, $file_name);
|
||||
if ($mimetype === false) {
|
||||
become404Page();
|
||||
}
|
||||
finfo_close($finfo);
|
||||
}
|
||||
finfo_close($finfo);
|
||||
|
||||
header("X-Sendfile: $file_name");
|
||||
header("Content-type: $mimetype");
|
||||
header("Cache-Control: max-age=604800", true);
|
||||
header("X-Sendfile: $file_name");
|
||||
header("Content-type: $mimetype");
|
||||
header("Cache-Control: max-age=604800", true);
|
||||
|
@ -1,29 +1,35 @@
|
||||
<?php
|
||||
use Gregwar\Captcha\PhraseBuilder;
|
||||
use Gregwar\Captcha\CaptchaBuilder;
|
||||
|
||||
requirePHPLib('form');
|
||||
requireLib('bootstrap5');
|
||||
use Gregwar\Captcha\PhraseBuilder;
|
||||
|
||||
if (!Auth::check()) {
|
||||
redirectToLogin();
|
||||
}
|
||||
requirePHPLib('form');
|
||||
requireLib('bootstrap5');
|
||||
|
||||
if (!isNormalUser($myUser)) {
|
||||
become403Page();
|
||||
}
|
||||
Auth::check() || redirectToLogin();
|
||||
|
||||
$limit = $myUser['images_size_limit'];
|
||||
$_result = DB::selectFirst("SELECT SUM(size), count(*) FROM `users_images` WHERE uploader = '{$myUser['username']}'");
|
||||
$used = $_result["SUM(size)"];
|
||||
$count = $_result["count(*)"];
|
||||
$extra = UOJUser::getExtra($user);
|
||||
$limit = $extra['image_hosting']['total_size_limit'];
|
||||
$used = DB::selectSingle([
|
||||
"select sum(size)",
|
||||
"from users_images",
|
||||
"where", [
|
||||
"uploader" => Auth::id(),
|
||||
],
|
||||
]);
|
||||
$count = DB::selectCount([
|
||||
"select count(*)",
|
||||
"from users_images",
|
||||
"where", [
|
||||
"uploader" => Auth::id(),
|
||||
],
|
||||
]);
|
||||
|
||||
function throwError($msg) {
|
||||
function throwError($msg) {
|
||||
dieWithJsonData(['status' => 'error', 'message' => $msg]);
|
||||
}
|
||||
}
|
||||
|
||||
$allowedTypes = [IMAGETYPE_PNG, IMAGETYPE_JPEG];
|
||||
if ($_POST['image_upload_file_submit'] == 'submit') {
|
||||
$allowedTypes = [IMAGETYPE_PNG, IMAGETYPE_JPEG, IMAGETYPE_WEBP];
|
||||
if ($_POST['image_upload_file_submit'] == 'submit') {
|
||||
if (!crsf_check()) {
|
||||
throwError('expired');
|
||||
}
|
||||
@ -59,7 +65,7 @@
|
||||
$watermark_text = "";
|
||||
$hash .= "__no_watermark";
|
||||
} elseif ($_POST['watermark'] == 'site_shortname_and_username') {
|
||||
$watermark_text .= ' @'.Auth::id();
|
||||
$watermark_text .= ' @' . Auth::id();
|
||||
$hash .= "__id";
|
||||
}
|
||||
|
||||
@ -71,7 +77,7 @@
|
||||
|
||||
$image = new Imagick($_FILES["image_upload_file"]["tmp_name"]);
|
||||
$draw = new ImagickDraw();
|
||||
$draw->setFont(UOJContext::documentRoot().'/fonts/roboto-mono/RobotoMono-Bold.ttf');
|
||||
$draw->setFont(UOJContext::documentRoot() . '/fonts/roboto-mono/RobotoMono-Bold.ttf');
|
||||
$draw->setFontSize($scale * 14);
|
||||
$draw->setGravity(Imagick::GRAVITY_SOUTHEAST);
|
||||
$draw->setFillColor("rgba(100,100,100,0.5)");
|
||||
@ -86,38 +92,38 @@
|
||||
}
|
||||
|
||||
$filename = uojRandAvaiableFileName('/image_hosting/', 10, '.png');
|
||||
if (!move_uploaded_file($_FILES["image_upload_file"]["tmp_name"], UOJContext::storagePath().$filename)) {
|
||||
if (!move_uploaded_file($_FILES["image_upload_file"]["tmp_name"], UOJContext::storagePath() . $filename)) {
|
||||
throwError('unknown error');
|
||||
}
|
||||
|
||||
DB::insert("INSERT INTO users_images (`path`, uploader, width, height, upload_time, size, `hash`) VALUES ('$filename', '{$myUser['username']}', $width, $height, now(), {$_FILES["image_upload_file"]["size"]}, '$hash')");
|
||||
|
||||
dieWithJsonData(['status' => 'success', 'path' => $filename]);
|
||||
} elseif ($_POST['image_delete_submit'] == 'submit') {
|
||||
} elseif ($_POST['image_delete_submit'] == 'submit') {
|
||||
crsf_defend();
|
||||
|
||||
$id = $_POST['image_delete_id'];
|
||||
if (!validateUInt($id)) {
|
||||
becomeMsgPage('ID 不合法。<a href="'.UOJContext::requestURI().'">返回</a>');
|
||||
becomeMsgPage('ID 不合法。<a href="' . UOJContext::requestURI() . '">返回</a>');
|
||||
} else {
|
||||
$result = DB::selectFirst("SELECT * from users_images WHERE id = $id");
|
||||
if (!$result) {
|
||||
becomeMsgPage('图片不存在。<a href="'.UOJContext::requestURI().'">返回</a>');
|
||||
becomeMsgPage('图片不存在。<a href="' . UOJContext::requestURI() . '">返回</a>');
|
||||
} else {
|
||||
unlink(UOJContext::storagePath().$result['path']);
|
||||
unlink(UOJContext::storagePath() . $result['path']);
|
||||
DB::delete("DELETE FROM users_images WHERE id = $id");
|
||||
|
||||
header("Location: ". UOJContext::requestURI());
|
||||
header("Location: " . UOJContext::requestURI());
|
||||
die();
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
}
|
||||
?>
|
||||
|
||||
<?php echoUOJPageHeader(UOJLocale::get('image hosting')) ?>
|
||||
|
||||
<style>
|
||||
.drop {
|
||||
.drop {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
flex-direction: column;
|
||||
@ -133,19 +139,19 @@
|
||||
border: 1px solid #e8e8e8;
|
||||
box-sizing: border-box;
|
||||
border-radius: 4px;
|
||||
}
|
||||
}
|
||||
|
||||
.drop:hover {
|
||||
.drop:hover {
|
||||
border-color: #89d1f5;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
||||
<h1 class="h2">
|
||||
<h1>
|
||||
<?= UOJLocale::get('image hosting') ?>
|
||||
</h1>
|
||||
|
||||
<div class="card card-default">
|
||||
<div class="card-body">
|
||||
<div class="card-body">
|
||||
<form class="row m-0" id="image-upload-form" method="post" enctype="multipart/form-data">
|
||||
<div class="col-12 col-md-3 col-lg-3 order-1 drop mx-auto mx-md-0" id="image-upload-form-drop">
|
||||
<svg aria-hidden="true" focusable="false" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 576 512" width="56" class="mb-2">
|
||||
@ -185,8 +191,8 @@
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-12 col-md-4 col-lg-2 order-2 mt-3 mt-md-0 ms-md-2">
|
||||
<h2 class="h4">水印</h2>
|
||||
<?php if (isSuperUser($myUser)): ?>
|
||||
<h2 class="h3">水印</h2>
|
||||
<?php if (isSuperUser($myUser)) : ?>
|
||||
<div class="form-check d-inline-block d-md-block me-2">
|
||||
<input class="form-check-input" type="radio" name="watermark" id="watermark-no_watermark" data-value="no_watermark">
|
||||
<label class="form-check-label" for="watermark-no_watermark">
|
||||
@ -208,7 +214,7 @@
|
||||
</div>
|
||||
</div>
|
||||
<div class="col order-3 order-md-4 order-lg-3 mt-3 mt-lg-0 ms-lg-2">
|
||||
<h2 class="h4">上传须知</h2>
|
||||
<h2 class="h3">上传须知</h2>
|
||||
<ul>
|
||||
<li>上传的图片必须符合法律与社会道德;</li>
|
||||
<li>图床仅供 S2OJ 站内使用,校外用户无法查看;</li>
|
||||
@ -218,7 +224,7 @@
|
||||
<p class="small">更多信息可以查看 <a href="https://s2oj.github.io/#/user/apps/image_hosting" target="_blank">使用文档</a>。</p>
|
||||
</div>
|
||||
<div class="col-12 col-md-5 col-lg-3 order-4 order-md-3 order-lg-4 mt-3 mt-md-0 ms-md-2">
|
||||
<h2 class="h4">使用统计</h2>
|
||||
<h2 class="h3">使用统计</h2>
|
||||
<div class="d-flex justify-content-between">
|
||||
<span class="small">已用空间</span>
|
||||
<span><?= round($used * 1.0 / 1024 / 1024, 2) ?> MB / <?= round($limit * 1.0 / 1024 / 1024, 2) ?> MB</span>
|
||||
@ -229,7 +235,7 @@
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="toast-container position-fixed bottom-0 start-0 ms-3 mb-4" style="z-index: 999999">
|
||||
<div id="image-upload-toast" class="toast text-bg-danger align-items-center border-0" role="alert" aria-live="assertive" aria-atomic="true">
|
||||
@ -242,20 +248,22 @@
|
||||
</div>
|
||||
</div>
|
||||
<script>
|
||||
var image_upload_modal = new bootstrap.Modal('#image-upload-modal');
|
||||
var image_upload_toast = new bootstrap.Toast('#image-upload-toast', { delay: 2000 });
|
||||
var droppedFiles = false;
|
||||
var image_upload_modal = new bootstrap.Modal('#image-upload-modal');
|
||||
var image_upload_toast = new bootstrap.Toast('#image-upload-toast', {
|
||||
delay: 2000
|
||||
});
|
||||
var droppedFiles = false;
|
||||
|
||||
function refreshCaptcha() {
|
||||
function refreshCaptcha() {
|
||||
var timestamp = new Date().getTime();
|
||||
$("#captcha").attr("src", "/captcha" + '?' + timestamp);
|
||||
}
|
||||
}
|
||||
|
||||
$("#captcha").click(function(e) {
|
||||
$("#captcha").click(function(e) {
|
||||
refreshCaptcha();
|
||||
});
|
||||
});
|
||||
|
||||
$('#image-upload-form').submit(function(event) {
|
||||
$('#image-upload-form').submit(function(event) {
|
||||
event.preventDefault();
|
||||
|
||||
var data = new FormData();
|
||||
@ -303,32 +311,32 @@ $('#image-upload-form').submit(function(event) {
|
||||
});
|
||||
|
||||
return false;
|
||||
});
|
||||
$('#image-upload-form-drop').click(function() {
|
||||
});
|
||||
$('#image-upload-form-drop').click(function() {
|
||||
$('#image_upload_file').click();
|
||||
});
|
||||
$('#image-upload-form-drop').on('drag dragstart dragend dragover dragenter dragleave drop', function(e) {
|
||||
});
|
||||
$('#image-upload-form-drop').on('drag dragstart dragend dragover dragenter dragleave drop', function(e) {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
}).on('dragover dragenter', function() {
|
||||
}).on('dragover dragenter', function() {
|
||||
$('#select-image-text').html('松开以上传');
|
||||
}).on('dragleave dragend drop', function() {
|
||||
}).on('dragleave dragend drop', function() {
|
||||
$('#select-image-text').html('点击此处选择图片');
|
||||
}).on('drop', function(e) {
|
||||
}).on('drop', function(e) {
|
||||
$('#image_upload_file').prop('files', e.originalEvent.dataTransfer.files);
|
||||
$('#image_upload_file').trigger('change');
|
||||
});
|
||||
$(document).on('paste', function(e) {
|
||||
});
|
||||
$(document).on('paste', function(e) {
|
||||
if (e.originalEvent.clipboardData) {
|
||||
$('#image_upload_file').prop('files', e.originalEvent.clipboardData.files);
|
||||
}
|
||||
|
||||
$('#image_upload_file').trigger('change');
|
||||
});
|
||||
$('#image-upload-modal').on('hide.bs.modal', function() {
|
||||
});
|
||||
$('#image-upload-modal').on('hide.bs.modal', function() {
|
||||
$('#image-upload-form').trigger('reset');
|
||||
});
|
||||
$('#image_upload_file').change(function() {
|
||||
});
|
||||
$('#image_upload_file').change(function() {
|
||||
var items = $(this).prop('files');
|
||||
var file = null;
|
||||
|
||||
@ -346,8 +354,8 @@ $('#image_upload_file').change(function() {
|
||||
var watermark_type = $('input[name=watermark]:checked', '#image-upload-form').data('value');
|
||||
var html = '';
|
||||
|
||||
html += '<p><img src="'+ URL.createObjectURL(file) +'" height="150" style="object-fit: contain"></p>';
|
||||
html += '<p class="small">大小:<b>'+(file.size / 1024).toFixed(2)+'</b> KB。';
|
||||
html += '<p><img src="' + URL.createObjectURL(file) + '" height="150" style="object-fit: contain"></p>';
|
||||
html += '<p class="small">大小:<b>' + (file.size / 1024).toFixed(2) + '</b> KB。';
|
||||
|
||||
if (watermark_type === 'no_watermark') {
|
||||
html += '不添加水印。';
|
||||
@ -365,7 +373,7 @@ $('#image_upload_file').change(function() {
|
||||
} else {
|
||||
image_upload_toast.show();
|
||||
}
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
<?php
|
||||
@ -376,15 +384,15 @@ $pag_config = [
|
||||
'cond' => "uploader = '{$myUser['username']}'",
|
||||
'tail' => 'order by upload_time desc',
|
||||
];
|
||||
$pag = new Paginator($pag_config);
|
||||
?>
|
||||
$pag = new Paginator($pag_config);
|
||||
?>
|
||||
|
||||
<h2 class="h3 mt-4 mb-3">
|
||||
<h2 class="mt-4 mb-3">
|
||||
我的图片
|
||||
</h2>
|
||||
|
||||
<div class="row row-cols-1 row-cols-sm-2 row-cols-md-3 row-cols-lg-4 g-4">
|
||||
<?php foreach ($pag->get() as $idx => $row): ?>
|
||||
<?php foreach ($pag->get() as $idx => $row) : ?>
|
||||
<div class="col">
|
||||
<div class="card">
|
||||
<img src="<?= $row['path'] ?>" class="card-img-top" height="200" style="object-fit: contain">
|
||||
@ -392,9 +400,9 @@ $pag_config = [
|
||||
<div class="d-flex flex-wrap justify-content-between">
|
||||
<time><?= $row['upload_time'] ?></time>
|
||||
<span>
|
||||
<?php if ($row['size'] < 1024 * 512): ?>
|
||||
<?php if ($row['size'] < 1024 * 512) : ?>
|
||||
<?= round($row['size'] * 1.0 / 1024, 1) ?> KB
|
||||
<?php else: ?>
|
||||
<?php else : ?>
|
||||
<?= round($row['size'] * 1.0 / 1024 / 1024, 1) ?> MB
|
||||
<?php endif ?>
|
||||
</span>
|
||||
@ -423,7 +431,7 @@ $pag_config = [
|
||||
<?php endforeach ?>
|
||||
</div>
|
||||
|
||||
<?php if ($pag->isEmpty()): ?>
|
||||
<?php if ($pag->isEmpty()) : ?>
|
||||
<div class="mt-4 text-muted">
|
||||
<?= UOJLocale::get('none') ?>
|
||||
</div>
|
||||
@ -445,23 +453,25 @@ $pag_config = [
|
||||
</div>
|
||||
|
||||
<script>
|
||||
$(document).ready(function() {
|
||||
$(document).ready(function() {
|
||||
[...document.querySelectorAll('[data-bs-toggle="tooltip"]')].map(tooltipTriggerEl => new bootstrap.Tooltip(tooltipTriggerEl));
|
||||
});
|
||||
});
|
||||
|
||||
var copy_url_toast = new bootstrap.Toast('#copy-url-toast', { delay: 2000 });
|
||||
var copy_url_toast = new bootstrap.Toast('#copy-url-toast', {
|
||||
delay: 2000
|
||||
});
|
||||
|
||||
$('.image-copy-url-button').click(function() {
|
||||
$('.image-copy-url-button').click(function() {
|
||||
var url = new URL($(this).data('image-path'), location.origin);
|
||||
navigator.clipboard.writeText(url);
|
||||
copy_url_toast.show();
|
||||
});
|
||||
});
|
||||
|
||||
$('.image-copy-md-button').click(function() {
|
||||
$('.image-copy-md-button').click(function() {
|
||||
var url = new URL($(this).data('image-path'), location.origin);
|
||||
navigator.clipboard.writeText('![](' + url + ')');
|
||||
copy_url_toast.show();
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
<?php echoUOJPageFooter() ?>
|
||||
|
@ -1,10 +1,21 @@
|
||||
<?php requireLib('bootstrap5'); ?>
|
||||
<?php
|
||||
$blogs = DB::selectAll("select blogs.id, title, poster, post_time from important_blogs, blogs where is_hidden = 0 and important_blogs.blog_id = blogs.id order by level desc, important_blogs.blog_id desc limit 5");
|
||||
$countdowns = DB::selectAll("select * from countdowns order by end_time asc");
|
||||
$friend_links = DB::selectAll("select * from friend_links order by level desc, id asc");
|
||||
|
||||
requireLib('bootstrap5');
|
||||
?>
|
||||
$blogs = DB::selectAll([
|
||||
"select blogs.id, title, poster, post_time from important_blogs inner join blogs on important_blogs.blog_id = blogs.id",
|
||||
"where", [
|
||||
"is_hidden" => 0,
|
||||
], "order by level desc, important_blogs.blog_id desc",
|
||||
DB::limit(5)
|
||||
]);
|
||||
$countdowns = DB::selectAll([
|
||||
"select title, end_time from countdowns",
|
||||
"order by end_time asc",
|
||||
]);
|
||||
$friend_links = DB::selectAll([
|
||||
"select title, url from friend_links",
|
||||
"order by level desc, id asc",
|
||||
]);
|
||||
?>
|
||||
<?php echoUOJPageHeader(UOJConfig::$data['profile']['oj-name-short']) ?>
|
||||
<div class="row">
|
||||
<div class="col-lg-9">
|
||||
@ -23,25 +34,21 @@
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php $now_cnt = 0; ?>
|
||||
<?php foreach ($blogs as $blog): ?>
|
||||
<?php foreach ($blogs as $blog_info) : ?>
|
||||
<?php
|
||||
$blog = new UOJBlog($blog_info);
|
||||
$now_cnt++;
|
||||
$new_tag = '';
|
||||
if ((time() - strtotime($blog['post_time'])) / 3600 / 24 <= 7) {
|
||||
$new_tag = '<sup style="color:red"> new</sup>';
|
||||
}
|
||||
?>
|
||||
<tr>
|
||||
<td>
|
||||
<a href="/blogs/<?= $blog['id'] ?>" class="text-decoration-none"><?= $blog['title'] ?></a>
|
||||
<?= $new_tag ?>
|
||||
</td>
|
||||
<td>by <?= getUserLink($blog['poster']) ?></td>
|
||||
<td><small><?= $blog['post_time'] ?></small></td>
|
||||
<td><?= $blog->getLink(['show_new_tag' => true]) ?></td>
|
||||
<td>by <?= getUserLink($blog->info['poster']) ?></td>
|
||||
<td><small><?= $blog->info['post_time'] ?></small></td>
|
||||
</tr>
|
||||
<?php endforeach ?>
|
||||
<?php for ($i = $now_cnt + 1; $i <= 5; $i++): ?>
|
||||
<tr><td colspan="233"> </td></tr>
|
||||
<?php for ($i = $now_cnt + 1; $i <= 5; $i++) : ?>
|
||||
<tr>
|
||||
<td colspan="233"> </td>
|
||||
</tr>
|
||||
<?php endfor ?>
|
||||
</tbody>
|
||||
</table>
|
||||
@ -52,27 +59,19 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<?php if (!UOJConfig::$data['switch']['force-login'] || Auth::check()): ?>
|
||||
<?php if (!UOJConfig::$data['switch']['force-login'] || isNormalUser($myUser)): ?>
|
||||
|
||||
<?php if (Auth::check()) : ?>
|
||||
<div class="mt-4 card">
|
||||
<div class="card-body">
|
||||
<h4 class="card-title"><?= UOJLocale::get('top solver') ?></h4>
|
||||
<?php echoRanklist([
|
||||
'echo_full' => true,
|
||||
'top10' => true,
|
||||
'by_accepted' => true,
|
||||
'table_classes' => ['table', 'text-center'],
|
||||
]) ?>
|
||||
<div class="text-center">
|
||||
<h4 class="card-title mb-2"><?= UOJLocale::get('top solver') ?></h4>
|
||||
<?php UOJRanklist::printHTML(['top10' => true]) ?>
|
||||
<div class="text-center mt-2">
|
||||
<a href="/solverlist" class="text-decoration-none">
|
||||
<?= UOJLocale::get('view all') ?>
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<?php endif ?>
|
||||
<?php else: ?>
|
||||
<?php else : ?>
|
||||
<div class="mt-4 card card-default">
|
||||
<div class="card-body text-center">
|
||||
请 <a role="button" class="btn btn-outline-primary" href="<?= HTML::url('/login') ?>">登录</a> 以查看更多内容。
|
||||
@ -90,22 +89,22 @@
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<ul class="list-unstyled mb-0">
|
||||
<?php foreach ($countdowns as $countdown): ?>
|
||||
<?php foreach ($countdowns as $countdown) : ?>
|
||||
<?php
|
||||
$enddate = strtotime($countdown['end_time']);
|
||||
$nowdate = time();
|
||||
$diff = ceil(($enddate - $nowdate) / (24 * 60 * 60));
|
||||
?>
|
||||
<li>
|
||||
<?php if ($diff > 0): ?>
|
||||
<?php if ($diff > 0) : ?>
|
||||
<?= UOJLocale::get('x days until countdown title', $countdown['title'], $diff) ?>
|
||||
<?php else: ?>
|
||||
<?php else : ?>
|
||||
<?= UOJLocale::get("countdown title has begun", $countdown['title']) ?>
|
||||
<?php endif ?>
|
||||
</li>
|
||||
<?php endforeach ?>
|
||||
</ul>
|
||||
<?php if (count($countdowns) == 0): ?>
|
||||
<?php if (count($countdowns) == 0) : ?>
|
||||
<div class="text-center">
|
||||
<?= UOJLocale::get('none') ?>
|
||||
</div>
|
||||
@ -113,7 +112,7 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php if (Auth::check()): ?>
|
||||
<?php if (Auth::check()) : ?>
|
||||
<?php uojIncludeView('sidebar', ['assignments_hidden' => '', 'groups_hidden' => '']) ?>
|
||||
<?php endif ?>
|
||||
|
||||
@ -123,7 +122,7 @@
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<ul class="ps-3 mb-0">
|
||||
<?php foreach ($friend_links as $friend_link): ?>
|
||||
<?php foreach ($friend_links as $friend_link) : ?>
|
||||
<li>
|
||||
<a class="text-decoration-none" href="<?= $friend_link['url'] ?>" target="_blank">
|
||||
<?= $friend_link['title'] ?>
|
||||
@ -131,7 +130,7 @@
|
||||
</li>
|
||||
<?php endforeach ?>
|
||||
</ul>
|
||||
<?php if (count($friend_links) == 0): ?>
|
||||
<?php if (count($friend_links) == 0) : ?>
|
||||
<div class="text-center">
|
||||
<?= UOJLocale::get('none') ?>
|
||||
</div>
|
||||
|
@ -1,43 +0,0 @@
|
||||
<?php
|
||||
requirePHPLib('judger');
|
||||
|
||||
if (!authenticateJudger()) {
|
||||
become404Page();
|
||||
}
|
||||
|
||||
switch ($_GET['type']) {
|
||||
case 'submission':
|
||||
$file_name = UOJContext::storagePath()."/submission/{$_GET['id']}/{$_GET['rand_str_id']}";
|
||||
$download_name = "submission.zip";
|
||||
break;
|
||||
case 'tmp':
|
||||
$file_name = UOJContext::storagePath()."/tmp/{$_GET['rand_str_id']}";
|
||||
$download_name = "tmp";
|
||||
break;
|
||||
case 'problem':
|
||||
$id = $_GET['id'];
|
||||
if (!validateUInt($id) || !($problem = queryProblemBrief($id))) {
|
||||
become404Page();
|
||||
}
|
||||
$file_name = "/var/uoj_data/$id.zip";
|
||||
$download_name = "$id.zip";
|
||||
break;
|
||||
case 'judger':
|
||||
$file_name = UOJContext::storagePath()."/judge_client.zip";
|
||||
$download_name = "judge_client.zip";
|
||||
break;
|
||||
default:
|
||||
become404Page();
|
||||
}
|
||||
|
||||
$finfo = finfo_open(FILEINFO_MIME);
|
||||
$mimetype = finfo_file($finfo, $file_name);
|
||||
if ($mimetype === false) {
|
||||
become404Page();
|
||||
}
|
||||
finfo_close($finfo);
|
||||
|
||||
header("X-Sendfile: $file_name");
|
||||
header("Content-type: $mimetype");
|
||||
header("Content-Disposition: attachment; filename=$download_name");
|
||||
?>
|
@ -1,97 +1,102 @@
|
||||
<?php
|
||||
requirePHPLib('judger');
|
||||
requirePHPLib('data');
|
||||
requirePHPLib('judger');
|
||||
requirePHPLib('data');
|
||||
|
||||
if (!authenticateJudger()) {
|
||||
become404Page();
|
||||
}
|
||||
if (!authenticateJudger()) {
|
||||
UOJResponse::page404();
|
||||
}
|
||||
|
||||
function submissionJudged() {
|
||||
$submission = DB::selectFirst("select submitter, status, content, result, problem_id from submissions where id = {$_POST['id']}");
|
||||
if ($submission == null) {
|
||||
return;
|
||||
}
|
||||
if ($submission['status'] != 'Judging' && $submission['status'] != 'Judged, Judging') {
|
||||
return;
|
||||
}
|
||||
$content = json_decode($submission['content'], true);
|
||||
function submissionJudged() {
|
||||
UOJSubmission::onJudged(UOJRequest::post('id'), UOJRequest::post('result'), UOJRequest::post('judge_time'));
|
||||
}
|
||||
|
||||
if (isset($content['first_test_config'])) {
|
||||
$result = json_decode($submission['result'], true);
|
||||
$result['final_result'] = json_decode($_POST['result'], true);
|
||||
$result['final_result']['details'] = uojTextEncode($result['final_result']['details']);
|
||||
$esc_result = DB::escape(json_encode($result, JSON_UNESCAPED_UNICODE));
|
||||
|
||||
$content['final_test_config'] = $content['config'];
|
||||
$content['config'] = $content['first_test_config'];
|
||||
unset($content['first_test_config']);
|
||||
$esc_content = DB::escape(json_encode($content));
|
||||
|
||||
DB::update("update submissions set status = 'Judged', result = '$esc_result', content = '$esc_content' where id = {$_POST['id']}");
|
||||
} else {
|
||||
$result = json_decode($_POST['result'], true);
|
||||
$result['details'] = uojTextEncode($result['details']);
|
||||
$esc_result = DB::escape(json_encode($result, JSON_UNESCAPED_UNICODE));
|
||||
if (isset($result["error"])) {
|
||||
DB::update("update submissions set status = '{$result['status']}', result_error = '{$result['error']}', result = '$esc_result', score = null, used_time = null, used_memory = null where id = {$_POST['id']}");
|
||||
} else {
|
||||
DB::update("update submissions set status = '{$result['status']}', result_error = null, result = '$esc_result', score = {$result['score']}, used_time = {$result['time']}, used_memory = {$result['memory']} where id = {$_POST['id']}");
|
||||
}
|
||||
|
||||
if (isset($content['final_test_config'])) {
|
||||
$content['first_test_config'] = $content['config'];
|
||||
$content['config'] = $content['final_test_config'];
|
||||
unset($content['final_test_config']);
|
||||
$esc_content = DB::escape(json_encode($content));
|
||||
|
||||
DB::update("update submissions set status = 'Judged, Waiting', content = '$esc_content' where id = ${_POST['id']}");
|
||||
}
|
||||
}
|
||||
DB::update("update submissions set status_details = '' where id = {$_POST['id']}");
|
||||
updateBestACSubmissions($submission['submitter'], $submission['problem_id']);
|
||||
}
|
||||
|
||||
function customTestSubmissionJudged() {
|
||||
$submission = DB::selectFirst("select submitter, status, content, result, problem_id from custom_test_submissions where id = {$_POST['id']}");
|
||||
function customTestSubmissionJudged() {
|
||||
$submission = DB::selectFirst([
|
||||
"select submitter, status, content, result, problem_id from custom_test_submissions",
|
||||
"where", ['id' => $_POST['id']]
|
||||
]);
|
||||
if ($submission == null) {
|
||||
return;
|
||||
}
|
||||
if ($submission['status'] != 'Judging') {
|
||||
return;
|
||||
}
|
||||
$content = json_decode($submission['content'], true);
|
||||
$result = json_decode($_POST['result'], true);
|
||||
$result['details'] = uojTextEncode($result['details']);
|
||||
$esc_result = DB::escape(json_encode($result, JSON_UNESCAPED_UNICODE));
|
||||
if (isset($result["error"])) {
|
||||
DB::update("update custom_test_submissions set status = '{$result['status']}', result = '$esc_result' where id = {$_POST['id']}");
|
||||
} else {
|
||||
DB::update("update custom_test_submissions set status = '{$result['status']}', result = '$esc_result' where id = {$_POST['id']}");
|
||||
}
|
||||
DB::update("update custom_test_submissions set status_details = '' where id = {$_POST['id']}");
|
||||
}
|
||||
DB::update([
|
||||
"update custom_test_submissions",
|
||||
"set", [
|
||||
'status' => $result['status'],
|
||||
'status_details' => '',
|
||||
'result' => json_encode($result, JSON_UNESCAPED_UNICODE)
|
||||
], "where", ['id' => $_POST['id']]
|
||||
]);
|
||||
}
|
||||
|
||||
function hackJudged() {
|
||||
function hackJudged() {
|
||||
$result = json_decode($_POST['result'], true);
|
||||
$esc_details = DB::escape(uojTextEncode($result['details']));
|
||||
$ok = DB::update("update hacks set success = {$result['score']}, details = '$esc_details' where id = {$_POST['id']}");
|
||||
|
||||
if ($ok) {
|
||||
list($hack_input) = DB::fetch(DB::query("select input from hacks where id = {$_POST['id']}"), MYSQLI_NUM);
|
||||
unlink(UOJContext::storagePath().$hack_input);
|
||||
UOJHack::init($_POST['id']);
|
||||
UOJHack::cur()->setProblem();
|
||||
UOJHack::cur()->setSubmission();
|
||||
|
||||
if ($result['score']) {
|
||||
list($problem_id) = DB::selectFirst("select problem_id from hacks where id = ${_POST['id']}", MYSQLI_NUM);
|
||||
if (validateUploadedFile('hack_input') && validateUploadedFile('std_output')) {
|
||||
dataAddExtraTest(queryProblemBrief($problem_id), $_FILES["hack_input"]["tmp_name"], $_FILES["std_output"]["tmp_name"]);
|
||||
$status = 'Judged, Waiting';
|
||||
} else {
|
||||
error_log("hack successfully but received no data. id: ${_POST['id']}");
|
||||
}
|
||||
}
|
||||
}
|
||||
$status = 'Judged';
|
||||
}
|
||||
|
||||
if (isset($_POST['submit'])) {
|
||||
$ok = DB::update([
|
||||
"update hacks",
|
||||
"set", [
|
||||
'success' => $result['score'],
|
||||
'status' => $status,
|
||||
'details' => uojTextEncode($result['details'])
|
||||
], "where", ['id' => $_POST['id']]
|
||||
]);
|
||||
|
||||
if (!$result['score']) {
|
||||
return;
|
||||
}
|
||||
if (!$ok) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!(validateUploadedFile('hack_input') && validateUploadedFile('std_output'))) {
|
||||
UOJLog::error("hack successfully but received no data. id: {$_POST['id']}");
|
||||
return;
|
||||
}
|
||||
|
||||
$input = UOJContext::storagePath() . UOJHack::info('input');
|
||||
$up_in = $_FILES["hack_input"]['tmp_name'];
|
||||
$up_out = $_FILES["std_output"]['tmp_name'];
|
||||
|
||||
if (!UOJHack::cur()->problem->needToReviewHack()) {
|
||||
$err = dataAddHackPoint(UOJHack::cur()->problem->info, $up_in, $up_out);
|
||||
if ($err === '') {
|
||||
unlink($input);
|
||||
DB::update([
|
||||
"update hacks",
|
||||
"set", [
|
||||
'status' => 'Judged'
|
||||
], "where", ['id' => $_POST['id']]
|
||||
]);
|
||||
return;
|
||||
} else {
|
||||
UOJLog::error("hack successfully but failed to add an extra test: {$err}");
|
||||
}
|
||||
}
|
||||
move_uploaded_file($up_in, "{$input}_in");
|
||||
move_uploaded_file($up_out, "{$input}_out");
|
||||
DB::update([
|
||||
"update hacks",
|
||||
"set", [
|
||||
'status' => 'Judged, WaitingM'
|
||||
], "where", ['id' => $_POST['id']]
|
||||
]);
|
||||
}
|
||||
|
||||
if (isset($_POST['submit'])) {
|
||||
if (!validateUInt($_POST['id'])) {
|
||||
die("Wow! hacker! T_T....");
|
||||
}
|
||||
@ -102,111 +107,294 @@
|
||||
} else {
|
||||
submissionJudged();
|
||||
}
|
||||
}
|
||||
if (isset($_POST['update-status'])) {
|
||||
}
|
||||
if (isset($_POST['update-status'])) {
|
||||
if (!validateUInt($_POST['id'])) {
|
||||
die("Wow! hacker! T_T....");
|
||||
}
|
||||
$esc_status_details = DB::escape($_POST['status']);
|
||||
|
||||
$status_details = $_POST['status'];
|
||||
if (isset($_POST['is_custom_test'])) {
|
||||
DB::update("update custom_test_submissions set status_details = '$esc_status_details' where id = {$_POST['id']}");
|
||||
DB::update([
|
||||
"update custom_test_submissions",
|
||||
"set", ["status_details" => $status_details],
|
||||
"where", ["id" => $_POST['id']]
|
||||
]);
|
||||
} else {
|
||||
DB::update("update submissions set status_details = '$esc_status_details' where id = {$_POST['id']}");
|
||||
DB::update([
|
||||
"update submissions",
|
||||
"set", ["status_details" => $status_details],
|
||||
"where", ["id" => $_POST['id']]
|
||||
]);
|
||||
}
|
||||
die();
|
||||
}
|
||||
}
|
||||
|
||||
$submission = null;
|
||||
$hack = null;
|
||||
function querySubmissionToJudge($status, $set_q) {
|
||||
global $submission;
|
||||
$submission = DB::selectFirst("select id, problem_id, content from submissions where status = '$status' order by id limit 1");
|
||||
if ($submission) {
|
||||
DB::update("update submissions set $set_q where id = {$submission['id']} and status = '$status'");
|
||||
if (DB::affected_rows() != 1) {
|
||||
$submission = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
function queryCustomTestSubmissionToJudge() {
|
||||
global $submission;
|
||||
$submission = DB::selectFirst("select id, problem_id, content from custom_test_submissions where judge_time is null order by id limit 1");
|
||||
if ($submission) {
|
||||
DB::update("update custom_test_submissions set judge_time = now(), status = 'Judging' where id = {$submission['id']} and judge_time is null");
|
||||
if (DB::affected_rows() != 1) {
|
||||
$submission = null;
|
||||
}
|
||||
}
|
||||
if ($submission) {
|
||||
$submission['is_custom_test'] = '';
|
||||
}
|
||||
}
|
||||
function queryHackToJudge() {
|
||||
global $hack;
|
||||
$hack = DB::selectFirst("select id, submission_id, input, input_type from hacks where judge_time is null order by id limit 1");
|
||||
if ($hack) {
|
||||
DB::update("update hacks set judge_time = now() where id = {$hack['id']} and judge_time is null");
|
||||
if (DB::affected_rows() != 1) {
|
||||
$hack = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
function findSubmissionToJudge() {
|
||||
global $submission, $hack;
|
||||
querySubmissionToJudge('Waiting', "judge_time = now(), status = 'Judging'");
|
||||
if ($submission) {
|
||||
return true;
|
||||
}
|
||||
$problem_ban_list = DB::selectAll([
|
||||
"select id from problems",
|
||||
"where", [
|
||||
["assigned_to_judger", "!=", "any"],
|
||||
["assigned_to_judger", "!=", $_POST['judger_name']]
|
||||
]
|
||||
]);
|
||||
foreach ($problem_ban_list as &$val) {
|
||||
$val = $val['id'];
|
||||
}
|
||||
$assignCond = $problem_ban_list ? [["problem_id", "not in", DB::rawtuple($problem_ban_list)]] : [];
|
||||
|
||||
queryCustomTestSubmissionToJudge();
|
||||
if ($submission) {
|
||||
return true;
|
||||
}
|
||||
$submission = null;
|
||||
$hack = null;
|
||||
function querySubmissionToJudge($status, $set_q) {
|
||||
global $assignCond;
|
||||
|
||||
querySubmissionToJudge('Waiting Rejudge', "judge_time = now(), status = 'Judging'");
|
||||
if ($submission) {
|
||||
return true;
|
||||
}
|
||||
|
||||
querySubmissionToJudge('Judged, Waiting', "status = 'Judged, Judging'");
|
||||
if ($submission) {
|
||||
return true;
|
||||
}
|
||||
|
||||
queryHackToJudge();
|
||||
if ($hack) {
|
||||
$submission = DB::selectFirst("select id, problem_id, content from submissions where id = {$hack['submission_id']} and score = 100");
|
||||
for ($times = 0; $times < 10; $times++) {
|
||||
$submission = DB::selectFirst([
|
||||
"select id from submissions",
|
||||
"where", array_merge(["status" => $status], $assignCond),
|
||||
"order by id limit 1"
|
||||
]);
|
||||
if (!$submission) {
|
||||
$details = "<error>the score gained by the hacked submission is not 100.\n</error>";
|
||||
$esc_details = DB::escape(uojTextEncode($details));
|
||||
DB::update("update hacks set success = 0, details = '$esc_details' where id = {$hack['id']}");
|
||||
return null;
|
||||
}
|
||||
|
||||
$ok = DB::transaction(function () use (&$submission, $set_q, $status) {
|
||||
DB::update([
|
||||
"update submissions",
|
||||
"set", $set_q,
|
||||
"where", [
|
||||
"id" => $submission['id'],
|
||||
"status" => $status
|
||||
]
|
||||
]);
|
||||
if (DB::affected_rows() == 1) {
|
||||
$submission = DB::selectFirst([
|
||||
"select id, problem_id, content, status, judge_time from submissions",
|
||||
"where", ["id" => $submission['id']]
|
||||
]);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
});
|
||||
if ($ok) {
|
||||
return $submission;
|
||||
}
|
||||
}
|
||||
}
|
||||
function queryMinorSubmissionToJudge($status, $set_q) {
|
||||
global $assignCond;
|
||||
|
||||
for ($times = 0; $times < 10; $times++) {
|
||||
$submission = null;
|
||||
$his = DB::selectFirst([
|
||||
"select id, submission_id from submissions_history",
|
||||
"where", ["status" => $status, "major" => 0], // $assignCond is removed!!! fix this bug in the future!
|
||||
"order by id limit 1"
|
||||
]);
|
||||
if (!$his) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$ok = DB::transaction(function () use (&$submission, &$his, $set_q, $status) {
|
||||
$submission = DB::selectFirst([
|
||||
"select id, problem_id, content from submissions",
|
||||
"where", ["id" => $his['submission_id']], DB::for_share()
|
||||
]);
|
||||
if (!$submission) {
|
||||
return false;
|
||||
}
|
||||
DB::update([
|
||||
"update submissions_history",
|
||||
"set", $set_q,
|
||||
"where", [
|
||||
"id" => $his['id'],
|
||||
"status" => $status
|
||||
]
|
||||
]);
|
||||
if (DB::affected_rows() == 1) {
|
||||
$ret = DB::selectFirst([
|
||||
"select status, judge_time from submissions_history",
|
||||
"where", ["id" => $his['id']]
|
||||
]);
|
||||
if ($ret === false) {
|
||||
return false;
|
||||
}
|
||||
$submission += $ret;
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
});
|
||||
if ($ok) {
|
||||
return $submission;
|
||||
}
|
||||
}
|
||||
}
|
||||
function queryCustomTestSubmissionToJudge() {
|
||||
global $assignCond;
|
||||
|
||||
while (true) {
|
||||
$submission = DB::selectFirst([
|
||||
"select id, problem_id, content from custom_test_submissions",
|
||||
"where", array_merge(["judge_time" => null], $assignCond),
|
||||
"order by id limit 1"
|
||||
]);
|
||||
if (!$submission) {
|
||||
return null;
|
||||
}
|
||||
$submission['is_custom_test'] = '';
|
||||
|
||||
DB::update([
|
||||
"update custom_test_submissions",
|
||||
"set", [
|
||||
"judge_time" => DB::now(),
|
||||
"status" => 'Judging'
|
||||
], "where", [
|
||||
"id" => $submission['id'],
|
||||
"judge_time" => null
|
||||
]
|
||||
]);
|
||||
if (DB::affected_rows() == 1) {
|
||||
$submission['status'] = 'Judging';
|
||||
return $submission;
|
||||
}
|
||||
}
|
||||
}
|
||||
function queryHackToJudge() {
|
||||
global $assignCond;
|
||||
|
||||
while (true) {
|
||||
if (DB::selectFirst([
|
||||
"select 1 from hacks",
|
||||
"where", [
|
||||
["status", "!=", "Waiting"],
|
||||
["status", "!=", "Judged"],
|
||||
], "order by id limit 1"
|
||||
])) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$hack = DB::selectFirst([
|
||||
"select id, submission_id, input, input_type from hacks",
|
||||
"where", array_merge(["judge_time" => null], $assignCond),
|
||||
"order by id limit 1"
|
||||
]);
|
||||
if (!$hack) {
|
||||
return null;
|
||||
}
|
||||
|
||||
DB::update([
|
||||
"update hacks",
|
||||
"set", [
|
||||
"judge_time" => DB::now(),
|
||||
"status" => 'Judging'
|
||||
],
|
||||
"where", [
|
||||
"id" => $hack['id'],
|
||||
"judge_time" => null
|
||||
]
|
||||
]);
|
||||
if (DB::affected_rows() == 1) {
|
||||
$hack['status'] = 'Judging';
|
||||
return $hack;
|
||||
}
|
||||
}
|
||||
}
|
||||
function findSubmissionToJudge() {
|
||||
global $submission, $hack;
|
||||
$submission = querySubmissionToJudge('Waiting', [
|
||||
"judge_time" => DB::now(),
|
||||
"judger" => $_POST['judger_name'],
|
||||
"status" => 'Judging'
|
||||
]);
|
||||
if ($submission) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$submission = queryCustomTestSubmissionToJudge();
|
||||
if ($submission) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$submission = querySubmissionToJudge('Waiting Rejudge', [
|
||||
"judge_time" => DB::now(),
|
||||
"judger" => $_POST['judger_name'],
|
||||
"status" => 'Judging'
|
||||
]);
|
||||
if ($submission) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$submission = querySubmissionToJudge('Judged, Waiting', [
|
||||
"status" => 'Judged, Judging'
|
||||
]);
|
||||
if ($submission) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$submission = queryMinorSubmissionToJudge('Waiting Rejudge', [
|
||||
"judge_time" => DB::now(),
|
||||
"judger" => $_POST['judger_name'],
|
||||
"status" => 'Judging'
|
||||
]);
|
||||
if ($submission) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$submission = queryMinorSubmissionToJudge('Judged, Waiting', [
|
||||
"status" => 'Judged, Judging'
|
||||
]);
|
||||
if ($submission) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$hack = queryHackToJudge();
|
||||
if ($hack) {
|
||||
$submission = DB::selectFirst([
|
||||
"select id, problem_id, content from submissions",
|
||||
"where", [
|
||||
"id" => $hack['submission_id'],
|
||||
"score" => 100
|
||||
]
|
||||
]);
|
||||
if (!$submission) {
|
||||
$details = "<error>the score gained by the hacked submission is not 100.</error>";
|
||||
DB::update([
|
||||
"update hacks",
|
||||
"set", [
|
||||
'success' => 0,
|
||||
'status' => 'Judged',
|
||||
'details' => uojTextEncode($details)
|
||||
], "where", ["id" => $hack['id']]
|
||||
]);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (isset($_POST['fetch_new']) && !$_POST['fetch_new']) {
|
||||
if (isset($_POST['fetch_new']) && !$_POST['fetch_new']) {
|
||||
die("Nothing to judge");
|
||||
}
|
||||
if (!findSubmissionToJudge()) {
|
||||
}
|
||||
if (!findSubmissionToJudge()) {
|
||||
die("Nothing to judge");
|
||||
}
|
||||
}
|
||||
|
||||
$submission['id'] = (int)$submission['id'];
|
||||
$submission['problem_id'] = (int)$submission['problem_id'];
|
||||
$submission['problem_mtime'] = filemtime("/var/uoj_data/{$submission['problem_id']}");
|
||||
$submission['content'] = json_decode($submission['content']);
|
||||
$submission['id'] = (int)$submission['id'];
|
||||
$submission['problem_id'] = (int)$submission['problem_id'];
|
||||
$submission['problem_mtime'] = filemtime("/var/uoj_data/{$submission['problem_id']}");
|
||||
$submission['content'] = json_decode($submission['content'], true);
|
||||
if (isset($submission['status']) && $submission['status'] == 'Judged, Judging' && isset($submission['content']['final_test_config'])) {
|
||||
$submission['content']['config'] = $submission['content']['final_test_config'];
|
||||
unset($submission['content']['final_test_config']);
|
||||
}
|
||||
|
||||
if ($hack) {
|
||||
if ($hack) {
|
||||
$submission['is_hack'] = "";
|
||||
$submission['hack']['id'] = (int)$hack['id'];
|
||||
$submission['hack']['input'] = $hack['input'];
|
||||
$submission['hack']['input_type'] = $hack['input_type'];
|
||||
}
|
||||
}
|
||||
|
||||
echo json_encode($submission);
|
||||
?>
|
||||
echo json_encode($submission);
|
||||
|
@ -1,11 +1,19 @@
|
||||
<?php
|
||||
requirePHPLib('judger');
|
||||
requirePHPLib('judger');
|
||||
requirePHPLib('data');
|
||||
|
||||
if (!authenticateJudger()) {
|
||||
become404Page();
|
||||
}
|
||||
if (!authenticateJudger()) {
|
||||
UOJResponse::page404();
|
||||
}
|
||||
|
||||
foreach (DB::selectAll("select * from judger_info where ip != ''") as $judger) {
|
||||
$res = DB::selectAll([
|
||||
"select * from judger_info",
|
||||
"where", [
|
||||
["ip", "!=", ""],
|
||||
"enabled" => true
|
||||
]
|
||||
]);
|
||||
foreach ($res as $judger) {
|
||||
$socket = fsockopen($judger['ip'], UOJConfig::$data['judger']['socket']['port']);
|
||||
if ($socket === false) {
|
||||
die("judge client {$judger['ip']} lost.");
|
||||
@ -15,7 +23,6 @@
|
||||
'cmd' => 'update'
|
||||
]));
|
||||
fclose($socket);
|
||||
}
|
||||
}
|
||||
|
||||
die("ok");
|
||||
?>
|
||||
die("ok");
|
||||
|
@ -1,12 +1,8 @@
|
||||
<?php
|
||||
if (!Auth::check() && UOJConfig::$data['switch']['force-login']) {
|
||||
if (!Auth::check()) {
|
||||
redirectToLogin();
|
||||
}
|
||||
|
||||
if (!isNormalUser($myUser) && UOJConfig::$data['switch']['force-login']) {
|
||||
become403Page();
|
||||
}
|
||||
|
||||
requireLib('bootstrap5');
|
||||
requireLib('mathjax');
|
||||
requirePHPLib('form');
|
||||
@ -73,7 +69,7 @@ EOD;
|
||||
echo "<td>{$extra_config['difficulty']}</td>";
|
||||
}
|
||||
}
|
||||
echo '<td class="text-start">', getClickZanBlock('P', $problem['id'], $problem['zan'], null, false), '</td>';
|
||||
echo '<td class="text-start">', ClickZans::getBlock('P', $problem['id'], $problem['zan'], null, false), '</td>';
|
||||
echo '</tr>';
|
||||
}
|
||||
}
|
||||
@ -121,7 +117,7 @@ EOD;
|
||||
<!-- title container -->
|
||||
<div class="d-flex justify-content-between">
|
||||
|
||||
<h1 class="h2">
|
||||
<h1>
|
||||
<?= $list['title'] ?>
|
||||
<span class="fs-5">(ID: #<?= $list['id'] ?>)</span>
|
||||
<?php if ($list['is_hidden']): ?>
|
||||
@ -146,7 +142,7 @@ EOD;
|
||||
<!-- description -->
|
||||
<div class="card my-2">
|
||||
<div class="card-body">
|
||||
<h2 class="h5 mb-3">题单简介</h2>
|
||||
<h2 class="h4 mb-3">题单简介</h2>
|
||||
<?php $description = HTML::purifier()->purify(HTML::parsedown()->text($list['description'])) ?>
|
||||
<?php if ($description): ?>
|
||||
<?= $description ?>
|
||||
|
@ -44,7 +44,7 @@
|
||||
if ($cur_tab == 'profile') {
|
||||
$list_tags = queryProblemListTags($list_id);
|
||||
|
||||
$update_profile_form = new UOJForm('update_profile');
|
||||
$update_profile_form = new UOJBs4Form('update_profile');
|
||||
$update_profile_form->addVInput('name', 'text', '标题', $list['title'],
|
||||
function($title, &$vdata) {
|
||||
if ($title == '') {
|
||||
@ -151,7 +151,7 @@ function(res) {
|
||||
$(window).scrollTop(0);
|
||||
}
|
||||
EOD);
|
||||
$update_profile_form->submit_button_config['margin_class'] = 'mt-3';
|
||||
$update_profile_form->submit_button_config['class_str'] = 'btn btn-secondary mt-3';
|
||||
$update_profile_form->submit_button_config['text'] = '更新';
|
||||
$update_profile_form->runAtServer();
|
||||
} elseif ($cur_tab == 'problems') {
|
||||
@ -179,7 +179,7 @@ EOD);
|
||||
|
||||
$n_problems = DB::selectCount("SELECT count(*) FROM `lists_problems` WHERE `list_id` = {$list['id']}");
|
||||
|
||||
$add_new_problem_form = new UOJForm('add_new_problem');
|
||||
$add_new_problem_form = new UOJBs4Form('add_new_problem');
|
||||
$add_new_problem_form->addVInput('problem_id', 'text', '题目 ID', '',
|
||||
function ($problem_id, &$vdata) use ($list) {
|
||||
if (!validateUInt($problem_id)) {
|
||||
@ -200,7 +200,7 @@ EOD);
|
||||
},
|
||||
null
|
||||
);
|
||||
$add_new_problem_form->submit_button_config['margin_class'] = 'mt-3';
|
||||
$add_new_problem_form->submit_button_config['class_str'] = 'btn btn-secondary mt-3';
|
||||
$add_new_problem_form->submit_button_config['text'] = '添加';
|
||||
$add_new_problem_form->handle = function($vdata) use ($list) {
|
||||
DB::insert("INSERT INTO `lists_problems` (`list_id`, `problem_id`) values ({$list['id']}, {$vdata['problem_id']})");
|
||||
@ -250,7 +250,7 @@ EOD);
|
||||
dieWithAlert('移除成功!');
|
||||
}
|
||||
|
||||
$add_new_assignment_form = new UOJForm('add_new_assignment');
|
||||
$add_new_assignment_form = new UOJBs4Form('add_new_assignment');
|
||||
$add_new_assignment_form->addVInput('new_assignment_group_id', 'text', '小组 ID', '',
|
||||
function ($group_id, &$vdata) use ($list) {
|
||||
if (!validateUInt($group_id)) {
|
||||
@ -300,7 +300,7 @@ EOD);
|
||||
'message' => '题单 #' . $list['id'] . ' 已经被添加到小组 #' . $vdata['group_id'] . ' 的作业列表中,结束时间为 ' . $vdata['end_time']->format('Y-m-d H:i:s') . '。'
|
||||
]);
|
||||
};
|
||||
$add_new_assignment_form->submit_button_config['margin_class'] = 'mt-3';
|
||||
$add_new_assignment_form->submit_button_config['class_str'] = 'btn btn-secondary mt-3';
|
||||
$add_new_assignment_form->submit_button_config['text'] = '添加';
|
||||
$add_new_assignment_form->setAjaxSubmit(<<<EOD
|
||||
function(res) {
|
||||
@ -330,7 +330,7 @@ EOD);
|
||||
|
||||
<?php echoUOJPageHeader('管理 - ' . $list['title']) ?>
|
||||
|
||||
<h1 class="h2">
|
||||
<h1>
|
||||
<?= $list['title'] ?>
|
||||
<small class="fs-5">(ID: #<?= $list['id'] ?>)</small>
|
||||
管理
|
||||
|
@ -1,19 +1,15 @@
|
||||
<?php
|
||||
if (!Auth::check() && UOJConfig::$data['switch']['force-login']) {
|
||||
if (!Auth::check()) {
|
||||
redirectToLogin();
|
||||
}
|
||||
|
||||
if (!isNormalUser($myUser) && UOJConfig::$data['switch']['force-login']) {
|
||||
become403Page();
|
||||
}
|
||||
|
||||
requireLib('bootstrap5');
|
||||
requirePHPLib('form');
|
||||
requirePHPLib('judger');
|
||||
requirePHPLib('data');
|
||||
|
||||
if (isSuperUser($myUser)) {
|
||||
$new_list_form = new UOJForm('new_list');
|
||||
$new_list_form = new UOJBs4Form('new_list');
|
||||
$new_list_form->handle = function() {
|
||||
DB::query("insert into lists (title, is_hidden) values ('未命名题单', 1)");
|
||||
};
|
||||
@ -66,7 +62,7 @@
|
||||
<!-- title container -->
|
||||
<div class="d-flex justify-content-between">
|
||||
|
||||
<h1 class="h2">
|
||||
<h1>
|
||||
<?= UOJLocale::get('problems lists') ?>
|
||||
</h1>
|
||||
|
||||
@ -147,7 +143,6 @@ EOD;
|
||||
'page_len' => 40,
|
||||
'table_classes' => ['table', 'table-bordered', 'table-hover', 'table-striped'],
|
||||
'head_pagination' => true,
|
||||
'pagination_table' => 'lists',
|
||||
'div_classes' => ['card', 'my-3'],
|
||||
'table_classes' => ['table', 'uoj-table', 'mb-0'],
|
||||
]
|
||||
|
@ -1,15 +1,13 @@
|
||||
<?php
|
||||
use Gregwar\Captcha\PhraseBuilder;
|
||||
use Gregwar\Captcha\CaptchaBuilder;
|
||||
|
||||
requireLib('md5');
|
||||
requireLib('bootstrap5');
|
||||
use Gregwar\Captcha\PhraseBuilder;
|
||||
|
||||
if (Auth::check()) {
|
||||
redirectTo('/');
|
||||
}
|
||||
requireLib('md5');
|
||||
requireLib('bootstrap5');
|
||||
|
||||
function handleLoginPost() {
|
||||
Auth::check() && redirectTo('/');
|
||||
|
||||
function handleLoginPost() {
|
||||
if (!crsf_check()) {
|
||||
return 'expired';
|
||||
}
|
||||
@ -34,25 +32,26 @@
|
||||
return "failed";
|
||||
}
|
||||
|
||||
$user = queryUser($username);
|
||||
$user = UOJUser::query($username);
|
||||
if (!$user || !checkPassword($user, $password)) {
|
||||
return "failed";
|
||||
}
|
||||
|
||||
if ($user['usergroup'] == 'B') {
|
||||
return "banned";
|
||||
$account_status = UOJUser::getAccountStatus($user);
|
||||
if ($account_status != 'ok') {
|
||||
return 'account:' . $account_status;
|
||||
}
|
||||
|
||||
Auth::login($user['username']);
|
||||
return "ok";
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($_POST['login'])) {
|
||||
if (isset($_POST['login'])) {
|
||||
echo handleLoginPost();
|
||||
unset($_SESSION['phrase']);
|
||||
die();
|
||||
}
|
||||
?>
|
||||
}
|
||||
?>
|
||||
<?php echoUOJPageHeader(UOJLocale::get('login')) ?>
|
||||
|
||||
<style>
|
||||
@ -107,28 +106,28 @@
|
||||
</main>
|
||||
|
||||
<script type="text/javascript">
|
||||
function validateLoginPost() {
|
||||
function validateLoginPost() {
|
||||
var ok = true;
|
||||
ok &= getFormErrorAndShowHelp('username', validateUsername);
|
||||
ok &= getFormErrorAndShowHelp('password', validatePassword);
|
||||
return ok;
|
||||
}
|
||||
}
|
||||
|
||||
function refreshCaptcha() {
|
||||
function refreshCaptcha() {
|
||||
var timestamp = new Date().getTime();
|
||||
$("#captcha").attr("src", "/captcha" + '?' + timestamp);
|
||||
}
|
||||
}
|
||||
|
||||
function submitLoginPost() {
|
||||
function submitLoginPost() {
|
||||
if (!validateLoginPost()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$.post('/login', {
|
||||
_token : "<?= crsf_token() ?>",
|
||||
login : '',
|
||||
username : $('#input-username').val(),
|
||||
password : md5($('#input-password').val(), "<?= getPasswordClientSalt() ?>"),
|
||||
_token: "<?= crsf_token() ?>",
|
||||
login: '',
|
||||
username: $('#input-username').val(),
|
||||
password: md5($('#input-password').val(), "<?= getPasswordClientSalt() ?>"),
|
||||
captcha: $('#input-captcha').val(),
|
||||
}, function(msg) {
|
||||
$('#div-username, #div-password, #div-captcha').removeClass('has-validation');
|
||||
@ -166,9 +165,9 @@ function submitLoginPost() {
|
||||
}
|
||||
});
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
$(document).ready(function() {
|
||||
$(document).ready(function() {
|
||||
refreshCaptcha();
|
||||
|
||||
$('#form-login').submit(function(e) {
|
||||
@ -178,8 +177,7 @@ $(document).ready(function() {
|
||||
$("#captcha").click(function(e) {
|
||||
refreshCaptcha();
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
</script>
|
||||
|
||||
<?php echoUOJPageFooter() ?>
|
||||
|
@ -1,12 +1,12 @@
|
||||
<?php
|
||||
crsf_defend();
|
||||
Auth::logout();
|
||||
?>
|
||||
crsf_defend();
|
||||
Auth::logout();
|
||||
?>
|
||||
|
||||
<script type="text/javascript">
|
||||
var prevUrl = document.referrer;
|
||||
if (!prevUrl) {
|
||||
var prevUrl = document.referrer;
|
||||
if (!prevUrl) {
|
||||
prevUrl = '/';
|
||||
};
|
||||
window.location.href = prevUrl;
|
||||
};
|
||||
window.location.href = prevUrl;
|
||||
</script>
|
||||
|
@ -1,374 +1,324 @@
|
||||
<?php
|
||||
requireLib('bootstrap5');
|
||||
requireLib('hljs');
|
||||
requireLib('mathjax');
|
||||
requirePHPLib('form');
|
||||
requirePHPLib('judger');
|
||||
requireLib('bootstrap5');
|
||||
requireLib('hljs');
|
||||
requireLib('mathjax');
|
||||
requirePHPLib('form');
|
||||
requirePHPLib('judger');
|
||||
|
||||
if (!Auth::check() && UOJConfig::$data['switch']['force-login']) {
|
||||
redirectToLogin();
|
||||
Auth::check() || redirectToLogin();
|
||||
UOJProblem::init(UOJRequest::get('id')) || UOJResponse::page404();
|
||||
|
||||
$problem = UOJProblem::cur()->info;
|
||||
$problem_content = UOJProblem::cur()->queryContent();
|
||||
|
||||
if (UOJRequest::get('contest_id')) {
|
||||
UOJContest::init(UOJRequest::get('contest_id')) || UOJResponse::page404();
|
||||
UOJProblem::upgradeToContestProblem() || UOJResponse::page404();
|
||||
}
|
||||
UOJProblem::cur()->userCanView(Auth::user(), ['ensure' => true]);
|
||||
|
||||
$pre_submit_check_ret = UOJProblem::cur()->preSubmitCheck();
|
||||
|
||||
$is_participating = false;
|
||||
$no_more_submission = false;
|
||||
$submission_warning = null;
|
||||
if (UOJContest::cur()) {
|
||||
if (UOJContest::cur()->userCanParticipateNow(Auth::user())) {
|
||||
if (!UOJContest::cur()->userHasMarkedParticipated(Auth::user())) {
|
||||
redirectTo(UOJContest::cur()->getUri("/confirm"));
|
||||
}
|
||||
|
||||
if (!validateUInt($_GET['id']) || !($problem = queryProblemBrief($_GET['id']))) {
|
||||
become404Page();
|
||||
$is_participating = true;
|
||||
$submit_time_limit = UOJContestProblem::cur()->submitTimeLimit();
|
||||
$max_cnt = UOJContest::cur()->maxSubmissionCountPerProblem();
|
||||
if ($submit_time_limit != -1) {
|
||||
$cur_contest_time = (UOJTime::$time_now->getTimestamp() - UOJContest::info('start_time')->getTimestamp()) / 60;
|
||||
if ($cur_contest_time > $submit_time_limit) {
|
||||
$no_more_submission = "本题只能在比赛的前 {$submit_time_limit} 分钟提交,没法再交咯";
|
||||
}
|
||||
|
||||
$problem_content = queryProblemContent($problem['id']);
|
||||
|
||||
$contest = validateUInt($_GET['contest_id']) ? queryContest($_GET['contest_id']) : null;
|
||||
if ($contest != null) {
|
||||
genMoreContestInfo($contest);
|
||||
$problem_rank = queryContestProblemRank($contest, $problem);
|
||||
if ($problem_rank == null) {
|
||||
become404Page();
|
||||
}
|
||||
if (!$no_more_submission) {
|
||||
if ($max_cnt != -1) {
|
||||
$cnt = UOJContestProblem::cur()->queryUserSubmissionCountInContest(Auth::user());
|
||||
if ($cnt >= $max_cnt) {
|
||||
$no_more_submission = "提交次数已达到 {$cnt} 次,没法再交咯";
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!$no_more_submission) {
|
||||
if ($max_cnt != -1) {
|
||||
$warning1 = "已使用 {$cnt}/{$max_cnt} 次提交机会";
|
||||
} else {
|
||||
$problem_letter = chr(ord('A') + $problem_rank - 1);
|
||||
$warning1 = null;
|
||||
}
|
||||
if ($submit_time_limit != -1) {
|
||||
$warning2 = "注意本题只能在比赛的前 {$submit_time_limit} 分钟提交";
|
||||
} else {
|
||||
$warning2 = null;
|
||||
}
|
||||
if ($warning1 && $warning2) {
|
||||
$submission_warning = "{$warning1}({$warning2})";
|
||||
} else {
|
||||
$submission_warning = $warning1 !== null ? $warning1 : $warning2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$is_in_contest = false;
|
||||
$ban_in_contest = false;
|
||||
if ($contest != null) {
|
||||
if (!hasContestPermission($myUser, $contest)) {
|
||||
if ($contest['cur_progress'] == CONTEST_NOT_STARTED) {
|
||||
become404Page();
|
||||
} elseif ($contest['cur_progress'] == CONTEST_IN_PROGRESS) {
|
||||
if (Auth::check()) {
|
||||
if (hasParticipated($myUser, $contest)) {
|
||||
$is_in_contest = true;
|
||||
} else {
|
||||
redirectTo("/contest/{$contest['id']}/confirm");
|
||||
}
|
||||
} else {
|
||||
redirectToLogin();
|
||||
}
|
||||
} else {
|
||||
$ban_in_contest = !isProblemVisibleToUser($problem, $myUser);
|
||||
// 比赛导航
|
||||
$tabs_info = [
|
||||
'dashboard' => [
|
||||
'name' => UOJLocale::get('contests::contest dashboard'),
|
||||
'url' => '/contest/' . UOJContest::info('id'),
|
||||
],
|
||||
'submissions' => [
|
||||
'name' => UOJLocale::get('contests::contest submissions'),
|
||||
'url' => '/contest/' . UOJContest::info('id') . '/submissions',
|
||||
],
|
||||
'standings' => [
|
||||
'name' => UOJLocale::get('contests::contest standings'),
|
||||
'url' => '/contest/' . UOJContest::info('id') . '/standings',
|
||||
],
|
||||
];
|
||||
|
||||
if (!hasRegistered($myUser, $contest) && !isNormalUser($myUser) && UOJConfig::$data['switch']['force-login']) {
|
||||
become403Page();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if ($contest['cur_progress'] == CONTEST_IN_PROGRESS) {
|
||||
if (hasRegistered($myUser, $contest)) {
|
||||
if (hasParticipated($myUser, $contest)) {
|
||||
$is_in_contest = true;
|
||||
} else {
|
||||
redirectTo("/contest/{$contest['id']}/confirm");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (!isProblemVisibleToUser($problem, $myUser)) {
|
||||
become404Page();
|
||||
if (UOJContest::cur()->progress() > CONTEST_TESTING) {
|
||||
$tabs_info['after_contest_standings'] = [
|
||||
'name' => UOJLocale::get('contests::after contest standings'),
|
||||
'url' => '/contest/' . UOJContest::info('id') . '/after_contest_standings',
|
||||
];
|
||||
$tabs_info['self_reviews'] = [
|
||||
'name' => UOJLocale::get('contests::contest self reviews'),
|
||||
'url' => '/contest/' . UOJContest::info('id') . '/self_reviews',
|
||||
];
|
||||
}
|
||||
|
||||
if (!isNormalUser($myUser) && UOJConfig::$data['switch']['force-login']) {
|
||||
become403Page();
|
||||
}
|
||||
if (UOJContest::cur()->userCanManage(Auth::user())) {
|
||||
$tabs_info['backstage'] = [
|
||||
'name' => UOJLocale::get('contests::contest backstage'),
|
||||
'url' => '/contest/' . UOJContest::info('id') . '/backstage',
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
$submission_requirement = json_decode($problem['submission_requirement'], true);
|
||||
$problem_extra_config = getProblemExtraConfig($problem);
|
||||
$custom_test_requirement = getProblemCustomTestRequirement($problem);
|
||||
$submission_requirement = UOJProblem::cur()->getSubmissionRequirement();
|
||||
$custom_test_requirement = UOJProblem::cur()->getCustomTestRequirement();
|
||||
$custom_test_enabled = $custom_test_requirement && $pre_submit_check_ret === true;
|
||||
|
||||
if ($custom_test_requirement && Auth::check()) {
|
||||
$custom_test_submission = DB::selectFirst("select * from custom_test_submissions where submitter = '".Auth::id()."' and problem_id = {$problem['id']} order by id desc limit 1");
|
||||
$custom_test_submission_result = json_decode($custom_test_submission['result'], true);
|
||||
}
|
||||
if ($custom_test_requirement && $_GET['get'] == 'custom-test-status-details' && Auth::check()) {
|
||||
if ($custom_test_submission == null) {
|
||||
function handleUpload($zip_file_name, $content, $tot_size) {
|
||||
global $is_participating;
|
||||
UOJSubmission::onUpload($zip_file_name, $content, $tot_size, $is_participating);
|
||||
}
|
||||
function handleCustomTestUpload($zip_file_name, $content, $tot_size) {
|
||||
UOJCustomTestSubmission::onUpload($zip_file_name, $content, $tot_size);
|
||||
}
|
||||
if ($custom_test_enabled) {
|
||||
UOJCustomTestSubmission::init(UOJProblem::cur(), Auth::user());
|
||||
|
||||
if (UOJRequest::get('get') == 'custom-test-status-details') {
|
||||
if (!UOJCustomTestSubmission::cur()) {
|
||||
echo json_encode(null);
|
||||
} elseif ($custom_test_submission['status'] != 'Judged') {
|
||||
echo json_encode(array(
|
||||
} elseif (!UOJCustomTestSubmission::cur()->hasJudged()) {
|
||||
echo json_encode([
|
||||
'judged' => false,
|
||||
'html' => getSubmissionStatusDetails($custom_test_submission)
|
||||
));
|
||||
'waiting' => true,
|
||||
'html' => UOJCustomTestSubmission::cur()->getStatusDetailsHTML(),
|
||||
]);
|
||||
} else {
|
||||
ob_start();
|
||||
$styler = new CustomTestSubmissionDetailsStyler();
|
||||
if (!hasViewPermission($problem_extra_config['view_details_type'], $myUser, $problem, $submission)) {
|
||||
if (!UOJCustomTestSubmission::cur()->userPermissionCodeCheck(Auth::user(), UOJProblem::cur()->getExtraConfig('view_details_type'))) {
|
||||
$styler->fade_all_details = true;
|
||||
}
|
||||
echoJudgementDetails($custom_test_submission_result['details'], $styler, 'custom_test_details');
|
||||
echoJudgmentDetails(UOJCustomTestSubmission::cur()->getResult('details'), $styler, 'custom_test_details');
|
||||
$result = ob_get_contents();
|
||||
ob_end_clean();
|
||||
echo json_encode(array(
|
||||
echo json_encode([
|
||||
'judged' => true,
|
||||
'html' => getSubmissionStatusDetails($custom_test_submission),
|
||||
'waiting' => false,
|
||||
'html' => UOJCustomTestSubmission::cur()->getStatusDetailsHTML(),
|
||||
'result' => $result
|
||||
));
|
||||
]);
|
||||
}
|
||||
die();
|
||||
}
|
||||
|
||||
$can_use_zip_upload = true;
|
||||
foreach ($submission_requirement as $req) {
|
||||
if ($req['type'] == 'source code') {
|
||||
$can_use_zip_upload = false;
|
||||
}
|
||||
}
|
||||
|
||||
function handleUpload($zip_file_name, $content, $tot_size) {
|
||||
global $problem, $contest, $myUser, $is_in_contest;
|
||||
|
||||
$content['config'][] = array('problem_id', $problem['id']);
|
||||
if ($is_in_contest && $contest['extra_config']["contest_type"]!='IOI' && !isset($contest['extra_config']["problem_{$problem['id']}"])) {
|
||||
$content['final_test_config'] = $content['config'];
|
||||
$content['config'][] = array('test_sample_only', 'on');
|
||||
}
|
||||
$esc_content = DB::escape(json_encode($content));
|
||||
|
||||
$language = '/';
|
||||
foreach ($content['config'] as $row) {
|
||||
if (strEndWith($row[0], '_language')) {
|
||||
$language = $row[1];
|
||||
break;
|
||||
}
|
||||
}
|
||||
if ($language != '/') {
|
||||
Cookie::set('uoj_preferred_language', $language, time() + 60 * 60 * 24 * 365, '/');
|
||||
}
|
||||
$esc_language = DB::escape($language);
|
||||
|
||||
$result = array();
|
||||
$result['status'] = "Waiting";
|
||||
$result_json = json_encode($result);
|
||||
|
||||
if ($is_in_contest) {
|
||||
DB::query("insert into submissions (problem_id, contest_id, submit_time, submitter, content, language, tot_size, status, result, is_hidden) values (${problem['id']}, ${contest['id']}, now(), '${myUser['username']}', '$esc_content', '$esc_language', $tot_size, '${result['status']}', '$result_json', 0)");
|
||||
} else {
|
||||
DB::query("insert into submissions (problem_id, submit_time, submitter, content, language, tot_size, status, result, is_hidden) values (${problem['id']}, now(), '${myUser['username']}', '$esc_content', '$esc_language', $tot_size, '${result['status']}', '$result_json', {$problem['is_hidden']})");
|
||||
}
|
||||
}
|
||||
function handleCustomTestUpload($zip_file_name, $content, $tot_size) {
|
||||
global $problem, $contest, $myUser;
|
||||
|
||||
$content['config'][] = array('problem_id', $problem['id']);
|
||||
$content['config'][] = array('custom_test', 'on');
|
||||
$esc_content = DB::escape(json_encode($content));
|
||||
|
||||
$language = '/';
|
||||
foreach ($content['config'] as $row) {
|
||||
if (strEndWith($row[0], '_language')) {
|
||||
$language = $row[1];
|
||||
break;
|
||||
}
|
||||
}
|
||||
if ($language != '/') {
|
||||
Cookie::set('uoj_preferred_language', $language, time() + 60 * 60 * 24 * 365, '/');
|
||||
}
|
||||
$esc_language = DB::escape($language);
|
||||
|
||||
$result = array();
|
||||
$result['status'] = "Waiting";
|
||||
$result_json = json_encode($result);
|
||||
|
||||
DB::insert("insert into custom_test_submissions (problem_id, submit_time, submitter, content, status, result) values ({$problem['id']}, now(), '{$myUser['username']}', '$esc_content', '{$result['status']}', '$result_json')");
|
||||
}
|
||||
|
||||
if ($can_use_zip_upload) {
|
||||
$zip_answer_form = newZipSubmissionForm('zip_answer',
|
||||
$submission_requirement,
|
||||
'uojRandAvaiableSubmissionFileName',
|
||||
'handleUpload');
|
||||
$zip_answer_form->extra_validator = function() {
|
||||
global $ban_in_contest;
|
||||
if ($ban_in_contest) {
|
||||
return '请耐心等待比赛结束后题目对所有人可见了再提交';
|
||||
}
|
||||
return '';
|
||||
};
|
||||
$zip_answer_form->succ_href = $is_in_contest ? "/contest/{$contest['id']}/submissions" : '/submissions';
|
||||
$zip_answer_form->runAtServer();
|
||||
}
|
||||
|
||||
$answer_form = newSubmissionForm('answer',
|
||||
$submission_requirement,
|
||||
'uojRandAvaiableSubmissionFileName',
|
||||
'handleUpload');
|
||||
$answer_form->extra_validator = function() {
|
||||
global $ban_in_contest;
|
||||
if ($ban_in_contest) {
|
||||
return '请耐心等待比赛结束后题目对所有人可见了再提交';
|
||||
}
|
||||
return '';
|
||||
};
|
||||
$answer_form->succ_href = $is_in_contest ? "/contest/{$contest['id']}/submissions" : '/submissions';
|
||||
$answer_form->runAtServer();
|
||||
|
||||
if ($custom_test_requirement) {
|
||||
$custom_test_form = newSubmissionForm('custom_test',
|
||||
$custom_test_form = newSubmissionForm(
|
||||
'custom_test',
|
||||
$custom_test_requirement,
|
||||
function() {
|
||||
return uojRandAvaiableFileName('/tmp/');
|
||||
},
|
||||
'handleCustomTestUpload');
|
||||
$custom_test_form->appendHTML(<<<EOD
|
||||
<div id="div-custom_test_result"></div>
|
||||
EOD
|
||||
'FS::randomAvailableTmpFileName',
|
||||
'handleCustomTestUpload'
|
||||
);
|
||||
$custom_test_form->appendHTML('<div id="div-custom_test_result"></div>');
|
||||
$custom_test_form->succ_href = 'none';
|
||||
$custom_test_form->extra_validator = function() {
|
||||
global $ban_in_contest, $custom_test_submission;
|
||||
if ($ban_in_contest) {
|
||||
return '请耐心等待比赛结束后题目对所有人可见了再提交';
|
||||
}
|
||||
if ($custom_test_submission && $custom_test_submission['status'] != 'Judged') {
|
||||
$custom_test_form->extra_validator = function () {
|
||||
if (UOJCustomTestSubmission::cur() && !UOJCustomTestSubmission::cur()->hasJudged()) {
|
||||
return '上一个测评尚未结束';
|
||||
}
|
||||
return '';
|
||||
};
|
||||
$custom_test_form->ctrl_enter_submit = true;
|
||||
$custom_test_form->setAjaxSubmit(<<<EOD
|
||||
function(response_text) {custom_test_onsubmit(response_text, $('#div-custom_test_result')[0], '{$_SERVER['REQUEST_URI']}?get=custom-test-status-details')}
|
||||
EOD
|
||||
$custom_test_form->setAjaxSubmit(
|
||||
<<<EOD
|
||||
function(response_text) {
|
||||
custom_test_onsubmit(
|
||||
response_text,
|
||||
$('#div-custom_test_result')[0],
|
||||
'{$_SERVER['REQUEST_URI']}?get=custom-test-status-details'
|
||||
)
|
||||
}
|
||||
EOD
|
||||
);
|
||||
$custom_test_form->submit_button_config['text'] = UOJLocale::get('problems::run');
|
||||
$custom_test_form->runAtServer();
|
||||
}
|
||||
|
||||
$can_use_zip_upload = true;
|
||||
foreach ($submission_requirement as $req) {
|
||||
if ($req['type'] == 'source code') {
|
||||
$can_use_zip_upload = false;
|
||||
}
|
||||
?>
|
||||
}
|
||||
|
||||
if ($pre_submit_check_ret === true && !$no_more_submission) {
|
||||
$submission_extra_validator = function () {
|
||||
if (!submission_frequency_check()) {
|
||||
UOJLog::warning('a user exceeds the submission frequency limit! ' . Auth::id() . ' at problem #' . UOJProblem::info('id'));
|
||||
return '交题交得太快啦,坐下来喝杯阿华田休息下吧?';
|
||||
}
|
||||
return '';
|
||||
};
|
||||
|
||||
if (UOJProblem::cur()->userCanUploadSubmissionViaZip(Auth::user())) {
|
||||
$zip_answer_form = newZipSubmissionForm(
|
||||
'zip-answer',
|
||||
$submission_requirement,
|
||||
'FS::randomAvailableSubmissionFileName',
|
||||
'handleUpload'
|
||||
);
|
||||
$zip_answer_form->extra_validators[] = $submission_extra_validator;
|
||||
$zip_answer_form->succ_href = $is_participating ? '/contest/' . UOJContest::info('id') . '/submissions' : '/submissions';
|
||||
$zip_answer_form->runAtServer();
|
||||
}
|
||||
|
||||
$answer_form = newSubmissionForm(
|
||||
'answer',
|
||||
$submission_requirement,
|
||||
'FS::randomAvailableSubmissionFileName',
|
||||
'handleUpload'
|
||||
);
|
||||
$answer_form->extra_validator = $submission_extra_validator;
|
||||
$answer_form->succ_href = $is_participating ? '/contest/' . UOJContest::info('id') . '/submissions' : '/submissions';
|
||||
$answer_form->runAtServer();
|
||||
}
|
||||
|
||||
$conf = UOJProblem::cur()->getProblemConf();
|
||||
?>
|
||||
|
||||
<?php echoUOJPageHeader(HTML::stripTags($problem['title']) . ' - ' . UOJLocale::get('problems::problem')) ?>
|
||||
<?php
|
||||
$limit = getUOJConf("/var/uoj_data/{$problem['id']}/problem.conf");
|
||||
$time_limit = $limit['time_limit'];
|
||||
$memory_limit = $limit['memory_limit'];
|
||||
|
||||
$problem_uploader = $problem['uploader'];
|
||||
?>
|
||||
|
||||
<div class="row">
|
||||
<!-- Left col -->
|
||||
<div class="col-lg-9">
|
||||
|
||||
<!-- Left col -->
|
||||
<div class="col-lg-9">
|
||||
|
||||
<?php if ($contest): ?>
|
||||
<!-- 比赛导航 -->
|
||||
<?php
|
||||
$tabs_info = array(
|
||||
'dashboard' => array(
|
||||
'name' => UOJLocale::get('contests::contest dashboard'),
|
||||
'url' => "/contest/{$contest['id']}"
|
||||
),
|
||||
'submissions' => array(
|
||||
'name' => UOJLocale::get('contests::contest submissions'),
|
||||
'url' => "/contest/{$contest['id']}/submissions"
|
||||
),
|
||||
'standings' => array(
|
||||
'name' => UOJLocale::get('contests::contest standings'),
|
||||
'url' => "/contest/{$contest['id']}/standings"
|
||||
),
|
||||
);
|
||||
|
||||
if ($contest['cur_progress'] > CONTEST_TESTING) {
|
||||
$tabs_info['after_contest_standings'] = array(
|
||||
'name' => UOJLocale::get('contests::after contest standings'),
|
||||
'url' => "/contest/{$contest['id']}/after_contest_standings"
|
||||
);
|
||||
$tabs_info['self_reviews'] = array(
|
||||
'name' => UOJLocale::get('contests::contest self reviews'),
|
||||
'url' => "/contest/{$contest['id']}/self_reviews"
|
||||
);
|
||||
}
|
||||
|
||||
if (hasContestPermission(Auth::user(), $contest)) {
|
||||
$tabs_info['backstage'] = array(
|
||||
'name' => UOJLocale::get('contests::contest backstage'),
|
||||
'url' => "/contest/{$contest['id']}/backstage"
|
||||
);
|
||||
}
|
||||
?>
|
||||
<?php if (isset($tabs_info)) : ?>
|
||||
<!-- 比赛导航 -->
|
||||
<div class="mb-2">
|
||||
<?= HTML::tablist($tabs_info, '', 'nav-pills') ?>
|
||||
</div>
|
||||
<?php endif ?>
|
||||
<?php endif ?>
|
||||
|
||||
<div class="card card-default mb-2">
|
||||
<div class="card-body">
|
||||
<div class="card card-default mb-2">
|
||||
<div class="card-body">
|
||||
|
||||
<h1 class="h2 card-title text-center">
|
||||
<?php if ($contest): ?>
|
||||
<?= $problem_letter ?>. <?= $problem['title'] ?>
|
||||
<?php else: ?>
|
||||
#<?= $problem['id']?>. <?= $problem['title'] ?>
|
||||
<?php endif ?>
|
||||
</h1>
|
||||
<h1 class="card-title text-center">
|
||||
<?php if (UOJContest::cur()) : ?>
|
||||
<?= UOJProblem::cur()->getTitle(['with' => 'letter', 'simplify' => true]) ?>
|
||||
<?php else : ?>
|
||||
<?= UOJProblem::cur()->getTitle(['with' => 'id']) ?>
|
||||
<?php endif ?>
|
||||
</h1>
|
||||
|
||||
<div class="text-center small">
|
||||
时间限制: <?= $time_limit != null ? "$time_limit s" : "N/A" ?>
|
||||
<?php
|
||||
$time_limit = $conf instanceof UOJProblemConf ? $conf->getVal('time_limit', null) : null;
|
||||
$memory_limit = $conf instanceof UOJProblemConf ? $conf->getVal('memory_limit', null) : null;
|
||||
?>
|
||||
<div class="text-center small">
|
||||
时间限制: <?= $time_limit ? "$time_limit s" : "N/A" ?>
|
||||
 
|
||||
空间限制: <?= $memory_limit != null ? "$memory_limit MB" : "N/A" ?>
|
||||
空间限制: <?= $memory_limit ? "$memory_limit MB" : "N/A" ?>
|
||||
 
|
||||
上传者: <?= getUserLink($problem_uploader ?: "root") ?>
|
||||
</div>
|
||||
上传者: <?= UOJProblem::cur()->getUploaderLink() ?>
|
||||
</div>
|
||||
|
||||
<hr>
|
||||
<hr>
|
||||
|
||||
<div class="tab-content">
|
||||
<div class="tab-content">
|
||||
<div class="tab-pane active" id="statement">
|
||||
<article class="mt-3 markdown-body">
|
||||
<?= $problem_content['statement'] ?>
|
||||
</article>
|
||||
</div>
|
||||
<div class="tab-pane" id="submit">
|
||||
<div class="top-buffer-sm"></div>
|
||||
<?php if ($can_use_zip_upload): ?>
|
||||
<?php if ($pre_submit_check_ret !== true) : ?>
|
||||
<h3 class="text-warning"><?= $pre_submit_check_ret ?></h3>
|
||||
<?php elseif ($no_more_submission) : ?>
|
||||
<h3 class="text-warning"><?= $no_more_submission ?></h3>
|
||||
<?php else : ?>
|
||||
<?php if ($submission_warning) : ?>
|
||||
<h3 class="text-warning"><?= $submission_warning ?></h3>
|
||||
<?php endif ?>
|
||||
<?php if (isset($zip_answer_form)) : ?>
|
||||
<?php $zip_answer_form->printHTML(); ?>
|
||||
<hr />
|
||||
<strong><?= UOJLocale::get('problems::or upload files one by one') ?><br /></strong>
|
||||
<?php endif ?>
|
||||
<?php $answer_form->printHTML(); ?>
|
||||
<?php endif ?>
|
||||
</div>
|
||||
<?php if ($custom_test_requirement): ?>
|
||||
<?php if ($custom_test_enabled) : ?>
|
||||
<div class="tab-pane" id="custom-test">
|
||||
<div class="top-buffer-sm"></div>
|
||||
<?php $custom_test_form->printHTML(); ?>
|
||||
</div>
|
||||
<?php endif ?>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
<!-- End left col -->
|
||||
</div>
|
||||
<!-- End left col -->
|
||||
|
||||
<aside class="col-lg-3 mt-3 mt-lg-0">
|
||||
<!-- Right col -->
|
||||
<aside class="col-lg-3 mt-3 mt-lg-0">
|
||||
<!-- Right col -->
|
||||
|
||||
<?php if ($contest): ?>
|
||||
<!-- Contest card -->
|
||||
<div class="card card-default mb-2">
|
||||
<?php if (UOJContest::cur()) : ?>
|
||||
<!-- Contest card -->
|
||||
<div class="card card-default mb-2">
|
||||
<div class="card-body">
|
||||
<h3 class="h5 card-title text-center">
|
||||
<a class="text-decoration-none text-body" href="/contest/<?= $contest['id'] ?>">
|
||||
<?= $contest['name'] ?>
|
||||
<h3 class="h4 card-title text-center">
|
||||
<a class="text-decoration-none text-body" href="/contest/<?= UOJContest::info('id') ?>">
|
||||
<?= UOJContest::info('name') ?>
|
||||
</a>
|
||||
</h3>
|
||||
<div class="card-text text-center text-muted">
|
||||
<?php if ($contest['cur_progress'] <= CONTEST_IN_PROGRESS): ?>
|
||||
<?php if (UOJContest::cur()->progress() <= CONTEST_IN_PROGRESS) : ?>
|
||||
<span id="contest-countdown"></span>
|
||||
<?php else: ?>
|
||||
<?php else : ?>
|
||||
<?= UOJLocale::get('contests::contest ended') ?>
|
||||
<?php endif ?>
|
||||
</div>
|
||||
</div>
|
||||
<div class="card-footer bg-transparent">
|
||||
比赛评价:<?= getClickZanBlock('C', $contest['id'], $contest['zan']) ?>
|
||||
比赛评价:<?= ClickZans::getBlock('C', UOJContest::info('id'), UOJContest::info('zan')) ?>
|
||||
</div>
|
||||
</div>
|
||||
<?php if ($contest['cur_progress'] <= CONTEST_IN_PROGRESS): ?>
|
||||
<script type="text/javascript">
|
||||
$('#contest-countdown').countdown(<?= $contest['end_time']->getTimestamp() - UOJTime::$time_now->getTimestamp() ?>, function(){}, '1.75rem', false);
|
||||
</script>
|
||||
<?php endif ?>
|
||||
<?php endif ?>
|
||||
</div>
|
||||
<?php if (UOJContest::cur()->progress() <= CONTEST_IN_PROGRESS) : ?>
|
||||
<script>
|
||||
$('#contest-countdown').countdown(<?= UOJContest::info('end_time')->getTimestamp() - UOJTime::$time_now->getTimestamp() ?>, function() {}, '1.75rem', false);
|
||||
</script>
|
||||
<?php endif ?>
|
||||
<?php endif ?>
|
||||
|
||||
<!-- 题目导航卡片 -->
|
||||
<div class="card card-default mb-2">
|
||||
<!-- 题目导航卡片 -->
|
||||
<div class="card card-default mb-2">
|
||||
<ul class="nav nav-pills nav-fill flex-column" role="tablist">
|
||||
<li class="nav-item text-start">
|
||||
<a href="#statement" class="nav-link active" role="tab" data-bs-toggle="pill" data-bs-target="#statement">
|
||||
@ -382,7 +332,7 @@ $('#contest-countdown').countdown(<?= $contest['end_time']->getTimestamp() - UOJ
|
||||
<?= UOJLocale::get('problems::submit') ?>
|
||||
</a>
|
||||
</li>
|
||||
<?php if ($custom_test_requirement): ?>
|
||||
<?php if ($custom_test_enabled) : ?>
|
||||
<li class="nav-item text-start">
|
||||
<a class="nav-link" href="#custom-test" role="tab" data-bs-toggle="pill" data-bs-target="#custom-test">
|
||||
<i class="bi bi-braces"></i>
|
||||
@ -390,7 +340,7 @@ $('#contest-countdown').countdown(<?= $contest['end_time']->getTimestamp() - UOJ
|
||||
</a>
|
||||
</li>
|
||||
<?php endif ?>
|
||||
<?php if (!$contest || $contest['cur_progress'] >= CONTEST_FINISHED): ?>
|
||||
<?php if (!UOJContest::cur() || UOJContest::cur()->progress() >= CONTEST_FINISHED) : ?>
|
||||
<li class="nav-item text-start">
|
||||
<a href="/problem/<?= $problem['id'] ?>/solutions" class="nav-link" role="tab">
|
||||
<i class="bi bi-journal-bookmark"></i>
|
||||
@ -398,19 +348,22 @@ $('#contest-countdown').countdown(<?= $contest['end_time']->getTimestamp() - UOJ
|
||||
</a>
|
||||
</li>
|
||||
<?php endif ?>
|
||||
<?php if (UOJContest::cur() && UOJContest::cur()->userCanSeeProblemStatistics(Auth::user())) : ?>
|
||||
<li class="nav-item text-start">
|
||||
<a class="nav-link"
|
||||
<?php if ($contest): ?>
|
||||
href="/contest/<?= $contest['id'] ?>/problem/<?= $problem['id'] ?>/statistics"
|
||||
<?php else: ?>
|
||||
href="/problem/<?= $problem['id'] ?>/statistics"
|
||||
<?php endif ?>
|
||||
>
|
||||
<a class="nav-link" href="/contest/<?= UOJContest::info('id') ?>/problem/<?= $problem['id'] ?>/statistics">
|
||||
<i class="bi bi-graph-up"></i>
|
||||
<?= UOJLocale::get('problems::statistics') ?>
|
||||
</a>
|
||||
</li>
|
||||
<?php if (hasProblemPermission($myUser, $problem)): ?>
|
||||
<?php elseif (!UOJContest::cur()) : ?>
|
||||
<li class="nav-item text-start">
|
||||
<a class="nav-link" href="/problem/<?= $problem['id'] ?>/statistics">
|
||||
<i class="bi bi-graph-up"></i>
|
||||
<?= UOJLocale::get('problems::statistics') ?>
|
||||
</a>
|
||||
</li>
|
||||
<?php endif ?>
|
||||
<?php if (UOJProblem::cur()->userCanManage(Auth::user())) : ?>
|
||||
<li class="nav-item text-start">
|
||||
<a class="nav-link" href="/problem/<?= $problem['id'] ?>/manage/statement" role="tab">
|
||||
<i class="bi bi-sliders"></i>
|
||||
@ -420,42 +373,44 @@ $('#contest-countdown').countdown(<?= $contest['end_time']->getTimestamp() - UOJ
|
||||
<?php endif ?>
|
||||
</ul>
|
||||
<div class="card-footer bg-transparent">
|
||||
评价:<?= getClickZanBlock('P', $problem['id'], $problem['zan']) ?>
|
||||
评价:<?= ClickZans::getBlock('P', $problem['id'], $problem['zan']) ?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 附件 -->
|
||||
<div class="card card-default mb-2">
|
||||
<!-- 附件 -->
|
||||
<div class="card card-default mb-2">
|
||||
<ul class="nav nav-fill flex-column">
|
||||
<?php if (UOJProblem::cur()->userCanDownloadTestData(Auth::user())) : ?>
|
||||
<li class="nav-item text-start">
|
||||
<a class="nav-link" href="<?= HTML::url("/download.php?type=problem&id={$problem['id']}") ?>">
|
||||
<a class="nav-link" href="<?= HTML::url("/download/problem/{$problem['id']}/data.zip") ?>">
|
||||
<i class="bi bi-hdd-stack"></i>
|
||||
测试数据
|
||||
</a>
|
||||
</li>
|
||||
<?php endif ?>
|
||||
<li class="nav-item text-start">
|
||||
<a class="nav-link" href="<?= HTML::url("/download.php?type=attachment&id={$problem['id']}") ?>">
|
||||
<a class="nav-link" href="<?= HTML::url("/download/problem/{$problem['id']}/attachment.zip") ?>">
|
||||
<i class="bi bi-download"></i>
|
||||
附件下载
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php
|
||||
$sidebar_config = array();
|
||||
if ($contest && $contest['cur_progress'] <= CONTEST_IN_PROGRESS) {
|
||||
<?php
|
||||
$sidebar_config = [];
|
||||
if (UOJContest::cur() && UOJContest::cur()->progress() <= CONTEST_IN_PROGRESS) {
|
||||
$sidebar_config['upcoming_contests_hidden'] = '';
|
||||
}
|
||||
uojIncludeView('sidebar', $sidebar_config);
|
||||
?>
|
||||
</aside>
|
||||
<!-- end right col -->
|
||||
</aside>
|
||||
<!-- end right col -->
|
||||
|
||||
</div>
|
||||
|
||||
<script>
|
||||
$(document).ready(function() {
|
||||
$(document).ready(function() {
|
||||
// Javascript to enable link to tab
|
||||
var hash = location.hash.replace(/^#/, '');
|
||||
if (hash) {
|
||||
@ -470,13 +425,7 @@ $(document).ready(function() {
|
||||
window.location.hash = e.target.hash;
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
<?php if ($contest && $contest['cur_progress'] <= CONTEST_IN_PROGRESS): ?>
|
||||
<script type="text/javascript">
|
||||
checkContestNotice(<?= $contest['id'] ?>, '<?= UOJTime::$time_now_str ?>');
|
||||
</script>
|
||||
<?php endif ?>
|
||||
|
||||
<?php echoUOJPageFooter() ?>
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -1,50 +1,50 @@
|
||||
<?php
|
||||
requireLib('bootstrap5');
|
||||
requirePHPLib('form');
|
||||
requireLib('bootstrap5');
|
||||
requirePHPLib('form');
|
||||
|
||||
if (!Auth::check() && UOJConfig::$data['switch']['force-login']) {
|
||||
redirectToLogin();
|
||||
}
|
||||
Auth::check() || redirectToLogin();
|
||||
UOJProblem::init(UOJRequest::get('id')) || UOJResponse::page404();
|
||||
UOJProblem::cur()->userCanManage(Auth::user()) || UOJResponse::page403();
|
||||
|
||||
if (!validateUInt($_GET['id']) || !($problem = queryProblemBrief($_GET['id']))) {
|
||||
become404Page();
|
||||
}
|
||||
if (!hasProblemPermission($myUser, $problem)) {
|
||||
become403Page();
|
||||
}
|
||||
|
||||
$managers_form = newAddDelCmdForm('managers',
|
||||
function($username) {
|
||||
if (!validateUsername($username) || !queryUser($username)) {
|
||||
return "不存在名为{$username}的用户";
|
||||
}
|
||||
return '';
|
||||
},
|
||||
function($type, $username) {
|
||||
global $problem;
|
||||
$managers_form = newAddDelCmdForm(
|
||||
'managers',
|
||||
'validateUserAndStoreByUsername',
|
||||
function ($type, $username, &$vdata) {
|
||||
$user = $vdata['user'][$username];
|
||||
if ($type == '+') {
|
||||
DB::query("insert into problems_permissions (problem_id, username) values (${problem['id']}, '$username')");
|
||||
} elseif ($type == '-') {
|
||||
DB::query("delete from problems_permissions where problem_id = ${problem['id']} and username = '$username'");
|
||||
DB::insert([
|
||||
"insert into problems_permissions",
|
||||
"(problem_id, username)",
|
||||
"values", DB::tuple([UOJProblem::info('id'), $user['username']])
|
||||
]);
|
||||
} else if ($type == '-') {
|
||||
DB::delete([
|
||||
"delete from problems_permissions",
|
||||
"where", [
|
||||
"problem_id" => UOJProblem::info('id'),
|
||||
"username" => $user['username']
|
||||
]
|
||||
]);
|
||||
}
|
||||
}
|
||||
);
|
||||
);
|
||||
|
||||
$managers_form->runAtServer();
|
||||
$managers_form->runAtServer();
|
||||
|
||||
|
||||
if (isSuperUser($myUser)) {
|
||||
$update_uploader_form = new UOJForm('update_uploader');
|
||||
$update_uploader_form->addInput('new_uploader_username', 'text', '用户名', $problem['uploader'] ?: 'root',
|
||||
function ($x) {
|
||||
if (!validateUsername($x)) {
|
||||
return '用户名不合法';
|
||||
}
|
||||
|
||||
if (!queryUser($x)) {
|
||||
if (isSuperUser($myUser)) {
|
||||
$update_uploader_form = new UOJBs4Form('update_uploader');
|
||||
$update_uploader_form->addInput(
|
||||
'new_uploader_username',
|
||||
'text',
|
||||
'用户名',
|
||||
$problem['uploader'] ?: 'root',
|
||||
function ($username, &$vdata) {
|
||||
if (!UOJUser::query($username)) {
|
||||
return '用户不存在';
|
||||
}
|
||||
|
||||
$vdata['username'] = $username;
|
||||
|
||||
return '';
|
||||
},
|
||||
null
|
||||
@ -52,48 +52,47 @@
|
||||
$update_uploader_form->submit_button_config['align'] = 'compressed';
|
||||
$update_uploader_form->submit_button_config['text'] = '修改上传者';
|
||||
$update_uploader_form->submit_button_config['class_str'] = 'mt-2 btn btn-warning';
|
||||
$update_uploader_form->handle = function() {
|
||||
global $problem;
|
||||
|
||||
$username = $_POST['new_uploader_username'];
|
||||
|
||||
DB::query("update problems set uploader = '{$username}' where id = {$problem['id']}");
|
||||
$update_uploader_form->handle = function (&$vdata) {
|
||||
DB::update([
|
||||
"update problems",
|
||||
"set", ["uploader" => $vdata['username']],
|
||||
"where", ["id" => UOJProblem::info('id')]
|
||||
]);
|
||||
};
|
||||
$update_uploader_form->runAtServer();
|
||||
}
|
||||
?>
|
||||
<?php echoUOJPageHeader(HTML::stripTags($problem['title']) . ' - 管理者 - 题目管理') ?>
|
||||
}
|
||||
?>
|
||||
<?php echoUOJPageHeader('管理者 - ' . HTML::stripTags($problem['title'])) ?>
|
||||
|
||||
<div class="row">
|
||||
<!-- left col -->
|
||||
<div class="col-lg-9">
|
||||
<!-- left col -->
|
||||
<div class="col-lg-9">
|
||||
<h1>
|
||||
<?= UOJProblem::cur()->getTitle() ?> 管理
|
||||
</h1>
|
||||
|
||||
<h1 class="h2">
|
||||
#<?= $problem['id'] ?>. <?= $problem['title'] ?> 管理
|
||||
</h1>
|
||||
|
||||
<ul class="nav nav-pills my-3" role="tablist">
|
||||
<ul class="nav nav-pills my-3" role="tablist">
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="/problem/<?= $problem['id'] ?>/manage/statement" role="tab">
|
||||
<a class="nav-link" href="/problem/<?= UOJProblem::info('id') ?>/manage/statement" role="tab">
|
||||
题面
|
||||
</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link active" href="/problem/<?= $problem['id'] ?>/manage/managers" role="tab">
|
||||
<a class="nav-link active" href="/problem/<?= UOJProblem::info('id') ?>/manage/managers" role="tab">
|
||||
管理者
|
||||
</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="/problem/<?= $problem['id'] ?>/manage/data" role="tab">
|
||||
<a class="nav-link" href="/problem/<?= UOJProblem::info('id') ?>/manage/data" role="tab">
|
||||
数据
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
</ul>
|
||||
|
||||
<div class="card card-default">
|
||||
<div class="card-body">
|
||||
<div class="card card-default">
|
||||
<div class="card-body">
|
||||
|
||||
<table class="table">
|
||||
<table class="table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>#</th>
|
||||
@ -101,50 +100,53 @@
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php
|
||||
<?php
|
||||
$row_id = 0;
|
||||
$result = DB::query("select username from problems_permissions where problem_id = ${problem['id']}");
|
||||
while ($row = DB::fetch($result, MYSQLI_ASSOC)) {
|
||||
$res = DB::selectAll([
|
||||
"select username from problems_permissions",
|
||||
"where", ["problem_id" => UOJProblem::info('id')]
|
||||
]);
|
||||
foreach ($res as $row) {
|
||||
$row_id++;
|
||||
echo '<tr>', '<td>', $row_id, '</td>', '<td>', getUserLink($row['username']), '</td>', '</tr>';
|
||||
}
|
||||
?>
|
||||
</tbody>
|
||||
</table>
|
||||
<p class="text-center">命令格式:命令一行一个,+mike表示把mike加入管理者,-mike表示把mike从管理者中移除</p>
|
||||
<?php $managers_form->printHTML(); ?>
|
||||
</table>
|
||||
<p class="text-center">命令格式:命令一行一个,+mike表示把mike加入管理者,-mike表示把mike从管理者中移除</p>
|
||||
<?php $managers_form->printHTML(); ?>
|
||||
|
||||
<?php if (isset($update_uploader_form)): ?>
|
||||
<hr>
|
||||
<?php if (isset($update_uploader_form)) : ?>
|
||||
<hr>
|
||||
|
||||
<?php $update_uploader_form->printHTML(); ?>
|
||||
<?php endif ?>
|
||||
<?php $update_uploader_form->printHTML(); ?>
|
||||
<?php endif ?>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- end left col -->
|
||||
</div>
|
||||
<!-- end left col -->
|
||||
</div>
|
||||
|
||||
<!-- right col -->
|
||||
<aside class="col-lg-3 mt-3 mt-lg-0">
|
||||
<!-- right col -->
|
||||
<aside class="col-lg-3 mt-3 mt-lg-0">
|
||||
|
||||
<div class="card card-default mb-2">
|
||||
<div class="card card-default mb-2">
|
||||
<ul class="nav nav-pills nav-fill flex-column" role="tablist">
|
||||
<li class="nav-item text-start">
|
||||
<a href="/problem/<?= $problem['id'] ?>" class="nav-link" role="tab">
|
||||
<a href="/problem/<?= UOJProblem::info('id') ?>" class="nav-link" role="tab">
|
||||
<i class="bi bi-journal-text"></i>
|
||||
<?= UOJLocale::get('problems::statement') ?>
|
||||
</a>
|
||||
</li>
|
||||
<li class="nav-item text-start">
|
||||
<a href="/problem/<?= $problem['id'] ?>/solutions" class="nav-link" role="tab">
|
||||
<a href="/problem/<?= UOJProblem::info('id') ?>/solutions" class="nav-link" role="tab">
|
||||
<i class="bi bi-journal-bookmark"></i>
|
||||
<?= UOJLocale::get('problems::solutions') ?>
|
||||
</a>
|
||||
</li>
|
||||
<li class="nav-item text-start">
|
||||
<a class="nav-link" href="/problem/<?= $problem['id'] ?>/statistics">
|
||||
<a class="nav-link" href="/problem/<?= UOJProblem::info('id') ?>/statistics">
|
||||
<i class="bi bi-graph-up"></i>
|
||||
<?= UOJLocale::get('problems::statistics') ?>
|
||||
</a>
|
||||
@ -157,13 +159,13 @@
|
||||
</li>
|
||||
</ul>
|
||||
<div class="card-footer bg-transparent">
|
||||
评价:<?= getClickZanBlock('P', $problem['id'], $problem['zan']) ?>
|
||||
评价:<?= ClickZans::getBlock('P', $problem['id'], $problem['zan']) ?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php uojIncludeView('sidebar', array()) ?>
|
||||
</aside>
|
||||
<!-- end right col -->
|
||||
<?php uojIncludeView('sidebar') ?>
|
||||
</aside>
|
||||
<!-- end right col -->
|
||||
|
||||
</div>
|
||||
|
||||
|
@ -1,26 +1,25 @@
|
||||
<?php
|
||||
requireLib('bootstrap5');
|
||||
requirePHPLib('form');
|
||||
requirePHPLib('judger');
|
||||
requirePHPLib('data');
|
||||
requireLib('bootstrap5');
|
||||
requirePHPLib('form');
|
||||
requirePHPLib('judger');
|
||||
requirePHPLib('data');
|
||||
|
||||
if (!Auth::check() && UOJConfig::$data['switch']['force-login']) {
|
||||
redirectToLogin();
|
||||
}
|
||||
Auth::check() || redirectToLogin();
|
||||
|
||||
if (!isNormalUser($myUser) && UOJConfig::$data['switch']['force-login']) {
|
||||
become403Page();
|
||||
}
|
||||
|
||||
|
||||
if (isSuperUser($myUser) || isProblemManager($myUser) || isProblemUploader($myUser)) {
|
||||
$new_problem_form = new UOJForm('new_problem');
|
||||
$new_problem_form->handle = function() {
|
||||
global $myUser;
|
||||
|
||||
DB::query("insert into problems (title, uploader, is_hidden, submission_requirement) values ('New Problem', '{$myUser['username']}', 1, '{}')");
|
||||
if (isSuperUser($myUser) || isProblemManager($myUser) || isProblemUploader($myUser)) {
|
||||
$new_problem_form = new UOJBs4Form('new_problem');
|
||||
$new_problem_form->handle = function () {
|
||||
DB::insert([
|
||||
"insert into problems",
|
||||
"(title, uploader, is_hidden, submission_requirement)",
|
||||
"values", DB::tuple(["New Problem", Auth::id(), 1, "{}"])
|
||||
]);
|
||||
$id = DB::insert_id();
|
||||
DB::query("insert into problems_contents (id, statement, statement_md) values ($id, '', '')");
|
||||
DB::insert([
|
||||
"insert into problems_contents",
|
||||
"(id, statement, statement_md)",
|
||||
"values", DB::tuple([$id, "", "## 题目描述\n\n## 输入格式\n\n## 输出格式\n\n## 输入输出样例\n\n### 输入样例 #1\n\n<!-- 请将样例用代码块包裹起来 -->\n\n### 输出样例 #1\n\n<!-- 请将样例用代码块包裹起来 -->\n\n### 样例解释 #1\n\n<!--\n后续添加样例时格式类似,如果声明大样例的话可以使用这种格式:\n\n### 样例 #2\n\n见右侧「附件下载」中的 `ex_data2.in/out`。\n\n-->\n\n## 数据范围与约定\n\n<!-- 数据范围与一些其他提示 -->\n"])
|
||||
]);
|
||||
dataNewProblem($id);
|
||||
};
|
||||
$new_problem_form->submit_button_config['align'] = 'right';
|
||||
@ -29,112 +28,115 @@
|
||||
$new_problem_form->submit_button_config['smart_confirm'] = '';
|
||||
|
||||
$new_problem_form->runAtServer();
|
||||
}
|
||||
}
|
||||
|
||||
function echoProblem($problem) {
|
||||
global $myUser;
|
||||
function getProblemTR($info) {
|
||||
$problem = new UOJProblem($info);
|
||||
|
||||
if (isProblemVisibleToUser($problem, $myUser)) {
|
||||
echo '<tr class="text-center">';
|
||||
if ($problem['submission_id']) {
|
||||
echo '<td class="table-success">';
|
||||
$html = '<tr class="text-center">';
|
||||
if ($info['submission_id']) {
|
||||
$html .= '<td class="table-success">';
|
||||
} else {
|
||||
echo '<td>';
|
||||
$html .= '<td>';
|
||||
}
|
||||
echo '#', $problem['id'], '</td>';
|
||||
|
||||
echo '<td class="text-start">';
|
||||
echo '<a class="text-decoration-none" href="/problem/', $problem['id'], '">', $problem['title'], '</a>';
|
||||
|
||||
if ($problem['uploader'] == $myUser['username']) {
|
||||
echo ' <span class="badge text-white bg-info">', UOJLocale::get('problems::my problem') ,'</span> ';
|
||||
$html .= "#{$info['id']}</td>";
|
||||
$html .= '<td class="text-start">';
|
||||
$html .= $problem->getLink(['with' => 'none']);
|
||||
if ($problem->isUserOwnProblem(Auth::user())) {
|
||||
$html .= ' <span class="badge text-white bg-info">' . UOJLocale::get('problems::my problem') . '</span> ';
|
||||
}
|
||||
|
||||
if ($problem['is_hidden']) {
|
||||
echo ' <span class="badge text-bg-danger"><i class="bi bi-eye-slash-fill"></i> ', UOJLocale::get('hidden'), '</span> ';
|
||||
if ($info['is_hidden']) {
|
||||
$html .= ' <span class="badge text-bg-danger"><i class="bi bi-eye-slash-fill"></i> ' . UOJLocale::get('hidden') . '</span> ';
|
||||
}
|
||||
|
||||
if (isset($_COOKIE['show_tags_mode'])) {
|
||||
foreach (queryProblemTags($problem['id']) as $tag) {
|
||||
echo ' <a class="uoj-problem-tag my-1">';
|
||||
echo '<span class="badge bg-secondary">';
|
||||
echo HTML::escape($tag), '</span>';
|
||||
echo '</a> ';
|
||||
foreach ($problem->queryTags() as $tag) {
|
||||
$html .= ' <a class="uoj-problem-tag">' . '<span class="badge bg-secondary">' . HTML::escape($tag) . '</span>' . '</a> ';
|
||||
}
|
||||
}
|
||||
echo '</td>';
|
||||
$html .= '</td>';
|
||||
if (isset($_COOKIE['show_submit_mode'])) {
|
||||
$perc = $problem['submit_num'] > 0 ? round(100 * $problem['ac_num'] / $problem['submit_num']) : 0;
|
||||
echo <<<EOD
|
||||
<td><a class="text-decoration-none" href="/submissions?problem_id={$problem['id']}&min_score=100&max_score=100">×{$problem['ac_num']}</a></td>
|
||||
<td><a class="text-decoration-none" href="/submissions?problem_id={$problem['id']}">×{$problem['submit_num']}</a></td>
|
||||
<td>
|
||||
<div class="progress bot-buffer-no">
|
||||
<div class="progress-bar progress-bar-success" role="progressbar" aria-valuenow="$perc" aria-valuemin="0" aria-valuemax="100" style="width: $perc%; min-width: 20px;">{$perc}%</div>
|
||||
</div>
|
||||
</td>
|
||||
EOD;
|
||||
}
|
||||
if (isset($_COOKIE['show_difficulty'])) {
|
||||
$extra_config = getProblemExtraConfig($problem);
|
||||
if ($extra_config['difficulty'] == 0) {
|
||||
echo "<td></td>";
|
||||
} else {
|
||||
echo "<td>{$extra_config['difficulty']}</td>";
|
||||
}
|
||||
}
|
||||
echo '<td class="text-start">', getClickZanBlock('P', $problem['id'], $problem['zan'], null, false), '</td>';
|
||||
echo '</tr>';
|
||||
}
|
||||
$perc = $info['submit_num'] > 0 ? round(100 * $info['ac_num'] / $info['submit_num']) : 0;
|
||||
$html .= '<td><a href="/submissions?problem_id=' . $info['id'] . '&min_score=100&max_score=100">×' . $info['ac_num'] . '</a></td>';
|
||||
$html .= '<td><a href="/submissions?problem_id=' . $info['id'] . '">×' . $info['submit_num'] . '</a></td>';
|
||||
$html .= '<td>';
|
||||
$html .= '<div class="progress bot-buffer-no">';
|
||||
$html .= '<div class="progress-bar progress-bar-success" role="progressbar" aria-valuenow="' . $perc . '" aria-valuemin="0" aria-valuemax="100" style="width: ' . $perc . '%; min-width: 20px;">';
|
||||
$html .= $perc . '%';
|
||||
$html .= '</div>';
|
||||
$html .= '</div>';
|
||||
$html .= '</td>';
|
||||
}
|
||||
$html .= '<td class="text-center">' . ClickZans::getCntBlock($problem->info['zan']) . '</td>';
|
||||
$html .= '</tr>';
|
||||
return $html;
|
||||
}
|
||||
|
||||
$cond = array();
|
||||
|
||||
$search_tag = null;
|
||||
|
||||
$cur_tab = isset($_GET['tab']) ? $_GET['tab'] : 'all';
|
||||
if ($cur_tab == 'template') {
|
||||
$cond = [];
|
||||
$search_tag = UOJRequest::get('tag', 'is_string', null);
|
||||
$search_content = UOJRequest::get('search', 'is_string', '');
|
||||
$search_is_effective = false;
|
||||
$cur_tab = UOJRequest::get('tab', 'is_string', 'all');
|
||||
if ($cur_tab == 'template') {
|
||||
$search_tag = "模板题";
|
||||
}
|
||||
if (is_string($search_tag)) {
|
||||
$cond[] = [
|
||||
DB::rawvalue($search_tag), "in", DB::rawbracket([
|
||||
"select tag from problems_tags",
|
||||
"where", ["problems_tags.problem_id" => DB::raw("problems.id")]
|
||||
])
|
||||
];
|
||||
}
|
||||
if ($search_content !== '') {
|
||||
foreach (explode(' ', $search_content) as $key) {
|
||||
if (strlen($key) > 0) {
|
||||
$cond[] = DB::lor([
|
||||
[DB::instr(DB::raw('title'), $key), '>', 0],
|
||||
DB::exists([
|
||||
"select tag from problems_tags",
|
||||
"where", [
|
||||
[DB::instr(DB::raw('tag'), $key), '>', 0],
|
||||
"problems_tags.problem_id" => DB::raw("problems.id")
|
||||
]
|
||||
]),
|
||||
"id" => $key,
|
||||
]);
|
||||
$search_is_effective = true;
|
||||
}
|
||||
if (isset($_GET['tag'])) {
|
||||
$search_tag = $_GET['tag'];
|
||||
}
|
||||
if ($search_tag) {
|
||||
$cond[] = "'".DB::escape($search_tag)."' in (select tag from problems_tags where problems_tags.problem_id = problems.id)";
|
||||
}
|
||||
if (isset($_GET["search"])) {
|
||||
$cond[]="(title like '%".DB::escape($_GET["search"])."%' or id like '%".DB::escape($_GET["search"])."%')";
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($_GET['is_hidden'])) {
|
||||
$cond[] = 'is_hidden = 1';
|
||||
}
|
||||
if (isset($_GET['is_hidden'])) {
|
||||
$cond[] = [
|
||||
'is_hidden' => '1',
|
||||
];
|
||||
}
|
||||
|
||||
if (Auth::check() && isset($_GET['my'])) {
|
||||
$cond[] = "uploader = '{$myUser['username']}'";
|
||||
}
|
||||
if (Auth::check() && isset($_GET['my'])) {
|
||||
$cond[] = [
|
||||
'uploader' => Auth::id(),
|
||||
];
|
||||
}
|
||||
|
||||
if ($cond) {
|
||||
$cond = join($cond, ' and ');
|
||||
} else {
|
||||
if (!$cond) {
|
||||
$cond = '1';
|
||||
}
|
||||
}
|
||||
|
||||
$header = '<tr>';
|
||||
$header .= '<th class="text-center" style="width:5em;">ID</th>';
|
||||
$header .= '<th>'.UOJLocale::get('problems::problem').'</th>';
|
||||
if (isset($_COOKIE['show_submit_mode'])) {
|
||||
$header .= '<th class="text-center" style="width:4em;">'.UOJLocale::get('problems::ac').'</th>';
|
||||
$header .= '<th class="text-center" style="width:4em;">'.UOJLocale::get('problems::submit').'</th>';
|
||||
$header .= '<th class="text-center" style="width:125px;">'.UOJLocale::get('problems::ac ratio').'</th>';
|
||||
}
|
||||
if (isset($_COOKIE['show_difficulty'])) {
|
||||
$header .= '<th class="text-center" style="width:3em;">'.UOJLocale::get('problems::difficulty').'</th>';
|
||||
}
|
||||
$header .= '<th class="text-center" style="width:100px;">'.UOJLocale::get('appraisal').'</th>';
|
||||
$header .= '</tr>';
|
||||
$header = '<tr>';
|
||||
$header .= '<th class="text-center" style="width:5em;">ID</th>';
|
||||
$header .= '<th>' . UOJLocale::get('problems::problem') . '</th>';
|
||||
if (isset($_COOKIE['show_submit_mode'])) {
|
||||
$header .= '<th class="text-center" style="width:4em;">' . UOJLocale::get('problems::ac') . '</th>';
|
||||
$header .= '<th class="text-center" style="width:4em;">' . UOJLocale::get('problems::submit') . '</th>';
|
||||
$header .= '<th class="text-center" style="width:125px;">' . UOJLocale::get('problems::ac ratio') . '</th>';
|
||||
}
|
||||
if (isset($_COOKIE['show_difficulty'])) {
|
||||
$header .= '<th class="text-center" style="width:3em;">' . UOJLocale::get('problems::difficulty') . '</th>';
|
||||
}
|
||||
$header .= '<th class="text-center" style="width:50px;">' . UOJLocale::get('appraisal') . '</th>';
|
||||
$header .= '</tr>';
|
||||
|
||||
$tabs_info = array(
|
||||
$tabs_info = array(
|
||||
'all' => array(
|
||||
'name' => UOJLocale::get('problems::all problems'),
|
||||
'url' => "/problems"
|
||||
@ -143,179 +145,193 @@ EOD;
|
||||
'name' => UOJLocale::get('problems::template problems'),
|
||||
'url' => "/problems/template"
|
||||
)
|
||||
);
|
||||
);
|
||||
|
||||
$pag_config = array('page_len' => 40);
|
||||
$pag_config['col_names'] = array('best_ac_submissions.submission_id as submission_id', 'problems.id as id', 'problems.is_hidden as is_hidden', 'problems.title as title', 'problems.submit_num as submit_num', 'problems.ac_num as ac_num', 'problems.zan as zan', 'problems.extra_config as extra_config', 'problems.uploader as uploader', 'problems.extra_config as extra_config');
|
||||
$pag_config['table_name'] = "problems left join best_ac_submissions on best_ac_submissions.submitter = '{$myUser['username']}' and problems.id = best_ac_submissions.problem_id";
|
||||
$pag_config['cond'] = $cond;
|
||||
$pag_config['tail'] = "order by id asc";
|
||||
$pag = new Paginator($pag_config);
|
||||
$pag = new Paginator([
|
||||
'col_names' => ['*'],
|
||||
'table_name' => [
|
||||
"problems left join best_ac_submissions",
|
||||
"on", [
|
||||
"best_ac_submissions.submitter" => Auth::id(),
|
||||
"problems.id" => DB::raw("best_ac_submissions.problem_id")
|
||||
],
|
||||
],
|
||||
'cond' => $cond,
|
||||
'tail' => "order by id asc",
|
||||
'page_len' => 40,
|
||||
'post_filter' => function ($problem) {
|
||||
return (new UOJProblem($problem))->userCanView(Auth::user());
|
||||
}
|
||||
]);
|
||||
|
||||
$div_classes = ['card', 'my-3', 'table-responsive'];
|
||||
$table_classes = ['table', 'uoj-table', 'mb-0'];
|
||||
?>
|
||||
// if ($search_is_effective) {
|
||||
// $search_summary = [
|
||||
// 'count_in_cur_page' => $pag->countInCurPage(),
|
||||
// 'first_a_few' => []
|
||||
// ];
|
||||
// foreach ($pag->get(5) as $info) {
|
||||
// $problem = new UOJProblem($info);
|
||||
// $search_summary['first_a_few'][] = [
|
||||
// 'type' => 'problem',
|
||||
// 'id' => $problem->info['id'],
|
||||
// 'title' => $problem->getTitle()
|
||||
// ];
|
||||
// }
|
||||
// DB::insert([
|
||||
// "insert into search_requests",
|
||||
// "(created_at, remote_addr, type, cache_id, q, content, result)",
|
||||
// "values", DB::tuple([DB::now(), UOJContext::remoteAddr(), 'search', 0, $search_content, UOJContext::requestURI(), json_encode($search_summary)])
|
||||
// ]);
|
||||
// }
|
||||
?>
|
||||
<?php echoUOJPageHeader(UOJLocale::get('problems')) ?>
|
||||
|
||||
<div class="row">
|
||||
|
||||
<!-- left col -->
|
||||
<div class="col-lg-9">
|
||||
<!-- left col -->
|
||||
<div class="col-lg-9">
|
||||
|
||||
<!-- title -->
|
||||
<div class="d-flex justify-content-between">
|
||||
<!-- title -->
|
||||
<div class="d-flex justify-content-between">
|
||||
|
||||
<h1 class="h2">
|
||||
<h1>
|
||||
<?= UOJLocale::get('problems') ?>
|
||||
</h1>
|
||||
</h1>
|
||||
|
||||
<?php if (isSuperUser($myUser) || isProblemManager($myUser) || isProblemUploader($myUser)): ?>
|
||||
<?php if (isSuperUser($myUser) || isProblemManager($myUser) || isProblemUploader($myUser)) : ?>
|
||||
<div class="text-end">
|
||||
<?php $new_problem_form->printHTML(); ?>
|
||||
</div>
|
||||
<?php endif ?>
|
||||
<?php endif ?>
|
||||
|
||||
</div>
|
||||
<!-- end title -->
|
||||
</div>
|
||||
<!-- end title -->
|
||||
|
||||
<div class="row">
|
||||
<div class="row">
|
||||
<div class="col-sm-4 col-12">
|
||||
<?= HTML::tablist($tabs_info, $cur_tab, 'nav-pills') ?>
|
||||
</div>
|
||||
<div class="text-end p-2 col-12 col-sm-8">
|
||||
<div class="form-check d-inline-block me-2">
|
||||
<input
|
||||
type="checkbox" id="input-show_tags_mode"
|
||||
class="form-check-input"
|
||||
<?= isset($_COOKIE['show_tags_mode']) ? 'checked="checked" ': ''?>
|
||||
/>
|
||||
<input type="checkbox" id="input-show_tags_mode" class="form-check-input" <?= isset($_COOKIE['show_tags_mode']) ? 'checked="checked" ' : '' ?> />
|
||||
<label class="form-check-label" for="input-show_tags_mode">
|
||||
<?= UOJLocale::get('problems::show tags') ?>
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<div class="form-check d-inline-block">
|
||||
<input
|
||||
type="checkbox" id="input-show_submit_mode"
|
||||
class="form-check-input"
|
||||
<?= isset($_COOKIE['show_submit_mode']) ? 'checked="checked" ': ''?>
|
||||
/>
|
||||
<input type="checkbox" id="input-show_submit_mode" class="form-check-input" <?= isset($_COOKIE['show_submit_mode']) ? 'checked="checked" ' : '' ?> />
|
||||
<label class="form-check-label" for="input-show_submit_mode">
|
||||
<?= UOJLocale::get('problems::show statistics') ?>
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<div class="form-check d-inline-block">
|
||||
<input
|
||||
type="checkbox" id="input-show_difficulty"
|
||||
class="form-check-input"
|
||||
<?= isset($_COOKIE['show_difficulty']) ? 'checked="checked" ': ''?>
|
||||
/>
|
||||
<input type="checkbox" id="input-show_difficulty" class="form-check-input" <?= isset($_COOKIE['show_difficulty']) ? 'checked="checked" ' : '' ?> />
|
||||
<label class="form-check-label" for="input-show_difficulty">
|
||||
<?= UOJLocale::get('problems::show difficulty') ?>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="text-center">
|
||||
<?= $pag->pagination() ?>
|
||||
</div>
|
||||
|
||||
<script type="text/javascript">
|
||||
$('#input-show_tags_mode').click(function() {
|
||||
<script type="text/javascript">
|
||||
$('#input-show_tags_mode').click(function() {
|
||||
if (this.checked) {
|
||||
$.cookie('show_tags_mode', '', {path: '/problems'});
|
||||
$.cookie('show_tags_mode', '', {
|
||||
path: '/problems'
|
||||
});
|
||||
} else {
|
||||
$.removeCookie('show_tags_mode', {path: '/problems'});
|
||||
$.removeCookie('show_tags_mode', {
|
||||
path: '/problems'
|
||||
});
|
||||
}
|
||||
location.reload();
|
||||
});
|
||||
$('#input-show_submit_mode').click(function() {
|
||||
});
|
||||
$('#input-show_submit_mode').click(function() {
|
||||
if (this.checked) {
|
||||
$.cookie('show_submit_mode', '', {path: '/problems'});
|
||||
$.cookie('show_submit_mode', '', {
|
||||
path: '/problems'
|
||||
});
|
||||
} else {
|
||||
$.removeCookie('show_submit_mode', {path: '/problems'});
|
||||
$.removeCookie('show_submit_mode', {
|
||||
path: '/problems'
|
||||
});
|
||||
}
|
||||
location.reload();
|
||||
});
|
||||
$('#input-show_difficulty').click(function() {
|
||||
});
|
||||
$('#input-show_difficulty').click(function() {
|
||||
if (this.checked) {
|
||||
$.cookie('show_difficulty', '', {path: '/'});
|
||||
$.cookie('show_difficulty', '', {
|
||||
path: '/'
|
||||
});
|
||||
} else {
|
||||
$.removeCookie('show_difficulty', {path: '/'});
|
||||
$.removeCookie('show_difficulty', {
|
||||
path: '/'
|
||||
});
|
||||
}
|
||||
location.reload();
|
||||
});
|
||||
</script>
|
||||
<div class="<?= join($div_classes, ' ') ?>">
|
||||
<table class="<?= join($table_classes, ' ') ?>">
|
||||
<thead><?= $header ?></thead>
|
||||
<tbody>
|
||||
<?php
|
||||
foreach ($pag->get() as $idx => $row) {
|
||||
echoProblem($row);
|
||||
echo "\n";
|
||||
}
|
||||
if ($pag->isEmpty()) {
|
||||
echo '<tr><td class="text-center" colspan="233">'.UOJLocale::get('none').'</td></tr>';
|
||||
});
|
||||
</script>
|
||||
|
||||
<div class="card my-3">
|
||||
<?=
|
||||
HTML::responsive_table($header, $pag->get(), [
|
||||
'table_attr' => [
|
||||
'class' => ['table', 'uoj-table', 'mb-0'],
|
||||
],
|
||||
'tr' => function ($row, $idx) {
|
||||
return getProblemTR($row);
|
||||
}
|
||||
]);
|
||||
?>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="text-center">
|
||||
<?= $pag->pagination() ?>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
<!-- end left col -->
|
||||
</div>
|
||||
<!-- end left col -->
|
||||
|
||||
<!-- right col -->
|
||||
<aside class="col-lg-3 mt-3 mt-lg-0">
|
||||
<!-- right col -->
|
||||
<aside class="col-lg-3 mt-3 mt-lg-0">
|
||||
|
||||
<!-- search bar -->
|
||||
<form method="get" class="mb-3" id="form-problem_search">
|
||||
<!-- search bar -->
|
||||
<form method="get" class="mb-3" id="form-problem_search">
|
||||
<div class="input-group mb-3">
|
||||
<input id="search-input" name="search" type="text" class="form-control" placeholder="搜索">
|
||||
<button class="btn btn-outline-secondary" type="submit">
|
||||
<i class="bi bi-search"></i>
|
||||
</button>
|
||||
</div>
|
||||
<?php if (Auth::check()): ?>
|
||||
<?php if (Auth::check()) : ?>
|
||||
<div class="form-check d-inline-block">
|
||||
<input
|
||||
type="checkbox" name="my"
|
||||
<?= isset($_GET['my']) ? 'checked="checked"' : '' ?>
|
||||
class="form-check-input" id="input-my">
|
||||
<input type="checkbox" name="my" <?= isset($_GET['my']) ? 'checked="checked"' : '' ?> class="form-check-input" id="input-my">
|
||||
<label class="form-check-label" for="input-my">
|
||||
我的题目
|
||||
</label>
|
||||
</div>
|
||||
<?php endif ?>
|
||||
<?php if (isProblemManager(Auth::user())): ?>
|
||||
<?php if (isProblemManager(Auth::user())) : ?>
|
||||
<div class="form-check d-inline-block ms-2">
|
||||
<input
|
||||
type="checkbox" name="is_hidden"
|
||||
<?= isset($_GET['is_hidden']) ? 'checked="checked"' : '' ?>
|
||||
class="form-check-input" id="input-is_hidden">
|
||||
<input type="checkbox" name="is_hidden" <?= isset($_GET['is_hidden']) ? 'checked="checked"' : '' ?> class="form-check-input" id="input-is_hidden">
|
||||
<label class="form-check-label" for="input-is_hidden">
|
||||
隐藏题目
|
||||
</label>
|
||||
</div>
|
||||
<?php endif ?>
|
||||
</form>
|
||||
<script>
|
||||
</form>
|
||||
<script>
|
||||
$('#search-input').val(new URLSearchParams(location.search).get('search'));
|
||||
$('#input-my, #input-is_hidden').click(function() {
|
||||
$('#form-problem_search').submit();
|
||||
});
|
||||
</script>
|
||||
</script>
|
||||
|
||||
<!-- sidebar -->
|
||||
<?php uojIncludeView('sidebar', []) ?>
|
||||
</aside>
|
||||
<!-- sidebar -->
|
||||
<?php uojIncludeView('sidebar') ?>
|
||||
</aside>
|
||||
|
||||
</div>
|
||||
|
||||
|
@ -1,105 +1,73 @@
|
||||
<?php
|
||||
requireLib('bootstrap5');
|
||||
requireLib('hljs');
|
||||
requireLib('mathjax');
|
||||
requirePHPLib('form');
|
||||
requirePHPLib('judger');
|
||||
requireLib('bootstrap5');
|
||||
requireLib('hljs');
|
||||
requireLib('mathjax');
|
||||
requirePHPLib('form');
|
||||
requirePHPLib('judger');
|
||||
|
||||
if (!Auth::check() && UOJConfig::$data['switch']['force-login']) {
|
||||
redirectToLogin();
|
||||
Auth::check() || redirectToLogin();
|
||||
UOJProblem::init(UOJRequest::get('id')) || UOJResponse::page404();
|
||||
UOJProblem::cur()->userCanView(Auth::user()) || UOJResponse::page403();
|
||||
|
||||
if (!UOJProblem::cur()->userCanManage(Auth::user())) {
|
||||
UOJProblem::cur()->userPermissionCodeCheck(Auth::user(), UOJProblem::cur()->getExtraConfig('view_solution_type')) || UOJResponse::page403();
|
||||
|
||||
foreach (UOJProblem::cur()->findInContests() as $cp) {
|
||||
if ($cp->contest->progress() == CONTEST_IN_PROGRESS && $cp->contest->userHasRegistered(Auth::user())) {
|
||||
UOJResponse::page403();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (UOJRequest::post('submit-remove_solution') === 'remove_solution') {
|
||||
crsf_defend();
|
||||
|
||||
$blog = UOJBlog::query(UOJRequest::post('blog_id'));
|
||||
|
||||
if (!$blog || !$blog->userCanView(Auth::user())) {
|
||||
dieWithAlert('博客不存在。');
|
||||
}
|
||||
|
||||
if (!isNormalUser($myUser) && UOJConfig::$data['switch']['force-login']) {
|
||||
become403Page();
|
||||
if (!UOJProblem::cur()->userCanManage(Auth::user()) && $blog->info['poster'] != Auth::id()) {
|
||||
dieWithAlert('您没有权限移除该题解。');
|
||||
}
|
||||
|
||||
if (!validateUInt($_GET['id']) || !($problem = queryProblemBrief($_GET['id']))) {
|
||||
become404Page();
|
||||
if ($blog->info['poster'] != Auth::id()) {
|
||||
sendSystemMsg(
|
||||
$blog->info['poster'],
|
||||
'题解移除通知',
|
||||
"<p>" . UOJUser::getLink($blog->info['poster']) . " 您好:</p>" .
|
||||
"<p>您为问题 " . UOJProblem::cur()->getLink(['with' => 'id']) . " 提交的题解 " . $blog->getLink() . " 已被" . (isSuperUser(Auth::user()) ? "管理员" : " " . UOJUser::getLink(Auth::user()) . " ") . "移除。</p>"
|
||||
);
|
||||
}
|
||||
|
||||
if (!isProblemVisibleToUser($problem, $myUser)) {
|
||||
become404Page();
|
||||
}
|
||||
DB::delete([
|
||||
"delete from problems_solutions",
|
||||
"where", [
|
||||
"problem_id" => UOJProblem::info('id'),
|
||||
"blog_id" => $blog->info['id'],
|
||||
],
|
||||
]);
|
||||
|
||||
$problem_extra_config = getProblemExtraConfig($problem);
|
||||
$solution_viewable = hasViewSolutionPermission($problem_extra_config['view_solution_type'], $myUser, $problem);
|
||||
$solution_submittable = hasViewSolutionPermission($problem_extra_config['submit_solution_type'], $myUser, $problem);
|
||||
dieWithAlert('移除成功!');
|
||||
}
|
||||
|
||||
if (!$solution_viewable) {
|
||||
become403Page();
|
||||
}
|
||||
|
||||
if (!hasProblemPermission($myUser, $problem) && isRegisteredRunningContestProblem($myUser, $problem)) {
|
||||
become403Page();
|
||||
}
|
||||
|
||||
function removeSolutionForm($blog_id) {
|
||||
$res_form = new UOJForm("remove_solution_{$blog_id}");
|
||||
$res_form->addHidden("blog_id", $blog_id, function($blog_id) {
|
||||
global $myUser, $problem;
|
||||
|
||||
if (!validateUInt($blog_id)) {
|
||||
return '博客 ID 不是有效的数字';
|
||||
}
|
||||
|
||||
$blog = queryBlog($blog_id);
|
||||
if (UOJProblem::cur()->userCanManage(Auth::user()) || UOJProblem::cur()->userPermissionCodeCheck(Auth::user(), UOJProblem::cur()->getExtraConfig('submit_solution_type'))) {
|
||||
$add_new_solution_form = new UOJBs4Form('add_new_solution');
|
||||
$add_new_solution_form->addVInput(
|
||||
'blog_id_2',
|
||||
'text',
|
||||
'博客 ID',
|
||||
'',
|
||||
function ($blog_id) {
|
||||
$blog = UOJBlog::query($blog_id);
|
||||
if (!$blog) {
|
||||
return '博客不存在';
|
||||
}
|
||||
|
||||
if (!hasProblemPermission($myUser, $problem)) {
|
||||
if ($blog['poster'] != $myUser['username']) {
|
||||
return '您只能删除自己的题解';
|
||||
}
|
||||
}
|
||||
|
||||
return '';
|
||||
}, null);
|
||||
$res_form->handle = function() {
|
||||
global $myUser, $problem;
|
||||
|
||||
$blog_id = $_POST["blog_id"];
|
||||
DB::query("delete from problems_solutions where problem_id = {$problem['id']} and blog_id = {$blog_id}");
|
||||
$blog = queryBlog($blog_id);
|
||||
|
||||
if ($blog['poster'] != $myUser['username']) {
|
||||
$blog_link = getBlogLink($blog['id']);
|
||||
$poster_user_link = getUserLink($blog['poster']);
|
||||
$admin_user_link = isSuperUser($myUser) ? '管理员' : getUserLink($myUser['username']);
|
||||
$content = <<<EOD
|
||||
<p>{$poster_user_link} 您好:</p>
|
||||
<p>您为问题 <a href="/problem/{$problem['id']}">#{$problem['id']} ({$problem['title']})</a> 提交的题解 {$blog_link} 已经被 {$admin_user_link} 移除。 </p>
|
||||
EOD;
|
||||
sendSystemMsg($blog['poster'], '题解移除通知', $content);
|
||||
}
|
||||
};
|
||||
$res_form->submit_button_config['margin_class'] = 'mt-0';
|
||||
$res_form->submit_button_config['class_str'] = 'btn btn-link text-decoration-none text-danger p-0';
|
||||
$res_form->submit_button_config['text'] = '移除';
|
||||
$res_form->submit_button_config['confirm_text'] = '你真的要移除这篇题解吗?';
|
||||
$res_form->submit_button_config['align'] = 'inline';
|
||||
|
||||
return $res_form;
|
||||
}
|
||||
|
||||
if ($solution_submittable) {
|
||||
$add_new_solution_form = new UOJForm('add_new_solution');
|
||||
$add_new_solution_form->addVInput('blog_id_2', 'text', '博客 ID', '',
|
||||
function ($x) {
|
||||
global $myUser, $problem, $solution_submittable;
|
||||
|
||||
if (!validateUInt($x)) {
|
||||
return 'ID 不合法';
|
||||
}
|
||||
|
||||
$blog = queryBlog($x);
|
||||
if (!$blog) {
|
||||
return '博客不存在';
|
||||
}
|
||||
|
||||
if (!isSuperUser($myUser)) {
|
||||
if ($blog['poster'] != $myUser['username']) {
|
||||
if ($blog['is_hidden']) {
|
||||
if (!$blog->userCanManage(Auth::user())) {
|
||||
if ($blog->info['poster'] != Auth::id()) {
|
||||
if ($blog->info['is_hidden']) {
|
||||
return '博客不存在';
|
||||
}
|
||||
|
||||
@ -107,93 +75,82 @@ EOD;
|
||||
}
|
||||
}
|
||||
|
||||
if (!hasProblemPermission($myUser, $problem)) {
|
||||
if ($blog['is_hidden']) {
|
||||
if (!UOJProblem::cur()->userCanManage(Auth::user())) {
|
||||
if ($blog->info['is_hidden']) {
|
||||
return '只能提交公开的博客';
|
||||
}
|
||||
}
|
||||
|
||||
if (querySolution($problem['id'], $x)) {
|
||||
if (querySolution(UOJProblem::info('id'), $blog_id)) {
|
||||
return '该题解已提交';
|
||||
}
|
||||
|
||||
if (!$solution_submittable) {
|
||||
return '您无权提交题解';
|
||||
}
|
||||
|
||||
return '';
|
||||
},
|
||||
null
|
||||
);
|
||||
$add_new_solution_form->submit_button_config['text'] = '发布';
|
||||
$add_new_solution_form->submit_button_config['align'] = 'center';
|
||||
$add_new_solution_form->handle = function() {
|
||||
global $problem, $myUser;
|
||||
|
||||
$blog_id_2 = $_POST['blog_id_2'];
|
||||
$problem_id = $problem['id'];
|
||||
|
||||
DB::insert("insert into problems_solutions (problem_id, blog_id) values ({$problem_id}, {$blog_id_2})");
|
||||
$add_new_solution_form->submit_button_config['class_str'] = 'btn btn-secondary';
|
||||
$add_new_solution_form->handle = function () {
|
||||
DB::insert([
|
||||
"insert into problems_solutions",
|
||||
DB::bracketed_fields(["problem_id", "blog_id"]),
|
||||
"values", DB::tuple([UOJProblem::info('id'), $_POST['blog_id_2']]),
|
||||
]);
|
||||
};
|
||||
$add_new_solution_form->runAtServer();
|
||||
}
|
||||
}
|
||||
|
||||
$pag_config = array('page_len' => 5);
|
||||
$pag_config['col_names'] = array('blog_id', 'content', 'poster', 'post_time', 'zan', 'is_hidden');
|
||||
$pag_config['table_name'] = "problems_solutions inner join blogs on problems_solutions.blog_id = blogs.id";
|
||||
$pag_config['cond'] = "problem_id = {$problem['id']}";
|
||||
$pag_config = [
|
||||
'page_len' => 5,
|
||||
'col_names' => ['blog_id', 'zan'],
|
||||
'table_name' => 'problems_solutions inner join blogs on blogs.id = problems_solutions.blog_id',
|
||||
'cond' => ["problem_id" => UOJProblem::info('id')],
|
||||
'post_filter' => function ($row) {
|
||||
$blog = UOJBlog::query($row['blog_id']);
|
||||
|
||||
// 根据实际使用需要,题目管理员可以通过题解页面看到其他用户提交的题解,并且即使该题解对应的博客是隐藏状态也会照常显示
|
||||
// 如需仅允许超级管理员查看,请将下一行中 if 语句的条件改为 (!isSuperUser($myUser))
|
||||
if (!hasProblemPermission($myUser, $problem)) {
|
||||
$pag_config['cond'] .= " and (is_hidden = 0 or poster = '{$myUser['username']}')";
|
||||
}
|
||||
// 如需仅允许超级管理员查看,请将下一行改为 return $blog->userCanView(Auth::user());
|
||||
return $blog->userCanView(Auth::user()) || UOJProblem::cur()->userCanManage(Auth::user());
|
||||
},
|
||||
];
|
||||
|
||||
$pag_config['tail'] = "order by zan desc, post_time desc, id asc";
|
||||
$pag = new Paginator($pag_config);
|
||||
|
||||
$rows = [];
|
||||
|
||||
foreach ($pag->get() as $idx => $row) {
|
||||
$rows[$idx] = $row;
|
||||
if ($row['poster'] == $myUser['username'] || hasProblemPermission($myUser, $problem)) {
|
||||
$removeForm = removeSolutionForm($row['blog_id']);
|
||||
$removeForm->runAtServer();
|
||||
$rows[$idx]['removeForm'] = $removeForm;
|
||||
}
|
||||
}
|
||||
?>
|
||||
$pag_config['tail'] = "order by zan desc, post_time desc, id asc";
|
||||
$pag = new Paginator($pag_config);
|
||||
?>
|
||||
|
||||
<?php echoUOJPageHeader(UOJLocale::get('problems::solutions') . ' - ' . HTML::stripTags($problem['title'])) ?>
|
||||
|
||||
<div class="row">
|
||||
|
||||
<!-- Left col -->
|
||||
<div class="col-lg-9">
|
||||
|
||||
<div class="card card-default mb-2">
|
||||
<!-- Left col -->
|
||||
<div class="col-lg-9">
|
||||
<div class="card card-default mb-2">
|
||||
<div class="card-body">
|
||||
<h1 class="h2 card-title text-center">
|
||||
#<?= $problem['id']?>. <?= $problem['title'] ?>
|
||||
<h1 class="card-title text-center">
|
||||
<?= UOJProblem::cur()->getTitle(['with' => 'id']) ?>
|
||||
</h1>
|
||||
</div>
|
||||
|
||||
<ul class="list-group list-group-flush">
|
||||
<?php foreach ($rows as $row): ?>
|
||||
<?php foreach ($pag->get() as $row) : ?>
|
||||
<?php
|
||||
$blog = UOJBlog::query($row['blog_id']);
|
||||
$poster = UOJUser::query($blog->info['poster']);
|
||||
?>
|
||||
<li class="list-group-item">
|
||||
<?php $poster = queryUser($row['poster']); ?>
|
||||
<div class="mb-3">
|
||||
<span class="me-2 d-inline-block">
|
||||
<a class="text-decoration-none" href="<?= HTML::url('/user/'.$poster['username']) ?>">
|
||||
<a class="text-decoration-none" href="<?= HTML::url('/user/' . $poster['username']) ?>">
|
||||
<img src="<?= HTML::avatar_addr($poster, 64) ?>" width="32" height="32" class="rounded" />
|
||||
</a>
|
||||
<?= getUserLink($poster['username']) ?>
|
||||
<?= UOJUser::getLink($poster) ?>
|
||||
</span>
|
||||
<span class="text-muted small d-inline-block">
|
||||
<?= UOJLocale::get('post time') ?>:
|
||||
<time class="text-muted"><?= $row['post_time'] ?></time>
|
||||
<time class="text-muted"><?= $blog->info['post_time'] ?></time>
|
||||
</span>
|
||||
<?php if ($row['is_hidden']): ?>
|
||||
<?php if ($blog->info['is_hidden']) : ?>
|
||||
<span class="badge text-bg-danger ms-2">
|
||||
<i class="bi bi-eye-slash-fill"></i>
|
||||
<?= UOJLocale::get('hidden') ?>
|
||||
@ -202,51 +159,60 @@ EOD;
|
||||
</div>
|
||||
|
||||
<div class="markdown-body">
|
||||
<?= $row['content'] ?>
|
||||
<?= $blog->queryContent()['content'] ?>
|
||||
</div>
|
||||
|
||||
<ul class="mt-3 text-end list-inline">
|
||||
<?php if (isset($row['removeForm'])): ?>
|
||||
<?php if (UOJProblem::cur()->userCanManage(Auth::user()) || $poster['username'] == Auth::id()) : ?>
|
||||
<li class="list-inline-item">
|
||||
<?php $row['removeForm']->printHTML(); ?>
|
||||
<form class="d-inline-block" method="POST" onsubmit="return confirm('你真的要移除这篇题解吗?移除题解不会删除对应博客。')">
|
||||
<input type="hidden" name="_token" value="<?= crsf_token() ?>">
|
||||
<input type="hidden" name="blog_id" value="<?= $blog->info['id'] ?>">
|
||||
<button class="btn btn-link text-decoration-none text-danger p-0 mt-0" type="submit" name="submit-remove_solution" value="remove_solution">
|
||||
移除
|
||||
</button>
|
||||
</form>
|
||||
</li>
|
||||
<?php endif ?>
|
||||
<?php if (Auth::check() && (isSuperUser(Auth::user()) || Auth::id() == $row['poster'])): ?>
|
||||
<?php if ($blog->userCanManage(Auth::user())) : ?>
|
||||
<li class="list-inline-item">
|
||||
<a class="text-decoration-none" href="<?= HTML::blog_url($row['poster'], '/post/'.$row['blog_id'].'/write') ?>">
|
||||
<a class="d-inline-block align-middle" href="<?= $blog->getUriForWrite() ?>">
|
||||
修改
|
||||
</a>
|
||||
</li>
|
||||
<?php endif ?>
|
||||
<li class="list-inline-item">
|
||||
<a class="text-decoration-none" href="/blogs/<?= $row['blog_id'] ?>">在 Ta 的博客上查看</a>
|
||||
<a class="d-inline-block align-middle" href="<?= $blog->getBlogUri() ?>">
|
||||
在 Ta 的博客上查看
|
||||
</a>
|
||||
</li>
|
||||
<li class="list-inline-item">
|
||||
<?= getClickZanBlock('B', $row['blog_id'], $row['zan']) ?>
|
||||
<?= ClickZans::getBlock('B', $blog->info['id'], $blog->info['zan']) ?>
|
||||
</li>
|
||||
</ul>
|
||||
</li>
|
||||
<?php endforeach ?>
|
||||
<?php if ($pag->isEmpty()): ?>
|
||||
<div class="text-center py-2">
|
||||
<?php if ($pag->isEmpty()) : ?>
|
||||
<div class="text-center text-muted py-4">
|
||||
暂无题解
|
||||
</div>
|
||||
<?php endif ?>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Pagination -->
|
||||
<?= $pag->pagination() ?>
|
||||
<!-- Pagination -->
|
||||
<?= $pag->pagination() ?>
|
||||
|
||||
<!-- End left col -->
|
||||
</div>
|
||||
</div>
|
||||
<!-- End left col -->
|
||||
|
||||
<!-- Right col -->
|
||||
<aside class="col-lg-3 mt-3 mt-lg-0">
|
||||
<!-- Right col -->
|
||||
<aside class="col-lg-3 mt-3 mt-lg-0">
|
||||
|
||||
<div class="card card-default mb-2">
|
||||
<div class="card card-default mb-2">
|
||||
<ul class="nav nav-pills nav-fill flex-column" role="tablist">
|
||||
<li class="nav-item text-start">
|
||||
<a href="/problem/<?= $problem['id'] ?>" class="nav-link" role="tab">
|
||||
<a href="/problem/<?= UOJProblem::info('id') ?>" class="nav-link" role="tab">
|
||||
<i class="bi bi-journal-text"></i>
|
||||
<?= UOJLocale::get('problems::statement') ?>
|
||||
</a>
|
||||
@ -258,14 +224,14 @@ EOD;
|
||||
</a>
|
||||
</li>
|
||||
<li class="nav-item text-start">
|
||||
<a class="nav-link" href="/problem/<?= $problem['id'] ?>/statistics">
|
||||
<a class="nav-link" href="/problem/<?= UOJProblem::info('id') ?>/statistics">
|
||||
<i class="bi bi-graph-up"></i>
|
||||
<?= UOJLocale::get('problems::statistics') ?>
|
||||
</a>
|
||||
</li>
|
||||
<?php if (hasProblemPermission($myUser, $problem)): ?>
|
||||
<?php if (UOJProblem::cur()->userCanManage(Auth::user())) : ?>
|
||||
<li class="nav-item text-start">
|
||||
<a class="nav-link" href="/problem/<?= $problem['id'] ?>/manage/statement" role="tab">
|
||||
<a class="nav-link" href="/problem/<?= UOJProblem::info('id') ?>/manage/statement" role="tab">
|
||||
<i class="bi bi-sliders"></i>
|
||||
<?= UOJLocale::get('problems::manage') ?>
|
||||
</a>
|
||||
@ -273,33 +239,32 @@ EOD;
|
||||
<?php endif ?>
|
||||
</ul>
|
||||
<div class="card-footer bg-transparent">
|
||||
评价:<?= getClickZanBlock('P', $problem['id'], $problem['zan']) ?>
|
||||
评价:<?= ClickZans::getBlock('P', UOJProblem::info('id'), UOJProblem::info('zan')) ?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="card card-default mb-2">
|
||||
<div class="card card-default mb-2">
|
||||
<div class="card-header bg-transparent fw-bold">
|
||||
增加题解
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<?php if (isset($add_new_solution_form)): ?>
|
||||
<?php if (isset($add_new_solution_form)) : ?>
|
||||
<?php $add_new_solution_form->printHTML(); ?>
|
||||
<?php else: ?>
|
||||
<?php else : ?>
|
||||
您当前无法为本题新增题解。
|
||||
<?php endif ?>
|
||||
</div>
|
||||
<div class="card-footer bg-transparent">
|
||||
<a target="_blank" class="text-decoration-none" href="<?= HTML::blog_url(Auth::id(), '/post/new/write?title=' . urlencode('【题解】#' . $problem['id'] . '. ' . $problem['title']) . '&is_hidden=0&add_solution_for=' . $problem['id']) ?>">
|
||||
<a target="_blank" class="text-decoration-none" href="<?= HTML::blog_url(Auth::id(), '/post/new/write?title=' . urlencode('【题解】#' . UOJProblem::info('id') . '. ' . UOJProblem::info('title')) . '&is_hidden=0') ?>">
|
||||
快速新建文章
|
||||
</a>
|
||||
<div class="small text-muted mt-1">发布文章后,请返回本页输入博客 ID</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php uojIncludeView('sidebar', array()); ?>
|
||||
|
||||
<!-- End right col -->
|
||||
</aside>
|
||||
<?php uojIncludeView('sidebar'); ?>
|
||||
<!-- End right col -->
|
||||
</aside>
|
||||
|
||||
</div>
|
||||
|
||||
|
@ -1,94 +1,106 @@
|
||||
<?php
|
||||
requireLib('bootstrap5');
|
||||
requirePHPLib('form');
|
||||
requireLib('bootstrap5');
|
||||
requirePHPLib('form');
|
||||
|
||||
if (!Auth::check() && UOJConfig::$data['switch']['force-login']) {
|
||||
redirectToLogin();
|
||||
}
|
||||
Auth::check() || redirectToLogin();
|
||||
|
||||
if (!validateUInt($_GET['id']) || !($problem = queryProblemBrief($_GET['id']))) {
|
||||
become404Page();
|
||||
}
|
||||
if (!hasProblemPermission($myUser, $problem)) {
|
||||
become403Page();
|
||||
}
|
||||
UOJProblem::init(UOJRequest::get('id')) || UOJResponse::page404();
|
||||
UOJProblem::cur()->userCanManage(Auth::user()) || UOJResponse::page403();
|
||||
$problem_content = UOJProblem::cur()->queryContent();
|
||||
|
||||
$problem_content = queryProblemContent($problem['id']);
|
||||
$problem_tags = queryProblemTags($problem['id']);
|
||||
|
||||
$problem_editor = new UOJBlogEditor();
|
||||
$problem_editor->name = 'problem';
|
||||
$problem_editor->blog_url = "/problem/{$problem['id']}";
|
||||
$problem_editor->cur_data = array(
|
||||
'title' => $problem['title'],
|
||||
$problem_editor = new UOJBlogEditor();
|
||||
$problem_editor->name = 'problem';
|
||||
$problem_editor->blog_url = '/problem/' . UOJProblem::info('id');
|
||||
$problem_editor->cur_data = [
|
||||
'title' => UOJProblem::info('title'),
|
||||
'content_md' => $problem_content['statement_md'],
|
||||
'content' => $problem_content['statement'],
|
||||
'tags' => $problem_tags,
|
||||
'is_hidden' => $problem['is_hidden']
|
||||
);
|
||||
$problem_editor->label_text = array_merge($problem_editor->label_text, array(
|
||||
'tags' => UOJProblem::cur()->queryTags(),
|
||||
'is_hidden' => UOJProblem::info('is_hidden')
|
||||
];
|
||||
$problem_editor->label_text = array_merge($problem_editor->label_text, [
|
||||
'view blog' => '查看题目',
|
||||
'blog visibility' => '题目可见性'
|
||||
));
|
||||
]);
|
||||
|
||||
$problem_editor->save = function($data) {
|
||||
global $problem, $problem_tags;
|
||||
DB::update("update problems set title = '".DB::escape($data['title'])."' where id = {$problem['id']}");
|
||||
DB::update("update problems_contents set statement = '".DB::escape($data['content'])."', statement_md = '".DB::escape($data['content_md'])."' where id = {$problem['id']}");
|
||||
$problem_editor->save = function ($data) {
|
||||
DB::update([
|
||||
"update problems",
|
||||
"set", ["title" => $data['title']],
|
||||
"where", ["id" => UOJProblem::info('id')]
|
||||
]);
|
||||
|
||||
if ($data['tags'] !== $problem_tags) {
|
||||
DB::delete("delete from problems_tags where problem_id = {$problem['id']}");
|
||||
foreach ($data['tags'] as $tag) {
|
||||
DB::insert("insert into problems_tags (problem_id, tag) values ({$problem['id']}, '".DB::escape($tag)."')");
|
||||
}
|
||||
}
|
||||
if ($data['is_hidden'] != $problem['is_hidden'] ) {
|
||||
DB::update("update problems set is_hidden = {$data['is_hidden']} where id = {$problem['id']}");
|
||||
DB::update("update submissions set is_hidden = {$data['is_hidden']} where problem_id = {$problem['id']}");
|
||||
DB::update("update hacks set is_hidden = {$data['is_hidden']} where problem_id = {$problem['id']}");
|
||||
}
|
||||
};
|
||||
DB::update([
|
||||
"update problems_contents",
|
||||
"set", [
|
||||
"statement" => $data['content'],
|
||||
"statement_md" => $data['content_md']
|
||||
], "where", ["id" => UOJProblem::info('id')]
|
||||
]);
|
||||
|
||||
$problem_editor->runAtServer();
|
||||
?>
|
||||
<?php echoUOJPageHeader(HTML::stripTags($problem['title']) . ' - 编辑 - 题目管理') ?>
|
||||
UOJProblem::cur()->updateTags($data['tags']);
|
||||
|
||||
if ($data['is_hidden'] != UOJProblem::info('is_hidden')) {
|
||||
DB::update([
|
||||
"update problems",
|
||||
"set", ["is_hidden" => $data['is_hidden']],
|
||||
"where", ["id" => UOJProblem::info('id')]
|
||||
]);
|
||||
|
||||
DB::update([
|
||||
"update submissions",
|
||||
"set", ["is_hidden" => $data['is_hidden']],
|
||||
"where", ["problem_id" => UOJProblem::info('id')]
|
||||
]);
|
||||
|
||||
DB::update([
|
||||
"update hacks",
|
||||
"set", ["is_hidden" => $data['is_hidden']],
|
||||
"where", ["problem_id" => UOJProblem::info('id')]
|
||||
]);
|
||||
}
|
||||
};
|
||||
|
||||
$problem_editor->runAtServer();
|
||||
?>
|
||||
|
||||
<?php echoUOJPageHeader('题面编辑 - ' . HTML::stripTags(UOJProblem::info('title'))) ?>
|
||||
|
||||
<div class="row">
|
||||
<!-- left col -->
|
||||
<div class="col-lg-9">
|
||||
<!-- left col -->
|
||||
<div class="col-lg-9">
|
||||
<h1>
|
||||
<?= UOJProblem::cur()->getTitle(['with' => 'id']) ?> 管理
|
||||
</h1>
|
||||
|
||||
<h1 class="h2">
|
||||
#<?=$problem['id']?>. <?=$problem['title']?> 管理
|
||||
</h1>
|
||||
|
||||
<ul class="nav nav-pills my-3" role="tablist">
|
||||
<ul class="nav nav-pills my-3" role="tablist">
|
||||
<li class="nav-item">
|
||||
<a class="nav-link active" href="/problem/<?= $problem['id'] ?>/manage/statement" role="tab">
|
||||
<a class="nav-link active" href="/problem/<?= UOJProblem::info('id') ?>/manage/statement" role="tab">
|
||||
题面
|
||||
</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="/problem/<?= $problem['id'] ?>/manage/managers" role="tab">
|
||||
<a class="nav-link" href="/problem/<?= UOJProblem::info('id') ?>/manage/managers" role="tab">
|
||||
管理者
|
||||
</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="/problem/<?= $problem['id'] ?>/manage/data" role="tab">
|
||||
<a class="nav-link" href="/problem/<?= UOJProblem::info('id') ?>/manage/data" role="tab">
|
||||
数据
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
</ul>
|
||||
|
||||
<div class="card card-default">
|
||||
<div class="card-body">
|
||||
<?php $problem_editor->printHTML() ?>
|
||||
</div>
|
||||
</div>
|
||||
<div class="card card-default">
|
||||
<div class="card-body">
|
||||
<?php $problem_editor->printHTML() ?>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 提示信息 -->
|
||||
<div class="card mt-3">
|
||||
<div class="card-body">
|
||||
<h2 class="h4 card-title">提示</h2>
|
||||
<!-- 提示信息 -->
|
||||
<div class="card mt-3">
|
||||
<div class="card-body">
|
||||
<h2 class="h3 card-title">提示</h2>
|
||||
<ol>
|
||||
<li>请勿引用不稳定的外部资源(如来自个人服务器的图片或文档等),以便备份及后期维护;</li>
|
||||
<li>请勿在题面中直接插入大段 HTML 代码,这可能会破坏页面的显示,可以考虑使用 <a class="text-decoration-none" href="/html2markdown" target="_blank">转换工具</a> 转换后再作修正;</li>
|
||||
@ -97,30 +109,28 @@
|
||||
<p class="card-text">
|
||||
更多内容请查看 S2OJ 用户手册中的「<a class="text-decoration-none" href="https://s2oj.github.io/#/manage/problem?id=%e4%bc%a0%e9%a2%98%e6%8c%87%e5%bc%95">传题指引</a>」部分。
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<!-- right col -->
|
||||
<aside class="col-lg-3 mt-3 mt-lg-0">
|
||||
|
||||
<div class="card card-default mb-2">
|
||||
<!-- right col -->
|
||||
<aside class="col-lg-3 mt-3 mt-lg-0">
|
||||
<div class="card card-default mb-2">
|
||||
<ul class="nav nav-pills nav-fill flex-column" role="tablist">
|
||||
<li class="nav-item text-start">
|
||||
<a href="/problem/<?= $problem['id'] ?>" class="nav-link" role="tab">
|
||||
<a href="/problem/<?= UOJProblem::info('id') ?>" class="nav-link" role="tab">
|
||||
<i class="bi bi-journal-text"></i>
|
||||
<?= UOJLocale::get('problems::statement') ?>
|
||||
</a>
|
||||
</li>
|
||||
<li class="nav-item text-start">
|
||||
<a href="/problem/<?= $problem['id'] ?>/solutions" class="nav-link" role="tab">
|
||||
<a href="/problem/<?= UOJProblem::info('id') ?>/solutions" class="nav-link" role="tab">
|
||||
<i class="bi bi-journal-bookmark"></i>
|
||||
<?= UOJLocale::get('problems::solutions') ?>
|
||||
</a>
|
||||
</li>
|
||||
<li class="nav-item text-start">
|
||||
<a class="nav-link" href="/problem/<?= $problem['id'] ?>/statistics">
|
||||
<a class="nav-link" href="/problem/<?= UOJProblem::info('id') ?>/statistics">
|
||||
<i class="bi bi-graph-up"></i>
|
||||
<?= UOJLocale::get('problems::statistics') ?>
|
||||
</a>
|
||||
@ -133,12 +143,12 @@
|
||||
</li>
|
||||
</ul>
|
||||
<div class="card-footer bg-transparent">
|
||||
评价:<?= getClickZanBlock('P', $problem['id'], $problem['zan']) ?>
|
||||
评价:<?= ClickZans::getBlock('P', UOJProblem::info('id'), UOJProblem::info('zan')) ?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php uojIncludeView('sidebar', array()) ?>
|
||||
</aside>
|
||||
<?php uojIncludeView('sidebar') ?>
|
||||
</aside>
|
||||
|
||||
</div>
|
||||
|
||||
|
@ -1,145 +1,126 @@
|
||||
<?php
|
||||
requireLib('bootstrap5');
|
||||
requireLib('morris');
|
||||
requireLib('bootstrap5');
|
||||
requireLib('morris');
|
||||
|
||||
if (!Auth::check() && UOJConfig::$data['switch']['force-login']) {
|
||||
redirectToLogin();
|
||||
}
|
||||
Auth::check() || redirectToLogin();
|
||||
UOJProblem::init(UOJRequest::get('id')) || UOJResponse::page404();
|
||||
|
||||
if (!validateUInt($_GET['id']) || !($problem = queryProblemBrief($_GET['id']))) {
|
||||
become404Page();
|
||||
}
|
||||
$problem = UOJProblem::cur()->info;
|
||||
|
||||
$contest = validateUInt($_GET['contest_id']) ? queryContest($_GET['contest_id']) : null;
|
||||
if ($contest != null) {
|
||||
genMoreContestInfo($contest);
|
||||
if (!isContestProblemVisibleToUser($problem, $contest, $myUser)) {
|
||||
become404Page();
|
||||
}
|
||||
if (UOJRequest::get('contest_id')) {
|
||||
UOJContest::init(UOJRequest::get('contest_id')) || UOJResponse::page404();
|
||||
UOJProblem::upgradeToContestProblem() || UOJResponse::page404();
|
||||
UOJContest::cur()->userCanSeeProblemStatistics(Auth::user()) || UOJResponse::page403();
|
||||
}
|
||||
UOJProblem::cur()->userCanView(Auth::user(), ['ensure' => true]);
|
||||
|
||||
$problem_rank = queryContestProblemRank($contest, $problem);
|
||||
if ($problem_rank == null) {
|
||||
become404Page();
|
||||
} else {
|
||||
$problem_letter = chr(ord('A') + $problem_rank - 1);
|
||||
}
|
||||
} else {
|
||||
if (!isProblemVisibleToUser($problem, $myUser)) {
|
||||
become404Page();
|
||||
}
|
||||
|
||||
if (!isNormalUser($myUser) && UOJConfig::$data['switch']['force-login']) {
|
||||
become403Page();
|
||||
}
|
||||
}
|
||||
|
||||
function scoreDistributionData() {
|
||||
function scoreDistributionData() {
|
||||
$data = array();
|
||||
$result = DB::select("select score, count(*) from submissions where problem_id = {$_GET['id']} and score is not null group by score");
|
||||
$is_res_empty = true;
|
||||
$res = DB::selectAll([
|
||||
"select score, count(*) from submissions",
|
||||
"where", [
|
||||
"problem_id" => UOJProblem::info('id'),
|
||||
["score", "is not", null],
|
||||
UOJSubmission::sqlForUserCanView(Auth::user(), UOJProblem::cur())
|
||||
], "group by score", "order by score"
|
||||
], DB::NUM);
|
||||
$has_score_0 = false;
|
||||
$has_score_100 = false;
|
||||
while ($row = DB::fetch($result, MYSQLI_NUM)) {
|
||||
foreach ($res as $row) {
|
||||
if ($row[0] == 0) {
|
||||
$has_score_0 = true;
|
||||
} elseif ($row[0] == 100) {
|
||||
} else if ($row[0] == 100) {
|
||||
$has_score_100 = true;
|
||||
}
|
||||
$score = $row[0] * 100;
|
||||
$data[] = array('score' => $score, 'count' => $row[1]);
|
||||
$data[] = ['score' => $score, 'count' => $row[1]];
|
||||
}
|
||||
if (!$has_score_0) {
|
||||
array_unshift($data, array('score' => 0, 'count' => 0));
|
||||
array_unshift($data, ['score' => 0, 'count' => 0]);
|
||||
}
|
||||
if (!$has_score_100) {
|
||||
$data[] = array('score' => 10000, 'count' => 0);
|
||||
$data[] = ['score' => 10000, 'count' => 0];
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
|
||||
$data = scoreDistributionData();
|
||||
$pre_data = $data;
|
||||
$suf_data = $data;
|
||||
for ($i = 0; $i < count($data); $i++) {
|
||||
$data = scoreDistributionData();
|
||||
$pre_data = $data;
|
||||
$suf_data = $data;
|
||||
for ($i = 0; $i < count($data); $i++) {
|
||||
$data[$i]['score'] /= 100;
|
||||
}
|
||||
for ($i = 1; $i < count($data); $i++) {
|
||||
}
|
||||
for ($i = 1; $i < count($data); $i++) {
|
||||
$pre_data[$i]['count'] += $pre_data[$i - 1]['count'];
|
||||
}
|
||||
for ($i = count($data) - 1; $i > 0; $i--) {
|
||||
}
|
||||
for ($i = count($data) - 1; $i > 0; $i--) {
|
||||
$suf_data[$i - 1]['count'] += $suf_data[$i]['count'];
|
||||
}
|
||||
}
|
||||
|
||||
$submissions_sort_by_choice = !isset($_COOKIE['submissions-sort-by-code-length']) ? 'time' : 'tot_size';
|
||||
?>
|
||||
$submissions_sort_by_choice = !isset($_COOKIE['submissions-sort-by-code-length']) ? 'time' : 'tot_size';
|
||||
?>
|
||||
|
||||
<?php echoUOJPageHeader(HTML::stripTags($problem['title']) . ' - ' . UOJLocale::get('problems::statistics')) ?>
|
||||
<?php echoUOJPageHeader(HTML::stripTags(UOJProblem::info('title')) . ' - ' . UOJLocale::get('problems::statistics')) ?>
|
||||
|
||||
<div class="row">
|
||||
|
||||
<!-- left col -->
|
||||
<div class="col-lg-9">
|
||||
|
||||
<?php if ($contest): ?>
|
||||
<!-- 比赛导航 -->
|
||||
<?php
|
||||
$tabs_info = array(
|
||||
'dashboard' => array(
|
||||
<!-- left col -->
|
||||
<div class="col-lg-9">
|
||||
<?php if (UOJContest::cur()) : ?>
|
||||
<!-- 比赛导航 -->
|
||||
<?php
|
||||
$tabs_info = [
|
||||
'dashboard' => [
|
||||
'name' => UOJLocale::get('contests::contest dashboard'),
|
||||
'url' => "/contest/{$contest['id']}"
|
||||
),
|
||||
'submissions' => array(
|
||||
'url' => '/contest/' . UOJContest::info('id'),
|
||||
],
|
||||
'submissions' => [
|
||||
'name' => UOJLocale::get('contests::contest submissions'),
|
||||
'url' => "/contest/{$contest['id']}/submissions"
|
||||
),
|
||||
'standings' => array(
|
||||
'url' => '/contest/' . UOJContest::info('id') . '/submissions',
|
||||
],
|
||||
'standings' => [
|
||||
'name' => UOJLocale::get('contests::contest standings'),
|
||||
'url' => "/contest/{$contest['id']}/standings"
|
||||
),
|
||||
);
|
||||
'url' => '/contest/' . UOJContest::info('id') . '/standings',
|
||||
],
|
||||
];
|
||||
|
||||
if ($contest['cur_progress'] > CONTEST_TESTING) {
|
||||
$tabs_info['after_contest_standings'] = array(
|
||||
if (UOJContest::cur()->progress() > CONTEST_TESTING) {
|
||||
$tabs_info['after_contest_standings'] = [
|
||||
'name' => UOJLocale::get('contests::after contest standings'),
|
||||
'url' => "/contest/{$contest['id']}/after_contest_standings"
|
||||
);
|
||||
$tabs_info['self_reviews'] = array(
|
||||
'url' => '/contest/' . UOJContest::info('id') . '/after_contest_standings',
|
||||
];
|
||||
$tabs_info['self_reviews'] = [
|
||||
'name' => UOJLocale::get('contests::contest self reviews'),
|
||||
'url' => "/contest/{$contest['id']}/self_reviews"
|
||||
);
|
||||
'url' => '/contest/' . UOJContest::info('id') . '/self_reviews',
|
||||
];
|
||||
}
|
||||
|
||||
if (hasContestPermission(Auth::user(), $contest)) {
|
||||
$tabs_info['backstage'] = array(
|
||||
if (UOJContest::cur()->userCanManage(Auth::user())) {
|
||||
$tabs_info['backstage'] = [
|
||||
'name' => UOJLocale::get('contests::contest backstage'),
|
||||
'url' => "/contest/{$contest['id']}/backstage"
|
||||
);
|
||||
'url' => '/contest/' . UOJContest::info('id') . '/backstage',
|
||||
];
|
||||
}
|
||||
?>
|
||||
<div class="mb-2">
|
||||
<?= HTML::tablist($tabs_info, '', 'nav-pills') ?>
|
||||
</div>
|
||||
<?php endif ?>
|
||||
|
||||
<div class="card card-default mb-2">
|
||||
<div class="card-body">
|
||||
|
||||
<h1 class="page-header text-center h2">
|
||||
<?php if ($contest): ?>
|
||||
<?= $problem_letter ?>.
|
||||
<?php else: ?>
|
||||
#<?= $problem['id'] ?>.
|
||||
<?php endif ?>
|
||||
<?= $problem['title'] ?>
|
||||
</h1>
|
||||
|
||||
<hr />
|
||||
<div class="card card-default mb-2">
|
||||
<div class="card-body">
|
||||
|
||||
<?php if ($contest && !hasContestPermission($myUser, $contest) && $contest['cur_progress'] <= CONTEST_IN_PROGRESS): ?>
|
||||
<h2 class="text-center text-muted">比赛尚未结束</h2>
|
||||
<?php else: ?>
|
||||
<h2 class="text-center h3"><?= UOJLocale::get('problems::accepted submissions') ?></h2>
|
||||
<div class="text-end mb-2">
|
||||
<h1 class="text-center">
|
||||
<?php if (UOJContest::cur()) : ?>
|
||||
<?= UOJProblem::cur()->getTitle(['with' => 'letter']) ?>
|
||||
<?php else : ?>
|
||||
<?= UOJProblem::cur()->getTitle(['with' => 'id']) ?>
|
||||
<?php endif ?>
|
||||
</h1>
|
||||
|
||||
<hr />
|
||||
|
||||
<h2 class="text-center"><?= UOJLocale::get('problems::accepted submissions') ?></h2>
|
||||
<div class="text-end mb-2">
|
||||
<div class="btn-group btn-group-sm">
|
||||
<a href="<?= UOJContext::requestURI() ?>" class="btn btn-secondary btn-xs <?= $submissions_sort_by_choice == 'time' ? 'active' : '' ?>" id="submissions-sort-by-run-time">
|
||||
<?= UOJLocale::get('problems::fastest') ?>
|
||||
@ -148,9 +129,9 @@
|
||||
<?= UOJLocale::get('problems::shortest') ?>
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script type="text/javascript">
|
||||
<script type="text/javascript">
|
||||
$('#submissions-sort-by-run-time').click(function() {
|
||||
$.cookie('submissions-sort-by-run-time', '');
|
||||
$.removeCookie('submissions-sort-by-code-length');
|
||||
@ -159,27 +140,38 @@
|
||||
$.cookie('submissions-sort-by-code-length', '');
|
||||
$.removeCookie('submissions-sort-by-run-time');
|
||||
});
|
||||
</script>
|
||||
</script>
|
||||
|
||||
<?php
|
||||
$table_config = [
|
||||
<?php
|
||||
if ($submissions_sort_by_choice == 'time') {
|
||||
$submid = 'best_ac_submissions.submission_id = submissions.id';
|
||||
$orderby = 'order by best_ac_submissions.used_time, best_ac_submissions.used_memory, best_ac_submissions.tot_size, best_ac_submissions.submission_id';
|
||||
} else {
|
||||
$submid = 'best_ac_submissions.shortest_id = submissions.id';
|
||||
$orderby = 'order by best_ac_submissions.shortest_tot_size, best_ac_submissions.shortest_used_time, best_ac_submissions.shortest_used_memory, best_ac_submissions.shortest_id';
|
||||
}
|
||||
|
||||
echoSubmissionsList([
|
||||
$submid,
|
||||
"best_ac_submissions.problem_id" => UOJProblem::info('id')
|
||||
], $orderby, [
|
||||
'judge_time_hidden' => '',
|
||||
'problem_hidden' => true,
|
||||
'table_name' => 'best_ac_submissions, submissions',
|
||||
'problem' => UOJProblem::cur(),
|
||||
'table_config' => [
|
||||
'div_classes' => ['table-responsive', 'mb-3'],
|
||||
'table_classes' => ['table', 'mb-0', 'text-center'],
|
||||
];
|
||||
]
|
||||
], Auth::user());
|
||||
?>
|
||||
|
||||
<?php if ($submissions_sort_by_choice == 'time'): ?>
|
||||
<?php echoSubmissionsList("best_ac_submissions.submission_id = submissions.id and best_ac_submissions.problem_id = {$problem['id']}", 'order by best_ac_submissions.used_time, best_ac_submissions.used_memory, best_ac_submissions.tot_size', array('problem_hidden' => '', 'judge_time_hidden' => '', 'table_name' => 'best_ac_submissions, submissions', 'table_config' => $table_config), $myUser); ?>
|
||||
<?php else: ?>
|
||||
<?php echoSubmissionsList("best_ac_submissions.shortest_id = submissions.id and best_ac_submissions.problem_id = {$problem['id']}", 'order by best_ac_submissions.shortest_tot_size, best_ac_submissions.shortest_used_time, best_ac_submissions.shortest_used_memory', array('problem_hidden' => '', 'judge_time_hidden' => '', 'table_name' => 'best_ac_submissions, submissions', 'table_config' => $table_config), $myUser); ?>
|
||||
<?php endif ?>
|
||||
|
||||
<h2 class="text-center h3 mt-4">
|
||||
<h2 class="text-center mt-4">
|
||||
<?= UOJLocale::get('problems::score distribution') ?>
|
||||
</h2>
|
||||
<div id="score-distribution-chart" style="height: 250px;"></div>
|
||||
<script type="text/javascript">
|
||||
new Morris.Bar({
|
||||
</h2>
|
||||
<div id="score-distribution-chart" style="height: 250px;"></div>
|
||||
<script type="text/javascript">
|
||||
new Morris.Bar({
|
||||
element: 'score-distribution-chart',
|
||||
data: <?= json_encode($data) ?>,
|
||||
barColors: function(r, s, type) {
|
||||
@ -194,15 +186,15 @@ new Morris.Bar({
|
||||
'<div class="morris-hover-point">' + '<a href="/submissions?problem_id=' + <?= $problem['id'] ?> + '&min_score=' + scr + '&max_score=' + scr + '">' + 'number: ' + row.count + '</a>' + '</div>';
|
||||
},
|
||||
resize: true
|
||||
});
|
||||
</script>
|
||||
});
|
||||
</script>
|
||||
|
||||
<h2 class="text-center h3 mt-4">
|
||||
<h2 class="text-center mt-4">
|
||||
<?= UOJLocale::get('problems::prefix sum of score distribution') ?>
|
||||
</h2>
|
||||
<div id="score-distribution-chart-pre" style="height: 250px;"></div>
|
||||
<script type="text/javascript">
|
||||
new Morris.Line({
|
||||
</h2>
|
||||
<div id="score-distribution-chart-pre" style="height: 250px;"></div>
|
||||
<script type="text/javascript">
|
||||
new Morris.Line({
|
||||
element: 'score-distribution-chart-pre',
|
||||
data: <?= json_encode($pre_data) ?>,
|
||||
xkey: 'score',
|
||||
@ -223,15 +215,15 @@ new Morris.Line({
|
||||
'<div class="morris-hover-point">' + '<a href="/submissions?problem_id=' + <?= $problem['id'] ?> + '&max_score=' + scr + '">' + 'number: ' + row.count + '</a>' + '</div>';
|
||||
},
|
||||
resize: true
|
||||
});
|
||||
</script>
|
||||
});
|
||||
</script>
|
||||
|
||||
<h2 class="text-center h3 mt-4">
|
||||
<h2 class="text-center mt-4">
|
||||
<?= UOJLocale::get('problems::suffix sum of score distribution') ?>
|
||||
</h2>
|
||||
<div id="score-distribution-chart-suf" style="height: 250px;"></div>
|
||||
<script type="text/javascript">
|
||||
new Morris.Line({
|
||||
</h2>
|
||||
<div id="score-distribution-chart-suf" style="height: 250px;"></div>
|
||||
<script type="text/javascript">
|
||||
new Morris.Line({
|
||||
element: 'score-distribution-chart-suf',
|
||||
data: <?= json_encode($suf_data) ?>,
|
||||
xkey: 'score',
|
||||
@ -252,62 +244,54 @@ new Morris.Line({
|
||||
'<div class="morris-hover-point">' + '<a href="/submissions?problem_id=' + <?= $problem['id'] ?> + '&min_score=' + scr + '">' + 'number: ' + row.count + '</a>' + '</div>';
|
||||
},
|
||||
resize: true
|
||||
});
|
||||
</script>
|
||||
});
|
||||
</script>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php endif // $contest && !hasContestPermission($myUser, $contest) && $contest['cur_progress'] <= CONTEST_IN_PROGRESS ?>
|
||||
<!-- end left col -->
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
<!-- Right col -->
|
||||
<aside class="col-lg-3 mt-3 mt-lg-0">
|
||||
|
||||
<!-- end left col -->
|
||||
</div>
|
||||
|
||||
<!-- Right col -->
|
||||
<aside class="col-lg-3 mt-3 mt-lg-0">
|
||||
|
||||
<?php if ($contest): ?>
|
||||
<!-- Contest card -->
|
||||
<div class="card card-default mb-2">
|
||||
<?php if ($contest) : ?>
|
||||
<!-- Contest card -->
|
||||
<div class="card card-default mb-2">
|
||||
<div class="card-body">
|
||||
<h3 class="h5 card-title text-center">
|
||||
<h3 class="h4 card-title text-center">
|
||||
<a class="text-decoration-none text-body" href="/contest/<?= $contest['id'] ?>">
|
||||
<?= $contest['name'] ?>
|
||||
</a>
|
||||
</h3>
|
||||
<div class="card-text text-center text-muted">
|
||||
<?php if ($contest['cur_progress'] <= CONTEST_IN_PROGRESS): ?>
|
||||
<?php if ($contest['cur_progress'] <= CONTEST_IN_PROGRESS) : ?>
|
||||
<span id="contest-countdown"></span>
|
||||
<?php else: ?>
|
||||
<?php else : ?>
|
||||
<?= UOJLocale::get('contests::contest ended') ?>
|
||||
<?php endif ?>
|
||||
</div>
|
||||
</div>
|
||||
<div class="card-footer bg-transparent">
|
||||
比赛评价:<?= getClickZanBlock('C', $contest['id'], $contest['zan']) ?>
|
||||
比赛评价:<?= ClickZans::getBlock('C', $contest['id'], $contest['zan']) ?>
|
||||
</div>
|
||||
</div>
|
||||
<?php if ($contest['cur_progress'] <= CONTEST_IN_PROGRESS): ?>
|
||||
<script type="text/javascript">
|
||||
$('#contest-countdown').countdown(<?= $contest['end_time']->getTimestamp() - UOJTime::$time_now->getTimestamp() ?>, function(){}, '1.75rem', false);
|
||||
</script>
|
||||
<?php endif ?>
|
||||
<?php endif ?>
|
||||
</div>
|
||||
<?php if ($contest['cur_progress'] <= CONTEST_IN_PROGRESS) : ?>
|
||||
<script type="text/javascript">
|
||||
$('#contest-countdown').countdown(<?= $contest['end_time']->getTimestamp() - UOJTime::$time_now->getTimestamp() ?>, function() {}, '1.75rem', false);
|
||||
</script>
|
||||
<?php endif ?>
|
||||
<?php endif ?>
|
||||
|
||||
<div class="card card-default mb-2">
|
||||
<div class="card card-default mb-2">
|
||||
<ul class="nav nav-pills nav-fill flex-column" role="tablist">
|
||||
<li class="nav-item text-start">
|
||||
<a class="nav-link" role="tab"
|
||||
<?php if ($contest): ?>
|
||||
href="/contest/<?= $contest['id'] ?>/problem/<?= $problem['id'] ?>"
|
||||
<?php else: ?>
|
||||
href="/problem/<?= $problem['id'] ?>"
|
||||
<?php endif ?>>
|
||||
<a class="nav-link" role="tab" <?php if ($contest) : ?> href="/contest/<?= $contest['id'] ?>/problem/<?= $problem['id'] ?>" <?php else : ?> href="/problem/<?= $problem['id'] ?>" <?php endif ?>>
|
||||
<i class="bi bi-journal-text"></i>
|
||||
<?= UOJLocale::get('problems::statement') ?>
|
||||
</a>
|
||||
</li>
|
||||
<?php if (!$contest || $contest['cur_progress'] >= CONTEST_FINISHED): ?>
|
||||
<?php if (!$contest || $contest['cur_progress'] >= CONTEST_FINISHED) : ?>
|
||||
<li class="nav-item text-start">
|
||||
<a href="/problem/<?= $problem['id'] ?>/solutions" class="nav-link" role="tab">
|
||||
<i class="bi bi-journal-bookmark"></i>
|
||||
@ -321,7 +305,7 @@ $('#contest-countdown').countdown(<?= $contest['end_time']->getTimestamp() - UOJ
|
||||
<?= UOJLocale::get('problems::statistics') ?>
|
||||
</a>
|
||||
</li>
|
||||
<?php if (hasProblemPermission($myUser, $problem)): ?>
|
||||
<?php if (hasProblemPermission($myUser, $problem)) : ?>
|
||||
<li class="nav-item text-start">
|
||||
<a class="nav-link" href="/problem/<?= $problem['id'] ?>/manage/statement" role="tab">
|
||||
<i class="bi bi-sliders"></i>
|
||||
@ -331,21 +315,15 @@ $('#contest-countdown').countdown(<?= $contest['end_time']->getTimestamp() - UOJ
|
||||
<?php endif ?>
|
||||
</ul>
|
||||
<div class="card-footer bg-transparent">
|
||||
评价:<?= getClickZanBlock('P', $problem['id'], $problem['zan']) ?>
|
||||
评价:<?= ClickZans::getBlock('P', $problem['id'], $problem['zan']) ?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php uojIncludeView('sidebar', array()); ?>
|
||||
<?php uojIncludeView('sidebar') ?>
|
||||
|
||||
<!-- End right col -->
|
||||
</aside>
|
||||
<!-- End right col -->
|
||||
</aside>
|
||||
|
||||
</div>
|
||||
|
||||
<?php if ($contest && $contest['cur_progress'] <= CONTEST_IN_PROGRESS): ?>
|
||||
<script type="text/javascript">
|
||||
checkContestNotice(<?= $contest['id'] ?>, '<?= UOJTime::$time_now_str ?>');
|
||||
</script>
|
||||
<?php endif ?>
|
||||
|
||||
<?php echoUOJPageFooter() ?>
|
||||
|
@ -1,44 +1,39 @@
|
||||
<?php
|
||||
requireLib('bootstrap5');
|
||||
requireLib('bootstrap5');
|
||||
|
||||
if (!Auth::check() && UOJConfig::$data['switch']['force-login']) {
|
||||
redirectToLogin();
|
||||
}
|
||||
Auth::check() || redirectToLogin();
|
||||
|
||||
if (!isNormalUser($myUser) && UOJConfig::$data['switch']['force-login']) {
|
||||
become403Page();
|
||||
}
|
||||
|
||||
$config = [
|
||||
$config = [
|
||||
'page_len' => 50,
|
||||
'div_classes' => ['card', 'mb-3'],
|
||||
'table_classes' => ['table', 'uoj-table', 'mb-0', 'text-center'],
|
||||
];
|
||||
'card' => true
|
||||
];
|
||||
|
||||
if (isset($_GET['type']) && $_GET['type'] == 'accepted') {
|
||||
if (isset($_GET['type']) && $_GET['type'] == 'accepted') {
|
||||
$config['by_accepted'] = true;
|
||||
$title = UOJLocale::get('top solver');
|
||||
} else {
|
||||
} else {
|
||||
become404Page();
|
||||
}
|
||||
?>
|
||||
}
|
||||
?>
|
||||
|
||||
<?php echoUOJPageHeader($title) ?>
|
||||
|
||||
<div class="row">
|
||||
<!-- left col -->
|
||||
<div class="col-lg-9">
|
||||
<h1 class="h2"><?= $title ?></h1>
|
||||
<!-- left col -->
|
||||
<div class="col-lg-9">
|
||||
<h1><?= $title ?></h1>
|
||||
|
||||
<?php echoRanklist($config) ?>
|
||||
</div>
|
||||
<!-- end left col -->
|
||||
<?php UOJRanklist::printHTML($config) ?>
|
||||
</div>
|
||||
<!-- end left col -->
|
||||
|
||||
<!-- right col -->
|
||||
<aside class="col-lg-3 mt-3 mt-lg-0">
|
||||
<?php uojIncludeView('sidebar', array()) ?>
|
||||
</aside>
|
||||
<!-- end right col -->
|
||||
<!-- right col -->
|
||||
<aside class="col-lg-3 mt-3 mt-lg-0">
|
||||
<?php uojIncludeView('sidebar') ?>
|
||||
</aside>
|
||||
<!-- end right col -->
|
||||
|
||||
</div>
|
||||
|
||||
|
@ -1,129 +1,138 @@
|
||||
<?php
|
||||
if (!UOJConfig::$data['switch']['open-register'] && DB::selectCount("SELECT COUNT(*) FROM user_info")) {
|
||||
become404Page();
|
||||
}
|
||||
requireLib('bootstrap5');
|
||||
requireLib('md5');
|
||||
|
||||
function handleRegisterPost() {
|
||||
use Gregwar\Captcha\PhraseBuilder;
|
||||
|
||||
if (!UOJConfig::$data['switch']['open-register'] && DB::selectCount("SELECT COUNT(*) FROM user_info")) {
|
||||
become404Page();
|
||||
}
|
||||
|
||||
function handleRegisterPost() {
|
||||
if (!crsf_check()) {
|
||||
return '页面已过期';
|
||||
}
|
||||
if (!isset($_POST['username'])) {
|
||||
return "无效表单";
|
||||
|
||||
if (!isset($_SESSION['phrase']) || !PhraseBuilder::comparePhrases($_SESSION['phrase'], $_POST['captcha'])) {
|
||||
return "bad_captcha";
|
||||
}
|
||||
if (!isset($_POST['password'])) {
|
||||
return "无效表单";
|
||||
}
|
||||
if (!isset($_POST['email'])) {
|
||||
|
||||
if (!isset($_POST['username']) || !isset($_POST['password']) || !isset($_POST['email'])) {
|
||||
return "无效表单";
|
||||
}
|
||||
|
||||
if (!UOJConfig::$data['switch']['open-register'] && DB::selectCount("SELECT COUNT(*) FROM user_info")) {
|
||||
return "只有首位用户可以注册。";
|
||||
try {
|
||||
$user = UOJUser::register([
|
||||
'username' => UOJRequest::post('username'),
|
||||
'password' => UOJRequest::post('password'),
|
||||
'email' => UOJRequest::post('email')
|
||||
]);
|
||||
} catch (UOJInvalidArgumentException $e) {
|
||||
return "失败:" . $e->getMessage();
|
||||
}
|
||||
|
||||
$username = $_POST['username'];
|
||||
$password = $_POST['password'];
|
||||
$email = $_POST['email'];
|
||||
if (!validateUsername($username)) {
|
||||
return "失败:无效用户名。";
|
||||
}
|
||||
if (queryUser($username)) {
|
||||
return "失败:用户名已存在。";
|
||||
}
|
||||
if (!validatePassword($password)) {
|
||||
return "失败:无效密码。";
|
||||
}
|
||||
if (!validateEmail($email)) {
|
||||
return "失败:无效电子邮箱。";
|
||||
}
|
||||
return "欢迎你!" . $user['username'] . ",你已成功注册。";
|
||||
}
|
||||
|
||||
$password = getPasswordToStore($password, $username);
|
||||
|
||||
$esc_email = DB::escape($email);
|
||||
|
||||
$svn_pw = uojRandString(10);
|
||||
if (!DB::selectCount("SELECT COUNT(*) FROM user_info")) {
|
||||
DB::query("insert into user_info (username, email, password, svn_password, register_time, usergroup) values ('$username', '$esc_email', '$password', '$svn_pw', now(), 'S')");
|
||||
} else {
|
||||
DB::query("insert into user_info (username, email, password, svn_password, register_time) values ('$username', '$esc_email', '$password', '$svn_pw', now())");
|
||||
}
|
||||
|
||||
return "欢迎你!" . $username . ",你已成功注册。";
|
||||
}
|
||||
|
||||
if (isset($_POST['register'])) {
|
||||
if (isset($_POST['register'])) {
|
||||
echo handleRegisterPost();
|
||||
unset($_SESSION['phrase']);
|
||||
die();
|
||||
} elseif (isset($_POST['check_username'])) {
|
||||
} elseif (isset($_POST['check_username'])) {
|
||||
$username = $_POST['username'];
|
||||
if (validateUsername($username) && !queryUser($username)) {
|
||||
echo '{"ok" : true}';
|
||||
die('{"ok": true}');
|
||||
} else {
|
||||
echo '{"ok" : false}';
|
||||
die('{"ok": false}');
|
||||
}
|
||||
die();
|
||||
}
|
||||
?>
|
||||
<?php
|
||||
$REQUIRE_LIB['md5'] = '';
|
||||
$REQUIRE_LIB['dialog'] = '';
|
||||
?>
|
||||
}
|
||||
?>
|
||||
<?php echoUOJPageHeader(UOJLocale::get('register')) ?>
|
||||
<h2 class="page-header"><?= UOJLocale::get('register') ?></h2>
|
||||
<form id="form-register" class="form-horizontal">
|
||||
|
||||
|
||||
<form id="form-register" class="card mw-100 mx-auto" style="width:600px">
|
||||
<div class="card-body">
|
||||
<h1 class="card-title text-center mb-3">
|
||||
<?= UOJLocale::get('register') ?>
|
||||
</h1>
|
||||
<div id="div-email" class="form-group">
|
||||
<label for="input-email" class="col-sm-2 control-label"><?= UOJLocale::get('email') ?></label>
|
||||
<div class="col-sm-3">
|
||||
<label for="input-email" class="form-label"><?= UOJLocale::get('email') ?></label>
|
||||
<input type="email" class="form-control" id="input-email" name="email" placeholder="<?= UOJLocale::get('enter your email') ?>" maxlength="50" />
|
||||
<span class="help-block" id="help-email"></span>
|
||||
</div>
|
||||
</div>
|
||||
<div id="div-username" class="form-group">
|
||||
<label for="input-username" class="col-sm-2 control-label"><?= UOJLocale::get('username') ?></label>
|
||||
<div class="col-sm-3">
|
||||
<label for="input-username" class="form-label"><?= UOJLocale::get('username') ?></label>
|
||||
<input type="text" class="form-control" id="input-username" name="username" placeholder="<?= UOJLocale::get('enter your username') ?>" maxlength="20" />
|
||||
<span class="help-block" id="help-username"></span>
|
||||
</div>
|
||||
</div>
|
||||
<div id="div-password" class="form-group">
|
||||
<label for="input-password" class="col-sm-2 control-label"><?= UOJLocale::get('password') ?></label>
|
||||
<div class="col-sm-3">
|
||||
<label for="input-password" class="form-label"><?= UOJLocale::get('password') ?></label>
|
||||
<input type="password" class="form-control" id="input-password" name="password" placeholder="<?= UOJLocale::get('enter your password') ?>" maxlength="20" />
|
||||
<input type="password" class="form-control top-buffer-sm" id="input-confirm_password" placeholder="<?= UOJLocale::get('re-enter your password') ?>" maxlength="20" />
|
||||
<input type="password" class="form-control mt-2" id="input-confirm_password" placeholder="<?= UOJLocale::get('re-enter your password') ?>" maxlength="20" />
|
||||
<span class="help-block" id="help-password"></span>
|
||||
</div>
|
||||
<div id="div-captcha" class="form-group">
|
||||
<label for="input-captcha"><?= UOJLocale::get('verification code') ?></label>
|
||||
<div class="input-group">
|
||||
<input type="text" class="form-control" id="input-captcha" name="captcha" placeholder="<?= UOJLocale::get('enter verification code') ?>" maxlength="20" />
|
||||
<span class="input-group-text p-0">
|
||||
<img id="captcha" class="col w-100 h-100" src="/captcha">
|
||||
</span>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<div class="col-sm-offset-2 col-sm-3">
|
||||
<button type="submit" id="button-submit" class="btn btn-secondary"><?= UOJLocale::get('submit') ?></button>
|
||||
</div>
|
||||
<div class="text-center">
|
||||
<button type="submit" id="button-submit" class="btn btn-primary"><?= UOJLocale::get('submit') ?></button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<div id="dialog" class="modal fade" tabindex="-1">
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title" id="modal-title"></h5>
|
||||
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<p id="modal-text"></p>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-primary" data-bs-dismiss="modal" aria-label="Close">好的</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script type="text/javascript">
|
||||
function checkUsernameNotInUse() {
|
||||
function refreshCaptcha() {
|
||||
var timestamp = new Date().getTime();
|
||||
$("#captcha").attr("src", "/captcha" + '?' + timestamp);
|
||||
}
|
||||
|
||||
function checkUsernameNotInUse() {
|
||||
var ok = false;
|
||||
$.ajax({
|
||||
url : '/register',
|
||||
type : 'POST',
|
||||
dataType : 'json',
|
||||
async : false,
|
||||
url: '/register',
|
||||
type: 'POST',
|
||||
dataType: 'json',
|
||||
async: false,
|
||||
|
||||
data : {
|
||||
check_username : '',
|
||||
username : $('#input-username').val()
|
||||
data: {
|
||||
check_username: '',
|
||||
username: $('#input-username').val()
|
||||
},
|
||||
success : function(data) {
|
||||
success: function(data) {
|
||||
ok = data.ok;
|
||||
},
|
||||
error : function(XMLHttpRequest, textStatus, errorThrown) {
|
||||
error: function(XMLHttpRequest, textStatus, errorThrown) {
|
||||
alert(XMLHttpRequest.responseText);
|
||||
ok = false;
|
||||
}
|
||||
});
|
||||
return ok;
|
||||
}
|
||||
function validateRegisterPost() {
|
||||
}
|
||||
|
||||
function validateRegisterPost() {
|
||||
var ok = true;
|
||||
ok &= getFormErrorAndShowHelp('email', validateEmail);
|
||||
ok &= getFormErrorAndShowHelp('username', function(str) {
|
||||
@ -136,59 +145,52 @@ function validateRegisterPost() {
|
||||
})
|
||||
ok &= getFormErrorAndShowHelp('password', validateSettingPassword);
|
||||
return ok;
|
||||
}
|
||||
}
|
||||
|
||||
function submitRegisterPost() {
|
||||
function submitRegisterPost() {
|
||||
if (!validateRegisterPost()) {
|
||||
return;
|
||||
}
|
||||
|
||||
$.post('/register', {
|
||||
_token : "<?= crsf_token() ?>",
|
||||
register : '',
|
||||
username : $('#input-username').val(),
|
||||
email : $('#input-email').val(),
|
||||
password : md5($('#input-password').val(), "<?= getPasswordClientSalt() ?>")
|
||||
_token: "<?= crsf_token() ?>",
|
||||
register: '',
|
||||
username: $('#input-username').val(),
|
||||
email: $('#input-email').val(),
|
||||
password: md5($('#input-password').val(), "<?= getPasswordClientSalt() ?>"),
|
||||
captcha: $('#input-captcha').val(),
|
||||
}, function(msg) {
|
||||
if (/^欢迎你!/.test(msg)) {
|
||||
BootstrapDialog.show({
|
||||
title : '注册成功',
|
||||
message : msg,
|
||||
type : BootstrapDialog.TYPE_SUCCESS,
|
||||
buttons: [{
|
||||
label: '好的',
|
||||
action: function(dialog) {
|
||||
dialog.close();
|
||||
}
|
||||
}],
|
||||
onhidden : function(dialog) {
|
||||
var prevUrl = document.referrer;
|
||||
if (!prevUrl) {
|
||||
prevUrl = '/';
|
||||
};
|
||||
$('#modal-title').html('注册成功');
|
||||
$('#modal-text').html(msg);
|
||||
$('#dialog')
|
||||
.modal('show')
|
||||
.on('hidden.bs.modal', function() {
|
||||
window.location.href = prevUrl;
|
||||
}
|
||||
});
|
||||
refreshCaptcha();
|
||||
} else {
|
||||
BootstrapDialog.show({
|
||||
title : '注册失败',
|
||||
message : msg,
|
||||
type : BootstrapDialog.TYPE_DANGER,
|
||||
buttons: [{
|
||||
label: '好的',
|
||||
action: function(dialog) {
|
||||
dialog.close();
|
||||
}
|
||||
}],
|
||||
});
|
||||
$('#modal-title').html('注册失败');
|
||||
$('#modal-text').html(msg);
|
||||
$('#dialog').modal('show');
|
||||
refreshCaptcha();
|
||||
}
|
||||
});
|
||||
}
|
||||
$(document).ready(function() {
|
||||
}
|
||||
$(document).ready(function() {
|
||||
refreshCaptcha();
|
||||
|
||||
$('#captcha').click(refreshCaptcha);
|
||||
|
||||
$('#form-register').submit(function(e) {
|
||||
submitRegisterPost();
|
||||
return false;
|
||||
});
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
<?php echoUOJPageFooter() ?>
|
||||
|
@ -1,18 +1,11 @@
|
||||
<?php
|
||||
requireLib('bootstrap5');
|
||||
requireLib('calendar_heatmap');
|
||||
requirePHPLib('form');
|
||||
requireLib('bootstrap5');
|
||||
requireLib('calendar_heatmap');
|
||||
|
||||
if (!Auth::check() && UOJConfig::$data['switch']['force-login']) {
|
||||
redirectToLogin();
|
||||
}
|
||||
|
||||
if (!isNormalUser($myUser) && UOJConfig::$data['switch']['force-login']) {
|
||||
become403Page();
|
||||
}
|
||||
?>
|
||||
Auth::check() || redirectToLogin();
|
||||
?>
|
||||
<?php echoUOJPageHeader('关于我') ?>
|
||||
|
||||
<?php uojIncludeView('user-info', array('user' => UOJContext::user(), 'is_blog_aboutme' => '')) ?>
|
||||
<?php uojIncludeView('user-info', ['user' => UOJUserBlog::user(), 'is_blog_aboutme' => true]) ?>
|
||||
|
||||
<?php echoUOJPageFooter() ?>
|
||||
|
@ -1,49 +1,62 @@
|
||||
<?php
|
||||
requireLib('bootstrap5');
|
||||
requireLib('mathjax');
|
||||
requireLib('hljs');
|
||||
requirePHPLib('form');
|
||||
requireLib('bootstrap5');
|
||||
requireLib('mathjax');
|
||||
requireLib('hljs');
|
||||
requirePHPLib('form');
|
||||
|
||||
if (!Auth::check() && UOJConfig::$data['switch']['force-login']) {
|
||||
redirectToLogin();
|
||||
}
|
||||
Auth::check() || redirectToLogin();
|
||||
|
||||
if (!isNormalUser($myUser) && UOJConfig::$data['switch']['force-login']) {
|
||||
become403Page();
|
||||
}
|
||||
$blogs_conds = [
|
||||
"poster" => UOJUserBlog::id(),
|
||||
];
|
||||
|
||||
$blogs_cond = "poster = '".UOJContext::userid()."'";
|
||||
if (!UOJContext::hasBlogPermission()) {
|
||||
$blogs_cond .= " and is_hidden = false";
|
||||
}
|
||||
if (!UOJUserBlog::userCanManage(Auth::user())) {
|
||||
$blogs_conds["is_hidden"] = false;
|
||||
}
|
||||
|
||||
$display_blogs_cond = $blogs_cond;
|
||||
$display_blogs_conds = $blogs_conds;
|
||||
|
||||
if (isset($_GET['tag'])) {
|
||||
if (isset($_GET['tag'])) {
|
||||
$blog_tag_required = $_GET['tag'];
|
||||
$display_blogs_cond .= " and '".DB::escape($blog_tag_required)."' in (select tag from blogs_tags where blogs_tags.blog_id = blogs.id)";
|
||||
} else {
|
||||
$blog_tag_required = null;
|
||||
}
|
||||
|
||||
$blogs_pag = new Paginator(array(
|
||||
'col_names' => array('*'),
|
||||
$display_blogs_conds[] = [
|
||||
DB::rawvalue($blog_tag_required), "in", DB::rawbracket([
|
||||
"select tag from blogs_tags",
|
||||
"where", ["blogs_tags.blog_id" => DB::raw("blogs.id")]
|
||||
])
|
||||
];
|
||||
} else {
|
||||
$blog_tag_required = null;
|
||||
}
|
||||
|
||||
$blogs_pag = new Paginator([
|
||||
'col_names' => ['*'],
|
||||
'table_name' => 'blogs',
|
||||
'cond' => $display_blogs_cond,
|
||||
'cond' => $display_blogs_conds,
|
||||
'tail' => 'order by post_time desc',
|
||||
'page_len' => 15
|
||||
));
|
||||
]);
|
||||
|
||||
$all_tags = DB::selectAll("select distinct tag from blogs_tags where blog_id in (select id from blogs where $blogs_cond)");
|
||||
?>
|
||||
$all_tags = DB::selectAll([
|
||||
"select distinct tag from blogs_tags",
|
||||
"where", [
|
||||
[
|
||||
"blog_id", "in", DB::rawbracket([
|
||||
"select id from blogs",
|
||||
"where", $blogs_conds
|
||||
])
|
||||
]
|
||||
]
|
||||
]);
|
||||
?>
|
||||
<?php echoUOJPageHeader('日志') ?>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-md-9">
|
||||
<?php if (!$blog_tag_required): ?>
|
||||
<?php if ($blogs_pag->isEmpty()): ?>
|
||||
<?php if (!$blog_tag_required) : ?>
|
||||
<?php if ($blogs_pag->isEmpty()) : ?>
|
||||
<div class="text-muted">此人很懒,什么博客也没留下。</div>
|
||||
<?php else: ?>
|
||||
<?php else : ?>
|
||||
<div class="card">
|
||||
<div class="card-body">
|
||||
<table class="table uoj-table">
|
||||
@ -55,21 +68,24 @@
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php $cnt = 0 ?>
|
||||
<?php foreach ($blogs_pag->get() as $blog): ?>
|
||||
<?php $cnt++ ?>
|
||||
<?php $cnt = 0; ?>
|
||||
<?php foreach ($blogs_pag->get() as $blog_info) : ?>
|
||||
<?php
|
||||
$blog = new UOJBlog($blog_info);
|
||||
$cnt++;
|
||||
?>
|
||||
<tr>
|
||||
<td>
|
||||
<?php if ($blog['is_hidden']): ?>
|
||||
<?php if ($blog->info['is_hidden']) : ?>
|
||||
<span class="text-danger">[隐藏]</span>
|
||||
<?php endif ?>
|
||||
<?= getBlogLink($blog['id']) ?>
|
||||
<?php foreach (queryBlogTags($blog['id']) as $tag): ?>
|
||||
<?= $blog->getLink() ?>
|
||||
<?php foreach ($blog->queryTags() as $tag) : ?>
|
||||
<?php echoBlogTag($tag) ?>
|
||||
<?php endforeach ?>
|
||||
</td>
|
||||
<td><?= $blog['post_time'] ?></td>
|
||||
<td><?= getClickZanBlock('B', $blog['id'], $blog['zan'], null, false) ?></td>
|
||||
<td><?= $blog->info['post_time'] ?></td>
|
||||
<td><?= ClickZans::getBlock('B', $blog->info['id'], $blog->info['zan'], null, false) ?></td>
|
||||
</tr>
|
||||
<?php endforeach ?>
|
||||
</tbody>
|
||||
@ -80,12 +96,12 @@
|
||||
</div>
|
||||
</div>
|
||||
<?php endif ?>
|
||||
<?php else: ?>
|
||||
<?php if ($blogs_pag->isEmpty()): ?>
|
||||
<?php else : ?>
|
||||
<?php if ($blogs_pag->isEmpty()) : ?>
|
||||
<div class="alert alert-danger">
|
||||
没有找到包含 “<?= HTML::escape($blog_tag_required) ?>” 标签的博客:
|
||||
</div>
|
||||
<?php else: ?>
|
||||
<?php else : ?>
|
||||
<div class="alert alert-success">
|
||||
共找到 <?= $blogs_pag->n_rows ?> 篇包含 “<?= HTML::escape($blog_tag_required) ?>” 标签的博客:
|
||||
</div>
|
||||
@ -96,23 +112,24 @@
|
||||
<tr>
|
||||
<th>标题</th>
|
||||
<th style="width: 20%">发表时间</th>
|
||||
<th class="text-center" style="width: 180px">评价</th>
|
||||
<th class="text-center" style="width: 100px">评价</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php foreach ($blogs_pag->get() as $blog): ?>
|
||||
<?php foreach ($blogs_pag->get() as $blog_info) : ?>
|
||||
<?php $blog = new UOJBlog($blog_info); ?>
|
||||
<tr>
|
||||
<td>
|
||||
<?php if ($blog['is_hidden']): ?>
|
||||
<?php if ($blog->info['is_hidden']) : ?>
|
||||
<span class="text-danger">[隐藏]</span>
|
||||
<?php endif ?>
|
||||
<?= getBlogLink($blog['id']) ?>
|
||||
<?php foreach (queryBlogTags($blog['id']) as $tag): ?>
|
||||
<?= $blog->getLink() ?>
|
||||
<?php foreach ($blog->queryTags() as $tag) : ?>
|
||||
<?php echoBlogTag($tag) ?>
|
||||
<?php endforeach ?>
|
||||
</td>
|
||||
<td><?= $blog['post_time'] ?></td>
|
||||
<td><?= getClickZanBlock('B', $blog['id'], $blog['zan']) ?></td>
|
||||
<td><?= $blog->info['post_time'] ?></td>
|
||||
<td><?= ClickZans::getBlock('B', $blog->info['id'], $blog->info['zan'], null, false) ?></td>
|
||||
</tr>
|
||||
<?php endforeach ?>
|
||||
</tbody>
|
||||
@ -127,13 +144,13 @@
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-3">
|
||||
<?php if (UOJContext::hasBlogPermission()): ?>
|
||||
<?php if (UOJUserBlog::userCanManage(Auth::user())) : ?>
|
||||
<div class="btn-group d-flex">
|
||||
<a href="<?= HTML::blog_url(UOJContext::userid(), '/post/new/write') ?>" class="btn btn-primary">
|
||||
<a href="<?= HTML::blog_url(UOJUserBlog::id(), '/post/new/write') ?>" class="btn btn-primary">
|
||||
<i class="bi bi-pencil-square"></i>
|
||||
写新博客
|
||||
</a>
|
||||
<a href="<?= HTML::blog_url(UOJContext::userid(), '/slide/new/write') ?>" class="btn btn-primary">
|
||||
<a href="<?= HTML::blog_url(UOJUserBlog::id(), '/slide/new/write') ?>" class="btn btn-primary">
|
||||
<i class="bi bi-file-earmark-slides"></i>
|
||||
写新幻灯片
|
||||
</a>
|
||||
@ -142,11 +159,11 @@
|
||||
<div class="card border-info mt-3">
|
||||
<div class="card-header bg-info">标签</div>
|
||||
<div class="card-body">
|
||||
<?php if ($all_tags): ?>
|
||||
<?php foreach ($all_tags as $tag): ?>
|
||||
<?php if ($all_tags) : ?>
|
||||
<?php foreach ($all_tags as $tag) : ?>
|
||||
<?php echoBlogTag($tag['tag']) ?>
|
||||
<?php endforeach ?>
|
||||
<?php else: ?>
|
||||
<?php else : ?>
|
||||
<div class="text-muted">暂无</div>
|
||||
<?php endif ?>
|
||||
</div>
|
||||
|
@ -1,26 +1,29 @@
|
||||
<?php
|
||||
requireLib('bootstrap5');
|
||||
requireLib('mathjax');
|
||||
requireLib('hljs');
|
||||
requirePHPLib('form');
|
||||
requireLib('bootstrap5');
|
||||
requireLib('mathjax');
|
||||
requireLib('hljs');
|
||||
requirePHPLib('form');
|
||||
|
||||
if (!Auth::check() && UOJConfig::$data['switch']['force-login']) {
|
||||
UOJBlog::init(UOJRequest::get('id')) || UOJResponse::page404();
|
||||
UOJBlog::cur()->belongsToUserBlog() || UOJResponse::page404();
|
||||
UOJBlog::cur()->userCanView(Auth::user()) || UOJResponse::page403();
|
||||
|
||||
$blog = UOJBlog::info();
|
||||
|
||||
function getCommentContentToDisplay($comment) {
|
||||
if (!$comment['is_hidden']) {
|
||||
return $comment['content'];
|
||||
} else {
|
||||
return '<span class="text-muted">【' . HTML::escape($comment['reason_to_hide']) . '】</span>';
|
||||
}
|
||||
}
|
||||
|
||||
if (!Auth::check()) {
|
||||
redirectToLogin();
|
||||
}
|
||||
}
|
||||
|
||||
if (!isNormalUser($myUser) && UOJConfig::$data['switch']['force-login']) {
|
||||
become403Page();
|
||||
}
|
||||
|
||||
if (!isset($_GET['id']) || !validateUInt($_GET['id']) || !($blog = queryBlog($_GET['id'])) || !UOJContext::isHis($blog)) {
|
||||
become404Page();
|
||||
}
|
||||
if ($blog['is_hidden'] && !UOJContext::hasBlogPermission()) {
|
||||
become403Page();
|
||||
}
|
||||
|
||||
$solutions = DB::selectAll("select * from problems_solutions where blog_id = {$blog['id']}");
|
||||
if ($solutions) {
|
||||
$solutions = DB::selectAll("select * from problems_solutions where blog_id = {$blog['id']}");
|
||||
if ($solutions) {
|
||||
foreach ($solutions as $solution) {
|
||||
$problem = queryProblemBrief($solution['problem_id']);
|
||||
|
||||
@ -28,13 +31,15 @@
|
||||
become403Page();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$comment_form = new UOJForm('comment');
|
||||
$comment_form->addVTextArea('comment', '内容', '',
|
||||
function($comment) {
|
||||
global $myUser;
|
||||
if ($myUser == null) {
|
||||
$comment_form = new UOJBs4Form('comment');
|
||||
$comment_form->addVTextArea(
|
||||
'comment',
|
||||
'内容',
|
||||
'',
|
||||
function ($comment) {
|
||||
if (Auth::check()) {
|
||||
return '请先登录';
|
||||
}
|
||||
if (!$comment) {
|
||||
@ -46,18 +51,28 @@
|
||||
return '';
|
||||
},
|
||||
null
|
||||
);
|
||||
$comment_form->handle = function() {
|
||||
);
|
||||
$comment_form->handle = function () {
|
||||
global $myUser, $blog, $comment_form;
|
||||
$comment = HTML::escape($_POST['comment']);
|
||||
|
||||
list($comment, $referrers) = uojHandleAtSign($comment, "/post/{$blog['id']}");
|
||||
|
||||
$esc_comment = DB::escape($comment);
|
||||
DB::insert("insert into blogs_comments (poster, blog_id, content, reply_id, post_time, zan) values ('{$myUser['username']}', '{$blog['id']}', '$esc_comment', 0, now(), 0)");
|
||||
DB::insert([
|
||||
"insert into blogs_comments",
|
||||
"(poster, blog_id, content, reply_id, post_time)",
|
||||
"values", DB::tuple([Auth::id(), $blog['id'], $comment, 0, DB::now()])
|
||||
]);
|
||||
$comment_id = DB::insert_id();
|
||||
|
||||
$rank = DB::selectCount("select count(*) from blogs_comments where blog_id = {$blog['id']} and reply_id = 0 and id < {$comment_id}");
|
||||
$rank = DB::selectCount([
|
||||
"select count(*) from blogs_comments",
|
||||
"where", [
|
||||
"blog_id" => $blog['id'],
|
||||
"reply_id" => 0,
|
||||
["id", "<", $comment_id]
|
||||
]
|
||||
]);
|
||||
$page = floor($rank / 20) + 1;
|
||||
|
||||
$uri = getLongTablePageUri($page) . '#' . "comment-{$comment_id}";
|
||||
@ -68,24 +83,27 @@
|
||||
sendSystemMsg($referrer, '有人提到你', $content);
|
||||
}
|
||||
|
||||
if ($blog['poster'] !== $myUser['username']) {
|
||||
if ($blog['poster'] !== Auth::id()) {
|
||||
$content = $user_link . ' 回复了您的博客 ' . $blog['title'] . ' :<a href="' . $uri . '">点击此处查看</a>';
|
||||
sendSystemMsg($blog['poster'], '博客新回复通知', $content);
|
||||
}
|
||||
|
||||
UOJBlog::cur()->updateActiveTime();
|
||||
$comment_form->succ_href = getLongTablePageRawUri($page);
|
||||
};
|
||||
$comment_form->ctrl_enter_submit = true;
|
||||
$comment_form->runAtServer();
|
||||
};
|
||||
$comment_form->ctrl_enter_submit = true;
|
||||
$comment_form->runAtServer();
|
||||
|
||||
$reply_form = new UOJForm('reply');
|
||||
$reply_form->addHidden('reply_id', '0',
|
||||
function($reply_id, &$vdata) {
|
||||
$reply_form = new UOJBs4Form('reply');
|
||||
$reply_form->addHidden(
|
||||
'reply_id',
|
||||
'0',
|
||||
function ($reply_id, &$vdata) {
|
||||
global $blog;
|
||||
if (!validateUInt($reply_id) || $reply_id == 0) {
|
||||
return '您要回复的对象不存在';
|
||||
}
|
||||
$comment = queryBlogComment($reply_id);
|
||||
$comment = UOJBlogComment::query($reply_id);
|
||||
if (!$comment || $comment['blog_id'] != $blog['id']) {
|
||||
return '您要回复的对象不存在';
|
||||
}
|
||||
@ -93,11 +111,13 @@
|
||||
return '';
|
||||
},
|
||||
null
|
||||
);
|
||||
$reply_form->addVTextArea('reply_comment', '内容', '',
|
||||
function($comment) {
|
||||
global $myUser;
|
||||
if ($myUser == null) {
|
||||
);
|
||||
$reply_form->addVTextArea(
|
||||
'reply_comment',
|
||||
'内容',
|
||||
'',
|
||||
function ($comment) {
|
||||
if (!Auth::check()) {
|
||||
return '请先登录';
|
||||
}
|
||||
if (!$comment) {
|
||||
@ -109,8 +129,8 @@
|
||||
return '';
|
||||
},
|
||||
null
|
||||
);
|
||||
$reply_form->handle = function(&$vdata) {
|
||||
);
|
||||
$reply_form->handle = function (&$vdata) {
|
||||
global $myUser, $blog, $reply_form;
|
||||
$comment = HTML::escape($_POST['reply_comment']);
|
||||
|
||||
@ -118,11 +138,21 @@
|
||||
|
||||
$reply_id = $_POST['reply_id'];
|
||||
|
||||
$esc_comment = DB::escape($comment);
|
||||
DB::insert("insert into blogs_comments (poster, blog_id, content, reply_id, post_time, zan) values ('{$myUser['username']}', '{$blog['id']}', '$esc_comment', $reply_id, now(), 0)");
|
||||
DB::insert([
|
||||
"insert into blogs_comments",
|
||||
"(poster, blog_id, content, reply_id, post_time)",
|
||||
"values", DB::tuple([Auth::id(), $blog['id'], $comment, $reply_id, DB::now()])
|
||||
]);
|
||||
$comment_id = DB::insert_id();
|
||||
|
||||
$rank = DB::selectCount("select count(*) from blogs_comments where blog_id = {$blog['id']} and reply_id = 0 and id < {$reply_id}");
|
||||
$rank = DB::selectCount([
|
||||
"select count(*) from blogs_comments",
|
||||
"where", [
|
||||
"blog_id" => $blog['id'],
|
||||
"reply_id" => 0,
|
||||
["id", "<", $reply_id]
|
||||
]
|
||||
]);
|
||||
$page = floor($rank / 20) + 1;
|
||||
|
||||
$uri = getLongTablePageUri($page) . '#' . "comment-{$reply_id}";
|
||||
@ -134,64 +164,73 @@
|
||||
}
|
||||
|
||||
$parent = $vdata['parent'];
|
||||
$notified = array();
|
||||
if ($parent['poster'] !== $myUser['username']) {
|
||||
$notified[] = $parent['poster'];
|
||||
$content = $user_link . ' 回复了您在博客 ' . $blog['title'] . ' 下的评论:<a href="' . $uri . '">点击此处查看</a>';
|
||||
sendSystemMsg($parent['poster'], '评论新回复通知', $content);
|
||||
$notified = [];
|
||||
if ($parent->info['poster'] !== Auth::id()) {
|
||||
$notified[] = $parent->info['poster'];
|
||||
$content = $user_link . ' 回复了您在博客 ' . $blog['title'] . ' 下的评论 :<a href="' . $uri . '">点击此处查看</a>';
|
||||
sendSystemMsg($parent->info['poster'], '评论新回复通知', $content);
|
||||
}
|
||||
if ($blog['poster'] !== $myUser['username'] && !in_array($blog['poster'], $notified)) {
|
||||
if ($blog['poster'] !== Auth::id() && !in_array($blog['poster'], $notified)) {
|
||||
$notified[] = $blog['poster'];
|
||||
$content = $user_link . ' 回复了您的博客 ' . $blog['title'] . ' :<a href="' . $uri . '">点击此处查看</a>';
|
||||
$content = $user_link . '回复了您的博客 ' . $blog['title'] . ' :<a href="' . $uri . '">点击此处查看</a>';
|
||||
sendSystemMsg($blog['poster'], '博客新回复通知', $content);
|
||||
}
|
||||
|
||||
UOJBlog::cur()->updateActiveTime();
|
||||
|
||||
$reply_form->succ_href = getLongTablePageRawUri($page);
|
||||
};
|
||||
$reply_form->ctrl_enter_submit = true;
|
||||
};
|
||||
$reply_form->ctrl_enter_submit = true;
|
||||
|
||||
$reply_form->runAtServer();
|
||||
$reply_form->runAtServer();
|
||||
|
||||
$comments_pag = new Paginator(array(
|
||||
'col_names' => array('*'),
|
||||
$comments_pag = new Paginator([
|
||||
'col_names' => ['*'],
|
||||
'table_name' => 'blogs_comments',
|
||||
'cond' => 'blog_id = ' . $blog['id'] . ' and reply_id = 0',
|
||||
'tail' => 'order by id asc',
|
||||
'page_len' => 20
|
||||
));
|
||||
?>
|
||||
]);
|
||||
?>
|
||||
<?php echoUOJPageHeader(HTML::stripTags($blog['title']) . ' - 博客') ?>
|
||||
<?php echoBlog($blog, array('show_title_only' => isset($_GET['page']) && $_GET['page'] != 1)) ?>
|
||||
<?php UOJBlog::cur()->echoView(['show_title_only' => isset($_GET['page']) && $_GET['page'] != 1]) ?>
|
||||
|
||||
<h2>
|
||||
评论
|
||||
<i class="bi bi-chat-fill"></i>
|
||||
</h2>
|
||||
|
||||
<div class="list-group">
|
||||
<?php if ($comments_pag->isEmpty()): ?>
|
||||
<?php if ($comments_pag->isEmpty()) : ?>
|
||||
<div class="list-group-item text-muted">暂无评论</div>
|
||||
<?php else: ?>
|
||||
<?php foreach ($comments_pag->get() as $comment):
|
||||
$poster = queryUser($comment['poster']);
|
||||
<?php else : ?>
|
||||
<?php foreach ($comments_pag->get() as $comment) :
|
||||
$poster = UOJUser::query($comment['poster']);
|
||||
$esc_email = HTML::escape($poster['email']);
|
||||
$asrc = HTML::avatar_addr($poster, 80);
|
||||
|
||||
$replies = DB::selectAll("select id, poster, content, post_time from blogs_comments where reply_id = {$comment['id']} order by id");
|
||||
$replies = DB::selectAll([
|
||||
"select id, poster, content, post_time, is_hidden, reason_to_hide from blogs_comments",
|
||||
"where", ["reply_id" => $comment['id']],
|
||||
"order by id"
|
||||
]);
|
||||
foreach ($replies as $idx => $reply) {
|
||||
$replies[$idx]['poster_realname'] = queryUser($reply['poster'])['realname'];
|
||||
$replies[$idx]['poster_realname'] = UOJUser::query($reply['poster'])['realname'];
|
||||
$replies[$idx]['content'] = getCommentContentToDisplay($reply);
|
||||
}
|
||||
$replies_json = json_encode($replies);
|
||||
?>
|
||||
<div id="comment-<?= $comment['id'] ?>" class="list-group-item">
|
||||
<div class="d-flex">
|
||||
<div class="comtposterbox mr-3 flex-shrink-0">
|
||||
<a href="<?= HTML::url('/user/'.$poster['username']) ?>" class="d-none d-sm-block text-decoration-none">
|
||||
<a href="<?= HTML::url('/user/' . $poster['username']) ?>" class="d-none d-sm-block text-decoration-none">
|
||||
<img class="media-object img-rounded" src="<?= $asrc ?>" alt="avatar" />
|
||||
</a>
|
||||
</div>
|
||||
<div id="comment-body-<?= $comment['id'] ?>" class="comtbox flex-grow-1 ms-3">
|
||||
<div class="row">
|
||||
<div class="col-sm-6"><?= getUserLink($poster['username']) ?></div>
|
||||
<div class="col-sm-6 text-end"><?= getClickZanBlock('BC', $comment['id'], $comment['zan']) ?></div>
|
||||
<div class="col-sm-6 text-end"><?= ClickZans::getBlock('BC', $comment['id'], $comment['zan']) ?></div>
|
||||
</div>
|
||||
<div class="comtbox1"><?= $comment['content'] ?></div>
|
||||
<ul class="list-inline mb-0 text-end">
|
||||
@ -206,15 +245,17 @@
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
<?php if ($replies): ?>
|
||||
<?php if ($replies) : ?>
|
||||
<div id="replies-<?= $comment['id'] ?>" class="comtbox5"></div>
|
||||
<?php endif ?>
|
||||
<script type="text/javascript">showCommentReplies('<?= $comment['id'] ?>', <?= $replies_json ?>);</script>
|
||||
<script type="text/javascript">
|
||||
showCommentReplies('<?= $comment['id'] ?>', <?= $replies_json ?>);
|
||||
</script>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<?php endforeach ?>
|
||||
<?php endif ?>
|
||||
<?php endif ?>
|
||||
</div>
|
||||
<?= $comments_pag->pagination() ?>
|
||||
|
||||
|
@ -1,49 +1,29 @@
|
||||
<?php
|
||||
requireLib('bootstrap5');
|
||||
requirePHPLib('form');
|
||||
requireLib('bootstrap5');
|
||||
requirePHPLib('form');
|
||||
|
||||
if (!Auth::check() && UOJConfig::$data['switch']['force-login']) {
|
||||
redirectToLogin();
|
||||
}
|
||||
Auth::check() || redirectToLogin();
|
||||
|
||||
if (!isNormalUser($myUser) && UOJConfig::$data['switch']['force-login']) {
|
||||
become403Page();
|
||||
}
|
||||
UOJBlog::init(UOJRequest::get('id')) || UOJResponse::page404();
|
||||
UOJBlog::cur()->belongsToUserBlog() || UOJResponse::page404();
|
||||
UOJBlog::cur()->userCanManage(Auth::user()) || UOJResponse::page403();
|
||||
|
||||
if (!UOJContext::hasBlogPermission()) {
|
||||
become403Page();
|
||||
}
|
||||
if (!isset($_GET['id']) || !validateUInt($_GET['id']) || !($blog = queryBlog($_GET['id'])) || !UOJContext::isHis($blog)) {
|
||||
become404Page();
|
||||
}
|
||||
$delete_form = new UOJBs4Form('delete');
|
||||
$delete_form->handle = function () {
|
||||
UOJBlog::cur()->delete();
|
||||
};
|
||||
$delete_form->submit_button_config['class_str'] = 'btn btn-danger';
|
||||
$delete_form->submit_button_config['text'] = '是的,我确定要删除';
|
||||
$delete_form->succ_href = HTML::blog_url(UOJBlog::info('poster'), '/archive');
|
||||
|
||||
$delete_form = new UOJForm('delete');
|
||||
$delete_form->handle = function() {
|
||||
global $myUser, $blog;
|
||||
$delete_form->runAtServer();
|
||||
?>
|
||||
<?php echoUOJPageHeader('删除博客 - ' . HTML::stripTags(UOJBlog::info('title'))) ?>
|
||||
|
||||
if ($myUser['username'] != $blog['poster']) {
|
||||
$poster_user_link = getUserLink($blog['poster']);
|
||||
$admin_user_link = isSuperUser($myUser) ? '管理员' : getUserLink($myUser['username']);
|
||||
$blog_content = HTML::escape($blog['content_md']);
|
||||
$content = <<<EOD
|
||||
<p>{$poster_user_link} 您好:</p>
|
||||
<p>您的博客 <b>{$blog['title']}</b>(ID:{$blog['id']})已经被 {$admin_user_link} 删除,现将博客原文备份发送给您,请查收。</p>
|
||||
<pre><code class="language-markdown">{$blog_content}</code></pre>
|
||||
EOD;
|
||||
sendSystemMsg($blog['poster'], '博客删除通知', $content);
|
||||
}
|
||||
|
||||
deleteBlog($blog['id']);
|
||||
};
|
||||
$delete_form->submit_button_config['class_str'] = 'btn btn-danger';
|
||||
$delete_form->submit_button_config['text'] = '是的,我确定要删除';
|
||||
$delete_form->succ_href = HTML::blog_url($blog['poster'], '/archive');
|
||||
|
||||
$delete_form->runAtServer();
|
||||
?>
|
||||
<?php echoUOJPageHeader('删除博客 - ' . HTML::stripTags($blog['title'])) ?>
|
||||
<h1 class="h3 text-center">
|
||||
您真的要删除博客 “<?= $blog['title'] ?>” <span class="fs-5">(博客 ID:<?= $blog['id'] ?>)</span>吗?该操作不可逆!
|
||||
<h1 class="h2 text-center">
|
||||
您真的要删除博客 “<?= UOJBlog::info('title') ?>” <span class="fs-5">(博客 ID:<?= UOJBlog::info('id') ?>)</span>吗?该操作不可逆!
|
||||
</h1>
|
||||
|
||||
<?php $delete_form->printHTML(); ?>
|
||||
|
||||
<?php echoUOJPageFooter() ?>
|
||||
|
@ -1,103 +1,109 @@
|
||||
<?php
|
||||
requireLib('bootstrap5');
|
||||
requirePHPLib('form');
|
||||
requireLib('bootstrap5');
|
||||
requirePHPLib('form');
|
||||
|
||||
if (!Auth::check() && UOJConfig::$data['switch']['force-login']) {
|
||||
UOJUserBlog::userCanManage(Auth::user()) || UOJResponse::page403();
|
||||
|
||||
if (!Auth::check()) {
|
||||
redirectToLogin();
|
||||
}
|
||||
}
|
||||
|
||||
if (!isNormalUser($myUser) && UOJConfig::$data['switch']['force-login']) {
|
||||
become403Page();
|
||||
}
|
||||
if (isset($_GET['id'])) {
|
||||
UOJBlog::init(UOJRequest::get('id')) || UOJResponse::page404();
|
||||
UOJBlog::cur()->belongsToUserBlog() || UOJResponse::page404();
|
||||
UOJBlog::info('type') == 'B' || UOJResponse::page404();
|
||||
$blog = UOJBlog::info();
|
||||
$blog['content'] = UOJBlog::cur()->queryContent()['content'];
|
||||
$blog['content_md'] = UOJBlog::cur()->queryContent()['content_md'];
|
||||
}
|
||||
|
||||
if (!UOJContext::hasBlogPermission()) {
|
||||
become403Page();
|
||||
}
|
||||
if (isset($_GET['id'])) {
|
||||
if (!validateUInt($_GET['id']) || !($blog = queryBlog($_GET['id'])) || !UOJContext::isHisBlog($blog)) {
|
||||
become404Page();
|
||||
}
|
||||
}
|
||||
|
||||
$blog_editor = new UOJBlogEditor();
|
||||
$blog_editor->name = 'blog';
|
||||
if ($blog) {
|
||||
$blog_editor = new UOJBlogEditor();
|
||||
$blog_editor->name = 'blog';
|
||||
if ($blog) {
|
||||
$blog_editor->cur_data = array(
|
||||
'title' => $blog['title'],
|
||||
'content_md' => $blog['content_md'],
|
||||
'content' => $blog['content'],
|
||||
'tags' => queryBlogTags($blog['id']),
|
||||
'tags' => UOJBlog::cur()->queryTags(),
|
||||
'is_hidden' => $blog['is_hidden']
|
||||
);
|
||||
} else {
|
||||
} else {
|
||||
$blog_editor->cur_data = array(
|
||||
'title' => $_GET['title'] ?: '新博客',
|
||||
'content_md' => '',
|
||||
'content' => '',
|
||||
'tags' => array(),
|
||||
'tags' => [],
|
||||
'is_hidden' => isset($_GET['is_hidden']) ? $_GET['is_hidden'] : true,
|
||||
);
|
||||
}
|
||||
if ($blog) {
|
||||
$blog_editor->blog_url = HTML::blog_url(UOJContext::userid(), "/post/{$blog['id']}");
|
||||
} else {
|
||||
}
|
||||
if ($blog) {
|
||||
$blog_editor->blog_url = HTML::blog_url(UOJUserBlog::id(), "/post/{$blog['id']}");
|
||||
} else {
|
||||
$blog_editor->blog_url = null;
|
||||
}
|
||||
}
|
||||
|
||||
function updateBlog($id, $data) {
|
||||
DB::update("update blogs set title = '".DB::escape($data['title'])."', content = '".DB::escape($data['content'])."', content_md = '".DB::escape($data['content_md'])."', is_hidden = {$data['is_hidden']} where id = {$id}");
|
||||
}
|
||||
function insertBlog($data) {
|
||||
DB::insert("insert into blogs (title, content, content_md, poster, is_hidden, post_time) values ('".DB::escape($data['title'])."', '".DB::escape($data['content'])."', '".DB::escape($data['content_md'])."', '".UOJContext::userid()."', {$data['is_hidden']}, now())");
|
||||
}
|
||||
function updateBlog($id, $data) {
|
||||
DB::update([
|
||||
"update blogs",
|
||||
"set", [
|
||||
"title" => $data['title'],
|
||||
"content" => $data['content'],
|
||||
"content_md" => $data['content_md'],
|
||||
"is_hidden" => $data['is_hidden']
|
||||
],
|
||||
"where", ["id" => $id]
|
||||
]);
|
||||
}
|
||||
function insertBlog($data) {
|
||||
DB::insert([
|
||||
"insert into blogs",
|
||||
"(title, content, content_md, poster, is_hidden, post_time, active_time)",
|
||||
"values", DB::tuple([
|
||||
$data['title'], $data['content'], $data['content_md'],
|
||||
UOJUserBlog::id(), $data['is_hidden'], DB::now(), DB::now()
|
||||
])
|
||||
]);
|
||||
}
|
||||
|
||||
$blog_editor->save = function($data) {
|
||||
$blog_editor->save = function ($data) {
|
||||
global $blog;
|
||||
$ret = array();
|
||||
$ret = [];
|
||||
if ($blog) {
|
||||
updateBlog($blog['id'], $data);
|
||||
} else {
|
||||
insertBlog($data);
|
||||
$blog = array('id' => DB::insert_id(), 'tags' => array());
|
||||
$ret['blog_id'] = $blog['id'];
|
||||
$ret['blog_write_url'] = HTML::blog_url(UOJContext::userid(), "/post/{$blog['id']}/write");
|
||||
$ret['blog_url'] = HTML::blog_url(UOJContext::userid(), "/post/{$blog['id']}");
|
||||
}
|
||||
if ($data['tags'] !== $blog['tags']) {
|
||||
DB::delete("delete from blogs_tags where blog_id = {$blog['id']}");
|
||||
foreach ($data['tags'] as $tag) {
|
||||
DB::insert("insert into blogs_tags (blog_id, tag) values ({$blog['id']}, '".DB::escape($tag)."')");
|
||||
}
|
||||
$blog_id = DB::insert_id();
|
||||
(new UOJBlog(['id' => $blog_id, 'type' => 'B']))->setAsCur();
|
||||
$ret['blog_id'] = $blog_id;
|
||||
$ret['blog_write_url'] = UOJBlog::cur()->getUriForWrite();
|
||||
$ret['blog_url'] = UOJBlog::cur()->getBlogUri();
|
||||
}
|
||||
UOJBlog::cur()->updateTags($data['tags']);
|
||||
return $ret;
|
||||
};
|
||||
};
|
||||
|
||||
$blog_editor->runAtServer();
|
||||
?>
|
||||
$blog_editor->runAtServer();
|
||||
?>
|
||||
<?php echoUOJPageHeader('写博客') ?>
|
||||
|
||||
<div class="card">
|
||||
<div class="card-header bg-transparent d-flex justify-content-between">
|
||||
<div class="card-header bg-transparent d-flex justify-content-between">
|
||||
<div class="fw-bold">写博客</div>
|
||||
<div id="div-blog-id"
|
||||
<?php if (!$blog): ?>
|
||||
style="display: none"
|
||||
<?php endif ?>
|
||||
>
|
||||
<?php if ($blog): ?>
|
||||
<div id="div-blog-id" <?php if (!$blog) : ?> style="display: none" <?php endif ?>>
|
||||
<?php if ($blog) : ?>
|
||||
<small>博客 ID:<b><?= $blog['id'] ?></b></small>
|
||||
<?php endif ?>
|
||||
</div>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<?php $blog_editor->printHTML() ?>
|
||||
</div>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<?php $blog_editor->printHTML() ?>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 提示信息 -->
|
||||
<div class="card mt-3">
|
||||
<div class="card-body">
|
||||
<h2 class="h4 card-title">提示</h2>
|
||||
<div class="card-body">
|
||||
<h2 class="h3 card-title">提示</h2>
|
||||
<ol>
|
||||
<li>题解发布后还需要返回对应题目的题解页面 <b>手动输入博客 ID</b> 来将本文添加到题目的题解列表中(博客 ID 可以在右上角找到);</li>
|
||||
<li>请勿引用不稳定的外部资源(如来自个人服务器的图片或文档等),以便备份及后期维护;</li>
|
||||
@ -107,7 +113,7 @@
|
||||
<p class="card-text">
|
||||
帮助:<a class="text-decoration-none" href="http://uoj.ac/blog/7">UOJ 博客使用教程</a>。
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php echoUOJPageFooter() ?>
|
||||
|
@ -1,50 +1,45 @@
|
||||
<?php
|
||||
requireLib('bootstrap5');
|
||||
requireLib('hljs');
|
||||
requireLib('mathjax');
|
||||
requireLib('bootstrap5');
|
||||
requireLib('hljs');
|
||||
requireLib('mathjax');
|
||||
|
||||
if (!Auth::check() && UOJConfig::$data['switch']['force-login']) {
|
||||
redirectToLogin();
|
||||
}
|
||||
Auth::check() || redirectToLogin();
|
||||
|
||||
if (!isNormalUser($myUser) && UOJConfig::$data['switch']['force-login']) {
|
||||
become403Page();
|
||||
}
|
||||
|
||||
$blogs_pag = new Paginator(array(
|
||||
'col_names' => array('*'),
|
||||
$blogs_pag = new Paginator([
|
||||
'col_names' => ['*'],
|
||||
'table_name' => 'blogs',
|
||||
'cond' => "poster = '".UOJContext::userid()."' and is_hidden = 0",
|
||||
'cond' => "poster = '" . UOJUserBlog::id() . "' and is_hidden = 0",
|
||||
'tail' => 'order by post_time desc',
|
||||
'page_len' => 5
|
||||
));
|
||||
]);
|
||||
|
||||
$all_tags = DB::selectAll("select distinct tag from blogs_tags where blog_id in (select id from blogs where $blogs_cond)");
|
||||
?>
|
||||
<?php echoUOJPageHeader(UOJContext::user()['username'] . '的博客') ?>
|
||||
$all_tags = DB::selectAll("select distinct tag from blogs_tags where blog_id in (select id from blogs where $blogs_cond)");
|
||||
?>
|
||||
<?php echoUOJPageHeader(UOJUserBlog::id() . '的博客') ?>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-lg-9">
|
||||
<?php if ($blogs_pag->isEmpty()): ?>
|
||||
<?php if ($blogs_pag->isEmpty()) : ?>
|
||||
<div class="text-muted">此人很懒,什么博客也没留下。</div>
|
||||
<?php else: ?>
|
||||
<?php foreach ($blogs_pag->get() as $blog): ?>
|
||||
<?php echoBlog($blog, array('is_preview' => true)) ?>
|
||||
<?php endforeach ?>
|
||||
<?php else : ?>
|
||||
<?php
|
||||
foreach ($blogs_pag->get() as $blog_info) {
|
||||
$blog = new UOJBlog($blog_info);
|
||||
$blog->echoView(['is_preview' => true]);
|
||||
}
|
||||
?>
|
||||
<?php endif ?>
|
||||
<div class="text-center">
|
||||
<?= $blogs_pag->pagination(); ?>
|
||||
</div>
|
||||
<?= $blogs_pag->pagination() ?>
|
||||
</div>
|
||||
<div class="col-lg-3">
|
||||
<img class="media-object img-thumbnail center-block" alt="<?= UOJContext::user()['username'] ?> Avatar" src="<?= HTML::avatar_addr(UOJContext::user(), 512) ?>" />
|
||||
<?php if (UOJContext::hasBlogPermission()): ?>
|
||||
<img class="media-object img-thumbnail center-block" alt="<?= UOJUserBlog::id() ?> Avatar" src="<?= HTML::avatar_addr(UOJUserBlog::user(), 512) ?>" />
|
||||
<?php if (UOJUserBlog::userCanManage(Auth::user())) : ?>
|
||||
<div class="btn-group d-flex mt-3">
|
||||
<a href="<?= HTML::blog_url(UOJContext::userid(), '/post/new/write') ?>" class="btn btn-primary">
|
||||
<a href="<?= HTML::blog_url(UOJUserBlog::id(), '/post/new/write') ?>" class="btn btn-primary">
|
||||
<i class="bi bi-pencil-square"></i>
|
||||
写新博客
|
||||
</a>
|
||||
<a href="<?= HTML::blog_url(UOJContext::userid(), '/slide/new/write') ?>" class="btn btn-primary">
|
||||
<a href="<?= HTML::blog_url(UOJUserBlog::id(), '/slide/new/write') ?>" class="btn btn-primary">
|
||||
<i class="bi bi-file-earmark-slides"></i>
|
||||
写新幻灯片
|
||||
</a>
|
||||
@ -53,15 +48,16 @@
|
||||
<div class="card border-info mt-3">
|
||||
<div class="card-header bg-info">标签</div>
|
||||
<div class="card-body">
|
||||
<?php if ($all_tags): ?>
|
||||
<?php foreach ($all_tags as $tag): ?>
|
||||
<?php if ($all_tags) : ?>
|
||||
<?php foreach ($all_tags as $tag) : ?>
|
||||
<?php echoBlogTag($tag['tag']) ?>
|
||||
<?php endforeach ?>
|
||||
<?php else: ?>
|
||||
<?php else : ?>
|
||||
<div class="text-muted">暂无</div>
|
||||
<?php endif ?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php echoUOJPageFooter() ?>
|
||||
|
@ -1,12 +1,12 @@
|
||||
<?php
|
||||
|
||||
call_user_func(function() { // to prevent variable scope leak
|
||||
call_user_func(function () { // to prevent variable scope leak
|
||||
Route::pattern('id', '[1-9][0-9]{0,9}');
|
||||
Route::pattern('blog_username', '[a-zA-Z0-9_\-]{1,20}');
|
||||
|
||||
switch (UOJConfig::$data['switch']['blog-domain-mode']) {
|
||||
case 1:
|
||||
$domain = '{blog_username}.'.UOJConfig::$data['web']['blog']['host'];
|
||||
$domain = '{blog_username}.' . UOJConfig::$data['web']['blog']['host'];
|
||||
$prefix = '';
|
||||
break;
|
||||
case 2:
|
||||
@ -19,20 +19,24 @@ call_user_func(function() { // to prevent variable scope leak
|
||||
break;
|
||||
}
|
||||
|
||||
Route::group([
|
||||
Route::group(
|
||||
[
|
||||
'domain' => UOJConfig::$data['web']['blog']['host']
|
||||
], function() {
|
||||
],
|
||||
function () {
|
||||
Route::any("/", '/blogs.php');
|
||||
Route::any("/blogs/{id}", '/blog_show.php');
|
||||
Route::any("/post/{id}", '/blog_show.php');
|
||||
}
|
||||
);
|
||||
Route::group([
|
||||
Route::group(
|
||||
[
|
||||
'domain' => $domain,
|
||||
'onload' => function() {
|
||||
'onload' => function () {
|
||||
UOJContext::setupBlog();
|
||||
}
|
||||
], function() use ($prefix) {
|
||||
],
|
||||
function () use ($prefix) {
|
||||
Route::any("$prefix/", '/subdomain/blog/index.php');
|
||||
Route::any("$prefix/archive", '/subdomain/blog/archive.php');
|
||||
Route::any("$prefix/aboutme", '/subdomain/blog/aboutme.php');
|
||||
|
@ -1,84 +1,86 @@
|
||||
<?php
|
||||
if (!Auth::check() && UOJConfig::$data['switch']['force-login']) {
|
||||
redirectToLogin();
|
||||
}
|
||||
requireLib('bootstrap5');
|
||||
requireLib('mathjax');
|
||||
requirePHPLib('form');
|
||||
|
||||
if (!isNormalUser($myUser) && UOJConfig::$data['switch']['force-login']) {
|
||||
become403Page();
|
||||
}
|
||||
|
||||
requireLib('bootstrap5');
|
||||
requireLib('mathjax');
|
||||
requirePHPLib('form');
|
||||
|
||||
$username = UOJContext::userid();
|
||||
?>
|
||||
Auth::check() || redirectToLogin();
|
||||
?>
|
||||
|
||||
<?php echoUOJPageHeader(UOJLocale::get('contests::contest self reviews')) ?>
|
||||
|
||||
<h1 class="h2">
|
||||
<?= $username ?> 的所有赛后总结
|
||||
<h1>
|
||||
<?= UOJUserBlog::id() ?> 的所有赛后总结
|
||||
</h1>
|
||||
|
||||
<?php
|
||||
$col_names = array('contest_id');
|
||||
$from = 'contests_registrants a left join contests b on a.contest_id = b.id';
|
||||
$cond = "username = '$username' and has_participated = 1";
|
||||
$tail = 'order by start_time desc, id desc';
|
||||
$config = array(
|
||||
'pagination_table' => 'contests_registrants',
|
||||
$col_names = ['contest_id'];
|
||||
$from = 'contests_registrants inner join contests on contests_registrants.contest_id = contests.id';
|
||||
$cond = ["username" => UOJUserBlog::id(), "has_participated" => 1];
|
||||
$tail = 'order by start_time desc, id desc';
|
||||
$config = [
|
||||
'page_len' => 10,
|
||||
'div_classes' => ['card', 'card-default', 'table-responsive'],
|
||||
'table_classes' => ['table', 'table-bordered', 'text-center', 'align-middle', 'uoj-table', 'mb-0'],
|
||||
);
|
||||
];
|
||||
|
||||
$header_row = '';
|
||||
$header_row .= '<tr>';
|
||||
$header_row .= '<th style="width: 28em;">'.UOJLocale::get('contests::contest name').'</th>';
|
||||
$header_row .= '<th style="width: 14em;">'.UOJLocale::get('problems::problem').'</th>';
|
||||
$header_row .= '<th style="width: 35em;">'.UOJLocale::get('contests::problem self review').'</th>';
|
||||
$header_row .= '<th style="width: 35em;">'.UOJLocale::get('contests::contest self review').'</th>';
|
||||
$header_row .= '</tr>';
|
||||
$header_row = '';
|
||||
$header_row .= '<tr>';
|
||||
$header_row .= '<th style="width:28em">' . UOJLocale::get('contests::contest name') . '</th>';
|
||||
$header_row .= '<th style="width:14em">' . UOJLocale::get('problems::problem') . '</th>';
|
||||
$header_row .= '<th style="width:35em">' . UOJLocale::get('contests::problem self review') . '</th>';
|
||||
$header_row .= '<th style="width:35em">' . UOJLocale::get('contests::contest self review') . '</th>';
|
||||
$header_row .= '</tr>';
|
||||
|
||||
$parsedown = HTML::parsedown();
|
||||
$purifier = HTML::purifier_inline();
|
||||
$parsedown = HTML::parsedown();
|
||||
$purifier = HTML::purifier_inline();
|
||||
|
||||
$print_row = function($row) use ($parsedown, $purifier) {
|
||||
global $username;
|
||||
$print_row = function ($row) use ($parsedown, $purifier) {
|
||||
$contest = UOJContest::query($row['contest_id']);
|
||||
$problems = $contest->getProblemIDs();
|
||||
$result = '';
|
||||
|
||||
$contest_id = $row['contest_id'];
|
||||
$contest = queryContest($contest_id);
|
||||
$contest_problems = queryContestProblems($contest_id);
|
||||
$n_contest_problems = count($contest_problems);
|
||||
|
||||
for ($i = 0; $i < $n_contest_problems; $i++) {
|
||||
$problem_id = $contest_problems[$i]['problem_id'];
|
||||
$problem = queryProblemBrief($problem_id);
|
||||
$problem_self_review = DB::selectFirst("select content from contests_reviews where contest_id = $contest_id and problem_id = $problem_id and poster = '$username'");
|
||||
for ($i = 0; $i < count($problems); $i++) {
|
||||
$problem = UOJContestProblem::query($problems[$i], $contest);
|
||||
$review = DB::selectSingle([
|
||||
"select content",
|
||||
"from contests_reviews",
|
||||
"where", [
|
||||
"contest_id" => $contest->info['id'],
|
||||
"problem_id" => $problem->info['id'],
|
||||
"poster" => UOJUserBlog::id(),
|
||||
]
|
||||
]);
|
||||
|
||||
$result .= '<tr>';
|
||||
|
||||
if ($i == 0) {
|
||||
$result .= '<td rowspan="' . $n_contest_problems . '"><a href="' . HTML::url("/contest/$contest_id") . '">' . $contest['name'] . '</a></td>';
|
||||
$result .= '<td rowspan="' . count($problems) . '"><a href="' . $contest->getUri() . '">' . $contest->info['name'] . '</a></td>';
|
||||
}
|
||||
|
||||
$problem_review_id = "review-$contest_id-$i";
|
||||
$result .= '<td>' . chr(ord('A') + $i) . '. <a href="/problem/' . $problem_id . '">' . $problem['title'] . '</a></td>';
|
||||
$result .= '<td>' . $purifier->purify($problem_self_review != null ? $parsedown->line($problem_self_review['content']) : '') . '</td>';
|
||||
$result .= '<td>' . $problem->getLink(['with' => 'letter', 'simplify' => true]) . '</td>';
|
||||
$result .= '<td>' . $purifier->purify($review ? $parsedown->line($review) : '') . '</td>';
|
||||
|
||||
if ($i == 0) {
|
||||
$contest_review_id = "review-$contest_id-overall";
|
||||
$contest_self_review = DB::selectFirst("select content from contests_reviews where contest_id = $contest_id and problem_id = -1 and poster = '$username'");
|
||||
$result .= '<td rowspan="' . $n_contest_problems . '">' . $purifier->purify($contest_self_review != null ? $parsedown->line($contest_self_review['content']) : '') . '</td>';
|
||||
$review = DB::selectSingle([
|
||||
"select content",
|
||||
"from contests_reviews",
|
||||
"where", [
|
||||
"contest_id" => $contest->info['id'],
|
||||
"problem_id" => -1,
|
||||
"poster" => UOJUserBlog::id(),
|
||||
]
|
||||
]);
|
||||
|
||||
$result .= '<td rowspan="' . count($problems) . '">' . $purifier->purify($review ? $parsedown->line($review) : '') . '</td>';
|
||||
}
|
||||
|
||||
$result .= '</tr>';
|
||||
}
|
||||
|
||||
echo $result;
|
||||
};
|
||||
};
|
||||
|
||||
echoLongTable($col_names, $from, $cond, $tail, $header_row, $print_row, $config);
|
||||
?>
|
||||
echoLongTable($col_names, $from, $cond, $tail, $header_row, $print_row, $config);
|
||||
?>
|
||||
|
||||
<?php echoUOJPageFooter() ?>
|
||||
|
@ -1,23 +1,16 @@
|
||||
<?php
|
||||
requirePHPLib('form');
|
||||
requirePHPLib('form');
|
||||
|
||||
if (!Auth::check() && UOJConfig::$data['switch']['force-login']) {
|
||||
redirectToLogin();
|
||||
}
|
||||
Auth::check() || redirectToLogin();
|
||||
UOJBlog::init(UOJRequest::get('id')) || UOJResponse::page404();
|
||||
UOJBlog::cur()->belongsToUserBlog() || UOJResponse::page404();
|
||||
UOJBlog::cur()->userCanView(Auth::user()) || UOJResponse::page403();
|
||||
UOJBlog::cur()->isTypeS() || UOJResponse::page404();
|
||||
|
||||
if (!isNormalUser($myUser) && UOJConfig::$data['switch']['force-login']) {
|
||||
become403Page();
|
||||
}
|
||||
|
||||
if (!isset($_GET['id']) || !validateUInt($_GET['id']) || !($blog = queryBlog($_GET['id'])) || !UOJContext::isHisSlide($blog)) {
|
||||
become404Page();
|
||||
}
|
||||
if ($blog['is_hidden'] && !UOJContext::hasBlogPermission()) {
|
||||
become403Page();
|
||||
}
|
||||
|
||||
$page_config = UOJContext::pageConfig();
|
||||
$page_config['PageTitle'] = HTML::stripTags($blog['title']) . ' - 幻灯片';
|
||||
$page_config['content'] = $blog['content'];
|
||||
uojIncludeView('slide', $page_config);
|
||||
?>
|
||||
$page_config = UOJContext::pageConfig();
|
||||
$page_config += [
|
||||
'PageTitle' => HTML::stripTags(UOJBlog::info('title')) . ' - 幻灯片',
|
||||
'content' => UOJBlog::cur()->queryContent()['content']
|
||||
];
|
||||
uojIncludeView('slide', $page_config);
|
||||
|
@ -1,82 +1,95 @@
|
||||
<?php
|
||||
requirePHPLib('form');
|
||||
requireLib('bootstrap5');
|
||||
requireLib('bootstrap5');
|
||||
requirePHPLib('form');
|
||||
|
||||
if (!Auth::check() && UOJConfig::$data['switch']['force-login']) {
|
||||
redirectToLogin();
|
||||
}
|
||||
Auth::check() || redirectToLogin();
|
||||
UOJUserBlog::userCanManage(Auth::user()) || UOJResponse::page403();
|
||||
|
||||
if (!isNormalUser($myUser) && UOJConfig::$data['switch']['force-login']) {
|
||||
become403Page();
|
||||
}
|
||||
if (isset($_GET['id'])) {
|
||||
UOJBlog::init(UOJRequest::get('id')) || UOJResponse::page404();
|
||||
UOJBlog::cur()->belongsToUserBlog() || UOJResponse::page404();
|
||||
UOJBlog::info('type') == 'S' || UOJResponse::page404();
|
||||
$blog = UOJBlog::info();
|
||||
$blog['content'] = UOJBlog::cur()->queryContent()['content'];
|
||||
$blog['content_md'] = UOJBlog::cur()->queryContent()['content_md'];
|
||||
}
|
||||
|
||||
if (!UOJContext::hasBlogPermission()) {
|
||||
become403Page();
|
||||
}
|
||||
if (isset($_GET['id'])) {
|
||||
if (!validateUInt($_GET['id']) || !($blog = queryBlog($_GET['id'])) || !UOJContext::isHisSlide($blog)) {
|
||||
become404Page();
|
||||
}
|
||||
}
|
||||
|
||||
$blog_editor = new UOJBlogEditor();
|
||||
$blog_editor->type = 'slide';
|
||||
$blog_editor->name = 'blog';
|
||||
if ($blog) {
|
||||
$blog_editor = new UOJBlogEditor();
|
||||
$blog_editor->type = 'slide';
|
||||
$blog_editor->name = 'blog';
|
||||
if ($blog) {
|
||||
$blog_editor->cur_data = array(
|
||||
'title' => $blog['title'],
|
||||
'content_md' => $blog['content_md'],
|
||||
'content' => $blog['content'],
|
||||
'tags' => queryBlogTags($blog['id']),
|
||||
'tags' => UOJBlog::cur()->queryTags(),
|
||||
'is_hidden' => $blog['is_hidden']
|
||||
);
|
||||
} else {
|
||||
} else {
|
||||
$blog_editor->cur_data = array(
|
||||
'title' => '新幻灯片',
|
||||
'content_md' => '',
|
||||
'content' => '',
|
||||
'tags' => array(),
|
||||
'tags' => [],
|
||||
'is_hidden' => true
|
||||
);
|
||||
}
|
||||
if ($blog) {
|
||||
$blog_editor->blog_url = HTML::blog_url(UOJContext::user()['username'], "/post/{$blog['id']}");
|
||||
} else {
|
||||
}
|
||||
if ($blog) {
|
||||
$blog_editor->blog_url = HTML::blog_url(UOJUserBlog::id(), "/post/{$blog['id']}");
|
||||
} else {
|
||||
$blog_editor->blog_url = null;
|
||||
}
|
||||
}
|
||||
|
||||
function updateBlog($id, $data) {
|
||||
DB::update("update blogs set title = '".DB::escape($data['title'])."', content = '".DB::escape($data['content'])."', content_md = '".DB::escape($data['content_md'])."', is_hidden = {$data['is_hidden']} where id = {$id}");
|
||||
}
|
||||
function insertSlide($data) {
|
||||
DB::insert("insert into blogs (type, title, content, content_md, poster, is_hidden, post_time) values ('S', '".DB::escape($data['title'])."', '".DB::escape($data['content'])."', '".DB::escape($data['content_md'])."', '".Auth::id()."', {$data['is_hidden']}, now())");
|
||||
}
|
||||
function insertBlog($data) {
|
||||
DB::insert([
|
||||
"insert into blogs",
|
||||
"(title, content, content_md, poster, is_hidden, post_time, active_time)",
|
||||
"values", DB::tuple([
|
||||
$data['title'], $data['content'], $data['content_md'],
|
||||
UOJUserBlog::id(), $data['is_hidden'], DB::now(), DB::now()
|
||||
])
|
||||
]);
|
||||
}
|
||||
function insertSlide($data) {
|
||||
DB::insert("insert into blogs (type, title, content, content_md, poster, is_hidden, post_time) values ('S', '" . DB::escape($data['title']) . "', '" . DB::escape($data['content']) . "', '" . DB::escape($data['content_md']) . "', '" . Auth::id() . "', {$data['is_hidden']}, now())");
|
||||
}
|
||||
|
||||
$blog_editor->save = function($data) {
|
||||
$blog_editor->save = function ($data) {
|
||||
global $blog;
|
||||
$ret = array();
|
||||
$ret = [];
|
||||
if ($blog) {
|
||||
updateBlog($blog['id'], $data);
|
||||
} else {
|
||||
insertSlide($data);
|
||||
$blog = array('id' => DB::insert_id(), 'tags' => array());
|
||||
$ret['blog_write_url'] = HTML::blog_url(UOJContext::user()['username'], "/slide/{$blog['id']}/write");
|
||||
$ret['blog_url'] = HTML::blog_url(UOJContext::user()['username'], "/slide/{$blog['id']}");
|
||||
}
|
||||
if ($data['tags'] !== $blog['tags']) {
|
||||
DB::delete("delete from blogs_tags where blog_id = {$blog['id']}");
|
||||
foreach ($data['tags'] as $tag) {
|
||||
DB::insert("insert into blogs_tags (blog_id, tag) values ({$blog['id']}, '".DB::escape($tag)."')");
|
||||
}
|
||||
$blog_id = DB::insert_id();
|
||||
(new UOJBlog(['id' => $blog_id, 'type' => 'S']))->setAsCur();
|
||||
$ret['blog_id'] = $blog_id;
|
||||
$ret['blog_write_url'] = UOJBlog::cur()->getUriForWrite();
|
||||
$ret['blog_url'] = UOJBlog::cur()->getBlogUri();
|
||||
}
|
||||
UOJBlog::cur()->updateTags($data['tags']);
|
||||
return $ret;
|
||||
};
|
||||
};
|
||||
|
||||
$blog_editor->runAtServer();
|
||||
?>
|
||||
$blog_editor->runAtServer();
|
||||
?>
|
||||
<?php echoUOJPageHeader('写幻灯片') ?>
|
||||
<div class="text-end">
|
||||
<a class="text-decoration-none" href="http://uoj.ac/blog/75">这玩意儿怎么用?</a>
|
||||
<a class="text-decoration-none" href="http://uoj.ac/blog/75">这玩意儿怎么用?</a>
|
||||
</div>
|
||||
<?php $blog_editor->printHTML() ?>
|
||||
|
||||
<div class="card">
|
||||
<div class="card-header bg-transparent d-flex justify-content-between">
|
||||
<div class="fw-bold">写幻灯片</div>
|
||||
<div id="div-blog-id" <?php if (!$blog) : ?> style="display: none" <?php endif ?>>
|
||||
<?php if ($blog) : ?>
|
||||
<small>博客 ID:<b><?= $blog['id'] ?></b></small>
|
||||
<?php endif ?>
|
||||
</div>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<?php $blog_editor->printHTML() ?>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php echoUOJPageFooter() ?>
|
||||
|
@ -1,160 +1,183 @@
|
||||
<?php
|
||||
requireLib('bootstrap5');
|
||||
requireLib('hljs');
|
||||
requirePHPLib('form');
|
||||
requirePHPLib('judger');
|
||||
requireLib('bootstrap5');
|
||||
requireLib('hljs');
|
||||
requirePHPLib('form');
|
||||
requirePHPLib('judger');
|
||||
|
||||
if (!Auth::check() && UOJConfig::$data['switch']['force-login']) {
|
||||
redirectToLogin();
|
||||
Auth::check() || redirectToLogin();
|
||||
UOJSubmission::init(UOJRequest::get('id')) || UOJResponse::page404();
|
||||
UOJSubmission::initProblemAndContest() || UOJResponse::page404();
|
||||
UOJSubmission::cur()->userCanView(Auth::user(), ['ensure' => true]);
|
||||
|
||||
$perm = UOJSubmission::cur()->viewerCanSeeComponents(Auth::user());
|
||||
|
||||
$can_see_minor = false;
|
||||
if ($perm['score']) {
|
||||
$can_see_minor = UOJSubmission::cur()->userCanSeeMinorVersions(Auth::user());
|
||||
UOJSubmissionHistory::init(UOJSubmission::cur(), ['minor' => $can_see_minor]) || UOJResponse::page404();
|
||||
if (isset($_GET['time'])) {
|
||||
$history_time = UOJRequest::get('time', 'is_short_string');
|
||||
!empty($history_time) || UOJResponse::page404();
|
||||
UOJSubmission::cur()->loadHistoryByTime($history_time) || UOJResponse::page404();
|
||||
UOJSubmission::cur()->isMajor() || UOJResponse::page404();
|
||||
} elseif (isset($_GET['tid'])) {
|
||||
$can_see_minor || UOJResponse::page404();
|
||||
UOJSubmission::cur()->loadHistoryByTID(UOJRequest::get('tid', 'validateUInt')) || UOJResponse::page404();
|
||||
!UOJSubmission::cur()->isMajor() || UOJResponse::page404();
|
||||
}
|
||||
}
|
||||
|
||||
if (!validateUInt($_GET['id']) || !($submission = querySubmission($_GET['id']))) {
|
||||
become404Page();
|
||||
}
|
||||
$submission = UOJSubmission::info();
|
||||
$submission_result = UOJSubmission::cur()->getResult();
|
||||
$problem = UOJProblem::info();
|
||||
|
||||
$submission_result = json_decode($submission['result'], true);
|
||||
if ($can_see_minor) {
|
||||
$minor_rejudge_form = new UOJBs4Form('minor_rejudge');
|
||||
$minor_rejudge_form->handle = function () {
|
||||
UOJSubmission::rejudgeById(UOJSubmission::info('id'), [
|
||||
'reason_text' => '管理员偷偷重测该提交记录',
|
||||
'major' => false
|
||||
]);
|
||||
$tid = DB::insert_id();
|
||||
redirectTo(UOJSubmission::cur()->getUriForNewTID($tid));
|
||||
};
|
||||
$minor_rejudge_form->submit_button_config['class_str'] = 'btn btn-sm btn-primary';
|
||||
$minor_rejudge_form->submit_button_config['text'] = '偷偷重新测试';
|
||||
$minor_rejudge_form->submit_button_config['align'] = 'right';
|
||||
$minor_rejudge_form->runAtServer();
|
||||
}
|
||||
|
||||
$problem = queryProblemBrief($submission['problem_id']);
|
||||
$problem_extra_config = getProblemExtraConfig($problem);
|
||||
|
||||
if ($submission['contest_id']) {
|
||||
$contest = queryContest($submission['contest_id']);
|
||||
genMoreContestInfo($contest);
|
||||
} else {
|
||||
$contest = null;
|
||||
|
||||
if (!isNormalUser($myUser) && UOJConfig::$data['switch']['force-login']) {
|
||||
become403Page();
|
||||
}
|
||||
}
|
||||
|
||||
if (!isSubmissionVisibleToUser($submission, $problem, $myUser)) {
|
||||
become403Page();
|
||||
}
|
||||
|
||||
$out_status = explode(', ', $submission['status'])[0];
|
||||
|
||||
if ($_GET['get'] == 'status-details' && Auth::check() && $submission['submitter'] === Auth::id()) {
|
||||
echo json_encode(array(
|
||||
'judged' => $out_status == 'Judged',
|
||||
'html' => getSubmissionStatusDetails($submission)
|
||||
));
|
||||
die();
|
||||
}
|
||||
|
||||
$hackable = $submission['score'] == 100 && $problem['hackable'] == 1;
|
||||
if ($hackable) {
|
||||
$hack_form = new UOJForm('hack');
|
||||
if (UOJSubmission::cur()->isLatest()) {
|
||||
if (UOJSubmission::cur()->preHackCheck()) {
|
||||
$hack_form = new UOJBs4Form('hack');
|
||||
|
||||
$hack_form->addTextFileInput('input', '输入数据');
|
||||
$hack_form->addCheckBox('use_formatter', '帮我整理文末回车、行末空格、换行符', true);
|
||||
$hack_form->handle = function(&$vdata) {
|
||||
global $myUser, $problem, $submission;
|
||||
if ($myUser == null) {
|
||||
redirectToLogin();
|
||||
}
|
||||
$hack_form->handle = function (&$vdata) {
|
||||
global $problem, $submission;
|
||||
Auth::check() || redirectToLogin();
|
||||
|
||||
if ($_POST["input_upload_type"] == 'file') {
|
||||
$tmp_name = UOJForm::uploadedFileTmpName("input_file");
|
||||
$tmp_name = UOJBs4Form::uploadedFileTmpName("input_file");
|
||||
if ($tmp_name == null) {
|
||||
becomeMsgPage('你在干啥……怎么什么都没交过来……?');
|
||||
UOJResponse::message('你在干啥……怎么什么都没交过来……?');
|
||||
}
|
||||
}
|
||||
|
||||
$fileName = uojRandAvaiableTmpFileName();
|
||||
$fileFullName = UOJContext::storagePath().$fileName;
|
||||
$fileName = FS::randomAvailableTmpFileName();
|
||||
$fileFullName = UOJContext::storagePath() . $fileName;
|
||||
if ($_POST["input_upload_type"] == 'editor') {
|
||||
file_put_contents($fileFullName, $_POST['input_editor']);
|
||||
} else {
|
||||
move_uploaded_file($_FILES["input_file"]['tmp_name'], $fileFullName);
|
||||
}
|
||||
$input_type = isset($_POST['use_formatter']) ? "USE_FORMATTER" : "DONT_USE_FORMATTER";
|
||||
DB::insert("insert into hacks (problem_id, submission_id, hacker, owner, input, input_type, submit_time, details, is_hidden) values ({$problem['id']}, {$submission['id']}, '{$myUser['username']}', '{$submission['submitter']}', '$fileName', '$input_type', now(), '', {$problem['is_hidden']})");
|
||||
DB::insert([
|
||||
"insert into hacks",
|
||||
"(problem_id, submission_id, hacker, owner, input, input_type, submit_time, status, details, is_hidden)",
|
||||
"values", DB::tuple([
|
||||
$problem['id'], $submission['id'], Auth::id(), $submission['submitter'],
|
||||
$fileName, $input_type, DB::now(), 'Waiting', '', $problem['is_hidden']
|
||||
])
|
||||
]);
|
||||
};
|
||||
$hack_form->max_post_size = 25 * 1024 * 1024;
|
||||
$hack_form->max_file_size_mb = 20;
|
||||
$hack_form->succ_href = "/hacks";
|
||||
|
||||
$hack_form->runAtServer();
|
||||
}
|
||||
|
||||
if ($submission['status'] == 'Judged' && hasProblemPermission($myUser, $problem)) {
|
||||
$rejudge_form = new UOJForm('rejudge');
|
||||
$rejudge_form->handle = function() {
|
||||
global $submission;
|
||||
rejudgeSubmission($submission);
|
||||
if (UOJSubmission::cur()->userCanRejudge(Auth::user())) {
|
||||
$rejudge_form = new UOJBs4Form('rejudge');
|
||||
$rejudge_form->handle = function () {
|
||||
UOJSubmission::rejudgeById(UOJSubmission::info('id'));
|
||||
};
|
||||
$rejudge_form->submit_button_config['class_str'] = 'btn btn-primary';
|
||||
$rejudge_form->submit_button_config['class_str'] = 'btn btn-sm btn-primary';
|
||||
$rejudge_form->submit_button_config['text'] = '重新测试';
|
||||
$rejudge_form->submit_button_config['align'] = 'right';
|
||||
$rejudge_form->submit_button_config['align'] = 'end';
|
||||
$rejudge_form->runAtServer();
|
||||
}
|
||||
|
||||
if (isSuperUser($myUser)) {
|
||||
$delete_form = new UOJForm('delete');
|
||||
$delete_form->handle = function() {
|
||||
global $submission;
|
||||
$content = json_decode($submission['content'], true);
|
||||
unlink(UOJContext::storagePath().$content['file_name']);
|
||||
DB::delete("delete from submissions where id = {$submission['id']}");
|
||||
updateBestACSubmissions($submission['submitter'], $submission['problem_id']);
|
||||
if (UOJSubmission::cur()->userCanDelete(Auth::user())) {
|
||||
$delete_form = new UOJBs4Form('delete');
|
||||
$delete_form->handle = function () {
|
||||
UOJSubmission::cur()->delete();
|
||||
};
|
||||
$delete_form->submit_button_config['class_str'] = 'btn btn-danger';
|
||||
$delete_form->submit_button_config['class_str'] = 'btn btn-sm btn-danger';
|
||||
$delete_form->submit_button_config['text'] = '删除此提交记录';
|
||||
$delete_form->submit_button_config['align'] = 'right';
|
||||
$delete_form->submit_button_config['align'] = 'end';
|
||||
$delete_form->submit_button_config['smart_confirm'] = '';
|
||||
$delete_form->succ_href = "/submissions";
|
||||
$delete_form->runAtServer();
|
||||
}
|
||||
|
||||
$should_show_content = hasViewPermission($problem_extra_config['view_content_type'], $myUser, $problem, $submission);
|
||||
$should_show_all_details = hasViewPermission($problem_extra_config['view_all_details_type'], $myUser, $problem, $submission);
|
||||
$should_show_details = hasViewPermission($problem_extra_config['view_details_type'], $myUser, $problem, $submission);
|
||||
$should_show_details_to_me = isSuperUser($myUser);
|
||||
if (explode(', ', $submission['status'])[0] != 'Judged') {
|
||||
$should_show_all_details = false;
|
||||
} else {
|
||||
if (UOJSubmission::cur()->userCanDelete(Auth::user()) && !UOJSubmission::cur()->isMajor()) {
|
||||
$delete_form = new UOJBs4Form('delete');
|
||||
$delete_form->handle = function () {
|
||||
UOJSubmission::cur()->deleteThisMinorVersion();
|
||||
};
|
||||
$delete_form->submit_button_config['class_str'] = 'btn btn-sm btn-danger';
|
||||
$delete_form->submit_button_config['text'] = '删除当前历史记录(保留其他历史记录)';
|
||||
$delete_form->submit_button_config['align'] = 'end';
|
||||
$delete_form->submit_button_config['smart_confirm'] = '';
|
||||
$delete_form->succ_href = UOJSubmission::cur()->getUriForLatest();
|
||||
$delete_form->runAtServer();
|
||||
}
|
||||
if ($contest != null && $contest['cur_progress'] == CONTEST_IN_PROGRESS) {
|
||||
if ($contest['extra_config']["problem_{$submission['problem_id']}"] === 'no-details') {
|
||||
$should_show_details = false;
|
||||
}
|
||||
}
|
||||
if (!isSubmissionFullVisibleToUser($submission, $contest, $problem, $myUser)) {
|
||||
$should_show_content = $should_show_all_details = false;
|
||||
}
|
||||
if ($contest != null && hasContestPermission($myUser, $contest)) {
|
||||
$should_show_details_to_me = true;
|
||||
$should_show_content = true;
|
||||
$should_show_all_details = true;
|
||||
}
|
||||
|
||||
if ($should_show_all_details) {
|
||||
$styler = new SubmissionDetailsStyler();
|
||||
if ((!$should_show_details || ($contest['extra_config']['contest_type']=='IOI' && $contest['cur_progress'] == CONTEST_IN_PROGRESS)) && !hasContestPermission($myUser, $contest)) {
|
||||
$styler->fade_all_details = true;
|
||||
$styler->show_small_tip = false;
|
||||
if ($contest['extra_config']['contest_type']=='IOI' && $contest['cur_progress'] == CONTEST_IN_PROGRESS) {
|
||||
$styler->ioi_contest_is_running = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
}
|
||||
?>
|
||||
<script>
|
||||
var problem_id = parseInt('<?= $submission['problem_id'] ?>');
|
||||
</script>
|
||||
<?php echoUOJPageHeader(UOJLocale::get('problems::submission').' #'.$submission['id']) ?>
|
||||
<?php echoUOJPageHeader(UOJLocale::get('problems::submission') . ' #' . $submission['id']) ?>
|
||||
|
||||
<h1 class="h3">
|
||||
<?= UOJLocale::get('problems::submission').' #'.$submission['id'] ?>
|
||||
<h1>
|
||||
<?= UOJLocale::get('problems::submission') . ' #' . $submission['id'] ?>
|
||||
</h1>
|
||||
|
||||
<?php echoSubmissionsListOnlyOne($submission, array('id_hidden' => ''), $myUser) ?>
|
||||
<?php UOJSubmission::cur()->echoStatusTable(['show_actual_score' => $perm['score'], 'id_hidden' => true], Auth::user()) ?>
|
||||
|
||||
<?php if ($should_show_content): ?>
|
||||
<?php echoSubmissionContent($submission, getProblemSubmissionRequirement($problem)) ?>
|
||||
<?php if ($hackable): ?>
|
||||
<?php
|
||||
if ($perm['score']) {
|
||||
HTML::echoPanel('mb-3', '测评历史', function () {
|
||||
UOJSubmissionHistory::cur()->echoTimeline();
|
||||
});
|
||||
}
|
||||
?>
|
||||
|
||||
<?php
|
||||
if ($perm['manager_view']) {
|
||||
HTML::echoPanel('mb-3', '测评机信息(管理员可见)', function () {
|
||||
if (empty(UOJSubmission::info('judger'))) {
|
||||
echo '暂无';
|
||||
} else {
|
||||
$judger = DB::selectFirst([
|
||||
"select * from judger_info",
|
||||
"where", [
|
||||
"judger_name" => UOJSubmission::info('judger')
|
||||
]
|
||||
]);
|
||||
if (!$judger) {
|
||||
echo '测评机信息损坏';
|
||||
} else {
|
||||
echo '<strong>', $judger['display_name'], ': </strong>', $judger['description'];
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
?>
|
||||
|
||||
<?php if ($perm['content'] || $perm['manager_view']) : ?>
|
||||
<?php UOJSubmission::cur()->echoContent() ?>
|
||||
|
||||
<?php if (isset($hack_form)) : ?>
|
||||
<p class="text-center">
|
||||
这程序好像有点Bug,我给组数据试试? <button id="button-display-hack" type="button" class="btn btn-danger btn-xs">Hack!</button>
|
||||
</p>
|
||||
<div id="div-form-hack" style="display:none" class="bot-buffer-md">
|
||||
<div id="div-form-hack" style="display:none" class="mb-3">
|
||||
<p class="text-center text-danger">
|
||||
Hack 功能是给大家互相查错用的。请勿故意提交错误代码,然后自己 Hack 自己、贼喊捉贼哦(故意贼喊捉贼会予以封禁处理)
|
||||
</p>
|
||||
<?php $hack_form->printHTML() ?>
|
||||
</div>
|
||||
<script type="text/javascript">
|
||||
@ -167,36 +190,48 @@
|
||||
<?php endif ?>
|
||||
<?php endif ?>
|
||||
|
||||
<?php if ($should_show_all_details): ?>
|
||||
<div class="card border-info mb-3">
|
||||
<div class="card-header bg-info">
|
||||
<h4 class="card-title"><?= UOJLocale::get('details') ?></h4>
|
||||
</div>
|
||||
<?php
|
||||
if (UOJSubmission::cur()->hasJudged()) {
|
||||
if ($perm['high_level_details']) {
|
||||
HTML::echoPanel(['card' => 'mb-3', 'body' => 'p-0'], UOJLocale::get('details'), function () use ($perm, $submission_result) {
|
||||
$styler = new SubmissionDetailsStyler();
|
||||
if (!$perm['low_level_details']) {
|
||||
$styler->fade_all_details = true;
|
||||
$styler->show_small_tip = false;
|
||||
}
|
||||
echoJudgmentDetails($submission_result['details'], $styler, 'details');
|
||||
|
||||
<?php echoJudgementDetails($submission_result['details'], $styler, 'details') ?>
|
||||
<?php if ($should_show_details_to_me): ?>
|
||||
<?php if (isset($submission_result['final_result'])): ?>
|
||||
<hr />
|
||||
<?php echoSubmissionDetails($submission_result['final_result']['details'], 'final_details') ?>
|
||||
<?php endif ?>
|
||||
<?php if ($styler->fade_all_details): ?>
|
||||
<hr />
|
||||
<?php echoSubmissionDetails($submission_result['details'], 'final_details') ?>
|
||||
<?php endif ?>
|
||||
<?php endif ?>
|
||||
</div>
|
||||
if ($perm['manager_view'] && !$perm['low_level_details']) {
|
||||
echo '<hr />';
|
||||
echo '<h4 class="text-info">全部详细信息(管理员可见)</h4>';
|
||||
echoSubmissionDetails($submission_result['details'], 'all_details');
|
||||
}
|
||||
});
|
||||
} else if ($perm['manager_view']) {
|
||||
HTML::echoPanel(['card' => 'mb-3', 'body' => 'p-0'], '详细(管理员可见)', function () use ($submission_result) {
|
||||
echoSubmissionDetails($submission_result['details'], 'details');
|
||||
});
|
||||
}
|
||||
if ($perm['manager_view'] && isset($submission_result['final_result'])) {
|
||||
HTML::echoPanel(['card' => 'mb-3', 'body' => 'p-0'], '终测结果预测(管理员可见)', function () use ($submission_result) {
|
||||
echoSubmissionDetails($submission_result['final_result']['details'], 'final_details');
|
||||
});
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
<div class="d-flex gap-2 justify-content-end">
|
||||
<?php if (isset($minor_rejudge_form)) : ?>
|
||||
<?php $minor_rejudge_form->printHTML() ?>
|
||||
<?php endif ?>
|
||||
|
||||
<?php if (isset($rejudge_form)): ?>
|
||||
<div class="text-end">
|
||||
<?php if (isset($rejudge_form)) : ?>
|
||||
<?php $rejudge_form->printHTML() ?>
|
||||
</div>
|
||||
<?php endif ?>
|
||||
|
||||
<?php if (isset($delete_form)): ?>
|
||||
<div class="text-end">
|
||||
<?php if (isset($delete_form)) : ?>
|
||||
<?php $delete_form->printHTML() ?>
|
||||
</div>
|
||||
<?php endif ?>
|
||||
</div>
|
||||
|
||||
<?php echoUOJPageFooter() ?>
|
||||
|
@ -1,37 +1,18 @@
|
||||
<?php
|
||||
|
||||
if (!Auth::check() && UOJConfig::$data['switch']['force-login']) {
|
||||
redirectToLogin();
|
||||
}
|
||||
|
||||
if (!is_array($_GET['get'])) {
|
||||
become404Page();
|
||||
}
|
||||
Auth::check() || UOJResponse::page403();
|
||||
is_array($_GET['get']) || UOJResponse::page404();
|
||||
|
||||
$res = [];
|
||||
|
||||
foreach ($_GET['get'] as $id) {
|
||||
if (!validateUInt($id)) {
|
||||
become404Page();
|
||||
}
|
||||
$submission = querySubmission($id);
|
||||
if ($submission['submitter'] !== Auth::id()) {
|
||||
become403Page();
|
||||
}
|
||||
if ($submission['contest_id'] == null && !(isNormalUser($myUser) && UOJConfig::$data['switch']['force-login'])) {
|
||||
become403Page();
|
||||
}
|
||||
|
||||
$problem = queryProblemBrief($submission['problem_id']);
|
||||
if (!isSubmissionVisibleToUser($submission, $problem, Auth::user())) {
|
||||
become403Page();
|
||||
}
|
||||
|
||||
$out_status = explode(', ', $submission['status'])[0];
|
||||
|
||||
($submission = UOJSubmission::query($id)) || UOJResponse::page404();
|
||||
$submission->setProblem() || UOJResponse::page404();
|
||||
$submission->userIsSubmitter(Auth::user()) || UOJResponse::page403();
|
||||
$submission->userCanView(Auth::user(), ['ensure' => true]);
|
||||
$res[] = [
|
||||
'judged' => $out_status == 'Judged',
|
||||
'html' => getSubmissionStatusDetails($submission)
|
||||
'judged' => $submission->hasJudged(),
|
||||
'waiting' => $submission->isWaiting(),
|
||||
'html' => $submission->getStatusDetailsHTML()
|
||||
];
|
||||
}
|
||||
|
||||
|
@ -1,49 +1,52 @@
|
||||
<?php
|
||||
requireLib('bootstrap5');
|
||||
requirePHPLib('judger');
|
||||
requireLib('bootstrap5');
|
||||
requirePHPLib('judger');
|
||||
|
||||
if (!Auth::check() && UOJConfig::$data['switch']['force-login']) {
|
||||
redirectToLogin();
|
||||
Auth::check() || redirectToLogin();
|
||||
|
||||
$conds = [];
|
||||
$config = [
|
||||
'judge_time_hidden' => true,
|
||||
'table_config' => [
|
||||
'div_classes' => ['card', 'mb-3', 'table-responsive'],
|
||||
'table_classes' => ['table', 'mb-0', 'uoj-table', 'text-center'],
|
||||
]
|
||||
];
|
||||
|
||||
$q_problem_id = UOJRequest::get('problem_id', 'validateUInt', null);
|
||||
$q_submitter = UOJRequest::get('submitter', 'validateUsername', null);
|
||||
$q_min_score = UOJRequest::get('min_score', 'validateUInt', null);
|
||||
$q_max_score = UOJRequest::get('max_score', 'validateUInt', null);
|
||||
$q_lang = UOJRequest::get('language', 'is_short_string', null);
|
||||
|
||||
if ($q_problem_id !== null) {
|
||||
$problem = UOJProblem::query($q_problem_id);
|
||||
if ($problem) {
|
||||
$config['problem'] = $problem;
|
||||
}
|
||||
|
||||
if (!isNormalUser($myUser) && UOJConfig::$data['switch']['force-login']) {
|
||||
become403Page();
|
||||
}
|
||||
$conds['problem_id'] = $q_problem_id;
|
||||
}
|
||||
if ($q_submitter !== null) {
|
||||
$conds['submitter'] = $q_submitter;
|
||||
}
|
||||
if ($q_min_score !== null) {
|
||||
$conds[] = ['score', '>=', $q_min_score];
|
||||
}
|
||||
if ($q_max_score !== null) {
|
||||
$conds[] = ['score', '<=', $q_max_score];
|
||||
}
|
||||
if ($q_lang != null) {
|
||||
$conds['language'] = $q_lang;
|
||||
}
|
||||
|
||||
$conds = array();
|
||||
|
||||
$q_problem_id = isset($_GET['problem_id']) && validateUInt($_GET['problem_id']) ? $_GET['problem_id'] : null;
|
||||
$q_submitter = isset($_GET['submitter']) && validateUsername($_GET['submitter']) ? $_GET['submitter'] : null;
|
||||
$q_min_score = isset($_GET['min_score']) && validateUInt($_GET['min_score']) ? $_GET['min_score'] : null;
|
||||
$q_max_score = isset($_GET['max_score']) && validateUInt($_GET['max_score']) ? $_GET['max_score'] : null;
|
||||
$q_language = isset($_GET['language']) ? $_GET['language'] : null;
|
||||
if ($q_problem_id != null) {
|
||||
$conds[] = "problem_id = $q_problem_id";
|
||||
}
|
||||
if ($q_submitter != null) {
|
||||
$conds[] = "submitter = '$q_submitter'";
|
||||
}
|
||||
if ($q_min_score != null) {
|
||||
$conds[] = "score >= $q_min_score";
|
||||
}
|
||||
if ($q_max_score != null) {
|
||||
$conds[] = "score <= $q_max_score";
|
||||
}
|
||||
if ($q_language != null) {
|
||||
$conds[] = sprintf("language = '%s'", DB::escape($q_language));
|
||||
}
|
||||
|
||||
$html_esc_q_language = htmlspecialchars($q_language);
|
||||
|
||||
if ($conds) {
|
||||
$cond = join($conds, ' and ');
|
||||
} else {
|
||||
$cond = '1';
|
||||
}
|
||||
?>
|
||||
if (!$conds) {
|
||||
$conds = '1';
|
||||
}
|
||||
?>
|
||||
<?php echoUOJPageHeader(UOJLocale::get('submissions')) ?>
|
||||
|
||||
<h1 class="h2">
|
||||
<h1>
|
||||
<?= UOJLocale::get('submissions') ?>
|
||||
</h1>
|
||||
|
||||
@ -51,17 +54,17 @@
|
||||
<form id="form-search" class="row gy-2 gx-3 align-items-end mb-3" target="_self" method="GET">
|
||||
<div id="form-group-problem_id" class="col-auto">
|
||||
<label for="input-problem_id" class="form-label">
|
||||
<?= UOJLocale::get('problems::problem id')?>:
|
||||
<?= UOJLocale::get('problems::problem id') ?>:
|
||||
</label>
|
||||
<input type="text" class="form-control form-control-sm" name="problem_id" id="input-problem_id" value="<?= $q_problem_id ?>" style="width:4em" />
|
||||
</div>
|
||||
<div id="form-group-submitter" class="col-auto">
|
||||
<label for="input-submitter" class="control-label">
|
||||
<?= UOJLocale::get('username')?>:
|
||||
<?= UOJLocale::get('username') ?>:
|
||||
</label>
|
||||
<div class="input-group input-group-sm">
|
||||
<input type="text" class="form-control form-control-sm" name="submitter" id="input-submitter" value="<?= $q_submitter ?>" maxlength="20" style="width:10em" />
|
||||
<?php if (Auth::check()): ?>
|
||||
<?php if (Auth::check()) : ?>
|
||||
<a id="my-submissions" href="/submissions?submitter=<?= Auth::id() ?>" class="btn btn-outline-secondary btn-sm">
|
||||
我的
|
||||
</a>
|
||||
@ -77,7 +80,7 @@
|
||||
</div>
|
||||
<div id="form-group-score" class="col-auto">
|
||||
<label for="input-min_score" class="control-label">
|
||||
<?= UOJLocale::get('score range')?>:
|
||||
<?= UOJLocale::get('score range') ?>:
|
||||
</label>
|
||||
<div class="input-group input-group-sm">
|
||||
<input type="text" class="form-control" name="min_score" id="input-min_score" value="<?= $q_min_score ?>" maxlength="3" style="width:4em" placeholder="0" />
|
||||
@ -86,31 +89,20 @@
|
||||
</div>
|
||||
</div>
|
||||
<div id="form-group-language" class="col-auto">
|
||||
<label for="input-language" class="control-label"><?= UOJLocale::get('problems::language')?>:</label>
|
||||
<label for="input-language" class="control-label"><?= UOJLocale::get('problems::language') ?>:</label>
|
||||
<select class="form-select form-select-sm" id="input-language" name="language">
|
||||
<option value="">All</option>
|
||||
<?php foreach ($uojSupportedLanguages as $lang): ?>
|
||||
<option value="<?= HTML::escape($lang) ?>" <?= $lang == $q_language ? 'selected' : '' ?>><?= HTML::escape($lang) ?></option>
|
||||
<?php foreach (UOJLang::$supported_languages as $name => $lang) : ?>
|
||||
<option value="<?= HTML::escape($name) ?>" <?= $name == $q_lang ? 'selected' : '' ?>><?= HTML::escape($lang) ?></option>
|
||||
<?php endforeach ?>
|
||||
</select>
|
||||
</div>
|
||||
<div class="col-auto">
|
||||
<button type="submit" id="submit-search" class="btn btn-secondary btn-sm ml-2"><?= UOJLocale::get('search')?></button>
|
||||
<button type="submit" id="submit-search" class="btn btn-secondary btn-sm ml-2"><?= UOJLocale::get('search') ?></button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<?php
|
||||
echoSubmissionsList($cond,
|
||||
'order by id desc',
|
||||
[
|
||||
'judge_time_hidden' => '',
|
||||
'table_config' => [
|
||||
'div_classes' => ['card', 'mb-3', 'table-responsive'],
|
||||
'table_classes' => ['table', 'mb-0', 'uoj-table', 'text-center'],
|
||||
]
|
||||
],
|
||||
$myUser);
|
||||
?>
|
||||
<?php echoSubmissionsList($conds, 'order by id desc', $config, Auth::user()) ?>
|
||||
|
||||
<?php echoUOJPageFooter() ?>
|
||||
|
@ -1,23 +1,21 @@
|
||||
<?php
|
||||
requireLib('bootstrap5');
|
||||
requireLib('md5');
|
||||
requireLib('jquery.query');
|
||||
requirePHPLib('form');
|
||||
requirePHPLib('judger');
|
||||
requireLib('bootstrap5');
|
||||
requireLib('md5');
|
||||
requireLib('jquery.query');
|
||||
requirePHPLib('form');
|
||||
requirePHPLib('judger');
|
||||
|
||||
define('SCRIPT_REFRESH_AS_GET', '<script>;window.location = window.location.origin + window.location.pathname + (window.location.search.length ? window.location.search + "&" : "?") + "_=" + (+new Date()) + window.location.hash;</script>');
|
||||
|
||||
if (!Auth::check()) {
|
||||
if (!Auth::check()) {
|
||||
redirectToLogin();
|
||||
}
|
||||
}
|
||||
|
||||
if (!isSuperUser($myUser)) {
|
||||
if (!isSuperUser($myUser)) {
|
||||
become403Page();
|
||||
}
|
||||
}
|
||||
|
||||
$cur_tab = isset($_GET['tab']) ? $_GET['tab'] : 'index';
|
||||
$cur_tab = isset($_GET['tab']) ? $_GET['tab'] : 'index';
|
||||
|
||||
$tabs_info = [
|
||||
$tabs_info = [
|
||||
'index' => [
|
||||
'name' => '首页管理',
|
||||
'url' => "/super_manage/index",
|
||||
@ -42,33 +40,56 @@
|
||||
'name' => '图床管理',
|
||||
'url' => "/super_manage/image_hosting",
|
||||
],
|
||||
];
|
||||
];
|
||||
|
||||
if (!isset($tabs_info[$cur_tab])) {
|
||||
if (!isset($tabs_info[$cur_tab])) {
|
||||
become404Page();
|
||||
}
|
||||
}
|
||||
|
||||
if ($cur_tab == 'index') {
|
||||
if ($cur_tab == 'index') {
|
||||
// ========== 公告 ==========
|
||||
if (isset($_POST['submit-delete_announcement']) && $_POST['submit-delete_announcement'] == 'delete_announcement') {
|
||||
if (UOJRequest::post('submit-delete_announcement') === 'delete_announcement') {
|
||||
crsf_defend();
|
||||
|
||||
$blog_id = $_POST['blog_id'];
|
||||
$blog_id = UOJRequest::post('blog_id');
|
||||
|
||||
if (!validateUInt($blog_id)) {
|
||||
dieWithAlert('移除失败:博客 ID 无效');
|
||||
}
|
||||
|
||||
DB::delete("DELETE FROM important_blogs WHERE blog_id = {$blog_id}");
|
||||
DB::delete([
|
||||
"delete from important_blogs",
|
||||
"where", [
|
||||
"blog_id" => $blog_id,
|
||||
]
|
||||
]);
|
||||
|
||||
dieWithAlert('移除成功!');
|
||||
}
|
||||
|
||||
$announcements = DB::selectAll("SELECT blogs.id as id, blogs.title as title, blogs.poster as poster, user_info.realname as realname, blogs.post_time as post_time, important_blogs.level as level, blogs.is_hidden as is_hidden FROM important_blogs INNER JOIN blogs ON important_blogs.blog_id = blogs.id INNER JOIN user_info ON blogs.poster = user_info.username ORDER BY level DESC, important_blogs.blog_id DESC");
|
||||
$announcements = DB::selectAll([
|
||||
"select", DB::fields([
|
||||
"id" => "blogs.id",
|
||||
"title" => "blogs.title",
|
||||
"poster" => "blogs.poster",
|
||||
"realname" => "user_info.realname",
|
||||
"post_time" => "blogs.post_time",
|
||||
"level" => "important_blogs.level",
|
||||
"is_hidden" => "blogs.is_hidden",
|
||||
]),
|
||||
"from blogs",
|
||||
"inner join important_blogs on important_blogs.blog_id = blogs.id",
|
||||
"inner join user_info on blogs.poster = user_info.username",
|
||||
"order by level desc, important_blogs.blog_id desc",
|
||||
]);
|
||||
|
||||
$add_announcement_form = new UOJForm('add_announcement');
|
||||
$add_announcement_form->addInput('blog_id', 'text', '博客 ID', '',
|
||||
function($id, &$vdata) {
|
||||
$add_announcement_form = new UOJBs4Form('add_announcement');
|
||||
$add_announcement_form->addInput(
|
||||
'blog_id',
|
||||
'text',
|
||||
'博客 ID',
|
||||
'',
|
||||
function ($id, &$vdata) {
|
||||
if (!validateUInt($id)) {
|
||||
return '博客 ID 无效';
|
||||
}
|
||||
@ -83,7 +104,11 @@
|
||||
},
|
||||
null
|
||||
);
|
||||
$add_announcement_form->addInput('blog_level', 'text', '置顶级别', '0',
|
||||
$add_announcement_form->addInput(
|
||||
'blog_level',
|
||||
'text',
|
||||
'置顶级别',
|
||||
'0',
|
||||
function ($x, &$vdata) {
|
||||
if (!validateUInt($x)) {
|
||||
return '数字不合法';
|
||||
@ -99,14 +124,32 @@
|
||||
},
|
||||
null
|
||||
);
|
||||
$add_announcement_form->handle = function(&$vdata) {
|
||||
$add_announcement_form->handle = function (&$vdata) {
|
||||
$blog_id = $vdata['blog_id'];
|
||||
$blog_level = $vdata['level'];
|
||||
|
||||
if (DB::selectFirst("select * from important_blogs where blog_id = {$blog_id}")) {
|
||||
DB::update("update important_blogs set level = {$blog_level} where blog_id = {$blog_id}");
|
||||
if (DB::selectExists([
|
||||
"select * from important_blogs",
|
||||
"where", [
|
||||
"blog_id" => $blog_id,
|
||||
]
|
||||
])) {
|
||||
DB::update([
|
||||
"update important_blogs",
|
||||
"set", [
|
||||
"level" => $blog_level,
|
||||
],
|
||||
"where", [
|
||||
"blog_id" => $blog_id,
|
||||
]
|
||||
]);
|
||||
} else {
|
||||
DB::insert("insert into important_blogs (blog_id, level) values ({$blog_id}, {$blog_level})");
|
||||
DB::insert([
|
||||
"insert into important_blogs",
|
||||
DB::bracketed_fields(["blog_id", "level"]),
|
||||
"values",
|
||||
DB::tuple([$blog_id, $blog_level]),
|
||||
]);
|
||||
}
|
||||
};
|
||||
$add_announcement_form->submit_button_config['align'] = 'compressed';
|
||||
@ -115,25 +158,38 @@
|
||||
$add_announcement_form->runAtServer();
|
||||
|
||||
// ========== 倒计时 ==========
|
||||
if (isset($_POST['submit-delete_countdown']) && $_POST['submit-delete_countdown'] == 'delete_countdown') {
|
||||
if (UOJRequest::post('submit-delete_countdown') === 'delete_countdown') {
|
||||
crsf_defend();
|
||||
|
||||
$countdown_id = $_POST['countdown_id'];
|
||||
$countdown_id = UOJRequest::post('countdown_id');
|
||||
|
||||
if (!validateUInt($countdown_id)) {
|
||||
dieWithAlert('删除失败:倒计时 ID 无效');
|
||||
}
|
||||
|
||||
DB::delete("DELETE FROM countdowns WHERE id = {$countdown_id}");
|
||||
DB::delete([
|
||||
"delete from countdowns",
|
||||
"where", [
|
||||
"id" => $countdown_id,
|
||||
]
|
||||
]);
|
||||
|
||||
dieWithAlert('删除成功!');
|
||||
}
|
||||
|
||||
$countdowns = DB::selectAll("SELECT id, title, end_time FROM countdowns ORDER BY end_time ASC");
|
||||
$countdowns = DB::selectAll([
|
||||
"select", DB::fields(["id", "title", "end_time"]),
|
||||
"from countdowns",
|
||||
"order by end_time asc",
|
||||
]);
|
||||
|
||||
$add_countdown_form = new UOJForm('add_countdown');
|
||||
$add_countdown_form->addInput('countdown_title', 'text', '标题', '',
|
||||
function($title, &$vdata) {
|
||||
$add_countdown_form = new UOJBs4Form('add_countdown');
|
||||
$add_countdown_form->addInput(
|
||||
'countdown_title',
|
||||
'text',
|
||||
'标题',
|
||||
'',
|
||||
function ($title, &$vdata) {
|
||||
if ($title == '') {
|
||||
return '标题不能为空';
|
||||
}
|
||||
@ -144,8 +200,12 @@
|
||||
},
|
||||
null
|
||||
);
|
||||
$add_countdown_form->addInput('countdown_end_time', 'text', '结束时间', date("Y-m-d H:i:s"),
|
||||
function($end_time, &$vdata) {
|
||||
$add_countdown_form->addInput(
|
||||
'countdown_end_time',
|
||||
'text',
|
||||
'结束时间',
|
||||
date("Y-m-d H:i:s"),
|
||||
function ($end_time, &$vdata) {
|
||||
try {
|
||||
$vdata['end_time'] = new DateTime($end_time);
|
||||
} catch (Exception $e) {
|
||||
@ -156,11 +216,13 @@
|
||||
},
|
||||
null
|
||||
);
|
||||
$add_countdown_form->handle = function(&$vdata) {
|
||||
$esc_title = DB::escape($vdata['title']);
|
||||
$esc_end_time = DB::escape($vdata['end_time']->format('Y-m-d H:i:s'));
|
||||
|
||||
DB::insert("INSERT INTO countdowns (title, end_time) VALUES ('{$esc_title}', '{$esc_end_time}')");
|
||||
$add_countdown_form->handle = function (&$vdata) {
|
||||
DB::insert([
|
||||
"insert into countdowns",
|
||||
DB::bracketed_fields(["title", "end_time"]),
|
||||
"values",
|
||||
DB::tuple([$vdata['title'], $vdata['end_time']->format('Y-m-d H:i:s')]),
|
||||
]);
|
||||
};
|
||||
$add_countdown_form->submit_button_config['align'] = 'compressed';
|
||||
$add_countdown_form->submit_button_config['text'] = '添加';
|
||||
@ -168,25 +230,38 @@
|
||||
$add_countdown_form->runAtServer();
|
||||
|
||||
// ========== 常用链接 ==========
|
||||
if (isset($_POST['submit-delete_link']) && $_POST['submit-delete_link'] == 'delete_link') {
|
||||
if (UOJRequest::post('submit-delete_link') === 'delete_link') {
|
||||
crsf_defend();
|
||||
|
||||
$item_id = $_POST['item_id'];
|
||||
$link_id = UOJRequest::post('link_id');
|
||||
|
||||
if (!validateUInt($item_id)) {
|
||||
if (!validateUInt($link_id)) {
|
||||
dieWithAlert('删除失败:ID 无效');
|
||||
}
|
||||
|
||||
DB::delete("DELETE FROM links WHERE id = {$item_id}");
|
||||
DB::delete([
|
||||
"delete from friend_links",
|
||||
"where", [
|
||||
"id" => $link_id,
|
||||
]
|
||||
]);
|
||||
|
||||
dieWithAlert('删除成功!');
|
||||
}
|
||||
|
||||
$links = DB::selectAll("SELECT `id`, `title`, `url`, `level` FROM `friend_links` ORDER BY `level` DESC, `id` ASC");
|
||||
$links = DB::selectAll([
|
||||
"select", DB::fields(["id", "title", "url", "level"]),
|
||||
"from friend_links",
|
||||
"order by level desc, id asc",
|
||||
]);
|
||||
|
||||
$add_link_form = new UOJForm('add_link');
|
||||
$add_link_form->addInput('link_title', 'text', '标题', '',
|
||||
function($title, &$vdata) {
|
||||
$add_link_form = new UOJBs4Form('add_link');
|
||||
$add_link_form->addInput(
|
||||
'link_title',
|
||||
'text',
|
||||
'标题',
|
||||
'',
|
||||
function ($title, &$vdata) {
|
||||
if ($title == '') {
|
||||
return '标题不能为空';
|
||||
}
|
||||
@ -197,8 +272,12 @@
|
||||
},
|
||||
null
|
||||
);
|
||||
$add_link_form->addInput('link_url', 'text', '链接', '',
|
||||
function($url, &$vdata) {
|
||||
$add_link_form->addInput(
|
||||
'link_url',
|
||||
'text',
|
||||
'链接',
|
||||
'',
|
||||
function ($url, &$vdata) {
|
||||
if (!validateURL($url)) {
|
||||
return '链接不合法';
|
||||
}
|
||||
@ -209,8 +288,12 @@
|
||||
},
|
||||
null
|
||||
);
|
||||
$add_link_form->addInput('link_level', 'text', '权重', '10',
|
||||
function($level, &$vdata) {
|
||||
$add_link_form->addInput(
|
||||
'link_level',
|
||||
'text',
|
||||
'权重',
|
||||
'10',
|
||||
function ($level, &$vdata) {
|
||||
if (!validateUInt($level)) {
|
||||
return '数字不合法';
|
||||
}
|
||||
@ -221,18 +304,19 @@
|
||||
},
|
||||
null
|
||||
);
|
||||
$add_link_form->handle = function(&$vdata) {
|
||||
$esc_title = DB::escape($vdata['title']);
|
||||
$esc_url = DB::escape($vdata['url']);
|
||||
$level = $vdata['level'];
|
||||
|
||||
DB::insert("INSERT INTO friend_links (title, url, level) VALUES ('{$esc_title}', '{$esc_url}', {$level})");
|
||||
$add_link_form->handle = function (&$vdata) {
|
||||
DB::insert([
|
||||
"insert into friend_links",
|
||||
DB::bracketed_fields(["title", "url", "level"]),
|
||||
"values",
|
||||
DB::tuple([$vdata['title'], $vdata['url'], $vdata['level']]),
|
||||
]);
|
||||
};
|
||||
$add_link_form->submit_button_config['align'] = 'compressed';
|
||||
$add_link_form->submit_button_config['text'] = '添加';
|
||||
$add_link_form->succ_href = '/super_manage/index#links';
|
||||
$add_link_form->runAtServer();
|
||||
} elseif ($cur_tab == 'users') {
|
||||
} elseif ($cur_tab == 'users') {
|
||||
$user_list_cond = [];
|
||||
|
||||
if (isset($_GET['username']) && $_GET['username'] != "") {
|
||||
@ -246,13 +330,17 @@
|
||||
}
|
||||
|
||||
if ($user_list_cond) {
|
||||
$user_list_cond = join($user_list_cond, ' and ');
|
||||
$user_list_cond = implode(' and ', $user_list_cond);
|
||||
} else {
|
||||
$user_list_cond = '1';
|
||||
}
|
||||
|
||||
$register_form = new UOJForm('register');
|
||||
$register_form->addVInput('new_username', 'text', '用户名', '',
|
||||
$register_form = new UOJBs4Form('register');
|
||||
$register_form->addVInput(
|
||||
'new_username',
|
||||
'text',
|
||||
'用户名',
|
||||
'',
|
||||
function ($username, &$vdata) {
|
||||
if (!validateUsername($username)) {
|
||||
return '用户名不合法';
|
||||
@ -268,7 +356,11 @@
|
||||
},
|
||||
null
|
||||
);
|
||||
$register_form->addVInput('new_password', 'password', '密码', '',
|
||||
$register_form->addVInput(
|
||||
'new_password',
|
||||
'password',
|
||||
'密码',
|
||||
'',
|
||||
function ($password, &$vdata) {
|
||||
$vdata['password'] = $password;
|
||||
|
||||
@ -276,7 +368,11 @@
|
||||
},
|
||||
'validatePassword'
|
||||
);
|
||||
$register_form->addVInput('new_email', 'text', '电子邮件(选填)', '',
|
||||
$register_form->addVInput(
|
||||
'new_email',
|
||||
'text',
|
||||
'电子邮件(选填)',
|
||||
'',
|
||||
function ($email, &$vdata) {
|
||||
if ($email && !validateEmail($email)) {
|
||||
return '邮件地址不合法';
|
||||
@ -288,7 +384,11 @@
|
||||
},
|
||||
null
|
||||
);
|
||||
$register_form->addVInput('new_realname', 'text', '真实姓名(选填)', '',
|
||||
$register_form->addVInput(
|
||||
'new_realname',
|
||||
'text',
|
||||
'真实姓名(选填)',
|
||||
'',
|
||||
function ($realname, &$vdata) {
|
||||
$vdata['realname'] = $realname;
|
||||
|
||||
@ -296,7 +396,11 @@
|
||||
},
|
||||
null
|
||||
);
|
||||
$register_form->addVInput('new_school', 'text', '学校名称(选填)', '',
|
||||
$register_form->addVInput(
|
||||
'new_school',
|
||||
'text',
|
||||
'学校名称(选填)',
|
||||
'',
|
||||
function ($school, &$vdata) {
|
||||
$vdata['school'] = $school;
|
||||
|
||||
@ -304,16 +408,16 @@
|
||||
},
|
||||
null
|
||||
);
|
||||
$register_form->handle = function(&$vdata) {
|
||||
$username = $vdata['username'];
|
||||
$realname = DB::escape($vdata['realname']);
|
||||
$school = DB::escape($vdata['school']);
|
||||
$email = DB::escape($vdata['email']);
|
||||
$password = hash_hmac('md5', $vdata['password'], getPasswordClientSalt());
|
||||
$password = getPasswordToStore($password, $username);
|
||||
$svn_password = uojRandString(10);
|
||||
$register_form->handle = function (&$vdata) {
|
||||
$user = [
|
||||
'username' => $vdata['username'],
|
||||
'realname' => $vdata['realname'],
|
||||
'school' => $vdata['school'],
|
||||
'email' => $vdata['email'],
|
||||
'password' => hash_hmac('md5', $vdata['password'], getPasswordClientSalt()),
|
||||
];
|
||||
|
||||
DB::query("insert into user_info (username, realname, email, school, password, svn_password, register_time, usergroup) values ('$username', '$realname', '$email', '$school', '$password', '$svn_password', now(), 'U')");
|
||||
UOJUser::register($user, ['check_email' => false]);
|
||||
|
||||
dieWithJsonData(['status' => 'success', 'message' => '']);
|
||||
};
|
||||
@ -338,8 +442,12 @@
|
||||
EOD);
|
||||
$register_form->runAtServer();
|
||||
|
||||
$change_password_form = new UOJForm('change_password');
|
||||
$change_password_form->addVInput('p_username', 'text', '用户名', '',
|
||||
$change_password_form = new UOJBs4Form('change_password');
|
||||
$change_password_form->addVInput(
|
||||
'p_username',
|
||||
'text',
|
||||
'用户名',
|
||||
'',
|
||||
function ($username, &$vdata) {
|
||||
if (!validateUsername($username)) {
|
||||
return '用户名不合法';
|
||||
@ -355,7 +463,11 @@ EOD);
|
||||
},
|
||||
null
|
||||
);
|
||||
$change_password_form->addVInput('p_password', 'password', '密码', '',
|
||||
$change_password_form->addVInput(
|
||||
'p_password',
|
||||
'password',
|
||||
'密码',
|
||||
'',
|
||||
function ($password, &$vdata) {
|
||||
$vdata['password'] = $password;
|
||||
|
||||
@ -363,16 +475,22 @@ EOD);
|
||||
},
|
||||
'validatePassword'
|
||||
);
|
||||
$change_password_form->handle = function(&$vdata) {
|
||||
$esc_username = DB::escape($vdata['username']);
|
||||
$change_password_form->handle = function (&$vdata) {
|
||||
$password = hash_hmac('md5', $vdata['password'], getPasswordClientSalt());
|
||||
$esc_password = DB::escape(getPasswordToStore($password, $vdata['username']));
|
||||
|
||||
DB::query("update user_info set password = '$esc_password' where username = '$esc_username'");
|
||||
DB::update([
|
||||
"update user_info",
|
||||
"set", [
|
||||
"password" => getPasswordToStore($password, $vdata['username']),
|
||||
],
|
||||
"where", [
|
||||
"username" => $vdata['username'],
|
||||
],
|
||||
]);
|
||||
|
||||
dieWithJsonData(['status' => 'success', 'message' => '用户 ' . $vdata['username'] . ' 的密码已经被成功重置。']);
|
||||
};
|
||||
$change_password_form->submit_button_config['margin_class'] = 'mt-3';
|
||||
$change_password_form->submit_button_config['class_str'] = 'btn btn-secondary mt-3';
|
||||
$change_password_form->submit_button_config['text'] = '重置';
|
||||
$change_password_form->setAjaxSubmit(<<<EOD
|
||||
function(res) {
|
||||
@ -395,8 +513,12 @@ EOD);
|
||||
EOD);
|
||||
$change_password_form->runAtServer();
|
||||
|
||||
$change_usergroup_form = new UOJForm('change_usergroup');
|
||||
$change_usergroup_form->addVInput('username', 'text', '用户名', '',
|
||||
$change_usergroup_form = new UOJBs4Form('change_usergroup');
|
||||
$change_usergroup_form->addVInput(
|
||||
'username',
|
||||
'text',
|
||||
'用户名',
|
||||
'',
|
||||
function ($username, &$vdata) {
|
||||
if (!validateUsername($username)) {
|
||||
return '用户名不合法';
|
||||
@ -417,7 +539,7 @@ EOD);
|
||||
'normaluser' => '设为普通用户',
|
||||
'superuser' => '设为超级用户',
|
||||
], '操作类型', '');
|
||||
$change_usergroup_form->handle = function($vdata) {
|
||||
$change_usergroup_form->handle = function ($vdata) {
|
||||
$username = $vdata['username'];
|
||||
$usergroup = '';
|
||||
|
||||
@ -458,8 +580,8 @@ EOD);
|
||||
}
|
||||
EOD);
|
||||
$change_usergroup_form->runAtServer();
|
||||
} elseif ($cur_tab == 'submissions') {
|
||||
} elseif ($cur_tab == 'custom_test') {
|
||||
} elseif ($cur_tab == 'submissions') {
|
||||
} elseif ($cur_tab == 'custom_test') {
|
||||
requireLib('hljs');
|
||||
|
||||
$submissions_pag = new Paginator([
|
||||
@ -470,8 +592,12 @@ EOD);
|
||||
'page_len' => 10
|
||||
]);
|
||||
|
||||
$custom_test_deleter = new UOJForm('custom_test_deleter');
|
||||
$custom_test_deleter->addInput('last', 'text', '删除末尾记录', '5',
|
||||
$custom_test_deleter = new UOJBs4Form('custom_test_deleter');
|
||||
$custom_test_deleter->addInput(
|
||||
'last',
|
||||
'text',
|
||||
'删除末尾记录',
|
||||
'5',
|
||||
function ($x, &$vdata) {
|
||||
if (!validateUInt($x)) {
|
||||
return '不合法';
|
||||
@ -481,24 +607,28 @@ EOD);
|
||||
},
|
||||
null
|
||||
);
|
||||
$custom_test_deleter->handle = function(&$vdata) {
|
||||
$custom_test_deleter->handle = function (&$vdata) {
|
||||
$all = DB::selectAll("select * from custom_test_submissions order by id asc limit {$vdata['last']}");
|
||||
foreach ($all as $submission) {
|
||||
$content = json_decode($submission['content'], true);
|
||||
unlink(UOJContext::storagePath().$content['file_name']);
|
||||
unlink(UOJContext::storagePath() . $content['file_name']);
|
||||
}
|
||||
DB::delete("delete from custom_test_submissions order by id asc limit {$vdata['last']}");
|
||||
};
|
||||
$custom_test_deleter->submit_button_config['align'] = 'compressed';
|
||||
$custom_test_deleter->runAtServer();
|
||||
} elseif ($cur_tab == 'judger') {
|
||||
$judger_adder = new UOJForm('judger_adder');
|
||||
$judger_adder->addInput('judger_adder_name', 'text', '评测机名称', '',
|
||||
} elseif ($cur_tab == 'judger') {
|
||||
$judger_adder = new UOJBs4Form('judger_adder');
|
||||
$judger_adder->addInput(
|
||||
'judger_adder_name',
|
||||
'text',
|
||||
'评测机名称',
|
||||
'',
|
||||
function ($x, &$vdata) {
|
||||
if (!validateUsername($x)) {
|
||||
return '不合法';
|
||||
}
|
||||
if (DB::selectCount("select count(*) from judger_info where judger_name='$x'")!=0) {
|
||||
if (DB::selectCount("select count(*) from judger_info where judger_name='$x'") != 0) {
|
||||
return '不合法';
|
||||
}
|
||||
$vdata['name'] = $x;
|
||||
@ -506,20 +636,24 @@ EOD);
|
||||
},
|
||||
null
|
||||
);
|
||||
$judger_adder->handle = function(&$vdata) {
|
||||
$judger_adder->handle = function (&$vdata) {
|
||||
$password = uojRandString(32);
|
||||
DB::insert("insert into judger_info (judger_name,password) values('{$vdata['name']}','{$password}')");
|
||||
};
|
||||
$judger_adder->submit_button_config['align'] = 'compressed';
|
||||
$judger_adder->runAtServer();
|
||||
|
||||
$judger_deleter = new UOJForm('judger_deleter');
|
||||
$judger_deleter->addInput('judger_deleter_name', 'text', '评测机名称', '',
|
||||
$judger_deleter = new UOJBs4Form('judger_deleter');
|
||||
$judger_deleter->addInput(
|
||||
'judger_deleter_name',
|
||||
'text',
|
||||
'评测机名称',
|
||||
'',
|
||||
function ($x, &$vdata) {
|
||||
if (!validateUsername($x)) {
|
||||
return '不合法';
|
||||
}
|
||||
if (DB::selectCount("select count(*) from judger_info where judger_name='$x'")!=1) {
|
||||
if (DB::selectCount("select count(*) from judger_info where judger_name='$x'") != 1) {
|
||||
return '不合法';
|
||||
}
|
||||
$vdata['name'] = $x;
|
||||
@ -527,12 +661,12 @@ EOD);
|
||||
},
|
||||
null
|
||||
);
|
||||
$judger_deleter->handle = function(&$vdata) {
|
||||
$judger_deleter->handle = function (&$vdata) {
|
||||
DB::delete("delete from judger_info where judger_name='{$vdata['name']}'");
|
||||
};
|
||||
$judger_deleter->submit_button_config['align'] = 'compressed';
|
||||
$judger_deleter->runAtServer();
|
||||
} elseif ($cur_tab == 'image_hosting') {
|
||||
} elseif ($cur_tab == 'image_hosting') {
|
||||
if (isset($_POST['submit-delete_image']) && $_POST['submit-delete_image'] == 'delete_image') {
|
||||
crsf_defend();
|
||||
|
||||
@ -546,16 +680,19 @@ EOD);
|
||||
dieWithAlert('删除失败:图片不存在');
|
||||
}
|
||||
|
||||
unlink(UOJContext::storagePath().$result['path']);
|
||||
unlink(UOJContext::storagePath() . $result['path']);
|
||||
DB::delete("DELETE FROM users_images WHERE id = $image_id");
|
||||
|
||||
dieWithAlert('删除成功!');
|
||||
}
|
||||
|
||||
|
||||
$change_user_image_total_size_limit_form = new UOJForm('change_user_image_total_size_limit');
|
||||
$change_user_image_total_size_limit_form = new UOJBs4Form('change_user_image_total_size_limit');
|
||||
$change_user_image_total_size_limit_form->submit_button_config['align'] = 'compressed';
|
||||
$change_user_image_total_size_limit_form->addInput('change_user_image_total_size_limit_username', 'text', '用户名', '',
|
||||
$change_user_image_total_size_limit_form->addInput(
|
||||
'change_user_image_total_size_limit_username',
|
||||
'text',
|
||||
'用户名',
|
||||
'',
|
||||
function ($x, &$vdata) {
|
||||
if (!validateUsername($x)) {
|
||||
return '用户名不合法';
|
||||
@ -571,7 +708,11 @@ EOD);
|
||||
},
|
||||
null
|
||||
);
|
||||
$change_user_image_total_size_limit_form->addInput('change_user_image_total_size_limit_limit', 'text', '存储限制(单位:Byte)', '104857600',
|
||||
$change_user_image_total_size_limit_form->addInput(
|
||||
'change_user_image_total_size_limit_limit',
|
||||
'text',
|
||||
'存储限制(单位:Byte)',
|
||||
'104857600',
|
||||
function ($x, &$vdata) {
|
||||
if (!validateUInt($x, 10)) {
|
||||
return '限制不合法';
|
||||
@ -587,35 +728,41 @@ EOD);
|
||||
},
|
||||
null
|
||||
);
|
||||
|
||||
$change_user_image_total_size_limit_form->handle = function(&$vdata) {
|
||||
DB::update("UPDATE user_info SET images_size_limit = {$vdata['limit']} WHERE username = '{$vdata['username']}'");
|
||||
$change_user_image_total_size_limit_form->handle = function (&$vdata) {
|
||||
DB::update([
|
||||
"update user_info",
|
||||
"set", [
|
||||
'extra' => DB::json_set(
|
||||
'extra',
|
||||
'$.image_hosting.total_size_limit',
|
||||
$vdata['limit'],
|
||||
),
|
||||
],
|
||||
"where", ["username" => $vdata['username']]
|
||||
]);
|
||||
};
|
||||
|
||||
$change_user_image_total_size_limit_form->runAtServer();
|
||||
}
|
||||
?>
|
||||
}
|
||||
?>
|
||||
|
||||
<?php echoUOJPageHeader(UOJLocale::get('system manage')) ?>
|
||||
|
||||
<h1 class="h2">
|
||||
<h1>
|
||||
<?= UOJLocale::get('system manage') ?>
|
||||
</h1>
|
||||
|
||||
|
||||
<div class="row mt-4">
|
||||
<!-- left col -->
|
||||
<div class="col-md-3">
|
||||
<!-- left col -->
|
||||
<div class="col-md-3">
|
||||
<?= HTML::navListGroup($tabs_info, $cur_tab) ?>
|
||||
</div>
|
||||
<!-- end left col -->
|
||||
|
||||
<?= HTML::navListGroup($tabs_info, $cur_tab) ?>
|
||||
|
||||
</div>
|
||||
<!-- end left col -->
|
||||
|
||||
<!-- right col -->
|
||||
<div class="col-md-9">
|
||||
<?php if ($cur_tab == 'index'): ?>
|
||||
<div class="card mt-3 mt-md-0">
|
||||
<!-- right col -->
|
||||
<div class="col-md-9">
|
||||
<?php if ($cur_tab == 'index') : ?>
|
||||
<div class="card mt-3 mt-md-0">
|
||||
<div class="card-header">
|
||||
<ul class="nav nav-tabs card-header-tabs" role="tablist">
|
||||
<li class="nav-item">
|
||||
@ -676,8 +823,7 @@ EOD);
|
||||
col_tr += '</tr>';
|
||||
|
||||
return col_tr;
|
||||
},
|
||||
{
|
||||
}, {
|
||||
div_classes: ['table-responsive'],
|
||||
table_classes: ['table', 'align-middle'],
|
||||
page_len: 20,
|
||||
@ -722,8 +868,7 @@ EOD);
|
||||
col_tr += '</tr>';
|
||||
|
||||
return col_tr;
|
||||
},
|
||||
{
|
||||
}, {
|
||||
div_classes: ['table-responsive'],
|
||||
table_classes: ['table', 'align-middle'],
|
||||
page_len: 20,
|
||||
@ -770,8 +915,7 @@ EOD);
|
||||
col_tr += '</tr>';
|
||||
|
||||
return col_tr;
|
||||
},
|
||||
{
|
||||
}, {
|
||||
div_classes: ['table-responsive'],
|
||||
table_classes: ['table', 'align-middle'],
|
||||
page_len: 20,
|
||||
@ -784,10 +928,10 @@ EOD);
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
$(document).ready(function() {
|
||||
<script>
|
||||
$(document).ready(function() {
|
||||
// Javascript to enable link to tab
|
||||
var hash = location.hash.replace(/^#/, '');
|
||||
if (hash) {
|
||||
@ -798,10 +942,10 @@ $(document).ready(function() {
|
||||
$('.nav-tabs a').on('shown.bs.tab', function(e) {
|
||||
window.location.hash = e.target.hash;
|
||||
});
|
||||
});
|
||||
</script>
|
||||
<?php elseif ($cur_tab == 'users'): ?>
|
||||
<div class="card mt-3 mt-md-0">
|
||||
});
|
||||
</script>
|
||||
<?php elseif ($cur_tab == 'users') : ?>
|
||||
<div class="card mt-3 mt-md-0">
|
||||
<div class="card-header">
|
||||
<ul class="nav nav-tabs card-header-tabs">
|
||||
<li class="nav-item">
|
||||
@ -837,12 +981,8 @@ $(document).ready(function() {
|
||||
'S' => 'S: 超级用户',
|
||||
];
|
||||
?>
|
||||
<?php foreach ($usergroups as $name => $group): ?>
|
||||
<option value="<?= $name ?>"
|
||||
<?php if ($_GET['usergroup'] == $name): ?>
|
||||
selected
|
||||
<?php endif ?>
|
||||
><?= $group ?></option>
|
||||
<?php foreach ($usergroups as $name => $group) : ?>
|
||||
<option value="<?= $name ?>" <?php if ($_GET['usergroup'] == $name) : ?> selected <?php endif ?>><?= $group ?></option>
|
||||
<?php endforeach ?>
|
||||
</select>
|
||||
</div>
|
||||
@ -857,15 +997,10 @@ $(document).ready(function() {
|
||||
'problem_uploader' => 'problem_uploader: 题目上传者',
|
||||
'problem_manager' => 'problem_manager: 题目管理员',
|
||||
'contest_judger' => 'contest_judger: 比赛评测员',
|
||||
'contest_only' => 'contest_only: 仅比赛参加者',
|
||||
];
|
||||
?>
|
||||
<?php foreach ($usertypes as $name => $type): ?>
|
||||
<option value="<?= $name ?>"
|
||||
<?php if ($_GET['usertype'] == $name): ?>
|
||||
selected
|
||||
<?php endif ?>
|
||||
><?= $type ?></option>
|
||||
<?php foreach ($usertypes as $name => $type) : ?>
|
||||
<option value="<?= $name ?>" <?php if ($_GET['usertype'] == $name) : ?> selected <?php endif ?>><?= $type ?></option>
|
||||
<?php endforeach ?>
|
||||
</select>
|
||||
</div>
|
||||
@ -889,7 +1024,7 @@ $(document).ready(function() {
|
||||
<th>操作</th>
|
||||
</tr>
|
||||
EOD,
|
||||
function($row) {
|
||||
function ($row) {
|
||||
echo '<tr>';
|
||||
echo '<td>', '<span class="uoj-username" data-realname="', HTML::escape($row['realname']), '">', $row['username'], '</span>', '</td>';
|
||||
echo '<td>', HTML::escape($row['school']), '</td>';
|
||||
@ -978,10 +1113,10 @@ EOD,
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
$(document).ready(function() {
|
||||
<script>
|
||||
$(document).ready(function() {
|
||||
// Javascript to enable link to tab
|
||||
var hash = location.hash.replace(/^#/, '');
|
||||
if (hash) {
|
||||
@ -992,12 +1127,12 @@ $(document).ready(function() {
|
||||
$('.nav-tabs a').on('shown.bs.tab', function(e) {
|
||||
window.location.hash = e.target.hash;
|
||||
});
|
||||
});
|
||||
</script>
|
||||
<?php elseif ($cur_tab === 'submissions'): ?>
|
||||
<h4>测评失败的提交记录</h4>
|
||||
<?php
|
||||
echoSubmissionsList(
|
||||
});
|
||||
</script>
|
||||
<?php elseif ($cur_tab === 'submissions') : ?>
|
||||
<h4>测评失败的提交记录</h4>
|
||||
<?php
|
||||
echoSubmissionsList(
|
||||
"result_error = 'Judgement Failed'",
|
||||
'order by id desc',
|
||||
[
|
||||
@ -1008,9 +1143,9 @@ echoSubmissionsList(
|
||||
]
|
||||
],
|
||||
$myUser
|
||||
);
|
||||
);
|
||||
?>
|
||||
<?php elseif ($cur_tab === 'custom_test'): ?>
|
||||
<?php elseif ($cur_tab === 'custom_test') : ?>
|
||||
<div class="card mb-3 table-responsive">
|
||||
<table class="table uoj-table mb-0">
|
||||
<thead>
|
||||
@ -1023,7 +1158,7 @@ echoSubmissionsList(
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php foreach ($submissions_pag->get() as $submission): ?>
|
||||
<?php foreach ($submissions_pag->get() as $submission) : ?>
|
||||
<?php
|
||||
$problem = queryProblemBrief($submission['problem_id']);
|
||||
$submission_result = json_decode($submission['result'], true);
|
||||
@ -1042,7 +1177,7 @@ echoSubmissionsList(
|
||||
</td>
|
||||
</tr>
|
||||
<?php endforeach ?>
|
||||
<?php if ($submissions_pag->isEmpty()): ?>
|
||||
<?php if ($submissions_pag->isEmpty()) : ?>
|
||||
<tr>
|
||||
<td class="text-center" colspan="233">
|
||||
<?= UOJLocale::get('none') ?>
|
||||
@ -1060,7 +1195,7 @@ echoSubmissionsList(
|
||||
<?php $custom_test_deleter->printHTML() ?>
|
||||
</div>
|
||||
</div>
|
||||
<?php elseif ($cur_tab == 'judger'): ?>
|
||||
<?php elseif ($cur_tab == 'judger') : ?>
|
||||
<h3>评测机列表</h3>
|
||||
<?php
|
||||
echoLongTable(
|
||||
@ -1075,7 +1210,7 @@ echoSubmissionsList(
|
||||
<th>IP</th>
|
||||
</tr>
|
||||
EOD,
|
||||
function($row) {
|
||||
function ($row) {
|
||||
echo <<<EOD
|
||||
<tr>
|
||||
<td>{$row['judger_name']}</td>
|
||||
@ -1099,8 +1234,8 @@ EOD;
|
||||
<?php $judger_deleter->printHTML(); ?>
|
||||
</div>
|
||||
</div>
|
||||
<?php elseif ($cur_tab == 'image_hosting'): ?>
|
||||
<?php
|
||||
<?php elseif ($cur_tab == 'image_hosting') : ?>
|
||||
<?php
|
||||
echoLongTable(
|
||||
['*'],
|
||||
'users_images',
|
||||
@ -1115,7 +1250,7 @@ EOD;
|
||||
<th style="width: 6em">操作</th>
|
||||
</tr>
|
||||
EOD,
|
||||
function($row) {
|
||||
function ($row) {
|
||||
$user_link = getUserLink($row['uploader']);
|
||||
if ($row['size'] < 1024 * 512) {
|
||||
$size = strval(round($row['size'] * 1.0 / 1024, 1)) . ' KB';
|
||||
@ -1152,9 +1287,9 @@ EOD;
|
||||
<?php $change_user_image_total_size_limit_form->printHTML() ?>
|
||||
</div>
|
||||
</div>
|
||||
<?php endif ?>
|
||||
</div>
|
||||
<!-- end right col -->
|
||||
<?php endif ?>
|
||||
</div>
|
||||
<!-- end right col -->
|
||||
</div>
|
||||
|
||||
<?php echoUOJPageFooter() ?>
|
||||
|
@ -2,23 +2,15 @@
|
||||
requireLib('bootstrap5');
|
||||
requireLib('calendar_heatmap');
|
||||
|
||||
if (!Auth::check() && UOJConfig::$data['switch']['force-login']) {
|
||||
if (!Auth::check()) {
|
||||
redirectToLogin();
|
||||
}
|
||||
|
||||
if (!isNormalUser($myUser) && UOJConfig::$data['switch']['force-login']) {
|
||||
become403Page();
|
||||
}
|
||||
|
||||
$username = $_GET['username'];
|
||||
|
||||
if (!validateUsername($username) || !($user = queryUser($username))) {
|
||||
become404Page();
|
||||
}
|
||||
($user = UOJUser::query($_GET['username'])) || UOJResponse::page404();
|
||||
?>
|
||||
|
||||
<?php echoUOJPageHeader($user['username'] . ' - ' . UOJLocale::get('user profile')) ?>
|
||||
|
||||
<?php uojIncludeView('user-info', array('user' => $user, 'myUser' => $myUser)) ?>
|
||||
<?php uojIncludeView('user-info', ['user' => $user]) ?>
|
||||
|
||||
<?php echoUOJPageFooter() ?>
|
||||
|
@ -1,27 +1,23 @@
|
||||
<?php
|
||||
requireLib('bootstrap5');
|
||||
requireLib('md5');
|
||||
requirePHPLib('form');
|
||||
requireLib('bootstrap5');
|
||||
requireLib('md5');
|
||||
requirePHPLib('form');
|
||||
|
||||
if (!Auth::check()) {
|
||||
if (!Auth::check()) {
|
||||
redirectToLogin();
|
||||
}
|
||||
}
|
||||
|
||||
if (!validateUsername($_GET['username']) || !($user = queryUser($_GET['username']))) {
|
||||
become404Page();
|
||||
}
|
||||
($user = UOJUser::query($_GET['username'])) || UOJResponse::page404();
|
||||
(isSuperUser(Auth::user()) || Auth::id() == $user['username']) || UOJResponse::page403();
|
||||
$extra = UOJUser::getExtra($user);
|
||||
|
||||
if (!isSuperUser($myUser) && $myUser['username'] != $user['username']) {
|
||||
become403Page();
|
||||
}
|
||||
|
||||
if (isset($_GET['tab'])) {
|
||||
if (isset($_GET['tab'])) {
|
||||
$cur_tab = $_GET['tab'];
|
||||
} else {
|
||||
} else {
|
||||
$cur_tab = 'profile';
|
||||
}
|
||||
}
|
||||
|
||||
$tabs_info = [
|
||||
$tabs_info = [
|
||||
'profile' => [
|
||||
'name' => '<i class="bi bi-person-fill"></i> 个人资料',
|
||||
'url' => "/user/{$user['username']}/edit/profile",
|
||||
@ -34,14 +30,14 @@
|
||||
'name' => '<i class="bi bi-key-fill"></i> 特权',
|
||||
'url' => "/user/{$user['username']}/edit/privilege",
|
||||
]
|
||||
];
|
||||
];
|
||||
|
||||
if (!isset($tabs_info[$cur_tab])) {
|
||||
if (!isset($tabs_info[$cur_tab])) {
|
||||
become404Page();
|
||||
}
|
||||
}
|
||||
|
||||
if ($cur_tab == 'profile') {
|
||||
$update_profile_form = new UOJForm('update_profile');
|
||||
if ($cur_tab == 'profile') {
|
||||
$update_profile_form = new UOJBs4Form('update_profile');
|
||||
$username = UOJLocale::get('username');
|
||||
$avatar = UOJLocale::get('avatar');
|
||||
$update_profile_form->appendHTML(<<<EOD
|
||||
@ -51,13 +47,19 @@
|
||||
<div id="help-username" class="form-text">用户名不能被修改。</div>
|
||||
</div>
|
||||
EOD);
|
||||
if (isSuperUser($myUser)) {
|
||||
$update_profile_form->addVInput('realname', 'text', UOJLocale::get('user::real name'), $user['realname'],
|
||||
function($realname, &$vdata) {
|
||||
if (isSuperUser(Auth::user())) {
|
||||
$update_profile_form->addVInput(
|
||||
'realname',
|
||||
'text',
|
||||
UOJLocale::get('user::real name'),
|
||||
$user['realname'],
|
||||
function ($realname, &$vdata) {
|
||||
$vdata['realname'] = $realname;
|
||||
|
||||
return '';
|
||||
}, null);
|
||||
},
|
||||
null
|
||||
);
|
||||
} else {
|
||||
$real_name = UOJLocale::get('user::real name');
|
||||
$update_profile_form->appendHTML(<<<EOD
|
||||
@ -71,15 +73,19 @@ EOD);
|
||||
$update_profile_form->addVCheckboxes('avatar_source', [
|
||||
'gravatar' => 'Gravatar',
|
||||
'qq' => 'QQ',
|
||||
], UOJLocale::get('user::avatar source'), $user['avatar_source']);
|
||||
], UOJLocale::get('user::avatar source'), $extra['avatar_source'] ?: 'gravatar');
|
||||
$change_avatar_help = UOJLocale::get('change avatar help');
|
||||
$update_profile_form->appendHTML(<<<EOD
|
||||
<div style="margin-top: -1.25rem;" class="mb-3 small text-muted">
|
||||
$change_avatar_help
|
||||
</div>
|
||||
EOD);
|
||||
$update_profile_form->addVInput('email', 'email', UOJLocale::get('email'), $user['email'],
|
||||
function($email, &$vdata) {
|
||||
$update_profile_form->addVInput(
|
||||
'email',
|
||||
'email',
|
||||
UOJLocale::get('email'),
|
||||
$user['email'] ?: '',
|
||||
function ($email, &$vdata) {
|
||||
if (!validateEmail($email)) {
|
||||
return 'Email 格式不合法。';
|
||||
}
|
||||
@ -87,9 +93,15 @@ EOD);
|
||||
$vdata['email'] = $email;
|
||||
|
||||
return '';
|
||||
}, null);
|
||||
$update_profile_form->addVInput('qq', 'text', UOJLocale::get('QQ'), $user['qq'] == 0 ? '' : $user['qq'],
|
||||
function($qq, &$vdata) {
|
||||
},
|
||||
null
|
||||
);
|
||||
$update_profile_form->addVInput(
|
||||
'qq',
|
||||
'text',
|
||||
UOJLocale::get('QQ'),
|
||||
$user['qq'] == 0 ? '' : $user['qq'],
|
||||
function ($qq, &$vdata) {
|
||||
if ($qq && !validateQQ($qq)) {
|
||||
return 'QQ 格式不合法。';
|
||||
}
|
||||
@ -97,9 +109,15 @@ EOD);
|
||||
$vdata['qq'] = $qq;
|
||||
|
||||
return '';
|
||||
}, null);
|
||||
$update_profile_form->addVInput('github', 'text', 'GitHub', $user['github'],
|
||||
function($github, &$vdata) {
|
||||
},
|
||||
null
|
||||
);
|
||||
$update_profile_form->addVInput(
|
||||
'github',
|
||||
'text',
|
||||
'GitHub',
|
||||
$extra['social']['github'] ?: '',
|
||||
function ($github, &$vdata) {
|
||||
if ($github && !validateGitHubUsername($github)) {
|
||||
return 'GitHub 用户名不合法。';
|
||||
}
|
||||
@ -107,14 +125,22 @@ EOD);
|
||||
$vdata['github'] = $github;
|
||||
|
||||
return '';
|
||||
}, null);
|
||||
if (isSuperUser($myUser)) {
|
||||
$update_profile_form->addVInput('school', 'text', UOJLocale::get('school'), $user['school'],
|
||||
function($school, &$vdata) {
|
||||
},
|
||||
null
|
||||
);
|
||||
if (isSuperUser(Auth::user())) {
|
||||
$update_profile_form->addVInput(
|
||||
'school',
|
||||
'text',
|
||||
UOJLocale::get('school'),
|
||||
$user['school'] ?: '',
|
||||
function ($school, &$vdata) {
|
||||
$vdata['school'] = $school;
|
||||
|
||||
return '';
|
||||
}, null);
|
||||
},
|
||||
null
|
||||
);
|
||||
} else {
|
||||
$school = UOJLocale::get('school');
|
||||
$update_profile_form->appendHTML(<<<EOD
|
||||
@ -130,8 +156,12 @@ EOD);
|
||||
'M' => UOJLocale::get('male'),
|
||||
'F' => UOJLocale::get('female'),
|
||||
], UOJLocale::get('sex'), $user['sex']);
|
||||
$update_profile_form->addVInput('motto', 'text', UOJLocale::get('motto'), $user['motto'],
|
||||
function($motto, &$vdata) {
|
||||
$update_profile_form->addVInput(
|
||||
'motto',
|
||||
'text',
|
||||
UOJLocale::get('motto'),
|
||||
$user['motto'] ?: '',
|
||||
function ($motto, &$vdata) {
|
||||
if (!validateMotto($motto)) {
|
||||
return '格言格式不合法';
|
||||
}
|
||||
@ -139,19 +169,31 @@ EOD);
|
||||
$vdata['motto'] = $motto;
|
||||
|
||||
return '';
|
||||
}, null);
|
||||
$update_profile_form->addVInput('codeforces_handle', 'text', UOJLocale::get('codeforces handle'), $user['codeforces_handle'],
|
||||
function($codeforces_handle, &$vdata) {
|
||||
if ($codeforces_handle && !validateUsername($codeforces_handle)) {
|
||||
},
|
||||
null
|
||||
);
|
||||
$update_profile_form->addVInput(
|
||||
'codeforces',
|
||||
'text',
|
||||
UOJLocale::get('codeforces handle'),
|
||||
$extra['social']['codeforces'] ?: '',
|
||||
function ($codeforces, &$vdata) {
|
||||
if ($codeforces && !validateUsername($codeforces)) {
|
||||
return 'Codeforces 用户名格式不合法。';
|
||||
}
|
||||
|
||||
$vdata['codeforces_handle'] = $codeforces_handle;
|
||||
$vdata['codeforces'] = $codeforces;
|
||||
|
||||
return '';
|
||||
}, null);
|
||||
$update_profile_form->addVInput('website', 'text', UOJLocale::get('user::website'), $user['website'],
|
||||
function($url, &$vdata) {
|
||||
},
|
||||
null
|
||||
);
|
||||
$update_profile_form->addVInput(
|
||||
'website',
|
||||
'text',
|
||||
UOJLocale::get('user::website'),
|
||||
$extra['social']['website'] ?: '',
|
||||
function ($url, &$vdata) {
|
||||
if ($url && !validateURL($url)) {
|
||||
return '链接格式不合法。';
|
||||
}
|
||||
@ -159,29 +201,49 @@ EOD);
|
||||
$vdata['website'] = $url;
|
||||
|
||||
return '';
|
||||
}, null);
|
||||
$update_profile_form->handle = function(&$vdata) use ($user, $myUser) {
|
||||
$esc_email = DB::escape($vdata['email']);
|
||||
$esc_qq = DB::escape($vdata['qq']);
|
||||
$esc_github = DB::escape($vdata['github']);
|
||||
$esc_sex = DB::escape($_POST['sex']);
|
||||
$esc_motto = DB::escape($vdata['motto']);
|
||||
$esc_codeforces_handle = DB::escape($vdata['codeforces_handle']);
|
||||
$esc_website = DB::escape($vdata['website']);
|
||||
$esc_avatar_source = DB::escape($_POST['avatar_source']);
|
||||
},
|
||||
null
|
||||
);
|
||||
$update_profile_form->handle = function (&$vdata) use ($user) {
|
||||
$data = [
|
||||
'email' => $vdata['email'],
|
||||
'qq' => $vdata['qq'],
|
||||
'sex' => $_POST['sex'],
|
||||
'motto' => $vdata['motto'],
|
||||
];
|
||||
|
||||
if (isSuperUser($myUser)) {
|
||||
$esc_realname = DB::escape($vdata['realname']);
|
||||
$esc_school = DB::escape($vdata['school']);
|
||||
|
||||
DB::update("UPDATE user_info SET realname = '$esc_realname', school = '$esc_school' WHERE username = '{$user['username']}'");
|
||||
if (isSuperUser(Auth::user())) {
|
||||
$data['realname'] = $vdata['realname'];
|
||||
$data['school'] = $vdata['school'];
|
||||
}
|
||||
|
||||
DB::update("UPDATE user_info SET email = '$esc_email', qq = '$esc_qq', sex = '$esc_sex', motto = '$esc_motto', codeforces_handle = '$esc_codeforces_handle', github = '$esc_github', website = '$esc_website', avatar_source = '$esc_avatar_source' WHERE username = '{$user['username']}'");
|
||||
DB::update([
|
||||
"update user_info",
|
||||
"set", $data,
|
||||
"where", ["username" => $user['username']]
|
||||
]);
|
||||
|
||||
DB::update([
|
||||
"update user_info",
|
||||
"set", [
|
||||
'extra' => DB::json_set(
|
||||
'extra',
|
||||
'$.avatar_source',
|
||||
$_POST['avatar_source'],
|
||||
'$.social.github',
|
||||
$vdata['github'],
|
||||
'$.social.codeforces',
|
||||
$vdata['codeforces'],
|
||||
'$.social.website',
|
||||
$vdata['website']
|
||||
),
|
||||
],
|
||||
"where", ["username" => $user['username']]
|
||||
]);
|
||||
|
||||
dieWithJsonData(['status' => 'success']);
|
||||
};
|
||||
$update_profile_form->submit_button_config['margin_class'] = 'mt-3';
|
||||
$update_profile_form->submit_button_config['class_str'] = 'btn btn-secondary mt-3';
|
||||
$update_profile_form->submit_button_config['text'] = '更新';
|
||||
$update_profile_form->setAjaxSubmit(<<<EOD
|
||||
function(res) {
|
||||
@ -203,7 +265,7 @@ function(res) {
|
||||
}
|
||||
EOD);
|
||||
$update_profile_form->runAtServer();
|
||||
} elseif ($cur_tab == 'password') {
|
||||
} elseif ($cur_tab == 'password') {
|
||||
if (isset($_POST['submit-change_password']) && $_POST['submit-change_password'] == 'change_password') {
|
||||
$old_password = $_POST['current_password'];
|
||||
$new_password = $_POST['new_password'];
|
||||
@ -220,13 +282,18 @@ EOD);
|
||||
dieWithJsonData(['status' => 'error', 'message' => '新密码不能与旧密码相同']);
|
||||
}
|
||||
|
||||
$password = getPasswordToStore($new_password, $user['username']);
|
||||
DB::update("UPDATE `user_info` SET `password` = '$password' where `username` = '{$user['username']}'");
|
||||
DB::update([
|
||||
"update user_info",
|
||||
"set", [
|
||||
'password' => getPasswordToStore($new_password, $user['username']),
|
||||
],
|
||||
"where", ["username" => $user['username']]
|
||||
]);
|
||||
|
||||
dieWithJsonData(['status' => 'success', 'message' => '密码修改成功']);
|
||||
}
|
||||
} elseif ($cur_tab == 'privilege') {
|
||||
if (isset($_POST['submit-privilege']) && $_POST['submit-privilege'] == 'privilege' && isSuperUser($myUser)) {
|
||||
} elseif ($cur_tab == 'privilege') {
|
||||
if (isset($_POST['submit-privilege']) && $_POST['submit-privilege'] == 'privilege' && isSuperUser(Auth::user())) {
|
||||
$user['usertype'] = 'student';
|
||||
|
||||
if ($_POST['user_type'] == 'teacher') {
|
||||
@ -248,59 +315,52 @@ EOD);
|
||||
addUserType($user, 'contest_judger');
|
||||
}
|
||||
|
||||
if ($_POST['contest_only'] == 'yes') {
|
||||
addUserType($user, 'contest_only');
|
||||
}
|
||||
|
||||
DB::update("UPDATE `user_info` SET `usertype` = '{$user['usertype']}' where `username` = '{$user['username']}'");
|
||||
|
||||
dieWithJsonData(['status' => 'success', 'message' => '权限修改成功']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$pageTitle = $user['username'] == $myUser['username']
|
||||
$pageTitle = $user['username'] == Auth::id()
|
||||
? UOJLocale::get('modify my profile')
|
||||
: UOJLocale::get('modify his profile', $user['username'])
|
||||
?>
|
||||
?>
|
||||
|
||||
<?php echoUOJPageHeader($pageTitle) ?>
|
||||
|
||||
<h1 class="h2">
|
||||
<h1>
|
||||
<?= $pageTitle ?>
|
||||
</h1>
|
||||
|
||||
<div class="row mt-4">
|
||||
<!-- left col -->
|
||||
<div class="col-md-3">
|
||||
<!-- left col -->
|
||||
<div class="col-md-3">
|
||||
|
||||
<?= HTML::navListGroup($tabs_info, $cur_tab) ?>
|
||||
<?= HTML::navListGroup($tabs_info, $cur_tab) ?>
|
||||
|
||||
<a
|
||||
class="btn btn-light d-block mt-2 w-100 text-start text-primary"
|
||||
style="--bs-btn-hover-bg: #d3d4d570; --bs-btn-hover-border-color: transparent;"
|
||||
href="<?= HTML::url("/user/{$user['username']}") ?>">
|
||||
<a class="btn btn-light d-block mt-2 w-100 text-start text-primary" style="--bs-btn-hover-bg: #d3d4d570; --bs-btn-hover-border-color: transparent;" href="<?= HTML::url("/user/{$user['username']}") ?>">
|
||||
<i class="bi bi-arrow-left"></i> 返回
|
||||
</a>
|
||||
</a>
|
||||
|
||||
<?php if (isSuperUser($myUser) && $user['username'] != $myUser['username']): ?>
|
||||
<div class="alert alert-warning mt-3 small" role="alert">
|
||||
<?php if ($user['username'] != Auth::id()) : ?>
|
||||
<div class="alert alert-warning mt-3 small" role="alert">
|
||||
您正在使用管理特权查看并编辑其它用户的资料。
|
||||
</div>
|
||||
<?php endif ?>
|
||||
</div>
|
||||
<?php endif ?>
|
||||
|
||||
</div>
|
||||
<!-- end left col -->
|
||||
</div>
|
||||
<!-- end left col -->
|
||||
|
||||
<!-- right col -->
|
||||
<div class="col-md-9">
|
||||
<?php if ($cur_tab == 'profile'): ?>
|
||||
<!-- right col -->
|
||||
<div class="col-md-9">
|
||||
<?php if ($cur_tab == 'profile') : ?>
|
||||
<div class="card">
|
||||
<div class="card-body">
|
||||
<div id="result-alert" class="alert" role="alert" style="display: none"></div>
|
||||
<?php $update_profile_form->printHTML() ?>
|
||||
</div>
|
||||
</div>
|
||||
<?php elseif ($cur_tab == 'password'): ?>
|
||||
<?php elseif ($cur_tab == 'password') : ?>
|
||||
<div class="card">
|
||||
<div class="card-body">
|
||||
<div id="result-alert" class="alert" role="alert" style="display: none"></div>
|
||||
@ -326,7 +386,7 @@ EOD);
|
||||
<input type="password" class="form-control" id="input-confirm_password" placeholder="<?= UOJLocale::get('re-enter your new password') ?>" maxlength="20">
|
||||
<div id="help-confirm_password" class="invalid-feedback"></div>
|
||||
</div>
|
||||
<?php if (isSuperUser($myUser) && $user['username'] != $myUser['username']): ?>
|
||||
<?php if (isSuperUser(Auth::user()) && $user['username'] != $myUser['username']) : ?>
|
||||
<div class="alert alert-warning mb-0" role="alert">
|
||||
如需重置其他用户的密码,请前往 <a href="/super_manage/users" class="alert-link">系统管理</a> 页面操作。
|
||||
</div>
|
||||
@ -387,14 +447,14 @@ EOD);
|
||||
return false;
|
||||
});
|
||||
</script>
|
||||
<?php elseif ($cur_tab == 'privilege'): ?>
|
||||
<?php elseif ($cur_tab == 'privilege') : ?>
|
||||
<div class="card">
|
||||
<div class="card-body">
|
||||
<div id="result-alert" class="alert" role="alert" style="display: none"></div>
|
||||
<form id="form-privilege" method="post">
|
||||
<?php if (isSuperUser($myUser)): ?>
|
||||
<?php if (isSuperUser(Auth::user())) : ?>
|
||||
<fieldset>
|
||||
<?php else: ?>
|
||||
<?php else : ?>
|
||||
<fieldset disabled>
|
||||
<?php endif ?>
|
||||
<div class="mb-3">
|
||||
@ -402,11 +462,11 @@ EOD);
|
||||
<?= UOJLocale::get('user::user group') ?>
|
||||
</span>
|
||||
<span class="d-inline-block ms-3">
|
||||
<?php if ($user['usergroup'] == 'S'): ?>
|
||||
<?php if ($user['usergroup'] == 'S') : ?>
|
||||
<?= UOJLocale::get('user::super user') ?>
|
||||
<?php elseif ($user['usergroup'] == 'B'): ?>
|
||||
<?php elseif ($user['usergroup'] == 'B') : ?>
|
||||
<?= UOJLocale::get('user::banned user') ?>
|
||||
<?php else: ?>
|
||||
<?php else : ?>
|
||||
<?= UOJLocale::get('user::normal user') ?>
|
||||
<?php endif ?>
|
||||
</span>
|
||||
@ -449,16 +509,9 @@ EOD);
|
||||
<?= UOJLocale::get('user::contest judger') ?>
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<div class="form-check form-switch">
|
||||
<input class="form-check-input" type="checkbox" role="switch" name="contest_only" id="input-contest_only" <?= hasUserType($user, 'contest_only') ? 'checked' : '' ?>>
|
||||
<label class="form-check-label" for="input-contest_only">
|
||||
<?= UOJLocale::get('user::contest only') ?>
|
||||
</label>
|
||||
</div>
|
||||
</fieldset>
|
||||
|
||||
<?php if (isSuperUser($myUser)): ?>
|
||||
<?php if (isSuperUser(Auth::user())) : ?>
|
||||
<div class="text-center">
|
||||
<button type="submit" id="button-submit-privilege" name="submit-privilege" value="privilege" class="mt-3 btn btn-secondary">更新</button>
|
||||
</div>
|
||||
@ -473,7 +526,6 @@ EOD);
|
||||
problem_uploader: $('input[name=problem_uploader]').prop('checked') ? 'yes' : 'no',
|
||||
problem_manager: $('input[name=problem_manager]').prop('checked') ? 'yes' : 'no',
|
||||
contest_judger: $('input[name=contest_judger]').prop('checked') ? 'yes' : 'no',
|
||||
contest_only: $('input[name=contest_only]').prop('checked') ? 'yes' : 'no',
|
||||
'submit-privilege': 'privilege',
|
||||
}, function(res) {
|
||||
if (res && res.status === 'success') {
|
||||
@ -500,9 +552,9 @@ EOD);
|
||||
</script>
|
||||
</div>
|
||||
</div>
|
||||
<?php endif ?>
|
||||
<!-- end right col -->
|
||||
</div>
|
||||
<?php endif ?>
|
||||
<!-- end right col -->
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php echoUOJPageFooter() ?>
|
||||
|
@ -1,12 +1,8 @@
|
||||
<?php
|
||||
if (!Auth::check() && UOJConfig::$data['switch']['force-login']) {
|
||||
if (!Auth::check()) {
|
||||
redirectToLogin();
|
||||
}
|
||||
|
||||
if (!isNormalUser($myUser) && UOJConfig::$data['switch']['force-login']) {
|
||||
become403Page();
|
||||
}
|
||||
|
||||
function handleMsgPost() {
|
||||
global $myUser;
|
||||
if (!isset($_POST['receiver'])) {
|
||||
|
@ -1,23 +1,21 @@
|
||||
<?php
|
||||
requireLib('bootstrap5');
|
||||
requirePHPLib('form');
|
||||
requireLib('bootstrap5');
|
||||
requirePHPLib('form');
|
||||
|
||||
if (!Auth::check()) {
|
||||
redirectToLogin();
|
||||
}
|
||||
Auth::check() || redirectToLogin();
|
||||
|
||||
if (!validateUsername($_GET['username']) || !($user = queryUser($_GET['username']))) {
|
||||
if (!($user = UOJUser::query($_GET['username']))) {
|
||||
become404Page();
|
||||
}
|
||||
}
|
||||
|
||||
if (!isSuperUser($myUser) && $myUser['username'] != $user['username']) {
|
||||
if (!isSuperUser(Auth::user()) && Auth::id() != $user['username']) {
|
||||
become403Page();
|
||||
}
|
||||
}
|
||||
|
||||
function newDeleteSystemMsgForm($id) {
|
||||
$form = new UOJForm('remove_system_msg_' . $id);
|
||||
function newDeleteSystemMsgForm($id) {
|
||||
$form = new UOJBs4Form('remove_system_msg_' . $id);
|
||||
|
||||
$form->addHidden("msg_id", $id, function($msg_id) {
|
||||
$form->addHidden("msg_id", $id, function ($msg_id) {
|
||||
global $user;
|
||||
|
||||
if (!validateUInt($msg_id)) {
|
||||
@ -31,31 +29,30 @@
|
||||
|
||||
return '';
|
||||
}, null);
|
||||
$form->handle = function() {
|
||||
$form->handle = function () {
|
||||
$msg_id = $_POST["msg_id"];
|
||||
DB::delete("delete from user_system_msg where id = {$msg_id}");
|
||||
};
|
||||
$form->submit_button_config['text'] = '删除';
|
||||
$form->submit_button_config['margin_class'] = 'mt-0';
|
||||
$form->submit_button_config['class_str'] = 'btn btn-link text-decoration-none text-danger p-0';
|
||||
$form->submit_button_config['class_str'] = 'btn btn-link text-decoration-none text-danger p-0 mt-0';
|
||||
$form->submit_button_config['align'] = 'inline';
|
||||
$form->submit_button_config['smart_confirm'] = '';
|
||||
|
||||
return $form;
|
||||
}
|
||||
}
|
||||
|
||||
$pag_config = [
|
||||
$pag_config = [
|
||||
'page_len' => 10,
|
||||
'col_names' => ['*'],
|
||||
'table_name' => 'user_system_msg',
|
||||
'cond' => "receiver = '{$user['username']}'",
|
||||
'tail' => 'order by send_time desc',
|
||||
];
|
||||
$pag = new Paginator($pag_config);
|
||||
];
|
||||
$pag = new Paginator($pag_config);
|
||||
|
||||
$system_msgs = [];
|
||||
$system_msgs = [];
|
||||
|
||||
foreach ($pag->get() as $idx => $msg) {
|
||||
foreach ($pag->get() as $idx => $msg) {
|
||||
$system_msgs[$idx] = $msg;
|
||||
|
||||
if (isSuperUser($myUser)) {
|
||||
@ -63,28 +60,23 @@
|
||||
$delete_form->runAtServer();
|
||||
$system_msgs[$idx]['delete_form'] = $delete_form;
|
||||
}
|
||||
}
|
||||
?>
|
||||
}
|
||||
?>
|
||||
|
||||
<?php echoUOJPageHeader('系统消息') ?>
|
||||
|
||||
<div class="row">
|
||||
<!-- left col -->
|
||||
<div class="col-lg-9">
|
||||
<!-- left col -->
|
||||
<div class="col-lg-9">
|
||||
<h1>系统消息</h1>
|
||||
|
||||
<h1 class="h2">
|
||||
系统消息
|
||||
</h1>
|
||||
|
||||
<div class="card mb-3">
|
||||
<div class="card mb-3">
|
||||
<ul class="list-group list-group-flush">
|
||||
<?php foreach ($system_msgs as $msg): ?>
|
||||
<li class="list-group-item
|
||||
<?= $msg['read_time'] ? '' : 'bg-warning bg-opacity-25' ?>
|
||||
">
|
||||
<?php foreach ($system_msgs as $msg) : ?>
|
||||
<li class="list-group-item">
|
||||
<div class="mb-2 d-flex justify-content-between">
|
||||
<div>
|
||||
<?php if ($msg['title']): ?>
|
||||
<?php if ($msg['title']) : ?>
|
||||
<h4 class="d-inline"><?= $msg['title'] ?></h4>
|
||||
<?php endif ?>
|
||||
|
||||
@ -93,7 +85,7 @@
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<?php if (isset($msg['delete_form'])): ?>
|
||||
<?php if (isset($msg['delete_form'])) : ?>
|
||||
<?php $msg['delete_form']->printHTML() ?>
|
||||
<?php endif ?>
|
||||
</div>
|
||||
@ -101,31 +93,29 @@
|
||||
<div><?= $msg['content'] ?></div>
|
||||
</li>
|
||||
<?php endforeach ?>
|
||||
<?php if ($pag->isEmpty()): ?>
|
||||
<?php if ($pag->isEmpty()) : ?>
|
||||
<div class="text-center">
|
||||
<?= UOJLocale::get('none') ?>
|
||||
</div>
|
||||
<?php endif ?>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?= $pag->pagination() ?>
|
||||
<?= $pag->pagination() ?>
|
||||
</div>
|
||||
<!-- end left col -->
|
||||
|
||||
<!-- right col -->
|
||||
<aside class="col-lg-3 mt-3 mt-lg-0">
|
||||
<?php uojIncludeView('sidebar') ?>
|
||||
</aside>
|
||||
<!-- end right col -->
|
||||
</div>
|
||||
|
||||
<?php
|
||||
if (Auth::id() == $user['username']) {
|
||||
if (Auth::id() == $user['username']) {
|
||||
DB::update("update user_system_msg set read_time = now() where receiver = '" . $user['username'] . "'");
|
||||
}
|
||||
?>
|
||||
|
||||
</div>
|
||||
<!-- end left col -->
|
||||
|
||||
<!-- right col -->
|
||||
<aside class="col-lg-3 mt-3 mt-lg-0">
|
||||
<?php uojIncludeView('sidebar', array()) ?>
|
||||
</aside>
|
||||
<!-- end right col -->
|
||||
|
||||
</div>
|
||||
}
|
||||
?>
|
||||
|
||||
<?php echoUOJPageFooter() ?>
|
||||
|
@ -33,30 +33,103 @@ function genMoreContestInfo(&$contest) {
|
||||
}
|
||||
|
||||
function updateContestPlayerNum($contest) {
|
||||
DB::update("update contests set player_num = (select count(*) from contests_registrants where contest_id = {$contest['id']}) where id = {$contest['id']}");
|
||||
DB::update([
|
||||
"update contests",
|
||||
"set", [
|
||||
"player_num" => DB::rawbracket([
|
||||
"select count(*) from contests_registrants",
|
||||
"where", ["contest_id" => $contest['id']]
|
||||
])
|
||||
], "where", ["id" => $contest['id']]
|
||||
]);
|
||||
}
|
||||
|
||||
// return value: ['problems' => $problems, 'data' => $data, 'people' => $people]
|
||||
// problems: pos => id
|
||||
//
|
||||
// for individual competition:
|
||||
// people : username, realname
|
||||
// for team competition:
|
||||
// people : username, null, ['team_name' => team_name, 'members' => members]
|
||||
//
|
||||
// for OI/IOI contest:
|
||||
// data : id, submit_time, submitter, problem_pos, score
|
||||
// people : username
|
||||
function queryContestData($contest, $config = array(), $is_after_contest_query = false) {
|
||||
// for ACM contest:
|
||||
// data : id, submit_time (plus penalty), submitter, problem_pos, score, cnt, n_failures
|
||||
// if the contest is not finished, then cnt = null, n_failures = null;
|
||||
// otherwise, cnt is the total number of submission of this subitter for this problem
|
||||
// (by the time of getting 100, including the first submission with score 100)
|
||||
// n_failures is the number of failure attempts of this submitter for this problem
|
||||
function queryContestData($contest, $config = []) {
|
||||
mergeConfig($config, [
|
||||
'pre_final' => false
|
||||
'pre_final' => false,
|
||||
'after_contest' => false,
|
||||
]);
|
||||
|
||||
$problems = [];
|
||||
$prob_pos = [];
|
||||
$n_problems = 0;
|
||||
$result = DB::query("select problem_id from contests_problems where contest_id = {$contest['id']} order by dfn, problem_id");
|
||||
while ($row = DB::fetch($result, MYSQLI_NUM)) {
|
||||
$res = DB::selectAll([
|
||||
"select problem_id from contests_problems",
|
||||
"where", ["contest_id" => $contest['id']],
|
||||
"order by level, problem_id"
|
||||
], DB::NUM);
|
||||
foreach ($res as $row) {
|
||||
$prob_pos[$problems[] = (int)$row[0]] = $n_problems++;
|
||||
}
|
||||
|
||||
if ($contest['extra_config']['basic_rule'] == 'OI' || $contest['extra_config']['basic_rule'] == 'IOI') {
|
||||
$data = queryOIorIOIContestSubmissionData($contest, $problems, $prob_pos, $config);
|
||||
} elseif ($contest['extra_config']['basic_rule'] == 'ACM') {
|
||||
$data = queryACMContestSubmissionData($contest, $problems, $prob_pos, $config);
|
||||
}
|
||||
|
||||
$people = [];
|
||||
|
||||
if ($contest['extra_config']['individual_or_team'] == 'individual') {
|
||||
$people = DB::selectAll([
|
||||
"select contests_registrants.username, user_info.realname from contests_registrants",
|
||||
"inner join user_info on contests_registrants.username = user_info.username",
|
||||
"where", [
|
||||
"contest_id" => $contest['id'],
|
||||
"has_participated" => 1
|
||||
]
|
||||
], DB::NUM);
|
||||
} elseif ($contest['extra_config']['individual_or_team'] == 'team') {
|
||||
$res = DB::selectAll([
|
||||
"select user_info.username, null, user_info.extra from contests_registrants, user_info",
|
||||
"where", [
|
||||
"contest_id" => $contest['id'],
|
||||
"has_participated" => 1,
|
||||
"contests_registrants.username = user_info.username"
|
||||
]
|
||||
], DB::NUM);
|
||||
foreach ($res as $row) {
|
||||
$extra = json_decode($row[2], true);
|
||||
$row[2] = [
|
||||
'team_name' => $extra['acm']['team_name'],
|
||||
'members' => $extra['acm']['members']
|
||||
];
|
||||
$people[] = $row;
|
||||
}
|
||||
}
|
||||
|
||||
return ['problems' => $problems, 'data' => $data, 'people' => $people];
|
||||
}
|
||||
function queryOIorIOIContestSubmissionData($contest, $problems, $prob_pos, $config = []) {
|
||||
$data = [];
|
||||
if ($config['pre_final']) {
|
||||
$result = DB::query("select id, submit_time, submitter, problem_id, result from submissions"
|
||||
." where contest_id = {$contest['id']} and score is not null order by id");
|
||||
while ($row = DB::fetch($result, MYSQLI_NUM)) {
|
||||
|
||||
$use_final_res = $config['pre_final'] && $contest['extra_config']['basic_rule'] == 'OI';
|
||||
|
||||
if ($use_final_res) {
|
||||
$res = DB::selectAll([
|
||||
"select id, submit_time, submitter, problem_id, result from submissions",
|
||||
"where", [
|
||||
"contest_id" => $contest['id'],
|
||||
["score", "is not", null]
|
||||
], "order by id"
|
||||
], DB::NUM);
|
||||
foreach ($res as $row) {
|
||||
$r = json_decode($row[4], true);
|
||||
if (!isset($r['final_result'])) {
|
||||
continue;
|
||||
@ -68,71 +141,233 @@ function queryContestData($contest, $config = array(), $is_after_contest_query =
|
||||
}
|
||||
} else {
|
||||
if ($contest['cur_progress'] < CONTEST_FINISHED) {
|
||||
$result = DB::query("select id, submit_time, submitter, problem_id, score from submissions"
|
||||
." where contest_id = {$contest['id']} and score is not null order by id");
|
||||
} elseif ($is_after_contest_query == true) {
|
||||
$result = DB::query("select id, submit_time, submitter, problem_id, score from submissions order by score");
|
||||
$res = DB::selectAll([
|
||||
"select id, submit_time, submitter, problem_id, score from submissions",
|
||||
"where", [
|
||||
"contest_id" => $contest['id'],
|
||||
["score", "is not", null]
|
||||
], "order by id"
|
||||
], DB::NUM);
|
||||
} elseif ($config['after_contest']) {
|
||||
$res = DB::selectAll([
|
||||
"select id, submit_time, submitter, problem_id, score from submissions",
|
||||
"where", [
|
||||
["problem_id", "in", DB::rawtuple($problems)],
|
||||
], "order by score",
|
||||
], DB::NUM);
|
||||
} else {
|
||||
$result = DB::query("select submission_id, date_add('{$contest['start_time_str']}', interval penalty second),"
|
||||
." submitter, problem_id, score from contests_submissions where contest_id = {$contest['id']}");
|
||||
$esc_start_time_str = DB::escape($contest['start_time_str']);
|
||||
$res = DB::selectAll([
|
||||
"select submission_id, date_add('{$esc_start_time_str}', interval penalty second), submitter, problem_id, score from contests_submissions",
|
||||
"where", ["contest_id" => $contest['id']],
|
||||
], DB::NUM);
|
||||
}
|
||||
while ($row = DB::fetch($result, MYSQLI_NUM)) {
|
||||
foreach ($res as $row) {
|
||||
$row[0] = (int)$row[0];
|
||||
$row[3] = $prob_pos[$row[3]];
|
||||
$row[4] = (int)$row[4];
|
||||
$data[] = $row;
|
||||
}
|
||||
}
|
||||
|
||||
$people = [];
|
||||
$result = DB::query("select a.username, b.realname from contests_registrants a inner join user_info b on a.username = b.username where a.contest_id = {$contest['id']} and a.has_participated = 1");
|
||||
while ($row = DB::fetch($result, MYSQLI_NUM)) {
|
||||
$people[] = $row;
|
||||
}
|
||||
|
||||
return ['problems' => $problems, 'data' => $data, 'people' => $people];
|
||||
return $data;
|
||||
}
|
||||
|
||||
function calcStandings($contest, $contest_data, &$score, &$standings, $update_contests_submissions = false, $show_reviews = false) {
|
||||
// score: username, problem_pos => score, penalty, id, ?review
|
||||
$score = array();
|
||||
function queryACMContestSubmissionData($contest, $problems, $prob_pos, $config = []) {
|
||||
$data = [];
|
||||
|
||||
$username_or_empty = Auth::id();
|
||||
if (!isset($username_or_empty)) {
|
||||
$username_or_empty = '';
|
||||
}
|
||||
|
||||
$actual_score = UOJSubmission::sqlForActualScore();
|
||||
$visible_score = 'if(' . DB::land(['hide_score_to_others' => 1, 'submitter' => $username_or_empty]) . ', hidden_score, score)';
|
||||
|
||||
if ($config['pre_final']) {
|
||||
$res = DB::selectAll([
|
||||
"select id, submit_time, submitter, problem_id, $actual_score as actual_score, null, null from submissions",
|
||||
"where", [
|
||||
"contest_id" => $contest['id'],
|
||||
[$actual_score, "is not", null]
|
||||
], "order by id"
|
||||
], DB::NUM);
|
||||
} else {
|
||||
if ($contest['cur_progress'] < CONTEST_FINISHED) {
|
||||
$res = DB::selectAll([
|
||||
"select id, submit_time, submitter, problem_id, $visible_score as visible_score, null, null from submissions",
|
||||
"where", [
|
||||
"contest_id" => $contest['id'],
|
||||
DB::lor([
|
||||
[$visible_score, "is not", null],
|
||||
DB::land([
|
||||
"hide_score_to_others" => 1,
|
||||
["submitter", "!=", $username_or_empty]
|
||||
])
|
||||
])
|
||||
], "order by id"
|
||||
], DB::NUM);
|
||||
} else {
|
||||
$esc_start_time_str = DB::escape($contest['start_time_str']);
|
||||
$res = DB::selectAll([
|
||||
"select submission_id, date_add('{$esc_start_time_str}', interval penalty second), submitter, problem_id, score, cnt, n_failures from contests_submissions",
|
||||
"where", ["contest_id" => $contest['id']],
|
||||
], DB::NUM);
|
||||
}
|
||||
}
|
||||
foreach ($res as $row) {
|
||||
$row[0] = (int)$row[0];
|
||||
$row[3] = $prob_pos[$row[3]];
|
||||
if (isset($row[4])) {
|
||||
$row[4] = (int)$row[4];
|
||||
}
|
||||
if (isset($row[5])) {
|
||||
$row[5] = (int)$row[5];
|
||||
}
|
||||
if (isset($row[6])) {
|
||||
$row[6] = (int)$row[6];
|
||||
}
|
||||
$data[] = $row;
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
// standings: rank => score, penalty, [username, realname], virtual_rank
|
||||
function calcStandings($contest, $contest_data, &$score, &$standings, $cfg = []) {
|
||||
$cfg += [
|
||||
'update_contests_submissions' => false,
|
||||
];
|
||||
|
||||
// score for OI: username, problem_pos => score, penalty, id
|
||||
// score for ACM: username, problem_pos => score, penalty, id, cnt, n_failures, n_frozen
|
||||
$score = [];
|
||||
$n_people = count($contest_data['people']);
|
||||
$n_problems = count($contest_data['problems']);
|
||||
foreach ($contest_data['people'] as $person) {
|
||||
$score[$person[0]] = array();
|
||||
$score[$person[0]] = [];
|
||||
}
|
||||
foreach ($contest_data['data'] as $submission) {
|
||||
$penalty = (new DateTime($submission[1]))->getTimestamp() - $contest['start_time']->getTimestamp();
|
||||
|
||||
if ($contest['extra_config']['basic_rule'] === 'OI') {
|
||||
foreach ($contest_data['data'] as $sub) {
|
||||
$penalty = (new DateTime($sub[1]))->getTimestamp() - $contest['start_time']->getTimestamp();
|
||||
if ($contest['extra_config']['standings_version'] >= 2) {
|
||||
if ($submission[4] == 0) {
|
||||
if ($sub[4] == 0) {
|
||||
$penalty = 0;
|
||||
}
|
||||
}
|
||||
|
||||
$score[$submission[2]][$submission[3]] = array($submission[4], $penalty, $submission[0]);
|
||||
$score[$sub[2]][$sub[3]] = array($sub[4], $penalty, $sub[0]);
|
||||
}
|
||||
} else if ($contest['extra_config']['basic_rule'] === 'ACM') {
|
||||
// sub: id, submit_time, submitter, problem_pos, score
|
||||
// id, submit_time (plus penalty), submitter, problem_pos, score, cnt, n_failures
|
||||
foreach ($contest_data['data'] as $sub) {
|
||||
if (!isset($score[$sub[2]][$sub[3]])) {
|
||||
$score[$sub[2]][$sub[3]] = [];
|
||||
}
|
||||
$score[$sub[2]][$sub[3]][] = $sub;
|
||||
}
|
||||
|
||||
if ($show_reviews) {
|
||||
$parsedown = HTML::parsedown();
|
||||
$purifier = HTML::purifier_inline();
|
||||
|
||||
foreach ($contest_data['people'] as $person) {
|
||||
foreach ($contest_data['problems'] as $key => $problem) {
|
||||
$review_result = DB::selectFirst("select content from contests_reviews where contest_id = {$contest['id']} and problem_id = {$problem} and poster = '{$person[0]}'");
|
||||
$uname = $person[0];
|
||||
for ($pr = 0; $pr < $n_problems; $pr++) {
|
||||
if (isset($score[$uname][$pr])) {
|
||||
// username, problem_pos => score, penalty, id, cnt, n_failures, n_frozen
|
||||
$final_scr = null;
|
||||
$penalty = 0;
|
||||
$key_sub = null;
|
||||
$cnt = 0;
|
||||
$n_failures = 0;
|
||||
$n_frozen = 0;
|
||||
|
||||
if (!isset($score[$person[0]][$key])) {
|
||||
$score[$person[0]][$key] = array(0, 0, 0);
|
||||
if (isset($score[$uname][$pr][0][5])) { // the stored contest data is used
|
||||
$sub = $score[$uname][$pr][0];
|
||||
$final_scr = $sub[4];
|
||||
$penalty = (new DateTime($sub[1]))->getTimestamp() - $contest['start_time']->getTimestamp();
|
||||
$key_sub = $sub;
|
||||
$cnt = $sub[5];
|
||||
$n_failures = $sub[6];
|
||||
$n_frozen = 0;
|
||||
} else {
|
||||
for ($i = 0; $i < count($score[$uname][$pr]); $i++) {
|
||||
$sub = $score[$uname][$pr][$i];
|
||||
$cnt++;
|
||||
if (!isset($sub[4])) {
|
||||
$n_frozen++;
|
||||
} elseif (!isset($final_scr) || $final_scr < $sub[4]) {
|
||||
$final_scr = $sub[4];
|
||||
if ($final_scr == 100) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($review_result['content']) {
|
||||
$score[$person[0]][$key][] = $purifier->purify($parsedown->line($review_result['content']));
|
||||
if (!isset($final_scr)) {
|
||||
$key_sub = end($score[$uname][$pr]);
|
||||
} else if ($final_scr == 0) {
|
||||
for ($i = 0; $i < count($score[$uname][$pr]); $i++) {
|
||||
$sub = $score[$uname][$pr][$i];
|
||||
if (!isset($sub[4])) {
|
||||
break;
|
||||
} else {
|
||||
$n_failures++;
|
||||
$key_sub = $sub;
|
||||
}
|
||||
}
|
||||
|
||||
list($final_scr, $penalty) = calcACMScoreAndPenaltyForOneProblem(
|
||||
$contest,
|
||||
$contest_data['problems'][$pr],
|
||||
$key_sub,
|
||||
$n_failures
|
||||
);
|
||||
} else {
|
||||
$scr_set = [];
|
||||
for ($i = 0; $i < count($score[$uname][$pr]); $i++) {
|
||||
$sub = $score[$uname][$pr][$i];
|
||||
if ($sub[4] > 0 && $sub[4] != 97 && !isset($scr_set[$sub[4]])) {
|
||||
$scr_set[$sub[4]] = true;
|
||||
} else {
|
||||
$n_failures++;
|
||||
}
|
||||
if ($sub[4] === $final_scr) {
|
||||
$key_sub = $sub;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
list($final_scr, $penalty) = calcACMScoreAndPenaltyForOneProblem(
|
||||
$contest,
|
||||
$contest_data['problems'][$pr],
|
||||
$key_sub,
|
||||
$n_failures
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
$score[$uname][$pr] = [
|
||||
$final_scr,
|
||||
$penalty,
|
||||
$key_sub[0],
|
||||
$cnt,
|
||||
$n_failures,
|
||||
$n_frozen
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if ($contest['extra_config']['basic_rule'] === 'IOI') {
|
||||
foreach ($contest_data['data'] as $sub) {
|
||||
$penalty = (new DateTime($sub[1]))->getTimestamp() - $contest['start_time']->getTimestamp();
|
||||
if ($sub[4] == 0) {
|
||||
$penalty = 0;
|
||||
}
|
||||
if (!isset($score[$sub[2]][$sub[3]]) || $score[$sub[2]][$sub[3]][0] < $sub[4]) {
|
||||
$score[$sub[2]][$sub[3]] = array($sub[4], $penalty, $sub[0]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// standings: rank => score, penalty, [username, realname], virtual_rank, ?review
|
||||
$standings = array();
|
||||
$standings = [];
|
||||
foreach ($contest_data['people'] as $person) {
|
||||
$cur = array(0, 0, $person);
|
||||
for ($i = 0; $i < $n_problems; $i++) {
|
||||
@ -140,52 +375,71 @@ function calcStandings($contest, $contest_data, &$score, &$standings, $update_co
|
||||
$cur_row = $score[$person[0]][$i];
|
||||
$cur[0] += $cur_row[0];
|
||||
$cur[1] += $cur_row[1];
|
||||
if ($update_contests_submissions) {
|
||||
DB::insert("replace into contests_submissions (contest_id, submitter, problem_id, submission_id, score, penalty) values ({$contest['id']}, '{$person[0]}', {$contest_data['problems'][$i]}, {$cur_row[2]}, {$cur_row[0]}, {$cur_row[1]})");
|
||||
if ($cfg['update_contests_submissions']) {
|
||||
DB::insert([
|
||||
"replace into contests_submissions",
|
||||
"(contest_id, submitter, problem_id, submission_id, score, penalty, cnt, n_failures)",
|
||||
"values", DB::tuple([
|
||||
$contest['id'], $person[0], $contest_data['problems'][$i], $cur_row[2],
|
||||
$cur_row[0], $cur_row[1],
|
||||
isset($cur_row[3]) ? $cur_row[3] : null,
|
||||
isset($cur_row[4]) ? $cur_row[4] : null
|
||||
])
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($show_reviews) {
|
||||
$review_result = DB::selectFirst("select content from contests_reviews where contest_id = {$contest['id']} and problem_id = -1 and poster = '{$person[0]}'");
|
||||
|
||||
if ($review_result['content']) {
|
||||
$cur[] = $purifier->purify($parsedown->line($review_result['content']));
|
||||
}
|
||||
}
|
||||
|
||||
$standings[] = $cur;
|
||||
}
|
||||
|
||||
usort($standings, function($lhs, $rhs) {
|
||||
usort($standings, function ($lhs, $rhs) {
|
||||
if ($lhs[0] != $rhs[0]) {
|
||||
return $rhs[0] - $lhs[0];
|
||||
} elseif ($lhs[1] != $rhs[1]) {
|
||||
} else if ($lhs[1] != $rhs[1]) {
|
||||
return $lhs[1] - $rhs[1];
|
||||
} else {
|
||||
return strcmp($lhs[2][0], $rhs[2][0]);
|
||||
}
|
||||
});
|
||||
|
||||
$is_same_rank = function($lhs, $rhs) {
|
||||
$is_same_rank = function ($lhs, $rhs) {
|
||||
return $lhs[0] == $rhs[0] && $lhs[1] == $rhs[1];
|
||||
};
|
||||
|
||||
for ($i = 0; $i < $n_people; $i++) {
|
||||
if ($i == 0 || !$is_same_rank($standings[$i - 1], $standings[$i])) {
|
||||
if ($show_reviews && count($standings[$i]) == 4) {
|
||||
$standings[$i][] = $standings[$i][3];
|
||||
$standings[$i][3] = $i + 1;
|
||||
} else {
|
||||
$standings[$i][] = $i + 1;
|
||||
}
|
||||
} else {
|
||||
if ($show_reviews && count($standings[$i]) == 4) {
|
||||
$standings[$i][] = $standings[$i][3];
|
||||
$standings[$i][3] = $standings[$i - 1][3];
|
||||
} else {
|
||||
$standings[$i][] = $standings[$i - 1][3];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function calcACMScoreAndPenaltyForOneProblem($contest, $problem_id, $sub, $n_failures) {
|
||||
if (isset($contest['extra_config']['bonus']["problem_{$problem_id}"])) {
|
||||
if ($sub[4] === 100) {
|
||||
return [0, -60 * 20];
|
||||
} else {
|
||||
return [0, 0];
|
||||
}
|
||||
} else {
|
||||
$penalty = (new DateTime($sub[1]))->getTimestamp() - $contest['start_time']->getTimestamp();
|
||||
$penalty += $n_failures * 60 * 20;
|
||||
if ($sub[4] === 0) {
|
||||
$penalty = 0;
|
||||
}
|
||||
return [$sub[4], $penalty];
|
||||
}
|
||||
}
|
||||
|
||||
function getContestBlogLink($contest, $title) {
|
||||
if (!isset($contest['extra_config']['links'])) {
|
||||
return null;
|
||||
}
|
||||
foreach ($contest['extra_config']['links'] as $link) {
|
||||
if ($link[0] === $title) {
|
||||
return '/blogs/' . $link[1];
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
@ -1,171 +1,306 @@
|
||||
<?php
|
||||
// Actually, these things should be done by main_judger so that the code would be much simpler.
|
||||
// However, this lib exists due to some history issues.
|
||||
// Actually, these things should be done by main_judger so that the code would be much simpler.
|
||||
// However, this lib exists due to some history issues.
|
||||
|
||||
function dataNewProblem($id) {
|
||||
function dataNewProblem($id) {
|
||||
mkdir("/var/uoj_data/upload/$id");
|
||||
mkdir("/var/uoj_data/$id");
|
||||
|
||||
exec("cd /var/uoj_data; rm $id.zip; zip $id.zip $id -r -q");
|
||||
}
|
||||
UOJLocalRun::execAnd([
|
||||
['cd', '/var/uoj_data'],
|
||||
['rm', "$id.zip"],
|
||||
['zip', "$id.zip", $id, '-r', '-q']
|
||||
]);
|
||||
}
|
||||
|
||||
class UOJProblemConfException extends Exception {
|
||||
public function __construct($message) {
|
||||
parent::__construct("<strong>problem.conf</strong> : $message");
|
||||
}
|
||||
}
|
||||
class UOJFileNotFoundException extends Exception {
|
||||
public function __construct($file_name) {
|
||||
parent::__construct("file <strong>" . htmlspecialchars($file_name) . '</strong> not found');
|
||||
}
|
||||
}
|
||||
|
||||
function dataClearProblemData($problem) {
|
||||
function dataClearProblemData($problem) {
|
||||
$id = $problem['id'];
|
||||
if (!validateUInt($id)) {
|
||||
error_log("dataClearProblemData: hacker detected");
|
||||
UOJLog::error("dataClearProblemData: hacker detected");
|
||||
return "invalid problem id";
|
||||
}
|
||||
|
||||
exec("rm /var/uoj_data/upload/$id -r");
|
||||
exec("rm /var/uoj_data/$id -r");
|
||||
UOJLocalRun::exec(['rm', "/var/uoj_data/$id", '-r']);
|
||||
UOJLocalRun::exec(['rm', "/var/uoj_data/upload/$id", '-r']);
|
||||
dataNewProblem($id);
|
||||
}
|
||||
}
|
||||
|
||||
class SyncProblemDataHandler {
|
||||
private $problem, $user;
|
||||
private $upload_dir, $data_dir, $prepare_dir;
|
||||
class SyncProblemDataHandler {
|
||||
private UOJProblem $problem;
|
||||
private $user;
|
||||
private int $id;
|
||||
private string $upload_dir, $data_dir, $prepare_dir;
|
||||
private $requirement, $problem_extra_config;
|
||||
private $problem_conf, $final_problem_conf;
|
||||
private $allow_files;
|
||||
|
||||
public function __construct($problem, $user) {
|
||||
$this->problem = $problem;
|
||||
public function retryMsg() {
|
||||
return '请等待上一次数据上传或同步操作结束后重试';
|
||||
}
|
||||
|
||||
public function __construct($problem_info, $user = null) {
|
||||
$this->problem = new UOJProblem($problem_info);
|
||||
$this->user = $user;
|
||||
|
||||
if (!validateUInt($this->problem->info['id'])) {
|
||||
UOJLog::error("SyncProblemDataHandler: hacker detected");
|
||||
return;
|
||||
}
|
||||
$this->id = (int)$this->problem->info['id'];
|
||||
|
||||
$this->data_dir = "/var/uoj_data/{$this->id}";
|
||||
$this->prepare_dir = "/var/uoj_data/prepare_{$this->id}";
|
||||
$this->upload_dir = "/var/uoj_data/upload/{$this->id}";
|
||||
}
|
||||
|
||||
/**
|
||||
* $type can be either LOCK_SH or LOCK_EX
|
||||
*/
|
||||
private function lock($type, $func) {
|
||||
$ret = FS::lock_file("/var/uoj_data/{$this->id}_lock", $type, $func);
|
||||
return $ret === false ? $this->retryMsg() : $ret;
|
||||
}
|
||||
|
||||
private function check_conf_on($name) {
|
||||
return isset($this->problem_conf[$name]) && $this->problem_conf[$name] == 'on';
|
||||
}
|
||||
|
||||
private function create_prepare_folder() {
|
||||
return mkdir($this->prepare_dir, 0755);
|
||||
}
|
||||
private function remove_prepare_folder() {
|
||||
return UOJLocalRun::exec(['rm', $this->prepare_dir, '-rf']);
|
||||
}
|
||||
|
||||
private function copy_to_prepare($file_name) {
|
||||
global $uojMainJudgerWorkPath;
|
||||
if (!isset($this->allow_files[$file_name])) {
|
||||
throw new UOJFileNotFoundException($file_name);
|
||||
}
|
||||
$src = escapeshellarg("{$this->upload_dir}/$file_name");
|
||||
$dest = escapeshellarg("{$this->prepare_dir}/$file_name");
|
||||
|
||||
$src = "{$this->upload_dir}/$file_name";
|
||||
$dest = "{$this->prepare_dir}/$file_name";
|
||||
|
||||
if (file_exists($dest)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (isset($this->problem_extra_config['dont_use_formatter']) || !is_file("{$this->upload_dir}/$file_name")) {
|
||||
exec("cp $src $dest -r", $output, $ret);
|
||||
$ret = UOJLocalRun::exec(['cp', $src, $dest, '-r']);
|
||||
} else {
|
||||
exec("$uojMainJudgerWorkPath/run/formatter <$src >$dest", $output, $ret);
|
||||
$ret = UOJLocalRun::formatter($src, $dest);
|
||||
}
|
||||
if ($ret) {
|
||||
|
||||
if ($ret === false) {
|
||||
throw new UOJFileNotFoundException($file_name);
|
||||
}
|
||||
}
|
||||
|
||||
private function copy_file_to_prepare($file_name) {
|
||||
global $uojMainJudgerWorkPath;
|
||||
if (!isset($this->allow_files[$file_name]) || !is_file("{$this->upload_dir}/$file_name")) {
|
||||
throw new UOJFileNotFoundException($file_name);
|
||||
}
|
||||
|
||||
$this->copy_to_prepare($file_name);
|
||||
}
|
||||
private function compile_at_prepare($name, $config = array()) {
|
||||
global $uojMainJudgerWorkPath;
|
||||
$include_path = "$uojMainJudgerWorkPath/include";
|
||||
|
||||
if (!isset($config['src'])) {
|
||||
$config['src'] = "$name.cpp";
|
||||
private function copy_source_code_to_prepare($code_name) { // file name without suffix
|
||||
$src = UOJLang::findSourceCode($code_name, $this->upload_dir);
|
||||
|
||||
if ($src === false) {
|
||||
throw new UOJFileNotFoundException($code_name);
|
||||
}
|
||||
|
||||
$this->copy_to_prepare($src['path']);
|
||||
}
|
||||
|
||||
private function compile_at_prepare($name, $config = []) {
|
||||
$include_path = UOJLocalRun::$judger_include_path;
|
||||
|
||||
$src = UOJLang::findSourceCode($name, $this->prepare_dir);
|
||||
|
||||
if (isset($config['path'])) {
|
||||
exec("mv {$this->prepare_dir}/$name.cpp {$this->prepare_dir}/{$config['path']}/$name.cpp");
|
||||
if (rename("{$this->prepare_dir}/{$src['path']}", "{$this->prepare_dir}/{$config['path']}/{$src['path']}") === false) {
|
||||
throw new Exception("<strong>$name</strong> : move failed");
|
||||
}
|
||||
$work_path = "{$this->prepare_dir}/{$config['path']}";
|
||||
} else {
|
||||
$work_path = $this->prepare_dir;
|
||||
}
|
||||
|
||||
$cmd_prefix = "$uojMainJudgerWorkPath/run/run_program >{$this->prepare_dir}/run_compiler_result.txt --in=/dev/null --out=stderr --err={$this->prepare_dir}/compiler_result.txt --tl=10 --ml=512 --ol=64 --type=compiler --work-path={$work_path}";
|
||||
if (isset($config['need_include_header']) && $config['need_include_header']) {
|
||||
exec("$cmd_prefix --add-readable-raw=$include_path/ /usr/bin/g++ -o $name {$config['src']} -I$include_path -lm -O2 -DONLINE_JUDGE");
|
||||
} else {
|
||||
exec("$cmd_prefix /usr/bin/g++ -o $name {$config['src']} -lm -O2 -DONLINE_JUDGE");
|
||||
$compile_options = [
|
||||
['custom', UOJLocalRun::$judger_run_path]
|
||||
];
|
||||
$runp_options = [
|
||||
['in', '/dev/null'],
|
||||
['out', 'stderr'],
|
||||
['err', "{$this->prepare_dir}/compiler_result.txt"],
|
||||
['tl', 60],
|
||||
['ml', 512],
|
||||
['ol', 64],
|
||||
['type', 'compiler'],
|
||||
['work-path', $work_path],
|
||||
];
|
||||
if (!empty($config['need_include_header'])) {
|
||||
$compile_options[] = ['cinclude', $include_path];
|
||||
$runp_options[] = ['add-readable-raw', "{$include_path}/"];
|
||||
}
|
||||
|
||||
$fp = fopen("{$this->prepare_dir}/run_compiler_result.txt", "r");
|
||||
if (fscanf($fp, '%d %d %d %d', $rs, $used_time, $used_memory, $exit_code) != 4) {
|
||||
$rs = 7;
|
||||
if (!empty($config['implementer'])) {
|
||||
$compile_options[] = ['impl', $config['implementer']];
|
||||
}
|
||||
fclose($fp);
|
||||
$res = UOJLocalRun::compile($name, $compile_options, $runp_options);
|
||||
$this->final_problem_conf["{$name}_run_type"] = UOJLang::getRunTypeFromLanguage($src['lang']);
|
||||
$rstype = isset($res['rstype']) ? $res['rstype'] : 7;
|
||||
|
||||
unlink("{$this->prepare_dir}/run_compiler_result.txt");
|
||||
|
||||
if ($rs != 0 || $exit_code != 0) {
|
||||
if ($rs == 0) {
|
||||
throw new Exception("<strong>$name</strong> : compile error<pre>\n" . uojFilePreview("{$this->prepare_dir}/compiler_result.txt", 100) . "\n</pre>");
|
||||
} elseif ($rs == 7) {
|
||||
if ($rstype != 0 || $res['exit_code'] != 0) {
|
||||
if ($rstype == 0) {
|
||||
throw new Exception("<strong>$name</strong> : compile error<pre>\n" . HTML::escape(uojFilePreview("{$this->prepare_dir}/compiler_result.txt", 10000)) . "\n</pre>");
|
||||
} elseif ($rstype == 7) {
|
||||
throw new Exception("<strong>$name</strong> : compile error. No comment");
|
||||
} else {
|
||||
throw new Exception("<strong>$name</strong> : compile error. Compiler " . judgerCodeStr($rs));
|
||||
throw new Exception("<strong>$name</strong> : compile error. Compiler " . judgerCodeStr($rstype));
|
||||
}
|
||||
}
|
||||
|
||||
unlink("{$this->prepare_dir}/compiler_result.txt");
|
||||
|
||||
if (isset($config['path'])) {
|
||||
exec("mv {$this->prepare_dir}/{$config['path']}/$name.cpp {$this->prepare_dir}/$name.cpp");
|
||||
exec("mv {$this->prepare_dir}/{$config['path']}/$name {$this->prepare_dir}/$name");
|
||||
rename("{$this->prepare_dir}/{$config['path']}/{$src['path']}", "{$this->prepare_dir}/{$src['path']}");
|
||||
rename("{$this->prepare_dir}/{$config['path']}/$name", "{$this->prepare_dir}/$name");
|
||||
}
|
||||
}
|
||||
|
||||
private function makefile_at_prepare() {
|
||||
global $uojMainJudgerWorkPath;
|
||||
$include_path = UOJLocalRun::$judger_include_path;
|
||||
|
||||
$include_path = "$uojMainJudgerWorkPath/include";
|
||||
$cmd_prefix = "$uojMainJudgerWorkPath/run/run_program >{$this->prepare_dir}/run_makefile_result.txt --in=/dev/null --out=stderr --err={$this->prepare_dir}/makefile_result.txt --tl=10 --ml=512 --ol=64 --type=compiler --work-path={$this->prepare_dir}";
|
||||
exec("$cmd_prefix --add-readable-raw=$include_path/ /usr/bin/make INCLUDE_PATH=$include_path");
|
||||
$res = UOJLocalRun::exec(['/usr/bin/make', "INCLUDE_PATH={$include_path}"], [
|
||||
['in', '/dev/null'],
|
||||
['out', 'stderr'],
|
||||
['err', "{$this->prepare_dir}/makefile_result.txt"],
|
||||
['tl', 60],
|
||||
['ml', 512],
|
||||
['ol', 64],
|
||||
['type', 'compiler'],
|
||||
['work-path', $this->prepare_dir],
|
||||
['add-readable-raw', "{$include_path}/"]
|
||||
]);
|
||||
$rstype = isset($res['rstype']) ? $res['rstype'] : 7;
|
||||
|
||||
$fp = fopen("{$this->prepare_dir}/run_makefile_result.txt", "r");
|
||||
if (fscanf($fp, '%d %d %d %d', $rs, $used_time, $used_memory, $exit_code) != 4) {
|
||||
$rs = 7;
|
||||
}
|
||||
fclose($fp);
|
||||
|
||||
unlink("{$this->prepare_dir}/run_makefile_result.txt");
|
||||
|
||||
if ($rs != 0 || $exit_code != 0) {
|
||||
if ($rs == 0) {
|
||||
throw new Exception("<strong>Makefile</strong> : compile error<pre>\n" . uojFilePreview("{$this->prepare_dir}/makefile_result.txt", 100) . "\n</pre>");
|
||||
} elseif ($rs == 7) {
|
||||
if ($rstype != 0 || $res['exit_code'] != 0) {
|
||||
if ($rstype == 0) {
|
||||
throw new Exception("<strong>Makefile</strong> : compile error<pre>\n" . HTML::escape(uojFilePreview("{$this->prepare_dir}/makefile_result.txt", 10000)) . "\n</pre>");
|
||||
} elseif ($rstype == 7) {
|
||||
throw new Exception("<strong>Makefile</strong> : compile error. No comment");
|
||||
} else {
|
||||
throw new Exception("<strong>Makefile</strong> : compile error. Compiler " . judgerCodeStr($rs));
|
||||
throw new Exception("<strong>Makefile</strong> : compile error. Compiler " . judgerCodeStr($rstype));
|
||||
}
|
||||
}
|
||||
|
||||
unlink("{$this->prepare_dir}/makefile_result.txt");
|
||||
}
|
||||
|
||||
public function handle() {
|
||||
$id = $this->problem['id'];
|
||||
if (!validateUInt($id)) {
|
||||
error_log("dataSyncProblemData: hacker detected");
|
||||
return "invalid problem id";
|
||||
}
|
||||
|
||||
$this->upload_dir = "/var/uoj_data/upload/$id";
|
||||
$this->data_dir = "/var/uoj_data/$id";
|
||||
$this->prepare_dir = "/var/uoj_data/prepare_$id";
|
||||
|
||||
if (file_exists($this->prepare_dir)) {
|
||||
return "please wait until the last sync finish";
|
||||
}
|
||||
|
||||
public function _updateProblemConf($new_problem_conf) {
|
||||
try {
|
||||
$this->requirement = array();
|
||||
$this->problem_extra_config = json_decode($this->problem['extra_config'], true);
|
||||
putUOJConf("{$this->data_dir}/problem.conf", $new_problem_conf);
|
||||
return '';
|
||||
} catch (Exception $e) {
|
||||
return $e->getMessage();
|
||||
}
|
||||
}
|
||||
public function updateProblemConf($new_problem_conf) {
|
||||
return $this->lock(LOCK_EX, fn () => $this->_updateProblemConf($new_problem_conf));
|
||||
}
|
||||
|
||||
mkdir($this->prepare_dir, 0755);
|
||||
private function _addHackPoint($uploaded_input_file, $uploaded_output_file, $reason) {
|
||||
try {
|
||||
switch ($this->problem->getExtraConfig('add_hack_as')) {
|
||||
case 'test':
|
||||
$key_num = 'n_tests';
|
||||
$msg = 'add new test';
|
||||
$gen_in_name = 'getUOJProblemInputFileName';
|
||||
$gen_out_name = 'getUOJProblemOutputFileName';
|
||||
break;
|
||||
case 'ex_test':
|
||||
$key_num = 'n_ex_tests';
|
||||
$msg = 'add new extra test';
|
||||
$gen_in_name = 'getUOJProblemExtraInputFileName';
|
||||
$gen_out_name = 'getUOJProblemExtraOutputFileName';
|
||||
break;
|
||||
default:
|
||||
return 'add hack to data failed: add_hack_as should be either "ex_test" or "test"';
|
||||
}
|
||||
|
||||
$new_problem_conf = $this->problem->getProblemConfArray();
|
||||
if ($new_problem_conf == -1 || $new_problem_conf == -2) {
|
||||
return $new_problem_conf;
|
||||
}
|
||||
$new_problem_conf[$key_num] = getUOJConfVal($new_problem_conf, $key_num, 0) + 1;
|
||||
|
||||
putUOJConf("{$this->upload_dir}/problem.conf", $new_problem_conf);
|
||||
|
||||
$new_input_name = $gen_in_name($new_problem_conf, $new_problem_conf[$key_num]);
|
||||
$new_output_name = $gen_out_name($new_problem_conf, $new_problem_conf[$key_num]);
|
||||
|
||||
if (!copy($uploaded_input_file, "{$this->upload_dir}/$new_input_name")) {
|
||||
return "input file not found";
|
||||
}
|
||||
if (!copy($uploaded_output_file, "{$this->upload_dir}/$new_output_name")) {
|
||||
return "output file not found";
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
return $e->getMessage();
|
||||
}
|
||||
|
||||
$ret = $this->_sync();
|
||||
if ($ret !== '') {
|
||||
return "hack successfully but sync failed: $ret";
|
||||
}
|
||||
|
||||
if (isset($reason['hack_url'])) {
|
||||
UOJSystemUpdate::updateProblem($this->problem, [
|
||||
'text' => 'Hack 成功,自动添加数据',
|
||||
'url' => $reason['hack_url']
|
||||
]);
|
||||
}
|
||||
UOJSubmission::rejudgeProblemAC($this->problem, [
|
||||
'reason_text' => $reason['rejudge'],
|
||||
'requestor' => ''
|
||||
]);
|
||||
return '';
|
||||
}
|
||||
|
||||
public function addHackPoint($uploaded_input_file, $uploaded_output_file, $reason = []) {
|
||||
return $this->lock(LOCK_EX, fn () => $this->_addHackPoint($uploaded_input_file, $uploaded_output_file, $reason));
|
||||
}
|
||||
|
||||
public function fast_hackable_check() {
|
||||
if (!$this->problem->info['hackable']) {
|
||||
return;
|
||||
}
|
||||
if (!$this->check_conf_on('use_builtin_judger')) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ($this->check_conf_on('submit_answer')) {
|
||||
throw new UOJProblemConfException("提交答案题不可 Hack,请先停用本题的 Hack 功能。");
|
||||
} else {
|
||||
if (UOJLang::findSourceCode('std', $this->upload_dir) === false) {
|
||||
throw new UOJProblemConfException("找不到本题的 std。请上传 std 代码文件,或停用本题的 Hack 功能。");
|
||||
}
|
||||
if (UOJLang::findSourceCode('val', $this->upload_dir) === false) {
|
||||
throw new UOJProblemConfException("找不到本题的 val。请上传 val 代码文件,或停用本题的 Hack 功能。");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function _sync() {
|
||||
try {
|
||||
if (!$this->create_prepare_folder()) {
|
||||
throw new UOJSyncFailedException('创建临时文件夹失败');
|
||||
}
|
||||
|
||||
$this->requirement = [];
|
||||
$this->problem_extra_config = $this->problem->getExtraConfig();;
|
||||
if (!is_file("{$this->upload_dir}/problem.conf")) {
|
||||
throw new UOJFileNotFoundException("problem.conf");
|
||||
}
|
||||
@ -178,9 +313,7 @@
|
||||
throw new UOJProblemConfException("syntax error");
|
||||
}
|
||||
|
||||
$this->allow_files = array_flip(array_filter(scandir($this->upload_dir), function($x) {
|
||||
return $x !== '.' && $x !== '..';
|
||||
}));
|
||||
$this->allow_files = array_flip(FS::scandir($this->upload_dir));
|
||||
|
||||
$zip_file = new ZipArchive();
|
||||
if ($zip_file->open("{$this->prepare_dir}/download.zip", ZipArchive::CREATE) !== true) {
|
||||
@ -191,6 +324,12 @@
|
||||
$this->copy_to_prepare('require');
|
||||
}
|
||||
|
||||
if (isset($this->allow_files['testlib.h']) && is_file("{$this->upload_dir}/testlib.h")) {
|
||||
$this->copy_file_to_prepare('testlib.h');
|
||||
}
|
||||
|
||||
$this->fast_hackable_check();
|
||||
|
||||
if ($this->check_conf_on('use_builtin_judger')) {
|
||||
$n_tests = getUOJConfVal($this->problem_conf, 'n_tests', 10);
|
||||
if (!validateUInt($n_tests) || $n_tests <= 0) {
|
||||
@ -207,33 +346,38 @@
|
||||
if (!$this->check_conf_on('interaction_mode')) {
|
||||
if (isset($this->problem_conf['use_builtin_checker'])) {
|
||||
if (!preg_match('/^[a-zA-Z0-9_]{1,20}$/', $this->problem_conf['use_builtin_checker'])) {
|
||||
throw new Exception("<strong>" . htmlspecialchars($this->problem_conf['use_builtin_checker']) . "</strong> is not a valid checker");
|
||||
throw new Exception("<strong>" . HTML::escape($this->problem_conf['use_builtin_checker']) . "</strong> is not a valid checker");
|
||||
}
|
||||
} else {
|
||||
$this->copy_file_to_prepare('chk.cpp');
|
||||
$this->compile_at_prepare('chk', array('need_include_header' => true));
|
||||
$this->copy_source_code_to_prepare('chk');
|
||||
$this->compile_at_prepare('chk', ['need_include_header' => true]);
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->check_conf_on('submit_answer')) {
|
||||
if ($this->problem['hackable']) {
|
||||
throw new UOJProblemConfException("the problem can't be hackable if submit_answer is on");
|
||||
}
|
||||
|
||||
if (!isset($this->problem_extra_config['dont_download_input'])) {
|
||||
for ($num = 1; $num <= $n_tests; $num++) {
|
||||
$input_file_name = getUOJProblemInputFileName($this->problem_conf, $num);
|
||||
$output_file_name = getUOJProblemOutputFileName($this->problem_conf, $num);
|
||||
|
||||
if (!isset($this->problem_extra_config['dont_download_input'])) {
|
||||
$zip_file->addFile("{$this->prepare_dir}/$input_file_name", "$input_file_name");
|
||||
}
|
||||
}
|
||||
|
||||
$this->requirement[] = array('name' => "output$num", 'type' => 'text', 'file_name' => $output_file_name);
|
||||
$n_output_files = 0;
|
||||
for ($num = 1; $num <= $n_tests; $num++) {
|
||||
$output_file_id = getUOJConfVal($this->problem_conf, ["output_file_id_{$num}", "output_file_id"], "$num");
|
||||
if (!validateUInt($output_file_id) || $output_file_id < 0 || $output_file_id > $n_tests) {
|
||||
throw new UOJProblemConfException("output_file_id/output_file_id_{$num} must be in [1, n_tests]");
|
||||
}
|
||||
$n_output_files = max($n_output_files, $output_file_id);
|
||||
}
|
||||
for ($num = 1; $num <= $n_output_files; $num++) {
|
||||
$output_file_name = getUOJProblemOutputFileName($this->problem_conf, $num);
|
||||
$this->requirement[] = ['name' => "output$num", 'type' => 'text', 'file_name' => $output_file_name];
|
||||
}
|
||||
} else {
|
||||
$n_ex_tests = getUOJConfVal($this->problem_conf, 'n_ex_tests', 0);
|
||||
if (!validateUInt($n_ex_tests) || $n_ex_tests < 0) {
|
||||
throw new UOJProblemConfException("n_ex_tests must be a non-negative integer");
|
||||
throw new UOJProblemConfException('n_ex_tests must be a non-negative integer. Current value: ' . HTML::escape($n_ex_tests));
|
||||
}
|
||||
|
||||
for ($num = 1; $num <= $n_ex_tests; $num++) {
|
||||
@ -244,30 +388,28 @@
|
||||
$this->copy_file_to_prepare($output_file_name);
|
||||
}
|
||||
|
||||
if ($this->problem['hackable']) {
|
||||
$this->copy_file_to_prepare('std.cpp');
|
||||
if ($this->problem->info['hackable']) {
|
||||
$this->copy_source_code_to_prepare('std');
|
||||
if (isset($this->problem_conf['with_implementer']) && $this->problem_conf['with_implementer'] == 'on') {
|
||||
$this->compile_at_prepare('std',
|
||||
array(
|
||||
'src' => 'implementer.cpp std.cpp',
|
||||
$this->compile_at_prepare('std', [
|
||||
'implementer' => 'implementer',
|
||||
'path' => 'require'
|
||||
)
|
||||
);
|
||||
]);
|
||||
} else {
|
||||
$this->compile_at_prepare('std');
|
||||
}
|
||||
$this->copy_file_to_prepare('val.cpp');
|
||||
$this->compile_at_prepare('val', array('need_include_header' => true));
|
||||
$this->copy_source_code_to_prepare('val');
|
||||
$this->compile_at_prepare('val', ['need_include_header' => true]);
|
||||
}
|
||||
|
||||
if ($this->check_conf_on('interaction_mode')) {
|
||||
$this->copy_file_to_prepare('interactor.cpp');
|
||||
$this->compile_at_prepare('interactor', array('need_include_header' => true));
|
||||
$this->copy_source_code_to_prepare('interactor');
|
||||
$this->compile_at_prepare('interactor', ['need_include_header' => true]);
|
||||
}
|
||||
|
||||
$n_sample_tests = getUOJConfVal($this->problem_conf, 'n_sample_tests', $n_tests);
|
||||
if (!validateUInt($n_sample_tests) || $n_sample_tests < 0) {
|
||||
throw new UOJProblemConfException("n_sample_tests must be a non-negative integer");
|
||||
throw new UOJProblemConfException('n_sample_tests must be a non-negative integer. Current value: ' . HTML::escape($n_sample_tests));
|
||||
}
|
||||
if ($n_sample_tests > $n_ex_tests) {
|
||||
throw new UOJProblemConfException("n_sample_tests can't be greater than n_ex_tests");
|
||||
@ -284,7 +426,7 @@
|
||||
}
|
||||
}
|
||||
|
||||
$this->requirement[] = array('name' => 'answer', 'type' => 'source code', 'file_name' => 'answer.code');
|
||||
$this->requirement[] = ['name' => 'answer', 'type' => 'source code', 'file_name' => 'answer.code'];
|
||||
}
|
||||
} else {
|
||||
if (!isSuperUser($this->user)) {
|
||||
@ -295,65 +437,72 @@
|
||||
}
|
||||
$this->makefile_at_prepare();
|
||||
|
||||
$this->requirement[] = array('name' => 'answer', 'type' => 'source code', 'file_name' => 'answer.code');
|
||||
$this->requirement[] = ['name' => 'answer', 'type' => 'source code', 'file_name' => 'answer.code'];
|
||||
}
|
||||
}
|
||||
putUOJConf("{$this->prepare_dir}/problem.conf", $this->final_problem_conf);
|
||||
|
||||
if (isset($this->allow_files['download']) && is_dir("{$this->upload_dir}/download")) {
|
||||
foreach (scandir("{$this->upload_dir}/download") as $file_name) {
|
||||
if (is_file("{$this->upload_dir}/download/{$file_name}")) {
|
||||
$zip_file->addFile("{$this->upload_dir}/download/{$file_name}", $file_name);
|
||||
$download_dir = "{$this->upload_dir}/download";
|
||||
foreach (FS::scandir_r($download_dir) as $file_name) {
|
||||
if (is_file("{$download_dir}/{$file_name}")) {
|
||||
$zip_file->addFile("{$download_dir}/{$file_name}", $file_name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$zip_file->close();
|
||||
|
||||
$orig_requirement = json_decode($this->problem['submission_requirement'], true);
|
||||
$orig_requirement = $this->problem->getSubmissionRequirement();
|
||||
if (!$orig_requirement) {
|
||||
$esc_requirement = DB::escape(json_encode($this->requirement));
|
||||
DB::update("update problems set submission_requirement = '$esc_requirement' where id = $id");
|
||||
DB::update([
|
||||
"update problems",
|
||||
"set", ["submission_requirement" => json_encode($this->requirement)],
|
||||
"where", ["id" => $this->id]
|
||||
]);
|
||||
}
|
||||
|
||||
UOJSystemUpdate::updateProblemInternally($this->problem, [
|
||||
'text' => 'sync',
|
||||
'requestor' => Auth::check() ? Auth::id() : null
|
||||
]);
|
||||
} catch (Exception $e) {
|
||||
exec("rm {$this->prepare_dir} -r");
|
||||
$this->remove_prepare_folder();
|
||||
return $e->getMessage();
|
||||
}
|
||||
|
||||
exec("rm {$this->data_dir} -r");
|
||||
UOJLocalRun::exec(['rm', $this->data_dir, '-r']);
|
||||
rename($this->prepare_dir, $this->data_dir);
|
||||
|
||||
exec("cd /var/uoj_data; rm $id.zip; zip $id.zip $id -r -q");
|
||||
UOJLocalRun::execAnd([
|
||||
['cd', '/var/uoj_data'],
|
||||
['zip', "{$this->id}.next.zip", $this->id, '-r', '-q'],
|
||||
['mv', "{$this->id}.next.zip", "{$this->id}.zip", '-f'],
|
||||
]);
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
public function sync() {
|
||||
return $this->lock(LOCK_EX, fn () => $this->_sync());
|
||||
}
|
||||
}
|
||||
|
||||
function dataSyncProblemData($problem, $user = null) {
|
||||
return (new SyncProblemDataHandler($problem, $user))->handle();
|
||||
}
|
||||
function dataAddExtraTest($problem, $input_file_name, $output_file_name) {
|
||||
$id = $problem['id'];
|
||||
function dataSyncProblemData($problem, $user = null) {
|
||||
return (new SyncProblemDataHandler($problem, $user))->sync();
|
||||
}
|
||||
|
||||
$cur_dir = "/var/uoj_data/upload/$id";
|
||||
|
||||
$problem_conf = getUOJConf("{$cur_dir}/problem.conf");
|
||||
if ($problem_conf == -1 || $problem_conf == -2) {
|
||||
return $problem_conf;
|
||||
}
|
||||
$problem_conf['n_ex_tests'] = getUOJConfVal($problem_conf, 'n_ex_tests', 0) + 1;
|
||||
|
||||
$new_input_name = getUOJProblemExtraInputFileName($problem_conf, $problem_conf['n_ex_tests']);
|
||||
$new_output_name = getUOJProblemExtraOutputFileName($problem_conf, $problem_conf['n_ex_tests']);
|
||||
|
||||
putUOJConf("$cur_dir/problem.conf", $problem_conf);
|
||||
move_uploaded_file($input_file_name, "$cur_dir/$new_input_name");
|
||||
move_uploaded_file($output_file_name, "$cur_dir/$new_output_name");
|
||||
|
||||
if (dataSyncProblemData($problem) === '') {
|
||||
rejudgeProblemAC($problem);
|
||||
function dataAddHackPoint($problem, $uploaded_input_file, $uploaded_output_file, $reason = null, $user = null) {
|
||||
if ($reason === null) {
|
||||
if (UOJHack::cur()) {
|
||||
$reason = [
|
||||
'rejudge' => '自动重测本题所有获得 100 分的提交记录',
|
||||
'hack_url' => HTML::url(UOJHack::cur()->getUri())
|
||||
];
|
||||
} else {
|
||||
error_log('hack successfully but sync failed.');
|
||||
$reason = [];
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
return (new SyncProblemDataHandler($problem, $user))->addHackPoint($uploaded_input_file, $uploaded_output_file, $reason);
|
||||
}
|
||||
|
34
web/app/libs/uoj-expection-lib.php
Normal file
34
web/app/libs/uoj-expection-lib.php
Normal file
@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
class UOJProblemConfException extends Exception {
|
||||
public function __construct($message) {
|
||||
parent::__construct("<strong>problem.conf</strong> : $message");
|
||||
}
|
||||
}
|
||||
class UOJFileNotFoundException extends Exception {
|
||||
public function __construct($file_name) {
|
||||
parent::__construct("file <strong>" . HTML::escape($file_name) . '</strong> not found');
|
||||
}
|
||||
}
|
||||
class UOJSyncFailedException extends Exception {
|
||||
public function __construct($msg) {
|
||||
parent::__construct('同步失败:'.HTML::escape($msg));
|
||||
}
|
||||
}
|
||||
class UOJUploadFailedException extends Exception {
|
||||
public function __construct($msg) {
|
||||
parent::__construct('上传失败:'.HTML::escape($msg));
|
||||
}
|
||||
}
|
||||
|
||||
class UOJInvalidArgumentException extends Exception {
|
||||
public function __construct($msg) {
|
||||
parent::__construct(HTML::escape($msg));
|
||||
}
|
||||
}
|
||||
|
||||
class UOJNotLoginException extends Exception {
|
||||
public function __construct($msg = '未登录') {
|
||||
parent::__construct(HTML::escape($msg));
|
||||
}
|
||||
}
|
@ -1,9 +1,10 @@
|
||||
<?php
|
||||
define('SCRIPT_REFRESH_AS_GET', '<script>;window.location = window.location.origin + window.location.pathname + (window.location.search.length ? window.location.search + "&" : "?") + "_refresh_" + (+new Date()) + "=" + (+new Date()) + window.location.hash;</script>');
|
||||
define('SCRIPT_REFRESH_AS_GET', '<script>;window.location = window.location.origin + window.location.pathname + (window.location.search.length ? window.location.search + "&" : "?") + "_refresh_" + (+new Date()) + "=" + (+new Date()) + window.location.hash;</script>');
|
||||
|
||||
class UOJForm {
|
||||
class UOJBs4Form {
|
||||
public $form_name;
|
||||
public $succ_href;
|
||||
public $back_href = null;
|
||||
public $no_submit = false;
|
||||
public $ctrl_enter_submit = false;
|
||||
public $extra_validator = null;
|
||||
@ -15,36 +16,40 @@
|
||||
private $vdata = array();
|
||||
private $main_html = '';
|
||||
public $max_post_size = 15728640; // 15M
|
||||
public $max_file_size_mb = 10; // 10M
|
||||
|
||||
public $handle;
|
||||
|
||||
public $submit_button_config = array();
|
||||
public $submit_button_config = [];
|
||||
public $control_label_config = ['class' => 'col-sm-2'];
|
||||
public $input_config = ['class' => 'col-sm-3'];
|
||||
public $textarea_config = ['class' => 'col-sm-10'];
|
||||
|
||||
public function __construct($form_name) {
|
||||
$this->form_name = $form_name;
|
||||
$this->succ_href = $_SERVER['REQUEST_URI'];
|
||||
$this->handle = function(&$vdata) {
|
||||
$this->succ_href = UOJContext::requestURI();
|
||||
$this->handle = function (&$vdata) {
|
||||
};
|
||||
|
||||
$this->run_at_server_handler["check-{$this->form_name}"] = function() {
|
||||
$this->run_at_server_handler["check-{$this->form_name}"] = function () {
|
||||
die(json_encode($this->validateAtServer()));
|
||||
};
|
||||
$this->run_at_server_handler["submit-{$this->form_name}"] = function() {
|
||||
$this->run_at_server_handler["submit-{$this->form_name}"] = function () {
|
||||
if ($this->no_submit) {
|
||||
become404Page();
|
||||
UOJResponse::page404();
|
||||
}
|
||||
foreach ($this->data as $field) {
|
||||
if (!isset($field['no_val']) && !isset($_POST[$field['name']])) {
|
||||
becomeMsgPage('The form is incomplete.');
|
||||
UOJResponse::message('The form is incomplete.');
|
||||
}
|
||||
}
|
||||
|
||||
if (UOJContext::requestMethod() == 'POST') {
|
||||
$len = UOJContext::contentLength();
|
||||
if ($len === null) {
|
||||
become403Page();
|
||||
UOJResponse::page403();
|
||||
} elseif ($len > $this->max_post_size) {
|
||||
becomeMsgPage('The form is too large.');
|
||||
UOJResponse::message('The form is too large.');
|
||||
}
|
||||
}
|
||||
|
||||
@ -56,13 +61,13 @@
|
||||
$esc_err = htmlspecialchars($err);
|
||||
$err_str .= "$name: $esc_err<br />";
|
||||
}
|
||||
becomeMsgPage($err_str);
|
||||
UOJResponse::message($err_str);
|
||||
}
|
||||
$fun = $this->handle;
|
||||
$fun($this->vdata);
|
||||
|
||||
if ($this->succ_href !== 'none') {
|
||||
header("Location: {$this->succ_href}");
|
||||
redirectTo($this->succ_href);
|
||||
}
|
||||
die();
|
||||
};
|
||||
@ -73,18 +78,13 @@
|
||||
$this->ajax_submit_js = $js;
|
||||
}
|
||||
|
||||
public function add($name, $html, $validator_php, $validator_js, $no_val = false) {
|
||||
public function add($name, $html, $validator_php, $validator_js) {
|
||||
$this->main_html .= $html;
|
||||
$data = array(
|
||||
$this->data[] = array(
|
||||
'name' => $name,
|
||||
'validator_php' => $validator_php,
|
||||
'validator_js' => $validator_js);
|
||||
|
||||
if ($no_val) {
|
||||
$data['no_val'] = '';
|
||||
}
|
||||
|
||||
$this->data[] = $data;
|
||||
'validator_js' => $validator_js
|
||||
);
|
||||
}
|
||||
public function appendHTML($html) {
|
||||
$this->main_html .= $html;
|
||||
@ -95,59 +95,62 @@
|
||||
$this->data[] = array(
|
||||
'name' => $name,
|
||||
'validator_js' => 'always_ok',
|
||||
'no_val' => '');
|
||||
'no_val' => ''
|
||||
);
|
||||
}
|
||||
|
||||
public function addHidden($name, $default_value, $validator_php, $validator_js) {
|
||||
$default_value = htmlspecialchars($default_value);
|
||||
$html = <<<EOD
|
||||
<input type="hidden" name="$name" id="input-$name" value="$default_value" />
|
||||
EOD;
|
||||
<input type="hidden" name="$name" id="input-$name" value="$default_value" />
|
||||
EOD;
|
||||
$this->add($name, $html, $validator_php, $validator_js);
|
||||
}
|
||||
|
||||
public function addInput($name, $type, $label_text, $default_value, $validator_php, $validator_js) {
|
||||
$default_value = htmlspecialchars($default_value);
|
||||
$html = <<<EOD
|
||||
<div id="div-$name" class="form-group">
|
||||
<label for="input-$name" class="col-sm-2 control-label">$label_text</label>
|
||||
<div class="col-sm-3">
|
||||
<input type="$type" class="form-control" name="$name" id="input-$name" value="$default_value" />
|
||||
<span class="help-block invalid-feedback" id="help-$name"></span>
|
||||
<div class="form-group" id="div-$name">
|
||||
<label for="input-$name" class="{$this->control_label_config['class']} control-label">$label_text</label>
|
||||
<div class="{$this->input_config['class']}">
|
||||
<input class="form-control" type="$type" class="form-control" name="$name" id="input-$name" value="$default_value" />
|
||||
<span class="help-block" id="help-$name"></span>
|
||||
</div>
|
||||
</div>
|
||||
EOD;
|
||||
</div>
|
||||
EOD;
|
||||
$this->add($name, $html, $validator_php, $validator_js);
|
||||
}
|
||||
public function addSelect($name, $options, $label_text, $default_value) {
|
||||
$default_value = htmlspecialchars($default_value);
|
||||
$html = <<<EOD
|
||||
<div id="div-$name" class="form-group">
|
||||
<label for="input-$name" class="col-sm-2 control-label">$label_text</label>
|
||||
<div class="col-sm-3">
|
||||
<select class="form-control form-select" id="input-$name" name="$name">
|
||||
<div id="div-$name">
|
||||
<label for="input-$name" class="{$this->control_label_config['class']} control-label">$label_text</label>
|
||||
<div class="{$this->input_config['class']}">
|
||||
<select class="form-select" id="input-content" name="$name">
|
||||
|
||||
EOD;
|
||||
EOD;
|
||||
foreach ($options as $opt_name => $opt_label) {
|
||||
if ($opt_name != $default_value) {
|
||||
$html .= <<<EOD
|
||||
<option value="$opt_name">$opt_label</option>
|
||||
|
||||
EOD;
|
||||
EOD;
|
||||
} else {
|
||||
$html .= <<<EOD
|
||||
<option value="$opt_name" selected="selected">$opt_label</option>
|
||||
|
||||
EOD;
|
||||
EOD;
|
||||
}
|
||||
}
|
||||
$html .= <<<EOD
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
EOD;
|
||||
$this->add($name, $html,
|
||||
function($opt) use ($options) {
|
||||
</div>
|
||||
EOD;
|
||||
$this->add(
|
||||
$name,
|
||||
$html,
|
||||
function ($opt) use ($options) {
|
||||
return isset($options[$opt]) ? '' : "无效选项";
|
||||
},
|
||||
null
|
||||
@ -161,81 +164,86 @@ EOD;
|
||||
public function addVSelect($name, $options, $label_text, $default_value) {
|
||||
$default_value = htmlspecialchars($default_value);
|
||||
$html = <<<EOD
|
||||
<div id="div-$name" class="mb-3">
|
||||
<label for="input-$name" class="control-label">$label_text</label>
|
||||
<select class="form-control form-select" id="input-{$name}" name="$name">
|
||||
<div id="div-$name">
|
||||
<label for="input-$name" class="form-label">$label_text</label>
|
||||
<select class="form-select" id="input-{$name}" name="$name">
|
||||
|
||||
EOD;
|
||||
EOD;
|
||||
foreach ($options as $opt_name => $opt_label) {
|
||||
if ($opt_name != $default_value) {
|
||||
$html .= <<<EOD
|
||||
<option value="$opt_name">$opt_label</option>
|
||||
|
||||
EOD;
|
||||
EOD;
|
||||
} else {
|
||||
$html .= <<<EOD
|
||||
<option value="$opt_name" selected="selected">$opt_label</option>
|
||||
|
||||
EOD;
|
||||
EOD;
|
||||
}
|
||||
}
|
||||
$html .= <<<EOD
|
||||
</select>
|
||||
</div>
|
||||
EOD;
|
||||
$this->add($name, $html,
|
||||
function($opt) use ($options) {
|
||||
</div>
|
||||
EOD;
|
||||
$this->add(
|
||||
$name,
|
||||
$html,
|
||||
function ($opt) use ($options) {
|
||||
return isset($options[$opt]) ? '' : "无效选项";
|
||||
},
|
||||
null
|
||||
);
|
||||
}
|
||||
|
||||
public function addTextArea($name, $label_text, $default_value, $validator_php, $validator_js, $no_val = false) {
|
||||
public function addTextArea($name, $label_text, $default_value, $validator_php, $validator_js) {
|
||||
$default_value = htmlspecialchars($default_value);
|
||||
$this->is_big = true;
|
||||
$html = <<<EOD
|
||||
<div id="div-$name" class="form-group">
|
||||
<label for="input-$name" class="col-sm-2 control-label">$label_text</label>
|
||||
<div class="col-sm-10">
|
||||
<div id="div-$name" class="form-group">
|
||||
<label for="input-$name" class="{$this->control_label_config['class']} control-label">$label_text</label>
|
||||
<div class="{$this->textarea_config['class']}">
|
||||
<textarea class="form-control" name="$name" id="input-$name">$default_value</textarea>
|
||||
<span class="help-block invalid-feedback" id="help-$name"></span>
|
||||
<span class="invalid-feedback" id="help-$name"></span>
|
||||
</div>
|
||||
</div>
|
||||
EOD;
|
||||
$this->add($name, $html, $validator_php, $validator_js, $no_val);
|
||||
</div>
|
||||
EOD;
|
||||
$this->add($name, $html, $validator_php, $validator_js);
|
||||
}
|
||||
public function addVTextArea($name, $label_text, $default_value, $validator_php, $validator_js, $no_val = false) {
|
||||
public function addVTextArea($name, $label_text, $default_value, $validator_php, $validator_js) {
|
||||
$default_value = htmlspecialchars($default_value);
|
||||
$this->is_big = true;
|
||||
$html = <<<EOD
|
||||
<div id="div-$name" class="form-group">
|
||||
<label for="input-$name" class="control-label">$label_text</label>
|
||||
<div id="div-$name">
|
||||
<label for="input-$name" class="form-label">$label_text</label>
|
||||
<textarea class="form-control" name="$name" id="input-$name">$default_value</textarea>
|
||||
<span class="help-block invalid-feedback" id="help-$name"></span>
|
||||
</div>
|
||||
EOD;
|
||||
$this->add($name, $html, $validator_php, $validator_js, $no_val);
|
||||
<span class="invalid-feedback" id="help-$name"></span>
|
||||
</div>
|
||||
EOD;
|
||||
$this->add($name, $html, $validator_php, $validator_js);
|
||||
}
|
||||
public function addCheckBox($name, $label_text, $default_value) {
|
||||
$default_value = htmlspecialchars($default_value);
|
||||
$status = $default_value ? 'checked="checked" ' : '';
|
||||
$html = <<<EOD
|
||||
<div class="checkbox">
|
||||
<label for="input-$name"><input type="checkbox" id="input-$name" name="$name" $status/> $label_text</label>
|
||||
</div>
|
||||
EOD;
|
||||
<div class="form-checkbox">
|
||||
<input class="form-check-input" type="checkbox" id="input-$name" name="$name" $status/>
|
||||
<label class="form-check-label" for="input-$name">
|
||||
$label_text
|
||||
</label>
|
||||
</div>
|
||||
EOD;
|
||||
$this->addNoVal($name, $html);
|
||||
}
|
||||
public function addVCheckboxes($name, $options, $label_text, $default_value) {
|
||||
$default_value = htmlspecialchars($default_value);
|
||||
$html = <<<EOD
|
||||
<div id="div-$name" class="input-group mb-3">
|
||||
<label class="form-label me-3">$label_text</label>
|
||||
<label class="form-label me-3">$label_text</label>
|
||||
EOD;
|
||||
foreach ($options as $opt_name => $opt_label) {
|
||||
$html .= <<<EOD
|
||||
<div class="form-check ms-2">
|
||||
<div class="form-check ms-2">
|
||||
EOD;
|
||||
if ($opt_name != $default_value) {
|
||||
$html .= <<<EOD
|
||||
@ -248,14 +256,16 @@ EOD;
|
||||
}
|
||||
$html .= <<<EOD
|
||||
<label class="form-check-label" for="input-$name-$opt_name">$opt_label</label>
|
||||
</div>
|
||||
</div>
|
||||
EOD;
|
||||
}
|
||||
$html .= <<<EOD
|
||||
</div>
|
||||
EOD;
|
||||
$this->add($name, $html,
|
||||
function($opt) use ($options) {
|
||||
$this->add(
|
||||
$name,
|
||||
$html,
|
||||
function ($opt) use ($options) {
|
||||
return isset($options[$opt]) ? '' : "无效选项";
|
||||
},
|
||||
null
|
||||
@ -263,81 +273,18 @@ EOD;
|
||||
}
|
||||
public function addCKEditor($name, $label_text, $default_value, $validator_php, $validator_js) {
|
||||
$default_value = htmlspecialchars($default_value);
|
||||
$GLOBALS['REQUIRE_LIB']['ckeditor'] = '';
|
||||
global $REQUIRE_LIB;
|
||||
$REQUIRE_LIB['ckeditor'] = '';
|
||||
|
||||
$this->is_big = true;
|
||||
|
||||
$html = <<<EOD
|
||||
<div id="div-$name">
|
||||
<div id="div-$name">
|
||||
<label for="input-$name" class="control-label">$label_text</label>
|
||||
<textarea class="ckeditor" name="$name" id="input-$name">$default_value</textarea>
|
||||
<span class="help-block invalid-feedback" id="help-$name"></span>
|
||||
</div>
|
||||
EOD;
|
||||
$this->add($name, $html, $validator_php, $validator_js);
|
||||
}
|
||||
|
||||
public function addBlogEditor(UOJBlogEditor $editor) {
|
||||
$GLOBALS['REQUIRE_LIB']['blog-editor'] = '';
|
||||
|
||||
$this->is_big = true;
|
||||
|
||||
$name = $editor->name;
|
||||
|
||||
$this->addVInput("{$name}_title", 'text', '标题', $editor->cur_data['title'],
|
||||
function ($title) use ($editor) {
|
||||
return $editor->validateTitle();
|
||||
},
|
||||
null
|
||||
);
|
||||
|
||||
$content_md_html = HTML::div_vtextarea("{$name}_content_md", '内容', $editor->cur_data['content_md']);
|
||||
|
||||
$this->add("{$name}_content_md", $content_md_html,
|
||||
function ($content_md) use ($editor) {
|
||||
return $editor->validateContentMd();
|
||||
},
|
||||
'always_ok'
|
||||
);
|
||||
|
||||
$this->appendHTML(<<<EOD
|
||||
<script type="text/javascript">blog_editor_init("$name");</script>
|
||||
EOD
|
||||
);
|
||||
|
||||
$this->run_at_server_handler["save-{$name}"] = function() use ($name, $editor) {
|
||||
if ($this->no_submit) {
|
||||
become404Page();
|
||||
}
|
||||
foreach (array("{$name}_title", "{$name}_content_md") as $field_name) {
|
||||
if (!isset($_POST[$field_name])) {
|
||||
becomeMsgPage('The form is incomplete.');
|
||||
}
|
||||
}
|
||||
crsf_defend();
|
||||
$errors = $this->validateAtServer();
|
||||
if (!$errors) {
|
||||
$editor->handleSave();
|
||||
}
|
||||
die(json_encode($errors));
|
||||
};
|
||||
}
|
||||
public function addSlideEditor($name, $label_text, $default_value, $validator_php, $validator_js) {
|
||||
$GLOBALS['REQUIRE_LIB']['slide-editor'] = '';
|
||||
$default_value = htmlspecialchars($default_value);
|
||||
|
||||
$this->is_big = true;
|
||||
|
||||
$html = <<<EOD
|
||||
<div id="div-$name">
|
||||
<label for="input-$name" class="control-label">$label_text</label>
|
||||
<textarea name="$name" id="input-$name">$default_value</textarea>
|
||||
<span class="help-block invalid-feedback" id="help-$name"></span>
|
||||
</div>
|
||||
<script type="text/javascript">
|
||||
$('#input-$name').slide_editor();
|
||||
</script>
|
||||
EOD;
|
||||
<span class="help-block" id="help-$name"></span>
|
||||
</div>
|
||||
EOD;
|
||||
$this->add($name, $html, $validator_php, $validator_js);
|
||||
}
|
||||
|
||||
@ -349,9 +296,11 @@ EOD;
|
||||
}
|
||||
}
|
||||
|
||||
public function addSourceCodeInput($name, $text, $languages) {
|
||||
$this->add("{$name}_upload_type", '',
|
||||
function($type, &$vdata) use ($name) {
|
||||
public function addSourceCodeInput($name, $text, $languages, $preferred_lang = null) {
|
||||
$this->add(
|
||||
"{$name}_upload_type",
|
||||
'',
|
||||
function ($type, &$vdata) use ($name) {
|
||||
if ($type == 'editor') {
|
||||
if (!isset($_POST["{$name}_editor"])) {
|
||||
return '你在干啥……怎么什么都没交过来……?';
|
||||
@ -365,9 +314,11 @@ EOD;
|
||||
);
|
||||
$this->addNoVal("{$name}_editor", '');
|
||||
$this->addNoVal("{$name}_file", '');
|
||||
$this->add("{$name}_language", '',
|
||||
function($lang) use ($languages) {
|
||||
if (!in_array($lang, $languages)) {
|
||||
$this->add(
|
||||
"{$name}_language",
|
||||
'',
|
||||
function ($lang) use ($languages) {
|
||||
if (!isset($languages[$lang])) {
|
||||
return '该语言不被支持';
|
||||
}
|
||||
return '';
|
||||
@ -375,34 +326,40 @@ EOD;
|
||||
'always_ok'
|
||||
);
|
||||
|
||||
$preferred_language = Cookie::get('uoj_preferred_language');
|
||||
if ($preferred_language == null || !in_array($preferred_language, $languages)) {
|
||||
$preferred_language = $languages[0];
|
||||
if ($preferred_lang == null || !isset($languages[$preferred_lang])) {
|
||||
$preferred_lang = Cookie::get('uoj_preferred_language');
|
||||
}
|
||||
if ($preferred_lang == null || !isset($languages[$preferred_lang])) {
|
||||
$preferred_lang = UOJLang::$default_preferred_language;
|
||||
}
|
||||
|
||||
$langs_options_str = '';
|
||||
foreach ($languages as $lang) {
|
||||
$langs_options_str .= "<option";
|
||||
if ($lang == $preferred_language) {
|
||||
foreach ($languages as $lang_code => $lang_display) {
|
||||
$langs_options_str .= '<option';
|
||||
$langs_options_str .= ' value="' . $lang_code . '"';
|
||||
if ($lang_code == $preferred_lang) {
|
||||
$langs_options_str .= ' selected="selected"';
|
||||
}
|
||||
$langs_options_str .= ">$lang</option>";
|
||||
$langs_options_str .= ">$lang_display</option>";
|
||||
}
|
||||
$langs_options_json = json_encode($langs_options_str);
|
||||
$this->appendHTML(<<<EOD
|
||||
<div class="form-group" id="form-group-$name"></div>
|
||||
<script type="text/javascript">
|
||||
$('#form-group-$name').source_code_form_group('$name', '$text', $langs_options_json);
|
||||
</script>
|
||||
EOD
|
||||
$this->appendHTML(
|
||||
<<<EOD
|
||||
<div class="form-group" id="form-group-$name"></div>
|
||||
<script type="text/javascript">
|
||||
$('#form-group-$name').source_code_form_group('$name', '$text', $langs_options_json);
|
||||
</script>
|
||||
EOD
|
||||
);
|
||||
|
||||
$this->is_big = true;
|
||||
$this->has_file = true;
|
||||
}
|
||||
public function addTextFileInput($name, $text) {
|
||||
$this->add("{$name}_upload_type", '',
|
||||
function($type, &$vdata) use ($name) {
|
||||
$this->add(
|
||||
"{$name}_upload_type",
|
||||
'',
|
||||
function ($type, &$vdata) use ($name) {
|
||||
if ($type == 'editor') {
|
||||
if (!isset($_POST["{$name}_editor"])) {
|
||||
return '你在干啥……怎么什么都没交过来……?';
|
||||
@ -417,12 +374,13 @@ EOD
|
||||
$this->addNoVal("{$name}_editor", '');
|
||||
$this->addNoVal("{$name}_file", '');
|
||||
|
||||
$this->appendHTML(<<<EOD
|
||||
<div class="form-group" id="form-group-$name"></div>
|
||||
<script type="text/javascript">
|
||||
$('#form-group-$name').text_file_form_group('$name', '$text');
|
||||
</script>
|
||||
EOD
|
||||
$this->appendHTML(
|
||||
<<<EOD
|
||||
<div class="form-group" id="form-group-$name"></div>
|
||||
<script type="text/javascript">
|
||||
$('#form-group-$name').text_file_form_group('$name', '$text');
|
||||
</script>
|
||||
EOD
|
||||
);
|
||||
|
||||
$this->is_big = true;
|
||||
@ -434,16 +392,12 @@ EOD
|
||||
|
||||
$form_class = "form-horizontal";
|
||||
if ($this->submit_button_config['align'] == 'inline') {
|
||||
$form_class .= " uoj-form-inline";
|
||||
$form_class .= " uoj-bs4-form-inline";
|
||||
}
|
||||
if ($this->submit_button_config['align'] == 'compressed') {
|
||||
$form_class .= " uoj-form-compressed";
|
||||
}
|
||||
if (isset($this->submit_button_config['narrow']) && $this->submit_button_config['narrow']) {
|
||||
$form_class .= " uoj-form-narrow";
|
||||
$form_class .= " uoj-bs4-form-compressed";
|
||||
}
|
||||
echo '<form action="', $_SERVER['REQUEST_URI'], '" method="post" class="', $form_class, '" id="form-', $this->form_name, '"', $form_entype_str, '>';
|
||||
|
||||
echo HTML::hiddenToken();
|
||||
echo $this->main_html;
|
||||
|
||||
@ -455,7 +409,7 @@ EOD
|
||||
$this->submit_button_config['text'] = UOJLocale::get('submit');
|
||||
}
|
||||
if (!isset($this->submit_button_config['class_str'])) {
|
||||
$this->submit_button_config['class_str'] = 'btn btn-secondary';
|
||||
$this->submit_button_config['class_str'] = 'btn btn-secondary mt-2';
|
||||
}
|
||||
if ($this->submit_button_config['align'] == 'offset') {
|
||||
echo '<div class="form-group">';
|
||||
@ -463,7 +417,23 @@ EOD
|
||||
} else {
|
||||
echo '<div class="text-', $this->submit_button_config['align'], '">';
|
||||
}
|
||||
echo '<button type="submit" id="button-submit-', $this->form_name, '" name="submit-', $this->form_name, '" value="', $this->form_name, '" class="', (isset($this->submit_button_config['margin_class']) ? $this->submit_button_config['margin_class'] : 'mt-2'), ' ', $this->submit_button_config['class_str'], '">', $this->submit_button_config['text'], '</button>';
|
||||
|
||||
if ($this->back_href !== null) {
|
||||
echo '<div class="btn-toolbar">';
|
||||
}
|
||||
echo HTML::tag('button', [
|
||||
'type' => 'submit', 'id' => "button-submit-{$this->form_name}", 'name' => "submit-{$this->form_name}",
|
||||
'value' => $this->form_name, 'class' => $this->submit_button_config['class_str']
|
||||
], $this->submit_button_config['text']);
|
||||
if ($this->back_href !== null) {
|
||||
echo HTML::tag('a', [
|
||||
'class' => 'btn btn-secondary', 'href' => $this->back_href
|
||||
], '返回');
|
||||
}
|
||||
if ($this->back_href !== null) {
|
||||
echo '</div>';
|
||||
}
|
||||
|
||||
if ($this->submit_button_config['align'] == 'offset') {
|
||||
echo '</div>';
|
||||
}
|
||||
@ -477,10 +447,10 @@ EOD
|
||||
}
|
||||
|
||||
echo <<<EOD
|
||||
<script type="text/javascript">
|
||||
$(document).ready(function() {
|
||||
<script type="text/javascript">
|
||||
$(document).ready(function() {
|
||||
|
||||
EOD;
|
||||
EOD;
|
||||
if ($this->ctrl_enter_submit) {
|
||||
echo <<<EOD
|
||||
$('#form-{$this->form_name}').keydown(function(e) {
|
||||
@ -489,13 +459,13 @@ EOD;
|
||||
}
|
||||
});
|
||||
|
||||
EOD;
|
||||
EOD;
|
||||
}
|
||||
echo <<<EOD
|
||||
$('#form-{$this->form_name}').submit(function(e) {
|
||||
var ok = true;
|
||||
|
||||
EOD;
|
||||
EOD;
|
||||
$need_ajax = false;
|
||||
if ($this->extra_validator) {
|
||||
$need_ajax = true;
|
||||
@ -504,9 +474,9 @@ EOD;
|
||||
if ($field['validator_js'] != null) {
|
||||
if ($field['validator_js'] != 'always_ok') {
|
||||
echo <<<EOD
|
||||
var ${field['name']}_err = (${field['validator_js']})($('#input-${field['name']}').val());
|
||||
var {$field['name']}_err = ({$field['validator_js']})($('#input-{$field['name']}').val());
|
||||
|
||||
EOD;
|
||||
EOD;
|
||||
}
|
||||
} else {
|
||||
$need_ajax = true;
|
||||
@ -517,21 +487,20 @@ EOD;
|
||||
echo <<<EOD
|
||||
var post_data = {};
|
||||
|
||||
EOD;
|
||||
EOD;
|
||||
foreach ($this->data as $field) {
|
||||
if ($field['validator_js'] == null) {
|
||||
echo <<<EOD
|
||||
var ${field['name']}_err = 'Unknown error';
|
||||
post_data.${field['name']} = $('#input-${field['name']}').val();
|
||||
var {$field['name']}_err = 'Unknown error';
|
||||
post_data.{$field['name']} = $('#input-{$field['name']}').val();
|
||||
|
||||
EOD;
|
||||
EOD;
|
||||
}
|
||||
}
|
||||
echo <<<EOD
|
||||
if (post_data != {}) {
|
||||
post_data['check-{$this->form_name}'] = "";
|
||||
$.ajax({
|
||||
url : '${_SERVER['REQUEST_URI']}',
|
||||
url : '{$_SERVER['REQUEST_URI']}',
|
||||
type : 'POST',
|
||||
dataType : 'json',
|
||||
async : false,
|
||||
@ -539,13 +508,13 @@ EOD;
|
||||
data : post_data,
|
||||
success : function(data) {
|
||||
|
||||
EOD;
|
||||
EOD;
|
||||
foreach ($this->data as $field) {
|
||||
if ($field['validator_js'] == null) {
|
||||
echo <<<EOD
|
||||
${field['name']}_err = data.${field['name']};
|
||||
{$field['name']}_err = data.${field['name']};
|
||||
|
||||
EOD;
|
||||
EOD;
|
||||
}
|
||||
}
|
||||
echo <<<EOD
|
||||
@ -553,30 +522,29 @@ EOD;
|
||||
alert(data.extra);
|
||||
ok = false;
|
||||
}
|
||||
|
||||
EOD;
|
||||
echo <<<EOD
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
EOD;
|
||||
EOD;
|
||||
}
|
||||
|
||||
foreach ($this->data as $field) {
|
||||
if ($field['validator_js'] != 'always_ok') {
|
||||
echo <<<EOD
|
||||
if (${field['name']}_err) {
|
||||
$('#div-${field['name']}').addClass('has-error'); // for bootstrap4
|
||||
$('#div-${field['name']}').addClass('has-validation has-error');
|
||||
$('#div-${field['name']}').addClass('is-invalid');
|
||||
$('#input-${field['name']}').addClass('is-invalid');
|
||||
$('#help-${field['name']}').text(${field['name']}_err);
|
||||
ok = false;
|
||||
} else {
|
||||
$('#div-${field['name']}').removeClass('has-error'); // for bootstrap4
|
||||
$('#div-${field['name']}').removeClass('has-validation has-error');
|
||||
$('#div-${field['name']}').removeClass('is-invalid');
|
||||
$('#input-${field['name']}').removeClass('is-invalid');
|
||||
$('#help-${field['name']}').text('');
|
||||
}
|
||||
EOD;
|
||||
|
||||
EOD;
|
||||
}
|
||||
}
|
||||
|
||||
@ -589,26 +557,24 @@ EOD;
|
||||
ok = false;
|
||||
}
|
||||
|
||||
EOD;
|
||||
EOD;
|
||||
}
|
||||
if ($this->has_file) {
|
||||
echo <<<EOD
|
||||
$(this).find("input[type='file']").each(function() {
|
||||
for (var i = 0; i < this.files.length; i++) {
|
||||
if (this.files[i].size > 10 * 1024 * 1024) {
|
||||
$('#div-' + $(this).attr('name')).addClass('has-error'); // for bootstrap4
|
||||
$('#input-' + $(this).attr('name')).addClass('is-invalid');
|
||||
$('#help-' + $(this).attr('name')).text('文件大小不能超过10M');
|
||||
if (this.files[i].size > {$this->max_file_size_mb} * 1024 * 1024) {
|
||||
$('#div-' + $(this).attr('name')).addClass('has-error');
|
||||
$('#help-' + $(this).attr('name')).text('文件大小不能超过{$this->max_file_size_mb}M');
|
||||
ok = false;
|
||||
} else {
|
||||
$('#div-' + $(this).attr('name')).removeClass('has-error'); // for bootstrap4
|
||||
$('#input-' + $(this).attr('name')).removeClass('is-invalid');
|
||||
$('#div-' + $(this).attr('name')).removeClass('has-error');
|
||||
$('#help-' + $(this).attr('name')).text('');
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
EOD;
|
||||
EOD;
|
||||
}
|
||||
|
||||
if ($this->ajax_submit_js !== null) {
|
||||
@ -623,18 +589,18 @@ EOD;
|
||||
});
|
||||
}
|
||||
|
||||
EOD;
|
||||
EOD;
|
||||
} else {
|
||||
echo <<<EOD
|
||||
return ok;
|
||||
|
||||
EOD;
|
||||
EOD;
|
||||
}
|
||||
echo <<<EOD
|
||||
});
|
||||
});
|
||||
</script>
|
||||
EOD;
|
||||
});
|
||||
</script>
|
||||
EOD;
|
||||
}
|
||||
|
||||
private function validateAtServer() {
|
||||
@ -649,10 +615,18 @@ EOD;
|
||||
foreach ($this->data as $field) {
|
||||
if (!isset($field['no_val']) && isset($_POST[$field['name']])) {
|
||||
$fun = $field['validator_php'];
|
||||
$err = $fun($_POST[$field['name']], $this->vdata);
|
||||
$ret = $fun($_POST[$field['name']], $this->vdata, $field['name']);
|
||||
if (is_array($ret) && isset($ret['error'])) {
|
||||
$err = $ret['error'];
|
||||
} else {
|
||||
$err = $ret;
|
||||
}
|
||||
if ($err) {
|
||||
$errors[$field['name']] = $err;
|
||||
}
|
||||
if (is_array($ret) && isset($ret['store'])) {
|
||||
$this->vdata[$field['name']] = $ret['store'];
|
||||
}
|
||||
}
|
||||
}
|
||||
return $errors;
|
||||
@ -665,13 +639,15 @@ EOD;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function newAddDelCmdForm($form_name, $validate, $handle, $final = null) {
|
||||
$form = new UOJForm($form_name);
|
||||
function newAddDelCmdForm($form_name, $validate, $handle, $final = null) {
|
||||
$form = new UOJBs4Form($form_name);
|
||||
$form->addVTextArea(
|
||||
$form_name . '_cmds', '命令', '',
|
||||
function($str, &$vdata) use ($validate) {
|
||||
$form_name . '_cmds',
|
||||
'命令',
|
||||
'',
|
||||
function ($str, &$vdata) use ($validate) {
|
||||
$cmds = array();
|
||||
foreach (explode("\n", $str) as $line_id => $raw_line) {
|
||||
$line = trim($raw_line);
|
||||
@ -683,7 +659,7 @@ EOD;
|
||||
}
|
||||
$obj = trim(substr($line, 1));
|
||||
|
||||
if ($err = $validate($obj)) {
|
||||
if ($err = $validate($obj, $vdata)) {
|
||||
return '第' . ($line_id + 1) . '行:' . $err;
|
||||
}
|
||||
$cmds[] = array('type' => $line[0], 'obj' => $obj);
|
||||
@ -694,34 +670,34 @@ EOD;
|
||||
null
|
||||
);
|
||||
if (!isset($final)) {
|
||||
$form->handle = function(&$vdata) use ($handle) {
|
||||
$form->handle = function (&$vdata) use ($handle) {
|
||||
foreach ($vdata['cmds'] as $cmd) {
|
||||
$handle($cmd['type'], $cmd['obj']);
|
||||
$handle($cmd['type'], $cmd['obj'], $vdata);
|
||||
}
|
||||
};
|
||||
} else {
|
||||
$form->handle = function(&$vdata) use ($handle, $final) {
|
||||
$form->handle = function (&$vdata) use ($handle, $final) {
|
||||
foreach ($vdata['cmds'] as $cmd) {
|
||||
$handle($cmd['type'], $cmd['obj']);
|
||||
$handle($cmd['type'], $cmd['obj'], $vdata);
|
||||
}
|
||||
$final();
|
||||
};
|
||||
}
|
||||
return $form;
|
||||
}
|
||||
}
|
||||
|
||||
function newSubmissionForm($form_name, $requirement, $zip_file_name_gen, $handle) {
|
||||
$form = new UOJForm($form_name);
|
||||
function newSubmissionForm($form_name, $requirement, $zip_file_name_gen, $handle) {
|
||||
$form = new UOJBs4Form($form_name);
|
||||
foreach ($requirement as $req) {
|
||||
if ($req['type'] == "source code") {
|
||||
$languages = isset($req['languages']) ? $req['languages'] : $GLOBALS['uojSupportedLanguages'];
|
||||
$form->addSourceCodeInput("{$form_name}_{$req['name']}", UOJLocale::get('problems::source code').':'.$req['name'], $languages);
|
||||
$languages = UOJLang::getAvailableLanguages(isset($req['languages']) ? $req['languages'] : null);
|
||||
$form->addSourceCodeInput("{$form_name}_{$req['name']}", UOJLocale::get('problems::source code') . ':' . $req['name'], $languages);
|
||||
} elseif ($req['type'] == "text") {
|
||||
$form->addTextFileInput("{$form_name}_{$req['name']}", UOJLocale::get('problems::text file').':'.$req['file_name']);
|
||||
$form->addTextFileInput("{$form_name}_{$req['name']}", UOJLocale::get('problems::text file') . ':' . $req['file_name']);
|
||||
}
|
||||
}
|
||||
|
||||
$form->handle = function(&$vdata) use ($form_name, $requirement, $zip_file_name_gen, $handle) {
|
||||
$form->handle = function (&$vdata) use ($form_name, $requirement, $zip_file_name_gen, $handle) {
|
||||
global $myUser;
|
||||
|
||||
if ($myUser == null) {
|
||||
@ -732,8 +708,8 @@ EOD;
|
||||
$zip_file_name = $zip_file_name_gen();
|
||||
|
||||
$zip_file = new ZipArchive();
|
||||
if ($zip_file->open(UOJContext::storagePath().$zip_file_name, ZipArchive::CREATE) !== true) {
|
||||
becomeMsgPage('提交失败');
|
||||
if ($zip_file->open(UOJContext::storagePath() . $zip_file_name, ZipArchive::CREATE) !== true) {
|
||||
UOJResponse::message('提交失败');
|
||||
}
|
||||
|
||||
$content = array();
|
||||
@ -741,7 +717,7 @@ EOD;
|
||||
$content['config'] = array();
|
||||
foreach ($requirement as $req) {
|
||||
if ($req['type'] == "source code") {
|
||||
$content['config'][] = array("{$req['name']}_language", $_POST["{$form_name}_{$req['name']}_language"]);
|
||||
$content['config'][] = ["{$req['name']}_language", $_POST["{$form_name}_{$req['name']}_language"]];
|
||||
}
|
||||
}
|
||||
|
||||
@ -749,7 +725,7 @@ EOD;
|
||||
if ($_POST["{$form_name}_{$req['name']}_upload_type"] == 'editor') {
|
||||
$zip_file->addFromString($req['file_name'], $_POST["{$form_name}_{$req['name']}_editor"]);
|
||||
} else {
|
||||
$tmp_name = UOJForm::uploadedFileTmpName("{$form_name}_{$req['name']}_file");
|
||||
$tmp_name = UOJBs4Form::uploadedFileTmpName("{$form_name}_{$req['name']}_file");
|
||||
if ($tmp_name == null) {
|
||||
$zip_file->addFromString($req['file_name'], '');
|
||||
} else {
|
||||
@ -762,8 +738,8 @@ EOD;
|
||||
$max_size = isset($req['size']) ? (int)$req['size'] : 50;
|
||||
if ($stat['size'] > $max_size * 1024) {
|
||||
$zip_file->close();
|
||||
unlink(UOJContext::storagePath().$zip_file_name);
|
||||
becomeMsgPage("源代码长度不能超过 {$max_size}KB。");
|
||||
unlink(UOJContext::storagePath() . $zip_file_name);
|
||||
UOJResponse::message("源代码长度不能超过 {$max_size}KB。");
|
||||
}
|
||||
}
|
||||
|
||||
@ -775,25 +751,23 @@ EOD;
|
||||
$handle($zip_file_name, $content, $tot_size);
|
||||
};
|
||||
return $form;
|
||||
}
|
||||
function newZipSubmissionForm($form_name, $requirement, $zip_file_name_gen, $handle) {
|
||||
$form = new UOJForm($form_name);
|
||||
}
|
||||
function newZipSubmissionForm($form_name, $requirement, $zip_file_name_gen, $handle) {
|
||||
$form = new UOJBs4Form($form_name);
|
||||
$name = "zip_ans_{$form_name}";
|
||||
$text = UOJLocale::get('problems::zip file upload introduction', join(array_map(function($req) {
|
||||
return $req['file_name'];
|
||||
}, $requirement), ', '));
|
||||
$text = UOJLocale::get('problems::zip file upload introduction', implode(', ', array_map(fn ($req) => $req['file_name'], $requirement)));
|
||||
$browse_text = UOJLocale::get('browse');
|
||||
$html = <<<EOD
|
||||
<div id="div-{$name}">
|
||||
<label for="input-{$name}">$text</label>
|
||||
<input type="file" id="input-{$name}" name="{$name}" style="display:none;" onchange="$('#input-{$name}_path').val($('#input-{$name}').val());" />
|
||||
<div class="input-group bot-buffer-md">
|
||||
<label for="input-{$name}">$text</label>
|
||||
<input type="file" id="input-{$name}" name="{$name}" style="display:none;" onchange="$('#input-{$name}_path').val($('#input-{$name}').val());" />
|
||||
<div class="input-group bot-buffer-md">
|
||||
<input id="input-{$name}_path" class="form-control" type="text" readonly="readonly" />
|
||||
<span class="input-group-append">
|
||||
<button type="button" class="btn btn-primary" style="width:100px; !important" onclick="$('#input-{$name}').click();"><span class="glyphicon glyphicon-folder-open"></span> $browse_text</button>
|
||||
</span>
|
||||
</div>
|
||||
<span class="help-block invalid-feedback" id="help-{$name}"></span>
|
||||
</div>
|
||||
<span class="help-block invalid-feedback" id="help-{$name}"></span>
|
||||
</div>
|
||||
EOD;
|
||||
|
||||
@ -801,7 +775,7 @@ EOD;
|
||||
$form->is_big = true;
|
||||
$form->has_file = true;
|
||||
|
||||
$form->handle = function() use ($name, $requirement, $zip_file_name_gen, $handle) {
|
||||
$form->handle = function () use ($name, $requirement, $zip_file_name_gen, $handle) {
|
||||
global $myUser;
|
||||
|
||||
if ($myUser == null) {
|
||||
@ -843,7 +817,7 @@ EOD;
|
||||
$zip_file_name = $zip_file_name_gen();
|
||||
|
||||
$zip_file = new ZipArchive();
|
||||
if ($zip_file->open(UOJContext::storagePath().$zip_file_name, ZipArchive::CREATE) !== true) {
|
||||
if ($zip_file->open(UOJContext::storagePath() . $zip_file_name, ZipArchive::CREATE) !== true) {
|
||||
becomeMsgPage('提交失败');
|
||||
}
|
||||
|
||||
@ -859,14 +833,13 @@ EOD;
|
||||
$handle($zip_file_name, $content, $tot_size);
|
||||
};
|
||||
return $form;
|
||||
}
|
||||
}
|
||||
|
||||
function dieWithJsonData($data) {
|
||||
function dieWithJsonData($data) {
|
||||
header('Content-Type: application/json');
|
||||
die(json_encode($data));
|
||||
}
|
||||
}
|
||||
|
||||
function dieWithAlert($str) {
|
||||
die('<script>alert(decodeURIComponent("'.rawurlencode($str).'"));</script>'.SCRIPT_REFRESH_AS_GET);
|
||||
}
|
||||
?>
|
||||
function dieWithAlert($str) {
|
||||
die('<script>alert(decodeURIComponent("' . rawurlencode($str) . '"));</script>' . SCRIPT_REFRESH_AS_GET);
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -1,21 +1,21 @@
|
||||
<?php
|
||||
global $uojSupportedLanguages, $uojMainJudgerWorkPath;
|
||||
$uojSupportedLanguages = array('C', 'C++', 'C++98', 'C++03', 'C++11', 'C++17', 'C++20', 'Pascal', 'Python2.7', 'Python3', 'Java8', 'Java11', 'Java17');
|
||||
$uojMainJudgerWorkPath = "/opt/uoj/judger/uoj_judger";
|
||||
|
||||
function authenticateJudger() {
|
||||
function authenticateJudger() {
|
||||
if (!is_string($_POST['judger_name']) || !is_string($_POST['password'])) {
|
||||
return false;
|
||||
}
|
||||
$esc_judger_name = DB::escape($_POST['judger_name']);
|
||||
$judger = DB::selectFirst("select password from judger_info where judger_name = '$esc_judger_name'");
|
||||
if ($judger == null) {
|
||||
return false;
|
||||
}
|
||||
return $judger['password'] == $_POST['password'];
|
||||
}
|
||||
$judger = DB::selectFirst([
|
||||
"select password from judger_info",
|
||||
"where", [
|
||||
"judger_name" => $_POST['judger_name'],
|
||||
"enabled" => true,
|
||||
"password" => $_POST['password']
|
||||
]
|
||||
]);
|
||||
return $judger != null;
|
||||
}
|
||||
|
||||
function judgerCodeStr($code) {
|
||||
function judgerCodeStr($code) {
|
||||
switch ($code) {
|
||||
case 0:
|
||||
return "Accepted";
|
||||
@ -36,151 +36,127 @@
|
||||
default:
|
||||
return "No Comment";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class StrictFileReader {
|
||||
private $f;
|
||||
private $buf = '', $off = 0;
|
||||
|
||||
public function __construct($file_name) {
|
||||
$this->f = fopen($file_name, 'r');
|
||||
}
|
||||
|
||||
public function failed() {
|
||||
return $this->f === false;
|
||||
}
|
||||
|
||||
public function readChar() {
|
||||
if (isset($this->buf[$this->off])) {
|
||||
return $this->buf[$this->off++];
|
||||
}
|
||||
return fgetc($this->f);
|
||||
}
|
||||
public function unreadChar($c) {
|
||||
$this->buf .= $c;
|
||||
if ($this->off > 1000) {
|
||||
$this->buf = substr($this->buf, $this->off);
|
||||
$this->off = 0;
|
||||
}
|
||||
}
|
||||
|
||||
public function readString() {
|
||||
$str = '';
|
||||
while (true) {
|
||||
$c = $this->readChar();
|
||||
if ($c === false) {
|
||||
break;
|
||||
} elseif ($c === " " || $c === "\n" || $c === "\r") {
|
||||
$this->unreadChar($c);
|
||||
break;
|
||||
/**
|
||||
* Better to use UOJProblemConf instead
|
||||
*
|
||||
* @return array|int
|
||||
*/
|
||||
function getUOJConf($file_name) {
|
||||
$ret = UOJProblemConf::getFromFile($file_name);
|
||||
if ($ret instanceof UOJProblemConf) {
|
||||
return $ret->conf;
|
||||
} else {
|
||||
$str .= $c;
|
||||
}
|
||||
}
|
||||
return $str;
|
||||
}
|
||||
public function ignoreWhite() {
|
||||
while (true) {
|
||||
$c = $this->readChar();
|
||||
if ($c === false) {
|
||||
break;
|
||||
} elseif ($c === " " || $c === "\n" || $c === "\r") {
|
||||
continue;
|
||||
} else {
|
||||
$this->unreadChar($c);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
}
|
||||
|
||||
public function eof() {
|
||||
return feof($this->f);
|
||||
}
|
||||
/**
|
||||
* Better to use UOJProblemConf instead
|
||||
*/
|
||||
function putUOJConf($file_name, $conf) {
|
||||
(new UOJProblemConf($conf))->putToFile($file_name);
|
||||
}
|
||||
|
||||
public function close() {
|
||||
fclose($this->f);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Better to use UOJProblemConf instead
|
||||
*/
|
||||
function getUOJConfVal($conf, $key, $default_val) {
|
||||
return (new UOJProblemConf($conf))->getVal($key, $default_val);
|
||||
}
|
||||
|
||||
function getUOJConf($file_name) {
|
||||
$reader = new StrictFileReader($file_name);
|
||||
if ($reader->failed()) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
$conf = array();
|
||||
while (!$reader->eof()) {
|
||||
$reader->ignoreWhite();
|
||||
$key = $reader->readString();
|
||||
if ($key === '') {
|
||||
break;
|
||||
}
|
||||
$reader->ignoreWhite();
|
||||
$val = $reader->readString();
|
||||
if ($val === '') {
|
||||
break;
|
||||
}
|
||||
|
||||
if (isset($conf[$key])) {
|
||||
return -2;
|
||||
}
|
||||
$conf[$key] = $val;
|
||||
}
|
||||
$reader->close();
|
||||
return $conf;
|
||||
}
|
||||
function putUOJConf($file_name, $conf) {
|
||||
$f = fopen($file_name, 'w');
|
||||
foreach ($conf as $key => $val) {
|
||||
fwrite($f, "$key $val\n");
|
||||
}
|
||||
fclose($f);
|
||||
}
|
||||
|
||||
function getUOJConfVal($conf, $key, $default_val) {
|
||||
if (isset($conf[$key])) {
|
||||
return $conf[$key];
|
||||
} else {
|
||||
return $default_val;
|
||||
}
|
||||
}
|
||||
|
||||
function getUOJProblemInputFileName($problem_conf, $num) {
|
||||
function getUOJProblemInputFileName($problem_conf, $num) {
|
||||
return getUOJConfVal($problem_conf, 'input_pre', 'input') . $num . '.' . getUOJConfVal($problem_conf, 'input_suf', 'txt');
|
||||
}
|
||||
function getUOJProblemOutputFileName($problem_conf, $num) {
|
||||
}
|
||||
function getUOJProblemOutputFileName($problem_conf, $num) {
|
||||
return getUOJConfVal($problem_conf, 'output_pre', 'output') . $num . '.' . getUOJConfVal($problem_conf, 'output_suf', 'txt');
|
||||
}
|
||||
function getUOJProblemExtraInputFileName($problem_conf, $num) {
|
||||
}
|
||||
function getUOJProblemExtraInputFileName($problem_conf, $num) {
|
||||
return 'ex_' . getUOJConfVal($problem_conf, 'input_pre', 'input') . $num . '.' . getUOJConfVal($problem_conf, 'input_suf', 'txt');
|
||||
}
|
||||
function getUOJProblemExtraOutputFileName($problem_conf, $num) {
|
||||
}
|
||||
function getUOJProblemExtraOutputFileName($problem_conf, $num) {
|
||||
return 'ex_' . getUOJConfVal($problem_conf, 'output_pre', 'output') . $num . '.' . getUOJConfVal($problem_conf, 'output_suf', 'txt');
|
||||
}
|
||||
}
|
||||
|
||||
function rejudgeProblem($problem) {
|
||||
DB::query("update submissions set judge_time = NULL , result = '' , score = NULL , status = 'Waiting Rejudge' where problem_id = ${problem['id']}");
|
||||
}
|
||||
function rejudgeProblemAC($problem) {
|
||||
DB::query("update submissions set judge_time = NULL , result = '' , score = NULL , status = 'Waiting Rejudge' where problem_id = ${problem['id']} and score = 100");
|
||||
}
|
||||
function rejudgeProblemGe97($problem) {
|
||||
DB::query("update submissions set judge_time = NULL , result = '' , score = NULL , status = 'Waiting Rejudge' where problem_id = ${problem['id']} and score >= 97");
|
||||
}
|
||||
function rejudgeSubmission($submission) {
|
||||
DB::query("update submissions set judge_time = NULL , result = '' , score = NULL , status = 'Waiting Rejudge' where id = ${submission['id']}");
|
||||
}
|
||||
function updateBestACSubmissions($username, $problem_id) {
|
||||
$best = DB::selectFirst("select id, used_time, used_memory, tot_size from submissions where submitter = '$username' and problem_id = $problem_id and score = 100 order by used_time, used_memory, tot_size asc limit 1");
|
||||
$shortest = DB::selectFirst("select id, used_time, used_memory, tot_size from submissions where submitter = '$username' and problem_id = $problem_id and score = 100 order by tot_size, used_time, used_memory asc limit 1");
|
||||
DB::delete("delete from best_ac_submissions where submitter = '$username' and problem_id = $problem_id");
|
||||
function updateBestACSubmissions($username, $problem_id) {
|
||||
$update_best = function() use($username, $problem_id) {
|
||||
$best = DB::selectFirst([
|
||||
"select id, used_time, used_memory, tot_size from submissions",
|
||||
"where", [
|
||||
"submitter" => $username,
|
||||
"problem_id" => $problem_id,
|
||||
"score" => 100
|
||||
], "order by used_time, used_memory, tot_size asc limit 1", DB::for_share()
|
||||
]);
|
||||
if ($best) {
|
||||
DB::insert("insert into best_ac_submissions (problem_id, submitter, submission_id, used_time, used_memory, tot_size, shortest_id, shortest_used_time, shortest_used_memory, shortest_tot_size) values ($problem_id, '$username', ${best['id']}, ${best['used_time']}, ${best['used_memory']}, ${best['tot_size']}, ${shortest['id']}, ${shortest['used_time']}, ${shortest['used_memory']}, ${shortest['tot_size']})");
|
||||
$shortest = DB::selectFirst([
|
||||
"select id, used_time, used_memory, tot_size from submissions",
|
||||
"where", [
|
||||
"submitter" => $username,
|
||||
"problem_id" => $problem_id,
|
||||
"score" => 100
|
||||
], "order by tot_size, used_time, used_memory asc limit 1", DB::for_share()
|
||||
]);
|
||||
$keys = [
|
||||
'submission_id', 'used_time', 'used_memory', 'tot_size',
|
||||
'shortest_id', 'shortest_used_time', 'shortest_used_memory', 'shortest_tot_size'
|
||||
];
|
||||
$vals = [
|
||||
$best['id'], $best['used_time'], $best['used_memory'], $best['tot_size'],
|
||||
$shortest['id'], $shortest['used_time'], $shortest['used_memory'], $shortest['tot_size']
|
||||
];
|
||||
$fields_str = '(problem_id, submitter';
|
||||
for ($i = 0; $i < count($keys); $i++) {
|
||||
$fields_str .= ", {$keys[$i]}";
|
||||
}
|
||||
$fields_str .= ')';
|
||||
|
||||
$cnt = DB::selectCount("select count(*) from best_ac_submissions where submitter='$username'");
|
||||
DB::update("update user_info set ac_num = $cnt where username='$username'");
|
||||
|
||||
DB::update("update problems set ac_num = (select count(*) from submissions where problem_id = problems.id and score = 100), submit_num = (select count(*) from submissions where problem_id = problems.id) where id = $problem_id");
|
||||
DB::insert([
|
||||
"insert into best_ac_submissions",
|
||||
$fields_str,
|
||||
"values", DB::tuple(array_merge([$problem_id, $username], $vals)),
|
||||
"on duplicate key update", array_combine($keys, $vals)
|
||||
]);
|
||||
} else {
|
||||
DB::delete([
|
||||
"delete from best_ac_submissions",
|
||||
"where", [
|
||||
"submitter" => $username,
|
||||
"problem_id" => $problem_id
|
||||
]
|
||||
]);
|
||||
}
|
||||
?>
|
||||
};
|
||||
|
||||
DB::transaction($update_best);
|
||||
|
||||
DB::update([
|
||||
"update user_info",
|
||||
"set", [
|
||||
"ac_num" => DB::rawbracket([
|
||||
"select count(*) from best_ac_submissions",
|
||||
"where", ["submitter" => $username]
|
||||
])
|
||||
], "where", ["username" => $username]
|
||||
]);
|
||||
|
||||
DB::update([
|
||||
"update problems",
|
||||
"set", [
|
||||
"ac_num" => DB::rawbracket([
|
||||
"select count(*) from submissions",
|
||||
"where", [
|
||||
"problem_id" => DB::raw("problems.id"),
|
||||
"score" => 100
|
||||
]
|
||||
]),
|
||||
"submit_num" => DB::rawbracket([
|
||||
"select count(*) from submissions",
|
||||
"where", [
|
||||
"problem_id" => DB::raw("problems.id")
|
||||
]
|
||||
])
|
||||
], "where", ["id" => $problem_id]
|
||||
]);
|
||||
}
|
||||
|
@ -1,36 +1,35 @@
|
||||
<?php
|
||||
error_reporting(E_ALL ^ E_NOTICE);
|
||||
error_reporting(E_ALL ^ E_NOTICE);
|
||||
|
||||
spl_autoload_register(function($class_name) {
|
||||
spl_autoload_register(function ($class_name) {
|
||||
$lib = $_SERVER['DOCUMENT_ROOT'] . '/app/models/' . $class_name . '.php';
|
||||
if (file_exists($lib)) {
|
||||
require_once $lib;
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
function requireLib($name) { // html lib
|
||||
function requireLib($name) { // html lib
|
||||
global $REQUIRE_LIB;
|
||||
$REQUIRE_LIB[$name] = '';
|
||||
}
|
||||
function requirePHPLib($name) { // uoj php lib
|
||||
require $_SERVER['DOCUMENT_ROOT'].'/app/libs/uoj-'.$name.'-lib.php';
|
||||
}
|
||||
}
|
||||
function requirePHPLib($name) { // uoj php lib
|
||||
require $_SERVER['DOCUMENT_ROOT'] . '/app/libs/uoj-' . $name . '-lib.php';
|
||||
}
|
||||
|
||||
requirePHPLib('validate');
|
||||
requirePHPLib('query');
|
||||
requirePHPLib('rand');
|
||||
requirePHPLib('utility');
|
||||
requirePHPLib('security');
|
||||
requirePHPLib('contest');
|
||||
requirePHPLib('html');
|
||||
requirePHPLib('expection');
|
||||
requirePHPLib('validate');
|
||||
requirePHPLib('query');
|
||||
requirePHPLib('rand');
|
||||
requirePHPLib('utility');
|
||||
requirePHPLib('security');
|
||||
requirePHPLib('contest');
|
||||
requirePHPLib('html');
|
||||
|
||||
Session::init();
|
||||
UOJTime::init();
|
||||
DB::init();
|
||||
Auth::init();
|
||||
Session::init();
|
||||
UOJTime::init();
|
||||
DB::init();
|
||||
|
||||
if (isset($_GET['locale'])) {
|
||||
UOJLocale::setLocale($_GET['locale']);
|
||||
}
|
||||
UOJLocale::requireModule('basic');
|
||||
?>
|
||||
$myUser = null;
|
||||
Auth::init();
|
||||
|
||||
UOJLocale::init();
|
||||
|
@ -12,31 +12,6 @@ function hasProblemPermission($user, $problem) {
|
||||
}
|
||||
return DB::selectFirst("select * from problems_permissions where username = '{$user['username']}' and problem_id = {$problem['id']}") != null;
|
||||
}
|
||||
function hasViewPermission($str, $user, $problem, $submission) {
|
||||
if ($str == 'ALL') {
|
||||
return true;
|
||||
}
|
||||
if ($str == 'ALL_AFTER_AC') {
|
||||
return hasAC($user,$problem);
|
||||
}
|
||||
if ($str == 'SELF') {
|
||||
return $submission['submitter'] == $user['username'];
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function hasViewSolutionPermission($str, $user, $problem) {
|
||||
if (isSuperUser($user) || isProblemManager($user)) {
|
||||
return true;
|
||||
}
|
||||
if ($str == 'ALL') {
|
||||
return true;
|
||||
}
|
||||
if ($str == 'ALL_AFTER_AC') {
|
||||
return hasAC($user, $problem);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function hasContestPermission($user, $contest) {
|
||||
if ($user == null) {
|
||||
@ -51,14 +26,6 @@ function hasContestPermission($user, $contest) {
|
||||
function hasRegistered($user, $contest) {
|
||||
return DB::selectFirst("select * from contests_registrants where username = '${user['username']}' and contest_id = ${contest['id']}") != null;
|
||||
}
|
||||
function hasAC($user, $problem) {
|
||||
return DB::selectFirst("select * from best_ac_submissions where submitter = '${user['username']}' and problem_id = ${problem['id']}") != null;
|
||||
}
|
||||
function hasParticipated($user, $contest) {
|
||||
$result = DB::selectFirst("select * from contests_registrants where username = '${user['username']}' and contest_id = ${contest['id']}");
|
||||
|
||||
return $result != null && $result['has_participated'];
|
||||
}
|
||||
|
||||
function queryUser($username) {
|
||||
if (!validateUsername($username)) {
|
||||
@ -66,9 +33,6 @@ function queryUser($username) {
|
||||
}
|
||||
return DB::selectFirst("select * from user_info where username='$username'", MYSQLI_ASSOC);
|
||||
}
|
||||
function queryProblemContent($id) {
|
||||
return DB::selectFirst("select * from problems_contents where id = $id", MYSQLI_ASSOC);
|
||||
}
|
||||
function queryProblemBrief($id) {
|
||||
return DB::selectFirst("select * from problems where id = $id", MYSQLI_ASSOC);
|
||||
}
|
||||
@ -108,27 +72,15 @@ function queryContestProblemRank($contest, $problem) {
|
||||
if (!DB::selectFirst("select * from contests_problems where contest_id = {$contest['id']} and problem_id = {$problem['id']}")) {
|
||||
return null;
|
||||
}
|
||||
$contest_problems = DB::selectAll("select problem_id from contests_problems where contest_id = {$contest['id']} order by dfn, problem_id");
|
||||
$contest_problems = DB::selectAll("select problem_id from contests_problems where contest_id = {$contest['id']} order by level, problem_id");
|
||||
return array_search(array('problem_id' => $problem['id']), $contest_problems) + 1;
|
||||
}
|
||||
function querySubmission($id) {
|
||||
return DB::selectFirst("select * from submissions where id = $id", MYSQLI_ASSOC);
|
||||
}
|
||||
function queryHack($id) {
|
||||
return DB::selectFirst("select * from hacks where id = $id", MYSQLI_ASSOC);
|
||||
}
|
||||
function queryContest($id) {
|
||||
return DB::selectFirst("select * from contests where id = $id", MYSQLI_ASSOC);
|
||||
}
|
||||
function queryContestProblem($id) {
|
||||
return DB::selectFirst("select * from contest_problems where contest_id = $id", MYSQLI_ASSOC);
|
||||
}
|
||||
function queryContestProblems($id) {
|
||||
return DB::selectAll("select * from contests_problems where contest_id = $id order by dfn, problem_id", MYSQLI_ASSOC);
|
||||
}
|
||||
|
||||
function queryGroup($id) {
|
||||
return DB::selectFirst("select * from groups where id = $id", MYSQLI_ASSOC);
|
||||
return DB::selectFirst("select * from `groups` where id = $id", MYSQLI_ASSOC);
|
||||
}
|
||||
function queryGroupUsers($id) {
|
||||
return DB::selectAll("SELECT * FROM groups_users WHERE group_id = $id");
|
||||
@ -137,10 +89,23 @@ function queryUserInGroup($group_id, $username) {
|
||||
return DB::selectFirst("select * from groups_users where username='$username' and group_id='$group_id'", MYSQLI_ASSOC);
|
||||
}
|
||||
function queryGroupsOfUser($username) {
|
||||
return DB::selectAll("select b.title as title, b.id as id from groups_users a inner join groups b on a.group_id = b.id where a.username = '$username' and b.is_hidden = 0 order by id", MYSQLI_ASSOC);
|
||||
return DB::selectAll([
|
||||
"select", DB::fields([
|
||||
"title" => "groups.title",
|
||||
"id" => "groups.id",
|
||||
]),
|
||||
"from groups_users",
|
||||
"inner join `groups`", "on", [
|
||||
"groups_users.group_id" => DB::raw("groups.id"),
|
||||
],
|
||||
"where", [
|
||||
"groups_users.username" => $username,
|
||||
"groups.is_hidden" => false,
|
||||
],
|
||||
]);
|
||||
}
|
||||
function queryGroupmateCurrentAC($username) {
|
||||
return DB::selectAll("select a.problem_id as problem_id, a.submitter as submitter, a.submission_id as submission_id, b.submit_time as submit_time, c.group_id as group_id, c.group_name as group_name, d.title as problem_title, b.submit_time as submit_time, e.realname as realname from best_ac_submissions a inner join submissions b on (a.submission_id = b.id) inner join (select a.username as username, any_value(a.group_id) as group_id, any_value(c.title) as group_name from groups_users a inner join (select a.group_id as group_id from groups_users a inner join groups b on a.group_id = b.id where a.username = '$username' and b.is_hidden = 0) b on a.group_id = b.group_id inner join groups c on a.group_id = c.id group by a.username) c on a.submitter = c.username inner join problems d on (a.problem_id = d.id and d.is_hidden = 0) inner join user_info e on a.submitter = e.username where b.submit_time > addtime(now(), '-360:00:00') order by b.submit_time desc limit 10", MYSQLI_ASSOC);
|
||||
return DB::selectAll("select a.problem_id as problem_id, a.submitter as submitter, a.submission_id as submission_id, b.submit_time as submit_time, c.group_id as group_id, c.group_name as group_name, d.title as problem_title, b.submit_time as submit_time, e.realname as realname from best_ac_submissions a inner join submissions b on (a.submission_id = b.id) inner join (select a.username as username, any_value(a.group_id) as group_id, any_value(c.title) as group_name from groups_users a inner join (select a.group_id as group_id from groups_users a inner join `groups` b on a.group_id = b.id where a.username = '$username' and b.is_hidden = 0) b on a.group_id = b.group_id inner join `groups` c on a.group_id = c.id group by a.username) c on a.submitter = c.username inner join problems d on (a.problem_id = d.id and d.is_hidden = 0) inner join user_info e on a.submitter = e.username where b.submit_time > addtime(now(), '-360:00:00') order by b.submit_time desc limit 10", MYSQLI_ASSOC);
|
||||
}
|
||||
function queryGroupCurrentAC($group_id) {
|
||||
return DB::selectAll("select a.problem_id as problem_id, a.submitter as submitter, a.submission_id as submission_id, b.submit_time as submit_time, d.title as problem_title, b.submit_time as submit_time, e.realname as realname from best_ac_submissions a inner join submissions b on (a.submission_id = b.id) inner join groups_users c on (a.submitter = c.username and c.group_id = $group_id) inner join problems d on (a.problem_id = d.id and d.is_hidden = 0) inner join user_info e on (a.submitter = e.username) where b.submit_time > addtime(now(), '-360:00:00') order by b.submit_time desc limit 10", MYSQLI_ASSOC);
|
||||
@ -154,30 +119,9 @@ function queryGroupActiveAssignments($group_id) {
|
||||
function queryAssignmentByGroupListID($group_id, $list_id) {
|
||||
return DB::selectFirst("select * from groups_assignments where list_id='$list_id' and group_id='$group_id'", MYSQLI_ASSOC);
|
||||
}
|
||||
|
||||
function queryZanVal($id, $type, $user) {
|
||||
if ($user == null) {
|
||||
return 0;
|
||||
}
|
||||
$esc_type = DB::escape($type);
|
||||
$row = DB::selectFirst("select val from click_zans where username='{$user['username']}' and type='$esc_type' and target_id='$id'");
|
||||
if ($row == null) {
|
||||
return 0;
|
||||
}
|
||||
return $row['val'];
|
||||
}
|
||||
|
||||
function queryBlog($id) {
|
||||
return DB::selectFirst("select * from blogs where id='$id'", MYSQLI_ASSOC);
|
||||
}
|
||||
function queryBlogTags($id) {
|
||||
$tags = array();
|
||||
$result = DB::select("select tag from blogs_tags where blog_id = $id order by id");
|
||||
while ($row = DB::fetch($result, MYSQLI_NUM)) {
|
||||
$tags[] = $row[0];
|
||||
}
|
||||
return $tags;
|
||||
}
|
||||
function queryBlogComment($id) {
|
||||
return DB::selectFirst("select * from blogs_comments where id='$id'", MYSQLI_ASSOC);
|
||||
}
|
||||
@ -188,92 +132,21 @@ function isProblemVisibleToUser($problem, $user) {
|
||||
function isListVisibleToUser($list, $user) {
|
||||
return !$list['is_hidden'] || isSuperUser($user);
|
||||
}
|
||||
function isContestProblemVisibleToUser($problem, $contest, $user) {
|
||||
if (isProblemVisibleToUser($problem, $user)) {
|
||||
return true;
|
||||
}
|
||||
if ($contest['cur_progress'] >= CONTEST_PENDING_FINAL_TEST) {
|
||||
return true;
|
||||
}
|
||||
if ($contest['cur_progress'] == CONTEST_NOT_STARTED) {
|
||||
return false;
|
||||
}
|
||||
return hasRegistered($user, $contest);
|
||||
}
|
||||
|
||||
function isSubmissionVisibleToUser($submission, $problem, $user) {
|
||||
if (isProblemManager($user)) {
|
||||
return true;
|
||||
} elseif (!$submission['is_hidden']) {
|
||||
return true;
|
||||
} else {
|
||||
return hasProblemPermission($user, $problem);
|
||||
}
|
||||
}
|
||||
function isHackVisibleToUser($hack, $problem, $user) {
|
||||
if (isSuperUser($user)) {
|
||||
return true;
|
||||
} elseif (!$hack['is_hidden']) {
|
||||
return true;
|
||||
} else {
|
||||
return hasProblemPermission($user, $problem);
|
||||
}
|
||||
}
|
||||
|
||||
function isSubmissionFullVisibleToUser($submission, $contest, $problem, $user) {
|
||||
if (isSuperUser($user)) {
|
||||
return true;
|
||||
} elseif ($submission['submitter'] == $user['username']) {
|
||||
return true;
|
||||
} elseif (isRegisteredRunningContestProblem($user, $problem)) {
|
||||
return false;
|
||||
} elseif (!$contest) {
|
||||
return true;
|
||||
} elseif ($contest['cur_progress'] > CONTEST_IN_PROGRESS) {
|
||||
return true;
|
||||
} else {
|
||||
return hasProblemPermission($user, $problem);
|
||||
}
|
||||
}
|
||||
function isHackFullVisibleToUser($hack, $contest, $problem, $user) {
|
||||
if (isSuperUser($user)) {
|
||||
return true;
|
||||
} elseif (!$contest) {
|
||||
return true;
|
||||
} elseif ($contest['cur_progress'] > CONTEST_IN_PROGRESS) {
|
||||
return true;
|
||||
} elseif ($hack['hacker'] == $user['username']) {
|
||||
return true;
|
||||
} else {
|
||||
return hasProblemPermission($user, $problem);
|
||||
}
|
||||
}
|
||||
|
||||
function isRegisteredRunningContestProblem($user, $problem) {
|
||||
$result = DB::query("select contest_id from contests_problems where problem_id = {$problem['id']}");
|
||||
while (list($contest_id) = DB::fetch($result, MYSQLI_NUM)) {
|
||||
$contest = queryContest($contest_id);
|
||||
genMoreContestInfo($contest);
|
||||
if ($contest['cur_progress'] == CONTEST_IN_PROGRESS
|
||||
if (
|
||||
$contest['cur_progress'] == CONTEST_IN_PROGRESS
|
||||
&& hasRegistered($user, $contest)
|
||||
&& !hasContestPermission($user, $contest)
|
||||
&& queryContestProblemRank($contest, $problem)) {
|
||||
&& queryContestProblemRank($contest, $problem)
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
function deleteBlog($id) {
|
||||
if (!validateUInt($id)) {
|
||||
return;
|
||||
}
|
||||
DB::delete("delete from click_zans where type = 'B' and target_id = $id");
|
||||
DB::delete("delete from click_zans where type = 'BC' and target_id in (select id from blogs_comments where blog_id = $id)");
|
||||
DB::delete("delete from blogs where id = $id");
|
||||
DB::delete("delete from blogs_comments where blog_id = $id");
|
||||
DB::delete("delete from important_blogs where blog_id = $id");
|
||||
DB::delete("delete from blogs_tags where blog_id = $id");
|
||||
DB::delete("DELETE FROM problems_solutions WHERE blog_id = $id");
|
||||
}
|
||||
|
@ -16,8 +16,8 @@ function uojRandString($len, $charset = '0123456789abcdefghijklmnopqrstuvwxyz')
|
||||
function uojRandAvaiableFileName($dir, $length = 20, $suffix = '') {
|
||||
do {
|
||||
$fileName = $dir . uojRandString($length);
|
||||
} while (file_exists(UOJContext::storagePath().$fileName.$suffix));
|
||||
return $fileName.$suffix;
|
||||
} while (file_exists(UOJContext::storagePath() . $fileName . $suffix));
|
||||
return $fileName . $suffix;
|
||||
}
|
||||
|
||||
function uojRandAvaiableTmpFileName() {
|
||||
@ -26,8 +26,8 @@ function uojRandAvaiableTmpFileName() {
|
||||
|
||||
function uojRandAvaiableSubmissionFileName() {
|
||||
$num = uojRand(1, 10000);
|
||||
if (!file_exists(UOJContext::storagePath()."/submission/$num")) {
|
||||
mkdir(UOJContext::storagePath()."/submission/$num", 0777, true);
|
||||
if (!file_exists(UOJContext::storagePath() . "/submission/$num")) {
|
||||
mkdir(UOJContext::storagePath() . "/submission/$num", 0777, true);
|
||||
}
|
||||
return uojRandAvaiableFileName("/submission/$num/");
|
||||
}
|
||||
|
@ -28,6 +28,68 @@ function crsf_check() {
|
||||
}
|
||||
function crsf_defend() {
|
||||
if (!crsf_check()) {
|
||||
becomeMsgPage('This page has expired.');
|
||||
UOJResponse::page403('页面已过期(可能页面真的过期了,也可能是刚才你访问的网页没有完全加载,也可能是你的浏览器版本太老)');
|
||||
}
|
||||
}
|
||||
|
||||
function submission_frequency_check() {
|
||||
$recent = clone UOJTime::$time_now;
|
||||
$recent->sub(new DateInterval("PT1S"));
|
||||
$num = DB::selectCount([
|
||||
"select count(*) from submissions",
|
||||
"where", [
|
||||
"submitter" => Auth::id(),
|
||||
["submit_time", ">=", $recent->format('Y-m-d H:i:s')]
|
||||
]
|
||||
]);
|
||||
if ($num >= 1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// use the implementation below if OJ is under attack
|
||||
/*
|
||||
// 1
|
||||
$recent = clone UOJTime::$time_now;
|
||||
$recent->sub(new DateInterval("PT3S"));
|
||||
$num = DB::selectCount([
|
||||
"select count(*) from submissions",
|
||||
"where", [
|
||||
"submitter" => Auth::id(),
|
||||
["submit_time", ">=", $recent->format('Y-m-d H:i:s')]
|
||||
]
|
||||
]);
|
||||
if ($num >= 1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// 2
|
||||
$recent = clone UOJTime::$time_now;
|
||||
$recent->sub(new DateInterval("PT1M"));
|
||||
$num = DB::selectCount([
|
||||
"select count(*) from submissions",
|
||||
"where", [
|
||||
"submitter" => Auth::id(),
|
||||
["submit_time", ">=", $recent->format('Y-m-d H:i:s')]
|
||||
]
|
||||
]);
|
||||
if ($num >= 6) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// 3
|
||||
$recent = clone UOJTime::$time_now;
|
||||
$recent->sub(new DateInterval("PT30M"));
|
||||
$num = DB::selectCount([
|
||||
"select count(*) from submissions",
|
||||
"where", [
|
||||
"submitter" => Auth::id(),
|
||||
["submit_time", ">=", $recent->format('Y-m-d H:i:s')]
|
||||
]
|
||||
]);
|
||||
if ($num >= 30) {
|
||||
return false;
|
||||
}
|
||||
*/
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -10,6 +10,18 @@ function mergeConfig(&$config, $default_config) {
|
||||
}
|
||||
}
|
||||
|
||||
function is_assoc($arr) {
|
||||
if (!is_array($arr)) {
|
||||
return false;
|
||||
}
|
||||
foreach (array_keys($arr) as $key) {
|
||||
if (!is_int($key)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function strStartWith($str, $pre) {
|
||||
return substr($str, 0, strlen($pre)) === $pre;
|
||||
}
|
||||
@ -129,6 +141,15 @@ function blog_name_decode($name) {
|
||||
return $name;
|
||||
}
|
||||
|
||||
|
||||
function camelize($str, $delimiters = '-_') {
|
||||
$str = ucwords($str, $delimiters);
|
||||
foreach (str_split($delimiters) as $c) {
|
||||
$str = str_replace($c, '', $str);
|
||||
}
|
||||
return $str;
|
||||
}
|
||||
|
||||
function addUserType(&$user, $type) {
|
||||
$usertype = explode(',', $user['usertype']);
|
||||
if (!in_array($type, $usertype)) {
|
||||
@ -150,9 +171,6 @@ function hasUserType($user, $type) {
|
||||
return in_array($type, $usertype);
|
||||
}
|
||||
|
||||
function isNormalUser($user) {
|
||||
return $user != null && !hasUserType($user, 'contest_only');
|
||||
}
|
||||
function isProblemUploader($user) {
|
||||
if ($user == null) {
|
||||
return false;
|
||||
@ -178,6 +196,9 @@ function isContestJudger($user) {
|
||||
function isSuperUser($user) {
|
||||
return $user != null && $user['usergroup'] == 'S';
|
||||
}
|
||||
function isTmpUser($user) {
|
||||
return $user != null && $user['usergroup'] == 'T';
|
||||
}
|
||||
function getProblemExtraConfig($problem) {
|
||||
$extra_config = json_decode($problem['extra_config'], true);
|
||||
|
||||
@ -223,7 +244,20 @@ function getProblemCustomTestRequirement($problem) {
|
||||
}
|
||||
|
||||
function sendSystemMsg($username, $title, $content) {
|
||||
$content = DB::escape($content);
|
||||
$title = DB::escape($title);
|
||||
DB::insert("insert into user_system_msg (receiver, title, content, send_time) values ('$username', '$title', '$content', now())");
|
||||
DB::insert([
|
||||
"insert into user_system_msg",
|
||||
"(receiver, title, content, send_time)",
|
||||
"values", DB::tuple([$username, $title, $content, DB::now()])
|
||||
]);
|
||||
}
|
||||
|
||||
function retry_loop(callable $f, $retry = 5, $ms = 10) {
|
||||
for ($i = 0; $i < $retry; $i++) {
|
||||
$ret = $f();
|
||||
if ($ret !== false) {
|
||||
return $ret;
|
||||
}
|
||||
usleep($ms * 1000);
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
|
@ -59,3 +59,19 @@ function validateString($str) {
|
||||
function validateGitHubUsername($username) {
|
||||
return is_string($username) && preg_match('/^[a-zA-Z0-9_-]{1,20}$/', $username);
|
||||
}
|
||||
|
||||
function validateUserAndStoreByUsername($username, &$vdata) {
|
||||
if (!isset($vdata['user'])) {
|
||||
$vdata['user'] = [];
|
||||
}
|
||||
$user = UOJUser::query($username);
|
||||
if (!$user) {
|
||||
return "不存在名为{$username}的用户";
|
||||
}
|
||||
$vdata['user'][$username] = $user;
|
||||
return '';
|
||||
}
|
||||
|
||||
function is_short_string($str) {
|
||||
return is_string($str) && strlen($str) <= 256;
|
||||
}
|
||||
|
@ -14,6 +14,7 @@ return [
|
||||
'in progress' => 'in progress',
|
||||
'pending final test' => 'pending final test',
|
||||
'final testing' => 'final testing',
|
||||
'official results to be announced' => 'official results to be announced',
|
||||
'ended' => 'ended',
|
||||
'total score' => 'total score',
|
||||
'add new contest' => 'Add new contest',
|
||||
@ -23,10 +24,11 @@ return [
|
||||
'after contest standings' => 'After contest standings',
|
||||
'contest backstage' => 'Backstage',
|
||||
'contest notice' => 'Notice',
|
||||
'show all submissions' => 'Show all submissions',
|
||||
'show all submissions' => "Show everyone's submissions",
|
||||
'contest ends in' => 'Contest ends in',
|
||||
'contest pending final test' => 'Pending final test',
|
||||
'contest final testing' => 'Final testing',
|
||||
'contest official results to be announced' => 'Official results to be announced',
|
||||
'contest ended' => 'Contest Ended',
|
||||
'contest registrants' => 'Registrants',
|
||||
'problem self review' => 'Problem self review',
|
||||
|
@ -14,6 +14,7 @@ return [
|
||||
'in progress' => '正在进行',
|
||||
'pending final test' => '等待评测',
|
||||
'final testing' => '正在评测',
|
||||
'official results to be announced' => '等待宣布正式成绩',
|
||||
'ended' => '已结束',
|
||||
'total score' => '总分',
|
||||
'add new contest' => '添加比赛',
|
||||
@ -23,10 +24,11 @@ return [
|
||||
'after contest standings' => '赛后排行榜',
|
||||
'contest backstage' => '大后台',
|
||||
'contest notice' => '比赛通知',
|
||||
'show all submissions' => '显示所有提交',
|
||||
'show all submissions' => '显示所有人的提交',
|
||||
'contest ends in' => '距离比赛结束',
|
||||
'contest pending final test' => '等待评测',
|
||||
'contest final testing' => '正在测评',
|
||||
'contest official results to be announced' => '等待宣布正式成绩',
|
||||
'contest ended' => '比赛已结束',
|
||||
'contest registrants' => '报名选手列表',
|
||||
'problem self review' => '题目总结',
|
||||
|
@ -3,26 +3,43 @@
|
||||
class Auth {
|
||||
public static function check() {
|
||||
global $myUser;
|
||||
return $myUser != null;
|
||||
return $myUser !== null;
|
||||
}
|
||||
public static function id() {
|
||||
global $myUser;
|
||||
if ($myUser === null) {
|
||||
return null;
|
||||
}
|
||||
return $myUser['username'];
|
||||
}
|
||||
public static function user() {
|
||||
global $myUser;
|
||||
return $myUser;
|
||||
}
|
||||
public static function property($name) {
|
||||
global $myUser;
|
||||
if (!$myUser) {
|
||||
return false;
|
||||
}
|
||||
return $myUser[$name];
|
||||
}
|
||||
public static function login($username, $remember = true) {
|
||||
if (!validateUsername($username)) {
|
||||
return;
|
||||
}
|
||||
$_SESSION['username'] = $username;
|
||||
if ($remember) {
|
||||
$remember_token = DB::selectFirst("select remember_token from user_info where username = '$username'")['remember_token'];
|
||||
$remember_token = DB::selectSingle([
|
||||
"select remember_token from user_info",
|
||||
"where", ["username" => $username]
|
||||
]);
|
||||
if ($remember_token == '') {
|
||||
$remember_token = uojRandString(60);
|
||||
DB::update("update user_info set remember_token = '$remember_token', last_login = now() where username = '$username'");
|
||||
DB::update([
|
||||
"update user_info",
|
||||
"set", ["remember_token" => $remember_token],
|
||||
"where", ["username" => $username]
|
||||
]);
|
||||
}
|
||||
|
||||
$_SESSION['last_login'] = time();
|
||||
@ -30,6 +47,12 @@ class Auth {
|
||||
Cookie::safeSet('uoj_username', $username, $expire, '/', array('httponly' => true));
|
||||
Cookie::safeSet('uoj_remember_token', $remember_token, $expire, '/', array('httponly' => true));
|
||||
}
|
||||
|
||||
DB::update([
|
||||
"update user_info",
|
||||
"set", ["last_login_time" => UOJTime::$time_now_str],
|
||||
"where", ["username" => $username]
|
||||
]);
|
||||
}
|
||||
public static function logout() {
|
||||
unset($_SESSION['username']);
|
||||
@ -37,7 +60,11 @@ class Auth {
|
||||
unset($_SESSION['last_visited']);
|
||||
Cookie::safeUnset('uoj_username', '/');
|
||||
Cookie::safeUnset('uoj_remember_token', '/');
|
||||
DB::update("update user_info set remember_token = '' where username = '".Auth::id()."'");
|
||||
DB::update([
|
||||
"update user_info",
|
||||
"set", ["remember_token" => ''],
|
||||
"where", ["username" => Auth::id()]
|
||||
]);
|
||||
}
|
||||
|
||||
private static function initMyUser() {
|
||||
@ -51,7 +78,7 @@ class Auth {
|
||||
if (!validateUsername($_SESSION['username'])) {
|
||||
return;
|
||||
}
|
||||
$myUser = queryUser($_SESSION['username']);
|
||||
$myUser = UOJUser::query($_SESSION['username']);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -61,7 +88,7 @@ class Auth {
|
||||
if (!validateUsername($username)) {
|
||||
return;
|
||||
}
|
||||
$myUser = queryUser($username);
|
||||
$myUser = UOJUser::query($username);
|
||||
if ($myUser['remember_token'] !== $remember_token) {
|
||||
$myUser = null;
|
||||
}
|
||||
@ -72,24 +99,19 @@ class Auth {
|
||||
global $myUser;
|
||||
|
||||
Auth::initMyUser();
|
||||
|
||||
if ($myUser) {
|
||||
if ($myUser['usergroup'] == 'B') {
|
||||
if ($myUser && UOJUser::getAccountStatus($myUser) != 'ok') {
|
||||
$myUser = null;
|
||||
}
|
||||
}
|
||||
|
||||
if ($myUser) {
|
||||
if (!isset($_SESSION['last_login'])) {
|
||||
$_SESSION['last_login'] = strtotime($myUser['last_login']);
|
||||
$_SESSION['last_login'] = strtotime($myUser['last_login_time']);
|
||||
}
|
||||
if ((time() - $_SESSION['last_login']) > 60 * 60 * 24 * 7) { // 1 week
|
||||
Auth::logout();
|
||||
$myUser = null;
|
||||
}
|
||||
|
||||
$_SESSION["last_visited"] = time();
|
||||
DB::update("update user_info set remote_addr = '".DB::escape($_SERVER['REMOTE_ADDR'])."', http_x_forwarded_for = '".DB::escape($_SERVER['HTTP_X_FORWARDED_FOR'])."', last_visited = now() where username = '".DB::escape($myUser['username'])."'");
|
||||
$myUser = UOJUser::updateVisitHistory($myUser, [
|
||||
'remote_addr' => UOJContext::remoteAddr(),
|
||||
'http_x_forwarded_for' => UOJContext::httpXForwardedFor(),
|
||||
'http_user_agent' => UOJContext::httpUserAgent()
|
||||
]);
|
||||
$_SESSION['last_visited'] = time();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
121
web/app/models/ClickZans.php
Normal file
121
web/app/models/ClickZans.php
Normal file
@ -0,0 +1,121 @@
|
||||
<?php
|
||||
|
||||
class ClickZans {
|
||||
public static function getTable($type) {
|
||||
switch ($type) {
|
||||
case 'B':
|
||||
return 'blogs';
|
||||
case 'BC':
|
||||
return 'blogs_comments';
|
||||
case 'P':
|
||||
return 'problems';
|
||||
case 'C':
|
||||
return 'contests';
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static function canClickZan($id, $type, $user) {
|
||||
switch ($type) {
|
||||
case 'P':
|
||||
return UOJProblem::query($id)->userCanClickZan($user);
|
||||
default:
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public static function query($id, $type, $user) {
|
||||
if ($user == null) {
|
||||
return 0;
|
||||
}
|
||||
$row = DB::selectFirst([
|
||||
"select val from click_zans",
|
||||
"where", [
|
||||
'username' => $user['username'],
|
||||
'type' => $type,
|
||||
'target_id' => $id
|
||||
]
|
||||
]);
|
||||
if ($row == null) {
|
||||
return 0;
|
||||
}
|
||||
return $row['val'];
|
||||
}
|
||||
|
||||
public static function click($id, $type, $user, $delta, $show_text = true) {
|
||||
if (!DB::$in_transaction) {
|
||||
return DB::transaction(fn() => ClickZans::click($id, $type, $user, $delta));
|
||||
}
|
||||
|
||||
$table_name = ClickZans::getTable($type);
|
||||
|
||||
$cur = ClickZans::query($id, $type, $user);
|
||||
|
||||
$row = DB::selectFirst([
|
||||
"select zan from", DB::table($table_name),
|
||||
"where", ['id' => $id], DB::for_update()
|
||||
]);
|
||||
if (!$row) {
|
||||
return '<div class="text-danger">failed</div>';
|
||||
}
|
||||
|
||||
if ($cur != $delta) {
|
||||
$cur += $delta;
|
||||
if ($cur == 0) {
|
||||
DB::delete([
|
||||
"delete from click_zans",
|
||||
"where", [
|
||||
'username' => Auth::id(),
|
||||
'type' => $type,
|
||||
'target_id' => $id
|
||||
]
|
||||
]);
|
||||
} elseif ($cur != $delta) {
|
||||
DB::update([
|
||||
"update click_zans",
|
||||
"set", ['val' => $cur],
|
||||
"where", [
|
||||
'username' => Auth::id(),
|
||||
'type' => $type,
|
||||
'target_id' => $id
|
||||
]
|
||||
]);
|
||||
} else {
|
||||
DB::insert([
|
||||
"insert into click_zans",
|
||||
"(username, type, target_id, val)", "values",
|
||||
DB::tuple([Auth::id(), $type, $id, $cur])
|
||||
]);
|
||||
}
|
||||
$cnt = $row['zan'] + $delta;
|
||||
DB::update([
|
||||
"update", DB::table($table_name),
|
||||
"set", ['zan' => $cnt],
|
||||
"where", ['id' => $id]
|
||||
]);
|
||||
} else {
|
||||
$cnt = $row['zan'];
|
||||
}
|
||||
|
||||
return ClickZans::getBlock($type, $id, $cnt, $cur, $show_text);
|
||||
}
|
||||
|
||||
public static function getBlock($type, $id, $cnt, $val = null, $show_text = true) {
|
||||
if ($val === null) {
|
||||
$val = ClickZans::query($id, $type, Auth::user());
|
||||
}
|
||||
return '<div class="uoj-click-zan-block" data-id="'.$id.'" data-type="'.$type.'" data-val="'.$val.'" data-cnt="'.$cnt.'" data-show-text="'.$show_text.'"></div>';
|
||||
}
|
||||
|
||||
public static function getCntBlock($cnt) {
|
||||
$cls = 'uoj-click-zan-block-';
|
||||
if ($cnt > 0) {
|
||||
$cls .= 'positive';
|
||||
} elseif ($cnt < 0) {
|
||||
$cls .= 'negative';
|
||||
} else {
|
||||
$cls .= 'neutral';
|
||||
}
|
||||
return '<span class="'.$cls.'"><span class="uoj-click-zan-cnt">[<strong>' . ($cnt > 0 ? '+' . $cnt : $cnt) . '</strong>]</span></span>';
|
||||
}
|
||||
}
|
@ -1,78 +1,451 @@
|
||||
<?php
|
||||
|
||||
class DB {
|
||||
public static mysqli $conn;
|
||||
public static array $cache = [];
|
||||
public static bool $in_transaction = false;
|
||||
|
||||
const WLOCK = "WRITE";
|
||||
const RLOCK = "READ";
|
||||
|
||||
const ASSOC = MYSQLI_ASSOC;
|
||||
const NUM = MYSQLI_NUM;
|
||||
const BOTH = MYSQLI_BOTH;
|
||||
|
||||
public static function init() {
|
||||
global $uojMySQL;
|
||||
@$uojMySQL = mysqli_connect(UOJConfig::$data['database']['host'] . ':' . UOJConfig::$data['database']['port'], UOJConfig::$data['database']['username'], UOJConfig::$data['database']['password'], UOJConfig::$data['database']['database']);
|
||||
if (!$uojMySQL) {
|
||||
echo 'There is something wrong with database >_<.... ' . mysqli_connect_error();
|
||||
die();
|
||||
$server = UOJConfig::$data['database']['host'];
|
||||
$username = UOJConfig::$data['database']['username'];
|
||||
$password = UOJConfig::$data['database']['password'];
|
||||
$dbname = UOJConfig::$data['database']['database'];
|
||||
DB::$conn = new mysqli($server, $username, $password, $dbname);
|
||||
if (DB::$conn->connect_error) {
|
||||
UOJLog::error('database initialization failed: '. DB::$conn->connect_error);
|
||||
die('There is something wrong with the database >_<... Connection failed');
|
||||
}
|
||||
if (!DB::$conn->set_charset("utf8mb4")) {
|
||||
UOJLog::error("database initialization failed: Error loading character set utf8. " . DB::$conn->error);
|
||||
die('There is something wrong with the database >_<.... Charset utf8 not supported');
|
||||
}
|
||||
}
|
||||
|
||||
// lc: local cache
|
||||
public static function lc() {
|
||||
return new DBUseLocalCache('');
|
||||
}
|
||||
|
||||
public static function escape($str) {
|
||||
global $uojMySQL;
|
||||
return mysqli_real_escape_string($uojMySQL, $str);
|
||||
return DB::$conn->real_escape_string($str);
|
||||
}
|
||||
public static function fetch($r, $opt = MYSQLI_ASSOC) {
|
||||
global $uojMySQL;
|
||||
return mysqli_fetch_array($r, $opt);
|
||||
public static function raw($str) {
|
||||
return new DBRawString($str);
|
||||
}
|
||||
public static function rawbracket($q) {
|
||||
return DB::raw(DB::bracket($q));
|
||||
}
|
||||
public static function rawvalue($str) {
|
||||
return DB::raw(DB::value($str));
|
||||
}
|
||||
public static function rawtuple(array $vals) {
|
||||
return DB::raw(DB::tuple($vals));
|
||||
}
|
||||
public static function call($fun, ...$args) {
|
||||
return DB::raw("{$fun}(".implode(',', array_map('DB::value', $args)).')');
|
||||
}
|
||||
public static function now() {
|
||||
return DB::call('now');
|
||||
}
|
||||
public static function instr($str, $substr) {
|
||||
return DB::call('instr', $str, $substr);
|
||||
}
|
||||
public static function cast_as_json($value) {
|
||||
return DB::raw('cast('.DB::value($value).' as json)');
|
||||
}
|
||||
public static function json_set($json_doc, ...$args) {
|
||||
return DB::call('json_set', DB::raw($json_doc), ...$args);
|
||||
}
|
||||
public static function json_insert($json_doc, ...$args) {
|
||||
return DB::call('json_insert', DB::raw($json_doc), ...$args);
|
||||
}
|
||||
public static function json_replace($json_doc, ...$args) {
|
||||
return DB::call('json_replace', DB::raw($json_doc), ...$args);
|
||||
}
|
||||
public static function json_remove($json_doc, ...$args) {
|
||||
return DB::call('json_remove', DB::raw($json_doc), ...$args);
|
||||
}
|
||||
public static function json_array_append($json_doc, ...$args) {
|
||||
return DB::call('json_array_append', DB::raw($json_doc), ...$args);
|
||||
}
|
||||
public static function json_array_insert($json_doc, ...$args) {
|
||||
return DB::call('json_array_insert', DB::raw($json_doc), ...$args);
|
||||
}
|
||||
public static function json_unquote($json_doc) {
|
||||
return DB::call('json_unquote', DB::raw($json_doc));
|
||||
}
|
||||
|
||||
public static function table($table) {
|
||||
//return '`'.str_replace('`', '``', $table).'`';
|
||||
return $table;
|
||||
}
|
||||
public static function fields($fields) {
|
||||
if (is_assoc($fields)) {
|
||||
$new_fields = [];
|
||||
foreach ($fields as $name => $val) {
|
||||
if (is_int($name)) {
|
||||
$new_fields[] = $val;
|
||||
} else {
|
||||
$new_fields[] = DB::field_as($val, $name);
|
||||
}
|
||||
}
|
||||
$fields = $new_fields;
|
||||
}
|
||||
return implode(',', $fields);
|
||||
}
|
||||
public static function bracketed_fields($fields) {
|
||||
return '('.DB::fields($fields).')';
|
||||
}
|
||||
public static function value($str) {
|
||||
if ($str === null) {
|
||||
return 'NULL';
|
||||
} elseif ($str === true) {
|
||||
return 'true';
|
||||
} elseif ($str === false) {
|
||||
return 'false';
|
||||
} elseif (is_int($str)) {
|
||||
return $str;
|
||||
} elseif (is_string($str)) {
|
||||
return '\''.DB::escape($str).'\'';
|
||||
} elseif ($str instanceof DBRawString) {
|
||||
return $str->str;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
public static function field_as($field, $name) {
|
||||
return "{$field} as {$name}";
|
||||
}
|
||||
public static function value_as($value, $name) {
|
||||
return DB::value($value)."as {$name}";
|
||||
}
|
||||
|
||||
public static function if_func($conds, $val1, $val2) {
|
||||
return 'if('.DB::conds($conds).','.DB::value($val1).','.DB::value($val2).')';
|
||||
}
|
||||
|
||||
public static function setValue($field, $val) {
|
||||
return $field.' = '.DB::value($val);
|
||||
}
|
||||
public static function setValues(array $arr) {
|
||||
$all = [];
|
||||
foreach ($arr as $key => $val) {
|
||||
if (is_int($key)) {
|
||||
$all[] = $val;
|
||||
} else {
|
||||
$all[] = DB::setValue($key, $val);
|
||||
}
|
||||
}
|
||||
return implode(', ', $all);
|
||||
}
|
||||
|
||||
public static function cond($cond) {
|
||||
if (is_array($cond)) {
|
||||
if (count($cond) == 3) {
|
||||
$lhs = $cond[0] instanceof DBRawString ? $cond[0]->str : $cond[0];
|
||||
$op = $cond[1];
|
||||
$rhs = DB::value($cond[2]);
|
||||
return $lhs.' '.$op.' '.$rhs;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return $cond;
|
||||
}
|
||||
public static function conds($conds) {
|
||||
return is_array($conds) ? DB::land($conds) : $conds;
|
||||
}
|
||||
public static function land(array $conds) {
|
||||
if (is_assoc($conds)) {
|
||||
$new_conds = [];
|
||||
foreach ($conds as $key => $val) {
|
||||
if (is_int($key)) {
|
||||
$new_conds[] = $val;
|
||||
} else {
|
||||
if ($val !== null) {
|
||||
$new_conds[] = [$key, '=', $val];
|
||||
} else {
|
||||
$new_conds[] = [$key, 'is', $val];
|
||||
}
|
||||
}
|
||||
}
|
||||
$conds = $new_conds;
|
||||
}
|
||||
return '('.implode(' and ', array_map('DB::cond', $conds)).')';
|
||||
}
|
||||
public static function lor(array $conds) {
|
||||
if (is_assoc($conds)) {
|
||||
$new_conds = [];
|
||||
foreach ($conds as $key => $val) {
|
||||
if (is_int($key)) {
|
||||
$new_conds[] = $val;
|
||||
} else {
|
||||
if ($val !== null) {
|
||||
$new_conds[] = [$key, '=', $val];
|
||||
} else {
|
||||
$new_conds[] = [$key, 'is', $val];
|
||||
}
|
||||
}
|
||||
}
|
||||
$conds = $new_conds;
|
||||
}
|
||||
return '('.implode(' or ', array_map('DB::cond', $conds)).')';
|
||||
}
|
||||
public static function tuple(array $vals) {
|
||||
$str = '(';
|
||||
$first = true;
|
||||
foreach ($vals as $val) {
|
||||
if (!$first) {
|
||||
$str .= ',';
|
||||
} else {
|
||||
$first = false;
|
||||
}
|
||||
$str .= DB::value($val);
|
||||
}
|
||||
$str .= ')';
|
||||
return $str;
|
||||
}
|
||||
public static function tuples(array $tuples) {
|
||||
$all = [];
|
||||
foreach ($tuples as $vals) {
|
||||
$all[] = DB::tuple($vals);
|
||||
}
|
||||
return implode(', ', $all);
|
||||
}
|
||||
|
||||
public static function fetch($res, $opt = DB::ASSOC) {
|
||||
return $res->fetch_array($opt);
|
||||
}
|
||||
|
||||
public static function bracket($q) {
|
||||
return '('.DB::query_str($q).')';
|
||||
}
|
||||
public static function query_str($q) {
|
||||
if (is_array($q)) {
|
||||
$last = '';
|
||||
$qn = 0;
|
||||
$use_local_cache = false;
|
||||
foreach ($q as $val) {
|
||||
if (is_array($val)) {
|
||||
if ($last !== 'set' && $last !== "on duplicate key update") {
|
||||
$val = DB::land($val);
|
||||
} else {
|
||||
$val = DB::setValues($val);
|
||||
}
|
||||
} elseif ($val instanceof DBUseLocalCache) {
|
||||
$use_local_cache = true;
|
||||
$val = $val->str;
|
||||
}
|
||||
$last = $val;
|
||||
if ($val !== '') {
|
||||
$q[$qn++] = $val;
|
||||
}
|
||||
}
|
||||
array_splice($q, $qn);
|
||||
$q = implode(' ', $q);
|
||||
if ($use_local_cache) {
|
||||
$q = new DBUseLocalCache($q);
|
||||
}
|
||||
return $q;
|
||||
}
|
||||
return $q;
|
||||
}
|
||||
|
||||
public static function exists($q) {
|
||||
return 'exists '.DB::bracket($q);
|
||||
}
|
||||
|
||||
public static function query($q) {
|
||||
global $uojMySQL;
|
||||
return mysqli_query($uojMySQL, $q);
|
||||
return DB::$conn->query(DB::query_str($q));
|
||||
}
|
||||
public static function update($q) {
|
||||
global $uojMySQL;
|
||||
return mysqli_query($uojMySQL, $q);
|
||||
$ret = DB::$conn->query(DB::query_str($q));
|
||||
if ($ret === false) {
|
||||
UOJLog::error(DB::query_str($q));
|
||||
UOJLog::error('update failed: '.DB::$conn->error);
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
public static function insert($q) {
|
||||
global $uojMySQL;
|
||||
return mysqli_query($uojMySQL, $q);
|
||||
$ret = DB::$conn->query(DB::query_str($q));
|
||||
if ($ret === false) {
|
||||
UOJLog::error(DB::query_str($q));
|
||||
UOJLog::error('insert failed: '.DB::$conn->error);
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
public static function insert_id() {
|
||||
global $uojMySQL;
|
||||
return mysqli_insert_id($uojMySQL);
|
||||
return DB::$conn->insert_id;
|
||||
}
|
||||
|
||||
public static function delete($q) {
|
||||
global $uojMySQL;
|
||||
return mysqli_query($uojMySQL, $q);
|
||||
$ret = DB::$conn->query(DB::query_str($q));
|
||||
if ($ret === false) {
|
||||
UOJLog::error(DB::query_str($q));
|
||||
UOJLog::error('delete failed: '.DB::$conn->error);
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
public static function select($q) {
|
||||
global $uojMySQL;
|
||||
return mysqli_query($uojMySQL, $q);
|
||||
$q = DB::query_str($q);
|
||||
if ($q instanceof DBUseLocalCache) {
|
||||
$q = $q->str;
|
||||
$use_local_cache = true;
|
||||
} else {
|
||||
$use_local_cache = false;
|
||||
}
|
||||
public static function selectAll($q, $opt = MYSQLI_ASSOC) {
|
||||
global $uojMySQL;
|
||||
$res = array();
|
||||
$qr = mysqli_query($uojMySQL, $q);
|
||||
while ($row = mysqli_fetch_array($qr, $opt)) {
|
||||
if ($use_local_cache && isset(DB::$cache[$q])) {
|
||||
$res = DB::$cache[$q];
|
||||
$res->data_seek(0);
|
||||
$res->field_seek(0);
|
||||
return $res;
|
||||
}
|
||||
$res = DB::$conn->query($q);
|
||||
if ($use_local_cache) {
|
||||
DB::$cache[$q] = $res;
|
||||
}
|
||||
if ($res === false) {
|
||||
UOJLog::error($q);
|
||||
UOJLog::error(DB::$conn->error);
|
||||
}
|
||||
return $res;
|
||||
}
|
||||
public static function selectAll($q, $opt = DB::ASSOC) {
|
||||
$qres = DB::select($q);
|
||||
if ($qres === false) {
|
||||
return false;
|
||||
}
|
||||
// return $qres->fetch_all($opt); not supported
|
||||
|
||||
$res = [];
|
||||
while ($row = $qres->fetch_array($opt)) {
|
||||
$res[] = $row;
|
||||
}
|
||||
return $res;
|
||||
}
|
||||
public static function selectFirst($q, $opt = MYSQLI_ASSOC) {
|
||||
global $uojMySQL;
|
||||
return mysqli_fetch_array(mysqli_query($uojMySQL, $q), $opt);
|
||||
public static function selectFirst($q, $opt = DB::ASSOC) {
|
||||
$res = DB::select($q);
|
||||
if ($res === false) {
|
||||
return false;
|
||||
}
|
||||
return $res->fetch_array($opt);
|
||||
}
|
||||
public static function selectSingle($q) {
|
||||
$res = DB::select($q);
|
||||
if ($res === false) {
|
||||
return false;
|
||||
}
|
||||
$row = $res->fetch_row();
|
||||
if (!$row) {
|
||||
return false;
|
||||
}
|
||||
return $row[0];
|
||||
}
|
||||
|
||||
/**
|
||||
* perform SQL query $q in the form of select count(*) from XXX where XXX;
|
||||
*/
|
||||
public static function selectCount($q) {
|
||||
global $uojMySQL;
|
||||
list($cnt) = mysqli_fetch_array(mysqli_query($uojMySQL, $q), MYSQLI_NUM);
|
||||
$res = DB::select($q);
|
||||
if ($res === false) {
|
||||
return false;
|
||||
}
|
||||
list($cnt) = $res->fetch_row();
|
||||
return $cnt;
|
||||
}
|
||||
|
||||
public static function checkTableExists($name) {
|
||||
global $uojMySQL;
|
||||
return DB::query("select 1 from $name") !== false;
|
||||
/**
|
||||
* perform SQL query: select exists ($q);
|
||||
*
|
||||
* on success, returns 0 or 1
|
||||
* on failure, returns false
|
||||
*
|
||||
* @return int|false
|
||||
*/
|
||||
public static function selectExists($q) {
|
||||
$res = DB::select(["select", DB::exists($q)]);
|
||||
if ($res === false) {
|
||||
return false;
|
||||
}
|
||||
return (int)($res->fetch_row()[0]);
|
||||
}
|
||||
|
||||
public static function num_rows() {
|
||||
global $uojMySQL;
|
||||
return mysqli_num_rows($uojMySQL);
|
||||
public static function limit() {
|
||||
$num = func_get_args();
|
||||
if (count($num) == 1) {
|
||||
return "limit ".((int)$num[0]);
|
||||
} elseif (count($num) == 2) {
|
||||
return "limit ".((int)$num[0]).",".((int)$num[1]);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static function for_share() {
|
||||
return "for share";
|
||||
}
|
||||
public static function for_update() {
|
||||
return "for update";
|
||||
}
|
||||
|
||||
public static function startTransaction() {
|
||||
return DB::$conn->begin_transaction();
|
||||
}
|
||||
|
||||
public static function rollback() {
|
||||
return DB::$conn->rollback();
|
||||
}
|
||||
|
||||
public static function commit() {
|
||||
return DB::$conn->commit();
|
||||
}
|
||||
|
||||
public static function transaction($func) {
|
||||
if (DB::$in_transaction) {
|
||||
$ret = $func();
|
||||
} else {
|
||||
DB::$in_transaction = true;
|
||||
DB::startTransaction();
|
||||
$ret = $func();
|
||||
DB::commit();
|
||||
DB::$in_transaction = false;
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
|
||||
public static function lock($tables, $func) {
|
||||
$q = [];
|
||||
foreach ($tables as $table => $type) {
|
||||
if ($type != DB::WLOCK && $type != DB::RLOCK) {
|
||||
UOJLog::error('Unknown type: '.$type);
|
||||
return false;
|
||||
}
|
||||
$q[] = $table.' '.$type;
|
||||
}
|
||||
$q = 'lock tables '.implode(',', $q);
|
||||
DB::query($q);
|
||||
|
||||
$ret = $func();
|
||||
|
||||
DB::query("unlock tables");
|
||||
|
||||
return $ret;
|
||||
}
|
||||
public static function checkTableExists($name) {
|
||||
return DB::select(["select 1 from", DB::table($name)]) !== false;
|
||||
}
|
||||
|
||||
public static function num_rows($res) {
|
||||
return $res->num_rows;
|
||||
}
|
||||
public static function affected_rows() {
|
||||
global $uojMySQL;
|
||||
return mysqli_affected_rows($uojMySQL);
|
||||
return DB::$conn->affected_rows;
|
||||
}
|
||||
}
|
||||
|
9
web/app/models/DBRawString.php
Normal file
9
web/app/models/DBRawString.php
Normal file
@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
class DBRawString {
|
||||
public $str = '';
|
||||
|
||||
function __construct($str) {
|
||||
$this->str = $str;
|
||||
}
|
||||
}
|
9
web/app/models/DBUseLocalCache.php
Normal file
9
web/app/models/DBUseLocalCache.php
Normal file
@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
class DBUseLocalCache {
|
||||
public $str;
|
||||
|
||||
function __construct($str) {
|
||||
$this->str = $str;
|
||||
}
|
||||
}
|
64
web/app/models/FS.php
Normal file
64
web/app/models/FS.php
Normal file
@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
class FS {
|
||||
public static function scandir(string $directory, $cfg = []) {
|
||||
$cfg += [
|
||||
'exclude_dots' => true
|
||||
];
|
||||
$entries = scandir($directory);
|
||||
if ($cfg['exclude_dots']) {
|
||||
$entries = array_filter($entries, fn($name) => $name !== '.' && $name !== '..');
|
||||
}
|
||||
return $entries;
|
||||
}
|
||||
|
||||
public static function scandir_r(string $directory, $cfg = []) {
|
||||
foreach (FS::scandir($directory, $cfg) as $name) {
|
||||
$cur = "{$directory}/{$name}";
|
||||
if (is_dir($cur)) {
|
||||
foreach (FS::scandir_r($cur, $cfg) as $sub) {
|
||||
yield "{$name}/{$sub}";
|
||||
}
|
||||
} else {
|
||||
yield $name;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $type lock type. can be either LOCK_SH or LOCK_EX
|
||||
*/
|
||||
public static function lock_file(string $path, int $type, callable $func) {
|
||||
$lock_fp = fopen($path, 'c');
|
||||
|
||||
if (!flock($lock_fp, $type | LOCK_NB)) {
|
||||
UOJLog::error("lock failed: {$path}");
|
||||
return false;
|
||||
}
|
||||
|
||||
$ret = $func();
|
||||
|
||||
flock($lock_fp, LOCK_UN | LOCK_NB);
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
public static function randomAvailableFileName($dir, $suffix = '') {
|
||||
do {
|
||||
$name = $dir . uojRandString(20) . $suffix;
|
||||
} while (file_exists(UOJContext::storagePath().$name));
|
||||
return $name;
|
||||
}
|
||||
|
||||
public static function randomAvailableTmpFileName() {
|
||||
return static::randomAvailableFileName('/tmp/');
|
||||
}
|
||||
|
||||
public static function randomAvailableSubmissionFileName() {
|
||||
$num = uojRand(1, 10000);
|
||||
if (!file_exists(UOJContext::storagePath()."/submission/$num")) {
|
||||
system("mkdir ".UOJContext::storagePath()."/submission/$num");
|
||||
}
|
||||
return static::randomAvailableFileName("/submission/$num/");
|
||||
}
|
||||
}
|
@ -1,14 +1,74 @@
|
||||
<?php
|
||||
|
||||
class HTML {
|
||||
public static function escape($str) {
|
||||
public static function escape(?string $str, $cfg = []) {
|
||||
if ($str === null) {
|
||||
return '';
|
||||
} else {
|
||||
if (!empty($cfg['single_line'])) {
|
||||
$str = str_replace(["\n", "\r"], '', $str);
|
||||
}
|
||||
return htmlspecialchars($str);
|
||||
}
|
||||
}
|
||||
public static function stripTags($str) {
|
||||
return strip_tags($str);
|
||||
}
|
||||
|
||||
public static function protocol(string $loc = 'main') {
|
||||
if (UOJConfig::$data['web'][$loc]['protocol'] === 'http/https') {
|
||||
if (UOJContext::isUsingHttps()) {
|
||||
return 'https';
|
||||
} else {
|
||||
return 'http';
|
||||
}
|
||||
} else {
|
||||
return UOJConfig::$data['web'][$loc]['protocol'];
|
||||
}
|
||||
}
|
||||
public static function port(string $loc = 'main') {
|
||||
if (UOJConfig::$data['web'][$loc]['port'] === '80/443') {
|
||||
return HTML::standard_port(HTML::protocol($loc));
|
||||
} else {
|
||||
return UOJConfig::$data['web'][$loc]['port'];
|
||||
}
|
||||
}
|
||||
public static function standard_port(string $protocol) {
|
||||
if ($protocol === 'http') {
|
||||
return 80;
|
||||
} elseif ($protocol === 'https') {
|
||||
return 443;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static function attr($attr) {
|
||||
$html = '';
|
||||
foreach ($attr as $key => $val) {
|
||||
$html .= ' ' . $key . '="';
|
||||
$html .= HTML::escape(is_array($val) ? implode(' ', $val) : $val);
|
||||
$html .= '"';
|
||||
}
|
||||
return $html;
|
||||
}
|
||||
|
||||
public static function tag_begin(string $name, array $attr = []) {
|
||||
return '<' . $name . HTML::attr($attr) . '>';
|
||||
}
|
||||
public static function tag_end(string $name) {
|
||||
return '</' . $name . '>';
|
||||
}
|
||||
public static function tag(string $name, array $attr, $content) {
|
||||
return HTML::tag_begin($name, $attr) . $content . HTML::tag_end($name);
|
||||
}
|
||||
public static function empty_tag(string $name, array $attr) {
|
||||
return '<' . $name . HTML::attr($attr) . ' />';
|
||||
}
|
||||
|
||||
public static function avatar_addr($user, $size) {
|
||||
if ($user['avatar_source'] == 'qq' && $user['qq']) {
|
||||
$extra = UOJUser::getExtra($user);
|
||||
if ($extra['avatar_source'] == 'qq' && $user['qq']) {
|
||||
$s = '5';
|
||||
|
||||
if ($size <= 40) {
|
||||
@ -26,9 +86,9 @@ class HTML {
|
||||
}
|
||||
|
||||
public static function tablist($tabs_info, $cur, $type = 'nav-tabs') {
|
||||
$html = '<ul class="nav '.$type.'" role="tablist">';
|
||||
$html = '<ul class="nav ' . $type . '" role="tablist">';
|
||||
foreach ($tabs_info as $id => $tab) {
|
||||
$html .= '<li class="nav-item"><a class="nav-link'.($cur == $id ? ' active' : '').'" href="'.$tab['url'].'" role="tab">'.$tab['name'].'</a></li>';
|
||||
$html .= '<li class="nav-item"><a class="nav-link' . ($cur == $id ? ' active' : '') . '" href="' . $tab['url'] . '" role="tab">' . $tab['name'] . '</a></li>';
|
||||
}
|
||||
$html .= '</ul>';
|
||||
return $html;
|
||||
@ -37,58 +97,76 @@ class HTML {
|
||||
public static function navListGroup($tabs_info, $cur) {
|
||||
$html = '<div class="list-group">';
|
||||
foreach ($tabs_info as $id => $tab) {
|
||||
$html .= '<a role="button" class="list-group-item list-group-item-action'.($cur == $id ? ' active' : '').'" href="'.$tab['url'].'">'.$tab['name'].'</a>';
|
||||
$html .= '<a role="button" class="list-group-item list-group-item-action' . ($cur == $id ? ' active' : '') . '" href="' . $tab['url'] . '">' . $tab['name'] . '</a>';
|
||||
}
|
||||
$html .= '</div>';
|
||||
return $html;
|
||||
}
|
||||
|
||||
public static function hiddenToken() {
|
||||
return '<input type="hidden" name="_token" value="'.crsf_token().'" />';
|
||||
return '<input type="hidden" name="_token" value="' . crsf_token() . '" />';
|
||||
}
|
||||
public static function div_vinput($name, $type, $label_text, $default_value) {
|
||||
return '<div id="'."div-$name".'" class="mb-3">'
|
||||
. '<label for="'."input-$name".'" class="control-label form-label">'.$label_text.'</label>'
|
||||
. '<input type="'.$type.'" class="form-control" name="'.$name.'" id="'."input-$name".'" value="'.HTML::escape($default_value).'" />'
|
||||
. '<span class="help-block invalid-feedback" id="'."help-$name".'"></span>'
|
||||
return '<div id="' . "div-$name" . '" class="mb-3">'
|
||||
. '<label for="' . "input-$name" . '" class="control-label form-label">' . $label_text . '</label>'
|
||||
. '<input type="' . $type . '" class="form-control" name="' . $name . '" id="' . "input-$name" . '" value="' . HTML::escape($default_value) . '" />'
|
||||
. '<span class="help-block invalid-feedback" id="' . "help-$name" . '"></span>'
|
||||
. '</div>';
|
||||
}
|
||||
public static function div_vtextarea($name, $label_text, $default_value) {
|
||||
return '<div id="'."div-$name".'" class="mb-3">'
|
||||
. '<label for="'."input-$name".'" class="control-label">'.$label_text.'</label>'
|
||||
. '<textarea class="form-control" name="'.$name.'" id="'."input-$name".'">'.HTML::escape($default_value).'</textarea>'
|
||||
. '<span class="help-block" id="'."help-$name".'"></span>'
|
||||
return '<div id="' . "div-$name" . '" class="mb-3">'
|
||||
. '<label for="' . "input-$name" . '" class="control-label">' . $label_text . '</label>'
|
||||
. '<textarea class="form-control" name="' . $name . '" id="' . "input-$name" . '">' . HTML::escape($default_value) . '</textarea>'
|
||||
. '<span class="help-block" id="' . "help-$name" . '"></span>'
|
||||
. '</div>';
|
||||
}
|
||||
public static function checkbox($name, $default_value) {
|
||||
$status = $default_value ? 'checked="checked" ' : '';
|
||||
return '<input type="checkbox" id="'."input-$name".'" name="'.$name.'" '.$status.'/>';
|
||||
return '<input class="form-check-input" type="checkbox" id="' . "input-$name" . '" name="' . $name . '" ' . $status . '/>';
|
||||
}
|
||||
public static function option($value, $text, $selected) {
|
||||
return '<option value="' . HTML::escape($value) . '"'
|
||||
. ($selected ? ' selected="selected"' : '') . '>'
|
||||
. HTML::escape($text)
|
||||
. '</option>';
|
||||
}
|
||||
public static function tr_none() {
|
||||
return '<tr class="text-center"><td colspan="233">' . UOJLocale::get('none') . '</td></tr>';
|
||||
}
|
||||
|
||||
public static function blog_url($username, $uri) {
|
||||
public static function blog_url($username, $uri, array $cfg = []) {
|
||||
$cfg += [
|
||||
'escape' => true
|
||||
];
|
||||
|
||||
switch (UOJConfig::$data['switch']['blog-domain-mode']) {
|
||||
case 1:
|
||||
$port = ((UOJConfig::$data['web']['blog']['protocol'] === "http" && UOJConfig::$data['web']['blog']['port'] == 80) || (UOJConfig::$data['web']['blog']['protocol'] === "https" && UOJConfig::$data['web']['blog']['port'] == 443)) ? '' : (':'.UOJConfig::$data['web']['blog']['port']);
|
||||
$url = UOJConfig::$data['web']['blog']['protocol'].'://'.blog_name_encode($username).'.'.UOJConfig::$data['web']['blog']['host'].$port;
|
||||
$port = ((UOJConfig::$data['web']['blog']['protocol'] === "http" && UOJConfig::$data['web']['blog']['port'] == 80) || (UOJConfig::$data['web']['blog']['protocol'] === "https" && UOJConfig::$data['web']['blog']['port'] == 443)) ? '' : (':' . UOJConfig::$data['web']['blog']['port']);
|
||||
$url = UOJConfig::$data['web']['blog']['protocol'] . '://' . blog_name_encode($username) . '.' . UOJConfig::$data['web']['blog']['host'] . $port;
|
||||
break;
|
||||
case 2:
|
||||
$port = ((UOJConfig::$data['web']['blog']['protocol'] === "http" && UOJConfig::$data['web']['blog']['port'] == 80) || (UOJConfig::$data['web']['blog']['protocol'] === "https" && UOJConfig::$data['web']['blog']['port'] == 443)) ? '' : (':'.UOJConfig::$data['web']['blog']['port']);
|
||||
$url = UOJConfig::$data['web']['blog']['protocol'].'://'.UOJConfig::$data['web']['blog']['host'].$port.'/'.blog_name_encode($username);
|
||||
$port = ((UOJConfig::$data['web']['blog']['protocol'] === "http" && UOJConfig::$data['web']['blog']['port'] == 80) || (UOJConfig::$data['web']['blog']['protocol'] === "https" && UOJConfig::$data['web']['blog']['port'] == 443)) ? '' : (':' . UOJConfig::$data['web']['blog']['port']);
|
||||
$url = UOJConfig::$data['web']['blog']['protocol'] . '://' . UOJConfig::$data['web']['blog']['host'] . $port . '/' . blog_name_encode($username);
|
||||
break;
|
||||
case 3:
|
||||
$url = HTML::url('/blog/'.blog_name_encode($username));
|
||||
$url = HTML::url('/blog/' . blog_name_encode($username));
|
||||
break;
|
||||
}
|
||||
$url .= $uri;
|
||||
$url = rtrim($url, '/');
|
||||
return HTML::escape($url);
|
||||
|
||||
if ($cfg['escape']) {
|
||||
$url = HTML::escape($url);
|
||||
}
|
||||
|
||||
return $url;
|
||||
}
|
||||
public static function blog_list_url() {
|
||||
switch (UOJConfig::$data['switch']['blog-domain-mode']) {
|
||||
case 1:
|
||||
case 2:
|
||||
$port = ((UOJConfig::$data['web']['blog']['protocol'] === "http" && UOJConfig::$data['web']['blog']['port'] == 80) || (UOJConfig::$data['web']['blog']['protocol'] === "https" && UOJConfig::$data['web']['blog']['port'] == 443)) ? '' : (':'.UOJConfig::$data['web']['blog']['port']);
|
||||
$url = UOJConfig::$data['web']['blog']['protocol'].'://'.UOJConfig::$data['web']['blog']['host'].$port;
|
||||
$port = ((UOJConfig::$data['web']['blog']['protocol'] === "http" && UOJConfig::$data['web']['blog']['port'] == 80) || (UOJConfig::$data['web']['blog']['protocol'] === "https" && UOJConfig::$data['web']['blog']['port'] == 443)) ? '' : (':' . UOJConfig::$data['web']['blog']['port']);
|
||||
$url = UOJConfig::$data['web']['blog']['protocol'] . '://' . UOJConfig::$data['web']['blog']['host'] . $port;
|
||||
break;
|
||||
case 3:
|
||||
$url = HTML::url('/blogs');
|
||||
@ -97,50 +175,214 @@ class HTML {
|
||||
return HTML::escape(rtrim($url, '/'));
|
||||
}
|
||||
|
||||
public static function url($uri, $config = array()) {
|
||||
$config = array_merge(array(
|
||||
public static function url($uri, array $cfg = []) {
|
||||
$cfg += [
|
||||
'location' => 'main',
|
||||
'params' => null
|
||||
), $config);
|
||||
'params' => null,
|
||||
'remove_all_params' => false,
|
||||
'with_token' => false,
|
||||
'escape' => true
|
||||
];
|
||||
|
||||
$path = strtok($uri, '?');
|
||||
$qs = strtok('?');
|
||||
parse_str($qs, $param);
|
||||
|
||||
if ($config['params'] != null) {
|
||||
$param = array_merge($param, $config['params']);
|
||||
if ($cfg['location'] == 'cdn' && !UOJContext::hasCDN()) {
|
||||
$cfg['location'] = 'main';
|
||||
}
|
||||
|
||||
$url = ''; // '//'.UOJConfig::$data['web'][$config['location']]['host'];
|
||||
if (strStartWith($uri, '?')) {
|
||||
$path = strtok(UOJContext::requestURI(), '?');
|
||||
$qs = strtok($uri, '?');
|
||||
} else {
|
||||
$path = strtok($uri, '?');
|
||||
$qs = strtok('?');
|
||||
}
|
||||
|
||||
parse_str($qs, $param);
|
||||
|
||||
|
||||
if ($cfg['remove_all_params']) {
|
||||
$param = [];
|
||||
} elseif ($cfg['params'] != null) {
|
||||
$param = array_merge($param, $cfg['params']);
|
||||
}
|
||||
if ($cfg['with_token']) {
|
||||
$param['_token'] = crsf_token();
|
||||
}
|
||||
|
||||
// $url = '//'.UOJConfig::$data['web'][$config['location']]['host'];
|
||||
// if (HTML::port($cfg['location']) != HTML::standard_port($protocol)) {
|
||||
// $url .= ':'.HTML::port($cfg['location']);
|
||||
// }
|
||||
$url = '';
|
||||
if ($param) {
|
||||
$url .= $path.'?'.HTML::query_string_encode($param);
|
||||
$url .= $path . '?' . HTML::query_string_encode($param);
|
||||
} elseif ($path != '/') {
|
||||
$url .= rtrim($path, '/');
|
||||
} else {
|
||||
$url .= $path;
|
||||
}
|
||||
return HTML::escape($url);
|
||||
}
|
||||
public static function timeanddate_url($time, $config = array()) {
|
||||
$url = UOJConfig::$data['web']['blog']['protocol'].'://';
|
||||
$url .= 'www.timeanddate.com/worldclock/fixedtime.html';
|
||||
$url .= '?'.'iso='.$time->format('Ymd\THi');
|
||||
$url .= '&'.'p1=33';
|
||||
if (isset($config['duration']) && $config['duration'] < 3600) {
|
||||
$url .= '&'.'ah='.floor($config['duration'] / 60);
|
||||
if ($config['duration'] % 60 != 0) {
|
||||
$url .= '&'.'am='.($config['duration'] % 60);
|
||||
}
|
||||
}
|
||||
|
||||
if ($cfg['escape']) {
|
||||
$url = HTML::escape($url);
|
||||
}
|
||||
return $url;
|
||||
}
|
||||
|
||||
public static function js_src($uri, $config = array('location' => 'main')) {
|
||||
return '<script src="'.HTML::url($uri, $config).'"></script>';
|
||||
public static function timeanddate_url(DateTime $time, array $cfg = []) {
|
||||
$url = HTML::protocol() . '://';
|
||||
$url .= 'www.timeanddate.com/worldclock/fixedtime.html';
|
||||
$url .= '?' . 'iso=' . $time->format('Ymd\THi');
|
||||
$url .= '&' . 'p1=33';
|
||||
if (isset($cfg['duration']) && $cfg['duration'] < 3600) {
|
||||
$url .= '&' . 'ah=' . floor($cfg['duration'] / 60);
|
||||
if ($cfg['duration'] % 60 != 0) {
|
||||
$url .= '&' . 'am=' . ($cfg['duration'] % 60);
|
||||
}
|
||||
public static function css_link($uri, $config = array('location' => 'main')) {
|
||||
return '<link type="text/css" rel="stylesheet" href="'.HTML::url($uri, $config).'" />';
|
||||
}
|
||||
return HTML::escape($url);
|
||||
}
|
||||
|
||||
public static function relative_time_str($time, $gran = -1) {
|
||||
$d = [
|
||||
[1, 'seconds'],
|
||||
[60, 'minutes'],
|
||||
[3600, 'hours'],
|
||||
[86400, 'days'],
|
||||
[604800, 'weeks'],
|
||||
[2592000, 'months'],
|
||||
[31536000, 'years'],
|
||||
];
|
||||
$w = [];
|
||||
|
||||
$res = "";
|
||||
$diff = time() - $time;
|
||||
$secondsLeft = $diff;
|
||||
$stopat = 0;
|
||||
for ($i = 6; $i > $gran; $i--) {
|
||||
$w[$i] = intval($secondsLeft / $d[$i][0]);
|
||||
$secondsLeft -= ($w[$i] * $d[$i][0]);
|
||||
if ($w[$i] != 0) {
|
||||
$res .= UOJLocale::get('time::x ' . $d[$i][1], abs($w[$i])) . " ";
|
||||
switch ($i) {
|
||||
case 6: // shows years and months
|
||||
if ($stopat == 0) {
|
||||
$stopat = 5;
|
||||
}
|
||||
break;
|
||||
case 5: // shows months and weeks
|
||||
if ($stopat == 0) {
|
||||
$stopat = 4;
|
||||
}
|
||||
break;
|
||||
case 4: // shows weeks and days
|
||||
if ($stopat == 0) {
|
||||
$stopat = 3;
|
||||
}
|
||||
break;
|
||||
case 3: // shows days and hours
|
||||
if ($stopat == 0) {
|
||||
$stopat = 2;
|
||||
}
|
||||
break;
|
||||
case 2: // shows hours and minutes
|
||||
if ($stopat == 0) {
|
||||
$stopat = 1;
|
||||
}
|
||||
break;
|
||||
case 1: // shows minutes and seconds if granularity is not set higher
|
||||
break;
|
||||
}
|
||||
if ($i === $stopat) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$res .= ($diff > 0) ? UOJLocale::get('time::ago') : UOJLocale::get('time::left');
|
||||
|
||||
return $res;
|
||||
}
|
||||
|
||||
public static function link(?string $uri, $text, $cfg = ['location' => 'main']) {
|
||||
if ($uri === null) {
|
||||
return '<a>' . HTML::escape($text) . '</a>';
|
||||
}
|
||||
return '<a class="text-decoration-none" href="' . HTML::url($uri, $cfg) . '">' . HTML::escape($text) . '</a>';
|
||||
}
|
||||
public static function autolink(string $url, array $attr = []) {
|
||||
return '<a class="text-decoration-none" href="' . $url . '"' . HTML::attr($attr) . '>' . $url . '</a>';
|
||||
}
|
||||
public static function js_src(string $uri, array $cfg = []) {
|
||||
$cfg += [
|
||||
'location' => 'cdn',
|
||||
'async' => false
|
||||
];
|
||||
$async = empty($cfg['async']) ? '' : 'async ';
|
||||
return '<script ' . $async . 'src="' . HTML::url($uri, $cfg) . '"></script>';
|
||||
}
|
||||
public static function css_link(string $uri, $cfg = []) {
|
||||
$cfg += ['location' => 'cdn'];
|
||||
return '<link rel="stylesheet" href="' . HTML::url($uri, $cfg) . '" />';
|
||||
}
|
||||
|
||||
public static function table($header, iterable $data, $cfg = []) {
|
||||
mergeConfig($cfg, [
|
||||
'th' => function ($c) {
|
||||
return "<th>{$c}</th>";
|
||||
},
|
||||
'td' => function ($d) {
|
||||
return "<td>{$d}</td>";
|
||||
},
|
||||
'tr' => false, // if tr is a function, then td and tr_attr is disabled
|
||||
'empty' => 'HTML::tr_none',
|
||||
'table_attr' => [
|
||||
'class' => ['table'],
|
||||
],
|
||||
'thead_attr' => [],
|
||||
'tbody_attr' => [],
|
||||
'tr_attr' => function ($row, $idx) {
|
||||
return [];
|
||||
}
|
||||
]);
|
||||
|
||||
$html = HTML::tag_begin('table', $cfg['table_attr']);
|
||||
$html .= HTML::tag_begin('thead', $cfg['thead_attr']);
|
||||
if (is_array($header)) {
|
||||
$html .= '<tr>' . implode(' ', array_map($cfg['th'], array_values($header), array_keys($header))) . '</tr>';
|
||||
} else {
|
||||
$html .= $header;
|
||||
}
|
||||
$html .= HTML::tag_end('thead');
|
||||
$html .= HTML::tag_begin('tbody', $cfg['tbody_attr']);
|
||||
if (is_iterable($data)) {
|
||||
$data_html = [];
|
||||
if (is_callable($cfg['tr'])) {
|
||||
foreach ($data as $idx => $row) {
|
||||
$data_html[] = $cfg['tr']($row, $idx);
|
||||
}
|
||||
} else {
|
||||
foreach ($data as $idx => $row) {
|
||||
$data_html[] = HTML::tag_begin('tr', $cfg['tr_attr']($row, $idx));
|
||||
if (is_array($row)) {
|
||||
foreach ($row as $cidx => $c) {
|
||||
$data_html[] = $cfg['td']($c, $cidx);
|
||||
}
|
||||
} else {
|
||||
$data_html[] = $row;
|
||||
}
|
||||
$data_html[] = HTML::tag_end('tr');
|
||||
}
|
||||
}
|
||||
$data_html = implode($data_html);
|
||||
} else {
|
||||
$data_html = $data;
|
||||
}
|
||||
$html .= $data_html !== '' ? $data_html : $cfg['empty']();
|
||||
$html .= HTML::tag_end('tbody');
|
||||
$html .= HTML::tag_end('table');
|
||||
return $html;
|
||||
}
|
||||
|
||||
public static function responsive_table($header, $data, $cfg = []) {
|
||||
return HTML::tag_begin('div', ['class' => 'table-responsive']) . HTML::table($header, $data, $cfg) . HTML::tag_end('div');
|
||||
}
|
||||
|
||||
public static function query_string_encode($q, $array_name = null) {
|
||||
@ -151,15 +393,15 @@ class HTML {
|
||||
foreach ((array)$q as $k => $v) {
|
||||
if ($array_name !== null) {
|
||||
if (is_numeric($k)) {
|
||||
$k = $array_name."[]";
|
||||
$k = $array_name . "[]";
|
||||
} else {
|
||||
$k = $array_name."[$k]";
|
||||
$k = $array_name . "[$k]";
|
||||
}
|
||||
}
|
||||
if (is_array($v) || is_object($v)) {
|
||||
$r[] = self::query_string_encode($v, $k);
|
||||
} else {
|
||||
$r[] = urlencode($k)."=".urlencode($v);
|
||||
$r[] = urlencode($k) . "=" . urlencode($v);
|
||||
}
|
||||
}
|
||||
return implode("&", $r);
|
||||
@ -239,4 +481,35 @@ class HTML {
|
||||
]
|
||||
]);
|
||||
}
|
||||
|
||||
public static function echoPanel($cls = [], $title, $body, $other = null) {
|
||||
if (is_string($cls)) {
|
||||
$cls = ['card' => $cls];
|
||||
}
|
||||
|
||||
$cls += [
|
||||
'card' => '',
|
||||
'header' => '',
|
||||
'body' => '',
|
||||
];
|
||||
echo '<div class="card ', $cls['card'], '">';
|
||||
echo '<div class="card-header fw-bold ', $cls['header'], '">', $title, '</div>';
|
||||
if ($body !== null) {
|
||||
echo '<div class="card-body ', $cls['body'], '">';
|
||||
if (is_string($body)) {
|
||||
echo $body;
|
||||
} else {
|
||||
$body();
|
||||
}
|
||||
echo '</div>';
|
||||
}
|
||||
if ($other !== null) {
|
||||
if (is_string($other)) {
|
||||
echo $other;
|
||||
} else {
|
||||
$other();
|
||||
}
|
||||
}
|
||||
echo '</div>';
|
||||
}
|
||||
}
|
||||
|
@ -7,44 +7,113 @@ class Paginator {
|
||||
public $cur_page;
|
||||
public $cur_start;
|
||||
public $max_extend;
|
||||
|
||||
public $table_name;
|
||||
public $cond;
|
||||
public $col_names;
|
||||
public $tail;
|
||||
public $post_filter;
|
||||
|
||||
public $table;
|
||||
|
||||
public function getPage($page) {
|
||||
$cur_start = ($page - 1) * $this->page_len;
|
||||
$table = DB::selectAll([
|
||||
"select", DB::fields($this->col_names), "from", DB::query_str($this->table_name),
|
||||
"where", $this->cond,
|
||||
$this->tail, DB::limit($cur_start, $this->page_len)
|
||||
]);
|
||||
if ($this->post_filter === null) {
|
||||
return $table;
|
||||
} else {
|
||||
return array_filter($table, $this->post_filter);
|
||||
}
|
||||
}
|
||||
|
||||
public function checkPageExists($page) {
|
||||
if ($page < 1 || $page > $this->n_pages) {
|
||||
return false;
|
||||
}
|
||||
if ($this->post_filter === null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$post_filter = $this->post_filter;
|
||||
$cur_start = ($page - 1) * $this->page_len;
|
||||
for ($bg = 0; $bg < $this->page_len; $bg += 10) {
|
||||
$table = DB::selectAll([
|
||||
"select", DB::fields($this->col_names), "from", DB::query_str($this->table_name),
|
||||
"where", $this->cond,
|
||||
$this->tail, DB::limit($cur_start + $bg, min(10, $this->page_len - $bg))
|
||||
]);
|
||||
foreach ($table as $entry) {
|
||||
if ($post_filter($entry)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public function __construct($config) {
|
||||
$this->max_extend = isset($config['max_extend']) ? (int)$config['max_extend'] : 5;
|
||||
$this->post_filter = isset($config['post_filter']) ? $config['post_filter'] : null;
|
||||
|
||||
if (isset($config['data'])) {
|
||||
$this->n_pages = 1;
|
||||
$this->cur_page = 1;
|
||||
$this->cur_start = 0;
|
||||
$this->table = $config['data'];
|
||||
} elseif (!isset($config['echo_full'])) {
|
||||
$table = $config['table_name'];
|
||||
$cond = isset($config['cond']) ? $config['cond'] : '1';
|
||||
if (isset($config['pagination_table'])) {
|
||||
$table = $config['pagination_table'];
|
||||
$cond = isset($config['pagination_cond']) ? $config['pagination_cond'] : $cond;
|
||||
if ($this->post_filter !== null) {
|
||||
$this->table = array_filter($this->table, $this->post_filter);
|
||||
}
|
||||
$this->n_rows = DB::selectCount("select count(*) from {$table} where {$cond}");
|
||||
|
||||
$this->page_len = isset($config['page_len']) ? $config['page_len'] : 10;
|
||||
|
||||
$this->n_pages = max((int)ceil($this->n_rows / $this->page_len), 1);
|
||||
|
||||
$this->cur_page = validateUInt($_GET['page']) ? (int)$_GET['page'] : 1;
|
||||
} elseif (!isset($config['echo_full'])) {
|
||||
$this->cur_page = UOJRequest::get('page', 'validateUInt', 1);
|
||||
if ($this->cur_page < 1) {
|
||||
$this->cur_page = 1;
|
||||
} elseif ($this->cur_page > $this->n_pages) {
|
||||
}
|
||||
$this->page_len = isset($config['page_len']) ? $config['page_len'] : 10;
|
||||
|
||||
$this->table_name = $config['table_name'];
|
||||
$this->cond = $config['cond'];
|
||||
$this->col_names = $config['col_names'];
|
||||
$this->tail = $config['tail'];
|
||||
|
||||
$this->n_rows = DB::selectCount([
|
||||
"select", "count(*)",
|
||||
"from", DB::query_str($this->table_name),
|
||||
"where", $this->cond,
|
||||
$this->tail,
|
||||
]);
|
||||
|
||||
$this->n_pages = max((int)ceil($this->n_rows / $this->page_len), 1);
|
||||
while ($this->n_pages > 1 && !$this->checkPageExists($this->n_pages)) {
|
||||
$this->n_pages--;
|
||||
}
|
||||
if ($this->cur_page > $this->n_pages) {
|
||||
$this->cur_page = $this->n_pages;
|
||||
}
|
||||
while (true) {
|
||||
$this->table = $this->getPage($this->cur_page);
|
||||
if ($this->table || $this->cur_page == 1) {
|
||||
break;
|
||||
}
|
||||
$this->cur_page--;
|
||||
}
|
||||
$this->cur_start = ($this->cur_page - 1) * $this->page_len;
|
||||
|
||||
$this->table = DB::selectAll("select ".join($config['col_names'], ',')." from {$config['table_name']} where {$config['cond']} {$config['tail']} limit {$this->cur_start}, {$this->page_len}");
|
||||
} else {
|
||||
$this->n_pages = 1;
|
||||
$this->cur_page = 1;
|
||||
$this->cur_start = ($this->cur_page - 1) * $this->page_len;
|
||||
$this->table = DB::selectAll("select ".join($config['col_names'], ',')." from {$config['table_name']} where {$config['cond']} {$config['tail']}");
|
||||
$this->cur_start = 0;
|
||||
$this->table = DB::selectAll([
|
||||
"select", DB::fields($config['col_names']), "from", DB::query_str($config['table_name']),
|
||||
"where", $config['cond'],
|
||||
$config['tail']
|
||||
]);
|
||||
if ($this->post_filter !== null) {
|
||||
$this->table = array_filter($this->table, $this->post_filter);
|
||||
}
|
||||
}
|
||||
|
||||
$this->max_extend = isset($config['max_extend']) ? (int)$config['max_extend'] : 5;
|
||||
}
|
||||
|
||||
public function getPageRawUri($page) {
|
||||
@ -67,101 +136,73 @@ class Paginator {
|
||||
return HTML::escape($this->getPageRawUri($page));
|
||||
}
|
||||
|
||||
public function get() {
|
||||
public function get($limit = -1) {
|
||||
$cur_idx = $this->cur_start + 1;
|
||||
foreach ($this->table as $idx => $row) {
|
||||
foreach ($this->table as $row) {
|
||||
if ($limit != -1 && $cur_idx - $this->cur_start > $limit) {
|
||||
break;
|
||||
}
|
||||
yield $cur_idx++ => $row;
|
||||
}
|
||||
}
|
||||
public function isEmpty() {
|
||||
return empty($this->table);
|
||||
}
|
||||
public function countInCurPage() {
|
||||
return count($this->table);
|
||||
}
|
||||
|
||||
public function pagination() {
|
||||
global $REQUIRE_LIB;
|
||||
|
||||
if ($this->n_pages == 1) {
|
||||
return '';
|
||||
}
|
||||
if (isset($REQUIRE_LIB['bootstrap5'])) {
|
||||
$html = '<ul class="pagination my-0 justify-content-center">';
|
||||
} else {
|
||||
$html = '<ul class="pagination top-buffer-no bot-buffer-sm justify-content-center">';
|
||||
}
|
||||
if ($this->cur_page > 1) {
|
||||
$html .= '<li class="page-item">'
|
||||
. '<a class="page-link" href="'.$this->getPageUri(1).'">';
|
||||
if (isset($REQUIRE_LIB['bootstrap5'])) {
|
||||
$html .= '<i class="bi bi-chevron-double-left"></i>';
|
||||
} else {
|
||||
$html .= '<span class="glyphicon glyphicon glyphicon-fast-backward"></span>';
|
||||
}
|
||||
$html .= '</a></li>';
|
||||
$html .= '<li class="page-item">'
|
||||
. '<a class="page-link" href="'.$this->getPageUri($this->cur_page - 1).'">';
|
||||
if (isset($REQUIRE_LIB['bootstrap5'])) {
|
||||
$html .= '<i class="bi bi-chevron-left"></i>';
|
||||
} else {
|
||||
$html .= '<span class="glyphicon glyphicon glyphicon-backward"></span>';
|
||||
}
|
||||
$html .= '</a></li>';
|
||||
} else {
|
||||
$html .= '<li class="page-item disabled"><a class="page-link">';
|
||||
if (isset($REQUIRE_LIB['bootstrap5'])) {
|
||||
$html .= '<i class="bi bi-chevron-double-left"></i>';
|
||||
} else {
|
||||
$html .= '<span class="glyphicon glyphicon glyphicon-fast-backward"></span>';
|
||||
}
|
||||
$html .= '</a></li>';
|
||||
$html .= '<li class="page-item disabled"><a class="page-link">';
|
||||
if (isset($REQUIRE_LIB['bootstrap5'])) {
|
||||
$html .= '<i class="bi bi-chevron-left"></i>';
|
||||
} else {
|
||||
$html .= '<span class="glyphicon glyphicon glyphicon-backward"></span>';
|
||||
}
|
||||
$html .= '</a></li>';
|
||||
}
|
||||
$prev_page = false;
|
||||
$next_page = false;
|
||||
$main_lis = '';
|
||||
|
||||
for ($i = max($this->cur_page - $this->max_extend, 1); $i <= min($this->cur_page + $this->max_extend, $this->n_pages); $i++) {
|
||||
$page_st = $this->cur_page - $this->max_extend;
|
||||
$page_ed = $this->cur_page + $this->max_extend;
|
||||
if ($this->n_pages <= $this->max_extend * 2 + 1) {
|
||||
$page_st = 1;
|
||||
$page_ed = $this->n_pages;
|
||||
} elseif ($page_st < 1) {
|
||||
$page_st = 1;
|
||||
$page_ed = $this->max_extend * 2 + 1;
|
||||
} elseif ($page_ed > $this->n_pages) {
|
||||
$page_st = $this->n_pages - $this->max_extend * 2;
|
||||
$page_ed = $this->n_pages;
|
||||
}
|
||||
for ($i = $page_st; $i <= $page_ed; $i++) {
|
||||
if ($i == $this->cur_page) {
|
||||
$html .= '<li class="page-item active"><a class="page-link" href="'.$this->getPageUri($i).'">'.$i.'</a></li>';
|
||||
$main_lis .= '<li class="page-item active"><a class="page-link" href="' . $this->getPageUri($i) . '">' . $i . '</a></li>';
|
||||
} else {
|
||||
$html .= '<li class="page-item"><a class="page-link" href="'.$this->getPageUri($i).'">'.$i.'</a></li>';
|
||||
if ($this->checkPageExists($i)) {
|
||||
$main_lis .= '<li class="page-item"><a class="page-link" href="' . $this->getPageUri($i) . '">' . $i . '</a></li>';
|
||||
if ($i < $this->cur_page) {
|
||||
$prev_page = $i;
|
||||
} elseif ($next_page === false) {
|
||||
$next_page = $i;
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($this->cur_page < $this->n_pages) {
|
||||
$html .= '<li class="page-item">'
|
||||
. '<a class="page-link" href="'.$this->getPageUri($this->cur_page + 1).'">';
|
||||
if (isset($REQUIRE_LIB['bootstrap5'])) {
|
||||
$html .= '<i class="bi bi-chevron-right"></i>';
|
||||
} else {
|
||||
$html .= '<span class="glyphicon glyphicon glyphicon-forward"></span>';
|
||||
}
|
||||
$html .= '</a></li>';
|
||||
|
||||
$html .= '<li class="page-item">'
|
||||
. '<a class="page-link" href="'.$this->getPageUri($this->n_pages).'">';
|
||||
if (isset($REQUIRE_LIB['bootstrap5'])) {
|
||||
$html .= '<i class="bi bi-chevron-double-right"></i>';
|
||||
$html = '';
|
||||
$html .= '<ul class="pagination my-0 justify-content-center">';
|
||||
if ($prev_page !== false) {
|
||||
$html .= '<li class="page-item"><a class="page-link" href="' . $this->getPageUri(1) . '""><i class="bi bi-chevron-double-left"></i></a></li>';
|
||||
$html .= '<li class="page-item"><a class="page-link" href="' . $this->getPageUri($prev_page) . '"><i class="bi bi-chevron-left"></i></a></li>';
|
||||
} else {
|
||||
$html .= '<span class="glyphicon glyphicon glyphicon-fast-forward"></span>';
|
||||
$html .= '<li class="page-item disabled"><a class="page-link"><i class="bi bi-chevron-double-left"></i></a></li>';
|
||||
$html .= '<li class="page-item disabled"><a class="page-link"><i class="bi bi-chevron-left"></i></a></li>';
|
||||
}
|
||||
$html .= '</a></li>';
|
||||
$html .= $main_lis;
|
||||
if ($next_page !== false) {
|
||||
$html .= '<li class="page-item"><a class="page-link" href="' . $this->getPageUri($next_page) . '"><i class="bi bi-chevron-right"></i></a></li>';
|
||||
$html .= '<li class="page-item"><a class="page-link" href="' . $this->getPageUri($this->n_pages) . '"><i class="bi bi-chevron-double-right"></i></a></li>';
|
||||
} else {
|
||||
$html .= '<li class="page-item disabled"><a class="page-link">';
|
||||
if (isset($REQUIRE_LIB['bootstrap5'])) {
|
||||
$html .= '<i class="bi bi-chevron-right"></i>';
|
||||
} else {
|
||||
$html .= '<span class="glyphicon glyphicon glyphicon-forward"></span>';
|
||||
}
|
||||
$html .= '</a></li>';
|
||||
$html .= '<li class="page-item disabled"><a class="page-link">';
|
||||
if (isset($REQUIRE_LIB['bootstrap5'])) {
|
||||
$html .= '<i class="bi bi-chevron-double-right"></i>';
|
||||
} else {
|
||||
$html .= '<span class="glyphicon glyphicon glyphicon-fast-forward"></span>';
|
||||
}
|
||||
$html .= '</a></li>';
|
||||
$html .= '<li class="page-item disabled"><a class="page-link"><i class="bi bi-chevron-right"></i></a></li>';
|
||||
$html .= '<li class="page-item disabled"><a class="page-link"><i class="bi bi-chevron-double-right"></i></a></li>';
|
||||
}
|
||||
$html .= '</ul>';
|
||||
return $html;
|
||||
|
@ -1,15 +1,15 @@
|
||||
<?php
|
||||
|
||||
class Route {
|
||||
protected static $routes = array();
|
||||
protected static $patterns = array();
|
||||
protected static $groupStack = array(array());
|
||||
protected static $routes = [];
|
||||
protected static $patterns = [];
|
||||
protected static $groupStack = [[]];
|
||||
|
||||
public static function match($methods, $uri, $action) {
|
||||
return self::addRoute(array_map('strtoupper', (array)$methods), $uri, $action);
|
||||
}
|
||||
public static function any($uri, $action) {
|
||||
return self::addRoute(array('GET', 'HEAD', 'POST', 'PUT', 'PATCH', 'DELETE'), $uri, $action);
|
||||
return self::addRoute(['GET', 'HEAD', 'POST', 'PUT', 'PATCH', 'DELETE'], $uri, $action);
|
||||
}
|
||||
public static function get($uri, $action) {
|
||||
return self::addRoute(['GET', 'HEAD'], $uri, $action);
|
||||
@ -46,7 +46,7 @@ class Route {
|
||||
return $route;
|
||||
}
|
||||
}
|
||||
become404Page();
|
||||
UOJResponse::page404();
|
||||
}
|
||||
|
||||
protected static function addRoute($methods, $uri, $action) {
|
||||
@ -54,7 +54,7 @@ class Route {
|
||||
$methods = [$methods];
|
||||
}
|
||||
|
||||
$cur = array();
|
||||
$cur = [];
|
||||
$cur['methods'] = $methods;
|
||||
$cur['uri'] = rtrim($uri, '/');
|
||||
$cur['action'] = $action;
|
||||
@ -67,21 +67,27 @@ class Route {
|
||||
return false;
|
||||
}
|
||||
|
||||
$rep_arr = array();
|
||||
$rep_arr = [];
|
||||
foreach (self::$patterns as $name => $pat) {
|
||||
$rep_arr['{'.$name.'}'] = "(?P<$name>$pat)";
|
||||
}
|
||||
$rep_arr['/'] = '\/';
|
||||
$rep_arr['.'] = '\.';
|
||||
|
||||
$matches = array();
|
||||
$matches = [];
|
||||
if (isset($route['domain'])) {
|
||||
$domain_pat = strtr($route['domain'], $rep_arr);
|
||||
if (!preg_match('/^'.$domain_pat.'$/', UOJContext::httpHost(), $domain_matches)) {
|
||||
if (!preg_match('/^'.$domain_pat.'$/', UOJContext::requestDomain(), $domain_matches)) {
|
||||
return false;
|
||||
}
|
||||
$matches = array_merge($matches, $domain_matches);
|
||||
}
|
||||
if (isset($route['port'])) {
|
||||
$ports = explode('/', $route['port']);
|
||||
if (!in_array(UOJContext::requestPort(), $ports)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
$uri_pat = strtr($route['uri'], $rep_arr);
|
||||
if (!preg_match('/^'.$uri_pat.'$/', rtrim(UOJContext::requestPath(), '/'), $uri_matches)) {
|
||||
@ -95,6 +101,21 @@ class Route {
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($route['protocol'])) {
|
||||
switch ($route['protocol']) {
|
||||
case 'http':
|
||||
if (UOJContext::isUsingHttps()) {
|
||||
permanentlyRedirectToHTTP();
|
||||
}
|
||||
break;
|
||||
case 'https':
|
||||
if (!UOJContext::isUsingHttps()) {
|
||||
permanentlyRedirectToHTTPS();
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -8,7 +8,7 @@ class Session {
|
||||
|
||||
session_start();
|
||||
|
||||
register_shutdown_function(function() {
|
||||
register_shutdown_function(function () {
|
||||
if (empty($_SESSION)) {
|
||||
session_unset();
|
||||
session_destroy();
|
||||
|
65
web/app/models/StrictFileReader.php
Normal file
65
web/app/models/StrictFileReader.php
Normal file
@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
class StrictFileReader {
|
||||
private $f;
|
||||
private $buf = '', $off = 0;
|
||||
|
||||
public function __construct($file_name) {
|
||||
$this->f = fopen($file_name, 'r');
|
||||
}
|
||||
|
||||
public function failed() {
|
||||
return $this->f === false;
|
||||
}
|
||||
|
||||
public function readChar() {
|
||||
if (isset($this->buf[$this->off])) {
|
||||
return $this->buf[$this->off++];
|
||||
}
|
||||
return fgetc($this->f);
|
||||
}
|
||||
public function unreadChar($c) {
|
||||
$this->buf .= $c;
|
||||
if ($this->off > 1000) {
|
||||
$this->buf = substr($this->buf, $this->off);
|
||||
$this->off = 0;
|
||||
}
|
||||
}
|
||||
|
||||
public function readString() {
|
||||
$str = '';
|
||||
while (true) {
|
||||
$c = $this->readChar();
|
||||
if ($c === false) {
|
||||
break;
|
||||
} elseif ($c === " " || $c === "\n" || $c === "\r") {
|
||||
$this->unreadChar($c);
|
||||
break;
|
||||
} else {
|
||||
$str .= $c;
|
||||
}
|
||||
}
|
||||
return $str;
|
||||
}
|
||||
public function ignoreWhite() {
|
||||
while (true) {
|
||||
$c = $this->readChar();
|
||||
if ($c === false) {
|
||||
break;
|
||||
} elseif ($c === " " || $c === "\n" || $c === "\r") {
|
||||
continue;
|
||||
} else {
|
||||
$this->unreadChar($c);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function eof() {
|
||||
return feof($this->f);
|
||||
}
|
||||
|
||||
public function close() {
|
||||
fclose($this->f);
|
||||
}
|
||||
}
|
55
web/app/models/UOJArticleTrait.php
Normal file
55
web/app/models/UOJArticleTrait.php
Normal file
@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
trait UOJArticleTrait {
|
||||
static string $table_for_content;
|
||||
static string $key_for_content;
|
||||
static array $fields_for_content;
|
||||
static string $table_for_tags;
|
||||
static string $key_for_tags;
|
||||
|
||||
public ?array $tags = null;
|
||||
public ?array $content = null;
|
||||
|
||||
public function queryContent() {
|
||||
if ($this->content === null) {
|
||||
$this->content = DB::selectFirst([
|
||||
"select", DB::fields(static::$fields_for_content), "from", static::$table_for_content,
|
||||
"where", [static::$key_for_content => $this->info['id']]
|
||||
]);
|
||||
}
|
||||
return $this->content;
|
||||
}
|
||||
public function queryTags() {
|
||||
if ($this->tags === null) {
|
||||
$res = DB::selectAll([
|
||||
"select tag from", static::$table_for_tags,
|
||||
"where", [static::$key_for_tags => $this->info['id']],
|
||||
"order by id"
|
||||
]);
|
||||
$this->tags = [];
|
||||
foreach ($res as $row) {
|
||||
$this->tags[] = $row['tag'];
|
||||
}
|
||||
}
|
||||
return $this->tags;
|
||||
}
|
||||
public function updateTags(array $tags) {
|
||||
if ($tags !== $this->queryTags()) {
|
||||
DB::delete([
|
||||
"delete from", static::$table_for_tags,
|
||||
"where", [static::$key_for_tags => $this->info['id']],
|
||||
]);
|
||||
if ($tags) {
|
||||
$tuples = [];
|
||||
foreach ($tags as $tag) {
|
||||
$tuples[] = [$this->info['id'], $tag];
|
||||
}
|
||||
DB::insert([
|
||||
"insert into", static::$table_for_tags,
|
||||
DB::bracketed_fields([static::$key_for_tags, 'tag']),
|
||||
"values", DB::tuples($tuples)
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
200
web/app/models/UOJBlog.php
Normal file
200
web/app/models/UOJBlog.php
Normal file
@ -0,0 +1,200 @@
|
||||
<?php
|
||||
|
||||
class UOJBlog {
|
||||
use UOJDataTrait;
|
||||
use UOJArticleTrait;
|
||||
|
||||
public static function query($id) {
|
||||
if (!isset($id) || !validateUInt($id)) {
|
||||
return null;
|
||||
}
|
||||
$info = DB::selectFirst([
|
||||
"select id, title, post_time, active_time, poster, zan, is_hidden, type from blogs",
|
||||
"where", ['id' => $id]
|
||||
]);
|
||||
if (!$info) {
|
||||
return null;
|
||||
}
|
||||
return new UOJBlog($info);
|
||||
}
|
||||
|
||||
public function __construct($info) {
|
||||
$this->info = $info;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the blog belongs to the current user blog
|
||||
*/
|
||||
public function belongsToUserBlog() {
|
||||
return UOJContext::type() == 'blog' && UOJUserBlog::id() === $this->info['poster'];
|
||||
}
|
||||
|
||||
public function userCanView(array $user = null) {
|
||||
return !$this->info['is_hidden'] || $this->userCanManage($user);
|
||||
}
|
||||
|
||||
public function userCanManage(array $user = null) {
|
||||
return UOJUserBlog::userCanManage($user, $this->info['poster']);
|
||||
}
|
||||
|
||||
public function isTypeB() {
|
||||
return $this->info['type'] === 'B';
|
||||
}
|
||||
public function isTypeS() {
|
||||
return $this->info['type'] === 'S';
|
||||
}
|
||||
|
||||
public function getTitle(array $cfg = []) {
|
||||
$title = $this->info['title'];
|
||||
return $title;
|
||||
}
|
||||
|
||||
public function getBlogUri($where = '') {
|
||||
return HTML::blog_url($this->info['poster'], "/post/{$this->info['id']}{$where}");
|
||||
}
|
||||
|
||||
public function getSlideUri($where = '') {
|
||||
return HTML::blog_url($this->info['poster'], "/slide/{$this->info['id']}{$where}");
|
||||
}
|
||||
|
||||
public function getUriForWrite() {
|
||||
return $this->isTypeB() ? $this->getBlogUri('/write') : $this->getSlideUri('/write');
|
||||
}
|
||||
|
||||
public function getLink(array $cfg = []) {
|
||||
// title has been escaped by the blog editor
|
||||
$link = '';
|
||||
if (!empty($cfg['show_level'])) {
|
||||
$level_str = $this->getLevelString();
|
||||
if ($level_str !== '') {
|
||||
$link .= "{$level_str} ";
|
||||
}
|
||||
}
|
||||
$link .= '<a href="'. $this->getBlogUri() .'">'.$this->getTitle($cfg).'</a>';
|
||||
if (!empty($cfg['show_new_tag'])) {
|
||||
if ($this->isNew()) {
|
||||
$link .= '<sup style="color:red"> new</sup>';
|
||||
}
|
||||
}
|
||||
return $link;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true if the blog is marked as "new".
|
||||
* Call this function only if info['is_new'] has been filled by the corresponding value in the table important_blogs.
|
||||
*/
|
||||
public function isNew() {
|
||||
return (time() - strtotime($this->info['post_time'])) / 3600 / 24 <= 7;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the string that shows the importance level of this blog.
|
||||
* Call this function only if info['level'] has been filled by the corresponding value in the table important_blogs.
|
||||
*/
|
||||
public function getLevelString() {
|
||||
$level = $this->info['level'];
|
||||
switch ($level) {
|
||||
case 1:
|
||||
return '<span style="color:red">[三级置顶]</span>';
|
||||
case 2:
|
||||
return '<span style="color:red">[二级置顶]</span>';
|
||||
case 3:
|
||||
return '<span style="color:red">[一级置顶]</span>';
|
||||
default: // such as 0
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
public function queryNewestComment() {
|
||||
return DB::selectFirst([
|
||||
"select * from blogs_comments",
|
||||
"where", [
|
||||
'blog_id' => $this->info['id'],
|
||||
'is_hidden' => false
|
||||
],
|
||||
"order by post_time desc",
|
||||
DB::limit(1)
|
||||
]);
|
||||
}
|
||||
|
||||
public function updateActiveTime() {
|
||||
$active_time = $this->info['post_time'];
|
||||
|
||||
$newest = $this->queryNewestComment();
|
||||
if ($newest) {
|
||||
$active_time = $newest['post_time'];
|
||||
}
|
||||
|
||||
DB::update([
|
||||
"update blogs",
|
||||
"set", ['active_time' => $active_time],
|
||||
"where", ['id' => $this->info['id']]
|
||||
]);
|
||||
}
|
||||
|
||||
public static function deleteByID($id) {
|
||||
$id = (int)$id;
|
||||
DB::delete([
|
||||
"delete from click_zans",
|
||||
"where", [
|
||||
'type' => 'B',
|
||||
'target_id' => $id
|
||||
]
|
||||
]);
|
||||
DB::delete([
|
||||
"delete from click_zans",
|
||||
"where", [
|
||||
'type' => 'BC',
|
||||
[
|
||||
"target_id", "in", DB::rawbracket([
|
||||
"select id from blogs_comments",
|
||||
"where", ["blog_id" => $id]
|
||||
])
|
||||
]
|
||||
]
|
||||
]);
|
||||
DB::delete([
|
||||
"delete from blogs",
|
||||
"where", ['id' => $id]
|
||||
]);
|
||||
DB::delete([
|
||||
"delete from blogs_comments",
|
||||
"where", ['blog_id' => $id]
|
||||
]);
|
||||
DB::delete([
|
||||
"delete from important_blogs",
|
||||
"where", ['blog_id' => $id]
|
||||
]);
|
||||
DB::delete([
|
||||
"delete from blogs_tags",
|
||||
"where", ['blog_id' => $id]
|
||||
]);
|
||||
DB::delete([
|
||||
"delete from problems_solutions",
|
||||
"where", ['blog_id' => $id]
|
||||
]);
|
||||
}
|
||||
|
||||
public function delete() {
|
||||
self::deleteByID($this->info['id']);
|
||||
}
|
||||
|
||||
public function echoView(array $cfg = []) {
|
||||
// load tags and content into cache
|
||||
$this->queryContent();
|
||||
$this->queryTags();
|
||||
|
||||
$cfg += [
|
||||
'blog' => $this,
|
||||
'show_title_only' => false,
|
||||
'is_preview' => false
|
||||
];
|
||||
uojIncludeView('blog-preview', $cfg);
|
||||
}
|
||||
}
|
||||
|
||||
UOJBlog::$table_for_content = 'blogs';
|
||||
UOJBlog::$key_for_content = 'id';
|
||||
UOJBlog::$fields_for_content = ['content', 'content_md'];
|
||||
UOJBlog::$table_for_tags = 'blogs_tags';
|
||||
UOJBlog::$key_for_tags = 'blog_id';
|
39
web/app/models/UOJBlogComment.php
Normal file
39
web/app/models/UOJBlogComment.php
Normal file
@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
class UOJBlogComment {
|
||||
use UOJDataTrait;
|
||||
|
||||
public static function query($id) {
|
||||
if (!isset($id) || !validateUInt($id)) {
|
||||
return null;
|
||||
}
|
||||
$info = DB::selectFirst([
|
||||
"select * from blogs_comments",
|
||||
"where", ['id' => $id]
|
||||
]);
|
||||
if (!$info) {
|
||||
return null;
|
||||
}
|
||||
return new UOJBlogComment($info);
|
||||
}
|
||||
|
||||
public function __construct($info) {
|
||||
$this->info = $info;
|
||||
}
|
||||
|
||||
public function hide($reason) {
|
||||
DB::update([
|
||||
"update blogs_comments",
|
||||
"set", [
|
||||
'is_hidden' => ($reason !== ''),
|
||||
'reason_to_hide' => $reason
|
||||
],
|
||||
"where", ['id' => $this->info['id']]
|
||||
]);
|
||||
|
||||
$blog = UOJBlog::query($this->info['blog_id']);
|
||||
if ($blog) {
|
||||
$blog->updateActiveTime($blog);
|
||||
}
|
||||
}
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user