示例#1
0
 function init()
 {
     $this->exam_hash = array_shift($this->param);
     $this->page = array_shift($this->param);
     $course = new Course();
     $training = new Training();
     $t_data = $training->get(array('exam_hash' => $this->exam_hash, 'user_id' => $_SESSION['user_id']));
     $c_data = $course->get(array('id' => $t_data['course_id']));
     switch ($t_data['status_id']) {
         case Training::EXAM:
             // fill table "exams" with questions from table "questions"
             // via cross select course_id and question_id
             if (intval($c_data['exam_duration']) < 1) {
                 $c_data['exam_duration'] = 30;
             }
             $training->update($t_data['id'], array('status_id' => Training::EXAM_STARTED, 'exam_started' => date('Y-m-d H:i', time()), 'finished' => date('Y-m-d H:i', time() + $c_data['exam_duration'] * 60)));
             $question = new Question();
             $enum = $question->enumerateIDs(array('course_id' => $t_data['course_id']));
             foreach ($enum as $val) {
                 $questions[] = $val['id'];
             }
             $exam = new Exam();
             srand();
             shuffle($questions);
             for ($i = 0; $i < $c_data['questions']; $i++) {
                 $question_id = array_shift($questions);
                 if (!isset($question_id)) {
                     break;
                 }
                 $exam->add(array('question_id' => $question_id, 'training_id' => $t_data['id']));
             }
             header("Location: /exam/{$this->exam_hash}/0");
             exit;
             break;
         case Training::EXAM_STARTED:
             if (isset($_POST['answer'])) {
                 if (is_array($_POST['answer'])) {
                     $_POST['answer'] = implode(',', $_POST['answer']);
                 }
                 $exam = new Exam();
                 $e_data = $exam->get(array('id' => $_POST['id'], 'training_id' => $t_data['id']));
                 $exam->update($e_data['id'], array('answer' => $_POST['answer']));
                 $this->page++;
                 header("Location: /exam/{$this->exam_hash}/{$this->page}");
                 exit;
             }
             break;
         default:
             header('Location: /403');
             exit;
     }
 }
示例#2
0
function showExam()
{
    global $connector;
    $student = new Student();
    $plan = new Plan();
    $course = new Course();
    $subject = new Subject();
    $exam = new Exam();
    $student->setConnector($connector);
    $plan->setConnector($connector);
    $course->setConnector($connector);
    $subject->setConnector($connector);
    $exam->setConnector($connector);
    if (isset($_POST['operation'])) {
        list($operation, $params) = explode("#", $_POST['operation']);
        switch ($operation) {
            case 'selectStudent':
                $stud = $student->getById($_POST['id_studente']);
                $studentPlan = $plan->getById($stud->id_plan);
                $result['edit']->student = $stud;
                $result['edit']->planList = $studentPlan;
                $result['edit']->exam = $exam->getList($stud);
                break;
            case 'delete':
                $error_msg = $exam->delete($_POST['id_studente'], $params);
                $stud = $student->getById($_POST['id_studente']);
                $studentPlan = $plan->getById($stud->id_plan);
                $result['edit']->student = $stud;
                $result['edit']->planList = $studentPlan;
                $result['edit']->exam = $exam->getList($stud);
                break;
            case 'edit':
                $stud = $student->getById($_POST['id_studente']);
                $studentPlan = $plan->getById($stud->id_plan);
                $curr_exam = $exam->getById($stud->id, $params);
                $result['edit']->subject_id = $curr_exam->id_subject;
                $result['edit']->vote = $curr_exam->vote;
                $result['edit']->date = $curr_exam->date;
                $result['edit']->student = $stud;
                $result['edit']->planList = $studentPlan;
                $result['edit']->exam = $exam->getList($stud);
                break;
            case 'editChanges':
                $exam->storeFormValues($_POST);
                $error_msg = $exam->update();
                $stud = $student->getById($_POST['id_studente']);
                $studentPlan = $plan->getById($stud->id_plan);
                $result['edit']->student = $stud;
                $result['edit']->planList = $studentPlan;
                $result['edit']->exam = $exam->getList($stud);
                break;
            case 'saveChanges':
                $exam->storeFormValues($_POST);
                $error_msg = $exam->insert();
                $stud = $student->getById($_POST['id_studente']);
                $studentPlan = $plan->getById($stud->id_plan);
                $result['edit']->student = $stud;
                $result['edit']->planList = $studentPlan;
                $result['edit']->exam = $exam->getList($stud);
                break;
            default:
                $error_msg = "Operazione non valida";
        }
        if ($error_msg != "") {
            $result["errorMessage"] = $error_msg;
        } elseif ($operation != 'edit' && $operation != 'selectStudent') {
            $result["statusMessage"] = "Operazione completata!";
        }
    }
    $result["students"] = $student->getList("cognome");
    $page = "exam.php";
    include_once BASE_PATH . "template.php";
}