Cleaning exercise files, adding UTC support

skala
Julio Montoya 14 years ago
parent 6cd582b541
commit 849efb08dc
  1. 38
      main/exercice/admin.php
  2. 222
      main/exercice/exercice.php
  3. 10
      main/exercice/exercice_history.php
  4. 1270
      main/exercice/exercice_submit.php
  5. 998
      main/exercice/exercise.class.php
  6. 75
      main/exercice/exercise.lib.php
  7. 10
      main/exercice/exercise_admin.php
  8. 197
      main/exercice/exercise_result.php
  9. 199
      main/exercice/exercise_show.php
  10. 320
      main/inc/lib/events.lib.inc.php
  11. 11
      main/inc/lib/main_api.lib.php

@ -71,24 +71,16 @@ define(ALLOWED_TO_INCLUDE,1);
require_once api_get_path(LIBRARY_PATH).'fileUpload.lib.php';
require_once api_get_path(LIBRARY_PATH).'document.lib.php';
/****************************/
/* stripslashes POST data */
/****************************/
if($_SERVER['REQUEST_METHOD'] == 'POST') {
foreach($_POST as $key=>$val) {
if(is_string($val))
{
if(is_string($val)) {
$_POST[$key]=stripslashes($val);
}
elseif(is_array($val))
{
foreach($val as $key2=>$val2)
{
} elseif(is_array($val)) {
foreach($val as $key2=>$val2) {
$_POST[$key][$key2]=stripslashes($val2);
}
}
$GLOBALS[$key]=$_POST[$key];
}
}
@ -180,8 +172,7 @@ if(!is_object($objExercise)) {
$objExercise=new Exercise();
// creation of a new exercise if wrong or not specified exercise ID
if($exerciseId)
{
if($exerciseId) {
$objExercise->read($exerciseId);
}
@ -200,14 +191,11 @@ if(!$fromExercise) {
$nbrQuestions=$objExercise->selectNbrQuestions();
// intializes the Question object
if($editQuestion || $newQuestion || $modifyQuestion || $modifyAnswers)
{
if($editQuestion || $newQuestion)
{
if($editQuestion || $newQuestion || $modifyQuestion || $modifyAnswers) {
if($editQuestion || $newQuestion) {
// reads question data
if($editQuestion)
{
if($editQuestion) {
// question not found
if(!$objQuestion = Question::read($editQuestion))
{
@ -434,10 +422,8 @@ echo Display::return_icon('preview.gif', get_lang('Preview')).'<a href="exercice
echo Display::return_icon('edit.gif', get_lang('ModifyExercise')).'<a href="exercise_admin.php?'.api_get_cidreq().'&modifyExercise=yes&exerciseId='.$objExercise->id.'">'.get_lang('ModifyExercise').'</a>';
echo '</div>';
if(isset($_GET['message']))
{
if (in_array($_GET['message'], array('ExerciseStored')))
{
if(isset($_GET['message'])) {
if (in_array($_GET['message'], array('ExerciseStored'))) {
Display::display_confirmation_message(get_lang($_GET['message']));
}
}
@ -460,10 +446,10 @@ if($newQuestion || $editQuestion) {
}
if(isset($_GET['hotspotadmin'])) {
include('hotspot_admin.inc.php');
require 'hotspot_admin.inc.php';
}
if(!$newQuestion && !$modifyQuestion && !$editQuestion && !isset($_GET['hotspotadmin'])) {
include_once(api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php');
require_once api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php';
$form = new FormValidator('exercise_admin', 'post', api_get_self().'?exerciseId='.$_GET['exerciseId']);
$form -> addElement ('hidden','edit','true');
//$objExercise -> createForm ($form,'simple');
@ -479,7 +465,7 @@ if(!$newQuestion && !$modifyQuestion && !$editQuestion && !isset($_GET['hotspota
$form -> display ();
echo '<br />';
// question list management
include('question_list_admin.inc.php');
require 'question_list_admin.inc.php';
}
api_session_register('objExercise');

@ -1,6 +1,5 @@
<?php
/* For licensing terms, see /license.txt */
/**
* Exercise list: This script shows the list of exercises for administrators and students.
* @package chamilo.exercise
@ -28,6 +27,7 @@ $show = (isset ($_GET['show']) && $_GET['show'] == 'result') ? 'result' : 'test'
// 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';
@ -111,8 +111,8 @@ if (empty ($exerciseId)) {
if (empty ($file)) {
$file = Database :: escape_string($_REQUEST['file']);
}
$learnpath_id = Database :: escape_string(Security::remove_XSS($_REQUEST['learnpath_id']));
$learnpath_item_id = Database :: escape_string(Security::remove_XSS($_REQUEST['learnpath_item_id']));
$learnpath_id = intval($_REQUEST['learnpath_id']);
$learnpath_item_id = intval($_REQUEST['learnpath_item_id']);
$page = Database :: escape_string($_REQUEST['page']);
if ($origin == 'learnpath') {
@ -129,12 +129,16 @@ if ($_GET['delete'] == 'delete' && ($is_allowedToEdit || api_is_coach()) && !emp
if ($show == 'result' && $_REQUEST['comments'] == 'update' && ($is_allowedToEdit || $is_tutor) && $_GET['exeid']== strval(intval($_GET['exeid']))) {
$id = intval($_GET['exeid']); //filtered by post-condition
$emailid = $_GET['emailid'];
$test = $_GET['test'];
$track_exercise_info = get_exercise_track_exercise_info($id);
$test = $track_exercise_info['title'];
$my_user_id = $track_exercise_info['exe_user_id'];
$user_info = api_get_user_info($my_user_id);
$emailid = $user_info['mail'];
$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';
$TBL_RECORDING = Database :: get_statistic_table('track_e_attempt_recording');
$url = api_get_path(WEB_CODE_PATH) . 'exercice/exercice.php?' . api_get_cidreq() . '&show=result';
$total_weighting = $_REQUEST['totalWeighting'];
$my_post_info=array();
@ -155,18 +159,14 @@ if ($show == 'result' && $_REQUEST['comments'] == 'update' && ($is_allowedToEdit
} 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]]);
$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]]);
$my_comments = Database::escape_string($_POST['comments_'.$array_content_id_exe[$i]]);
} else {
$my_comments='';
$my_comments = '';
}
$my_questionid=$array_content_id_exe[$i];
$sql = "SELECT question from $TBL_QUESTIONS WHERE id = '$my_questionid'";
@ -174,14 +174,11 @@ if ($show == 'result' && $_REQUEST['comments'] == 'update' && ($is_allowedToEdit
$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."'";
WHERE question_id = '".$my_questionid."' AND exe_id='".$id."'";
Database::query($query);
$qry = 'SELECT sum(marks) as tot
FROM '.$TBL_TRACK_ATTEMPT.' WHERE exe_id = '.$id.'
GROUP BY question_id';
$qry = 'SELECT sum(marks) as tot FROM '.$TBL_TRACK_ATTEMPT.' WHERE exe_id = '.$id.' GROUP BY question_id';
$res = Database::query($qry);
$tot = Database::result($res,0,'tot');
@ -189,15 +186,9 @@ if ($show == 'result' && $_REQUEST['comments'] == 'update' && ($is_allowedToEdit
$totquery = "UPDATE $TBL_TRACK_EXERCICES SET exe_result = '".Database::escape_string($tot)."', exe_weighting = '".Database::escape_string($total_weighting)."'
WHERE exe_Id='".$id."'";
Database::query($totquery);
$recording_changes = 'INSERT INTO '.$TBL_RECORDING.' ' .
'(exe_id,
question_id,
marks,
insert_date,
author,
teacher_comment)
VALUES
('."'$id','".$my_questionid."','$my_marks','".date('Y-m-d H:i:s')."','".api_get_user_id()."'".',"'.$my_comments.'")';
//@todo Why we insert this?
$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);
}
@ -648,14 +639,11 @@ if ($is_allowedToEdit) {
break;
}
}
if ($show == 'test') {
$sql = "SELECT id,title,type,active,description, results_disabled FROM $TBL_EXERCICES WHERE active<>'-1' ORDER BY title LIMIT " . (int) $from . "," . (int) ($limitExPage +1);
$result = Database::query($sql);
}
}
elseif ($show == 'test') { // only for students //fin
} elseif ($show == 'test') { // only for students
$sql = "SELECT id,title,type,description, results_disabled FROM $TBL_EXERCICES WHERE active='1' ORDER BY title LIMIT " . (int) $from . "," . (int) ($limitExPage +1);
$result = Database::query($sql);
}
@ -677,23 +665,19 @@ $condition_session = api_get_session_condition($session_id,true,true);
// only for administrator
if ($is_allowedToEdit) {
if ($show == 'test') {
$sql = "SELECT id, title, type, active, description, results_disabled, session_id, start_time FROM $TBL_EXERCICES WHERE active<>'-1' $condition_session ORDER BY title LIMIT " . (int) $from . "," . (int) ($limitExPage +1);
$sql = "SELECT id, title, type, active, description, results_disabled, session_id, start_time, end_time FROM $TBL_EXERCICES WHERE active<>'-1' $condition_session ORDER BY title LIMIT " . (int) $from . "," . (int) ($limitExPage +1);
$result = Database::query($sql);
}
}
elseif ($show == 'test') { // only for students
$sql = "SELECT id, title, type, description, results_disabled, session_id, start_time FROM $TBL_EXERCICES WHERE active='1' $condition_session ORDER BY title LIMIT " . (int) $from . "," . (int) ($limitExPage +1);
} elseif ($show == 'test') { // only for students
$sql = "SELECT id, title, type, description, results_disabled, session_id, start_time, end_time FROM $TBL_EXERCICES WHERE active='1' $condition_session ORDER BY title LIMIT " . (int) $from . "," . (int) ($limitExPage +1);
$result = Database::query($sql);
}
if ($show == 'test') {
if ($show == 'test') {
$nbrExercises = Database :: num_rows($result);
//get HotPotatoes files (active and inactive)
$res = Database::query("SELECT *
FROM $TBL_DOCUMENT
WHERE
path LIKE '" . Database :: escape_string($uploadPath) . "/%/%'");
$nbrTests = Database :: num_rows($res);
$res = Database::query("SELECT * FROM $TBL_DOCUMENT WHERE path LIKE '" . Database :: escape_string($uploadPath) . "/%/%'");
$nbrTests = Database :: num_rows($res);
$res = Database::query("SELECT *
FROM $TBL_DOCUMENT d, $TBL_ITEM_PROPERTY ip
WHERE d.id = ip.ref
@ -821,11 +805,11 @@ if ($show == 'test') {
} else {
//student only
?> <tr>
<th colspan="2"><?php echo get_lang('ExerciseName');?></th>
<th colspan="2"><?php echo get_lang('ExerciseName');?></th>
<th><?php echo get_lang('QuantityQuestions');?></th>
<th><?php echo get_lang('State');?></th>
</tr>
<?php
<?php
}
// show message if no HP test to show
if (!($nbrExercises + $nbrHpTests)) {
@ -847,16 +831,28 @@ if ($show == 'test') {
$mylpitemid = (empty ($learnpath_item_id) ? '' : '&learnpath_item_id=' . $learnpath_item_id);
$token = Security::get_token();
while ($row = Database :: fetch_array($result)) {
while ($row = Database :: fetch_array($result)) {
//validacion when belongs to a session
$session_img = api_get_session_image($row['session_id'], $_user['status']);
// check if start time
$is_actived_time = true;
if ($row['start_time'] != '0000-00-00 00:00:00' && api_strtotime($row['start_time']) > time()) {
$is_actived_time = false;
$time_limits = false;
if ($row['start_time'] != '0000-00-00 00:00:00' && $row['end_time'] != '0000-00-00 00:00:00') {
$time_limits = true;
}
if ($time_limits) {
// check if start time
$start_time = api_strtotime(api_get_local_time($row['start_time']));
$end_time = api_strtotime(api_get_local_time($row['end_time']));
$now = api_strtotime(api_get_local_time());
$is_actived_time = false;
if ($now > $start_time && $end_time > $now ) {
$is_actived_time = true;
}
}
if ($i % 2 == 0)
$s_class = "row_odd";
else
@ -933,11 +929,14 @@ if ($show == 'test') {
<?php
// if time is actived show link to exercise
if ($is_actived_time) { ?>
<a href="exercice_submit.php?<?php echo api_get_cidreq().$myorigin.$mylpid.$myllpitemid; ?>&exerciseId=<?php echo $row['id']; ?>"><?php echo $row['title']; ?></a>
<?php
if ($time_limits) {
if ($is_actived_time) {
echo '<a href="exercice_submit.php?'.api_get_cidreq().$myorigin.$mylpid.$myllpitemid.'&exerciseId='.$row['id'].'">'.$row['title'].'</a>';
} else {
echo $row['title'];
}
} else {
echo $row['title'];
echo '<a href="exercice_submit.php?'.api_get_cidreq().$myorigin.$mylpid.$myllpitemid.'&exerciseId='.$row['id'].'">'.$row['title'].'</a>';
}
echo '</td><td align="center">';
$exid = $row['id'];
@ -965,11 +964,22 @@ if ($show == 'test') {
ORDER BY exe_id DESC";
$qryres = Database::query($qry);
$num = Database :: num_rows($qryres);
//hide the results
if (!$is_actived_time) {
$my_result_disabled = $row['results_disabled'];
if ($my_result_disabled == 0) {
if ($time_limits) {
if ($my_result_disabled == 0) {
if ($num > 0) {
echo sprintf(get_lang('ExerciseWillBeActivatedFromXToY'), api_get_local_time($row['start_time']), api_get_local_time($row['end_time']));
} else {
echo get_lang('NotAttempted');
}
} else {
echo get_lang('CantShowResults');
}
} else {
if ($my_result_disabled == 0) {
if ($num > 0) {
$row = Database :: fetch_array($qryres);
$percentage = 0;
@ -980,15 +990,17 @@ if ($show == 'test') {
printf("%1.2f\n", $percentage);
echo " %)";
} else {
echo get_lang('WillBeActivated' .' '. $row['start_time']);
//echo get_lang('WillBeActivated' .' '. $row['start_time']);
echo get_lang('NotAttempted');
}
} else {
echo get_lang('CantShowResults');
}
echo '</td></tr>';
} else {
echo get_lang('NotAttempted');
}
echo '</td></tr>';
/*} else {
echo get_lang('NotAttempted');
}*/
}
// skips the last exercise, that is only used to know if we have or not to create a link "Next page"
if ($i == $limitExPage) {
@ -1110,32 +1122,32 @@ if ($_configuration['tracking_enabled'] && ($show == 'result')) {
$exercise_where_query = 'te.exe_exo_id =ce.id AND ';
}
$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,cuser.user_id as excruid,te.exe_duration as exduration
FROM $TBL_EXERCICES AS ce , $TBL_TRACK_EXERCICES AS te, $TBL_USER AS user,$tbl_course_rel_user AS cuser
WHERE user.user_id=cuser.user_id AND cuser.relation_type<>".COURSE_RELATION_TYPE_RRHH." AND te.exe_exo_id = ce.id AND te.status != 'incomplete' AND cuser.user_id=te.exe_user_id 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
AND cuser.course_code=te.exe_cours_id ORDER BY userpart2, te.exe_cours_id ASC, ce.title ASC, te.exe_date DESC";
$hpsql="SELECT ".(api_is_western_name_order() ? "firstname as userpart1, lastname userpart2" : "lastname as userpart1, firstname as userpart2").", 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) . " $user_id_and '
ORDER BY tth.exe_cours_id ASC, tth.exe_date DESC";
$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,cuser.user_id as excruid,te.exe_duration as exduration
FROM $TBL_EXERCICES AS ce , $TBL_TRACK_EXERCICES AS te, $TBL_USER AS user,$tbl_course_rel_user AS cuser
WHERE user.user_id=cuser.user_id AND cuser.relation_type<>".COURSE_RELATION_TYPE_RRHH." AND te.exe_exo_id = ce.id AND te.status != 'incomplete' AND cuser.user_id=te.exe_user_id 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
AND cuser.course_code=te.exe_cours_id ORDER BY userpart2, te.exe_cours_id ASC, ce.title ASC, te.exe_date DESC";
$hpsql="SELECT ".(api_is_western_name_order() ? "firstname as userpart1, lastname userpart2" : "lastname as userpart1, firstname as userpart2").", 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) . " $user_id_and '
ORDER BY tth.exe_cours_id ASC, tth.exe_date DESC";
} else {
// get only this user's results
$user_id_and = ' AND te.exe_user_id = ' . api_get_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, te.exe_date as exdate, te.exe_id as exid, email as exemail, " .
"te.start_date as exstart, steps_counter as exstep, cuser.user_id as excruid, te.exe_duration as exduration, ce.results_disabled as exdisabled
FROM $TBL_EXERCICES AS ce , $TBL_TRACK_EXERCICES AS te, $TBL_USER AS user,$tbl_course_rel_user AS cuser
WHERE user.user_id=cuser.user_id AND te.exe_exo_id = ce.id AND te.status != 'incomplete' AND cuser.user_id=te.exe_user_id
AND te.exe_cours_id='" . Database :: escape_string($_cid) . "'
AND cuser.relation_type<>".COURSE_RELATION_TYPE_RRHH." $user_id_and $session_id_and AND ce.active <>-1 AND" .
" orig_lp_id = 0 AND orig_lp_item_id = 0 AND cuser.course_code=te.exe_cours_id ORDER BY userpart2, te.exe_cours_id ASC, ce.title ASC," .
"te.exe_date DESC";
$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, cuser.user_id as excruid, te.exe_duration as exduration, ce.results_disabled as exdisabled
FROM $TBL_EXERCICES AS ce , $TBL_TRACK_EXERCICES AS te, $TBL_USER AS user,$tbl_course_rel_user AS cuser
WHERE user.user_id=cuser.user_id AND te.exe_exo_id = ce.id AND te.status != 'incomplete' AND cuser.user_id=te.exe_user_id
AND te.exe_cours_id='" . Database :: escape_string($_cid) . "'
AND cuser.relation_type<>".COURSE_RELATION_TYPE_RRHH." $user_id_and $session_id_and AND ce.active <>-1 AND" .
" orig_lp_id = 0 AND orig_lp_item_id = 0 AND cuser.course_code=te.exe_cours_id 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
FROM $TBL_TRACK_HOTPOTATOES
@ -1147,7 +1159,6 @@ if ($_configuration['tracking_enabled'] && ($show == 'result')) {
while ($rowx = Database::fetch_array($resx,'ASSOC')) {
$results[] = $rowx;
}
//$results = getManyResultsXCol($sql, 12);
$hpresults = getManyResultsXCol($hpsql, 5);
$has_test_results = false;
@ -1157,16 +1168,13 @@ if ($_configuration['tracking_enabled'] && ($show == 'result')) {
$lang_nostartdate = get_lang('NoStartDate') . ' / ';
if (is_array($results)) {
$has_test_results = true;
$users_array_id = array ();
if ($_GET['gradebook'] == 'view') {
$filter_by_no_revised = true;
$from_gradebook = true;
}
$sizeof = sizeof($results);
$user_list_id = array ();
$user_last_name = '';
$user_first_name = '';
@ -1177,8 +1185,8 @@ if ($_configuration['tracking_enabled'] && ($show == 'result')) {
$more_details_list = '';
for ($i = 0; $i < $sizeof; $i++) {
$revised = false;
$sql_exe = 'SELECT exe_id FROM ' . Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_ATTEMPT_RECORDING) . '
WHERE author != ' . "''" . ' AND exe_id = ' . "'" . Database :: escape_string($results[$i]['exid']) . "'" . ' LIMIT 1';
$sql_exe = 'SELECT exe_id FROM ' . $TBL_TRACK_ATTEMPT_RECORDING . '
WHERE author != ' . "''" . ' AND exe_id = ' . "'" . Database :: escape_string($results[$i]['exid']) . "'" . ' LIMIT 1';
$query = Database::query($sql_exe);
if (Database :: num_rows($query) > 0) {
@ -1201,7 +1209,7 @@ if ($_configuration['tracking_enabled'] && ($show == 'result')) {
$user_last_name = $results[$i]['userpart2'];
$user_list_id[] = $results[$i]['excruid'];
$id = $results[$i]['exid'];
$mailid = $results[$i]['exemail'];
$user = $results[$i]['userpart1'] . $results[$i]['userpart2'];;
$test = $results[$i]['extitle'];
$quiz_name_list = $test;
@ -1223,15 +1231,15 @@ if ($_configuration['tracking_enabled'] && ($show == 'result')) {
}
if ($results[$i]['exstart'] != "0000-00-00 00:00:00") {
//echo ceil((($results[$i][4] - $results[$i][7]) / 60)) . ' ' . get_lang('MinMinutes');
$exe_date_timestamp = api_strtotime($results[$i]['exdate'], date_default_timezone_get());
$start_date_timestamp = api_strtotime($results[$i]['exstart'], date_default_timezone_get());
$exe_date_timestamp = api_strtotime($results[$i]['exdate'], date_default_timezone_get());
$start_date_timestamp = api_strtotime($results[$i]['exstart'], date_default_timezone_get());
$my_duration = ceil((($exe_date_timestamp - $start_date_timestamp) / 60));
if ($my_duration == 1 ) {
$duration_list = $my_duration . ' ' . get_lang('MinMinute');
if ($my_duration == 1 ) {
$duration_list = $my_duration . ' ' . get_lang('MinMinute');
} else {
$duration_list = $my_duration. ' ' . get_lang('MinMinutes');
}
$duration_list = $my_duration. ' ' . get_lang('MinMinutes');
}
if ($results[$i]['exstep'] > 1) {
//echo ' ( ' . $results[$i][8] . ' ' . get_lang('Steps') . ' )';
$duration_list = ' ( ' . $results[$i]['exstep'] . ' ' . get_lang('Steps') . ' )';
@ -1242,7 +1250,7 @@ if ($_configuration['tracking_enabled'] && ($show == 'result')) {
//echo get_lang('NoLogOfDuration');
}
// Date conversion
$date_list = api_get_local_time($results[$i]['exstart'], null, date_default_timezone_get()). ' / ' . api_get_local_time($results[$i]['exdate'], null, date_default_timezone_get());
$date_list = api_get_local_time($results[$i]['exstart']). ' / ' . api_get_local_time($results[$i]['exdate']);
// there are already a duration test period calculated??
//echo '<td>'.sprintf(get_lang('DurationFormat'), $duration).'</td>';
@ -1269,12 +1277,12 @@ if ($_configuration['tracking_enabled'] && ($show == 'result')) {
if ($revised) {
//echo "<a href='exercise_show.php?action=edit&user=$user&dt=$dt&res=$res&id=$id&email=$mailid'>".Display :: return_icon('edit.gif', get_lang('Edit'));
//echo '&nbsp;';
$html_link.= "<a href='exercise_show.php?".api_get_cidreq()."&action=edit&user=$user&dt=$dt&res=$res&id=$id&email=$mailid'>".Display :: return_icon('edit.gif', get_lang('Edit'));
$html_link.= "<a href='exercise_show.php?".api_get_cidreq()."&action=edit&id=$id'>".Display :: return_icon('edit.gif', get_lang('Edit'));
$html_link.= '&nbsp;';
} else {
//echo "<a href='exercise_show.php?action=qualify&user=$user&dt=$dt&res=$res&id=$id&email=$mailid'>".Display :: return_icon('quizz_small.gif', get_lang('Qualify'));
//echo '&nbsp;';
$html_link.="<a href='exercise_show.php?".api_get_cidreq()."&action=qualify&user=$user&dt=$dt&res=$res&id=$id&email=$mailid'>".Display :: return_icon('quizz_small.gif', get_lang('Qualify'));
$html_link.="<a href='exercise_show.php?".api_get_cidreq()."&action=qualify&id=$id'>".Display :: return_icon('quizz_small.gif', get_lang('Qualify'));
$html_link.='&nbsp;';
}
//echo "</a>";
@ -1305,7 +1313,7 @@ if ($_configuration['tracking_enabled'] && ($show == 'result')) {
$more_details_list = $html_link;
if ($is_allowedToEdit || $is_tutor) {
$list_info [] = array($user_first_name,$user_last_name,$quiz_name_list,$duration_list,$date_list,$result_list,$more_details_list);
} else {
} else {
$list_info [] = array($quiz_name_list,$duration_list,$date_list,$result_list,$more_details_list);
}
//$list_info [] = array($user_list_name,$quiz_name_list,$duration_list,$date_list,$result_list,$more_details_list);
@ -1318,9 +1326,7 @@ if ($_configuration['tracking_enabled'] && ($show == 'result')) {
// Print HotPotatoes test results.
if (is_array($hpresults)) {
$has_test_results = true;
for ($i = 0; $i < sizeof($hpresults); $i++) {
$hp_title = GetQuizName($hpresults[$i][1], $documentPath);
if ($hp_title == '') {
@ -1352,21 +1358,17 @@ if ($_configuration['tracking_enabled'] && ($show == 'result')) {
$table->set_header(1, get_lang('FirstName'));
$secuence = 0;
}
$table->set_header(-$secuence + 2, get_lang('Exercice'));
$table->set_header(-$secuence + 3, get_lang('Duration'),false);
$table->set_header(-$secuence + 4, get_lang('Date'));
$table->set_header(-$secuence + 5, get_lang('Result'),false);
$table->set_header(-$secuence + 6, (($is_allowedToEdit||$is_tutor) ? get_lang('CorrectTest') : get_lang('ViewTest')), false);
$table->display();
} else {
echo get_lang('NoResult');
}
}
if ($origin != 'learnpath') { //so we are not in learnpath tool
Display :: display_footer();
} else {

@ -21,9 +21,7 @@ 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
/*
-----------------------------------------------------------
Libraries
-----------------------------------------------------------
*/
require_once(api_get_path(LIBRARY_PATH).'document.lib.php');
@ -31,9 +29,7 @@ require_once(api_get_path(LIBRARY_PATH).'document.lib.php');
include(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);
@ -106,14 +102,10 @@ while($row = Database::fetch_array($query)){
} else {
echo '<td>'.get_lang('WithoutComment').'</td>';
}
echo '<td>'.$row['insert_date'].'</td>';
echo '<td>'.api_get_local_time($row['insert_date']).'</td>';
echo '<td>'.(empty($row['firstname']) && empty($row['lastname']) ? '<i>'.get_lang('OriginalValue').'</i>' : api_get_person_name($row['firstname'], $row['lastname'])).'</td>';
echo '</tr>';
}
echo '</table>';
Display::display_footer();
?>

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

@ -27,11 +27,6 @@ function showQuestion($questionId, $onlyAnswers = false, $origin = false, $curre
// Change false to true in the following line to enable answer hinting.
$debug_mark_answer = api_is_allowed_to_edit() && false;
if (!ereg("MSIE", $_SERVER["HTTP_USER_AGENT"])) {
//echo '<script src="'.api_get_path(WEB_LIBRARY_PATH).'javascript/jquery.js" type="text/javascript"></script>';
//echo '<script src="'.api_get_path(WEB_LIBRARY_PATH).'javascript/jquery.corners.min.js" type="text/javascript"></script>';
}
// Reads question informations.
if (!$objQuestionTmp = Question::read($questionId)) {
// question not found
@ -49,8 +44,7 @@ function showQuestion($questionId, $onlyAnswers = false, $origin = false, $curre
$questionName=text_filter($questionName);
$s="<div id=\"question_title\" class=\"sectiontitle\">
".get_lang('Question').' ';
$s="<div id=\"question_title\" class=\"sectiontitle\">".get_lang('Question').' ';
$s.=$current_item;
//@todo I need the get the feedback type
@ -541,4 +535,69 @@ function showQuestion($questionId, $onlyAnswers = false, $origin = false, $curre
}
echo '</table><br />';
return $nbrAnswers;
}
}
function get_exercise_track_exercise_info($exe_id) {
$TBL_EXERCICES = Database::get_course_table(TABLE_QUIZ_TEST);
$TBL_TRACK_EXERCICES = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES);
$sql_fb_type='SELECT * FROM '.$TBL_EXERCICES.' as e INNER JOIN '.$TBL_TRACK_EXERCICES.' as te ON (e.id=te.exe_exo_id) WHERE te.exe_id='.Database::escape_string($exe_id);
$res_fb_type=Database::query($sql_fb_type);
$row_fb_type=Database::fetch_array($res_fb_type, 'ASSOC');
return $row_fb_type;
}
/**
* Validates the time control key
*/
function exercise_time_control_is_valid($exercise_id) {
//Fast check
$exercise_id = intval($exercise_id);
$TBL_EXERCICES = Database::get_course_table(TABLE_QUIZ_TEST);
$sql = "SELECT expired_time FROM $TBL_EXERCICES WHERE id = $exercise_id";
$result = Database::query($sql);
$row = Database::fetch_array($result, 'ASSOC');
if (!empty($row['expired_time']) ) {
$current_expired_time_key = get_time_control_key($exercise_id);
if (isset($_SESSION['expired_time'][$current_expired_time_key])) {
$current_time = time();
$expired_time = api_strtotime($_SESSION['expired_time'][$current_expired_time_key], 'UTC');
$total_time_allowed = $expired_time + 30;
//error_log('expired time converted + 30: '.$total_time_allowed);
//error_log('$current_time: '.$current_time);
if ($total_time_allowed < $current_time) {
return false;
}
return true;
} else {
return false;
}
} else {
return true;
}
}
/**
Deletes the time control token
*/
function exercise_time_control_delete($exercise_id) {
$current_expired_time_key = get_time_control_key($exercise_id);
unset($_SESSION['expired_time'][$current_expired_time_key]);
}
/**
Generates the time control key
*/
function generate_time_control_key($exercise_id) {
$exercise_id = intval($exercise_id);
return api_get_course_int_id().'_'.api_get_session_id().'_'.$exercise_id.'_'.api_get_user_id();
}
/**
Returns the time controller key
*/
function get_time_control_key($exercise_id){
$exercise_id = intval($exercise_id);
return api_get_course_int_id().'_'.api_get_session_id().'_'.$exercise_id.'_'.api_get_user_id();
}

@ -12,11 +12,11 @@
// name of the language file that needs to be included
$language_file='exercice';
include('exercise.class.php');
include('question.class.php');
include('answer.class.php');
include('../inc/global.inc.php');
include('exercise.lib.php');
include 'exercise.class.php';
include 'question.class.php';
include 'answer.class.php';
include '../inc/global.inc.php';
include 'exercise.lib.php';
$this_section=SECTION_COURSES;
if(!api_is_allowed_to_edit(null,true)) {

@ -15,9 +15,10 @@
* @todo split more code up in functions, move functions to library?
*/
/* INIT SECTION */
require_once('exercise.class.php');
require_once('question.class.php');
require_once('answer.class.php');
require_once 'exercise.class.php';
require_once 'exercise.lib.php';
require_once 'question.class.php';
require_once 'answer.class.php';
if ($_GET['origin']=='learnpath') {
require_once ('../newscorm/learnpath.class.php');
@ -98,6 +99,8 @@ if ( empty ( $exerciseType ) ) {
$exerciseType = $_REQUEST['exerciseType'];
}
//@todo There should be some doc about this settings
$_configuration['live_exercise_tracking'] = false;
if($_configuration['live_exercise_tracking']) define('ENABLED_LIVE_EXERCISE_TRACKING',1);
@ -150,126 +153,13 @@ if (!empty($gradebook) && $gradebook=='view') {
$nameTools=get_lang('Exercice');
$interbreadcrumb[]=array("url" => "exercice.php?gradebook=$gradebook","name" => get_lang('Exercices'));
$htmlHeadXtra[] = "<script type=\"text/javascript\" src=\"../plugin/hotspot/JavaScriptFlashGateway.js\"></script>
<script src=\"../plugin/hotspot/hotspot.js\" type=\"text/javascript\"></script>
<script language=\"JavaScript\" type=\"text/javascript\">
<!--
// -----------------------------------------------------------------------------
// Globals
// Major version of Flash required
var requiredMajorVersion = 7;
// Minor version of Flash required
var requiredMinorVersion = 0;
// Minor version of Flash required
var requiredRevision = 0;
// the version of javascript supported
var jsVersion = 1.0;
// -----------------------------------------------------------------------------
// -->
</script>
<script language=\"VBScript\" type=\"text/vbscript\">
<!-- // Visual basic helper required to detect Flash Player ActiveX control version information
Function VBGetSwfVer(i)
on error resume next
Dim swControl, swVersion
swVersion = 0
set swControl = CreateObject(\"ShockwaveFlash.ShockwaveFlash.\" + CStr(i))
if (IsObject(swControl)) then
swVersion = swControl.GetVariable(\"\$version\")
end if
VBGetSwfVer = swVersion
End Function
// -->
</script>
<script language=\"JavaScript1.1\" type=\"text/javascript\">
<!-- // Detect Client Browser type
var isIE = (navigator.appVersion.indexOf(\"MSIE\") != -1) ? true : false;
var isWin = (navigator.appVersion.toLowerCase().indexOf(\"win\") != -1) ? true : false;
var isOpera = (navigator.userAgent.indexOf(\"Opera\") != -1) ? true : false;
jsVersion = 1.1;
// JavaScript helper required to detect Flash Player PlugIn version information
function JSGetSwfVer(i){
// NS/Opera version >= 3 check for Flash plugin in plugin array
if (navigator.plugins != null && navigator.plugins.length > 0) {
if (navigator.plugins[\"Shockwave Flash 2.0\"] || navigator.plugins[\"Shockwave Flash\"]) {
var swVer2 = navigator.plugins[\"Shockwave Flash 2.0\"] ? \" 2.0\" : \"\";
var flashDescription = navigator.plugins[\"Shockwave Flash\" + swVer2].description;
descArray = flashDescription.split(\" \");
tempArrayMajor = descArray[2].split(\".\");
versionMajor = tempArrayMajor[0];
versionMinor = tempArrayMajor[1];
if ( descArray[3] != \"\" ) {
tempArrayMinor = descArray[3].split(\"r\");
} else {
tempArrayMinor = descArray[4].split(\"r\");
}
versionRevision = tempArrayMinor[1] > 0 ? tempArrayMinor[1] : 0;
flashVer = versionMajor + \".\" + versionMinor + \".\" + versionRevision;
} else {
flashVer = -1;
}
}
// MSN/WebTV 2.6 supports Flash 4
else if (navigator.userAgent.toLowerCase().indexOf(\"webtv/2.6\") != -1) flashVer = 4;
// WebTV 2.5 supports Flash 3
else if (navigator.userAgent.toLowerCase().indexOf(\"webtv/2.5\") != -1) flashVer = 3;
// older WebTV supports Flash 2
else if (navigator.userAgent.toLowerCase().indexOf(\"webtv\") != -1) flashVer = 2;
// Can't detect in all other cases
else {
flashVer = -1;
}
return flashVer;
}
// When called with reqMajorVer, reqMinorVer, reqRevision returns true if that version or greater is available
function DetectFlashVer(reqMajorVer, reqMinorVer, reqRevision)
{
reqVer = parseFloat(reqMajorVer + \".\" + reqRevision);
// loop backwards through the versions until we find the newest version
for (i=25;i>0;i--) {
if (isIE && isWin && !isOpera) {
versionStr = VBGetSwfVer(i);
} else {
versionStr = JSGetSwfVer(i);
}
if (versionStr == -1 ) {
return false;
} else if (versionStr != 0) {
if(isIE && isWin && !isOpera) {
tempArray = versionStr.split(\" \");
tempString = tempArray[1];
versionArray = tempString .split(\",\");
} else {
versionArray = versionStr.split(\".\");
}
versionMajor = versionArray[0];
versionMinor = versionArray[1];
versionRevision = versionArray[2];
versionString = versionMajor + \".\" + versionRevision; // 7.0r24 == 7.24
versionNum = parseFloat(versionString);
// is the major.revision >= requested major.revision AND the minor version >= requested minor
if ( (versionMajor > reqMajorVer) && (versionNum >= reqVer) ) {
return true;
} else {
return ((versionNum >= reqVer && versionMinor >= reqMinorVer) ? true : false );
}
}
}
}
// -->
</script>";
$htmlHeadXtra[] = $objExercise->show_lp_javascript();
if ($origin != 'learnpath') {
//so we are not in learnpath tool
Display::display_header($nameTools,"Exercise");
} else {
header('Content-Type: text/html; charset='.api_get_system_encoding());
$document_language = api_get_language_isocode();
/*
@ -401,9 +291,7 @@ function display_hotspot_answer($answerId, $answer, $studentChoice, $answerComme
<?php echo $answerId; ?>
</div>
<div style="float:left; padding-left:5px;">
<div style="display:inline; float:left; width:80px;"><?php echo $answer ?></div>
</div>
</td>
<td valign="top">
@ -435,7 +323,7 @@ DISPLAY AND MAIN PROCESS
// I'm in a preview mode as course admin. Display the action menu.
if (api_is_course_admin() && $origin != 'learnpath') {
echo '<div class="actions">';
echo Display::return_icon('quiz.gif', get_lang('GoBackToEx')).'<a href="admin.php?'.api_get_cidreq().'&exerciseId='.$objExercise->id.'">'.get_lang('GoBackToEx').'</a>';
echo Display::return_icon('back.png', get_lang('GoBackToEx')).'<a href="admin.php?'.api_get_cidreq().'&exerciseId='.$objExercise->id.'">'.get_lang('GoBackToEx').'</a>';
echo Display::return_icon('edit.gif', get_lang('ModifyExercise')).'<a href="exercise_admin.php?'.api_get_cidreq().'&modifyExercise=yes&exerciseId='.$objExercise->id.'">'.get_lang('ModifyExercise').'</a>';
echo '</div>';
}
@ -445,7 +333,7 @@ $exerciseTitle=text_filter($exerciseTitle);
//show exercise title
?>
<?php if($origin != 'learnpath') {?>
<h3><?php echo $exerciseTitle ?>: <?php echo get_lang("Result"); ?></h3>
<h2><?php echo Display::return_icon('quiz_big.png', get_lang('Result')).' '; echo $exerciseTitle; ?> : <?php echo get_lang("Result"); ?></h2>
<?php echo $exerciseDescription; ?>
<?php } ?>
@ -710,8 +598,7 @@ foreach ($questionList as $questionId) {
$correct_tags=array();
$real_text=array();
// the loop will stop at the end of the text
while(1)
{
while(1) {
// quits the loop if there are no more blanks (detect '[')
if(($pos = api_strpos($temp,'[')) === false)
{
@ -772,9 +659,7 @@ foreach ($questionList as $questionId) {
{
// adds the word in red at the end of the string, and strikes it
$answer.='<font color="red"><s>'.$user_tags[$i].'</s></font>';
}
else
{
} else {
// adds a tabulation if no word has been typed by the student
$answer.='&nbsp;&nbsp;&nbsp;';
}
@ -791,13 +676,10 @@ foreach ($questionList as $questionId) {
// adds the word in green at the end of the string
$answer.=$user_tags[$i];
} // else if the word entered by the student IS NOT the same as the one defined by the professor
elseif(!empty($user_tags[$i]))
{
elseif(!empty($user_tags[$i])) {
// adds the word in red at the end of the string, and strikes it
$answer.='<font color="red"><s>'.$user_tags[$i].'</s></font>';
}
else
{
} else {
// adds a tabulation if no word has been typed by the student
$answer.='&nbsp;&nbsp;&nbsp;';
}
@ -812,9 +694,7 @@ foreach ($questionList as $questionId) {
// for free answer
case FREE_ANSWER :
$studentChoice=$choice;
if($studentChoice)
{
if($studentChoice) {
//Score is at -1 because the question has'nt been corected
$questionScore=-1;
$totalScore+=0;
@ -845,17 +725,13 @@ foreach ($questionList as $questionId) {
case HOT_SPOT_ORDER :
$studentChoice=$choice['order'][$answerId];
if($studentChoice == $answerId)
{
if($studentChoice == $answerId) {
$questionScore+=$answerWeighting;
$totalScore+=$answerWeighting;
$studentChoice = true;
}
else
{
} else {
$studentChoice = false;
}
break;
} // end switch Answertype
@ -871,28 +747,18 @@ foreach ($questionList as $questionId) {
}
} elseif($answerType == FREE_ANSWER) {
// to store the details of open questions in an array to be used in mail
$arrques[] = $questionName;
$arrans[] = $choice;
if($origin != 'learnpath') {
display_free_answer($choice);
}
}
elseif($answerType == HOT_SPOT)
{
} elseif($answerType == HOT_SPOT) {
if ($origin != 'learnpath') {
display_hotspot_answer($answerId, $answer, $studentChoice, $answerComment);
}
}
elseif($answerType == HOT_SPOT_ORDER)
{
} elseif($answerType == HOT_SPOT_ORDER) {
display_hotspot_order_answer($answerId, $answer, $studentChoice, $answerComment);
}
elseif($answerType==MATCHING)
{
} elseif($answerType==MATCHING) {
if ($origin != 'learnpath') {
echo '<tr>';
echo '<td>'.text_filter($answer_matching[$answerId]).'</td><td>'.text_filter($user_answer).' / <b><span style="color: #008000;">'.text_filter($answer_matching[$answerCorrect]).'</span></b></td>';
@ -970,43 +836,43 @@ foreach ($questionList as $questionId) {
$reply = array_keys($choice);
for ($i=0;$i<sizeof($reply);$i++) {
$ans = $reply[$i];
exercise_attempt($questionScore,$ans,$quesId,$exeId,$i);
exercise_attempt($questionScore,$ans,$quesId,$exeId,$i, $objExercise->id);
}
} else {
exercise_attempt($questionScore, 0 ,$quesId,$exeId,0);
exercise_attempt($questionScore, 0 ,$quesId,$exeId,0, $objExercise->id);
}
} elseif ($answerType==MULTIPLE_ANSWER_COMBINATION ) {
if ($choice != 0) {
$reply = array_keys($choice);
for ($i=0;$i<sizeof($reply);$i++) {
$ans = $reply[$i];
exercise_attempt($questionScore,$ans,$quesId,$exeId,$i);
exercise_attempt($questionScore,$ans,$quesId,$exeId,$i, $objExercise->id);
}
} else {
exercise_attempt($questionScore, 0 ,$quesId,$exeId,0);
exercise_attempt($questionScore, 0 ,$quesId,$exeId,0, $objExercise->id);
}
} elseif ($answerType==MATCHING) {
foreach ($matching as $j => $val) {
exercise_attempt($questionScore, $val, $quesId, $exeId, $j);
exercise_attempt($questionScore, $val, $quesId, $exeId, $j, $objExercise->id);
}
}
elseif ($answerType==FREE_ANSWER) {
$answer = $choice;
exercise_attempt($questionScore,$answer,$quesId,$exeId,0);
exercise_attempt($questionScore,$answer,$quesId,$exeId,0, $objExercise->id);
}
elseif ($answerType==UNIQUE_ANSWER) {
// exercise_attempt($questionScore,$answer,$quesId,$exeId,0);
// In fact, we are not storing the results by answer ID, but by *position*, which is stored in $choice
exercise_attempt($questionScore,$choice,$quesId,$exeId,0);
exercise_attempt($questionScore,$choice,$quesId,$exeId,0, $objExercise->id);
} elseif ($answerType == HOT_SPOT) {
exercise_attempt($questionScore, $answer, $quesId, $exeId, 0);
exercise_attempt($questionScore, $answer, $quesId, $exeId, 0, $objExercise->id);
if (is_array($exerciseResultCoordinates[$quesId])) {
foreach($exerciseResultCoordinates[$quesId] as $idx => $val) {
exercise_attempt_hotspot($exeId,$quesId,$idx,$choice[$idx],$val);
exercise_attempt_hotspot($exeId,$quesId,$idx,$choice[$idx],$val, $objExercise->id);
}
}
} else {
exercise_attempt($questionScore,$answer,$quesId,$exeId,0);
exercise_attempt($questionScore,$answer,$quesId,$exeId,0, $objExercise->id);
}
}
} // end huge foreach() block that loops over all questions
@ -1042,9 +908,7 @@ foreach ($questionList as $questionId) {
<?php
/*
==============================================================================
Tracking of results
==============================================================================
*/
if ($_configuration['tracking_enabled']) {
@ -1085,7 +949,6 @@ if($objExercise->results_disabled) {
echo '<script language="javascript" type="text/javascript">window.parent.API.void_save_asset('.$totalScore.','.$totalWeighting.');</script>'."\n";
echo '</body></html>';
}
}
if ($origin != 'learnpath') {
@ -1125,7 +988,6 @@ if($num>1) {
//this is a problem (it means that there is no admin for this course)
}
// we are able to send emails to the teachers?
if (api_get_course_setting('email_alert_manager_on_new_quiz') == 1 ) {
// only for "simple tests"
@ -1182,7 +1044,6 @@ if (api_get_course_setting('email_alert_manager_on_new_quiz') == 1 ) {
$msg1= str_replace("#i#",$i,$msg);
$msg= str_replace("#course#",$courseName,$msg1);
}
$msg.='</table><br>
<span class="style16">'.get_lang('ClickToCommentAndGiveFeedback').',<br />
<a href="#url#">#url#</a></span></body></html>';

@ -17,6 +17,7 @@ require_once '../inc/global.inc.php';
require_once '../inc/lib/course.lib.php';
// including additional libraries
require_once 'exercise.class.php';
require_once 'exercise.lib.php';
require_once 'question.class.php'; //also defines answer type constants
require_once 'answer.class.php';
require_once api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php';
@ -80,6 +81,7 @@ if ( empty ( $questionList ) ) {
if ( empty ( $objExercise ) ) {
$objExercise = $_SESSION['objExercise'];
}
if ( empty ( $exeId ) ) {
$exeId = $_REQUEST['id'];
}
@ -87,51 +89,28 @@ if ( empty ( $exeId ) ) {
if ( empty ( $action ) ) {
$action = $_GET['action'];
}
$current_user_id = api_get_user_id();
$current_user_id = "'".$current_user_id."'";
$current_attempt = $_SESSION['current_exercice_attempt'][$current_user_id];
//Is fraudulent exercice
$current_time = time();
$emailId = $_REQUEST['email'];
$user_name = $_REQUEST['user'];
$test = $_REQUEST['test'];
$dt = $_REQUEST['dt'];
$marks = $_REQUEST['res'];
$id = $_REQUEST['id'];
$sql_fb_type='SELECT feedback_type, exercises.id FROM '.$TBL_EXERCICES.' as exercises, '.$TBL_TRACK_EXERCICES.' as track_exercises WHERE exercises.id=track_exercises.exe_exo_id AND track_exercises.exe_id="'.Database::escape_string($id).'"';
$res_fb_type=Database::query($sql_fb_type);
$row_fb_type=Database::fetch_row($res_fb_type);
$feedback_type = $row_fb_type[0];
$exercise_id = intval($row_fb_type[1]);
$course_code = api_get_course_id();
$session_id = api_get_session_id();
$current_expired_time_key = $course_code.'_'.$session_id.'_'.$exercise_id;
if (isset($_SESSION['expired_time'][$current_expired_time_key])) { //Only for exercice of type "One page"
$expired_date = $_SESSION['expired_time'][$current_expired_time_key];
$expired_time = strtotime($expired_date);
//Validation in case of fraud
$total_time_allowed = $expired_time + 30;
if ($total_time_allowed < $current_time) {
$sql_fraud = "UPDATE $TBL_TRACK_ATTEMPT SET answer = 0, marks=0, position=0 WHERE exe_id = '$current_attempt' ";
Database::query($sql_fraud);
}
if (empty($id)) {
api_not_allowed();
}
$track_exercise_info = get_exercise_track_exercise_info($id);
$exercise_id = $track_exercise_info['id'];
$course_code = api_get_course_id();
if (!exercise_time_control_is_valid($exercise_id)) {
$sql_fraud = "UPDATE $TBL_TRACK_ATTEMPT SET answer = 0, marks=0, position=0 WHERE exe_id = '{$track_exercise_info['exe_id']}' ";
Database::query($sql_fraud);
}
//Unset session for clock time
unset($_SESSION['current_exercice_attempt'][$current_user_id]);
unset($_SESSION['expired_time'][$current_expired_time_key]);
unset($_SESSION['end_expired_time'][$current_expired_time_key]);
exercise_time_control_delete($exercise_id);
$is_allowedToEdit=api_is_allowed_to_edit(null,true) || $is_courseTutor;
$nameTools=get_lang('CorrectTest');
if (isset($_SESSION['gradebook'])){
if (isset($_SESSION['gradebook'])) {
$gradebook= $_SESSION['gradebook'];
}
@ -143,7 +122,6 @@ if($origin=='user_course') {
$interbreadcrumb[] = array ("url" => "../user/user.php?cidReq=".Security::remove_XSS($_GET['course']), "name" => get_lang("Users"));
$interbreadcrumb[] = array("url" => "../mySpace/myStudents.php?student=".Security::remove_XSS($_GET['student'])."&course=".$_course['id']."&details=true&origin=".Security::remove_XSS($_GET['origin']) , "name" => get_lang("DetailsStudentInCourse"));
} else if($origin=='tracking_course') {
//$interbreadcrumb[] = array ("url" => "../mySpace/index.php", "name" => get_lang('MySpace'));
//$interbreadcrumb[] = array ("url" => "../mySpace/myStudents.php?student=".Security::remove_XSS($_GET['student']).'&details=true&origin='.$origin.'&course='.Security::remove_XSS($_GET['cidReq']), "name" => get_lang("DetailsStudentInCourse"));
$interbreadcrumb[] = array ("url" => api_get_path(WEB_COURSE_PATH).$_course['directory'], 'name' => $_course['title']);
@ -186,20 +164,17 @@ if ($origin != 'learnpath') {
height:75px;
z-index:1;
}
-->
</style>
<script language="javascript">
function showfck(sid,marksid)
{
function showfck(sid,marksid) {
document.getElementById(sid).style.display='block';
document.getElementById(marksid).style.display='block';
var comment = 'feedback_'+sid;
document.getElementById(comment).style.display='none';
}
function getFCK(vals,marksid)
{
function getFCK(vals,marksid) {
var f=document.getElementById('myform');
var m_id = marksid.split(',');
@ -233,8 +208,6 @@ function getFCK(vals,marksid)
// Email configuration settings
$coursecode = api_get_course_id();
$courseName = $_SESSION['_course']['name'];
$to = '';
$teachers = array();
if(api_get_setting('use_session_mode')=='true' && !empty($_SESSION['id_session'])) {
@ -263,17 +236,14 @@ if($num>1) {
<tr>
<td colspan="2">
<?php
$sql_test_name='SELECT title, description, results_disabled FROM '.$TBL_EXERCICES.' as exercises, '.$TBL_TRACK_EXERCICES.' as track_exercises WHERE exercises.id=track_exercises.exe_exo_id AND track_exercises.exe_id="'.Database::escape_string($id).'"';
$result=Database::query($sql_test_name);
$show_results = true;
// Avoiding the "Score 0/0" message when the exe_id is not set
if (Database::num_rows($result)>0 && isset($id)) {
$test=Database::result($result,0,0);
$exerciseTitle=text_filter($test);
$exerciseDescription=Database::result($result,0,1);
if (!empty($track_exercise_info)) {
$exerciseTitle = text_filter($track_exercise_info['title']);
$exerciseDescription = $track_exercise_info['description'];
// if the results_disabled of the Quiz is 1 when block the script
$result_disabled=Database::result($result,0,2);
$result_disabled = $track_exercise_info['results_disabled'];
if (!(api_is_platform_admin() || api_is_course_admin()) ) {
if ($result_disabled==1) {
//api_not_allowed();
@ -287,17 +257,6 @@ if (Database::num_rows($result)>0 && isset($id)) {
}
}
}
if ($show_results) {
$user_restriction = $is_allowedToEdit ? '' : "AND user_id=".intval($_user['user_id'])." ";
$query = "SELECT attempts.question_id, answer from ".$TBL_TRACK_ATTEMPT." as attempts
INNER JOIN ".$TBL_TRACK_EXERCICES." as stats_exercices ON stats_exercices.exe_id=attempts.exe_id
INNER JOIN ".$TBL_EXERCICE_QUESTION." as quizz_rel_questions ON quizz_rel_questions.exercice_id=stats_exercices.exe_exo_id AND quizz_rel_questions.question_id = attempts.question_id
INNER JOIN ".$TBL_QUESTIONS." as questions ON questions.id=quizz_rel_questions.question_id
WHERE attempts.exe_id='".Database::escape_string($id)."' $user_restriction
GROUP BY quizz_rel_questions.question_order, attempts.question_id";
//GROUP BY questions.position, attempts.question_id";
$result =Database::query($query);
}
} else {
Display::display_warning_message(get_lang('CantViewResults'));
$show_results = false;
@ -308,50 +267,60 @@ if (Database::num_rows($result)>0 && isset($id)) {
if ($origin == 'learnpath' && !isset($_GET['fb_type']) ) {
$show_results = false;
}
/*
<tr>
<td style="font-weight:bold" width="10%">
<div class="actions-message"><?php echo '&nbsp;'.get_lang('CourseTitle')?> : </div></td>
<td><div class="actions-message" width="90%"><?php echo $_course['name'] ?></div></td>
</tr>*/
if ($show_results) {
?>
<table width="100%">
<tr>
<td style="font-weight:bold" width="10%"><div class="actions-message"><?php echo '&nbsp;'.get_lang('CourseTitle')?> : </div></td>
<td><div class="actions-message" width="90%"><?php echo $_course['name'] ?></div></td>
</tr>
<td colspan="2">
<h2><?php echo Display::return_icon('quiz_big.png', get_lang('Result')).' '.$exerciseTitle.' : '.get_lang('Result');?></h2>
</td>
</tr>
<tr>
<td style="font-weight:bold" width="10%"><div class="actions-message"><?php echo '&nbsp;'.get_lang('User')?> : </div></td>
<td><div class="actions-message" width="90%"><?php
<td style="font-weight:bold" width="80px"><div ><?php echo '&nbsp;'.get_lang('User')?> : </div></td>
<td><div width="90%"><?php
/*
if (isset($_GET['cidReq'])) {
$course_code = Security::remove_XSS($_GET['cidReq']);
} else {
$course_code = api_get_course_id();
}
}*/
/*
if (isset($_GET['student'])) {
$user_id = Security::remove_XSS($_GET['student']);
}else {
$user_id = api_get_user_id();
}
$status_info=CourseManager::get_user_in_course_status($user_id,$course_code);
$user_id = intval($_GET['student']);
} else {
$user_id = $track_exercise_info['exe_user_id'];
}*/
$user_id = $track_exercise_info['exe_user_id'];
$user_info=api_get_user_info($user_id);
echo api_get_person_name($user_info['firstName'], $user_info['lastName']);
/*$status_info=CourseManager::get_user_in_course_status($user_id,$course_code);
if (STUDENT==$status_info) {
$user_info=api_get_user_info($user_id);
echo api_get_person_name($user_info['firstName'], $user_info['lastName']);
} elseif(COURSEMANAGER==$status_info && !isset($_GET['user'])) {
$user_info=api_get_user_info($user_id);
echo api_get_person_name($user_info['firstName'], $user_info['lastName']);
} else {
echo $user_name;
}
}*/
?></div></td>
</tr>
<?php if (!empty($exerciseDescription)) { ?>
<tr>
<td style="font-weight:bold" width="10%" class="actions-message">
<?php echo '&nbsp;'.get_lang("Exercise").' :'; ?>
<?php echo '&nbsp;'.get_lang("Description").' :'; ?>
</td>
<td width="90%">
<?php echo $test; ?><br />
<td width="90%">
<?php echo $exerciseDescription; ?>
</td>
</tr>
<?php } ?>
</table>
<br />
</table>
@ -362,28 +331,46 @@ $i=$totalScore=$totalWeighting=0;
if($debug>0){echo "ExerciseResult: "; var_dump($exerciseResult); echo "QuestionList: ";var_dump($questionList);}
$arrques = array();
$arrans = array();
if ($show_results) {
$user_restriction = $is_allowedToEdit ? '' : "AND user_id=".intval($_user['user_id'])." ";
$query = "SELECT attempts.question_id, answer from ".$TBL_TRACK_ATTEMPT." as attempts
INNER JOIN ".$TBL_TRACK_EXERCICES." as stats_exercices ON stats_exercices.exe_id=attempts.exe_id
INNER JOIN ".$TBL_EXERCICE_QUESTION." as quizz_rel_questions ON quizz_rel_questions.exercice_id=stats_exercices.exe_exo_id AND quizz_rel_questions.question_id = attempts.question_id
INNER JOIN ".$TBL_QUESTIONS." as questions ON questions.id=quizz_rel_questions.question_id
WHERE attempts.exe_id='".Database::escape_string($id)."' $user_restriction
GROUP BY quizz_rel_questions.question_order, attempts.question_id";
//GROUP BY questions.position, attempts.question_id";
$result =Database::query($query);
$questionList = array();
$exerciseResult = array();
$k=0;
$counter=0;
while ($row = Database::fetch_array($result)) {
$questionList[] = $row['question_id'];
$exerciseResult[] = $row['answer'];
$exerciseResult[$row['question_id']] = $row['answer'];
}
//Fixing #2073
if (!empty($track_exercise_info['data_tracking']) && $track_exercise_info['random_answers'] == 1) {
$tempquestionList = explode(',',$track_exercise_info['data_tracking']);
if (is_array($tempquestionList) && count($tempquestionList) == count($questionList)) {
$questionList = $tempquestionList;
}
}
// for each question
$counter=0;
foreach($questionList as $questionId) {
$counter++;
$k++;
$counter++;
$choice=$exerciseResult[$questionId];
// creates a temporary Question object
$objQuestionTmp = Question::read($questionId);
$questionName=$objQuestionTmp->selectTitle();
$questionDescription=$objQuestionTmp->selectDescription();
$questionWeighting=$objQuestionTmp->selectWeighting();
$answerType=$objQuestionTmp->selectType();
$quesId =$objQuestionTmp->selectId(); //added by priya saini
$objQuestionTmp = Question::read($questionId);
$questionName = $objQuestionTmp->selectTitle();
$questionDescription= $objQuestionTmp->selectDescription();
$questionWeighting = $objQuestionTmp->selectWeighting();
$answerType = $objQuestionTmp->selectType();
$quesId = $objQuestionTmp->selectId(); //added by priya saini
// destruction of the Question object
unset($objQuestionTmp);
@ -430,7 +417,7 @@ if ($show_results) {
$objAnswerTmp=new Answer($questionId);
$nbrAnswers=$objAnswerTmp->selectNbrAnswers();
$questionScore=0;
for ($answerId=1;$answerId <= $nbrAnswers;$answerId++) {
for ($answerId=1; $answerId <= $nbrAnswers; $answerId++) {
$answer=$objAnswerTmp->selectAnswer($answerId);
$answerComment=$objAnswerTmp->selectComment($answerId);
$answerCorrect=$objAnswerTmp->isCorrect($answerId);
@ -441,20 +428,17 @@ if ($show_results) {
$ind = $row['answer'];
$choice[$ind] = 1;
}
$numAnswer=$objAnswerTmp->selectAutoId($answerId);
$studentChoice=$choice[$numAnswer];
if ($studentChoice) {
$questionScore+=$answerWeighting;
$totalScore+=$answerWeighting;
}
echo '<tr><td>';
if ($answerId==1) {
ExerciseShowFunctions::display_unique_or_multiple_answer($answerType, $studentChoice, $answer, $answerComment, $answerCorrect,$id,$questionId,$answerId);
ExerciseShowFunctions::display_unique_or_multiple_answer($answerType, $studentChoice, $answer, $answerComment, $answerCorrect,$id,$questionId,$answerId);
} else {
ExerciseShowFunctions::display_unique_or_multiple_answer($answerType, $studentChoice, $answer, $answerComment, $answerCorrect,$id,$questionId,"");
ExerciseShowFunctions::display_unique_or_multiple_answer($answerType, $studentChoice, $answer, $answerComment, $answerCorrect,$id,$questionId,"");
}
echo '</td></tr>';
$i++;
@ -514,14 +498,13 @@ if ($show_results) {
echo '<tr><td>';
if ($answerId==1) {
ExerciseShowFunctions::display_unique_or_multiple_answer($answerType, $studentChoice, $answer, $answerComment, $answerCorrect,$id,$questionId,$answerId);
ExerciseShowFunctions::display_unique_or_multiple_answer($answerType, $studentChoice, $answer, $answerComment, $answerCorrect,$id,$questionId,$answerId);
} else {
ExerciseShowFunctions::display_unique_or_multiple_answer($answerType, $studentChoice, $answer, $answerComment, $answerCorrect,$id,$questionId,"");
ExerciseShowFunctions::display_unique_or_multiple_answer($answerType, $studentChoice, $answer, $answerComment, $answerCorrect,$id,$questionId,"");
}
echo '</td></tr>';
$i++;
}
$final_answer = true;
foreach($real_answers as $my_answer) {
if (!$my_answer) {
@ -990,8 +973,6 @@ if ($show_results) {
</td>
</tr>
</table>
<?php
$my_total_score = float_format($questionScore,1);
$my_total_weight = float_format($questionWeighting,1);
@ -1020,7 +1001,7 @@ if ($origin!='learnpath' || ($origin == 'learnpath' && isset($_GET['fb_type'])))
$my_total_weight = float_format($totalWeighting,1);
echo $my_total_score."/".$my_total_weight;
}
echo '!</div>';
echo '</div>';
}
}
@ -1031,8 +1012,7 @@ if (is_array($arrid) && is_array($arrmarks)) {
if ($is_allowedToEdit) {
if (in_array($origin, array('tracking_course','user_course'))) {
echo ' <form name="myform" id="myform" action="exercice.php?show=result&comments=update&exeid='.$id.'&test='.urlencode($test).'&emailid='.$emailId.'&origin='.$origin.'&student='.Security::remove_XSS($_GET['student']).'&details=true&course='.Security::remove_XSS($_GET['cidReq']).$fromlink.'" method="post">';
echo ' <form name="myform" id="myform" action="exercice.php?show=result&comments=update&exeid='.$id.'&origin='.$origin.'&details=true&course='.Security::remove_XSS($_GET['cidReq']).$fromlink.'" method="post">';
echo ' <input type = "hidden" name="totalWeighting" value="'.$totalWeighting.'">';
if (isset($_GET['myid']) && isset($_GET['my_lp_id']) && isset($_GET['student'])) {
?>
@ -1045,7 +1025,7 @@ if ($is_allowedToEdit) {
<?php
}
} else {
echo ' <form name="myform" id="myform" action="exercice.php?show=result&comments=update&exeid='.$id.'&test='.$test.'&emailid='.$emailId.'&totalWeighting='.$totalWeighting.'" method="post">';
echo ' <form name="myform" id="myform" action="exercice.php?show=result&comments=update&exeid='.$id.'&totalWeighting='.$totalWeighting.'" method="post">';
}
if ($origin!='learnpath' && $origin!='student_progress') {
?>
@ -1054,8 +1034,6 @@ if ($is_allowedToEdit) {
<?php
}
}
if ($origin=='student_progress' && !isset($_GET['my_lp_id'])) {?>
<button type="button" class="back" onclick="window.back();" value="<?php echo get_lang('Back'); ?>" ><?php echo get_lang('Backs');?></button>
<?php
@ -1067,7 +1045,6 @@ if ($origin=='student_progress' && !isset($_GET['my_lp_id'])) {?>
if ($origin != 'learnpath') {
$url_email = api_get_path(WEB_CODE_PATH).'exercice/exercice.php?'.api_get_cidreq().'&show=result';
//we are not in learnpath tool
Display::display_footer();
} else {

@ -56,20 +56,19 @@ function event_open()
// record informations only if user comes from another site
//if(!eregi($_configuration['root_web'],$referer))
$pos = strpos($referer, $_configuration['root_web']);
if ($pos === false && $referer != '')
{
if ($pos === false && $referer != '') {
$remhost = @ getHostByAddr($_SERVER['REMOTE_ADDR']);
if ($remhost == $_SERVER['REMOTE_ADDR'])
$remhost = "Unknown"; // don't change this
$reallyNow = time();
$reallyNow = api_get_utc_datetime();
$sql = "INSERT INTO ".$TABLETRACK_OPEN."
(open_remote_host,
open_agent,
open_referer,
open_date)
VALUES
('".$remhost."',
'".Database::escape_string($_SERVER['HTTP_USER_AGENT'])."', '".Database::escape_string($referer)."', FROM_UNIXTIME($reallyNow) )";
(open_remote_host,
open_agent,
open_referer,
open_date)
VALUES
('".$remhost."',
'".Database::escape_string($_SERVER['HTTP_USER_AGENT'])."', '".Database::escape_string($referer)."', '$reallyNow')";
$res = Database::query($sql);
}
return 1;
@ -105,8 +104,7 @@ function event_login()
* @author Sebastien Piraux <piraux_seb@hotmail.com>
* @desc Record information for access event for courses
*/
function event_access_course()
{
function event_access_course() {
global $_configuration;
global $_user;
global $_cid;
@ -117,9 +115,8 @@ function event_access_course()
if (!$_configuration['tracking_enabled']){
return 0;
}
$id_session = api_get_session_id();
$reallyNow = time();
$id_session = api_get_session_id();
$reallyNow = api_get_utc_datetime();
if ($_user['user_id']) {
$user_id = "'".$_user['user_id']."'";
} else {
@ -137,15 +134,13 @@ function event_access_course()
'".$id_session."')";
$res = Database::query($sql);
// added for "what's new" notification
$sql = " UPDATE $TABLETRACK_LASTACCESS
SET access_date = FROM_UNIXTIME($reallyNow)
WHERE access_user_id = ".$user_id." AND access_cours_code = '".$_cid."' AND access_tool IS NULL AND access_session_id=".$id_session;
$sql = "UPDATE $TABLETRACK_LASTACCESS
SET access_date = '$reallyNow'
WHERE access_user_id = $user_id AND access_cours_code = '$_cid' AND access_tool IS NULL AND access_session_id=".$id_session;
$res = Database::query($sql);
if (Database::affected_rows() == 0) {
$sql = " INSERT INTO $TABLETRACK_LASTACCESS
(access_user_id,access_cours_code,access_date, access_session_id)
VALUES
(".$user_id.", '".$_cid."', FROM_UNIXTIME($reallyNow), ".$id_session.")";
$sql = "INSERT INTO $TABLETRACK_LASTACCESS (access_user_id, access_cours_code, access_date, access_session_id)
VALUES (".$user_id.", '".$_cid."', '$reallyNow', '".$id_session."')";
$res = Database::query($sql);
}
// end "what's new" notification
@ -180,7 +175,7 @@ function event_access_tool($tool, $id_session=0)
$id_session = api_get_session_id();
$tool = Database::escape_string($tool);
$reallyNow = time();
$reallyNow = api_get_utc_datetime();
$user_id = $_user['user_id'] ? "'".$_user['user_id']."'" : "0"; // no one
// record information
// only if user comes from the course $_cid
@ -203,18 +198,18 @@ function event_access_tool($tool, $id_session=0)
(".$user_id.",".// Don't add ' ' around value, it's already done.
"'".$_cid."' ,
'".$tool."',
FROM_UNIXTIME(".$reallyNow."),
'".$reallyNow."',
'".$id_session."')";
$res = Database::query($sql);
}
// "what's new" notification
$sql = "UPDATE $TABLETRACK_LASTACCESS
SET access_date = FROM_UNIXTIME($reallyNow)
SET access_date = '$reallyNow'
WHERE access_user_id = ".$user_id." AND access_cours_code = '".$_cid."' AND access_tool = '".$tool."' AND access_session_id=".$id_session;
$res = Database::query($sql);
if (Database::affected_rows() == 0) {
$sql = "INSERT INTO $TABLETRACK_LASTACCESS (access_user_id,access_cours_code,access_tool, access_date, access_session_id)
VALUES (".$user_id.", '".$_cid."' , '".$tool."', FROM_UNIXTIME($reallyNow), $id_session)";
VALUES (".$user_id.", '".$_cid."' , '$tool', '$reallyNow', $id_session)";
$res = Database::query($sql);
}
return 1;
@ -233,38 +228,32 @@ function event_access_tool($tool, $id_session=0)
* and later again.
* Doing this twice causes an error, I remove one of them.
*/
function event_download($doc_url)
{
function event_download($doc_url) {
global $_configuration, $_user, $_cid;
$tbl_stats_downloads = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_DOWNLOADS);
// if tracking is disabled record nothing
if (!$_configuration['tracking_enabled']) {
return 0;
}
$reallyNow = time();
$reallyNow = api_get_utc_datetime();
if ($_user['user_id']) {
$user_id = "'".$_user['user_id']."'";
} else {
$user_id = "0";
}
$sql = "INSERT INTO $tbl_stats_downloads
(
$sql = "INSERT INTO $tbl_stats_downloads (
down_user_id,
down_cours_id,
down_doc_path,
down_date,
down_session_id
)
VALUES
(
VALUES (
".$user_id.",
'".$_cid."',
'".htmlspecialchars($doc_url, ENT_QUOTES)."',
FROM_UNIXTIME(".$reallyNow."),
'".$reallyNow."',
'".api_get_session_id()."'
)";
$res = Database::query($sql);
@ -288,8 +277,7 @@ function event_upload($doc_id)
if (!$_configuration['tracking_enabled']) {
return 0;
}
$reallyNow = time();
$reallyNow = api_get_utc_datetime();
if (isset($_user['user_id']) && $_user['user_id']!='') {
$user_id = "'".$_user['user_id']."'";
} else {
@ -306,7 +294,7 @@ function event_upload($doc_id)
".$user_id.",
'".$_cid."',
'".$doc_id."',
FROM_UNIXTIME(".$reallyNow."),
'".$reallyNow."',
'".api_get_session_id()."'
)";
$res = Database::query($sql);
@ -319,17 +307,14 @@ function event_upload($doc_id)
* @desc Record information for link event (when an user click on an added link)
* it will be used in a redirection page
*/
function event_link($link_id)
{
global $_configuration, $_user, $_cid;
global $TABLETRACK_LINKS;
function event_link($link_id) {
global $_configuration, $_user, $TABLETRACK_LINKS;
// if tracking is disabled record nothing
if (!$_configuration['tracking_enabled']) {
return 0;
}
$reallyNow = time();
$reallyNow = api_get_utc_datetime();
if (isset($_user['user_id']) && $_user['user_id']!='') {
$user_id = "'".Database::escape_string($_user['user_id'])."'";
} else {
@ -347,9 +332,9 @@ function event_link($link_id)
VALUES
(
".$user_id.",
'".$_cid."',
'".api_get_course_id()."',
'".Database::escape_string($link_id)."',
FROM_UNIXTIME(".$reallyNow."),
'".$reallyNow."',
'".api_get_session_id()."'
)";
$res = Database::query($sql);
@ -357,35 +342,28 @@ function event_link($link_id)
}
/**
* @param exeid ( id of the exercise)
* @param exo_id ( id in courseDb exercices table )
* @param result ( score @ exercice )
* @param weighting ( higher score )
* @param duration ( duration of the attempt, in seconds )
* @param session_id
* @param learnpath_id (id of the learnpath)
* @param learnpath_item_id (id of the learnpath_item)
* Update the TRACK_E_EXERCICES exercises
*
* @param int exeid id of the attempt
* @param int exo_id exercise id
* @param mixed result score
* @param int weighting ( higher score )
* @param int duration ( duration of the attempt, in seconds )
* @param int session_id
* @param int learnpath_id (id of the learnpath)
* @param int learnpath_item_id (id of the learnpath_item)
*
* @author Sebastien Piraux <piraux_seb@hotmail.com>
* @author Julio Montoya Armas <gugli100@gmail.com>
* @author Julio Montoya Armas <gugli100@gmail.com> Reworked 2010
* @desc Record result of user when an exercice was done
*/
function update_event_exercice($exeid,$exo_id, $score, $weighting,$session_id,$learnpath_id=0,$learnpath_item_id=0, $duration)
{
function update_event_exercice($exeid,$exo_id, $score, $weighting,$session_id,$learnpath_id=0,$learnpath_item_id=0, $duration) {
if ($exeid!='') {
// Validation in case of fraud with actived control time
$course_code = api_get_course_id();
$current_expired_time_key = $course_code.'_'.$session_id.'_'.$exeid;
if (isset($_SESSION['expired_time'][$current_expired_time_key])) { //Only for exercice of type "One page"
$current_time = time();
$expired_date = $_SESSION['expired_time'][$current_expired_time_key];
$expired_time = strtotime($expired_date);
$total_time_allowed = $expired_time + 30;
if ($total_time_allowed < $current_time) {
$score = 0;
}
// Validation in case of fraud with actived control time
if (!exercise_time_control_is_valid($exo_id)) {
$score = 0;
}
$now = time();
//Validation in case of wrong start_date
if (isset($_SESSION['exercice_start_date'])) {
@ -399,18 +377,20 @@ function update_event_exercice($exeid,$exo_id, $score, $weighting,$session_id,$l
$TABLETRACK_EXERCICES = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES);
$sql = "UPDATE $TABLETRACK_EXERCICES SET
exe_exo_id = '".Database::escape_string($exo_id)."',
exe_result = '".Database::escape_string($score)."',
exe_weighting = '".Database::escape_string($weighting)."',
exe_exo_id = '".Database::escape_string($exo_id)."',
exe_result = '".Database::escape_string($score)."',
exe_weighting = '".Database::escape_string($weighting)."',
session_id = '".Database::escape_string($session_id)."',
orig_lp_id = '".Database::escape_string($learnpath_id)."',
orig_lp_item_id = '".Database::escape_string($learnpath_item_id)."',
exe_duration = '".Database::escape_string($duration)."',
exe_date= FROM_UNIXTIME(".$now."),status = '', data_tracking='', start_date = FROM_UNIXTIME(".Database::escape_string($start_date).")
orig_lp_id = '".Database::escape_string($learnpath_id)."',
orig_lp_item_id = '".Database::escape_string($learnpath_item_id)."',
exe_duration = '".Database::escape_string($duration)."',
exe_date = ".api_get_utc_datetime().",
status = '',
data_tracking = '',
start_date = '".api_get_utc_datetime($start_date)."')
WHERE exe_id = '".Database::escape_string($exeid)."'";
$res = @Database::query($sql);
unset($_SESSION['expired_time'][$current_expired_time_key]);
$res = @Database::query($sql);
exercise_time_control_delete($exo_id);
return $res;
} else
return false;
@ -423,9 +403,8 @@ function update_event_exercice($exeid,$exo_id, $score, $weighting,$session_id,$l
* @author Julio Montoya <gugli100@gmail.com>
* @desc Record result of user when an exercice was done
*/
function create_event_exercice($exo_id)
{
global $_user, $_cid, $_configuration;
function create_event_exercice($exo_id) {
global $_user, $_configuration;
$TABLETRACK_EXERCICES = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES);
$TBL_EXERCICES = Database::get_course_table(TABLE_QUIZ_TEST);
$reallyNow = time();
@ -440,7 +419,7 @@ function create_event_exercice($exo_id)
$condition = ' WHERE ' .
'exe_exo_id = '."'".Database::escape_string($exo_id)."'".' AND ' .
'exe_user_id = '."'".api_get_user_id()."'".' AND ' .
'exe_cours_id = '."'".$_cid."'".' AND ' .
'exe_cours_id = '."'".api_get_course_id()."'".' AND ' .
'status = '."'incomplete'".' AND '.
'session_id = '."'".api_get_session_id()."'";
$sql = Database::query('SELECT exe_id FROM '.$TABLETRACK_EXERCICES.$condition);
@ -453,10 +432,8 @@ function create_event_exercice($exo_id)
$row_exe_id=Database::fetch_row($res_exe_id);
$exercise_id = intval($row_exe_id[0]);
// get expired_date
$course_code = api_get_course_id();
$session_id = api_get_session_id();
$current_expired_time_key = $course_code.'_'.$session_id.'_'.$exercise_id;
// get expired_date
$current_expired_time_key = get_time_control_key($exercise_id);
if (isset($_SESSION['expired_time'][$current_expired_time_key])) { //Only for exercice of type "One page"
$expired_date = $_SESSION['expired_time'][$current_expired_time_key];
@ -464,15 +441,13 @@ function create_event_exercice($exo_id)
$expired_date = '0000-00-00 00:00:00';
}
$sql = "INSERT INTO $TABLETRACK_EXERCICES ( exe_user_id, exe_cours_id,expired_time_control,exe_exo_id)
VALUES ( ".$user_id.", '".$_cid."' ,'".$expired_date."','".$exo_id."')";
$res = @Database::query($sql);
$sql = "INSERT INTO $TABLETRACK_EXERCICES ( exe_user_id, exe_cours_id, expired_time_control, exe_exo_id)
VALUES ( ".$user_id.", '".api_get_course_id()."' ,'".$expired_date."','".$exo_id."')";
$res = Database::query($sql);
$id= Database::insert_id();
return $id;
}
/**
* Record an event for this attempt at answering an exercise
* @param float Score achieved
@ -482,50 +457,38 @@ function create_event_exercice($exo_id)
* @param integer Position
* @return boolean Result of the insert query
*/
function exercise_attempt($score,$answer,$quesId,$exeId,$j)
{
$score = Database::escape_string($score);
function exercise_attempt($score, $answer, $quesId, $exeId, $j, $exercise_id = 0) {
global $_configuration;
// If tracking is disabled record nothing
if (!$_configuration['tracking_enabled']) {
return 0;
}
$score = Database::escape_string($score);
$answer = Database::escape_string($answer);
$quesId = Database::escape_string($quesId);
$exeId = Database::escape_string($exeId);
$j = Database::escape_string($j);
global $_configuration, $_user, $_cid;
$exeId = Database::escape_string($exeId);
$j = Database::escape_string($j);
$TBL_TRACK_ATTEMPT = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_ATTEMPT);
//Validation in case of fraud with actived control time
$course_code = api_get_course_id();
$session_id = api_get_session_id();
$current_expired_time_key = $course_code.'_'.$session_id.'_'.$exeId;
if (isset($_SESSION['expired_time'][$current_expired_time_key])) { //Only for exercice of type "One page"
$current_time = time();
$expired_date = $_SESSION['expired_time'][$current_expired_time_key];
$expired_time = strtotime($expired_date);
$total_time_allowed = $expired_time + 30;
if ($total_time_allowed < $current_time) {
$score = 0;
$answer = 0;
$j = 0;
}
}
// if tracking is disabled record nothing
if (!$_configuration['tracking_enabled'])
{
return 0;
}
$reallyNow = time();
if (isset($_user['user_id']) && $_user['user_id']!='')
{
$user_id = "'".$_user['user_id']."'";
//Validation in case of fraud with actived control time
if (!exercise_time_control_is_valid($exercise_id)) {
$score = 0;
$answer = 0;
$j = 0;
}
else // anonymous
{
$reallyNow = api_get_utc_datetime();
$user_id = api_get_user_id();
if (!empty($user_id)) {
$user_id = "'".$user_id."'";
} else {
// anonymous
$user_id = api_get_anonymous_id();
}
$_SESSION['current_exercice_attempt'][$user_id] = $exeId;
$sql = "INSERT INTO $TBL_TRACK_ATTEMPT
(
$sql = "INSERT INTO $TBL_TRACK_ATTEMPT (
exe_id,
user_id,
question_id,
@ -535,37 +498,31 @@ function exercise_attempt($score,$answer,$quesId,$exeId,$j)
position,
tms
)
VALUES
(
VALUES (
".$exeId.",
".$user_id.",
'".$quesId."',
'".addslashes($answer)."',
'".$answer."',
'".$score."',
'".$_cid."',
'".api_get_course_id()."',
'".$j."',
FROM_UNIXTIME(".$reallyNow.")
'".$reallyNow."'
)";
if(defined('ENABLED_LIVE_EXERCISE_TRACKING')){
$TBL_RECORDING = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_ATTEMPT_RECORDING);
$recording_changes = 'INSERT INTO '.$TBL_RECORDING.' ' .
'(exe_id,
question_id,
marks,
insert_date,
author)
VALUES
('."'$exeId','".$quesId."','$score','".date('Y-m-d H:i:s')."',''".')';
Database::query($recording_changes);
}
if (!empty($quesId) && !empty($exeId) && !empty($user_id)) {
$res = Database::query($sql);
$res = Database::query($sql);
if (defined('ENABLED_LIVE_EXERCISE_TRACKING')){
$TBL_RECORDING = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_ATTEMPT_RECORDING);
$recording_changes = "INSERT INTO $TBL_RECORDING (exe_id, question_id, marks, insert_date, author) VALUES ('$exeId','$quesId','$score','".api_get_utc_datetime()."','') ";
Database::query($recording_changes);
error_log($recording_changes);
}
return $res;
} else {
return false;
}
}
/**
* Record an hotspot spot for this attempt at answering an hotspot question
* @param int Exercise ID
@ -576,36 +533,23 @@ function exercise_attempt($score,$answer,$quesId,$exeId,$j)
* @return boolean Result of the insert query
* @uses Course code and user_id from global scope $_cid and $_user
*/
function exercise_attempt_hotspot($exe_id, $question_id, $answer_id, $correct, $coords)
{
global $_configuration, $_user, $_cid;
function exercise_attempt_hotspot($exe_id, $question_id, $answer_id, $correct, $coords, $exerciseId = 0) {
global $_configuration, $_user;
// if tracking is disabled record nothing
if (!$_configuration['tracking_enabled'])
{
if (!$_configuration['tracking_enabled']) {
return 0;
}
//Validation in case of fraud with actived control time
$course_code = api_get_course_id();
$session_id = api_get_session_id();
$current_expired_time_key = $course_code.'_'.$session_id.'_'.$exe_id;
if (isset($_SESSION['expired_time'][$current_expired_time_key])) { //Only for exercice of type "One page"
$current_time = time();
$expired_date = $_SESSION['expired_time'][$current_expired_time_key];
$expired_time = strtotime($expired_date);
$total_time_allowed = $expired_time + 30;
if ($total_time_allowed < $current_time) {
$correct = 0;
}
if (!exercise_time_control_is_valid($exerciseId)) {
$correct = 0;
}
$tbl_track_e_hotspot = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_HOTSPOT);
$sql = "INSERT INTO $tbl_track_e_hotspot " .
"(hotspot_user_id, hotspot_course_code, hotspot_exe_id, hotspot_question_id, hotspot_answer_id, hotspot_correct, hotspot_coordinate)".
" VALUES ('" . Database :: escape_string($_user['user_id']) . "'," .
" '" . Database :: escape_string($_cid) . "', " .
" '" . api_get_course_id() . "', " .
" '" . Database :: escape_string($exe_id) . "', " .
" '" . Database :: escape_string($question_id) . "'," .
" '" . Database :: escape_string($answer_id) . "'," .
@ -674,4 +618,40 @@ function event_system($event_type, $event_value_type, $event_value, $timestamp =
$res = Database::query($sql);
return true;
}
?>
function get_last_attempt_date_of_exercise($exe_id) {
$exe_id = intval($exe_id);
$track_attempts = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_ATTEMPT);
$track_exercises = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES);
$sql_track_attempt = 'SELECT max(tms) as last_attempt_date FROM '.$track_attempts.' WHERE exe_id='.$exe_id;
error_log('$sql_track_attempt: '.$sql_track_attempt);
$rs_last_attempt = Database::query($sql_track_attempt);
$row_last_attempt = Database::fetch_array($rs_last_attempt);
$last_attempt_date = $row_last_attempt['last_attempt_date'];//Get the date of last attempt
return $last_attempt_date;
}
function get_attempt_count($user_id, $exerciseId, $lp_id, $lp_item_id) {
$stat_table = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES);
$user_id = intval($user_id);
$exerciseId = intval($exerciseId);
$lp_id = intval($lp_id);
$lp_item_id = intval($lp_item_id);
$sql = "SELECT count(*) as count FROM $stat_table WHERE exe_exo_id = '$exerciseId'
AND exe_user_id = '$user_id' AND status != 'incomplete'
AND orig_lp_id = $lp_id AND orig_lp_item_id = $lp_item_id AND exe_cours_id = '".api_get_course_id()."' AND session_id = '" . api_get_session_id() . "'";
$query = Database::query($sql);
if (Database::num_rows($query) > 0 ) {
$attempt = Database :: fetch_array($query,'ASSOC');
return $attempt['count'];
} else {
return 0;
}
}

@ -884,6 +884,14 @@ function api_get_real_course_id() {
return $GLOBALS['_real_cid'];
}
/**
* Returns the current course id (integer)
*/
function api_get_course_int_id() {
return $GLOBALS['_real_cid'];
}
/**
* Returns the current course directory
*
@ -4632,5 +4640,4 @@ function api_get_template($path_type = 'rel') {
}
$actived_theme_path = $template_path.$actived_theme.DIRECTORY_SEPARATOR;
return $actived_theme_path;
}
}
Loading…
Cancel
Save