lp_controller.php 54 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546
  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. $extraFieldValues = new ExtraFieldValue('lp_item');
  686. $extraFieldValues->saveFieldValues($_POST);
  687. Display::addFlash(Display::return_message(get_lang('Updated')));
  688. $url = api_get_self().'?action=add_item&type=step&lp_id='.intval($_SESSION['oLP']->lp_id).'&'.api_get_cidreq();
  689. header('Location: '.$url);
  690. exit;
  691. }
  692. if (isset($_GET['view']) && $_GET['view'] == 'build') {
  693. require 'lp_edit_item.php';
  694. } else {
  695. require 'lp_admin_view.php';
  696. }
  697. }
  698. break;
  699. case 'edit_item_prereq':
  700. if (!$is_allowed_to_edit) {
  701. api_not_allowed(true);
  702. }
  703. if (!$lp_found) {
  704. require 'lp_list.php';
  705. } else {
  706. if (isset($_POST['submit_button'])) {
  707. // Updating the lp.modified_on
  708. $_SESSION['oLP']->set_modified_on();
  709. Session::write('refresh', 1);
  710. $min = isset($_POST['min_'.$_POST['prerequisites']]) ? $_POST['min_'.$_POST['prerequisites']] : '';
  711. $max = isset($_POST['max_'.$_POST['prerequisites']]) ? $_POST['max_'.$_POST['prerequisites']] : '';
  712. $editPrerequisite = $_SESSION['oLP']->edit_item_prereq(
  713. $_GET['id'],
  714. $_POST['prerequisites'],
  715. $min,
  716. $max
  717. );
  718. if ($editPrerequisite) {
  719. $is_success = true;
  720. }
  721. Display::addFlash(Display::return_message(get_lang('Updated')));
  722. $url = api_get_self().'?action=add_item&type=step&lp_id='.intval($_SESSION['oLP']->lp_id).'&'.api_get_cidreq();
  723. header('Location: '.$url);
  724. exit;
  725. } else {
  726. require 'lp_edit_item_prereq.php';
  727. }
  728. }
  729. break;
  730. case 'move_item':
  731. if (!$is_allowed_to_edit) {
  732. api_not_allowed(true);
  733. }
  734. if (!$lp_found) {
  735. require 'lp_list.php';
  736. } else {
  737. Session::write('refresh', 1);
  738. if (isset($_POST['submit_button'])) {
  739. //Updating the lp.modified_on
  740. $_SESSION['oLP']->set_modified_on();
  741. $_SESSION['oLP']->edit_item(
  742. $_GET['id'],
  743. $_POST['parent'],
  744. $_POST['previous'],
  745. $post_title,
  746. $_POST['description']
  747. );
  748. $is_success = true;
  749. $url = api_get_self().'?action=add_item&type=step&lp_id='.intval($_SESSION['oLP']->lp_id).'&'.api_get_cidreq();
  750. header('Location: '.$url);
  751. exit;
  752. }
  753. if (isset($_GET['view']) && $_GET['view'] == 'build') {
  754. require 'lp_move_item.php';
  755. } else {
  756. // Avoids weird behaviours see CT#967.
  757. $check = Security::check_token('get');
  758. if ($check) {
  759. $_SESSION['oLP']->move_item($_GET['id'], $_GET['direction']);
  760. }
  761. Security::clear_token();
  762. require 'lp_admin_view.php';
  763. }
  764. }
  765. break;
  766. case 'view_item':
  767. if (!$is_allowed_to_edit) {
  768. api_not_allowed(true);
  769. }
  770. if (!$lp_found) {
  771. require 'lp_list.php';
  772. } else {
  773. Session::write('refresh', 1);
  774. require 'lp_view_item.php';
  775. }
  776. break;
  777. case 'upload':
  778. if (!$is_allowed_to_edit) {
  779. api_not_allowed(true);
  780. }
  781. $cwdir = getcwd();
  782. require 'lp_upload.php';
  783. // Reinit current working directory as many functions in upload change it.
  784. chdir($cwdir);
  785. require 'lp_list.php';
  786. break;
  787. case 'copy':
  788. if (!$is_allowed_to_edit) {
  789. api_not_allowed(true);
  790. }
  791. $hideScormCopyLink = api_get_setting('hide_scorm_copy_link');
  792. if ($hideScormCopyLink === 'true') {
  793. api_not_allowed(true);
  794. }
  795. if (!$lp_found) {
  796. require 'lp_list.php';
  797. } else {
  798. $_SESSION['oLP']->copy();
  799. }
  800. require 'lp_list.php';
  801. break;
  802. case 'export':
  803. if (!$is_allowed_to_edit) {
  804. api_not_allowed(true);
  805. }
  806. $hideScormExportLink = api_get_setting('hide_scorm_export_link');
  807. if ($hideScormExportLink === 'true') {
  808. api_not_allowed(true);
  809. }
  810. if (!$lp_found) {
  811. require 'lp_list.php';
  812. } else {
  813. $_SESSION['oLP']->scormExport();
  814. exit();
  815. }
  816. break;
  817. case 'export_to_pdf':
  818. $hideScormPdfLink = api_get_setting('hide_scorm_pdf_link');
  819. if ($hideScormPdfLink === 'true') {
  820. api_not_allowed(true);
  821. }
  822. // Teachers can export to PDF
  823. if (!$is_allowed_to_edit) {
  824. if (!learnpath::is_lp_visible_for_student($_SESSION['oLP']->lp_id, api_get_user_id())) {
  825. api_not_allowed();
  826. }
  827. }
  828. if (!$lp_found) {
  829. require 'lp_list.php';
  830. } else {
  831. $result = $_SESSION['oLP']->scorm_export_to_pdf($_GET['lp_id']);
  832. if (!$result) {
  833. require 'lp_list.php';
  834. }
  835. exit;
  836. }
  837. break;
  838. case 'export_to_course_build':
  839. $allowExport = api_get_configuration_value('allow_lp_chamilo_export');
  840. if (api_is_allowed_to_edit() && $allowExport) {
  841. if (!$lp_found) {
  842. require 'lp_list.php';
  843. } else {
  844. $result = $_SESSION['oLP']->exportToCourseBuildFormat($_GET['lp_id']);
  845. if (!$result) {
  846. require 'lp_list.php';
  847. }
  848. exit;
  849. }
  850. }
  851. require 'lp_list.php';
  852. break;
  853. case 'delete':
  854. if (!$is_allowed_to_edit) {
  855. api_not_allowed(true);
  856. }
  857. if (!$lp_found) {
  858. require 'lp_list.php';
  859. } else {
  860. Session::write('refresh', 1);
  861. $_SESSION['oLP']->delete(null, $_GET['lp_id'], 'remove');
  862. Skill::deleteSkillsFromItem($_GET['lp_id'], ITEM_TYPE_LEARNPATH);
  863. Display::addFlash(Display::return_message(get_lang('Deleted')));
  864. Session::erase('oLP');
  865. require 'lp_list.php';
  866. }
  867. break;
  868. case 'toggle_category_visibility':
  869. if (!$is_allowed_to_edit) {
  870. api_not_allowed(true);
  871. }
  872. learnpath::toggleCategoryVisibility($_REQUEST['id'], $_REQUEST['new_status']);
  873. Display::addFlash(Display::return_message(get_lang('Updated')));
  874. header('Location: '.api_get_self().'?'.api_get_cidreq());
  875. exit;
  876. case 'toggle_visible':
  877. // Change lp visibility (inside lp tool).
  878. if (!$is_allowed_to_edit) {
  879. api_not_allowed(true);
  880. }
  881. if (!$lp_found) {
  882. require 'lp_list.php';
  883. } else {
  884. learnpath::toggle_visibility($_REQUEST['lp_id'], $_REQUEST['new_status']);
  885. Display::addFlash(Display::return_message(get_lang('Updated')));
  886. require 'lp_list.php';
  887. }
  888. break;
  889. case 'toggle_category_publish':
  890. if (!$is_allowed_to_edit) {
  891. api_not_allowed(true);
  892. }
  893. learnpath::toggleCategoryPublish($_REQUEST['id'], $_REQUEST['new_status']);
  894. Display::addFlash(Display::return_message(get_lang('Updated')));
  895. require 'lp_list.php';
  896. break;
  897. case 'toggle_publish':
  898. // Change lp published status (visibility on homepage).
  899. if (!$is_allowed_to_edit) {
  900. api_not_allowed(true);
  901. }
  902. if (!$lp_found) {
  903. require 'lp_list.php';
  904. } else {
  905. learnpath::toggle_publish($_REQUEST['lp_id'], $_REQUEST['new_status']);
  906. Display::addFlash(Display::return_message(get_lang('Updated')));
  907. require 'lp_list.php';
  908. }
  909. break;
  910. case 'move_lp_up':
  911. // Change lp published status (visibility on homepage)
  912. if (!$is_allowed_to_edit) {
  913. api_not_allowed(true);
  914. }
  915. if (!$lp_found) {
  916. require 'lp_list.php';
  917. } else {
  918. learnpath::move_up($_REQUEST['lp_id'], $_REQUEST['category_id']);
  919. Display::addFlash(Display::return_message(get_lang('Updated')));
  920. require 'lp_list.php';
  921. }
  922. break;
  923. case 'move_lp_down':
  924. // Change lp published status (visibility on homepage)
  925. if (!$is_allowed_to_edit) {
  926. api_not_allowed(true);
  927. }
  928. if (!$lp_found) {
  929. require 'lp_list.php';
  930. } else {
  931. learnpath::move_down($_REQUEST['lp_id'], $_REQUEST['category_id']);
  932. Display::addFlash(Display::return_message(get_lang('Updated')));
  933. require 'lp_list.php';
  934. }
  935. break;
  936. case 'edit':
  937. if (!$is_allowed_to_edit) {
  938. api_not_allowed(true);
  939. }
  940. if (!$lp_found) {
  941. require 'lp_list.php';
  942. } else {
  943. Session::write('refresh', 1);
  944. require 'lp_edit.php';
  945. }
  946. break;
  947. case 'update_lp':
  948. if (!$is_allowed_to_edit) {
  949. api_not_allowed(true);
  950. }
  951. if (!$lp_found) {
  952. require 'lp_list.php';
  953. } else {
  954. Session::write('refresh', 1);
  955. $lp_name = Security::remove_XSS($_REQUEST['lp_name']);
  956. $_SESSION['oLP']->set_name($lp_name);
  957. $author = $_REQUEST['lp_author'];
  958. // Fixing the author name (no body or html tags).
  959. $auth_init = stripos($author, '<p>');
  960. if ($auth_init === false) {
  961. $auth_init = stripos($author, '<body>');
  962. $auth_end = $auth_init + stripos(substr($author, $auth_init + 6), '</body>') + 7;
  963. $len = $auth_end - $auth_init + 6;
  964. } else {
  965. $auth_end = strripos($author, '</p>');
  966. $len = $auth_end - $auth_init + 4;
  967. }
  968. $author_fixed = substr($author, $auth_init, $len);
  969. $_SESSION['oLP']->set_author($author_fixed);
  970. // TODO (as of Chamilo 1.8.8): Check in the future whether this field is needed.
  971. $_SESSION['oLP']->set_encoding($_REQUEST['lp_encoding']);
  972. if (isset($_REQUEST['lp_maker'])) {
  973. $_SESSION['oLP']->set_maker($_REQUEST['lp_maker']);
  974. }
  975. if (isset($_REQUEST['lp_proximity'])) {
  976. $_SESSION['oLP']->set_proximity($_REQUEST['lp_proximity']);
  977. }
  978. $_SESSION['oLP']->set_theme($_REQUEST['lp_theme']);
  979. if (isset($_REQUEST['hide_toc_frame']) && $_REQUEST['hide_toc_frame'] == 1) {
  980. $hide_toc_frame = $_REQUEST['hide_toc_frame'];
  981. } else {
  982. $hide_toc_frame = null;
  983. }
  984. $_SESSION['oLP']->set_hide_toc_frame($hide_toc_frame);
  985. $_SESSION['oLP']->set_prerequisite(isset($_POST['prerequisites']) ? (int) $_POST['prerequisites'] : 0);
  986. $_SESSION['oLP']->setAccumulateWorkTime(isset($_REQUEST['accumulate_work_time']) ? $_REQUEST['accumulate_work_time'] : 0);
  987. $_SESSION['oLP']->set_use_max_score(isset($_POST['use_max_score']) ? 1 : 0);
  988. $subscribeUsers = isset($_REQUEST['subscribe_users']) ? 1 : 0;
  989. $_SESSION['oLP']->setSubscribeUsers($subscribeUsers);
  990. $accumulateScormTime = isset($_REQUEST['accumulate_scorm_time']) ? $_REQUEST['accumulate_scorm_time'] : 'true';
  991. $_SESSION['oLP']->setAccumulateScormTime($accumulateScormTime);
  992. if (isset($_REQUEST['activate_start_date_check']) && $_REQUEST['activate_start_date_check'] == 1) {
  993. $publicated_on = $_REQUEST['publicated_on'];
  994. } else {
  995. $publicated_on = null;
  996. }
  997. if (isset($_REQUEST['activate_end_date_check']) && $_REQUEST['activate_end_date_check'] == 1) {
  998. $expired_on = $_REQUEST['expired_on'];
  999. } else {
  1000. $expired_on = null;
  1001. }
  1002. $_SESSION['oLP']->setCategoryId($_REQUEST['category_id']);
  1003. $_SESSION['oLP']->set_modified_on();
  1004. $_SESSION['oLP']->set_publicated_on($publicated_on);
  1005. $_SESSION['oLP']->set_expired_on($expired_on);
  1006. if (isset($_REQUEST['remove_picture']) && $_REQUEST['remove_picture']) {
  1007. $_SESSION['oLP']->delete_lp_image();
  1008. }
  1009. $extraFieldValue = new ExtraFieldValue('lp');
  1010. $_REQUEST['item_id'] = $_SESSION['oLP']->lp_id;
  1011. $extraFieldValue->saveFieldValues($_REQUEST);
  1012. if ($_FILES['lp_preview_image']['size'] > 0) {
  1013. $_SESSION['oLP']->upload_image($_FILES['lp_preview_image']);
  1014. }
  1015. $form = new FormValidator('form1');
  1016. $form->addSelect('skills', 'skills');
  1017. Skill::saveSkills($form, ITEM_TYPE_LEARNPATH, $_SESSION['oLP']->get_id());
  1018. if (api_get_setting('search_enabled') === 'true') {
  1019. require_once api_get_path(LIBRARY_PATH).'specific_fields_manager.lib.php';
  1020. $specific_fields = get_specific_field_list();
  1021. foreach ($specific_fields as $specific_field) {
  1022. $_SESSION['oLP']->set_terms_by_prefix($_REQUEST[$specific_field['code']], $specific_field['code']);
  1023. $new_values = explode(',', trim($_REQUEST[$specific_field['code']]));
  1024. if (!empty($new_values)) {
  1025. array_walk($new_values, 'trim');
  1026. delete_all_specific_field_value(
  1027. api_get_course_id(),
  1028. $specific_field['id'],
  1029. TOOL_LEARNPATH,
  1030. $_SESSION['oLP']->lp_id
  1031. );
  1032. foreach ($new_values as $value) {
  1033. if (!empty($value)) {
  1034. add_specific_field_value(
  1035. $specific_field['id'],
  1036. api_get_course_id(),
  1037. TOOL_LEARNPATH,
  1038. $_SESSION['oLP']->lp_id,
  1039. $value
  1040. );
  1041. }
  1042. }
  1043. }
  1044. }
  1045. }
  1046. Display::addFlash(Display::return_message(get_lang('Updated')));
  1047. $url = api_get_self().'?action=add_item&type=step&lp_id='.intval($_SESSION['oLP']->lp_id).'&'.api_get_cidreq();
  1048. header('Location: '.$url);
  1049. exit;
  1050. }
  1051. break;
  1052. case 'add_sub_item':
  1053. // Add an item inside a dir/chapter.
  1054. // @todo check if this is @deprecated
  1055. if (!$is_allowed_to_edit) {
  1056. api_not_allowed(true);
  1057. }
  1058. if (!$lp_found) {
  1059. require 'lp_list.php';
  1060. } else {
  1061. Session::write('refresh', 1);
  1062. if (!empty($_REQUEST['parent_item_id'])) {
  1063. $_SESSION['from_learnpath'] = 'yes';
  1064. $_SESSION['origintoolurl'] = 'lp_controller.php?action=admin_view&lp_id='.intval($_REQUEST['lp_id']);
  1065. } else {
  1066. require 'lp_admin_view.php';
  1067. }
  1068. }
  1069. break;
  1070. case 'deleteitem':
  1071. case 'delete_item':
  1072. if (!$is_allowed_to_edit) {
  1073. api_not_allowed(true);
  1074. }
  1075. if (!$lp_found) {
  1076. require 'lp_list.php';
  1077. } else {
  1078. if (!empty($_REQUEST['id'])) {
  1079. $_SESSION['oLP']->delete_item($_REQUEST['id']);
  1080. }
  1081. $url = api_get_self().'?action=add_item&type=step&lp_id='.intval($_REQUEST['lp_id']).'&'.api_get_cidreq();
  1082. header('Location: '.$url);
  1083. exit;
  1084. }
  1085. break;
  1086. case 'restart':
  1087. if (!$lp_found) {
  1088. require 'lp_list.php';
  1089. } else {
  1090. $_SESSION['oLP']->restart();
  1091. require 'lp_view.php';
  1092. }
  1093. break;
  1094. case 'last':
  1095. if (!$lp_found) {
  1096. require 'lp_list.php';
  1097. } else {
  1098. $_SESSION['oLP']->last();
  1099. require 'lp_view.php';
  1100. }
  1101. break;
  1102. case 'first':
  1103. if (!$lp_found) {
  1104. require 'lp_list.php';
  1105. } else {
  1106. $_SESSION['oLP']->first();
  1107. require 'lp_view.php';
  1108. }
  1109. break;
  1110. case 'next':
  1111. if (!$lp_found) {
  1112. require 'lp_list.php';
  1113. } else {
  1114. $_SESSION['oLP']->next();
  1115. require 'lp_view.php';
  1116. }
  1117. break;
  1118. case 'previous':
  1119. if (!$lp_found) {
  1120. require 'lp_list.php';
  1121. } else {
  1122. $_SESSION['oLP']->previous();
  1123. require 'lp_view.php';
  1124. }
  1125. break;
  1126. case 'content':
  1127. if ($debug > 0) {
  1128. error_log('lp_controller: action: content');
  1129. error_log('Item id is '.intval($_GET['item_id']));
  1130. }
  1131. if (!$lp_found) {
  1132. require 'lp_list.php';
  1133. } else {
  1134. if ($debug > 0) {
  1135. error_log('save_last()');
  1136. }
  1137. $_SESSION['oLP']->save_last();
  1138. if ($debug > 0) {
  1139. error_log('set_current_item('.$_GET['item_id'].')');
  1140. }
  1141. $_SESSION['oLP']->set_current_item($_GET['item_id']);
  1142. if ($debug > 0) {
  1143. error_log('start_current_item()');
  1144. }
  1145. $_SESSION['oLP']->start_current_item();
  1146. require 'lp_content.php';
  1147. }
  1148. break;
  1149. case 'view':
  1150. if (!$lp_found) {
  1151. require 'lp_list.php';
  1152. } else {
  1153. if ($debug > 0) {
  1154. error_log('Trying to set current item to '.$_REQUEST['item_id'], 0);
  1155. }
  1156. if (!empty($_REQUEST['item_id'])) {
  1157. $_SESSION['oLP']->set_current_item($_REQUEST['item_id']);
  1158. }
  1159. require 'lp_view.php';
  1160. }
  1161. break;
  1162. case 'save':
  1163. if (!$lp_found) {
  1164. require 'lp_list.php';
  1165. } else {
  1166. $_SESSION['oLP']->save_item();
  1167. require 'lp_save.php';
  1168. }
  1169. break;
  1170. case 'stats':
  1171. if (!$lp_found) {
  1172. require 'lp_list.php';
  1173. } else {
  1174. $_SESSION['oLP']->save_current();
  1175. $_SESSION['oLP']->save_last();
  1176. $output = require 'lp_stats.php';
  1177. echo $output;
  1178. }
  1179. break;
  1180. case 'list':
  1181. if ($lp_found) {
  1182. Session::write('refresh', 1);
  1183. $_SESSION['oLP']->save_last();
  1184. }
  1185. require 'lp_list.php';
  1186. break;
  1187. case 'mode':
  1188. // Switch between fullscreen and embedded mode.
  1189. $mode = $_REQUEST['mode'];
  1190. if ($mode == 'fullscreen') {
  1191. $_SESSION['oLP']->mode = 'fullscreen';
  1192. } elseif ($mode == 'embedded') {
  1193. $_SESSION['oLP']->mode = 'embedded';
  1194. } elseif ($mode == 'embedframe') {
  1195. $_SESSION['oLP']->mode = 'embedframe';
  1196. } elseif ($mode == 'impress') {
  1197. $_SESSION['oLP']->mode = 'impress';
  1198. }
  1199. require 'lp_view.php';
  1200. break;
  1201. case 'switch_view_mode':
  1202. if (!$lp_found) {
  1203. require 'lp_list.php';
  1204. }
  1205. if (Security::check_token('get')) {
  1206. Session::write('refresh', 1);
  1207. $_SESSION['oLP']->update_default_view_mode();
  1208. }
  1209. require 'lp_list.php';
  1210. break;
  1211. case 'switch_force_commit':
  1212. if (!$lp_found) {
  1213. require 'lp_list.php';
  1214. }
  1215. Session::write('refresh', 1);
  1216. $_SESSION['oLP']->update_default_scorm_commit();
  1217. require 'lp_list.php';
  1218. break;
  1219. case 'switch_attempt_mode':
  1220. if (!$lp_found) {
  1221. require 'lp_list.php';
  1222. }
  1223. Session::write('refresh', 1);
  1224. $_SESSION['oLP']->switch_attempt_mode();
  1225. require 'lp_list.php';
  1226. break;
  1227. case 'switch_scorm_debug':
  1228. if (!$lp_found) {
  1229. require 'lp_list.php';
  1230. }
  1231. Session::write('refresh', 1);
  1232. $_SESSION['oLP']->update_scorm_debug();
  1233. require 'lp_list.php';
  1234. break;
  1235. case 'intro_cmdAdd':
  1236. // Add introduction section page.
  1237. break;
  1238. case 'return_to_course_homepage':
  1239. if (!$lp_found) {
  1240. require 'lp_list.php';
  1241. } else {
  1242. $_SESSION['oLP']->save_current();
  1243. $_SESSION['oLP']->save_last();
  1244. if ($debug > 0) {
  1245. error_log('save_current()');
  1246. error_log('save_last()');
  1247. }
  1248. $url = api_get_path(WEB_COURSE_PATH).api_get_course_path().'/index.php?id_session='.api_get_session_id();
  1249. $redirectTo = isset($_GET['redirectTo']) ? $_GET['redirectTo'] : '';
  1250. switch ($redirectTo) {
  1251. case 'lp_list':
  1252. $url = 'lp_controller.php?'.api_get_cidreq();
  1253. break;
  1254. case 'my_courses':
  1255. $url = api_get_path(WEB_PATH).'user_portal.php';
  1256. break;
  1257. }
  1258. header('location: '.$url);
  1259. exit;
  1260. }
  1261. break;
  1262. case 'search':
  1263. /* Include the search script, it's smart enough to know when we are
  1264. * searching or not.
  1265. */
  1266. require 'lp_list_search.php';
  1267. break;
  1268. case 'impress':
  1269. if (!$lp_found) {
  1270. require 'lp_list.php';
  1271. } else {
  1272. if ($debug > 0) {
  1273. error_log('Trying to impress this LP item to '.$_REQUEST['item_id'], 0);
  1274. }
  1275. if (!empty($_REQUEST['item_id'])) {
  1276. $_SESSION['oLP']->set_current_item($_REQUEST['item_id']);
  1277. }
  1278. require 'lp_impress.php';
  1279. }
  1280. break;
  1281. case 'set_previous_step_as_prerequisite':
  1282. $_SESSION['oLP']->set_previous_step_as_prerequisite_for_all_items();
  1283. $url = api_get_self().'?action=add_item&type=step&lp_id='.intval($_SESSION['oLP']->lp_id)."&".api_get_cidreq();
  1284. Display::addFlash(Display::return_message(get_lang('ItemUpdated')));
  1285. header('Location: '.$url);
  1286. exit;
  1287. break;
  1288. case 'clear_prerequisites':
  1289. $_SESSION['oLP']->clear_prerequisites();
  1290. $url = api_get_self().'?action=add_item&type=step&lp_id='.intval($_SESSION['oLP']->lp_id)."&".api_get_cidreq();
  1291. Display::addFlash(Display::return_message(get_lang('ItemUpdated')));
  1292. header('Location: '.$url);
  1293. exit;
  1294. break;
  1295. case 'toggle_seriousgame':
  1296. // activate/deactive seriousgame_mode
  1297. if (!$is_allowed_to_edit) {
  1298. api_not_allowed(true);
  1299. }
  1300. if (!$lp_found) {
  1301. require 'lp_list.php';
  1302. }
  1303. Session::write('refresh', 1);
  1304. $_SESSION['oLP']->set_seriousgame_mode();
  1305. require 'lp_list.php';
  1306. break;
  1307. case 'create_forum':
  1308. if (!isset($_GET['id'])) {
  1309. break;
  1310. }
  1311. $selectedItem = null;
  1312. foreach ($_SESSION['oLP']->items as $item) {
  1313. if ($item->db_id == $_GET['id']) {
  1314. $selectedItem = $item;
  1315. }
  1316. }
  1317. if (!empty($selectedItem)) {
  1318. $forumThread = $selectedItem->getForumThread(
  1319. $_SESSION['oLP']->course_int_id,
  1320. $_SESSION['oLP']->lp_session_id
  1321. );
  1322. if (empty($forumThread)) {
  1323. require '../forum/forumfunction.inc.php';
  1324. $forumCategory = getForumCategoryByTitle(
  1325. get_lang('LearningPaths'),
  1326. $_SESSION['oLP']->course_int_id,
  1327. $_SESSION['oLP']->lp_session_id
  1328. );
  1329. $forumCategoryId = !empty($forumCategory) ? $forumCategory['cat_id'] : 0;
  1330. if (empty($forumCategoryId)) {
  1331. $forumCategoryId = store_forumcategory(
  1332. [
  1333. 'lp_id' => 0,
  1334. 'forum_category_title' => get_lang('LearningPaths'),
  1335. 'forum_category_comment' => null,
  1336. ],
  1337. [],
  1338. false
  1339. );
  1340. }
  1341. if (!empty($forumCategoryId)) {
  1342. $forum = $_SESSION['oLP']->getForum(
  1343. $_SESSION['oLP']->lp_session_id
  1344. );
  1345. $forumId = !empty($forum) ? $forum['forum_id'] : 0;
  1346. if (empty($forumId)) {
  1347. $forumId = $_SESSION['oLP']->createForum($forumCategoryId);
  1348. }
  1349. if (!empty($forumId)) {
  1350. $selectedItem->createForumThread($forumId);
  1351. }
  1352. }
  1353. }
  1354. }
  1355. header('Location:'.api_get_self().'?'.http_build_query([
  1356. 'action' => 'add_item',
  1357. 'type' => 'step',
  1358. 'lp_id' => $_SESSION['oLP']->lp_id,
  1359. ]));
  1360. exit;
  1361. break;
  1362. case 'report':
  1363. require 'lp_report.php';
  1364. break;
  1365. case 'dissociate_forum':
  1366. if (!isset($_GET['id'])) {
  1367. break;
  1368. }
  1369. $selectedItem = null;
  1370. foreach ($_SESSION['oLP']->items as $item) {
  1371. if ($item->db_id != $_GET['id']) {
  1372. continue;
  1373. }
  1374. $selectedItem = $item;
  1375. }
  1376. if (!empty($selectedItem)) {
  1377. $forumThread = $selectedItem->getForumThread(
  1378. $_SESSION['oLP']->course_int_id,
  1379. $_SESSION['oLP']->lp_session_id
  1380. );
  1381. if (!empty($forumThread)) {
  1382. $dissociated = $selectedItem->dissociateForumThread($forumThread['iid']);
  1383. if ($dissociated) {
  1384. Display::addFlash(
  1385. Display::return_message(get_lang('ForumDissociate'), 'success')
  1386. );
  1387. }
  1388. }
  1389. }
  1390. header('Location:'.api_get_self().'?'.http_build_query([
  1391. 'action' => 'add_item',
  1392. 'type' => 'step',
  1393. 'lp_id' => $_SESSION['oLP']->lp_id,
  1394. ]));
  1395. exit;
  1396. break;
  1397. case 'add_final_item':
  1398. if (!$lp_found) {
  1399. Display::addFlash(
  1400. Display::return_message(get_lang('NoLPFound'), 'error')
  1401. );
  1402. break;
  1403. }
  1404. Session::write('refresh', 1);
  1405. if (!isset($_POST['submit']) || empty($post_title)) {
  1406. break;
  1407. }
  1408. $_SESSION['oLP']->getFinalItemForm();
  1409. $redirectTo = api_get_self().'?'.api_get_cidreq().'&'.http_build_query([
  1410. 'action' => 'add_item',
  1411. 'type' => 'step',
  1412. 'lp_id' => intval($_SESSION['oLP']->lp_id),
  1413. ]);
  1414. break;
  1415. default:
  1416. require 'lp_list.php';
  1417. break;
  1418. }
  1419. if (!empty($_SESSION['oLP'])) {
  1420. $_SESSION['lpobject'] = serialize($_SESSION['oLP']);
  1421. if ($debug > 0) {
  1422. error_log('lpobject is serialized in session', 0);
  1423. }
  1424. }
  1425. if (!empty($redirectTo)) {
  1426. header("Location: $redirectTo");
  1427. exit;
  1428. }