exercice.php 41 KB

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