Beispiel #1
0
 /**
  * 判断用户是否有权限参加此考试,判断包括:
  * 1.是否在权限列表 0
  * 2.考试是否存在或可见 -1
  * 3.如果是vip考试,是否在不同机器上登陆过  -2
  * 4.可选。是否已经交卷 -3
  * @param  number $eid 比赛编号
  * @param  string $user_id 用户ID]
  * @param  boolean $havetaken 是否判断已经参加考试过
  * @return number|array        返回数字表示没有权限,否则有
  */
 public function checkExamPrivilege($eid, $user_id, $havetaken = false)
 {
     $hasPrivilege = $this->getPrivilege($user_id, $eid);
     if (!(checkAdmin(2) || $hasPrivilege)) {
         return 0;
     }
     $field = array('title', 'start_time', 'end_time', 'isvip', 'visible');
     $row = ExamBaseModel::instance()->getExamInfoById($eid, $field);
     if (empty($row)) {
         return -1;
     }
     if (C('OJ_VIP_CONTEST')) {
         if ($row['isvip'] == 'Y') {
             $today = date('Y-m-d');
             $ip1 = $_SERVER['REMOTE_ADDR'];
             $sql = "SELECT `user_id` FROM `loginlog` WHERE `user_id`='{$user_id}' AND `time`>='{$today}' AND ip<>'{$ip1}' AND\n\t\t\t\t `user_id` NOT IN( SELECT `user_id` FROM `privilege` WHERE `rightstr`='administrator' or `rightstr`='contest_creator') ORDER BY `time` DESC limit 0,1";
             $tmprow = M()->query($sql);
             if ($tmprow) {
                 return -2;
             }
         }
     }
     if ($havetaken) {
         $where = array('user_id' => $user_id, 'exam_id' => $eid);
         $field = array('score');
         $score = StudentBaseModel::instance()->queryOne($where, $field);
         if (!is_null($score['score']) && $score['score'] >= 0) {
             return -3;
         }
     }
     return $row;
 }
 public function index()
 {
     if (!$this->isSuperAdmin()) {
         if ($this->isCreator()) {
             $userId = $this->userInfo['user_id'];
             $_where = array('isprivate' => 0, 'creator' => array('eq', $userId), '_logic' => 'or');
             $where = array('visible' => 'Y', '_complex' => $_where, '_logic' => 'and');
         } else {
             $where = array('user_id' => $this->userInfo['user_id']);
             $fields = array('rightstr');
             $privileges = M('ex_privilege')->field($fields)->where($where)->select();
             $examIds = array(0);
             foreach ($privileges as $privilege) {
                 $rightstr = $privilege['rightstr'];
                 $examIds[] = intval(substr($rightstr, 1));
             }
             $where = array('visible' => 'Y', 'exam_id' => array('in', $examIds));
         }
     } else {
         $where = array('visible' => 'Y');
     }
     $mypage = splitpage('exam', $where);
     $where['order'] = array('end_time desc');
     $where['limit'] = $mypage['sqladd'];
     $field = array('exam_id', 'title', 'start_time', 'end_time');
     $row = ExamBaseModel::instance()->queryData($where, $field);
     $this->zadd('row', $row);
     $this->zadd('mypage', $mypage);
     $this->auto_display();
 }
 /**
  * 是否可以查看某场考试的信息
  * @param $eid
  * @param bool|false $isReturn
  * @return mixed
  */
 protected function isCanWatchInfo($eid, $isReturn = false)
 {
     $field = array('creator', 'isprivate', 'end_time');
     $res = ExamBaseModel::instance()->getExamInfoById(intval($eid), $field);
     $hasPrivilege = false;
     if ($res['isprivate'] == PrivilegeBaseModel::PROBLEM_PUBLIC && $this->isCreator()) {
         $hasPrivilege = true;
     }
     if (!($this->isSuperAdmin() || $this->isOwner4ExamByUserId($res['creator']) || $hasPrivilege)) {
         $this->echoError('You have no privilege of this exam');
     }
     if ($isReturn) {
         return $res;
     }
 }
Beispiel #4
0
 public function exam()
 {
     if (!$this->isOwner4ExamByExamId($this->id)) {
         $this->echoError('You have no privilege!');
     } else {
         $data = array('visible' => 'N');
         ExamBaseModel::instance()->updateById($this->id, $data);
         $this->success("考试删除成功", U("Teacher/Index/index", array('page' => $this->page)), 2);
         //if the exam was deleted
         //the info of exam was deleted
         // $query="DELETE FROM `exp_question` WHERE `exam_id`='$id'";
         // $query="DELETE FROM `ex_privilege` WHERE `rightstr`='e$id'";
         // $query="DELETE FROM `ex_stuanswer` WHERE `exam_id`='$id'";
         // $query="DELETE FROM `ex_student` WHERE `exam_id`='$id'";
     }
 }
Beispiel #5
0
 private function saveFillAnswer($user_id, $eid, $issave)
 {
     $cntfill = 0;
     $tempsql = "";
     $fillsum = 0;
     $fillq = $this->getQuestion4ExamByType($eid, FillBaseModel::FILL_PROBLEM_TYPE, $issave);
     if (!$issave) {
         $field = array('fillscore', 'prgans', 'prgfill');
         $score = ExamBaseModel::instance()->getExamInfoById($eid, $field);
     }
     foreach ($fillq as $value) {
         $aid = $value['answer_id'];
         $fid = $value['fill_id'];
         $name = $fid . "tkda";
         if (isset($_POST["{$name}{$aid}"])) {
             $myanswer = $_POST["{$name}{$aid}"];
             $myanswer = test_input($myanswer);
             $myanswer = addslashes($myanswer);
             if ($cntfill == 0) {
                 $tempsql = "INSERT INTO `ex_stuanswer` VALUES('{$user_id}','{$eid}','3','{$fid}','{$aid}','{$myanswer}')";
                 $cntfill = 1;
             } else {
                 $tempsql = $tempsql . ",('{$user_id}','{$eid}','3','{$fid}','{$aid}','{$myanswer}')";
             }
             if (!$issave) {
                 $rightans = addslashes($value['answer']);
                 if ($myanswer == $rightans && strlen($myanswer) == strlen($rightans)) {
                     if ($value['kind'] == 1) {
                         $fillsum += $score['fillscore'];
                     } else {
                         if ($value['kind'] == 2) {
                             $fillsum = $fillsum + $score['prgans'] / $value['answernum'];
                         } else {
                             if ($value['kind'] == 3) {
                                 $fillsum = $fillsum + $score['prgfill'] / $value['answernum'];
                             }
                         }
                     }
                 }
             }
         }
     }
     if (!empty($tempsql)) {
         $tempsql = $tempsql . " on duplicate key update `answer`=values(`answer`)";
         M()->execute($tempsql);
     }
     if (!$issave) {
         return $fillsum;
     }
 }
Beispiel #6
0
 public function getBaseScoreByExamId($eid)
 {
     $field = array('choosescore', 'judgescore', 'fillscore', 'prgans', 'prgfill', 'programscore');
     $allScore = ExamBaseModel::instance()->getExamInfoById($eid, $field);
     return $allScore;
 }
Beispiel #7
0
 private function dojudgeone($eid, $userId)
 {
     $field = array('start_time', 'end_time');
     $prirow = ExamBaseModel::instance()->getExamInfoById($eid, $field);
     $start_timeC = strftime("%Y-%m-%d %X", strtotime($prirow['start_time']));
     $end_timeC = strftime("%Y-%m-%d %X", strtotime($prirow['end_time']));
     $rightstr = "e{$eid}";
     $cnt1 = M('ex_privilege')->where("user_id='%s' and rightstr='%s'", $userId, $rightstr)->count();
     if ($cnt1 == 0) {
         $this->echoError('Student ID is Wrong!');
         return false;
     }
     if (time() < $start_timeC) {
         $this->echoError('Exam Not Start');
     }
     $mark = M('ex_student')->where("exam_id=%d and user_id='%s'", $eid, $userId)->count();
     $this->rejudgepaper($userId, $eid, $start_timeC, $end_timeC, $mark);
     return true;
 }
Beispiel #8
0
 private function getEachProgramAvgScore($programIds, $personCnt, $sqladd)
 {
     $examId = $this->eid;
     $ans = array();
     foreach ($programIds as $_programId) {
         $programId = $_programId['question_id'];
         if ($personCnt == 0) {
             $ans[$programId] = 0;
             continue;
         }
         $allScore = ExamService::instance()->getBaseScoreByExamId($examId);
         $examBase = ExamBaseModel::instance()->getById($examId);
         $sTime = $examBase['start_time'];
         $eTime = $examBase['end_time'];
         $programScore = $allScore['programscore'];
         $sql = "select (sum(rate) * {$programScore} / {$personCnt}) as r from (" . "select user_id, if(max(pass_rate)=0.99, 1, max(pass_rate)) as rate from solution " . "where problem_id={$programId} and pass_rate > 0 and " . "in_date>='{$sTime}' and in_date<='{$eTime}' {$sqladd} group by user_id" . ") t";
         $res = M()->query($sql);
         if (empty($res)) {
             $ans[$programId] = 0;
         } else {
             $ans[$programId] = isset($res[0]['r']) ? $res[0]['r'] : 0;
         }
     }
     return $ans;
 }
Beispiel #9
0
 public function copyOneExam()
 {
     $eid = I('get.eid', 0, 'intval');
     $row = ExamBaseModel::instance()->getExamInfoById($eid);
     if (empty($row)) {
         $this->echoError("No Such Exam!");
     }
     if (!$this->isOwner4ExamByUserId($row['creator'])) {
         $this->echoError('You have no privilege!');
     } else {
         // copy exam's base info
         unset($row['exam_id']);
         $row['creator'] = $this->userInfo['user_id'];
         $examId = ExamBaseModel::instance()->insertData($row);
         if (empty($examId)) {
             $this->echoError("复制考试失败,请刷新页面重试");
         }
         // copy exam's problem
         $field = array('exam_id', 'question_id', 'type');
         $res = QuestionBaseModel::instance()->getQuestionByExamId($eid, $field);
         foreach ($res as &$r) {
             $r['exam_id'] = $examId;
         }
         unset($r);
         QuestionBaseModel::instance()->insertQuestions($res);
         $this->success('考试复制成功!', U('/Teacher'), 1);
     }
 }