<?php
// +----------------------------------------------------------------------+
// | PHP version 4                                                        |
// +----------------------------------------------------------------------+
// | Copyright (c) 1997-2005 Snapshot Inc.                                |
// +----------------------------------------------------------------------+
// | License                                                              |
// | GNU General Public License                                           |
// +----------------------------------------------------------------------+
// | Authors: Mai Kawasaki                                                |
// +----------------------------------------------------------------------+
//
// $Id: StartAction.class.php,v 1.1 2005/06/20 09:31:26 snapshot Exp $
//
// Description:
// 2005/05/18
//

/** 
*	StartAction.class.php
*	Mai Kawasaki
*	2005/05/18
*/
require_once(OPT_DIR.'u-learning/config.php');
require_once(OPT_DIR.'u-learning/action/SecureStudentAction.class.php');
require_once(OPT_DIR.'u-learning/data/Subject.class.php');
require_once(OPT_DIR.'u-learning/data/Admin.class.php');
require_once(OPT_DIR.'u-learning/data/AdminExam.class.php');
require_once(OPT_DIR.'u-learning/data/StudentExam.class.php');
require_once(OPT_DIR.'u-learning/data/Student.class.php');

/** 
*	StartAction
*/
class StartAction extends SecureStudentAction {
    function execute (&$controller, &$request, &$user) {
		// ブラウザの判別
		$type = $this->getUserAgentType();
		$request->setAttribute('type', $type);
			
		$DB = $request->getAttribute('DB');
		// 教員情報取得
		$request->setAttribute('admin', new Admin($user->getAttribute('aid'), $DB));
		$eid = $request->getParameter('eid');
		// テスト情報取得
		$exam = new AdminExam($eid, $DB);
    	$sql_count = "select count(eid) as count from admin_question where eid = ".$eid;
    	$count =  $DB->GetOne($sql_count);
    	$sql_point = "select sum(point) as points from admin_question where eid = ".$eid;
    	$points =  $DB->GetOne($sql_point);
		// 科目情報取得
		$subject = new Subject($exam->sid, $DB);

		// 選択したテストの回答状況取得
		$student = new Student($user->getAttribute('aid'), $user->getAttribute('uid'), $DB);
		$exams_student = $student->getExamsStudentByExam($eid, $DB);

		$exam_student = new StudentExam();
		$exam_student->aid = $user->getAttribute('aid');
		$exam_student->uid = $user->getAttribute('uid');
		$exam_student->eid = $eid;		
		$rid = $exam_student->getUnansweredID($DB);
		if(count($exams_student) > 0){
			if ( $rid == '' || is_null($rid) ){
				$request->setAttribute('reply_flug', '1');
			} else{
				$request->setAttribute('reply_flug', '2');
			}
		} else{
			if ( $rid == '' || is_null($rid) ){
				$request->setAttribute('reply_flug', '0');
			} else{
				$request->setAttribute('reply_flug', '2');
			}
		}
		$request->setAttribute('exam', $exam);
		$request->setAttribute('subject', $subject);
		$request->setAttribute('count', $count);
		$request->setAttribute('points', $points);
		$request->setAttribute('exams_student', $exams_student);
	
		return VIEW_SUCCESS;
    }
}

?>