error("Course not found"); } $course = $courseTbl->detail; if (!is_course_modifiable($course_id)) { error("No permission"); } $p = tryget("p", 1); $rs = new RecordSet($conn); $query_str = "SELECT cid, title, information FROM contests WHERE avail = 1 AND course_id = {$course_id} "; $count_str = "SELECT count(*) FROM contests WHERE avail = 1 AND course_id = {$course_id} "; $reglist = array(); $regTbl = new CourseRegTbl($course_id); if ($regTbl->Get()) { do { $uid = intval($regTbl->detail['uid']); $user = new UserTbl($regTbl->detail['uid']); $user->Get(); $reglist[] = $user->detail; } while ($regTbl->MoreRows()); } $rs->nPageSize = 20; $rs->PageCount($count_str); $rs->SetPage($p); $query_str .= "ORDER BY cid DESC"; $rs->dpQuery($query_str); $now = time(); ?> <div class="blue_anchor"> <fieldset> <legend>
echo _("Submit Time"); ?> </b></td> </tr> </thead> <?php global $conn; $rs = new RecordSet($conn); $rs->query("SELECT * FROM status WHERE sid={$problem['stdsid']}"); if ($rs->MoveNext()) { $user_id = $rs->Fields["uid"]; global $login_uid; if ($user_id == $login_uid) { $username = $login_username; } else { $user = new UserTbl($user_id); if ($user->Get()) { $username = $user->detail['username']; } else { $username = '******'; } } $problem_id = $rs->Fields["pid"]; $language = $rs->Fields["language"]; $status = $rs->Fields["status"]; $run_time = $rs->Fields["run_time"]; $run_memory = $rs->Fields["run_memory"]; $failcase = $rs->Fields["failcase"]; $codelength = $rs->Fields["codelength"]; if ($run_time == NULL) { $run_time = _("N/A");
/** * Check whether the profile info is complete for the registering courses * @global type $login_uid * @global type $logged * @return type */ function is_info_complete() { if (is_admins() || is_manager()) { return true; } global $login_uid; global $logged; if (!$logged) { return false; } $userTbl = new UserTbl($login_uid); if (!$userTbl->Get()) { return false; } $user = $userTbl->detail; return trim($user['cn_name']) && is_chinese($user['cn_name']) && trim($user['major']) && trim($user['grade']) && is_grade_valid($user['grade']) && trim($user['class']) && trim($user['student_id']) && is_student_id_valid($user['student_id']); }
function GetEmail(&$arg) { $username = safefetch($arg, "username", "Fail"); if (empty($username)) { Fail("Username can't be null"); } $user = new UserTbl(); if (!$user->GetByField("username", $username)) { Fail("Invalid username"); } Output("email", $user->detail["email"]); }
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"); }
/** * 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; }
public function isExistedTest() { $userTbl = new UserTbl(); $next_name = "Adds not exist email isExisted() -> UserTbl"; $next_in = "*****@*****.**"; $next_expResult = false; $next_actResult = $userTbl->isExisted($next_in); echo $this->unit->run($next_expResult, $next_actResult, $next_name); $ext_name = "Adds exist email isExisted() -> UserTbl"; $ext_in = "*****@*****.**"; $ext_expResult = true; $ext_actResult = $userTbl->isExisted($ext_in); echo $this->unit->run($ext_expResult, $ext_actResult, $ext_name); }
} echo "<td>"; if ($preview != "on") { $storage = array(); $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 {
<?php include_once "../inc/global.inc.php"; include_once "auth.inc.php"; global $conn; $id = $_GET["id"]; if ($id == "") { error("Invalid user ID!", "ranklist.php"); } $user = new UserTbl(); if (!$user->Get($id)) { error("Invalid user ID!", "ranklist.php"); } $solved = $user->detail['solved']; $submissions = $user->detail['submissions']; $rs = new RecordSet($conn); $rs->Query("SELECT count(*) FROM user WHERE solved > '{$solved}' OR (solved = '{$solved}' AND submissions < '{$submissions}') OR (solved = '{$solved}' AND submissions = '{$submissions}' AND uid < '{$id}')"); $rank = $rs->Fields[0] + 1; /* @mysql_connect($host, $user, $password) or die("Unable to connect database!"); mysql_select_db($database); $table = "user"; $query = "SELECT * FROM $table WHERE id = '$id'"; $result = mysql_query($query); if (mysql_num_rows($result) == 0) error("Invalid user ID!", "ranklist.php"); $row = mysql_fetch_array($result); $id = $row["id"]; $username = $row["username"]; $email = $row["email"]; $address = $row["address"]; $solved = $row["solved"];
<?php require "./navigation.php"; $cid = @$_GET["cid"]; if (isset($login_uid)) { $user = new UserTbl(); $user->Get($login_uid); $list = $user->detail['list']; } $rs = new RecordSet($conn); $rs->nPageSize = 20; if ($cid) { $contest = new ContestsTbl(); if ($contest->Get($cid) < 0) { error("No such contest ID"); } if (!is_admins()) { $now = time(); if ($now < strtotime($contest->detail['starttime'])) { error("The contest is not started"); } } $rs->PageCount("SELECT count(*) FROM contest_problems"); $rs->SetPage($p); $rs->dpQuery("SELECT pid, title, accepted, submissions, avail FROM contest_problems WHERE cid='{$cid}'"); } else { $rs->PageCount("SELECT count(*) FROM problems"); $rs->SetPage($p); $rs->dpQuery("SELECT pid, title, accepted, submissions, avail FROM problems"); } ?>
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; }