exercice.php 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Exercise list: This script shows the list of exercises for administrators and students.
  5. * @package chamilo.exercise
  6. * @author Olivier Brouckaert, original author
  7. * @author Denes Nagy, HotPotatoes integration
  8. * @author Wolfgang Schneider, code/html cleanup
  9. * @author Julio Montoya <gugli100@gmail.com>, lots of cleanup + several improvements
  10. * Modified by hubert.borderiou (question category)
  11. */
  12. /**
  13. * Code
  14. */
  15. // name of the language file that needs to be included
  16. $language_file = array('exercice','tracking');
  17. // including the global library
  18. require_once '../inc/global.inc.php';
  19. require_once '../gradebook/lib/be.inc.php';
  20. // Setting the tabs
  21. $this_section = SECTION_COURSES;
  22. $htmlHeadXtra[] = api_get_jquery_ui_js();
  23. $htmlHeadXtra[] = api_get_js('qtip2/jquery.qtip.min.js');
  24. $htmlHeadXtra[] = api_get_css(api_get_path(WEB_LIBRARY_PATH).'javascript/qtip2/jquery.qtip.min.css');
  25. // Access control
  26. api_protect_course_script(true);
  27. // including additional libraries
  28. require_once 'exercise.class.php';
  29. require_once 'exercise.lib.php';
  30. require_once 'question.class.php';
  31. require_once 'answer.class.php';
  32. require_once api_get_path(LIBRARY_PATH) . 'fileManage.lib.php';
  33. require_once api_get_path(LIBRARY_PATH) . 'fileUpload.lib.php';
  34. require_once 'hotpotatoes.lib.php';
  35. require_once api_get_path(LIBRARY_PATH) . 'document.lib.php';
  36. require_once api_get_path(LIBRARY_PATH) . 'mail.lib.inc.php';
  37. require_once api_get_path(LIBRARY_PATH)."groupmanager.lib.php"; // for group filtering
  38. /* Constants and variables */
  39. $is_allowedToEdit = api_is_allowed_to_edit(null,true);
  40. $is_tutor = api_is_allowed_to_edit(true);
  41. $is_tutor_course = api_is_course_tutor();
  42. $TBL_DOCUMENT = Database :: get_course_table(TABLE_DOCUMENT);
  43. $TBL_ITEM_PROPERTY = Database :: get_course_table(TABLE_ITEM_PROPERTY);
  44. $TBL_EXERCICE_QUESTION = Database :: get_course_table(TABLE_QUIZ_TEST_QUESTION);
  45. $TBL_EXERCICES = Database :: get_course_table(TABLE_QUIZ_TEST);
  46. $TBL_TRACK_EXERCICES = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES);
  47. $table_lp_item = Database::get_course_table(TABLE_LP_ITEM);
  48. // document path
  49. $documentPath = api_get_path(SYS_COURSE_PATH) . $_course['path'] . "/document";
  50. // picture path
  51. $picturePath = $documentPath . '/images';
  52. // audio path
  53. $audioPath = $documentPath . '/audio';
  54. // hotpotatoes
  55. $uploadPath = DIR_HOTPOTATOES; //defined in main_api
  56. $exercicePath = api_get_self();
  57. $exfile = explode('/', $exercicePath);
  58. $exfile = strtolower($exfile[sizeof($exfile) - 1]);
  59. $exercicePath = substr($exercicePath, 0, strpos($exercicePath, $exfile));
  60. $exercicePath = $exercicePath . "exercice.php";
  61. // Clear the exercise session
  62. if (isset ($_SESSION['objExercise'])) {
  63. api_session_unregister('objExercise');
  64. }
  65. if (isset ($_SESSION['objQuestion'])) {
  66. api_session_unregister('objQuestion');
  67. }
  68. if (isset ($_SESSION['objAnswer'])) {
  69. api_session_unregister('objAnswer');
  70. }
  71. if (isset ($_SESSION['questionList'])) {
  72. api_session_unregister('questionList');
  73. }
  74. if (isset ($_SESSION['exerciseResult'])) {
  75. api_session_unregister('exerciseResult');
  76. }
  77. //General POST/GET/SESSION/COOKIES parameters recovery
  78. if (empty ($origin)) {
  79. $origin = Security::remove_XSS($_REQUEST['origin']);
  80. }
  81. if (empty ($choice)) {
  82. $choice = $_REQUEST['choice'];
  83. }
  84. if (empty ($hpchoice)) {
  85. $hpchoice = $_REQUEST['hpchoice'];
  86. }
  87. if (empty ($exerciseId)) {
  88. $exerciseId = intval($_REQUEST['exerciseId']);
  89. }
  90. if (empty ($file)) {
  91. $file = Database :: escape_string($_REQUEST['file']);
  92. }
  93. $learnpath_id = intval($_REQUEST['learnpath_id']);
  94. $learnpath_item_id = intval($_REQUEST['learnpath_item_id']);
  95. $page = intval($_REQUEST['page']);
  96. $course_info = api_get_course_info();
  97. $course_id = api_get_course_int_id();
  98. if ($page < 0) {
  99. $page = 1;
  100. }
  101. if (!empty($_GET['gradebook']) && $_GET['gradebook']=='view' ) {
  102. $_SESSION['gradebook']=Security::remove_XSS($_GET['gradebook']);
  103. $gradebook= $_SESSION['gradebook'];
  104. } elseif (empty($_GET['gradebook'])) {
  105. unset($_SESSION['gradebook']);
  106. $gradebook= '';
  107. }
  108. if (!empty($gradebook) && $gradebook=='view') {
  109. $interbreadcrumb[] = array ('url' => '../gradebook/' . $_SESSION['gradebook_dest'],'name' => get_lang('ToolGradebook'));
  110. }
  111. if ($show != 'result') {
  112. $nameTools = get_lang('Exercices');
  113. } else {
  114. if ($is_allowedToEdit || $is_tutor) {
  115. $nameTools = get_lang('StudentScore');
  116. $interbreadcrumb[] = array("url" => "exercice.php?gradebook=$gradebook","name" => get_lang('Exercices'));
  117. $objExerciseTmp = new Exercise();
  118. if ($objExerciseTmp->read($exerciseId)) {
  119. $interbreadcrumb[] = array("url" => "admin.php?exerciseId=".$exerciseId, "name" => $objExerciseTmp->name);
  120. }
  121. } else {
  122. $nameTools = get_lang('YourScore');
  123. $interbreadcrumb[] = array ("url" => "exercice.php?gradebook=$gradebook","name" => get_lang('Exercices'));
  124. }
  125. }
  126. if ($is_allowedToEdit && !empty ($choice) && $choice == 'exportqti2') {
  127. require_once 'export/qti2/qti2_export.php';
  128. $export = export_exercise($exerciseId, true);
  129. require_once api_get_path(LIBRARY_PATH) . 'pclzip/pclzip.lib.php';
  130. $archive_path = api_get_path(SYS_ARCHIVE_PATH);
  131. $temp_dir_short = api_get_unique_id();
  132. $temp_zip_dir = $archive_path . "/" . $temp_dir_short;
  133. if (!is_dir($temp_zip_dir))
  134. mkdir($temp_zip_dir, api_get_permissions_for_new_directories());
  135. $temp_zip_file = $temp_zip_dir . "/" . api_get_unique_id() . ".zip";
  136. $temp_xml_file = $temp_zip_dir . "/qti2export_" . $exerciseId . '.xml';
  137. file_put_contents($temp_xml_file, $export);
  138. $zip_folder = new PclZip($temp_zip_file);
  139. $zip_folder->add($temp_xml_file, PCLZIP_OPT_REMOVE_ALL_PATH);
  140. $name = 'qti2_export_' . $exerciseId . '.zip';
  141. //DocumentManager::string_send_for_download($export,true,'qti2export_'.$exerciseId.'.xml');
  142. DocumentManager :: file_send_for_download($temp_zip_file, true, $name);
  143. unlink($temp_zip_file);
  144. unlink($temp_xml_file);
  145. rmdir($temp_zip_dir);
  146. exit; //otherwise following clicks may become buggy
  147. }
  148. $htmlHeadXtra[] = '<script>
  149. $(document).ready(function() {
  150. $(".link_tooltip").each(function(){
  151. $(this).qtip({
  152. content: $(this).find(".tooltip"),
  153. position: { at:"top right", my:"bottom left"},
  154. show: {
  155. event: false,
  156. ready: true // ... but show the tooltip when ready
  157. },
  158. hide: false, //
  159. });
  160. });
  161. });
  162. </script>';
  163. if ($origin != 'learnpath') {
  164. //so we are not in learnpath tool
  165. Display :: display_header($nameTools, get_lang('Exercise'));
  166. if (isset ($_GET['message'])) {
  167. if (in_array($_GET['message'], array ('ExerciseEdited'))) {
  168. Display :: display_confirmation_message(get_lang($_GET['message']));
  169. }
  170. }
  171. } else {
  172. //echo '<link rel="stylesheet" type="text/css" href="' . api_get_path(WEB_CODE_PATH) . 'css/default.css"/>';
  173. Display :: display_reduced_header();
  174. }
  175. event_access_tool(TOOL_QUIZ);
  176. // Tool introduction
  177. Display :: display_introduction_section(TOOL_QUIZ);
  178. HotPotGCt($documentPath, 1, api_get_user_id() );
  179. // only for administrator
  180. if ($is_allowedToEdit) {
  181. if (!empty($choice)) {
  182. // construction of Exercise
  183. $objExerciseTmp = new Exercise();
  184. $check = Security::check_token('get');
  185. if ($objExerciseTmp->read($exerciseId)) {
  186. if ($check) {
  187. switch ($choice) {
  188. case 'delete' : // deletes an exercise
  189. $objExerciseTmp->delete();
  190. require_once api_get_path(SYS_CODE_PATH).'gradebook/lib/gradebook_functions.inc.php';
  191. $link_id = is_resource_in_course_gradebook(api_get_course_id(), 1 , $exerciseId, api_get_session_id());
  192. if ($link_id !== false) {
  193. remove_resource_from_course_gradebook($link_id);
  194. }
  195. Display :: display_confirmation_message(get_lang('ExerciseDeleted'));
  196. break;
  197. case 'enable' : // enables an exercise
  198. $objExerciseTmp->enable();
  199. $objExerciseTmp->save();
  200. api_item_property_update($course_info, TOOL_QUIZ, $objExerciseTmp->id,'visible', api_get_user_id());
  201. // "WHAT'S NEW" notification: update table item_property (previously last_tooledit)
  202. Display :: display_confirmation_message(get_lang('VisibilityChanged'));
  203. break;
  204. case 'disable' : // disables an exercise
  205. $objExerciseTmp->disable();
  206. $objExerciseTmp->save();
  207. api_item_property_update($course_info, TOOL_QUIZ, $objExerciseTmp->id,'invisible', api_get_user_id());
  208. Display :: display_confirmation_message(get_lang('VisibilityChanged'));
  209. break;
  210. case 'disable_results' : //disable the results for the learners
  211. $objExerciseTmp->disable_results();
  212. $objExerciseTmp->save();
  213. Display :: display_confirmation_message(get_lang('ResultsDisabled'));
  214. break;
  215. case 'enable_results' : //disable the results for the learners
  216. $objExerciseTmp->enable_results();
  217. $objExerciseTmp->save();
  218. Display :: display_confirmation_message(get_lang('ResultsEnabled'));
  219. break;
  220. case 'clean_results' : //clean student results
  221. $quantity_results_deleted= $objExerciseTmp->clean_results();
  222. Display :: display_confirmation_message(sprintf(get_lang('XResultsCleaned'),$quantity_results_deleted));
  223. break;
  224. case 'copy_exercise' : //copy an exercise
  225. $objExerciseTmp->copy_exercise();
  226. Display :: display_confirmation_message(get_lang('ExerciseCopied'));
  227. break;
  228. }
  229. }
  230. }
  231. // destruction of Exercise
  232. unset ($objExerciseTmp);
  233. Security::clear_token();
  234. }
  235. if (!empty($hpchoice)) {
  236. switch($hpchoice) {
  237. case 'delete' : // deletes an exercise
  238. $imgparams = array ();
  239. $imgcount = 0;
  240. GetImgParams($file, $documentPath, $imgparams, $imgcount);
  241. $fld = GetFolderName($file);
  242. for ($i = 0; $i < $imgcount; $i++) {
  243. my_delete($documentPath . $uploadPath . "/" . $fld . "/" . $imgparams[$i]);
  244. update_db_info("delete", $uploadPath . "/" . $fld . "/" . $imgparams[$i]);
  245. }
  246. if (my_delete($documentPath . $file)) {
  247. update_db_info("delete", $file);
  248. }
  249. my_delete($documentPath . $uploadPath . "/" . $fld . "/");
  250. break;
  251. case 'enable' : // enables an exercise
  252. $newVisibilityStatus = "1"; //"visible"
  253. $query = "SELECT id FROM $TBL_DOCUMENT WHERE c_id = $course_id AND path='" . Database :: escape_string($file) . "'";
  254. $res = Database::query($query);
  255. $row = Database :: fetch_array($res, 'ASSOC');
  256. api_item_property_update($_course, TOOL_DOCUMENT, $row['id'], 'visible', $_user['user_id']);
  257. //$dialogBox = get_lang('ViMod');
  258. break;
  259. case 'disable' : // disables an exercise
  260. $newVisibilityStatus = "0"; //"invisible"
  261. $query = "SELECT id FROM $TBL_DOCUMENT WHERE c_id = $course_id AND path='" . Database :: escape_string($file) . "'";
  262. $res = Database::query($query);
  263. $row = Database :: fetch_array($res, 'ASSOC');
  264. api_item_property_update($_course, TOOL_DOCUMENT, $row['id'], 'invisible', $_user['user_id']);
  265. break;
  266. default :
  267. break;
  268. }
  269. }
  270. }
  271. // Actions div bar
  272. if ($is_allowedToEdit) {
  273. echo '<div class="actions">';
  274. }
  275. // Selects $limit exercises at the same time
  276. // maximum number of exercises on a same page
  277. $limit = 50;
  278. // Display the next and previous link if needed
  279. $from = $page * $limit;
  280. HotPotGCt($documentPath, 1, api_get_user_id());
  281. //condition for the session
  282. $session_id = api_get_session_id();
  283. $condition_session = api_get_session_condition($session_id,true,true);
  284. // Only for administrators
  285. if ($is_allowedToEdit) {
  286. $total_sql = "SELECT count(id) as count FROM $TBL_EXERCICES WHERE c_id = $course_id AND active<>'-1' $condition_session ";
  287. $sql = "SELECT * FROM $TBL_EXERCICES WHERE c_id = $course_id AND active<>'-1' $condition_session ORDER BY title LIMIT ".$from."," .$limit;
  288. } else {
  289. // Only for students
  290. $total_sql = "SELECT count(id) as count FROM $TBL_EXERCICES WHERE c_id = $course_id AND active = '1' $condition_session ";
  291. $sql = "SELECT id, title, type, description, results_disabled, session_id, start_time, end_time, max_attempt FROM $TBL_EXERCICES
  292. WHERE c_id = $course_id AND
  293. active='1' $condition_session
  294. ORDER BY title LIMIT ".$from."," .$limit;
  295. }
  296. $result = Database::query($sql);
  297. $exercises_count = Database :: num_rows($result);
  298. $result_total = Database::query($total_sql);
  299. $total_exercises = 0;
  300. if (Database :: num_rows($result_total)) {
  301. $result_total = Database::fetch_array($result_total);
  302. $total_exercises = $result_total['count'];
  303. }
  304. //get HotPotatoes files (active and inactive)
  305. if ($is_allowedToEdit) {
  306. $sql = "SELECT * FROM $TBL_DOCUMENT WHERE c_id = $course_id AND path LIKE '" . Database :: escape_string($uploadPath) . "/%/%'";
  307. $res = Database::query($sql);
  308. $hp_count = Database :: num_rows($res);
  309. } else {
  310. $sql = "SELECT * FROM $TBL_DOCUMENT d, $TBL_ITEM_PROPERTY ip
  311. WHERE d.id = ip.ref AND
  312. ip.tool = '" . TOOL_DOCUMENT . "' AND
  313. d.path LIKE '" . Database :: escape_string($uploadPath) . "/%/%' AND
  314. ip.visibility ='1' AND
  315. d.c_id = ".$course_id." AND
  316. ip.c_id = ".$course_id;
  317. $res = Database::query($sql);
  318. $hp_count = Database :: num_rows($res);
  319. }
  320. $total = $total_exercises + $hp_count;
  321. if ($is_allowedToEdit && $origin != 'learnpath') {
  322. echo '<a href="exercise_admin.php?' . api_get_cidreq() . '">' . Display :: return_icon('new_exercice.png', get_lang('NewEx'),'','32').'</a>';
  323. echo '<a href="question_create.php?' . api_get_cidreq() . '">' . Display :: return_icon('new_question.png', get_lang('AddQ'),'','32').'</a>';
  324. // Question category
  325. echo '<a href="tests_category.php">';
  326. echo Display::return_icon('question_category_show.gif', get_lang('QuestionCategory'));
  327. echo '</a>';
  328. echo '<a href="question_pool.php">';
  329. echo Display::return_icon('database.png', get_lang('langQuestionPool'), array('style'=>'width:32px'));
  330. echo '</a>';
  331. // end question category
  332. echo '<a href="hotpotatoes.php?' . api_get_cidreq() . '">' . Display :: return_icon('import_hotpotatoes.png', get_lang('ImportHotPotatoesQuiz'),'','32').'</a>';
  333. // link to import qti2 ...
  334. echo '<a href="qti2.php?' . api_get_cidreq() . '">' . Display :: return_icon('import_qti2.png', get_lang('ImportQtiQuiz'),'','32') .'</a>';
  335. echo '<a href="upload_exercise.php?' . api_get_cidreq() . '">' . Display :: return_icon('import_excel.png', get_lang('ImportExcelQuiz'),'','32') .'</a>';
  336. }
  337. if ($is_allowedToEdit) {
  338. echo '</div>'; // closing the actions div
  339. }
  340. if ($total > $limit) {
  341. echo '<div style="float:right;height:20px;">';
  342. //show pages navigation link for previous page
  343. if ($page) {
  344. echo "<a href=\"" . api_get_self() . "?" . api_get_cidreq() . "&amp;page=" . ($page -1) . "\">" . Display :: return_icon('action_prev.png', get_lang('PreviousPage'))."</a>";
  345. } elseif ($total_exercises + $hp_count > $limit) {
  346. echo Display :: return_icon('action_prev_na.png', get_lang('PreviousPage'));
  347. }
  348. //show pages navigation link for previous page
  349. if ($total_exercises > $from + $limit || $hp_count > $from + $limit ) {
  350. echo ' '."<a href=\"" . api_get_self() . "?" . api_get_cidreq() . "&amp;page=" . ($page +1) . "\">" .Display::return_icon('action_next.png', get_lang('NextPage')) . "</a>";
  351. } elseif ($page) {
  352. echo ' '.Display :: return_icon('action_next_na.png', get_lang('NextPage'));
  353. }
  354. echo '</div>';
  355. }
  356. $i =1;
  357. $lis = '';
  358. $exercise_list = array();
  359. $online_icon = Display::return_icon('online.png', get_lang('Visible'),array('width'=>'12px'));
  360. $offline_icon = Display::return_icon('offline.png',get_lang('Invisible'),array('width'=>'12px'));
  361. while ($row = Database :: fetch_array($result,'ASSOC')) {
  362. $exercise_list[] = $row;
  363. }
  364. echo '<table class="data_table">';
  365. if (!empty($exercise_list)) {
  366. /* Listing exercises */
  367. if ($origin != 'learnpath') {
  368. //avoid sending empty parameters
  369. $myorigin = (empty ($origin) ? '' : '&origin=' . $origin);
  370. $mylpid = (empty ($learnpath_id) ? '' : '&learnpath_id=' . $learnpath_id);
  371. $mylpitemid = (empty ($learnpath_item_id) ? '' : '&learnpath_item_id=' . $learnpath_item_id);
  372. $token = Security::get_token();
  373. $i=1;
  374. if ($is_allowedToEdit) {
  375. $headers = array(array('name' => get_lang('ExerciseName')),
  376. array('name' => get_lang('QuantityQuestions'), 'params' => array('width'=>'100px')),
  377. array('name' => get_lang('Actions'), 'params' => array('width'=>'180px')));
  378. } else {
  379. $headers = array(array('name' => get_lang('ExerciseName')),
  380. array('name' => get_lang('Status')),
  381. array('name' => get_lang('Results')));
  382. }
  383. $header_list = '';
  384. foreach($headers as $header) {
  385. $params = isset($header['params'])? $header['params'] : null;
  386. $header_list .= Display::tag('th', $header['name'], $params);
  387. }
  388. echo Display::tag('tr', $header_list);
  389. $count = 0;
  390. if (!empty($exercise_list))
  391. foreach ($exercise_list as $row) {
  392. $my_exercise_id = $row['id'];
  393. //echo '<div id="tabs-'.$i.'">';
  394. $i++;
  395. //validacion when belongs to a session
  396. $session_img = api_get_session_image($row['session_id'], $_user['status']);
  397. $time_limits = false;
  398. if ($row['start_time'] != '0000-00-00 00:00:00' || $row['end_time'] != '0000-00-00 00:00:00') {
  399. $time_limits = true;
  400. }
  401. if ($time_limits) {
  402. // check if start time
  403. $start_time = false;
  404. if ($row['start_time'] != '0000-00-00 00:00:00') {
  405. $start_time = api_strtotime($row['start_time'],'UTC');
  406. }
  407. $end_time = false;
  408. if ($row['end_time'] != '0000-00-00 00:00:00') {
  409. $end_time = api_strtotime($row['end_time'],'UTC');
  410. }
  411. $now = time();
  412. $is_actived_time = false;
  413. //If both "clocks" are enable
  414. if ($start_time && $end_time) {
  415. if ($now > $start_time && $end_time > $now ) {
  416. $is_actived_time = true;
  417. }
  418. } else {
  419. //we check the start and end
  420. if ($start_time) {
  421. if ($now > $start_time) {
  422. $is_actived_time = true;
  423. }
  424. }
  425. if ($end_time) {
  426. if ($end_time > $now ) {
  427. $is_actived_time = true;
  428. }
  429. }
  430. }
  431. }
  432. //Blocking empty start times see BT#2800
  433. global $_custom;
  434. if (isset($_custom['exercises_hidden_when_no_start_date']) && $_custom['exercises_hidden_when_no_start_date']) {
  435. if (empty($row['start_time']) || $row['start_time'] == '0000-00-00 00:00:00') {
  436. $time_limits = true;
  437. $is_actived_time = false;
  438. }
  439. }
  440. // Teacher only
  441. if ($is_allowedToEdit) {
  442. $show_quiz_edition = true;
  443. $sql="SELECT max_score FROM $table_lp_item
  444. WHERE c_id = $course_id AND
  445. item_type = '".TOOL_QUIZ."' AND
  446. path ='".Database::escape_string($row['id'])."'";
  447. $result = Database::query($sql);
  448. if (Database::num_rows($result) > 0) {
  449. $show_quiz_edition = false;
  450. }
  451. $lp_blocked = '';
  452. if (!$show_quiz_edition) {
  453. $lp_blocked = Display::tag('font', '<i>'.get_lang('AddedToALP').'</i>', array('style'=>'color:grey'));
  454. }
  455. //Showing exercise title
  456. $row['title'] = cut($row['title'], EXERCISE_MAX_NAME_SIZE);
  457. if ($session_id == $row['session_id']) {
  458. //Settings
  459. //echo Display::url(Display::return_icon('settings.png',get_lang('Edit'), array('width'=>'22px'))." ".get_lang('Edit'), 'exercise_admin.php?'.api_get_cidreq().'&modifyExercise=yes&exerciseId='.$row['id']);
  460. }
  461. if ($row['active'] == 0) {
  462. $title = Display::tag('font', $row['title'], array('style'=>'color:grey'));
  463. } else {
  464. $title = $row['title'];
  465. }
  466. $count = intval(count_exercise_result_not_validated($my_exercise_id, $course_code, $session_id));
  467. $class_tip = '';
  468. if (!empty($count)) {
  469. $results_text = $count == 1 ? get_lang('ResultNotRevised') : get_lang('ResultsNotRevised');
  470. $title .= '<span class="tooltip" style="display: none;">'.$count.' '.$results_text.' </span>';
  471. $class_tip = 'link_tooltip';
  472. }
  473. $url = '<a class="'.$class_tip.'" id="tooltip_'.$row['id'].'" href="overview.php?'.api_get_cidreq().$myorigin.$mylpid.$mylpitemid.'&exerciseId='.$row['id'].'"><img src="../img/quiz.gif" /> '.$title.' </a>'.$lp_blocked;
  474. $item = Display::tag('td', $url.' '.$session_img);
  475. //count number exercice - teacher
  476. $sqlquery = "SELECT count(*) FROM $TBL_EXERCICE_QUESTION WHERE c_id = $course_id AND exercice_id = $my_exercise_id";
  477. $sqlresult = Database::query($sqlquery);
  478. $rowi = Database :: result($sqlresult, 0);
  479. if ($session_id == $row['session_id']) {
  480. //Settings
  481. $actions = Display::url(Display::return_icon('edit.png',get_lang('Edit'),'',22), 'admin.php?'.api_get_cidreq().'&exerciseId='.$row['id']);
  482. $actions .='<a href="exercise_report.php?' . api_get_cidreq() . '&exerciseId='.$row['id'].'">'.Display :: return_icon('test_results.png', get_lang('Results'),'',22).'</a>';
  483. //Export
  484. $actions .= Display::url(Display::return_icon('cd.gif', get_lang('CopyExercise')), '', array('onclick'=>"javascript:if(!confirm('".addslashes(api_htmlentities(get_lang('AreYouSureToCopy'),ENT_QUOTES,$charset))." ".addslashes($row['title'])."?"."')) return false;",'href'=>'exercice.php?'.api_get_cidreq().'&choice=copy_exercise&sec_token='.$token.'&exerciseId='.$row['id']));
  485. //Clean exercise
  486. $actions .= Display::url(Display::return_icon('clean.png', get_lang('CleanStudentResults'),'',22),'', array('onclick'=>"javascript:if(!confirm('".addslashes(api_htmlentities(get_lang('AreYouSureToDeleteResults'),ENT_QUOTES,$charset))." ".addslashes($row['title'])."?"."')) return false;",'href'=>'exercice.php?'.api_get_cidreq().'&choice=clean_results&sec_token='.$token.'&exerciseId='.$row['id']));
  487. //Visible / invisible
  488. if ($row['active']) {
  489. $actions .= Display::url(Display::return_icon('visible.png', get_lang('Deactivate'),'',22) , 'exercice.php?'.api_get_cidreq().'&choice=disable&sec_token='.$token.'&page='.$page.'&exerciseId='.$row['id']);
  490. } else { // else if not active
  491. $actions .= Display::url(Display::return_icon('invisible.png', get_lang('Activate'),'',22) , 'exercice.php?'.api_get_cidreq().'&choice=enable&sec_token='.$token.'&page='.$page.'&exerciseId='.$row['id']);
  492. }
  493. // Export qti ...
  494. $actions .= Display::url(Display::return_icon('export_qti2.png','IMS/QTI','','22'), 'exercice.php?choice=exportqti2&exerciseId='.$row['id']);
  495. } else {
  496. // not session
  497. $actions = Display::return_icon('edit_na.png', get_lang('ExerciseEditionNotAvailableInSession'));
  498. $actions .='<a href="exercise_report.php?' . api_get_cidreq() . '&exerciseId='.$row['id'].'">'.Display :: return_icon('test_results.png', get_lang('Results'),'',22).'</a>';
  499. $actions .= Display::url(Display::return_icon('cd.gif', get_lang('CopyExercise')), '', array('onclick'=>"javascript:if(!confirm('".addslashes(api_htmlentities(get_lang('AreYouSureToCopy'),ENT_QUOTES,$charset))." ".addslashes($row['title'])."?"."')) return false;",'href'=>'exercice.php?'.api_get_cidreq().'&choice=copy_exercise&sec_token='.$token.'&exerciseId='.$row['id']));
  500. }
  501. //Delete
  502. if ($session_id == $row['session_id']) {
  503. $actions .= Display::url(Display::return_icon('delete.png', get_lang('Delete'),'',22), '', array('onclick'=>"javascript:if(!confirm('".addslashes(api_htmlentities(get_lang('AreYouSureToDelete'),ENT_QUOTES,$charset))." ".addslashes($row['title'])."?"."')) return false;",'href'=>'exercice.php?'.api_get_cidreq().'&choice=delete&sec_token='.$token.'&exerciseId='.$row['id']));
  504. }
  505. // Number of questions
  506. $random_label = '';
  507. if ($row['random'] > 0 || $row['random'] == -1) {
  508. // if random == -1 means use random questions with all questions
  509. $random_number_of_question = $row['random'];
  510. if ($random_number_of_question == -1) {
  511. $random_number_of_question = $rowi;
  512. }
  513. if ($row['random_by_category'] > 0) {
  514. if (!class_exists("testcategory.class.php")) include_once "testcategory.class.php" ;
  515. $nbQuestionsTotal = Testcategory::getNumberOfQuestionRandomByCategory($my_exercise_id, $random_number_of_question);
  516. $number_of_questions .= $nbQuestionsTotal." ";
  517. $number_of_questions .= ($nbQuestionsTotal > 1) ? get_lang("QuestionsLowerCase") : get_lang("QuestionLowerCase") ;
  518. $number_of_questions .= " - ";
  519. //$number_of_questions .= Testcategory::getNumberMaxQuestionByCat($my_exercise_id).' '.get_lang('QuestionByCategory');
  520. $number_of_questions .= min(Testcategory::getNumberMaxQuestionByCat($my_exercise_id), $random_number_of_question).' '.get_lang('QuestionByCategory');
  521. } else {
  522. $random_label = ' ('.get_lang('Random').') ';
  523. $number_of_questions = $random_number_of_question . ' ' .$random_label.' '.$textByCategory;
  524. //Bug if we set a random value bigger than the real number of questions
  525. if ($random_number_of_question > $rowi) {
  526. $number_of_questions = $rowi. ' ' .$random_label;
  527. }
  528. }
  529. } else {
  530. $number_of_questions = $rowi;
  531. }
  532. //Attempts
  533. //$attempts = get_count_exam_results($row['id']).' '.get_lang('Attempts');
  534. //$item .= Display::tag('td',$attempts);
  535. $item .= Display::tag('td', $number_of_questions);
  536. } else {
  537. // --- Student only
  538. $row['title'] = cut($row['title'], EXERCISE_MAX_NAME_SIZE);
  539. // if time is actived show link to exercise
  540. if ($time_limits) {
  541. if ($is_actived_time) {
  542. $url = '<a href="overview.php?'.api_get_cidreq().$myorigin.$mylpid.$mylpitemid.'&exerciseId='.$row['id'].'">'.$row['title'].'</a>';
  543. } else {
  544. $url = $row['title'];
  545. }
  546. } else {
  547. $url = '<a href="overview.php?'.api_get_cidreq().$myorigin.$mylpid.$mylpitemid.'&exerciseId='.$row['id'].'">'.$row['title'].'</a>';
  548. }
  549. //Link of the exercise
  550. $item = Display::tag('td',$url.' '.$session_img);
  551. //count number exercise questions
  552. $sqlquery = "SELECT count(*) FROM $TBL_EXERCICE_QUESTION WHERE c_id = $course_id AND exercice_id = ".$row['id'];
  553. $sqlresult = Database::query($sqlquery);
  554. $rowi = Database::result($sqlresult, 0);
  555. if ($row['random'] > 0) {
  556. $row['random'] . ' ' . api_strtolower(get_lang(($row['random'] > 1 ? 'Questions' : 'Question')));
  557. } else {
  558. //show results student
  559. $rowi . ' ' . api_strtolower(get_lang(($rowi > 1 ? 'Questions' : 'Question')));
  560. }
  561. //This query might be improved later on by ordering by the new "tms" field rather than by exe_id
  562. //Don't remove this marker: note-query-exe-results
  563. $qry = "SELECT * FROM $TBL_TRACK_EXERCICES
  564. WHERE exe_exo_id = ".$row['id']." AND
  565. exe_user_id = ".api_get_user_id()." AND
  566. exe_cours_id = '".api_get_course_id()."' AND
  567. status <> 'incomplete' AND
  568. orig_lp_id = 0 AND
  569. orig_lp_item_id = 0 AND
  570. session_id = '" . api_get_session_id() . "'
  571. ORDER BY exe_id DESC";
  572. $qryres = Database::query($qry);
  573. $num = Database :: num_rows($qryres);
  574. //Hide the results
  575. $my_result_disabled = $row['results_disabled'];
  576. //Time limits are on
  577. if ($time_limits) {
  578. // Examn is ready to be taken
  579. if ($is_actived_time) {
  580. //Show results
  581. if ($my_result_disabled == 0 || $my_result_disabled == 2) {
  582. //More than one attempt
  583. if ($num > 0) {
  584. $row_track = Database :: fetch_array($qryres);
  585. $attempt_text = get_lang('LatestAttempt') . ' : ';
  586. $attempt_text .= show_score($row_track['exe_result'], $row_track['exe_weighting']);
  587. } else {
  588. //No attempts
  589. $attempt_text = get_lang('NotAttempted');
  590. }
  591. } else {
  592. $attempt_text = get_lang('CantShowResults');
  593. }
  594. } else {
  595. //Quiz not ready due to time limits
  596. if ($row['start_time'] != '0000-00-00 00:00:00' && $row['end_time'] != '0000-00-00 00:00:00') {
  597. $attempt_text = sprintf(get_lang('ExerciseWillBeActivatedFromXToY'), api_convert_and_format_date($row['start_time']), api_convert_and_format_date($row['end_time']));
  598. } else {
  599. //$attempt_text = get_lang('ExamNotAvailableAtThisTime');
  600. if ($row['start_time'] != '0000-00-00 00:00:00') {
  601. $attempt_text = sprintf(get_lang('ExerciseAvailableFromX'), api_convert_and_format_date($row['start_time']));
  602. }
  603. if ($row['end_time'] != '0000-00-00 00:00:00') {
  604. $attempt_text = sprintf(get_lang('ExerciseAvailableUntilX'), api_convert_and_format_date($row['end_time']));
  605. }
  606. }
  607. }
  608. } else {
  609. //Normal behaviour
  610. //Show results
  611. if ($my_result_disabled == 0 || $my_result_disabled == 2) {
  612. if ($num > 0) {
  613. $row_track = Database :: fetch_array($qryres);
  614. $attempt_text = get_lang('LatestAttempt') . ' : ';
  615. $attempt_text .= show_score($row_track['exe_result'], $row_track['exe_weighting']);
  616. } else {
  617. $attempt_text = get_lang('NotAttempted');
  618. }
  619. } else {
  620. $attempt_text = get_lang('CantShowResults');
  621. }
  622. }
  623. if (empty($num)) {
  624. $num = '';
  625. }
  626. $item .= Display::tag('td', $attempt_text);
  627. //See results
  628. $actions =' '.$num.' <a href="exercise_report.php?' . api_get_cidreq() . '&exerciseId='.$row['id'].'"> '.Display::return_icon('test_results.png', get_lang('Results'),'',22).' </a>';
  629. }
  630. $class = 'row_even';
  631. if ($count % 2) {
  632. $class = 'row_odd';
  633. }
  634. $item .= Display::tag('td', $actions);
  635. echo Display::tag('tr',$item, array('class'=>$class));
  636. $count++;
  637. } // end foreach()
  638. }
  639. }
  640. // end exercise list
  641. //Hotpotatoes results
  642. if ($is_allowedToEdit) {
  643. $sql = "SELECT d.path as path, d.comment as comment, ip.visibility as visibility
  644. FROM $TBL_DOCUMENT d, $TBL_ITEM_PROPERTY ip
  645. WHERE d.c_id = $course_id AND
  646. ip.c_id = $course_id AND
  647. d.id = ip.ref AND
  648. ip.tool = '" . TOOL_DOCUMENT . "' AND
  649. (d.path LIKE '%htm%') AND
  650. d.path LIKE '" . Database :: escape_string($uploadPath) . "/%/%'
  651. LIMIT " .$from . "," .$limit; // only .htm or .html files listed
  652. } else {
  653. $sql = "SELECT d.path as path, d.comment as comment, ip.visibility as visibility
  654. FROM $TBL_DOCUMENT d, $TBL_ITEM_PROPERTY ip
  655. WHERE d.c_id = $course_id AND
  656. ip.c_id = $course_id AND
  657. d.id = ip.ref AND ip.tool = '" . TOOL_DOCUMENT . "' AND (d.path LIKE '%htm%')
  658. AND d.path LIKE '" . Database :: escape_string($uploadPath) . "/%/%' AND ip.visibility='1'
  659. LIMIT " .$from . "," .$limit;
  660. }
  661. $result = Database::query($sql);
  662. while ($row = Database :: fetch_array($result, 'ASSOC')) {
  663. $attribute['path'][] = $row['path'];
  664. $attribute['visibility'][] = $row['visibility'];
  665. $attribute['comment'][] = $row['comment'];
  666. }
  667. $nbrActiveTests = 0;
  668. if (isset($attribute['path']) && is_array($attribute['path'])) {
  669. while (list($key, $path) = each($attribute['path'])) {
  670. $item = '';
  671. list ($a, $vis) = each($attribute['visibility']);
  672. if (strcmp($vis, "1") == 0) {
  673. $active = 1;
  674. } else {
  675. $active = 0;
  676. }
  677. $title = GetQuizName($path, $documentPath);
  678. if ($title == '') {
  679. $title = basename($path);
  680. }
  681. $class = 'row_even';
  682. if ($count % 2) {
  683. $class = 'row_odd';
  684. }
  685. // prof only
  686. if ($is_allowedToEdit) {
  687. $item = Display::tag('td','<img src="../img/hotpotatoes_s.png" alt="HotPotatoes" /> <a href="showinframes.php?file='.$path.'&cid='.api_get_course_id().'&uid='.api_get_user_id().'"'.(!$active?'class="invisible"':'').'>'.$title.'</a> ');
  688. $item .= Display::tag('td','-');
  689. $actions = Display::url(Display::return_icon('edit.png',get_lang('Edit'),'',22), 'adminhp.php?'.api_get_cidreq().'&hotpotatoesName='.$path);
  690. $actions .='<a href="exercise_report.php?' . api_get_cidreq() . '&path='.$path.'">' . Display :: return_icon('test_results.png', get_lang('Results'),'',22).'</a>';
  691. // if active
  692. if ($active) {
  693. $nbrActiveTests = $nbrActiveTests +1;
  694. $actions .= ' <a href="'.$exercicePath.'?'.api_get_cidreq().'&hpchoice=disable&amp;page='.$page.'&amp;file='.$path.'">'.Display::return_icon('visible.png', get_lang('Deactivate'),'',22).'</a>';
  695. } else { // else if not active
  696. $actions .=' <a href="'.$exercicePath.'?'.api_get_cidreq().'&hpchoice=enable&amp;page='.$page.'&amp;file='.$path.'">'.Display::return_icon('invisible.png', get_lang('Activate'),'',22).'</a>';
  697. }
  698. $actions .= '<a href="'.$exercicePath.'?'.api_get_cidreq().'&amp;hpchoice=delete&amp;file='.$path.'" onclick="javascript:if(!confirm(\''.addslashes(api_htmlentities(get_lang('AreYouSureToDelete'),ENT_QUOTES,$charset).' '.$title."?").'\')) return false;">'.Display::return_icon('delete.png', get_lang('Delete'),'',22).'</a>';
  699. //$actions .='<img src="../img/lp_quiz_na.gif" border="0" title="'.get_lang('NotMarkActivity').'" alt="" />';
  700. $item .= Display::tag('td', $actions);
  701. echo Display::tag('tr',$item, array('class'=>$class));
  702. } else { // student only
  703. if ($active == 1) {
  704. $nbrActiveTests = $nbrActiveTests +1;
  705. $item .= Display::tag('td', '<a href="showinframes.php?'.api_get_cidreq().'&file='.$path.'&cid='.api_get_course_id().'&uid='.api_get_user_id().'"'.(!$active?'class="invisible"':'').'">'.$title.'</a>');
  706. $item .= Display::tag('td', '');
  707. $actions ='<a href="exercise_report.php?' . api_get_cidreq() . '&path='.$path.'">' . Display :: return_icon('test_results.png', get_lang('Results'),'',22).'</a>';
  708. $item .= Display::tag('td', $actions);
  709. echo Display::tag('tr',$item, array('class'=>$class));
  710. }
  711. }
  712. $count ++;
  713. }
  714. }
  715. echo '</table>';
  716. Display :: display_footer();
  717. exit;
  718. if ($origin != 'learnpath') { //so we are not in learnpath tool
  719. Display :: display_footer();
  720. }