lp_controller.php 54 KB

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