lp_controller.php 49 KB

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