lp_controller.php 55 KB

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