lp_controller.php 53 KB

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