lp_controller.php 53 KB

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