lp_controller.php 47 KB

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