lp_controller.php 54 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. use ChamiloSession as Session;
  4. /**
  5. * Controller script. Prepares the common background variables to give to the scripts corresponding to
  6. * the requested action.
  7. *
  8. * @todo remove repeated if $lp_found redirect
  9. *
  10. * @package chamilo.learnpath
  11. *
  12. * @author Yannick Warnier <ywarnier@beeznest.org>
  13. */
  14. // Flag to allow for anonymous user - needs to be set before global.inc.php.
  15. $use_anonymous = true;
  16. $debug = 0;
  17. require_once __DIR__.'/../inc/global.inc.php';
  18. api_protect_course_script(true);
  19. $current_course_tool = TOOL_LEARNPATH;
  20. $_course = api_get_course_info();
  21. $glossaryExtraTools = api_get_setting('show_glossary_in_extra_tools');
  22. $showGlossary = in_array($glossaryExtraTools, ['true', 'lp', 'exercise_and_lp']);
  23. if ($showGlossary) {
  24. if (api_get_setting('show_glossary_in_documents') === 'ismanual' ||
  25. api_get_setting('show_glossary_in_documents') === 'isautomatic'
  26. ) {
  27. $htmlHeadXtra[] = '<script>
  28. <!--
  29. var jQueryFrameReadyConfigPath = \''.api_get_jquery_web_path().'\';
  30. -->
  31. </script>';
  32. $htmlHeadXtra[] = '<script src="'.api_get_path(WEB_LIBRARY_PATH).'javascript/jquery.frameready.js" type="text/javascript" language="javascript"></script>';
  33. $htmlHeadXtra[] = '<script src="'.api_get_path(WEB_LIBRARY_PATH).'javascript/jquery.highlight.js" type="text/javascript" language="javascript"></script>';
  34. }
  35. }
  36. $htmlHeadXtra[] = '<script>
  37. function setFocus(){
  38. $("#idTitle").focus();
  39. }
  40. $(window).on("load", function () {
  41. setFocus();
  42. });
  43. </script>';
  44. $ajax_url = api_get_path(WEB_AJAX_PATH).'lp.ajax.php?'.api_get_cidreq();
  45. $htmlHeadXtra[] = '
  46. <script>
  47. /*
  48. Script to manipulate Learning Path items with Drag and drop
  49. */
  50. var newOrderData = "";
  51. function buildLPtree(in_elem, in_parent_id) {
  52. var item_tag = in_elem.get(0).tagName;
  53. var item_id = in_elem.attr("id");
  54. var parent_id = item_id;
  55. if (item_tag == "LI" && item_id != undefined) {
  56. // in_parent_id de la forme UL_x
  57. newOrderData += item_id+"|"+get_UL_integer_id(in_parent_id)+"^";
  58. }
  59. in_elem.children().each(function () {
  60. buildLPtree($(this), parent_id);
  61. });
  62. }
  63. // return the interge part of an UL id
  64. // (0 for lp_item_list)
  65. function get_UL_integer_id(in_ul_id) {
  66. in_parent_integer_id = in_ul_id;
  67. in_parent_integer_id = in_parent_integer_id.replace("lp_item_list", "0");
  68. in_parent_integer_id = in_parent_integer_id.replace("UL_", "");
  69. return in_parent_integer_id;
  70. }
  71. $(function() {
  72. $(".lp_resource").sortable({
  73. items: ".lp_resource_element ",
  74. handle: ".moved", //only the class "moved"
  75. cursor: "move",
  76. connectWith: "#lp_item_list",
  77. placeholder: "ui-state-highlight", //defines the yellow highlight
  78. start: function(event, ui) {
  79. $(ui.item).css("width", "350px");
  80. $(ui.item).find(".item_data").attr("style", "");
  81. },
  82. stop: function(event, ui) {
  83. $(ui.item).css("width", "100%");
  84. }
  85. });
  86. $("#lp_item_list").sortable({
  87. items: "li",
  88. handle: ".moved", //only the class "moved"
  89. cursor: "move",
  90. placeholder: "ui-state-highlight", //defines the yellow highlight
  91. update: function(event, ui) {
  92. buildLPtree($("#lp_item_list"), 0);
  93. var order = "new_order="+ newOrderData + "&a=update_lp_item_order";
  94. $.post(
  95. "'.$ajax_url.'",
  96. order,
  97. function(reponse) {
  98. $("#message").html(reponse);
  99. order = "";
  100. newOrderData = "";
  101. }
  102. );
  103. },
  104. receive: function(event, ui) {
  105. var id = $(ui.item).attr("data_id");
  106. var type = $(ui.item).attr("data_type");
  107. var title = $(ui.item).attr("title");
  108. processReceive = true;
  109. if (ui.item.parent()[0]) {
  110. var parent_id = $(ui.item.parent()[0]).attr("id");
  111. var previous_id = $(ui.item.prev()).attr("id");
  112. if (parent_id) {
  113. parent_id = parent_id.split("_")[1];
  114. var params = {
  115. "a": "add_lp_item",
  116. "id": id,
  117. "parent_id": parent_id,
  118. "previous_id": previous_id,
  119. "type": type,
  120. "title" : title
  121. };
  122. $.ajax({
  123. type: "GET",
  124. url: "'.$ajax_url.'",
  125. data: params,
  126. async: false,
  127. success: function(data) {
  128. $("#lp_item_list").html(data);
  129. }
  130. });
  131. }
  132. }
  133. } // End receive
  134. });
  135. processReceive = false;
  136. });
  137. </script>';
  138. $session_id = api_get_session_id();
  139. $lpfound = false;
  140. $myrefresh = 0;
  141. $myrefresh_id = 0;
  142. $refresh = Session::read('refresh');
  143. if ($refresh == 1) {
  144. // Check if we should do a refresh of the oLP object (for example after editing the LP).
  145. // If refresh is set, we regenerate the oLP object from the database (kind of flush).
  146. Session::erase('refresh');
  147. $myrefresh = 1;
  148. }
  149. if ($debug > 0) {
  150. error_log(' $refresh: '.$refresh);
  151. error_log(' $myrefresh: '.$myrefresh);
  152. }
  153. if (!empty($_REQUEST['dialog_box'])) {
  154. $dialog_box = stripslashes(urldecode($_REQUEST['dialog_box']));
  155. }
  156. $lp_controller_touched = 1;
  157. $lp_found = false;
  158. $lpObject = Session::read('lpobject');
  159. if (!empty($lpObject)) {
  160. if ($debug) {
  161. error_log(' SESSION[lpobject] is defined');
  162. }
  163. /** @var learnpath $oLP */
  164. $oLP = UnserializeApi::unserialize('lp', $lpObject);
  165. if (isset($oLP) && is_object($oLP)) {
  166. if ($debug) {
  167. error_log(' oLP is object');
  168. }
  169. if ($myrefresh == 1 ||
  170. empty($oLP->cc) ||
  171. $oLP->cc != api_get_course_id() ||
  172. $oLP->lp_view_session_id != $session_id
  173. ) {
  174. if ($debug) {
  175. error_log('Course has changed, discard lp object');
  176. error_log('$oLP->lp_view_session_id: '.$oLP->lp_view_session_id);
  177. error_log('api_get_session_id(): '.$session_id);
  178. error_log('$oLP->cc: '.$oLP->cc);
  179. error_log('api_get_course_id(): '.api_get_course_id());
  180. }
  181. if ($myrefresh == 1) {
  182. $myrefresh_id = $oLP->get_id();
  183. }
  184. $oLP = null;
  185. Session::erase('oLP');
  186. Session::erase('lpobject');
  187. } else {
  188. Session::write('oLP', $oLP);
  189. $lp_found = true;
  190. }
  191. }
  192. }
  193. if ($debug) {
  194. error_log('$lp_found: '.$lp_found);
  195. error_log('$myrefresh_id: '.$myrefresh_id);
  196. }
  197. $course_id = api_get_course_int_id();
  198. if (!$lp_found || (!empty($_REQUEST['lp_id']) && $_SESSION['oLP']->get_id() != $_REQUEST['lp_id'])) {
  199. if ($debug > 0) {
  200. error_log(' oLP is not object, has changed or refresh been asked, getting new');
  201. }
  202. // Regenerate a new lp object? Not always as some pages don't need the object (like upload?)
  203. if (!empty($_REQUEST['lp_id']) || !empty($myrefresh_id)) {
  204. // Select the lp in the database and check which type it is (scorm/chamilo/aicc) to generate the
  205. // right object.
  206. if (!empty($_REQUEST['lp_id'])) {
  207. $lp_id = $_REQUEST['lp_id'];
  208. } else {
  209. $lp_id = $myrefresh_id;
  210. }
  211. $lp_id = (int) $lp_id;
  212. $lp_table = Database::get_course_table(TABLE_LP_MAIN);
  213. if (!empty($lp_id)) {
  214. $sel = "SELECT iid, lp_type FROM $lp_table WHERE c_id = $course_id AND id = $lp_id";
  215. if ($debug > 0) {
  216. error_log(' querying '.$sel);
  217. }
  218. $res = Database::query($sel);
  219. if (Database::num_rows($res)) {
  220. $row = Database::fetch_array($res);
  221. $lpIid = $row['iid'];
  222. $type = $row['lp_type'];
  223. if ($debug > 0) {
  224. error_log('Found row type '.$type);
  225. error_log('Calling constructor: '.api_get_course_id().' - '.$lp_id.' - '.api_get_user_id());
  226. }
  227. $logInfo = [
  228. 'tool' => TOOL_LEARNPATH,
  229. 'tool_id' => 0,
  230. 'tool_id_detail' => 0,
  231. 'action' => 'lp_load',
  232. ];
  233. Event::registerLog($logInfo);
  234. switch ($type) {
  235. case 1:
  236. $oLP = new learnpath(api_get_course_id(), $lpIid, api_get_user_id());
  237. if ($oLP !== false) {
  238. $lp_found = true;
  239. }
  240. break;
  241. case 2:
  242. $oLP = new scorm(api_get_course_id(), $lpIid, api_get_user_id());
  243. if ($oLP !== false) {
  244. $lp_found = true;
  245. }
  246. break;
  247. case 3:
  248. $oLP = new aicc(api_get_course_id(), $lpIid, api_get_user_id());
  249. if ($oLP !== false) {
  250. $lp_found = true;
  251. }
  252. break;
  253. default:
  254. $oLP = new learnpath(api_get_course_id(), $lpIid, api_get_user_id());
  255. if ($oLP !== false) {
  256. $lp_found = true;
  257. }
  258. break;
  259. }
  260. }
  261. } else {
  262. if ($debug > 0) {
  263. error_log(' Request[lp_id] is not numeric');
  264. }
  265. }
  266. } else {
  267. if ($debug > 0) {
  268. error_log(' Request[lp_id] and refresh_id were empty');
  269. }
  270. }
  271. if ($lp_found) {
  272. Session::write('oLP', $oLP);
  273. }
  274. }
  275. if ($debug > 0) {
  276. error_log('Passed oLP creation check');
  277. }
  278. $is_allowed_to_edit = api_is_allowed_to_edit(false, true, false, false);
  279. if (isset($_SESSION['oLP'])) {
  280. // Reinitialises array used by javascript to update items in the TOC.
  281. $_SESSION['oLP']->update_queue = [];
  282. }
  283. $action = !empty($_REQUEST['action']) ? $_REQUEST['action'] : '';
  284. if ($debug) {
  285. error_log('Entered lp_controller.php -+- (action: '.$action.')');
  286. }
  287. $eventLpId = $lp_id = !empty($_REQUEST['lp_id']) ? (int) $_REQUEST['lp_id'] : 0;
  288. if (empty($lp_id)) {
  289. if (isset($_SESSION['oLP'])) {
  290. $eventLpId = $_SESSION['oLP']->get_id();
  291. }
  292. }
  293. $lp_detail_id = 0;
  294. switch ($action) {
  295. case '':
  296. case 'list':
  297. $eventLpId = 0;
  298. break;
  299. case 'view':
  300. case 'content':
  301. $lp_detail_id = $_SESSION['oLP']->get_current_item_id();
  302. break;
  303. default:
  304. $lp_detail_id = (!empty($_REQUEST['id']) ? (int) $_REQUEST['id'] : 0);
  305. break;
  306. }
  307. $logInfo = [
  308. 'tool' => TOOL_LEARNPATH,
  309. 'tool_id' => $eventLpId,
  310. 'tool_id_detail' => $lp_detail_id,
  311. 'action' => !empty($action) ? $action : 'list',
  312. ];
  313. Event::registerLog($logInfo);
  314. // format title to be displayed correctly if QUIZ
  315. $post_title = '';
  316. if (isset($_POST['title'])) {
  317. $post_title = Security::remove_XSS($_POST['title']);
  318. if (isset($_POST['type']) &&
  319. isset($_POST['title']) &&
  320. $_POST['type'] == TOOL_QUIZ &&
  321. !empty($_POST['title'])
  322. ) {
  323. $post_title = Exercise::format_title_variable($_POST['title']);
  324. }
  325. }
  326. $redirectTo = '';
  327. if ($debug > 0) {
  328. error_log('action "'.$action.'" triggered');
  329. if (!$lp_found) {
  330. //check if the learnpath ID was defined, otherwise send back to list
  331. error_log('No learnpath given');
  332. }
  333. }
  334. switch ($action) {
  335. case 'send_notify_teacher':
  336. // Enviar correo al profesor
  337. $studentInfo = api_get_user_info();
  338. $course_info = api_get_course_info();
  339. global $_configuration;
  340. $root_web = $_configuration['root_web'];
  341. if (api_get_session_id() > 0) {
  342. $session_info = api_get_session_info(api_get_session_id());
  343. $course_name = $session_info['name'];
  344. $course_url = $root_web.'courses/'.$course_info['code'].'/index.php?id_session='.api_get_session_id();
  345. } else {
  346. $course_name = $course_info['title'];
  347. $course_url = $root_web.'courses/'.$course_info['code'].'/index.php?';
  348. }
  349. $url = Display::url($course_name, $course_url, ['title' => get_lang('GoToCourse')]);
  350. $coachList = CourseManager::get_coachs_from_course(api_get_session_id(), api_get_course_int_id());
  351. foreach ($coachList as $coach_course) {
  352. $recipient_name = $coach_course['full_name'];
  353. $coachInfo = api_get_user_info($coach_course['user_id']);
  354. $email = $coachInfo['email'];
  355. $tplContent = new Template(null, false, false, false, false, false);
  356. // variables for the default template
  357. $tplContent->assign('name_teacher', $recipient_name);
  358. $tplContent->assign('name_student', $studentInfo['complete_name']);
  359. $tplContent->assign('course_name', $course_name);
  360. $tplContent->assign('course_url', $url);
  361. //$tplContent->assign('telefono', $telefono);
  362. //$tplContent->assign('prefix', $prefix);
  363. $layoutContent = $tplContent->get_template('mail/content_ending_learnpath.tpl');
  364. $emailBody = $tplContent->fetch($layoutContent);
  365. api_mail_html(
  366. $recipient_name,
  367. $email,
  368. sprintf(get_lang('StudentXFinishedLp'), $studentInfo['complete_name']),
  369. $emailBody,
  370. $studentInfo['complete_name'],
  371. $studentInfo['email'],
  372. true
  373. );
  374. }
  375. Display::addFlash(Display::return_message(get_lang('MessageSent')));
  376. require 'lp_list.php';
  377. break;
  378. case 'add_item':
  379. if (!$is_allowed_to_edit) {
  380. api_not_allowed(true);
  381. }
  382. if (!$lp_found) {
  383. // Check if the learnpath ID was defined, otherwise send back to list
  384. require 'lp_list.php';
  385. } else {
  386. Session::write('refresh', 1);
  387. if (isset($_POST['submit_button']) && !empty($post_title)) {
  388. // If a title was submitted:
  389. // Updating the lp.modified_on
  390. $_SESSION['oLP']->set_modified_on();
  391. if (isset($_SESSION['post_time']) && $_SESSION['post_time'] == $_POST['post_time']) {
  392. // Check post_time to ensure ??? (counter-hacking measure?)
  393. require 'lp_add_item.php';
  394. } else {
  395. Session::write('post_time', $_POST['post_time']);
  396. $directoryParentId = isset($_POST['directory_parent_id']) ? $_POST['directory_parent_id'] : 0;
  397. $courseInfo = api_get_course_info();
  398. if (empty($directoryParentId)) {
  399. $_SESSION['oLP']->generate_lp_folder($courseInfo);
  400. }
  401. $parent = isset($_POST['parent']) ? $_POST['parent'] : '';
  402. $previous = isset($_POST['previous']) ? $_POST['previous'] : '';
  403. $type = isset($_POST['type']) ? $_POST['type'] : '';
  404. $path = isset($_POST['path']) ? $_POST['path'] : '';
  405. $description = isset($_POST['description']) ? $_POST['description'] : '';
  406. $prerequisites = isset($_POST['prerequisites']) ? $_POST['prerequisites'] : '';
  407. $maxTimeAllowed = isset($_POST['maxTimeAllowed']) ? $_POST['maxTimeAllowed'] : '';
  408. if ($_POST['type'] == TOOL_DOCUMENT) {
  409. if (isset($_POST['path']) && $_GET['edit'] != 'true') {
  410. $document_id = $_POST['path'];
  411. } else {
  412. if ($_POST['content_lp']) {
  413. $document_id = $_SESSION['oLP']->create_document(
  414. $_course,
  415. $_POST['content_lp'],
  416. $_POST['title'],
  417. 'html',
  418. $directoryParentId
  419. );
  420. }
  421. }
  422. $new_item_id = $_SESSION['oLP']->add_item(
  423. $parent,
  424. $previous,
  425. $type,
  426. $document_id,
  427. $post_title,
  428. $description,
  429. $prerequisites
  430. );
  431. } elseif ($_POST['type'] == TOOL_READOUT_TEXT) {
  432. if (isset($_POST['path']) && $_GET['edit'] != 'true') {
  433. $document_id = $_POST['path'];
  434. } else {
  435. $document_id = $_SESSION['oLP']->createReadOutText(
  436. $_course,
  437. $_POST['content_lp'],
  438. $_POST['title'],
  439. $directoryParentId
  440. );
  441. }
  442. $new_item_id = $_SESSION['oLP']->add_item(
  443. $parent,
  444. $previous,
  445. TOOL_READOUT_TEXT,
  446. $document_id,
  447. $post_title,
  448. $description,
  449. $prerequisites
  450. );
  451. } else {
  452. // For all other item types than documents,
  453. // load the item using the item type and path rather than its ID.
  454. $new_item_id = $_SESSION['oLP']->add_item(
  455. $parent,
  456. $previous,
  457. $type,
  458. $path,
  459. $post_title,
  460. $description,
  461. $prerequisites,
  462. $maxTimeAllowed
  463. );
  464. }
  465. $url = api_get_self().'?action=add_item&type=step&lp_id='.intval($_SESSION['oLP']->lp_id).'&'.api_get_cidreq();
  466. header('Location: '.$url);
  467. exit;
  468. }
  469. } else {
  470. require 'lp_add_item.php';
  471. }
  472. }
  473. break;
  474. case 'add_users_to_category':
  475. if (!$is_allowed_to_edit) {
  476. api_not_allowed(true);
  477. }
  478. require 'lp_subscribe_users_to_category.php';
  479. break;
  480. case 'add_audio':
  481. if (!$is_allowed_to_edit) {
  482. api_not_allowed(true);
  483. }
  484. if (!$lp_found) {
  485. // Check if the learnpath ID was defined, otherwise send back to list
  486. require 'lp_list.php';
  487. } else {
  488. Session::write('refresh', 1);
  489. if (isset($_REQUEST['id'])) {
  490. $lp_item_obj = new learnpathItem($_REQUEST['id']);
  491. // Remove audio
  492. if (isset($_GET['delete_file']) && $_GET['delete_file'] == 1) {
  493. $lp_item_obj->remove_audio();
  494. $url = api_get_self().'?action=add_audio&lp_id='.intval($_SESSION['oLP']->lp_id).'&id='.$lp_item_obj->get_id().'&'.api_get_cidreq();
  495. header('Location: '.$url);
  496. exit;
  497. }
  498. // Upload audio
  499. if (isset($_FILES['file']) && !empty($_FILES['file'])) {
  500. // Updating the lp.modified_on
  501. $_SESSION['oLP']->set_modified_on();
  502. $lp_item_obj->add_audio();
  503. }
  504. //Add audio file from documents
  505. if (isset($_REQUEST['document_id']) && !empty($_REQUEST['document_id'])) {
  506. $_SESSION['oLP']->set_modified_on();
  507. $lp_item_obj->add_audio_from_documents($_REQUEST['document_id']);
  508. }
  509. // Display.
  510. require 'lp_add_audio.php';
  511. } else {
  512. require 'lp_add_audio.php';
  513. }
  514. }
  515. break;
  516. case 'add_lp_category':
  517. if (!$is_allowed_to_edit) {
  518. api_not_allowed(true);
  519. }
  520. require 'lp_add_category.php';
  521. break;
  522. case 'move_up_category':
  523. if (!$is_allowed_to_edit) {
  524. api_not_allowed(true);
  525. }
  526. if (isset($_REQUEST['id'])) {
  527. learnpath::moveUpCategory($_REQUEST['id']);
  528. }
  529. require 'lp_list.php';
  530. break;
  531. case 'move_down_category':
  532. if (!$is_allowed_to_edit) {
  533. api_not_allowed(true);
  534. }
  535. if (isset($_REQUEST['id'])) {
  536. learnpath::moveDownCategory($_REQUEST['id']);
  537. }
  538. require 'lp_list.php';
  539. break;
  540. case 'delete_lp_category':
  541. if (!$is_allowed_to_edit) {
  542. api_not_allowed(true);
  543. }
  544. if (isset($_REQUEST['id'])) {
  545. $result = learnpath::deleteCategory($_REQUEST['id']);
  546. if ($result) {
  547. Display::addFlash(Display::return_message(get_lang('Deleted')));
  548. }
  549. }
  550. require 'lp_list.php';
  551. break;
  552. case 'add_lp':
  553. if (!$is_allowed_to_edit) {
  554. api_not_allowed(true);
  555. }
  556. if (isset($_REQUEST['lp_name']) && !empty($_REQUEST['lp_name'])) {
  557. $_REQUEST['lp_name'] = trim($_REQUEST['lp_name']);
  558. Session::write('refresh', 1);
  559. if (isset($_SESSION['post_time']) && $_SESSION['post_time'] == $_REQUEST['post_time']) {
  560. require 'lp_add.php';
  561. } else {
  562. Session::write('post_time', $_POST['post_time']);
  563. if (isset($_REQUEST['activate_start_date_check']) &&
  564. $_REQUEST['activate_start_date_check'] == 1
  565. ) {
  566. $publicated_on = $_REQUEST['publicated_on'];
  567. } else {
  568. $publicated_on = null;
  569. }
  570. if (isset($_REQUEST['activate_end_date_check']) &&
  571. $_REQUEST['activate_end_date_check'] == 1
  572. ) {
  573. $expired_on = $_REQUEST['expired_on'];
  574. } else {
  575. $expired_on = null;
  576. }
  577. $new_lp_id = learnpath::add_lp(
  578. api_get_course_id(),
  579. Security::remove_XSS($_REQUEST['lp_name']),
  580. '',
  581. 'chamilo',
  582. 'manual',
  583. '',
  584. $publicated_on,
  585. $expired_on,
  586. $_REQUEST['category_id']
  587. );
  588. if (is_numeric($new_lp_id)) {
  589. // Create temp form validator to save skills
  590. $form = new FormValidator('lp_add');
  591. $form->addSelect('skills', 'skills');
  592. Skill::saveSkills($form, ITEM_TYPE_LEARNPATH, $new_lp_id);
  593. // TODO: Maybe create a first directory directly to avoid bugging the user with useless queries
  594. $_SESSION['oLP'] = new learnpath(
  595. api_get_course_id(),
  596. $new_lp_id,
  597. api_get_user_id()
  598. );
  599. $accumulateScormTime = isset($_REQUEST['accumulate_scorm_time']) ? $_REQUEST['accumulate_scorm_time'] : 'true';
  600. $_SESSION['oLP']->setAccumulateScormTime($accumulateScormTime);
  601. $url = api_get_self().'?action=add_item&type=step&lp_id='.intval($new_lp_id).'&'.api_get_cidreq();
  602. header("Location: $url&isStudentView=false");
  603. exit;
  604. }
  605. }
  606. } else {
  607. require 'lp_add.php';
  608. }
  609. break;
  610. case 'admin_view':
  611. if (!$is_allowed_to_edit) {
  612. api_not_allowed(true);
  613. }
  614. if (!$lp_found) {
  615. require 'lp_list.php';
  616. } else {
  617. Session::write('refresh', 1);
  618. require 'lp_admin_view.php';
  619. }
  620. break;
  621. case 'auto_launch':
  622. // Redirect to a specific LP
  623. if (api_get_course_setting('enable_lp_auto_launch') == 1) {
  624. if (!$is_allowed_to_edit) {
  625. api_not_allowed(true);
  626. }
  627. if (!$lp_found) {
  628. require 'lp_list.php';
  629. } else {
  630. $_SESSION['oLP']->set_autolaunch($_GET['lp_id'], $_GET['status']);
  631. require 'lp_list.php';
  632. exit;
  633. }
  634. }
  635. break;
  636. case 'build':
  637. if (!$is_allowed_to_edit) {
  638. api_not_allowed(true);
  639. }
  640. if (!$lp_found) {
  641. require 'lp_list.php';
  642. } else {
  643. Session::write('refresh', 1);
  644. //require 'lp_build.php';
  645. $url = api_get_self().'?action=add_item&type=step&lp_id='.intval($_SESSION['oLP']->lp_id).'&'.api_get_cidreq();
  646. header('Location: '.$url);
  647. exit;
  648. }
  649. break;
  650. case 'edit_item':
  651. if (!$is_allowed_to_edit) {
  652. api_not_allowed(true);
  653. }
  654. if (!$lp_found) {
  655. require 'lp_list.php';
  656. } else {
  657. Session::write('refresh', 1);
  658. if (isset($_POST['submit_button']) && !empty($post_title)) {
  659. //Updating the lp.modified_on
  660. $_SESSION['oLP']->set_modified_on();
  661. // TODO: mp3 edit
  662. $audio = [];
  663. if (isset($_FILES['mp3'])) {
  664. $audio = $_FILES['mp3'];
  665. }
  666. $description = isset($_POST['description']) ? $_POST['description'] : '';
  667. $prerequisites = isset($_POST['prerequisites']) ? $_POST['prerequisites'] : '';
  668. $maxTimeAllowed = isset($_POST['maxTimeAllowed']) ? $_POST['maxTimeAllowed'] : '';
  669. $url = isset($_POST['url']) ? $_POST['url'] : '';
  670. $_SESSION['oLP']->edit_item(
  671. $_REQUEST['id'],
  672. $_POST['parent'],
  673. $_POST['previous'],
  674. $post_title,
  675. $description,
  676. $prerequisites,
  677. $audio,
  678. $maxTimeAllowed,
  679. $url
  680. );
  681. if (isset($_POST['content_lp'])) {
  682. $_SESSION['oLP']->edit_document($_course);
  683. }
  684. $is_success = true;
  685. Display::addFlash(Display::return_message(get_lang('Updated')));
  686. $url = api_get_self().'?action=add_item&type=step&lp_id='.intval($_SESSION['oLP']->lp_id).'&'.api_get_cidreq();
  687. header('Location: '.$url);
  688. exit;
  689. }
  690. if (isset($_GET['view']) && $_GET['view'] == 'build') {
  691. require 'lp_edit_item.php';
  692. } else {
  693. require 'lp_admin_view.php';
  694. }
  695. }
  696. break;
  697. case 'edit_item_prereq':
  698. if (!$is_allowed_to_edit) {
  699. api_not_allowed(true);
  700. }
  701. if (!$lp_found) {
  702. require 'lp_list.php';
  703. } else {
  704. if (isset($_POST['submit_button'])) {
  705. // Updating the lp.modified_on
  706. $_SESSION['oLP']->set_modified_on();
  707. Session::write('refresh', 1);
  708. $min = isset($_POST['min_'.$_POST['prerequisites']]) ? $_POST['min_'.$_POST['prerequisites']] : '';
  709. $max = isset($_POST['max_'.$_POST['prerequisites']]) ? $_POST['max_'.$_POST['prerequisites']] : '';
  710. $editPrerequisite = $_SESSION['oLP']->edit_item_prereq(
  711. $_GET['id'],
  712. $_POST['prerequisites'],
  713. $min,
  714. $max
  715. );
  716. if ($editPrerequisite) {
  717. $is_success = true;
  718. }
  719. Display::addFlash(Display::return_message(get_lang('Updated')));
  720. $url = api_get_self().'?action=add_item&type=step&lp_id='.intval($_SESSION['oLP']->lp_id).'&'.api_get_cidreq();
  721. header('Location: '.$url);
  722. exit;
  723. } else {
  724. require 'lp_edit_item_prereq.php';
  725. }
  726. }
  727. break;
  728. case 'move_item':
  729. if (!$is_allowed_to_edit) {
  730. api_not_allowed(true);
  731. }
  732. if (!$lp_found) {
  733. require 'lp_list.php';
  734. } else {
  735. Session::write('refresh', 1);
  736. if (isset($_POST['submit_button'])) {
  737. //Updating the lp.modified_on
  738. $_SESSION['oLP']->set_modified_on();
  739. $_SESSION['oLP']->edit_item(
  740. $_GET['id'],
  741. $_POST['parent'],
  742. $_POST['previous'],
  743. $post_title,
  744. $_POST['description']
  745. );
  746. $is_success = true;
  747. $url = api_get_self().'?action=add_item&type=step&lp_id='.intval($_SESSION['oLP']->lp_id).'&'.api_get_cidreq();
  748. header('Location: '.$url);
  749. exit;
  750. }
  751. if (isset($_GET['view']) && $_GET['view'] == 'build') {
  752. require 'lp_move_item.php';
  753. } else {
  754. // Avoids weird behaviours see CT#967.
  755. $check = Security::check_token('get');
  756. if ($check) {
  757. $_SESSION['oLP']->move_item($_GET['id'], $_GET['direction']);
  758. }
  759. Security::clear_token();
  760. require 'lp_admin_view.php';
  761. }
  762. }
  763. break;
  764. case 'view_item':
  765. if (!$is_allowed_to_edit) {
  766. api_not_allowed(true);
  767. }
  768. if (!$lp_found) {
  769. require 'lp_list.php';
  770. } else {
  771. Session::write('refresh', 1);
  772. require 'lp_view_item.php';
  773. }
  774. break;
  775. case 'upload':
  776. if (!$is_allowed_to_edit) {
  777. api_not_allowed(true);
  778. }
  779. $cwdir = getcwd();
  780. require 'lp_upload.php';
  781. // Reinit current working directory as many functions in upload change it.
  782. chdir($cwdir);
  783. require 'lp_list.php';
  784. break;
  785. case 'copy':
  786. if (!$is_allowed_to_edit) {
  787. api_not_allowed(true);
  788. }
  789. $hideScormCopyLink = api_get_setting('hide_scorm_copy_link');
  790. if ($hideScormCopyLink === 'true') {
  791. api_not_allowed(true);
  792. }
  793. if (!$lp_found) {
  794. require 'lp_list.php';
  795. } else {
  796. $_SESSION['oLP']->copy();
  797. }
  798. require 'lp_list.php';
  799. break;
  800. case 'export':
  801. if (!$is_allowed_to_edit) {
  802. api_not_allowed(true);
  803. }
  804. $hideScormExportLink = api_get_setting('hide_scorm_export_link');
  805. if ($hideScormExportLink === 'true') {
  806. api_not_allowed(true);
  807. }
  808. if (!$lp_found) {
  809. require 'lp_list.php';
  810. } else {
  811. $_SESSION['oLP']->scormExport();
  812. exit();
  813. }
  814. break;
  815. case 'export_to_pdf':
  816. $hideScormPdfLink = api_get_setting('hide_scorm_pdf_link');
  817. if ($hideScormPdfLink === 'true') {
  818. api_not_allowed(true);
  819. }
  820. // Teachers can export to PDF
  821. if (!$is_allowed_to_edit) {
  822. if (!learnpath::is_lp_visible_for_student($_SESSION['oLP']->lp_id, api_get_user_id())) {
  823. api_not_allowed();
  824. }
  825. }
  826. if (!$lp_found) {
  827. require 'lp_list.php';
  828. } else {
  829. $result = $_SESSION['oLP']->scorm_export_to_pdf($_GET['lp_id']);
  830. if (!$result) {
  831. require 'lp_list.php';
  832. }
  833. exit;
  834. }
  835. break;
  836. case 'export_to_course_build':
  837. $allowExport = api_get_configuration_value('allow_lp_chamilo_export');
  838. if (api_is_allowed_to_edit() && $allowExport) {
  839. if (!$lp_found) {
  840. require 'lp_list.php';
  841. } else {
  842. $result = $_SESSION['oLP']->exportToCourseBuildFormat($_GET['lp_id']);
  843. if (!$result) {
  844. require 'lp_list.php';
  845. }
  846. exit;
  847. }
  848. }
  849. require 'lp_list.php';
  850. break;
  851. case 'delete':
  852. if (!$is_allowed_to_edit) {
  853. api_not_allowed(true);
  854. }
  855. if (!$lp_found) {
  856. require 'lp_list.php';
  857. } else {
  858. Session::write('refresh', 1);
  859. $_SESSION['oLP']->delete(null, $_GET['lp_id'], 'remove');
  860. Skill::deleteSkillsFromItem($_GET['lp_id'], ITEM_TYPE_LEARNPATH);
  861. Display::addFlash(Display::return_message(get_lang('Deleted')));
  862. Session::erase('oLP');
  863. require 'lp_list.php';
  864. }
  865. break;
  866. case 'toggle_category_visibility':
  867. if (!$is_allowed_to_edit) {
  868. api_not_allowed(true);
  869. }
  870. learnpath::toggleCategoryVisibility($_REQUEST['id'], $_REQUEST['new_status']);
  871. Display::addFlash(Display::return_message(get_lang('Updated')));
  872. header('Location: '.api_get_self().'?'.api_get_cidreq());
  873. exit;
  874. case 'toggle_visible':
  875. // Change lp visibility (inside lp tool).
  876. if (!$is_allowed_to_edit) {
  877. api_not_allowed(true);
  878. }
  879. if (!$lp_found) {
  880. require 'lp_list.php';
  881. } else {
  882. learnpath::toggle_visibility($_REQUEST['lp_id'], $_REQUEST['new_status']);
  883. Display::addFlash(Display::return_message(get_lang('Updated')));
  884. require 'lp_list.php';
  885. }
  886. break;
  887. case 'toggle_category_publish':
  888. if (!$is_allowed_to_edit) {
  889. api_not_allowed(true);
  890. }
  891. learnpath::toggleCategoryPublish($_REQUEST['id'], $_REQUEST['new_status']);
  892. Display::addFlash(Display::return_message(get_lang('Updated')));
  893. require 'lp_list.php';
  894. break;
  895. case 'toggle_publish':
  896. // Change lp published status (visibility on homepage).
  897. if (!$is_allowed_to_edit) {
  898. api_not_allowed(true);
  899. }
  900. if (!$lp_found) {
  901. require 'lp_list.php';
  902. } else {
  903. learnpath::toggle_publish($_REQUEST['lp_id'], $_REQUEST['new_status']);
  904. Display::addFlash(Display::return_message(get_lang('Updated')));
  905. require 'lp_list.php';
  906. }
  907. break;
  908. case 'move_lp_up':
  909. // Change lp published status (visibility on homepage)
  910. if (!$is_allowed_to_edit) {
  911. api_not_allowed(true);
  912. }
  913. if (!$lp_found) {
  914. require 'lp_list.php';
  915. } else {
  916. learnpath::move_up($_REQUEST['lp_id'], $_REQUEST['category_id']);
  917. Display::addFlash(Display::return_message(get_lang('Updated')));
  918. require 'lp_list.php';
  919. }
  920. break;
  921. case 'move_lp_down':
  922. // Change lp published status (visibility on homepage)
  923. if (!$is_allowed_to_edit) {
  924. api_not_allowed(true);
  925. }
  926. if (!$lp_found) {
  927. require 'lp_list.php';
  928. } else {
  929. learnpath::move_down($_REQUEST['lp_id'], $_REQUEST['category_id']);
  930. Display::addFlash(Display::return_message(get_lang('Updated')));
  931. require 'lp_list.php';
  932. }
  933. break;
  934. case 'edit':
  935. if (!$is_allowed_to_edit) {
  936. api_not_allowed(true);
  937. }
  938. if (!$lp_found) {
  939. require 'lp_list.php';
  940. } else {
  941. Session::write('refresh', 1);
  942. require 'lp_edit.php';
  943. }
  944. break;
  945. case 'update_lp':
  946. if (!$is_allowed_to_edit) {
  947. api_not_allowed(true);
  948. }
  949. if (!$lp_found) {
  950. require 'lp_list.php';
  951. } else {
  952. Session::write('refresh', 1);
  953. $lp_name = Security::remove_XSS($_REQUEST['lp_name']);
  954. $_SESSION['oLP']->set_name($lp_name);
  955. $author = $_REQUEST['lp_author'];
  956. // Fixing the author name (no body or html tags).
  957. $auth_init = stripos($author, '<p>');
  958. if ($auth_init === false) {
  959. $auth_init = stripos($author, '<body>');
  960. $auth_end = $auth_init + stripos(substr($author, $auth_init + 6), '</body>') + 7;
  961. $len = $auth_end - $auth_init + 6;
  962. } else {
  963. $auth_end = strripos($author, '</p>');
  964. $len = $auth_end - $auth_init + 4;
  965. }
  966. $author_fixed = substr($author, $auth_init, $len);
  967. $_SESSION['oLP']->set_author($author_fixed);
  968. // TODO (as of Chamilo 1.8.8): Check in the future whether this field is needed.
  969. $_SESSION['oLP']->set_encoding($_REQUEST['lp_encoding']);
  970. if (isset($_REQUEST['lp_maker'])) {
  971. $_SESSION['oLP']->set_maker($_REQUEST['lp_maker']);
  972. }
  973. if (isset($_REQUEST['lp_proximity'])) {
  974. $_SESSION['oLP']->set_proximity($_REQUEST['lp_proximity']);
  975. }
  976. $_SESSION['oLP']->set_theme($_REQUEST['lp_theme']);
  977. if (isset($_REQUEST['hide_toc_frame']) && $_REQUEST['hide_toc_frame'] == 1) {
  978. $hide_toc_frame = $_REQUEST['hide_toc_frame'];
  979. } else {
  980. $hide_toc_frame = null;
  981. }
  982. $_SESSION['oLP']->set_hide_toc_frame($hide_toc_frame);
  983. $_SESSION['oLP']->set_prerequisite(isset($_POST['prerequisites']) ? (int) $_POST['prerequisites'] : 0);
  984. $_SESSION['oLP']->setAccumulateWorkTime(isset($_REQUEST['accumulate_work_time']) ? $_REQUEST['accumulate_work_time'] : 0);
  985. $_SESSION['oLP']->set_use_max_score(isset($_POST['use_max_score']) ? 1 : 0);
  986. $subscribeUsers = isset($_REQUEST['subscribe_users']) ? 1 : 0;
  987. $_SESSION['oLP']->setSubscribeUsers($subscribeUsers);
  988. $accumulateScormTime = isset($_REQUEST['accumulate_scorm_time']) ? $_REQUEST['accumulate_scorm_time'] : 'true';
  989. $_SESSION['oLP']->setAccumulateScormTime($accumulateScormTime);
  990. if (isset($_REQUEST['activate_start_date_check']) && $_REQUEST['activate_start_date_check'] == 1) {
  991. $publicated_on = $_REQUEST['publicated_on'];
  992. } else {
  993. $publicated_on = null;
  994. }
  995. if (isset($_REQUEST['activate_end_date_check']) && $_REQUEST['activate_end_date_check'] == 1) {
  996. $expired_on = $_REQUEST['expired_on'];
  997. } else {
  998. $expired_on = null;
  999. }
  1000. $_SESSION['oLP']->setCategoryId($_REQUEST['category_id']);
  1001. $_SESSION['oLP']->set_modified_on();
  1002. $_SESSION['oLP']->set_publicated_on($publicated_on);
  1003. $_SESSION['oLP']->set_expired_on($expired_on);
  1004. if (isset($_REQUEST['remove_picture']) && $_REQUEST['remove_picture']) {
  1005. $_SESSION['oLP']->delete_lp_image();
  1006. }
  1007. $extraFieldValue = new ExtraFieldValue('lp');
  1008. $_REQUEST['item_id'] = $_SESSION['oLP']->lp_id;
  1009. $extraFieldValue->saveFieldValues($_REQUEST);
  1010. if ($_FILES['lp_preview_image']['size'] > 0) {
  1011. $_SESSION['oLP']->upload_image($_FILES['lp_preview_image']);
  1012. }
  1013. $form = new FormValidator('form1');
  1014. $form->addSelect('skills', 'skills');
  1015. Skill::saveSkills($form, ITEM_TYPE_LEARNPATH, $_SESSION['oLP']->get_id());
  1016. if (api_get_setting('search_enabled') === 'true') {
  1017. require_once api_get_path(LIBRARY_PATH).'specific_fields_manager.lib.php';
  1018. $specific_fields = get_specific_field_list();
  1019. foreach ($specific_fields as $specific_field) {
  1020. $_SESSION['oLP']->set_terms_by_prefix($_REQUEST[$specific_field['code']], $specific_field['code']);
  1021. $new_values = explode(',', trim($_REQUEST[$specific_field['code']]));
  1022. if (!empty($new_values)) {
  1023. array_walk($new_values, 'trim');
  1024. delete_all_specific_field_value(
  1025. api_get_course_id(),
  1026. $specific_field['id'],
  1027. TOOL_LEARNPATH,
  1028. $_SESSION['oLP']->lp_id
  1029. );
  1030. foreach ($new_values as $value) {
  1031. if (!empty($value)) {
  1032. add_specific_field_value(
  1033. $specific_field['id'],
  1034. api_get_course_id(),
  1035. TOOL_LEARNPATH,
  1036. $_SESSION['oLP']->lp_id,
  1037. $value
  1038. );
  1039. }
  1040. }
  1041. }
  1042. }
  1043. }
  1044. Display::addFlash(Display::return_message(get_lang('Updated')));
  1045. $url = api_get_self().'?action=add_item&type=step&lp_id='.intval($_SESSION['oLP']->lp_id).'&'.api_get_cidreq();
  1046. header('Location: '.$url);
  1047. exit;
  1048. }
  1049. break;
  1050. case 'add_sub_item':
  1051. // Add an item inside a dir/chapter.
  1052. // @todo check if this is @deprecated
  1053. if (!$is_allowed_to_edit) {
  1054. api_not_allowed(true);
  1055. }
  1056. if (!$lp_found) {
  1057. require 'lp_list.php';
  1058. } else {
  1059. Session::write('refresh', 1);
  1060. if (!empty($_REQUEST['parent_item_id'])) {
  1061. $_SESSION['from_learnpath'] = 'yes';
  1062. $_SESSION['origintoolurl'] = 'lp_controller.php?action=admin_view&lp_id='.intval($_REQUEST['lp_id']);
  1063. } else {
  1064. require 'lp_admin_view.php';
  1065. }
  1066. }
  1067. break;
  1068. case 'deleteitem':
  1069. case 'delete_item':
  1070. if (!$is_allowed_to_edit) {
  1071. api_not_allowed(true);
  1072. }
  1073. if (!$lp_found) {
  1074. require 'lp_list.php';
  1075. } else {
  1076. if (!empty($_REQUEST['id'])) {
  1077. $_SESSION['oLP']->delete_item($_REQUEST['id']);
  1078. }
  1079. $url = api_get_self().'?action=add_item&type=step&lp_id='.intval($_REQUEST['lp_id']).'&'.api_get_cidreq();
  1080. header('Location: '.$url);
  1081. exit;
  1082. }
  1083. break;
  1084. case 'restart':
  1085. if (!$lp_found) {
  1086. require 'lp_list.php';
  1087. } else {
  1088. $_SESSION['oLP']->restart();
  1089. require 'lp_view.php';
  1090. }
  1091. break;
  1092. case 'last':
  1093. if (!$lp_found) {
  1094. require 'lp_list.php';
  1095. } else {
  1096. $_SESSION['oLP']->last();
  1097. require 'lp_view.php';
  1098. }
  1099. break;
  1100. case 'first':
  1101. if (!$lp_found) {
  1102. require 'lp_list.php';
  1103. } else {
  1104. $_SESSION['oLP']->first();
  1105. require 'lp_view.php';
  1106. }
  1107. break;
  1108. case 'next':
  1109. if (!$lp_found) {
  1110. require 'lp_list.php';
  1111. } else {
  1112. $_SESSION['oLP']->next();
  1113. require 'lp_view.php';
  1114. }
  1115. break;
  1116. case 'previous':
  1117. if (!$lp_found) {
  1118. require 'lp_list.php';
  1119. } else {
  1120. $_SESSION['oLP']->previous();
  1121. require 'lp_view.php';
  1122. }
  1123. break;
  1124. case 'content':
  1125. if ($debug > 0) {
  1126. error_log('lp_controller: action: content');
  1127. error_log('Item id is '.intval($_GET['item_id']));
  1128. }
  1129. if (!$lp_found) {
  1130. require 'lp_list.php';
  1131. } else {
  1132. if ($debug > 0) {
  1133. error_log('save_last()');
  1134. }
  1135. $_SESSION['oLP']->save_last();
  1136. if ($debug > 0) {
  1137. error_log('set_current_item('.$_GET['item_id'].')');
  1138. }
  1139. $_SESSION['oLP']->set_current_item($_GET['item_id']);
  1140. if ($debug > 0) {
  1141. error_log('start_current_item()');
  1142. }
  1143. $_SESSION['oLP']->start_current_item();
  1144. require 'lp_content.php';
  1145. }
  1146. break;
  1147. case 'view':
  1148. if (!$lp_found) {
  1149. require 'lp_list.php';
  1150. } else {
  1151. if ($debug > 0) {
  1152. error_log('Trying to set current item to '.$_REQUEST['item_id'], 0);
  1153. }
  1154. if (!empty($_REQUEST['item_id'])) {
  1155. $_SESSION['oLP']->set_current_item($_REQUEST['item_id']);
  1156. }
  1157. require 'lp_view.php';
  1158. }
  1159. break;
  1160. case 'save':
  1161. if (!$lp_found) {
  1162. require 'lp_list.php';
  1163. } else {
  1164. $_SESSION['oLP']->save_item();
  1165. require 'lp_save.php';
  1166. }
  1167. break;
  1168. case 'stats':
  1169. if (!$lp_found) {
  1170. require 'lp_list.php';
  1171. } else {
  1172. $_SESSION['oLP']->save_current();
  1173. $_SESSION['oLP']->save_last();
  1174. $output = require 'lp_stats.php';
  1175. echo $output;
  1176. }
  1177. break;
  1178. case 'list':
  1179. if ($lp_found) {
  1180. Session::write('refresh', 1);
  1181. $_SESSION['oLP']->save_last();
  1182. }
  1183. require 'lp_list.php';
  1184. break;
  1185. case 'mode':
  1186. // Switch between fullscreen and embedded mode.
  1187. $mode = $_REQUEST['mode'];
  1188. if ($mode == 'fullscreen') {
  1189. $_SESSION['oLP']->mode = 'fullscreen';
  1190. } elseif ($mode == 'embedded') {
  1191. $_SESSION['oLP']->mode = 'embedded';
  1192. } elseif ($mode == 'embedframe') {
  1193. $_SESSION['oLP']->mode = 'embedframe';
  1194. } elseif ($mode == 'impress') {
  1195. $_SESSION['oLP']->mode = 'impress';
  1196. }
  1197. require 'lp_view.php';
  1198. break;
  1199. case 'switch_view_mode':
  1200. if (!$lp_found) {
  1201. require 'lp_list.php';
  1202. }
  1203. if (Security::check_token('get')) {
  1204. Session::write('refresh', 1);
  1205. $_SESSION['oLP']->update_default_view_mode();
  1206. }
  1207. require 'lp_list.php';
  1208. break;
  1209. case 'switch_force_commit':
  1210. if (!$lp_found) {
  1211. require 'lp_list.php';
  1212. }
  1213. Session::write('refresh', 1);
  1214. $_SESSION['oLP']->update_default_scorm_commit();
  1215. require 'lp_list.php';
  1216. break;
  1217. case 'switch_attempt_mode':
  1218. if (!$lp_found) {
  1219. require 'lp_list.php';
  1220. }
  1221. Session::write('refresh', 1);
  1222. $_SESSION['oLP']->switch_attempt_mode();
  1223. require 'lp_list.php';
  1224. break;
  1225. case 'switch_scorm_debug':
  1226. if (!$lp_found) {
  1227. require 'lp_list.php';
  1228. }
  1229. Session::write('refresh', 1);
  1230. $_SESSION['oLP']->update_scorm_debug();
  1231. require 'lp_list.php';
  1232. break;
  1233. case 'intro_cmdAdd':
  1234. // Add introduction section page.
  1235. break;
  1236. case 'return_to_course_homepage':
  1237. if (!$lp_found) {
  1238. require 'lp_list.php';
  1239. } else {
  1240. $_SESSION['oLP']->save_current();
  1241. $_SESSION['oLP']->save_last();
  1242. if ($debug > 0) {
  1243. error_log('save_current()');
  1244. error_log('save_last()');
  1245. }
  1246. $url = api_get_path(WEB_COURSE_PATH).api_get_course_path().'/index.php?id_session='.api_get_session_id();
  1247. $redirectTo = isset($_GET['redirectTo']) ? $_GET['redirectTo'] : '';
  1248. switch ($redirectTo) {
  1249. case 'lp_list':
  1250. $url = 'lp_controller.php?'.api_get_cidreq();
  1251. break;
  1252. case 'my_courses':
  1253. $url = api_get_path(WEB_PATH).'user_portal.php';
  1254. break;
  1255. }
  1256. header('location: '.$url);
  1257. exit;
  1258. }
  1259. break;
  1260. case 'search':
  1261. /* Include the search script, it's smart enough to know when we are
  1262. * searching or not.
  1263. */
  1264. require 'lp_list_search.php';
  1265. break;
  1266. case 'impress':
  1267. if (!$lp_found) {
  1268. require 'lp_list.php';
  1269. } else {
  1270. if ($debug > 0) {
  1271. error_log('Trying to impress this LP item to '.$_REQUEST['item_id'], 0);
  1272. }
  1273. if (!empty($_REQUEST['item_id'])) {
  1274. $_SESSION['oLP']->set_current_item($_REQUEST['item_id']);
  1275. }
  1276. require 'lp_impress.php';
  1277. }
  1278. break;
  1279. case 'set_previous_step_as_prerequisite':
  1280. $_SESSION['oLP']->set_previous_step_as_prerequisite_for_all_items();
  1281. $url = api_get_self().'?action=add_item&type=step&lp_id='.intval($_SESSION['oLP']->lp_id)."&".api_get_cidreq();
  1282. Display::addFlash(Display::return_message(get_lang('ItemUpdated')));
  1283. header('Location: '.$url);
  1284. exit;
  1285. break;
  1286. case 'clear_prerequisites':
  1287. $_SESSION['oLP']->clear_prerequisites();
  1288. $url = api_get_self().'?action=add_item&type=step&lp_id='.intval($_SESSION['oLP']->lp_id)."&".api_get_cidreq();
  1289. Display::addFlash(Display::return_message(get_lang('ItemUpdated')));
  1290. header('Location: '.$url);
  1291. exit;
  1292. break;
  1293. case 'toggle_seriousgame':
  1294. // activate/deactive seriousgame_mode
  1295. if (!$is_allowed_to_edit) {
  1296. api_not_allowed(true);
  1297. }
  1298. if (!$lp_found) {
  1299. require 'lp_list.php';
  1300. }
  1301. Session::write('refresh', 1);
  1302. $_SESSION['oLP']->set_seriousgame_mode();
  1303. require 'lp_list.php';
  1304. break;
  1305. case 'create_forum':
  1306. if (!isset($_GET['id'])) {
  1307. break;
  1308. }
  1309. $selectedItem = null;
  1310. foreach ($_SESSION['oLP']->items as $item) {
  1311. if ($item->db_id == $_GET['id']) {
  1312. $selectedItem = $item;
  1313. }
  1314. }
  1315. if (!empty($selectedItem)) {
  1316. $forumThread = $selectedItem->getForumThread(
  1317. $_SESSION['oLP']->course_int_id,
  1318. $_SESSION['oLP']->lp_session_id
  1319. );
  1320. if (empty($forumThread)) {
  1321. require '../forum/forumfunction.inc.php';
  1322. $forumCategory = getForumCategoryByTitle(
  1323. get_lang('LearningPaths'),
  1324. $_SESSION['oLP']->course_int_id,
  1325. $_SESSION['oLP']->lp_session_id
  1326. );
  1327. $forumCategoryId = !empty($forumCategory) ? $forumCategory['cat_id'] : 0;
  1328. if (empty($forumCategoryId)) {
  1329. $forumCategoryId = store_forumcategory(
  1330. [
  1331. 'lp_id' => 0,
  1332. 'forum_category_title' => get_lang('LearningPaths'),
  1333. 'forum_category_comment' => null,
  1334. ],
  1335. [],
  1336. false
  1337. );
  1338. }
  1339. if (!empty($forumCategoryId)) {
  1340. $forum = $_SESSION['oLP']->getForum(
  1341. $_SESSION['oLP']->lp_session_id
  1342. );
  1343. $forumId = !empty($forum) ? $forum['forum_id'] : 0;
  1344. if (empty($forumId)) {
  1345. $forumId = $_SESSION['oLP']->createForum($forumCategoryId);
  1346. }
  1347. if (!empty($forumId)) {
  1348. $selectedItem->createForumThread($forumId);
  1349. }
  1350. }
  1351. }
  1352. }
  1353. header('Location:'.api_get_self().'?'.http_build_query([
  1354. 'action' => 'add_item',
  1355. 'type' => 'step',
  1356. 'lp_id' => $_SESSION['oLP']->lp_id,
  1357. ]));
  1358. exit;
  1359. break;
  1360. case 'report':
  1361. require 'lp_report.php';
  1362. break;
  1363. case 'dissociate_forum':
  1364. if (!isset($_GET['id'])) {
  1365. break;
  1366. }
  1367. $selectedItem = null;
  1368. foreach ($_SESSION['oLP']->items as $item) {
  1369. if ($item->db_id != $_GET['id']) {
  1370. continue;
  1371. }
  1372. $selectedItem = $item;
  1373. }
  1374. if (!empty($selectedItem)) {
  1375. $forumThread = $selectedItem->getForumThread(
  1376. $_SESSION['oLP']->course_int_id,
  1377. $_SESSION['oLP']->lp_session_id
  1378. );
  1379. if (!empty($forumThread)) {
  1380. $dissociated = $selectedItem->dissociateForumThread($forumThread['iid']);
  1381. if ($dissociated) {
  1382. Display::addFlash(
  1383. Display::return_message(get_lang('ForumDissociate'), 'success')
  1384. );
  1385. }
  1386. }
  1387. }
  1388. header('Location:'.api_get_self().'?'.http_build_query([
  1389. 'action' => 'add_item',
  1390. 'type' => 'step',
  1391. 'lp_id' => $_SESSION['oLP']->lp_id,
  1392. ]));
  1393. exit;
  1394. break;
  1395. case 'add_final_item':
  1396. if (!$lp_found) {
  1397. Display::addFlash(
  1398. Display::return_message(get_lang('NoLPFound'), 'error')
  1399. );
  1400. break;
  1401. }
  1402. Session::write('refresh', 1);
  1403. if (!isset($_POST['submit']) || empty($post_title)) {
  1404. break;
  1405. }
  1406. $_SESSION['oLP']->getFinalItemForm();
  1407. $redirectTo = api_get_self().'?'.api_get_cidreq().'&'.http_build_query([
  1408. 'action' => 'add_item',
  1409. 'type' => 'step',
  1410. 'lp_id' => intval($_SESSION['oLP']->lp_id),
  1411. ]);
  1412. break;
  1413. default:
  1414. require 'lp_list.php';
  1415. break;
  1416. }
  1417. if (!empty($_SESSION['oLP'])) {
  1418. $_SESSION['lpobject'] = serialize($_SESSION['oLP']);
  1419. if ($debug > 0) {
  1420. error_log('lpobject is serialized in session', 0);
  1421. }
  1422. }
  1423. if (!empty($redirectTo)) {
  1424. header("Location: $redirectTo");
  1425. exit;
  1426. }