lp_controller.php 53 KB

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