aboutsummaryrefslogtreecommitdiffstats
path: root/toj
diff options
context:
space:
mode:
authorpzread <netfirewall@gmail.com>2013-04-09 09:37:29 +0800
committerpzread <netfirewall@gmail.com>2013-04-09 09:44:11 +0800
commit31e170379d567a71f1792e0bad9aea6ca3c6478a (patch)
tree73cac5d618f466db3b5be6982824cc0e1b421f90 /toj
parent3c6abbe11d9f2d173020add74217af2d450a1d16 (diff)
downloadtaiwan-online-judge-31e170379d567a71f1792e0bad9aea6ca3c6478a.tar
taiwan-online-judge-31e170379d567a71f1792e0bad9aea6ca3c6478a.tar.gz
taiwan-online-judge-31e170379d567a71f1792e0bad9aea6ca3c6478a.tar.bz2
taiwan-online-judge-31e170379d567a71f1792e0bad9aea6ca3c6478a.tar.lz
taiwan-online-judge-31e170379d567a71f1792e0bad9aea6ca3c6478a.tar.xz
taiwan-online-judge-31e170379d567a71f1792e0bad9aea6ca3c6478a.tar.zst
taiwan-online-judge-31e170379d567a71f1792e0bad9aea6ca3c6478a.zip
Fix segment fault(use deleted memory). Add square-problem manage. Check setting file exist
Diffstat (limited to 'toj')
-rwxr-xr-xtoj/center/src/center_judge.cpp47
-rwxr-xr-xtoj/center/src/center_judge.h14
-rwxr-xr-xtoj/center/src/center_manage.cpp165
-rwxr-xr-xtoj/center/src/center_manage.h1
-rw-r--r--toj/center/src/judge_manage.cpp4
-rw-r--r--toj/center/src/judge_manage.h2
-rwxr-xr-xtoj/center/src/judge_server.cpp2
-rwxr-xr-xtoj/center/src/judge_server.h2
-rwxr-xr-xtoj/index.html11
-rwxr-xr-xtoj/jcs/user.css33
-rwxr-xr-xtoj/jcs/user.js150
-rwxr-xr-xtoj/php/square.inc.php2
-rwxr-xr-xtoj/php/square.php14
13 files changed, 341 insertions, 106 deletions
diff --git a/toj/center/src/center_judge.cpp b/toj/center/src/center_judge.cpp
index 85a2fd6..46600c2 100755
--- a/toj/center/src/center_judge.cpp
+++ b/toj/center/src/center_judge.cpp
@@ -82,6 +82,16 @@ int judge_info::updatepro(std::vector<std::pair<int,int> > &pro_list){
return 0;
}
+int judge_info::updatejmod(std::vector<std::pair<char*,int> > &jmod_list){
+ int i;
+
+ for(i = 0;i < jmod_list.size();i++){
+ jmod_map.erase(jmod_list[i].first);
+ }
+ conn_main->send_setjmod(jmod_list,0);
+
+ return 0;
+}
judge_conn::judge_conn(int fd):netio(fd){
@@ -181,18 +191,21 @@ int judge_conn::send_setpro(std::vector<std::pair<int,int> > &pro_list,int type)
return 0;
}
-int judge_conn::send_setjmod(char **jmod_name,int *cacheid,int type,int count){
+int judge_conn::send_setjmod(std::vector<std::pair<char*,int> > &jmod_list,int type){
int i;
+ int count;
char *write_buf;
int write_len;
center_com_setjmod *setjmod;
+ count = jmod_list.size();
write_buf = create_combuf(CENTER_COMCODE_SETJMOD,sizeof(center_com_setjmod) * count,write_len,(void**)&setjmod);
+
for(i = 0;i < count;i++){
setjmod[i].jmod_name[0] = '\0';
- strncat(setjmod[i].jmod_name,jmod_name[i],sizeof(setjmod[i].jmod_name));
- setjmod[i].cacheid = cacheid[i];
+ strncat(setjmod[i].jmod_name,jmod_list[i].first,sizeof(setjmod[i].jmod_name));
+ setjmod[i].cacheid = jmod_list[i].second;
setjmod[i].type = type;
}
writebytes(write_buf,write_len,NULL,NULL);
@@ -268,27 +281,20 @@ void judge_conn::recv_setinfo(void *buf,size_t len,void *data){
int count;
center_com_setinfo *setinfo;
- char **jmod_name;
std::map<std::string,center_jmod_info*>::iterator jmod_it;
- std::vector<std::pair<int,int> > pro_list;
- int *cacheid;
+ std::vector<std::pair<char*,int> > jmod_list;
std::map<int,center_pro_info*>::iterator pro_it;
+ std::vector<std::pair<int,int> > pro_list;
setinfo = (center_com_setinfo*)buf;
info->setinfo(setinfo->avail);
count = center_manage_jmodmap.size();
- jmod_name = new char*[count];
- cacheid = new int[count];
jmod_it = center_manage_jmodmap.begin();
for(i = 0;i < count;i++,jmod_it++){
- jmod_name[i] = jmod_it->second->name;
- cacheid[i] = jmod_it->second->cacheid;
+ jmod_list.push_back(std::make_pair(jmod_it->second->name,jmod_it->second->cacheid));
}
- send_setjmod(jmod_name,cacheid,0,count);
-
- delete jmod_name;
- delete cacheid;
+ send_setjmod(jmod_list,0);
count = center_manage_promap.size();
pro_it = center_manage_promap.begin();
@@ -489,6 +495,7 @@ static int judge_run_waitqueue(){
center_pro_info *pro_info;
count = judge_submitqueue.size();
+ printf(" remain count %d\n",count);
for(;count > 0;count--){
sub_info = judge_submitqueue.front();
judge_submitqueue.pop();
@@ -557,3 +564,15 @@ int center_judge_updatepro(std::vector<std::pair<int,int> > &pro_list){
return 0;
}
+int center_judge_updatejmod(std::vector<std::pair<char*,int> > &jmod_list){
+ int i;
+ int j;
+ std::list<judge_info*>::iterator judge_it;
+ judge_info *info;
+
+ for(judge_it = judge_runlist.begin();judge_it != judge_runlist.end();judge_it++){
+ (*judge_it)->updatejmod(jmod_list);
+ }
+
+ return 0;
+}
diff --git a/toj/center/src/center_judge.h b/toj/center/src/center_judge.h
index 99a3cf9..a955ce9 100755
--- a/toj/center/src/center_judge.h
+++ b/toj/center/src/center_judge.h
@@ -22,6 +22,7 @@ public:
int submit(judge_submit_info *submit_info);
int result(int subid,char *res_data);
int updatepro(std::vector<std::pair<int,int> > &pro_list);
+ int updatejmod(std::vector<std::pair<char*,int> > &jmod_list);
};
class judge_conn : public netio{
@@ -58,7 +59,7 @@ public:
int send_setid(int judgeid);
int send_submit(judge_submit_info* submit_info);
int send_setpro(std::vector<std::pair<int,int> > &pro_list,int type);
- int send_setjmod(char **jmod_name,int *cacheid,int type,int count);
+ int send_setjmod(std::vector<std::pair<char*,int> > &jmod_list,int type);
virtual int readidle();
};
@@ -70,13 +71,13 @@ public:
char *set_data;
size_t set_len;
- judge_submit_info(int subid,int proid,int lang,char *setdata,size_t setlen){
+ judge_submit_info(int subid,int proid,int lang,char *set_data,size_t set_len){
this->subid = subid;
this->proid = proid;
this->lang = lang;
- this->set_data = new char[setlen];
- memcpy(this->set_data,setdata,setlen);
- this->set_len = setlen;
+ this->set_data = new char[set_len];
+ memcpy(this->set_data,set_data,set_len);
+ this->set_len = set_len;
}
~judge_submit_info(){
delete this->set_data;
@@ -92,8 +93,9 @@ static std::queue<judge_submit_info*> judge_submitqueue;
int center_judge_init();
void* center_judge_addconn(int fd);
int center_judge_dispatch(int evflag,void *data);
-int center_judge_submit(int subid,int proid,int lang,char *setdata,size_t setlen);
+int center_judge_submit(int subid,int proid,int lang,char *set_data,size_t set_len);
int center_judge_updatepro(std::vector<std::pair<int,int> > &pro_list);
+int center_judge_updatejmod(std::vector<std::pair<char*,int> > &jmod_list);
extern int center_manage_result(int subid,char *res_data);
extern center_pro_info* center_manage_getprobyid(int proid);
diff --git a/toj/center/src/center_manage.cpp b/toj/center/src/center_manage.cpp
index 454faf2..a6a759c 100755
--- a/toj/center/src/center_manage.cpp
+++ b/toj/center/src/center_manage.cpp
@@ -228,38 +228,51 @@ static void manage_submit_cb(void *data){
char lchr;
char tchr;
- sub_info = (manage_submit_info*)data;
- jmod_info = sub_info->jmod_info;
- pro_info = sub_info->pro_info;
+ try{
+ sub_info = (manage_submit_info*)data;
+ jmod_info = sub_info->jmod_info;
+ pro_info = sub_info->pro_info;
+
+ if(jmod_info->manage_dll == NULL){
+ getcwd(cwd_path,sizeof(cwd_path));
+ snprintf(tpath,sizeof(tpath),"%s/jmod/%s/%s_manage.so",cwd_path,jmod_info->name,jmod_info->name);
+
+ jmod_info->manage_dll = dlopen(tpath,RTLD_NOW);
+ jmod_info->manage_sub_fn = dlsym(jmod_info->manage_dll,"submit");
+ jmod_info->manage_res_fn = dlsym(jmod_info->manage_dll,"result");
+ }
+ mg_sub_fn = (judgm_manage_submit_fn)jmod_info->manage_sub_fn;
- if(jmod_info->manage_dll == NULL){
- getcwd(cwd_path,sizeof(cwd_path));
- snprintf(tpath,sizeof(tpath),"%s/jmod/%s/%s_manage.so",cwd_path,jmod_info->name,jmod_info->name);
+ mg_info = sub_info->manage_info;
+ snprintf(mg_info->pro_path,sizeof(mg_info->pro_path),"tmp/pro/%d_%d",pro_info->proid,pro_info->cacheid);
+ snprintf(mg_info->res_path,sizeof(mg_info->res_path),"submit/%d/%d/result",(sub_info->subid / 1000) * 1000,sub_info->subid);
- jmod_info->manage_dll = dlopen(tpath,RTLD_NOW);
- jmod_info->manage_sub_fn = dlsym(jmod_info->manage_dll,"submit");
- jmod_info->manage_res_fn = dlsym(jmod_info->manage_dll,"result");
- }
- mg_sub_fn = (judgm_manage_submit_fn)jmod_info->manage_sub_fn;
-
- mg_info = sub_info->manage_info;
- snprintf(mg_info->pro_path,sizeof(mg_info->pro_path),"pro/%d",pro_info->proid);
- snprintf(mg_info->res_path,sizeof(mg_info->res_path),"submit/%d/%d/result",(sub_info->subid / 1000) * 1000,sub_info->subid);
-
- snprintf(tpath,sizeof(tpath),"pro/%d/setting",pro_info->proid);
- set_file = fopen(tpath,"r");
- lchr = '\n';
- while((tchr = fgetc(set_file)) != EOF){
- if(lchr == '\n' && tchr == '='){
- while(fgetc(set_file) != '\n');
- break;
+ snprintf(tpath,sizeof(tpath),"tmp/pro/%d_%d/setting",pro_info->proid,pro_info->cacheid);
+ if((set_file = fopen(tpath,"r")) == NULL){
+ throw 0;
+ }
+ lchr = '\n';
+ while((tchr = fgetc(set_file)) != EOF){
+ if(lchr == '\n' && tchr == '='){
+ while(fgetc(set_file) != '\n');
+ break;
+ }
+ lchr = tchr;
}
- lchr = tchr;
- }
-
- mg_sub_fn(mg_info,set_file);
- fclose(set_file);
+ mg_sub_fn(mg_info,set_file);
+
+ fclose(set_file);
+ }catch(...){
+ manage_finish_result(sub_info->subid,
+ sub_info->uid,
+ sub_info->pro_info->proid,
+ JUDGE_ERR,
+ 0,
+ 0,
+ 0,
+ sub_info->rejudge_flag);
+ }
}
DLL_PUBLIC int center_manage_queuesubmit(int subid,int proid,int lang,char *set_data,size_t set_len){
center_judge_submit(subid,proid,lang,set_data,set_len);
@@ -275,15 +288,6 @@ int center_manage_result(int subid,char *res_data){
judgm_manage_info *mg_info;
judgm_manage_result_fn mg_res_fn;
- PGconn *db_conn;
- PGresult *db_res;
- char db_result[32];
- char db_score[32];
- char db_runtime[32];
- char db_memory[32];
- char db_subid[32];
- char *db_param[5];
-
if((sub_it = manage_submap.find(subid)) == manage_submap.end()){
return -1;
}
@@ -295,39 +299,14 @@ int center_manage_result(int subid,char *res_data){
if(mg_res_fn(mg_info,res_data)){
manage_submap.erase(sub_it);
- if((db_conn = center_manage_conndb()) == NULL){
- return -1;
- }
-
- snprintf(db_result,sizeof(db_result),"%d",mg_info->result);
- snprintf(db_score,sizeof(db_score),"%lf",mg_info->score);
- snprintf(db_runtime,sizeof(db_runtime),"%lu",mg_info->runtime);
- snprintf(db_memory,sizeof(db_memory),"%lu",mg_info->memory / 1024UL);
- snprintf(db_subid,sizeof(db_subid),"%d",subid);
- db_param[0] = db_result;
- db_param[1] = db_score;
- db_param[2] = db_runtime;
- db_param[3] = db_memory;
- db_param[4] = db_subid;
- db_res = PQexecParams(db_conn,
- "UPDATE \"submit\" SET \"result\"=$1,\"score\"=$2,\"runtime\"=$3,\"memory\"=$4 WHERE \"subid\"=$5;",
- 5,
- NULL,
- db_param,
- NULL,
- NULL,
- 0);
- PQclear(db_res);
- center_manage_closedb(db_conn);
-
- manage_notice(subid,
- sub_info->uid,
- sub_info->pro_info->proid,
- mg_info->result,
- mg_info->score,
- mg_info->runtime,
- mg_info->memory,
- sub_info->rejudge_flag);
+ manage_finish_result(subid,
+ sub_info->uid,
+ sub_info->pro_info->proid,
+ mg_info->result,
+ mg_info->score,
+ mg_info->runtime,
+ mg_info->memory,
+ sub_info->rejudge_flag);
center_manage_putpro(sub_info->pro_info);
delete sub_info;
@@ -337,6 +316,52 @@ int center_manage_result(int subid,char *res_data){
return 0;
}
+static int manage_finish_result(int subid,int uid,int proid,int result,double score,int runtime,int memory,bool rejudge_flag){
+ PGconn *db_conn;
+ PGresult *db_res;
+ char db_result[32];
+ char db_score[32];
+ char db_runtime[32];
+ char db_memory[32];
+ char db_subid[32];
+ char *db_param[5];
+
+ if((db_conn = center_manage_conndb()) == NULL){
+ return -1;
+ }
+
+ snprintf(db_result,sizeof(db_result),"%d",result);
+ snprintf(db_score,sizeof(db_score),"%lf",score);
+ snprintf(db_runtime,sizeof(db_runtime),"%lu",runtime);
+ snprintf(db_memory,sizeof(db_memory),"%lu",memory / 1024UL);
+ snprintf(db_subid,sizeof(db_subid),"%d",subid);
+ db_param[0] = db_result;
+ db_param[1] = db_score;
+ db_param[2] = db_runtime;
+ db_param[3] = db_memory;
+ db_param[4] = db_subid;
+ db_res = PQexecParams(db_conn,
+ "UPDATE \"submit\" SET \"result\"=$1,\"score\"=$2,\"runtime\"=$3,\"memory\"=$4 WHERE \"subid\"=$5;",
+ 5,
+ NULL,
+ db_param,
+ NULL,
+ NULL,
+ 0);
+ PQclear(db_res);
+ center_manage_closedb(db_conn);
+
+ manage_notice(subid,
+ uid,
+ proid,
+ result,
+ score,
+ runtime,
+ memory,
+ rejudge_flag);
+
+ return 0;
+}
static int manage_notice(int subid,int uid,int proid,int result,double score,int runtime,int memory,bool rejudge_flag){
char msg[4096];
json_object *jso_msg;
diff --git a/toj/center/src/center_manage.h b/toj/center/src/center_manage.h
index 1f84403..b2ee36e 100755
--- a/toj/center/src/center_manage.h
+++ b/toj/center/src/center_manage.h
@@ -28,6 +28,7 @@ public:
static void manage_submit_th(void *data);
static void manage_submit_cb(void *data);
+static int manage_finish_result(int subid,int uid,int proid,int result,double score,int runtime,int memory,bool rejudge_flag);
static int manage_notice(int subid,int uid,int proid,int result,double score,int runtime,int memory,bool rejudge_flag);
static int manage_updatepro(int proid,int cacheid,center_jmod_info *jmod_info,int lang_flag);
diff --git a/toj/center/src/judge_manage.cpp b/toj/center/src/judge_manage.cpp
index 6901565..32181bc 100644
--- a/toj/center/src/judge_manage.cpp
+++ b/toj/center/src/judge_manage.cpp
@@ -194,7 +194,7 @@ static void manage_updatepro_cb(void *data){
}
-int judge_manage_submit(int subid,int proid,int lang,char *set_data){
+int judge_manage_submit(int subid,int proid,int lang,char *set_data,int set_len){
judge_pro_info *pro_info;
judge_submit_info *sub_info;
@@ -202,7 +202,7 @@ int judge_manage_submit(int subid,int proid,int lang,char *set_data){
struct stat st;
pro_info = judge_manage_getprobyid(proid);
- sub_info = new judge_submit_info(subid,pro_info,lang,set_data);
+ sub_info = new judge_submit_info(subid,pro_info,lang,set_data,set_len);
if(manage_submap.find(subid) == manage_submap.end()){
snprintf(tpath,sizeof(tpath),"tmp/code/%d",subid);
diff --git a/toj/center/src/judge_manage.h b/toj/center/src/judge_manage.h
index 00abc22..594ea71 100644
--- a/toj/center/src/judge_manage.h
+++ b/toj/center/src/judge_manage.h
@@ -44,7 +44,7 @@ int judge_manage_getpro(judge_pro_info *pro_info);
int judge_manage_putpro(judge_pro_info *pro_info);
int judge_manage_updatepro(int proid,int cacheid,bool check_flag,judge_pro_info **update_pro_info);
int judge_manage_done_updatepro(judge_pro_info *pro_info);
-int judge_manage_submit(int subid,int proid,int lang,char *set_data);
+int judge_manage_submit(int subid,int proid,int lang,char *set_data,int set_len);
int judge_manage_done_code(int subid);
std::map<int,judge_pro_info*> judge_manage_promap;
diff --git a/toj/center/src/judge_server.cpp b/toj/center/src/judge_server.cpp
index 7a2bb6a..66b4d01 100755
--- a/toj/center/src/judge_server.cpp
+++ b/toj/center/src/judge_server.cpp
@@ -216,7 +216,7 @@ void server_conn::recv_submit(void *buf,size_t len,void *data){
center_com_submit *sub;
sub = (center_com_submit*)buf;
- judge_manage_submit(sub->subid,sub->proid,sub->lang,(char*)((char*)buf + sizeof(center_com_submit)));
+ judge_manage_submit(sub->subid,sub->proid,sub->lang,(char*)((char*)buf + sizeof(center_com_submit)),len - sizeof(center_com_submit));
delete sub;
}
diff --git a/toj/center/src/judge_server.h b/toj/center/src/judge_server.h
index fadde93..90a4e7c 100755
--- a/toj/center/src/judge_server.h
+++ b/toj/center/src/judge_server.h
@@ -82,6 +82,6 @@ extern int judge_manage_getpro(judge_pro_info *pro_info);
extern int judge_manage_putpro(judge_pro_info *pro_info);
extern int judge_manage_updatepro(int proid,int cacheid,bool check_flag,judge_pro_info **update_pro_info);
extern int judge_manage_done_updatepro(judge_pro_info *pro_info);
-extern int judge_manage_submit(int subid,int proid,int lang,char *set_data);
+extern int judge_manage_submit(int subid,int proid,int lang,char *set_data,int set_len);
extern int judge_manage_done_code(int subid);
diff --git a/toj/index.html b/toj/index.html
index f3894c0..b295ed9 100755
--- a/toj/index.html
+++ b/toj/index.html
@@ -330,6 +330,17 @@ input,select{
<button class="cancel">取消</button>
<button class="delete" style="display:none;">刪除</button>
</div>
+ <div class="pro_box">
+ <h1>已加入題目</h1>
+ <div class="prolist_box">
+ <table class="prolist prolist_in"></table>
+ </div>
+ <h1>未加入題目</h1>
+ <div class="prolist_box">
+ <table class="prolist prolist_out"></table>
+ </div>
+ </div>
+ <div style="width:100%; clear:both;"></div>
</div>
<div class="com_mbox editpro_mbox">
<div class="edit_box">
diff --git a/toj/jcs/user.css b/toj/jcs/user.css
index d1c1b73..dc36dfe 100755
--- a/toj/jcs/user.css
+++ b/toj/jcs/user.css
@@ -103,8 +103,10 @@ div.user_page > div.mg_pbox table.prolist th.name,div.user_page > div.mg_pbox ta
}
div.user_mask > div.editsq_mbox > div.edit_box{
- margin:0px 0px 0px 246px;
+ width:322px;
+ margin:0px 0px 0px 164px;
padding:6px 0px 32px 0px;
+ float:left;
}
div.user_mask > div.editsq_mbox > div.edit_box > div.error{
margin:0px 0px 16px 0px;
@@ -128,6 +130,35 @@ div.user_mask > div.editsq_mbox > div.edit_box select{
border-width:0px;
display:block;
}
+div.user_mask > div.editsq_mbox > div.pro_box{
+ width:404px;
+ margin:0px 0px 0px 6px;
+ padding:6px 0px 32px 0px;
+ float:left;
+}
+div.user_mask > div.editsq_mbox > div.pro_box > div.prolist_box{
+ width:100%;
+ max-height:256px;
+ overflow-y:scroll;
+}
+div.user_mask > div.editsq_mbox > div.pro_box table.prolist{
+ width:100%;
+ border-collapse:collapse;
+ text-align:left;
+}
+div.user_mask > div.editsq_mbox > div.pro_box table.prolist tr.item{
+ height:44px;
+}
+div.user_mask > div.editsq_mbox > div.pro_box table.prolist tr:hover.item{
+ background-color:rgba(255,255,255,0.2);
+}
+div.user_mask > div.editsq_mbox > div.pro_box table.prolist td{
+ width:76px;
+ padding:0px 0px 0px 6px;
+}
+div.user_mask > div.editsq_mbox > div.pro_box table.prolist td.name{
+ width:auto;
+}
div.user_mask > div.editpro_mbox > div.edit_box{
margin:0px 0px 0px 246px;
diff --git a/toj/jcs/user.js b/toj/jcs/user.js
index 51859c1..230aed5 100755
--- a/toj/jcs/user.js
+++ b/toj/jcs/user.js
@@ -507,15 +507,16 @@ var class_user_mgsq_pbox = function(){
var i;
var j;
- var j_divs;
+ var divs;
var j_last;
var j_item;
var oldhash;
+ var sqo;
- j_divs = j_list.children('div.item');
+ divs = j_list.children('div.item');
oldhash = new Array();
- for(i = 0;i < j_divs.length;i++){
- oldhash[$(j_divs[i]).attr('sqid')] = i;
+ for(i = 0;i < divs.length;i++){
+ oldhash[$(divs[i]).attr('sqid')] = i;
}
j = 0;
@@ -524,10 +525,10 @@ var class_user_mgsq_pbox = function(){
sqo = sqlist[i];
if(sqo.sqid in oldhash){
for(;j < oldhash[sqo.sqid];j++){
- j_item = $(j_divs[j]);
+ j_item = $(divs[j]);
j_item.stop().fadeTo(100,0).slideUp('fast',function(){$(this).remove();});
}
- j_item = $(j_divs[j]);
+ j_item = $(divs[j]);
j++;
sq_listset(j_item,sqo);
@@ -537,16 +538,15 @@ var class_user_mgsq_pbox = function(){
j_item.hide();
if(j_last == null){
j_list.prepend(j_item);
- j_item.css('opacity',0).slideDown('fast').fadeTo(100,1);
}else{
j_item.insertAfter(j_last);
- j_item.css('opacity',0).slideDown('fast').fadeTo(100,1);
}
+ j_item.css('opacity',0).slideDown('fast').fadeTo(100,1);
j_last = j_item;
}
}
- for(;j < j_divs.length;j++){
- j_item = $(j_divs[j]);
+ for(;j < divs.length;j++){
+ j_item = $(divs[j]);
j_item.stop().fadeTo(100,0).slideUp('fast',function(){$(this).remove();});
}
};
@@ -767,6 +767,132 @@ var class_user_editsq_mbox = function(){
var sqid = null;
var defer = null;
+ var pro_listset = function(j_item,proo,type){
+ j_item.attr('proid',proo.proid);
+ j_item.find('td.id').text(proo.proid);
+ j_item.find('td.name').text(proo.proname);
+
+ j_button = j_item.find('button.oper');
+ if(type == 'in'){
+ j_button.text('移除');
+ j_button.off('click').on('click',function(e){
+ $.post('/toj/php/square.php',{'action':'delete_pro_from_sq','data':JSON.stringify({'sqid':sqid,'proid':proo.proid})},function(res){
+ if(res == 'S'){
+ pro_update();
+ }
+ });
+ });
+ }else{
+ j_button.text('加入');
+ j_button.off('click').on('click',function(e){
+ $.post('/toj/php/square.php',{'action':'add_pro_into_sq','data':JSON.stringify({'sqid':sqid,'proid':proo.proid})},function(res){
+ if(res == 'S'){
+ pro_update();
+ }
+ });
+ });
+ }
+ };
+ var pro_listnew = function(proo,type){
+ var j_item;
+
+ j_item = $('<tr class="item"><td class="id"></td><td class="name"></td><td><button class="oper" style="display:none;"></button></td></tr>');
+ pro_listset(j_item,proo,type);
+
+ j_item.hover(
+ function(){
+ $(this).find('button.oper').show();
+ },
+ function(){
+ $(this).find('button.oper').hide();
+ }
+ );
+
+ return j_item;
+ };
+ var pro_update = function(){
+ _updatelist = function(j_table,prolist,type){
+ var i;
+ var j;
+
+ var trs;
+ var j_last;
+ var j_item;
+ var oldhash;
+ var proo;
+
+ trs = j_table.find('tr.item');
+ oldhash = new Array();
+ for(i = 0;i < trs.length;i++){
+ oldhash[$(trs[i]).attr('proid')] = i;
+ }
+
+ j = 0;
+ j_last = null;
+ for(i = 0;i < prolist.length;i++){
+ proo = prolist[i];
+
+ if(proo.proid in oldhash){
+ for(;j < oldhash[proo.proid];j++){
+ j_item = $(trs[j]);
+ j_item.stop().fadeTo(100,0).slideUp('fast',function(){$(this).remove()});
+ }
+ j_item = $(trs[j]);
+ j++;
+
+ pro_listset(j_item,proo,type);
+ j_last = j_item;
+ }else{
+ j_item = pro_listnew(proo,type);
+ j_item.hide();
+
+ if(j_last == null){
+ j_table.append(j_item);
+ }else{
+ j_item.insertAfter(j_last);
+ }
+ j_item.css('opacity',0).slideDown('fast').fadeTo(100,1);
+ }
+ }
+ for(;j < trs.length;j++){
+ j_item = $(trs[j]);
+ j_item.stop().fadeTo(100,0).slideUp('fast',function(){$(this).remove()});
+ }
+ };
+
+ $.post('/toj/php/square.php',{'action':'get_sq_pro_list','data':JSON.stringify({'sqid':sqid})},function(res){
+ var i;
+
+ var inlist;
+
+ if(res[0] != 'E'){
+ inlist = JSON.parse(res);
+ _updatelist(j_mbox.find('table.prolist_in'),inlist,'in');
+ }
+
+ $.post('/toj/php/problem.php',{'action':'get_pro_list','data':null},function(res){
+ var i;
+ var j;
+
+ var reto;
+ var outlist;
+
+ if(res[0] != 'E'){
+ reto = JSON.parse(res);
+ outlist = new Array();
+ for(i = 0,j = 0;i < reto.length;i++){
+ if(j < inlist.length && reto[i].proid == inlist[j].proid){
+ j++;
+ }else{
+ outlist.push(reto[i]);
+ }
+ }
+ _updatelist(j_mbox.find('table.prolist_out'),outlist,'out');
+ }
+ });
+ });
+ };
+
that.node = new vus.node('user_editsq');
that.__super();
@@ -806,6 +932,7 @@ var class_user_editsq_mbox = function(){
that.node.url_chg = function(direct,url_upart,url_dpart){
if(direct == 'in'){
that.fadein(j_mbox);
+ pro_update();
}else if(direct == 'out'){
that.fadeout(j_mbox);
@@ -818,6 +945,9 @@ var class_user_editsq_mbox = function(){
j_mbox.find('button.delete').hide();
j_mbox.find('div.error').text('');
+ j_mbox.find('table.prolist_in').empty();
+ j_mbox.find('table.prolist_out').empty();
+
if(defer.state() == 'pending'){
defer.reject();
}
diff --git a/toj/php/square.inc.php b/toj/php/square.inc.php
index 784490d..4a4b52f 100755
--- a/toj/php/square.inc.php
+++ b/toj/php/square.inc.php
@@ -143,6 +143,7 @@ class square
$ret = array();
while($row = pg_fetch_object($sqlr))
{
+ $row->sqid = intval($row->sqid);
array_push($ret, $row);
}
return $ret;
@@ -159,6 +160,7 @@ class square
$ret = array();
while($row = pg_fetch_object($sqlr))
{
+ $row->sqid = intval($row->sqid);
array_push($ret, $row);
}
return $ret;
diff --git a/toj/php/square.php b/toj/php/square.php
index ca57994..c95c584 100755
--- a/toj/php/square.php
+++ b/toj/php/square.php
@@ -284,6 +284,20 @@ if($action == 'get_entered_sq')
echo(json_encode($ret));
}
+if($action == 'get_sq_pro_list')
+{
+ if(!sec_is_login())
+ die('Enot_login');
+ if(!sec_check_level($sqlc, USER_LEVEL_SUPERADMIN))
+ die('Epermission_denied');
+
+ $dt = json_decode($data);
+ if(!square::get($sqlc, $dt->sqid))
+ die('Ewrong_sqid');
+
+ $ret = square::get_pro_list($sqlc, $dt->sqid);
+ echo(json_encode($ret));
+}
if($action == 'add_pro_into_sq')
{
if(!sec_is_login())