|
@@ -239,12 +239,13 @@ switch ($action) {
|
|
|
$h = floor($remaining/3600);
|
|
|
$m = floor(($remaining - ($h*3600))/60);
|
|
|
$s = ($remaining - ($h*3600) - ($m*60));
|
|
|
- $array = array( $row['firstname'],
|
|
|
- $row['lastname'],
|
|
|
- api_format_date($row['start_date'], DATE_TIME_FORMAT_LONG).' ['.($h>0?$h.':':'').sprintf("%02d",$m).':'.sprintf("%02d",$s).']',
|
|
|
- $row['count_questions'],
|
|
|
- round($row['score']*100).'%'
|
|
|
- );
|
|
|
+ $array = array(
|
|
|
+ $row['firstname'],
|
|
|
+ $row['lastname'],
|
|
|
+ api_format_date($row['start_date'], DATE_TIME_FORMAT_LONG).' ['.($h>0?$h.':':'').sprintf("%02d",$m).':'.sprintf("%02d",$s).']',
|
|
|
+ $row['count_questions'],
|
|
|
+ round($row['score']*100).'%'
|
|
|
+ );
|
|
|
$response->rows[$i]['cell'] = $array;
|
|
|
$i++;
|
|
|
}
|
|
@@ -333,6 +334,7 @@ switch ($action) {
|
|
|
}
|
|
|
|
|
|
// Exercise information.
|
|
|
+ /** @var \Exercise $objExercise */
|
|
|
$objExercise = isset($_SESSION['objExercise']) ? $_SESSION['objExercise'] : null;
|
|
|
|
|
|
// Question info.
|
|
@@ -355,15 +357,15 @@ switch ($action) {
|
|
|
// First time here we create an attempt (getting the exe_id).
|
|
|
if (empty($exercise_stat_info)) {
|
|
|
} else {
|
|
|
- //We know the user we get the exe_id
|
|
|
+ // We know the user we get the exe_id.
|
|
|
$exe_id = $exercise_stat_info['exe_id'];
|
|
|
$total_score = $exercise_stat_info['exe_result'];
|
|
|
|
|
|
- //Getting the list of attempts
|
|
|
+ // Getting the list of attempts.
|
|
|
$attempt_list = getAllExerciseEventByExeId($exe_id);
|
|
|
}
|
|
|
|
|
|
- // Updating Reminder algorythm.
|
|
|
+ // Updating Reminder algorythme.
|
|
|
if ($objExercise->type == ONE_PER_PAGE) {
|
|
|
$bd_reminder_list = explode(',', $exercise_stat_info['questions_to_check']);
|
|
|
|
|
@@ -399,7 +401,7 @@ switch ($action) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- // No exe id? Can't save answer.
|
|
|
+ // No exe id? Can't save answer!
|
|
|
if (empty($exe_id)) {
|
|
|
// Fires an error.
|
|
|
echo 'error';
|
|
@@ -433,11 +435,13 @@ switch ($action) {
|
|
|
continue;
|
|
|
}
|
|
|
|
|
|
- if ($debug) error_log("Saving question_id = $my_question_id ");
|
|
|
|
|
|
$my_choice = isset($choice[$my_question_id]) ? $choice[$my_question_id] : null;
|
|
|
|
|
|
- if ($debug) error_log("my_choice = ".print_r($my_choice, 1)."");
|
|
|
+ if ($debug) {
|
|
|
+ error_log("Saving question_id = $my_question_id ");
|
|
|
+ error_log("my_choice = ".print_r($my_choice, 1)."");
|
|
|
+ }
|
|
|
|
|
|
// creates a temporary Question object
|
|
|
$objQuestionTmp = Question::read($my_question_id, $course_id);
|
|
@@ -451,14 +455,14 @@ switch ($action) {
|
|
|
$total_weight += $objQuestionTmp->selectWeighting();
|
|
|
}
|
|
|
|
|
|
- // This variable commes from exercise_submit_modal.php
|
|
|
+ // This variable came from exercise_submit_modal.php
|
|
|
$hotspot_delineation_result = null;
|
|
|
if (isset($_SESSION['hotspot_delineation_result']) && isset($_SESSION['hotspot_delineation_result'][$objExercise->selectId()])) {
|
|
|
$hotspot_delineation_result = $_SESSION['hotspot_delineation_result'][$objExercise->selectId()][$my_question_id];
|
|
|
}
|
|
|
|
|
|
if ($type == 'simple') {
|
|
|
- //Getting old attempt in order to decrees the total score
|
|
|
+ // Getting old attempt in order to decrees the total score.
|
|
|
$old_result = $objExercise->manageAnswers(
|
|
|
$exe_id,
|
|
|
$my_question_id,
|
|
@@ -470,13 +474,19 @@ switch ($action) {
|
|
|
false
|
|
|
);
|
|
|
|
|
|
- //Removing old score
|
|
|
+ // Removing old score.
|
|
|
$total_score = $total_score - $old_result['score'];
|
|
|
+ if ($debug) {
|
|
|
+ error_log("old score = ".$old_result['score']);
|
|
|
+ error_log("total_score = ".$total_score."");
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
// Deleting old attempt
|
|
|
if (isset($attempt_list) && !empty($attempt_list[$my_question_id])) {
|
|
|
- if ($debug) error_log("delete_attempt exe_id : $exe_id, my_question_id: $my_question_id");
|
|
|
+ if ($debug) {
|
|
|
+ error_log("delete_attempt exe_id : $exe_id, my_question_id: $my_question_id");
|
|
|
+ }
|
|
|
delete_attempt($exe_id, api_get_user_id(), $course_id, $session_id, $my_question_id);
|
|
|
if ($objQuestionTmp->type == HOT_SPOT) {
|
|
|
delete_attempt_hotspot($exe_id, api_get_user_id(), $course_id, $my_question_id);
|
|
@@ -503,8 +513,10 @@ switch ($action) {
|
|
|
//Adding the new score
|
|
|
$total_score += $result['score'];
|
|
|
|
|
|
- if ($debug) error_log("total_score: $total_score ");
|
|
|
- if ($debug) error_log("total_weight: $total_weight ");
|
|
|
+ if ($debug) {
|
|
|
+ error_log("total_score: $total_score ");
|
|
|
+ error_log("total_weight: $total_weight ");
|
|
|
+ }
|
|
|
|
|
|
$duration = 0;
|
|
|
$now = time();
|
|
@@ -587,7 +599,121 @@ switch ($action) {
|
|
|
}
|
|
|
echo 'ok';
|
|
|
break;
|
|
|
+ case 'correct_exercise_result':
|
|
|
+
|
|
|
+ $is_allowedToEdit = api_is_allowed_to_edit(null, true) || api_is_drh();
|
|
|
+ $is_tutor = api_is_allowed_to_edit(true);
|
|
|
+
|
|
|
+ //Send student email @todo move this code in a class, library
|
|
|
+ if (isset($_POST['comments']) && $_POST['comments'] == 'update' && ($is_allowedToEdit || $is_tutor) && $_POST['exeid'] == strval(intval($_POST['exeid']))) {
|
|
|
+ $exeId = intval($_POST['exeid']);
|
|
|
+
|
|
|
+ $TBL_QUESTIONS = Database :: get_course_table(TABLE_QUIZ_QUESTION);
|
|
|
+ $TBL_TRACK_EXERCICES = Database :: get_main_table(TABLE_STATISTIC_TRACK_E_EXERCICES);
|
|
|
+ $TBL_TRACK_ATTEMPT = Database :: get_main_table(TABLE_STATISTIC_TRACK_E_ATTEMPT);
|
|
|
+ $TBL_TRACK_ATTEMPT_RECORDING = Database :: get_main_table(TABLE_STATISTIC_TRACK_E_ATTEMPT_RECORDING);
|
|
|
+ $TBL_LP_ITEM_VIEW = Database :: get_course_table(TABLE_LP_ITEM_VIEW);
|
|
|
+
|
|
|
+ $track_exercise_info = ExerciseLib::get_exercise_track_exercise_info($exeId);
|
|
|
+
|
|
|
+ if (empty($track_exercise_info)) {
|
|
|
+ echo 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ $test = $track_exercise_info['title'];
|
|
|
+ $student_id = $track_exercise_info['exe_user_id'];
|
|
|
+ $session_id = $track_exercise_info['session_id'];
|
|
|
+ $lp_id = $track_exercise_info['orig_lp_id'];
|
|
|
+ //$lp_item_id = $track_exercise_info['orig_lp_item_id'];
|
|
|
+ $lp_item_view_id = $track_exercise_info['orig_lp_item_view_id'];
|
|
|
+
|
|
|
+ $course_info = api_get_course_info();
|
|
|
+
|
|
|
+ // Teacher data
|
|
|
+ $teacher_info = api_get_user_info(api_get_user_id());
|
|
|
+
|
|
|
+ $from_name = api_get_person_name(
|
|
|
+ $teacher_info['firstname'],
|
|
|
+ $teacher_info['lastname'],
|
|
|
+ null,
|
|
|
+ PERSON_NAME_EMAIL_ADDRESS
|
|
|
+ );
|
|
|
|
|
|
+ $url = api_get_path(WEB_CODE_PATH).'exercice/result.php?id='.$track_exercise_info['exe_id'].'&'.api_get_cidreq().'&show_headers=1&id_session='.$session_id;
|
|
|
+
|
|
|
+ $commentIds = array();
|
|
|
+ $marks = array();
|
|
|
+ $comments = array();
|
|
|
+
|
|
|
+ $result = array();
|
|
|
+ $values = explode(',', $_POST['vals']);
|
|
|
+ if (empty($values)) {
|
|
|
+ echo 0;
|
|
|
+ exit;
|
|
|
+ }
|
|
|
+
|
|
|
+ $countComments = count($commentIds);
|
|
|
+
|
|
|
+ foreach ($values as $questionId) {
|
|
|
+ $questionId = intval($questionId);
|
|
|
+ $comment = isset($_POST['comments_'.$questionId]) ? $_POST['comments_'.$questionId] : null;
|
|
|
+ $mark = isset($_POST['marks_'.$questionId]) ? $_POST['marks_'.$questionId] : null;
|
|
|
+
|
|
|
+ $mark = Database::escape_string($mark);
|
|
|
+ $comment = Database::escape_string($comment);
|
|
|
+
|
|
|
+ $query = "UPDATE $TBL_TRACK_ATTEMPT SET marks = '$mark', teacher_comment = '$comment'
|
|
|
+ WHERE question_id = ".$questionId." AND exe_id=".$exeId;
|
|
|
+ Database::query($query);
|
|
|
+
|
|
|
+ //Saving results in the track recording table
|
|
|
+ $recording_changes = 'INSERT INTO '.$TBL_TRACK_ATTEMPT_RECORDING.' (exe_id, question_id, marks, insert_date, author, teacher_comment)
|
|
|
+ VALUES ('."'$exeId','".$questionId."','$mark','".api_get_utc_datetime()."','".api_get_user_id()."'".',"'.$comment.'")';
|
|
|
+ Database::query($recording_changes);
|
|
|
+ }
|
|
|
+
|
|
|
+ $qry = 'SELECT DISTINCT question_id, marks FROM '.$TBL_TRACK_ATTEMPT.' WHERE exe_id = '.$exeId.' GROUP BY question_id';
|
|
|
+ $res = Database::query($qry);
|
|
|
+ $tot = 0;
|
|
|
+ while ($row = Database :: fetch_array($res, 'ASSOC')) {
|
|
|
+ $tot += $row['marks'];
|
|
|
+ }
|
|
|
+
|
|
|
+ $sql = "UPDATE $TBL_TRACK_EXERCICES SET exe_result = '".floatval($tot)."' WHERE exe_id = ".$exeId;
|
|
|
+ Database::query($sql);
|
|
|
+
|
|
|
+ if (isset($_POST['send_notification'])) {
|
|
|
+ //@todo move this somewhere else
|
|
|
+ $subject = get_lang('ExamSheetVCC');
|
|
|
+
|
|
|
+ $message = '<p>'.get_lang('DearStudentEmailIntroduction').'</p><p>'.get_lang('AttemptVCC');
|
|
|
+ $message .= '<h3>'.get_lang('CourseName').'</h3><p>'.Security::remove_XSS($course_info['name']).'';
|
|
|
+ $message .= '<h3>'.get_lang('Exercise').'</h3><p>'.Security::remove_XSS($test);
|
|
|
+
|
|
|
+ //Only for exercises not in a LP
|
|
|
+ if ($lp_id == 0) {
|
|
|
+ $message .= '<p>'.get_lang('ClickLinkToViewComment').' <a href="#url#">#url#</a><br />';
|
|
|
+ }
|
|
|
+
|
|
|
+ $message .= '<p>'.get_lang('Regards').'</p>';
|
|
|
+ $message .= $from_name;
|
|
|
+ $message = str_replace("#test#", Security::remove_XSS($test), $message);
|
|
|
+ $message = str_replace("#url#", $url, $message);
|
|
|
+ MessageManager::send_message_simple($student_id, $subject, $message, api_get_user_id());
|
|
|
+ }
|
|
|
+
|
|
|
+ $origin = $_POST['origin'];
|
|
|
+
|
|
|
+ // Updating LP score here
|
|
|
+ if (isset($origin) && in_array($origin, array('tracking_course', 'user_course', 'correct_exercise_in_lp'))) {
|
|
|
+ $sql_update_score = "UPDATE $TBL_LP_ITEM_VIEW SET score = '".floatval($tot)."' WHERE c_id = ".$course_id." AND id = ".$lp_item_view_id;
|
|
|
+ Database::query($sql_update_score);
|
|
|
+ }
|
|
|
+ echo 1;
|
|
|
+ exit;
|
|
|
+ }
|
|
|
+ echo 0;
|
|
|
+ break;
|
|
|
default:
|
|
|
echo '';
|
|
|
}
|