exercise.php 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. use ChamiloSession as Session;
  4. /**
  5. * Exercise list: This script shows the list of exercises for administrators and students.
  6. *
  7. * @package chamilo.exercise
  8. *
  9. * @author Olivier Brouckaert, original author
  10. * @author Denes Nagy, HotPotatoes integration
  11. * @author Wolfgang Schneider, code/html cleanup
  12. * @author Julio Montoya <gugli100@gmail.com>, lots of cleanup + several improvements
  13. * Modified by hubert.borderiou (question category)
  14. */
  15. require_once __DIR__.'/../inc/global.inc.php';
  16. $current_course_tool = TOOL_QUIZ;
  17. // Setting the tabs
  18. $this_section = SECTION_COURSES;
  19. //$htmlHeadXtra[] = api_get_asset('qtip2/jquery.qtip.min.js');
  20. //$htmlHeadXtra[] = api_get_css_asset('qtip2/jquery.qtip.min.css');
  21. api_protect_course_script(true);
  22. $limitTeacherAccess = api_get_configuration_value('limit_exercise_teacher_access');
  23. $check = Security::get_existing_token('get');
  24. $currentUrl = api_get_self().'?'.api_get_cidreq();
  25. require_once 'hotpotatoes.lib.php';
  26. /* Constants and variables */
  27. $is_allowedToEdit = api_is_allowed_to_edit(null, true);
  28. $is_tutor = api_is_allowed_to_edit(true);
  29. $is_tutor_course = api_is_course_tutor();
  30. $courseInfo = api_get_course_info();
  31. $courseId = $courseInfo['real_id'];
  32. $userInfo = api_get_user_info();
  33. $userId = $userInfo['id'];
  34. $sessionId = api_get_session_id();
  35. $isDrhOfCourse = CourseManager::isUserSubscribedInCourseAsDrh(
  36. $userId,
  37. $courseInfo
  38. );
  39. $TBL_DOCUMENT = Database::get_course_table(TABLE_DOCUMENT);
  40. $TBL_ITEM_PROPERTY = Database::get_course_table(TABLE_ITEM_PROPERTY);
  41. $TBL_EXERCISE_QUESTION = Database::get_course_table(TABLE_QUIZ_TEST_QUESTION);
  42. $TBL_EXERCISES = Database::get_course_table(TABLE_QUIZ_TEST);
  43. $TBL_TRACK_EXERCISES = Database::get_main_table(TABLE_STATISTIC_TRACK_E_EXERCISES);
  44. // document path
  45. $documentPath = api_get_path(SYS_COURSE_PATH).$courseInfo['path'].'/document';
  46. // picture path
  47. $picturePath = $documentPath.'/images';
  48. // audio path
  49. $audioPath = $documentPath.'/audio';
  50. // hot potatoes
  51. $uploadPath = DIR_HOTPOTATOES; //defined in main_api
  52. $exercisePath = api_get_self();
  53. $exfile = explode('/', $exercisePath);
  54. $exfile = strtolower($exfile[count($exfile) - 1]);
  55. $exercisePath = substr($exercisePath, 0, strpos($exercisePath, $exfile));
  56. $exercisePath = $exercisePath.'exercise.php';
  57. // Clear the exercise session
  58. Exercise::cleanSessionVariables();
  59. //General POST/GET/SESSION/COOKIES parameters recovery
  60. $origin = api_get_origin();
  61. $choice = isset($_REQUEST['choice']) ? Security::remove_XSS($_REQUEST['choice']) : null;
  62. $hpchoice = isset($_REQUEST['hpchoice']) ? Security::remove_XSS($_REQUEST['hpchoice']) : null;
  63. $exerciseId = isset($_REQUEST['exerciseId']) ? (int) $_REQUEST['exerciseId'] : null;
  64. $file = isset($_REQUEST['file']) ? Database::escape_string($_REQUEST['file']) : null;
  65. $learnpath_id = isset($_REQUEST['learnpath_id']) ? (int) $_REQUEST['learnpath_id'] : null;
  66. $learnpath_item_id = isset($_REQUEST['learnpath_item_id']) ? (int) $_REQUEST['learnpath_item_id'] : null;
  67. $categoryId = isset($_REQUEST['category_id']) ? (int) $_REQUEST['category_id'] : 0;
  68. $action = isset($_REQUEST['action']) ? $_REQUEST['action'] : '';
  69. $keyword = isset($_REQUEST['keyword']) ? Security::remove_XSS($_REQUEST['keyword']) : '';
  70. if (api_is_in_gradebook()) {
  71. $interbreadcrumb[] = [
  72. 'url' => Category::getUrl(),
  73. 'name' => get_lang('Assessments'),
  74. ];
  75. }
  76. $nameTools = get_lang('Tests');
  77. // Simple actions
  78. if ($is_allowedToEdit) {
  79. switch ($action) {
  80. case 'clean_all_test':
  81. if ($check) {
  82. if ($limitTeacherAccess && !api_is_platform_admin()) {
  83. api_not_allowed(true);
  84. }
  85. // list of exercises in a course/session
  86. // we got variable $courseId $courseInfo session api_get_session_id()
  87. $exerciseList = ExerciseLib::get_all_exercises_for_course_id(
  88. $courseInfo,
  89. $sessionId,
  90. $courseId,
  91. false
  92. );
  93. $quantity_results_deleted = 0;
  94. foreach ($exerciseList as $exeItem) {
  95. // delete result for test, if not in a gradebook
  96. $exercise_action_locked = api_resource_is_locked_by_gradebook($exeItem['id'], LINK_EXERCISE);
  97. if ($exercise_action_locked == false) {
  98. $objExerciseTmp = new Exercise();
  99. if ($objExerciseTmp->read($exeItem['id'])) {
  100. $quantity_results_deleted += $objExerciseTmp->cleanResults(true);
  101. }
  102. }
  103. }
  104. Display::addFlash(Display::return_message(
  105. sprintf(
  106. get_lang('%d results cleaned'),
  107. $quantity_results_deleted
  108. ),
  109. 'confirm'
  110. ));
  111. header('Location: '.$currentUrl);
  112. exit;
  113. }
  114. break;
  115. case 'exportqti2':
  116. if ($limitTeacherAccess && !api_is_platform_admin()) {
  117. api_not_allowed(true);
  118. }
  119. require_once api_get_path(SYS_CODE_PATH).'exercise/export/qti2/qti2_export.php';
  120. $export = export_exercise_to_qti($exerciseId, true);
  121. $xmlReader = new XMLReader();
  122. $xmlReader->xml($export);
  123. $xmlReader->setParserProperty(XMLReader::VALIDATE, true);
  124. $isValid = $xmlReader->isValid();
  125. if ($isValid) {
  126. $name = 'qti2_export_'.$exerciseId.'.zip';
  127. $zip = api_create_zip($name);
  128. $zip->addFile('qti2export_'.$exerciseId.'.xml', $export);
  129. $zip->finish();
  130. exit;
  131. } else {
  132. Display::addFlash(Display::return_message(get_lang('There was an error writing the XML file. Please ask the administrator to check the error logs.'), 'error'));
  133. header('Location: '.$currentUrl);
  134. exit;
  135. }
  136. break;
  137. case 'up_category':
  138. case 'down_category':
  139. $categoryIdFromGet = isset($_REQUEST['category_id_edit']) ? $_REQUEST['category_id_edit'] : 0;
  140. $em = Database::getManager();
  141. $repo = $em->getRepository('ChamiloCourseBundle:CExerciseCategory');
  142. $category = $repo->find($categoryIdFromGet);
  143. $currentPosition = $category->getPosition();
  144. if ($action === 'up_category') {
  145. $currentPosition--;
  146. } else {
  147. $currentPosition++;
  148. }
  149. $category->setPosition($currentPosition);
  150. $em->persist($category);
  151. $em->flush();
  152. Display::addFlash(Display::return_message(get_lang('Update successful')));
  153. header('Location: '.$currentUrl);
  154. exit;
  155. break;
  156. }
  157. }
  158. // Mass actions
  159. if (!empty($action) && $is_allowedToEdit) {
  160. $exerciseListToEdit = isset($_REQUEST['id']) ? $_REQUEST['id'] : 0;
  161. if (!empty($exerciseListToEdit)) {
  162. foreach ($exerciseListToEdit as $exerciseIdToEdit) {
  163. $objExerciseTmp = new Exercise();
  164. $result = $objExerciseTmp->read($exerciseIdToEdit);
  165. if (empty($result)) {
  166. continue;
  167. }
  168. switch ($action) {
  169. case 'delete':
  170. $objExerciseTmp->delete();
  171. break;
  172. case 'visible':
  173. if ($limitTeacherAccess && !api_is_platform_admin()) {
  174. // Teacher change exercise
  175. break;
  176. }
  177. // enables an exercise
  178. if (empty($sessionId)) {
  179. $objExerciseTmp->enable();
  180. $objExerciseTmp->save();
  181. } else {
  182. if (!empty($objExerciseTmp->sessionId)) {
  183. $objExerciseTmp->enable();
  184. $objExerciseTmp->save();
  185. }
  186. }
  187. api_item_property_update(
  188. $courseInfo,
  189. TOOL_QUIZ,
  190. $objExerciseTmp->id,
  191. 'visible',
  192. $userId
  193. );
  194. break;
  195. case 'invisible':
  196. if ($limitTeacherAccess && !api_is_platform_admin()) {
  197. // Teacher change exercise
  198. break;
  199. }
  200. // enables an exercise
  201. if (empty($sessionId)) {
  202. $objExerciseTmp->disable();
  203. $objExerciseTmp->save();
  204. } else {
  205. if (!empty($objExerciseTmp->sessionId)) {
  206. $objExerciseTmp->disable();
  207. $objExerciseTmp->save();
  208. }
  209. }
  210. api_item_property_update(
  211. $courseInfo,
  212. TOOL_QUIZ,
  213. $objExerciseTmp->id,
  214. 'visible',
  215. $userId
  216. );
  217. break;
  218. }
  219. }
  220. Display::addFlash(Display::return_message(get_lang('Update successful')));
  221. header('Location: '.$currentUrl);
  222. exit;
  223. }
  224. }
  225. Event::event_access_tool(TOOL_QUIZ);
  226. $logInfo = [
  227. 'tool' => TOOL_QUIZ,
  228. 'tool_id' => (int) $exerciseId,
  229. 'action' => isset($_REQUEST['learnpath_id']) ? 'learnpath_id' : '',
  230. 'action_details' => isset($_REQUEST['learnpath_id']) ? (int) $_REQUEST['learnpath_id'] : '',
  231. ];
  232. Event::registerLog($logInfo);
  233. HotPotGCt($documentPath, 1, $userId);
  234. // Only for administrator
  235. if ($is_allowedToEdit) {
  236. if (!empty($choice)) {
  237. // single exercise choice
  238. // construction of Exercise
  239. $objExerciseTmp = new Exercise();
  240. $exercise_action_locked = api_resource_is_locked_by_gradebook(
  241. $exerciseId,
  242. LINK_EXERCISE
  243. );
  244. if ($objExerciseTmp->read($exerciseId)) {
  245. if ($check) {
  246. switch ($choice) {
  247. case 'enable_launch':
  248. $objExerciseTmp->cleanCourseLaunchSettings();
  249. $objExerciseTmp->enableAutoLaunch();
  250. Display::addFlash(Display::return_message(get_lang('Updated')));
  251. break;
  252. case 'disable_launch':
  253. $objExerciseTmp->cleanCourseLaunchSettings();
  254. break;
  255. case 'delete':
  256. // deletes an exercise
  257. $result = $objExerciseTmp->delete();
  258. if ($result) {
  259. Display::addFlash(Display::return_message(get_lang('ExerciseDeleted'), 'confirmation'));
  260. }
  261. break;
  262. case 'enable':
  263. if ($limitTeacherAccess && !api_is_platform_admin()) {
  264. // Teacher change exercise
  265. break;
  266. }
  267. // Enables an exercise
  268. if (empty($sessionId)) {
  269. $objExerciseTmp->enable();
  270. $objExerciseTmp->save();
  271. } else {
  272. if (!empty($objExerciseTmp->sessionId)) {
  273. $objExerciseTmp->enable();
  274. $objExerciseTmp->save();
  275. }
  276. }
  277. api_item_property_update(
  278. $courseInfo,
  279. TOOL_QUIZ,
  280. $objExerciseTmp->id,
  281. 'visible',
  282. $userId
  283. );
  284. Display::addFlash(Display::return_message(get_lang('VisibilityChanged'), 'confirmation'));
  285. break;
  286. case 'disable':
  287. if ($limitTeacherAccess && !api_is_platform_admin()) {
  288. // Teacher change exercise
  289. break;
  290. }
  291. // disables an exercise
  292. if (empty($sessionId)) {
  293. $objExerciseTmp->disable();
  294. $objExerciseTmp->save();
  295. } else {
  296. // Only change active if it belongs to a session
  297. if (!empty($objExerciseTmp->sessionId)) {
  298. $objExerciseTmp->disable();
  299. $objExerciseTmp->save();
  300. }
  301. }
  302. api_item_property_update(
  303. $courseInfo,
  304. TOOL_QUIZ,
  305. $objExerciseTmp->id,
  306. 'invisible',
  307. $userId
  308. );
  309. Display::addFlash(Display::return_message(get_lang('The visibility has been changed.'), 'confirmation'));
  310. break;
  311. case 'disable_results':
  312. //disable the results for the learners
  313. $objExerciseTmp->disable_results();
  314. $objExerciseTmp->save();
  315. Display::addFlash(Display::return_message(get_lang('Results disabled for learners'), 'confirmation'));
  316. break;
  317. case 'enable_results':
  318. //disable the results for the learners
  319. $objExerciseTmp->enable_results();
  320. $objExerciseTmp->save();
  321. Display::addFlash(Display::return_message(get_lang('Results enabled for learners'), 'confirmation'));
  322. break;
  323. case 'clean_results':
  324. if ($limitTeacherAccess && !api_is_platform_admin()) {
  325. // Teacher change exercise
  326. break;
  327. }
  328. // Clean student results
  329. if ($exercise_action_locked == false) {
  330. $quantity_results_deleted = $objExerciseTmp->cleanResults(true);
  331. $title = $objExerciseTmp->selectTitle();
  332. Display::addFlash(
  333. Display::return_message(
  334. $title.': '.sprintf(
  335. get_lang('%d results cleaned'),
  336. $quantity_results_deleted
  337. ),
  338. 'confirmation'
  339. )
  340. );
  341. }
  342. break;
  343. case 'copy_exercise': //copy an exercise
  344. api_set_more_memory_and_time_limits();
  345. $objExerciseTmp->copyExercise();
  346. Display::addFlash(Display::return_message(
  347. get_lang('Test copied'),
  348. 'confirmation'
  349. ));
  350. break;
  351. }
  352. header('Location: '.$currentUrl);
  353. exit;
  354. }
  355. }
  356. // destruction of Exercise
  357. unset($objExerciseTmp);
  358. Security::clear_token();
  359. }
  360. if (!empty($hpchoice)) {
  361. switch ($hpchoice) {
  362. case 'delete':
  363. if ($limitTeacherAccess && !api_is_platform_admin()) {
  364. // Teacher change exercise
  365. break;
  366. }
  367. // deletes an exercise
  368. $imgparams = [];
  369. $imgcount = 0;
  370. GetImgParams($file, $documentPath, $imgparams, $imgcount);
  371. $fld = GetFolderName($file);
  372. for ($i = 0; $i < $imgcount; $i++) {
  373. my_delete($documentPath.$uploadPath."/".$fld."/".$imgparams[$i]);
  374. DocumentManager::updateDbInfo("delete", $uploadPath."/".$fld."/".$imgparams[$i]);
  375. }
  376. if (!is_dir($documentPath.$uploadPath."/".$fld."/")) {
  377. my_delete($documentPath.$file);
  378. DocumentManager::updateDbInfo("delete", $file);
  379. } else {
  380. if (my_delete($documentPath.$file)) {
  381. DocumentManager::updateDbInfo("delete", $file);
  382. }
  383. }
  384. /* hotpotatoes folder may contains several tests so
  385. don't delete folder if not empty :
  386. http://support.chamilo.org/issues/2165
  387. */
  388. if (!(strstr($uploadPath, DIR_HOTPOTATOES) &&
  389. !folder_is_empty($documentPath.$uploadPath."/".$fld."/"))
  390. ) {
  391. my_delete($documentPath.$uploadPath."/".$fld."/");
  392. }
  393. break;
  394. case 'enable': // enables an exercise
  395. if ($limitTeacherAccess && !api_is_platform_admin()) {
  396. // Teacher change exercise
  397. break;
  398. }
  399. $newVisibilityStatus = '1'; //"visible"
  400. $query = "SELECT id FROM $TBL_DOCUMENT
  401. WHERE c_id = $courseId AND path='".Database::escape_string($file)."'";
  402. $res = Database::query($query);
  403. $row = Database :: fetch_array($res, 'ASSOC');
  404. api_item_property_update(
  405. $courseInfo,
  406. TOOL_DOCUMENT,
  407. $row['id'],
  408. 'visible',
  409. $userId
  410. );
  411. Display::addFlash(Display::return_message(get_lang('Update successful')));
  412. break;
  413. case 'disable': // disables an exercise
  414. if ($limitTeacherAccess && !api_is_platform_admin()) {
  415. // Teacher change exercise
  416. break;
  417. }
  418. $newVisibilityStatus = '0'; //"invisible"
  419. $query = "SELECT id FROM $TBL_DOCUMENT
  420. WHERE c_id = $courseId AND path='".Database::escape_string($file)."'";
  421. $res = Database::query($query);
  422. $row = Database :: fetch_array($res, 'ASSOC');
  423. api_item_property_update(
  424. $courseInfo,
  425. TOOL_DOCUMENT,
  426. $row['id'],
  427. 'invisible',
  428. $userId
  429. );
  430. break;
  431. default:
  432. break;
  433. }
  434. header('Location: '.$currentUrl);
  435. exit;
  436. }
  437. }
  438. if ($origin !== 'learnpath') {
  439. //so we are not in learnpath tool
  440. Display::display_header($nameTools, get_lang('Test'));
  441. if (isset($_GET['message']) && in_array($_GET['message'], ['ExerciseEdited'])) {
  442. echo Display::return_message(get_lang('TestEdited'), 'confirmation');
  443. }
  444. } else {
  445. Display::display_reduced_header();
  446. }
  447. Display::display_introduction_section(TOOL_QUIZ);
  448. // Selects $limit exercises at the same time
  449. // maximum number of exercises on a same page
  450. $limit = Exercise::PAGINATION_ITEMS_PER_PAGE;
  451. HotPotGCt($documentPath, 1, $userId);
  452. $token = Security::get_token();
  453. if ($is_allowedToEdit && $origin !== 'learnpath') {
  454. $actionsLeft = '<a href="'.api_get_path(WEB_CODE_PATH).'exercise/exercise_admin.php?'.api_get_cidreq().'">'.
  455. Display::return_icon('new_exercice.png', get_lang('Create a new test'), '', ICON_SIZE_MEDIUM).'</a>';
  456. $actionsLeft .= '<a href="'.api_get_path(WEB_CODE_PATH).'exercise/question_create.php?'.api_get_cidreq().'">'.
  457. Display::return_icon('new_question.png', get_lang('Add a question'), '', ICON_SIZE_MEDIUM).'</a>';
  458. if (api_get_configuration_value('allow_exercise_categories')) {
  459. $actionsLeft .= '<a href="'.api_get_path(WEB_CODE_PATH).'exercise/category.php?'.api_get_cidreq().'">';
  460. $actionsLeft .= Display::return_icon('folder.png', get_lang('Category'), '', ICON_SIZE_MEDIUM);
  461. $actionsLeft .= '</a>';
  462. }
  463. // Question category
  464. $actionsLeft .= '<a href="'.api_get_path(WEB_CODE_PATH).'exercise/tests_category.php?'.api_get_cidreq().'">';
  465. $actionsLeft .= Display::return_icon('green_open.png', get_lang('Questions category'), '', ICON_SIZE_MEDIUM);
  466. $actionsLeft .= '</a>';
  467. $actionsLeft .= '<a href="'.api_get_path(WEB_CODE_PATH).'exercise/question_pool.php?'.api_get_cidreq().'">';
  468. $actionsLeft .= Display::return_icon('database.png', get_lang('Recycle existing questions'), '', ICON_SIZE_MEDIUM);
  469. $actionsLeft .= '</a>';
  470. //echo Display::url(Display::return_icon('looknfeel.png', get_lang('Media')), 'media.php?' . api_get_cidreq());
  471. // end question category
  472. $actionsLeft .= '<a href="'.api_get_path(WEB_CODE_PATH).'exercise/hotpotatoes.php?'.api_get_cidreq().'">'.
  473. Display::return_icon('import_hotpotatoes.png', get_lang('Import Hotpotatoes'), '', ICON_SIZE_MEDIUM).'</a>';
  474. // link to import qti2 ...
  475. $actionsLeft .= '<a href="'.api_get_path(WEB_CODE_PATH).'exercise/qti2.php?'.api_get_cidreq().'">'.
  476. Display::return_icon('import_qti2.png', get_lang('Import exercises Qti2'), '', ICON_SIZE_MEDIUM).'</a>';
  477. $actionsLeft .= '<a href="'.api_get_path(WEB_CODE_PATH).'exercise/aiken.php?'.api_get_cidreq().'">'.
  478. Display::return_icon('import_aiken.png', get_lang('Import Aiken quiz'), '', ICON_SIZE_MEDIUM).'</a>';
  479. $actionsLeft .= '<a href="'.api_get_path(WEB_CODE_PATH).'exercise/upload_exercise.php?'.api_get_cidreq().'">'.
  480. Display::return_icon('import_excel.png', get_lang('Import quiz from Excel'), '', ICON_SIZE_MEDIUM).'</a>';
  481. $cleanAll = Display::url(
  482. Display::return_icon(
  483. 'clean_all.png',
  484. get_lang('Are you sure to delete all test\'s results ?'),
  485. '',
  486. ICON_SIZE_MEDIUM
  487. ),
  488. '#',
  489. [
  490. 'data-item-question' => addslashes(get_lang('Clear all learners results for every exercises ?')),
  491. 'data-href' => api_get_path(WEB_CODE_PATH).'exercise/exercise.php?'.api_get_cidreq().'&action=clean_all_test&sec_token='.$token,
  492. 'data-toggle' => 'modal',
  493. 'data-target' => '#confirm-delete',
  494. ]
  495. );
  496. if ($limitTeacherAccess) {
  497. if (api_is_platform_admin()) {
  498. $actionsLeft .= $cleanAll;
  499. }
  500. } else {
  501. $actionsLeft .= $cleanAll;
  502. }
  503. // Create a search-box
  504. $form = new FormValidator('search_simple', 'get', $currentUrl, null, null, FormValidator::LAYOUT_INLINE);
  505. $form->addCourseHiddenParams();
  506. if (api_get_configuration_value('allow_exercise_categories')) {
  507. $manager = new ExerciseCategoryManager();
  508. $options = $manager->getCategoriesForSelect(api_get_course_int_id());
  509. if (!empty($options)) {
  510. $form->addSelect(
  511. 'category_id',
  512. get_lang('Category'),
  513. $options,
  514. ['placeholder' => get_lang('Please select an option'), 'disable_js' => true]
  515. );
  516. }
  517. }
  518. $form->addText(
  519. 'keyword',
  520. get_lang('Search'),
  521. false,
  522. [
  523. 'aria-label' => get_lang('Search'),
  524. ]
  525. );
  526. $form->addButtonSearch(get_lang('Search'));
  527. $actionsRight = $form->returnForm();
  528. }
  529. if ($is_allowedToEdit) {
  530. echo Display::toolbarAction(
  531. 'toolbarUser',
  532. [$actionsLeft, '', $actionsRight],
  533. [6, 1, 5]
  534. );
  535. }
  536. if (api_get_configuration_value('allow_exercise_categories') === false) {
  537. echo Exercise::exerciseGrid(0, $keyword);
  538. } else {
  539. if (empty($categoryId)) {
  540. echo Display::page_subheader(get_lang('General'));
  541. echo Exercise::exerciseGrid(0, $keyword);
  542. $counter = 0;
  543. $manager = new ExerciseCategoryManager();
  544. $categories = $manager->getCategories($courseId);
  545. $modifyUrl = api_get_self().'?'.api_get_cidreq();
  546. $total = count($categories);
  547. $upIcon = Display::return_icon('up.png', get_lang('Move up'));
  548. $downIcon = Display::return_icon('down.png', get_lang('Move down'));
  549. /** @var \Chamilo\CourseBundle\Entity\CExerciseCategory $category */
  550. foreach ($categories as $category) {
  551. $categoryIdItem = $category->getId();
  552. $up = '';
  553. $down = '';
  554. if ($is_allowedToEdit) {
  555. $up = Display::url($upIcon, $modifyUrl.'&action=up_category&category_id_edit='.$categoryIdItem);
  556. if ($counter === 0) {
  557. $up = Display::url(Display::return_icon('up_na.png'), '#');
  558. }
  559. $down = Display::url($downIcon, $modifyUrl.'&action=down_category&category_id_edit='.$categoryIdItem);
  560. $counter++;
  561. if ($total === $counter) {
  562. $down = Display::url(Display::return_icon('down_na.png'), '#');
  563. }
  564. }
  565. echo Display::page_subheader($category->getName().$up.$down);
  566. echo Exercise::exerciseGrid($category->getId(), $keyword);
  567. }
  568. } else {
  569. $manager = new ExerciseCategoryManager();
  570. $category = $manager->get($categoryId);
  571. echo Display::page_subheader($category['name']);
  572. echo Exercise::exerciseGrid($category['id'], $keyword);
  573. }
  574. }
  575. if ($origin !== 'learnpath') {
  576. // We are not in learnpath tool
  577. Display::display_footer();
  578. }