/** * 考试进行中 */ public function doMobileStart() { global $_GPC, $_W; $this->check_member(); $weid = $_W['uniacid']; $pindex = max(1, intval($_GPC['page'])); $psize = 1; $paperid = intval($_GPC['paperid']); $recordid = intval($_GPC['recordid']); $types_config = $this->_types_config; $answer_array = $this->_answer_array; if (empty($paperid) || empty($recordid)) { echo "传递参数错误"; exit; } $record_info = $this->getRecordInfo($recordid); //该试卷已经完成,不能再继续了 if ($record_info['did'] == 1) { echo "该试卷已经完成,不能再继续了"; exit; } $member_info = $this->getMemberInfo(); //提交答案 if (checksubmit('submit')) { $data = array(); $data['result'] = 1; $count_flag = intval($_GPC['count_flag']); $questionid = intval($_GPC['questionid']); $now_page = intval($_GPC['now_page']); $btime = intval($_GPC['btime']); $type = intval($_GPC['type']); $items = ""; $answer = ""; $now_time = time(); //试题类型 switch ($type) { case 1: //判断题 $answer = $_GPC['answer1']; break; case 2: //单选题 $answer = $_GPC['answer2']; break; case 3: //多选题 $arr = $_GPC['answer3']; if (empty($arr)) { $answer = ''; } else { $answer = implode("", $arr); } break; } //判断答案是否正确 $now_question_info = get_one_question($questionid); if (empty($answer)) { $isright = 0; } else { if ($now_question_info['answer'] == $answer) { $isright = 1; } else { $isright = 0; } } //判断用户是否回答过 $params = array(); $params[':weid'] = $weid; $params[':paperid'] = $paperid; $params[':memberid'] = $member_info['id']; $params[':recordid'] = $recordid; $params[':questionid'] = $questionid; $item = get_one_member_question($params); //要添加或者更新的数据 $array = array(); $array['isright'] = $isright; $array['answer'] = $answer; $array['type'] = $type; $array['pageid'] = $now_page; if ($item) { //已经回答过 pdo_update('ewei_exam_paper_member_data', $array, array('id' => $item['id'])); if ($isright == 1 && $item['isright'] == 0) { //多少人正确+1 $this->updateQuestionMemberNum($questionid, 2); } } else { //还没有回答过 $array['weid'] = $weid; $array['paperid'] = $paperid; $array['memberid'] = $member_info['id']; $array['recordid'] = $recordid; $array['questionid'] = $questionid; $array['createtime'] = $now_time; pdo_insert('ewei_exam_paper_member_data', $array); if ($isright) { //多少人做过,正确+1 $this->updateQuestionMemberNum($questionid, 3); } else { //多少人做过+1 $this->updateQuestionMemberNum($questionid, 1); } } //统计该用户当前试卷的做题情况 if ($count_flag) { $paper_info = $this->getPaperInfo($paperid); $total = $paper_info['total']; $now_total = get_count_one_paper_record($params); if ($now_total == $total) { $msg = "共" . $total . "题,您已全部做完"; } else { $msg = "共" . $total . "题,您做了" . $now_total . "题,还剩" . ($total - $now_total) . "题未做"; } $data['count_msg'] = $msg; } die(json_encode($data)); } else { $question_item = get_paper_question_list($paperid); $total = count($question_item); $ac = $_GPC['ac']; //获取题目信息 if ($ac == "getDate") { $data = array(); $data['result'] = 1; if ($pindex > $total) { $data['result'] = 0; $data['error'] = "抱歉,题数参数错误"; echo 12345; exit; die(json_encode($data)); } $question_info = $question_item[$pindex - 1]; if (!$question_info) { $data['result'] = 0; $data['error'] = "抱歉,试题错误"; die(json_encode($data)); } //判断用户是否回答过 $params = array(); $params[':weid'] = $weid; $params[':paperid'] = $paperid; $params[':memberid'] = $member_info['id']; $params[':recordid'] = $recordid; $params[':questionid'] = $question_info['id']; $item = get_one_member_question($params); if ($item) { //已经回答过 $is_has = 1; } else { //还没有回答过 $is_has = 0; } $page_array = get_page_array($total, $pindex, $psize); ob_start(); include $this->template('question_form'); $data['code'] = ob_get_contents(); ob_clean(); $data['total'] = $total; $data['isshow'] = $page_array['isshow']; if ($page_array['isshow'] == 1) { $data['nindex'] = $page_array['nindex']; } die(json_encode($data)); } else { if ($ac == "close_exam") { $paper_info = $this->getPaperInfo($paperid); $now_question = $this->getRecordQuestion($paper_info, $recordid); //结束本次考试记录 $data = array(); $data['score'] = $now_question['score']; $data['did'] = 1; pdo_update('ewei_exam_paper_member_record', $data, array('id' => $recordid)); //计算平均分和用时 $sql = "SELECT AVG(score) as avg_score, AVG(times) as avg_times FROM " . tablename('ewei_exam_paper_member_record'); $sql .= " WHERE paperid = :paperid AND weid = :weid AND did = 1"; $question_item = pdo_fetch($sql, array(':paperid' => $paperid, ':weid' => $weid)); $avg_score = round($question_item['avg_score'], 2); $avg_times = $question_item['avg_times']; //更新到试卷信息表中 $data = array(); $data['avscore'] = $avg_score; $data['avtimes'] = $avg_times; pdo_update('ewei_exam_paper', $data, array('id' => $paperid)); $url = $this->createMobileUrl('score', array('paperid' => $paperid, 'recordid' => $recordid)); die(json_encode(array("result" => 1, "url" => $url))); } else { if ($ac == "update_countdown") { $paper_info = $this->getPaperInfo($paperid); if ($record_info['countdown'] > 0) { $countdown = intval($_GPC['total_time']); //更新考试剩余时间 $data = array(); $data['countdown'] = $countdown; $data['times'] = $paper_info['times'] * 60 - $countdown; pdo_update('ewei_exam_paper_member_record', $data, array('id' => $recordid)); } else { $data['times'] = $paper_info['times'] * 60; pdo_update('ewei_exam_paper_member_record', $data, array('id' => $recordid)); } } else { $paper_info = $this->getPaperInfo($paperid); include $this->template('question'); } } } } }
public function doPaper() { global $_GPC, $_W; $op = $_GPC['op']; $weid = $_W['weid']; $types_config = $this->_types_config; if ($op == 'edit') { //编辑 $id = intval($_GPC['id']); $tid = intval($_GPC['tid']); $year_array = array(); for ($i = date("Y"); $i >= 2000; $i--) { $year_array[] = $i; } if (checksubmit()) { $insert = array('weid' => $weid, 'displayorder' => $_GPC['displayorder'], 'title' => $_GPC['title'], 'level' => $_GPC['level'], 'year' => $_GPC['year'], 'tid' => $_GPC['tid'], 'description' => $_GPC['description'], 'status' => $_GPC['status'], 'pcate' => $_GPC['pcate']); if (empty($id)) { pdo_insert('ewei_exam_paper', $insert); } else { pdo_update('ewei_exam_paper', $insert, array('id' => $id)); } message("试卷信息保存成功!", $this->createWebUrl('paper'), "success"); } if (!empty($id)) { $item = pdo_fetch("select * from " . tablename('ewei_exam_paper') . " where id=:id limit 1", array(":id" => $id)); $tid = $item['tid']; } if (!empty($item)) { $paper_category = pdo_fetch("select id, cname as title from " . tablename('ewei_exam_paper_category') . " where id=:id limit 1", array(':id' => $item['pcate'])); } // if(!empty($item)){ // $paper = pdo_fetch("select id,title from ".tablename('ewei_exam_paper')." where id=:id limit 1",array(':id'=>$item['paperid'])); // } $type_item = pdo_fetch("select * from " . tablename('ewei_exam_paper_type') . " where id=:id limit 1", array(':id' => $tid)); $types = unserialize($type_item['types']); if (!empty($id)) { $question_array = array(); $question_array['id'] = $id; $question_array['types'] = $types; $d_question = $this->getDefaultPaperQuestion($question_array); $now_question_data = $d_question['data']; } //print_r($question_item);exit; include $this->template('paper_form'); } else { if ($op == 'editquestion') { session_start(); $_SESSION['last_url'] = $_SERVER['REQUEST_URI']; //编辑 $id = intval($_GPC['id']); $tid = intval($_GPC['tid']); if (checksubmit()) { //更改排序 foreach ($_GPC['displayorder'] as $k => $v) { if (empty($v)) { $v = 0; } pdo_update('ewei_exam_paper_question', array('displayorder' => $v), array('paperid' => $id, 'questionid' => $k)); } } if (!empty($id)) { $item = pdo_fetch("select * from " . tablename('ewei_exam_paper') . " where id=:id limit 1", array(":id" => $id)); $tid = $item['tid']; } if (!empty($item)) { $paper_category = pdo_fetch("select id, cname as title from " . tablename('ewei_exam_paper_category') . " where id=:id limit 1", array(':id' => $item['pcate'])); } $type_item = pdo_fetch("select * from " . tablename('ewei_exam_paper_type') . " where id=:id limit 1", array(':id' => $tid)); $types = unserialize($type_item['types']); if (!empty($id)) { $question_array = array(); $question_array['id'] = $id; $question_array['types'] = $types; $d_question = $this->getDefaultPaperQuestion($question_array); $now_question_data = $d_question['data']; } $question_item = get_paper_question_list($id); //print_r($question_item);exit; include $this->template('paper_question_form'); } else { if ($op == 'delete') { $id = intval($_GPC['id']); pdo_delete("ewei_exam_paper_question", array("paperid" => $id)); //pdo_delete("ewei_exam_paper_member", array("questionid" => $id)); //pdo_delete("ewei_exam_paper_member_data", array("questionid" => $id)); pdo_delete("ewei_exam_paper", array("id" => $id)); message("试题信息删除成功!", referer(), "success"); } else { if ($op == 'deleteall') { foreach ($_GPC['idArr'] as $k => $id) { $id = intval($id); pdo_delete("ewei_exam_paper_question", array("paperid" => $id)); //pdo_delete("ewei_exam_paper_member", array("questionid" => $id)); //pdo_delete("ewei_exam_paper_member_data", array("questionid" => $id)); pdo_delete("ewei_exam_paper", array("id" => $id)); } $this->message('试题信息删除成功!', '', 0); exit; } else { if ($op == 'showall') { if ($_GPC['show_name'] == 'showall') { $show_status = 1; } else { $show_status = 0; } foreach ($_GPC['idArr'] as $k => $id) { $id = intval($id); if (!empty($id)) { pdo_update('ewei_exam_paper', array('status' => $show_status), array('id' => $id)); } } //message('操作成功!', '', 0); exit; } else { if ($op == 'status') { $id = intval($_GPC['id']); if (empty($id)) { message('抱歉,传递的参数错误!', '', 'error'); } $temp = pdo_update('ewei_exam_paper', array('status' => $_GPC['status']), array('id' => $id)); if ($temp == false) { message('抱歉,刚才操作数据失败!', '', 'error'); } else { message('状态设置成功!', referer(), 'success'); } } else { if ($op == 'query') { $kwd = trim($_GPC['keyword']); $sql = "SELECT p.id, p.title, p.description,t.types, t.score FROM " . tablename('ewei_exam_paper') . " AS p"; $sql .= " LEFT JOIN " . tablename('ewei_exam_paper_type') . " AS t on p.tid = t.id"; $sql .= " WHERE p.weid = :weid"; $params = array(); $params[':weid'] = $_W['weid']; if (!empty($kwd)) { $sql .= " AND p.title LIKE :title"; $params[':title'] = "%{$kwd}%"; } $ds = pdo_fetchall($sql, $params); foreach ($ds as $key => $value) { $value['types'] = unserialize($value['types']); $d_question = $this->getDefaultPaperQuestion($value); $ds[$key]['now_score'] = $d_question['score']; $now_question_data = $d_question['data']; $pager_str = '该试卷包含 '; foreach ($value['types'] as $k => $v) { if ($v['has'] == 1) { $pager_str .= $types_config[$k] . "(" . $now_question_data[$k]['num'] . "/" . $v['num'] . ")道 "; } } $ds[$key]['pager_str'] = $pager_str; } include $this->template('paper_query'); } else { $pindex = max(1, intval($_GPC['page'])); $psize = 20; $sql = ""; $params = array(); if (!empty($_GPC['title'])) { $sql .= ' AND p.title LIKE :keywords'; $params[':keywords'] = "%{$_GPC['title']}%"; } if (!empty($_GPC['level'])) { $sql .= ' AND p.level=:level'; $params[':level'] = intva($_GPC['level']); } if (!empty($_GPC['pcate'])) { $pcate = intval($_GPC['pcate']); //判断是否为一级分类 $cate_sql = "SELECT id FROM " . tablename('ewei_exam_paper_category'); $cate_sql .= " WHERE parentid = " . $pcate; $cate_sql .= " AND weid = " . $weid; //$cate_sql .= " AND status = 1"; $item = pdo_fetchall($cate_sql); $cate_num = count($item); if ($cate_num == 0) { $sql .= " AND p.pcate = :pcate"; $params[':pcate'] = $pcate; } else { if ($cate_num > 0) { $item[$cate_num]['id'] = $pcate; $cate_str = ''; foreach ($item as $k => $v) { $cate_str .= $v['id'] . ","; } $cate_str = trim($cate_str, ","); $sql .= " AND p.pcate in (" . $cate_str . ")"; } } } $pindex = max(1, intval($_GPC['page'])); $psize = 20; $select_sql = "SELECT p.*, t.score, t.times FROM " . tablename('ewei_exam_paper') . " as p"; $select_sql .= " LEFT JOIN " . tablename('ewei_exam_paper_type') . " as t on p.tid = t.id"; $select_sql .= " WHERE p.weid = '{$_W['weid']}' {$sql} ORDER BY displayorder DESC LIMIT " . ($pindex - 1) * $psize . ',' . $psize; $list = pdo_fetchall($select_sql, $params); $count_sql = "SELECT COUNT(p.id) FROM " . tablename('ewei_exam_paper') . " as p"; $count_sql .= " LEFT JOIN " . tablename('ewei_exam_paper_type') . " as t on p.tid = t.id"; $count_sql .= " WHERE p.weid = '{$_W['weid']}'" . $sql; $category = pdo_fetchall("SELECT * FROM " . tablename('ewei_exam_paper_category') . " WHERE weid = '{$_W['weid']}' AND status = 1 ORDER BY parentid ASC, displayorder DESC"); //print_r($category);exit; $total = pdo_fetchcolumn($count_sql, $params); $pager = pagination($total, $pindex, $psize); include $this->template('paper'); } } } } } } } }