Exemple #1
0
function ExportContest(&$arg)
{
    $cid = safefetch($arg, 'cid');
    $contest = new ContestsTbl($cid);
    $contest->Get() or error("Invalid cid");
    $contest = $contest->detail;
    $zip = new ZipArchive();
    $filename = tempnam(sys_get_temp_dir(), "export_contest") . '.zip';
    if (!$zip->open($filename, ZIPARCHIVE::CREATE)) {
        error("Error creating archive file");
    }
    $cpids = get_cpids($cid);
    $problem_files = array();
    foreach ($cpids as $pid => $cpid) {
        $file_path = ExportProblem2File($pid);
        if (!$zip->addFile($file_path, "{$cpid}.zip")) {
            error("Error adding file [{$cpid}.zip]");
        }
        $problem_files[] = $file_path;
    }
    if (!$zip->addFromString('metadata.json', json_encode(array_values($cpids)))) {
        error("Error writing meta data");
    }
    if (!$zip->addFromString('.SET', date(DATE_W3C))) {
        error("Error writing .SET file");
    }
    if (!$zip->close()) {
        error("Error compressing");
    }
    foreach ($problem_files as $file_path) {
        unlink($file_path);
    }
    output_file($filename, "{$cid} - {$contest['title']}.zip");
}
Exemple #2
0
/**
 * Get a pid list for a particular contest
 * @param type $cid contest id
 * @return array pid list
 */
function get_pids($cid)
{
    $cpids = get_cpids($cid);
    return array_keys($cpids);
}