コード例 #1
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;
}
コード例 #2
0
ファイル: import_user.php プロジェクト: thezawad/Sicily
     $storage = $user->detail;
     // get existing id
     if (!$user->GetByField('username', $user->detail['username'])) {
         $user->detail['perm'] = $perm;
         $user->detail["reg_time"] = date("Y.m.d G:i:s");
         $user->detail['password'] = md5($user->detail['password']);
         $id = $user->Add();
         echo "New ID {$id}";
     } else {
         $id = $user->detail['uid'];
         echo "User {$id} ";
         $olduser = new UserTbl($id);
         $olduser->update = $storage;
         $olduser->update['perm'] = $perm;
         $olduser->update['password'] = md5($storage['password']);
         $olduser->Update();
     }
     $reg = new ContestRegistrationTbl();
     if (!$reg->GetByFields(array("uid" => $id, "cid" => $cid))) {
         $reg->detail['uid'] = $id;
         $reg->detail['cid'] = $cid;
         $reg->Add();
         echo " Added";
     } else {
         echo " Already imported";
     }
 } else {
     if ($user->GetByField('username', $user->detail['username'])) {
         echo "Exists";
     } else {
         echo "Ok";
コード例 #3
0
ファイル: process.php プロジェクト: thezawad/Sicily
function ResetPassword(&$arg)
{
    $uid = $arg['uid'];
    if (!$uid) {
        MsgAndBack("No such user");
    }
    $user = new UserTbl();
    if (!$user->Get($uid)) {
        MsgAndBack("No such user");
    }
    $newpass = rand();
    $md5pass = md5($newpass);
    $user->update['password'] = $md5pass;
    if ($user->Update($uid)) {
        echo "Reset successful, the new password is " . $newpass;
    } else {
        MsgAndBack("fail to reset password");
    }
}
コード例 #4
0
ファイル: permission.php プロジェクト: thezawad/Sicily
function getAuthcode($uid)
{
    $authcode = "";
    for ($i = 0; $i < 10; ++$i) {
        $authcode .= rand(0, 9);
    }
    $user = new UserTbl($uid);
    if (!$user->Get()) {
        return null;
    }
    $user->update["authcode"] = $authcode;
    $user->update["authtime"] = time();
    if (!$user->Update()) {
        return null;
    }
    return $authcode;
}