Example #1
0
function edit_problem()
{
    if (!isset($_POST['title'], $_POST['test-editormd-markdown-doc'], $_POST['time_limit'], $_POST['memory_limit'], $_POST['tag'])) {
        return False;
    }
    if (!$_POST['title'] || !$_POST['test-editormd-markdown-doc'] || !is_numeric($_POST['time_limit']) || !is_numeric($_POST['memory_limit'])) {
        $_SESSION['admin_publish_tmp'] = $_POST;
        $_SESSION['admin_publish_tmp']['description'] = $_POST['test-editormd-markdown-doc'];
        $_SESSION['admin_publish_tmp']['error'] = '未定义的操作。';
        return False;
    }
    $extra = '';
    $prob = get_problem(1);
    $hash = $prob['hash'];
    $ver = (int) $prob['ver'];
    $datacount = 0;
    while (isset($_FILES["stdout{$datacount}"], $_FILES["input{$datacount}"]) && !$_FILES["stdout{$datacount}"]['error'] && !$_FILES["input{$datacount}"]['error']) {
        $datacount++;
    }
    if ($datacount) {
        $floder = dirname(__FILE__) . '/../mo-content/data/' . $hash;
        if (file_exists($floder) && ($handle = opendir($floder))) {
            while (($item = readdir($handle)) != False) {
                if (!is_dir("{$floder}/{$item}")) {
                    unlink("{$floder}/{$item}");
                }
            }
            closedir($handle);
        } else {
            mkdir($floder, 0777, true);
        }
        for ($i = 0; $i < $datacount; $i++) {
            move_uploaded_file($_FILES["stdout{$i}"]['tmp_name'], $floder . "/std{$i}.out");
            move_uploaded_file($_FILES["input{$i}"]['tmp_name'], $floder . "/test{$i}.in");
        }
        $ver++;
    } else {
        $datacount = $prob['test_turn'];
    }
    $sql = 'UPDATE `mo_judge_problem` SET `title` = ?, `description` = ?, `tag` = ?, `extra` = ?, `ver` = ?, `time_limit` = ?, ' . '`memory_limit` = ?, `test_turn` = ? WHERE `mo_judge_problem`.`id` = ?';
    global $db;
    $db->prepare($sql);
    $db->bind('ssssiiiii', $_POST['title'], $_POST['test-editormd-markdown-doc'], $_POST['tag'], serialize($extra), $ver, $_POST['time_limit'], $_POST['memory_limit'], $datacount, $_POST['edit_id']);
    $db->execute();
    return $_POST['edit_id'];
}
Example #2
0
<link href="//cdn.bootcss.com/formvalidation/0.6.1/css/formValidation.css" rel="stylesheet">
<script src="//cdn.bootcss.com/formvalidation/0.6.1/js/formValidation.min.js"></script>
<script src="//cdn.bootcss.com/formvalidation/0.6.1/js/framework/bootstrap.min.js"></script>
<script src="inc/bootstrap.file-input.js"></script>
<script>
	$().ready(function() {
		filePrint();
	});
</script>';
require_once 'header.php';
if (!isset($_GET['action'])) {
    $error = '未定义的操作。';
} else {
    switch ($_GET['action']) {
        case 'edit':
            if (!isset($_GET['pid']) || !($pv_info = get_problem($_GET['pid']))) {
                $error = '未定义的操作。';
                break;
            }
        case 'add':
            if (isset($_SESSION['admin_publish_tmp'])) {
                $pv_info = $_SESSION['admin_publish_tmp'];
                if (isset($_SESSION['admin_publish_tmp']['error'])) {
                    $error = $_SESSION['admin_publish_tmp']['error'];
                }
                unset($_SESSION['admin_publish_tmp']);
            }
            $error = False;
            break;
        default:
            $error = '未定义的操作。';
Example #3
0
    }
    return $ac_langs;
}
/*-----------------------------------------------------------------------------*/
require 'database.php';
// Markdown parser
require 'lib/Parsedown.php';
// the PlatesPHP template engine
require 'lib/vendor/autoload.php';
$title = "Problem Statement";
// check if the user is logged in
$user_logged_in = isset($_COOKIE['username']);
// requested problem_id, if does not exist, 404
$problem_id = isset($_GET['problem']) ? $_GET['problem'] : "404";
// array with problem info if the problem_id is correct
$problem_data = get_problem($problem_id, $dbc);
// parse the markdown of the problem statement into html
if (isset($problem_data['problem_text'])) {
    $Parsedown = new Parsedown();
    $problem_data['problem_text'] = $Parsedown->text($problem_data['problem_text']);
}
// 2D array of users previous submits for the problem
$previous_submits = isset($_COOKIE['username']) ? get_submits($_COOKIE['username'], $problem_id, $dbc) : array();
// list of languages for the submissions
$languages = array(array("Detect the language", ""), array("C++", ".cpp"), array("C", ".c"), array("Pascal", ".pas"), array("Java 7", ".java"), array("Python 3", ".py"));
// check in what languages did the user solve this problem
$accepted_langs = check_ac_langs($previous_submits, $languages);
$data = array('title' => $title, 'user_logged_in' => $user_logged_in, 'problem_data' => $problem_data, 'submits' => $previous_submits, 'languages' => $languages, 'accepted' => $accepted_langs, 'problem' => $problem_id);
// render the webpage
$templates = new League\Plates\Engine('templates');
echo $templates->render('problem', $data);