Beispiel #1
0
function ShareCode(&$arg, $enable = 1)
{
    $sid = safefetch($arg, 'sid', "Fail");
    global $login_uid;
    if ($login_uid == -1) {
        Fail("Must login first");
    }
    $status = new StatusTbl($sid);
    if (!$status->Get()) {
        Fail("No such code");
    }
    if ($login_uid != $status->detail["uid"]) {
        Fail("You are not the owner of the code");
    }
    $status->update["public"] = $enable;
    $status->Update();
    $status->FreeResource();
}
Beispiel #2
0
/**
 * Get the source code with in a status(backward compatibility)
 * @global type $app_config
 * @param type $sid
 * @param type $lang
 * @return type 
 */
function getSource($sid, $lang = null)
{
    $status = new StatusTbl($sid);
    if ($status->Get() && !empty($status->detail['sourcecode'])) {
        return $status->detail['sourcecode'];
    }
    global $app_config;
    $path = sprintf($app_config["source_path"] . "/%03d/%06d", $sid / 1000, $sid);
    $exts = array('C' => '.c', 'C++' => '.cpp', 'Pascal' => '.pas', 'Java' => '.java');
    if ($lang == null) {
        foreach ($exts as $value) {
            if (file_exists($path . $value)) {
                $path .= $value;
                break;
            }
        }
    } else {
        $path .= $exts[$lang];
    }
    return file_get_contents($path);
}
Beispiel #3
0
<?php 
global $app_config;
$sid = $_GET['sid'];
if (isset($_GET['cid'])) {
    $cid = $_GET['cid'];
} else {
    $cid = "";
}
if ($cid) {
    $problem = new ContestStatus($cid);
    $problem->Get($sid);
    $sid = $problem->detail['sid'];
}
$status = new StatusTbl();
if (!$status->Get($sid)) {
    error("No such submission!");
}
$content = $status->detail['compilelog'];
$content = ereg_replace("[0-9a-zA-Z]*/", "", $content);
?>

<div style="background-image: url(images/bg2.gif); padding: 15px;">

    <table width="100%">
        <tr><td>
                <pre><?php 
echo $content;
?>
</pre>
            </td></tr>
Beispiel #4
0
/**
 * Export a single problem to a temporay file. 
 * @global type $app_config
 * @global array $img_list
 * @global type $img_count
 * @param type $pid
 * @return string the path of the temporay archive file
 */
function ExportProblem2File($pid)
{
    global $app_config;
    global $img_list;
    $img_list = array();
    $problem = new ProblemTbl($pid);
    if (!$problem->Get()) {
        error("Invalid problem ID");
    }
    $zip = new ZipArchive();
    $filename = tempnam(sys_get_temp_dir(), "prob") . '.zip';
    if ($zip->open($filename, ZIPARCHIVE::CREATE) !== TRUE) {
        error("cannot Create file <{$filename}>");
    }
    $problem_prefix = $app_config['testdata_path'] . $pid . "/";
    $indexpath = $problem_prefix . '.DIR';
    if (!$zip->addFile($indexpath, basename($indexpath))) {
        error("Error adding index file to archive");
    }
    if ($problem->detail['special_judge']) {
        $spj_filename = $problem_prefix . $pid . '_spj.cpp';
        if (file_exists($spj_filename)) {
            if (!$zip->addFile($spj_filename, basename($spj_filename))) {
                error('Error adding special judge source file');
            }
        }
        $spj_exename = $problem_prefix . "spjudge";
        if (!file_exists($spj_exename)) {
            error("missing spjudge");
        }
        if (!$zip->addFile($spj_exename, basename($spj_exename))) {
            error('Error adding special judge binary file');
        }
    }
    if ($problem->detail['has_framework']) {
        $framework_filename = "{$problem_prefix}" . "framework.cpp";
        if (!file_exists($framework_filename)) {
            error("missing framework.cpp");
        }
        if (!$zip->addFile($framework_filename, basename($framework_filename))) {
            error('Error adding framework source file');
        }
    }
    if (!file_exists($indexpath)) {
        error("Index file is missing");
    }
    $handle = fopen($indexpath, "r");
    while (!feof($handle)) {
        $line = trim(fgets($handle));
        $paths = explode(" ", $line);
        if (count($paths) < 2) {
            continue;
        }
        $input_path = $problem_prefix . $paths[0];
        $output_path = $problem_prefix . $paths[1];
        if (!file_exists($input_path)) {
            error("File [{$input_path}] is missing");
        }
        if (!$zip->addFile($input_path, basename($input_path))) {
            error("Error adding file [{$input_path}]");
        }
        if (!file_exists($output_path)) {
            error("File [{$output_path}] is missing");
        }
        if (!$zip->addFile($output_path, basename($output_path))) {
            error("Error adding file [{$output_path}]");
        }
    }
    fclose($handle);
    global $img_count;
    $extract_key = array('description', 'input', 'output', 'hint');
    foreach ($extract_key as $value) {
        $problem->detail[$value] = ExtractImage($problem->detail[$value]);
    }
    $export_problem = $problem->detail;
    // clean up all the number keys
    for ($i = 0; array_key_exists($i, $export_problem); ++$i) {
        unset($export_problem[$i]);
    }
    if (!$zip->addFromString('metadata.json', json_encode($export_problem))) {
        error("Error writing meta data file");
    }
    foreach ($img_list as $img_path) {
        if (!$zip->addFile($img_path, basename($img_path))) {
            error("Error adding image [{$img_path}]");
        }
    }
    // add standard problem source code into archive for later use
    if ($problem->detail['stdsid']) {
        $status = new StatusTbl($problem->detail['stdsid']);
        $status->Get();
        $lang = $status->detail['language'];
        $src = $status->detail['sourcecode'];
        $ext_hash = array('C++' => '.cpp', 'C' => '.c', 'Pascal' => '.pas', 'Java' => '.java');
        $ext = $ext_hash[$lang];
        if (!$zip->addFromString('standard' . $ext, $src)) {
            error("Error writing standard source code");
        }
    }
    if (!$zip->close()) {
        error("Compressing error");
    }
    return $filename;
}