lp_controller.php 53 KB

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