lp_controller.php 53 KB

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