, lots of cleanup + several improvements */ // name of the language file that needs to be included $language_file = array('exercice','tracking'); // including the global library require_once '../inc/global.inc.php'; require_once api_get_path(LIBRARY_PATH).'sortabletable.class.php'; require_once '../gradebook/lib/be.inc.php'; // Setting the tabs $this_section = SECTION_COURSES; // Access control api_protect_course_script(true); $show = (isset ($_GET['show']) && $_GET['show'] == 'result') ? 'result' : 'test'; // moved down to fix bug: http://www.dokeos.com/forum/viewtopic.php?p=18609#18609 // including additional libraries require_once 'exercise.class.php'; require_once 'exercise.lib.php'; require_once 'question.class.php'; require_once 'answer.class.php'; require_once api_get_path(LIBRARY_PATH) . 'fileManage.lib.php'; require_once api_get_path(LIBRARY_PATH) . 'fileUpload.lib.php'; require_once 'hotpotatoes.lib.php'; require_once api_get_path(LIBRARY_PATH) . 'document.lib.php'; require_once api_get_path(LIBRARY_PATH) . 'mail.lib.inc.php'; require_once api_get_path(LIBRARY_PATH) . 'usermanager.lib.php'; /* Constants and variables */ $is_allowedToEdit = api_is_allowed_to_edit(null,true); $is_tutor = api_is_allowed_to_edit(true); $is_tutor_course = api_is_course_tutor(); $tbl_course_rel_user = Database :: get_main_table(TABLE_MAIN_COURSE_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_EXERCICE_ANSWER = Database :: get_course_table(TABLE_QUIZ_ANSWER); $TBL_EXERCICE_QUESTION = Database :: get_course_table(TABLE_QUIZ_TEST_QUESTION); $TBL_EXERCICES = Database :: get_course_table(TABLE_QUIZ_TEST); $TBL_QUESTIONS = Database :: get_course_table(TABLE_QUIZ_QUESTION); $TBL_TRACK_EXERCICES = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES); $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_LP_ITEM_VIEW = Database :: get_course_table(TABLE_LP_ITEM_VIEW); $TBL_LP_ITEM = Database :: get_course_table(TABLE_LP_ITEM); $TBL_LP_VIEW = Database :: get_course_table(TABLE_LP_VIEW); // document path $documentPath = api_get_path(SYS_COURSE_PATH) . $_course['path'] . "/document"; // picture path $picturePath = $documentPath . '/images'; // audio path $audioPath = $documentPath . '/audio'; // hotpotatoes $uploadPath = DIR_HOTPOTATOES; //defined in main_api $exercicePath = api_get_self(); $exfile = explode('/', $exercicePath); $exfile = strtolower($exfile[sizeof($exfile) - 1]); $exercicePath = substr($exercicePath, 0, strpos($exercicePath, $exfile)); $exercicePath = $exercicePath . "exercice.php"; if ($show == 'result') { if (empty($_GET['exerciseId']) && empty($_GET['path']) ) { //header('Location: exercice.php?' . api_get_cidreq()); } } // maximum number of exercises on a same page $limitExPage = 50; // Clear the exercise session if (isset ($_SESSION['objExercise'])) { api_session_unregister('objExercise'); } if (isset ($_SESSION['objQuestion'])) { api_session_unregister('objQuestion'); } if (isset ($_SESSION['objAnswer'])) { api_session_unregister('objAnswer'); } if (isset ($_SESSION['questionList'])) { api_session_unregister('questionList'); } if (isset ($_SESSION['exerciseResult'])) { api_session_unregister('exerciseResult'); } //General POST/GET/SESSION/COOKIES parameters recovery if (empty ($origin)) { $origin = Security::remove_XSS($_REQUEST['origin']); } if (empty ($choice)) { $choice = $_REQUEST['choice']; } if (empty ($hpchoice)) { $hpchoice = $_REQUEST['hpchoice']; } if (empty ($exerciseId)) { $exerciseId = intval($_REQUEST['exerciseId']); } if (empty ($file)) { $file = Database :: escape_string($_REQUEST['file']); } $learnpath_id = intval($_REQUEST['learnpath_id']); $learnpath_item_id = intval($_REQUEST['learnpath_item_id']); $page = intval($_REQUEST['page']); if ($origin == 'learnpath') { $show = 'result'; } //Deleting an attempt if ($_GET['delete'] == 'delete' && ($is_allowedToEdit || api_is_coach()) && !empty ($_GET['did']) && $_GET['did'] == strval(intval($_GET['did']))) { $sql = 'DELETE FROM ' . Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES) . ' WHERE exe_id = ' . $_GET['did']; //_GET[did] filtered by entry condition Database::query($sql); $filter=Security::remove_XSS($_GET['filter']); header('Location: exercice.php?cidReq=' . Security::remove_XSS($_GET['cidReq']) . '&show=result&filter=' . $filter . '&exerciseId='.$exerciseId); exit; } //Send student email @todo move this code in a class, library if ($show == 'result' && $_REQUEST['comments'] == 'update' && ($is_allowedToEdit || $is_tutor) && $_GET['exeid']== strval(intval($_GET['exeid']))) { $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(); } $test = $track_exercise_info['title']; $student_id = $track_exercise_info['exe_user_id']; $course_id = $track_exercise_info['exe_cours_id']; $session_id = $track_exercise_info['session_id']; $lp_id = $track_exercise_info['orig_lp_id']; $lp_item_id = $track_exercise_info['orig_lp_item_id']; $lp_item_view_id = $track_exercise_info['orig_lp_item_view_id']; $user_info = api_get_user_info($student_id); $student_email = $user_info['mail']; //Teacher data? $from = $_SESSION['_user']['mail']; $from_name = api_get_person_name($_SESSION['_user']['firstName'], $_SESSION['_user']['lastName'], null, PERSON_NAME_EMAIL_ADDRESS); $url = api_get_path(WEB_CODE_PATH) . 'exercice/exercice.php?' . api_get_cidreq() . '&show=result'; $total_weighting = $_REQUEST['totalWeighting']; $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]; if ($my_post_info[0]=='comments') { $comments_exist=true; } } $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]]); if (isset($contain_comments)) { $my_comments = Database::escape_string($_POST['comments_'.$array_content_id_exe[$i]]); } else { $my_comments = ''; } $my_questionid=$array_content_id_exe[$i]; $sql = "SELECT question from $TBL_QUESTIONS WHERE id = '$my_questionid'"; $result =Database::query($sql); $ques_name = Database::result($result,0,"question"); $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); //Not necessary to update the weight /* $qry = 'SELECT sum(marks) as tot FROM '.$TBL_TRACK_ATTEMPT.' WHERE exe_id = '.$id; $res = Database::query($qry); $tot = Database::result($res,0,'tot'); //updating also the total weight $totquery = "UPDATE $TBL_TRACK_EXERCICES SET exe_result = '".intval($tot)."', exe_weighting = '".Database::escape_string($total_weighting)."' WHERE exe_Id='".$id."'"; Database::query($totquery); */ //Saving results in the track recording table $recording_changes = 'INSERT INTO '.$TBL_TRACK_ATTEMPT_RECORDING.' (exe_id, question_id, marks, insert_date, author, teacher_comment) VALUES ('."'$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); $subject = get_lang('ExamSheetVCC'); $htmlmessage = '' . '
' . '' . '' . '' . '' . get_lang('DearStudentEmailIntroduction') . '
' . '' . get_lang('AttemptVCC') . '
' . '' . get_lang('Question') . ' | ' . '#ques_name# | ' . '
' . get_lang('Exercice') . ' | ' . '#test# | ' . '
' . get_lang('ClickLinkToViewComment') . ' #url#
' .
'
' .
' ' . get_lang('Regards') . '
' . sprintf(get_lang('AttemptVCCLong'), Security::remove_XSS($test)) . ' #url#