lp_controller.php 54 KB

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