Please Login First!"; exit(1); } if (isset($OJ_LANG)) { require_once("../lang/$OJ_LANG.php"); } require_once ("../include/const.inc.php"); require_once ("../include/problem.php"); ?>
  - Import Problem ...
  - 如果导入失败,请参考 FAQ

"); $j=mb_strpos($Node,""); return mb_substr($Node,$i+$len+2,$j-($i+$len+2)); } function getAttribute($Node, $TagName,$attribute) { return $Node->children()->$TagName->attributes()->$attribute; } function hasProblem($title) { //return false; $md5 = md5($title); $sql = "SELECT 1 FROM problem WHERE md5(title)=?"; $result = pdo_query($sql, $md5); $rows_cnt = count($result); //echo "row->$rows_cnt"; return ($rows_cnt>0); } function mkpta($pid,$prepends,$node) { $language_ext = $GLOBALS['language_ext']; $OJ_DATA = $GLOBALS['OJ_DATA']; foreach ($prepends as $prepend) { $language = $prepend->attributes()->language; $lang = getLang($language); $file_ext = $language_ext[$lang]; $basedir = "$OJ_DATA/$pid"; $file_name = "$basedir/$node.$file_ext"; file_put_contents($file_name,$prepend); } } function get_extension($file) { $info = pathinfo($file); return $info['extension']; } function import_json($json) { global $OJ_DATA,$OJ_SAE,$OJ_REDIS,$OJ_REDISSERVER,$OJ_REDISPORT,$OJ_REDISQNAME,$domain,$DOMAIN; $qduoj_problem=json_decode($json); echo( $qduoj_problem->{'problem'}->{'title'})."
"; $title = $qduoj_problem->{'problem'}->{'title'}; $time_limit = floatval($qduoj_problem->{'problem'}->{'timeLimit'}); $unit = "ms"; //echo $unit; if ($unit=='ms') $time_limit /= 1000; $memory_limit = floatval($qduoj_problem->{'problem'}->{'memoryLimit'}); $unit = "M"; if ($unit=='kb') $memory_limit /= 1024; $description = $qduoj_problem->{'problem'}->{'description'}; $input = $qduoj_problem->{'problem'}->{'input'}; $output = $qduoj_problem->{'problem'}->{'output'}; $sample_input = strip($qduoj_problem->{'problem'}->{'examples'},"input"); $sample_output = strip($qduoj_problem->{'problem'}->{'examples'},"output"); // echo $sample_input."
"; // echo $sample_output; $hint = $qduoj_problem->{'problem'}->{'hint'}; $source = $qduoj_problem->{'problem'}->{'source'}; $spj=0; $pid = addproblem($title, $time_limit, $memory_limit, $description, $input, $output, $sample_input, $sample_output, $hint, $source, $spj, $OJ_DATA); return $pid; } if ($_FILES ["fps"] ["error"] > 0) { echo "  - Error: ".$_FILES ["fps"] ["error"]."File size is too big, change in PHP.ini
"; } else { $tempdir = sys_get_temp_dir()."/import_qduoj"; mkdir($tempdir); $tempfile = $_FILES ["fps"] ["tmp_name"]; if (get_extension( $_FILES ["fps"] ["name"])=="zip") { echo "  - zip file, only QDUOJ exported file is supported"; $resource = zip_open($tempfile); $i = 1; while ($dir_resource = zip_read($resource)) { if (zip_entry_open($resource,$dir_resource)) { $file_name = $path.zip_entry_name($dir_resource); $file_path = substr($file_name,0,strrpos($file_name, "/")); if (!is_dir($file_name)) { $file_size = zip_entry_filesize($dir_resource); $file_content = zip_entry_read($dir_resource,$file_size); if(get_extension($file_name)=="json") { // import_json($file_content); }else{ //echo "$file_name"."
"; mkdir($tempdir."/".dirname($file_name)); file_put_contents($tempdir."/".$file_name,$file_content); } }else{ echo $file_name; } zip_entry_close($dir_resource); } } zip_close($resource); $resource = zip_open($tempfile); $i = 1; while ($dir_resource = zip_read($resource)) { if (zip_entry_open($resource,$dir_resource)) { $file_name = $path.zip_entry_name($dir_resource); $file_path = substr($file_name,0,strrpos($file_name, "/")); if (!is_dir($file_name)) { $file_size = zip_entry_filesize($dir_resource); $file_content = zip_entry_read($dir_resource,$file_size); if(get_extension($file_name)=="json") { $pid=import_json($file_content); $dir=$tempdir."/".basename($file_name,".json"); mkdir("$OJ_DATA/$pid"); system ("mv $dir/* $OJ_DATA/$pid/"); system ("rmdir $dir"); }else{ // echo "$file_name"."
"; // mkdir($tempdir."/".dirname($file_name)); // file_put_contents($tempdir."/".$file_name,$file_content); } }else{ echo $file_name; } zip_entry_close($dir_resource); } } zip_close($resource); unlink ( $_FILES ["fps"] ["tmp_name"] ); system ("rmdir $tempdir"); } else { echo ($tempfile); } } ?>