lp_controller.php 54 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544
  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. // Redirect to a specific LP
  623. if (api_get_course_setting('enable_lp_auto_launch') == 1) {
  624. if (!$is_allowed_to_edit) {
  625. api_not_allowed(true);
  626. }
  627. if (!$lp_found) {
  628. require 'lp_list.php';
  629. } else {
  630. $_SESSION['oLP']->set_autolaunch($_GET['lp_id'], $_GET['status']);
  631. require 'lp_list.php';
  632. exit;
  633. }
  634. }
  635. break;
  636. case 'build':
  637. if (!$is_allowed_to_edit) {
  638. api_not_allowed(true);
  639. }
  640. if (!$lp_found) {
  641. require 'lp_list.php';
  642. } else {
  643. Session::write('refresh', 1);
  644. //require 'lp_build.php';
  645. $url = api_get_self().'?action=add_item&type=step&lp_id='.intval($_SESSION['oLP']->lp_id).'&'.api_get_cidreq();
  646. header('Location: '.$url);
  647. exit;
  648. }
  649. break;
  650. case 'edit_item':
  651. if (!$is_allowed_to_edit) {
  652. api_not_allowed(true);
  653. }
  654. if (!$lp_found) {
  655. require 'lp_list.php';
  656. } else {
  657. Session::write('refresh', 1);
  658. if (isset($_POST['submit_button']) && !empty($post_title)) {
  659. //Updating the lp.modified_on
  660. $_SESSION['oLP']->set_modified_on();
  661. // TODO: mp3 edit
  662. $audio = [];
  663. if (isset($_FILES['mp3'])) {
  664. $audio = $_FILES['mp3'];
  665. }
  666. $description = isset($_POST['description']) ? $_POST['description'] : '';
  667. $prerequisites = isset($_POST['prerequisites']) ? $_POST['prerequisites'] : '';
  668. $maxTimeAllowed = isset($_POST['maxTimeAllowed']) ? $_POST['maxTimeAllowed'] : '';
  669. $url = isset($_POST['url']) ? $_POST['url'] : '';
  670. $_SESSION['oLP']->edit_item(
  671. $_REQUEST['id'],
  672. $_POST['parent'],
  673. $_POST['previous'],
  674. $post_title,
  675. $description,
  676. $prerequisites,
  677. $audio,
  678. $maxTimeAllowed,
  679. $url
  680. );
  681. if (isset($_POST['content_lp'])) {
  682. $_SESSION['oLP']->edit_document($_course);
  683. }
  684. $is_success = true;
  685. Display::addFlash(Display::return_message(get_lang('Updated')));
  686. $url = api_get_self().'?action=add_item&type=step&lp_id='.intval($_SESSION['oLP']->lp_id).'&'.api_get_cidreq();
  687. header('Location: '.$url);
  688. exit;
  689. }
  690. if (isset($_GET['view']) && $_GET['view'] == 'build') {
  691. require 'lp_edit_item.php';
  692. } else {
  693. require 'lp_admin_view.php';
  694. }
  695. }
  696. break;
  697. case 'edit_item_prereq':
  698. if (!$is_allowed_to_edit) {
  699. api_not_allowed(true);
  700. }
  701. if (!$lp_found) {
  702. require 'lp_list.php';
  703. } else {
  704. if (isset($_POST['submit_button'])) {
  705. // Updating the lp.modified_on
  706. $_SESSION['oLP']->set_modified_on();
  707. Session::write('refresh', 1);
  708. $min = isset($_POST['min_'.$_POST['prerequisites']]) ? $_POST['min_'.$_POST['prerequisites']] : '';
  709. $max = isset($_POST['max_'.$_POST['prerequisites']]) ? $_POST['max_'.$_POST['prerequisites']] : '';
  710. $editPrerequisite = $_SESSION['oLP']->edit_item_prereq(
  711. $_GET['id'],
  712. $_POST['prerequisites'],
  713. $min,
  714. $max
  715. );
  716. if ($editPrerequisite) {
  717. $is_success = true;
  718. }
  719. Display::addFlash(Display::return_message(get_lang('Updated')));
  720. $url = api_get_self().'?action=add_item&type=step&lp_id='.intval($_SESSION['oLP']->lp_id).'&'.api_get_cidreq();
  721. header('Location: '.$url);
  722. exit;
  723. } else {
  724. require 'lp_edit_item_prereq.php';
  725. }
  726. }
  727. break;
  728. case 'move_item':
  729. if (!$is_allowed_to_edit) {
  730. api_not_allowed(true);
  731. }
  732. if (!$lp_found) {
  733. require 'lp_list.php';
  734. } else {
  735. Session::write('refresh', 1);
  736. if (isset($_POST['submit_button'])) {
  737. //Updating the lp.modified_on
  738. $_SESSION['oLP']->set_modified_on();
  739. $_SESSION['oLP']->edit_item(
  740. $_GET['id'],
  741. $_POST['parent'],
  742. $_POST['previous'],
  743. $post_title,
  744. $_POST['description']
  745. );
  746. $is_success = true;
  747. $url = api_get_self().'?action=add_item&type=step&lp_id='.intval($_SESSION['oLP']->lp_id).'&'.api_get_cidreq();
  748. header('Location: '.$url);
  749. exit;
  750. }
  751. if (isset($_GET['view']) && $_GET['view'] == 'build') {
  752. require 'lp_move_item.php';
  753. } else {
  754. // Avoids weird behaviours see CT#967.
  755. $check = Security::check_token('get');
  756. if ($check) {
  757. $_SESSION['oLP']->move_item($_GET['id'], $_GET['direction']);
  758. }
  759. Security::clear_token();
  760. require 'lp_admin_view.php';
  761. }
  762. }
  763. break;
  764. case 'view_item':
  765. if (!$is_allowed_to_edit) {
  766. api_not_allowed(true);
  767. }
  768. if (!$lp_found) {
  769. require 'lp_list.php';
  770. } else {
  771. Session::write('refresh', 1);
  772. require 'lp_view_item.php';
  773. }
  774. break;
  775. case 'upload':
  776. if (!$is_allowed_to_edit) {
  777. api_not_allowed(true);
  778. }
  779. $cwdir = getcwd();
  780. require 'lp_upload.php';
  781. // Reinit current working directory as many functions in upload change it.
  782. chdir($cwdir);
  783. require 'lp_list.php';
  784. break;
  785. case 'copy':
  786. if (!$is_allowed_to_edit) {
  787. api_not_allowed(true);
  788. }
  789. $hideScormCopyLink = api_get_setting('hide_scorm_copy_link');
  790. if ($hideScormCopyLink === 'true') {
  791. api_not_allowed(true);
  792. }
  793. if (!$lp_found) {
  794. require 'lp_list.php';
  795. } else {
  796. $_SESSION['oLP']->copy();
  797. }
  798. require 'lp_list.php';
  799. break;
  800. case 'export':
  801. if (!$is_allowed_to_edit) {
  802. api_not_allowed(true);
  803. }
  804. $hideScormExportLink = api_get_setting('hide_scorm_export_link');
  805. if ($hideScormExportLink === 'true') {
  806. api_not_allowed(true);
  807. }
  808. if (!$lp_found) {
  809. require 'lp_list.php';
  810. } else {
  811. $_SESSION['oLP']->scormExport();
  812. exit();
  813. }
  814. break;
  815. case 'export_to_pdf':
  816. $hideScormPdfLink = api_get_setting('hide_scorm_pdf_link');
  817. if ($hideScormPdfLink === 'true') {
  818. api_not_allowed(true);
  819. }
  820. // Teachers can export to PDF
  821. if (!$is_allowed_to_edit) {
  822. if (!learnpath::is_lp_visible_for_student($_SESSION['oLP']->lp_id, api_get_user_id())) {
  823. api_not_allowed();
  824. }
  825. }
  826. if (!$lp_found) {
  827. require 'lp_list.php';
  828. } else {
  829. $result = $_SESSION['oLP']->scorm_export_to_pdf($_GET['lp_id']);
  830. if (!$result) {
  831. require 'lp_list.php';
  832. }
  833. exit;
  834. }
  835. break;
  836. case 'export_to_course_build':
  837. $allowExport = api_get_configuration_value('allow_lp_chamilo_export');
  838. if (api_is_allowed_to_edit() && $allowExport) {
  839. if (!$lp_found) {
  840. require 'lp_list.php';
  841. } else {
  842. $result = $_SESSION['oLP']->exportToCourseBuildFormat($_GET['lp_id']);
  843. if (!$result) {
  844. require 'lp_list.php';
  845. }
  846. exit;
  847. }
  848. }
  849. require 'lp_list.php';
  850. break;
  851. case 'delete':
  852. if (!$is_allowed_to_edit) {
  853. api_not_allowed(true);
  854. }
  855. if (!$lp_found) {
  856. require 'lp_list.php';
  857. } else {
  858. Session::write('refresh', 1);
  859. $_SESSION['oLP']->delete(null, $_GET['lp_id'], 'remove');
  860. Skill::deleteSkillsFromItem($_GET['lp_id'], ITEM_TYPE_LEARNPATH);
  861. Display::addFlash(Display::return_message(get_lang('Deleted')));
  862. Session::erase('oLP');
  863. require 'lp_list.php';
  864. }
  865. break;
  866. case 'toggle_category_visibility':
  867. if (!$is_allowed_to_edit) {
  868. api_not_allowed(true);
  869. }
  870. learnpath::toggleCategoryVisibility($_REQUEST['id'], $_REQUEST['new_status']);
  871. Display::addFlash(Display::return_message(get_lang('Updated')));
  872. header('Location: '.api_get_self().'?'.api_get_cidreq());
  873. exit;
  874. case 'toggle_visible':
  875. // Change lp visibility (inside lp tool).
  876. if (!$is_allowed_to_edit) {
  877. api_not_allowed(true);
  878. }
  879. if (!$lp_found) {
  880. require 'lp_list.php';
  881. } else {
  882. learnpath::toggle_visibility($_REQUEST['lp_id'], $_REQUEST['new_status']);
  883. Display::addFlash(Display::return_message(get_lang('Updated')));
  884. require 'lp_list.php';
  885. }
  886. break;
  887. case 'toggle_category_publish':
  888. if (!$is_allowed_to_edit) {
  889. api_not_allowed(true);
  890. }
  891. learnpath::toggleCategoryPublish($_REQUEST['id'], $_REQUEST['new_status']);
  892. Display::addFlash(Display::return_message(get_lang('Updated')));
  893. require 'lp_list.php';
  894. break;
  895. case 'toggle_publish':
  896. // Change lp published status (visibility on homepage).
  897. if (!$is_allowed_to_edit) {
  898. api_not_allowed(true);
  899. }
  900. if (!$lp_found) {
  901. require 'lp_list.php';
  902. } else {
  903. learnpath::toggle_publish($_REQUEST['lp_id'], $_REQUEST['new_status']);
  904. Display::addFlash(Display::return_message(get_lang('Updated')));
  905. require 'lp_list.php';
  906. }
  907. break;
  908. case 'move_lp_up':
  909. // Change lp published status (visibility on homepage)
  910. if (!$is_allowed_to_edit) {
  911. api_not_allowed(true);
  912. }
  913. if (!$lp_found) {
  914. require 'lp_list.php';
  915. } else {
  916. learnpath::move_up($_REQUEST['lp_id'], $_REQUEST['category_id']);
  917. Display::addFlash(Display::return_message(get_lang('Updated')));
  918. require 'lp_list.php';
  919. }
  920. break;
  921. case 'move_lp_down':
  922. // Change lp published status (visibility on homepage)
  923. if (!$is_allowed_to_edit) {
  924. api_not_allowed(true);
  925. }
  926. if (!$lp_found) {
  927. require 'lp_list.php';
  928. } else {
  929. learnpath::move_down($_REQUEST['lp_id'], $_REQUEST['category_id']);
  930. Display::addFlash(Display::return_message(get_lang('Updated')));
  931. require 'lp_list.php';
  932. }
  933. break;
  934. case 'edit':
  935. if (!$is_allowed_to_edit) {
  936. api_not_allowed(true);
  937. }
  938. if (!$lp_found) {
  939. require 'lp_list.php';
  940. } else {
  941. Session::write('refresh', 1);
  942. require 'lp_edit.php';
  943. }
  944. break;
  945. case 'update_lp':
  946. if (!$is_allowed_to_edit) {
  947. api_not_allowed(true);
  948. }
  949. if (!$lp_found) {
  950. require 'lp_list.php';
  951. } else {
  952. Session::write('refresh', 1);
  953. $lp_name = Security::remove_XSS($_REQUEST['lp_name']);
  954. $_SESSION['oLP']->set_name($lp_name);
  955. $author = $_REQUEST['lp_author'];
  956. // Fixing the author name (no body or html tags).
  957. $auth_init = stripos($author, '<p>');
  958. if ($auth_init === false) {
  959. $auth_init = stripos($author, '<body>');
  960. $auth_end = $auth_init + stripos(substr($author, $auth_init + 6), '</body>') + 7;
  961. $len = $auth_end - $auth_init + 6;
  962. } else {
  963. $auth_end = strripos($author, '</p>');
  964. $len = $auth_end - $auth_init + 4;
  965. }
  966. $author_fixed = substr($author, $auth_init, $len);
  967. $_SESSION['oLP']->set_author($author_fixed);
  968. // TODO (as of Chamilo 1.8.8): Check in the future whether this field is needed.
  969. $_SESSION['oLP']->set_encoding($_REQUEST['lp_encoding']);
  970. if (isset($_REQUEST['lp_maker'])) {
  971. $_SESSION['oLP']->set_maker($_REQUEST['lp_maker']);
  972. }
  973. if (isset($_REQUEST['lp_proximity'])) {
  974. $_SESSION['oLP']->set_proximity($_REQUEST['lp_proximity']);
  975. }
  976. $_SESSION['oLP']->set_theme($_REQUEST['lp_theme']);
  977. if (isset($_REQUEST['hide_toc_frame']) && $_REQUEST['hide_toc_frame'] == 1) {
  978. $hide_toc_frame = $_REQUEST['hide_toc_frame'];
  979. } else {
  980. $hide_toc_frame = null;
  981. }
  982. $_SESSION['oLP']->set_hide_toc_frame($hide_toc_frame);
  983. $_SESSION['oLP']->set_prerequisite(isset($_POST['prerequisites']) ? (int) $_POST['prerequisites'] : 0);
  984. $_SESSION['oLP']->setAccumulateWorkTime(isset($_REQUEST['accumulate_work_time']) ? $_REQUEST['accumulate_work_time'] : 0);
  985. $_SESSION['oLP']->set_use_max_score(isset($_POST['use_max_score']) ? 1 : 0);
  986. $subscribeUsers = isset($_REQUEST['subscribe_users']) ? 1 : 0;
  987. $_SESSION['oLP']->setSubscribeUsers($subscribeUsers);
  988. $accumulateScormTime = isset($_REQUEST['accumulate_scorm_time']) ? $_REQUEST['accumulate_scorm_time'] : 'true';
  989. $_SESSION['oLP']->setAccumulateScormTime($accumulateScormTime);
  990. if (isset($_REQUEST['activate_start_date_check']) && $_REQUEST['activate_start_date_check'] == 1) {
  991. $publicated_on = $_REQUEST['publicated_on'];
  992. } else {
  993. $publicated_on = null;
  994. }
  995. if (isset($_REQUEST['activate_end_date_check']) && $_REQUEST['activate_end_date_check'] == 1) {
  996. $expired_on = $_REQUEST['expired_on'];
  997. } else {
  998. $expired_on = null;
  999. }
  1000. $_SESSION['oLP']->setCategoryId($_REQUEST['category_id']);
  1001. $_SESSION['oLP']->set_modified_on();
  1002. $_SESSION['oLP']->set_publicated_on($publicated_on);
  1003. $_SESSION['oLP']->set_expired_on($expired_on);
  1004. if (isset($_REQUEST['remove_picture']) && $_REQUEST['remove_picture']) {
  1005. $_SESSION['oLP']->delete_lp_image();
  1006. }
  1007. $extraFieldValue = new ExtraFieldValue('lp');
  1008. $_REQUEST['item_id'] = $_SESSION['oLP']->lp_id;
  1009. $extraFieldValue->saveFieldValues($_REQUEST);
  1010. if ($_FILES['lp_preview_image']['size'] > 0) {
  1011. $_SESSION['oLP']->upload_image($_FILES['lp_preview_image']);
  1012. }
  1013. $form = new FormValidator('form1');
  1014. $form->addSelect('skills', 'skills');
  1015. Skill::saveSkills($form, ITEM_TYPE_LEARNPATH, $_SESSION['oLP']->get_id());
  1016. if (api_get_setting('search_enabled') === 'true') {
  1017. require_once api_get_path(LIBRARY_PATH).'specific_fields_manager.lib.php';
  1018. $specific_fields = get_specific_field_list();
  1019. foreach ($specific_fields as $specific_field) {
  1020. $_SESSION['oLP']->set_terms_by_prefix($_REQUEST[$specific_field['code']], $specific_field['code']);
  1021. $new_values = explode(',', trim($_REQUEST[$specific_field['code']]));
  1022. if (!empty($new_values)) {
  1023. array_walk($new_values, 'trim');
  1024. delete_all_specific_field_value(
  1025. api_get_course_id(),
  1026. $specific_field['id'],
  1027. TOOL_LEARNPATH,
  1028. $_SESSION['oLP']->lp_id
  1029. );
  1030. foreach ($new_values as $value) {
  1031. if (!empty($value)) {
  1032. add_specific_field_value(
  1033. $specific_field['id'],
  1034. api_get_course_id(),
  1035. TOOL_LEARNPATH,
  1036. $_SESSION['oLP']->lp_id,
  1037. $value
  1038. );
  1039. }
  1040. }
  1041. }
  1042. }
  1043. }
  1044. Display::addFlash(Display::return_message(get_lang('Updated')));
  1045. $url = api_get_self().'?action=add_item&type=step&lp_id='.intval($_SESSION['oLP']->lp_id).'&'.api_get_cidreq();
  1046. header('Location: '.$url);
  1047. exit;
  1048. }
  1049. break;
  1050. case 'add_sub_item':
  1051. // Add an item inside a dir/chapter.
  1052. // @todo check if this is @deprecated
  1053. if (!$is_allowed_to_edit) {
  1054. api_not_allowed(true);
  1055. }
  1056. if (!$lp_found) {
  1057. require 'lp_list.php';
  1058. } else {
  1059. Session::write('refresh', 1);
  1060. if (!empty($_REQUEST['parent_item_id'])) {
  1061. $_SESSION['from_learnpath'] = 'yes';
  1062. $_SESSION['origintoolurl'] = 'lp_controller.php?action=admin_view&lp_id='.intval($_REQUEST['lp_id']);
  1063. } else {
  1064. require 'lp_admin_view.php';
  1065. }
  1066. }
  1067. break;
  1068. case 'deleteitem':
  1069. case 'delete_item':
  1070. if (!$is_allowed_to_edit) {
  1071. api_not_allowed(true);
  1072. }
  1073. if (!$lp_found) {
  1074. require 'lp_list.php';
  1075. } else {
  1076. if (!empty($_REQUEST['id'])) {
  1077. $_SESSION['oLP']->delete_item($_REQUEST['id']);
  1078. }
  1079. $url = api_get_self().'?action=add_item&type=step&lp_id='.intval($_REQUEST['lp_id']).'&'.api_get_cidreq();
  1080. header('Location: '.$url);
  1081. exit;
  1082. }
  1083. break;
  1084. case 'restart':
  1085. if (!$lp_found) {
  1086. require 'lp_list.php';
  1087. } else {
  1088. $_SESSION['oLP']->restart();
  1089. require 'lp_view.php';
  1090. }
  1091. break;
  1092. case 'last':
  1093. if (!$lp_found) {
  1094. require 'lp_list.php';
  1095. } else {
  1096. $_SESSION['oLP']->last();
  1097. require 'lp_view.php';
  1098. }
  1099. break;
  1100. case 'first':
  1101. if (!$lp_found) {
  1102. require 'lp_list.php';
  1103. } else {
  1104. $_SESSION['oLP']->first();
  1105. require 'lp_view.php';
  1106. }
  1107. break;
  1108. case 'next':
  1109. if (!$lp_found) {
  1110. require 'lp_list.php';
  1111. } else {
  1112. $_SESSION['oLP']->next();
  1113. require 'lp_view.php';
  1114. }
  1115. break;
  1116. case 'previous':
  1117. if (!$lp_found) {
  1118. require 'lp_list.php';
  1119. } else {
  1120. $_SESSION['oLP']->previous();
  1121. require 'lp_view.php';
  1122. }
  1123. break;
  1124. case 'content':
  1125. if ($debug > 0) {
  1126. error_log('lp_controller: action: content');
  1127. error_log('Item id is '.intval($_GET['item_id']));
  1128. }
  1129. if (!$lp_found) {
  1130. require 'lp_list.php';
  1131. } else {
  1132. if ($debug > 0) {
  1133. error_log('save_last()');
  1134. }
  1135. $_SESSION['oLP']->save_last();
  1136. if ($debug > 0) {
  1137. error_log('set_current_item('.$_GET['item_id'].')');
  1138. }
  1139. $_SESSION['oLP']->set_current_item($_GET['item_id']);
  1140. if ($debug > 0) {
  1141. error_log('start_current_item()');
  1142. }
  1143. $_SESSION['oLP']->start_current_item();
  1144. require 'lp_content.php';
  1145. }
  1146. break;
  1147. case 'view':
  1148. if (!$lp_found) {
  1149. require 'lp_list.php';
  1150. } else {
  1151. if ($debug > 0) {
  1152. error_log('Trying to set current item to '.$_REQUEST['item_id'], 0);
  1153. }
  1154. if (!empty($_REQUEST['item_id'])) {
  1155. $_SESSION['oLP']->set_current_item($_REQUEST['item_id']);
  1156. }
  1157. require 'lp_view.php';
  1158. }
  1159. break;
  1160. case 'save':
  1161. if (!$lp_found) {
  1162. require 'lp_list.php';
  1163. } else {
  1164. $_SESSION['oLP']->save_item();
  1165. require 'lp_save.php';
  1166. }
  1167. break;
  1168. case 'stats':
  1169. if (!$lp_found) {
  1170. require 'lp_list.php';
  1171. } else {
  1172. $_SESSION['oLP']->save_current();
  1173. $_SESSION['oLP']->save_last();
  1174. $output = require 'lp_stats.php';
  1175. echo $output;
  1176. }
  1177. break;
  1178. case 'list':
  1179. if ($lp_found) {
  1180. Session::write('refresh', 1);
  1181. $_SESSION['oLP']->save_last();
  1182. }
  1183. require 'lp_list.php';
  1184. break;
  1185. case 'mode':
  1186. // Switch between fullscreen and embedded mode.
  1187. $mode = $_REQUEST['mode'];
  1188. if ($mode == 'fullscreen') {
  1189. $_SESSION['oLP']->mode = 'fullscreen';
  1190. } elseif ($mode == 'embedded') {
  1191. $_SESSION['oLP']->mode = 'embedded';
  1192. } elseif ($mode == 'embedframe') {
  1193. $_SESSION['oLP']->mode = 'embedframe';
  1194. } elseif ($mode == 'impress') {
  1195. $_SESSION['oLP']->mode = 'impress';
  1196. }
  1197. require 'lp_view.php';
  1198. break;
  1199. case 'switch_view_mode':
  1200. if (!$lp_found) {
  1201. require 'lp_list.php';
  1202. }
  1203. if (Security::check_token('get')) {
  1204. Session::write('refresh', 1);
  1205. $_SESSION['oLP']->update_default_view_mode();
  1206. }
  1207. require 'lp_list.php';
  1208. break;
  1209. case 'switch_force_commit':
  1210. if (!$lp_found) {
  1211. require 'lp_list.php';
  1212. }
  1213. Session::write('refresh', 1);
  1214. $_SESSION['oLP']->update_default_scorm_commit();
  1215. require 'lp_list.php';
  1216. break;
  1217. case 'switch_attempt_mode':
  1218. if (!$lp_found) {
  1219. require 'lp_list.php';
  1220. }
  1221. Session::write('refresh', 1);
  1222. $_SESSION['oLP']->switch_attempt_mode();
  1223. require 'lp_list.php';
  1224. break;
  1225. case 'switch_scorm_debug':
  1226. if (!$lp_found) {
  1227. require 'lp_list.php';
  1228. }
  1229. Session::write('refresh', 1);
  1230. $_SESSION['oLP']->update_scorm_debug();
  1231. require 'lp_list.php';
  1232. break;
  1233. case 'intro_cmdAdd':
  1234. // Add introduction section page.
  1235. break;
  1236. case 'return_to_course_homepage':
  1237. if (!$lp_found) {
  1238. require 'lp_list.php';
  1239. } else {
  1240. $_SESSION['oLP']->save_current();
  1241. $_SESSION['oLP']->save_last();
  1242. if ($debug > 0) {
  1243. error_log('save_current()');
  1244. error_log('save_last()');
  1245. }
  1246. $url = api_get_path(WEB_COURSE_PATH).api_get_course_path().'/index.php?id_session='.api_get_session_id();
  1247. $redirectTo = isset($_GET['redirectTo']) ? $_GET['redirectTo'] : '';
  1248. switch ($redirectTo) {
  1249. case 'lp_list':
  1250. $url = 'lp_controller.php?'.api_get_cidreq();
  1251. break;
  1252. case 'my_courses':
  1253. $url = api_get_path(WEB_PATH).'user_portal.php';
  1254. break;
  1255. }
  1256. header('location: '.$url);
  1257. exit;
  1258. }
  1259. break;
  1260. case 'search':
  1261. /* Include the search script, it's smart enough to know when we are
  1262. * searching or not.
  1263. */
  1264. require 'lp_list_search.php';
  1265. break;
  1266. case 'impress':
  1267. if (!$lp_found) {
  1268. require 'lp_list.php';
  1269. } else {
  1270. if ($debug > 0) {
  1271. error_log('Trying to impress this LP item to '.$_REQUEST['item_id'], 0);
  1272. }
  1273. if (!empty($_REQUEST['item_id'])) {
  1274. $_SESSION['oLP']->set_current_item($_REQUEST['item_id']);
  1275. }
  1276. require 'lp_impress.php';
  1277. }
  1278. break;
  1279. case 'set_previous_step_as_prerequisite':
  1280. $_SESSION['oLP']->set_previous_step_as_prerequisite_for_all_items();
  1281. $url = api_get_self().'?action=add_item&type=step&lp_id='.intval($_SESSION['oLP']->lp_id)."&".api_get_cidreq();
  1282. Display::addFlash(Display::return_message(get_lang('ItemUpdated')));
  1283. header('Location: '.$url);
  1284. exit;
  1285. break;
  1286. case 'clear_prerequisites':
  1287. $_SESSION['oLP']->clear_prerequisites();
  1288. $url = api_get_self().'?action=add_item&type=step&lp_id='.intval($_SESSION['oLP']->lp_id)."&".api_get_cidreq();
  1289. Display::addFlash(Display::return_message(get_lang('ItemUpdated')));
  1290. header('Location: '.$url);
  1291. exit;
  1292. break;
  1293. case 'toggle_seriousgame':
  1294. // activate/deactive seriousgame_mode
  1295. if (!$is_allowed_to_edit) {
  1296. api_not_allowed(true);
  1297. }
  1298. if (!$lp_found) {
  1299. require 'lp_list.php';
  1300. }
  1301. Session::write('refresh', 1);
  1302. $_SESSION['oLP']->set_seriousgame_mode();
  1303. require 'lp_list.php';
  1304. break;
  1305. case 'create_forum':
  1306. if (!isset($_GET['id'])) {
  1307. break;
  1308. }
  1309. $selectedItem = null;
  1310. foreach ($_SESSION['oLP']->items as $item) {
  1311. if ($item->db_id == $_GET['id']) {
  1312. $selectedItem = $item;
  1313. }
  1314. }
  1315. if (!empty($selectedItem)) {
  1316. $forumThread = $selectedItem->getForumThread(
  1317. $_SESSION['oLP']->course_int_id,
  1318. $_SESSION['oLP']->lp_session_id
  1319. );
  1320. if (empty($forumThread)) {
  1321. require '../forum/forumfunction.inc.php';
  1322. $forumCategory = getForumCategoryByTitle(
  1323. get_lang('LearningPaths'),
  1324. $_SESSION['oLP']->course_int_id,
  1325. $_SESSION['oLP']->lp_session_id
  1326. );
  1327. $forumCategoryId = !empty($forumCategory) ? $forumCategory['cat_id'] : 0;
  1328. if (empty($forumCategoryId)) {
  1329. $forumCategoryId = store_forumcategory(
  1330. [
  1331. 'lp_id' => 0,
  1332. 'forum_category_title' => get_lang('LearningPaths'),
  1333. 'forum_category_comment' => null,
  1334. ],
  1335. [],
  1336. false
  1337. );
  1338. }
  1339. if (!empty($forumCategoryId)) {
  1340. $forum = $_SESSION['oLP']->getForum(
  1341. $_SESSION['oLP']->lp_session_id
  1342. );
  1343. $forumId = !empty($forum) ? $forum['forum_id'] : 0;
  1344. if (empty($forumId)) {
  1345. $forumId = $_SESSION['oLP']->createForum($forumCategoryId);
  1346. }
  1347. if (!empty($forumId)) {
  1348. $selectedItem->createForumThread($forumId);
  1349. }
  1350. }
  1351. }
  1352. }
  1353. header('Location:'.api_get_self().'?'.http_build_query([
  1354. 'action' => 'add_item',
  1355. 'type' => 'step',
  1356. 'lp_id' => $_SESSION['oLP']->lp_id,
  1357. ]));
  1358. exit;
  1359. break;
  1360. case 'report':
  1361. require 'lp_report.php';
  1362. break;
  1363. case 'dissociate_forum':
  1364. if (!isset($_GET['id'])) {
  1365. break;
  1366. }
  1367. $selectedItem = null;
  1368. foreach ($_SESSION['oLP']->items as $item) {
  1369. if ($item->db_id != $_GET['id']) {
  1370. continue;
  1371. }
  1372. $selectedItem = $item;
  1373. }
  1374. if (!empty($selectedItem)) {
  1375. $forumThread = $selectedItem->getForumThread(
  1376. $_SESSION['oLP']->course_int_id,
  1377. $_SESSION['oLP']->lp_session_id
  1378. );
  1379. if (!empty($forumThread)) {
  1380. $dissociated = $selectedItem->dissociateForumThread($forumThread['iid']);
  1381. if ($dissociated) {
  1382. Display::addFlash(
  1383. Display::return_message(get_lang('ForumDissociate'), 'success')
  1384. );
  1385. }
  1386. }
  1387. }
  1388. header('Location:'.api_get_self().'?'.http_build_query([
  1389. 'action' => 'add_item',
  1390. 'type' => 'step',
  1391. 'lp_id' => $_SESSION['oLP']->lp_id,
  1392. ]));
  1393. exit;
  1394. break;
  1395. case 'add_final_item':
  1396. if (!$lp_found) {
  1397. Display::addFlash(
  1398. Display::return_message(get_lang('NoLPFound'), 'error')
  1399. );
  1400. break;
  1401. }
  1402. Session::write('refresh', 1);
  1403. if (!isset($_POST['submit']) || empty($post_title)) {
  1404. break;
  1405. }
  1406. $_SESSION['oLP']->getFinalItemForm();
  1407. $redirectTo = api_get_self().'?'.api_get_cidreq().'&'.http_build_query([
  1408. 'action' => 'add_item',
  1409. 'type' => 'step',
  1410. 'lp_id' => intval($_SESSION['oLP']->lp_id),
  1411. ]);
  1412. break;
  1413. default:
  1414. require 'lp_list.php';
  1415. break;
  1416. }
  1417. if (!empty($_SESSION['oLP'])) {
  1418. $_SESSION['lpobject'] = serialize($_SESSION['oLP']);
  1419. if ($debug > 0) {
  1420. error_log('lpobject is serialized in session', 0);
  1421. }
  1422. }
  1423. if (!empty($redirectTo)) {
  1424. header("Location: $redirectTo");
  1425. exit;
  1426. }