From 390c26584f1de00eef4975fc3013ce61fc2fbdfe Mon Sep 17 00:00:00 2001 From: Cristian Fasanando Date: Sun, 14 Dec 2008 03:26:03 +0100 Subject: [PATCH] [svn r17277] logic changes - added last changes in exercises of project dokeosla-usil into dokeos 1.8.6 (see FS#3249) --- main/exercice/exercice.php | 987 ++++++++++++++---------------- main/exercice/exercice_submit.php | 382 +++++------- 2 files changed, 626 insertions(+), 743 deletions(-) diff --git a/main/exercice/exercice.php b/main/exercice/exercice.php index 1557345d30..df2cab5207 100644 --- a/main/exercice/exercice.php +++ b/main/exercice/exercice.php @@ -1,4 +1,4 @@ -$v) - { + $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'); + foreach ($_POST as $key=>$v) { $keyexp = explode('_',$key); - if ($keyexp[0] == "marks") - { - $sql = "SELECT question from $TBL_QUESTIONS where id = '".Database::escape_string($keyexp[1])."'"; + if ($keyexp[0] == "marks") { + $sql = "select question from $TBL_QUESTIONS where id = '$keyexp[1]'"; $result =api_sql_query($sql, __FILE__, __LINE__); - $ques_name = mysql_result($result,0,"question"); + $ques_name = Database::result($result,0,"question"); $query = "UPDATE $TBL_TRACK_ATTEMPT SET marks = '".Database::escape_string($v)."' WHERE question_id = '".Database::escape_string($keyexp[1])."' @@ -165,67 +165,55 @@ if ($show=='result' && $_REQUEST['comments']=='update' && ($is_allowedToEdit || GROUP BY question_id'; $res = api_sql_query($qry,__FILE__,__LINE__); - $tot = mysql_result($res,0,'tot'); + $tot = Database::result($res,0,'tot'); $totquery = "update $TBL_TRACK_EXERCICES set exe_result = '".Database::escape_string($tot)."' where exe_Id='".Database::escape_string($id)."'"; api_sql_query($totquery, __FILE__, __LINE__); - // if this quiz is integrated in lps, we need to update the score in lp_view_item table - - // at first we need to get the id of the quiz - $sql = 'SELECT exe_exo_id FROM '.$TBL_TRACK_EXERCICES.' WHERE exe_id='.intval($id); - $rs = api_sql_query($sql,__FILE__,__LINE__); - $exercise_id_to_update = intval(Database::result($rs,0,0)); - - //then we need to get items where this quiz is integrated - $tbl_lp_item = Database::get_course_table(TABLE_LP_ITEM); - $sql = 'SELECT * FROM '.$tbl_lp_item.' WHERE item_type="quiz" AND path='.$exercise_id_to_update; - $rs_items = api_sql_query($sql,__FILE__,__LINE__); - while($lp_item = Database::fetch_array($rs_items)) - { - $tbl_lp_view = Database::get_course_table(TABLE_LP_VIEW); - - //we need to get last lp_view id of the user - $sql = 'SELECT id FROM '.$tbl_lp_view.' WHERE lp_id='.intval($lp_item['lp_id']).' AND user_id='.api_get_user_id().' ORDER BY view_count DESC LIMIT 1'; - $rs_view = api_sql_query($sql,__FILE__,__LINE__); - if($view_id = Database::result($rs_view,0,'id')) - { - // then we can update the score of the lp_view_item row - $tbl_lp_item_view = Database::get_course_table(TABLE_LP_ITEM_VIEW); - $sql = 'UPDATE '.$tbl_lp_item_view.' SET score='.intval($tot).' WHERE lp_view_id='.intval($view_id).' AND lp_item_id='.intval($lp_item['id']); - api_sql_query($sql, __FILE__, __LINE__); - } - - } - - // select the items where this quiz is integrated - } - else - { + $recording_changes = 'INSERT INTO '.$TBL_RECORDING.' ' . + '(exe_id, + question_id, + marks, + insert_date, + author) + VALUES + ('."'$id','".$keyexp[1]."','$v','".date('Y-m-d H:i:s')."','".api_get_user_id()."'".')'; + api_sql_query($recording_changes, __FILE__, __LINE__); + } else { $query = "UPDATE $TBL_TRACK_ATTEMPT SET teacher_comment = '".Database::escape_string($v)."' WHERE question_id = '".Database::escape_string($keyexp[1])."' AND exe_id = '".Database::escape_string($id)."'"; api_sql_query($query, __FILE__, __LINE__); - } + + $recording_changes = 'INSERT INTO '.$TBL_RECORDING.' ' . + '(exe_id, + question_id, + teacher_comment, + insert_date, + author) + VALUES + ('."'$id','".$keyexp[1]."','$v','".date('Y-m-d H:i:s')."','".api_get_user_id()."'".')'; + api_sql_query($recording_changes, __FILE__, __LINE__); - } + } - $qry = 'SELECT DISTINCT question_id, marks +} + +$qry = 'SELECT DISTINCT question_id, marks FROM '.$TBL_TRACK_ATTEMPT.' where exe_id = '.intval($id).' GROUP BY question_id'; - $res = api_sql_query($qry,__FILE__,__LINE__); - $tot = 0; - while($row = Database::fetch_array($res,'ASSOC')) - { - $tot += $row ['marks']; - } +$res = api_sql_query($qry,__FILE__,__LINE__); +$tot = 0; +while($row = Database::fetch_array($res,'ASSOC')) { + $tot += $row ['marks']; +} - $totquery = "UPDATE $TBL_TRACK_EXERCICES SET exe_result = '".Database::escape_string($tot)."' WHERE exe_Id='".Database::escape_string($id)."'"; +$totquery = "UPDATE $TBL_TRACK_EXERCICES SET exe_result = '".Database::escape_string($tot)."' WHERE exe_Id='".Database::escape_string($id)."'"; - api_sql_query($totquery, __FILE__, __LINE__); - $subject = get_lang('ExamSheetVCC'); - $htmlmessage = ''. +api_sql_query($totquery, __FILE__, __LINE__); +$subject = get_lang('ExamSheetVCC'); +$htmlmessage = ''. '' . '