lp_controller.php 48 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218
  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: none;
  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':
  426. if (!$is_allowed_to_edit) {
  427. api_not_allowed(true);
  428. }
  429. if ($debug > 0) error_log('New LP - add_lp action triggered', 0);
  430. if (isset($_REQUEST['lp_name']) && !empty($_REQUEST['lp_name'])) {
  431. $_REQUEST['lp_name'] = trim($_REQUEST['lp_name']);
  432. $_SESSION['refresh'] = 1;
  433. if (isset($_SESSION['post_time']) && $_SESSION['post_time'] == $_REQUEST['post_time']) {
  434. require 'lp_add.php';
  435. } else {
  436. $_SESSION['post_time'] = $_REQUEST['post_time'];
  437. if (isset($_REQUEST['activate_start_date_check']) && $_REQUEST['activate_start_date_check'] == 1) {
  438. $publicated_on = $_REQUEST['publicated_on'];
  439. } else {
  440. $publicated_on = null;
  441. }
  442. if (isset($_REQUEST['activate_end_date_check']) && $_REQUEST['activate_end_date_check'] == 1) {
  443. $expired_on = $_REQUEST['expired_on'];
  444. $expired_on = $expired_on['Y'].'-'.$expired_on['F'].'-'.$expired_on['d'].' '.$expired_on['H'].':'.$expired_on['i'].':00';
  445. } else {
  446. $expired_on = null;
  447. }
  448. $new_lp_id = learnpath::add_lp(
  449. api_get_course_id(),
  450. Security::remove_XSS($_REQUEST['lp_name']),
  451. '',
  452. 'chamilo',
  453. 'manual',
  454. '',
  455. $publicated_on,
  456. $expired_on
  457. );
  458. if (is_numeric($new_lp_id)) {
  459. // TODO: Maybe create a first module directly to avoid bugging the user with useless queries
  460. $_SESSION['oLP'] = new learnpath(api_get_course_id(),$new_lp_id,api_get_user_id());
  461. //require 'lp_build.php';
  462. $url = api_get_self().'?action=add_item&type=step&lp_id='.intval($new_lp_id).'&'.api_get_cidreq();
  463. header("Location: $url&isStudentView=false");
  464. exit;
  465. }
  466. }
  467. } else {
  468. require 'lp_add.php';
  469. }
  470. break;
  471. case 'admin_view':
  472. if (!$is_allowed_to_edit) {
  473. api_not_allowed(true);
  474. }
  475. if ($debug > 0) error_log('New LP - admin_view action triggered', 0);
  476. if (!$lp_found) { error_log('New LP - No learnpath given for admin_view', 0); require 'lp_list.php'; }
  477. else {
  478. $_SESSION['refresh'] = 1;
  479. require 'lp_admin_view.php';
  480. }
  481. break;
  482. case 'auto_launch':
  483. if (api_get_course_setting('enable_lp_auto_launch') == 1) { //Redirect to a specific LP
  484. if (!$is_allowed_to_edit) {
  485. api_not_allowed(true);
  486. }
  487. if ($debug > 0) error_log('New LP - auto_launch action triggered', 0);
  488. if (!$lp_found) { error_log('New LP - No learnpath given for set_autolunch', 0); require 'lp_list.php'; }
  489. else {
  490. $_SESSION['oLP']->set_autolunch($_GET['lp_id'], $_GET['status']);
  491. require 'lp_list.php';
  492. exit;
  493. }
  494. }
  495. break;
  496. case 'build':
  497. if (!$is_allowed_to_edit) {
  498. api_not_allowed(true);
  499. }
  500. if ($debug > 0) error_log('New LP - build action triggered', 0);
  501. if (!$lp_found) { error_log('New LP - No learnpath given for build', 0); require 'lp_list.php'; }
  502. else {
  503. $_SESSION['refresh'] = 1;
  504. //require 'lp_build.php';
  505. $url = api_get_self().'?action=add_item&type=step&lp_id='.intval($_SESSION['oLP']->lp_id);
  506. header('Location: '.$url);
  507. exit;
  508. }
  509. break;
  510. case 'edit_item':
  511. if (!$is_allowed_to_edit) {
  512. api_not_allowed(true);
  513. }
  514. if ($debug > 0) error_log('New LP - edit item action triggered', 0);
  515. if (!$lp_found) { error_log('New LP - No learnpath given for edit item', 0); require 'lp_list.php'; }
  516. else {
  517. $_SESSION['refresh'] = 1;
  518. if (isset($_POST['submit_button']) && !empty($post_title)) {
  519. //Updating the lp.modified_on
  520. $_SESSION['oLP']->set_modified_on();
  521. // TODO: mp3 edit
  522. $audio = array();
  523. if (isset($_FILES['mp3'])) {
  524. $audio = $_FILES['mp3'];
  525. }
  526. $_SESSION['oLP']->edit_item(
  527. $_REQUEST['id'],
  528. $_POST['parent'],
  529. $_POST['previous'],
  530. $post_title,
  531. $_POST['description'],
  532. $_POST['prerequisites'],
  533. $audio,
  534. $_POST['maxTimeAllowed'],
  535. $_POST['url']
  536. );
  537. if (isset($_POST['content_lp'])) {
  538. $_SESSION['oLP']->edit_document($_course);
  539. }
  540. $is_success = true;
  541. $url = api_get_self().'?action=add_item&type=step&lp_id='.intval($_SESSION['oLP']->lp_id);
  542. header('Location: '.$url);
  543. exit;
  544. }
  545. if (isset($_GET['view']) && $_GET['view'] == 'build') {
  546. require 'lp_edit_item.php';
  547. } else {
  548. require 'lp_admin_view.php';
  549. }
  550. }
  551. break;
  552. case 'edit_item_prereq':
  553. if (!$is_allowed_to_edit) {
  554. api_not_allowed(true);
  555. }
  556. if ($debug > 0) error_log('New LP - edit item prereq action triggered', 0);
  557. if (!$lp_found) { error_log('New LP - No learnpath given for edit item prereq', 0); require 'lp_list.php'; }
  558. else {
  559. if (isset($_POST['submit_button'])) {
  560. //Updating the lp.modified_on
  561. $_SESSION['oLP']->set_modified_on();
  562. $_SESSION['refresh'] = 1;
  563. $editPrerequisite = $_SESSION['oLP']->edit_item_prereq(
  564. $_GET['id'],
  565. $_POST['prerequisites'],
  566. $_POST['min_' . $_POST['prerequisites']],
  567. $_POST['max_' . $_POST['prerequisites']]
  568. );
  569. if ($editPrerequisite) {
  570. $is_success = true;
  571. }
  572. $url = api_get_self().'?action=add_item&type=step&lp_id='.intval($_SESSION['oLP']->lp_id);
  573. header('Location: '.$url);
  574. exit;
  575. } else {
  576. require 'lp_edit_item_prereq.php';
  577. }
  578. }
  579. break;
  580. case 'move_item':
  581. if (!$is_allowed_to_edit) {
  582. api_not_allowed(true);
  583. }
  584. if ($debug > 0) error_log('New LP - move item action triggered', 0);
  585. if (!$lp_found) { error_log('New LP - No learnpath given for move item', 0); require 'lp_list.php'; }
  586. else {
  587. $_SESSION['refresh'] = 1;
  588. if (isset($_POST['submit_button'])) {
  589. //Updating the lp.modified_on
  590. $_SESSION['oLP']->set_modified_on();
  591. $_SESSION['oLP']->edit_item(
  592. $_GET['id'],
  593. $_POST['parent'],
  594. $_POST['previous'],
  595. $post_title,
  596. $_POST['description']
  597. );
  598. $is_success = true;
  599. $url = api_get_self().'?action=add_item&type=step&lp_id='.intval($_SESSION['oLP']->lp_id);
  600. header('Location: '.$url);
  601. }
  602. if (isset($_GET['view']) && $_GET['view'] == 'build') {
  603. require 'lp_move_item.php';
  604. } else {
  605. // Avoids weird behaviours see CT#967.
  606. $check = Security::check_token('get');
  607. if ($check) {
  608. $_SESSION['oLP']->move_item($_GET['id'], $_GET['direction']);
  609. }
  610. Security::clear_token();
  611. require 'lp_admin_view.php';
  612. }
  613. }
  614. break;
  615. case 'view_item':
  616. if (!$is_allowed_to_edit) {
  617. api_not_allowed(true);
  618. }
  619. if ($debug > 0) error_log('New LP - view_item action triggered', 0);
  620. if (!$lp_found) {
  621. error_log('New LP - No learnpath given for view item', 0); require 'lp_list.php';
  622. } else {
  623. $_SESSION['refresh'] = 1;
  624. require 'lp_view_item.php';
  625. }
  626. break;
  627. case 'upload':
  628. if (!$is_allowed_to_edit) {
  629. api_not_allowed(true);
  630. }
  631. if ($debug > 0) error_log('New LP - upload action triggered', 0);
  632. $cwdir = getcwd();
  633. require 'lp_upload.php';
  634. // Reinit current working directory as many functions in upload change it.
  635. chdir($cwdir);
  636. require 'lp_list.php';
  637. break;
  638. case 'copy':
  639. if (!$is_allowed_to_edit) {
  640. api_not_allowed(true);
  641. }
  642. global $_configuration;
  643. if (isset($_configuration['hide_scorm_copy_link']) && $_configuration['hide_scorm_copy_link']) {
  644. api_not_allowed(true);
  645. }
  646. if ($debug > 0) error_log('New LP - export action triggered', 0);
  647. if (!$lp_found) { error_log('New LP - No learnpath given for copy', 0); require 'lp_list.php'; }
  648. else {
  649. $_SESSION['oLP']->copy();
  650. }
  651. require 'lp_list.php';
  652. break;
  653. case 'export':
  654. if (!$is_allowed_to_edit) {
  655. api_not_allowed(true);
  656. }
  657. global $_configuration;
  658. if (isset($_configuration['hide_scorm_export_link']) && $_configuration['hide_scorm_export_link']) {
  659. api_not_allowed(true);
  660. }
  661. if ($debug > 0) error_log('New LP - export action triggered', 0);
  662. if (!$lp_found) { error_log('New LP - No learnpath given for export', 0); require 'lp_list.php'; }
  663. else {
  664. $_SESSION['oLP']->scorm_export();
  665. exit();
  666. //require 'lp_list.php';
  667. }
  668. break;
  669. case 'export_to_pdf':
  670. if (!learnpath::is_lp_visible_for_student($_SESSION['oLP']->lp_id, api_get_user_id())) {
  671. api_not_allowed();
  672. }
  673. global $_configuration;
  674. if (isset($_configuration['hide_scorm_pdf_link']) && $_configuration['hide_scorm_pdf_link']) {
  675. api_not_allowed(true);
  676. }
  677. if ($debug > 0) error_log('New LP - export action triggered', 0);
  678. if (!$lp_found) { error_log('New LP - No learnpath given for export_to_pdf', 0); require 'lp_list.php';
  679. } else {
  680. $result = $_SESSION['oLP']->scorm_export_to_pdf($_GET['lp_id']);
  681. if (!$result) {
  682. require 'lp_list.php';
  683. }
  684. exit;
  685. }
  686. break;
  687. case 'delete':
  688. if (!$is_allowed_to_edit) {
  689. api_not_allowed(true);
  690. }
  691. if ($debug > 0) error_log('New LP - delete action triggered', 0);
  692. if (!$lp_found) { error_log('New LP - No learnpath given for delete', 0); require 'lp_list.php'; }
  693. else {
  694. $_SESSION['refresh'] = 1;
  695. $_SESSION['oLP']->delete(null, $_GET['lp_id'], 'remove');
  696. Session::erase('oLP');
  697. require 'lp_list.php';
  698. }
  699. break;
  700. case 'toggle_visible':
  701. // Change lp visibility (inside lp tool).
  702. if (!$is_allowed_to_edit) {
  703. api_not_allowed(true);
  704. }
  705. if ($debug > 0) error_log('New LP - visibility action triggered', 0);
  706. if (!$lp_found) { error_log('New LP - No learnpath given for visibility', 0); require 'lp_list.php'; }
  707. else {
  708. learnpath::toggle_visibility($_REQUEST['lp_id'], $_REQUEST['new_status']);
  709. require 'lp_list.php';
  710. }
  711. break;
  712. case 'toggle_publish':
  713. // Change lp published status (visibility on homepage).
  714. if (!$is_allowed_to_edit) {
  715. api_not_allowed(true);
  716. }
  717. if ($debug > 0) error_log('New LP - publish action triggered', 0);
  718. if (!$lp_found) { error_log('New LP - No learnpath given for publish', 0); require 'lp_list.php'; }
  719. else {
  720. learnpath::toggle_publish($_REQUEST['lp_id'], $_REQUEST['new_status']);
  721. require 'lp_list.php';
  722. }
  723. break;
  724. case 'move_lp_up':
  725. // Change lp published status (visibility on homepage)
  726. if (!$is_allowed_to_edit) {
  727. api_not_allowed(true);
  728. }
  729. if ($debug > 0) error_log('New LP - publish action triggered', 0);
  730. if (!$lp_found) {
  731. error_log('New LP - No learnpath given for publish', 0);
  732. require 'lp_list.php';
  733. } else {
  734. learnpath::move_up($_REQUEST['lp_id']);
  735. require 'lp_list.php';
  736. }
  737. break;
  738. case 'move_lp_down':
  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) {
  745. error_log('New LP - No learnpath given for publish', 0);
  746. require 'lp_list.php';
  747. } else {
  748. learnpath::move_down($_REQUEST['lp_id']);
  749. require 'lp_list.php';
  750. }
  751. break;
  752. case 'edit':
  753. if (!$is_allowed_to_edit) {
  754. api_not_allowed(true);
  755. }
  756. if ($debug > 0) error_log('New LP - edit action triggered', 0);
  757. if (!$lp_found) { error_log('New LP - No learnpath given for edit', 0); require 'lp_list.php'; }
  758. else {
  759. $_SESSION['refresh'] = 1;
  760. require 'lp_edit.php';
  761. }
  762. break;
  763. case 'update_lp':
  764. if (!$is_allowed_to_edit) {
  765. api_not_allowed(true);
  766. }
  767. if ($debug > 0) error_log('New LP - update_lp action triggered', 0);
  768. if (!$lp_found) { error_log('New LP - No learnpath given for edit', 0); require 'lp_list.php'; }
  769. else {
  770. $_SESSION['refresh'] = 1;
  771. $lp_name = Security::remove_XSS($_REQUEST['lp_name']);
  772. $_SESSION['oLP']->set_name($lp_name);
  773. $author = $_REQUEST['lp_author'];
  774. // Fixing the author name (no body or html tags).
  775. $auth_init = stripos($author, '<p>');
  776. if ($auth_init === false) {
  777. $auth_init = stripos($author, '<body>');
  778. $auth_end = $auth_init + stripos(substr($author, $auth_init + 6), '</body>') + 7;
  779. $len = $auth_end - $auth_init + 6;
  780. } else {
  781. $auth_end = strripos($author, '</p>');
  782. $len = $auth_end - $auth_init + 4;
  783. }
  784. $author_fixed = substr($author, $auth_init, $len);
  785. //$author_fixed = $author;
  786. $_SESSION['oLP']->set_author($author_fixed);
  787. // TODO (as of Chamilo 1.8.8): Check in the future whether this field is needed.
  788. $_SESSION['oLP']->set_encoding($_REQUEST['lp_encoding']);
  789. if (isset($_REQUEST['lp_maker'])) {
  790. $_SESSION['oLP']->set_maker($_REQUEST['lp_maker']);
  791. }
  792. if (isset($_REQUEST['lp_proximity'])) {
  793. $_SESSION['oLP']->set_proximity($_REQUEST['lp_proximity']);
  794. }
  795. $_SESSION['oLP']->set_theme($_REQUEST['lp_theme']);
  796. if (isset($_REQUEST['hide_toc_frame']) && $_REQUEST['hide_toc_frame'] == 1) {
  797. $hide_toc_frame = $_REQUEST['hide_toc_frame'];
  798. } else {
  799. $hide_toc_frame = null;
  800. }
  801. $_SESSION['oLP']->set_hide_toc_frame($hide_toc_frame);
  802. $_SESSION['oLP']->set_prerequisite($_REQUEST['prerequisites']);
  803. $_SESSION['oLP']->set_use_max_score($_REQUEST['use_max_score']);
  804. if (isset($_REQUEST['activate_start_date_check']) && $_REQUEST['activate_start_date_check'] == 1) {
  805. $publicated_on = $_REQUEST['publicated_on'];
  806. $publicated_on = $publicated_on['Y'].'-'.$publicated_on['F'].'-'.$publicated_on['d'].' '.$publicated_on['H'].':'.$publicated_on['i'].':00';
  807. } else {
  808. $publicated_on = null;
  809. }
  810. if (isset($_REQUEST['activate_end_date_check']) && $_REQUEST['activate_end_date_check'] == 1) {
  811. $expired_on = $_REQUEST['expired_on'];
  812. $expired_on = $expired_on['Y'].'-'.$expired_on['F'].'-'.$expired_on['d'].' '.$expired_on['H'].':'.$expired_on['i'].':00';
  813. } else {
  814. $expired_on = null;
  815. }
  816. $_SESSION['oLP']->set_modified_on();
  817. $_SESSION['oLP']->set_publicated_on($publicated_on);
  818. $_SESSION['oLP']->set_expired_on($expired_on);
  819. if (isset($_REQUEST['remove_picture']) && $_REQUEST['remove_picture']) {
  820. $_SESSION['oLP']->delete_lp_image();
  821. }
  822. $extraFieldValue = new ExtraFieldValue('lp');
  823. $params = array(
  824. 'lp_id' => $_SESSION['oLP']->id
  825. );
  826. $extraFieldValue->save_field_values($_REQUEST);
  827. if ($_FILES['lp_preview_image']['size'] > 0)
  828. $_SESSION['oLP']->upload_image($_FILES['lp_preview_image']);
  829. if (api_get_setting('search_enabled') === 'true') {
  830. require_once api_get_path(LIBRARY_PATH).'specific_fields_manager.lib.php';
  831. $specific_fields = get_specific_field_list();
  832. foreach ($specific_fields as $specific_field) {
  833. $_SESSION['oLP']->set_terms_by_prefix($_REQUEST[$specific_field['code']], $specific_field['code']);
  834. $new_values = explode(',', trim($_REQUEST[$specific_field['code']]));
  835. if (!empty($new_values)) {
  836. array_walk($new_values, 'trim');
  837. delete_all_specific_field_value(
  838. api_get_course_id(),
  839. $specific_field['id'],
  840. TOOL_LEARNPATH,
  841. $_SESSION['oLP']->lp_id
  842. );
  843. foreach ($new_values as $value) {
  844. if (!empty($value)) {
  845. add_specific_field_value(
  846. $specific_field['id'],
  847. api_get_course_id(),
  848. TOOL_LEARNPATH,
  849. $_SESSION['oLP']->lp_id,
  850. $value
  851. );
  852. }
  853. }
  854. }
  855. }
  856. }
  857. $url = api_get_self().'?action=add_item&type=step&lp_id='.intval($_SESSION['oLP']->lp_id).'&'.api_get_cidreq();
  858. header('Location: '.$url);
  859. exit;
  860. }
  861. break;
  862. case 'add_sub_item': // Add an item inside a chapter.
  863. if (!$is_allowed_to_edit) {
  864. api_not_allowed(true);
  865. }
  866. if ($debug > 0) error_log('New LP - add sub item action triggered', 0);
  867. if (!$lp_found) { error_log('New LP - No learnpath given for add sub item', 0); require 'lp_list.php'; }
  868. else {
  869. $_SESSION['refresh'] = 1;
  870. if (!empty($_REQUEST['parent_item_id'])) {
  871. $_SESSION['from_learnpath']='yes';
  872. $_SESSION['origintoolurl'] = 'lp_controller.php?action=admin_view&lp_id='.Security::remove_XSS($_REQUEST['lp_id']);
  873. require 'resourcelinker.php';
  874. } else {
  875. require 'lp_admin_view.php';
  876. }
  877. }
  878. break;
  879. case 'deleteitem':
  880. case 'delete_item':
  881. if (!$is_allowed_to_edit) {
  882. api_not_allowed(true);
  883. }
  884. if ($debug > 0) error_log('New LP - delete item action triggered', 0);
  885. if (!$lp_found) { error_log('New LP - No learnpath given for delete item', 0); require 'lp_list.php'; }
  886. else {
  887. //$_SESSION['refresh'] = 1;
  888. if (!empty($_REQUEST['id'])) {
  889. $_SESSION['oLP']->delete_item($_REQUEST['id']);
  890. }
  891. $url = api_get_self().'?action=add_item&type=step&lp_id='.intval($_REQUEST['lp_id']).api_get_cidreq();
  892. header('Location: '.$url);
  893. exit;
  894. }
  895. break;
  896. case 'edititemprereq':
  897. case 'edit_item_prereq':
  898. if (!$is_allowed_to_edit) {
  899. api_not_allowed(true);
  900. }
  901. if ($debug > 0) error_log('New LP - edit item prereq action triggered', 0);
  902. if (!$lp_found) { error_log('New LP - No learnpath given for edit item prereq', 0); require 'lp_list.php'; }
  903. else {
  904. if (!empty($_REQUEST['id']) && !empty($_REQUEST['submit_item'])) {
  905. $_SESSION['refresh'] = 1;
  906. $_SESSION['oLP']->edit_item_prereq($_REQUEST['id'], $_REQUEST['prereq']);
  907. }
  908. require 'lp_admin_view.php';
  909. }
  910. break;
  911. case 'restart':
  912. if ($debug > 0) error_log('New LP - restart action triggered', 0);
  913. if (!$lp_found) { error_log('New LP - No learnpath given for restart', 0); require 'lp_list.php'; }
  914. else {
  915. $_SESSION['oLP']->restart();
  916. require 'lp_view.php';
  917. }
  918. break;
  919. case 'last':
  920. if ($debug > 0) error_log('New LP - last action triggered', 0);
  921. if (!$lp_found) { error_log('New LP - No learnpath given for last', 0); require 'lp_list.php'; }
  922. else {
  923. $_SESSION['oLP']->last();
  924. require 'lp_view.php';
  925. }
  926. break;
  927. case 'first':
  928. if ($debug > 0) error_log('New LP - first action triggered', 0);
  929. if (!$lp_found) { error_log('New LP - No learnpath given for first', 0); require 'lp_list.php'; }
  930. else {
  931. $_SESSION['oLP']->first();
  932. require 'lp_view.php';
  933. }
  934. break;
  935. case 'next':
  936. if ($debug > 0) error_log('New LP - next action triggered', 0);
  937. if (!$lp_found) { error_log('New LP - No learnpath given for next', 0); require 'lp_list.php'; }
  938. else {
  939. $_SESSION['oLP']->next();
  940. require 'lp_view.php';
  941. }
  942. break;
  943. case 'previous':
  944. if ($debug > 0) error_log('New LP - previous action triggered', 0);
  945. if (!$lp_found) { error_log('New LP - No learnpath given for previous', 0); require 'lp_list.php'; }
  946. else {
  947. $_SESSION['oLP']->previous();
  948. require 'lp_view.php';
  949. }
  950. break;
  951. case 'content':
  952. if ($debug > 0) error_log('New LP - content action triggered', 0);
  953. if ($debug > 0) error_log('New LP - Item id is '.intval($_GET['item_id']), 0);
  954. if (!$lp_found) {
  955. error_log('New LP - No learnpath given for content', 0);
  956. require 'lp_list.php';
  957. }
  958. else {
  959. $_SESSION['oLP']->save_last();
  960. $_SESSION['oLP']->set_current_item($_GET['item_id']);
  961. $_SESSION['oLP']->start_current_item();
  962. require 'lp_content.php';
  963. }
  964. break;
  965. case 'view':
  966. if ($debug > 0)
  967. error_log('New LP - view action triggered', 0);
  968. if (!$lp_found) {
  969. error_log('New LP - No learnpath given for view', 0);
  970. require 'lp_list.php';
  971. } else {
  972. if ($debug > 0) {error_log('New LP - Trying to set current item to ' . $_REQUEST['item_id'], 0); }
  973. if ( !empty($_REQUEST['item_id']) ) {
  974. $_SESSION['oLP']->set_current_item($_REQUEST['item_id']);
  975. }
  976. require 'lp_view.php';
  977. }
  978. break;
  979. case 'save':
  980. if ($debug > 0) error_log('New LP - save action triggered', 0);
  981. if (!$lp_found) { error_log('New LP - No learnpath given for save', 0); require 'lp_list.php'; }
  982. else {
  983. $_SESSION['oLP']->save_item();
  984. require 'lp_save.php';
  985. }
  986. break;
  987. case 'stats':
  988. if ($debug > 0) error_log('New LP - stats action triggered', 0);
  989. if (!$lp_found) { error_log('New LP - No learnpath given for stats', 0); require 'lp_list.php'; }
  990. else {
  991. $_SESSION['oLP']->save_current();
  992. $_SESSION['oLP']->save_last();
  993. $output = require 'lp_stats.php';
  994. echo $output;
  995. }
  996. break;
  997. case 'list':
  998. if ($debug > 0) error_log('New LP - list action triggered', 0);
  999. if ($lp_found) {
  1000. $_SESSION['refresh'] = 1;
  1001. $_SESSION['oLP']->save_last();
  1002. }
  1003. require 'lp_list.php';
  1004. break;
  1005. case 'mode':
  1006. // Switch between fullscreen and embedded mode.
  1007. if ($debug > 0) error_log('New LP - mode change triggered', 0);
  1008. $mode = $_REQUEST['mode'];
  1009. if ($mode == 'fullscreen') {
  1010. $_SESSION['oLP']->mode = 'fullscreen';
  1011. } elseif ($mode == 'embedded') {
  1012. $_SESSION['oLP']->mode = 'embedded';
  1013. } elseif ($mode == 'embedframe') {
  1014. $_SESSION['oLP']->mode = 'embedframe';
  1015. } elseif ($mode == 'impress') {
  1016. $_SESSION['oLP']->mode = 'impress';
  1017. }
  1018. require 'lp_view.php';
  1019. break;
  1020. case 'switch_view_mode':
  1021. if ($debug > 0) error_log('New LP - switch_view_mode action triggered', 0);
  1022. if (!$lp_found) { error_log('New LP - No learnpath given for switch', 0); require 'lp_list.php'; }
  1023. if (Security::check_token('get')) {
  1024. $_SESSION['refresh'] = 1;
  1025. $_SESSION['oLP']->update_default_view_mode();
  1026. }
  1027. require 'lp_list.php';
  1028. break;
  1029. case 'switch_force_commit':
  1030. if ($debug > 0) error_log('New LP - switch_force_commit action triggered', 0);
  1031. if (!$lp_found) { error_log('New LP - No learnpath given for switch', 0); require 'lp_list.php'; }
  1032. $_SESSION['refresh'] = 1;
  1033. $_SESSION['oLP']->update_default_scorm_commit();
  1034. require 'lp_list.php';
  1035. break;
  1036. /* Those 2 switches have been replaced by switc_attempt_mode switch
  1037. case 'switch_reinit':
  1038. if ($debug > 0) error_log('New LP - switch_reinit action triggered', 0);
  1039. if (!$lp_found) { error_log('New LP - No learnpath given for switch', 0); require 'lp_list.php'; }
  1040. $_SESSION['refresh'] = 1;
  1041. $_SESSION['oLP']->update_reinit();
  1042. require 'lp_list.php';
  1043. break;
  1044. case 'switch_seriousgame_mode':
  1045. if($debug>0) error_log('New LP - switch_seriousgame_mode action triggered',0);
  1046. if(!$lp_found){ error_log('New LP - No learnpath given for switch',0); require 'lp_list.php'; }
  1047. $_SESSION['refresh'] = 1;
  1048. $_SESSION['oLP']->set_seriousgame_mode();
  1049. require 'lp_list.php';
  1050. break;
  1051. */
  1052. case 'switch_attempt_mode':
  1053. if($debug>0) error_log('New LP - switch_reinit action triggered',0);
  1054. if(!$lp_found){ error_log('New LP - No learnpath given for switch',0); require 'lp_list.php'; }
  1055. $_SESSION['refresh'] = 1;
  1056. $_SESSION['oLP']->switch_attempt_mode();
  1057. require 'lp_list.php';
  1058. break;
  1059. case 'switch_scorm_debug':
  1060. if ($debug > 0) error_log('New LP - switch_scorm_debug action triggered', 0);
  1061. if (!$lp_found) { error_log('New LP - No learnpath given for switch', 0); require 'lp_list.php'; }
  1062. $_SESSION['refresh'] = 1;
  1063. $_SESSION['oLP']->update_scorm_debug();
  1064. require 'lp_list.php';
  1065. break;
  1066. case 'intro_cmdAdd':
  1067. if ($debug > 0) error_log('New LP - intro_cmdAdd action triggered', 0);
  1068. // Add introduction section page.
  1069. break;
  1070. case 'js_api_refresh':
  1071. if ($debug > 0) error_log('New LP - js_api_refresh action triggered', 0);
  1072. if (!$lp_found) { error_log('New LP - No learnpath given for js_api_refresh', 0); require 'lp_message.php'; }
  1073. if (isset($_REQUEST['item_id'])) {
  1074. $htmlHeadXtra[] = $_SESSION['oLP']->get_js_info($_REQUEST['item_id']);
  1075. }
  1076. require 'lp_message.php';
  1077. break;
  1078. case 'return_to_course_homepage':
  1079. if (!$lp_found) { error_log('New LP - No learnpath given for stats', 0); require 'lp_list.php'; }
  1080. else {
  1081. $_SESSION['oLP']->save_current();
  1082. $_SESSION['oLP']->save_last();
  1083. $url = api_get_path(WEB_COURSE_PATH).api_get_course_path().'/index.php?id_session='.api_get_session_id();
  1084. if (isset($_GET['redirectTo']) && $_GET['redirectTo'] == 'lp_list') {
  1085. $url = 'lp_controller.php?'.api_get_cidreq();
  1086. }
  1087. header('location: '.$url);
  1088. exit;
  1089. }
  1090. break;
  1091. case 'search':
  1092. /* Include the search script, it's smart enough to know when we are
  1093. * searching or not.
  1094. */
  1095. require 'lp_list_search.php';
  1096. break;
  1097. case 'impress':
  1098. if ($debug > 0)
  1099. error_log('New LP - view action triggered', 0);
  1100. if (!$lp_found) {
  1101. error_log('New LP - No learnpath given for view', 0);
  1102. require 'lp_list.php';
  1103. } else {
  1104. if ($debug > 0) {error_log('New LP - Trying to impress this LP item to ' . $_REQUEST['item_id'], 0); }
  1105. if (!empty($_REQUEST['item_id']) ) {
  1106. $_SESSION['oLP']->set_current_item($_REQUEST['item_id']);
  1107. }
  1108. require 'lp_impress.php';
  1109. }
  1110. break;
  1111. case 'set_previous_step_as_prerequisite':
  1112. $_SESSION['oLP']->set_previous_step_as_prerequisite_for_all_items();
  1113. $url = api_get_self().'?action=add_item&type=step&lp_id='.intval($_SESSION['oLP']->lp_id)."&message=ItemUpdated";
  1114. header('Location: '.$url);
  1115. break;
  1116. case 'clear_prerequisites':
  1117. $_SESSION['oLP']->clear_prerequisites();
  1118. $url = api_get_self().'?action=add_item&type=step&lp_id='.intval($_SESSION['oLP']->lp_id)."&message=ItemUpdated";
  1119. header('Location: '.$url);
  1120. break;
  1121. default:
  1122. if ($debug > 0) error_log('New LP - default action triggered', 0);
  1123. require 'lp_list.php';
  1124. break;
  1125. }
  1126. if (!empty($_SESSION['oLP'])) {
  1127. $_SESSION['lpobject'] = serialize($_SESSION['oLP']);
  1128. if ($debug > 0) error_log('New LP - lpobject is serialized in session', 0);
  1129. }