lp_controller.php 53 KB

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