lp_controller.php 53 KB

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