user_login;
echo'
AIAcademy 考卷批改
';
$_answer_id = isset($_GET['answer_id']) ? $_GET['answer_id']+0 : 0;
if($_answer_id){ #step4
$row = $wpdb->get_row('SELECT * FROM '.TBL_EXAM.' WHERE id='.$_answer_id);
if(!$row){
die('There is no the exam answer. Go Back ');
}
$exam_correct_ans = get_post_meta($row->exam_post_id,'exam_correct_ans',true);
$ary_exam_correct_ans = preg_split("/(\r\n|\n|\r)/",$exam_correct_ans);
$options = get_post_meta($row->exam_post_id, 'exam_options', true);
$ary_options = preg_split("/(\r\n|\n|\r)/",$options);
$ary_options_score = array();
$ary_examinput_config_prefix = array('TXT','CHKBOX','RADIO');
$textarea_k = 1;
foreach($ary_options as$k=>$v){
$examinput_suffix = $k+1;
$_ = explode('|',$v);
$score = $_[count($_)-1];
if(in_array($_[0],$ary_examinput_config_prefix)){
$ary_options_score['examinput_'.$examinput_suffix] = $score;
}else{
$ary_options_score['examtextarea_'.$textarea_k] = $score;
$textarea_k++;
}
}
$ary_ans_opt = unserialize($row->ans_opt);
$ary_options_got_score = array();
foreach($ary_ans_opt as$k=>$v){
$exam_correct_ans_find_idx = str_replace('examinput_','',$k)-1;
$correct_ans = $ary_exam_correct_ans[$exam_correct_ans_find_idx];
$is_got_score = true;
if(strpos($correct_ans,'+')===false){
if($v!=$correct_ans){
$is_got_score = false;
}
}else{
$correct_ans = explode('+',$correct_ans);
if(count($correct_ans)!==count($v)){
$is_got_score=false;
}else{
sort($correct_ans);
sort($v);
foreach($correct_ans as $x=>$y){
if($v[$x]!=$correct_ans[$x]){
$is_got_score=false;
break;
}
}
}
}
if($is_got_score){
$ary_options_got_score[$k] = $ary_options_score[$k];
}
} // end of foreach
$exam_score_id = isset($_GET['score_record_id']) ? $_GET['score_record_id']+0 : 0;
if($exam_score_id){
$sql='SELECT * FROM '.TBL_EXAM_SCORE.' WHERE id="'.$exam_score_id.'"';
}else{
$sql='SELECT * FROM '.TBL_EXAM_SCORE.' WHERE tester_email="'.$row->tester_email
.'" AND answer_id="'.$row->id.'" ORDER BY `give_score_datetime` DESC LIMIT 1';
}
$user = wp_get_current_user(); if($user->user_login=='vansindata'){ echo$sql; } #debug
$exam_score_row = $wpdb->get_row($sql); # exam_id is `exam`.`id` , not wordpress post.id
$ary_exam_score__opt_score = null;
if($exam_score_row && $exam_score_row->opt_score){
$ary_exam_score__opt_score = unserialize($exam_score_row->opt_score);
}
$post = get_post($row->exam_post_id);
echo''.$post->post_title.' ';
echo'考生: '.$row->tester_name.' '.$row->tester_email.'
';
echo'本份交卷時間: '.$row->create_datetime.' ';
if($exam_score_row->give_score_by){
echo'';
echo'本份最近的批改者: '.$exam_score_row->give_score_by.'
';
echo'本份最近的批改者批的時間: '.$exam_score_row->give_score_datetime.' ';
echo'本份最近的批改者給的總成績: '.$exam_score_row->totalscore.' ';
echo'';
}
$sql='SELECT * FROM '.TBL_EXAM_SCORE.' WHERE tester_email="'.$row->tester_email
.'" AND answer_id="'.$row->id.'" ORDER BY `give_score_datetime` DESC';
$score_records = $wpdb->get_results($sql);
if($score_records){
echo'本份批改歷程: ';
foreach($score_records as$record){
echo''.$record->give_score_datetime .' 得分'.$record->totalscore.' by '.$record->give_score_by
.($record->id==$exam_score_row->id ? ' <-- 本頁已載入此批改紀錄 ':'')
.' ';
}
echo' ';
}
echo'註1: 若沒給,則以程式為初始化;若有給,則不論程式,以人工為主為準
';
exit;
}
###########################################################
$_id = isset($_GET['id']) ? $_GET['id']+0 : 0;
$_tester_email = isset($_GET['tester_email']) ? AIAExam::decode_tester_email_in_url($_GET['tester_email']) : '';
if(!$_id){ # step1
$a = AIAExam::get_all_exam_ids();
echo'請選擇要批改的考卷: ';
foreach($a as$v){
$post = get_post($v);
echo' 【考卷編號: '
.$post->ID.' 】'.$post->post_title.' - Download CSV for all the score ';
}
echo'開始批改 ';
exit;
}
if($_id){ #step2 + step3
$post = get_post($_id);
$exam_start_datetime_yyyymmddHHMM = get_post_meta($post->ID, 'exam_start_datetime', true);
$exam_start_datetime = substr($exam_start_datetime_yyyymmddHHMM,11);
$exam_end_datetime_yyyymmddHHMM = get_post_meta($post->ID, 'exam_end_datetime', true);
$exam_end_datetime = substr($exam_end_datetime_yyyymmddHHMM,11);
echo''.$post->post_title.': ';
echo'考試時間: '.$exam_start_datetime_yyyymmddHHMM.' ~ '.$exam_end_datetime_yyyymmddHHMM.'
';
}
if(!$_tester_email){ #step2
#$PAGESIZE = isset($_GET['size'])&&$_GET['size']+0 ? $_GET['size']+0 : 10;
$PAGESIZE = 20;
$PAGE = isset($_GET['page'])&&$_GET['page']+0 ? $_GET['page']+0 : 1;;
echo'選擇要批改哪位考生: ';
$sql="SELECT id,tester_name,tester_email,exam_post_id FROM {TBL_EXAM} WHERE exam_post_id={post_id} AND tester_email<>'' GROUP BY tester_email LIMIT ".(($PAGE-1)*$PAGESIZE).",".$PAGESIZE;
$sql=str_replace(array('{TBL_EXAM}','{post_id}'),array(TBL_EXAM,$post->ID),$sql);
if($IS_DEVELOPER_DEBUG){ echo$sql; }
$a=$wpdb->get_results($sql);
echo'考生姓名 Email 最後在考試截止前之交卷時間 選擇評分 問答評分 總評分 答卷筆數 ';
foreach($a as$v){
$all_exam_results_of_this_tester_link = '?id='.$post->ID.'&tester_email='.AIAExam::tester_email_in_url($v->tester_email);
# get all exam_answer which <=exam_end_datetime belongs to the one tester
$sql2='SELECT * FROM {TBL_EXAM} WHERE exam_post_id={post_id} AND tester_email="{tester_email}" AND create_datetime<="{exam_end_datetime}" ORDER BY create_datetime DESC';
$sql2=str_replace(
array('{TBL_EXAM}','{post_id}','{tester_email}','{exam_end_datetime}'),
array(TBL_EXAM, $post->ID, $v->tester_email, get_post_meta($post->ID, 'exam_end_datetime', true).':00' #MUST <=exam_end_datetime
),$sql2);
$tester_all_answer_in_this_exam = $wpdb->get_results($sql2);
$sql2b='SELECT totalscore,optscore,textareascore FROM '.TBL_EXAM_SCORE.' WHERE answer_id='.$tester_all_answer_in_this_exam[0]->id. ' ORDER BY give_score_datetime DESC LIMIT 1';
$score_row = $wpdb->get_row($sql2b);
$totalscore = $score_row->totalscore;
$optscore = $score_row->optscore;
$textareascore = $score_row->textareascore;
echo''.implode(' ',array(
$v->tester_name #. ($IS_DEVELOPER_DEBUG ? ' '.$sql2 : '')
,
$v->tester_email #. ($IS_DEVELOPER_DEBUG ? ' '.$sql2b : '')
,
''.$tester_all_answer_in_this_exam[0]->create_datetime.' ',
$optscore,
$textareascore,
$totalscore,
''.count($tester_all_answer_in_this_exam).' '
)).' ';
}
echo'
';#end of id=tester
exit;
}
# Start $_id and $_tester_email ....
#step3
/*$pagesize = 50;
$page = isset($_GET['page'])&&$_GET['page']+0 ? $_GET['page']+0 : 1;
if(!$page){$page=1;}*/ $pagesize=50;$page=1;
echo'';
echo'請選擇要批考此考生哪份時間點(倒序時間)的考卷 (只顯示TOP'.$pagesize.'): ';
#$querystring_prefix = '?id='.($_GET['id']).'&tester_email='.$_GET['tester_email'];
#echo $pgr = '上一頁 下一頁
';
echo'
考生姓名
Email
作答時間
紀錄模式
選擇評分
問答評分
總評分
評分人
評分時間
';
$exam_end_datetime = get_post_meta($_id, 'exam_end_datetime',true).':00';
$sql='SELECT * FROM '.TBL_EXAM.' WHERE exam_post_id='.$_id.' AND tester_email="'.$_tester_email.'" AND create_datetime<="'.$exam_end_datetime.'" ORDER BY create_datetime DESC LIMIT '.($pagesize*($page-1)).','.($pagesize);
$user = wp_get_current_user();if($user->user_login==='vansindata'){echo$sql.' ';}
foreach($wpdb->get_results($sql)as$k=>$v){
$score_row = null;
$is_last_exam_answer = ($k===0);
if($is_last_exam_answer){
$sql2='SELECT * FROM '.TBL_EXAM_SCORE.' WHERE exam_id='.$_id.' ORDER BY give_score_datetime DESC';
if($IS_DEVELOPER_DEBUG){echo$sql2.' ';}
$score_row = $wpdb->get_row($sql2);
}
echo '
'.implode(' ',array(
$v->tester_name, $v->tester_email,
$is_last_exam_answer ? ''.$v->create_datetime.' ' : $v->create_datetime,
AIAExam::display_is_save_manually_text($v->is_save_manually),
$score_row ? $score_row->optscore : '',
$score_row ? $score_row->textareascore : '',
$score_row ? $score_row->totalscore : '',
$score_row ? $score_row->give_score_by : '',
$score_row ? $score_row->give_score_datetime : '',
)).'
';
}
echo'
';
#echo$pgr;