Adding start_date, end_date, duration in reports see #4545

skala
Julio Montoya 13 years ago
parent 14c02d8ae0
commit f11a32b22a
  1. 3
      main/exercice/exercise.lib.php
  2. 249
      main/exercice/exercise_report.php
  3. 267
      main/exercice/exercise_result.class.php
  4. 16
      main/exercice/exercise_result.php
  5. 404
      main/exercice/exercise_submit.php

@ -844,8 +844,7 @@ function get_exam_results_data($from, $number_of_items, $column, $direction, $ex
$sqlFromOption = ""; $sqlFromOption = "";
$sqlWhereOption = ""; // for hpsql $sqlWhereOption = ""; // for hpsql
$sql_inner_join_tbl_user = "";
//@todo fix to work with COURSE_RELATION_TYPE_RRHH in both queries //@todo fix to work with COURSE_RELATION_TYPE_RRHH in both queries
//Hack in order to filter groups //Hack in order to filter groups

@ -5,9 +5,9 @@
* @package chamilo.exercise * @package chamilo.exercise
* @author Julio Montoya <gugli100@gmail.com> jqgrid integration * @author Julio Montoya <gugli100@gmail.com> jqgrid integration
* Modified by hubert.borderiou (question category) * Modified by hubert.borderiou (question category)
* *
* @todo fix excel export * @todo fix excel export
* *
*/ */
/** /**
* Code * Code
@ -46,7 +46,7 @@ $documentPath = api_get_path(SYS_COURSE_PATH) . $_course['path'] . "/document";
/* Constants and variables */ /* Constants and variables */
$is_allowedToEdit = api_is_allowed_to_edit(null,true); $is_allowedToEdit = api_is_allowed_to_edit(null,true);
$is_tutor = api_is_allowed_to_edit(true); $is_tutor = api_is_allowed_to_edit(true);
$TBL_QUESTIONS = Database :: get_course_table(TABLE_QUIZ_QUESTION); $TBL_QUESTIONS = Database :: get_course_table(TABLE_QUIZ_QUESTION);
$TBL_TRACK_EXERCICES = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES); $TBL_TRACK_EXERCICES = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES);
$TBL_TRACK_ATTEMPT = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_ATTEMPT); $TBL_TRACK_ATTEMPT = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_ATTEMPT);
@ -71,15 +71,16 @@ if (!empty($_GET['path'])) {
if (!empty($_REQUEST['export_report']) && $_REQUEST['export_report'] == '1') { if (!empty($_REQUEST['export_report']) && $_REQUEST['export_report'] == '1') {
if (api_is_platform_admin() || api_is_course_admin() || api_is_course_tutor() || api_is_course_coach()) { if (api_is_platform_admin() || api_is_course_admin() || api_is_course_tutor() || api_is_course_coach()) {
$load_extra_data = false; $load_extra_data = false;
if (isset($_REQUEST['extra_data'])) { if (isset($_REQUEST['extra_data']) && $_REQUEST['extra_data'] == 1) {
$load_extra_data = true; $load_extra_data = true;
} }
require_once 'exercise_result.class.php'; require_once 'exercise_result.class.php';
switch ($_GET['export_format']) { switch ($_GET['export_format']) {
case 'xls' : case 'xls' :
$export = new ExerciseResult(); $export = new ExerciseResult();
$export->exportCompleteReportXLS($documentPath, null, $load_extra_data, null, $_GET['exerciseId'], $_GET['hotpotato_name']); $export->exportCompleteReportXLS($documentPath, null, $load_extra_data, null, $_GET['exerciseId'], $_GET['hotpotato_name']);
exit; exit;
break; break;
@ -97,7 +98,7 @@ if (!empty($_REQUEST['export_report']) && $_REQUEST['export_report'] == '1') {
//Send student email @todo move this code in a class, library //Send student email @todo move this code in a class, library
if ($_REQUEST['comments'] == 'update' && ($is_allowedToEdit || $is_tutor) && $_GET['exeid']== strval(intval($_GET['exeid']))) { if ($_REQUEST['comments'] == 'update' && ($is_allowedToEdit || $is_tutor) && $_GET['exeid']== strval(intval($_GET['exeid']))) {
$id = intval($_GET['exeid']); //filtered by post-condition $id = intval($_GET['exeid']); //filtered by post-condition
$track_exercise_info = get_exercise_track_exercise_info($id); $track_exercise_info = get_exercise_track_exercise_info($id);
if (empty($track_exercise_info)) { if (empty($track_exercise_info)) {
api_not_allowed(); api_not_allowed();
@ -109,20 +110,20 @@ if ($_REQUEST['comments'] == 'update' && ($is_allowedToEdit || $is_tutor) && $_G
$lp_id = $track_exercise_info['orig_lp_id']; $lp_id = $track_exercise_info['orig_lp_id'];
//$lp_item_id = $track_exercise_info['orig_lp_item_id']; //$lp_item_id = $track_exercise_info['orig_lp_item_id'];
$lp_item_view_id = $track_exercise_info['orig_lp_item_view_id']; $lp_item_view_id = $track_exercise_info['orig_lp_item_view_id'];
// Teacher data // Teacher data
$teacher_info = api_get_user_info(api_get_user_id()); $teacher_info = api_get_user_info(api_get_user_id());
$user_info = api_get_user_info($student_id); $user_info = api_get_user_info($student_id);
$student_email = $user_info['mail']; $student_email = $user_info['mail'];
$from = $teacher_info['mail']; $from = $teacher_info['mail'];
$from_name = api_get_person_name($teacher_info['firstname'], $teacher_info['lastname'], null, PERSON_NAME_EMAIL_ADDRESS); $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/exercise_report.php?' . api_get_cidreq() . '&id_session='.$session_id.'&exerciseId='.$exercise_id; $url = api_get_path(WEB_CODE_PATH) . 'exercice/exercise_report.php?' . api_get_cidreq() . '&id_session='.$session_id.'&exerciseId='.$exercise_id;
$my_post_info = array(); $my_post_info = array();
$post_content_id = array(); $post_content_id = array();
$comments_exist = false; $comments_exist = false;
foreach ($_POST as $key_index => $key_value) { foreach ($_POST as $key_index => $key_value) {
$my_post_info = explode('_',$key_index); $my_post_info = explode('_',$key_index);
$post_content_id[]=$my_post_info[1]; $post_content_id[]=$my_post_info[1];
@ -132,14 +133,14 @@ if ($_REQUEST['comments'] == 'update' && ($is_allowedToEdit || $is_tutor) && $_G
} }
$loop_in_track=($comments_exist===true) ? (count($_POST)/2) : count($_POST); $loop_in_track=($comments_exist===true) ? (count($_POST)/2) : count($_POST);
$array_content_id_exe=array(); $array_content_id_exe=array();
if ($comments_exist===true) { if ($comments_exist===true) {
$array_content_id_exe = array_slice($post_content_id,$loop_in_track); $array_content_id_exe = array_slice($post_content_id,$loop_in_track);
} else { } else {
$array_content_id_exe = $post_content_id; $array_content_id_exe = $post_content_id;
} }
for ($i=0;$i<$loop_in_track;$i++) { for ($i=0;$i<$loop_in_track;$i++) {
$my_marks = Database::escape_string($_POST['marks_'.$array_content_id_exe[$i]]); $my_marks = Database::escape_string($_POST['marks_'.$array_content_id_exe[$i]]);
$contain_comments = Database::escape_string($_POST['comments_'.$array_content_id_exe[$i]]); $contain_comments = Database::escape_string($_POST['comments_'.$array_content_id_exe[$i]]);
@ -155,68 +156,68 @@ if ($_REQUEST['comments'] == 'update' && ($is_allowedToEdit || $is_tutor) && $_G
$query = "UPDATE $TBL_TRACK_ATTEMPT SET marks = '$my_marks',teacher_comment = '$my_comments' WHERE question_id = ".$my_questionid." AND exe_id=".$id; $query = "UPDATE $TBL_TRACK_ATTEMPT SET marks = '$my_marks',teacher_comment = '$my_comments' WHERE question_id = ".$my_questionid." AND exe_id=".$id;
Database::query($query); Database::query($query);
//Saving results in the track recording table //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) $recording_changes = 'INSERT INTO '.$TBL_TRACK_ATTEMPT_RECORDING.' (exe_id, question_id, marks, insert_date, author, teacher_comment)
VALUES ('."'$id','".$my_questionid."','$my_marks','".api_get_utc_datetime()."','".api_get_user_id()."'".',"'.$my_comments.'")'; VALUES ('."'$id','".$my_questionid."','$my_marks','".api_get_utc_datetime()."','".api_get_user_id()."'".',"'.$my_comments.'")';
Database::query($recording_changes); Database::query($recording_changes);
} }
$qry = 'SELECT DISTINCT question_id, marks FROM ' . $TBL_TRACK_ATTEMPT . ' WHERE exe_id = '.$id .' GROUP BY question_id'; $qry = 'SELECT DISTINCT question_id, marks FROM ' . $TBL_TRACK_ATTEMPT . ' WHERE exe_id = '.$id .' GROUP BY question_id';
$res = Database::query($qry); $res = Database::query($qry);
$tot = 0; $tot = 0;
while ($row = Database :: fetch_array($res, 'ASSOC')) { while ($row = Database :: fetch_array($res, 'ASSOC')) {
$tot += $row['marks']; $tot += $row['marks'];
} }
$totquery = "UPDATE $TBL_TRACK_EXERCICES SET exe_result = '".floatval($tot)."' WHERE exe_id = ".$id; $totquery = "UPDATE $TBL_TRACK_EXERCICES SET exe_result = '".floatval($tot)."' WHERE exe_id = ".$id;
Database::query($totquery); Database::query($totquery);
//@todo move this somewhere else //@todo move this somewhere else
$subject = get_lang('ExamSheetVCC'); $subject = get_lang('ExamSheetVCC');
$message = '<p>'.get_lang('DearStudentEmailIntroduction') . '</p><p>'.get_lang('AttemptVCC'); $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('CourseName'). '</h3><p>'.Security::remove_XSS($course_info['name']).'';
$message .= '<h3>'.get_lang('Exercise') . '</h3><p>'.Security::remove_XSS($test); $message .= '<h3>'.get_lang('Exercise') . '</h3><p>'.Security::remove_XSS($test);
//Only for exercises not in a LP //Only for exercises not in a LP
if ($lp_id == 0) { if ($lp_id == 0) {
$message .= '<p>'.get_lang('ClickLinkToViewComment') . ' <a href="#url#">#url#</a><br />'; $message .= '<p>'.get_lang('ClickLinkToViewComment') . ' <a href="#url#">#url#</a><br />';
} }
$message .= '<p>'.get_lang('Regards').'</p>'; $message .= '<p>'.get_lang('Regards').'</p>';
$message .= $from_name; $message .= $from_name;
$message = str_replace("#test#", Security::remove_XSS($test), $message); $message = str_replace("#test#", Security::remove_XSS($test), $message);
$message = str_replace("#url#", $url, $message); $message = str_replace("#url#", $url, $message);
@api_mail_html($student_email, $student_email, $subject, $message, $from_name, $from, array('charset'=>api_get_system_encoding())); @api_mail_html($student_email, $student_email, $subject, $message, $from_name, $from, array('charset'=>api_get_system_encoding()));
//Updating LP score here //Updating LP score here
if (in_array($origin, array ('tracking_course','user_course','correct_exercise_in_lp'))) { if (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; $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); Database::query($sql_update_score);
if ($origin == 'tracking_course') { if ($origin == 'tracking_course') {
//Redirect to the course detail in lp //Redirect to the course detail in lp
header('location: exercice.php?course=' . Security :: remove_XSS($_GET['course'])); header('location: exercice.php?course=' . Security :: remove_XSS($_GET['course']));
exit; exit;
} else { } else {
//Redirect to the reporting //Redirect to the reporting
header('location: ../mySpace/myStudents.php?origin=' . $origin . '&student=' . $student_id . '&details=true&course=' . $course_id.'&session_id='.$session_id); header('location: ../mySpace/myStudents.php?origin=' . $origin . '&student=' . $student_id . '&details=true&course=' . $course_id.'&session_id='.$session_id);
exit; exit;
} }
} }
} }
if ($is_allowedToEdit && $origin != 'learnpath') { if ($is_allowedToEdit && $origin != 'learnpath') {
// the form // the form
if (api_is_platform_admin() || api_is_course_admin() || api_is_course_tutor() || api_is_course_coach()) { if (api_is_platform_admin() || api_is_course_admin() || api_is_course_tutor() || api_is_course_coach()) {
$actions .= '<a href="admin.php?exerciseId='.intval($_GET['exerciseId']).'">' . Display :: return_icon('back.png', get_lang('GoBackToQuestionList'),'',ICON_SIZE_MEDIUM).'</a>'; $actions .= '<a href="admin.php?exerciseId='.intval($_GET['exerciseId']).'">' . Display :: return_icon('back.png', get_lang('GoBackToQuestionList'),'',ICON_SIZE_MEDIUM).'</a>';
$actions .='<a href="live_stats.php?' . api_get_cidreq() . '&exerciseId='.$exercise_id.'">'.Display :: return_icon('activity_monitor.png', get_lang('LiveResults'),'',ICON_SIZE_MEDIUM).'</a>'; $actions .='<a href="live_stats.php?' . api_get_cidreq() . '&exerciseId='.$exercise_id.'">'.Display :: return_icon('activity_monitor.png', get_lang('LiveResults'),'',ICON_SIZE_MEDIUM).'</a>';
$actions .='<a href="stats.php?' . api_get_cidreq() . '&exerciseId='.$exercise_id.'">'.Display :: return_icon('statistics.png', get_lang('ReportByQuestion'),'', ICON_SIZE_MEDIUM).'</a>'; $actions .='<a href="stats.php?' . api_get_cidreq() . '&exerciseId='.$exercise_id.'">'.Display :: return_icon('statistics.png', get_lang('ReportByQuestion'),'', ICON_SIZE_MEDIUM).'</a>';
$actions .= '<a id="export_opener" href="'.api_get_self().'?export_report=1&hotpotato_name='.Security::remove_XSS($_GET['path']).'&exerciseId='.intval($_GET['exerciseId']).'" >'. $actions .= '<a id="export_opener" href="'.api_get_self().'?export_report=1&hotpotato_name='.Security::remove_XSS($_GET['path']).'&exerciseId='.intval($_GET['exerciseId']).'" >'.
Display::return_icon('save.png', get_lang('Export'),'',ICON_SIZE_MEDIUM).'</a>'; Display::return_icon('save.png', get_lang('Export'),'',ICON_SIZE_MEDIUM).'</a>';
} }
} else { } else {
$actions .= '<a href="exercice.php">' . Display :: return_icon('back.png', get_lang('GoBackToQuestionList'),'',ICON_SIZE_MEDIUM).'</a>'; $actions .= '<a href="exercice.php">' . Display :: return_icon('back.png', get_lang('GoBackToQuestionList'),'',ICON_SIZE_MEDIUM).'</a>';
@ -225,29 +226,29 @@ if ($is_allowedToEdit && $origin != 'learnpath') {
//Deleting an attempt //Deleting an attempt
if ( ($is_allowedToEdit || $is_tutor || api_is_coach()) && $_GET['delete'] == 'delete' && !empty ($_GET['did']) && $locked == false) { if ( ($is_allowedToEdit || $is_tutor || api_is_coach()) && $_GET['delete'] == 'delete' && !empty ($_GET['did']) && $locked == false) {
$exe_id = intval($_GET['did']); $exe_id = intval($_GET['did']);
if (!empty($exe_id)) { if (!empty($exe_id)) {
$sql = 'DELETE FROM '.$TBL_TRACK_EXERCICES.' WHERE exe_id = '.$exe_id; $sql = 'DELETE FROM '.$TBL_TRACK_EXERCICES.' WHERE exe_id = '.$exe_id;
Database::query($sql); Database::query($sql);
$sql = 'DELETE FROM '.$TBL_TRACK_ATTEMPT.' WHERE exe_id = '.$exe_id; $sql = 'DELETE FROM '.$TBL_TRACK_ATTEMPT.' WHERE exe_id = '.$exe_id;
Database::query($sql); Database::query($sql);
header('Location: exercise_report.php?cidReq=' . Security::remove_XSS($_GET['cidReq']) . '&exerciseId='.$exercise_id); header('Location: exercise_report.php?cidReq=' . Security::remove_XSS($_GET['cidReq']) . '&exerciseId='.$exercise_id);
exit; exit;
} }
} }
if ($is_allowedToEdit || $is_tutor) { if ($is_allowedToEdit || $is_tutor) {
$nameTools = get_lang('StudentScore'); $nameTools = get_lang('StudentScore');
$interbreadcrumb[] = array("url" => "exercice.php?gradebook=$gradebook","name" => get_lang('Exercices')); $interbreadcrumb[] = array("url" => "exercice.php?gradebook=$gradebook","name" => get_lang('Exercices'));
$objExerciseTmp = new Exercise(); $objExerciseTmp = new Exercise();
if ($objExerciseTmp->read($exercise_id)) { if ($objExerciseTmp->read($exercise_id)) {
$interbreadcrumb[] = array("url" => "admin.php?exerciseId=".$exercise_id, "name" => $objExerciseTmp->name); $interbreadcrumb[] = array("url" => "admin.php?exerciseId=".$exercise_id, "name" => $objExerciseTmp->name);
} }
} else { } else {
$interbreadcrumb[] = array("url" => "exercice.php?gradebook=$gradebook","name" => get_lang('Exercices')); $interbreadcrumb[] = array("url" => "exercice.php?gradebook=$gradebook","name" => get_lang('Exercices'));
$objExerciseTmp = new Exercise(); $objExerciseTmp = new Exercise();
if ($objExerciseTmp->read($exercise_id)) { if ($objExerciseTmp->read($exercise_id)) {
$nameTools = get_lang('Results').': '.$objExerciseTmp->name; $nameTools = get_lang('Results').': '.$objExerciseTmp->name;
} }
} }
@ -257,34 +258,34 @@ $actions = Display::div($actions, array('class'=> 'actions'));
$extra = '<script type="text/javascript"> $extra = '<script type="text/javascript">
$(document).ready(function() { $(document).ready(function() {
$( "#dialog:ui-dialog" ).dialog( "destroy" ); $( "#dialog:ui-dialog" ).dialog( "destroy" );
$( "#dialog-confirm" ).dialog({ $( "#dialog-confirm" ).dialog({
autoOpen: false, autoOpen: false,
show: "blind", show: "blind",
resizable: false, resizable: false,
height:300, height:300,
modal: true modal: true
}); });
$("#export_opener").click(function() { $("#export_opener").click(function() {
var targetUrl = $(this).attr("href"); var targetUrl = $(this).attr("href");
$( "#dialog-confirm" ).dialog({ $( "#dialog-confirm" ).dialog({
width:400, width:400,
height:300, height:300,
buttons: { buttons: {
"'.addslashes(get_lang('Download')).'": function() { "'.addslashes(get_lang('Download')).'": function() {
var export_format = $("input[name=export_format]:checked").val(); var export_format = $("input[name=export_format]:checked").val();
var extra_data = $("input[name=load_extra_data]:checked").val(); var extra_data = $("input[name=load_extra_data]:checked").val();
location.href = targetUrl+"&export_format="+export_format+"&extra_data="+extra_data; location.href = targetUrl+"&export_format="+export_format+"&extra_data="+extra_data;
$( this ).dialog( "close" ); $( this ).dialog( "close" );
}, },
} }
}); });
$( "#dialog-confirm" ).dialog("open"); $( "#dialog-confirm" ).dialog("open");
return false; return false;
}); });
}); });
</script>'; </script>';
@ -297,7 +298,7 @@ $form->setDefaults(array('export_format' => 'csv'));
$extra .= $form->return_form(); $extra .= $form->return_form();
$extra .= '</div>'; $extra .= '</div>';
if ($is_allowedToEdit) if ($is_allowedToEdit)
echo $extra; echo $extra;
echo $actions; echo $actions;
@ -314,54 +315,54 @@ $url = api_get_path(WEB_AJAX_PATH).'model.ajax.php?a=get_exercise_results&exerci
//$activeurl = '?sidx=session_active'; //$activeurl = '?sidx=session_active';
$action_links = ''; $action_links = '';
//Generating group list //Generating group list
$group_list = GroupManager::get_group_list(); $group_list = GroupManager::get_group_list();
$group_parameters = array('group_all:'.get_lang('All'),'group_none:'.get_lang('None')); $group_parameters = array('group_all:'.get_lang('All'),'group_none:'.get_lang('None'));
foreach ($group_list as $group) { foreach ($group_list as $group) {
$group_parameters[] = $group['id'].':'.$group['name']; $group_parameters[] = $group['id'].':'.$group['name'];
} }
if (!empty($group_parameters)) { if (!empty($group_parameters)) {
$group_parameters = implode(';', $group_parameters); $group_parameters = implode(';', $group_parameters);
} }
if ($is_allowedToEdit || $is_tutor) { if ($is_allowedToEdit || $is_tutor) {
//The order is important you need to check the the $column variable in the model.ajax.php file //The order is important you need to check the the $column variable in the model.ajax.php file
$columns = array(get_lang('FirstName'), get_lang('LastName'), get_lang('LoginName'), $columns = array(get_lang('FirstName'), get_lang('LastName'), get_lang('LoginName'),
get_lang('Group'), get_lang('Duration'), get_lang('StartDate'), get_lang('EndDate'), get_lang('Score'), get_lang('Status'), get_lang('Actions')); get_lang('Group'), get_lang('Duration'), get_lang('StartDate'), get_lang('EndDate'), get_lang('Score'), get_lang('Status'), get_lang('Actions'));
//Column config //Column config
$column_model = array( $column_model = array(
array('name'=>'firstname', 'index'=>'firstname', 'width'=>'50', 'align'=>'left', 'search' => 'true'), array('name'=>'firstname', 'index'=>'firstname', 'width'=>'50', 'align'=>'left', 'search' => 'true'),
array('name'=>'lastname', 'index'=>'lastname', 'width'=>'50', 'align'=>'left', 'formatter'=>'action_formatter', 'search' => 'true'), array('name'=>'lastname', 'index'=>'lastname', 'width'=>'50', 'align'=>'left', 'formatter'=>'action_formatter', 'search' => 'true'),
array('name'=>'login', 'hidden'=>'true', 'index'=>'username', 'width'=>'40', 'align'=>'left', 'search' => 'true'), array('name'=>'login', 'hidden'=>'true', 'index'=>'username', 'width'=>'40', 'align'=>'left', 'search' => 'true'),
array('name'=>'group_name', 'index'=>'group_id', 'width'=>'40', 'align'=>'left', 'search' => 'true', 'stype'=> 'select', array('name'=>'group_name', 'index'=>'group_id', 'width'=>'40', 'align'=>'left', 'search' => 'true', 'stype'=> 'select',
//for the bottom bar //for the bottom bar
'searchoptions' => array( 'searchoptions' => array(
'defaultValue' => 'group_all', 'defaultValue' => 'group_all',
'value' => $group_parameters), 'value' => $group_parameters),
//for the top bar //for the top bar
'editoptions' => array('value' => $group_parameters)), 'editoptions' => array('value' => $group_parameters)),
array('name'=>'duration', 'index'=>'exe_duration', 'width'=>'30', 'align'=>'left', 'search' => 'true'), array('name'=>'duration', 'index'=>'exe_duration', 'width'=>'30', 'align'=>'left', 'search' => 'true'),
array('name'=>'start_date', 'index'=>'start_date', 'width'=>'60', 'align'=>'left', 'search' => 'true'), array('name'=>'start_date', 'index'=>'start_date', 'width'=>'60', 'align'=>'left', 'search' => 'true'),
array('name'=>'exe_date', 'index'=>'exe_date', 'width'=>'60', 'align'=>'left', 'search' => 'true'), array('name'=>'exe_date', 'index'=>'exe_date', 'width'=>'60', 'align'=>'left', 'search' => 'true'),
array('name'=>'score', 'index'=>'exe_result', 'width'=>'50', 'align'=>'left', 'search' => 'true'), array('name'=>'score', 'index'=>'exe_result', 'width'=>'50', 'align'=>'left', 'search' => 'true'),
array('name'=>'status', 'index'=>'revised', 'width'=>'40', 'align'=>'left', 'search' => 'true', 'stype'=>'select', array('name'=>'status', 'index'=>'revised', 'width'=>'40', 'align'=>'left', 'search' => 'true', 'stype'=>'select',
//for the bottom bar //for the bottom bar
'searchoptions' => array( 'searchoptions' => array(
'defaultValue' => '', 'defaultValue' => '',
'value' => ':'.get_lang('All').';1:'.get_lang('Validated').';0:'.get_lang('NotValidated')), 'value' => ':'.get_lang('All').';1:'.get_lang('Validated').';0:'.get_lang('NotValidated')),
//for the top bar //for the top bar
'editoptions' => array('value' => ':'.get_lang('All').';1:'.get_lang('Validated').';0:'.get_lang('NotValidated'))), 'editoptions' => array('value' => ':'.get_lang('All').';1:'.get_lang('Validated').';0:'.get_lang('NotValidated'))),
//issue fixed in jqgrid //issue fixed in jqgrid
// array('name'=>'actions', 'index'=>'actions', 'width'=>'100', 'align'=>'left','formatter'=>'action_formatter','sortable'=>'false', 'search' => 'false') // array('name'=>'actions', 'index'=>'actions', 'width'=>'100', 'align'=>'left','formatter'=>'action_formatter','sortable'=>'false', 'search' => 'false')
array('name'=>'actions', 'index'=>'actions', 'width'=>'60', 'align'=>'left', 'search' => 'false') array('name'=>'actions', 'index'=>'actions', 'width'=>'60', 'align'=>'left', 'search' => 'false')
); );
$action_links = ' $action_links = '
// add username as title in lastname filed - ref 4226 // add username as title in lastname filed - ref 4226
function action_formatter(cellvalue, options, rowObject) { function action_formatter(cellvalue, options, rowObject) {
@ -373,26 +374,26 @@ if ($is_allowedToEdit || $is_tutor) {
return "<span title=\""+tabLoginx[0]+rowObject[2]+tabLoginx[1]+"\">"+cellvalue+"</span>"; return "<span title=\""+tabLoginx[0]+rowObject[2]+tabLoginx[1]+"\">"+cellvalue+"</span>";
}'; }';
} else { } else {
api_not_allowed(); //view not available for students api_not_allowed(); //view not available for students
// //
//The order is important you need to check the the $column variable in the model.ajax.php file //The order is important you need to check the the $column variable in the model.ajax.php file
$columns = array(get_lang('Duration'), get_lang('StartDate'), get_lang('EndDate'), get_lang('Score'), get_lang('Status'), get_lang('Actions')); $columns = array(get_lang('Duration'), get_lang('StartDate'), get_lang('EndDate'), get_lang('Score'), get_lang('Status'), get_lang('Actions'));
//Column config //Column config
$column_model = array( $column_model = array(
array('name'=>'duration', 'index'=>'exe_duration', 'width'=>'20', 'align'=>'left', 'search' => 'false'), array('name'=>'duration', 'index'=>'exe_duration', 'width'=>'20', 'align'=>'left', 'search' => 'false'),
array('name'=>'start_date', 'index'=>'start_date', 'width'=>'50', 'align'=>'left', 'search' => 'false'), array('name'=>'start_date', 'index'=>'start_date', 'width'=>'50', 'align'=>'left', 'search' => 'false'),
array('name'=>'exe_date', 'index'=>'exe_date', 'width'=>'50', 'align'=>'left', 'search' => 'false'), array('name'=>'exe_date', 'index'=>'exe_date', 'width'=>'50', 'align'=>'left', 'search' => 'false'),
array('name'=>'score', 'index'=>'exe_result', 'width'=>'40', 'align'=>'left', 'search' => 'false'), array('name'=>'score', 'index'=>'exe_result', 'width'=>'40', 'align'=>'left', 'search' => 'false'),
array('name'=>'status', 'index'=>'revised', 'width'=>'40', 'align'=>'left', 'search' => 'false'), array('name'=>'status', 'index'=>'revised', 'width'=>'40', 'align'=>'left', 'search' => 'false'),
array('name'=>'actions', 'index'=>'actions', 'width'=>'40', 'align'=>'left', 'search' => 'false') array('name'=>'actions', 'index'=>'actions', 'width'=>'40', 'align'=>'left', 'search' => 'false')
); );
} }
//Autowidth //Autowidth
$extra_params['autowidth'] = 'true'; $extra_params['autowidth'] = 'true';
//height auto //height auto
$extra_params['height'] = 'auto'; $extra_params['height'] = 'auto';
//$extra_params['excel'] = 'excel'; //$extra_params['excel'] = 'excel';
@ -400,12 +401,12 @@ $extra_params['rowList'] = array(10, 20 ,30);
?> ?>
<script> <script>
function setSearchSelect(columnName) { function setSearchSelect(columnName) {
$("#results").jqGrid('setColProp', columnName, $("#results").jqGrid('setColProp', columnName,
{ {
searchoptions:{ searchoptions:{
dataInit:function(el){ dataInit:function(el){
$("option[value='1']",el).attr("selected", "selected"); $("option[value='1']",el).attr("selected", "selected");
setTimeout(function(){ setTimeout(function(){
$(el).trigger('change'); $(el).trigger('change');
@ -419,11 +420,11 @@ function exportExcel() {
var mya=new Array(); var mya=new Array();
mya=$("#results").getDataIDs(); // Get All IDs mya=$("#results").getDataIDs(); // Get All IDs
var data=$("#results").getRowData(mya[0]); // Get First row to get the labels var data=$("#results").getRowData(mya[0]); // Get First row to get the labels
var colNames=new Array(); var colNames=new Array();
var ii=0; var ii=0;
for (var i in data){colNames[ii++]=i;} // capture col names for (var i in data){colNames[ii++]=i;} // capture col names
var html=""; var html="";
for(i=0;i<mya.length;i++) { for(i=0;i<mya.length;i++) {
data=$("#results").getRowData(mya[i]); // get each row data=$("#results").getRowData(mya[i]); // get each row
for(j=0;j<colNames.length;j++) { for(j=0;j<colNames.length;j++) {
@ -432,39 +433,39 @@ function exportExcel() {
html=html+"\n"; // output each row with end of line html=html+"\n"; // output each row with end of line
} }
html = html+"\n"; // end of line at the end html = html+"\n"; // end of line at the end
var form = $("#export_report_form"); var form = $("#export_report_form");
$("#csvBuffer").attr('value', html); $("#csvBuffer").attr('value', html);
form.target='_blank'; form.target='_blank';
form.submit(); form.submit();
} }
$(function() { $(function() {
<?php <?php
echo Display::grid_js('results', $url,$columns,$column_model, $extra_params, array(), $action_links, true); echo Display::grid_js('results', $url,$columns,$column_model, $extra_params, array(), $action_links, true);
if ($is_allowedToEdit || $is_tutor) { ?> if ($is_allowedToEdit || $is_tutor) { ?>
//setSearchSelect("status"); //setSearchSelect("status");
// //
//view:true, del:false, add:false, edit:false, excel:true} //view:true, del:false, add:false, edit:false, excel:true}
$("#results").jqGrid('navGrid','#results_pager', {view:true, edit:false, add:false, del:false, excel:false}, $("#results").jqGrid('navGrid','#results_pager', {view:true, edit:false, add:false, del:false, excel:false},
{height:280, reloadAfterSubmit:false}, // view options {height:280, reloadAfterSubmit:false}, // view options
{height:280, reloadAfterSubmit:false}, // edit options {height:280, reloadAfterSubmit:false}, // edit options
{height:280, reloadAfterSubmit:false}, // add options {height:280, reloadAfterSubmit:false}, // add options
{reloadAfterSubmit: false}, // del options {reloadAfterSubmit: false}, // del options
{width:500} // search options {width:500} // search options
); );
/* /*
// add custom button to export the data to excel // add custom button to export the data to excel
jQuery("#results").jqGrid('navButtonAdd','#results_pager',{ jQuery("#results").jqGrid('navButtonAdd','#results_pager',{
caption:"", caption:"",
onClickButton : function () { onClickButton : function () {
//exportExcel(); //exportExcel();
} }
});*/ });*/
/* /*
jQuery('#sessions').jqGrid('navButtonAdd','#sessions_pager',{id:'pager_csv',caption:'',title:'Export To CSV',onClickButton : function(e) jQuery('#sessions').jqGrid('navButtonAdd','#sessions_pager',{id:'pager_csv',caption:'',title:'Export To CSV',onClickButton : function(e)
{ {
@ -480,19 +481,19 @@ $(function() {
var options = { var options = {
'stringResult': true, 'stringResult': true,
'autosearch' : true, 'autosearch' : true,
'searchOnEnter':false 'searchOnEnter':false
} }
jQuery("#results").jqGrid('filterToolbar',options); jQuery("#results").jqGrid('filterToolbar',options);
var sgrid = $("#results")[0]; var sgrid = $("#results")[0];
sgrid.triggerToolbar(); sgrid.triggerToolbar();
<?php } ?> <?php } ?>
}); });
</script> </script>
<form id="export_report_form" method="post" action="exercise_report.php"> <form id="export_report_form" method="post" action="exercise_report.php">
<input type="hidden" name="csvBuffer" id="csvBuffer" value="" /> <input type="hidden" name="csvBuffer" id="csvBuffer" value="" />
<input type="hidden" name="export_report" id="export_report" value="1" /> <input type="hidden" name="export_report" id="export_report" value="1" />
<input type="hidden" name="exerciseId" id="exerciseId" value="<?php echo $exercise_id ?>" /> <input type="hidden" name="exerciseId" id="exerciseId" value="<?php echo $exercise_id ?>" />
</form> </form>
<?php <?php

@ -1,7 +1,7 @@
<?php <?php
/* For licensing terms, see /license.txt */ /* For licensing terms, see /license.txt */
/** /**
* ExerciseResult class: This class allows to instantiate an object * ExerciseResult class: This class allows to instantiate an object
* of type ExerciseResult * of type ExerciseResult
* which allows you to export exercises results in multiple presentation forms * which allows you to export exercises results in multiple presentation forms
* @package chamilo.exercise * @package chamilo.exercise
@ -77,7 +77,7 @@ class ExerciseResult
} }
return true; return true;
} }
/** /**
* Gets the results of all students (or just one student if access is limited) * Gets the results of all students (or just one student if access is limited)
* @param string The document path (for HotPotatoes retrieval) * @param string The document path (for HotPotatoes retrieval)
@ -85,87 +85,101 @@ class ExerciseResult
*/ */
function _getExercisesReporting($document_path, $user_id = null, $filter=0, $exercise_id = 0, $hotpotato_name = null) { function _getExercisesReporting($document_path, $user_id = null, $filter=0, $exercise_id = 0, $hotpotato_name = null) {
$return = array(); $return = array();
$TBL_EXERCISES = Database::get_course_table(TABLE_QUIZ_TEST); $TBL_EXERCISES = Database::get_course_table(TABLE_QUIZ_TEST);
$TBL_EXERCISE_QUESTION = Database::get_course_table(TABLE_QUIZ_TEST_QUESTION);
$TBL_QUESTIONS = Database::get_course_table(TABLE_QUIZ_QUESTION);
$TBL_USER = Database::get_main_table(TABLE_MAIN_USER); $TBL_USER = Database::get_main_table(TABLE_MAIN_USER);
$TBL_DOCUMENT = Database::get_course_table(TABLE_DOCUMENT);
$TBL_ITEM_PROPERTY = Database::get_course_table(TABLE_ITEM_PROPERTY);
$TBL_TRACK_EXERCISES = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES); $TBL_TRACK_EXERCISES = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES);
$TBL_TRACK_HOTPOTATOES = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_HOTPOTATOES); $TBL_TRACK_HOTPOTATOES = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_HOTPOTATOES);
$TBL_TRACK_ATTEMPT = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_ATTEMPT);
$TBL_TRACK_ATTEMPT_RECORDING= Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_ATTEMPT_RECORDING); $TBL_TRACK_ATTEMPT_RECORDING= Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_ATTEMPT_RECORDING);
$TBL_COURSE_REL_USER = Database :: get_main_table(TABLE_MAIN_COURSE_USER);
$cid = api_get_course_id(); $cid = api_get_course_id();
$course_id = api_get_course_int_id(); $course_id = api_get_course_int_id();
$user_id = intval($user_id); $user_id = intval($user_id);
$session_id_and = ' AND te.session_id = ' . api_get_session_id() . ' '; $session_id_and = ' AND te.session_id = ' . api_get_session_id() . ' ';
$exercise_id = intval($exercise_id); $exercise_id = intval($exercise_id);
$hotpotato_name = Database::escape_string($hotpotato_name); $hotpotato_name = Database::escape_string($hotpotato_name);
if (!empty($exercise_id)) { if (!empty($exercise_id)) {
$session_id_and .= " AND exe_exo_id = $exercise_id "; $session_id_and .= " AND exe_exo_id = $exercise_id ";
} }
if (empty($user_id)) { if (empty($user_id)) {
$sql="SELECT ".(api_is_western_name_order() ? "firstname as userpart1, lastname userpart2" : "lastname as userpart1, firstname as userpart2").", ce.title as extitle, te.exe_result as exresult , te.exe_weighting as exweight, $sql = "SELECT ".(api_is_western_name_order() ? "firstname as userpart1, lastname userpart2" : "lastname as userpart1, firstname as userpart2").",
te.exe_date as exdate, te.exe_id as exid, email as exemail, te.start_date as exstart, steps_counter as exstep, exe_user_id as excruid, te.exe_duration as exduration ce.title as extitle,
FROM $TBL_EXERCISES AS ce INNER JOIN $TBL_TRACK_EXERCISES AS te ON (te.exe_exo_id = ce.id) INNER JOIN te.exe_result as exresult ,
te.exe_weighting as exweight,
te.exe_date as exdate,
te.exe_id as exid,
email as exemail,
te.start_date as exstart,
steps_counter as exstep,
exe_user_id as excruid,
te.exe_duration as duration
FROM $TBL_EXERCISES AS ce INNER JOIN $TBL_TRACK_EXERCISES AS te ON (te.exe_exo_id = ce.id) INNER JOIN
$TBL_USER AS user ON (user.user_id = exe_user_id) $TBL_USER AS user ON (user.user_id = exe_user_id)
WHERE ce.c_id = $course_id AND WHERE ce.c_id = $course_id AND
te.status != 'incomplete' AND te.status != 'incomplete' AND
te.exe_cours_id='" . Database :: escape_string($cid) . "' $user_id_and $session_id_and AND te.exe_cours_id='" . Database :: escape_string($cid) . "' $user_id_and $session_id_and AND
ce.active <>-1 AND ce.active <>-1 AND
orig_lp_id = 0 AND orig_lp_id = 0 AND
orig_lp_item_id = 0"; orig_lp_item_id = 0";
$hpsql="SELECT ".(api_is_western_name_order() ? "firstname as userpart1, lastname userpart2" : "lastname as userpart1, firstname as userpart2").",
$hpsql="SELECT ".(api_is_western_name_order() ? "firstname as userpart1, lastname userpart2" : "lastname as userpart1, firstname as userpart2").", email, tth.exe_name, tth.exe_result , tth.exe_weighting, tth.exe_date email,
tth.exe_name,
tth.exe_result,
tth.exe_weighting,
tth.exe_date
FROM $TBL_TRACK_HOTPOTATOES tth, $TBL_USER tu FROM $TBL_TRACK_HOTPOTATOES tth, $TBL_USER tu
WHERE tu.user_id=tth.exe_user_id AND WHERE tu.user_id=tth.exe_user_id AND
tth.exe_cours_id = '" . Database :: escape_string($cid) . "' AND tth.exe_cours_id = '" . Database :: escape_string($cid) . "' AND
tth.exe_name = '$hotpotato_name' tth.exe_name = '$hotpotato_name'
ORDER BY tth.exe_cours_id ASC, tth.exe_date DESC"; ORDER BY tth.exe_cours_id ASC, tth.exe_date DESC";
} else { } else {
$user_id_and = ' AND te.exe_user_id = ' . api_get_user_id() . ' '; $user_id_and = ' AND te.exe_user_id = ' . api_get_user_id() . ' ';
// get only this user's results // get only this user's results
$sql="SELECT ".(api_is_western_name_order() ? "firstname as userpart1, lastname userpart2" : "lastname as userpart1, firstname as userpart2").", ce.title as extitle, te.exe_result as exresult, " . $sql="SELECT ".(api_is_western_name_order() ? "firstname as userpart1, lastname userpart2" : "lastname as userpart1, firstname as userpart2").",
"te.exe_weighting as exweight, te.exe_date as exdate, te.exe_id as exid, email as exemail, " . ce.title as extitle,
"te.start_date as exstart, steps_counter as exstep, exe_user_id as excruid, te.exe_duration as exduration, ce.results_disabled as exdisabled te.exe_result as exresult,
te.exe_weighting as exweight,
te.exe_date as exdate,
te.exe_id as exid,
email as exemail,
te.start_date as exstart,
steps_counter as exstep,
exe_user_id as excruid,
te.exe_duration as duration,
ce.results_disabled as exdisabled
FROM $TBL_EXERCISES AS ce INNER JOIN $TBL_TRACK_EXERCISES AS te ON (te.exe_exo_id = ce.id) INNER JOIN $TBL_USER AS user ON (user.user_id = exe_user_id) FROM $TBL_EXERCISES AS ce INNER JOIN $TBL_TRACK_EXERCISES AS te ON (te.exe_exo_id = ce.id) INNER JOIN $TBL_USER AS user ON (user.user_id = exe_user_id)
WHERE ce.c_id = $course_id AND WHERE ce.c_id = $course_id AND
te.status != 'incomplete' AND te.status != 'incomplete' AND
te.exe_cours_id='" . Database :: escape_string($cid) . "' $user_id_and $session_id_and AND te.exe_cours_id='" . Database :: escape_string($cid) . "' $user_id_and $session_id_and AND
ce.active <>-1 AND ce.active <>-1 AND
orig_lp_id = 0 AND orig_lp_id = 0 AND
orig_lp_item_id = 0 orig_lp_item_id = 0
ORDER BY userpart2, te.exe_cours_id ASC, ce.title ASC, te.exe_date DESC"; ORDER BY userpart2, te.exe_cours_id ASC, ce.title ASC, te.exe_date DESC";
$hpsql = "SELECT '', exe_name, exe_result , exe_weighting, exe_date $hpsql = "SELECT '', exe_name, exe_result , exe_weighting, exe_date
FROM $TBL_TRACK_HOTPOTATOES FROM $TBL_TRACK_HOTPOTATOES
WHERE exe_user_id = '" . $user_id . "' AND WHERE exe_user_id = '" . $user_id . "' AND
exe_cours_id = '" . Database :: escape_string($cid) . "' AND exe_cours_id = '" . Database :: escape_string($cid) . "' AND
tth.exe_name = '$hotpotato_name' tth.exe_name = '$hotpotato_name'
ORDER BY exe_cours_id ASC, exe_date DESC"; ORDER BY exe_cours_id ASC, exe_date DESC";
} }
$results = array(); $results = array();
$resx = Database::query($sql); $resx = Database::query($sql);
while ($rowx = Database::fetch_array($resx,'ASSOC')) { while ($rowx = Database::fetch_array($resx,'ASSOC')) {
$results[] = $rowx; $results[] = $rowx;
} }
$hpresults = array(); $hpresults = array();
$resx = Database::query($hpsql); $resx = Database::query($hpsql);
while ($rowx = Database::fetch_array($resx,'ASSOC')) { while ($rowx = Database::fetch_array($resx,'ASSOC')) {
$hpresults[] = $rowx; $hpresults[] = $rowx;
} }
if ($filter) { if ($filter) {
switch ($filter) { switch ($filter) {
case 1 : case 1 :
@ -183,53 +197,58 @@ class ExerciseResult
if (is_array($results) && empty($hotpotato_name)) { if (is_array($results) && empty($hotpotato_name)) {
for ($i = 0; $i < sizeof($results); $i++) { for ($i = 0; $i < sizeof($results); $i++) {
$revised = false; $revised = false;
//revised or not //revised or not
$sql_exe = "SELECT exe_id FROM $TBL_TRACK_ATTEMPT_RECORDING $sql_exe = "SELECT exe_id FROM $TBL_TRACK_ATTEMPT_RECORDING
WHERE author != '' AND exe_id = ".Database :: escape_string($results[$i]['exid'])." LIMIT 1"; WHERE author != '' AND exe_id = ".Database :: escape_string($results[$i]['exid'])." LIMIT 1";
$query = Database::query($sql_exe); $query = Database::query($sql_exe);
if (Database :: num_rows($query) > 0) if (Database :: num_rows($query) > 0)
$revised = true; $revised = true;
if ($filter_by_not_revised && $revised) continue; if ($filter_by_not_revised && $revised) continue;
if ($filter_by_revised && !$revised) continue; if ($filter_by_revised && !$revised) continue;
$return[$i] = array(); $return[$i] = array();
if (empty($user_id)) { if (empty($user_id)) {
$return[$i]['first_name'] = $results[$i]['userpart1']; $return[$i]['first_name'] = $results[$i]['userpart1'];
$return[$i]['last_name'] = $results[$i]['userpart2']; $return[$i]['last_name'] = $results[$i]['userpart2'];
$return[$i]['user_id'] = $results[$i]['excruid']; $return[$i]['user_id'] = $results[$i]['excruid'];
$return[$i]['email'] = $results[$i]['exemail']; $return[$i]['email'] = $results[$i]['exemail'];
} }
$return[$i]['title'] = $results[$i]['extitle']; $return[$i]['title'] = $results[$i]['extitle'];
$return[$i]['time'] = api_convert_and_format_date($results[$i]['exdate']); $return[$i]['start_date'] = api_get_local_time($results[$i]['exstart']);
$return[$i]['end_date'] = api_get_local_time($results[$i]['exdate']);
$return[$i]['duration'] = $results[$i]['duration'];
$return[$i]['result'] = $results[$i]['exresult']; $return[$i]['result'] = $results[$i]['exresult'];
$return[$i]['max'] = $results[$i]['exweight']; $return[$i]['max'] = $results[$i]['exweight'];
$return[$i]['status'] = $revised ? get_lang('Validated') : get_lang('NotValidated'); $return[$i]['status'] = $revised ? get_lang('Validated') : get_lang('NotValidated');
} }
} }
// Print the Result of Hotpotatoes Tests // Print the Result of Hotpotatoes Tests
if (is_array($hpresults)) { if (is_array($hpresults)) {
for($i = 0; $i < sizeof($hpresults); $i++) { for($i = 0; $i < sizeof($hpresults); $i++) {
$return[$i] = array(); $return[$i] = array();
$title = GetQuizName($hpresults[$i]['exe_name'], $document_path); $title = GetQuizName($hpresults[$i]['exe_name'], $document_path);
if ($title =='') { if ($title =='') {
$title = basename($hpresults[$i]['exe_name']); $title = basename($hpresults[$i]['exe_name']);
} }
if(empty($user_id)) { if(empty($user_id)) {
$return[$i]['email'] = $hpresults[$i]['email']; $return[$i]['email'] = $hpresults[$i]['email'];
$return[$i]['first_name'] = $hpresults[$i]['userpart1']; $return[$i]['first_name'] = $hpresults[$i]['userpart1'];
$return[$i]['last_name'] = $hpresults[$i]['userpart2']; $return[$i]['last_name'] = $hpresults[$i]['userpart2'];
} }
$return[$i]['title'] = $title; $return[$i]['title'] = $title;
$return[$i]['time'] = api_convert_and_format_date($hpresults[$i]['exdate']); $return[$i]['start_date'] = api_get_local_time($results[$i]['exstart']);
$return[$i]['end_date'] = api_get_local_time($results[$i]['exdate']);
$return[$i]['duration'] = $results[$i]['duration'];
$return[$i]['result'] = $hpresults[$i]['exe_result']; $return[$i]['result'] = $hpresults[$i]['exe_result'];
$return[$i]['max'] = $hpresults[$i]['exe_weighting']; $return[$i]['max'] = $hpresults[$i]['exe_weighting'];
} }
} }
$this->results = $return; $this->results = $return;
return true; return true;
} }
@ -248,59 +267,56 @@ class ExerciseResult
$filename = 'exercise_results_user_'.$user_id.'_'.date('YmdGis').'.csv'; $filename = 'exercise_results_user_'.$user_id.'_'.date('YmdGis').'.csv';
} }
$data = ''; $data = '';
if (api_is_western_name_order()) { if (api_is_western_name_order()) {
if(!empty($this->results[0]['first_name'])) { if(!empty($this->results[0]['first_name'])) {
$data .= get_lang('FirstName').';'; $data .= get_lang('FirstName').';';
} }
if(!empty($this->results[0]['last_name'])) { if(!empty($this->results[0]['last_name'])) {
$data .= get_lang('LastName').';'; $data .= get_lang('LastName').';';
} }
} else { } else {
if(!empty($this->results[0]['last_name'])) { if(!empty($this->results[0]['last_name'])) {
$data .= get_lang('LastName').';'; $data .= get_lang('LastName').';';
} }
if(!empty($this->results[0]['first_name'])) { if(!empty($this->results[0]['first_name'])) {
$data .= get_lang('FirstName').';'; $data .= get_lang('FirstName').';';
} }
} }
$data .= get_lang('Email').';'; $data .= get_lang('Email').';';
if ($export_user_fields) { if ($export_user_fields) {
//show user fields section with a big th colspan that spans over all fields //show user fields section with a big th colspan that spans over all fields
$extra_user_fields = UserManager::get_extra_fields(0,1000,5,'ASC',false, 1); $extra_user_fields = UserManager::get_extra_fields(0,1000,5,'ASC',false, 1);
$num = count($extra_user_fields); $num = count($extra_user_fields);
foreach($extra_user_fields as $field) { foreach($extra_user_fields as $field) {
$data .= '"'.str_replace("\r\n",' ',api_html_entity_decode(strip_tags($field[3]), ENT_QUOTES, $charset)).'";'; $data .= '"'.str_replace("\r\n",' ',api_html_entity_decode(strip_tags($field[3]), ENT_QUOTES, $charset)).'";';
} }
} }
$data .= get_lang('Title').';'; $data .= get_lang('Title').';';
$data .= get_lang('StartDate').';'; $data .= get_lang('StartDate').';';
$data .= get_lang('EndDate').';';
$data .= get_lang('Duration'). ' ('.get_lang('MinMinutes').') ;';
$data .= get_lang('Score').';'; $data .= get_lang('Score').';';
$data .= get_lang('Total').';'; $data .= get_lang('Total').';';
$data .= get_lang('Status').';'; $data .= get_lang('Status').';';
$data .= "\n"; $data .= "\n";
//results //results
foreach($this->results as $row) { foreach($this->results as $row) {
if (api_is_western_name_order()) {
if(!empty($row['first_name'])) { if (api_is_western_name_order()) {
$data .= str_replace("\r\n",' ',api_html_entity_decode(strip_tags($row['first_name']), ENT_QUOTES, $charset)).';'; $data .= str_replace("\r\n",' ',api_html_entity_decode(strip_tags($row['first_name']), ENT_QUOTES, $charset)).';';
} $data .= str_replace("\r\n",' ',api_html_entity_decode(strip_tags($row['last_name']), ENT_QUOTES, $charset)).';';
if(!empty($row['last_name'])) {
$data .= str_replace("\r\n",' ',api_html_entity_decode(strip_tags($row['last_name']), ENT_QUOTES, $charset)).';';
}
} else { } else {
if(!empty($row['last_name'])) { $data .= str_replace("\r\n",' ',api_html_entity_decode(strip_tags($row['last_name']), ENT_QUOTES, $charset)).';';
$data .= str_replace("\r\n",' ',api_html_entity_decode(strip_tags($row['last_name']), ENT_QUOTES, $charset)).';'; $data .= str_replace("\r\n",' ',api_html_entity_decode(strip_tags($row['first_name']), ENT_QUOTES, $charset)).';';
}
if(!empty($row['first_name'])) {
$data .= str_replace("\r\n",' ',api_html_entity_decode(strip_tags($row['first_name']), ENT_QUOTES, $charset)).';';
}
} }
$data .= str_replace("\r\n",' ',api_html_entity_decode(strip_tags($row['email']), ENT_QUOTES, $charset)).';'; $data .= str_replace("\r\n",' ',api_html_entity_decode(strip_tags($row['email']), ENT_QUOTES, $charset)).';';
if ($export_user_fields) { if ($export_user_fields) {
//show user fields data, if any, for this user //show user fields data, if any, for this user
$user_fields_values = UserManager::get_extra_user_data($row['user_id'],false,false, false, true); $user_fields_values = UserManager::get_extra_user_data($row['user_id'],false,false, false, true);
@ -308,8 +324,11 @@ class ExerciseResult
$data .= '"'.str_replace('"','""',api_html_entity_decode(strip_tags($value), ENT_QUOTES, $charset)).'";'; $data .= '"'.str_replace('"','""',api_html_entity_decode(strip_tags($value), ENT_QUOTES, $charset)).'";';
} }
} }
$data .= str_replace("\r\n",' ',api_html_entity_decode(strip_tags($row['title']), ENT_QUOTES, $charset)).';'; $data .= str_replace("\r\n",' ',api_html_entity_decode(strip_tags($row['title']), ENT_QUOTES, $charset)).';';
$data .= str_replace("\r\n",' ',$row['time']).';'; $data .= str_replace("\r\n",' ',$row['start_date']).';';
$data .= str_replace("\r\n",' ',$row['end_date']).';';
$data .= str_replace("\r\n",' ',$row['duration']).';';
$data .= str_replace("\r\n",' ',$row['result']).';'; $data .= str_replace("\r\n",' ',$row['result']).';';
$data .= str_replace("\r\n",' ',$row['max']).';'; $data .= str_replace("\r\n",' ',$row['max']).';';
$data .= str_replace("\r\n",' ',$row['status']).';'; $data .= str_replace("\r\n",' ',$row['status']).';';
@ -342,14 +361,12 @@ class ExerciseResult
* @return boolean False on error * @return boolean False on error
*/ */
public function exportCompleteReportXLS($document_path='',$user_id = null, $export_user_fields= false, $export_filter = 0, $exercise_id=0, $hotpotato_name = null) { public function exportCompleteReportXLS($document_path='',$user_id = null, $export_user_fields= false, $export_filter = 0, $exercise_id=0, $hotpotato_name = null) {
global $charset; global $charset;
$this->_getExercisesReporting($document_path, $user_id, $export_filter, $exercise_id, $hotpotato_name); $this->_getExercisesReporting($document_path, $user_id, $export_filter, $exercise_id, $hotpotato_name);
$filename = 'exercise_results_'.date('YmdGis').'.xls'; $filename = 'exercise_results_'.date('YmdGis').'.xls';
if(!empty($user_id)) { if (!empty($user_id)) {
$filename = 'exercise_results_user_'.$user_id.'_'.date('YmdGis').'.xls'; $filename = 'exercise_results_user_'.$user_id.'_'.date('YmdGis').'.xls';
} }
require_once api_get_path(LIBRARY_PATH).'pear/Spreadsheet_Excel_Writer/Writer.php';
$workbook = new Spreadsheet_Excel_Writer(); $workbook = new Spreadsheet_Excel_Writer();
$workbook->setTempDir(api_get_path(SYS_ARCHIVE_PATH)); $workbook->setTempDir(api_get_path(SYS_ARCHIVE_PATH));
$workbook->setVersion(8); // BIFF8 $workbook->setVersion(8); // BIFF8
@ -369,68 +386,88 @@ class ExerciseResult
} }
} }
if ($with_column_user) { if ($with_column_user) {
$worksheet->write($line,$column,get_lang('Email')); $worksheet->write($line,$column,get_lang('Email'));
$column++; $column++;
if (api_is_western_name_order()) { if (api_is_western_name_order()) {
$worksheet->write($line,$column,get_lang('FirstName')); $worksheet->write($line,$column,get_lang('FirstName'));
$column++; $column++;
$worksheet->write($line,$column,get_lang('LastName')); $worksheet->write($line,$column,get_lang('LastName'));
$column++; $column++;
} else { } else {
$worksheet->write($line,$column,get_lang('LastName')); $worksheet->write($line,$column,get_lang('LastName'));
$column++; $column++;
$worksheet->write($line,$column,get_lang('FirstName')); $worksheet->write($line,$column,get_lang('FirstName'));
$column++; $column++;
} }
} }
if ($export_user_fields) { if ($export_user_fields) {
//show user fields section with a big th colspan that spans over all fields //show user fields section with a big th colspan that spans over all fields
$extra_user_fields = UserManager::get_extra_fields(0,1000,5,'ASC',false, 1); $extra_user_fields = UserManager::get_extra_fields(0,1000,5,'ASC',false, 1);
//show the fields names for user fields //show the fields names for user fields
foreach($extra_user_fields as $field) { foreach ($extra_user_fields as $field) {
$worksheet->write($line,$column,api_html_entity_decode(strip_tags($field[3]), ENT_QUOTES, $charset)); $worksheet->write($line,$column,api_html_entity_decode(strip_tags($field[3]), ENT_QUOTES, $charset));
$column++; $column++;
} }
} }
$worksheet->write($line,$column,get_lang('Title')); $worksheet->write($line,$column, get_lang('Title'));
$column++; $column++;
$worksheet->write($line,$column,get_lang('StartDate')); $worksheet->write($line,$column, get_lang('StartDate'));
$column++;
$worksheet->write($line,$column, get_lang('EndDate'));
$column++;
$worksheet->write($line,$column, get_lang('Duration').' ('.get_lang('MinMinutes').')');
$column++; $column++;
$worksheet->write($line,$column,get_lang('Score')); $worksheet->write($line,$column, get_lang('Score'));
$column++; $column++;
$worksheet->write($line,$column,get_lang('Total')); $worksheet->write($line,$column, get_lang('Total'));
$column++; $column++;
$worksheet->write($line,$column,get_lang('Status')); $worksheet->write($line,$column, get_lang('Status'));
$line++; $line++;
foreach($this->results as $row) { foreach ($this->results as $row) {
$column = 0; $column = 0;
if(!empty($row['last_name']) && !empty($row['first_name'])) {
$worksheet->write($line,$column,api_html_entity_decode(strip_tags($row['email']), ENT_QUOTES, $charset)); if ($with_column_user) {
$column++; $worksheet->write($line,$column,api_html_entity_decode(strip_tags($row['email']), ENT_QUOTES, $charset));
$worksheet->write($line,$column,api_html_entity_decode(strip_tags($row['last_name']), ENT_QUOTES, $charset)); $column++;
$column++;
$worksheet->write($line,$column,api_html_entity_decode(strip_tags($row['first_name']), ENT_QUOTES, $charset)); if (api_is_western_name_order()) {
$column++; $worksheet->write($line,$column,api_html_entity_decode(strip_tags($row['first_name']), ENT_QUOTES, $charset));
$column++;
$worksheet->write($line,$column,api_html_entity_decode(strip_tags($row['last_name']), ENT_QUOTES, $charset));
$column++;
} else {
$worksheet->write($line,$column,api_html_entity_decode(strip_tags($row['last_name']), ENT_QUOTES, $charset));
$column++;
$worksheet->write($line,$column,api_html_entity_decode(strip_tags($row['first_name']), ENT_QUOTES, $charset));
$column++;
}
} }
if ($export_user_fields) { if ($export_user_fields) {
//show user fields data, if any, for this user //show user fields data, if any, for this user
$user_fields_values = UserManager::get_extra_user_data($row['user_id'],false,false, false, true); $user_fields_values = UserManager::get_extra_user_data($row['user_id'],false,false, false, true);
foreach($user_fields_values as $value) { foreach($user_fields_values as $value) {
$worksheet->write($line,$column, api_html_entity_decode(strip_tags($value), ENT_QUOTES, $charset)); $worksheet->write($line,$column, api_html_entity_decode(strip_tags($value), ENT_QUOTES, $charset));
$column++; $column++;
} }
} }
$worksheet->write($line,$column,api_html_entity_decode(strip_tags($row['title']), ENT_QUOTES, $charset)); $worksheet->write($line,$column,api_html_entity_decode(strip_tags($row['title']), ENT_QUOTES, $charset));
$column++; $column++;
$worksheet->write($line,$column,$row['time']); $worksheet->write($line,$column,$row['start_date']);
$column++;
$worksheet->write($line,$column,$row['end_date']);
$column++;
$worksheet->write($line,$column,$row['duration']);
$column++; $column++;
$worksheet->write($line,$column,$row['result']); $worksheet->write($line,$column,$row['result']);
$column++; $column++;
@ -444,4 +481,4 @@ class ExerciseResult
return true; return true;
} }
} }
endif; endif;

@ -212,10 +212,22 @@ if ($origin != 'learnpath') {
// Updates the empty exercise // Updates the empty exercise
$quiz_duration = (!empty($_SESSION['quizStartTime']) ? time() - $_SESSION['quizStartTime'] : 0); $quiz_duration = 0;
$end_date = api_get_utc_datetime();
if (isset($_SESSION['quizStartTime']) && !empty($_SESSION['quizStartTime'])) {
if (isset($_SESSION['quizStartTime'][$objExercise->selectId()])) {
$start_date = $_SESSION['quizStartTime'][$objExercise->selectId()];
$end_date_datetime = new DateTime($end_date);
$start_date_date_time = new DateTime($start_date);
$interval = $end_date_datetime->diff($start_date_date_time);
$hours = $interval->format('%h');
$minutes = $interval->format('%i');
$quiz_duration = $hours * 60 + $minutes;
}
}
if (api_is_allowed_to_session_edit()) { if (api_is_allowed_to_session_edit()) {
update_event_exercice($exercise_stat_info['exe_id'], $objExercise->selectId(), $total_score, $total_weight, api_get_session_id(), $safe_lp_id, $safe_lp_item_id, $safe_lp_item_view_id, $quiz_duration, $question_list, ''); update_event_exercice($exercise_stat_info['exe_id'], $objExercise->selectId(), $total_score, $total_weight, api_get_session_id(), $safe_lp_id, $safe_lp_item_id, $safe_lp_item_view_id, $quiz_duration, $question_list, '', array(), $end_date);
} }
//If is not valid //If is not valid

@ -17,9 +17,9 @@
* the administrator * the administrator
* @package chamilo.exercise * @package chamilo.exercise
* @author Olivier Brouckaert * @author Olivier Brouckaert
* @author Julio Montoya <gugli100@gmail.com> * @author Julio Montoya <gugli100@gmail.com>
* Fill in blank option added (2008) * Fill in blank option added (2008)
* Cleaning exercises (2010), * Cleaning exercises (2010),
* Adding hotspot delineation support (2011) * Adding hotspot delineation support (2011)
* Adding reminder + ajax support (2011) * Adding reminder + ajax support (2011)
* Modified by hubert.borderiou (2011-10-21 question category) * Modified by hubert.borderiou (2011-10-21 question category)
@ -105,9 +105,9 @@ if (api_is_allowed_to_edit(null,true) && $_GET['preview'] == 1 ) {
// 1. Loading the $objExercise variable // 1. Loading the $objExercise variable
if (!isset($_SESSION['objExercise']) || $_SESSION['objExercise']->id != $_REQUEST['exerciseId']) { if (!isset($_SESSION['objExercise']) || $_SESSION['objExercise']->id != $_REQUEST['exerciseId']) {
// Construction of Exercise // Construction of Exercise
$objExercise = new Exercise(); $objExercise = new Exercise();
if ($debug) {error_log('1. Setting the $objExercise variable'); }; if ($debug) {error_log('1. Setting the $objExercise variable'); };
unset($_SESSION['questionList']); unset($_SESSION['questionList']);
@ -119,14 +119,14 @@ if (!isset($_SESSION['objExercise']) || $_SESSION['objExercise']->id != $_REQUES
} else { } else {
// Saves the object into the session // Saves the object into the session
Session::write('objExercise',$objExercise); Session::write('objExercise',$objExercise);
if ($debug) {error_log('1.1. $_SESSION[objExercise] was unset - set now - end'); }; if ($debug) {error_log('1.1. $_SESSION[objExercise] was unset - set now - end'); };
} }
} }
//2. Checking if $objExercise is set //2. Checking if $objExercise is set
if (!isset($objExercise) && isset($_SESSION['objExercise'])) { if (!isset($objExercise) && isset($_SESSION['objExercise'])) {
if ($debug) { error_log('2. Loading $objExercise from session'); }; if ($debug) { error_log('2. Loading $objExercise from session'); };
$objExercise = $_SESSION['objExercise']; $objExercise = $_SESSION['objExercise'];
} }
//3. $objExercise is not set, then return to the exercise list //3. $objExercise is not set, then return to the exercise list
@ -157,7 +157,7 @@ if ($objExercise->expired_time != 0 && $origin != 'learnpath') {
if ($time_control) { if ($time_control) {
//Get the expired time of the current exercice in track_e_exercices //Get the expired time of the current exercice in track_e_exercices
$total_seconds = $objExercise->expired_time*60; $total_seconds = $objExercise->expired_time*60;
//Generating the time control key for the user //Generating the time control key for the user
$current_expired_time_key = generate_time_control_key($objExercise->id); $current_expired_time_key = generate_time_control_key($objExercise->id);
} }
@ -205,14 +205,14 @@ if ($objExercise->selectAttempts() > 0) {
} else { } else {
$attempt_html .= Display :: return_message(sprintf(get_lang('ReachedMaxAttempts'), $exercise_title, $objExercise->selectAttempts()), 'warning', false); $attempt_html .= Display :: return_message(sprintf(get_lang('ReachedMaxAttempts'), $exercise_title, $objExercise->selectAttempts()), 'warning', false);
//Display :: display_warning_message(sprintf(get_lang('ReachedMaxAttemptsAdmin'), $exercise_title, $objExercise->selectAttempts()), false); //Display :: display_warning_message(sprintf(get_lang('ReachedMaxAttemptsAdmin'), $exercise_title, $objExercise->selectAttempts()), false);
} }
if ($origin == 'learnpath') { if ($origin == 'learnpath') {
Display :: display_reduced_header(); Display :: display_reduced_header();
} else { } else {
Display :: display_header($nameTools,'Exercises'); Display :: display_header($nameTools,'Exercises');
} }
echo $attempt_html; echo $attempt_html;
if ($origin != 'learnpath') if ($origin != 'learnpath')
Display :: display_footer(); Display :: display_footer();
@ -231,28 +231,28 @@ $exercise_stat_info = $objExercise->get_stat_track_exercise_info($safe_lp_id, $s
if (empty($exercise_stat_info)) { if (empty($exercise_stat_info)) {
if ($debug) error_log('5 $exercise_stat_info is empty '); if ($debug) error_log('5 $exercise_stat_info is empty ');
$total_weight = 0; $total_weight = 0;
$questionList = $objExercise->get_validated_question_list(); $questionList = $objExercise->get_validated_question_list();
foreach ($questionList as $question_id) { foreach ($questionList as $question_id) {
$objQuestionTmp = Question::read($question_id); $objQuestionTmp = Question::read($question_id);
$total_weight += floatval($objQuestionTmp->weighting); $total_weight += floatval($objQuestionTmp->weighting);
} }
$clock_expired_time = ''; $clock_expired_time = '';
if ($time_control) { if ($time_control) {
$expected_time = $current_timestamp + $total_seconds; $expected_time = $current_timestamp + $total_seconds;
if ($debug) error_log('5.1. $current_timestamp '.$current_timestamp); if ($debug) error_log('5.1. $current_timestamp '.$current_timestamp);
if ($debug) error_log('5.2. $expected_time '.$expected_time); if ($debug) error_log('5.2. $expected_time '.$expected_time);
$clock_expired_time = api_get_utc_datetime($expected_time); $clock_expired_time = api_get_utc_datetime($expected_time);
if ($debug) error_log('5.3. $expected_time '.$clock_expired_time); if ($debug) error_log('5.3. $expected_time '.$clock_expired_time);
//Sessions that contain the expired time //Sessions that contain the expired time
$_SESSION['expired_time'][$current_expired_time_key] = $clock_expired_time; $_SESSION['expired_time'][$current_expired_time_key] = $clock_expired_time;
if ($debug) { error_log('5.4. Setting the $_SESSION[expired_time]: '.$_SESSION['expired_time'][$current_expired_time_key] ); }; if ($debug) { error_log('5.4. Setting the $_SESSION[expired_time]: '.$_SESSION['expired_time'][$current_expired_time_key] ); };
} }
$exe_id = $objExercise->save_stat_track_exercise_info($clock_expired_time, $safe_lp_id, $safe_lp_item_id, $safe_lp_item_view_id, $questionList, $total_weight); $exe_id = $objExercise->save_stat_track_exercise_info($clock_expired_time, $safe_lp_id, $safe_lp_item_id, $safe_lp_item_view_id, $questionList, $total_weight);
$exercise_stat_info = $objExercise->get_stat_track_exercise_info($safe_lp_id, $safe_lp_item_id, $safe_lp_item_view_id); $exercise_stat_info = $objExercise->get_stat_track_exercise_info($safe_lp_id, $safe_lp_item_id, $safe_lp_item_view_id);
if ($debug) error_log("5.5 exercise_stat_info[] exists getting exe_id $exe_id"); if ($debug) error_log("5.5 exercise_stat_info[] exists getting exe_id $exe_id");
} else { } else {
$exe_id = $exercise_stat_info['exe_id']; $exe_id = $exercise_stat_info['exe_id'];
@ -270,7 +270,7 @@ if (!empty($exercise_stat_info['questions_to_check'])) {
$params = 'exe_id='.$exe_id.'&exerciseId='.$exerciseId.'&origin='.$origin.'&learnpath_id='.$learnpath_id.'&learnpath_item_id='.$learnpath_item_id.'&learnpath_item_view_id='.$learnpath_item_view_id; $params = 'exe_id='.$exe_id.'&exerciseId='.$exerciseId.'&origin='.$origin.'&learnpath_id='.$learnpath_id.'&learnpath_item_id='.$learnpath_item_id.'&learnpath_item_view_id='.$learnpath_item_view_id;
if ($debug) { error_log("6.1 params: -> $params"); }; if ($debug) { error_log("6.1 params: -> $params"); };
if ($reminder == 2 && empty($my_remind_list)) { if ($reminder == 2 && empty($my_remind_list)) {
if ($debug) { error_log("6.2 calling the exercise_reminder.php "); }; if ($debug) { error_log("6.2 calling the exercise_reminder.php "); };
header('Location: exercise_reminder.php?'.$params); header('Location: exercise_reminder.php?'.$params);
exit; exit;
@ -282,46 +282,46 @@ if ($reminder == 2 && empty($my_remind_list)) {
*/ */
if ($time_control) { if ($time_control) {
if ($debug) error_log('7.1. Time control is enabled'); if ($debug) error_log('7.1. Time control is enabled');
if ($debug) error_log('7.2. $current_expired_time_key '.$current_expired_time_key); if ($debug) error_log('7.2. $current_expired_time_key '.$current_expired_time_key);
if ($debug) error_log('7.3. $_SESSION[expired_time][$current_expired_time_key] '.$_SESSION['expired_time'][$current_expired_time_key]); if ($debug) error_log('7.3. $_SESSION[expired_time][$current_expired_time_key] '.$_SESSION['expired_time'][$current_expired_time_key]);
if (!isset($_SESSION['expired_time'][$current_expired_time_key])) { if (!isset($_SESSION['expired_time'][$current_expired_time_key])) {
//Timer - Get expired_time for a student //Timer - Get expired_time for a student
if (!empty($exercise_stat_info)) { if (!empty($exercise_stat_info)) {
if ($debug) {error_log('7.4 Seems that the session ends and the user want to retake the exam'); }; if ($debug) {error_log('7.4 Seems that the session ends and the user want to retake the exam'); };
$expired_time_of_this_attempt = $exercise_stat_info['expired_time_control']; $expired_time_of_this_attempt = $exercise_stat_info['expired_time_control'];
if ($debug) {error_log('7.5 $expired_time_of_this_attempt: '.$expired_time_of_this_attempt); } if ($debug) {error_log('7.5 $expired_time_of_this_attempt: '.$expired_time_of_this_attempt); }
//Get the last attempt of an exercice //Get the last attempt of an exercice
$last_attempt_date = get_last_attempt_date_of_exercise($exercise_stat_info['exe_id']); $last_attempt_date = get_last_attempt_date_of_exercise($exercise_stat_info['exe_id']);
//This means that the user enters the exam but do not answer the first question we get the date from the track_e_exercises not from the track_et_attempt see #2069 //This means that the user enters the exam but do not answer the first question we get the date from the track_e_exercises not from the track_et_attempt see #2069
if (empty($last_attempt_date)) { if (empty($last_attempt_date)) {
$diff = $current_timestamp - api_strtotime($exercise_stat_info['start_date'], 'UTC'); $diff = $current_timestamp - api_strtotime($exercise_stat_info['start_date'], 'UTC');
$last_attempt_date = api_get_utc_datetime(api_strtotime($exercise_stat_info['start_date'],'UTC') + $diff); $last_attempt_date = api_get_utc_datetime(api_strtotime($exercise_stat_info['start_date'],'UTC') + $diff);
} else { } else {
//Recalculate the time control due #2069 //Recalculate the time control due #2069
$diff = $current_timestamp - api_strtotime($last_attempt_date,'UTC'); $diff = $current_timestamp - api_strtotime($last_attempt_date,'UTC');
$last_attempt_date = api_get_utc_datetime(api_strtotime($last_attempt_date,'UTC') + $diff); $last_attempt_date = api_get_utc_datetime(api_strtotime($last_attempt_date,'UTC') + $diff);
} }
if ($debug) {error_log('7.6. $last_attempt_date: '.$last_attempt_date); } if ($debug) {error_log('7.6. $last_attempt_date: '.$last_attempt_date); }
//New expired time - it is due to the possible closure of session //New expired time - it is due to the possible closure of session
$new_expired_time_in_seconds = api_strtotime($expired_time_of_this_attempt, 'UTC') - api_strtotime($last_attempt_date,'UTC'); $new_expired_time_in_seconds = api_strtotime($expired_time_of_this_attempt, 'UTC') - api_strtotime($last_attempt_date,'UTC');
if ($debug) {error_log('7.7. $new_expired_time_in_seconds: '.$new_expired_time_in_seconds); } if ($debug) {error_log('7.7. $new_expired_time_in_seconds: '.$new_expired_time_in_seconds); }
$expected_time = $current_timestamp + $new_expired_time_in_seconds; $expected_time = $current_timestamp + $new_expired_time_in_seconds;
if ($debug) {error_log('7.8. $expected_time1: '.$expected_time); } if ($debug) {error_log('7.8. $expected_time1: '.$expected_time); }
$clock_expired_time = api_get_utc_datetime($expected_time); $clock_expired_time = api_get_utc_datetime($expected_time);
if ($debug) {error_log('7.9. $clock_expired_time: '.$clock_expired_time); } if ($debug) {error_log('7.9. $clock_expired_time: '.$clock_expired_time); }
// First we update the attempt to today // First we update the attempt to today
// How the expired time is changed into "track_e_exercices" table,then the last attempt for this student should be changed too,so // How the expired time is changed into "track_e_exercices" table,then the last attempt for this student should be changed too,so
$sql_track_e_exe = "UPDATE $exercice_attemp_table SET tms = '".api_get_utc_datetime()."' WHERE exe_id = '".$exercise_stat_info['exe_id']."' AND tms = '".$last_attempt_date."' "; $sql_track_e_exe = "UPDATE $exercice_attemp_table SET tms = '".api_get_utc_datetime()."' WHERE exe_id = '".$exercise_stat_info['exe_id']."' AND tms = '".$last_attempt_date."' ";
if ($debug) {error_log('7.10. $sql_track_e_exe2: '.$sql_track_e_exe); } if ($debug) {error_log('7.10. $sql_track_e_exe2: '.$sql_track_e_exe); }
Database::query($sql_track_e_exe); Database::query($sql_track_e_exe);
//Sessions that contain the expired time //Sessions that contain the expired time
$_SESSION['expired_time'][$current_expired_time_key] = $clock_expired_time; $_SESSION['expired_time'][$current_expired_time_key] = $clock_expired_time;
if ($debug) {error_log('7.11. Setting the $_SESSION[expired_time]: '.$_SESSION['expired_time'][$current_expired_time_key] ); }; if ($debug) {error_log('7.11. Setting the $_SESSION[expired_time]: '.$_SESSION['expired_time'][$current_expired_time_key] ); };
@ -340,7 +340,7 @@ $time_left = api_strtotime($clock_expired_time,'UTC') - time();
* The time control feature is enable here - this feature is enable for a jquery plugin called epiclock * The time control feature is enable here - this feature is enable for a jquery plugin called epiclock
* for more details of how it works see this link : http://eric.garside.name/docs.html?p=epiclock * for more details of how it works see this link : http://eric.garside.name/docs.html?p=epiclock
*/ */
if ($time_control) { //Sends the exercice form when the expired time is finished if ($time_control) { //Sends the exercice form when the expired time is finished
$htmlHeadXtra[] = $objExercise->show_time_control_js($time_left); $htmlHeadXtra[] = $objExercise->show_time_control_js($time_left);
} }
@ -353,24 +353,24 @@ $exercise_sound = $objExercise->selectSound();
//if (!isset($_SESSION['questionList']) || $origin == 'learnpath') { //if (!isset($_SESSION['questionList']) || $origin == 'learnpath') {
//in LP's is enabled the "remember question" feature? //in LP's is enabled the "remember question" feature?
if (!isset($_SESSION['questionList'])) { if (!isset($_SESSION['questionList'])) {
// selects the list of question ID // selects the list of question ID
$questionList = $objExercise->get_validated_question_list(); $questionList = $objExercise->get_validated_question_list();
if ($objExercise->isRandom() && !empty($exercise_stat_info['data_tracking'])) { if ($objExercise->isRandom() && !empty($exercise_stat_info['data_tracking'])) {
$questionList = explode(',', $exercise_stat_info['data_tracking']); $questionList = explode(',', $exercise_stat_info['data_tracking']);
} }
Session::write('questionList',$questionList); Session::write('questionList',$questionList);
if ($debug > 0) { error_log('$_SESSION[questionList] was set'); } if ($debug > 0) { error_log('$_SESSION[questionList] was set'); }
} else { } else {
if (isset($objExercise) && isset($_SESSION['objExercise'])) { if (isset($objExercise) && isset($_SESSION['objExercise'])) {
$questionList = $_SESSION['questionList']; $questionList = $_SESSION['questionList'];
} }
} }
if ($debug) error_log('8. Question list loaded '.print_r($questionList, 1)); if ($debug) error_log('8. Question list loaded '.print_r($questionList, 1));
$quizStartTime = time(); $quizStartTime = array( $exerciseId => api_get_utc_datetime());
Session::write('quizStartTime',$quizStartTime); Session::write('quizStartTime', $quizStartTime);
//Real question count //Real question count
$question_count = 0; $question_count = 0;
@ -385,28 +385,28 @@ if ($formSent && isset($_POST)) {
if (!is_array($exerciseResult)) { if (!is_array($exerciseResult)) {
$exerciseResult = array(); $exerciseResult = array();
$exerciseResultCoordinates = array(); $exerciseResultCoordinates = array();
} }
//Only for hotspot //Only for hotspot
if (!isset($choice) && isset($_REQUEST['hidden_hotspot_id'])) { if (!isset($choice) && isset($_REQUEST['hidden_hotspot_id'])) {
$hotspot_id = (int)($_REQUEST['hidden_hotspot_id']); $hotspot_id = (int)($_REQUEST['hidden_hotspot_id']);
$choice = array($hotspot_id => ''); $choice = array($hotspot_id => '');
} }
// if the user has answered at least one question // if the user has answered at least one question
if (is_array($choice)) { if (is_array($choice)) {
if ($debug) { error_log('9.1. $choice is an array '.print_r($choice, 1)); } if ($debug) { error_log('9.1. $choice is an array '.print_r($choice, 1)); }
// Also store hotspot spots in the session ($exerciseResultCoordinates // Also store hotspot spots in the session ($exerciseResultCoordinates
// will be stored in the session at the end of this script) // will be stored in the session at the end of this script)
if (isset($_POST['hotspot'])) { if (isset($_POST['hotspot'])) {
$exerciseResultCoordinates = $_POST['hotspot']; $exerciseResultCoordinates = $_POST['hotspot'];
if ($debug) { error_log('9.2. $_POST[hotspot] data '.print_r($exerciseResultCoordinates, 1)); } if ($debug) { error_log('9.2. $_POST[hotspot] data '.print_r($exerciseResultCoordinates, 1)); }
} }
if ($objExercise->type == ALL_ON_ONE_PAGE) { if ($objExercise->type == ALL_ON_ONE_PAGE) {
// $exerciseResult receives the content of the form. // $exerciseResult receives the content of the form.
// Each choice of the student is stored into the array $choice // Each choice of the student is stored into the array $choice
$exerciseResult = $choice; $exerciseResult = $choice;
} else { } else {
// gets the question ID from $choice. It is the key of the array // gets the question ID from $choice. It is the key of the array
list ($key) = array_keys($choice); list ($key) = array_keys($choice);
@ -417,9 +417,9 @@ if ($formSent && isset($_POST)) {
//saving each question //saving each question
if ($objExercise->feedback_type != EXERCISE_FEEDBACK_TYPE_DIRECT) { if ($objExercise->feedback_type != EXERCISE_FEEDBACK_TYPE_DIRECT) {
$nro_question = $current_question; // - 1; $nro_question = $current_question; // - 1;
$questionId = $key; $questionId = $key;
// gets the student choice for this question // gets the student choice for this question
$choice = $exerciseResult[$questionId]; $choice = $exerciseResult[$questionId];
if (isset($exe_id)) { if (isset($exe_id)) {
//Manage the question and answer attempts //Manage the question and answer attempts
if ($debug) { error_log('8.3. manage_answer exe_id: '.$exe_id.' - $questionId: '.$questionId.' Choice'.print_r($choice,1)); } if ($debug) { error_log('8.3. manage_answer exe_id: '.$exe_id.' - $questionId: '.$questionId.' Choice'.print_r($choice,1)); }
@ -432,35 +432,35 @@ if ($formSent && isset($_POST)) {
if ($debug) { error_log('9.3. $choice is an array - end'); } if ($debug) { error_log('9.3. $choice is an array - end'); }
if ($debug) { error_log('9.4. $exerciseResult '.print_r($exerciseResult,1)); } if ($debug) { error_log('9.4. $exerciseResult '.print_r($exerciseResult,1)); }
} }
// the script "exercise_result.php" will take the variable $exerciseResult from the session // the script "exercise_result.php" will take the variable $exerciseResult from the session
Session::write('exerciseResult',$exerciseResult); Session::write('exerciseResult',$exerciseResult);
Session::write('remind_list',$remind_list); Session::write('remind_list',$remind_list);
Session::write('exerciseResultCoordinates',$exerciseResultCoordinates); Session::write('exerciseResultCoordinates',$exerciseResultCoordinates);
// if all questions on one page OR if it is the last question (only for an exercise with one question per page) // if all questions on one page OR if it is the last question (only for an exercise with one question per page)
if (($objExercise->type == ALL_ON_ONE_PAGE || $current_question >= $question_count)) { if (($objExercise->type == ALL_ON_ONE_PAGE || $current_question >= $question_count)) {
if (api_is_allowed_to_session_edit()) { if (api_is_allowed_to_session_edit()) {
// goes to the script that will show the result of the exercise // goes to the script that will show the result of the exercise
if ($objExercise->type == ALL_ON_ONE_PAGE) { if ($objExercise->type == ALL_ON_ONE_PAGE) {
if ($debug) { error_log('10. Exercise ALL_ON_ONE_PAGE -> Redirecting to exercise_result.php'); } if ($debug) { error_log('10. Exercise ALL_ON_ONE_PAGE -> Redirecting to exercise_result.php'); }
//We check if the user attempts before sending to the exercise_result.php //We check if the user attempts before sending to the exercise_result.php
if ($objExercise->selectAttempts() > 0) { if ($objExercise->selectAttempts() > 0) {
$attempt_count = get_attempt_count(api_get_user_id(), $exerciseId, $safe_lp_id, $safe_lp_item_id, $safe_lp_item_view_id); $attempt_count = get_attempt_count(api_get_user_id(), $exerciseId, $safe_lp_id, $safe_lp_item_id, $safe_lp_item_view_id);
if ($attempt_count >= $objExercise->selectAttempts()) { if ($attempt_count >= $objExercise->selectAttempts()) {
Display :: display_warning_message(sprintf(get_lang('ReachedMaxAttempts'), $exercise_title, $objExercise->selectAttempts()), false); Display :: display_warning_message(sprintf(get_lang('ReachedMaxAttempts'), $exercise_title, $objExercise->selectAttempts()), false);
if ($origin != 'learnpath') { if ($origin != 'learnpath') {
//so we are not in learnpath tool //so we are not in learnpath tool
echo '</div>'; //End glossary div echo '</div>'; //End glossary div
Display :: display_footer(); Display :: display_footer();
} else { } else {
echo '</body></html>'; echo '</body></html>';
} }
} }
} }
header("Location: exercise_result.php?exe_id=$exe_id&origin=$origin&learnpath_id=$safe_lp_id&learnpath_item_id=$safe_lp_item_id&learnpath_item_view_id=$safe_lp_item_view_id"); header("Location: exercise_result.php?exe_id=$exe_id&origin=$origin&learnpath_id=$safe_lp_id&learnpath_item_id=$safe_lp_item_id&learnpath_item_view_id=$safe_lp_item_view_id");
exit; exit;
} else { } else {
@ -468,28 +468,28 @@ if ($formSent && isset($_POST)) {
if (!empty($exe_id) && is_numeric($exe_id)) { if (!empty($exe_id) && is_numeric($exe_id)) {
//Verify if the current test is fraudulent //Verify if the current test is fraudulent
if (exercise_time_control_is_valid($exerciseId)) { if (exercise_time_control_is_valid($exerciseId)) {
$sql_exe_result = ""; $sql_exe_result = "";
if ($debug) { error_log('exercise_time_control_is_valid is valid'); } if ($debug) { error_log('exercise_time_control_is_valid is valid'); }
} else { } else {
$sql_exe_result = ", exe_result = 0"; $sql_exe_result = ", exe_result = 0";
if ($debug) { error_log('exercise_time_control_is_valid is NOT valid then exe_result = 0 '); } if ($debug) { error_log('exercise_time_control_is_valid is NOT valid then exe_result = 0 '); }
} }
/* /*
//Clean incomplete - @todo why setting to blank the status? //Clean incomplete - @todo why setting to blank the status?
$update_query = "UPDATE $stat_table SET status = '', exe_date = '".api_get_utc_datetime() ."' , orig_lp_item_view_id = '$safe_lp_item_view_id' $sql_exe_result WHERE exe_id = ".$exe_id; $update_query = "UPDATE $stat_table SET status = '', exe_date = '".api_get_utc_datetime() ."' , orig_lp_item_view_id = '$safe_lp_item_view_id' $sql_exe_result WHERE exe_id = ".$exe_id;
if ($debug) { error_log('Updating track_e_exercises '.$update_query); } if ($debug) { error_log('Updating track_e_exercises '.$update_query); }
Database::query($update_query);*/ Database::query($update_query);*/
} }
if ($debug) { error_log('10. Redirecting to exercise_show.php'); } if ($debug) { error_log('10. Redirecting to exercise_show.php'); }
//header("Location: exercise_show.php?id=$exe_id&origin=$origin&learnpath_id=$safe_lp_id&learnpath_item_id=$safe_lp_item_id&learnpath_item_view_id=$safe_lp_item_view_id"); //header("Location: exercise_show.php?id=$exe_id&origin=$origin&learnpath_id=$safe_lp_id&learnpath_item_id=$safe_lp_item_id&learnpath_item_view_id=$safe_lp_item_view_id");
header("Location: exercise_result.php?exe_id=$exe_id&origin=$origin&learnpath_id=$safe_lp_id&learnpath_item_id=$safe_lp_item_id&learnpath_item_view_id=$safe_lp_item_view_id"); header("Location: exercise_result.php?exe_id=$exe_id&origin=$origin&learnpath_id=$safe_lp_id&learnpath_item_id=$safe_lp_item_id&learnpath_item_view_id=$safe_lp_item_view_id");
exit; exit;
} }
} else { } else {
if ($debug) { error_log('10. Redirecting to exercise_submit.php'); } if ($debug) { error_log('10. Redirecting to exercise_submit.php'); }
header("Location: exercise_submit.php?exerciseId=$exerciseId&origin=$origin"); header("Location: exercise_submit.php?exerciseId=$exerciseId&origin=$origin");
exit; exit;
} }
} }
if ($debug) { error_log('11. $formSent was set - end'); } if ($debug) { error_log('11. $formSent was set - end'); }
@ -508,62 +508,62 @@ if (!$current_question || $_REQUEST['num']) {
} }
if ($question_count != 0) { if ($question_count != 0) {
if (($objExercise->type == ALL_ON_ONE_PAGE || $current_question > $question_count)) { if (($objExercise->type == ALL_ON_ONE_PAGE || $current_question > $question_count)) {
if (api_is_allowed_to_session_edit()) { if (api_is_allowed_to_session_edit()) {
// goes to the script that will show the result of the exercise // goes to the script that will show the result of the exercise
if ($objExercise->type == ALL_ON_ONE_PAGE) { if ($objExercise->type == ALL_ON_ONE_PAGE) {
if ($debug) { error_log('12. Exercise ALL_ON_ONE_PAGE -> Redirecting to exercise_result.php'); } if ($debug) { error_log('12. Exercise ALL_ON_ONE_PAGE -> Redirecting to exercise_result.php'); }
//We check if the user attempts before sending to the exercise_result.php //We check if the user attempts before sending to the exercise_result.php
if ($objExercise->selectAttempts() > 0) { if ($objExercise->selectAttempts() > 0) {
$attempt_count = get_attempt_count(api_get_user_id(), $exerciseId, $safe_lp_id, $safe_lp_item_id, $safe_lp_item_view_id); $attempt_count = get_attempt_count(api_get_user_id(), $exerciseId, $safe_lp_id, $safe_lp_item_id, $safe_lp_item_view_id);
if ($attempt_count >= $objExercise->selectAttempts()) { if ($attempt_count >= $objExercise->selectAttempts()) {
Display :: display_warning_message(sprintf(get_lang('ReachedMaxAttempts'), $exercise_title, $objExercise->selectAttempts()), false); Display :: display_warning_message(sprintf(get_lang('ReachedMaxAttempts'), $exercise_title, $objExercise->selectAttempts()), false);
if ($origin != 'learnpath') { if ($origin != 'learnpath') {
//so we are not in learnpath tool //so we are not in learnpath tool
echo '</div>'; //End glossary div echo '</div>'; //End glossary div
Display :: display_footer(); Display :: display_footer();
} else { } else {
echo '</body></html>'; echo '</body></html>';
} }
exit; exit;
} }
} }
//header("Location: exercise_result.php?origin=$origin&learnpath_id=$safe_lp_id&learnpath_item_id=$safe_lp_item_id&learnpath_item_view_id=$safe_lp_item_view_id"); //header("Location: exercise_result.php?origin=$origin&learnpath_id=$safe_lp_id&learnpath_item_id=$safe_lp_item_id&learnpath_item_view_id=$safe_lp_item_view_id");
//exit; //exit;
} else { } else {
//Time control is only enabled for ONE PER PAGE //Time control is only enabled for ONE PER PAGE
if (!empty($exe_id) && is_numeric($exe_id)) { if (!empty($exe_id) && is_numeric($exe_id)) {
//Verify if the current test is fraudulent //Verify if the current test is fraudulent
$check = exercise_time_control_is_valid($exerciseId); $check = exercise_time_control_is_valid($exerciseId);
if ($check) { if ($check) {
$sql_exe_result = ""; $sql_exe_result = "";
if ($debug) { error_log('12. exercise_time_control_is_valid is valid'); } if ($debug) { error_log('12. exercise_time_control_is_valid is valid'); }
} else { } else {
$sql_exe_result = ", exe_result = 0"; $sql_exe_result = ", exe_result = 0";
if ($debug) { error_log('12. exercise_time_control_is_valid is NOT valid then exe_result = 0 '); } if ($debug) { error_log('12. exercise_time_control_is_valid is NOT valid then exe_result = 0 '); }
} }
/* /*
//Clean incomplete - @todo why setting to blank the status? //Clean incomplete - @todo why setting to blank the status?
$update_query = "UPDATE $stat_table SET status = '', exe_date = '".api_get_utc_datetime() ."' , orig_lp_item_view_id = '$safe_lp_item_view_id' $sql_exe_result WHERE exe_id = ".$exe_id; $update_query = "UPDATE $stat_table SET status = '', exe_date = '".api_get_utc_datetime() ."' , orig_lp_item_view_id = '$safe_lp_item_view_id' $sql_exe_result WHERE exe_id = ".$exe_id;
//if ($debug) { error_log('Updating track_e_exercises '.$update_query); } //if ($debug) { error_log('Updating track_e_exercises '.$update_query); }
Database::query($update_query);*/ Database::query($update_query);*/
} }
if ($objExercise->review_answers) { if ($objExercise->review_answers) {
header('Location: exercise_reminder.php?'.$params); header('Location: exercise_reminder.php?'.$params);
exit; exit;
} else { } else {
header("Location: exercise_result.php?exe_id=$exe_id&origin=$origin&learnpath_id=$safe_lp_id&learnpath_item_id=$safe_lp_item_id&learnpath_item_view_id=$safe_lp_item_view_id"); header("Location: exercise_result.php?exe_id=$exe_id&origin=$origin&learnpath_id=$safe_lp_id&learnpath_item_id=$safe_lp_item_id&learnpath_item_view_id=$safe_lp_item_view_id");
} }
} }
} else { } else {
if ($debug) { error_log('Redirecting to exercise_submit.php'); } if ($debug) { error_log('Redirecting to exercise_submit.php'); }
//header("Location: exercise_submit.php?exerciseId=$exerciseId"); //header("Location: exercise_submit.php?exerciseId=$exerciseId");
exit; exit;
} }
} }
} else { } else {
@ -589,7 +589,7 @@ if (!empty ($gradebook) && $gradebook == 'view') {
$interbreadcrumb[] = array ("url" => "exercice.php?gradebook=$gradebook", "name" => get_lang('Exercices')); $interbreadcrumb[] = array ("url" => "exercice.php?gradebook=$gradebook", "name" => get_lang('Exercices'));
$interbreadcrumb[] = array ("url" => "#","name" => $objExercise->name); $interbreadcrumb[] = array ("url" => "#","name" => $objExercise->name);
if ($origin != 'learnpath') { //so we are not in learnpath tool if ($origin != 'learnpath') { //so we are not in learnpath tool
Display :: display_header($nameTools,'Exercises'); Display :: display_header($nameTools,'Exercises');
if (!api_is_allowed_to_session_edit() ) { if (!api_is_allowed_to_session_edit() ) {
Display :: display_warning_message(get_lang('SessionIsReadOnly')); Display :: display_warning_message(get_lang('SessionIsReadOnly'));
@ -616,7 +616,7 @@ if (api_is_course_admin() && $origin != 'learnpath') {
$is_visible_return = $objExercise->is_visible($learnpath_id, $learnpath_item_id, $learnpath_item_view_id); $is_visible_return = $objExercise->is_visible($learnpath_id, $learnpath_item_id, $learnpath_item_view_id);
if ($is_visible_return['value'] == false) { if ($is_visible_return['value'] == false) {
echo $is_visible_return['message']; echo $is_visible_return['message'];
if ($origin != 'learnpath') { if ($origin != 'learnpath') {
Display :: display_footer(); Display :: display_footer();
} }
@ -625,11 +625,11 @@ if ($is_visible_return['value'] == false) {
$limit_time_exists = (($objExercise->start_time != '0000-00-00 00:00:00') || ($objExercise->end_time != '0000-00-00 00:00:00')) ? true : false; $limit_time_exists = (($objExercise->start_time != '0000-00-00 00:00:00') || ($objExercise->end_time != '0000-00-00 00:00:00')) ? true : false;
if ($limit_time_exists) { if ($limit_time_exists) {
$exercise_start_time = api_strtotime($objExercise->start_time, 'UTC'); $exercise_start_time = api_strtotime($objExercise->start_time, 'UTC');
$exercise_end_time = api_strtotime($objExercise->end_time, 'UTC'); $exercise_end_time = api_strtotime($objExercise->end_time, 'UTC');
$time_now = time(); $time_now = time();
if ($objExercise->start_time != '0000-00-00 00:00:00') { if ($objExercise->start_time != '0000-00-00 00:00:00') {
$permission_to_start = (($time_now - $exercise_start_time) > 0) ? true : false; $permission_to_start = (($time_now - $exercise_start_time) > 0) ? true : false;
} else { } else {
@ -640,11 +640,11 @@ if ($limit_time_exists) {
$exercise_timeover = (($time_now - $exercise_end_time) > 0) ? true : false; $exercise_timeover = (($time_now - $exercise_end_time) > 0) ? true : false;
} else { } else {
$exercise_timeover = false; $exercise_timeover = false;
} }
} }
if (!$permission_to_start || $exercise_timeover) { if (!$permission_to_start || $exercise_timeover) {
if (!api_is_allowed_to_edit(null,true)) { if (!api_is_allowed_to_edit(null,true)) {
$message_warning = $permission_to_start ? get_lang('ReachedTimeLimit') : get_lang('ExerciseNoStartedYet'); $message_warning = $permission_to_start ? get_lang('ReachedTimeLimit') : get_lang('ExerciseNoStartedYet');
Display :: display_warning_message(sprintf($message_warning, $exercise_title, $objExercise->selectAttempts())); Display :: display_warning_message(sprintf($message_warning, $exercise_title, $objExercise->selectAttempts()));
if ($origin != 'learnpath') { if ($origin != 'learnpath') {
@ -682,32 +682,32 @@ if ($origin != 'learnpath') {
if ($reminder == 2) { if ($reminder == 2) {
if ($debug) { error_log('. $reminder == 2'); } if ($debug) { error_log('. $reminder == 2'); }
$data_tracking = $exercise_stat_info['data_tracking']; $data_tracking = $exercise_stat_info['data_tracking'];
$data_tracking = explode(',', $data_tracking); $data_tracking = explode(',', $data_tracking);
$current_question = 1; //set by default the 1st question $current_question = 1; //set by default the 1st question
if (!empty($my_remind_list)) { if (!empty($my_remind_list)) {
//Checking which questions we are going to call from the remind list //Checking which questions we are going to call from the remind list
for ($i = 0; $i < count($data_tracking); $i++) { for ($i = 0; $i < count($data_tracking); $i++) {
for($j = 0; $j < count($my_remind_list); $j++) { for($j = 0; $j < count($my_remind_list); $j++) {
if (!empty($remind_question_id)) { if (!empty($remind_question_id)) {
if ($remind_question_id == $my_remind_list[$j]) { if ($remind_question_id == $my_remind_list[$j]) {
if ($remind_question_id == $data_tracking[$i]) { if ($remind_question_id == $data_tracking[$i]) {
if (isset($my_remind_list[$j+1])) { if (isset($my_remind_list[$j+1])) {
$remind_question_id = $my_remind_list[$j+1]; $remind_question_id = $my_remind_list[$j+1];
$current_question = $i + 1; $current_question = $i + 1;
} else { } else {
$remind_question_id = -1; //We end the remind list we go to the exercise_reminder.php please $remind_question_id = -1; //We end the remind list we go to the exercise_reminder.php please
$current_question = $i + 1; // last question $current_question = $i + 1; // last question
} }
break 2; break 2;
} }
} }
} else { } else {
if ($my_remind_list[$j] == $data_tracking[$i]) { if ($my_remind_list[$j] == $data_tracking[$i]) {
if (isset($my_remind_list[$j+1])) { if (isset($my_remind_list[$j+1])) {
$remind_question_id = $my_remind_list[$j+1]; $remind_question_id = $my_remind_list[$j+1];
@ -715,11 +715,11 @@ if ($reminder == 2) {
} else { } else {
$remind_question_id = -1; //We end the remind list we go to the exercise_reminder.php please $remind_question_id = -1; //We end the remind list we go to the exercise_reminder.php please
$current_question = $i + 1; // last question $current_question = $i + 1; // last question
} }
break 2; break 2;
} }
} }
} }
} }
} else { } else {
if ($objExercise->review_answers) { if ($objExercise->review_answers) {
@ -758,7 +758,7 @@ if (!empty($error)) {
// if it is not the right question, goes to the next loop iteration // if it is not the right question, goes to the next loop iteration
if ($current_question != $i) { if ($current_question != $i) {
continue; continue;
} else { } else {
if ($objQuestionTmp->selectType() == HOT_SPOT || $objQuestionTmp->selectType() == HOT_SPOT_DELINEATION) { if ($objQuestionTmp->selectType() == HOT_SPOT || $objQuestionTmp->selectType() == HOT_SPOT_DELINEATION) {
$number_of_hotspot_questions++; $number_of_hotspot_questions++;
} }
@ -771,15 +771,15 @@ if (!empty($error)) {
} }
} }
} }
if ($number_of_hotspot_questions > 0) { if ($number_of_hotspot_questions > 0) {
$onsubmit = "onsubmit=\"return validateFlashVar('" . $number_of_hotspot_questions . "', '" . get_lang('HotspotValidateError1') . "', '" . get_lang('HotspotValidateError2') . "');\""; $onsubmit = "onsubmit=\"return validateFlashVar('" . $number_of_hotspot_questions . "', '" . get_lang('HotspotValidateError1') . "', '" . get_lang('HotspotValidateError2') . "');\"";
} }
echo '<script> echo '<script>
$(function() { $(function() {
//$(".exercise_save_now_button").hide(); //$(".exercise_save_now_button").hide();
$(".main_question").mouseover(function() { $(".main_question").mouseover(function() {
//$(this).find(".exercise_save_now_button").show(); //$(this).find(".exercise_save_now_button").show();
//$(this).addClass("question_highlight"); //$(this).addClass("question_highlight");
@ -789,110 +789,110 @@ if (!empty($error)) {
//$(this).find(".exercise_save_now_button").hide(); //$(this).find(".exercise_save_now_button").hide();
$(this).removeClass("question_highlight"); $(this).removeClass("question_highlight");
}); });
}); });
function previous_question(question_num) {
function previous_question(question_num) { url = "exercise_submit.php?'.$params.'&num="+question_num;
url = "exercise_submit.php?'.$params.'&num="+question_num;
window.location = url; window.location = url;
} }
function save_now(question_id) { function save_now(question_id) {
//1. Normal choice inputs //1. Normal choice inputs
var my_choice = $(\'*[name*="choice[\'+question_id+\']"]\').serialize(); var my_choice = $(\'*[name*="choice[\'+question_id+\']"]\').serialize();
//2. Reminder checkbox //2. Reminder checkbox
var remind_list = $(\'*[name*="remind_list"]\').serialize(); var remind_list = $(\'*[name*="remind_list"]\').serialize();
//3. Hotspots //3. Hotspots
var hotspot = $(\'*[name*="hotspot[\'+question_id+\']"]\').serialize(); var hotspot = $(\'*[name*="hotspot[\'+question_id+\']"]\').serialize();
//Checking FCK //Checking FCK
if (typeof(FCKeditorAPI) !== "undefined") { if (typeof(FCKeditorAPI) !== "undefined") {
var oEditor = FCKeditorAPI.GetInstance("choice["+question_id+"]") ; var oEditor = FCKeditorAPI.GetInstance("choice["+question_id+"]") ;
var fck_content = ""; var fck_content = "";
if (oEditor) { if (oEditor) {
fck_content = oEditor.GetHTML(); fck_content = oEditor.GetHTML();
my_choice = {}; my_choice = {};
my_choice["choice["+question_id+"]"] = fck_content; my_choice["choice["+question_id+"]"] = fck_content;
my_choice = $.param(my_choice); my_choice = $.param(my_choice);
} }
} }
if ($(\'input[name="remind_list[\'+question_id+\']"]\').is(\':checked\')) { if ($(\'input[name="remind_list[\'+question_id+\']"]\').is(\':checked\')) {
$("#question_div_"+question_id).addClass("remind_highlight"); $("#question_div_"+question_id).addClass("remind_highlight");
} else { } else {
$("#question_div_"+question_id).removeClass("remind_highlight"); $("#question_div_"+question_id).removeClass("remind_highlight");
} }
// Only for the first time // Only for the first time
$("#save_for_now_"+question_id).html("'.addslashes(Display::return_icon('loading1.gif')).'"); $("#save_for_now_"+question_id).html("'.addslashes(Display::return_icon('loading1.gif')).'");
$.ajax({ $.ajax({
url: "'.api_get_path(WEB_AJAX_PATH).'exercise.ajax.php?a=save_exercise_by_now", url: "'.api_get_path(WEB_AJAX_PATH).'exercise.ajax.php?a=save_exercise_by_now",
data: "'.$params.'&type=simple&question_id="+question_id+"&"+my_choice+"&"+hotspot+"&"+remind_list, data: "'.$params.'&type=simple&question_id="+question_id+"&"+my_choice+"&"+hotspot+"&"+remind_list,
success: function(return_value) { success: function(return_value) {
if (return_value == "ok") { if (return_value == "ok") {
$("#save_for_now_"+question_id).html("'.addslashes(Display::return_icon('save.png', get_lang('Saved'), array(), ICON_SIZE_SMALL)).'"); $("#save_for_now_"+question_id).html("'.addslashes(Display::return_icon('save.png', get_lang('Saved'), array(), ICON_SIZE_SMALL)).'");
} else if (return_value == "error") { } else if (return_value == "error") {
$("#save_for_now_"+question_id).html("'.addslashes(Display::return_icon('error.png', get_lang('Error'), array(), ICON_SIZE_SMALL)).'"); $("#save_for_now_"+question_id).html("'.addslashes(Display::return_icon('error.png', get_lang('Error'), array(), ICON_SIZE_SMALL)).'");
} else if (return_value == "one_per_page") { } else if (return_value == "one_per_page") {
var url = ""; var url = "";
if ('.$reminder.' == 1 ) { if ('.$reminder.' == 1 ) {
url = "exercise_reminder.php?'.$params.'&num='.$current_question.'"; url = "exercise_reminder.php?'.$params.'&num='.$current_question.'";
} else if ('.$reminder.' == 2 ) { } else if ('.$reminder.' == 2 ) {
url = "exercise_submit.php?'.$params.'&num='.$current_question.'&remind_question_id='.$remind_question_id.'&reminder=2"; url = "exercise_submit.php?'.$params.'&num='.$current_question.'&remind_question_id='.$remind_question_id.'&reminder=2";
} else { } else {
url = "exercise_submit.php?'.$params.'&num='.$current_question.'&remind_question_id='.$remind_question_id.'"; url = "exercise_submit.php?'.$params.'&num='.$current_question.'&remind_question_id='.$remind_question_id.'";
} }
window.location = url; window.location = url;
} }
}, },
error: function() { error: function() {
$("#save_for_now_"+question_id).html("'.addslashes(Display::return_icon('error.png', get_lang('Error'), array(), ICON_SIZE_SMALL)).'"); $("#save_for_now_"+question_id).html("'.addslashes(Display::return_icon('error.png', get_lang('Error'), array(), ICON_SIZE_SMALL)).'");
} }
}); });
return false; return false;
} }
function save_now_all(validate) { function save_now_all(validate) {
//1. Input choice //1. Input choice
var my_choice = $(\'*[name*="choice"]\').serialize(); var my_choice = $(\'*[name*="choice"]\').serialize();
//2. Reminder //2. Reminder
var remind_list = $(\'*[name*="remind_list"]\').serialize(); var remind_list = $(\'*[name*="remind_list"]\').serialize();
//3. Hotspots //3. Hotspots
var hotspot = $(\'*[name*="hotspot"]\').serialize(); var hotspot = $(\'*[name*="hotspot"]\').serialize();
//Question list //Question list
var question_list = ['.implode(',', $questionList).']; var question_list = ['.implode(',', $questionList).'];
var free_answers = {}; var free_answers = {};
$.each(question_list, function(index, my_question_id) { $.each(question_list, function(index, my_question_id) {
//Checking FCK //Checking FCK
if (typeof(FCKeditorAPI) !== "undefined") { if (typeof(FCKeditorAPI) !== "undefined") {
var oEditor = FCKeditorAPI.GetInstance("choice["+my_question_id+"]") ; var oEditor = FCKeditorAPI.GetInstance("choice["+my_question_id+"]") ;
var fck_content = ""; var fck_content = "";
if (oEditor) { if (oEditor) {
fck_content = oEditor.GetHTML(); fck_content = oEditor.GetHTML();
//alert(index + " " +my_question_id + " " +fck_content); //alert(index + " " +my_question_id + " " +fck_content);
free_answers["free_choice["+my_question_id+"]"] = fck_content; free_answers["free_choice["+my_question_id+"]"] = fck_content;
} }
} }
}); });
//lok+(fgt)= data base //lok+(fgt)= data base
free_answers = $.param(free_answers); free_answers = $.param(free_answers);
$("#save_all_reponse").html("'.addslashes(Display::return_icon('loading1.gif')).'"); $("#save_all_reponse").html("'.addslashes(Display::return_icon('loading1.gif')).'");
$.ajax({ $.ajax({
url: "'.api_get_path(WEB_AJAX_PATH).'exercise.ajax.php?a=save_exercise_by_now", url: "'.api_get_path(WEB_AJAX_PATH).'exercise.ajax.php?a=save_exercise_by_now",
data: "'.$params.'&type=all&"+my_choice+"&"+hotspot+"&"+free_answers+"&"+remind_list, data: "'.$params.'&type=all&"+my_choice+"&"+hotspot+"&"+free_answers+"&"+remind_list,
success: function(return_value) { success: function(return_value) {
if (return_value == "ok") { if (return_value == "ok") {
//$("#save_all_reponse").html("'.addslashes(Display::return_icon('accept.png')).'"); //$("#save_all_reponse").html("'.addslashes(Display::return_icon('accept.png')).'");
if (validate == "validate") { if (validate == "validate") {
window.location = "'.$script_php.'?'.$params.'"; window.location = "'.$script_php.'?'.$params.'";
@ -901,17 +901,17 @@ if (!empty($error)) {
} }
} else { } else {
$("#save_all_reponse").html("'.addslashes(Display::return_icon('wrong.gif')).'"); $("#save_all_reponse").html("'.addslashes(Display::return_icon('wrong.gif')).'");
} }
}, },
}); });
return false; return false;
} }
function validate_all() { function validate_all() {
save_now_all("validate"); save_now_all("validate");
return false; return false;
} }
</script>'; </script>';
echo '<form id="exercise_form" method="post" action="'.api_get_self().'?'.api_get_cidreq().'&autocomplete=off&gradebook='.$gradebook."&exerciseId=" . $exerciseId .'" name="frm_exercise" '.$onsubmit.'> echo '<form id="exercise_form" method="post" action="'.api_get_self().'?'.api_get_cidreq().'&autocomplete=off&gradebook='.$gradebook."&exerciseId=" . $exerciseId .'" name="frm_exercise" '.$onsubmit.'>
<input type="hidden" name="formSent" value="1" /> <input type="hidden" name="formSent" value="1" />
@ -922,27 +922,27 @@ if (!empty($error)) {
<input type="hidden" name="learnpath_id" value="'.$safe_lp_id . '" /> <input type="hidden" name="learnpath_id" value="'.$safe_lp_id . '" />
<input type="hidden" name="learnpath_item_id" value="'.$safe_lp_item_id . '" /> <input type="hidden" name="learnpath_item_id" value="'.$safe_lp_item_id . '" />
<input type="hidden" name="learnpath_item_view_id" value="'.$safe_lp_item_view_id . '" />'; <input type="hidden" name="learnpath_item_view_id" value="'.$safe_lp_item_view_id . '" />';
//Show list of questions //Show list of questions
$i = 1; $i = 1;
$attempt_list = array(); $attempt_list = array();
if (isset($exe_id)) { if (isset($exe_id)) {
$attempt_list = get_all_exercise_event_by_exe_id($exe_id); $attempt_list = get_all_exercise_event_by_exe_id($exe_id);
} }
if (!empty($attempt_list) && $current_question == 1) { if (!empty($attempt_list) && $current_question == 1) {
//Display::display_normal_message(get_lang('YouTriedToResolveThisExerciseEarlier')); //Display::display_normal_message(get_lang('YouTriedToResolveThisExerciseEarlier'));
} }
$remind_list = array(); $remind_list = array();
if (isset($exercise_stat_info['questions_to_check']) && !empty($exercise_stat_info['questions_to_check'])) { if (isset($exercise_stat_info['questions_to_check']) && !empty($exercise_stat_info['questions_to_check'])) {
$remind_list = explode(',', $exercise_stat_info['questions_to_check']); $remind_list = explode(',', $exercise_stat_info['questions_to_check']);
} }
foreach ($questionList as $questionId) { foreach ($questionList as $questionId) {
// for sequential exercises // for sequential exercises
if ($objExercise->type == ONE_PER_PAGE) { if ($objExercise->type == ONE_PER_PAGE) {
// if it is not the right question, goes to the next loop iteration // if it is not the right question, goes to the next loop iteration
@ -965,13 +965,13 @@ if (!empty($error)) {
} }
} }
} }
$user_choice = $attempt_list[$questionId]; $user_choice = $attempt_list[$questionId];
$remind_highlight = ''; $remind_highlight = '';
$exercise_actions = ''; $exercise_actions = '';
$is_remind_on = false; $is_remind_on = false;
$attributes = array('id' =>'remind_list['.$questionId.']'); $attributes = array('id' =>'remind_list['.$questionId.']');
if (in_array($questionId, $remind_list)) { if (in_array($questionId, $remind_list)) {
$is_remind_on = true; $is_remind_on = true;
@ -979,47 +979,47 @@ if (!empty($error)) {
$remind_question = true; $remind_question = true;
$remind_highlight = ' remind_highlight '; $remind_highlight = ' remind_highlight ';
} }
//Showing the question //Showing the question
echo '<div id="question_div_'.$questionId.'" class="main_question '.$remind_highlight.'" >'; echo '<div id="question_div_'.$questionId.'" class="main_question '.$remind_highlight.'" >';
// shows the question and its answers // shows the question and its answers
showQuestion($questionId, false, $origin, $i, true, false, $user_choice); showQuestion($questionId, false, $origin, $i, true, false, $user_choice);
//BUtton save and continue //BUtton save and continue
switch ($objExercise->type) { switch ($objExercise->type) {
case ONE_PER_PAGE: case ONE_PER_PAGE:
$exercise_actions .= $objExercise->show_button($questionId, $current_question); $exercise_actions .= $objExercise->show_button($questionId, $current_question);
break; break;
case ALL_ON_ONE_PAGE : case ALL_ON_ONE_PAGE :
$button = '<a href="javascript://" class="btn" onclick="save_now(\''.$questionId.'\'); ">'.get_lang('SaveForNow').'</a>'; $button = '<a href="javascript://" class="btn" onclick="save_now(\''.$questionId.'\'); ">'.get_lang('SaveForNow').'</a>';
$button .= '<span id="save_for_now_'.$questionId.'"></span>&nbsp;'; $button .= '<span id="save_for_now_'.$questionId.'"></span>&nbsp;';
$exercise_actions .= Display::div($button, array('class'=>'exercise_save_now_button')); $exercise_actions .= Display::div($button, array('class'=>'exercise_save_now_button'));
break; break;
} }
//Checkbox review answers //Checkbox review answers
if ($objExercise->review_answers) { if ($objExercise->review_answers) {
$remind_question_div = Display::tag('label', Display::input('checkbox', 'remind_list['.$questionId.']', '', $attributes).get_lang('ReviewQuestionLater'), array('class' => 'checkbox', 'for' =>'remind_list['.$questionId.']')); $remind_question_div = Display::tag('label', Display::input('checkbox', 'remind_list['.$questionId.']', '', $attributes).get_lang('ReviewQuestionLater'), array('class' => 'checkbox', 'for' =>'remind_list['.$questionId.']'));
$exercise_actions .= Display::div($remind_question_div, array('class'=>'exercise_save_now_button')); $exercise_actions .= Display::div($remind_question_div, array('class'=>'exercise_save_now_button'));
} }
echo Display::div($exercise_actions, array('class'=>'form-actions')); echo Display::div($exercise_actions, array('class'=>'form-actions'));
echo '</div>'; echo '</div>';
$i++; $i++;
// for sequential exercises // for sequential exercises
if ($objExercise->type == ONE_PER_PAGE) { if ($objExercise->type == ONE_PER_PAGE) {
// quits the loop // quits the loop
break; break;
} }
} }
// end foreach() // end foreach()
if ($objExercise->type == ALL_ON_ONE_PAGE) { if ($objExercise->type == ALL_ON_ONE_PAGE) {
$exercise_actions = $objExercise->show_button($questionId, $current_question); $exercise_actions = $objExercise->show_button($questionId, $current_question);
echo Display::div($exercise_actions, array('class'=>'exercise_actions')); echo Display::div($exercise_actions, array('class'=>'exercise_actions'));
} }
echo '</form>'; echo '</form>';
} }
if ($origin != 'learnpath') { if ($origin != 'learnpath') {

Loading…
Cancel
Save