lp_controller.php 53 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397
  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. switch ($action) {
  323. case 'add_item':
  324. if (!$is_allowed_to_edit) {
  325. api_not_allowed(true);
  326. }
  327. if ($debug > 0) error_log('New LP - add item action triggered', 0);
  328. if (!$lp_found) {
  329. //check if the learnpath ID was defined, otherwise send back to list
  330. if ($debug > 0) error_log('New LP - No learnpath given for add item', 0);
  331. require 'lp_list.php';
  332. } else {
  333. $_SESSION['refresh'] = 1;
  334. if (isset($_POST['submit_button']) && !empty($post_title)) {
  335. // If a title was sumbitted:
  336. //Updating the lp.modified_on
  337. $_SESSION['oLP']->set_modified_on();
  338. if (isset($_SESSION['post_time']) && $_SESSION['post_time'] == $_POST['post_time']) {
  339. // Check post_time to ensure ??? (counter-hacking measure?)
  340. require 'lp_add_item.php';
  341. } else {
  342. $_SESSION['post_time'] = $_POST['post_time'];
  343. $parent = isset($_POST['parent']) ? $_POST['parent'] : '';
  344. $previous = isset($_POST['previous']) ? $_POST['previous'] : '';
  345. $type = isset($_POST['type']) ? $_POST['type'] : '';
  346. $path = isset($_POST['path']) ? $_POST['path'] : '';
  347. $description = isset($_POST['description']) ? $_POST['description'] : '';
  348. $prerequisites = isset($_POST['prerequisites']) ? $_POST['prerequisites'] : '';
  349. $maxTimeAllowed = isset($_POST['maxTimeAllowed']) ? $_POST['maxTimeAllowed'] : '';
  350. if ($_POST['type'] == TOOL_DOCUMENT) {
  351. if (isset($_POST['path']) && $_GET['edit'] != 'true') {
  352. $document_id = $_POST['path'];
  353. } else {
  354. if ($_POST['content_lp']) {
  355. $document_id = $_SESSION['oLP']->create_document(
  356. $_course,
  357. $_POST['content_lp'],
  358. $_POST['title']
  359. );
  360. }
  361. }
  362. $new_item_id = $_SESSION['oLP']->add_item(
  363. $parent,
  364. $previous,
  365. $type,
  366. $document_id,
  367. $post_title,
  368. $description,
  369. $prerequisites
  370. );
  371. } else {
  372. // For all other item types than documents, load the item using the item type and path rather than its ID.
  373. $new_item_id = $_SESSION['oLP']->add_item(
  374. $parent,
  375. $previous,
  376. $type,
  377. $path,
  378. $post_title,
  379. $description,
  380. $prerequisites,
  381. $maxTimeAllowed
  382. );
  383. }
  384. $url = api_get_self().'?action=add_item&type=step&lp_id='.intval($_SESSION['oLP']->lp_id);
  385. header('Location: '.$url);
  386. exit;
  387. }
  388. } else {
  389. require 'lp_add_item.php';
  390. }
  391. }
  392. break;
  393. case 'add_audio':
  394. if (!$is_allowed_to_edit) {
  395. api_not_allowed(true);
  396. }
  397. if ($debug > 0) error_log('New LP - add audio action triggered', 0);
  398. if (!$lp_found) {
  399. //check if the learnpath ID was defined, otherwise send back to list
  400. if ($debug > 0) error_log('New LP - No learnpath given for add audio', 0);
  401. require 'lp_list.php';
  402. } else {
  403. $_SESSION['refresh'] = 1;
  404. if (isset($_REQUEST['id'])) {
  405. $lp_item_obj = new learnpathItem($_REQUEST['id']);
  406. // Remove audio
  407. if (isset($_GET['delete_file']) && $_GET['delete_file'] == 1) {
  408. $lp_item_obj->remove_audio();
  409. $url = api_get_self().'?action=add_audio&lp_id='.intval($_SESSION['oLP']->lp_id).'&id='.$lp_item_obj->get_id().'&'.api_get_cidreq();
  410. header('Location: '.$url);
  411. exit;
  412. }
  413. // Upload audio
  414. if (isset($_FILES['file']) && !empty($_FILES['file'])) {
  415. // Updating the lp.modified_on
  416. $_SESSION['oLP']->set_modified_on();
  417. $lp_item_obj->add_audio();
  418. }
  419. //Add audio file from documents
  420. if (isset($_REQUEST['document_id']) && !empty($_REQUEST['document_id'])) {
  421. $_SESSION['oLP']->set_modified_on();
  422. $lp_item_obj->add_audio_from_documents($_REQUEST['document_id']);
  423. }
  424. // Display.
  425. require 'lp_add_audio.php';
  426. } else {
  427. require 'lp_add_audio.php';
  428. }
  429. }
  430. break;
  431. case 'add_lp_category':
  432. if (!$is_allowed_to_edit) {
  433. api_not_allowed(true);
  434. }
  435. require 'lp_add_category.php';
  436. break;
  437. case 'move_up_category':
  438. if (!$is_allowed_to_edit) {
  439. api_not_allowed(true);
  440. }
  441. if (isset($_REQUEST['id'])) {
  442. learnpath::moveUpCategory($_REQUEST['id']);
  443. }
  444. require 'lp_list.php';
  445. break;
  446. case 'move_down_category':
  447. if (!$is_allowed_to_edit) {
  448. api_not_allowed(true);
  449. }
  450. if (isset($_REQUEST['id'])) {
  451. learnpath::moveDownCategory($_REQUEST['id']);
  452. }
  453. require 'lp_list.php';
  454. break;
  455. case 'delete_lp_category':
  456. if (!$is_allowed_to_edit) {
  457. api_not_allowed(true);
  458. }
  459. if (isset($_REQUEST['id'])) {
  460. learnpath::deleteCategory($_REQUEST['id']);
  461. }
  462. require 'lp_list.php';
  463. break;
  464. case 'add_lp':
  465. if (!$is_allowed_to_edit) {
  466. api_not_allowed(true);
  467. }
  468. if ($debug > 0) error_log('New LP - add_lp action triggered', 0);
  469. if (isset($_REQUEST['lp_name']) && !empty($_REQUEST['lp_name'])) {
  470. $_REQUEST['lp_name'] = trim($_REQUEST['lp_name']);
  471. $_SESSION['refresh'] = 1;
  472. if (isset($_SESSION['post_time']) && $_SESSION['post_time'] == $_REQUEST['post_time']) {
  473. require 'lp_add.php';
  474. } else {
  475. $_SESSION['post_time'] = $_REQUEST['post_time'];
  476. if (isset($_REQUEST['activate_start_date_check']) &&
  477. $_REQUEST['activate_start_date_check'] == 1
  478. ) {
  479. $publicated_on = $_REQUEST['publicated_on'];
  480. } else {
  481. $publicated_on = null;
  482. }
  483. if (isset($_REQUEST['activate_end_date_check']) &&
  484. $_REQUEST['activate_end_date_check'] == 1
  485. ) {
  486. $expired_on = $_REQUEST['expired_on'];
  487. } else {
  488. $expired_on = null;
  489. }
  490. $new_lp_id = learnpath::add_lp(
  491. api_get_course_id(),
  492. Security::remove_XSS($_REQUEST['lp_name']),
  493. '',
  494. 'chamilo',
  495. 'manual',
  496. '',
  497. $publicated_on,
  498. $expired_on,
  499. $_REQUEST['category_id']
  500. );
  501. if (is_numeric($new_lp_id)) {
  502. // TODO: Maybe create a first module directly to avoid bugging the user with useless queries
  503. $_SESSION['oLP'] = new learnpath(
  504. api_get_course_id(),
  505. $new_lp_id,
  506. api_get_user_id()
  507. );
  508. //require 'lp_build.php';
  509. $url = api_get_self().'?action=add_item&type=step&lp_id='.intval($new_lp_id).'&'.api_get_cidreq();
  510. header("Location: $url&isStudentView=false");
  511. exit;
  512. }
  513. }
  514. } else {
  515. require 'lp_add.php';
  516. }
  517. break;
  518. case 'admin_view':
  519. if (!$is_allowed_to_edit) {
  520. api_not_allowed(true);
  521. }
  522. if ($debug > 0) error_log('New LP - admin_view action triggered', 0);
  523. if (!$lp_found) { error_log('New LP - No learnpath given for admin_view', 0); require 'lp_list.php'; }
  524. else {
  525. $_SESSION['refresh'] = 1;
  526. require 'lp_admin_view.php';
  527. }
  528. break;
  529. case 'auto_launch':
  530. if (api_get_course_setting('enable_lp_auto_launch') == 1) { //Redirect to a specific LP
  531. if (!$is_allowed_to_edit) {
  532. api_not_allowed(true);
  533. }
  534. if ($debug > 0) error_log('New LP - auto_launch action triggered', 0);
  535. if (!$lp_found) { error_log('New LP - No learnpath given for set_autolaunch', 0); require 'lp_list.php'; }
  536. else {
  537. $_SESSION['oLP']->set_autolaunch($_GET['lp_id'], $_GET['status']);
  538. require 'lp_list.php';
  539. exit;
  540. }
  541. }
  542. break;
  543. case 'build':
  544. if (!$is_allowed_to_edit) {
  545. api_not_allowed(true);
  546. }
  547. if ($debug > 0) error_log('New LP - build action triggered', 0);
  548. if (!$lp_found) { error_log('New LP - No learnpath given for build', 0); require 'lp_list.php'; }
  549. else {
  550. $_SESSION['refresh'] = 1;
  551. //require 'lp_build.php';
  552. $url = api_get_self().'?action=add_item&type=step&lp_id='.intval($_SESSION['oLP']->lp_id);
  553. header('Location: '.$url);
  554. exit;
  555. }
  556. break;
  557. case 'edit_item':
  558. if (!$is_allowed_to_edit) {
  559. api_not_allowed(true);
  560. }
  561. if ($debug > 0) error_log('New LP - edit item action triggered', 0);
  562. if (!$lp_found) { error_log('New LP - No learnpath given for edit item', 0); require 'lp_list.php'; }
  563. else {
  564. $_SESSION['refresh'] = 1;
  565. if (isset($_POST['submit_button']) && !empty($post_title)) {
  566. //Updating the lp.modified_on
  567. $_SESSION['oLP']->set_modified_on();
  568. // TODO: mp3 edit
  569. $audio = array();
  570. if (isset($_FILES['mp3'])) {
  571. $audio = $_FILES['mp3'];
  572. }
  573. $description = isset($_POST['description']) ? $_POST['description'] : '';
  574. $prerequisites = isset($_POST['prerequisites']) ? $_POST['prerequisites'] : '';
  575. $maxTimeAllowed = isset($_POST['maxTimeAllowed']) ? $_POST['maxTimeAllowed'] : '';
  576. $url = isset($_POST['url']) ? $_POST['url'] : '';
  577. $_SESSION['oLP']->edit_item(
  578. $_REQUEST['id'],
  579. $_POST['parent'],
  580. $_POST['previous'],
  581. $post_title,
  582. $description,
  583. $prerequisites,
  584. $audio,
  585. $maxTimeAllowed,
  586. $url
  587. );
  588. if (isset($_POST['content_lp'])) {
  589. $_SESSION['oLP']->edit_document($_course);
  590. }
  591. $is_success = true;
  592. $url = api_get_self().'?action=add_item&type=step&lp_id='.intval($_SESSION['oLP']->lp_id);
  593. header('Location: '.$url);
  594. exit;
  595. }
  596. if (isset($_GET['view']) && $_GET['view'] == 'build') {
  597. require 'lp_edit_item.php';
  598. } else {
  599. require 'lp_admin_view.php';
  600. }
  601. }
  602. break;
  603. case 'edit_item_prereq':
  604. if (!$is_allowed_to_edit) {
  605. api_not_allowed(true);
  606. }
  607. if ($debug > 0) error_log('New LP - edit item prereq action triggered', 0);
  608. if (!$lp_found) { error_log('New LP - No learnpath given for edit item prereq', 0); require 'lp_list.php'; }
  609. else {
  610. if (isset($_POST['submit_button'])) {
  611. //Updating the lp.modified_on
  612. $_SESSION['oLP']->set_modified_on();
  613. $_SESSION['refresh'] = 1;
  614. $editPrerequisite = $_SESSION['oLP']->edit_item_prereq(
  615. $_GET['id'],
  616. $_POST['prerequisites'],
  617. $_POST['min_' . $_POST['prerequisites']],
  618. $_POST['max_' . $_POST['prerequisites']]
  619. );
  620. if ($editPrerequisite) {
  621. $is_success = true;
  622. }
  623. $url = api_get_self().'?action=add_item&type=step&lp_id='.intval($_SESSION['oLP']->lp_id).'&'.api_get_cidreq();
  624. header('Location: '.$url);
  625. exit;
  626. } else {
  627. require 'lp_edit_item_prereq.php';
  628. }
  629. }
  630. break;
  631. case 'move_item':
  632. if (!$is_allowed_to_edit) {
  633. api_not_allowed(true);
  634. }
  635. if ($debug > 0) error_log('New LP - move item action triggered', 0);
  636. if (!$lp_found) { error_log('New LP - No learnpath given for move item', 0); require 'lp_list.php'; }
  637. else {
  638. $_SESSION['refresh'] = 1;
  639. if (isset($_POST['submit_button'])) {
  640. //Updating the lp.modified_on
  641. $_SESSION['oLP']->set_modified_on();
  642. $_SESSION['oLP']->edit_item(
  643. $_GET['id'],
  644. $_POST['parent'],
  645. $_POST['previous'],
  646. $post_title,
  647. $_POST['description']
  648. );
  649. $is_success = true;
  650. $url = api_get_self().'?action=add_item&type=step&lp_id='.intval($_SESSION['oLP']->lp_id).'&'.api_get_cidreq();
  651. header('Location: '.$url);
  652. }
  653. if (isset($_GET['view']) && $_GET['view'] == 'build') {
  654. require 'lp_move_item.php';
  655. } else {
  656. // Avoids weird behaviours see CT#967.
  657. $check = Security::check_token('get');
  658. if ($check) {
  659. $_SESSION['oLP']->move_item($_GET['id'], $_GET['direction']);
  660. }
  661. Security::clear_token();
  662. require 'lp_admin_view.php';
  663. }
  664. }
  665. break;
  666. case 'view_item':
  667. if (!$is_allowed_to_edit) {
  668. api_not_allowed(true);
  669. }
  670. if ($debug > 0) error_log('New LP - view_item action triggered', 0);
  671. if (!$lp_found) {
  672. error_log('New LP - No learnpath given for view item', 0); require 'lp_list.php';
  673. } else {
  674. $_SESSION['refresh'] = 1;
  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('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. $_SESSION['oLP']->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('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. $_SESSION['oLP']->scorm_export();
  716. exit();
  717. //require 'lp_list.php';
  718. }
  719. break;
  720. case 'export_to_pdf':
  721. if (!learnpath::is_lp_visible_for_student($_SESSION['oLP']->lp_id, api_get_user_id())) {
  722. api_not_allowed();
  723. }
  724. $hideScormPdfLink = api_get_setting('hide_scorm_pdf_link');
  725. if ($hideScormPdfLink === 'true') {
  726. api_not_allowed(true);
  727. }
  728. if ($debug > 0) error_log('New LP - export action triggered', 0);
  729. if (!$lp_found) { error_log('New LP - No learnpath given for export_to_pdf', 0); require 'lp_list.php';
  730. } else {
  731. $result = $_SESSION['oLP']->scorm_export_to_pdf($_GET['lp_id']);
  732. if (!$result) {
  733. require 'lp_list.php';
  734. }
  735. exit;
  736. }
  737. break;
  738. case 'delete':
  739. if (!$is_allowed_to_edit) {
  740. api_not_allowed(true);
  741. }
  742. if ($debug > 0) error_log('New LP - delete action triggered', 0);
  743. if (!$lp_found) { error_log('New LP - No learnpath given for delete', 0); require 'lp_list.php'; }
  744. else {
  745. $_SESSION['refresh'] = 1;
  746. $_SESSION['oLP']->delete(null, $_GET['lp_id'], 'remove');
  747. Session::erase('oLP');
  748. require 'lp_list.php';
  749. }
  750. break;
  751. case 'toggle_visible':
  752. // Change lp visibility (inside lp tool).
  753. if (!$is_allowed_to_edit) {
  754. api_not_allowed(true);
  755. }
  756. if ($debug > 0) error_log('New LP - visibility action triggered', 0);
  757. if (!$lp_found) { error_log('New LP - No learnpath given for visibility', 0); require 'lp_list.php'; }
  758. else {
  759. learnpath::toggle_visibility($_REQUEST['lp_id'], $_REQUEST['new_status']);
  760. require 'lp_list.php';
  761. }
  762. break;
  763. case 'toggle_publish':
  764. // Change lp published status (visibility on homepage).
  765. if (!$is_allowed_to_edit) {
  766. api_not_allowed(true);
  767. }
  768. if ($debug > 0) error_log('New LP - publish action triggered', 0);
  769. if (!$lp_found) { error_log('New LP - No learnpath given for publish', 0); require 'lp_list.php'; }
  770. else {
  771. learnpath::toggle_publish($_REQUEST['lp_id'], $_REQUEST['new_status']);
  772. require 'lp_list.php';
  773. }
  774. break;
  775. case 'move_lp_up':
  776. // Change lp published status (visibility on homepage)
  777. if (!$is_allowed_to_edit) {
  778. api_not_allowed(true);
  779. }
  780. if ($debug > 0) error_log('New LP - publish action triggered', 0);
  781. if (!$lp_found) {
  782. error_log('New LP - No learnpath given for publish', 0);
  783. require 'lp_list.php';
  784. } else {
  785. learnpath::move_up($_REQUEST['lp_id']);
  786. require 'lp_list.php';
  787. }
  788. break;
  789. case 'move_lp_down':
  790. // Change lp published status (visibility on homepage)
  791. if (!$is_allowed_to_edit) {
  792. api_not_allowed(true);
  793. }
  794. if ($debug > 0) error_log('New LP - publish action triggered', 0);
  795. if (!$lp_found) {
  796. error_log('New LP - No learnpath given for publish', 0);
  797. require 'lp_list.php';
  798. } else {
  799. learnpath::move_down($_REQUEST['lp_id']);
  800. require 'lp_list.php';
  801. }
  802. break;
  803. case 'edit':
  804. if (!$is_allowed_to_edit) {
  805. api_not_allowed(true);
  806. }
  807. if ($debug > 0) error_log('New LP - edit action triggered', 0);
  808. if (!$lp_found) { error_log('New LP - No learnpath given for edit', 0); require 'lp_list.php'; }
  809. else {
  810. $_SESSION['refresh'] = 1;
  811. require 'lp_edit.php';
  812. }
  813. break;
  814. case 'update_lp':
  815. if (!$is_allowed_to_edit) {
  816. api_not_allowed(true);
  817. }
  818. if ($debug > 0) error_log('New LP - update_lp action triggered', 0);
  819. if (!$lp_found) { error_log('New LP - No learnpath given for edit', 0); require 'lp_list.php'; }
  820. else {
  821. $_SESSION['refresh'] = 1;
  822. $lp_name = Security::remove_XSS($_REQUEST['lp_name']);
  823. $_SESSION['oLP']->set_name($lp_name);
  824. $author = $_REQUEST['lp_author'];
  825. // Fixing the author name (no body or html tags).
  826. $auth_init = stripos($author, '<p>');
  827. if ($auth_init === false) {
  828. $auth_init = stripos($author, '<body>');
  829. $auth_end = $auth_init + stripos(substr($author, $auth_init + 6), '</body>') + 7;
  830. $len = $auth_end - $auth_init + 6;
  831. } else {
  832. $auth_end = strripos($author, '</p>');
  833. $len = $auth_end - $auth_init + 4;
  834. }
  835. $author_fixed = substr($author, $auth_init, $len);
  836. //$author_fixed = $author;
  837. $_SESSION['oLP']->set_author($author_fixed);
  838. // TODO (as of Chamilo 1.8.8): Check in the future whether this field is needed.
  839. $_SESSION['oLP']->set_encoding($_REQUEST['lp_encoding']);
  840. if (isset($_REQUEST['lp_maker'])) {
  841. $_SESSION['oLP']->set_maker($_REQUEST['lp_maker']);
  842. }
  843. if (isset($_REQUEST['lp_proximity'])) {
  844. $_SESSION['oLP']->set_proximity($_REQUEST['lp_proximity']);
  845. }
  846. $_SESSION['oLP']->set_theme($_REQUEST['lp_theme']);
  847. if (isset($_REQUEST['hide_toc_frame']) && $_REQUEST['hide_toc_frame'] == 1) {
  848. $hide_toc_frame = $_REQUEST['hide_toc_frame'];
  849. } else {
  850. $hide_toc_frame = null;
  851. }
  852. $_SESSION['oLP']->set_hide_toc_frame($hide_toc_frame);
  853. $_SESSION['oLP']->set_prerequisite($_REQUEST['prerequisites']);
  854. $_SESSION['oLP']->set_use_max_score($_REQUEST['use_max_score']);
  855. $_SESSION['oLP']->setSubscribeUsers($_REQUEST['subscribe_users']);
  856. if (isset($_REQUEST['activate_start_date_check']) && $_REQUEST['activate_start_date_check'] == 1) {
  857. $publicated_on = $_REQUEST['publicated_on'];
  858. } else {
  859. $publicated_on = null;
  860. }
  861. if (isset($_REQUEST['activate_end_date_check']) && $_REQUEST['activate_end_date_check'] == 1) {
  862. $expired_on = $_REQUEST['expired_on'];
  863. } else {
  864. $expired_on = null;
  865. }
  866. $_SESSION['oLP']->setCategoryId($_REQUEST['category_id']);
  867. $_SESSION['oLP']->set_modified_on();
  868. $_SESSION['oLP']->set_publicated_on($publicated_on);
  869. $_SESSION['oLP']->set_expired_on($expired_on);
  870. if (isset($_REQUEST['remove_picture']) && $_REQUEST['remove_picture']) {
  871. $_SESSION['oLP']->delete_lp_image();
  872. }
  873. $extraFieldValue = new ExtraFieldValue('lp');
  874. $params = array(
  875. 'lp_id' => $_SESSION['oLP']->id
  876. );
  877. $extraFieldValue->saveFieldValues($_REQUEST);
  878. if ($_FILES['lp_preview_image']['size'] > 0)
  879. $_SESSION['oLP']->upload_image($_FILES['lp_preview_image']);
  880. if (api_get_setting('search_enabled') === 'true') {
  881. require_once api_get_path(LIBRARY_PATH).'specific_fields_manager.lib.php';
  882. $specific_fields = get_specific_field_list();
  883. foreach ($specific_fields as $specific_field) {
  884. $_SESSION['oLP']->set_terms_by_prefix($_REQUEST[$specific_field['code']], $specific_field['code']);
  885. $new_values = explode(',', trim($_REQUEST[$specific_field['code']]));
  886. if (!empty($new_values)) {
  887. array_walk($new_values, 'trim');
  888. delete_all_specific_field_value(
  889. api_get_course_id(),
  890. $specific_field['id'],
  891. TOOL_LEARNPATH,
  892. $_SESSION['oLP']->lp_id
  893. );
  894. foreach ($new_values as $value) {
  895. if (!empty($value)) {
  896. add_specific_field_value(
  897. $specific_field['id'],
  898. api_get_course_id(),
  899. TOOL_LEARNPATH,
  900. $_SESSION['oLP']->lp_id,
  901. $value
  902. );
  903. }
  904. }
  905. }
  906. }
  907. }
  908. $url = api_get_self().'?action=add_item&type=step&lp_id='.intval($_SESSION['oLP']->lp_id).'&'.api_get_cidreq();
  909. header('Location: '.$url);
  910. exit;
  911. }
  912. break;
  913. case 'add_sub_item': // Add an item inside a chapter.
  914. if (!$is_allowed_to_edit) {
  915. api_not_allowed(true);
  916. }
  917. if ($debug > 0) error_log('New LP - add sub item action triggered', 0);
  918. if (!$lp_found) { error_log('New LP - No learnpath given for add sub item', 0); require 'lp_list.php'; }
  919. else {
  920. $_SESSION['refresh'] = 1;
  921. if (!empty($_REQUEST['parent_item_id'])) {
  922. $_SESSION['from_learnpath']='yes';
  923. $_SESSION['origintoolurl'] = 'lp_controller.php?action=admin_view&lp_id='.Security::remove_XSS($_REQUEST['lp_id']);
  924. require 'resourcelinker.php';
  925. } else {
  926. require 'lp_admin_view.php';
  927. }
  928. }
  929. break;
  930. case 'deleteitem':
  931. case 'delete_item':
  932. if (!$is_allowed_to_edit) {
  933. api_not_allowed(true);
  934. }
  935. if ($debug > 0) error_log('New LP - delete item action triggered', 0);
  936. if (!$lp_found) { error_log('New LP - No learnpath given for delete item', 0); require 'lp_list.php'; }
  937. else {
  938. //$_SESSION['refresh'] = 1;
  939. if (!empty($_REQUEST['id'])) {
  940. $_SESSION['oLP']->delete_item($_REQUEST['id']);
  941. }
  942. $url = api_get_self().'?action=add_item&type=step&lp_id='.intval($_REQUEST['lp_id']).api_get_cidreq();
  943. header('Location: '.$url);
  944. exit;
  945. }
  946. break;
  947. case 'edititemprereq':
  948. case 'edit_item_prereq':
  949. if (!$is_allowed_to_edit) {
  950. api_not_allowed(true);
  951. }
  952. if ($debug > 0) error_log('New LP - edit item prereq action triggered', 0);
  953. if (!$lp_found) { error_log('New LP - No learnpath given for edit item prereq', 0); require 'lp_list.php'; }
  954. else {
  955. if (!empty($_REQUEST['id']) && !empty($_REQUEST['submit_item'])) {
  956. $_SESSION['refresh'] = 1;
  957. $_SESSION['oLP']->edit_item_prereq($_REQUEST['id'], $_REQUEST['prereq']);
  958. }
  959. require 'lp_admin_view.php';
  960. }
  961. break;
  962. case 'restart':
  963. if ($debug > 0) error_log('New LP - restart action triggered', 0);
  964. if (!$lp_found) { error_log('New LP - No learnpath given for restart', 0); require 'lp_list.php'; }
  965. else {
  966. $_SESSION['oLP']->restart();
  967. require 'lp_view.php';
  968. }
  969. break;
  970. case 'last':
  971. if ($debug > 0) error_log('New LP - last action triggered', 0);
  972. if (!$lp_found) { error_log('New LP - No learnpath given for last', 0); require 'lp_list.php'; }
  973. else {
  974. $_SESSION['oLP']->last();
  975. require 'lp_view.php';
  976. }
  977. break;
  978. case 'first':
  979. if ($debug > 0) error_log('New LP - first action triggered', 0);
  980. if (!$lp_found) { error_log('New LP - No learnpath given for first', 0); require 'lp_list.php'; }
  981. else {
  982. $_SESSION['oLP']->first();
  983. require 'lp_view.php';
  984. }
  985. break;
  986. case 'next':
  987. if ($debug > 0) error_log('New LP - next action triggered', 0);
  988. if (!$lp_found) { error_log('New LP - No learnpath given for next', 0); require 'lp_list.php'; }
  989. else {
  990. $_SESSION['oLP']->next();
  991. require 'lp_view.php';
  992. }
  993. break;
  994. case 'previous':
  995. if ($debug > 0) error_log('New LP - previous action triggered', 0);
  996. if (!$lp_found) { error_log('New LP - No learnpath given for previous', 0); require 'lp_list.php'; }
  997. else {
  998. $_SESSION['oLP']->previous();
  999. require 'lp_view.php';
  1000. }
  1001. break;
  1002. case 'content':
  1003. if ($debug > 0) error_log('New LP - content action triggered', 0);
  1004. if ($debug > 0) error_log('New LP - Item id is '.intval($_GET['item_id']), 0);
  1005. if (!$lp_found) {
  1006. error_log('New LP - No learnpath given for content', 0);
  1007. require 'lp_list.php';
  1008. }
  1009. else {
  1010. $_SESSION['oLP']->save_last();
  1011. $_SESSION['oLP']->set_current_item($_GET['item_id']);
  1012. $_SESSION['oLP']->start_current_item();
  1013. require 'lp_content.php';
  1014. }
  1015. break;
  1016. case 'view':
  1017. if ($debug > 0)
  1018. error_log('New LP - view action triggered', 0);
  1019. if (!$lp_found) {
  1020. error_log('New LP - No learnpath given for view', 0);
  1021. require 'lp_list.php';
  1022. } else {
  1023. if ($debug > 0) {error_log('New LP - Trying to set current item to ' . $_REQUEST['item_id'], 0); }
  1024. if ( !empty($_REQUEST['item_id']) ) {
  1025. $_SESSION['oLP']->set_current_item($_REQUEST['item_id']);
  1026. }
  1027. require 'lp_view.php';
  1028. }
  1029. break;
  1030. case 'save':
  1031. if ($debug > 0) error_log('New LP - save action triggered', 0);
  1032. if (!$lp_found) { error_log('New LP - No learnpath given for save', 0); require 'lp_list.php'; }
  1033. else {
  1034. $_SESSION['oLP']->save_item();
  1035. require 'lp_save.php';
  1036. }
  1037. break;
  1038. case 'stats':
  1039. if ($debug > 0) error_log('New LP - stats action triggered', 0);
  1040. if (!$lp_found) { error_log('New LP - No learnpath given for stats', 0); require 'lp_list.php'; }
  1041. else {
  1042. $_SESSION['oLP']->save_current();
  1043. $_SESSION['oLP']->save_last();
  1044. $output = require 'lp_stats.php';
  1045. echo $output;
  1046. }
  1047. break;
  1048. case 'list':
  1049. if ($debug > 0) error_log('New LP - list action triggered', 0);
  1050. if ($lp_found) {
  1051. $_SESSION['refresh'] = 1;
  1052. $_SESSION['oLP']->save_last();
  1053. }
  1054. require 'lp_list.php';
  1055. break;
  1056. case 'mode':
  1057. // Switch between fullscreen and embedded mode.
  1058. if ($debug > 0) error_log('New LP - mode change triggered', 0);
  1059. $mode = $_REQUEST['mode'];
  1060. if ($mode == 'fullscreen') {
  1061. $_SESSION['oLP']->mode = 'fullscreen';
  1062. } elseif ($mode == 'embedded') {
  1063. $_SESSION['oLP']->mode = 'embedded';
  1064. } elseif ($mode == 'embedframe') {
  1065. $_SESSION['oLP']->mode = 'embedframe';
  1066. } elseif ($mode == 'impress') {
  1067. $_SESSION['oLP']->mode = 'impress';
  1068. }
  1069. require 'lp_view.php';
  1070. break;
  1071. case 'switch_view_mode':
  1072. if ($debug > 0) error_log('New LP - switch_view_mode action triggered', 0);
  1073. if (!$lp_found) { error_log('New LP - No learnpath given for switch', 0); require 'lp_list.php'; }
  1074. if (Security::check_token('get')) {
  1075. $_SESSION['refresh'] = 1;
  1076. $_SESSION['oLP']->update_default_view_mode();
  1077. }
  1078. require 'lp_list.php';
  1079. break;
  1080. case 'switch_force_commit':
  1081. if ($debug > 0) error_log('New LP - switch_force_commit action triggered', 0);
  1082. if (!$lp_found) { error_log('New LP - No learnpath given for switch', 0); require 'lp_list.php'; }
  1083. $_SESSION['refresh'] = 1;
  1084. $_SESSION['oLP']->update_default_scorm_commit();
  1085. require 'lp_list.php';
  1086. break;
  1087. /* Those 2 switches have been replaced by switc_attempt_mode switch
  1088. case 'switch_reinit':
  1089. if ($debug > 0) error_log('New LP - switch_reinit action triggered', 0);
  1090. if (!$lp_found) { error_log('New LP - No learnpath given for switch', 0); require 'lp_list.php'; }
  1091. $_SESSION['refresh'] = 1;
  1092. $_SESSION['oLP']->update_reinit();
  1093. require 'lp_list.php';
  1094. break;
  1095. case 'switch_seriousgame_mode':
  1096. if($debug>0) error_log('New LP - switch_seriousgame_mode action triggered',0);
  1097. if(!$lp_found){ error_log('New LP - No learnpath given for switch',0); require 'lp_list.php'; }
  1098. $_SESSION['refresh'] = 1;
  1099. $_SESSION['oLP']->set_seriousgame_mode();
  1100. require 'lp_list.php';
  1101. break;
  1102. */
  1103. case 'switch_attempt_mode':
  1104. if($debug>0) error_log('New LP - switch_reinit action triggered',0);
  1105. if(!$lp_found){ error_log('New LP - No learnpath given for switch',0); require 'lp_list.php'; }
  1106. $_SESSION['refresh'] = 1;
  1107. $_SESSION['oLP']->switch_attempt_mode();
  1108. require 'lp_list.php';
  1109. break;
  1110. case 'switch_scorm_debug':
  1111. if ($debug > 0) error_log('New LP - switch_scorm_debug 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_scorm_debug();
  1115. require 'lp_list.php';
  1116. break;
  1117. case 'intro_cmdAdd':
  1118. if ($debug > 0) error_log('New LP - intro_cmdAdd action triggered', 0);
  1119. // Add introduction section page.
  1120. break;
  1121. case 'js_api_refresh':
  1122. if ($debug > 0) error_log('New LP - js_api_refresh action triggered', 0);
  1123. if (!$lp_found) { error_log('New LP - No learnpath given for js_api_refresh', 0); require 'lp_message.php'; }
  1124. if (isset($_REQUEST['item_id'])) {
  1125. $htmlHeadXtra[] = $_SESSION['oLP']->get_js_info($_REQUEST['item_id']);
  1126. }
  1127. require 'lp_message.php';
  1128. break;
  1129. case 'return_to_course_homepage':
  1130. if (!$lp_found) { error_log('New LP - No learnpath given for stats', 0); require 'lp_list.php'; }
  1131. else {
  1132. $_SESSION['oLP']->save_current();
  1133. $_SESSION['oLP']->save_last();
  1134. $url = api_get_path(WEB_COURSE_PATH).api_get_course_path().'/index.php?id_session='.api_get_session_id();
  1135. if (isset($_GET['redirectTo']) && $_GET['redirectTo'] == 'lp_list') {
  1136. $url = 'lp_controller.php?'.api_get_cidreq();
  1137. }
  1138. header('location: '.$url);
  1139. exit;
  1140. }
  1141. break;
  1142. case 'search':
  1143. /* Include the search script, it's smart enough to know when we are
  1144. * searching or not.
  1145. */
  1146. require 'lp_list_search.php';
  1147. break;
  1148. case 'impress':
  1149. if ($debug > 0)
  1150. error_log('New LP - view action triggered', 0);
  1151. if (!$lp_found) {
  1152. error_log('New LP - No learnpath given for view', 0);
  1153. require 'lp_list.php';
  1154. } else {
  1155. if ($debug > 0) {error_log('New LP - Trying to impress this LP item to ' . $_REQUEST['item_id'], 0); }
  1156. if (!empty($_REQUEST['item_id']) ) {
  1157. $_SESSION['oLP']->set_current_item($_REQUEST['item_id']);
  1158. }
  1159. require 'lp_impress.php';
  1160. }
  1161. break;
  1162. case 'set_previous_step_as_prerequisite':
  1163. $_SESSION['oLP']->set_previous_step_as_prerequisite_for_all_items();
  1164. $url = api_get_self().'?action=add_item&type=step&lp_id='.intval($_SESSION['oLP']->lp_id)."&message=ItemUpdated";
  1165. header('Location: '.$url);
  1166. break;
  1167. case 'clear_prerequisites':
  1168. $_SESSION['oLP']->clear_prerequisites();
  1169. $url = api_get_self().'?action=add_item&type=step&lp_id='.intval($_SESSION['oLP']->lp_id)."&message=ItemUpdated";
  1170. header('Location: '.$url);
  1171. break;
  1172. case 'toggle_seriousgame': //activate/deactive seriousgame_mode
  1173. if (!$is_allowed_to_edit) {
  1174. api_not_allowed(true);
  1175. }
  1176. if ($debug > 0) {
  1177. error_log('New LP - seriousgame_mode action triggered');
  1178. }
  1179. if (!$lp_found) {
  1180. error_log('New LP - No learnpath given for visibility');
  1181. require 'lp_list.php';
  1182. }
  1183. $_SESSION['refresh'] = 1;
  1184. $_SESSION['oLP']->set_seriousgame_mode();
  1185. require 'lp_list.php';
  1186. break;
  1187. case 'create_forum':
  1188. if (!isset($_GET['id'])) {
  1189. break;
  1190. }
  1191. $selectedItem = null;
  1192. foreach ($_SESSION['oLP']->items as $item) {
  1193. if ($item->db_id == $_GET['id']) {
  1194. $selectedItem = $item;
  1195. }
  1196. }
  1197. if (!empty($selectedItem)) {
  1198. $forumThread = $selectedItem->getForumThread(
  1199. $_SESSION['oLP']->course_int_id,
  1200. $_SESSION['oLP']->lp_session_id
  1201. );
  1202. if (empty($forumThread)) {
  1203. require '../forum/forumfunction.inc.php';
  1204. $forumCategory = getForumCategoryByTitle(
  1205. get_lang('LearningPaths'),
  1206. $_SESSION['oLP']->course_int_id,
  1207. $_SESSION['oLP']->lp_session_id
  1208. );
  1209. $forumCategoryId = !empty($forumCategory) ? $forumCategory['cat_id']: 0;
  1210. if (empty($forumCategoryId)) {
  1211. $forumCategoryId = store_forumcategory(
  1212. [
  1213. 'lp_id' => 0,
  1214. 'forum_category_title' => get_lang('LearningPaths'),
  1215. 'forum_category_comment' => null
  1216. ],
  1217. [],
  1218. false
  1219. );
  1220. }
  1221. if (!empty($forumCategoryId)) {
  1222. $forum = $_SESSION['oLP']->getForum(
  1223. $_SESSION['oLP']->lp_session_id
  1224. );
  1225. $forumId = !empty($forum) ? $forum['forum_id'] : 0;
  1226. if (empty($forumId)) {
  1227. $forumId = $_SESSION['oLP']->createForum($forumCategoryId);
  1228. }
  1229. if (!empty($forumId)) {
  1230. $selectedItem->createForumThread($forumId);
  1231. }
  1232. }
  1233. }
  1234. }
  1235. header('Location:' . api_get_self() . '?' . http_build_query([
  1236. 'action' => 'add_item',
  1237. 'type' => 'step',
  1238. 'lp_id' => $_SESSION['oLP']->lp_id
  1239. ]));
  1240. break;
  1241. case 'report':
  1242. require 'lp_report.php';
  1243. break;
  1244. case 'dissociate_forum':
  1245. if (!isset($_GET['id'])) {
  1246. break;
  1247. }
  1248. $selectedItem = null;
  1249. foreach ($_SESSION['oLP']->items as $item) {
  1250. if ($item->db_id != $_GET['id']) {
  1251. continue;
  1252. }
  1253. $selectedItem = $item;
  1254. }
  1255. if (!empty($selectedItem)) {
  1256. $forumThread = $selectedItem->getForumThread(
  1257. $_SESSION['oLP']->course_int_id,
  1258. $_SESSION['oLP']->lp_session_id
  1259. );
  1260. if (!empty($forumThread)) {
  1261. $dissoaciated = $selectedItem->dissociateForumThread($forumThread['iid']);
  1262. if ($dissoaciated) {
  1263. Display::addFlash(
  1264. Display::return_message(get_lang('ForumDissociate'), 'success')
  1265. );
  1266. }
  1267. }
  1268. }
  1269. header('Location:' . api_get_self() . '?' . http_build_query([
  1270. 'action' => 'add_item',
  1271. 'type' => 'step',
  1272. 'lp_id' => $_SESSION['oLP']->lp_id
  1273. ]));
  1274. break;
  1275. default:
  1276. if ($debug > 0) error_log('New LP - default action triggered', 0);
  1277. require 'lp_list.php';
  1278. break;
  1279. }
  1280. if (!empty($_SESSION['oLP'])) {
  1281. $_SESSION['lpobject'] = serialize($_SESSION['oLP']);
  1282. if ($debug > 0) error_log('New LP - lpobject is serialized in session', 0);
  1283. }