$v)
{
$keyexp = explode('_',$key);
if ($keyexp[0] == "marks")
{
$sql = "SELECT question from $TBL_QUESTIONS where id = '".Database::escape_string($keyexp[1])."'";
$result =api_sql_query($sql, __FILE__, __LINE__);
$ques_name = mysql_result($result,0,"question");
$query = "UPDATE $TBL_TRACK_ATTEMPT SET marks = '".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__);
$qry = 'SELECT sum(marks) as tot
FROM '.$TBL_TRACK_ATTEMPT.' where exe_id = '.intval($id).'
GROUP BY question_id';
$res = api_sql_query($qry,__FILE__,__LINE__);
$tot = mysql_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
{
$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__);
}
}
$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'];
}
$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 = ''.
'
';
echo '';
}
// skips the last exercise, that is only used to know if we have or not to create a link "Next page"
if($i == $limitExPage)
{
break;
}
$i++;
} // end while()
$ind = $i;
if (($from+$limitExPage-1)>$nbrexerc)
{
if($from>$nbrexerc)
{
$from = $from - $nbrexerc;
$to = $limitExPage;
}
else
{
$to = $limitExPage-($nbrexerc-$from);
$from = 0;
}
}
else{
$to = $limitExPage;
}
if($is_allowedToEdit)
{
$sql = "SELECT d.path as path, d.comment as comment, ip.visibility as visibility
FROM $TBL_DOCUMENT d, $TBL_ITEM_PROPERTY ip
WHERE d.id = ip.ref AND ip.tool = '".TOOL_DOCUMENT."' AND
(d.path LIKE '%htm%')
AND d.path LIKE '".Database::escape_string($uploadPath)."/%/%' LIMIT ".(int)$from.",".(int)$to; // only .htm or .html files listed
}
else
{
$sql = "SELECT d.path as path, d.comment as comment, ip.visibility as visibility
FROM $TBL_DOCUMENT d, $TBL_ITEM_PROPERTY ip
WHERE d.id = ip.ref AND ip.tool = '".TOOL_DOCUMENT."' AND
(d.path LIKE '%htm%')
AND d.path LIKE '".Database::escape_string($uploadPath)."/%/%' AND ip.visibility='1' LIMIT ".(int)$from.",".(int)$to;
}
$result = api_sql_query ($sql,__FILE__,__LINE__);
while($row = Database::fetch_array($result, 'ASSOC'))
{
$attribute['path' ][] = $row['path' ];
$attribute['visibility'][] = $row['visibility'];
$attribute['comment' ][] = $row['comment' ];
}
$nbrActiveTests = 0;
if(is_array($attribute['path']))
{
while(list($key,$path) = each($attribute['path']))
{
list($a,$vis)=each($attribute['visibility']);
if (strcmp($vis,"1")==0)
{ $active=1;}
else
{ $active=0;}
echo "
\n";
$title = GetQuizName($path,$documentPath);
if ($title =='')
{
$title = GetFileName($path);
}
// prof only
if($is_allowedToEdit)
{
/************/
?>
$_user['user_id'] clause has been removed
$sql="SELECT CONCAT(lastname,' ',firstname),ce.title, te.exe_result ,
te.exe_weighting, UNIX_TIMESTAMP(te.exe_date),te.exe_Id,email, UNIX_TIMESTAMP(te.start_date),steps_counter
FROM $TBL_EXERCICES AS ce , $TBL_TRACK_EXERCICES AS te, $TBL_USER AS user
WHERE te.exe_exo_id = ce.id AND te.status != 'incomplete' AND user_id=te.exe_user_id AND te.exe_cours_id='$_cid' ";
switch ($_GET['column']) {
case 'username':
$sql .= ' order by lastname '.$ordering.', firstname ASC, ce.title ASC, te.exe_date ASC';
break;
case 'exercisename':
$sql .= ' order by ce.title '.$ordering.', te.exe_date ASC, lastname ASC, firstname ASC';
break;
case 'date':
$sql .= ' order by te.exe_date '.$ordering.',ce.title ASC, lastname ASC, firstname ASC';
break;
case '':
$sql .= ' ORDER BY te.exe_cours_id ASC, ce.title ASC, te.exe_date ASC';
break;
}
$hpsql="SELECT CONCAT(tu.lastname,' ',tu.firstname), tth.exe_name,
tth.exe_result , tth.exe_weighting, UNIX_TIMESTAMP(tth.exe_date)
FROM $TBL_TRACK_HOTPOTATOES tth, $TBL_USER tu
WHERE tu.user_id=tth.exe_user_id AND tth.exe_cours_id = '".$_cid."'";
switch ($_GET['column']) {
case 'username':
$hpsql .= ' order by tu.lastname '.$ordering.', tu.firstname ASC,tth.exe_date ASC,tth.exe_name ASC';
break;
case 'exercisename':
$hpsql .= ' order by tth.exe_name '.$ordering.', tth.exe_date ASC, tu.lastname ASC, tu.firstname ASC';
break;
case 'date':
$hpsql .= ' order by tth.exe_date '.$ordering.',tth.exe_name ASC, tu.lastname ASC, tu.firstname ASC';
break;
case '':
$hpsql .= ' ORDER BY tth.exe_cours_id ASC, tth.exe_date ASC';
break;
}
}
else
{// get only this user's results
$_uid = api_get_user_id();
$sql="SELECT '',ce.title, te.exe_result , te.exe_weighting, UNIX_TIMESTAMP(te.exe_date),te.exe_id
FROM $TBL_EXERCICES AS ce , $TBL_TRACK_EXERCICES AS te
WHERE te.exe_exo_id = ce.id AND te.exe_user_id='".$_uid."'AND te.status != 'incomplete' AND te.exe_cours_id='$_cid'";
switch ($_GET['column']) {
case 'exercisename':
$sql .= " order by ce.title $ordering, te.exe_date ASC";
break;
case 'date':
$sql .= " order by te.exe_date $ordering,ce.title ASC";
break;
case '':
$sql .= " ORDER BY te.exe_cours_id ASC, ce.title ASC, te.exe_date ASC";
break;
}
$hpsql="SELECT '',exe_name, exe_result , exe_weighting, UNIX_TIMESTAMP(exe_date)
FROM $TBL_TRACK_HOTPOTATOES
WHERE exe_user_id = '".$_uid."' AND exe_cours_id = '".$_cid."'";
switch ($_GET['column']) {
case 'exercisename':
$hpsql .= " order by exe_name $ordering, exe_date ASC";
break;
case 'date':
$hpsql .= " order by exe_date $ordering,exe_name ASC";
break;
case '':
$hpsql .= " ORDER BY exe_cours_id ASC, exe_date ASC";
break;
}
}
$results=getManyResultsXCol($sql,9);
$hpresults=getManyResultsXCol($hpsql,5);
$NoTestRes = 0;
$NoHPTestRes = 0;
//Print the results of tests
$lang_nostartdate = get_lang('NoStartDate').' / ';
if(is_array($results))
{
$sizeof = sizeof($results);
for($i = 0; $i < $sizeof; $i++)
{
$id = $results[$i][5];
$mailid = $results[$i][6];
$user = $results[$i][0];
$test = $results[$i][1];
$dt = strftime($dateTimeFormatLong,$results[$i][4]);
$res = $results[$i][2];
echo '