lp_controller.php 55 KB

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