diff --git a/scripts/dbforadd2.2.sql b/scripts/dbforadd2.2.sql deleted file mode 100644 index aba6d5ad..00000000 --- a/scripts/dbforadd2.2.sql +++ /dev/null @@ -1,155 +0,0 @@ --- MySQL dump 10.13 Distrib 5.7.44, for Linux (x86_64) --- --- Host: localhost Database: jol --- ------------------------------------------------------ --- Server version 5.7.44 - -use jol; - -DROP TABLE IF EXISTS `all_problem_tag`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8mb4 */; -CREATE TABLE `all_problem_tag` ( - `idx` int(11) NOT NULL AUTO_INCREMENT, - `tag` varchar(255) CHARACTER SET utf8mb4 DEFAULT NULL, - PRIMARY KEY (`idx`) -) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=utf8mb4 ROW_FORMAT=COMPACT; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `all_problem_tag` --- - -LOCK TABLES `all_problem_tag` WRITE; -/*!40000 ALTER TABLE `all_problem_tag` DISABLE KEYS */; -INSERT INTO `all_problem_tag` VALUES (1,'tag1'),(2,'tag2'),(3,'tag3'); -/*!40000 ALTER TABLE `all_problem_tag` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Table structure for table `dailydetails` --- - -DROP TABLE IF EXISTS `dailydetails`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8mb4 */; -CREATE TABLE `dailydetails` ( - `start_time` date NOT NULL, - `end_time` date NOT NULL -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `dailydetails` --- - -LOCK TABLES `dailydetails` WRITE; -/*!40000 ALTER TABLE `dailydetails` DISABLE KEYS */; -INSERT INTO `dailydetails` VALUES ('2023-09-01','2024-02-01'); -/*!40000 ALTER TABLE `dailydetails` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Table structure for table `gpt_code` --- - -DROP TABLE IF EXISTS `gpt_code`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8mb4 */; -CREATE TABLE `gpt_code` ( - `problem_id` int(11) NOT NULL, - `code` text, - `last_update_time` datetime DEFAULT NULL, - PRIMARY KEY (`problem_id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `gpt_code` --- - -LOCK TABLES `gpt_code` WRITE; -/*!40000 ALTER TABLE `gpt_code` DISABLE KEYS */; -INSERT INTO `gpt_code` VALUES (1000,'No gpt now!','2024-02-02 15:41:48'); -/*!40000 ALTER TABLE `gpt_code` ENABLE KEYS */; -UNLOCK TABLES; - --- privilege_distribution添加新的列 -ALTER TABLE `privilege_distribution` -ADD COLUMN `manage_gptcode` tinyint(4) DEFAULT NULL, -ADD COLUMN `manage_tag` tinyint(4) DEFAULT NULL, -ADD COLUMN `set_dailydetails` tinyint(4) DEFAULT NULL; - --- 更新数据 -LOCK TABLES `privilege_distribution` WRITE; -/*!40000 ALTER TABLE `privilege_distribution` DISABLE KEYS */; - -UPDATE `privilege_distribution` -SET `manage_gptcode` = 1, - `manage_tag` = 1, - `set_dailydetails` = 1 -WHERE `group_name` = 'administrator'; - -UPDATE `privilege_distribution` -SET `manage_gptcode` = 0, - `manage_tag` = 0, - `set_dailydetails` = 0 -WHERE `group_name` = 'exam_user'; - -UPDATE `privilege_distribution` -SET `manage_gptcode` = 0, - `manage_tag` = 0, - `set_dailydetails` = 0 -WHERE `group_name` = 'hznu_viewer'; - -UPDATE `privilege_distribution` -SET `manage_gptcode` = 1, - `manage_tag` = 1, - `set_dailydetails` = 1 -WHERE `group_name` = 'root'; - -UPDATE `privilege_distribution` -SET `manage_gptcode` = 0, - `manage_tag` = 0, - `set_dailydetails` = 0 -WHERE `group_name` = 'source_browser'; - -UPDATE `privilege_distribution` -SET `manage_gptcode` = 1, - `manage_tag` = 1, - `set_dailydetails` = 1 -WHERE `group_name` = 'teacher'; - -UPDATE `privilege_distribution` -SET `manage_gptcode` = 0, - `manage_tag` = 0, - `set_dailydetails` = 0 -WHERE `group_name` = 'teacher_assistant'; - -/*!40000 ALTER TABLE `privilege_distribution` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Table structure for table `problem_tag` --- - -DROP TABLE IF EXISTS `problem_tag`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8mb4 */; -CREATE TABLE `problem_tag` ( - `index` int(11) NOT NULL AUTO_INCREMENT, - `problem_id` int(10) unsigned zerofill NOT NULL, - `tag` varchar(100) CHARACTER SET utf8mb4 NOT NULL, - PRIMARY KEY (`index`) -) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=utf8mb4; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `problem_tag` --- - -LOCK TABLES `problem_tag` WRITE; -/*!40000 ALTER TABLE `problem_tag` DISABLE KEYS */; -INSERT INTO `problem_tag` VALUES (1,0000001000,'tag1'); -/*!40000 ALTER TABLE `problem_tag` ENABLE KEYS */; -UNLOCK TABLES; diff --git a/web/OJ/admin/problem_edit.php b/web/OJ/admin/problem_edit.php index bb5669ed..61c62bb7 100644 --- a/web/OJ/admin/problem_edit.php +++ b/web/OJ/admin/problem_edit.php @@ -1,5 +1,4 @@ query($sql); - $row = $result->fetch_object(); - if (!HAS_PRI("edit_" . $row->problemset . "_problem")) { - require_once("error.php"); - exit(0); - } +if(!$add_problem_mod){ + if(isset($_GET['id'])) { + $pid=intval($_GET['id']); + $sql="SELECT * FROM `problem` WHERE `problem_id`=$pid"; + $result=$mysqli->query($sql); + $row=$result->fetch_object(); + if (!HAS_PRI("edit_".$row->problemset."_problem")) { + require_once("error.php"); + exit(0); + } - $sql = "SELECT input, output, show_after FROM problem_samples WHERE problem_id='$pid' ORDER BY sample_id"; - $res = $mysqli->query($sql); - $samples = array(); - while ($r = $res->fetch_array()) { - array_push($samples, array( - "input" => $r['input'], - "output" => $r['output'], - "show_after" => $r['show_after'], - )); + $sql="SELECT input, output, show_after FROM problem_samples WHERE problem_id='$pid' ORDER BY sample_id"; + $res=$mysqli->query($sql); + $samples=array(); + while($r=$res->fetch_array()){ + array_push($samples, array( + "input" => $r['input'], + "output" => $r['output'], + "show_after" => $r['show_after'], + )); + } } - } } ?> - +
remove $path:$success"; - - $path = $OJ_DATA . "/$id/sample" . $i . ".out"; - if (file_exists($path)) $success = unlink($path); - //echo "
remove $path:$success"; - } - if (isset($_POST['add_problem_mod'])) { - $id = addproblem($problemset, $title, $time_limit, $memory_limit, $description, $input, $output, $hint, $author, $source, $spj, $OJ_DATA); - mkdir($OJ_DATA . "/$id"); - } - $sql = "DELETE FROM problem_samples WHERE problem_id=$id"; - $mysqli->query($sql); - if ($sample_inputs) { - foreach ($sample_inputs as $key => $sample_input) { - $sample_input = preg_replace("/(\r\n)/", "\n", $sample_input); - $sample_output = preg_replace("/(\r\n)/", "\n", $sample_outputs[$key]); - if ($sample_input == "" && $sample_output == "") continue; - - //don't auto generate sample files if is SPJ - if (!$spj) { - $fp = fopen($OJ_DATA . "/$id/sample" . $key . ".in", "w"); - fputs($fp, $sample_input); - fclose($fp); - //echo "
create: ".$OJ_DATA."/$id/sample".$key.".in".""; - - $fp = fopen($OJ_DATA . "/$id/sample" . $key . ".out", "w"); - fputs($fp, preg_replace("/(\r\n)/", "\n", $sample_output)); - fclose($fp); - } +if(isset($_POST['problem_id'])){ + require_once("../include/check_post_key.php"); + $id=intval($_POST['problem_id']); + $title=$_POST['title']; + $problemset=$_POST['problemset']; + $time_limit=$_POST['time_limit']; + $memory_limit=$_POST['memory_limit']; + $description=$_POST['description']; + $input=$_POST['input']; + $output=$_POST['output']; + $sample_inputs=$_POST['sample_input']; + $sample_outputs=$_POST['sample_output']; + $sample_show_after=$_POST['show_after']; + // var_dump($sample_inputs); + // var_dump($sample_outputs); + $hint=$_POST['hint']; + $tags = isset($_POST['tags']) ? explode(',', $_POST['tags']) : []; + $xing_tmp = $_POST['xing']; + $ming_tmp = $_POST['ming']; + $xing = $ming = ""; + $strlen = strlen($xing_tmp); + for ($i=0; $i<$strlen; ++$i) { + if ($xing_tmp[$i]==' ' || $xing_tmp[$i]=='\n' || $xing_tmp[$i]=='\t' || $xing_tmp[$i]=='\r') continue; + $xing .= $xing_tmp[$i]; + } + $xing = strtoupper($xing); + $strlen = strlen($ming_tmp); + for ($i=0; $i<$strlen; ++$i) { + if ($ming_tmp[$i]==' ' || $ming_tmp[$i]=='\n' || $ming_tmp[$i]=='\t' || $ming_tmp[$i]=='\r') continue; + $ming .= $ming_tmp[$i]; + } + $ming = ucfirst($ming); + $author = $xing.", ".$ming; + if ($author[0] == ',') $author = ""; + if (strlen($author)>=2 && $author[strlen($author)-2] == ',') $author = substr($author, 0, strlen($author)-2); + $source=$_POST['source']; + $spj=$_POST['spj']; + //remove original samples + $sql="SELECT COUNT(1) FROM problem_samples WHERE problem_id=$id"; + $original_sample_cnt=$mysqli->query($sql)->fetch_array()[0]; + for($i=0 ; $i<$original_sample_cnt ; ++$i){ + $path=$OJ_DATA."/$id/sample".$i.".in"; + if(file_exists($path)) $success=unlink($path); + //echo "
remove $path:$success"; + + $path=$OJ_DATA."/$id/sample".$i.".out"; + if(file_exists($path)) $success=unlink($path); + //echo "
remove $path:$success"; + } + if(isset($_POST['add_problem_mod'])){ + $id=addproblem($problemset, $title, $time_limit, $memory_limit, $description, $input, $output, $hint, $author, $source, $spj, $OJ_DATA ); + mkdir($OJ_DATA."/$id"); + } + $sql="DELETE FROM problem_samples WHERE problem_id=$id"; + $mysqli->query($sql); + if($sample_inputs){ + foreach ($sample_inputs as $key => $sample_input) { + $sample_input=preg_replace("/(\r\n)/","\n",$sample_input); + $sample_output=preg_replace("/(\r\n)/","\n",$sample_outputs[$key]); + if($sample_input=="" && $sample_output=="")continue; + + //don't auto generate sample files if is SPJ + if(!$spj) { + $fp=fopen($OJ_DATA."/$id/sample".$key.".in","w"); + fputs($fp,$sample_input); + fclose($fp); + //echo "
create: ".$OJ_DATA."/$id/sample".$key.".in".""; + + $fp=fopen($OJ_DATA."/$id/sample".$key.".out","w"); + fputs($fp,preg_replace("/(\r\n)/","\n",$sample_output)); + fclose($fp); + } - $sample_input = $mysqli->real_escape_string($sample_input); - $sample_output = $mysqli->real_escape_string($sample_output); - $sql = <<
$sql"; + $mysqli->query($sql); + } } - } - echo "Sample data file Updated!