예제 #1
0
/**
 * Check whether the contest is accessible
 * @param type $cid
 * @return type 
 */
function is_contest_accessible($cid)
{
    if (is_contest_modifiable($cid)) {
        return true;
    }
    // This is a user. Auth to login
    $contest = new ContestsTbl($cid);
    if (!$contest->Get()) {
        return false;
    }
    if (!$contest->detail['avail']) {
        return false;
    }
    if ($contest->detail['course_id'] && !is_course_registered($contest->detail['course_id'])) {
        return false;
    }
    if (is_temporary_user()) {
        return $contest->detail['perm'] == 'temp' && is_contest_registered($cid) && is_contest_auth($cid) && is_contest_started($cid);
    } else {
        return $contest->detail['perm'] == 'user' && is_contest_auth($cid) && is_contest_started($cid);
    }
    return false;
}
예제 #2
0
        } else {
            echo $rs->Fields['sid'] - $min_sid;
        }
        ?>
 </td>
                <td>
                    <?php 
        if ($cid == 0) {
            if ($user_id == get_uid() || is_admins() || is_manager()) {
                echo "<a href=\"../viewsource.php?sid=" . $rs->Fields['sid'] . "\" class=\"black\">";
                echo "<center><img src='../images/source-code.png' alt='view' title='View source code' /></center>";
                echo "</a>";
            }
        } else {
            $timestamp = strtotime($time) - strtotime($contest->detail['starttime']);
            if ($user_id == get_uid() || is_contest_modifiable($cid)) {
                echo "<a href=\"../viewsource.php?cid=" . $cid . "&sid=" . $rs->Fields['sid'] . "\" class=\"black\">";
                echo "<center><img src='../images/source-code.png' alt='view' title='View source code' /></center>";
                echo "</a>";
            }
        }
        ?>

                </td>
                <td>&nbsp;&nbsp;<a href="../user.php?id=<?php 
        echo $user_id;
        ?>
" class="black"><?php 
        echo $username;
        ?>
</a></td>
예제 #3
0
파일: source.php 프로젝트: thezawad/Sicily
/**
 * Submit Source code to server
 * @global type $login_uid
 * @global type $login_username
 * @global type $logged
 * @param type $arg
 * @return mixed if success, return sid. otherwise error message
 */
function submit_source($pid, $cid, $language, $source)
{
    if (!is_logged()) {
        return "Invalid login";
    }
    $pid = intval(trim($pid));
    $source = trim($source);
    if ($cid) {
        $problem = new ContestProblem($cid);
        if (!is_contest_accessible($cid)) {
            return "You can't access to the contest";
        }
        if (is_contest_ended($cid) && !is_contest_modifiable($cid)) {
            return "Contest is finished";
        }
    } else {
        $problem = new ProblemTbl();
    }
    if (!$problem->Get($pid)) {
        return "Invalid Problem ID!";
    }
    $acutal_cid = $problem->detail['cid'];
    if (!$cid && $acutal_cid) {
        // this is a problem automaticly added after the end of contest
        if (!is_contest_accessible($acutal_cid)) {
            return "You can't access to this problem";
        }
        if (!is_contest_modifiable($acutal_cid) && !is_contest_ended($acutal_cid)) {
            return "Contest is not finished. Can't submit to normal problem";
        }
    }
    $sdata = array();
    $sdata["contest"] = $cid;
    if ($language < 1 || $language > 4) {
        return "Invalid language!";
    }
    $sdata['language'] = $language;
    $app_config = get_app_config();
    $codelength = strlen($source);
    if ($codelength > $app_config['max_sourcecode_length']) {
        return "Size of your submittion exceeds limitation.";
    }
    if ($codelength == 0) {
        return "You can't submit an empty source code";
    }
    $sdata['uid'] = get_uid();
    $sdata['time'] = date("Y-m-d H:i:s");
    if ($cid) {
        $sdata['pid'] = $problem->detail['pid'];
        $cpid = $pid;
        $pid = $sdata['pid'];
    } else {
        $sdata['pid'] = $pid;
    }
    $sdata['codelength'] = $codelength;
    $sdata['sourcecode'] = mysql_real_escape_string($source);
    $status = new StatusTbl();
    $status->detail = $sdata;
    $status_id = $status->Add();
    $user = new UserTbl(get_uid());
    $user->Get();
    $user->update['submissions'] = $user->detail['submissions'] + 1;
    $user->Update();
    $problem = new ProblemTbl($pid);
    $problem->Get();
    $problem->update['submissions'] = $problem->detail['submissions'] + 1;
    $problem->Update();
    if ($cid) {
        $con_status = new ContestStatus($cid);
        $con_status->detail = array('cid' => $cid, 'sid' => $status_id, 'cpid' => $cpid);
        $con_status->Add();
    }
    $queue = new QueueTbl();
    $queue->detail['sid'] = $status_id;
    if ($cid) {
        $queue->detail['cid'] = $cid;
        $queue->detail['cpid'] = $cpid;
    }
    $queue->Add();
    return $status_id;
}
예제 #4
0
파일: process.php 프로젝트: thezawad/Sicily
function ExportSource(&$arg)
{
    $cid = safefetch($arg, 'cid');
    $contest = new ContestsTbl($cid);
    $contest->Get() or error('Invalid Contest ID');
    if (!is_contest_modifiable($cid)) {
        error("Permission Denied");
    }
    $contest = $contest->detail;
    $zip = new ZipArchive();
    $filename = tempnam(sys_get_temp_dir(), "cnt") . '.zip';
    if ($zip->open($filename, ZIPARCHIVE::CREATE) !== TRUE) {
        error("cannot Create file <{$filename}>");
    }
    $cpid_hash = get_cpids($cid);
    global $conn;
    $rs = new RecordSet($conn);
    $rs->Query("SELECT * FROM status WHERE contest = '{$cid}'");
    while ($rs->MoveNext()) {
        $ret = $rs->Fields;
        $sid = $ret['sid'];
        $pid = $ret['pid'];
        if (array_key_exists($pid, $cpid_hash)) {
            $pid = $cpid_hash[$pid];
        }
        $uid = $ret['uid'];
        $user = new UserTbl($uid);
        $user->Get();
        $user = $user->detail;
        $src_code = $ret['sourcecode'];
        $status = $ret['status'];
        $lang = $ret['language'];
        $ext_hash = array('C++' => '.cpp', 'C' => '.c', 'Pascal' => '.pas', 'Java' => '.java');
        $ext = $ext_hash[$lang];
        // multiple catalog
        // by pid
        if (!$zip->addFromString('pid/' . $pid . '/' . $sid . $ext, $src_code)) {
            error("Fail to write file for submit [{$sid}]\n");
        }
        // by uid
        if (!$zip->addFromString('uid/' . $user['username'] . '/' . $pid . '_' . $sid . $ext, $src_code)) {
            error("Fail to write file for submit [{$sid}]\n");
        }
    }
    $zip->close();
    output_file($filename, "export_contest{$cid}.zip");
}
예제 #5
0
    <table width="100%" border="0" cellpadding="4" cellspacing="2" class="ui-widget tblcontainer ui-widget-content ui-corner-all">
        <thead>
            <tr align="center" class="ui-widget-header"> 

                <td height=25 width="6%">ID</td>
                <td>Title</td>
                <td width="30%">Schedule</td>
                <td width="8%">Edit Contest</td>
                <td width="8%">Add Problem</td>
            </tr>
        </thead>
        <?php 
$i = 0;
while ($rs->MoveNext()) {
    $id = $rs->Fields["cid"];
    if (!is_contest_modifiable($id)) {
        continue;
    }
    $i++;
    if ($i % 2 == 0) {
        echo "<tr bgcolor=\"#FCFCFC\">\n";
    } else {
        echo "<tr bgcolor=\"#EEEEEE\">\n";
    }
    $time = $rs->Fields["starttime"];
    $title = $rs->Fields["title"];
    $during = $rs->Fields["during"];
    ?>
            <td height=25 align="center"><?php 
    echo $id;
    ?>