exercice.php 41 KB

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