From f11a32b22aa88274b94328240f8a85de5006347d Mon Sep 17 00:00:00 2001 From: Julio Montoya Date: Fri, 8 Jun 2012 12:26:14 +0200 Subject: [PATCH] Adding start_date, end_date, duration in reports see #4545 --- main/exercice/exercise.lib.php | 3 +- main/exercice/exercise_report.php | 249 +++++++-------- main/exercice/exercise_result.class.php | 267 +++++++++------- main/exercice/exercise_result.php | 16 +- main/exercice/exercise_submit.php | 404 ++++++++++++------------ 5 files changed, 494 insertions(+), 445 deletions(-) diff --git a/main/exercice/exercise.lib.php b/main/exercice/exercise.lib.php index 759aeab49d..2e92527303 100644 --- a/main/exercice/exercise.lib.php +++ b/main/exercice/exercise.lib.php @@ -844,8 +844,7 @@ function get_exam_results_data($from, $number_of_items, $column, $direction, $ex $sqlFromOption = ""; $sqlWhereOption = ""; // for hpsql - $sql_inner_join_tbl_user = ""; - + //@todo fix to work with COURSE_RELATION_TYPE_RRHH in both queries //Hack in order to filter groups diff --git a/main/exercice/exercise_report.php b/main/exercice/exercise_report.php index dba81a9f0e..2a8ed7f5ac 100644 --- a/main/exercice/exercise_report.php +++ b/main/exercice/exercise_report.php @@ -5,9 +5,9 @@ * @package chamilo.exercise * @author Julio Montoya jqgrid integration * Modified by hubert.borderiou (question category) - * + * * @todo fix excel export - * + * */ /** * Code @@ -46,7 +46,7 @@ $documentPath = api_get_path(SYS_COURSE_PATH) . $_course['path'] . "/document"; /* Constants and variables */ $is_allowedToEdit = api_is_allowed_to_edit(null,true); $is_tutor = api_is_allowed_to_edit(true); - + $TBL_QUESTIONS = Database :: get_course_table(TABLE_QUIZ_QUESTION); $TBL_TRACK_EXERCICES = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES); $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 (api_is_platform_admin() || api_is_course_admin() || api_is_course_tutor() || api_is_course_coach()) { - + $load_extra_data = false; - if (isset($_REQUEST['extra_data'])) { - $load_extra_data = true; - } + if (isset($_REQUEST['extra_data']) && $_REQUEST['extra_data'] == 1) { + $load_extra_data = true; + } + require_once 'exercise_result.class.php'; switch ($_GET['export_format']) { case 'xls' : - $export = new ExerciseResult(); + $export = new ExerciseResult(); $export->exportCompleteReportXLS($documentPath, null, $load_extra_data, null, $_GET['exerciseId'], $_GET['hotpotato_name']); exit; 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 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); if (empty($track_exercise_info)) { 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_item_id = $track_exercise_info['orig_lp_item_id']; $lp_item_view_id = $track_exercise_info['orig_lp_item_view_id']; - - // Teacher data - $teacher_info = api_get_user_info(api_get_user_id()); - $user_info = api_get_user_info($student_id); - $student_email = $user_info['mail']; + + // Teacher data + $teacher_info = api_get_user_info(api_get_user_id()); + $user_info = api_get_user_info($student_id); + $student_email = $user_info['mail']; $from = $teacher_info['mail']; $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(); $post_content_id = array(); $comments_exist = false; - + foreach ($_POST as $key_index => $key_value) { $my_post_info = explode('_',$key_index); $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); - + $array_content_id_exe=array(); if ($comments_exist===true) { $array_content_id_exe = array_slice($post_content_id,$loop_in_track); } else { $array_content_id_exe = $post_content_id; } - + for ($i=0;$i<$loop_in_track;$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]]); @@ -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; Database::query($query); - + //Saving results in the track recording table - $recording_changes = 'INSERT INTO '.$TBL_TRACK_ATTEMPT_RECORDING.' (exe_id, question_id, marks, insert_date, author, teacher_comment) + $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.'")'; Database::query($recording_changes); } - + $qry = 'SELECT DISTINCT question_id, marks FROM ' . $TBL_TRACK_ATTEMPT . ' WHERE exe_id = '.$id .' GROUP BY question_id'; $res = Database::query($qry); $tot = 0; while ($row = Database :: fetch_array($res, 'ASSOC')) { $tot += $row['marks']; } - + $totquery = "UPDATE $TBL_TRACK_EXERCICES SET exe_result = '".floatval($tot)."' WHERE exe_id = ".$id; Database::query($totquery); - + //@todo move this somewhere else - $subject = get_lang('ExamSheetVCC'); - + $subject = get_lang('ExamSheetVCC'); + $message = '

'.get_lang('DearStudentEmailIntroduction') . '

'.get_lang('AttemptVCC'); $message .= '

'.get_lang('CourseName'). '

'.Security::remove_XSS($course_info['name']).''; $message .= '

'.get_lang('Exercise') . '

'.Security::remove_XSS($test); - + //Only for exercises not in a LP - if ($lp_id == 0) { + if ($lp_id == 0) { $message .= '

'.get_lang('ClickLinkToViewComment') . ' #url#
'; } - + $message .= '

'.get_lang('Regards').'

'; - $message .= $from_name; - + $message .= $from_name; + $message = str_replace("#test#", Security::remove_XSS($test), $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())); - - //Updating LP score here - if (in_array($origin, array ('tracking_course','user_course','correct_exercise_in_lp'))) { + + //Updating LP score here + 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; Database::query($sql_update_score); if ($origin == 'tracking_course') { //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; } else { //Redirect to the reporting header('location: ../mySpace/myStudents.php?origin=' . $origin . '&student=' . $student_id . '&details=true&course=' . $course_id.'&session_id='.$session_id); exit; - } + } } } if ($is_allowedToEdit && $origin != 'learnpath') { // the form - if (api_is_platform_admin() || api_is_course_admin() || api_is_course_tutor() || api_is_course_coach()) { - $actions .= '' . Display :: return_icon('back.png', get_lang('GoBackToQuestionList'),'',ICON_SIZE_MEDIUM).''; - $actions .=''.Display :: return_icon('activity_monitor.png', get_lang('LiveResults'),'',ICON_SIZE_MEDIUM).''; + if (api_is_platform_admin() || api_is_course_admin() || api_is_course_tutor() || api_is_course_coach()) { + $actions .= '' . Display :: return_icon('back.png', get_lang('GoBackToQuestionList'),'',ICON_SIZE_MEDIUM).''; + $actions .=''.Display :: return_icon('activity_monitor.png', get_lang('LiveResults'),'',ICON_SIZE_MEDIUM).''; $actions .=''.Display :: return_icon('statistics.png', get_lang('ReportByQuestion'),'', ICON_SIZE_MEDIUM).''; $actions .= ''. - Display::return_icon('save.png', get_lang('Export'),'',ICON_SIZE_MEDIUM).''; + Display::return_icon('save.png', get_lang('Export'),'',ICON_SIZE_MEDIUM).''; } } else { $actions .= '' . Display :: return_icon('back.png', get_lang('GoBackToQuestionList'),'',ICON_SIZE_MEDIUM).''; @@ -225,29 +226,29 @@ if ($is_allowedToEdit && $origin != 'learnpath') { //Deleting an attempt if ( ($is_allowedToEdit || $is_tutor || api_is_coach()) && $_GET['delete'] == 'delete' && !empty ($_GET['did']) && $locked == false) { $exe_id = intval($_GET['did']); - if (!empty($exe_id)) { + if (!empty($exe_id)) { $sql = 'DELETE FROM '.$TBL_TRACK_EXERCICES.' WHERE exe_id = '.$exe_id; Database::query($sql); $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); exit; - + } } if ($is_allowedToEdit || $is_tutor) { $nameTools = get_lang('StudentScore'); $interbreadcrumb[] = array("url" => "exercice.php?gradebook=$gradebook","name" => get_lang('Exercices')); - $objExerciseTmp = new Exercise(); + $objExerciseTmp = new Exercise(); if ($objExerciseTmp->read($exercise_id)) { - $interbreadcrumb[] = array("url" => "admin.php?exerciseId=".$exercise_id, "name" => $objExerciseTmp->name); - } -} else { + $interbreadcrumb[] = array("url" => "admin.php?exerciseId=".$exercise_id, "name" => $objExerciseTmp->name); + } +} else { $interbreadcrumb[] = array("url" => "exercice.php?gradebook=$gradebook","name" => get_lang('Exercices')); - $objExerciseTmp = new Exercise(); + $objExerciseTmp = new Exercise(); 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 = ''; @@ -297,7 +298,7 @@ $form->setDefaults(array('export_format' => 'csv')); $extra .= $form->return_form(); $extra .= ''; -if ($is_allowedToEdit) +if ($is_allowedToEdit) echo $extra; 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'; $action_links = ''; -//Generating group list +//Generating group list $group_list = GroupManager::get_group_list(); $group_parameters = array('group_all:'.get_lang('All'),'group_none:'.get_lang('None')); foreach ($group_list as $group) { - $group_parameters[] = $group['id'].':'.$group['name']; + $group_parameters[] = $group['id'].':'.$group['name']; } if (!empty($group_parameters)) { $group_parameters = implode(';', $group_parameters); } if ($is_allowedToEdit || $is_tutor) { - - //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'), + + //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'), get_lang('Group'), get_lang('Duration'), get_lang('StartDate'), get_lang('EndDate'), get_lang('Score'), get_lang('Status'), get_lang('Actions')); //Column config $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'=>'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', //for the bottom bar - 'searchoptions' => array( - 'defaultValue' => 'group_all', + 'searchoptions' => array( + 'defaultValue' => 'group_all', 'value' => $group_parameters), - //for the top bar + //for the top bar 'editoptions' => array('value' => $group_parameters)), - + 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'=>'exe_date', 'index'=>'exe_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'=>'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 - 'searchoptions' => array( - 'defaultValue' => '', + 'searchoptions' => array( + 'defaultValue' => '', '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'))), -//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'=>'60', 'align'=>'left', 'search' => 'false') - ); - + ); + $action_links = ' // add username as title in lastname filed - ref 4226 function action_formatter(cellvalue, options, rowObject) { @@ -373,26 +374,26 @@ if ($is_allowedToEdit || $is_tutor) { return ""+cellvalue+""; }'; } else { - + 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')); - + //Column config - $column_model = array( + $column_model = array( 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'=>'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'=>'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'=>'score', 'index'=>'exe_result', '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'; -//height auto +//height auto $extra_params['height'] = 'auto'; //$extra_params['excel'] = 'excel'; @@ -400,12 +401,12 @@ $extra_params['rowList'] = array(10, 20 ,30); ?>
- - + +
-1 AND - orig_lp_id = 0 AND + te.status != 'incomplete' AND + te.exe_cours_id='" . Database :: escape_string($cid) . "' $user_id_and $session_id_and AND + ce.active <>-1 AND + orig_lp_id = 0 AND orig_lp_item_id = 0"; - - $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 + $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 FROM $TBL_TRACK_HOTPOTATOES tth, $TBL_USER tu - WHERE tu.user_id=tth.exe_user_id AND - tth.exe_cours_id = '" . Database :: escape_string($cid) . "' AND + WHERE tu.user_id=tth.exe_user_id AND + tth.exe_cours_id = '" . Database :: escape_string($cid) . "' AND tth.exe_name = '$hotpotato_name' ORDER BY tth.exe_cours_id ASC, tth.exe_date DESC"; } else { $user_id_and = ' AND te.exe_user_id = ' . api_get_user_id() . ' '; // 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, " . - "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 exduration, ce.results_disabled as exdisabled + $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, + 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) WHERE ce.c_id = $course_id AND - te.status != 'incomplete' AND - te.exe_cours_id='" . Database :: escape_string($cid) . "' $user_id_and $session_id_and AND - ce.active <>-1 AND - orig_lp_id = 0 AND - orig_lp_item_id = 0 + te.status != 'incomplete' AND + te.exe_cours_id='" . Database :: escape_string($cid) . "' $user_id_and $session_id_and AND + ce.active <>-1 AND + orig_lp_id = 0 AND + orig_lp_item_id = 0 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 - WHERE exe_user_id = '" . $user_id . "' AND - exe_cours_id = '" . Database :: escape_string($cid) . "' AND + WHERE exe_user_id = '" . $user_id . "' AND + exe_cours_id = '" . Database :: escape_string($cid) . "' AND tth.exe_name = '$hotpotato_name' ORDER BY exe_cours_id ASC, exe_date DESC"; } - $results = array(); - + $results = array(); + $resx = Database::query($sql); while ($rowx = Database::fetch_array($resx,'ASSOC')) { $results[] = $rowx; } - + $hpresults = array(); $resx = Database::query($hpsql); while ($rowx = Database::fetch_array($resx,'ASSOC')) { $hpresults[] = $rowx; } - + if ($filter) { switch ($filter) { case 1 : @@ -183,53 +197,58 @@ class ExerciseResult if (is_array($results) && empty($hotpotato_name)) { for ($i = 0; $i < sizeof($results); $i++) { $revised = false; - + //revised or not $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); - if (Database :: num_rows($query) > 0) + if (Database :: num_rows($query) > 0) $revised = true; - + if ($filter_by_not_revised && $revised) continue; if ($filter_by_revised && !$revised) continue; $return[$i] = array(); - - if (empty($user_id)) { + + if (empty($user_id)) { $return[$i]['first_name'] = $results[$i]['userpart1']; $return[$i]['last_name'] = $results[$i]['userpart2']; $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]['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]['max'] = $results[$i]['exweight']; $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)) { for($i = 0; $i < sizeof($hpresults); $i++) { - $return[$i] = array(); + $return[$i] = array(); $title = GetQuizName($hpresults[$i]['exe_name'], $document_path); if ($title =='') { $title = basename($hpresults[$i]['exe_name']); } - if(empty($user_id)) { + if(empty($user_id)) { $return[$i]['email'] = $hpresults[$i]['email']; $return[$i]['first_name'] = $hpresults[$i]['userpart1']; $return[$i]['last_name'] = $hpresults[$i]['userpart2']; } $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]['max'] = $hpresults[$i]['exe_weighting']; } - } + } $this->results = $return; return true; } @@ -248,59 +267,56 @@ class ExerciseResult $filename = 'exercise_results_user_'.$user_id.'_'.date('YmdGis').'.csv'; } $data = ''; - + + if (api_is_western_name_order()) { if(!empty($this->results[0]['first_name'])) { $data .= get_lang('FirstName').';'; - } + } if(!empty($this->results[0]['last_name'])) { $data .= get_lang('LastName').';'; - } + } } else { if(!empty($this->results[0]['last_name'])) { $data .= get_lang('LastName').';'; } if(!empty($this->results[0]['first_name'])) { $data .= get_lang('FirstName').';'; - } - } - $data .= get_lang('Email').';'; - + } + } + $data .= get_lang('Email').';'; + if ($export_user_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); - $num = count($extra_user_fields); + $extra_user_fields = UserManager::get_extra_fields(0,1000,5,'ASC',false, 1); + $num = count($extra_user_fields); foreach($extra_user_fields as $field) { $data .= '"'.str_replace("\r\n",' ',api_html_entity_decode(strip_tags($field[3]), ENT_QUOTES, $charset)).'";'; - } + } } - + $data .= get_lang('Title').';'; $data .= get_lang('StartDate').';'; + $data .= get_lang('EndDate').';'; + $data .= get_lang('Duration'). ' ('.get_lang('MinMinutes').') ;'; $data .= get_lang('Score').';'; $data .= get_lang('Total').';'; $data .= get_lang('Status').';'; $data .= "\n"; - + //results foreach($this->results as $row) { - if (api_is_western_name_order()) { - if(!empty($row['first_name'])) { - $data .= str_replace("\r\n",' ',api_html_entity_decode(strip_tags($row['first_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)).';'; - } + + 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['last_name']), ENT_QUOTES, $charset)).';'; } else { - if(!empty($row['last_name'])) { - $data .= str_replace("\r\n",' ',api_html_entity_decode(strip_tags($row['last_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['last_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['email']), ENT_QUOTES, $charset)).';'; - + if ($export_user_fields) { //show user fields data, if any, for this user $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("\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['max']).';'; $data .= str_replace("\r\n",' ',$row['status']).';'; @@ -342,14 +361,12 @@ class ExerciseResult * @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) { - global $charset; + global $charset; $this->_getExercisesReporting($document_path, $user_id, $export_filter, $exercise_id, $hotpotato_name); $filename = 'exercise_results_'.date('YmdGis').'.xls'; - if(!empty($user_id)) { + if (!empty($user_id)) { $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->setTempDir(api_get_path(SYS_ARCHIVE_PATH)); $workbook->setVersion(8); // BIFF8 @@ -369,68 +386,88 @@ class ExerciseResult } } + + if ($with_column_user) { - + $worksheet->write($line,$column,get_lang('Email')); $column++; - - if (api_is_western_name_order()) { + + if (api_is_western_name_order()) { $worksheet->write($line,$column,get_lang('FirstName')); - $column++; + $column++; $worksheet->write($line,$column,get_lang('LastName')); $column++; } else { $worksheet->write($line,$column,get_lang('LastName')); - $column++; + $column++; $worksheet->write($line,$column,get_lang('FirstName')); - $column++; + $column++; } } if ($export_user_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); - + //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)); $column++; } } - - $worksheet->write($line,$column,get_lang('Title')); + + $worksheet->write($line,$column, get_lang('Title')); $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++; - $worksheet->write($line,$column,get_lang('Score')); + $worksheet->write($line,$column, get_lang('Score')); $column++; - $worksheet->write($line,$column,get_lang('Total')); + $worksheet->write($line,$column, get_lang('Total')); $column++; - $worksheet->write($line,$column,get_lang('Status')); + $worksheet->write($line,$column, get_lang('Status')); $line++; - foreach($this->results as $row) { + foreach ($this->results as $row) { $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)); - $column++; - $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 ($with_column_user) { + $worksheet->write($line,$column,api_html_entity_decode(strip_tags($row['email']), ENT_QUOTES, $charset)); + $column++; + + if (api_is_western_name_order()) { + $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 - $user_fields_values = UserManager::get_extra_user_data($row['user_id'],false,false, false, true); - foreach($user_fields_values as $value) { + $user_fields_values = UserManager::get_extra_user_data($row['user_id'],false,false, false, true); + foreach($user_fields_values as $value) { $worksheet->write($line,$column, api_html_entity_decode(strip_tags($value), ENT_QUOTES, $charset)); $column++; } } + $worksheet->write($line,$column,api_html_entity_decode(strip_tags($row['title']), ENT_QUOTES, $charset)); $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++; $worksheet->write($line,$column,$row['result']); $column++; @@ -444,4 +481,4 @@ class ExerciseResult return true; } } -endif; +endif; \ No newline at end of file diff --git a/main/exercice/exercise_result.php b/main/exercice/exercise_result.php index e52ea005cd..7117c8f894 100644 --- a/main/exercice/exercise_result.php +++ b/main/exercice/exercise_result.php @@ -212,10 +212,22 @@ if ($origin != 'learnpath') { // 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()) { - 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 diff --git a/main/exercice/exercise_submit.php b/main/exercice/exercise_submit.php index c7f37e5d9a..4ec01e4097 100644 --- a/main/exercice/exercise_submit.php +++ b/main/exercice/exercise_submit.php @@ -17,9 +17,9 @@ * the administrator * @package chamilo.exercise * @author Olivier Brouckaert -* @author Julio Montoya -* Fill in blank option added (2008) -* Cleaning exercises (2010), +* @author Julio Montoya +* Fill in blank option added (2008) +* Cleaning exercises (2010), * Adding hotspot delineation support (2011) * Adding reminder + ajax support (2011) * 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 -if (!isset($_SESSION['objExercise']) || $_SESSION['objExercise']->id != $_REQUEST['exerciseId']) { +if (!isset($_SESSION['objExercise']) || $_SESSION['objExercise']->id != $_REQUEST['exerciseId']) { // Construction of Exercise - $objExercise = new Exercise(); + $objExercise = new Exercise(); if ($debug) {error_log('1. Setting the $objExercise variable'); }; unset($_SESSION['questionList']); @@ -119,14 +119,14 @@ if (!isset($_SESSION['objExercise']) || $_SESSION['objExercise']->id != $_REQUES } else { // Saves the object into the session 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 if (!isset($objExercise) && isset($_SESSION['objExercise'])) { - if ($debug) { error_log('2. Loading $objExercise from session'); }; - $objExercise = $_SESSION['objExercise']; + if ($debug) { error_log('2. Loading $objExercise from session'); }; + $objExercise = $_SESSION['objExercise']; } //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) { //Get the expired time of the current exercice in track_e_exercices $total_seconds = $objExercise->expired_time*60; - + //Generating the time control key for the user $current_expired_time_key = generate_time_control_key($objExercise->id); } @@ -205,14 +205,14 @@ if ($objExercise->selectAttempts() > 0) { } else { $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); - } - + } + if ($origin == 'learnpath') { - Display :: display_reduced_header(); + Display :: display_reduced_header(); } else { - Display :: display_header($nameTools,'Exercises'); + Display :: display_header($nameTools,'Exercises'); } - + echo $attempt_html; if ($origin != 'learnpath') 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 ($debug) error_log('5 $exercise_stat_info is empty '); $total_weight = 0; - $questionList = $objExercise->get_validated_question_list(); + $questionList = $objExercise->get_validated_question_list(); foreach ($questionList as $question_id) { $objQuestionTmp = Question::read($question_id); $total_weight += floatval($objQuestionTmp->weighting); } $clock_expired_time = ''; - + if ($time_control) { $expected_time = $current_timestamp + $total_seconds; - + if ($debug) error_log('5.1. $current_timestamp '.$current_timestamp); if ($debug) error_log('5.2. $expected_time '.$expected_time); - + $clock_expired_time = api_get_utc_datetime($expected_time); if ($debug) error_log('5.3. $expected_time '.$clock_expired_time); - + //Sessions that contain the 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] ); }; } $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"); } else { $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; 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 "); }; header('Location: exercise_reminder.php?'.$params); exit; @@ -282,46 +282,46 @@ if ($reminder == 2 && empty($my_remind_list)) { */ 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.3. $_SESSION[expired_time][$current_expired_time_key] '.$_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 ($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']; - 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 $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)) { $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); - } else { + $last_attempt_date = api_get_utc_datetime(api_strtotime($exercise_stat_info['start_date'],'UTC') + $diff); + } else { //Recalculate the time control due #2069 $diff = $current_timestamp - api_strtotime($last_attempt_date,'UTC'); $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); } - + //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'); - 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; if ($debug) {error_log('7.8. $expected_time1: '.$expected_time); } - + $clock_expired_time = api_get_utc_datetime($expected_time); if ($debug) {error_log('7.9. $clock_expired_time: '.$clock_expired_time); } - + // 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 $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); } Database::query($sql_track_e_exe); - + //Sessions that contain the 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] ); }; @@ -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 * 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); } @@ -353,24 +353,24 @@ $exercise_sound = $objExercise->selectSound(); //if (!isset($_SESSION['questionList']) || $origin == 'learnpath') { //in LP's is enabled the "remember question" feature? -if (!isset($_SESSION['questionList'])) { - // selects the list of question ID - $questionList = $objExercise->get_validated_question_list(); +if (!isset($_SESSION['questionList'])) { + // selects the list of question ID + $questionList = $objExercise->get_validated_question_list(); if ($objExercise->isRandom() && !empty($exercise_stat_info['data_tracking'])) { - $questionList = explode(',', $exercise_stat_info['data_tracking']); - } - Session::write('questionList',$questionList); + $questionList = explode(',', $exercise_stat_info['data_tracking']); + } + Session::write('questionList',$questionList); if ($debug > 0) { error_log('$_SESSION[questionList] was set'); } } else { - if (isset($objExercise) && isset($_SESSION['objExercise'])) { + if (isset($objExercise) && isset($_SESSION['objExercise'])) { $questionList = $_SESSION['questionList']; } } if ($debug) error_log('8. Question list loaded '.print_r($questionList, 1)); -$quizStartTime = time(); -Session::write('quizStartTime',$quizStartTime); +$quizStartTime = array( $exerciseId => api_get_utc_datetime()); +Session::write('quizStartTime', $quizStartTime); //Real question count $question_count = 0; @@ -385,28 +385,28 @@ if ($formSent && isset($_POST)) { if (!is_array($exerciseResult)) { $exerciseResult = array(); $exerciseResultCoordinates = array(); - } + } //Only for hotspot if (!isset($choice) && isset($_REQUEST['hidden_hotspot_id'])) { $hotspot_id = (int)($_REQUEST['hidden_hotspot_id']); $choice = array($hotspot_id => ''); } - + // if the user has answered at least one question 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 // will be stored in the session at the end of this script) if (isset($_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) { // $exerciseResult receives the content of the form. // Each choice of the student is stored into the array $choice - $exerciseResult = $choice; + $exerciseResult = $choice; } else { // gets the question ID from $choice. It is the key of the array list ($key) = array_keys($choice); @@ -417,9 +417,9 @@ if ($formSent && isset($_POST)) { //saving each question if ($objExercise->feedback_type != EXERCISE_FEEDBACK_TYPE_DIRECT) { $nro_question = $current_question; // - 1; - $questionId = $key; + $questionId = $key; // gets the student choice for this question - $choice = $exerciseResult[$questionId]; + $choice = $exerciseResult[$questionId]; if (isset($exe_id)) { //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)); } @@ -432,35 +432,35 @@ if ($formSent && isset($_POST)) { if ($debug) { error_log('9.3. $choice is an array - end'); } if ($debug) { error_log('9.4. $exerciseResult '.print_r($exerciseResult,1)); } } - - + + // the script "exercise_result.php" will take the variable $exerciseResult from the session Session::write('exerciseResult',$exerciseResult); - Session::write('remind_list',$remind_list); + Session::write('remind_list',$remind_list); 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 (($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()) { // goes to the script that will show the result of the exercise if ($objExercise->type == ALL_ON_ONE_PAGE) { 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) { - $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()) { - 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') { //so we are not in learnpath tool echo ''; //End glossary div Display :: display_footer(); } else { echo ''; - } + } } - } + } 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; } else { @@ -468,28 +468,28 @@ if ($formSent && isset($_POST)) { if (!empty($exe_id) && is_numeric($exe_id)) { //Verify if the current test is fraudulent if (exercise_time_control_is_valid($exerciseId)) { - $sql_exe_result = ""; + $sql_exe_result = ""; if ($debug) { error_log('exercise_time_control_is_valid is valid'); } } else { $sql_exe_result = ", 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; - - if ($debug) { error_log('Updating track_e_exercises '.$update_query); } + + if ($debug) { error_log('Updating track_e_exercises '.$update_query); } Database::query($update_query);*/ - } + } 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_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; - } + } } else { if ($debug) { error_log('10. Redirecting to exercise_submit.php'); } header("Location: exercise_submit.php?exerciseId=$exerciseId&origin=$origin"); - exit; + exit; } } if ($debug) { error_log('11. $formSent was set - end'); } @@ -508,62 +508,62 @@ if (!$current_question || $_REQUEST['num']) { } 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()) { // goes to the script that will show the result of the exercise if ($objExercise->type == ALL_ON_ONE_PAGE) { 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 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()) { - 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') { //so we are not in learnpath tool echo ''; //End glossary div - Display :: display_footer(); + Display :: display_footer(); } else { echo ''; } 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"); //exit; } 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)) { //Verify if the current test is fraudulent $check = exercise_time_control_is_valid($exerciseId); - + if ($check) { - $sql_exe_result = ""; + $sql_exe_result = ""; if ($debug) { error_log('12. exercise_time_control_is_valid is valid'); } } else { $sql_exe_result = ", 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; - - //if ($debug) { error_log('Updating track_e_exercises '.$update_query); } + + //if ($debug) { error_log('Updating track_e_exercises '.$update_query); } Database::query($update_query);*/ - } - if ($objExercise->review_answers) { + } + if ($objExercise->review_answers) { header('Location: exercise_reminder.php?'.$params); exit; } 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 { if ($debug) { error_log('Redirecting to exercise_submit.php'); } //header("Location: exercise_submit.php?exerciseId=$exerciseId"); - exit; + exit; } } } else { @@ -589,7 +589,7 @@ if (!empty ($gradebook) && $gradebook == 'view') { $interbreadcrumb[] = array ("url" => "exercice.php?gradebook=$gradebook", "name" => get_lang('Exercices')); $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'); if (!api_is_allowed_to_session_edit() ) { 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); if ($is_visible_return['value'] == false) { - echo $is_visible_return['message']; + echo $is_visible_return['message']; if ($origin != 'learnpath') { 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; -if ($limit_time_exists) { +if ($limit_time_exists) { $exercise_start_time = api_strtotime($objExercise->start_time, 'UTC'); $exercise_end_time = api_strtotime($objExercise->end_time, 'UTC'); $time_now = time(); - + if ($objExercise->start_time != '0000-00-00 00:00:00') { $permission_to_start = (($time_now - $exercise_start_time) > 0) ? true : false; } else { @@ -640,11 +640,11 @@ if ($limit_time_exists) { $exercise_timeover = (($time_now - $exercise_end_time) > 0) ? true : false; } else { $exercise_timeover = false; - } + } } - + 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'); Display :: display_warning_message(sprintf($message_warning, $exercise_title, $objExercise->selectAttempts())); if ($origin != 'learnpath') { @@ -682,32 +682,32 @@ if ($origin != 'learnpath') { if ($reminder == 2) { if ($debug) { error_log('. $reminder == 2'); } - + $data_tracking = $exercise_stat_info['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)) { - //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($j = 0; $j < count($my_remind_list); $j++) { - + for($j = 0; $j < count($my_remind_list); $j++) { + if (!empty($remind_question_id)) { if ($remind_question_id == $my_remind_list[$j]) { - + 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]; $current_question = $i + 1; - } else { - $remind_question_id = -1; //We end the remind list we go to the exercise_reminder.php please + } else { + $remind_question_id = -1; //We end the remind list we go to the exercise_reminder.php please $current_question = $i + 1; // last question - } - break 2; - } + } + break 2; + } } - } else { + } else { if ($my_remind_list[$j] == $data_tracking[$i]) { if (isset($my_remind_list[$j+1])) { $remind_question_id = $my_remind_list[$j+1]; @@ -715,11 +715,11 @@ if ($reminder == 2) { } else { $remind_question_id = -1; //We end the remind list we go to the exercise_reminder.php please $current_question = $i + 1; // last question - } + } break 2; } } - } + } } } else { 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 ($current_question != $i) { continue; - } else { + } else { if ($objQuestionTmp->selectType() == HOT_SPOT || $objQuestionTmp->selectType() == HOT_SPOT_DELINEATION) { $number_of_hotspot_questions++; } @@ -771,15 +771,15 @@ if (!empty($error)) { } } } - + if ($number_of_hotspot_questions > 0) { $onsubmit = "onsubmit=\"return validateFlashVar('" . $number_of_hotspot_questions . "', '" . get_lang('HotspotValidateError1') . "', '" . get_lang('HotspotValidateError2') . "');\""; } - + echo ''; + } + '; echo '
@@ -922,27 +922,27 @@ if (!empty($error)) { '; - + //Show list of questions $i = 1; - + $attempt_list = array(); - - if (isset($exe_id)) { + + if (isset($exe_id)) { $attempt_list = get_all_exercise_event_by_exe_id($exe_id); } - + if (!empty($attempt_list) && $current_question == 1) { //Display::display_normal_message(get_lang('YouTriedToResolveThisExerciseEarlier')); } - + $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']); - } - + } + foreach ($questionList as $questionId) { - + // for sequential exercises if ($objExercise->type == ONE_PER_PAGE) { // 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 = ''; $exercise_actions = ''; $is_remind_on = false; - + $attributes = array('id' =>'remind_list['.$questionId.']'); if (in_array($questionId, $remind_list)) { $is_remind_on = true; @@ -979,47 +979,47 @@ if (!empty($error)) { $remind_question = true; $remind_highlight = ' remind_highlight '; } - + //Showing the question - - echo '
'; - + + echo '
'; + // shows the question and its answers showQuestion($questionId, false, $origin, $i, true, false, $user_choice); - + //BUtton save and continue switch ($objExercise->type) { - case ONE_PER_PAGE: + case ONE_PER_PAGE: $exercise_actions .= $objExercise->show_button($questionId, $current_question); break; case ALL_ON_ONE_PAGE : $button = ''.get_lang('SaveForNow').''; $button .= ' '; - $exercise_actions .= Display::div($button, array('class'=>'exercise_save_now_button')); + $exercise_actions .= Display::div($button, array('class'=>'exercise_save_now_button')); break; } - + //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.']')); - $exercise_actions .= Display::div($remind_question_div, array('class'=>'exercise_save_now_button')); - } - - echo Display::div($exercise_actions, array('class'=>'form-actions')); - echo '
'; - + $exercise_actions .= Display::div($remind_question_div, array('class'=>'exercise_save_now_button')); + } + + echo Display::div($exercise_actions, array('class'=>'form-actions')); + echo '
'; + $i++; // for sequential exercises if ($objExercise->type == ONE_PER_PAGE) { // quits the loop break; } - } + } // end foreach() if ($objExercise->type == ALL_ON_ONE_PAGE) { $exercise_actions = $objExercise->show_button($questionId, $current_question); echo Display::div($exercise_actions, array('class'=>'exercise_actions')); - } + } echo '
'; } if ($origin != 'learnpath') {