aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpzread <netfirewall@gmail.com>2012-12-09 15:46:19 +0800
committerpzread <netfirewall@gmail.com>2012-12-09 15:46:19 +0800
commit1eb32c90ffc524b7d56eb0c64386c366848854b8 (patch)
tree1734e74e00d9ea4ff868dd071a8e9ac638351838
parenteb4b34b75c356247506be0251bb1b7963f605c48 (diff)
downloadtaiwan-online-judge-1eb32c90ffc524b7d56eb0c64386c366848854b8.tar
taiwan-online-judge-1eb32c90ffc524b7d56eb0c64386c366848854b8.tar.gz
taiwan-online-judge-1eb32c90ffc524b7d56eb0c64386c366848854b8.tar.bz2
taiwan-online-judge-1eb32c90ffc524b7d56eb0c64386c366848854b8.tar.lz
taiwan-online-judge-1eb32c90ffc524b7d56eb0c64386c366848854b8.tar.xz
taiwan-online-judge-1eb32c90ffc524b7d56eb0c64386c366848854b8.tar.zst
taiwan-online-judge-1eb32c90ffc524b7d56eb0c64386c366848854b8.zip
ExpOJ web code
-rw-r--r--web/common.php16
-rw-r--r--web/data.js39
-rw-r--r--web/data_update.php81
-rw-r--r--web/index.html810
-rw-r--r--web/nor.css112
-rw-r--r--web/nor.js111
-rw-r--r--web/page.css6
-rw-r--r--web/page.js91
-rw-r--r--web/page_problem.css164
-rw-r--r--web/page_problem.js525
-rw-r--r--web/page_square.css167
-rw-r--r--web/page_square.js840
-rw-r--r--web/page_status.css110
-rw-r--r--web/page_status.js497
-rw-r--r--web/page_user.css123
-rw-r--r--web/page_user.js305
-rw-r--r--web/problem_code_submit.php66
-rw-r--r--web/problem_view.php41
-rw-r--r--web/square_list.php81
-rw-r--r--web/square_problem_list.php63
-rw-r--r--web/square_rank_list.php115
-rw-r--r--web/square_scoreboard_list.php115
-rw-r--r--web/square_set.php0
-rw-r--r--web/status_submit_list.php147
-rw-r--r--web/status_viewcode.php30
-rw-r--r--web/user_get.php65
-rw-r--r--web/user_login.php32
-rw-r--r--web/user_register.php41
-rw-r--r--web/user_set.php109
-rw-r--r--web/viewcode.html54
30 files changed, 4956 insertions, 0 deletions
diff --git a/web/common.php b/web/common.php
new file mode 100644
index 0000000..9fd34f8
--- /dev/null
+++ b/web/common.php
@@ -0,0 +1,16 @@
+<?php
+
+define('DB_NAME','expoj');
+define('DB_USER','expoj');
+define('DB_PASSWORD','');
+define('SEC_SALT','xxxxx');
+
+function sec_checkuser($userid,$usersec){
+ if($userid == '' || $usersec == '' || strval(intval($userid)) != $userid || hash('sha512',$userid.SEC_SALT) != $usersec){
+ return false;
+ }
+
+ return true;
+}
+
+?>
diff --git a/web/data.js b/web/data.js
new file mode 100644
index 0000000..874ce80
--- /dev/null
+++ b/web/data.js
@@ -0,0 +1,39 @@
+var data_callback;
+var data_paramo;
+var data_ajaxupdate;
+
+function data_init(){
+ data_callback = $.Callbacks();
+
+ data_paramo = new Object();
+ data_paramo.laststamp = '_';
+
+ data_ajaxupdate = null;
+}
+function data_update(force){
+ if(data_ajaxupdate != null){
+ data_ajaxupdate.abort();
+ }
+ if(force){
+ data_paramo.laststamp = '_';
+ }
+
+ data_ajaxupdate = $.post('data_update.php',
+ {'param':JSON.stringify(data_paramo)},
+ function(res){
+ var reto;
+
+ if(res == 'Esame'){
+ data_update();
+ }else if(res[0] != 'E'){
+ reto = JSON.parse(res);
+ data_paramo.laststamp = reto.laststamp;
+
+ data_callback.fire(reto);
+
+ data_ajaxupdate = null;
+ data_update(false);
+ }
+ }
+ );
+}
diff --git a/web/data_update.php b/web/data_update.php
new file mode 100644
index 0000000..b7bf9d2
--- /dev/null
+++ b/web/data_update.php
@@ -0,0 +1,81 @@
+<?php
+require_once('common.php');
+require_once('status_submit_list.php');
+require_once('square_list.php');
+require_once('square_rank_list.php');
+require_once('square_problem_list.php');
+require_once('square_scoreboard_list.php');
+require_once('problem_view.php');
+
+set_time_limit(0);
+
+$paramo = json_decode($_POST['param']);
+if($paramo == null){
+ exit('Eerror');
+}
+$laststamp = $paramo->laststamp;
+if($laststamp == null){
+ return 'Eerror';
+}
+
+$sqlc = pg_connect('host=localhost port=5432 dbname='.DB_NAME.' user='.DB_USER.' password='.DB_PASSWORD);
+
+$retry = 8;
+while(true){
+ $sqlr = pg_query($sqlc,'SELECT "timestamp",array_to_string("status",\',\') AS status FROM "submit" ORDER BY "timestamp" DESC LIMIT 1;');
+ $sqlo = pg_fetch_object($sqlr);
+
+ $nowstamp = $sqlo->timestamp.'_'.$sqlo->status;
+ pg_free_result($sqlr);
+
+ if($nowstamp != $laststamp){
+ break;
+ }
+
+ if(($retry--) > 0){
+ sleep(1);
+ }else{
+ pg_close($sqlc);
+ exit('Esame');
+ }
+}
+
+$ret = array(
+ 'laststamp' => $nowstamp
+);
+if($paramo->status_submit_list != null){
+ $ret['status_submit_list'] = status_submit_list($sqlc,$paramo->status_submit_list,false);
+}
+if($paramo->status_submit_userlist != null){
+ $ret['status_submit_userlist'] = status_submit_list($sqlc,$paramo->status_submit_userlist,true);
+}
+
+if($paramo->problem_log_submit_acceptlist != null){
+ $ret['problem_log_submit_acceptlist'] = status_submit_list($sqlc,$paramo->problem_log_submit_acceptlist,false);
+}
+if($paramo->problem_log_submit_alllist != null){
+ $ret['problem_log_submit_alllist'] = status_submit_list($sqlc,$paramo->problem_log_submit_alllist,false);
+}
+
+if($paramo->square_list != null){
+ $ret['square_list'] = square_list($sqlc,$paramo->square_list);
+}
+
+if($paramo->square_rank_list != null){
+ $ret['square_rank_list'] = square_rank_list($sqlc,$paramo->square_rank_list);
+}
+if($paramo->square_problem_list != null){
+ $ret['square_problem_list'] = square_problem_list($sqlc,$paramo->square_problem_list);
+}
+if($paramo->square_scoreboard_list != null){
+ $ret['square_scoreboard_list'] = square_scoreboard_list($sqlc,$paramo->square_scoreboard_list);
+}
+
+if($paramo->problem_view != null){
+ $ret['problem_view'] = problem_view($sqlc,$paramo->problem_view);
+}
+
+pg_close($sqlc);
+
+echo json_encode($ret);
+?>
diff --git a/web/index.html b/web/index.html
new file mode 100644
index 0000000..50f87cb
--- /dev/null
+++ b/web/index.html
@@ -0,0 +1,810 @@
+<!DOCTYPE html>
+<html>
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
+<title>ExpOJ</title>
+<style type="text/css">
+body{
+ width:100%;
+ height:100%;
+ margin:0px 0px;
+ background-color:#151515;
+ color:#E9E9E9;
+ font-family:Tahoma,Geneva;
+ overflow:hidden;
+}
+div.index_head{
+ width:100%;
+ height:32px;
+ background-color:#050505;
+ z-index:0;
+}
+div.index_head div.title{
+ margin:0px 0px 0px 6px;
+ font-weight:bold;
+ font-size:18px;
+ line-height:32px;
+ float:left;
+}
+div.index_head div.tab{
+ position:absolute;
+ top:0px;
+ left:31%;
+}
+div.index_head div.content{
+ width:auto;
+ padding:0px 0px 0px 6px;
+ font-weight:bold;
+ font-size:18px;
+ line-height:32px;
+ position:absolute;
+ top:0px;
+ left:19%;
+}
+div.index_head div.panel{
+ width:97px;
+ height:100%;
+ font-weight:bold;
+ font-size:18px;
+ line-height:32px;
+ text-align:center;
+ float:right;
+ cursor:pointer;
+}
+div.index_head div.panel_m{
+ color:#FFFFFF;
+}
+div.index_head div.msg{
+ height:100%;
+ padding:0px 6px 0px 6px;
+ font-weight:bold;
+ font-size:18px;
+ line-height:32px;
+ text-align:center;
+ float:right;
+ cursor:pointer;
+
+ //background-color:#FF2400;
+}
+div.index_head div.msg_m{
+ color:#FFFFFF;
+}
+
+div.index_panel_box{
+ width:256px;
+ position:absolute;
+ top:32px;
+ left:auto;
+ right:0px;
+ z-index:100;
+ overflow:hidden;
+}
+div.index_panel{
+ width:256px;
+ height:100%;
+ background-color:#001E4E;
+ position:absolute;
+ top:0px;
+ left:auto;
+ right:-256px;
+ overflow-x:hidden;
+ overflow-y:auto;
+}
+div.index_panel div.button{
+ height:48px;
+ padding:0px 0px 0px 32px;
+ font-weight:normal;
+ font-size:20px;
+ line-height:48px;
+ color:#E9E9E9;
+ position:relative;
+ top:0px;
+ left:50%;
+ cursor:pointer;
+}
+div.index_panel div.button_m{
+ background-color:rgba(255,255,255,0.1);
+}
+div.index_panel a.button{
+ height:100%;
+ font-weight:normal;
+ font-size:20px;
+ line-height:48px;
+ color:#E9E9E9;
+ text-decoration:none;
+ display:block;
+}
+
+div.index_panel div.square_list{
+ margin:0px 0px 32px 0px;
+}
+div.index_panel div.square_list div.button{
+ height:32px;
+ padding:0px 0px 0px 32px;
+ position:relative;
+ top:0px;
+ left:50%;
+ cursor:pointer;
+}
+div.index_panel div.square_list a.button{
+ height:100%;
+ font-weight:normal;
+ font-size:16px;
+ line-height:32px;
+ color:#E9E9E9;
+ text-decoration:none;
+ display:block;
+}
+
+div.index_page{
+ width:100%;
+ position:absolute;
+ top:32px;
+ left:0px;
+ z-index:0;
+ overflow:auto;
+}
+
+div.index_mask{
+ width:100%;
+ height:100%;
+ position:fixed;
+ top:0px;
+ left:0px;
+ background-color:rgba(0,0,0,0.9);
+ z-index:1000;
+}
+</style>
+
+<script src="http://code.jquery.com/jquery-1.8.2.min.js"></script>
+<script src="http://gsgd.co.uk/sandbox/jquery/easing/jquery.easing.1.3.js"></script>
+<script type="text/javascript" src="http://codemirror.net/lib/codemirror.js"></script>
+<link rel="stylesheet" href="http://codemirror.net/lib/codemirror.css">
+<link rel="stylesheet" href="http://codemirror.net/theme/lesser-dark.css">
+<script type="text/javascript" src="http://codemirror.net/mode/clike/clike.js"></script>
+
+<link rel="stylesheet" href="nor.css">
+<script type="text/javascript" src="nor.js"></script>
+<script type="text/javascript" src="data.js"></script>
+<link rel="stylesheet" href="page.css">
+<script type="text/javascript" src="page.js"></script>
+<link rel="stylesheet" href="page_status.css">
+<script type="text/javascript" src="page_status.js"></script>
+<link rel="stylesheet" href="page_user.css">
+<script type="text/javascript" src="page_user.js"></script>
+<link rel="stylesheet" href="page_square.css">
+<script type="text/javascript" src="page_square.js"></script>
+<link rel="stylesheet" href="page_problem.css">
+<script type="text/javascript" src="page_problem.js"></script>
+
+<script type="text/javascript">
+var initurl;
+
+$(document).ready(function(){
+ $('body').on('mouseover',function(e){
+ if(e.target == null ||
+ e.target.id == 'index_panel' ||
+ e.target.id == 'index_head_panel' ||
+ $(e.target).parents('#index_panel').length > 0){
+ return;
+ }
+
+ $('#index_head_panel').removeClass('panel_m');
+ $('#index_panel').stop().animate({opacity:0},'fast','easeOutQuad',
+ function(){
+ $('#index_panel').css('right','-256px');
+ $('#index_panel div.button').css('left','50%');
+ }
+ );
+ });
+
+ $('#index_head_panel').on('mouseover',function(e){
+ $(this).addClass('panel_m');
+ $('#index_panel').css('opacity','1').stop().animate({right:0},'slow','easeOutExpo');
+
+ $('#index_panel div.button').stop().animate({left:0},'slow','easeOutQuart');
+ });
+
+ $('#index_panel div.button').hover(
+ function(e){
+ $(this).addClass('button_m');
+ },
+ function(e){
+ $(this).removeClass('button_m');
+ }
+ );
+ $('#index_panel a.button').on('click',function(e){
+ page_switch($(this.parentNode).attr('page'));
+ return false;
+ });
+
+ $('#index_panel_squarebutton').off('click').on('click',function(e){
+ var j_div;
+
+ j_div = $('#index_panel_squarelist');
+ if(j_div.is(':visible')){
+ j_div.stop().slideUp('slow','easeOutExpo');
+ }else{
+ j_div.stop().slideDown('slow','easeOutExpo');
+ }
+ });
+
+ $('#index_head_msg').hover(
+ function(e){
+ $(this).addClass('msg_m');
+ },
+ function(e){
+ $(this).removeClass('msg_m');
+ }
+ );
+
+ nor_init();
+ data_init();
+ user_init();
+ page_init();
+ status_init();
+ square_init();
+ problem_init();
+
+ nor_expendheight();
+ user_loginchange();
+ $(window).resize(function(e){nor_expendheight();});
+ $(window).on('popstate',function(e){
+ if(location.href == initurl){
+ return;
+ }
+ initurl = null;
+
+ page_switch(null);
+ });
+
+ initurl = location.href;
+ page_switch(null);
+});
+</script>
+</head>
+<body>
+<div class="index_head">
+ <div id="index_head_title" class="title"></div>
+ <div id="index_head_tab" class="tab">
+ <div id="index_headtab_status" class="nor_tab" style="display:none;">
+ <div tab="allsubmit" class="button">
+ <a class="button" href="/expoj/index.html?page=status&tab=allsubmit">All Submit</a>
+ </div>
+ <div tab="usersubmit" class="button" style="display:none;">
+ <a class="button" href="/expoj/index.html?page=status&tab=usersubmit">User Submit</a>
+ </div>
+ </div>
+ <div id="index_headtab_square" class="nor_tab" style="display:none;">
+ <div tab="rank" class="button">
+ <a class="button">Rank</a>
+ </div>
+ <div tab="problem" class="button">
+ <a class="button">Problem</a>
+ </div>
+ <div tab="scoreboard" class="button" style="display:none;">
+ <a class="button">Scoreboard</a>
+ </div>
+ </div>
+ </div>
+ <div id="index_head_content" class="content"></div>
+ <div id="index_head_panel" class="panel">Panel</div>
+ <div id="index_head_msg" class="msg">[0]</div>
+</div>
+
+<div expendheight=true class="index_panel_box">
+<div id="index_panel" class="index_panel">
+ <div page="home" class="button" style="margin:32px 0px 0px 0px;">
+ <a class="button" href="/expoj/index.html?page=home">Home</a>
+ </div>
+ <div page="status" class="button">
+ <a class="button" href="/expoj/index.html?page=status">Status</a>
+ </div>
+ <div page="user" class="button" style="display:none;">
+ <a class="button">User</a>
+ </div>
+ <div id="index_panel_squarebutton" class="button">Square</div>
+ <div id="index_panel_squarelist" class="square_list" style="display:none;">
+ <div page="squaremg" id="index_panel_squaremg" class="button">
+ <a class="button" style="font-weight:bold;">Manage Square</a>
+ </div>
+ <div class="button ori" style="display:none;">
+ <a class="button"></a>
+ </div>
+ </div>
+
+ <div page="login" class="button" style="margin:64px 0px 0px 0px;">
+ <a class="button" href="/expoj/index.html?page=login">Login</a>
+ </div>
+ <div page="register" class="button">
+ <a class="button" href="/expoj/index.html?page=register">Register</a>
+ </div>
+ <div page="logout" class="button" style="margin:64px 0px 0px 0px; display:none;">Logout</div>
+</div>
+</div>
+
+<div expendheight=true class="index_page">
+ <div id="page_home" class="page_box"></div>
+
+ <div id="page_status" class="page_box">
+ <div id="status_allsubmit" class="status_submit" style="display:none;">
+ <div class="submitinfo">
+ <div class="head">
+ <div class="nor_button" style="margin:0px 6px 0px 0px; float:right; display:none;" onclick="status_viewcode($(this).parents('div.status_submit').data('tabo').submitid);">View Code</div>
+ </div>
+
+ <table class="info">
+ <colgroup>
+ <col width="80px">
+ <col width="auto">
+ <col width="64px">
+ <col width="64px">
+ </colgroup>
+ <tr>
+ <td>SubmitID</td>
+ <td></td>
+ <td>ProID</td>
+ <td><a class="link"></a></td>
+ </tr>
+ <tr>
+ <td>Name</td>
+ <td><a class="link"></a></td>
+ <td>Score</td>
+ <td></td>
+ </tr>
+ </table>
+ <table class="list">
+ <tr>
+ <th>No</th>
+ <th>Result</th>
+ <th>Score</th>
+ <th>Time(ms)</th>
+ <th>Mem(KB)</th>
+ </tr>
+ </table>
+ </div>
+
+ <div class="submitlist">
+ <table class="list">
+ <tr class="head">
+ <th class="id">ID</th>
+ <th class="proid">ProID</th>
+ <th class="nickname">Name</th>
+ <th class="time">Time</th>
+ <th class="result">Result</th>
+ <th class="runtime">Runtime</th>
+ <th class="score">Score</th>
+ </tr>
+ <tr class="item ori" style="display:none;">
+ <td class="id"></td>
+ <td class="proid"><a class="link"></a></td>
+ <td class="nickname"><a class="link"></a></td>
+ <td class="time"></td>
+ <td class="result"></td>
+ <td class="runtime"></td>
+ <td class="score"></td>
+ </tr>
+ </table>
+ <div class="nor_chpg"></div>
+ </div>
+ </div>
+
+ <div id="status_usersubmit" class="status_submit" style="display:none;">
+ <div class="submitinfo">
+ <div class="head">
+ <div class="nor_button" style="margin:0px 6px 0px 0px; float:right; display:none;" onclick="status_viewcode($(this).parents('div.status_submit').data('tabo').submitid);">View Code</div>
+ </div>
+
+ <table class="info">
+ <colgroup>
+ <col width="80px">
+ <col width="auto">
+ <col width="64px">
+ <col width="64px">
+ </colgroup>
+ <tr>
+ <td>SubmitID</td>
+ <td></td>
+ <td>ProID</td>
+ <td><a class="link"></a></td>
+ </tr>
+ <tr>
+ <td>Name</td>
+ <td><a class="link"></a></td>
+ <td>Score</td>
+ <td></td>
+ </tr>
+ </table>
+ <table class="list">
+ <tr>
+ <th>No</th>
+ <th>Result</th>
+ <th>Score</th>
+ <th>Time(ms)</th>
+ <th>Mem(KB)</th>
+ </tr>
+ </table>
+ </div>
+
+ <div class="submitlist">
+ <table class="list">
+ <tr class="head">
+ <th class="id">ID</th>
+ <th class="proid">ProID</th>
+ <th class="nickname">Name</th>
+ <th class="time">Time</th>
+ <th class="result">Result</th>
+ <th class="runtime">Runtime</th>
+ <th class="score">Score</th>
+ </tr>
+ <tr class="item ori" style="display:none;">
+ <td class="id"></td>
+ <td class="proid"><a class="link"></a></td>
+ <td class="nickname"><a class="link"></a></td>
+ <td class="time"></td>
+ <td class="result"></td>
+ <td class="runtime"></td>
+ <td class="score"></td>
+ </tr>
+ </table>
+ <div class="nor_chpg"></div>
+ </div>
+ </div>
+ </div>
+
+ <div id="page_user" class="page_box">
+ <div id="user_info" class="user_info">
+ <div class="head">
+ <div class="setting" style="display:none;">
+ <div class="nor_button" style="margin:0px 6px 0px 0px; float:right;" onclick="user_infoedit(true);">Edit</div>
+ <div class="nor_button" style="margin:0px 6px 0px 0px; float:right; display:none;" onclick="user_infoedit(false);">Cancel</div>
+ <div class="nor_button" style="margin:0px 6px 0px 0px; float:right; display:none;" onclick="user_infosubmit();">Apply</div>
+ </div>
+ <input type="textbox" readonly=readonly class="name">
+ <input type="textbox" readonly=readonly class="aboutme">
+ <input type="textbox" class="headimg" style="display:none;">
+ <img class="headimg"></img>
+ </div>
+ <table class="info">
+ <tr>
+ <td class="info">Accepted</td>
+ <td class="info"></td>
+ </tr>
+ <tr>
+ <td class="info">Submited</td>
+ <td class="info"></td>
+ </tr>
+ <tr>
+ <td class="info">Tried</td>
+ <td class="info"></td>
+ </tr>
+ </table>
+ </div>
+ <div id="user_data" class="user_data">
+ <div class="prolist"></div>
+ </div>
+ </div>
+
+ <div id="page_squaremg" class="page_box">
+ <div id="squaremg_inside" class="squaremg_square" style="margin:0px 0px 0px 19%;">
+ <div class="head">Inside square</div>
+ <div class="squarelist upcoming">
+ <div class="head">Upcoming</div>
+ <table class="list">
+ <tr class="item ori" style="display:none;">
+ <td class="name"></td>
+ <td class="time"></td>
+ <td class="button"><div class="nor_button" style="display:none;">Remove</div></td>
+ </tr>
+ </table>
+ </div>
+ <div class="squarelist active">
+ <div class="head">Active</div>
+ <table class="list">
+ <tr class="item ori" style="display:none;">
+ <td class="name"></td>
+ <td class="time"></td>
+ <td class="button"><div class="nor_button" style="display:none;">Remove</div></td>
+ </tr>
+ </table>
+ </div>
+ <div class="squarelist inactive">
+ <div class="head">Inactive</div>
+ <table class="list">
+ <tr class="item ori" style="display:none;">
+ <td class="name"></td>
+ <td class="time"></td>
+ <td class="button"><div class="nor_button" style="display:none;">Remove</div></td>
+ </tr>
+ </table>
+ </div>
+ </div>
+ <div id="squaremg_outside" class="squaremg_square" style="margin:0px 0px 0px 16px;">
+ <div class="head">Outside square</div>
+ <div class="squarelist upcoming">
+ <div class="head">Upcoming</div>
+ <table class="list">
+ <tr class="item ori" style="display:none;">
+ <td class="name"></td>
+ <td class="button"><div class="nor_button" style="display:none;">Add</div></td>
+ </tr>
+ </table>
+ </div>
+ <div class="squarelist active">
+ <div class="head">Active</div>
+ <table class="list">
+ <tr class="item ori" style="display:none;">
+ <td class="name"></td>
+ <td class="button"><div class="nor_button" style="display:none;">Add</div></td>
+ </tr>
+ </table>
+ </div>
+ <div class="squarelist inactive">
+ <div class="head">Inactive</div>
+ <table class="list">
+ <tr class="item ori" style="display:none;">
+ <td class="name"></td>
+ <td class="button"><div class="nor_button" style="display:none;">Add</div></td>
+ </tr>
+ </table>
+ </div>
+ </div>
+ </div>
+
+ <div id="page_square" class="page_box">
+ <div class="square_rank" style="display:none;">
+ <table class="list">
+ <tr class="head">
+ <th class="rank">#</th>
+ <th class="name">Name</th>
+ <th class="rate">AC/SU</th>
+ <th class="score">Score</th>
+ </tr>
+ <tr class="item ori" style="display:none;">
+ <td class="rank"></td>
+ <td class="name"><a class="link"></a></td>
+ <td class="rate"></td>
+ <td class="score"></td>
+ </tr>
+ </table>
+ <div class="nor_chpg"></div>
+ </div>
+
+ <div class="square_problem" style="display:none;">
+ <table class="list">
+ <tr class="head">
+ <th class="blank"></th>
+ <th class="id">ID</th>
+ <th class="name">Problem Name</th>
+ <th class="rate">AC/SU</th>
+ </tr>
+ <tr class="item ori" style="display:none;">
+ <td class="blank"></td>
+ <td class="id"></td>
+ <td class="name"><a class="link"></a></td>
+ <td class="rate"></td>
+ </tr>
+ </table>
+ <div class="nor_chpg"></div>
+ </div>
+
+ <div class="square_scoreboard" style="display:none;">
+ <table class="list">
+ <tr class="head"></tr>
+ </table>
+ </div>
+ </div>
+
+ <div id="page_problem" class="page_box">
+ <div class="problem_info">
+ <div class="head">
+ <div class="nor_button" style="margin:0px 6px 0px 0px; float:right;" onclick="problem_codeswitch(true);">Submit</div>
+ </div>
+ <table class="info">
+ <tr>
+ <td class="info">ProID</td>
+ <td class="info"></td>
+ </tr>
+ <tr>
+ <td class="info">AC/SU</td>
+ <td class="info"><a class="info" onclick="problem_logswitch(true);"></a></td>
+ </tr>
+ <tr>
+ <td class="info">Time(ms)</td>
+ <td class="info"></td>
+ </tr>
+ <tr>
+ <td class="info">Mem(KB)</td>
+ <td class="info"></td>
+ </tr>
+ </table>
+ </div>
+ <div class="problem_view">
+ <div class="content"></div>
+ </div>
+ </div>
+
+ <div id="page_login" class="page_box">
+ <table class="login">
+ <tr><td><div id="login_error" class="error"></div></td></tr>
+ <tr><td>
+ <div class="head">Username</div>
+ <input id="login_username" type="textbox" class="input">
+ </td></tr>
+ <tr><td>
+ <div class="head">Password</div>
+ <input id="login_password" type="password" class="input">
+ </td></tr>
+ <tr><td>
+ <div class="nor_button" style="width:auto; float:right;" onclick="user_login_reset();">Cancel</div>
+ <div class="nor_button" style="width:auto; margin:0px 6px 0px 0px; float:right;" onclick="user_login_submit();">Login</div>
+ </td></tr>
+ </table>
+ </div>
+ <div id="page_register" class="page_box">
+ <table class="register">
+ <tr><td><div id="register_error" class="error"></div></td></tr>
+ <tr><td>
+ <div class="head">Username</div>
+ <input id="register_username" type="textbox" class="input">
+ </td></tr>
+ <tr><td>
+ <div class="head">Password</div>
+ <input id="register_password" type="password" class="input">
+ </td></tr>
+ <tr><td>
+ <div class="head">Nickname</div>
+ <input id="register_nickname" type="textbox" class="input">
+ </td></tr>
+ <tr><td>
+ <div class="nor_button" style="width:auto; float:right;" onclick="user_register_reset();">Cancel</div>
+ <div class="nor_button" style="width:auto; margin:0px 6px 0px 0px; float:right;" onclick="user_register_submit();">Register</div>
+ </td></tr>
+ </table>
+ </div>
+
+ <div id="index_mask" class="index_mask" style="display:none;">
+ <div id="mask_problem_log" class="mask_problem_log" style="display:none;">
+ <div class="nor_mask_head">
+ <div class="title"></div>
+ <div class="nor_tab" style="position:absolute; top:0px; left:31%;">
+ <div tab="allsubmit" class="button">All Submit</div>
+ <div tab="acceptsubmit" class="button button_s">AC Submit</div>
+ </div>
+ <div class="button" style="float:right;" onclick="problem_logswitch(false);">Close</div>
+ </div>
+ <div expendheight=true class="nor_mask_box">
+ <div id="problem_log_acceptsubmit" class="problem_log_submit">
+ <div class="submitinfo">
+ <div class="head">
+ <div class="nor_button" style="margin:0px 6px 0px 0px; float:right; display:none;" onclick="status_viewcode($(this).parents('div.problem_log_submit').data('tabo').submitid);">View Code</div>
+ </div>
+
+ <table class="info">
+ <colgroup>
+ <col width="80px">
+ <col width="auto">
+ <col width="64px">
+ <col width="64px">
+ </colgroup>
+ <tr>
+ <td>SubmitID</td>
+ <td></td>
+ <td>ProID</td>
+ <td></td>
+ </tr>
+ <tr>
+ <td>Name</td>
+ <td><a class="link"></a></td>
+ <td>Score</td>
+ <td></td>
+ </tr>
+ </table>
+ <table class="list">
+ <tr>
+ <th>No</th>
+ <th>Result</th>
+ <th>Score</th>
+ <th>Time(ms)</th>
+ <th>Mem(KB)</th>
+ </tr>
+ </table>
+ </div>
+
+ <div class="submitlist">
+ <table class="list">
+ <tr class="head">
+ <th class="id">ID</th>
+ <th class="nickname">Name</th>
+ <th class="time">Time</th>
+ <th class="runtime">Runtime</th>
+ <th class="score">Score</th>
+ </tr>
+ <tr class="item ori" style="display:none;">
+ <td class="id"></td>
+ <td class="nickname"><a class="link"></a></td>
+ <td class="time"></td>
+ <td class="runtime"></td>
+ <td class="score"></td>
+ </tr>
+ </table>
+ <div class="nor_chpg"></div>
+ </div>
+ </div>
+
+ <div id="problem_log_allsubmit" class="problem_log_submit" style="display:none;">
+ <div class="submitinfo">
+ <div class="head">
+ <div class="nor_button" style="margin:0px 6px 0px 0px; float:right; display:none;" onclick="status_viewcode($(this).parents('div.problem_log_submit').data('tabo').submitid);">View Code</div>
+ </div>
+
+ <table class="info">
+ <colgroup>
+ <col width="80px">
+ <col width="auto">
+ <col width="64px">
+ <col width="64px">
+ </colgroup>
+ <tr>
+ <td>SubmitID</td>
+ <td></td>
+ <td>ProID</td>
+ <td><a class="link"></a></td>
+ </tr>
+ <tr>
+ <td>Name</td>
+ <td><a class="link"></a></td>
+ <td>Score</td>
+ <td></td>
+ </tr>
+ </table>
+ <table class="list">
+ <tr>
+ <th>No</th>
+ <th>Result</th>
+ <th>Score</th>
+ <th>Time(ms)</th>
+ <th>Mem(KB)</th>
+ </tr>
+ </table>
+ </div>
+
+ <div class="submitlist">
+ <table class="list">
+ <tr class="head">
+ <th class="id">ID</th>
+ <th class="nickname">Name</th>
+ <th class="time">Time</th>
+ <th class="runtime">Runtime</th>
+ <th class="score">Score</th>
+ </tr>
+ <tr class="item ori" style="display:none;">
+ <td class="id"></td>
+ <td class="nickname"><a class="link"></a></td>
+ <td class="time"></td>
+ <td class="runtime"></td>
+ <td class="score"></td>
+ </tr>
+ </table>
+ <div class="nor_chpg"></div>
+ </div>
+ </div>
+ </div>
+ </div>
+
+ <div id="mask_problem_code" class="mask_problem_code" style="display:none;">
+ <div class="nor_mask_head">
+ <div class="title"></div>
+ <div class="content error"></div>
+ <div class="button" style="float:right;" onclick="problem_codeswitch(false);">Close</div>
+ <div class="button" style="margin:0px 6px 0px 0px; float:right;" onclick="problem_code_submit();">Submit</div>
+ </div>
+ <div expendheight=true class="nor_mask_box">
+ <div class="code"></div>
+ </div>
+ </div>
+ </div>
+</div>
+</body>
+</html>
+
diff --git a/web/nor.css b/web/nor.css
new file mode 100644
index 0000000..e0d2039
--- /dev/null
+++ b/web/nor.css
@@ -0,0 +1,112 @@
+div.nor_button{
+ height:32px;
+ padding:0px 6px;
+ background-color:#393939;
+ font-size:16px;
+ font-weight:bold;
+ text-align:center;
+ line-height:32px;
+ color:#E9E9E9;
+ cursor:pointer;
+}
+div.nor_button_m{
+ background-color:#36454F;
+}
+
+div.nor_tab{
+ width:auto;
+ height:32px;
+}
+div.nor_tab div.button{
+ width:auto;
+ height:100%;
+ padding:0px 8px 0px 8px;
+ font-weight:normal;
+ font-size:18px;
+ line-height:32px;
+ color:#E9E9E9;
+ float:left;
+ cursor:pointer;
+}
+div.nor_tab div.button_m{
+ color:#FFFFFF;
+}
+div.nor_tab div.button_s{
+ background-color:#2E8B57;
+}
+div.nor_tab a.button{
+ width:100%;
+ height:100%;
+ font-weight:normal;
+ font-size:18px;
+ line-height:32px;
+ color:#E9E9E9;
+ text-decoration:none;
+ display:block;
+}
+div.nor_tab a:hover.button{
+ color:#FFFFFF;
+}
+
+div.nor_mask_head{
+ width:100%;
+ height:32px;
+ background-color:#050505;
+ position:relative;
+}
+div.nor_mask_head div.title{
+ margin:0px 0px 0px 6px;
+ font-weight:bold;
+ font-size:18px;
+ line-height:32px;
+ float:left;
+}
+div.nor_mask_head div.content{
+ width:auto;
+ padding:0px 0px 0px 6px;
+ font-weight:bold;
+ font-size:18px;
+ line-height:32px;
+ float:left;
+}
+div.nor_mask_head div.button{
+ height:100%;
+ padding:0px 6px 0px 6px;
+ font-weight:bold;
+ font-size:18px;
+ line-height:32px;
+ text-align:center;
+ float:right;
+ cursor:pointer;
+}
+div.nor_mask_head div.button_m{
+ color:#FFFFFF;
+}
+div.nor_mask_box{
+ width:100%;
+ position:absolute;
+ left:0px;
+ top:32px;
+ overflow:hidden;
+}
+
+div.nor_chpg{
+ margin:0px auto auto;
+ padding:16px 0px 16px 0px;
+ font-size:20px;
+ text-align:center;
+}
+a.nor_chpg{
+ height:100%;
+ padding:0px 3px 0px 3px;
+ color:#E9E9E9;
+ text-decoration:none;
+ cursor:pointer;
+ display:inline-block;
+}
+a.nor_chpg_s{
+ background-color:#36454F;
+}
+a:hover.nor_chpg{
+ background-color:#36454F;
+}
diff --git a/web/nor.js b/web/nor.js
new file mode 100644
index 0000000..8021bf5
--- /dev/null
+++ b/web/nor.js
@@ -0,0 +1,111 @@
+var nor_userid;
+var nor_usersec;
+
+function nor_init(){
+ $('div.nor_button').hover(
+ function(e){
+ $(this).addClass('nor_button_m');
+ },
+ function(e){
+ $(this).removeClass('nor_button_m');
+ }
+ );
+ $('div.nor_tab > div.button').hover(
+ function(e){
+ $(this).addClass('button_m');
+ },
+ function(e){
+ $(this).removeClass('button_m');
+ }
+ );
+ $('div.nor_mask_head > div.button').hover(
+ function(e){
+ $(this).addClass('button_m');
+ },
+ function(e){
+ $(this).removeClass('button_m');
+ }
+ );
+}
+function nor_scoretolight(sumscore,summaxscore){
+ var i;
+ var part;
+ var light;
+
+ if(sumscore == null){
+ return 0;
+ }
+
+ if(summaxscore == 0){
+ light = 1;
+ }else{
+ ratio = Math.floor(sumscore / summaxscore * 100);
+ if(ratio == 100){
+ light = 4;
+ }else if(ratio >= 80){
+ light = 3;
+ }else if(ratio >= 60){
+ light = 2;
+ }else{
+ light = 1;
+ }
+ }
+
+ return light;
+}
+function nor_expendheight(){
+ var i;
+ var es;
+ var j_e;
+
+ es = $('[expendheight=true]');
+ for(i = 0;i < es.length;i++){
+ j_e = $(es[i]);
+ j_e.css('height',(window.innerHeight - parseInt(j_e.css('top').match(/(.+)px/)[1])) + 'px');
+ }
+}
+function nor_new_chpgbutton(text,click){
+ var j_a;
+
+ j_a = $('<a></a>')
+ j_a.addClass('nor_chpg');
+ j_a.on('click',click);
+ j_a.text(text)
+
+ return j_a;
+}
+
+function nor_getparam(){
+ var ret;
+ var i;
+
+ var part;
+ var subpart;
+
+ ret = new Object();
+ part = location.href.match(/([^?&]+)/g);
+ for(i = 1;i < part.length;i++){
+ part[i] = part[i].replace(/\+/g,' ');
+ subpart = part[i].split('=');
+ ret[decodeURIComponent(subpart[0]).replace(/^\s+|\s$/,' ')] = decodeURIComponent(subpart[1]);
+ }
+
+ return ret;
+}
+function nor_getcookie(){
+ var ret;
+ var i;
+
+ var part;
+ var subpart;
+
+ ret = new Object();
+ part = document.cookie.split(';');
+ for(i = 0;i < part.length;i++){
+ part[i] = part[i].replace(/\+/g,' ');
+ subpart = part[i].split('=');
+ ret[decodeURIComponent(subpart[0])] = decodeURIComponent(subpart[1]);
+ }
+
+ return ret;
+}
diff --git a/web/page.css b/web/page.css
new file mode 100644
index 0000000..1424623
--- /dev/null
+++ b/web/page.css
@@ -0,0 +1,6 @@
+div.page_box{
+ width:auto;
+ height:100%;
+ overflow:auto;
+ display:none;
+}
diff --git a/web/page.js b/web/page.js
new file mode 100644
index 0000000..43e0a2a
--- /dev/null
+++ b/web/page.js
@@ -0,0 +1,91 @@
+var page_name_select;
+var page_name_previous;
+
+function page_init(){
+ page_name_select = 'home';
+ page_name_previous = 'home';
+}
+function page_switch(page_name){
+ var j_bar_button;
+ var show = function(){
+ page_name_previous = page_name_select;
+ page_name_select = page_name;
+
+ document.title = page_name + '-ExpOJ';
+
+ if(page_name_previous == 'status'){
+ status_pageswitch(false);
+ }else if(page_name_previous.match(/^square_.+/) != null){
+ square_pageswitch(page_name_previous,false);
+ }else if(page_name_previous.match(/^problem_.+/) != null){
+ problem_pageswitch(page_name_previous,false);
+ }else if(page_name.match(/^user_.+/) != null){
+ user_pageswitch(page_name,false);
+ }
+
+ if(page_name == 'home'){
+ $('#index_head_title').text('Experiment OnlineJudge');
+ $('#page_home').fadeIn('fast');
+ }else if(page_name == 'status'){
+ status_pageswitch(true);
+ }else if(page_name == 'squaremg'){
+ squaremg_pageswitch(true);
+ }else if(page_name.match(/^square_.+/) != null){
+ square_pageswitch(page_name,true);
+ }else if(page_name.match(/^problem_.+/) != null){
+ problem_pageswitch(page_name,true);
+ }else if(page_name.match(/^user_.+/) != null){
+ user_pageswitch(page_name,true);
+ }else if(page_name == 'login'){
+ user_login_pageswitch();
+ }else if(page_name == 'register'){
+ user_register_pageswitch();
+ }else{
+ page_name = 'home';
+ page_name_select = page_name_previous;
+ window.history.replaceState(page_name,document.title,'/expoj/index.html?page=home');
+
+ show();
+ }
+ }
+
+ if(page_name == null){
+ page_name = nor_getparam().page;
+ if(page_name == undefined){
+ page_name = 'home';
+ window.history.replaceState(page_name,document.title,'/expoj/index.html?page=home');
+ }
+ }else{
+ if(page_name == page_name_select){
+ return -1;
+ }
+ window.history.pushState(page_name,document.title,'/expoj/index.html?page=' + page_name);
+ }
+
+ $('#index_head_tab').find('div.nor_tab').hide();
+ $('#index_head_content').empty();
+
+ if(page_name_select != null){
+ $('#page_' + page_name_select).fadeOut('fast',show);
+ }else{
+ show();
+ }
+
+ return 0;
+}
+function page_maskswitch(j_div,on){
+ var i;
+
+ var j_mask;
+
+ j_mask = $('#index_mask');
+ j_mask.children('div').hide();
+
+ if(on == true){
+ j_div.show();
+ j_mask.fadeIn('fast');
+ }else{
+ j_div.hide();
+ j_mask.fadeOut('fast');
+ }
+}
diff --git a/web/page_problem.css b/web/page_problem.css
new file mode 100644
index 0000000..afe1a7f
--- /dev/null
+++ b/web/page_problem.css
@@ -0,0 +1,164 @@
+div.problem_info{
+ width:19%;
+ height:100%;
+ background-color:#222222;
+ font-size:18px;
+ overflow:auto;
+ float:left;
+}
+div.problem_info > div.head{
+ width:100%;
+ height:32px;
+ margin:6px 0px 0px 0px;
+}
+div.problem_info > table.info{
+ margin:16px auto;
+}
+div.problem_info td.info{
+ padding:2px 3px 2px 3px;
+}
+div.problem_info a.info{
+ cursor:pointer;
+ text-decoration:underline;
+}
+div.problem_info a:hover.info{
+ color:#FFFFFF;
+}
+div.problem_view{
+ width:81%;
+ height:100%;
+ overflow:auto;
+ float:left;
+}
+div.problem_view > div.content{
+ padding:6px 6px 32px 6px;
+ font-size:18px;
+ font-family:Courier New,monospace;
+}
+
+div.mask_problem_log{
+ width:86%;
+ height:100%;
+ margin:0px auto;
+ background-color:#151515;
+}
+div.problem_log_submit{
+ width:86%;
+ height:100%;
+ margin:0px auto;
+ overflow:hidden;
+}
+div.problem_log_submit > div.submitlist{
+ width:69%;
+ height:100%;
+ margin:0px auto;
+ float:left;
+ overflow:auto;
+}
+div.problem_log_submit > div.submitlist > table.list{
+ width:95%;
+ margin:6px auto 0px auto;
+ font-size:20px;
+ text-align:left;
+ border-spacing:0px;
+ border-collapse:collapse;
+}
+div.problem_log_submit > div.submitlist tr.head{
+ height:32px;
+}
+div.problem_log_submit > div.submitlist tr.item{
+ height:32px;
+ cursor:pointer;
+}
+div.problem_log_submit > div.submitlist tr:hover.item{
+ background-color:#36454F;
+}
+div.problem_log_submit > div.submitlist th.id,div.problem_log_submit > div.submitlist td.id{
+ width:64px;
+}
+div.problem_log_submit > div.submitlist th.nickname,div.problem_log_submit > div.submitlist td.nickname{
+ width:auto;
+}
+div.problem_log_submit > div.submitlist th.time{
+ width:224px;
+}
+div.problem_log_submit > div.submitlist td.time{
+ width:192px;
+ font-weight:normal;
+ font-size:16px;
+}
+div.problem_log_submit > div.submitlist th.runtime{
+ width:104px;
+}
+div.problem_log_submit > div.submitlist td.runtime{
+ width:104px;
+ font-weight:normal;
+ font-size:16px;
+}
+div.problem_log_submit > div.submitlist th.score,div.problem_log_submit > div.submitlist td.score{
+ width:64px;
+}
+div.problem_log_submit > div.submitlist a.link{
+ height:100%;
+ color:#E9E9E9;
+ text-decoration:none;
+ cursor:pointer;
+}
+div.problem_log_submit > div.submitlist a:hover.link{
+ text-decoration:underline;
+}
+
+div.problem_log_submit > div.submitinfo{
+ width:31%;
+ height:100%;
+ background-color:#222222;
+ overflow:auto;
+ float:left;
+}
+div.problem_log_submit > div.submitinfo > div.head{
+ width:100%;
+ height:32px;
+ margin:6px 0px 0px 0px;
+}
+div.problem_log_submit > div.submitinfo > table.info{
+ width:95%;
+ margin:26px 0px 0px auto;
+ font-size:16px;
+ text-align:left;
+ border-spacing:0px;
+ border-collapse:collapse;
+}
+div.problem_log_submit > div.submitinfo > table.list{
+ width:95%;
+ margin:32px 0px 0px auto;
+ font-size:16px;
+ text-align:left;
+ border-spacing:0px;
+ border-collapse:collapse;
+}
+div.problem_log_submit > div.submitinfo a.link{
+ width:100%;
+ height:100%;
+ color:#E9E9E9;
+ text-decoration:none;
+ display:block;
+ cursor:pointer;
+}
+div.problem_log_submit div.submitinfo a:hover.link{
+ text-decoration:underline;
+}
+
+div.mask_problem_code{
+ width:62%;
+ height:100%;
+ margin:0px auto;
+ background-color:#151515;
+}
+div.mask_problem_code > div.nor_mask_head > div.error{
+ color:#FFA0A0;
+}
+div.mask_problem_code div.code{
+ width:62%;
+ height:100%;
+ margin:0px auto;
+}
diff --git a/web/page_problem.js b/web/page_problem.js
new file mode 100644
index 0000000..e805ec8
--- /dev/null
+++ b/web/page_problem.js
@@ -0,0 +1,525 @@
+var problem_page;
+var problem_pageo;
+var problem_log_tab;
+var problem_submitcode;
+
+function problem_init(){
+ var j_tab;
+ var j_div;
+
+ problem_page = $('#page_problem');
+ problem_pageo = {
+ 'proid':null
+ };
+ problem_log_tab = 'acceptsubmit';
+
+ problem_submitcode = CodeMirror($('#mask_problem_code > div.nor_mask_box > div.code')[0],{
+ mode:'text/x-c++src',
+ theme:'lesser-dark',
+ lineNumbers:true,
+ matchBrackets:true,
+ indentUnit:4
+ });
+ problem_submitcode.getWrapperElement().style.width = '100%';
+ problem_submitcode.getWrapperElement().style.height = '100%';
+ problem_submitcode.getScrollerElement().style.width = '100%';
+ problem_submitcode.getScrollerElement().style.height = '100%';
+
+ j_tab = $('#problem_log_acceptsubmit')
+ j_tab.data('tabo',{
+ 'result':0,
+ 'submitid':2147483647,
+ 'submitoff':0,
+ 'submitcount':0,
+ 'callback':$.Callbacks()
+ });
+ data_callback.add(function(j_tab){return function(res){
+ problem_log_submit_callback(j_tab,res);
+ }}(j_tab));
+
+ j_tab = $('#problem_log_allsubmit')
+ j_tab.data('tabo',{
+ 'result':-100,
+ 'submitid':2147483647,
+ 'submitoff':0,
+ 'submitcount':0,
+ 'callback':$.Callbacks()
+ });
+ data_callback.add(function(j_tab){return function(res){
+ problem_log_submit_callback(j_tab,res);
+ }}(j_tab));
+
+ $('#mask_problem_log > div.nor_mask_head > div.nor_tab > div.button').on('click',function(e){
+ problem_log_tabswitch($(this).attr('tab'));
+ });
+
+
+ data_callback.add(function(res){
+ var proid;
+ var proo;
+ var tds;
+ var j_name;
+ var j_content;
+
+ if((proo = res.problem_view) === undefined){
+ return;
+ }
+
+ if((proid = problem_pageo.proid) == null){
+ return;
+ }
+
+ tds = problem_page.find('div.problem_info > table.info td.info');
+ j_name = $('#index_head_content');
+ j_content = $(problem_page.find('div.problem_view > div.content')[0]);
+
+ if(data_paramo.problem_view.infoonly == true){
+ $($(tds[3]).find('a.info')[0]).text(proo.acceptcount + '/' + proo.submitcount);
+ }else{
+ if(proo == null){
+ $(tds[1]).text(proid);
+ j_name.html('<span style="color:#FFA0A0">Page not found</span>');
+
+ delete data_paramo.problem_view;
+ }else{
+ $(tds[1]).text(proid);
+ $($(tds[3]).find('a.info')[0]).text(proo.acceptcount + '/' + proo.submitcount);
+ $(tds[5]).text(proo.timelimit);
+ $(tds[7]).text(proo.memlimit);
+ j_name.text(proo.proname);
+ j_content.html(problem_textconvert(proo.protext));
+ data_paramo.problem_view.infoonly = true;
+ }
+ $('#mask_problem_code > div.nor_mask_head > div.title').text('ProID:' + proid);
+
+ problem_page.fadeIn('slow');
+ window.history.replaceState('problem',document.title,'/expoj/index.html?page=problem_' + proid);
+ }
+ });
+}
+function problem_pageswitch(pagename,on){
+ var proid;
+
+ if(on){
+ proid = pagename.match(/^problem_(.+)/)[1];
+
+ $('#index_head_title').text('ExpOJ-ProID:' + proid);
+
+ problem_page.attr('id','page_problem_' + proid);
+ problem_pageo.proid = proid;
+
+ data_paramo.problem_view = {
+ 'infoonly':false,
+ 'proid':parseInt(proid)
+ };
+ data_update(true);
+ }else{
+ delete data_paramo.problem_view;
+ delete data_paramo.problem_log_submit_acceptlist;
+ delete data_paramo.problem_log_submit_alllist;
+
+ problem_pageo.proid = null;
+ }
+}
+function problem_logswitch(on){
+ var j_tab;
+ var tabo;
+
+ if(on){
+ problem_log_tab = 'acceptsubmit';
+ $('#mask_problem_log > div.nor_mask_head > div.nor_tab > [tab="acceptsubmit"]').addClass('button_s');
+ $('#mask_problem_log > div.nor_mask_head > div.nor_tab > [tab="allsubmit"]').removeClass('button_s');
+
+ $('#mask_problem_log > div.nor_mask_head > div.title').text('ProID:' + problem_pageo.proid);
+
+ j_tab = $('#problem_log_allsubmit');
+ j_tab.hide();
+ problem_log_submit_update(j_tab);
+
+ j_tab = $('#problem_log_acceptsubmit');
+ j_tab.hide();
+ tabo = j_tab.data('tabo');
+
+ tabo.callback.add(function(){
+ j_tab.show();
+ tabo.callback.remove(arguments.callee);
+ });
+
+ problem_log_submit_update(j_tab);
+
+ page_maskswitch($('#mask_problem_log'),true);
+ }else{
+ delete data_paramo.problem_log_submit_acceptlist;
+ delete data_paramo.problem_log_submit_alllist;
+
+ page_maskswitch($('#mask_problem_log'),false);
+ }
+}
+function problem_textconvert(text){
+ var ret;
+ var i;
+
+ ret = '';
+ for(i = 0;i < text.length;i++){
+ if(text[i] != '\r' && text[i] != '\n'){
+ ret += text[i];
+ }else if(text[i] == '\n'){
+ ret += '<br/>';
+ }
+ }
+
+ return ret;
+}
+
+function problem_log_tabswitch(tabname){
+ var j_tab;
+ var tabo;
+ var show = function(){
+ problem_log_tab = tabname;
+
+ j_tab = $('#problem_log_' + problem_log_tab);
+ switch(problem_log_tab){
+ case 'acceptsubmit':
+ tabo = j_tab.data('tabo');
+ tabo.callback.add(function(){
+ j_tab.fadeIn('fast');
+ tabo.callback.remove(arguments.callee);
+ });
+
+ problem_log_submit_update(j_tab);
+ break;
+ case 'allsubmit':
+ tabo = j_tab.data('tabo');
+ tabo.callback.add(function(){
+ j_tab.fadeIn('fast');
+ tabo.callback.remove(arguments.callee);
+ });
+
+ problem_log_submit_update(j_tab);
+ break;
+ }
+ }
+
+ if(problem_log_tab == tabname){
+ return -1;
+ }
+
+ $('#mask_problem_log > div.nor_mask_head > div.nor_tab > [tab="' + problem_log_tab + '"]').removeClass('button_s');
+ $('#problem_log_' + problem_log_tab).fadeOut('fast',show);
+
+ $('#mask_problem_log > div.nor_mask_head > div.nor_tab > [tab="' + tabname + '"]').addClass('button_s');
+}
+
+function problem_log_submit_listadd(e_table,idx,submitid,userid,nickname,time,runtime,score,light){
+ var j_tr;
+ var j_td;
+ var j_a;
+
+ if((e_table.rows.length - 2) <= idx){
+ j_tr = $($(e_table).find('tr.ori')[0]).clone(true);
+ j_tr.removeClass('ori');
+ $(e_table).append(j_tr);
+ }else{
+ j_tr = $(e_table.rows[idx + 2]);
+ }
+
+ $(j_tr.find('td.id')[0]).text(submitid);
+ $(j_tr.find('td.time')[0]).text(time.match(/(.*)\./)[1]);
+ $(j_tr.find('td.runtime')[0]).text(Math.round(parseInt(runtime) / 1000));
+ j_td = $(j_tr.find('td.score')[0]);
+ j_td.text(score);
+ switch(light){
+ case 1:
+ j_td.css('color','#FF0000');
+ break;
+ case 2:
+ j_td.css('color','#00FF00');
+ break;
+ case 3:
+ j_td.css('color','#FFFF00');
+ break;
+ case 4:
+ j_td.css('color','#FFFFFF');
+ break;
+ }
+
+ j_a = $(j_tr.find('td.nickname > a.link')[0]);
+ j_a.attr('href','/expoj/index.html?page=user_' + userid);
+ j_a.text(nickname);
+ j_a.off('click').on('click',function(e){
+ problem_logswitch(false);
+ page_switch('user_' + userid);
+ return false;
+ });
+
+ j_tr.off('click').on('click',function(e){
+ var j_tab;
+ var tabo;
+
+ if(e.target.tagName == 'A'){
+ return;
+ }
+
+ j_tab = $(this).data('j_tab');
+ tabo = j_tab.data('tabo');
+ tabo.submitid = $(this).data('submitid');
+ problem_log_submit_update(j_tab);
+ });
+
+ j_tr.show();
+ return j_tr;
+}
+function problem_log_submit_listchpg(j_tab,submitoff){
+ var tabo;
+
+ tabo = j_tab.data('tabo');
+ if(submitoff >= 0 && submitoff < tabo.submitcount){
+ tabo.submitoff = submitoff;
+ tabo.laststamp = '_';
+ tabo.callback.add(function(){
+ tabo.callback.remove(arguments.callee);
+ });
+ problem_log_submit_update(j_tab);
+ }
+}
+function problem_log_submit_update(j_tab){
+ var tabo;
+ var paramo;
+
+ tabo = j_tab.data('tabo');
+ paramo = {
+ 'proid':parseInt(problem_pageo.proid),
+ 'result':parseInt(tabo.result),
+ 'submitoff':parseInt(tabo.submitoff),
+ 'submitid':parseInt(tabo.submitid)
+ };
+ if(tabo.result == 0){
+ data_paramo.problem_log_submit_acceptlist = paramo;
+ }else if(tabo.result == -100){
+ data_paramo.problem_log_submit_alllist = paramo;
+ }
+
+ data_update(true);
+}
+function problem_log_submit_callback(j_tab,res){
+ var reto;
+ var tabo;
+ var submitlist;
+
+ tabo = j_tab.data('tabo');
+ if(tabo.result == 0){
+ reto = res.problem_log_submit_acceptlist;
+ }else if(tabo.result == -100){
+ reto = res.problem_log_submit_alllist;
+ }
+ if(reto != null){
+ tabo.submitcount = reto.submitcount;
+ submitlist = reto.submitlist;
+
+ if(tabo.result == 0){
+ $('#mask_problem_log > div.nor_mask_head > div.nor_tab > [tab="acceptsubmit"]').text('AC Submit [' + tabo.submitcount+ ']');
+ }else if(tabo.result == -100){
+ $('#mask_problem_log > div.nor_mask_head > div.nor_tab > [tab="allsubmit"]').text('All Submit [' + tabo.submitcount+ ']');
+ }
+
+ if(tabo.submitoff != null){
+ var i;
+ var j;
+
+ var e_table;
+ var j_tr;
+ var j_div;
+ var j_a;
+ var submito;
+ var offs;
+ var offe;
+
+ e_table = j_tab.find('div.submitlist > table.list')[0];
+ for(i = e_table.rows.length - 1;i > 1;i--){
+ $(e_table.rows[i]).hide();
+ }
+
+ for(i = 0;i < submitlist.length - 1;i++){
+ submito = submitlist[i];
+ j_tr = problem_log_submit_listadd(
+ e_table,
+ i,
+ submito.submitid,
+ submito.userid,
+ submito.nickname,
+ submito.timestamp,
+ submito.sumruntime,
+ submito.sumscore,
+ nor_scoretolight(submito.sumscore,submito.summaxscore));
+ j_tr.data('j_tab',j_tab);
+ j_tr.data('submitid',submito.submitid);
+ }
+
+ j_div = $(j_tab.find('div.nor_chpg')[0]);
+ j_div.empty();
+
+ j_a = nor_new_chpgbutton('«',function(){
+ problem_log_submit_listchpg(j_tab,0);
+ });
+ j_div.append(j_a);
+
+ j_a = nor_new_chpgbutton('‹',function(){
+ problem_log_submit_listchpg(j_tab,(tabo.submitoff - 20));
+ });
+ j_div.append(j_a);
+
+ offs = Math.max(0,tabo.submitoff - 100);
+ if((offe = Math.min(tabo.submitcount,offs + 200)) == tabo.submitcount){
+ offs = Math.max(0,(offe - offe % 20) - 180);
+ }
+ for(i = offs;i < offe;i += 20){
+ j_a = nor_new_chpgbutton((i / 20 + 1),function(){
+ problem_log_submit_listchpg(j_tab,$(this).data('submitoff'));
+ });
+ j_a.data('submitoff',i);
+
+ if(i == tabo.submitoff){
+ j_a.addClass('nor_chpg_s');
+ }
+
+ j_div.append(j_a);
+ }
+
+ j_a = nor_new_chpgbutton('›',function(){
+ problem_log_submit_listchpg(j_tab,(tabo.submitoff + 20));
+ });
+ j_div.append(j_a);
+
+ j_a = nor_new_chpgbutton('»',function(){
+ problem_log_submit_listchpg(j_tab,(tabo.submitcount - tabo.submitcount % 20));
+ });
+ j_div.append(j_a);
+ }
+ if(tabo.submitid != null){
+ var i;
+
+ var e_table;
+ var j_tr;
+ var j_td;
+ var tds;
+ var j_a;
+ var submito;
+ var partstatus;
+ var partscore;
+ var partruntime;
+ var partpeakmem;
+
+ if(submitlist.length == 0){
+ e_table = j_tab.find('div.submitinfo > table.list')[0];
+ for(i = e_table.rows.length - 1;i > 0;i--){
+ e_table.deleteRow(i);
+ }
+
+ e_table = j_tab.find('div.submitinfo > table.info')[0];
+ tds = $(e_table).find('td');
+ $(tds[1]).text('');
+ $(tds[3]).text('');
+ $(tds[7]).text('');
+ j_a = $($(e_table).find('a')[0]);
+ j_a.attr('href',null);
+ j_a.text('');
+ j_a.off('click');
+ }else{
+ submito = submitlist[submitlist.length - 1];
+ tabo.submitid = submito.submitid;
+
+ partstatus = submito.status.split(',');
+ partscore = submito.score.split(',');
+ partruntime = submito.runtime.split(',');
+ partpeakmem = submito.peakmem.split(',');
+
+ e_table = j_tab.find('div.submitinfo > table.list')[0];
+ for(i = e_table.rows.length - 1;i > 0;i--){
+ e_table.deleteRow(i);
+ }
+
+ for(i = 0;i < partstatus.length;i++){
+ j_tr = $('<tr></tr>');
+
+ j_td = $('<td></td>');
+ j_td.text(i + 1);
+ j_tr.append(j_td);
+ j_td = $('<td></td>');
+ j_td.text(status_judgestat[parseInt(partstatus[i])]);
+ j_tr.append(j_td);
+ j_td = $('<td></td>');
+ j_td.text(partscore[i]);
+ j_tr.append(j_td);
+ j_td = $('<td></td>');
+ j_td.text(Math.round(parseInt(partruntime[i]) / 1000));
+ j_tr.append(j_td);
+ j_td = $('<td></td>');
+ j_td.text(Math.round(parseInt(partpeakmem[i]) / 1024));
+ j_tr.append(j_td);
+
+ $(e_table).append(j_tr);
+ }
+
+ e_table = j_tab.find('div.submitinfo > table.info')[0];
+ tds = $(e_table).find('td');
+ $(tds[1]).text(submito.submitid);
+ $(tds[3]).text(submito.proid);
+ $(tds[7]).text(submito.sumscore);
+
+ j_a = $($(e_table).find('a')[0]);
+ j_a.attr('href','/expoj/index.html?page=user_' + submito.userid);
+ j_a.text(submito.nickname);
+ j_a.off('click').on('click',function(userid){return function(e){
+ problem_logswitch(false);
+ page_switch('user_' + userid);
+ return false;
+ }}(submito.userid));
+
+ if(user_usero != null && submito.userid == user_usero.userid){
+ $(j_tab.find('div.submitinfo > div > div.nor_button')[0]).show();
+ }else{
+ $(j_tab.find('div.submitinfo > div > div.nor_button')[0]).hide();
+ }
+ }
+ }
+
+ tabo.callback.fire();
+ }
+}
+
+function problem_codeswitch(on){
+ if(user_usero == null){
+ page_switch('login');
+ return;
+ }
+
+ if(on){
+ $($('#mask_problem_code > div.nor_mask_head > div.error')[0]).empty();
+
+ page_maskswitch($('#mask_problem_code'),true);
+ problem_submitcode.setValue('');
+ }else{
+ problem_submitcode.setValue('');
+ page_maskswitch($('#mask_problem_code'),false);
+ }
+}
+function problem_code_submit(){
+ $.post('problem_code_submit.php',
+ {'proid':problem_pageo.proid,'code':problem_submitcode.getValue()},
+ function(res){
+ var j_div;
+
+ j_div = $($('#mask_problem_code > div.nor_mask_head > div.error')[0]);
+ if(res[0] != 'E'){
+ problem_submitcode.setValue('');
+ page_maskswitch($('#mask_problem_code'),false);
+ }else if(res == 'Euser'){
+ page_switch('login');
+ }else if(res == 'Ecode'){
+ j_div.text('Ccde長度超過64KB');
+ }else if(res == 'Elimit'){
+ j_div.text('Submit間隔必須大於10s');
+ }
+ }
+ );
+}
diff --git a/web/page_square.css b/web/page_square.css
new file mode 100644
index 0000000..6699a35
--- /dev/null
+++ b/web/page_square.css
@@ -0,0 +1,167 @@
+div.square_rank{
+ width:100%;
+}
+div.square_rank > table.list{
+ width:62%;
+ margin:6px auto 0px auto;
+ font-size:20px;
+ text-align:left;
+ border-spacing:0px;
+ border-collapse:collapse;
+}
+div.square_rank tr.head{
+ height:32px;
+}
+div.square_rank tr.item{
+ height:32px;
+}
+div.square_rank th.rank,div.square_rank td.rank{
+ width:64px;
+}
+div.square_rank th.name,div.square_rank td.name{
+ width:auto;
+}
+div.square_rank th.rate,div.square_rank td.rate{
+ width:128px;
+}
+div.square_rank th.score,div.square_rank td.score{
+ width:64px;
+}
+div.square_rank a.link{
+ width:100%;
+ height:100%;
+ text-decoration:none;
+ color:#E9E9E9;
+ display:block;
+}
+div.square_rank a.link:hover{
+ text-decoration:underline;
+}
+
+div.square_problem{
+ width:100%;
+}
+div.square_problem > table.list{
+ width:62%;
+ margin:6px auto 0px auto;
+ font-size:20px;
+ text-align:left;
+ border-spacing:0px;
+ border-collapse:collapse;
+}
+div.square_problem tr.head{
+ height:32px;
+}
+div.square_problem tr.item{
+ height:32px;
+ border-left:#333333 5px solid;
+ cursor:pointer;
+}
+div.square_problem tr:hover.item{
+ background-color:#36454F;
+}
+div.square_problem th.blank,div.square_problem td.blank{
+ width:8px;
+}
+div.square_problem th.id,div.square_problem td.id{
+ width:64px;
+}
+div.square_problem th.name,div.square_problem td.name{
+ width:auto;
+}
+div.square_problem th.rate,div.square_problem td.rate{
+ width:128px;
+}
+div.square_problem a.link{
+ width:100%;
+ height:100%;
+ text-decoration:none;
+ color:#E9E9E9;
+ display:block;
+}
+div.square_problem a:hover.link{
+ text-decoration:underline;
+}
+
+div.square_scoreboard{
+ padding:6px 6px;
+ overflow:auto;
+}
+div.square_scoreboard > table.list{
+ width:100%;
+ font-size:20px;
+ text-align:left;
+ border-spacing:0px;
+ border-collapse:collapse;
+}
+div.square_scoreboard tr.head{
+ height:32px;
+}
+div.square_scoreboard tr.item{
+ height:32px;
+}
+div.square_scoreboard th.rank,div.square_scoreboard td.rank{
+ width:64px;
+ border:#333333 1px solid;
+}
+div.square_scoreboard th.name,div.square_scoreboard td.name{
+ width:192px;
+ border:#333333 1px solid;
+}
+div.square_scoreboard th.problem,div.square_scoreboard td.problem{
+ width:104px;
+ font-size:16px;
+ text-align:center;
+ border:#333333 1px solid;
+}
+div.square_scoreboard a.link{
+ width:100%;
+ height:100%;
+ text-decoration:none;
+ color:#E9E9E9;
+ display:block;
+}
+div.square_scoreboard a.link:hover{
+ text-decoration:underline;
+}
+
+div.squaremg_square{
+ width:31%;
+ float:left;
+}
+div.squaremg_square > div.head{
+ font-size:32px;
+ padding:0px 0px 6px 0px;
+}
+div.squaremg_square > div.squarelist{
+ margin:6px 0px 0px 0px;
+}
+div.squaremg_square > div.squarelist > div.head{
+ font-size:24px;
+ border-bottom:#2E8B57 3px solid;
+}
+div.squaremg_square > div.squarelist > table.list{
+ width:100%;
+ margin:6px 0px 0px 0px;
+ text-align:left;
+ border-spacing:0px;
+ border-collapse:collapse;
+}
+div.squaremg_square > div.squarelist tr.item{
+ height:36px;
+}
+div.squaremg_square > div.squarelist tr:hover.item{
+ color:#FFFFFF;
+}
+div.squaremg_square > div.squarelist td.name{
+ width:auto;
+ font-size:16px;
+}
+div.squaremg_square > div.squarelist td.time{
+ width:256px;
+ font-size:16px;
+}
+div.squaremg_square > div.squarelist td.button{
+ width:96px;
+}
+
diff --git a/web/page_square.js b/web/page_square.js
new file mode 100644
index 0000000..6ce6403
--- /dev/null
+++ b/web/page_square.js
@@ -0,0 +1,840 @@
+var square_page;
+var square_pageo_list;
+var suqare_pageo;
+var square_update_callback;
+
+function square_init(){
+ square_page = $('#page_square');
+ square_pageo_list = new Array();
+ square_pageo = null;
+ square_update_callback = $.Callbacks();
+
+ user_logincallback.add(square_update);
+
+ $('#index_headtab_square a.button').on('click',function(e){
+ square_tabswitch($(this.parentNode).attr('tab'));
+ return false;
+ });
+
+ $('div.squaremg_square > div.squarelist > table.list tr.item').hover(
+ function(e){
+ $(this).find('div.nor_button').show();
+ },
+ function(e){
+ $(this).find('div.nor_button').hide();
+ }
+ );
+
+ $('#squaremg_inside > div.squarelist > table.list tr.item div.nor_button').on('click',function(e){
+ $.post('user_set.php',
+ {
+ 'type':'squareremove',
+ 'squareid':$(this).parents('tr.item').data('squareid')
+ },
+ function(res){
+ square_update();
+ }
+ );
+ });
+ $('#squaremg_outside > div.squarelist > table.list tr.item div.nor_button').on('click',function(e){
+ $.post('user_set.php',
+ {
+ 'type':'squareadd',
+ 'squareid':$(this).parents('tr.item').data('squareid')
+ },
+ function(res){
+ square_update();
+ }
+ );
+ });
+ data_callback.add(square_callback);
+ data_callback.add(square_rank_callback);
+ data_callback.add(square_problem_callback);
+ data_callback.add(square_scoreboard_callback);
+
+ square_update();
+}
+function square_update(){
+ data_paramo.square_list = new Object();
+ data_update(true);
+}
+function square_callback(res){
+ var i;
+
+ var reto;
+ var inlist;
+ var outlist;
+ var squareo;
+
+ var divs;
+ var j_oributton;
+ var j_button;
+ var j_a;
+
+ var e_u_table;
+ var e_a_table;
+ var e_i_table;
+ var uidx;
+ var aidx;
+ var iidx;
+
+ if(res.square_list === undefined){
+ return;
+ }
+ if(res.square_list != null){
+ reto = res.square_list;
+ inlist = reto.inlist;
+ outlist = reto.outlist;
+
+ j_oributton = $('#index_panel_squarelist > div.ori');
+ divs = $('#index_panel_squarelist').children('div.button');
+ for(i = 1;i < divs.length;i++){
+ $(divs[i]).hide();
+ }
+ for(i = 0;i < inlist.length;i++){
+ squareo = inlist[i];
+ if(squareo.status != 'active'){
+ continue;
+ }
+
+ if((divs.length - 2) <= i){
+ j_button = j_oributton.clone(true);
+ j_button.removeClass('ori');
+ j_oributton.before(j_button);
+ }else{
+ j_button = $(divs[i + 1]);
+ }
+
+ j_button.attr('page','square_' + squareo.squareid);
+ j_a = $(j_button.find('a.button')[0]);
+ j_a.attr('href','/expoj/index.html?page=square_' + squareo.squareid);
+ j_a.text(squareo.squarename);
+
+ j_button.show();
+
+ if(squareo.squareid in square_pageo_list){
+ square_pageo_list[squareo.squareid].squarename = squareo.squarename;
+ }else{
+ square_pageo_list[squareo.squareid] = {
+ 'squareid':squareo.squareid,
+ 'squarename':squareo.squarename,
+ 'flag':squareo.flag,
+ 'tab':'problem',
+ 'tabo_rank':{
+ 'rankcount':0,
+ 'rankoff':0,
+ 'callback':$.Callbacks()
+ },
+ 'tabo_problem':{
+ 'procount':0,
+ 'prooff':0,
+ 'callback':$.Callbacks()
+ },
+ 'tabo_scoreboard':{
+ 'callback':$.Callbacks()
+ }
+ }
+ }
+ }
+
+ e_u_table = $('#squaremg_inside > div.upcoming > table.list')[0];
+ e_a_table = $('#squaremg_inside > div.active > table.list')[0];
+ e_i_table = $('#squaremg_inside > div.inactive > table.list')[0];
+ for(i = e_u_table.rows.length - 1;i > 0;i--){
+ $(e_u_table.rows[i]).hide();
+ }
+ for(i = e_a_table.rows.length - 1;i > 0;i--){
+ $(e_a_table.rows[i]).hide();
+ }
+ for(i = e_i_table.rows.length - 1;i > 0;i--){
+ $(e_i_table.rows[i]).hide();
+ }
+
+ uidx = 0;
+ aidx = 0;
+ iidx = 0;
+ for(i = 0;i < inlist.length;i++){
+ squareo = inlist[i];
+
+ switch(squareo.status){
+ case 'upcoming':
+ squaremg_square_listadd(
+ e_u_table,
+ uidx,
+ squareo.squareid,
+ squareo.squarename,
+ squareo.starttime,
+ squareo.endtime);
+
+ uidx++;
+ break;
+ case 'active':
+ squaremg_square_listadd(
+ e_a_table,
+ aidx,
+ squareo.squareid,
+ squareo.squarename,
+ squareo.starttime,
+ squareo.endtime);
+
+ aidx++;
+ break;
+ case 'inactive':
+ squaremg_square_listadd(
+ e_i_table,
+ iidx,
+ squareo.squareid,
+ squareo.squarename,
+ squareo.starttime,
+ squareo.endtime);
+
+ iidx++;
+ break;
+ }
+ }
+
+ e_u_table = $('#squaremg_outside > div.upcoming > table.list')[0];
+ e_a_table = $('#squaremg_outside > div.active > table.list')[0];
+ e_i_table = $('#squaremg_outside > div.inactive > table.list')[0];
+ for(i = e_u_table.rows.length - 1;i > 0;i--){
+ $(e_u_table.rows[i]).hide();
+ }
+ for(i = e_a_table.rows.length - 1;i > 0;i--){
+ $(e_a_table.rows[i]).hide();
+ }
+ for(i = e_i_table.rows.length - 1;i > 0;i--){
+ $(e_i_table.rows[i]).hide();
+ }
+
+ uidx = 0;
+ aidx = 0;
+ iidx = 0;
+ for(i = 0;i < outlist.length;i++){
+ squareo = outlist[i];
+
+ switch(squareo.status){
+ case 'upcoming':
+ squaremg_square_listadd(
+ e_u_table,
+ uidx,
+ squareo.squareid,
+ squareo.squarename,
+ squareo.starttime,
+ squareo.endtime);
+
+ uidx++;
+ break;
+ case 'active':
+ squaremg_square_listadd(
+ e_a_table,
+ aidx,
+ squareo.squareid,
+ squareo.squarename,
+ squareo.starttime,
+ squareo.endtime);
+
+ aidx++;
+ break;
+ case 'inactive':
+ squaremg_square_listadd(
+ e_i_table,
+ iidx,
+ squareo.squareid,
+ squareo.squarename,
+ squareo.starttime,
+ squareo.endtime);
+
+ iidx++;
+ break;
+ } }
+
+ square_update_callback.fire();
+ }
+}
+
+function square_pageswitch(pagename,on){
+ var squareid;
+ var param;
+ var as;
+ var tabo;
+ var show = function(){
+ squareid = pagename.match(/^square_(.+)/)[1];
+ square_pageo = square_pageo_list[squareid];
+
+ param = nor_getparam();
+ if(param.tab != undefined){
+ square_pageo.tab = param.tab;
+ }
+
+ if(square_pageo.tab != 'rank' && square_pageo.tab != 'problem' && square_pageo.tab != 'scoreboard'){
+ square_pageo.tab = 'problem';
+ }
+ if(square_pageo.tab == 'scoreboard' && !('1' in square_pageo.flag)){
+ square_pageo.tab = 'problem';
+ }
+
+ $('#index_head_title').text('ExpOJ-' + square_pageo.squarename);
+
+ square_page.attr('id','page_square_' + square_pageo.squareid);
+
+ as = $('#index_headtab_square > div.button > a.button');
+ $(as[0]).attr('href','/expoj/index.html?page=square_' + square_pageo.squareid + '&tab=problem');
+ $(as[1]).attr('href','/expoj/index.html?page=square_' + square_pageo.squareid + '&tab=rank');
+ $(as[2]).attr('href','/expoj/index.html?page=square_' + square_pageo.squareid + '&tab=scoreboard');
+
+ if('1' in square_pageo.flag){
+ $('#index_headtab_square > [tab="scoreboard"]').show();
+ }else{
+ $('#index_headtab_square > [tab="scoreboard"]').hide();
+ }
+
+ $('#index_headtab_square > div.button').removeClass('button_s');
+ $('#index_headtab_square > [tab="' + square_pageo.tab + '"]').addClass('button_s');
+ $('#index_headtab_square').show();
+
+ $(square_page.find('div.square_rank')[0]).hide();
+ $(square_page.find('div.square_problem')[0]).hide();
+ $(square_page.find('div.square_scoreboard')[0]).hide();
+
+ switch(square_pageo.tab){
+ case 'rank':
+ tabo = square_pageo.tabo_rank;
+ if(param.rankoff != undefined){
+ tabo.rankoff = param.rankoff;
+ }
+
+ tabo.callback.add(function(){
+ $(square_page.find('div.square_rank')[0]).show();
+ window.history.replaceState('square',document.title,square_geturl());
+ tabo.callback.remove(arguments.callee);
+ });
+
+ square_rank_update();
+ break;
+ case 'problem':
+ tabo = square_pageo.tabo_problem;
+ if(param.prooff != undefined){
+ tabo.prooff = param.prooff;
+ }
+
+ tabo.callback.add(function(){
+ $(square_page.find('div.square_problem')[0]).show();
+ window.history.replaceState('square',document.title,square_geturl());
+ tabo.callback.remove(arguments.callee);
+ });
+
+ square_problem_update();
+ break;
+ case 'scoreboard':
+ tabo = square_pageo.tabo_scoreboard;
+ tabo.callback.add(function(){
+ $(square_page.find('div.square_scoreboard')[0]).show();
+ window.history.replaceState('square',document.title,square_geturl());
+ tabo.callback.remove(arguments.callee);
+ });
+
+ square_scoreboard_update();
+ break;
+ }
+
+ square_page.fadeIn('slow');
+ }
+
+ if(on){
+ square_update_callback.add(function(){
+ show();
+ square_update_callback.remove(arguments.callee);
+ });
+ square_update();
+ }else{
+ delete data_paramo.square_rank_list;
+ delete data_paramo.square_problem_list;
+ delete data_paramo.square_scoreboard_list;
+ }
+}
+function square_tabswitch(tabname){
+ var j_tab;
+ var tabo;
+ var j_div;
+ var show = function(){
+ square_pageo.tab = tabname;
+
+ j_tab = $(square_page.find('div.square_' + square_pageo.tab)[0]);
+ switch(square_pageo.tab){
+ case 'rank':
+ tabo = square_pageo.tabo_rank;
+ tabo.callback.add(function(){
+ j_tab.fadeIn('fast');
+ window.history.pushState('square',document.title,square_geturl());
+ tabo.callback.remove(arguments.callee);
+ });
+
+ square_rank_update();
+ break;
+ case 'problem':
+ tabo = square_pageo.tabo_problem;
+ tabo.callback.add(function(){
+ j_tab.fadeIn('fast');
+ window.history.pushState('square',document.title,square_geturl());
+ tabo.callback.remove(arguments.callee);
+ });
+
+ square_problem_update();
+ break;
+ case 'scoreboard':
+ tabo = square_pageo.tabo_scoreboard;
+ tabo.callback.add(function(){
+ j_tab.fadeIn('fast');
+ window.history.pushState('square',document.title,square_geturl());
+ tabo.callback.remove(arguments.callee);
+ })
+
+ square_scoreboard_update();
+ break;
+ }
+ }
+
+ if(square_pageo.tab == tabname){
+ return -1;
+ }
+
+ delete data_paramo.square_rank_list;
+ delete data_paramo.square_problem_list;
+ delete data_paramo.square_scoreboard_list;
+
+ $('#index_headtab_square > div.button').removeClass('button_s');
+ $(square_page.find('div.square_' + square_pageo.tab)[0]).fadeOut('fast',show);
+ $('#index_headtab_square > [tab="' + tabname + '"]').addClass('button_s');
+}
+function square_geturl(){
+ var url;
+ var pageo;
+ var j_tab;
+ var tabo;
+
+ url = '/expoj/index.html?page=square_' + square_pageo.squareid + '&tab=' + square_pageo.tab;
+
+ switch(square_pageo.tab){
+ case 'rank':
+ url = url + '&rankoff=' + square_pageo.tabo_rank.rankoff;
+ break;
+ case 'problem':
+ url = url + '&prooff=' + square_pageo.tabo_problem.prooff;
+ break;
+ case 'scoreboard':
+ break;
+ }
+
+ return url;
+}
+
+function square_rank_listadd(e_table,rank,userid,nickname,acceptcount,submitcount,score){
+ var j_tr;
+ var j_a;
+
+ j_tr = $($(e_table).find('tr.ori')[0]).clone(true);
+ j_tr.removeClass('ori');
+ $(j_tr.find('td.rank')[0]).text(rank);
+ j_a = $(j_tr.find('td.name > a.link')[0]);
+ j_a.attr('href','/expoj/index.html?page=user_' + userid);
+ j_a.text(nickname);
+ j_a.off('click').on('click',function(userid){return function(e){
+ page_switch('user_' + userid);
+ return false;
+ }}(userid));
+ $(j_tr.find('td.rate')[0]).text(acceptcount + '/' + submitcount);
+ $(j_tr.find('td.score')[0]).text(score);
+
+ j_tr.show();
+ $(e_table).append(j_tr);
+}
+function square_rank_chpg(rankoff){
+ var tabo;
+
+ tabo = square_pageo.tabo_rank;
+ if(rankoff >=0 && rankoff < tabo.rankcount){
+ tabo.rankoff = rankoff;
+ tabo.callback.add(function(){
+ window.history.pushState('square',document.title,square_geturl());
+ tabo.callback.remove(arguments.callee);
+ });
+
+ square_rank_update();
+ }
+}
+function square_rank_update(){
+ data_paramo.square_rank_list = {
+ 'squareid':parseInt(square_pageo.squareid),
+ 'rankoff':parseInt(square_pageo.tabo_rank.rankoff)
+ }
+
+ data_update(true);
+}
+function square_rank_callback(res){
+ var i;
+
+ var reto;
+ var ranklist;
+ var tabo;
+ var e_table;
+ var j_div;
+ var j_a;
+
+ if((reto = res.square_rank_list) === undefined){
+ return;
+ }
+
+ if(reto == null){
+ delete data_paramo.square_rank_list;
+ }else{
+ tabo = square_pageo.tabo_rank;
+ tabo.rankcount = reto.rankcount;
+ ranklist = reto.ranklist;
+
+ j_tab = $(square_page.find('div.square_rank')[0]);
+
+ e_table = j_tab.find('table.list')[0];
+ for(i = e_table.rows.length - 1;i > 1;i--){
+ e_table.deleteRow(i);
+ }
+
+ for(i = 0;i < ranklist.length;i++){
+ square_rank_listadd(
+ e_table,
+ ranklist[i].rank,
+ ranklist[i].userid,
+ ranklist[i].nickname,
+ ranklist[i].acceptcount,
+ ranklist[i].submitcount,
+ ranklist[i].score);
+ }
+
+ j_div = $(j_tab.find('div.nor_chpg')[0]);
+ j_div.empty();
+
+ j_a = nor_new_chpgbutton('«',function(){
+ square_rank_chpg(0);
+ });
+ j_div.append(j_a);
+
+ j_a = nor_new_chpgbutton('‹',function(){
+ square_rank_chpg(tabo.rankoff - 20);
+ });
+ j_div.append(j_a);
+
+ offs = Math.max(0,tabo.rankoff - 100);
+ if((offe = Math.min(tabo.rankcount,offs + 200)) == tabo.rankcount){
+ offs = Math.max(0,(offe - offe % 20) - 180);
+ }
+ for(i = offs;i < offe;i += 20){
+ j_a = nor_new_chpgbutton((i / 20 + 1),function(rankoff){return function(){
+ square_rank_chpg(rankoff);
+ }}(i));
+
+ if(i == tabo.rankoff){
+ j_a.addClass('nor_chpg_s');
+ }
+
+ j_div.append(j_a);
+ }
+
+ j_a = nor_new_chpgbutton('›',function(){
+ square_rank_chpg(tabo.rankoff + 20);
+ });
+ j_div.append(j_a);
+
+ j_a = nor_new_chpgbutton('»',function(){
+ square_rank_chpg(tabo.rankcount - tabo.rankcount % 20);
+ });
+ j_div.append(j_a);
+
+ tabo.callback.fire();
+ }
+}
+
+function square_problem_listadd(e_table,idx,proid,proname,acceptcount,submitcount,light){
+ var j_tr;
+ var j_a;
+
+ if((e_table.rows.length - 2) <= idx){
+ j_tr = $($(e_table).find('tr.ori')[0]).clone(true);
+ j_tr.removeClass('ori');
+ $(e_table).append(j_tr);
+ }else{
+ j_tr = $(e_table.rows[idx + 2]);
+ }
+
+ switch(light){
+ case 0:
+ j_tr.css('border-left','#333333 5px solid');
+ break;
+ case 1:
+ j_tr.css('border-left','#FF0000 5px solid');
+ break;
+ case 2:
+ j_tr.css('border-left','#00FF00 5px solid');
+ break;
+ case 3:
+ j_tr.css('border-left','#FFFF00 5px solid');
+ break;
+ case 4:
+ j_tr.css('border-left','#FFFFFF 5px solid');
+ break;
+ }
+
+ $(j_tr.find('td.id')[0]).text(proid);
+ $(j_tr.find('td.rate')[0]).text(acceptcount + '/' + submitcount);
+ j_a = $(j_tr.find('td.name > a.link')[0]);
+ j_a.attr('href','/expoj/index.html?page=problem_' + proid);
+ j_a.text(proname);
+
+ j_tr.off('click').on('click',function(e){
+ page_switch('problem_' + proid);
+ return false;
+ });
+
+ j_tr.show();
+ return j_tr;
+}
+function square_problem_chpg(prooff){
+ var tabo;
+
+ tabo = square_pageo.tabo_problem;
+ if(prooff >=0 && prooff < tabo.procount){
+ tabo.prooff = prooff;
+ tabo.callback.add(function(){
+ window.history.pushState('square',document.title,square_geturl());
+ tabo.callback.remove(arguments.callee);
+ });
+
+ square_problem_update();
+ }
+}
+function square_problem_update(){
+ var tabo;
+
+ tabo = square_pageo.tabo_problem;
+ data_paramo.square_problem_list = {
+ 'squareid':parseInt(square_pageo.squareid),
+ 'prooff':parseInt(tabo.prooff)
+ };
+
+ data_update(true);
+}
+function square_problem_callback(res){
+ var i;
+ var j;
+
+ var reto;
+ var tabo;
+ var prolist;
+ var proo;
+ var e_table;
+ var j_tr;
+ var j_div;
+
+ if((reto = res.square_problem_list) === undefined){
+ return;
+ }
+
+ if(reto == null){
+ delete data_paramo.square_problem_list;
+ }else{
+ tabo = square_pageo.tabo_problem;
+ tabo.procount = reto.procount;
+ prolist = reto.prolist;
+
+ j_tab = $(square_page.find('div.square_problem')[0]);
+
+ e_table = j_tab.find('table.list')[0];
+ for(i = e_table.rows.length - 1;i > 1;i--){
+ $(e_table.rows[i]).hide();
+ }
+
+ for(i = 0;i < prolist.length;i++){
+ proo = prolist[i];
+ square_problem_listadd(
+ e_table,
+ i,
+ proo.proid,
+ proo.proname,
+ proo.acceptcount,
+ proo.submitcount,
+ nor_scoretolight(proo.sumscore,proo.summaxscore));
+ }
+
+ j_div = $(j_tab.find('div.nor_chpg')[0]);
+ j_div.empty();
+
+ j_a = nor_new_chpgbutton('«',function(){
+ square_problem_chpg(0);
+ });
+ j_div.append(j_a);
+
+ j_a = nor_new_chpgbutton('‹',function(){
+ square_problem_chpg(tabo.prooff - 20);
+ });
+ j_div.append(j_a);
+
+ offs = Math.max(0,tabo.prooff - 100);
+ if((offe = Math.min(tabo.procount,offs + 200)) == tabo.procount){
+ offs = Math.max(0,(offe - offe % 20) - 180);
+ }
+ for(i = offs;i < offe;i += 20){
+ j_a = nor_new_chpgbutton((i / 20 + 1),function(prooff){return function(){
+ square_problem_chpg(prooff);
+ }}(i));
+
+ if(i == tabo.prooff){
+ j_a.addClass('nor_chpg_s');
+ }
+
+ j_div.append(j_a);
+ }
+
+ j_a = nor_new_chpgbutton('›',function(){
+ square_problem_chpg(tabo.prooff + 20);
+ });
+ j_div.append(j_a);
+
+ j_a = nor_new_chpgbutton('»',function(){
+ square_problem_chpg(tabo.procount - tabo.procount % 20);
+ });
+ j_div.append(j_a);
+
+ tabo.callback.fire();
+ }
+}
+
+function square_scoreboard_listadd(e_table,rank,userid,nickname,proidlist,prolist){
+ var i;
+
+ var proo;
+ var j_tr;
+ var j_td;
+ var j_a;
+
+ j_tr = $('<tr class="item"></tr>');
+ j_td = $('<td class="rank"></td>');
+ j_td.text(rank);
+ j_tr.append(j_td);
+ j_td = $('<td class="name"></td>');
+ j_a = $('<a class="link"></a>');
+ j_a.attr('href','/expoj/index.html?page=user_' + userid);
+ j_a.text(nickname);
+ j_a.off('click').on('click',function(userid){return function(e){
+ page_switch('user_' + userid);
+ return false;
+ }}(userid));
+ j_td.append(j_a);
+ j_tr.append(j_td);
+
+ for(i = 0;i < proidlist.length;i++){
+ j_td = $('<td class="problem"></td>');
+ if(proidlist[i] in prolist){
+ proo = prolist[proidlist[i]];
+ if(proo.accepttime == null){
+ j_td.text('-/' + proo.submitcount);
+ }else{
+ j_td.text(Math.round(proo.accepttime / 14400) + '/' + proo.submitcount);
+ j_td.css('background-color','#222222');
+ }
+ }
+ j_tr.append(j_td);
+ }
+
+ $(e_table).append(j_tr);
+}
+function square_scoreboard_update(){
+ data_paramo.square_scoreboard_list = {
+ 'squareid':parseInt(square_pageo.squareid),
+ }
+
+ data_update(true);
+}
+function square_scoreboard_callback(res){
+ var i;
+
+ var reto;
+ var tabo;
+ var proidlist;
+ var scoreboardlist;
+ var scoreboardo;
+ var e_table;
+ var j_tr;
+ var j_th;
+ var j_a;
+
+ if((reto = res.square_scoreboard_list) === undefined){
+ return;
+ }
+
+ if(reto == null){
+ delete data_paramo.square_scoreboard_list;
+ }else{
+ tabo = square_pageo.tabo_scoreboard;
+ proidlist = reto.proidlist;
+ scoreboardlist = reto.scoreboardlist;
+
+ j_tab = $(square_page.find('div.square_scoreboard')[0]);
+ j_tab.css('width',(192 + 64 + proidlist.length * 104) + 'px');
+
+ e_table = j_tab.find('table.list')[0];
+
+ j_tr = $(e_table.rows[0]);
+ j_tr.empty();
+ j_tr.append('<th class="rank">#</th>');
+ j_tr.append('<th class="name">Name</th>');
+ for(i = 0;i < proidlist.length;i++){
+ j_th = $('<th class="problem"></th>');
+ j_a = $('<a class="link"></a>');
+ j_a.attr('href','/expoj/index.html?page=problem_' + proidlist[i]);
+ j_a.text(proidlist[i]);
+ j_a.off('click').on('click',function(proid){return function(e){
+ page_switch('problem_' + proid);
+ return false;
+ }}(proidlist[i]));
+ j_th.append(j_a);
+ j_tr.append(j_th);
+ }
+
+ for(i = e_table.rows.length - 1;i > 0;i--){
+ e_table.deleteRow(i);
+ }
+
+ for(i = 0;i < scoreboardlist.length;i++){
+ scoreboardo = scoreboardlist[i];
+ square_scoreboard_listadd(
+ e_table,
+ scoreboardo.rank,
+ scoreboardo.userid,
+ scoreboardo.nickname,
+ proidlist,
+ scoreboardo.prolist);
+ }
+
+ tabo.callback.fire();
+ }
+}
+
+function squaremg_pageswitch(on){
+ square_update();
+ $('#page_squaremg').fadeIn('slow');
+}
+function squaremg_square_listadd(e_table,idx,squareid,squarename,starttime,endtime){
+ var j_tr;
+
+ if((e_table.rows.length - 1) <= idx){
+ j_tr = $($(e_table).find('tr.ori')[0]).clone(true);
+ j_tr.removeClass('ori');
+ $(e_table).append(j_tr);
+ }else{
+ j_tr = $(e_table.rows[idx + 1]);
+ }
+
+ $(j_tr.find('td.name')).text(squarename);
+ $(j_tr.find('td.time')).html(starttime.match(/(.*)[\.,\+]/)[1] + '<br/>' + endtime.match(/(.*)[\.,\+]/)[1]);
+ j_tr.data('squareid',squareid);
+
+ j_tr.show();
+}
diff --git a/web/page_status.css b/web/page_status.css
new file mode 100644
index 0000000..95f9401
--- /dev/null
+++ b/web/page_status.css
@@ -0,0 +1,110 @@
+div.status_submit{
+ width:100%;
+ height:100%;
+ overflow:hidden;
+}
+
+div.status_submit > div.submitlist{
+ width:69%;
+ height:100%;
+ float:left;
+ overflow:auto;
+}
+div.status_submit > div.submitlist > table.list{
+ width:95%;
+ margin:6px auto 0px auto;
+ font-size:20px;
+ text-align:left;
+ border-spacing:0px;
+ border-collapse:collapse;
+}
+div.status_submit > div.submitlist tr.head{
+ height:32px;
+}
+div.status_submit > div.submitlist tr.item{
+ height:32px;
+ cursor:pointer;
+}
+div.status_submit > div.submitlist tr:hover.item{
+ background-color:#36454F;
+}
+div.status_submit > div.submitlist th.id,div.status_submit > div.submitlist td.id{
+ width:64px;
+}
+div.status_submit > div.submitlist th.proid,div.status_submit > div.submitlist td.proid{
+ width:96px;
+}
+div.status_submit > div.submitlist th.nickname,div.status_submit > div.submitlist td.nickname{
+ width:auto;
+}
+div.status_submit > div.submitlist th.time{
+ width:224px;
+}
+div.status_submit > div.submitlist td.time{
+ width:224px;
+ font-weight:normal;
+ font-size:16px;
+}
+div.status_submit > div.submitlist th.result,div.status_submit > div.submitlist td.result{
+ width:80px;
+}
+div.status_submit > div.submitlist th.runtime{
+ width:104px;
+}
+div.status_submit > div.submitlist td.runtime{
+ width:104px;
+ font-weight:normal;
+ font-size:16px;
+}
+div.status_submit > div.submitlist th.score,div.status_submit > div.submitlist td.score{
+ width:64px;
+}
+div.status_submit > div.submitlist a.link{
+ height:100%;
+ color:#E9E9E9;
+ text-decoration:none;
+ cursor:pointer;
+}
+div.status_submit > div.submitlist a:hover.link{
+ text-decoration:underline;
+}
+
+div.status_submit > div.submitinfo{
+ width:31%;
+ height:100%;
+ background-color:#222222;
+ overflow:auto;
+ float:left;
+}
+div.status_submit > div.submitinfo div.head{
+ width:100%;
+ height:32px;
+ margin:6px 0px 0px 0px;
+}
+div.status_submit > div.submitinfo table.info{
+ width:95%;
+ margin:26px 0px 0px auto;
+ font-size:16px;
+ text-align:left;
+ border-spacing:0px;
+ border-collapse:collapse;
+}
+div.status_submit > div.submitinfo > table.list{
+ width:95%;
+ margin:32px 0px 0px auto;
+ font-size:16px;
+ text-align:left;
+ border-spacing:0px;
+ border-collapse:collapse;
+}
+div.status_submit > div.submitinfo a.link{
+ width:100%;
+ height:100%;
+ color:#E9E9E9;
+ text-decoration:none;
+ display:block;
+ cursor:pointer;
+}
+div.status_submit > div.submitinfo a:hover.link{
+ text-decoration:underline;
+}
diff --git a/web/page_status.js b/web/page_status.js
new file mode 100644
index 0000000..415f3d2
--- /dev/null
+++ b/web/page_status.js
@@ -0,0 +1,497 @@
+var status_judgestat;
+var status_tab;
+
+function status_init(){
+ var j_tab;
+ var j_div;
+ var as;
+
+ status_judgestat = new Array();
+ status_judgestat[0] = 'AC';
+ status_judgestat[1] = 'WA';
+ status_judgestat[2] = 'TLE';
+ status_judgestat[3] = 'MLE';
+ status_judgestat[4] = 'RF';
+ status_judgestat[5] = 'RE';
+ status_judgestat[6] = 'CE';
+ status_judgestat[7] = 'ERR';
+ status_judgestat[100] = 'WAIT';
+
+ j_tab = $('#status_allsubmit');
+ j_tab.data('tabo',{
+ 'useronly':false,
+ 'submitid':2147483647,
+ 'submitoff':0,
+ 'submitcount':0,
+ 'callback':$.Callbacks()
+ });
+ data_callback.add(function(j_tab){return function(res){
+ status_submit_callback(j_tab,res);
+ }}(j_tab));
+
+ j_tab = $('#status_usersubmit');
+ j_tab.data('tabo',{
+ 'useronly':true,
+ 'submitid':2147483647,
+ 'submitoff':0,
+ 'submitcount':0,
+ 'callback':$.Callbacks()
+ });
+ user_logincallback.add(function(){
+ var j_tab;
+
+ j_tab = $('#status_usersubmit');
+ if(user_usero != null){
+ $('#index_headtab_status > [tab="usersubmit"]').show();
+ }
+ });
+ data_callback.add(function(j_tab){return function(res){
+ status_submit_callback(j_tab,res);
+ }}(j_tab));
+ status_submit_update(j_tab);
+
+ $('#index_headtab_status > div.button').on('click',function(e){
+ status_tabswitch($(this).attr('tab'));
+ return false;
+ });
+}
+function status_pageswitch(on){
+ var param;
+ var j_tab;
+ var tabo;
+
+ if(on){
+ param = nor_getparam();
+ if(param.tab != undefined){
+ status_tab = param.tab;
+ }
+ if(status_tab != 'usersubmit' && status_tab != 'allsubmit'){
+ status_tab = 'allsubmit';
+ }
+
+ $('#index_head_title').text('ExpOJ-Status');
+
+ $('#index_headtab_status > div.button').removeClass('button_s');
+ $('#index_headtab_status > [tab="' + status_tab + '"]').addClass('button_s');
+ $('#index_headtab_status').show();
+
+ $('#status_allsubmit').hide();
+ $('#status_usersubmit').hide();
+
+ switch(status_tab){
+ case 'allsubmit':
+ j_tab = $('#status_allsubmit');
+ tabo = j_tab.data('tabo');
+
+ if(param.submitid != undefined){
+ tabo.submitid = param.submitid;
+ }
+ if(param.submitoff != undefined){
+ tabo.submitoff = param.submitoff;
+ }
+
+ tabo.callback.add(function(){
+ j_tab.show();
+ window.history.replaceState('status',document.title,status_geturl());
+ tabo.callback.remove(arguments.callee);
+ });
+
+ status_submit_update(j_tab);
+ break;
+ case 'usersubmit':
+ j_tab = $('#status_usersubmit');
+ tabo = j_tab.data('tabo');
+
+ if(param.submitid != undefined){
+ tabo.submitid = param.submitid;
+ }
+ if(param.submitoff != undefined){
+ tabo.submitoff = param.submitoff;
+ }
+
+ tabo.callback.add(function(){
+ j_tab.show();
+ window.history.replaceState('status',document.title,status_geturl());
+ tabo.callback.remove(arguments.callee);
+ });
+
+ status_submit_update(j_tab);
+ break;
+ }
+
+ $('#page_status').fadeIn('slow');
+ }else{
+ delete data_paramo.status_submit_userlist;
+ delete data_paramo.status_submit_list;
+ }
+}
+function status_tabswitch(tabname){
+ var j_tab;
+ var tabo;
+ var show = function(){
+ status_tab = tabname;
+
+ j_tab = $('#status_' + status_tab);
+ switch(status_tab){
+ case 'allsubmit':
+ tabo = j_tab.data('tabo')
+ tabo.callback.add(function(){
+ j_tab.fadeIn('fast');
+ window.history.pushState('status',document.title,status_geturl());
+ tabo.callback.remove(arguments.callee);
+ });
+
+ status_submit_update(j_tab);
+ break;
+ case 'usersubmit':
+ tabo = j_tab.data('tabo')
+ tabo.callback.add(function(){
+ j_tab.fadeIn('fast');
+ window.history.pushState('status',document.title,status_geturl());
+ tabo.callback.remove(arguments.callee);
+ });
+
+ status_submit_update(j_tab);
+ break;
+ }
+ }
+
+ if(status_tab == tabname){
+ return -1;
+ }
+
+ delete data_paramo.status_submit_userlist;
+ delete data_paramo.status_submit_list;
+
+ $('#index_headtab_status > [tab="' + status_tab + '"]').removeClass('button_s');
+ $('#status_' + status_tab).fadeOut('fast',show);
+
+ $('#index_headtab_status > [tab="' + tabname + '"]').addClass('button_s');
+}
+function status_geturl(){
+ var url;
+ var tabo;
+
+ switch(status_tab){
+ case 'allsubmit':
+ tabo = $('#status_allsubmit').data('tabo');
+ if(tabo.submitid == null){
+ url = '/expoj/index.html?page=status&tab=allsubmit&submitoff=' + tabo.submitoff;
+ }else{
+ url = '/expoj/index.html?page=status&tab=allsubmit&submitoff=' + tabo.submitoff + '&submitid=' + tabo.submitid;
+ }
+ break;
+ case 'usersubmit':
+ tabo = $('#status_usersubmit').data('tabo');
+ if(tabo.submitid == null){
+ url = '/expoj/index.html?page=status&tab=usersubmit&submitoff=' + tabo.submitoff;
+ }else{
+ url = '/expoj/index.html?page=status&tab=usersubmit&submitoff=' + tabo.submitoff + '&submitid=' + tabo.submitid;
+ }
+ break;
+ }
+
+ return url;
+}
+
+function status_submit_listadd(e_table,idx,submitid,proid,userid,nickname,time,result,runtime,score,light){
+ var j_tr;
+ var j_td;
+ var j_a;
+
+ if((e_table.rows.length - 2) <= idx){
+ j_tr = $($(e_table).find('tr.ori')[0]).clone(true);
+ j_tr.removeClass('ori');
+ $(e_table).append(j_tr);
+ }else{
+ j_tr = $(e_table.rows[idx + 2]);
+ }
+
+ $(j_tr.find('td.id')[0]).text(submitid);
+ $(j_tr.find('td.time')[0]).text(time.match(/(.*)\./)[1]);
+ $(j_tr.find('td.result')[0]).text(result);
+ $(j_tr.find('td.runtime')[0]).text(Math.round(parseInt(runtime) / 1000));
+ j_td = $(j_tr.find('td.score')[0]);
+ j_td.text(score);
+ switch(light){
+ case 1:
+ j_td.css('color','#FF0000');
+ break;
+ case 2:
+ j_td.css('color','#00FF00');
+ break;
+ case 3:
+ j_td.css('color','#FFFF00');
+ break;
+ case 4:
+ j_td.css('color','#FFFFFF');
+ break;
+ }
+
+ j_a = $(j_tr.find('td.proid > a.link')[0]);
+ j_a.attr('href','/expoj/index.html?page=problem_' + proid);
+ j_a.text(proid);
+ j_a.off('click').on('click',function(e){
+ page_switch('problem_' + proid);
+ return false;
+ });
+
+ j_a = $(j_tr.find('td.nickname > a.link')[0]);
+ j_a.attr('href','/expoj/index.html?page=user_' + userid);
+ j_a.text(nickname);
+ j_a.off('click').on('click',function(e){
+ page_switch('user_' + userid);
+ return false;
+ });
+
+ j_tr.off('click').on('click',function(e){
+ var j_tab;
+ var tabo;
+
+ if(e.target.tagName == 'A'){
+ return;
+ }
+
+ j_tab = $(this).data('j_tab');
+ tabo = j_tab.data('tabo');
+ tabo.submitid = $(this).data('submitid');
+
+ tabo.callback.add(function(){
+ window.history.pushState('status',document.title,status_geturl());
+ tabo.callback.remove(arguments.callee);
+ });
+ status_submit_update(j_tab);
+ });
+
+ j_tr.show();
+ return j_tr;
+}
+function status_submit_listchpg(j_tab,submitoff){
+ var tabo;
+
+ tabo = j_tab.data('tabo');
+ if(submitoff >= 0 && submitoff < tabo.submitcount){
+ tabo.submitoff = submitoff;
+ tabo.callback.add(function(){
+ window.history.pushState('status',document.title,status_geturl());
+ tabo.callback.remove(arguments.callee);
+ });
+ status_submit_update(j_tab);
+ }
+}
+function status_submit_update(j_tab){
+ var tabo;
+ var paramo;
+
+ tabo = j_tab.data('tabo');
+ paramo = {
+ 'submitoff':parseInt(tabo.submitoff),
+ 'submitid':parseInt(tabo.submitid)
+ };
+ if(tabo.useronly){
+ data_paramo.status_submit_userlist = paramo;
+ }else{
+ data_paramo.status_submit_list = paramo;
+ }
+
+ data_update(true);
+}
+function status_submit_callback(j_tab,res){
+ var reto;
+ var j_tab;
+ var tabo;
+ var submitlist;
+
+ tabo = j_tab.data('tabo');
+ if(tabo.useronly){
+ reto = res.status_submit_userlist;
+ }else{
+ reto = res.status_submit_list;
+ }
+ if(reto === undefined){
+ return;
+ }
+
+ if(reto == null){
+ if(tabo.useronly){
+ delete data_paramo.status_submit_userlist;
+ }else{
+ delete data_paramo.status_submit_list;
+ }
+ }else{
+ tabo.submitcount = reto.submitcount;
+ submitlist = reto.submitlist;
+
+ if(tabo.submitoff != null){
+ var i;
+ var j;
+
+ var e_table;
+ var j_tr;
+ var j_div;
+ var j_a;
+ var submito;
+ var offs;
+ var offe;
+
+ e_table = j_tab.find('div.submitlist > table.list')[0];
+ for(i = e_table.rows.length - 1;i > 1;i--){
+ $(e_table.rows[i]).hide();
+ }
+
+ for(i = 0;i < submitlist.length - 1;i++){
+ submito = submitlist[i];
+ j_tr = status_submit_listadd(
+ e_table,
+ i,
+ submito.submitid,
+ submito.proid,
+ submito.userid,
+ submito.nickname,
+ submito.timestamp,
+ status_judgestat[submito.result],
+ submito.sumruntime,
+ submito.sumscore,
+ nor_scoretolight(submito.sumscore,submito.summaxscore));
+ j_tr.data('j_tab',j_tab);
+ j_tr.data('submitid',submito.submitid);
+ }
+
+ j_div = $(j_tab.find('div.nor_chpg')[0]);
+ j_div.empty();
+
+ j_a = nor_new_chpgbutton('«',function(){
+ status_submit_listchpg(j_tab,0);
+ });
+ j_div.append(j_a);
+
+ j_a = nor_new_chpgbutton('‹',function(){
+ status_submit_listchpg(j_tab,(tabo.submitoff - 20));
+ });
+ j_div.append(j_a);
+
+ offs = Math.max(0,tabo.submitoff - 100);
+ if((offe = Math.min(tabo.submitcount,offs + 200)) == tabo.submitcount){
+ offs = Math.max(0,(offe - offe % 20) - 180);
+ }
+ for(i = offs;i < offe;i += 20){
+ j_a = nor_new_chpgbutton((i / 20 + 1),function(){
+ status_submit_listchpg(j_tab,$(this).data('submitoff'));
+ });
+ j_a.data('submitoff',i);
+
+ if(i == tabo.submitoff){
+ j_a.addClass('nor_chpg_s');
+ }
+
+ j_div.append(j_a);
+ }
+
+ j_a = nor_new_chpgbutton('›',function(){
+ status_submit_listchpg(j_tab,(tabo.submitoff + 20));
+ });
+ j_div.append(j_a);
+
+ j_a = nor_new_chpgbutton('»',function(){
+ status_submit_listchpg(j_tab,(tabo.submitcount - tabo.submitcount % 20));
+ });
+ j_div.append(j_a);
+ }
+ if(tabo.submitid != null){
+ var i;
+
+ var e_table;
+ var tds;
+ var as;
+ var j_tr;
+ var j_td;
+ var submito;
+ var partstatus;
+ var partscore;
+ var partruntime;
+ var partpeakmem;
+
+ if(submitlist.length == 0){
+ e_table = j_tab.find('div.submitinfo > table.info')[0];
+
+ tds = $(e_table).find('td');
+ $(tds[1]).text('');
+ $(tds[7]).text('');
+
+ as = $(e_table).find('a');
+ $(as[0]).attr('href','');
+ $(as[0]).text('');
+ $(as[0]).off('click');
+ $(as[1]).attr('href','');
+ $(as[1]).text('');
+ $(as[1]).off('click');
+ }else{
+ submito = submitlist[submitlist.length - 1];
+ tabo.submitid = submito.submitid;
+ partstatus = submito.status.split(',');
+ partscore = submito.score.split(',');
+ partruntime = submito.runtime.split(',');
+ partpeakmem = submito.peakmem.split(',');
+
+ e_table = j_tab.find('div.submitinfo > table.list')[0];
+ for(i = e_table.rows.length - 1;i > 0;i--){
+ e_table.deleteRow(i);
+ }
+
+ for(i = 0;i < partstatus.length;i++){
+ j_tr = $('<tr></tr>');
+
+ j_td = $('<td></td>');
+ j_td.text(i + 1);
+ j_tr.append(j_td);
+ j_td = $('<td></td>');
+ j_td.text(status_judgestat[parseInt(partstatus[i])]);
+ j_tr.append(j_td);
+ j_td = $('<td></td>');
+ j_td.text(partscore[i]);
+ j_tr.append(j_td);
+ j_td = $('<td></td>');
+ j_td.text(Math.round(parseInt(partruntime[i]) / 1000));
+ j_tr.append(j_td);
+ j_td = $('<td></td>');
+ j_td.text(Math.round(parseInt(partpeakmem[i]) / 1024));
+ j_tr.append(j_td);
+
+ $(e_table).append(j_tr);
+ }
+
+ e_table = j_tab.find('div.submitinfo > table.info')[0];
+
+ tds = $(e_table).find('td');
+ $(tds[1]).text(submito.submitid);
+ $(tds[7]).text(submito.sumscore);
+
+ as = $(e_table).find('a');
+ $(as[0]).attr('href','/expoj/index.html?page=problem_' + submito.proid);
+ $(as[0]).text(submito.proid);
+ $(as[0]).off('click').on('click',function(proid){return function(e){
+ page_switch('problem_' + proid);
+ return false;
+ }}(submito.proid));
+ $(as[1]).attr('href','/expoj/index.html?page=user_' + submito.userid);
+ $(as[1]).text(submito.nickname);
+ $(as[1]).off('click').on('click',function(userid){return function(e){
+ page_switch('user_' + userid);
+ return false;
+ }}(submito.userid));
+
+ if(user_usero != null && submito.userid == user_usero.userid){
+ $(j_tab.find('div.submitinfo > div > div.nor_button')[0]).show();
+ }else{
+ $(j_tab.find('div.submitinfo > div > div.nor_button')[0]).hide();
+ }
+ }
+ }
+
+ tabo.callback.fire();
+ }
+}
+
+function status_viewcode(submitid){
+ window.open('/expoj/viewcode.html?submitid=' + submitid);
+}
diff --git a/web/page_user.css b/web/page_user.css
new file mode 100644
index 0000000..7b2d91c
--- /dev/null
+++ b/web/page_user.css
@@ -0,0 +1,123 @@
+div.user_info{
+ width:31%;
+ height:100%;
+ background-color:#222222;
+ font-size:18px;
+ overflow:auto;
+ float:left;
+}
+div.user_info div.head{
+ margin:6px 0px 6px 0px;
+}
+div.user_info div.setting{
+ float:right;
+}
+div.user_info div.head input.name{
+ width:62%;
+ height:32px;
+ margin:0px 0px 6px 6px;
+ background-color:#222222;
+ color:#E9E9E9;
+ font-weight:bold;
+ font-size:24px;
+ line-height:32px;
+ border-width:0px;
+}
+div.user_info div.head input.aboutme,input.headimg{
+ width:95%;
+ height:24px;
+ margin:0px 0px 6px 6px;
+ background-color:#222222;
+ color:#E9E9E9;
+ font-weight:normal;
+ font-size:16px;
+ line-height:24px;
+ border-width:0px;
+}
+div.user_info div.head img.headimg{
+ width:100%;
+ margin:0px 0px 0px 0px;
+ display:block;
+}
+div.user_info table.info{
+ width:95%;
+ margin:0px auto 0px 6px;
+}
+div.user_info table.info td.info{
+ font-weight:normal;
+ font-size:16px;
+}
+
+div.user_data{
+ width:69%;
+ height:100%;
+ overflow:auto;
+ float:left;
+}
+div.user_data div.prolist{
+ width:62%;
+ margin:32px auto 0px auto;
+}
+div.user_data div.prolist span.item{
+ width:64px;
+ height:32px;
+ line-height:32px;
+ display:inline-block;
+}
+div.user_data div.prolist a.item{
+ width:100%;
+ height:100%;
+ font-weight:bold;
+ font-size:16px;
+ text-align:center;
+ text-decoration:none;
+ display:block;
+}
+div.user_data div.prolist a:hover.item{
+ text-decoration:underline;
+}
+
+table.login{
+ width:256px;
+ margin:192px auto;
+ border-spacing:16px;
+}
+table.login div.error{
+ width:100%;
+ height:16px;
+ font-size:16px;
+ color:#FFA0A0;
+}
+table.login div.head{
+ width:100%;
+ font-size:16px;
+}
+table.login input.input{
+ width:100%;
+ padding:0px 0px 0px 0px;
+ font-size:20px;
+ background-color:#E9E9E9;
+ border-width:0px;
+}
+table.register{
+ width:256px;
+ margin:192px auto;
+ border-spacing:16px;
+}
+table.register div.error{
+ width:100%;
+ height:16px;
+ font-size:16px;
+ color:#FFA0A0;
+}
+table.register div.head{
+ width:100%;
+ font-size:16px;
+}
+table.register input.input{
+ width:100%;
+ padding:0px 0px 0px 0px;
+ font-size:20px;
+ background-color:#E9E9E9;
+ border-width:0px;
+}
diff --git a/web/page_user.js b/web/page_user.js
new file mode 100644
index 0000000..e016a51
--- /dev/null
+++ b/web/page_user.js
@@ -0,0 +1,305 @@
+var user_usero;
+var user_logincallback;
+
+function user_init(){
+ user_logincallback = $.Callbacks();
+
+ $('#login_username').on('keypress',function(e){
+ if(e.which == 13){
+ user_login_submit();
+ }
+ });
+ $('#login_password').on('keypress',function(e){
+ if(e.which == 13){
+ user_login_submit();
+ }
+ });
+
+ $('#register_username').on('keypress',function(e){
+ if(e.which == 13){
+ user_register_submit();
+ }
+ });
+ $('#register_password').on('keypress',function(e){
+ if(e.which == 13){
+ user_register_submit();
+ }
+ });
+ $('#register_nickname').on('keypress',function(e){
+ if(e.which == 13){
+ user_register_submit();
+ }
+ });
+
+ $('#index_panel > [page="logout"]').off('click').on('click',user_logout);
+}
+function user_loginchange(){
+ var cookie;
+ var j_div;
+
+ cookie = nor_getcookie();
+ if(cookie['userid'] != undefined){
+ user_update(cookie['userid'],true);
+ }else{
+ user_usero = null;
+ user_panelswitch(false);
+ user_logincallback.fire();
+ }
+}
+function user_update(userid,login){
+ $.ajax({
+ url:'user_get.php',
+ type:'POST',
+ data:{'userid':parseInt(userid)},
+ async:false,
+ success:function(res){
+ var i;
+
+ var reto;
+ var usero;
+ var prolist;
+ var tds;
+
+ var j_div;
+ var proo;
+ var j_span;
+ var j_a;
+ var color;
+
+ if(res[0] != 'E'){
+ reto = JSON.parse(res);
+ usero = reto.userinfo;
+ prolist = reto.prolist;
+
+ $('#user_info > div.head > input.name').val(usero.nickname);
+ $('#user_info > div.head > input.aboutme').val(usero.aboutme);
+ $('#user_info > div.head > input.headimg').val(usero.headimg);
+ $('#user_info > div.head > img.headimg').attr('src',usero.headimg);
+
+ tds = $('#user_info > table.info td.info');
+ $(tds[1]).text(usero.acceptcount);
+ $(tds[3]).text(usero.submitcount);
+ $(tds[5]).text(usero.trycount);
+
+ j_div = $($('#user_data > div.prolist')[0]);
+ j_div.empty();
+ for(i = 0;i < prolist.length;i++){
+ proo = prolist[i];
+
+ j_span = $('<span class="item"></span');
+ j_span.on('click',function(proid){return function(e){
+ page_switch('problem_' + proid);
+ return false;
+ }}(proo.proid));
+
+ j_a = $('<a class="item"></a>');
+ j_a.attr('href','/expoj/index.html?page=problem_' + proo.proid);
+ j_a.text(proo.proid);
+
+ switch(nor_scoretolight(parseInt(proo.rate),100)){
+ case 0:
+ color = '#333333';
+ case 1:
+ color = '#FF0000';
+ break;
+ case 2:
+ color = '#00FF00';
+ break;
+ case 3:
+ color = '#FFFF00';
+ break;
+ case 4:
+ color = '#FFFFFF';
+ break;
+ }
+ j_a.css('color',color);
+
+ j_span.append(j_a);
+ j_div.append(j_span);
+ }
+
+ if(login){
+ user_usero = usero;
+ user_panelswitch(true);
+ user_logincallback.fire();
+ }
+ }else if(login){
+ user_usero = null;
+ user_panelswitch(false);
+ user_logincallback.fire();
+ }
+ }
+ });
+}
+
+function user_panelswitch(on){
+ var j_div;
+
+ if(on){
+ j_div = $('#index_panel > [page="user"]');
+ j_div.attr('page','user_' + user_usero.userid);
+ $(j_div.find('a.button')[0]).attr('href','/expoj/index.html?page=user_' + user_usero.userid);
+ j_div.show();
+ $('#index_panel > [page="login"]').hide();
+ $('#index_panel > [page="register"]').hide();
+ $('#index_panel > [page="logout"]').show();
+ }else{
+ j_div = $('#index_panel > [page^="user"]');
+ j_div.attr('page','user');
+ $(j_div.find('a.button')[0]).attr('href',null);
+ j_div.hide();
+ $('#index_panel > [page="login"]').show();
+ $('#index_panel > [page="register"]').show();
+ $('#index_panel > [page="logout"]').hide();
+ }
+}
+function user_pageswitch(pagename,on){
+ var userid;
+ var j_page;
+
+ if(on){
+ userid = pagename.match(/^user_(.+)/)[1];
+
+ $('#index_head_title').text('ExpOJ-UID:' + userid);
+
+ user_update(userid,false);
+
+ if(user_usero != null && userid == user_usero.userid){
+ $('#user_info > div.head > div.setting').show();
+ }else{
+ $('#user_info > div.head > div.setting').hide();
+ }
+
+ j_page = $('[id^="page_user"]');
+ j_page.attr('id','page_user_' + userid);
+ j_page.fadeIn('slow');
+ }else{
+ $('[id^="page_user"]').attr('id','page_user');
+ }
+}
+function user_infoedit(on){
+ var divs;
+ var inputs;
+
+ divs = $('#user_info > div.head > div.setting > div.nor_button');
+ inputs = $('#user_info > div.head > input');
+ if(on){
+ $(divs[0]).hide();
+ $(divs[1]).show();
+ $(divs[2]).show();
+ $('#user_info > div.head > input.headimg').show();
+ inputs.attr('readonly',null);
+ inputs.css('background-color','#333333');
+ }else{
+ $(divs[0]).show();
+ $(divs[1]).hide();
+ $(divs[2]).hide();
+ $('#user_info > div.head > input.headimg').hide();
+ inputs.attr('readonly','readonly');
+ inputs.css('background-color','transparent');
+
+ user_update(user_usero.userid,false);
+ }
+}
+function user_infosubmit(){
+ var inputs;
+ inputs = $('#user_info > div.head > input');
+ $.post('user_set.php',
+ {
+ 'type':'userinfo',
+ 'nickname':$('#user_info > div.head > input.name').val(),
+ 'aboutme':$('#user_info > div.head > input.aboutme').val(),
+ 'headimg':$('#user_info > div.head > input.headimg').val()
+ },
+ function(res){
+ user_infoedit(false);
+ }
+ );
+}
+
+function user_login_pageswitch(){
+ $('#index_head_title').text('ExpOJ-Login');
+
+ user_login_reset();
+ $('#page_login').fadeIn('fast',function(){
+ $('#login_username').focus();
+ });
+}
+function user_login_reset(){
+ $('#login_error').html('');
+ $('#login_username').val('');
+ $('#login_password').val('');
+}
+function user_login_submit(){
+ $.post('user_login.php',
+ {'username':$('#login_username').val(),'password':$('#login_password').val()},
+ function(res){
+ if(res[0] == 'S'){
+ user_login_reset();
+ user_loginchange();
+ if(page_name_previous == 'login' || page_name_previous == 'register'){
+ page_switch('home');
+ }else{
+ page_switch(page_name_previous);
+ }
+ }else if(res == 'Eerror'){
+ $('#login_error').html('使用者名稱或密碼錯誤');
+ }else{
+ $('#login_error').html('Oops');
+ }
+ }
+ );
+}
+
+function user_register_pageswitch(){
+ $('#index_head_title').text('ExpOJ-Register');
+
+ user_register_reset();
+ $('#page_register').fadeIn('fast',function(){
+ $('#register_username').focus();
+ });
+}
+function user_register_reset(){
+ $('#register_error').html('');
+ $('#register_username').val('');
+ $('#register_password').val('');
+ $('#register_nickname').val('');
+}
+function user_register_submit(){
+ $.post('user_register.php',
+ {'username':$('#register_username').val(),'password':$('#register_password').val(),'nickname':$('#register_nickname').val()},
+ function(res){
+ if(res[0] == 'S'){
+ user_register_reset();
+ user_loginchange();
+ if(page_name_previous == 'login' || page_name_previous == 'register'){
+ page_switch('home');
+ }else{
+ page_switch(page_name_previous);
+ }
+ }else if(res == 'Eusername'){
+ $('#register_error').html('使用者名稱不可為空或有非法字元<br/>最長16 Bytes');
+ }else if(res == 'Epassword'){
+ $('#register_error').html('<br/>密碼不可為空,最長128 Bytes');
+ }else if(res == 'Enickname'){
+ $('#register_error').html('暱稱不可為空或有非法字元<br/>最長16 Bytes');
+ }else if(res == 'Eexist'){
+ $('#register_error').html('使用者名稱已存在');
+ }else{
+ $('#register_error').html('Oops');
+ }
+ }
+ );
+}
+
+function user_logout(){
+ var cookie;
+ var key;
+
+ cookie = nor_getcookie();
+ for(key in cookie){
+ document.cookie = key + '=;expires=Thu, 01 Jan 1970 00:00:00 GMT';
+ }
+
+ location.href = '/expoj/index.html?page=home';
+}
diff --git a/web/problem_code_submit.php b/web/problem_code_submit.php
new file mode 100644
index 0000000..2e7459a
--- /dev/null
+++ b/web/problem_code_submit.php
@@ -0,0 +1,66 @@
+<?php
+require_once('common.php');
+
+$userid = $_COOKIE['userid'];
+$usersec = $_COOKIE['usersec'];
+$proid = $_POST['proid'];
+$code = $_POST['code'];
+
+if(!sec_checkuser($userid,$usersec)){
+ exit('Euser');
+}
+if($proid == '' || strval(intval($proid)) != $proid){
+ exit('Epro');
+}
+if(strlen($code) > (64 * 1024)){
+ exit('Ecode');
+}
+
+$sqlc = pg_connect('host=localhost port=5432 dbname='.DB_NAME.' user='.DB_USER.' password='.DB_PASSWORD);
+
+$userid = pg_escape_string($userid);
+$sqlr = pg_query_params($sqlc,'SELECT * FROM "user" WHERE userid=$1 LIMIT 1;',
+ array($userid));
+if(($usero = pg_fetch_object($sqlr)) == null){
+ pg_free_result($sqlr);
+ pg_close($sqlc);
+ exit('Euser');
+}
+pg_free_result($sqlr);
+
+$mc = new Memcached();
+$mc->addServer('localhost',11211);
+if(!$mc->add('problem_code_submit_limit_'.$userid,true,10)){
+ pg_close($sqlc);
+ exit('Elimit');
+}
+
+$proid = pg_escape_string($proid);
+$sqlr = pg_query_params($sqlc,'SELECT * FROM "problem" WHERE proid=$1 LIMIT 1;',
+ array($proid));
+if(($proo = pg_fetch_object($sqlr)) == null){
+ pg_free_result($sqlr);
+ pg_close($sqlc);
+ exit('Epro');
+}
+pg_free_result($sqlr);
+
+$sqlr = pg_query_params($sqlc,'INSERT INTO "submit" ("proid","userid","status","score","maxscore","runtime","peakmem") VALUES($1,$2,$3,$4,$5,$6,$7) RETURNING "submitid";',
+ array($proid,$userid,'{100}','{0}','{0}','{0}','{0}'));
+$submitid = pg_fetch_row($sqlr)[0];
+pg_free_result($sqlr);
+
+file_put_contents('submit/'.$submitid.'_submit.cpp',$code);
+
+pg_close($sqlc);
+
+$sd = socket_create(AF_INET,SOCK_STREAM,0);
+socket_connect($sd,'127.0.0.1',2501);
+
+$data = $submitid.' '.$proid.chr(0);
+socket_write($sd,$data,strlen($data));
+
+socket_close($sd);
+
+echo 'S';
+?>
diff --git a/web/problem_view.php b/web/problem_view.php
new file mode 100644
index 0000000..d53db88
--- /dev/null
+++ b/web/problem_view.php
@@ -0,0 +1,41 @@
+<?php
+require_once('common.php');
+
+function problem_view($sqlc,$paramo){
+ $proid = $paramo->proid;
+ $infoonly = $paramo->infoonly;
+
+ if(gettype($proid) != 'integer' || $proid < 1){
+ return null;
+ }
+
+ $sqlc = pg_connect('host=localhost port=5432 dbname='.DB_NAME.' user='.DB_USER.' password='.DB_PASSWORD);
+
+ $proid = pg_escape_string($proid);
+ $sqlr = pg_query_params($sqlc,'SELECT * FROM "problem" WHERE proid=$1 LIMIT 1;',
+ array($proid));
+ if(($proo = pg_fetch_object($sqlr)) == null){
+ pg_free_result($sqlr);
+ return null;
+ }
+
+ if($infoonly){
+ $proo = array(
+ 'acceptcount' => $proo->acceptcount,
+ 'submitcount' => $proo->submitcount);
+ }else{
+ $setting_info = parse_ini_file('pro/'.$proo->proid.'/'.$proo->proid.'_setting.txt',true);
+ $proo = array(
+ 'proid' => $proo->proid,
+ 'proname' => $proo->proname,
+ 'timelimit' => $setting_info['JUDGE']['timelimit'],
+ 'memlimit' => $setting_info['JUDGE']['memlimit'],
+ 'acceptcount' => $proo->acceptcount,
+ 'submitcount' => $proo->submitcount,
+ 'protext' => file_get_contents('pro/'.$proo->proid.'/'.$proo->proid.'_text.txt'));
+ }
+
+ pg_free_result($sqlr);
+ return $proo;
+}
+?>
diff --git a/web/square_list.php b/web/square_list.php
new file mode 100644
index 0000000..7ac9188
--- /dev/null
+++ b/web/square_list.php
@@ -0,0 +1,81 @@
+<?php
+require_once('common.php');
+
+function square_list($sqlc,$paramo){
+ $userid = $_COOKIE['userid'];
+ $usersec = $_COOKIE['usersec'];
+ if(!sec_checkuser($userid,$usersec)){
+ return null;
+ }
+
+ $userid = pg_escape_string($userid);
+ $sqlr = pg_query_params($sqlc,'SELECT array_to_string("squarelist",\',\') AS "squarelist" FROM "user" WHERE "userid"=$1 LIMIT 1;',
+ array($userid));
+
+ if(($sqlo = pg_fetch_object($sqlr)) == null){
+ pg_free_result($sqlr);
+ return null;
+ }
+ $squarelist = $sqlo->squarelist;
+ pg_free_result($sqlr);
+
+ $sqlr = pg_query($sqlc,'SELECT *,array_to_string("flag",\',\') AS "flag","starttime"<=now() AS "start","endtime"<=now() AS "end" FROM "square" WHERE "squareid" IN ('.$squarelist.') ORDER BY "squareid" ASC;');
+ $inlist = array();
+ while($squareo = pg_fetch_object($sqlr)){
+ if($squareo->end == 't'){
+ $status = 'inactive';
+ }else if($squareo->start == 't'){
+ $status = 'active';
+ }else{
+ $status = 'upcoming';
+ }
+ $flaglist = explode(',',$squareo->flag);
+ $flag = array();
+ for($idx = 0;$idx < count($flaglist);$idx++){
+ $flag[$flaglist[$idx]] = true;
+ }
+
+ $inlist[] = array(
+ 'squareid' => $squareo->squareid,
+ 'squarename' => $squareo->squarename,
+ 'starttime' => $squareo->starttime,
+ 'endtime' => $squareo->endtime,
+ 'status' => $status,
+ 'flag' => $flag
+ );
+ }
+ pg_free_result($sqlr);
+
+ $sqlr = pg_query($sqlc,'SELECT *,array_to_string("flag",\',\') AS "flag","starttime"<=now() AS "start","endtime"<=now() AS "end" FROM "square" WHERE "squareid" NOT IN ('.$squarelist.') ORDER BY "squareid" ASC;');
+ $outlist = array();
+ while($squareo = pg_fetch_object($sqlr)){
+ if($squareo->end == 't'){
+ $status = 'inactive';
+ }else if($squareo->start == 't'){
+ $status = 'active';
+ }else{
+ $status = 'upcoming';
+ }
+ $flaglist = explode(',',$squareo->flag);
+ $flag = array();
+ for($idx = 0;$idx < count($flaglist);$idx++){
+ $flag[$flaglist[$idx]] = true;
+ }
+
+ $outlist[] = array(
+ 'squareid' => $squareo->squareid,
+ 'squarename' => $squareo->squarename,
+ 'starttime' => $squareo->starttime,
+ 'endtime' => $squareo->endtime,
+ 'status' => $status,
+ 'flag' => $flag
+ );
+ }
+ pg_free_result($sqlr);
+
+ return array(
+ 'inlist' => $inlist,
+ 'outlist' => $outlist
+ );
+}
+?>
diff --git a/web/square_problem_list.php b/web/square_problem_list.php
new file mode 100644
index 0000000..60d4268
--- /dev/null
+++ b/web/square_problem_list.php
@@ -0,0 +1,63 @@
+<?php
+require_once('common.php');
+
+function square_problem_list($sqlc,$paramo){
+ $userid = $_COOKIE['userid'];
+ $usersec = $_COOKIE['usersec'];
+ $squareid = $paramo->squareid;
+ $prooff = $paramo->prooff;
+
+ if(!sec_checkuser($userid,$usersec)){
+ $userid = null;
+ }
+ if(gettype($squareid) != 'integer' || $squareid < 1){
+ return null;
+ }
+ if(gettype($prooff) != 'integer' || $prooff < 0){
+ return null;
+ }
+
+ $squaireid = pg_escape_string($squareid);
+ $prooff = pg_escape_string($prooff);
+ $sqlr = pg_query_params($sqlc,'SELECT * FROM "problem" WHERE $1 = ANY ("squarelist") ORDER BY "proid" LIMIT 20 OFFSET $2;',
+ array($squareid,$prooff));
+
+ $prolist = array();
+ $proidlist = array();
+ while($proo = pg_fetch_object($sqlr)){
+ $prolist[] = array(
+ 'proid' => $proo->proid,
+ 'proname' => $proo->proname,
+ 'acceptcount' => $proo->acceptcount,
+ 'submitcount' => $proo->submitcount,
+ 'sumscore' => null,
+ 'summaxscore' => null);
+ $proidlist[$proo->proid] = count($prolist) - 1;
+ }
+ pg_free_result($sqlr);
+
+ $sqlr = pg_query_params($sqlc,'SELECT COUNT(*) FROM "problem" WHERE $1 = ANY ("squarelist");',
+ array($squareid));
+ $procount = pg_fetch_row($sqlr)[0];
+ pg_free_result($sqlr);
+
+ if($userid){
+ $userid = pg_escape_string($userid);
+ $sqlr = pg_query_params($sqlc,'SELECT "proid","sumscore","summaxscore" FROM "submit" WHERE "userid"=$1 AND "proid" IN ('.implode(',',array_keys($proidlist)).') ORDER BY "sumscore" DESC;',
+ array($userid));
+
+ while($sqlo = pg_fetch_object($sqlr)){
+ if($prolist[$proidlist[$sqlo->proid]]['sumscore'] == null){
+ $prolist[$proidlist[$sqlo->proid]]['sumscore'] = $sqlo->sumscore;
+ $prolist[$proidlist[$sqlo->proid]]['summaxscore'] = $sqlo->summaxscore;
+ }
+ }
+ pg_free_result($sqlr);
+ }
+
+ return array(
+ 'procount' => $procount,
+ 'prolist' => $prolist
+ );
+}
+?>
diff --git a/web/square_rank_list.php b/web/square_rank_list.php
new file mode 100644
index 0000000..01f3f45
--- /dev/null
+++ b/web/square_rank_list.php
@@ -0,0 +1,115 @@
+<?php
+require_once('common.php');
+
+function ranklist_cmp($a,$b){
+ if($a['acceptcount'] == $b['acceptcount']){
+ if($a['submitcount'] == $b['submitcount']){
+ return $a['userid'] - $b['userid'];
+ }else{
+ return $a['submitcount'] - $b['submitcount'];
+ }
+ }
+ return $b['acceptcount'] - $a['acceptcount'];
+}
+
+function square_rank_list($sqlc,$paramo){
+ $squareid = $paramo->squareid;
+ $rankoff = $paramo->rankoff;
+
+ if(gettype($squareid) != 'integer' || $squareid < 1){
+ return null;
+ }
+ if(gettype($rankoff) != 'integer' || $rankoff < 0){
+ return null;
+ }
+
+ $squareid = pg_escape_string($squareid);
+ $sqlr = pg_query_params($sqlc,'SELECT * FROM "square" WHERE "squareid"=$1',
+ array($squareid));
+
+ if(($squareo = pg_fetch_object($sqlr)) == null){
+ pg_free_result($sqlr);
+ return null;
+ }
+ pg_free_result($sqlr);
+
+ $sqlr = pg_query_params($sqlc,'SELECT "proid" FROM "problem" WHERE $1=ANY("squarelist");',
+ array($squareid));
+
+ $proidlist = array();
+ while($sqlo = pg_fetch_object($sqlr)){
+ $proidlist[] = $sqlo->proid;
+ }
+ pg_free_result($sqlr);
+
+ $sqlr = pg_query_params($sqlc,'SELECT "userid","nickname" FROM "user" WHERE $1=ANY("squarelist");',
+ array($squareid));
+
+ $useridlist = array();
+ while($sqlo = pg_fetch_object($sqlr)){
+ $useridlist[$sqlo->userid] = array(
+ 'nickname' => $sqlo->nickname,
+ 'acceptcount' => 0,
+ 'submitcount' => 0,
+ 'score' => 0);
+ }
+ pg_free_result($sqlr);
+
+ $sqlr = pg_query_params($sqlc,'SELECT "userid" FROM "submit" WHERE "proid" IN ('.implode(',',$proidlist).') AND "result"=0 AND "timestamp">=$1 AND "timestamp"<$2 GROUP BY "proid","userid";',
+ array($squareo->starttime,$squareo->endtime));
+
+ while($sqlo = pg_fetch_object($sqlr)){
+ if(array_key_exists($sqlo->userid,$useridlist)){
+ $useridlist[$sqlo->userid]['acceptcount']++;
+ }
+ }
+ pg_free_result($sqlr);
+
+ $sqlr = pg_query_params($sqlc,'SELECT "userid",COUNT("userid") AS "submitcount" FROM "submit" WHERE "proid" IN ('.implode(',',$proidlist).') AND "timestamp">=$1 AND "timestamp"<$2 GROUP BY "userid";',
+ array($squareo->starttime,$squareo->endtime));
+
+ while($sqlo = pg_fetch_object($sqlr)){
+ if(array_key_exists($sqlo->userid,$useridlist)){
+ $useridlist[$sqlo->userid]['submitcount'] += $sqlo->submitcount;
+ }
+ }
+ pg_free_result($sqlr);
+
+ $sqlr = pg_query_params($sqlc,'SELECT "userid",MAX("sumscore") AS "score" FROM "submit" WHERE "proid" IN ('.implode(',',$proidlist).') AND "timestamp">=$1 AND "timestamp"<$2 GROUP BY "proid","userid";',
+ array($squareo->starttime,$squareo->endtime));
+
+ while($sqlo = pg_fetch_object($sqlr)){
+ if(array_key_exists($sqlo->userid,$useridlist)){
+ $useridlist[$sqlo->userid]['score'] += $sqlo->score;
+ }
+ }
+ pg_free_result($sqlr);
+
+ $ranklist = array();
+ foreach($useridlist as $key => $value){
+ $ranklist[] = array(
+ 'userid' => $key,
+ 'nickname' => $value['nickname'],
+ 'acceptcount' => $value['acceptcount'],
+ 'submitcount' => $value['submitcount'],
+ 'score' => $value['score']);
+ }
+ usort($ranklist,'ranklist_cmp');
+
+ $rank = 1;
+ for($idx = 0;$idx < count($ranklist);$idx++){
+ if($idx > 0){
+ if($ranklist[$idx]['acceptcount'] != $ranklist[$idx - 1]['acceptcount'] ||
+ $ranklist[$idx]['submitcount'] != $ranklist[$idx - 1]['submitcount']){
+ $rank = $idx + 1;
+ }
+ }
+ $ranklist[$idx]['rank'] = $rank;
+ }
+
+ return array(
+ 'rankcount' => count($ranklist),
+ 'ranklist' => array_slice($ranklist,$rankoff,20)
+ );
+}
+?>
diff --git a/web/square_scoreboard_list.php b/web/square_scoreboard_list.php
new file mode 100644
index 0000000..6fdbf13
--- /dev/null
+++ b/web/square_scoreboard_list.php
@@ -0,0 +1,115 @@
+<?php
+require_once('common.php');
+
+function scoreboardlist_cmp($a,$b){
+ if($a['acceptcount'] == $b['acceptcount']){
+ if($a['penalty'] == $b['penalty']){
+ return $a['userid'] - $b['userid'];
+ }else{
+ return $a['penalty'] - $b['penalty'];
+ }
+ }
+ return $b['acceptcount'] - $a['acceptcount'];
+}
+
+function square_scoreboard_list($sqlc,$paramo){
+ $squareid = $paramo->squareid;
+
+ if(gettype($squareid) != 'integer' || $squareid < 1){
+ return null;
+ }
+
+ $squareid = pg_escape_string($squareid);
+ $sqlr = pg_query_params($sqlc,'SELECT * FROM "square" WHERE "squareid"=$1',
+ array($squareid));
+
+ if(($squareo = pg_fetch_object($sqlr)) == null){
+ pg_free_result($sqlr);
+ return null;
+ }
+ pg_free_result($sqlr);
+
+ $sqlr = pg_query_params($sqlc,'SELECT "proid" FROM "problem" WHERE $1=ANY("squarelist") ORDER BY "proid";',
+ array($squareid));
+
+ $proidlist = array();
+ while($sqlo = pg_fetch_object($sqlr)){
+ $proidlist[] = $sqlo->proid;
+ }
+ pg_free_result($sqlr);
+
+ $sqlr = pg_query_params($sqlc,'SELECT "userid","nickname" FROM "user" WHERE $1=ANY("squarelist");',
+ array($squareid));
+
+ $useridlist = array();
+ while($sqlo = pg_fetch_object($sqlr)){
+ $useridlist[$sqlo->userid] = array(
+ 'nickname' => $sqlo->nickname,
+ 'acceptcount' => 0,
+ 'penalty' => 0,
+ 'prolist' => array()
+ );
+ }
+ pg_free_result($sqlr);
+
+ $sqlr = pg_query_params($sqlc,'SELECT "userid","proid",EXTRACT(EPOCH FROM age("timestamp",$1)) AS "time","result"=0 AS "accept" FROM "submit" WHERE "proid" IN ('.implode(',',$proidlist).') ORDER BY "timestamp";',
+ array($squareo->starttime));
+
+ while($sqlo = pg_fetch_object($sqlr)){
+ if(!array_key_exists($sqlo->userid,$useridlist)){
+ continue;
+ }
+
+ $userido = &$useridlist[$sqlo->userid];
+ if(!array_key_exists($sqlo->proid,$userido['prolist'])){
+ $userido['prolist'][$sqlo->proid] = array(
+ 'accepttime' => null,
+ 'submitcount' => 0,
+ 'penalty' => 0
+ );
+ }
+ $proo = &$userido['prolist'][$sqlo->proid];
+
+ if($proo['accepttime'] == null){
+ if($sqlo->accept == 't'){
+ $proo['accepttime'] = intval($sqlo->time);
+ $proo['submitcount']++;
+ $proo['penalty'] = ($userido->submitcount - 1) * 1200 + $proo['accepttime'];
+
+ $userido['acceptcount']++;
+ $userido['penalty'] += $proo['penalty'];
+ }else{
+ $proo['submitcount']++;
+ }
+ }
+ }
+ pg_free_result($sqlr);
+
+ $scoreboardlist = array();
+ foreach($useridlist as $key => $value){
+ $scoreboardlist[] = array(
+ 'userid' => $key,
+ 'nickname' => $value['nickname'],
+ 'acceptcount' => $value['acceptcount'],
+ 'penalty' => $value['penalty'],
+ 'prolist' => $value['prolist']);
+ }
+ usort($scoreboardlist,'scoreboardlist_cmp');
+
+ $rank = 1;
+ for($idx = 0;$idx < count($scoreboardlist);$idx++){
+ if($idx > 0){
+ if($scoreboardlist[$idx]['acceptcount'] != $scoreboardlist[$idx - 1]['acceptcount'] ||
+ $scoreboardlist[$idx]['penalty'] != $scoreboardlist[$idx - 1]['penalty']){
+ $rank = $idx + 1;
+ }
+ }
+ $scoreboardlist[$idx]['rank'] = $rank;
+ }
+
+ return array(
+ 'proidlist' => $proidlist,
+ 'scoreboardlist' => $scoreboardlist
+ );
+}
+?>
diff --git a/web/square_set.php b/web/square_set.php
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/web/square_set.php
diff --git a/web/status_submit_list.php b/web/status_submit_list.php
new file mode 100644
index 0000000..57bf003
--- /dev/null
+++ b/web/status_submit_list.php
@@ -0,0 +1,147 @@
+<?php
+require_once('common.php');
+
+function status_submit_list($sqlc,$paramo,$useronly){
+ $submitoff = $paramo->submitoff;
+ $submitid = $paramo->submitid;
+ $proid = $paramo->proid;
+ $result = $paramo->result;
+
+ if($useronly == true){
+ $userid = $_COOKIE['userid'];
+ $usersec = $_COOKIE['usersec'];
+ if(!sec_checkuser($userid,$usersec)){
+ return null;
+ }
+ $userid = pg_escape_string($userid);
+ }
+ if(gettype($submitoff) != 'integer' || $submitoff < 0){
+ $submitoff = -1;
+ }
+ if(gettype($submitid) != 'integer' || $submitid < 1){
+ $submitid = -1;
+ }
+ if(gettype($proid) != 'integer' || $proid < 1){
+ $proid = -1;
+ }
+ if(gettype($result) != 'integer'){
+ $result = -100;
+ }
+ if($submitoff == -1 && $submitid == -1){
+ return null;
+ }
+
+ $submitlist = array();
+ $useridlist = array();
+
+ if($submitoff != -1){
+ $submitoff = pg_escape_string($submitoff);
+ $sqlstr = 'SELECT "submitid","proid","userid","timestamp","result","sumscore","summaxscore","sumruntime" FROM "submit" ';
+
+ if($useronly == true){
+ $sqlr = pg_query_params($sqlc,$sqlstr.'WHERE "userid"=$1 ORDER BY "submitid" DESC LIMIT 20 OFFSET $2;',
+ array($userid,$submitoff));
+ }else if($proid != -1 && $result != -100){
+ $sqlr = pg_query_params($sqlc,$sqlstr.'WHERE "proid"=$1 AND "result"=$2 ORDER BY "sumruntime" ASC LIMIT 20 OFFSET $3;',
+ array($proid,$result,$submitoff));
+ }else if($proid != -1 && $result == -100){
+ $sqlr = pg_query_params($sqlc,$sqlstr.'WHERE "proid"=$1 AND "result"<>100 ORDER BY "submitid" DESC LIMIT 20 OFFSET $2;',
+ array($proid,$submitoff));
+ }else{
+ $sqlr = pg_query_params($sqlc,$sqlstr.'ORDER BY "submitid" DESC LIMIT 20 OFFSET $1;',
+ array($submitoff));
+ }
+
+ while($submito = pg_fetch_object($sqlr)){
+ $submitlist[] = array(
+ 'submitid' => $submito->submitid,
+ 'proid' => $submito->proid,
+ 'userid' => $submito->userid,
+ 'timestamp' => $submito->timestamp,
+ 'result' => $submito->result,
+ 'sumscore' => $submito->sumscore,
+ 'summaxscore' => $submito->summaxscore,
+ 'sumruntime' => $submito->sumruntime);
+ $useridlist[$submito->userid] = '';
+ }
+ pg_free_result($sqlr);
+ }
+
+ if($submitid != -1){
+ $sqlstr = 'SELECT "submitid","proid","userid",array_to_string("status",\',\') AS "status",array_to_string("score",\',\') AS "score",array_to_string("maxscore",\',\') AS "maxscore",array_to_string("runtime",\',\') AS "runtime",array_to_string("peakmem",\',\') AS "peakmem","timestamp","result","sumscore","summaxscore","sumruntime" FROM "submit" ';
+
+ if($submitid != 2147483647){
+ $submitid = pg_escape_string($submitid);
+ $sqlr = pg_query_params($sqlc,$sqlstr.'WHERE "submitid"=$1 LIMIT 1;',
+ array($submitid));
+ }else{
+ if($useronly == true){
+ $sqlr = pg_query_params($sqlc,$sqlstr.'WHERE "userid"=$1 ORDER BY "submitid" DESC LIMIT 1;',
+ array($userid));
+ }else if($proid != -1 && $result != -100){
+ $sqlr = pg_query_params($sqlc,$sqlstr.'WHERE "proid"=$1 AND "result"=$2 ORDER BY "sumruntime" ASC LIMIT 1;',
+ array($proid,$result));
+ }else if($proid != -1 && $result == -100){
+ $sqlr = pg_query_params($sqlc,$sqlstr.'WHERE "proid"=$1 AND "result"<>100 ORDER BY "submitid" DESC LIMIT 1;',
+ array($proid));
+ }else{
+ $sqlr = pg_query($sqlc,$sqlstr.'ORDER BY "submitid" DESC LIMIT 1;');
+ }
+ }
+
+ while($submito = pg_fetch_object($sqlr)){
+ $submitlist[] = array(
+ 'submitid' => $submito->submitid,
+ 'proid' => $submito->proid,
+ 'userid' => $submito->userid,
+ 'status' => $submito->status,
+ 'score' => $submito->score,
+ 'maxscore' => $submito->maxscore,
+ 'runtime' => $submito->runtime,
+ 'peakmem' => $submito->peakmem,
+ 'timestamp' => $submito->timestamp,
+ 'result' => $submito->result,
+ 'sumscore' => $submito->sumscore,
+ 'summaxscore' => $submito->summaxscore,
+ 'sumruntime' => $submito->sumruntime);
+ $useridlist[$submito->userid] = '';
+ }
+ pg_free_result($sqlr);
+ }else{
+ $submitlist[] = null;
+ }
+
+ $sqlr = pg_query($sqlc,'SELECT "userid","nickname" FROM "user" WHERE "userid" IN ('.implode(',',array_keys($useridlist)).');');
+
+ while($sqlo = pg_fetch_object($sqlr)){
+ $useridlist[$sqlo->userid] = $sqlo->nickname;
+ }
+ pg_free_result($sqlr);
+
+ for($idx = 0;$idx < count($submitlist);$idx++){
+ if($submitlist[$idx] != null){
+ $submitlist[$idx]['nickname'] = $useridlist[$submitlist[$idx]['userid']];
+ }
+ }
+
+ if($useronly == true){
+ $sqlr = pg_query_params('SELECT COUNT(*) FROM "submit" WHERE "userid"=$1;',
+ array($userid));
+ }else if($proid != -1 && $result != -100){
+ $sqlr = pg_query_params('SELECT COUNT(*) FROM "submit" WHERE "proid"=$1 AND "result"=$2;',
+ array($proid,$result));
+ }else if($proid != -1 && $result == -100){
+ $sqlr = pg_query_params('SELECT COUNT(*) FROM "submit" WHERE "proid"=$1 AND "result"<>100;',
+ array($proid));
+ }else{
+ $sqlr = pg_query('SELECT COUNT(*) FROM "submit";');
+ }
+ $submitcount = pg_fetch_row($sqlr)[0];
+ pg_free_result($sqlr);
+
+ return array(
+ 'submitcount' => $submitcount,
+ 'submitlist' => $submitlist
+ );
+}
+?>
diff --git a/web/status_viewcode.php b/web/status_viewcode.php
new file mode 100644
index 0000000..0bf1fb4
--- /dev/null
+++ b/web/status_viewcode.php
@@ -0,0 +1,30 @@
+<?php
+require_once('common.php');
+
+$userid = $_COOKIE['userid'];
+$usersec = $_COOKIE['usersec'];
+$submitid = $_POST['submitid'];
+
+if(!sec_checkuser($userid,$usersec)){
+ exit('Eerror');
+}
+if($submitid == '' || strval(intval($submitid)) != $submitid){
+ exit('Eerror');
+}
+
+$sqlc = pg_connect('host=localhost port=5432 dbname='.DB_NAME.' user='.DB_USER.' password='.DB_PASSWORD);
+
+$userid = pg_escape_string($userid);
+$submitid = pg_escape_string($submitid);
+$sqlr = pg_query_params($sqlc,'SELECT "submitid" FROM "submit" WHERE "userid"=$1 AND "submitid"=$2 LIMIT 1',
+ array($userid,$submitid));
+if(pg_num_rows($sqlr) == 0){
+ pg_free_result($sqlr);
+ pg_close($sqlc);
+ exit('Eerror');
+}
+pg_free_result($sqlr);
+pg_close($sqlc);
+
+echo json_encode(['code' => file_get_contents('submit/'.$submitid.'_submit.cpp')]);
+?>
diff --git a/web/user_get.php b/web/user_get.php
new file mode 100644
index 0000000..85b0127
--- /dev/null
+++ b/web/user_get.php
@@ -0,0 +1,65 @@
+<?php
+require_once('common.php');
+
+$userid = intval($_POST['userid']);
+
+if(gettype($userid) != 'integer' || $userid < 1){
+ exit('Eerror');
+}
+
+$sqlc = pg_connect('host=localhost port=5432 dbname='.DB_NAME.' user='.DB_USER.' password='.DB_PASSWORD);
+
+$userid = pg_escape_string($userid);
+$sqlr = pg_query_params($sqlc,'SELECT * FROM "user" WHERE "userid"=$1 LIMIT 1;',
+ array($userid));
+
+if(($usero = pg_fetch_object($sqlr)) == null){
+ pg_free_result($sqlr);
+ pg_close($sqlc);
+ exit('Eerror');
+}
+pg_free_result($sqlr);
+
+$sqlr = pg_query_params($sqlc,'SELECT COUNT(DISTINCT "proid") FROM "submit" WHERE "userid"=$1 AND "result"=0;',
+ array($userid));
+$acceptcount = pg_fetch_row($sqlr)[0];
+pg_free_result($sqlr);
+
+$sqlr = pg_query_params($sqlc,'SELECT COUNT(DISTINCT "proid") FROM "submit" WHERE "userid"=$1;',
+ array($userid));
+$trycount = pg_fetch_row($sqlr)[0];
+pg_free_result($sqlr);
+
+$sqlr = pg_query_params($sqlc,'SELECT COUNT("proid") FROM "submit" WHERE "userid"=$1;',
+ array($userid));
+$submitcount = pg_fetch_row($sqlr)[0];
+pg_free_result($sqlr);
+
+$userinfo = array(
+ 'userid' => $usero->userid,
+ 'username' => $usero->username,
+ 'nickname' => $usero->nickname,
+ 'headimg' => $usero->headimg,
+ 'aboutme' => $usero->aboutme,
+ 'acceptcount' => $acceptcount,
+ 'submitcount' => $submitcount,
+ 'trycount' => $trycount);
+
+$sqlr = pg_query_params($sqlc,'SELECT "proid",MAX("sumscore"/"summaxscore") AS "rate" FROM "submit" WHERE "userid"=$1 AND "result"<>100 GROUP BY "proid" ORDER BY "proid";',
+ array($userid));
+
+$prolist = array();
+while($sqlo = pg_fetch_object($sqlr)){
+ $prolist[] = array(
+ 'proid' => $sqlo->proid,
+ 'rate' => $sqlo->rate * 100);
+}
+pg_free_result($sqlr);
+
+pg_close($sqlc);
+
+echo json_encode(array(
+ 'userinfo' => $userinfo,
+ 'prolist' => $prolist
+));
+?>
diff --git a/web/user_login.php b/web/user_login.php
new file mode 100644
index 0000000..1f455c2
--- /dev/null
+++ b/web/user_login.php
@@ -0,0 +1,32 @@
+<?php
+require_once('common.php');
+
+$username = $_POST['username'];
+$password = $_POST['password'];
+
+if($username == '' || strlen($username) > 16 || $username != pg_escape_string($username)){
+ exit('Eerror');
+}
+if($password == '' || strlen($password) > 128){
+ exit('Eerror');
+}
+
+$sqlc = pg_connect('host=localhost port=5432 dbname='.DB_NAME.' user='.DB_USER.' password='.DB_PASSWORD);
+
+$username = pg_escape_string($username);
+$password = hash('sha512',$password);
+$sqlr = pg_query_params($sqlc,'SELECT "userid" FROM "user" WHERE "username"=$1 AND "password"=$2 LIMIT 1;',
+ array($username,$password));
+if(($sqlo = pg_fetch_object($sqlr)) == null){
+ pg_free_result($sqlr);
+ pg_close($sqlc);
+ exit('Eerror');
+}
+$userid = $sqlo->userid;
+pg_free_result($sqlr);
+pg_close($sqlc);
+
+setcookie('userid',$userid,time() + 31536000);
+setcookie('usersec',hash('sha512',$userid.SEC_SALT),time() + 31536000);
+echo 'S';
+?>
diff --git a/web/user_register.php b/web/user_register.php
new file mode 100644
index 0000000..a728e64
--- /dev/null
+++ b/web/user_register.php
@@ -0,0 +1,41 @@
+<?php
+require_once('common.php');
+
+$username = $_POST['username'];
+$password = $_POST['password'];
+$nickname = $_POST['nickname'];
+
+if($username == '' || strlen($username) > 16 || $username != pg_escape_string($username)){
+ exit('Eusername');
+}
+if($password == '' || strlen($password) > 128){
+ exit('Epassword');
+}
+if($nickname == '' || strlen($nickname) > 16 || $nickname != pg_escape_string($nickname)){
+ exit('Enickname');
+}
+
+$sqlc = pg_connect('host=localhost port=5432 dbname='.DB_NAME.' user='.DB_USER.' password='.DB_PASSWORD);
+
+$username = pg_escape_string($username);
+$sqlr = pg_query_params($sqlc,'SELECT "username" FROM "user" WHERE "username"=$1 LIMIT 1;',
+ array($username));
+if(pg_num_rows($sqlr) > 0){
+ pg_free_result($sqlr);
+ pg_close($sqlc);
+ exit('Eexist');
+}
+pg_free_result($sqlr);
+
+$password = hash('sha512',$password);
+$sqlr = pg_query_params($sqlc,'INSERT INTO "user" ("username","password","nickname") VALUES($1,$2,$3) RETURNING "userid";',
+ array($username,$password,$nickname));
+$userid = pg_fetch_row($sqlr)[0];
+pg_free_result($sqlr);
+
+pg_close($sqlc);
+
+setcookie('userid',$userid,time() + 31536000);
+setcookie('usersec',hash('sha512',$userid.SEC_SALT),time() + 31536000);
+echo 'S';
+?>
diff --git a/web/user_set.php b/web/user_set.php
new file mode 100644
index 0000000..de5ea32
--- /dev/null
+++ b/web/user_set.php
@@ -0,0 +1,109 @@
+<?php
+require_once('common.php');
+
+$userid = $_COOKIE['userid'];
+$usersec = $_COOKIE['usersec'];
+$type = $_POST['type'];
+
+if(!sec_checkuser($userid,$usersec)){
+ exit('Euser');
+}
+$userid = pg_escape_string($userid);
+
+$sqlc = pg_connect('host=localhost port=5432 dbname='.DB_NAME.' user='.DB_USER.' password='.DB_PASSWORD);
+
+if($type == 'userinfo'){
+ $nickname = $_POST['nickname'];
+ $aboutme = $_POST['aboutme'];
+ $headimg = $_POST['headimg'];
+
+ if($nickname == '' || strlen($nickname) > 16 || $nickname != pg_escape_string($nickname)){
+ exit('Enickname');
+ }
+ if(strlen($aboutme) > 4096){
+ exit('Eaboutme');
+ }
+ if($headimg == '' || strlen($headimg) > 4096){
+ exit('Eheadimg');
+ }
+
+ $sqlr = pg_query_params($sqlc,'UPDATE "user" SET "nickname"=$1,"aboutme"=$2,"headimg"=$3 WHERE "userid"=$4;',
+ array($nickname,$aboutme,$headimg,$userid));
+
+ pg_free_result($sqlr);
+}else if($type == 'squareadd'){
+ $squareid = $_POST['squareid'];
+
+ if($squareid == '' || strval(intval($squareid)) != $squareid){
+ exit('Eerror');
+ }
+
+ $squareid = pg_escape_string($squareid);
+ $sqlr = pg_query_params($sqlc,'SELECT "squareid" FROM "square" WHERE "squareid"=$1 LIMIT 1',
+ array($squareid));
+
+ if(pg_num_rows($sqlr) == 0){
+ exit('Eerror');
+ pg_free_result($sqlr);
+ }
+ pg_free_result($sqlr);
+
+ $sqlr = pg_query_params($sqlc,'SELECT array_to_string("squarelist",\',\') AS "squarelist" FROM "user" WHERE "userid"=$1 LIMIT 1;',
+ array($userid));
+
+ if(($sqlo = pg_fetch_object($sqlr)) == null){
+ pg_free_result($sqlr);
+ exit('Eerror');
+ }
+ $squarelist = explode(',',$sqlo->squarelist);
+ pg_free_result($sqlr);
+
+ for($idx = 0;$idx < count($squarelist);$idx++){
+ if($squarelist[$idx] == $squareid){
+ exit('Eerror');
+ }
+ }
+ $squarelist[] = $squareid;
+
+ $sqlr = pg_query_params($sqlc,'UPDATE "user" SET "squarelist"=\'{'.implode(',',$squarelist).'}\' WHERE "userid"=$1;',
+ array($userid));
+
+ pg_free_result($sqlr);
+}else if($type == 'squareremove'){
+ $squareid = $_POST['squareid'];
+
+ if($squareid == '' || strval(intval($squareid)) != $squareid){
+ exit('Eerror');
+ }
+ if($squareid == '1'){
+ exit('Ecant');
+ }
+
+ $sqlr = pg_query_params($sqlc,'SELECT array_to_string("squarelist",\',\') AS "squarelist" FROM "user" WHERE "userid"=$1 LIMIT 1;',
+ array($userid));
+
+ if(($sqlo = pg_fetch_object($sqlr)) == null){
+ pg_free_result($sqlr);
+ exit('Eerror');
+ }
+ $squarelist = explode(',',$sqlo->squarelist);
+ pg_free_result($sqlr);
+
+ for($idx = 0;$idx < count($squarelist);$idx++){
+ if($squarelist[$idx] == $squareid){
+ array_splice($squarelist,$idx,1);
+ break;
+ }
+ }
+
+ $sqlr = pg_query_params($sqlc,'UPDATE "user" SET "squarelist"=\'{'.implode(',',$squarelist).'}\' WHERE "userid"=$1;',
+ array($userid));
+
+ pg_free_result($sqlr);
+}else{
+ exit('Eerror');
+}
+
+pg_close($sqlc);
+echo 'S';
+?>
diff --git a/web/viewcode.html b/web/viewcode.html
new file mode 100644
index 0000000..bb39f9e
--- /dev/null
+++ b/web/viewcode.html
@@ -0,0 +1,54 @@
+<html>
+<head>
+<script src="https://ajax.googleapis.com/ajax/libs/prototype/1.7.1.0/prototype.js"></script>
+
+<script type="text/javascript" src="http://codemirror.net/lib/codemirror.js"></script>
+<link rel="stylesheet" href="http://codemirror.net/lib/codemirror.css">
+<link rel="stylesheet" href="http://codemirror.net/theme/lesser-dark.css">
+<script type="text/javascript" src="http://codemirror.net/mode/clike/clike.js"></script>
+
+<script type="text/javascript" src="nor.js"></script>
+<link rel=stylesheet type="text/css" href="nor.css">
+
+<script type="text/javascript">
+function init(){
+ var submitid;
+
+ submitid = nor_getparam().submitid;
+
+ new Ajax.Request('status_viewcode.php',{
+ method:'post',
+ parameters:{'submitid':submitid},
+ onSuccess:function(transport){
+ var res;
+ var code;
+ var e_codemirror;
+
+ res = transport.responseText;
+ if(res[0] == 'E'){
+ code = '錯誤';
+ }else{
+ code = JSON.parse(res).code;
+ }
+
+ e_codemirror = CodeMirror(document.body,{
+ mode:'text/x-c++src',
+ theme:'lesser-dark',
+ lineNumbers:true,
+ matchBrackets:true,
+ indentUnit:4,
+ value:code
+ });
+
+ e_codemirror.getWrapperElement().style.width = '100%';
+ e_codemirror.getWrapperElement().style.height = '100%';
+ e_codemirror.getScrollerElement().style.width = '100%';
+ e_codemirror.getScrollerElement().style.height = '100%';
+ }
+ });
+}
+</script>
+</head>
+<body style="width:100%; height:100%; margin:0px 0px;" onload='init();'></body>
+</html>
+