lp_controller.php 49 KB

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