diff options
author | LAN-TW <lantw44@gmail.com> | 2013-05-04 02:34:41 +0800 |
---|---|---|
committer | LAN-TW <lantw44@gmail.com> | 2013-05-04 02:34:55 +0800 |
commit | 3e5eb3a04d2772f4e6d746f99014845f6503223e (patch) | |
tree | 948185ddedb0805809463522db921a08e332fcb4 | |
parent | f32ce06a7c13bb6803e7062562781bb9f8619b41 (diff) | |
parent | 7557a467ea27ca6e0b0ea25b1d903d63a324ee11 (diff) | |
download | taiwan-online-judge-lantw44-master.tar.gz taiwan-online-judge-lantw44-master.tar.zst taiwan-online-judge-lantw44-master.zip |
Taiwan Online Judge upstream start developing the new version using python.
I will not provide any updates until the new python version reaches stable.
-rw-r--r-- | web/index.html | 17 | ||||
-rw-r--r-- | web/jcs/index.css | 30 | ||||
-rw-r--r-- | web/jcs/index.js | 2 | ||||
-rw-r--r-- | web/jcs/pro.js | 33 | ||||
-rw-r--r-- | web/jcs/user.js | 33 | ||||
-rw-r--r-- | web/php/problem.php | 9 | ||||
-rw-r--r-- | web/pmod/pmod_test/pmod_test.css | 102 | ||||
-rw-r--r-- | web/pmod/pmod_test/pmod_test.html | 106 | ||||
-rw-r--r-- | web/pmod/pmod_test/pmod_test.inc.php | 29 | ||||
-rw-r--r-- | web/pmod/pmod_test/pmod_test.js | 244 | ||||
-rw-r--r-- | web/pmod/pmod_test/pmod_test.php | 110 |
11 files changed, 599 insertions, 116 deletions
diff --git a/web/index.html b/web/index.html index 8f68a8b..a96b73a 100644 --- a/web/index.html +++ b/web/index.html @@ -9,6 +9,7 @@ <link rel="stylesheet" type="text/css" href="/codemirror.css"> <link rel="stylesheet" type="text/css" href="/lesser-dark.css"> +<link rel="stylesheet" type="text/css" href="/toj/jcs/ui.css"> <link rel="stylesheet" type="text/css" href="/toj/jcs/common.css"> <link rel="stylesheet" type="text/css" href="/toj/jcs/index.css"> <link rel="stylesheet" type="text/css" href="/toj/jcs/notice.css"> @@ -23,6 +24,10 @@ <script type="text/javascript" src="https://www.google.com/jsapi"></script> <script type="text/javascript" src="/codemirror.js"></script> <script type="text/javascript" src="/clike.js"></script> +<script type="text/javascript" src="/xml.js"></script> +<script type="text/javascript" src="/javascript.js"></script> +<script type="text/javascript" src="/css.js"></script> +<script type="text/javascript" src="/htmlmixed.js"></script> <script type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script> <script type="text/x-mathjax-config"> MathJax.Hub.Config({ @@ -148,8 +153,14 @@ select{ <li class="button home"><a href="/toj/home/" class="button">首頁</a></li> <li class="button stat"><a href="/toj/stat/sub/" class="button">狀態</a></li> <li class="button user" style="display:none;"><a class="button">個人</a></li> - <li class="button square"><a class="button">方塊</a></li> - <ul class="square_box"></ul> + <li class="button square" style="display:none;"><a class="button">方塊</a></li> + <ul class="square_box"> + <li class="button mgsq"><a class="button"><strong>管理方塊</strong></a></li> + <li class="title"><span class="title">進行中</span></li> + <ul class="run"></ul> + <li class="title"><span class="title">已結束</span></li> + <ul class="past"></ul> + </ul> <li class="button login" style="margin:64px 0px 0px 0px; display:none;"><a href="/toj/login/" class="button">登入</a></li> <li class="button register" style="display:none;"><a href="/toj/register/" class="button">註冊</a></li> @@ -319,7 +330,7 @@ select{ <div class="sq_page"></div> - <div class="com_pbox pro_pbox"></div> + <div class="pro_page"></div> <div class="com_pbox login_pbox"> <div class="info_box"> diff --git a/web/jcs/index.css b/web/jcs/index.css index 16da330..62de39e 100644 --- a/web/jcs/index.css +++ b/web/jcs/index.css @@ -140,17 +140,43 @@ ul.index_panel > ul.square_box{ overflow:hidden; display:none; } -ul.index_panel > ul.square_box > li.button{ +ul.index_panel > ul.square_box ul{ + width:100%; + margin:0px 0px; + padding:0px 0px; + list-style:none; + overflow:hidden; +} +ul.index_panel > ul.square_box li.title{ + width:auto; + height:32px; + margin:6px 0px 0px 0px; + padding:0px 0px 0px 32px; + line-height:32px; + border-bottom:#BDC0BA 1px solid; +} +ul.index_panel > ul.square_box li.button{ width:auto; height:32px; padding:0px 0px 0px 32px; font-size:16px; line-height:32px; } -ul.index_panel > ul.square_box > li:hover.button{ +ul.index_panel > ul.square_box li:hover.button{ color:#FFFFFF; background-color:rgba(255,255,255,0.2); } +ul.index_panel span.title{ + width:100%; + height:100%; + color:#BDC0BA; + font-size:16px; + font-weight:bold; + position:relative; + top:0px; + left:50%; + display:block; +} ul.index_panel a.button{ width:100%; height:100%; diff --git a/web/jcs/index.js b/web/jcs/index.js index 1d90756..262b5fa 100644 --- a/web/jcs/index.js +++ b/web/jcs/index.js @@ -23,6 +23,7 @@ var index = new function(){ j_panel.addClass('panel_m'); $('#index_panel_box').stop().css('opacity','1').animate({width:240},'slow','easeOutExpo'); + $('#index_panel span.title').stop().animate({left:0},'slow','easeOutQuart'); $('#index_panel a.button').stop().animate({left:0},'slow','easeOutQuart'); } }else{ @@ -31,6 +32,7 @@ var index = new function(){ $('#index_panel_box').stop().animate({opacity:0},'fast','easeOutQuad', function(){ $('#index_panel_box').css('width','0px'); + $('#index_panel span.title').css('left','50%'); $('#index_panel a.button').css('left','50%'); that.page_scroll_unlock(); diff --git a/web/jcs/pro.js b/web/jcs/pro.js index b2ea9ba..b922be0 100644 --- a/web/jcs/pro.js +++ b/web/jcs/pro.js @@ -1,12 +1,12 @@ var pro = new function(){ var that = this; - var j_pbox = null; - var pro_pbox = null; + var j_page = null; + var pro_page = null; var pro_proid = null; var pro_pmodname = null; that.init = function(){ - j_pbox = $('#index_page > div.pro_pbox'); + j_page = $('#index_page > div.pro_page'); that.sub_mbox = new class_pro_sub_mbox(); @@ -15,14 +15,15 @@ var pro = new function(){ var proid; var _clean = function(){ - if(pro_pbox != null){ - that.node.child_del(pro_pbox.node); + if(pro_page != null){ + that.node.child_del(pro_page.node); } - j_pbox.empty(); - j_pbox.removeClass(pro_pmodname); + j_page.empty(); + j_page.removeClass(pro_pmodname); + index.tab_empty(); index.content_empty(); - pro_pbox = null; + pro_page = null; pro_proid = null; pro_pmodname = null; }; @@ -55,14 +56,14 @@ var pro = new function(){ css = $('<link rel="stylesheet" type="text/css" href="/toj/pmod/' + pro_pmodname + '/' + pro_pmodname + '.css">'); $('head').append(css); css.ready(function(){ - j_pbox.addClass(pro_pmodname); + j_page.addClass(pro_pmodname); $.get('/toj/pmod/' + pro_pmodname + '/' + pro_pmodname + '.html',{},function(res){ - j_pbox.html(res); + j_page.html(res); $.getScript('/toj/pmod/' + pro_pmodname + '/' + pro_pmodname + '.js',function(script,stat,res){ - pro_pbox = new class_pro_pbox(pro_proid,reto.proname); - eval('new ' + pro_pmodname + '(pro_pbox,j_pbox)'); - that.node.child_set(pro_pbox.node); + pro_page = new class_pro_page(pro_proid,reto.proname); + eval('new ' + pro_pmodname + '(pro_page,j_page)'); + that.node.child_set(pro_page.node); }); }); }); @@ -80,9 +81,9 @@ var pro = new function(){ }; }; -var class_pro_pbox = function(proid,proname){ +var class_pro_page = function(proid,proname){ var that = this; - var j_pbox = $('#index_page > div.pro_pbox'); + var j_page = $('#index_page > div.pro_page'); that.proid = proid; that.proname = proname; @@ -97,7 +98,7 @@ var class_pro_pbox = function(proid,proname){ pro.sub_mbox.init(proid); com.url_push('/toj/m/pro_sub/'); }; -}; __extend(class_pro_pbox,class_com_pbox); +}; __extend(class_pro_page,class_com_pbox); var class_pro_sub_mbox = function(){ var that = this; diff --git a/web/jcs/user.js b/web/jcs/user.js index 4aa7252..81e30ca 100644 --- a/web/jcs/user.js +++ b/web/jcs/user.js @@ -126,6 +126,9 @@ var user = new function(){ index.panel_show('logout'); index.panel_set('user','/toj/user/' + that.uid + '/main/','個人'); index.panel_show('user'); + index.panel_show('square'); + + $('#index_panel > ul.square_box > li.mgsq > a.button').attr('href','/toj/user/' + that.uid + '/mgsq/'); }else{ j_notice.hide(); j_nickname.attr('href',''); @@ -136,20 +139,26 @@ var user = new function(){ index.panel_hide('logout'); index.panel_set('user',null,'個人'); index.panel_hide('user'); + index.panel_hide('square'); + + $('#index_panel > ul.square_box > li.mgsq > a.button').attr('href',null); } }); that.data_chg.add(function(){ var i; - var j_ul; - var j_li; + var j_ul_run; + var j_ul_past; var sqo; + var idx_run; + var idx_past; + var panelsq_listadd = function(j_ul,idx,sqid,sqname){ var j_li; var j_a; - j_li = $(j_ul.find('li.button')[idx]); + j_li = $(j_ul.find('li.square')[idx]); if(j_li.length == 0){ - j_li = $('<li class="button"><a class="button"></a></li>'); + j_li = $('<li class="button square"><a class="button"></a></li>'); j_li.hide(); j_ul.append(j_li); } @@ -163,12 +172,22 @@ var user = new function(){ $('#index_head_nickname > a.nickname').text(that.nickname); - j_ul = $('#index_panel > ul.square_box'); - j_ul.find('li.button').hide(); + j_ul_run = $('#index_panel > ul.square_box > ul.run'); + j_ul_run.find('li.square').hide(); + idx_run = 0; + j_ul_past = $('#index_panel > ul.square_box > ul.past'); + j_ul_past.find('li.square').hide(); + idx_past = 0; for(i = 0;i < user.sq_inlist.length;i++){ sqo = user.sq_inlist[i]; if(sqo.relationship != 1){ - panelsq_listadd(j_ul,i,sqo.sqid,sqo.sqname); + if(sqo.state == 1){ + panelsq_listadd(j_ul_run,idx_run,sqo.sqid,sqo.sqname); + idx_run++; + }else if(sqo.state == 2){ + panelsq_listadd(j_ul_past,idx_past,sqo.sqid,sqo.sqname); + idx_past++; + } } } }); diff --git a/web/php/problem.php b/web/php/problem.php index 69bb2f4..4ef43f3 100644 --- a/web/php/problem.php +++ b/web/php/problem.php @@ -4,6 +4,7 @@ require_once('problem.inc.php'); require_once('user.inc.php'); +require_once('event.inc.php'); $sqlc = db_connect(); @@ -50,8 +51,9 @@ if($action == 'add_pro') die('Eproname_too_short'); if(strlen($dt->proname) > PRONAME_LEN_MAX) die('Eproname_too_long'); - - if(!problem::getmod($sqlc, $dt->modid)) + + $mod = problem::getmod($sqlc, $dt->modid); + if(!$mod) die('Ewrong_modid'); if($dt->hidden !== true && $dt->hidden !== false) @@ -65,6 +67,9 @@ if($action == 'add_pro') if(!$pro) die('Eadd_problem'); + if(event::exec_func('../pmod/'.$mod->pmodname.'/'.$mod->pmodname.'.inc.php','event_create',[$pro->proid]) === false) + die('Eevent_error'); + echo(json_encode($pro)); } if($action == 'edit_pro') diff --git a/web/pmod/pmod_test/pmod_test.css b/web/pmod/pmod_test/pmod_test.css index f8a48a6..c238c44 100644 --- a/web/pmod/pmod_test/pmod_test.css +++ b/web/pmod/pmod_test/pmod_test.css @@ -1,48 +1,126 @@ -div.pmod_test > div.info{ +div.pmod_test > div.pro_pbox > div.info{ width:240px; float:left; } -div.pmod_test > div.info > table.statlist{ +div.pmod_test > div.pro_pbox > div.info > table.statlist{ width:100%; text-align:left; border-collapse:collapse; } -div.pmod_test > div.info > table.statlist td.name{ +div.pmod_test > div.pro_pbox > div.info > table.statlist td.name{ width:76px; } -div.pmod_test > div.info > table.statlist td.value{ +div.pmod_test > div.pro_pbox > div.info > table.statlist td.value{ width:auto; padding:0px 0px 0px 6px; } -div.pmod_test > div.info > table.limitlist{ +div.pmod_test > div.pro_pbox > div.info > table.limitlist{ width:100%; text-align:left; border-collapse:collapse; } -div.pmod_test > div.info > table.limitlist td.name{ +div.pmod_test > div.pro_pbox > div.info > table.limitlist td.name{ width:76px; } -div.pmod_test > div.info > table.limitlist td.value{ +div.pmod_test > div.pro_pbox > div.info > table.limitlist td.value{ width:auto; padding:0px 0px 0px 6px; } -div.pmod_test > div.info > table.scorelist{ +div.pmod_test > div.pro_pbox > div.info > table.scorelist{ width:100%; text-align:left; border-collapse:collapse; } -div.pmod_test > div.info > table.scorelist th.no,div.pmod_test > div.info > table.scorelist td.no{ +div.pmod_test > div.pro_pbox > div.info > table.scorelist th.no,div.pmod_test > div.pro_pbox > div.info > table.scorelist td.no{ width:76px; } -div.pmod_test > div.info > table.scorelist th.score,div.pmod_test > div.info > table.scorelist td.score{ +div.pmod_test > div.pro_pbox > div.info > table.scorelist th.score,div.pmod_test > div.pro_pbox > div.info > table.scorelist td.score{ width:auto; padding:0px 0px 0px 6px; } -div.pmod_test > div.content{ +div.pmod_test > div.pro_pbox > div.content{ width:978px; margin:0px 0px 0px 6px; float:left; } -div.pmod_test p{ +div.pmod_test > div.pro_pbox p{ text-indent:32px; } + + + +div.pmod_test > div.edit_pbox > div.edit_box{ + width:976px; + margin:0px 0px 0px 246px; + padding:0px 0px 32px 0px; +} +div.pmod_test > div.edit_pbox > div.edit_box input{ + width:228px; + margin:0px 0px 16px 0px; +} +div.pmod_test > div.edit_pbox > div.edit_box > div.contentbox{ + width:100%; + height:512px; + padding:0px 0px 32px 0px; +} +div.pmod_test > div.edit_pbox > div.testdata_box{ + width:976px; + margin:0px 0px 0px 246px; + padding:0px 0px 32px 0px; +} +div.pmod_test > div.edit_pbox > div.testdata_box > table.table{ + margin:32px 0px 32px 0px; + border-collapse:collapse; + text-align:left; +} +div.pmod_test > div.edit_pbox > div.testdata_box > table.table tr.head{ + height:64px +} +div.pmod_test > div.edit_pbox > div.testdata_box > table.table tr.item{ + height:64px +} +div.pmod_test > div.edit_pbox > div.testdata_box > table.table th,div.pmod_test > div.edit_pbox > div.testdata_box > table.table td{ + width:76px; + padding:0px 0px 0px 6px; +} +div.pmod_test > div.edit_pbox > div.testdata_box > table.table th.no,div.pmod_test > div.edit_pbox > div.testdata_box > table.table td.no{ + padding:0px 0px 0px 0px; +} + +div.pmod_test > div.edit_pbox > div.testdata_box > table.table td.score > input{ + width:35px; +} +div.pmod_test > div.edit_pbox > div.testdata_box > table.table th.file,div.pmod_test > div.edit_pbox > div.testdata_box > table.table td.file{ + width:322px; +} + +div.pmod_test > div.edit_pbox div.prog_box{ + width:486px; + height:16px; + margin:0px 0px 16px 0px; + background-color:rgba(255,255,255,0.2); + color:#1C1C1C; + font-size:12px; + font-family:monospace; + line-height:16px; + text-align:right; + position:relative; +} +div.pmod_test > div.edit_pbox div.prog_box > div.total{ + width:0%; + height:16px; + position:absolute; + top:0px; + left:0%; + overflow:hidden; +} +div.pmod_test > div.edit_pbox div.prog_box > div.prog{ + width:0%; + height:16px; + background-color:#3A8FB7; + font-weight:bold; + position:absolute; + top:0px; + left:0px; + overflow:hidden; +} diff --git a/web/pmod/pmod_test/pmod_test.html b/web/pmod/pmod_test/pmod_test.html index 7f1a1b8..a04c2a6 100644 --- a/web/pmod/pmod_test/pmod_test.html +++ b/web/pmod/pmod_test/pmod_test.html @@ -1,38 +1,76 @@ -<div class="info"> - <h2 class="proid">ProID:</h2> - <button class="submit">上傳</button> +<div class="com_pbox pro_pbox"> + <div class="info"> + <h2 class="proid">ProID:</h2> + <button class="submit">上傳</button> - <h3>狀態</h3> - <table class="statlist"> - <tr> - <td class="name">最佳分數</td> - <td class="value bscore"></td> - </tr> - <tr> - <td class="name">解題狀態</td> - <td class="value stat"></td> - </tr> - </table> + <h3>狀態</h3> + <table class="statlist"> + <tr> + <td class="name">最佳分數</td> + <td class="value bscore"></td> + </tr> + <tr> + <td class="name">解題狀態</td> + <td class="value stat"></td> + </tr> + </table> - <h3>限制</h3> - <table class="limitlist"> - <tr> - <td class="name">執行時間</td> - <td class="value timelimit"></td> - </tr> - <tr> - <td class="name">記憶體</td> - <td class="value memlimit"></td> - </tr> - </table> + <h3>限制</h3> + <table class="limitlist"> + <tr> + <td class="name">執行時間</td> + <td class="value timelimit"></td> + </tr> + <tr> + <td class="name">記憶體</td> + <td class="value memlimit"></td> + </tr> + </table> - <h3>配分</h3> - <table class="scorelist"> - <tr class="head"> - <th class="no">#</th> - <th class="score">Score</th> - </tr> - </table> + <h3>配分</h3> + <table class="scorelist"> + <tr class="head"> + <th class="no">#</th> + <th class="score">Score</th> + </tr> + </table> + </div> + <div class="content"></div> + <div style="width:100%; height:32px; clear:both;"></div> +</div> +<div class="com_pbox edit_pbox"> + <div class="edit_box"> + <h2>限制</h2> + <label>執行時間限制(ms)</label> + <input name="timelimit" type="textbox" placeholder="1000"> + <label>記憶體限制(KB)</label> + <input name="memlimit" type="textbox" placeholder="65536"> + + <h2>內容</h2> + <div class="contentbox"></div> + <button class="submit">更新資料</button> + <button class="cancel">取消</button> + </div> + <div class="testdata_box"> + <h2>測試資料</h2> + <label>數量</label> + <input name="count" type="textbox" placeholder="10"> + <table class="table"> + <thead> + <tr class="head"> + <th class="no">#</th> + <th class="score">配分</th> + <th class="file in">輸入檔</th> + <th class="file ans">輸出檔</th> + </tr> + </thead> + <tbody></tbody> + </table> + <div class="prog_box testdata_prog" style="display:none;"> + <div class="total"></div> + <div class="prog"></div> + </div> + <button class="submit">更新測試資料</button> + <button class="cancel">取消</button> + </div> </div> -<div class="content"></div> -<div style="width:100%; height:32px; clear:both;"></div> diff --git a/web/pmod/pmod_test/pmod_test.inc.php b/web/pmod/pmod_test/pmod_test.inc.php new file mode 100644 index 0000000..a433404 --- /dev/null +++ b/web/pmod/pmod_test/pmod_test.inc.php @@ -0,0 +1,29 @@ +<?php +require_once('problem.inc.php'); +require_once('user.inc.php'); + +function event_create($proid) +{ + $sqlc = db_connect(); + + $proid = intval($proid); + $prodir = '/srv/http/toj/center/pro/'.$proid.'/'; + + mkdir($prodir); + mkdir($prodir.'public/'); + mkdir($prodir.'private/'); + + $set = new stdClass(); + $set->timelimit = 0; + $set->memlimit = 0; + $set->count = 0; + $set->score = array(); + $newstr = "jmod_test\njmod_test_check\n=====\n\n".json_encode($set); + + file_put_contents($prodir.'public/content', ''); + file_put_contents($prodir.'setting', $newstr); + + db_close($sqlc); +} + +?> diff --git a/web/pmod/pmod_test/pmod_test.js b/web/pmod/pmod_test/pmod_test.js index 3f1e577..f21c5b0 100644 --- a/web/pmod/pmod_test/pmod_test.js +++ b/web/pmod/pmod_test/pmod_test.js @@ -1,10 +1,69 @@ -var pmod_test = function(that,j_pbox){ - that.node.url_chg = function(direct,url_upart,url_dpart){ - if(direct == 'in'){ - that.fadein(j_pbox); +var pmod_test = function(that,j_page){ + var j_pro_pbox = j_page.find('div.pro_pbox'); + var j_edit_pbox = j_page.find('div.edit_pbox'); + var edit_pbox = new vus.node('edit'); - j_pbox.find('div.info > h2.proid').text('ProID:' + that.proid); - $.post('/toj/pmod/pmod_test/pmod_test.php',{'proid':JSON.stringify(that.proid)},function(res){ + var contentbox = CodeMirror(j_edit_pbox.find('div.contentbox')[0],{ + mode:'text/html', + theme:'lesser-dark', + lineNumbers:true, + matchBrackets:true, + indentUnit:4 + }); + + var testdata_update = function(count,scorelist){ + var i; + var count; + var trs; + var j_table; + var _testdata_listnew = function(idx,score){ + var j_item = $('<tr class="item"><td class="no"></td><td class="score"><input name="score" type="textbox"></td><td class="file ans"><input name="infile" type="file"></td><td class="file ans"><input name="ansfile" type="file"></td></tr>'); + + j_item.find('td.no').text(idx + 1); + j_item.find('[name="score"]').val(score); + + return j_item; + }; + + trs = j_edit_pbox.find('div.testdata_box > table.table tr.item'); + j_table = j_edit_pbox.find('div.testdata_box > table.table'); + for(i = count;i < trs.length;i++){ + $(trs[i]).remove(); + } + if(scorelist != null){ + for(i = trs.length;i < count;i++){ + j_table.append(_testdata_listnew(i,scorelist[i])); + } + }else{ + for(i = trs.length;i < count;i++){ + j_table.append(_testdata_listnew(i,'0')); + } + } + }; + + that.node.url_chg = function(direct,url_upart,url_dpart,param){ + var _out = function(){ + index.tab_ll('pro'); + that.fadeout(j_pro_pbox); + index.content_empty(); + }; + + if(direct == 'in' || direct == 'same'){ + if(direct == 'in' && user.level == -1){ + index.tab_add('pro','/toj/pro/' + that.proid + '/','題目'); + index.tab_add('edit','/toj/pro/' + that.proid + '/edit/','設定'); + } + + if(url_dpart.length > 0){ + _out(); + return 'cont'; + } + + index.tab_hl('pro'); + that.fadein(j_pro_pbox); + + j_pro_pbox.find('div.info > h2.proid').text('ProID:' + that.proid); + $.post('/toj/pmod/pmod_test/pmod_test.php',{'action':'get_pro_data','data':JSON.stringify({'proid':that.proid})},function(res){ var i; var reto; var seto; @@ -15,42 +74,48 @@ var pmod_test = function(that,j_pbox){ reto = JSON.parse(res); seto = reto.set; index.content_set($('<span>' + that.proname + '</span>')); - j_pbox.find('div.content').html(reto.content); + + if(seto == null){ + j_pro_pbox.find('div.content').html('<h2>題目未設定</h2>'); + return; + } + + j_pro_pbox.find('div.content').html(reto.content); $.post('/toj/php/problem.php',{'action':'get_pro_stat','data':JSON.stringify({'proid':that.proid})},function(res){ var reto if(res[0] != 'E'){ reto = JSON.parse(res); - j_pbox.find('div.info > table.statlist td.bscore').text(reto.score); + j_pro_pbox.find('div.info > table.statlist td.bscore').text(reto.score); if(reto.tried == false){ - j_pbox.find('div.info > table.statlist td.bscore').css('color','#1C1C1C'); - j_pbox.find('div.info > table.statlist td.stat').text('未嘗試'); + j_pro_pbox.find('div.info > table.statlist td.bscore').css('color','#1C1C1C'); + j_pro_pbox.find('div.info > table.statlist td.stat').text('未嘗試'); }else{ if(reto.score < 60){ - j_pbox.find('div.info > table.statlist td.bscore').css('color','#FF0000'); + j_pro_pbox.find('div.info > table.statlist td.bscore').css('color','#FF0000'); }else if(reto.score < 80){ - j_pbox.find('div.info > table.statlist td.bscore').css('color','#00FF00'); + j_pro_pbox.find('div.info > table.statlist td.bscore').css('color','#00FF00'); }else if(reto.score < 100){ - j_pbox.find('div.info > table.statlist td.bscore').css('color','#FFFF00'); + j_pro_pbox.find('div.info > table.statlist td.bscore').css('color','#FFFF00'); }else{ - j_pbox.find('div.info > table.statlist td.bscore').css('color','#FFFFFF'); + j_pro_pbox.find('div.info > table.statlist td.bscore').css('color','#FFFFFF'); } if(reto.is_ac == true){ - j_pbox.find('div.info > table.statlist td.stat').text('已通過'); + j_pro_pbox.find('div.info > table.statlist td.stat').text('已通過'); }else{ - j_pbox.find('div.info > table.statlist td.stat').text('已嘗試'); + j_pro_pbox.find('div.info > table.statlist td.stat').text('已嘗試'); } } } }); - j_pbox.find('div.info > table.limitlist td.timelimit').text(seto.timelimit + ' ms'); - j_pbox.find('div.info > table.limitlist td.memlimit').text(seto.memlimit + ' KB'); + j_pro_pbox.find('div.info > table.limitlist td.timelimit').text(seto.timelimit + ' ms'); + j_pro_pbox.find('div.info > table.limitlist td.memlimit').text(seto.memlimit + ' KB'); - j_table = j_pbox.find('table.scorelist'); + j_table = j_pro_pbox.find('table.scorelist'); j_table.find('tr.item').remove(); for(i = 0;i < seto.count;i++){ j_item = $('<tr class="item"><td class="no"></td><td class="score"></td></tr>'); @@ -59,17 +124,152 @@ var pmod_test = function(that,j_pbox){ j_table.append(j_item); } - MathJax.Hub.Queue(["Typeset",MathJax.Hub,j_pbox[0]]); + MathJax.Hub.Queue(["Typeset",MathJax.Hub,j_pro_pbox[0]]); } }); }else if(direct == 'out'){ - that.fadeout(j_pbox); + _out(); } return 'cont'; }; - j_pbox.find('div.info > button.submit').on('click',function(e){ + j_pro_pbox.find('div.info > button.submit').on('click',function(e){ that.submit(); }); + j_edit_pbox.find('div.edit_box > button.submit').on('click',function(e){ + timelimit = parseInt(j_edit_pbox.find('div.edit_box > [name="timelimit"]').val()); + memlimit = parseInt(j_edit_pbox.find('div.edit_box > [name="memlimit"]').val()); + content = contentbox.getValue(); + + $.post('/toj/pmod/pmod_test/pmod_test.php',{'action':'set_pro_data','data':JSON.stringify({'proid':that.proid,'timelimit':timelimit,'memlimit':memlimit,'content':content})},function(res){ + com.url_push_back(); + }); + }); + j_edit_pbox.find('div.edit_box > button.cancel').on('click',function(e){ + com.url_push_back(); + }); + + j_edit_pbox.find('div.testdata_box > [name="count"]').on('change',function(e){ + testdata_update(parseInt($(this).val()),null); + }); + j_edit_pbox.find('div.testdata_box > button.submit').on('click',function(e){ + var i; + + var count; + var score; + var inputs + + var formdata; + var inputs; + var file; + + var j_progbox; + var j_total; + var j_prog; + + count = parseInt(j_edit_pbox.find('div.testdata_box > [name="count"]').val()); + + inputs = j_edit_pbox.find('div.testdata_box > table.table [name="score"]'); + score = Array(); + for(i = 0;i < count;i++){ + score[i] = parseInt($(inputs[i]).val()); + } + + formdata = new FormData(); + formdata.append('action','update_pro_testdata'); + formdata.append('data',JSON.stringify({'proid':that.proid,'count':count,'score':score})); + + inputs = j_edit_pbox.find('div.testdata_box > table.table [name="infile"]'); + for(i = 0;i < inputs.length;i++){ + if((file = inputs[i].files[0]) != undefined){ + formdata.append('infile_' + i,file); + } + } + inputs = j_edit_pbox.find('div.testdata_box > table.table [name="ansfile"]'); + for(i = 0;i < inputs.length;i++){ + if((file = inputs[i].files[0]) != undefined){ + formdata.append('ansfile_' + i,file); + } + } + + j_progbox = j_edit_pbox.find('div.testdata_box > div.testdata_prog'); + j_total = j_progbox.find('div.total'); + j_prog = j_progbox.find('div.prog'); + + j_total.css('width','100%'); + j_total.text('上傳中...'); + j_prog.css('width','0%'); + j_prog.text('0%'); + + j_progbox.show(); + + $.ajax({ + url:'/toj/pmod/pmod_test/pmod_test.php', + type:'POST', + xhr:function(){ + req = $.ajaxSettings.xhr(); + + req.upload.addEventListener('progress',function(e){ + console.log(); + j_prog.css('width',(e.loaded * 100 / e.total) + '%'); + j_prog.text(Math.round(e.loaded * 100 / e.total) + ' %'); + },false); + + return req; + }, + data:formdata, + contentType:false, + processData:false, + success:function(){ + com.url_push_back(); + } + }); + }); + j_edit_pbox.find('div.testdata_box > button.cancel').on('click',function(e){ + com.url_push_back(); + }); + + if(user.level == -1){ + edit_pbox.url_chg = function(direct,url_upart,url_dpart,param){ + if(direct == 'in'){ + index.tab_hl('edit'); + that.fadein(j_edit_pbox); + + contentbox.refresh(); + + $.post('/toj/pmod/pmod_test/pmod_test.php',{'action':'get_pro_data','data':JSON.stringify({'proid':that.proid})},function(res){ + var reto; + + if(res[0] != 'E'){ + reto = JSON.parse(res); + set = reto.set; + + j_edit_pbox.find('div.edit_box > [name="timelimit"]').val(set.timelimit); + j_edit_pbox.find('div.edit_box > [name="memlimit"]').val(set.memlimit); + + if(reto.content != false){ + contentbox.setValue(reto.content); + } + + j_edit_pbox.find('div.testdata_box > [name="count"]').val(set.count); + testdata_update(set.count,set.score); + } + }); + }else if(direct == 'out'){ + index.tab_ll('edit'); + that.fadeout(j_edit_pbox); + + j_edit_pbox.find('div.testdata_box > div.testdata_prog').hide(); + } + + return 'cont'; + }; + that.node.child_set(edit_pbox); + + contentbox.getWrapperElement().style.width = '100%'; + contentbox.getWrapperElement().style.height = '100%'; + contentbox.getScrollerElement().style.width = '100%'; + contentbox.getScrollerElement().style.height = '100%'; + } }; diff --git a/web/pmod/pmod_test/pmod_test.php b/web/pmod/pmod_test/pmod_test.php index 27eecf2..a472630 100644 --- a/web/pmod/pmod_test/pmod_test.php +++ b/web/pmod/pmod_test/pmod_test.php @@ -1,9 +1,32 @@ <?php -require_once('../../php/problem.inc.php'); +require_once('problem.inc.php'); +require_once('user.inc.php'); const PMODNAME = 'pmod_test'; -$proid = json_decode($_POST['proid']); +function get_setting($prodir) +{ + $fd = fopen($prodir.'setting','r'); + $prestr = array(); + while($line = fgets($fd)){ + if($line[0] == '='){ + break; + } + array_push($prestr, $line); + } + $set = ''; + while(($line = fgets($fd))){ + $set = $set.$line; + } + fclose($fd); + + return array($prestr, json_decode($set)); +} + +$action = $_POST['action']; +$data = json_decode($_POST['data']); + +$proid = intval($data->proid); if(gettype($proid) != 'integer' || $proid < 1){ exit('Eproid'); } @@ -17,26 +40,77 @@ $pro = problem::get($sqlc, $proid); if($pro->pmodname != PMODNAME) exit('Ewrong_pmod'); -db_close($sqlc); - $prodir = '/srv/http/toj/center/pro/'.$proid.'/'; -$fd = fopen($prodir.'setting','r'); -while($line = fgets($fd)){ - if($line[0] == '='){ - break; - } +if($action=='get_pro_data') +{ + $content = file_get_contents($prodir.'public/content'); + + echo(json_encode(array( + 'set' => get_setting($prodir)[1], + 'content' => $content + ))); } -$set = ''; -while(($line = fgets($fd))){ - $set = $set.$line; +if($action=='set_pro_data') +{ + if(!sec_check_level($sqlc, USER_LEVEL_SUPERADMIN)) + die('Epermission_denied'); + + $obj = get_setting($prodir); + $prestr = $obj[0]; + $set = $obj[1]; + $set->timelimit = $data->timelimit; + $set->memlimit = $data->memlimit; + file_put_contents($prodir.'public/content', $data->content); + + $newstr = ''; + foreach($prestr as $s) + { + $newstr = $newstr.$s; + } + $newstr = $newstr."=====\n\n"; + $newstr = $newstr.json_encode($set); + file_put_contents($prodir.'setting', $newstr); } -fclose($fd); +if($action=='update_pro_testdata') +{ + if(!sec_check_level($sqlc, USER_LEVEL_SUPERADMIN)) + die('Epermission_denied'); + + $count = $data->count; + $score = $data->score; + + $obj = get_setting($prodir); + $prestr = $obj[0]; + $set = $obj[1]; + $set->count = $count; + $set->score = $score; + + $newstr = ''; + foreach($prestr as $s) + { + $newstr = $newstr.$s; + } + $newstr = $newstr."=====\n\n"; + $newstr = $newstr.json_encode($set); + file_put_contents($prodir.'setting', $newstr); -$content = file_get_contents($prodir.'public/content'); + $tddir = $prodir.'/private/'; + for($idx = 0;$idx < $count;$idx++){ + $dst = $tddir.strval($idx + 1); + mkdir($dst); -echo(json_encode(array( - 'set' => json_decode($set), - 'content' => $content -))); + $key = 'infile_'.strval($idx); + if(array_key_exists($key,$_FILES)){ + move_uploaded_file($_FILES[$key]["tmp_name"],$dst.'/in'); + } + + $key = 'ansfile_'.strval($idx); + if(array_key_exists($key,$_FILES)){ + move_uploaded_file($_FILES[$key]["tmp_name"],$dst.'/ans'); + } + } +} + +db_close($sqlc); ?> |