public function actionSavepreview()
 {
     $test_id = isset($_POST['test_id']) ? $_POST['test_id'] : '';
     $course_id = isset($_POST['course_id']) ? $_POST['course_id'] : '';
     $lecture_id = isset($_POST['lecture_id']) ? $_POST['lecture_id'] : '';
     $ques_id = isset($_POST['question_id']) ? $_POST['question_id'] : '';
     $type_ques = isset($_POST['question_type']) ? $_POST['question_type'] : '';
     $point = isset($_POST['point']) ? $_POST['point'] : '';
     $total = isset($_POST['total']) ? $_POST['total'] : '';
     $test_kind = isset($_POST['test_kind']) ? $_POST['test_kind'] : '';
     $user_test_id = isset($_POST['user_test_id']) ? $_POST['user_test_id'] : '';
     $rdOne = isset($_POST['rdOne']) ? $_POST['rdOne'] : '';
     //var_dump($rdOne);exit();
     $txtFree = isset($_POST['txtFree']) ? $_POST['txtFree'] : '';
     $chkMulti = isset($_POST['chkMulti']) ? $_POST['chkMulti'] : '';
     if (WUserAnswers::deleteAnswerByUT($user_test_id) && WUserTest::updatePoint($user_test_id)) {
         $i = 1;
         foreach ($ques_id as $q) {
             $arrUT = WUserTest::model()->find('id=:id', array(':id' => $user_test_id));
             $point_current = $arrUT['pass_score_point'];
             $question_type = $type_ques[$i];
             if ($question_type == 1) {
                 $answer = $rdOne[$i];
                 if ($answer != '') {
                     $arrA = array('user_test_id' => $user_test_id, 'question_id' => $q, 'answer_id' => $answer, 'user_answer_id' => $answer, 'user_answer_text' => '', 'created_date' => date('Y-m-d H:i:s'));
                     WUserAnswers::insertAnswer($arrA);
                 }
                 if (WUserAnswers::checkAnswer($q, $question_type, $user_test_id)) {
                     $point_user = $point_current + $point[$i];
                 } else {
                     $point_user = $point_current;
                 }
                 //WUserTest::updatePointTrainee($test_id, $course_id, $lecture_id, Yii::app()->user->id, $point_user, $question_type);
                 WUserTest::updatePointTrainee($user_test_id, $point_user, $question_type);
             } elseif ($question_type == 2) {
                 $answer = $txtFree[$i];
                 if ($answer != '') {
                     $arrA = array('user_test_id' => $user_test_id, 'question_id' => $q, 'answer_id' => '', 'user_answer_id' => '', 'user_answer_text' => $answer, 'created_date' => date('Y-m-d H:i:s'));
                     WUserAnswers::insertAnswer($arrA);
                 }
             } elseif ($question_type == 4) {
                 $answers = $chkMulti[$i];
                 $arrValues = array();
                 if (count($answers) > 0) {
                     foreach ($answers as $a) {
                         $a = !empty($a) ? $a : NULL;
                         $arrValues[] = '("", ' . $user_test_id . ', ' . $q . ', ' . $a . ', ' . $a . ', "", "' . date("Y-m-d H:i:s") . '")';
                     }
                     $sql = "INSERT INTO {{user_answers}} (`id`, `user_test_id`, `question_id`, `answer_id`, `user_answer_id`, `user_answer_text`, `created_date`) VALUES " . implode(',', $arrValues) . "";
                     WUserAnswers::insertAnswerM($sql);
                 }
                 if (WUserAnswers::checkAnswer($q, $question_type, $user_test_id)) {
                     $point_user = $point_current + $point[$i];
                 } else {
                     $point_user = $point_current;
                 }
                 //WUserTest::updatePointTrainee($test_id, $course_id, $lecture_id, Yii::app()->user->id, $point_user, $question_type);
                 WUserTest::updatePointTrainee($user_test_id, $point_user, $question_type);
             }
             $i++;
         }
         $this->redirect(array('wTest/result', 'test_id' => $test_id, 'course_id' => $course_id, 'lecture_id' => $lecture_id, 'total' => $total, 'kind' => $test_kind));
     }
 }