Dokeos PHP Cross Reference Learning Management Systems

Source: /main/exercice/exercice.php - 1208 lines - 51659 bytes - Summary - Text - Print

Description: Exercise list: This script shows the list of exercises for administrators and students.

   1  <?php
   2  /* For licensing terms, see /dokeos_license.txt */
   3  
   4  /**
   5    ==============================================================================
   6   *     Exercise list: This script shows the list of exercises for administrators and students.
   7   *     @package dokeos.exercise
   8    ==============================================================================
   9   */
  10  // Language files that should be included
  11  //$language_file = 'exercice';
  12  $language_file = array('exercice','admin');
  13  
  14  // setting the help
  15  $help_content = 'exerciselist';
  16  
  17  // including the global library
  18  require_once  '../inc/global.inc.php';
  19  
  20  // including additional libraries
  21  require_once  '../gradebook/lib/be.inc.php';
  22  
  23  // setting the tabs
  24  $this_section = SECTION_COURSES;
  25  
  26  // access control
  27  api_protect_course_script(true);
  28  
  29  $show = (isset($_GET['show']) && $_GET['show'] == 'result') ? 'result' : 'test'; // moved down to fix bug: http://www.dokeos.com/forum/viewtopic.php?p=18609#18609
  30  // including additional libraries
  31  require_once  'exercise.class.php';
  32  require_once  'question.class.php';
  33  require_once  'answer.class.php';
  34  require_once api_get_path(LIBRARY_PATH) . 'fileManage.lib.php';
  35  require_once api_get_path(LIBRARY_PATH) . 'fileUpload.lib.php';
  36  require_once  'hotpotatoes.lib.php';
  37  require_once api_get_path(LIBRARY_PATH) . 'document.lib.php';
  38  require_once api_get_path(LIBRARY_PATH) . 'mail.lib.inc.php';
  39  require_once api_get_path(LIBRARY_PATH) . 'usermanager.lib.php';
  40  
  41  if (isset($_REQUEST['quizpopup']) && $_REQUEST['quizpopup'] == 1) {
  42    $htmlHeadXtra[] = '<script type="text/javascript" src="'.api_get_path(WEB_LIBRARY_PATH).'javascript/jquery-1.4.2.min.js" language="javascript"></script>';
  43    $htmlHeadXtra[] = '<script src="'.api_get_path(WEB_LIBRARY_PATH).'javascript/jquery.ui.all.js" type="text/javascript" language="javascript"></script>';
  44  }
  45  // Add the lp_id parameter to all links if the lp_id is defined in the uri
  46  if (isset($_GET['lp_id']) && $_GET['lp_id'] > 0) {
  47    $lp_id = Security::remove_XSS($_GET['lp_id']);
  48   $htmlHeadXtra[] = '<script>
  49      $(document).ready(function (){
  50        $("a[href]").attr("href", function(index, href) {
  51            var param = "lp_id=' . $lp_id . '";
  52             var is_javascript_link = false;
  53             var info = href.split("javascript");
  54  
  55             if (info.length >= 2) {
  56               is_javascript_link = true;
  57             }
  58             if ($(this).attr("class") == "course_main_home_button" || $(this).attr("class") == "course_menu_button"  || $(this).attr("class") == "next_button"  || $(this).attr("class") == "prev_button" || is_javascript_link) {
  59               return href;
  60             } else {
  61               if (href.charAt(href.length - 1) === "?")
  62                   return href + param;
  63               else if (href.indexOf("?") > 0)
  64                   return href + "&" + param;
  65               else
  66                   return href + "?" + param;
  67             }
  68        });
  69      });
  70    </script>';
  71  }
  72  // variable initialisation
  73  $is_allowedToEdit = api_is_allowed_to_edit();
  74  $is_tutor = api_is_allowed_to_edit(true);
  75  $is_tutor_course = api_is_course_tutor();
  76  $tbl_course_rel_user = Database :: get_main_table(TABLE_MAIN_COURSE_USER);
  77  $TBL_USER = Database :: get_main_table(TABLE_MAIN_USER);
  78  $TBL_DOCUMENT = Database :: get_course_table(TABLE_DOCUMENT);
  79  $TBL_ITEM_PROPERTY = Database :: get_course_table(TABLE_ITEM_PROPERTY);
  80  $TBL_EXERCICE_ANSWER = Database :: get_course_table(TABLE_QUIZ_ANSWER);
  81  $TBL_EXERCICE_QUESTION = Database :: get_course_table(TABLE_QUIZ_TEST_QUESTION);
  82  $TBL_EXERCICES = Database :: get_course_table(TABLE_QUIZ_TEST);
  83  $TBL_QUESTIONS = Database :: get_course_table(TABLE_QUIZ_QUESTION);
  84  $TBL_TRACK_EXERCICES = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES);
  85  $TBL_TRACK_HOTPOTATOES = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_HOTPOTATOES);
  86  $TBL_TRACK_ATTEMPT = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_ATTEMPT);
  87  $TBL_TRACK_ATTEMPT_RECORDING = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_ATTEMPT_RECORDING);
  88  $TBL_LP_ITEM_VIEW = Database :: get_course_table(TABLE_LP_ITEM_VIEW);
  89  $TBL_LP_ITEM = Database :: get_course_table(TABLE_LP_ITEM);
  90  $TBL_LP_VIEW = Database :: get_course_table(TABLE_LP_VIEW);
  91  
  92  
  93  // document path
  94  $documentPath = api_get_path(SYS_COURSE_PATH) . $_course['path'] . "/document";
  95  // picture path
  96  $picturePath = $documentPath . '/images';
  97  // audio path
  98  $audioPath = $documentPath . '/audio';
  99  
 100  // hotpotatoes
 101  $uploadPath = DIR_HOTPOTATOES; //defined in main_api
 102  $exercicePath = api_get_self();
 103  $exfile = explode('/', $exercicePath);
 104  $exfile = strtolower($exfile[sizeof($exfile) - 1]);
 105  $exercicePath = substr($exercicePath, 0, strpos($exercicePath, $exfile));
 106  $exercicePath = $exercicePath . "exercice.php";
 107  
 108  // maximum number of exercises on a same page
 109  $limitExPage = 50;
 110  
 111  // Clear the exercise session
 112  if (isset($_SESSION['objExercise'])) {
 113   api_session_unregister('objExercise');
 114  }
 115  if (isset($_SESSION['objQuestion'])) {
 116   api_session_unregister('objQuestion');
 117  }
 118  if (isset($_SESSION['objAnswer'])) {
 119   api_session_unregister('objAnswer');
 120  }
 121  if (isset($_SESSION['questionList'])) {
 122   api_session_unregister('questionList');
 123  }
 124  if (isset($_SESSION['exerciseResult'])) {
 125   api_session_unregister('exerciseResult');
 126  }
 127  if(isset($_POST['successcontent']))
 128  {
 129      $success_mailcontent = $_POST['successcontent'];
 130  }
 131  if(isset($_POST['failurecontent']))
 132  {
 133      $failure_mailcontent = $_POST['failurecontent'];
 134  }
 135  if(isset($_POST['quizstatus']))
 136  {
 137      $quizstatus = $_POST['quizstatus'];
 138  }
 139  if(isset($_POST['notes']))
 140  {
 141      $notes = $_POST['notes'];
 142  }
 143  
 144  //general POST/GET/SESSION/COOKIES parameters recovery
 145  if (empty($origin)) {
 146   $origin = Security::remove_XSS($_REQUEST['origin']);
 147  }
 148  if (empty($choice)) {
 149   $choice = $_REQUEST['choice'];
 150  }
 151  if (empty($hpchoice)) {
 152   $hpchoice = $_REQUEST['hpchoice'];
 153  }
 154  if (empty($exerciseId)) {
 155   $exerciseId = Security::remove_XSS($_REQUEST['exerciseId']);
 156  }
 157  if (empty($file)) {
 158   $file = $_REQUEST['file'];
 159  }
 160  
 161  if (isset($_SESSION['fromTpl'])) {
 162   $_SESSION['fromTpl'] = '';
 163  }
 164  if (isset($_SESSION['editQn'])) {
 165   $_SESSION['editQn'] = '';
 166  }
 167  $learnpath_id = Security::remove_XSS($_REQUEST['learnpath_id']);
 168  $learnpath_item_id = Security::remove_XSS($_REQUEST['learnpath_item_id']);
 169  $page = Security::remove_XSS($_REQUEST['page']);
 170  
 171  if ($origin == 'learnpath') {
 172   $show = 'result';
 173  }
 174  
 175  // redirect to exercise reporting page
 176  if ($show == 'result') {
 177      header('Location: '.api_get_path(WEB_CODE_PATH).'exercice/exercice_reporting.php?'.api_get_cidreq());
 178      exit;
 179  }
 180  
 181  
 182  
 183  if ($_GET['delete'] == 'delete' && ($is_allowedToEdit || api_is_coach()) && !empty($_GET['did']) && $_GET['did'] == strval(intval($_GET['did']))) {
 184   $sql = 'DELETE FROM ' . Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES) . ' WHERE exe_id = ' . Database::escape_string(Security::Remove_XSS($_GET['did'])); //_GET[did] filtered by entry condition
 185   api_sql_query($sql, __FILE__, __LINE__);
 186   $filter = Security::remove_XSS($_GET['filter']);
 187   header('Location: exercice.php?cidReq=' . Security::remove_XSS($_GET['cidReq']) . '&show=result&filter=' . $filter . '');
 188   exit;
 189  }
 190  
 191  if ($_REQUEST['comments'] == 'update' && ($is_allowedToEdit || $is_tutor) && $_GET['exeid'] == strval(intval($_GET['exeid']))) {
 192   $id = $_GET['exeid']; //filtered by post-condition
 193   $emailid = Security::remove_XSS($_GET['emailid']);
 194   $test = Security::remove_XSS($_GET['test']);
 195   $from = $_SESSION['_user']['mail'];
 196   $from_name = $_SESSION['_user']['firstName'] . " " . $_SESSION['_user']['lastName'];
 197   $url = api_get_path(WEB_CODE_PATH) . 'exercice/exercice.php?' . api_get_cidreq() . '&show=result';
 198   $TBL_RECORDING = Database :: get_statistic_table('track_e_attempt_recording');
 199   $total_weighting = Security::remove_XSS($_REQUEST['totalWeighting']);
 200  
 201   $my_post_info = array();
 202   $post_content_id = array();
 203   $comments_exist = false;
 204   foreach ($_POST as $key_index => $key_value) {
 205    $my_post_info = explode('_', $key_index);
 206    $post_content_id[] = $my_post_info[1];
 207    if ($my_post_info[0] == 'comments') {
 208     $comments_exist = true;
 209    }
 210   }
 211  
 212   $loop_in_track = ($comments_exist === true) ? (count($_POST) / 2) : count($_POST);
 213   $array_content_id_exe = array();
 214   if ($comments_exist === true) {
 215    $array_content_id_exe = array_slice($post_content_id, $loop_in_track);
 216   } else {
 217    $array_content_id_exe = $post_content_id;
 218   }
 219  
 220   for ($i = 0; $i < $loop_in_track; $i++) {
 221  
 222    $my_marks = $_POST['marks_' . $array_content_id_exe[$i]];
 223    $contain_comments = $_POST['comments_' . $array_content_id_exe[$i]];
 224  
 225    if (isset($contain_comments)) {
 226     $my_comments = $_POST['comments_' . $array_content_id_exe[$i]];
 227    } else {
 228     $my_comments = '';
 229    }
 230    $my_questionid = $array_content_id_exe[$i];
 231    $sql = "SELECT question from $TBL_QUESTIONS WHERE id = '" . Database::escape_string($my_questionid) . "'";
 232    $result = api_sql_query($sql, __FILE__, __LINE__);
 233    $ques_name = Database::result($result, 0, "question");
 234  
 235    $query = "UPDATE $TBL_TRACK_ATTEMPT SET marks = '" . Database::escape_string($my_marks) . "',teacher_comment = '" . Database::escape_string($my_comments) . "'
 236                        WHERE question_id = '" . Database::escape_string($my_questionid) . "'
 237                        AND exe_id='" . Database::escape_string($id) . "'";
 238    api_sql_query($query, __FILE__, __LINE__);
 239  
 240  
 241    $qry = 'SELECT sum(marks) as tot
 242                      FROM ' . $TBL_TRACK_ATTEMPT . ' WHERE exe_id = ' . Database::escape_string(intval($id)) . '
 243                      GROUP BY question_id';
 244  
 245    $res = api_sql_query($qry, __FILE__, __LINE__);
 246    $tot = Database::result($res, 0, 'tot');
 247    //updating also the total weight
 248    $totquery = "UPDATE $TBL_TRACK_EXERCICES SET exe_result = '" . Database::escape_string($tot) . "', exe_weighting = '" . Database::escape_string($total_weighting) . "'
 249                           WHERE exe_Id='" . Database::escape_string($id) . "'";
 250    api_sql_query($totquery, __FILE__, __LINE__);
 251    $recording_changes = "INSERT INTO " . $TBL_RECORDING . "
 252                              (exe_id, question_id, marks, insert_date, author, teacher_comment)
 253                          VALUES (
 254                              '" . Database::escape_string($id) . "',
 255                              '" . Database::escape_string($my_questionid) . "',
 256                              '" . Database::escape_string($my_marks) . "',
 257                              '" . date('Y-m-d H:i:s') . "',
 258                              '" . api_get_user_id() . "',
 259                              '" . Database::escape_string($my_comments) . "')";
 260    api_sql_query($recording_changes, __FILE__, __LINE__);
 261   }
 262   $post_content_id = array();
 263   $array_content_id_exe = array();
 264   /* foreach ($_POST as $key => $v) {
 265     $keyexp = explode('_', $key);
 266  
 267     $id = $id;
 268     $v = $v;
 269     $my_questionid = $keyexp[1];
 270  
 271     if ($keyexp[0] == "marks") {
 272     $sql = "SELECT question from $TBL_QUESTIONS WHERE id = '".Database::escape_string($my_questionid)."'";
 273     $result = api_sql_query($sql, __FILE__, __LINE__);
 274     $ques_name = Database :: result($result, 0, "question");
 275  
 276     $query = "UPDATE $TBL_TRACK_ATTEMPT SET marks = '" . $v . "'
 277     WHERE question_id = '" . Database::escape_string($my_questionid) . "'
 278     AND exe_id='" . Database::escape_string($id) . "'";
 279     api_sql_query($query, __FILE__, __LINE__);
 280  
 281     $qry = 'SELECT sum(marks) as tot
 282     FROM ' . $TBL_TRACK_ATTEMPT . ' WHERE exe_id = ' . Database::escape_string(intval($id)) . '
 283     GROUP BY question_id';
 284  
 285     $res = api_sql_query($qry, __FILE__, __LINE__);
 286     $tot = Database :: result($res, 0, 'tot');
 287     //updating also the total weight
 288     $totquery = "UPDATE $TBL_TRACK_EXERCICES SET exe_result = '" . Database :: escape_string($tot) . "', exe_weighting = '" . Database :: escape_string($total_weighting) . "'
 289     WHERE exe_Id='" . Database :: escape_string($id) . "'";
 290  
 291     api_sql_query($totquery, __FILE__, __LINE__);
 292  
 293     $recording_changes = "INSERT INTO " . $TBL_RECORDING . "(exe_id, question_id, marks, insert_date, author)
 294     VALUES (
 295     '" . Database::escape_string($id). "',
 296     '" . Database::escape_string($my_questionid) . "',
 297     '" . Database::escape_string($v) ."',
 298     '" . date('Y-m-d H:i:s') . "',
 299     '" . api_get_user_id() . "')";
 300     api_sql_query($recording_changes, __FILE__, __LINE__);
 301     } else {
 302     $query = "UPDATE $TBL_TRACK_ATTEMPT SET teacher_comment = '" . Database::escape_string($v) . "'
 303     WHERE question_id = '" . Database::escape_string($my_questionid) . "'
 304     AND exe_id = '" . Database::escape_string($id) . "')";
 305     api_sql_query($query, __FILE__, __LINE__);
 306  
 307     $recording_changes = "INSERT INTO " . $TBL_RECORDING . " (exe_id, question_id, teacher_comment, insert_date, author)
 308     VALUES (
 309     '" . Database::escape_string($id) ."',
 310     '" . Database::escape_string($my_questionid) . "',
 311     '" . Database::escape_string($v) . "',
 312     '" . date('Y-m-d H:i:s') . "',
 313     '" . api_get_user_id() . "')";
 314     api_sql_query($recording_changes, __FILE__, __LINE__);
 315     }
 316     } */
 317  
 318   $qry = 'SELECT DISTINCT question_id, marks
 319              FROM ' . $TBL_TRACK_ATTEMPT . ' as attempts 
 320              INNER JOIN '.$TBL_QUESTIONS.' as questions
 321                  ON questions.id = attempts.question_id
 322              where exe_id = ' . Database::escape_string(intval($id)) . '
 323              GROUP BY question_id';
 324  
 325   $res = api_sql_query($qry, __FILE__, __LINE__);
 326   $tot = 0;
 327   while ($row = Database :: fetch_array($res, 'ASSOC')) {
 328    $tot += $row['marks'];
 329   }
 330  
 331   $totquery = "UPDATE $TBL_TRACK_EXERCICES SET exe_result = '" . Database :: escape_string($tot) . "' WHERE exe_Id='" . Database :: escape_string($id) . "'";
 332  
 333   //search items
 334   if (isset($_POST['my_exe_exo_id']) && isset($_POST['student_id'])) {
 335    $sql_lp = 'SELECT li.id as lp_item_id,li.lp_id,li.item_type,li.path,liv.id AS lp_view_id,liv.user_id,max(liv.view_count) AS view_count FROM ' . $TBL_LP_ITEM . ' li
 336          INNER JOIN ' . $TBL_LP_VIEW . ' liv ON li.lp_id=liv.lp_id WHERE li.path="' . Database::escape_string(Security::remove_XSS($_POST['my_exe_exo_id'])) . '" AND li.item_type="quiz" AND user_id="' . Database::escape_string(Security::remove_XSS($_POST['student_id'])) . '" ';
 337    $rs_lp = Database::query($sql_lp, __FILE__, __LINE__);
 338    if (!($rs_lp === false)) {
 339     $row_lp = Database::fetch_array($rs_lp);
 340     //update score in learnig path
 341     $sql_lp_view = 'UPDATE ' . $TBL_LP_ITEM_VIEW . ' liv SET score ="' . Database::escape_string($tot) . '" WHERE liv.lp_item_id="' . Database::escape_string((int) $row_lp['lp_item_id']) . '" AND liv.lp_view_id="' . Database::escape_string((int) $row_lp['lp_view_id']) . '" AND liv.view_count="' . Database::escape_string((int) $row_lp['view_count']) . '" ;';
 342     $rs_lp_view = Database::query($sql_lp_view, __FILE__, __LINE__);
 343    }
 344   }
 345   Database::query($totquery, __FILE__, __LINE__);
 346  
 347  global $language_interface;
 348  $subject = get_lang('ExamSheetVCC');
 349  if($quizstatus == 'success')
 350  {
 351      $description = "Quizsuccess";
 352      $mailcontent = $successcontent;
 353  }
 354  else
 355  {
 356      $description = "Quizfailure";
 357      $mailcontent = $failurecontent;
 358  }
 359  
 360  if(empty($mailcontent)){
 361  $table_emailtemplate     = Database::get_main_table(TABLE_MAIN_EMAILTEMPLATES);
 362  $sql = "SELECT * FROM $table_emailtemplate WHERE description = '".$description."' AND language= '".$language_interface."'";
 363  $result = api_sql_query($sql, __FILE__, __LINE__);
 364  while($row = Database::fetch_array($result))
 365  {                
 366      $content = $row['content'];
 367  }
 368  if(empty($content))
 369  {
 370      $content = get_lang('DearStudentEmailIntroduction')."\n\n";
 371      $content .= get_lang('AttemptVCC')."\n\n";
 372      if($quizstatus == 'success'){
 373      $content .= get_lang('Quizsuccess')."\n\n";
 374      }
 375      else {
 376      $content .= get_lang('Quizfailure')."\n\n";
 377      }
 378      $content .= get_lang('Question').": {ques_name} \n";    
 379      $content .= get_lang('Exercice')." :{test} \n\n";
 380      $content .= get_lang('ClickLinkToViewComment')." - {url} \n\n";
 381      $content .= get_lang('Notes')."\n\n";    
 382      $content .= "{notes} \n\n";
 383      $content .= get_lang('Regards')."\n\n";    
 384      $content .= "{administratorSurname} \n";
 385      $content .= get_lang('Manager')."\n";
 386      $content .= "{administratorTelephone} \n";
 387      $content .= get_lang('Email')." : {emailAdministrator}";
 388  }
 389  }
 390  else {
 391      $content = $mailcontent;
 392  }
 393  /* $htmlmessage = '<html>' .
 394           '<head>' .
 395           '</head>' .
 396           '<body>' .
 397           '<div>' .
 398           '  <p>' . get_lang('DearStudentEmailIntroduction') . '</p>' .
 399           '  <p> ' . get_lang('AttemptVCC') . ' </p>' .
 400           '  <table width="417">' .
 401           '    <tr>' .
 402           '      <td width="229" valign="top" bgcolor="E5EDF8">&nbsp;&nbsp;<span>' . get_lang('Question') . '</span></td>' .
 403           '      <td width="469" valign="top" bgcolor="#F3F3F3"><span>#ques_name#</span></td>' .
 404           '    </tr>' .
 405           '    <tr>' .
 406           '      <td width="229" valign="top" bgcolor="E5EDF8">&nbsp;&nbsp;<span>' . get_lang('Exercice') . '</span></td>' .
 407           '       <td width="469" valign="top" bgcolor="#F3F3F3"><span>#test#</span></td>' .
 408           '    </tr>' .
 409           '  </table>' .
 410           '  <p>' . get_lang('ClickLinkToViewComment') . ' <a href="#url#">#url#</a><br />' .
 411           '    <br />' .
 412           '  ' . get_lang('Regards') . ' </p>' .
 413           '  </div>' .
 414           '  </body>' .
 415           '  </html>';
 416   $message = '<p>' . sprintf(get_lang('AttemptVCCLong'), Security::remove_XSS($test)) . ' <A href="#url#">#url#</A></p><br />';
 417   $mess = str_replace("#test#", Security::remove_XSS($test), $message);
 418   //$message= str_replace("#ques_name#",$ques_name,$mess);
 419   $message = str_replace("#url#", $url, $mess);
 420   $mess = $message;*/
 421   $content = str_replace("{ques_name}", $ques_name, $content);
 422   $content = str_replace("{test}", Security::remove_XSS($test), $content);
 423   $content = str_replace("{notes}", Security::remove_XSS($notes), $content);
 424   $content = str_replace("{url}", '<a href="'.$url.'">'.$url.'</a>', $content);
 425   $content = str_replace('{administratorSurname}',api_get_person_name(api_get_setting('administratorName'), api_get_setting('administratorSurname')), $content); 
 426   $content = str_replace('{administratorTelephone}',api_get_setting('administratorTelephone'), $content); 
 427   $content = str_replace('{emailAdministrator}',api_get_setting('emailAdministrator'), $content);
 428   $mess = $content;
 429   $headers = " MIME-Version: 1.0 \r\n";
 430   $headers .= "User-Agent: Dokeos/2.0";
 431   $headers .= "Content-Transfer-Encoding: 7bit";
 432   $headers .= 'From: ' . $from_name . ' <' . $from . '>' . "\r\n";
 433   $headers = "From:$from_name\r\nReply-to: $to\r\nContent-type: text/html; charset=" . ($charset ? $charset : 'ISO-8859-15');
 434   //mail($emailid, $subject, $mess,$headers);
 435  
 436   api_mail_html($emailid, $emailid, $subject, $mess, $from_name, $from);
 437   if (in_array($origin, array(
 438               'tracking_course',
 439               'user_course'
 440           ))) {
 441    if (isset($_POST['lp_item_id']) && isset($_POST['lp_item_view_id']) && isset($_POST['student_id']) && isset($_POST['total_score']) && isset($_POST['total_time']) && isset($_POST['totalWeighting'])) {
 442     $lp_item_id = $_POST['lp_item_id'];
 443     $lp_item_view_id = $_POST['lp_item_view_id'];
 444     $student_id = $_POST['student_id'];
 445     $totalWeighting = $_POST['totalWeighting'];
 446  
 447     if ($lp_item_id == strval(intval($lp_item_id)) && $lp_item_view_id == strval(intval($lp_item_view_id)) && $student_id == strval(intval($student_id))) {
 448      $score = $_POST['total_score'];
 449      $total_time = $_POST['total_time'];
 450      // get max view_count from lp_item_view
 451      /* $sql = "SELECT MAX(view_count) FROM $TBL_LP_ITEM_VIEW WHERE lp_item_id = '" . Database::escape_string((int) $lp_item_view_id) . "'
 452        AND lp_view_id = (SELECT id from $TBL_LP_VIEW  WHERE user_id = '" . Database::escape_string((int) $student_id) . "' and lp_id='" . Database::escape_string((int) $lp_item_id) . "')";
 453        $res_max_view_count = api_sql_query($sql, __FILE__, __LINE__);
 454        $row_max_view_count = Database :: fetch_row($res_max_view_count);
 455        $max_view_count = (int) $row_max_view_count[0];
 456  
 457        // update score and total_time from last attempt when you qualify the exercise in Learning path detail
 458        $sql_update_score = "UPDATE $TBL_LP_ITEM_VIEW SET score = '" . Database::escape_string((float) $score) . "',total_time = '" . Database::escape_string((int) $total_time) . "' WHERE lp_item_id = '" . Database::escape_string((int) $lp_item_view_id) . "'
 459        AND lp_view_id = (SELECT id from $TBL_LP_VIEW  WHERE user_id = '" . Database::escape_string((int) $student_id) . "' and lp_id='" . Database::escape_string((int) $lp_item_id) . "') AND view_count = '".Database::escape_string($max_view_count)."'";
 460        api_sql_query($sql_update_score, __FILE__, __LINE__);
 461  
 462        // update score and total_time from last attempt when you qualify the exercise in Learning path detail
 463        $sql_update_score = "UPDATE $TBL_LP_ITEM_VIEW SET score = '" . (float) $score . "',total_time = '" . Database::escape_string((int) $total_time) . "' WHERE lp_item_id = '" . Database::escape_string((int) $lp_item_view_id) . "'
 464        AND lp_view_id = (SELECT id from $TBL_LP_VIEW  WHERE user_id = '" . Database::escape_string((int) $student_id) . "' and lp_id='" . Database::escape_string((int) $lp_item_id) . "') AND view_count = '".Database::escape_string($max_view_count)."'";
 465        api_sql_query($sql_update_score, __FILE__, __LINE__); */
 466  
 467      // update max_score from a exercise in lp
 468      $sql_update_max_score = "UPDATE $TBL_LP_ITEM SET max_score = '" . Database::escape_string((float) $totalWeighting) . "'  WHERE id = '" . Database::escape_string((int) $lp_item_view_id) . "'";
 469  
 470      api_sql_query($sql_update_max_score, __FILE__, __LINE__);
 471     }
 472    }
 473    if ($origin == 'tracking_course' && !empty($_POST['lp_item_id'])) {
 474     //Redirect to the course detail in lp
 475     header('location: ../mySpace/lp_tracking.php?course=' . Security :: remove_XSS($_GET['course']) . '&origin=' . $origin . '&lp_id=' . Security :: remove_XSS($_POST['lp_item_id']) . '&student_id=' . Security :: remove_XSS($_GET['student']));
 476    } else {
 477     //Redirect to the reporting
 478     header('location: ../mySpace/myStudents.php?origin=' . $origin . '&student=' . Security :: remove_XSS($_GET['student']) . '&details=true&course=' . Security :: remove_XSS($_GET['course']));
 479    }
 480   } 
 481   header('Location: '.api_get_path(WEB_CODE_PATH).'exercice/exercice.php?'.api_get_cidreq().'&show=result');
 482   exit;
 483  }
 484  
 485  if (!empty($_GET['gradebook']) && $_GET['gradebook'] == 'view') {
 486   $_SESSION['gradebook'] = Security::remove_XSS($_GET['gradebook']);
 487   $gradebook = $_SESSION['gradebook'];
 488  } elseif (empty($_GET['gradebook'])) {
 489   unset($_SESSION['gradebook']);
 490   $gradebook = '';
 491  }
 492  
 493  if (!empty($gradebook) && $gradebook == 'view') {
 494   $interbreadcrumb[] = array(
 495       'url' => '../gradebook/' . $_SESSION['gradebook_dest'],
 496       'name' => get_lang('Gradebook')
 497   );
 498  }
 499  
 500  if ($show != 'result') {
 501   $nameTools = get_lang('Exercices');
 502  } 
 503  
 504  // need functions of statsutils lib to display previous exercices scores
 505  include_once (api_get_path(LIBRARY_PATH) . 'statsUtils.lib.inc.php');
 506  
 507  if ($is_allowedToEdit && !empty($choice) && $choice == 'exportqti2') {
 508   require_once  ('export/qti2/qti2_export.php');
 509   $export = export_exercise($exerciseId, true);
 510  
 511   require_once (api_get_path(LIBRARY_PATH) . 'pclzip/pclzip.lib.php');
 512   $archive_path = api_get_path(SYS_ARCHIVE_PATH);
 513   $temp_dir_short = uniqid();
 514   $temp_zip_dir = $archive_path . "/" . $temp_dir_short;
 515   if (!is_dir($temp_zip_dir))
 516    mkdir($temp_zip_dir);
 517   $temp_zip_file = $temp_zip_dir . "/" . md5(time()) . ".zip";
 518   $temp_xml_file = $temp_zip_dir . "/qti2export_" . $exerciseId . '.xml';
 519   file_put_contents($temp_xml_file, $export);
 520   $zip_folder = new PclZip($temp_zip_file);
 521   $zip_folder->add($temp_xml_file, PCLZIP_OPT_REMOVE_ALL_PATH);
 522   $name = 'qti2_export_' . $exerciseId . '.zip';
 523  
 524   //DocumentManager::string_send_for_download($export,true,'qti2export_'.$exerciseId.'.xml');
 525   DocumentManager :: file_send_for_download($temp_zip_file, true, $name);
 526   unlink($temp_zip_file);
 527   unlink($temp_xml_file);
 528   rmdir($temp_zip_dir);
 529   exit (); //otherwise following clicks may become buggy
 530  }
 531  if (!empty($_POST['export_user_fields'])) {
 532   switch ($_POST['export_user_fields']) {
 533    case 'export_user_fields' :
 534     $_SESSION['export_user_fields'] = true;
 535     break;
 536    case 'do_not_export_user_fields' :
 537    default :
 538     $_SESSION['export_user_fields'] = false;
 539     break;
 540   }
 541  }
 542  if (!empty($_POST['export_report']) && $_POST['export_report'] == 'export_report') {
 543   if (api_is_platform_admin() || api_is_course_admin() || api_is_course_tutor() || api_is_course_coach()) {
 544    $user_id = null;
 545    if (empty($_SESSION['export_user_fields']))
 546     $_SESSION['export_user_fields'] = false;
 547    if (!$is_allowedToEdit and !$is_tutor) {
 548     $user_id = api_get_user_id();
 549    }
 550    require_once  ('exercise_result.class.php');
 551    switch ($_POST['export_format']) {
 552     case 'xls' :
 553      $export = new ExerciseResult();
 554      $export->exportCompleteReportXLS($documentPath, $user_id, $_SESSION['export_user_fields']);
 555      exit;
 556      break;
 557     case 'csv' :
 558     default :
 559      $export = new ExerciseResult();
 560      $export->exportCompleteReportCSV($documentPath, $user_id, $_SESSION['export_user_fields']);
 561      exit;
 562      break;
 563    }
 564   } else {
 565    api_not_allowed(true);
 566   }
 567  }
 568  
 569  if (api_is_allowed_to_edit ()) {
 570   $htmlHeadXtra[] = '<link rel="stylesheet" href="' . api_get_path(WEB_LIBRARY_PATH) . 'javascript/thickbox.css" type="text/css" media="screen" />';
 571   $htmlHeadXtra[] = '<script type="text/javascript" src="' . api_get_path(WEB_LIBRARY_PATH) . 'javascript/thickbox.js"></script>';
 572   $htmlHeadXtra[] ='<script type="text/javascript">
 573  $(document).ready(function(){ 
 574  
 575      $(function() {
 576          $("#contentLeft ul").sortable({ opacity: 0.6, cursor: "move", cancel: ".nodrag", update: function() {
 577              var order = $(this).sortable("serialize") + "&action=updateQuiz";            
 578              var record = order.split("&");
 579              var recordlen = record.length;
 580              var disparr = new Array();
 581              for(var i=0;i<(recordlen-1);i++)
 582              {
 583               var recordval = record[i].split("=");
 584               disparr[i] = recordval[1];             
 585              }
 586              $.ajax({
 587              type: "GET",
 588              url: "exercise.ajax.php?'.api_get_cidReq().'&action=updateQuiz&disporder="+disparr,
 589              success: function(msg){
 590                               document.location="exercice.php?' . api_get_cidreq() . '";
 591                          }
 592          })            
 593          }
 594          });
 595      });
 596  
 597  });
 598  </script> ';
 599  }
 600  
 601  if ($origin != 'learnpath') {
 602   //so we are not in learnpath tool
 603   if (!isset($_REQUEST['quizpopup'])) {
 604  //  Display :: display_header($nameTools, "Exercise");
 605      Display :: display_tool_header();
 606   } else {
 607    Display::display_reduced_header($nameTools, 'Exercise');
 608   }
 609   if (isset($_GET['message'])) {
 610    if (in_array($_REQUEST['message'], array('ExerciseEdited'))) {
 611     Display :: display_confirmation_message(get_lang($_GET['message']));
 612    }
 613   }
 614  } else {
 615   echo '<link rel="stylesheet" type="text/css" href="' . api_get_path(WEB_CODE_PATH) . 'css/default.css"/>';
 616  }
 617  
 618  // tracking
 619  event_access_tool(TOOL_QUIZ);
 620  
 621  // Tool introduction
 622  Display :: display_introduction_section(TOOL_QUIZ);
 623  
 624  // selects $limitExPage exercises at the same time
 625  $from = $page * $limitExPage;
 626  $sql = "SELECT count(id) FROM $TBL_EXERCICES";
 627  $res = api_sql_query($sql, __FILE__, __LINE__);
 628  list ($nbrexerc) = Database :: fetch_array($res);
 629  
 630  HotPotGCt($documentPath, 1, $_user['user_id']);
 631  $tbl_grade_link = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_LINK);
 632  // only for administrator
 633  
 634  if ($is_allowedToEdit) {
 635  
 636   if (!empty($choice)) {
 637    // construction of Exercise
 638  
 639    $objExerciseTmp = new Exercise();
 640  
 641    if($choice == "multipledelete")
 642    {
 643        $del_quizid = array();
 644        $quizid = $_REQUEST['quizid'];
 645        $del_quizid = explode(",",$quizid);
 646        
 647        for($i=0;$i<sizeof($del_quizid);$i++)
 648        {          
 649            if ($objExerciseTmp->read($del_quizid[$i])) {
 650                $objExerciseTmp->delete();
 651                $sql = 'SELECT gl.id FROM ' . $tbl_grade_link . ' gl WHERE gl.type="1" AND gl.ref_id="' . Database::escape_string($exerciseId) . '";';
 652               $result = api_sql_query($sql, __FILE__, __LINE__);
 653               $row = Database :: fetch_array($result, 'ASSOC');
 654  
 655               $link = LinkFactory :: load($row['id']);
 656               if ($link[0] != null) {
 657                $link[0]->delete();
 658               }             
 659            }
 660        }
 661    }
 662  
 663    if ($objExerciseTmp->read($exerciseId)) {
 664     switch ($choice) {
 665      case 'delete' : // deletes an exercise
 666       $objExerciseTmp->delete();
 667  
 668       //delete link of exercise of gradebook tool
 669       $sql = 'SELECT gl.id FROM ' . $tbl_grade_link . ' gl WHERE gl.type="1" AND gl.ref_id="' . Database::escape_string($exerciseId) . '";';
 670       $result = api_sql_query($sql, __FILE__, __LINE__);
 671       $row = Database :: fetch_array($result, 'ASSOC');
 672  
 673       $link = LinkFactory :: load($row['id']);
 674       if ($link[0] != null) {
 675        $link[0]->delete();
 676       }
 677       Display :: display_confirmation_message(get_lang('ExerciseDeleted'));
 678       break;
 679      case 'enable' : // enables an exercise
 680       $objExerciseTmp->enable();
 681       $objExerciseTmp->save();
 682       // "WHAT'S NEW" notification: update table item_property (previously last_tooledit)
 683       Display :: display_confirmation_message(get_lang('VisibilityChanged'));
 684  
 685       break;
 686      case 'disable' : // disables an exercise
 687       $objExerciseTmp->disable();
 688       $objExerciseTmp->save();
 689       Display :: display_confirmation_message(get_lang('VisibilityChanged'));
 690       break;
 691      case 'disable_results' : //disable the results for the learners
 692       $objExerciseTmp->disable_results();
 693       $objExerciseTmp->save();
 694       Display :: display_confirmation_message(get_lang('ResultsDisabled'));
 695       break;
 696      case 'enable_results' : //disable the results for the learners
 697       $objExerciseTmp->enable_results();
 698       $objExerciseTmp->save();
 699       Display :: display_confirmation_message(get_lang('ResultsEnabled'));
 700       break;
 701      case 'integrate_quiz_in_lp':
 702       if (Security::check_token() && !empty($_POST['integrate_lp_id'])) { // if the form to integrate quiz in lp has been submitted
 703        Security::clear_token();
 704        $lp_id = intval($_POST['integrate_lp_id']);
 705        $quiz_title = $objExerciseTmp->selectTitle();
 706        require_once ('../newscorm/learnpath.class.php');
 707        $o_lp = new learnpath(api_get_course_id(), $lp_id, api_get_user_id());
 708        $previous = 0;
 709        if (count($o_lp->items) > 0) {
 710         $previous = $o_lp->get_last();
 711        }
 712        $o_lp->add_item(0, $previous, 'quiz', $exerciseId, $quiz_title, '');
 713        Display :: display_confirmation_message(get_lang('QuizIntegratedInCourse'));
 714       }
 715       break;
 716     }
 717    }
 718  
 719    // destruction of Exercise
 720    unset($objExerciseTmp);
 721   }
 722  
 723   if (!empty($hpchoice)) {
 724    switch ($hpchoice) {
 725     case 'delete' : // deletes an exercise
 726      $imgparams = array();
 727      $imgcount = 0;
 728      GetImgParams($file, $documentPath, $imgparams, $imgcount);
 729      $fld = GetFolderName($file);
 730      for ($i = 0; $i < $imgcount; $i++) {
 731       my_delete($documentPath . $uploadPath . "/" . $fld . "/" . $imgparams[$i]);
 732       update_db_info("delete", $uploadPath . "/" . $fld . "/" . $imgparams[$i]);
 733      }
 734  
 735      if (my_delete($documentPath . $file)) {
 736       update_db_info("delete", $file);
 737      }
 738      my_delete($documentPath . $uploadPath . "/" . $fld . "/");
 739      break;
 740     case 'enable' : // enables an exercise
 741      $newVisibilityStatus = "1"; //"visible"
 742      $query = "SELECT id FROM $TBL_DOCUMENT WHERE path='" . Database :: escape_string($file) . "'";
 743      $res = api_sql_query($query, __FILE__, __LINE__);
 744      $row = Database :: fetch_array($res, 'ASSOC');
 745      api_item_property_update($_course, TOOL_DOCUMENT, $row['id'], 'visible', $_user['user_id']);
 746      //$dialogBox = get_lang('ViMod');
 747  
 748      break;
 749     case 'disable' : // disables an exercise
 750      $newVisibilityStatus = "0"; //"invisible"
 751      $query = "SELECT id FROM $TBL_DOCUMENT WHERE path='" . Database :: escape_string($file) . "'";
 752      $res = api_sql_query($query, __FILE__, __LINE__);
 753      $row = Database :: fetch_array($res, 'ASSOC');
 754      api_item_property_update($_course, TOOL_DOCUMENT, $row['id'], 'invisible', $_user['user_id']);
 755      //$dialogBox = get_lang('ViMod');
 756      break;
 757     default :
 758      break;
 759    }
 760   }
 761  
 762   if ($show == 'test') {
 763    $sql = "SELECT id,title,type,active,description, results_disabled FROM $TBL_EXERCICES WHERE active<>'-1' ORDER BY title LIMIT " . (int) $from . "," . (int) ($limitExPage + 1);
 764    $result = api_sql_query($sql, __FILE__, __LINE__);
 765   }
 766  } elseif ($show == 'test') { // only for students //fin
 767   $sql = "SELECT id,title,type,description, results_disabled FROM $TBL_EXERCICES WHERE active='1' ORDER BY title LIMIT " . (int) $from . "," . (int) ($limitExPage + 1);
 768   $result = api_sql_query($sql, __FILE__, __LINE__);
 769  }
 770  
 771  // the actions
 772  echo '<div class="actions">';
 773  
 774  //echo '<a href="' . api_add_url_param($_SERVER['REQUEST_URI'], 'show=test') . '">' . Display :: return_icon('quiz.png', get_lang('BackToExercisesList')) . get_lang('BackToExercisesList') . '</a>';
 775  
 776  // display the next and previous link if needed
 777  $from = $page * $limitExPage;
 778  $sql = "SELECT count(id) FROM $TBL_EXERCICES";
 779  $res = api_sql_query($sql, __FILE__, __LINE__);
 780  list ($nbrexerc) = Database :: fetch_array($res);
 781  HotPotGCt($documentPath, 1, $_user['user_id']);
 782  // only for administrator
 783  if ($is_allowedToEdit) {
 784   if ($show == 'test') {
 785    $sql = "SELECT id,title,type,active,description, results_disabled FROM $TBL_EXERCICES q WHERE active<>'-1' ORDER BY position LIMIT " . (int) $from . "," . (int) ($limitExPage + 1);
 786    $result = api_sql_query($sql, __FILE__, __LINE__);
 787   }
 788  } elseif ($show == 'test') { // only for students
 789   $sql = "SELECT id,title,type,description, results_disabled FROM $TBL_EXERCICES WHERE active='1' ORDER BY position LIMIT " . (int) $from . "," . (int) ($limitExPage + 1);
 790   $result = api_sql_query($sql, __FILE__, __LINE__);
 791  }
 792  
 793  if ($show == 'test') {
 794   $nbrExercises = Database :: num_rows($result);
 795  
 796   //get HotPotatoes files (active and inactive)
 797   $res = api_sql_query("SELECT *
 798                          FROM $TBL_DOCUMENT
 799                          WHERE
 800                          path LIKE '" . Database :: escape_string($uploadPath) . "/%/%'", __FILE__, __LINE__);
 801   $nbrTests = Database :: num_rows($res);
 802   $res = api_sql_query("SELECT *
 803                          FROM $TBL_DOCUMENT d, $TBL_ITEM_PROPERTY ip
 804                          WHERE  d.id = ip.ref
 805                          AND ip.tool = '" . TOOL_DOCUMENT . "'
 806                          AND d.path LIKE '" . Database :: escape_string($uploadPath) . "/%/%'
 807                          AND ip.visibility='1'", __FILE__, __LINE__);
 808   $nbrActiveTests = Database :: num_rows($res);
 809  
 810   if ($is_allowedToEdit) {
 811    //if user is allowed to edit, also show hidden HP tests
 812    $nbrHpTests = $nbrTests;
 813   } else {
 814    $nbrHpTests = $nbrActiveTests;
 815   }
 816   $nbrNextTests = $nbrexerc - $nbrHpTests - (($page * $limitExPage));
 817  
 818   echo '<span style="float:right">';
 819   //show pages navigation link for previous page
 820   if ($page) {
 821    echo "<a href=\"" . api_get_self() . "?" . api_get_cidreq() . "&amp;page=" . ($page - 1) . "\">" . Display :: return_icon('prev.png') . get_lang("PreviousPage") . "</a> | ";
 822   } elseif ($nbrExercises + $nbrNextTests > $limitExPage) {
 823    echo Display :: return_icon('prev.png') . get_lang('PreviousPage') . " | ";
 824   }
 825  
 826   //show pages navigation link for previous page
 827   if ($nbrExercises + $nbrNextTests > $limitExPage) {
 828    echo "<a href=\"" . api_get_self() . "?" . api_get_cidreq() . "&amp;page=" . ($page + 1) . "\">" . get_lang("NextPage") . Display :: return_icon('next.png') . "</a>";
 829   } elseif ($page) {
 830    echo get_lang("NextPage") . Display :: return_icon('next.png');
 831   }
 832   echo '</span>';
 833  }
 834  
 835  if (($is_allowedToEdit) and ($origin != 'learnpath')) {
 836   if ($_GET['show'] != 'result') {
 837    echo '<a href="exercice.php?' . api_get_cidreq() . '">' . Display::return_icon('pixel.gif', get_lang('Move'), array('class' => 'toolactionplaceholdericon toolactionlist')) . get_lang('List') . '</a>';
 838    echo '<a href="exercise_admin.php?' . api_get_cidreq() . '">' . Display::return_icon('pixel.gif', get_lang('NewEx'), array('class' => 'toolactionplaceholdericon toolactionnewquiz'))  . get_lang('NewEx') . '</a>';  
 839  /*if (!isset($_GET['lp_id'])) {
 840     echo '<a href="upload_exercise.php?' . api_get_cidreq() . '">' . Display::return_icon('pixel.gif', get_lang('UploadQuiz'), array('class' => 'toolactionplaceholdericon toolactionexportcourse')) . get_lang('UploadQuiz') . '</a>';
 841    }*/
 842   }
 843  } else {
 844   //the student view
 845   if ($show == 'result') {
 846    
 847   } else {
 848    echo '<a href="' . api_add_url_param($_SERVER['REQUEST_URI'], 'show=result') . '">' . Display::return_icon('pixel.gif', get_lang("Results"), array('class' => 'toolactionplaceholdericon toolactionquizscores')) . get_lang('Results') . '</a>';
 849   }
 850  }
 851  
 852  echo '<script>
 853  function quiz_delete()
 854  {    
 855      var len = document.quiz_list.chk_quiz.length;
 856      var quizid = new Array();
 857      if(isNaN(len))
 858      {
 859          quizid = document.quiz_list.chk_quiz.value;
 860      }
 861      else
 862      {
 863          for(var i=0;i<len;i++)
 864          {
 865              if(document.quiz_list.chk_quiz[i].checked)
 866              {
 867                  quizid[i] = document.quiz_list.chk_quiz[i].value;            
 868              }
 869          }    
 870      }
 871  window.location.href = "'.api_get_self().'?'.api_get_cidReq().'&choice=multipledelete&quizid="+quizid;
 872  }
 873  </script>';
 874  
 875  echo '</div>'; // closing the actions div
 876  // start the content div
 877  if ($_GET['show'] == 'result') {
 878   $content_id = 'content';
 879  } else {
 880   $content_id = 'content_with_secondary_actions';
 881  }
 882  echo '<div id="content">';
 883  
 884  // showing the list of quizes
 885  if ($show == 'test') {
 886  ?>
 887  <form name="quiz_list" method="POST">
 888   <table id="table_quiz_list" class="data_table data_table_exercise" style="width:100%">
 889  <?php
 890  // table headers for teachers
 891   if (($is_allowedToEdit) and ($origin != 'learnpath')) {
 892  ?>
 893     <tr class="row_odd nodrop nodrag">
 894      <th width="8%"><?php echo get_lang('Move') ?></th>
 895      <th width="8%"><?php echo get_lang('Delete'); ?></th>
 896      <th width="3%">&nbsp;</th>
 897      <th width="8%"><?php echo get_lang('Modify') ?></th>
 898      <th align="left" width="40%"><?php echo get_lang('ExerciseName'); ?></th>
 899      <th width="9%"><?php echo get_lang('Questions') ?></th>
 900      <th width="9%"><?php echo get_lang('Visible'); ?></th>
 901      <th width="9%"><?php echo get_lang('Tracking'); ?></th>
 902      <th width="5%"><?php echo get_lang('Course'); ?></th>
 903     </tr>
 904  <?php
 905   } else {
 906  // table headers for students
 907  ?> 
 908       <tr>
 909     <th colspan="2"><?php echo get_lang('ExerciseName'); ?></th>
 910     <th style="width:200px;"><?php echo get_lang('State'); ?></th>
 911    </tr>
 912  <?php
 913   }
 914   echo "</table>";
 915  echo '<div id="contentWrap"><div id="contentLeft"><ul class="dragdrop nobullets ">';
 916   // show message if no HP test to show
 917   if (!($nbrExercises + $nbrHpTests)) {
 918  ?>
 919    <table width="100%"><tr>
 920     <td <?php echo ($is_allowedToEdit ? 'colspan="9"' : 'colspan="5"'); ?> align="center"><?php echo get_lang("NoEx"); ?></td>
 921    </tr></table>
 922  <?php
 923   }
 924   $i = 1;
 925   // while list exercises
 926   if ($origin != 'learnpath') {     
 927       
 928    //avoid sending empty parameters
 929    $myorigin = (empty($origin) ? '' : '&origin=' . $origin);
 930    $mylpid = (empty($learnpath_id) ? '' : '&learnpath_id=' . $learnpath_id);
 931    $mylpitemid = (empty($learnpath_item_id) ? '' : '&learnpath_item_id=' . $learnpath_item_id);
 932    while ($row = Database :: fetch_array($result)) {
 933     echo '<tr><td>';
 934     echo '<li id="recordsArray_' . $row['id'] . '" class="category">';
 935     echo '<div>';
 936     echo '<table class="data_table" width="100%">';
 937     if ($i % 2 == 0)
 938      $s_class = "row_odd";
 939     else
 940      $s_class = "row_even";
 941     // prof only
 942     if ($is_allowedToEdit) {
 943  //    echo '<tr class="' . $s_class . '" id="quiz_row_' . $row['id'] . '">' . "\n";
 944       echo '<tr class="' . $s_class . '">' . "\n";
 945  ?>
 946      <td width="8%" align="center" class="dragHandle" style="cursor:pointer"><?php echo Display::return_icon('pixel.gif', get_lang('Move'), array('class' => 'actionplaceholdericon actionsdraganddrop')); ?></td>
 947      <td class="nodrag" width="8%" valign="left" align="center"><input type="checkbox" name="chk_quiz" value="<?php echo $row['id']; ?>"></td>
 948      <td class="nodrag" width="3%" valign="left" align="center"><?php echo ($i + ($page * $limitExPage)) . '.'; ?></td>
 949      <td class="nodrag" width="8%" align="center"><a href="admin.php?exerciseId=<?php echo $row['id']; ?>&<?php echo api_get_cidreq() ?>"><?php echo Display::return_icon('pixel.gif', get_lang('Edit'), array('class' => 'actionplaceholdericon actionedit'));  ?></a></td>
 950   <?php $row['title'] = api_parse_tex($row['title']); ?>
 951      <td class="nodrag"  width="40%"><a href="exercice_submit.php?<?php echo api_get_cidreq() . $myorigin . $mylpid . $mylpitemid; ?>&amp;exerciseId=<?php echo $row['id']; ?>" <?php if (!$row['active'])
 952       echo 'class="invisible"'; ?>><?php echo $row['title']; ?></a></td>
 953      <td class="nodrag" width="9%" align="center"><?php
 954      $TBL_QUIZ_TYPE = Database::get_course_table(TABLE_QUIZ_TYPE);
 955      $sql_scenario = "SELECT count(*) FROM $TBL_QUIZ_TYPE WHERE exercice_id = ".$row['id']."  AND current_active = 1";
 956      $rs_scenario = Database::query($sql_scenario, __FILE__, __LINE__);
 957      $quiz_category = Database::result($rs_scenario, 0);
 958      if($quiz_category == 0)
 959      {
 960      $sql_quiz_question = "SELECT count(*) as count FROM " . $TBL_EXERCICE_QUESTION . " WHERE exercice_id='" . $row['id'] . "'";
 961      $rs_quiz_question = Database::query($sql_quiz_question, __FILE__, __LINE__);
 962      $number_questions = Database::result($rs_quiz_question, 0);
 963      }
 964      else
 965      {
 966              $sql1 = "SELECT category_id,quiz_level,number_of_question,scenario_type FROM $TBL_QUIZ_TYPE WHERE exercice_id = ".$row['id']. " AND current_active = 1";
 967              $result1 = Database::query($sql1, __FILE__, __LINE__);
 968              $total_questions = 0;
 969              while($row1 = Database::fetch_array($result1))
 970              {                
 971                  $sql_in = "SELECT DISTINCT(question.id) AS id FROM $TBL_EXERCICES quiz, $TBL_QUESTIONS question, $TBL_EXERCICE_QUESTION rel_question, $TBL_QUIZ_TYPE quiz_type WHERE quiz.id=rel_question.exercice_id AND rel_question.question_id = question.id AND quiz.id = quiz_type.exercice_id AND rel_question.exercice_id = quiz_type.exercice_id AND question.level = ".$row1['quiz_level']." AND question.category = ".$row1['category_id']." ORDER BY rel_question.question_order LIMIT ".$row1['number_of_question'];                
 972                  $result_in = Database::query($sql_in, __FILE__, __LINE__);
 973                  $nbrQuestions = Database::num_rows($result_in);
 974                  $total_questions = $total_questions + $nbrQuestions;
 975              }
 976              $number_questions = $total_questions;
 977      }
 978      echo $number_questions;
 979   ?></td>
 980  <!--<td  width="50" align="center">
 981       <a href="exercice.php?choice=delete&exerciseId=<?php echo $row['id']; ?>&<?php echo api_get_cidreq() ?>" onclick="javascript:if(!confirm('<?php echo addslashes(api_htmlentities(get_lang('AreYouSureToDelete'), ENT_QUOTES, $charset));
 982      echo " " . $row['title'];
 983      echo "?"; ?>')) return false;"><?php Display::display_icon('delete.png', get_lang('Delete')) ?></a>&nbsp;
 984      </td>-->
 985      <td class="nodrag" width="9%" align="center">
 986  <?php
 987      //if active
 988      if ($row['active']) {
 989  ?>
 990        <a href="exercice.php?choice=disable&page=<?php echo $page; ?>&exerciseId=<?php echo $row['id']; ?>&<?php echo api_get_cidreq() ?>"><?php echo Display::return_icon('pixel.gif', get_lang('Deactivate'), array('class' => 'actionplaceholdericon actionvisible')); ?></a>&nbsp;
 991  <?php
 992      } else {
 993       // else if not active
 994  ?>
 995       <a href="exercice.php?choice=enable&page=<?php echo $page; ?>&exerciseId=<?php echo $row['id']; ?>&<?php echo api_get_cidreq() ?>"><?php echo Display::return_icon('pixel.gif', get_lang('Activate'), array('class' => 'actionplaceholdericon actionvisible invisible')); ?></a>&nbsp;
 996    <?php
 997      }
 998    ?>
 999     </td>
1000     <td class="nodrag" width="9%"  align="center">
1001      <a href="tracking/by_questions.php?exerciceId=<?php echo $row['id']; ?>&<?php echo api_get_cidreq() ?>" title="<?php echo get_lang('ExercisesTracking') ?>"><?php echo Display::return_icon('pixel.gif', get_lang('ExercisesTracking'), array('class' => 'actionplaceholdericon actiontracking')); ?></a>
1002     </td>
1003     <td class="nodrag" width="9%" align="center">
1004      <a class="thickbox" href="integrate_quiz_in_course.php?quizId=<?php echo $row['id']; ?>&<?php echo api_get_cidreq() ?>&height=180&width=500" title="<?php echo get_lang('IntegrateQuizInCourse') ?>"><?php echo Display::return_icon('pixel.gif', get_lang('IntegrateQuizInCourse'), array('class' => 'actionplaceholdericon actionviewmodule')); ?></a>
1005     </td>
1006    </tr>
1007    <?php
1008     } else { // student only
1009      if ($i % 2 == 0)
1010       $s_class = "row_odd";
1011      else
1012       $s_class = "row_even";
1013    ?>
1014    <tr class="<?php echo $s_class; ?>">
1015     <td  style="width:40px;"><?php echo ($i + ($page * $limitExPage)) . '.'; ?></td>
1016     <td  style="width:40px;"><?php echo Display::return_icon('pixel.gif', '', array('class' => 'actionplaceholdericon actionstudentviewquiz'));?></td>
1017  <?php $row['title'] = api_parse_tex($row['title']); ?>
1018     <td align="left"><a href="exercice_submit.php?<?php echo api_get_cidreq() . $myorigin . $mylpid . $myllpitemid; ?>&exerciseId=<?php echo $row['id']; ?>"><?php echo $row['title']; ?></a></td>
1019     <td style="width:200px;" align="center"><?php
1020      $eid = $row['id'];
1021      $uid = api_get_user_id();
1022      //this query might be improved later on by ordering by the new "tms" field rather than by exe_id
1023      $qry = "SELECT * FROM $TBL_TRACK_EXERCICES
1024                          WHERE exe_exo_id = '" . Database :: escape_string($eid) . "' and exe_user_id = '" . Database :: escape_string($uid) . "' AND exe_cours_id = '" . api_get_course_id() . "' AND status <>'incomplete' AND orig_lp_id = 0 AND orig_lp_item_id = 0 AND session_id =  '" . api_get_session_id() . "'
1025                          ORDER BY exe_id DESC";
1026      $qryres = api_sql_query($qry);
1027      $num = Database :: num_rows($qryres);
1028  
1029      //hide the results
1030      $my_result_disabled = $row['results_disabled'];
1031      if ($my_result_disabled == 0) {
1032       if ($num > 0) {
1033        $row = Database :: fetch_array($qryres);
1034        $percentage = 0;
1035        if ($row['exe_weighting'] != 0) {
1036         $percentage = ($row['exe_result'] / $row['exe_weighting']) * 100;
1037        }
1038        echo get_lang('Attempted') . ' (' . get_lang('Score') . ': ';
1039        printf("%1.2f\n", $percentage);
1040        echo " %)";
1041       } else {
1042        echo get_lang('NotAttempted');
1043       }
1044      } else {
1045       echo get_lang('CantShowResults');
1046      }
1047  ?></td>
1048    </tr>
1049    <?php
1050     }
1051     // skips the last exercise, that is only used to know if we have or not to create a link "Next page"
1052     if ($i == $limitExPage) {
1053      break;
1054     }
1055     echo '</table></div></li></td></tr>';
1056     $i++;
1057    } // end while()
1058    
1059    echo '</form>';
1060  
1061    $ind = $i;
1062    if (($from + $limitExPage - 1) > $nbrexerc) {
1063     if ($from > $nbrexerc) {
1064      $from = $from - $nbrexerc;
1065      $to = $limitExPage;
1066     } else {
1067      $to = $limitExPage - ($nbrexerc - $from);
1068      $from = 0;
1069     }
1070    } else {
1071     $to = $limitExPage;
1072    }
1073  
1074    if ($is_allowedToEdit) {
1075     $sql = "SELECT d.path as path, d.comment as comment, ip.visibility as visibility
1076                              FROM $TBL_DOCUMENT d, $TBL_ITEM_PROPERTY ip
1077                                          WHERE   d.id = ip.ref AND ip.tool = '" . TOOL_DOCUMENT . "' AND
1078                                           (d.path LIKE '%htm%')
1079                                          AND   d.path  LIKE '" . Database :: escape_string($uploadPath) . "/%/%' LIMIT " . (int) $from . "," . (int) $to; // only .htm or .html files listed
1080    } else {
1081     $sql = "SELECT d.path as path, d.comment as comment, ip.visibility as visibility
1082                              FROM $TBL_DOCUMENT d, $TBL_ITEM_PROPERTY ip
1083                                              WHERE d.id = ip.ref AND ip.tool = '" . TOOL_DOCUMENT . "' AND
1084                                               (d.path LIKE '%htm%')
1085                                              AND   d.path  LIKE '" . Database :: escape_string($uploadPath) . "/%/%' AND ip.visibility='1' LIMIT " . (int) $from . "," . (int) $to;
1086    }
1087  
1088    $result = api_sql_query($sql, __FILE__, __LINE__);
1089    echo '<table>';
1090    while ($row = Database :: fetch_array($result, 'ASSOC')) {
1091     $attribute['path'][] = $row['path'];
1092     $attribute['visibility'][] = $row['visibility'];
1093     $attribute['comment'][] = $row['comment'];
1094    }
1095    $nbrActiveTests = 0;
1096    if (is_array($attribute['path'])) {
1097     while (list ($key, $path) = each($attribute['path'])) {
1098      list ($a, $vis) = each($attribute['visibility']);
1099      if (strcmp($vis, "1") == 0) {
1100       $active = 1;
1101      } else {
1102       $active = 0;
1103      }
1104      echo "<tr>\n";
1105  
1106      $title = GetQuizName($path, $documentPath);
1107      if ($title == '') {
1108       $title = basename($path);
1109      }
1110      // prof only
1111      if ($is_allowedToEdit) {
1112       /*      * ********* */
1113    ?>
1114  
1115       <tr>
1116        <td><img src="../img/jqz.gif" alt="HotPotatoes" /></td>
1117        <td><?php echo ($ind + ($page * $limitExPage)) . '.'; ?></td>
1118        <td><a href="showinframes.php?file=<?php echo $path ?>&cid=<?php echo $_course['official_code']; ?>&uid=<?php echo $_user['user_id']; ?>" <?php if (!$active)
1119        echo 'class="invisible"'; ?>><?php echo $title ?></a></td>
1120        <td></td>
1121        <td><a href="adminhp.php?hotpotatoesName=<?php echo $path; ?>"> <img src="../img/edit_link.png" border="0" alt="<?php echo api_htmlentities(get_lang('Modify'), ENT_QUOTES, $charset); ?>" /></a>
1122         <img src="../img/wizard_gray_small.gif" border="0" title="<?php echo api_htmlentities(get_lang('Edit'), ENT_QUOTES, $charset); ?>" alt="<?php echo api_htmlentities(get_lang('Edit'), ENT_QUOTES, $charset); ?>" />
1123         <a href="<?php echo $exercicePath; ?>?hpchoice=delete&amp;file=<?php echo $path; ?>" onclick="javascript:if(!confirm('<?php echo addslashes(api_htmlentities(get_lang('AreYouSure'), ENT_QUOTES, $charset) . $title . "?"); ?>')) return false;"><img src="../img/delete.png" border="0" alt="<?php echo api_htmlentities(get_lang('Delete'), ENT_QUOTES, $charset); ?>" /></a>
1124  <?php
1125       // if active
1126       if ($active) {
1127        $nbrActiveTests = $nbrActiveTests + 1;
1128  ?>
1129          <a href="<?php echo $exercicePath; ?>?hpchoice=disable&amp;page=<?php echo $page; ?>&amp;file=<?php echo $path; ?>"><img src="../img/visible.gif" border="0" alt="<?php echo api_htmlentities(get_lang('Deactivate'), ENT_QUOTES, $charset); ?>" /></a>
1130  <?php
1131       } else { // else if not active
1132  ?>
1133          <a href="<?php echo $exercicePath; ?>?hpchoice=enable&amp;page=<?php echo $page; ?>&amp;file=<?php echo $path; ?>"><img src="../img/invisible.gif" border="0" alt="<?php echo api_htmlentities(get_lang('Activate'), ENT_QUOTES, $charset); ?>" /></a>
1134  <?php
1135       }
1136       echo '<img src="../img/lp_quiz_na.gif" border="0" alt="" />';
1137       /*      * ************* */
1138  ?></td>
1139  <?php
1140      } else { // student only
1141       if ($active == 1) {
1142        $nbrActiveTests = $nbrActiveTests + 1;
1143  ?>
1144      <tr>
1145  
1146              <td><?php echo ($ind + ($page * $limitExPage)) . '.'; ?><!--<img src="../img/jqz.jpg" alt="HotPotatoes" />--></td>
1147       <td>&nbsp;</td>
1148       <td><a href="showinframes.php?<?php echo api_get_cidreq() . "&amp;file=" . $path . "&amp;cid=" . $_course['official_code'] . "&amp;uid=" . $_user['user_id'] . '"';
1149        if (!$active)
1150         echo 'class="invisible"'; ?>"><?php echo $title; ?></a></td>
1151       <td>&nbsp;</td><td>&nbsp;</td>
1152      </tr>
1153    <?php
1154       }
1155      }
1156    ?>
1157     <?php
1158      if ($ind == $limitExPage) {
1159       break;
1160      }
1161      if ($is_allowedToEdit) {
1162       $ind++;
1163      } else {
1164       if ($active == 1) {
1165        $ind++;
1166       }
1167      }
1168     }
1169    }
1170   } //end if ($origin != 'learnpath') {
1171     ?>
1172   </table>
1173   </ul></div></div>
1174  
1175  <?php
1176  echo '<div style="padding:5px 5px 5px 0px;">';
1177  if(api_is_allowed_to_edit() && $nbrExercises <> 0)
1178       {
1179          echo '<button class="cancel" type="button" name="submit_save" id="submit_save"  style="float:left;" onclick="quiz_delete()">'.get_lang('Delete').'</button>';
1180       }
1181  echo '</div>';
1182  
1183  // close the content div
1184   echo '</div>';
1185  ?>
1186  <div class="actions">
1187  <?php
1188    if (is_allowed_to_edit()) {
1189      if(api_get_setting('show_quizcategory') == 'true'){
1190      echo '<a href="exercise_category.php?' . api_get_cidreq() . '">' . Display :: return_icon('category_22.png', get_lang('Categories')) . get_lang('Categories') . '</a>';
1191      }    
1192      if (!isset($_GET['lp_id'])) {
1193      echo '<a href="upload_exercise.php?' . api_get_cidreq() . '">' . Display::return_icon('pixel.gif', get_lang('UploadQuiz'), array('class' => 'actionplaceholdericon actionuploadquiz')) . get_lang('UploadQuiz') . '</a>';
1194      }
1195  ?>
1196   <a href="exercice.php?<?php echo api_get_cidreq(); ?>&show=result"><?php echo Display::return_icon('pixel.gif', get_lang('Tracking'), array('class' => 'actionplaceholdericon actiontracking')) . get_lang('Tracking') ?></a>
1197       <!--><a href="<?php //echo api_add_url_param($_SERVER['REQUEST_URI'], 'show=export')?>"><?php //echo Display :: return_icon('down32.png', get_lang('Export')) . get_lang('Export')?></a><!-->
1198  <?php
1199    }
1200  ?>
1201  </div>
1202  
1203  <?php
1204  }
1205  
1206  // display footer
1207   Display :: display_footer();
1208   ?>

title

Description

title

Description

title

Description

title

title

Body