lp_controller.php 55 KB

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