while ($row = mysql_fetch_array($result)) { $data[] = $row; } } echo json_encode(array($data[0])); exit; } if (isset($_GET["action"])) { if ($_GET["action"] == "register") { action_register(); } if ($_GET["action"] == "login") { action_login(); } if ($_GET["action"] == "logout") { action_logout(); } if ($_GET["action"] == "updatepass") { action_updatepass(); } if ($_GET["action"] == "ajaxrefresh") { echo action_ajaxrefresh(0); mysql_terminate(); exit; } if ($_GET["action"] == "submitcode") { $rid = action_submitcode(); } if ($_GET["action"] == "makeproblem") { action_makeproblem(); }
function action_ajaxrefresh($type) { global $admin, $fullresult, $ajaxlogout; if ($admin["mode"] == "Active" && isset($admin["endtime"])) { $json["ajax-contest-time"] = $admin["endtime"] - time(); } else { $json["ajax-contest-time"] = -1; } $json["ajax-contest-status"] = $admin["mode"]; if ($admin["lastjudge"] >= time() - 30) { $json["ajax-contest-judgement"] = "<a title='The Execution Protocol is active. Submissions will be judged as soon as they are the next in queue.'>Ongoing</a>"; } else { $json["ajax-contest-judgement"] = "<a title='The Execution Protocol is currently not active. Submissions will be judged once it is initiated.'>Waiting</a>"; } if ($_SESSION["tid"] == 0) { $ip = $_SERVER["REMOTE_ADDR"]; $t = mysql_query("SELECT tid FROM teams WHERE (ip1='{$ip}' or ip2='{$ip}' or ip3='{$ip}')"); $json["ajax-mysubmit"] = "<a href='?display=register'>New Team? Click here to Register.</a>"; } else { if ($admin["mode"] == "Lockdown" && $_SESSION["status"] != "Admin") { $json["ajax-mysubmit"] = "<h3>My Submissions</h3><table><tr><td>Not Available</td></tr></table>"; } else { $json["ajax-mysubmit"] = "<h3><a href='?display=submissions&tid={$_SESSION['tid']}'>My Submissions</a></h3>"; $json["ajax-mysubmit"] .= "<table><th title='Run ID'>RID</th><th>Problem</th><th>Language</th><th>Result</th></tr>"; if (isset($admin["mysublist"]) && $admin["mysublist"] >= 0) { $limit = $admin["mysublist"]; } else { $limit = 5; } $data = mysql_query("SELECT * FROM problems,runs WHERE runs.tid='{$_SESSION['tid']}' AND problems.pid=runs.pid AND runs.access!='deleted' AND problems.status='Active' ORDER BY rid DESC LIMIT 0," . $limit); if (is_resource($data)) { while ($temp = mysql_fetch_array($data)) { if ($_SESSION["status"] == "Admin") { $t = mysql_query("SELECT name,code FROM problems WHERE pid={$temp['pid']}"); } else { $t = mysql_query("SELECT name,code FROM problems WHERE pid={$temp['pid']} and status='Active'"); } if (is_resource($t) && mysql_num_rows($t) == 1) { $t = mysql_fetch_array($t); $probname = $t['name']; $probcode = $t['code']; } else { continue; } $result = $temp["result"]; if (isset($fullresult[$result])) { $result = $fullresult[$result]; } if ($temp["language"] == "Brain") { $temp["language"] = "Brainf**k"; } $json["ajax-mysubmit"] .= "<tr class='{$temp['result']}'><td><a href='?display=code&rid={$temp['rid']}' title='Link to Code'>{$temp['rid']}</a></td><td title=\"Link to Problem : {$probname}\"><a href='?display=problem&pid={$temp['pid']}'>{$probcode}</td><td>{$temp['language']}</td><td title='{$result}'>{$temp['result']}</td></tr>"; } } $json["ajax-mysubmit"] .= "</table>"; } } if ($admin["mode"] == "Lockdown" && $_SESSION["status"] != "Admin" || !isset($admin["cache-rankings"])) { $json["ajax-rankings"] = "<h3>Current Rankings</h3><table><tr><td>Not Available</td></tr></table>"; } else { $json["ajax-rankings"] = $admin["cache-rankings"]; } if ($admin["mode"] == "Lockdown" && $_SESSION["status"] != "Admin" || !isset($admin["cache-allsubmit"])) { $json["ajax-allsubmit"] = "<h3>All Submissions</h3><table><tr><td>Not Available</td></tr></table>"; } else { $json["ajax-allsubmit"] = $admin["cache-allsubmit"]; } if (!isset($admin["cache-problems"]) || $admin["cache-problems"] == "") { $admin["cache-problems"] = "<h3>Problems Index</h3><table><tr><td>Not Available</td></tr></table>"; } if ($admin["mode"] == "Lockdown" && $_SESSION["status"] != "Admin") { $json["ajax-problem"] = "<h3>Problems Index</h3><table><tr><td>Not Available</td></tr></table>"; } else { $json["ajax-problem"] = $admin["cache-problems"]; } if ($_SESSION["tid"] != 0) { $tid = $_SESSION["tid"]; $t = mysql_query("SELECT teamname,score FROM teams WHERE tid={$tid}"); if (is_resource($t)) { $t = mysql_fetch_array($t); } $solvedn = mysql_query("SELECT count(distinct(runs.pid)) as n FROM runs,problems WHERE runs.tid='{$tid}' and runs.result='AC' and runs.pid=problems.pid and problems.status='Active'"); if (is_resource($solvedn) && mysql_num_rows($solvedn) == 1) { $solvedn = mysql_fetch_array($solvedn); $solvedn = $solvedn["n"]; } else { $solvedn = 0; } $json["ajax-account"] = "<h3>Team Name : <a href='?display=submissions&tid={$tid}'>{$t['teamname']}</a></h3>"; $json["ajax-account"] .= "<table><tr><th>Score</th><th>Solved</th><th><a href='?display=account'>Account</a></th></tr>"; $json["ajax-account"] .= "<tr><td>{$t['score']}</td><td>{$solvedn}</td><td><a href='?action=logout'>Logout</a></td></table>"; } if ($admin["mode"] == "Lockdown" && $_SESSION["status"] != "Admin" || !isset($admin["cache-clarlatest"])) { $json["ajax-publicclar"] = "<h3><a href='?display=clarifications' title='Link to Clarifications Page'>Public Clarifications</a></h3><table><tr><td>Not Available</td></tr></table>"; } else { $json["ajax-publicclar"] = "<h3><a href='?display=clarifications' title='Link to Clarifications Page'>Public Clarifications</a></h3>" . $admin["cache-clarlatest"]; } if ($_SESSION["tid"] == 0) { $json["ajax-privateclar"] = "<h3><a href='?display=clarifications'>Private Clarifications</a></h3><table><tr><td>Not Available</td></tr></table>"; } else { if (isset($admin["clarprivate"]) && $admin["clarprivate"] >= 0) { $limit = $admin["clarprivate"]; } else { $limit = 2; } $json["ajax-privateclar"] = "<h3><a href='?display=clarifications' title='Link to Clarifications Page'>My Clarifications</a></h3>"; if (($d = mysql_getdata("SELECT * FROM clar WHERE tid={$_SESSION['tid']} and access='Private' ORDER BY time DESC LIMIT 0,{$limit}")) != NULL) { $json["ajax-privateclar"] .= "<table>"; if (count($d) == 0) { $json["ajax-privateclar"] .= "<tr><td>Not Available</td></tr>"; } else { foreach ($d as $c) { if ($c["pid"] == 0) { $probname = "General"; } else { $probname = mysql_getdata("SELECT name FROM problems WHERE status='Active' AND pid={$c['pid']}"); $probname = "<a href='?display=problem&pid={$c['pid']}'>" . $probname[0]["name"] . "</a>"; } $json["ajax-privateclar"] .= "<tr><td style='text-align:left;'><b><a href='?display=submissions&tid={$_SESSION['tid']}'>{$_SESSION['teamname']}</a> ({$probname})</b> : {$c['query']}</td></tr>"; if (!empty($c["reply"])) { $json["ajax-privateclar"] .= "<tr><td style='text-align:left;'><i><b>Judge's Response</b> : {$c['reply']}</i></td></tr>"; } } } $json["ajax-privateclar"] .= "</table>"; } else { $json["ajax-privateclar"] .= "<table><tr><td>Not Available</td></tr></table>"; } } $json["refresh"] = 0; if ($_SESSION["tid"] != 0) { $temp = mysql_query("SELECT status FROM teams WHERE tid={$_SESSION['tid']}"); if (is_resource($temp) && mysql_num_rows($temp) == 1) { $temp = mysql_fetch_array($temp); if ($temp["status"] != "Normal" && $temp["status"] != "Admin") { if (isset($_GET["action"]) && $_GET["action"] == "ajaxrefresh") { action_logout(); } unset($_SESSION["message"][count($_SESSION["message"]) - 1]); $_SESSION["message"][] = "Access Denied : You have been logged out as your account is no longer Active."; $json["refresh"] = 1; } } } if ($type == 0 && $admin["ajaxrr"] == 0) { $json["refresh"] = 1; } if ($ajaxlogout == 1) { $json["refresh"] = 1; } $json["newclar"] = ""; $data = mysql_query("SELECT * FROM clar WHERE (access='Public' or tid=" . $_SESSION["tid"] . ") and access!='Delete' and time>" . $_SESSION["time"]); if (is_resource($data) && mysql_num_rows($data)) { $json["newclar"] = array(); while ($temp = mysql_fetch_array($data)) { if ($temp["pid"] == 0) { $prob = array("name" => "General"); } else { $prob = mysql_fetch_array(mysql_query("SELECT name FROM problems WHERE pid=" . $temp["pid"])); } $team = mysql_fetch_array(mysql_query("SELECT teamname FROM teams WHERE tid=" . $temp["tid"])); $json["newclar"][] = $team["teamname"] . " (" . $prob["name"] . ") : " . unfilter($temp["query"]) . (!empty($temp["reply"]) ? "\nJudge`s Response : " . unfilter($temp["reply"]) : ""); } $json["newclar"] = "Latest Clarification(s)\n\n" . implode($json["newclar"], "\n\n"); } $json["newclar2"] = ""; if ($_SESSION["status"] == "Admin") { $data = mysql_query("SELECT * FROM clar WHERE reply='' and time>" . $_SESSION["time"]); if (is_resource($data) && mysql_num_rows($data)) { $json["newclar2"] = array(); while ($temp = mysql_fetch_array($data)) { if ($temp["pid"] == 0) { $prob = array("name" => "General"); } else { $prob = mysql_fetch_array(mysql_query("SELECT name FROM problems WHERE pid=" . $temp["pid"])); } $team = mysql_fetch_array(mysql_query("SELECT teamname FROM teams WHERE tid=" . $temp["tid"])); $json["newclar2"][] = $team["teamname"] . " (" . $prob["name"] . ") : " . unfilter($temp["query"]); } $json["newclar2"] = "Clarification Request(s)\n\n" . implode($json["newclar2"], "\n\n"); } } $_SESSION["time"] = time(); return json_encode($json); }
function mysql_initiate() { global $mysql_hostname, $mysql_username, $mysql_password, $mysql_database, $admin, $ajaxlogout, $sessionid, $admin_teamname, $admin_password; $link = mysql_connect($mysql_hostname, $mysql_username, $mysql_password); if (!$link) { $_SESSION["message"][] = "SQL Error : Could Not Establish Connection."; return; } if (!mysql_select_db($mysql_database)) { mysql_query("CREATE DATABASE " . $mysql_database); if (!mysql_select_db($mysql_database)) { $_SESSION["message"][] = "SQL Error : Could Not Select Database."; return; } } $data = mysql_list_tables($mysql_database); $table = array(); if (is_resource($data)) { while ($temp = mysql_fetch_row($data)) { $table[] = $temp[0]; } } if (!in_array("teams", $table)) { mysql_query("CREATE TABLE teams (tid int not null primary key auto_increment,teamname tinytext,teamname2 tinytext,pass tinytext,status tinytext,score int,penalty bigint,name1 tinytext,roll1 tinytext,branch1 tinytext,email1 tinytext,phone1 tinytext,name2 tinytext,roll2 tinytext,branch2 tinytext,email2 tinytext,phone2 tinytext,name3 tinytext,roll3 tinytext,branch3 tinytext,email3 tinytext,phone3 tinytext,platform text,ip text,session tinytext,gid int not null)"); } if (!in_array("problems", $table)) { mysql_query("CREATE TABLE problems (pid int not null primary key auto_increment,code tinytext,name tinytext,type tinytext,status tinytext,pgroup tinytext,statement longtext,image blob,imgext tinytext,input longtext,output longtext,timelimit int,score int,languages tinytext,options tinytext)"); } if (!in_array("runs", $table)) { mysql_query("CREATE TABLE runs (rid int not null primary key auto_increment,pid int,tid int,language tinytext,name tinytext,code longtext,time tinytext,result tinytext,error text,access tinytext,submittime int,output longtext)"); } if (!in_array("admin", $table)) { mysql_query("CREATE TABLE admin (variable tinytext,value longtext)"); } if (!in_array("logs", $table)) { mysql_query("CREATE TABLE logs (time int not null primary key,ip tinytext,tid int,request tinytext)"); } if (!in_array("clar", $table)) { mysql_query("CREATE TABLE clar (time int not null primary key,tid int,pid int,query text,reply text,access tinytext,createtime int)"); } if (!in_array("groups", $table)) { mysql_query("CREATE TABLE groups (gid int not null primary key auto_increment, groupname tinytext, statusx int)"); } // If empty tables $temp = mysql_query("SELECT * FROM teams"); if (is_resource($temp) && mysql_num_rows($temp) == 0) { mysql_query("INSERT INTO teams (teamname,pass,status,score,name1,roll1,branch1,email1,phone1) VALUES ('" . $admin_teamname . "','" . _md5($admin_password) . "','Admin',0,'Kaustubh Karkare','','','*****@*****.**','')"); mysql_query("INSERT INTO teams (teamname,pass,status,score,name1,roll1,branch1,email1,phone1) VALUES ('ACM','" . _md5($admin_password) . "','Admin',0,'ACM Team','','','','')"); ### } $temp = mysql_query("SELECT * FROM problems"); if (is_resource($temp) && mysql_num_rows($temp) == 0) { mysql_query("INSERT INTO problems (pid,code,name,type,status,pgroup,statement,input,output,timelimit,score,languages) VALUES (1,'TEST','Squares','Ad-Hoc','Active','#00 Test','" . addslashes(file_get('data/example/problem.txt')) . "','" . addslashes(file_get('data/example/input.txt')) . "','" . addslashes(file_get('data/example/output.txt')) . "',1,0,'Brain,C,C++,C#,Java,JavaScript,Pascal,Perl,PHP,Python,Ruby,Text')"); } $temp = mysql_query("SELECT * FROM runs"); if (is_resource($temp) && mysql_num_rows($temp) == 0) { mysql_query("INSERT INTO runs (rid,pid,tid,language,name,code,time,result,access) VALUES (1,1,1,'C','code','" . addslashes(file_get('data/example/code.c')) . "',NULL,NULL,'public')"); mysql_query("INSERT INTO runs (rid,pid,tid,language,name,code,time,result,access) VALUES (2,1,1,'C++','code','" . addslashes(file_get('data/example/code.cpp')) . "',NULL,NULL,'public')"); mysql_query("INSERT INTO runs (rid,pid,tid,language,name,code,time,result,access) VALUES (3,1,1,'C#','code','" . addslashes(file_get('data/example/code.cs')) . "',NULL,NULL,'public')"); mysql_query("INSERT INTO runs (rid,pid,tid,language,name,code,time,result,access) VALUES (4,1,1,'Java','code','" . addslashes(file_get('data/example/code.java')) . "',NULL,NULL,'public')"); mysql_query("INSERT INTO runs (rid,pid,tid,language,name,code,time,result,access) VALUES (5,1,1,'JavaScript','code','" . addslashes(file_get('data/example/code.js')) . "',NULL,NULL,'public')"); mysql_query("INSERT INTO runs (rid,pid,tid,language,name,code,time,result,access) VALUES (6,1,1,'Pascal','code','" . addslashes(file_get('data/example/code.pas')) . "',NULL,NULL,'public')"); mysql_query("INSERT INTO runs (rid,pid,tid,language,name,code,time,result,access) VALUES (7,1,1,'Perl','code','" . addslashes(file_get('data/example/code.pl')) . "',NULL,NULL,'public')"); mysql_query("INSERT INTO runs (rid,pid,tid,language,name,code,time,result,access) VALUES (8,1,1,'PHP','code','" . addslashes(file_get('data/example/code.php')) . "',NULL,NULL,'public')"); mysql_query("INSERT INTO runs (rid,pid,tid,language,name,code,time,result,access) VALUES (9,1,1,'Python','code','" . addslashes(file_get('data/example/code.py')) . "',NULL,NULL,'public')"); mysql_query("INSERT INTO runs (rid,pid,tid,language,name,code,time,result,access) VALUES (10,1,1,'Ruby','code','" . addslashes(file_get('data/example/code.rb')) . "',NULL,NULL,'public')"); } $temp = mysql_query("SELECT * FROM admin"); if (is_resource($temp) && mysql_num_rows($temp) == 0) { mysql_query("INSERT INTO admin VALUES ('mode','Passive');"); mysql_query("INSERT INTO admin VALUES ('lastjudge','0');"); mysql_query("INSERT INTO admin VALUES ('ajaxrr','0');"); mysql_query("INSERT INTO admin VALUES ('mode','Passive');"); mysql_query("INSERT INTO admin VALUES ('penalty','20');"); mysql_query("INSERT INTO admin VALUES ('mysublist','5');"); mysql_query("INSERT INTO admin VALUES ('allsublist','10');"); mysql_query("INSERT INTO admin VALUES ('ranklist','10');"); mysql_query("INSERT INTO admin VALUES ('clarpublic','2');"); mysql_query("INSERT INTO admin VALUES ('clarprivate','2');"); mysql_query("INSERT INTO admin VALUES ('regautoauth','1');"); mysql_query("INSERT INTO admin VALUES ('multilogin','0');"); mysql_query("INSERT INTO admin VALUES ('clarpage','10');"); mysql_query("INSERT INTO admin VALUES ('substatpage','25');"); mysql_query("INSERT INTO admin VALUES ('probpage','25');"); mysql_query("INSERT INTO admin VALUES ('teampage','25');"); mysql_query("INSERT INTO admin VALUES ('rankpage','25');"); mysql_query("INSERT INTO admin VALUES ('logpage','100');"); mysql_query("INSERT INTO admin VALUES ('notice','Announcements\nWelcome to the Aurora Online Judge.');"); } // Other Inits $data = mysql_query("SELECT * FROM admin"); if (is_resource($data)) { while ($temp = mysql_fetch_array($data)) { if (!in_array($temp["variable"], array("scoreboard"))) { $admin[$temp["variable"]] = $temp["value"]; } } } if ($admin["mode"] == "Active" && time() >= $admin["endtime"]) { $admin["mode"] = "Disabled"; } if ($admin["mode"] == "Lockdown" && $_SESSION["tid"] != 0 && $_SESSION["status"] != "Admin") { $_SESSION["message"][] = "Access Denied : You have been logged out as the contest has been locked down. Please try again again."; action_logout(); $ajaxlogout = 1; } if (!$admin["multilogin"] && $_SESSION["tid"] && $_SESSION["status"] != "Admin") { $sess = mysql_query("SELECT session FROM teams WHERE tid=" . $_SESSION["tid"]); $sess = mysql_fetch_array($sess); $sess = $sess["session"]; if ($sess != $sessionid) { $_SESSION["message"][] = "Multiple Login Not Allowed."; action_logout(); $ajaxlogout = 1; } } if (1 || !isset($admin["adminwork"]) || $admin["adminwork"] < time()) { action_adminwork(); $admin["adminwork"] = time() + 10; } return 0; // Success }