123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653 |
- <?php
- /* For licensing terms, see /license.txt */
- use ChamiloSession as Session;
- /**
- * Controller script. Prepares the common background variables to give to the scripts corresponding to
- * the requested action.
- *
- * @todo remove repeated if $lp_found redirect
- *
- * @package chamilo.learnpath
- *
- * @author Yannick Warnier <ywarnier@beeznest.org>
- */
- // Flag to allow for anonymous user - needs to be set before global.inc.php.
- $use_anonymous = true;
- $debug = 0;
- require_once __DIR__.'/../inc/global.inc.php';
- api_protect_course_script(true);
- $current_course_tool = TOOL_LEARNPATH;
- $_course = api_get_course_info();
- $glossaryExtraTools = api_get_setting('show_glossary_in_extra_tools');
- $showGlossary = in_array($glossaryExtraTools, ['true', 'lp', 'exercise_and_lp']);
- if ($showGlossary) {
- if (api_get_setting('show_glossary_in_documents') === 'ismanual' ||
- api_get_setting('show_glossary_in_documents') === 'isautomatic'
- ) {
- $htmlHeadXtra[] = '<script>
- <!--
- var jQueryFrameReadyConfigPath = \''.api_get_jquery_web_path().'\';
- -->
- </script>';
- $htmlHeadXtra[] = '<script src="'.api_get_path(WEB_LIBRARY_PATH).'javascript/jquery.frameready.js" type="text/javascript" language="javascript"></script>';
- $htmlHeadXtra[] = '<script src="'.api_get_path(WEB_LIBRARY_PATH).'javascript/jquery.highlight.js" type="text/javascript" language="javascript"></script>';
- }
- }
- $htmlHeadXtra[] = '<script>
- function setFocus(){
- $("#idTitle").focus();
- }
- $(window).on("load", function () {
- setFocus();
- });
- </script>';
- $ajax_url = api_get_path(WEB_AJAX_PATH).'lp.ajax.php?'.api_get_cidreq();
- $htmlHeadXtra[] = '
- <script>
- /*
- Script to manipulate Learning Path items with Drag and drop
- */
- var newOrderData = "";
- function buildLPtree(in_elem, in_parent_id) {
- var item_tag = in_elem.get(0).tagName;
- var item_id = in_elem.attr("id");
- var parent_id = item_id;
- if (item_tag == "LI" && item_id != undefined) {
- // in_parent_id de la forme UL_x
- newOrderData += item_id+"|"+get_UL_integer_id(in_parent_id)+"^";
- }
- in_elem.children().each(function () {
- buildLPtree($(this), parent_id);
- });
- }
- // return the interge part of an UL id
- // (0 for lp_item_list)
- function get_UL_integer_id(in_ul_id) {
- in_parent_integer_id = in_ul_id;
- in_parent_integer_id = in_parent_integer_id.replace("lp_item_list", "0");
- in_parent_integer_id = in_parent_integer_id.replace("UL_", "");
- return in_parent_integer_id;
- }
- $(function() {
- $(".lp_resource").sortable({
- items: ".lp_resource_element ",
- handle: ".moved", //only the class "moved"
- cursor: "move",
- connectWith: "#lp_item_list",
- placeholder: "ui-state-highlight", //defines the yellow highlight
- start: function(event, ui) {
- $(ui.item).css("width", "350px");
- $(ui.item).find(".item_data").attr("style", "");
- },
- stop: function(event, ui) {
- $(ui.item).css("width", "100%");
- }
- });
-
- $(".li_container .order_items").click(function(e) {
- var dir = $(this).data("dir");
- var itemId = $(this).data("id");
- var jItems = $("#lp_item_list li.li_container");
- var jItem = $("#"+ itemId);
- var index = jItems.index(jItem);
- var total = jItems.length;
-
- switch (dir) {
- case "up":
- if (index != 0 && jItems[index - 1]) {
- /*var subItems = $(jItems[index - 1]).find("li.sub_item");
- if (subItems.length >= 0) {
- index = index - 1;
- }*/
- var subItems = $(jItems[index - 1]).find("li.sub_item");
- var parentClass = $(jItems[index - 1]).parent().parent().attr("class");
- var parentId = $(jItems[index]).parent().parent().attr("id");
- var myParentId = $(jItems[index - 1]).parent().parent().attr("id");
- //console.log(parentId + " - " + myParentId);
-
- // We are brothers!
- if (parentId == myParentId) {
- console.log("Brothers");
- console.log(subItems.length);
- if (subItems.length > 0) {
- var lastItem = $(jItems[index - 1]).find("li.sub_item");
- parentIndex = jItems.index(lastItem);
- console.log(parentIndex);
- jItem.detach().insertAfter(lastItem);
- //console.log("not classic");
- } else {
- //console.log("classic");
- jItem.detach().insertBefore(jItems[index - 1]);
- }
- break;
- }
-
- //console.log(parentClass);
- if (parentClass == "record li_container") {
- // previous is a chapter
- var lastItem = $(jItems[index - 1]).parent().parent().find("li.li_container").last();
- parentIndex = jItems.index(lastItem);
- //console.log(parentIndex);
- jItem.detach().insertAfter(jItems[parentIndex]);
- } else {
- jItem.detach().insertBefore(jItems[index - 1]);
- }
- }
- break;
- case "down":
- if (index != total - 1) {
- const originIndex = index;
- // The element is a chapter with items
- var subItems = jItem.find("li.li_container");
- if (subItems.length > 0) {
- index = subItems.length + index;
- //console.log("element is a chapter with items");
- //console.log("new index = " + index);
- }
-
- var subItems = $(jItems[index + 1]).find("li.sub_item");
- //console.log("next subItems.length: "+subItems.length);
- // This is an element entering in a chapter
- if (subItems.length > 0) {
- // Check if im a child
- var parentClass = jItem.parent().parent().attr("class");
- //console.log(parentClass);
- if (parentClass == "record li_container") {
- // Parent position
- var parentIndex = jItems.index(jItem.parent().parent());
- //console.log(jItem.parent().parent().attr("id"));
- //console.log(parentIndex);
- jItem.detach().insertAfter(jItems[parentIndex]);
- } else {
- jItem.detach().insertAfter(subItems);
- }
- break;
- }
-
- var currentSubItems = $(jItems[index]).parent().find("li.sub_item");
- //console.log("currentSubItems"+currentSubItems.length);
-
- var parentId = $(jItems[originIndex]).parent().parent().attr("id");
- var myParentId = $(jItems[index + 1]).parent().parent().attr("id");
- //console.log("parent ids: "+ parentId + " - " + myParentId);
-
- // We are brothers!
- if (parentId == myParentId) {
- if ((index + 1) < total) {
- //console.log(index + 1);
- //console.log("We are brothers");
- jItem.detach().insertAfter(jItems[index + 1]);
- }
- break;
- }
-
- if (currentSubItems.length > 0) {
- var parentIndex = jItems.index(jItem.parent().parent());
- //console.log("has currentSubItems");
- //console.log("id " + jItem.parent().parent().attr("id"));
- //console.log("parentIndex: " + parentIndex);
- if (parentIndex >= 0) {
- jItem.detach().insertAfter(jItems[parentIndex]);
- break;
- }
- //jItem.detach().insertAfter($(jItems[index]).parent().parent());
- }
-
- //var lastItem = $(jItems[index + 1]).parent().parent().find("li.li_container").last();
- if (subItems.length > 0) {
- index = originIndex;
- }
-
- if ((index + 1) < total) {
- //console.log(index + 1);
- //console.log("changed");
- jItem.detach().insertAfter(jItems[index + 1]);
- }
- }
- break;
- }
-
- //console.log("rebuild");
- buildLPtree($("#lp_item_list"), 0);
-
- var order = "new_order="+ newOrderData + "&a=update_lp_item_order";
- $.post(
- "'.$ajax_url.'",
- order,
- function(reponse) {
- $("#message").html(reponse);
- order = "";
- newOrderData = "";
- }
- );
- });
- $("#lp_item_list").sortable({
- items: "li",
- handle: ".moved", //only the class "moved"
- cursor: "move",
- placeholder: "ui-state-highlight", //defines the yellow highlight
- update: function(event, ui) {
- buildLPtree($("#lp_item_list"), 0);
- var order = "new_order="+ newOrderData + "&a=update_lp_item_order";
- $.post(
- "'.$ajax_url.'",
- order,
- function(reponse) {
- $("#message").html(reponse);
- order = "";
- newOrderData = "";
- }
- );
- },
- receive: function(event, ui) {
- var id = $(ui.item).attr("data_id");
- var type = $(ui.item).attr("data_type");
- var title = $(ui.item).attr("title");
- processReceive = true;
- if (ui.item.parent()[0]) {
- var parent_id = $(ui.item.parent()[0]).attr("id");
- var previous_id = $(ui.item.prev()).attr("id");
- if (parent_id) {
- parent_id = parent_id.split("_")[1];
- var params = {
- "a": "add_lp_item",
- "id": id,
- "parent_id": parent_id,
- "previous_id": previous_id,
- "type": type,
- "title" : title
- };
-
- $.ajax({
- type: "GET",
- url: "'.$ajax_url.'",
- data: params,
- async: false,
- success: function(data) {
- $("#lp_item_list").html(data);
- }
- });
- }
- }
- } // End receive
- });
- processReceive = false;
- });
- </script>';
- $session_id = api_get_session_id();
- $lpfound = false;
- $myrefresh = 0;
- $myrefresh_id = 0;
- $refresh = Session::read('refresh');
- if ($refresh == 1) {
- // Check if we should do a refresh of the oLP object (for example after editing the LP).
- // If refresh is set, we regenerate the oLP object from the database (kind of flush).
- Session::erase('refresh');
- $myrefresh = 1;
- }
- if ($debug > 0) {
- error_log(' $refresh: '.$refresh);
- error_log(' $myrefresh: '.$myrefresh);
- }
- $lp_controller_touched = 1;
- $lp_found = false;
- $lpObject = Session::read('lpobject');
- if (!empty($lpObject)) {
- if ($debug) {
- error_log(' SESSION[lpobject] is defined');
- }
- /** @var learnpath $oLP */
- $oLP = UnserializeApi::unserialize('lp', $lpObject);
- if (isset($oLP) && is_object($oLP)) {
- if ($debug) {
- error_log(' oLP is object');
- }
- if ($myrefresh == 1 ||
- empty($oLP->cc) ||
- $oLP->cc != api_get_course_id() ||
- $oLP->lp_view_session_id != $session_id
- ) {
- if ($debug) {
- error_log('Course has changed, discard lp object');
- error_log('$oLP->lp_view_session_id: '.$oLP->lp_view_session_id);
- error_log('api_get_session_id(): '.$session_id);
- error_log('$oLP->cc: '.$oLP->cc);
- error_log('api_get_course_id(): '.api_get_course_id());
- }
- if ($myrefresh == 1) {
- $myrefresh_id = $oLP->get_id();
- }
- $oLP = null;
- Session::erase('oLP');
- Session::erase('lpobject');
- } else {
- Session::write('oLP', $oLP);
- $lp_found = true;
- }
- }
- }
- if ($debug) {
- error_log('$lp_found: '.$lp_found);
- error_log('$myrefresh_id: '.$myrefresh_id);
- }
- $course_id = api_get_course_int_id();
- if (!$lp_found || (!empty($_REQUEST['lp_id']) && $_SESSION['oLP']->get_id() != $_REQUEST['lp_id'])) {
- if ($debug > 0) {
- error_log(' oLP is not object, has changed or refresh been asked, getting new');
- }
- // Regenerate a new lp object? Not always as some pages don't need the object (like upload?)
- if (!empty($_REQUEST['lp_id']) || !empty($myrefresh_id)) {
- // Select the lp in the database and check which type it is (scorm/chamilo/aicc) to generate the
- // right object.
- if (!empty($_REQUEST['lp_id'])) {
- $lp_id = $_REQUEST['lp_id'];
- } else {
- $lp_id = $myrefresh_id;
- }
- $lp_id = (int) $lp_id;
- $lp_table = Database::get_course_table(TABLE_LP_MAIN);
- if (!empty($lp_id)) {
- $sel = "SELECT iid, lp_type FROM $lp_table WHERE c_id = $course_id AND id = $lp_id";
- if ($debug > 0) {
- error_log(' querying '.$sel);
- }
- $res = Database::query($sel);
- if (Database::num_rows($res)) {
- $row = Database::fetch_array($res);
- $lpIid = $row['iid'];
- $type = $row['lp_type'];
- if ($debug > 0) {
- error_log('Found row type '.$type);
- error_log('Calling constructor: '.api_get_course_id().' - '.$lp_id.' - '.api_get_user_id());
- }
- $logInfo = [
- 'tool' => TOOL_LEARNPATH,
- 'tool_id' => 0,
- 'tool_id_detail' => 0,
- 'action' => 'lp_load',
- ];
- Event::registerLog($logInfo);
- switch ($type) {
- case 1:
- $oLP = new learnpath(api_get_course_id(), $lpIid, api_get_user_id());
- if ($oLP !== false) {
- $lp_found = true;
- }
- break;
- case 2:
- $oLP = new scorm(api_get_course_id(), $lpIid, api_get_user_id());
- if ($oLP !== false) {
- $lp_found = true;
- }
- break;
- case 3:
- $oLP = new aicc(api_get_course_id(), $lpIid, api_get_user_id());
- if ($oLP !== false) {
- $lp_found = true;
- }
- break;
- default:
- $oLP = new learnpath(api_get_course_id(), $lpIid, api_get_user_id());
- if ($oLP !== false) {
- $lp_found = true;
- }
- break;
- }
- }
- } else {
- if ($debug > 0) {
- error_log(' Request[lp_id] is not numeric');
- }
- }
- } else {
- if ($debug > 0) {
- error_log(' Request[lp_id] and refresh_id were empty');
- }
- }
- if ($lp_found) {
- Session::write('oLP', $oLP);
- }
- }
- if ($debug > 0) {
- error_log('Passed oLP creation check');
- }
- $is_allowed_to_edit = api_is_allowed_to_edit(false, true, false, false);
- if (isset($_SESSION['oLP'])) {
- // Reinitialises array used by javascript to update items in the TOC.
- $_SESSION['oLP']->update_queue = [];
- }
- $action = !empty($_REQUEST['action']) ? $_REQUEST['action'] : '';
- if ($debug) {
- error_log('Entered lp_controller.php -+- (action: '.$action.')');
- }
- $eventLpId = $lp_id = !empty($_REQUEST['lp_id']) ? (int) $_REQUEST['lp_id'] : 0;
- if (empty($lp_id)) {
- if (isset($_SESSION['oLP'])) {
- $eventLpId = $_SESSION['oLP']->get_id();
- }
- }
- $lp_detail_id = 0;
- $attemptId = 0;
- switch ($action) {
- case '':
- case 'list':
- $eventLpId = 0;
- break;
- case 'view':
- case 'content':
- $lp_detail_id = $oLP->get_current_item_id();
- $attemptId = $oLP->getCurrentAttempt();
- break;
- default:
- $lp_detail_id = (!empty($_REQUEST['id']) ? (int) $_REQUEST['id'] : 0);
- break;
- }
- $logInfo = [
- 'tool' => TOOL_LEARNPATH,
- 'tool_id' => $eventLpId,
- 'tool_id_detail' => $lp_detail_id,
- 'action_details' => $attemptId,
- 'action' => !empty($action) ? $action : 'list',
- ];
- Event::registerLog($logInfo);
- // format title to be displayed correctly if QUIZ
- $post_title = '';
- if (isset($_POST['title'])) {
- $post_title = Security::remove_XSS($_POST['title']);
- if (isset($_POST['type']) &&
- isset($_POST['title']) &&
- $_POST['type'] == TOOL_QUIZ &&
- !empty($_POST['title'])
- ) {
- $post_title = Exercise::format_title_variable($_POST['title']);
- if (api_get_configuration_value('save_titles_as_html')) {
- $post_title = $_POST['title'];
- }
- }
- }
- $redirectTo = '';
- if ($debug > 0) {
- error_log('action "'.$action.'" triggered');
- }
- switch ($action) {
- case 'send_notify_teacher':
- // Send notification to the teacher
- $studentInfo = api_get_user_info();
- $course_info = api_get_course_info();
- $sessionId = api_get_session_id();
- $courseName = $course_info['title'];
- $courseUrl = $course_info['course_public_url'];
- if (!empty($sessionId)) {
- $sessionInfo = api_get_session_info($sessionId);
- $courseName = $sessionInfo['name'];
- $courseUrl .= '?id_session='.$sessionId;
- }
- $url = Display::url($courseName, $courseUrl, ['title' => get_lang('Go to the course')]);
- $coachList = CourseManager::get_coachs_from_course($sessionId, api_get_course_int_id());
- foreach ($coachList as $coach_course) {
- $recipientName = $coach_course['full_name'];
- $coachInfo = api_get_user_info($coach_course['user_id']);
- if (empty($coachInfo)) {
- continue;
- }
- $email = $coachInfo['email'];
- $tplContent = new Template(null, false, false, false, false, false);
- $tplContent->assign('name_teacher', $recipientName);
- $tplContent->assign('name_student', $studentInfo['complete_name']);
- $tplContent->assign('course_name', $courseName);
- $tplContent->assign('course_url', $url);
- $layoutContent = $tplContent->get_template('mail/content_ending_learnpath.tpl');
- $emailBody = $tplContent->fetch($layoutContent);
- api_mail_html(
- $recipientName,
- $email,
- sprintf(get_lang('Student %s has completed his/her learning paths.'), $studentInfo['complete_name']),
- $emailBody,
- $studentInfo['complete_name'],
- $studentInfo['email'],
- true
- );
- }
- Display::addFlash(Display::return_message(get_lang('Message Sent')));
- $url = api_get_self().'?action=list&'.api_get_cidreq();
- header('Location: '.$url);
- exit;
- break;
- case 'add_item':
- if (!$is_allowed_to_edit) {
- api_not_allowed(true);
- }
- if (!$lp_found) {
- // Check if the learnpath ID was defined, otherwise send back to list
- require 'lp_list.php';
- } else {
- Session::write('refresh', 1);
- if (isset($_POST['submit_button']) && !empty($post_title)) {
- // If a title was submitted:
- // Updating the lp.modified_on
- $_SESSION['oLP']->set_modified_on();
- if (isset($_SESSION['post_time']) && $_SESSION['post_time'] == $_POST['post_time']) {
- // Check post_time to ensure ??? (counter-hacking measure?)
- require 'lp_add_item.php';
- } else {
- Session::write('post_time', $_POST['post_time']);
- $directoryParentId = isset($_POST['directory_parent_id']) ? $_POST['directory_parent_id'] : 0;
- $courseInfo = api_get_course_info();
- if (empty($directoryParentId)) {
- $_SESSION['oLP']->generate_lp_folder($courseInfo);
- }
- $parent = isset($_POST['parent']) ? $_POST['parent'] : '';
- $previous = isset($_POST['previous']) ? $_POST['previous'] : '';
- $type = isset($_POST['type']) ? $_POST['type'] : '';
- $path = isset($_POST['path']) ? $_POST['path'] : '';
- $description = isset($_POST['description']) ? $_POST['description'] : '';
- $prerequisites = isset($_POST['prerequisites']) ? $_POST['prerequisites'] : '';
- $maxTimeAllowed = isset($_POST['maxTimeAllowed']) ? $_POST['maxTimeAllowed'] : '';
- if ($_POST['type'] == TOOL_DOCUMENT) {
- if (isset($_POST['path']) && $_GET['edit'] != 'true') {
- $document_id = $_POST['path'];
- } else {
- if ($_POST['content_lp']) {
- $document_id = $_SESSION['oLP']->create_document(
- $_course,
- $_POST['content_lp'],
- $_POST['title'],
- 'html',
- $directoryParentId
- );
- }
- }
- $_SESSION['oLP']->add_item(
- $parent,
- $previous,
- $type,
- $document_id,
- $post_title,
- $description,
- $prerequisites
- );
- } elseif ($_POST['type'] == TOOL_READOUT_TEXT) {
- if (isset($_POST['path']) && $_GET['edit'] != 'true') {
- $document_id = $_POST['path'];
- } else {
- $document_id = $_SESSION['oLP']->createReadOutText(
- $_course,
- $_POST['content_lp'],
- $_POST['title'],
- $directoryParentId
- );
- }
- $_SESSION['oLP']->add_item(
- $parent,
- $previous,
- TOOL_READOUT_TEXT,
- $document_id,
- $post_title,
- $description,
- $prerequisites
- );
- } else {
- // For all other item types than documents,
- // load the item using the item type and path rather than its ID.
- $_SESSION['oLP']->add_item(
- $parent,
- $previous,
- $type,
- $path,
- $post_title,
- $description,
- $prerequisites,
- $maxTimeAllowed
- );
- }
- $url = api_get_self().'?action=add_item&type=step&lp_id='.intval($_SESSION['oLP']->lp_id).'&'.api_get_cidreq();
- header('Location: '.$url);
- exit;
- }
- } else {
- require 'lp_add_item.php';
- }
- }
- break;
- case 'add_users_to_category':
- if (!$is_allowed_to_edit) {
- api_not_allowed(true);
- }
- require 'lp_subscribe_users_to_category.php';
- break;
- case 'add_audio':
- if (!$is_allowed_to_edit) {
- api_not_allowed(true);
- }
- if (!$lp_found) {
- // Check if the learnpath ID was defined, otherwise send back to list
- require 'lp_list.php';
- } else {
- Session::write('refresh', 1);
- if (isset($_REQUEST['id'])) {
- $lp_item_obj = new learnpathItem($_REQUEST['id']);
- // Remove audio
- if (isset($_GET['delete_file']) && $_GET['delete_file'] == 1) {
- $lp_item_obj->remove_audio();
- $url = api_get_self().'?action=add_audio&lp_id='.intval($_SESSION['oLP']->lp_id).'&id='.$lp_item_obj->get_id().'&'.api_get_cidreq();
- header('Location: '.$url);
- exit;
- }
- // Upload audio
- if (isset($_FILES['file']) && !empty($_FILES['file'])) {
- // Updating the lp.modified_on
- $_SESSION['oLP']->set_modified_on();
- $lp_item_obj->add_audio();
- }
- //Add audio file from documents
- if (isset($_REQUEST['document_id']) && !empty($_REQUEST['document_id'])) {
- $_SESSION['oLP']->set_modified_on();
- $lp_item_obj->add_audio_from_documents($_REQUEST['document_id']);
- }
- // Display.
- require 'lp_add_audio.php';
- } else {
- require 'lp_add_audio.php';
- }
- }
- break;
- case 'add_lp_category':
- if (!$is_allowed_to_edit) {
- api_not_allowed(true);
- }
- require 'lp_add_category.php';
- break;
- case 'move_up_category':
- if (!$is_allowed_to_edit) {
- api_not_allowed(true);
- }
- if (isset($_REQUEST['id'])) {
- learnpath::moveUpCategory($_REQUEST['id']);
- }
- require 'lp_list.php';
- break;
- case 'move_down_category':
- if (!$is_allowed_to_edit) {
- api_not_allowed(true);
- }
- if (isset($_REQUEST['id'])) {
- learnpath::moveDownCategory($_REQUEST['id']);
- }
- require 'lp_list.php';
- break;
- case 'delete_lp_category':
- if (!$is_allowed_to_edit) {
- api_not_allowed(true);
- }
- if (isset($_REQUEST['id'])) {
- $result = learnpath::deleteCategory($_REQUEST['id']);
- if ($result) {
- Display::addFlash(Display::return_message(get_lang('Deleted')));
- }
- }
- require 'lp_list.php';
- break;
- case 'add_lp':
- if (!$is_allowed_to_edit) {
- api_not_allowed(true);
- }
- if (isset($_REQUEST['lp_name']) && !empty($_REQUEST['lp_name'])) {
- $_REQUEST['lp_name'] = trim($_REQUEST['lp_name']);
- Session::write('refresh', 1);
- if (isset($_SESSION['post_time']) && $_SESSION['post_time'] == $_REQUEST['post_time']) {
- require 'lp_add.php';
- } else {
- Session::write('post_time', $_POST['post_time']);
- $publicated_on = null;
- if (isset($_REQUEST['activate_start_date_check']) &&
- $_REQUEST['activate_start_date_check'] == 1
- ) {
- $publicated_on = $_REQUEST['publicated_on'];
- }
- $expired_on = null;
- if (isset($_REQUEST['activate_end_date_check']) &&
- $_REQUEST['activate_end_date_check'] == 1
- ) {
- $expired_on = $_REQUEST['expired_on'];
- }
- $new_lp_id = learnpath::add_lp(
- api_get_course_id(),
- $_REQUEST['lp_name'],
- '',
- 'chamilo',
- 'manual',
- '',
- $publicated_on,
- $expired_on,
- $_REQUEST['category_id']
- );
- if (is_numeric($new_lp_id)) {
- // Create temp form validator to save skills
- $form = new FormValidator('lp_add');
- $form->addSelect('skills', 'skills');
- Skill::saveSkills($form, ITEM_TYPE_LEARNPATH, $new_lp_id);
- $extraFieldValue = new ExtraFieldValue('lp');
- $_REQUEST['item_id'] = $new_lp_id;
- $extraFieldValue->saveFieldValues($_REQUEST);
- // TODO: Maybe create a first directory directly to avoid bugging the user with useless queries
- $_SESSION['oLP'] = new learnpath(
- api_get_course_id(),
- $new_lp_id,
- api_get_user_id()
- );
- $accumulateScormTime = isset($_REQUEST['accumulate_scorm_time']) ? $_REQUEST['accumulate_scorm_time'] : 'true';
- $_SESSION['oLP']->setAccumulateScormTime($accumulateScormTime);
- $url = api_get_self().'?action=add_item&type=step&lp_id='.intval($new_lp_id).'&'.api_get_cidreq();
- header("Location: $url&isStudentView=false");
- exit;
- }
- }
- } else {
- require 'lp_add.php';
- }
- break;
- case 'admin_view':
- if (!$is_allowed_to_edit) {
- api_not_allowed(true);
- }
- if (!$lp_found) {
- require 'lp_list.php';
- } else {
- Session::write('refresh', 1);
- require 'lp_admin_view.php';
- }
- break;
- case 'auto_launch':
- // Redirect to a specific LP
- if (api_get_course_setting('enable_lp_auto_launch') == 1) {
- if (!$is_allowed_to_edit) {
- api_not_allowed(true);
- }
- if (!$lp_found) {
- require 'lp_list.php';
- } else {
- $_SESSION['oLP']->set_autolaunch($_GET['lp_id'], $_GET['status']);
- require 'lp_list.php';
- exit;
- }
- }
- break;
- case 'build':
- if (!$is_allowed_to_edit) {
- api_not_allowed(true);
- }
- if (!$lp_found) {
- require 'lp_list.php';
- } else {
- Session::write('refresh', 1);
- $url = api_get_self().'?action=add_item&type=step&lp_id='.intval($_SESSION['oLP']->lp_id).'&'.api_get_cidreq();
- header('Location: '.$url);
- exit;
- }
- break;
- case 'edit_item':
- if (!$is_allowed_to_edit) {
- api_not_allowed(true);
- }
- if (!$lp_found) {
- require 'lp_list.php';
- } else {
- Session::write('refresh', 1);
- if (isset($_POST['submit_button']) && !empty($post_title)) {
- // Updating the lp.modified_on
- $_SESSION['oLP']->set_modified_on();
- // TODO: mp3 edit
- $audio = [];
- if (isset($_FILES['mp3'])) {
- $audio = $_FILES['mp3'];
- }
- $description = isset($_POST['description']) ? $_POST['description'] : '';
- $prerequisites = isset($_POST['prerequisites']) ? $_POST['prerequisites'] : '';
- $maxTimeAllowed = isset($_POST['maxTimeAllowed']) ? $_POST['maxTimeAllowed'] : '';
- $url = isset($_POST['url']) ? $_POST['url'] : '';
- $_SESSION['oLP']->edit_item(
- $_REQUEST['id'],
- $_POST['parent'],
- $_POST['previous'],
- $post_title,
- $description,
- $prerequisites,
- $audio,
- $maxTimeAllowed,
- $url
- );
- if (isset($_POST['content_lp'])) {
- $_SESSION['oLP']->edit_document($_course);
- }
- Display::addFlash(Display::return_message(get_lang('Update successful')));
- $url = api_get_self().'?action=add_item&type=step&lp_id='.intval($_SESSION['oLP']->lp_id).'&'.api_get_cidreq();
- header('Location: '.$url);
- exit;
- }
- if (isset($_GET['view']) && $_GET['view'] === 'build') {
- require 'lp_edit_item.php';
- } else {
- require 'lp_admin_view.php';
- }
- }
- break;
- case 'edit_item_prereq':
- if (!$is_allowed_to_edit) {
- api_not_allowed(true);
- }
- if (!$lp_found) {
- require 'lp_list.php';
- } else {
- if (isset($_POST['submit_button'])) {
- // Updating the lp.modified_on
- $_SESSION['oLP']->set_modified_on();
- Session::write('refresh', 1);
- $min = isset($_POST['min_'.$_POST['prerequisites']]) ? $_POST['min_'.$_POST['prerequisites']] : '';
- $max = isset($_POST['max_'.$_POST['prerequisites']]) ? $_POST['max_'.$_POST['prerequisites']] : '';
- $editPrerequisite = $_SESSION['oLP']->edit_item_prereq(
- $_GET['id'],
- $_POST['prerequisites'],
- $min,
- $max
- );
- Display::addFlash(Display::return_message(get_lang('Update successful')));
- $url = api_get_self().'?action=add_item&type=step&lp_id='.intval($_SESSION['oLP']->lp_id).'&'.api_get_cidreq();
- header('Location: '.$url);
- exit;
- } else {
- require 'lp_edit_item_prereq.php';
- }
- }
- break;
- case 'move_item':
- if (!$is_allowed_to_edit) {
- api_not_allowed(true);
- }
- if (!$lp_found) {
- require 'lp_list.php';
- } else {
- Session::write('refresh', 1);
- if (isset($_POST['submit_button'])) {
- //Updating the lp.modified_on
- $_SESSION['oLP']->set_modified_on();
- $_SESSION['oLP']->edit_item(
- $_GET['id'],
- $_POST['parent'],
- $_POST['previous'],
- $post_title,
- $_POST['description']
- );
- $url = api_get_self().'?action=add_item&type=step&lp_id='.intval($_SESSION['oLP']->lp_id).'&'.api_get_cidreq();
- header('Location: '.$url);
- exit;
- }
- if (isset($_GET['view']) && $_GET['view'] == 'build') {
- require 'lp_move_item.php';
- } else {
- // Avoids weird behaviours see CT#967.
- $check = Security::check_token('get');
- if ($check) {
- $_SESSION['oLP']->move_item($_GET['id'], $_GET['direction']);
- }
- Security::clear_token();
- require 'lp_admin_view.php';
- }
- }
- break;
- case 'view_item':
- if (!$is_allowed_to_edit) {
- api_not_allowed(true);
- }
- if (!$lp_found) {
- require 'lp_list.php';
- } else {
- Session::write('refresh', 1);
- require 'lp_view_item.php';
- }
- break;
- case 'upload':
- if (!$is_allowed_to_edit) {
- api_not_allowed(true);
- }
- $cwdir = getcwd();
- require 'lp_upload.php';
- // Reinit current working directory as many functions in upload change it.
- chdir($cwdir);
- require 'lp_list.php';
- break;
- case 'copy':
- if (!$is_allowed_to_edit) {
- api_not_allowed(true);
- }
- $hideScormCopyLink = api_get_setting('hide_scorm_copy_link');
- if ($hideScormCopyLink === 'true') {
- api_not_allowed(true);
- }
- if (!$lp_found) {
- require 'lp_list.php';
- } else {
- $_SESSION['oLP']->copy();
- }
- require 'lp_list.php';
- break;
- case 'export':
- if (!$is_allowed_to_edit) {
- api_not_allowed(true);
- }
- $hideScormExportLink = api_get_setting('hide_scorm_export_link');
- if ($hideScormExportLink === 'true') {
- api_not_allowed(true);
- }
- if (!$lp_found) {
- require 'lp_list.php';
- } else {
- $_SESSION['oLP']->scormExport();
- exit();
- }
- break;
- case 'export_to_pdf':
- $hideScormPdfLink = api_get_setting('hide_scorm_pdf_link');
- if ($hideScormPdfLink === 'true') {
- api_not_allowed(true);
- }
- // Teachers can export to PDF
- if (!$is_allowed_to_edit) {
- if (!learnpath::is_lp_visible_for_student($_SESSION['oLP']->lp_id, api_get_user_id(), $_course)) {
- api_not_allowed();
- }
- }
- if (!$lp_found) {
- require 'lp_list.php';
- } else {
- $result = $_SESSION['oLP']->scorm_export_to_pdf($_GET['lp_id']);
- if (!$result) {
- require 'lp_list.php';
- }
- exit;
- }
- break;
- case 'export_to_course_build':
- $allowExport = api_get_configuration_value('allow_lp_chamilo_export');
- if (api_is_allowed_to_edit() && $allowExport) {
- if (!$lp_found) {
- require 'lp_list.php';
- } else {
- $result = $_SESSION['oLP']->exportToCourseBuildFormat($_GET['lp_id']);
- if (!$result) {
- require 'lp_list.php';
- }
- exit;
- }
- }
- require 'lp_list.php';
- break;
- case 'delete':
- if (!$is_allowed_to_edit) {
- api_not_allowed(true);
- }
- if (!$lp_found) {
- require 'lp_list.php';
- } else {
- Session::write('refresh', 1);
- $_SESSION['oLP']->delete(null, $_GET['lp_id'], 'remove');
- Skill::deleteSkillsFromItem($_GET['lp_id'], ITEM_TYPE_LEARNPATH);
- Display::addFlash(Display::return_message(get_lang('Deleted')));
- Session::erase('oLP');
- require 'lp_list.php';
- }
- break;
- case 'toggle_category_visibility':
- if (!$is_allowed_to_edit) {
- api_not_allowed(true);
- }
- learnpath::toggleCategoryVisibility($_REQUEST['id'], $_REQUEST['new_status']);
- Display::addFlash(Display::return_message(get_lang('Update successful')));
- header('Location: '.api_get_self().'?'.api_get_cidreq());
- exit;
- case 'toggle_visible':
- // Change lp visibility (inside lp tool).
- if (!$is_allowed_to_edit) {
- api_not_allowed(true);
- }
- if (!$lp_found) {
- require 'lp_list.php';
- } else {
- learnpath::toggle_visibility($_REQUEST['lp_id'], $_REQUEST['new_status']);
- Display::addFlash(Display::return_message(get_lang('Update successful')));
- require 'lp_list.php';
- }
- break;
- case 'toggle_category_publish':
- if (!$is_allowed_to_edit) {
- api_not_allowed(true);
- }
- learnpath::toggleCategoryPublish($_REQUEST['id'], $_REQUEST['new_status']);
- Display::addFlash(Display::return_message(get_lang('Update successful')));
- require 'lp_list.php';
- break;
- case 'toggle_publish':
- // Change lp published status (visibility on homepage).
- if (!$is_allowed_to_edit) {
- api_not_allowed(true);
- }
- if (!$lp_found) {
- require 'lp_list.php';
- } else {
- learnpath::toggle_publish($_REQUEST['lp_id'], $_REQUEST['new_status']);
- Display::addFlash(Display::return_message(get_lang('Update successful')));
- require 'lp_list.php';
- }
- break;
- case 'move_lp_up':
- // Change lp published status (visibility on homepage)
- if (!$is_allowed_to_edit) {
- api_not_allowed(true);
- }
- if (!$lp_found) {
- require 'lp_list.php';
- } else {
- learnpath::move_up($_REQUEST['lp_id'], $_REQUEST['category_id']);
- Display::addFlash(Display::return_message(get_lang('Update successful')));
- require 'lp_list.php';
- }
- break;
- case 'move_lp_down':
- // Change lp published status (visibility on homepage)
- if (!$is_allowed_to_edit) {
- api_not_allowed(true);
- }
- if (!$lp_found) {
- require 'lp_list.php';
- } else {
- learnpath::move_down($_REQUEST['lp_id'], $_REQUEST['category_id']);
- Display::addFlash(Display::return_message(get_lang('Update successful')));
- require 'lp_list.php';
- }
- break;
- case 'edit':
- if (!$is_allowed_to_edit) {
- api_not_allowed(true);
- }
- if (!$lp_found) {
- require 'lp_list.php';
- } else {
- Session::write('refresh', 1);
- require 'lp_edit.php';
- }
- break;
- case 'update_lp':
- if (!$is_allowed_to_edit) {
- api_not_allowed(true);
- }
- if (!$lp_found) {
- require 'lp_list.php';
- } else {
- Session::write('refresh', 1);
- $_SESSION['oLP']->set_name($_REQUEST['lp_name']);
- $author = $_REQUEST['lp_author'];
- // Fixing the author name (no body or html tags).
- $auth_init = stripos($author, '<p>');
- if ($auth_init === false) {
- $auth_init = stripos($author, '<body>');
- $auth_end = $auth_init + stripos(substr($author, $auth_init + 6), '</body>') + 7;
- $len = $auth_end - $auth_init + 6;
- } else {
- $auth_end = strripos($author, '</p>');
- $len = $auth_end - $auth_init + 4;
- }
- $author_fixed = substr($author, $auth_init, $len);
- $_SESSION['oLP']->set_author($author_fixed);
- // TODO (as of Chamilo 1.8.8): Check in the future whether this field is needed.
- $_SESSION['oLP']->set_encoding($_REQUEST['lp_encoding']);
- if (isset($_REQUEST['lp_maker'])) {
- $_SESSION['oLP']->set_maker($_REQUEST['lp_maker']);
- }
- if (isset($_REQUEST['lp_proximity'])) {
- $_SESSION['oLP']->set_proximity($_REQUEST['lp_proximity']);
- }
- $_SESSION['oLP']->set_theme($_REQUEST['lp_theme']);
- $hide_toc_frame = null;
- if (isset($_REQUEST['hide_toc_frame']) && $_REQUEST['hide_toc_frame'] == 1) {
- $hide_toc_frame = $_REQUEST['hide_toc_frame'];
- }
- $_SESSION['oLP']->set_hide_toc_frame($hide_toc_frame);
- $_SESSION['oLP']->set_prerequisite(isset($_POST['prerequisites']) ? (int) $_POST['prerequisites'] : 0);
- $_SESSION['oLP']->setAccumulateWorkTime(isset($_REQUEST['accumulate_work_time']) ? $_REQUEST['accumulate_work_time'] : 0);
- $_SESSION['oLP']->set_use_max_score(isset($_POST['use_max_score']) ? 1 : 0);
- $subscribeUsers = isset($_REQUEST['subscribe_users']) ? 1 : 0;
- $_SESSION['oLP']->setSubscribeUsers($subscribeUsers);
- $accumulateScormTime = isset($_REQUEST['accumulate_scorm_time']) ? $_REQUEST['accumulate_scorm_time'] : 'true';
- $_SESSION['oLP']->setAccumulateScormTime($accumulateScormTime);
- $publicated_on = null;
- if (isset($_REQUEST['activate_start_date_check']) && $_REQUEST['activate_start_date_check'] == 1) {
- $publicated_on = $_REQUEST['publicated_on'];
- }
- $expired_on = null;
- if (isset($_REQUEST['activate_end_date_check']) && $_REQUEST['activate_end_date_check'] == 1) {
- $expired_on = $_REQUEST['expired_on'];
- }
- $_SESSION['oLP']->setCategoryId($_REQUEST['category_id']);
- $_SESSION['oLP']->set_modified_on();
- $_SESSION['oLP']->set_publicated_on($publicated_on);
- $_SESSION['oLP']->set_expired_on($expired_on);
- if (isset($_REQUEST['remove_picture']) && $_REQUEST['remove_picture']) {
- $_SESSION['oLP']->delete_lp_image();
- }
- $extraFieldValue = new ExtraFieldValue('lp');
- $_REQUEST['item_id'] = $_SESSION['oLP']->lp_id;
- $extraFieldValue->saveFieldValues($_REQUEST);
- if ($_FILES['lp_preview_image']['size'] > 0) {
- $_SESSION['oLP']->upload_image($_FILES['lp_preview_image']);
- }
- $form = new FormValidator('form1');
- $form->addSelect('skills', 'skills');
- Skill::saveSkills($form, ITEM_TYPE_LEARNPATH, $_SESSION['oLP']->get_id());
- if (api_get_setting('search_enabled') === 'true') {
- require_once api_get_path(LIBRARY_PATH).'specific_fields_manager.lib.php';
- $specific_fields = get_specific_field_list();
- foreach ($specific_fields as $specific_field) {
- $_SESSION['oLP']->set_terms_by_prefix($_REQUEST[$specific_field['code']], $specific_field['code']);
- $new_values = explode(',', trim($_REQUEST[$specific_field['code']]));
- if (!empty($new_values)) {
- array_walk($new_values, 'trim');
- delete_all_specific_field_value(
- api_get_course_id(),
- $specific_field['id'],
- TOOL_LEARNPATH,
- $_SESSION['oLP']->lp_id
- );
- foreach ($new_values as $value) {
- if (!empty($value)) {
- add_specific_field_value(
- $specific_field['id'],
- api_get_course_id(),
- TOOL_LEARNPATH,
- $_SESSION['oLP']->lp_id,
- $value
- );
- }
- }
- }
- }
- }
- Display::addFlash(Display::return_message(get_lang('Update successful')));
- $url = api_get_self().'?action=add_item&type=step&lp_id='.intval($_SESSION['oLP']->lp_id).'&'.api_get_cidreq();
- header('Location: '.$url);
- exit;
- }
- break;
- case 'add_sub_item':
- // Add an item inside a dir/chapter.
- // @todo check if this is @deprecated
- if (!$is_allowed_to_edit) {
- api_not_allowed(true);
- }
- if (!$lp_found) {
- require 'lp_list.php';
- } else {
- Session::write('refresh', 1);
- if (!empty($_REQUEST['parent_item_id'])) {
- $_SESSION['from_learnpath'] = 'yes';
- $_SESSION['origintoolurl'] = 'lp_controller.php?action=admin_view&lp_id='.intval($_REQUEST['lp_id']);
- } else {
- require 'lp_admin_view.php';
- }
- }
- break;
- case 'deleteitem':
- case 'delete_item':
- if (!$is_allowed_to_edit) {
- api_not_allowed(true);
- }
- if (!$lp_found) {
- require 'lp_list.php';
- } else {
- if (!empty($_REQUEST['id'])) {
- $_SESSION['oLP']->delete_item($_REQUEST['id']);
- }
- $url = api_get_self().'?action=add_item&type=step&lp_id='.intval($_REQUEST['lp_id']).'&'.api_get_cidreq();
- header('Location: '.$url);
- exit;
- }
- break;
- case 'restart':
- if (!$lp_found) {
- require 'lp_list.php';
- } else {
- $_SESSION['oLP']->restart();
- require 'lp_view.php';
- }
- break;
- case 'last':
- if (!$lp_found) {
- require 'lp_list.php';
- } else {
- $_SESSION['oLP']->last();
- require 'lp_view.php';
- }
- break;
- case 'first':
- if (!$lp_found) {
- require 'lp_list.php';
- } else {
- $_SESSION['oLP']->first();
- require 'lp_view.php';
- }
- break;
- case 'next':
- if (!$lp_found) {
- require 'lp_list.php';
- } else {
- $_SESSION['oLP']->next();
- require 'lp_view.php';
- }
- break;
- case 'previous':
- if (!$lp_found) {
- require 'lp_list.php';
- } else {
- $_SESSION['oLP']->previous();
- require 'lp_view.php';
- }
- break;
- case 'content':
- if (!$lp_found) {
- require 'lp_list.php';
- } else {
- $_SESSION['oLP']->save_last();
- $_SESSION['oLP']->set_current_item($_GET['item_id']);
- $_SESSION['oLP']->start_current_item();
- require 'lp_content.php';
- }
- break;
- case 'view':
- if (!$lp_found) {
- require 'lp_list.php';
- } else {
- if (!empty($_REQUEST['item_id'])) {
- $_SESSION['oLP']->set_current_item($_REQUEST['item_id']);
- }
- require 'lp_view.php';
- }
- break;
- case 'save':
- if (!$lp_found) {
- require 'lp_list.php';
- } else {
- $_SESSION['oLP']->save_item();
- require 'lp_save.php';
- }
- break;
- case 'stats':
- if (!$lp_found) {
- require 'lp_list.php';
- } else {
- $_SESSION['oLP']->save_current();
- $_SESSION['oLP']->save_last();
- $output = require 'lp_stats.php';
- echo $output;
- }
- break;
- case 'list':
- if ($lp_found) {
- Session::write('refresh', 1);
- $_SESSION['oLP']->save_last();
- }
- require 'lp_list.php';
- break;
- case 'mode':
- // Switch between fullscreen and embedded mode.
- $mode = $_REQUEST['mode'];
- if ($mode == 'fullscreen') {
- $_SESSION['oLP']->mode = 'fullscreen';
- } elseif ($mode == 'embedded') {
- $_SESSION['oLP']->mode = 'embedded';
- } elseif ($mode == 'embedframe') {
- $_SESSION['oLP']->mode = 'embedframe';
- } elseif ($mode == 'impress') {
- $_SESSION['oLP']->mode = 'impress';
- }
- require 'lp_view.php';
- break;
- case 'switch_view_mode':
- if (!$lp_found) {
- require 'lp_list.php';
- }
- if (Security::check_token('get')) {
- Session::write('refresh', 1);
- $_SESSION['oLP']->update_default_view_mode();
- }
- require 'lp_list.php';
- break;
- case 'switch_force_commit':
- if (!$lp_found) {
- require 'lp_list.php';
- }
- Session::write('refresh', 1);
- $_SESSION['oLP']->update_default_scorm_commit();
- require 'lp_list.php';
- break;
- case 'switch_attempt_mode':
- if (!$lp_found) {
- require 'lp_list.php';
- }
- Session::write('refresh', 1);
- $_SESSION['oLP']->switch_attempt_mode();
- require 'lp_list.php';
- break;
- case 'switch_scorm_debug':
- if (!$lp_found) {
- require 'lp_list.php';
- }
- Session::write('refresh', 1);
- $_SESSION['oLP']->update_scorm_debug();
- require 'lp_list.php';
- break;
- case 'intro_cmdAdd':
- // Add introduction section page.
- break;
- case 'return_to_course_homepage':
- if (!$lp_found) {
- require 'lp_list.php';
- } else {
- $_SESSION['oLP']->save_current();
- $_SESSION['oLP']->save_last();
- if ($debug > 0) {
- error_log('save_current()');
- error_log('save_last()');
- }
- $url = api_get_path(WEB_COURSE_PATH).api_get_course_path().'/index.php?id_session='.api_get_session_id();
- $redirectTo = isset($_GET['redirectTo']) ? $_GET['redirectTo'] : '';
- switch ($redirectTo) {
- case 'lp_list':
- $url = 'lp_controller.php?'.api_get_cidreq();
- break;
- case 'my_courses':
- $url = api_get_path(WEB_PATH).'user_portal.php';
- break;
- }
- header('location: '.$url);
- exit;
- }
- break;
- case 'search':
- /* Include the search script, it's smart enough to know when we are
- * searching or not.
- */
- require 'lp_list_search.php';
- break;
- case 'impress':
- if (!$lp_found) {
- require 'lp_list.php';
- } else {
- if ($debug > 0) {
- error_log('Trying to impress this LP item to '.$_REQUEST['item_id'], 0);
- }
- if (!empty($_REQUEST['item_id'])) {
- $_SESSION['oLP']->set_current_item($_REQUEST['item_id']);
- }
- require 'lp_impress.php';
- }
- break;
- case 'set_previous_step_as_prerequisite':
- $_SESSION['oLP']->set_previous_step_as_prerequisite_for_all_items();
- $url = api_get_self().'?action=add_item&type=step&lp_id='.intval($_SESSION['oLP']->lp_id)."&".api_get_cidreq();
- Display::addFlash(Display::return_message(get_lang('ItemUpdate successful')));
- header('Location: '.$url);
- exit;
- break;
- case 'clear_prerequisites':
- $_SESSION['oLP']->clear_prerequisites();
- $url = api_get_self().'?action=add_item&type=step&lp_id='.intval($_SESSION['oLP']->lp_id)."&".api_get_cidreq();
- Display::addFlash(Display::return_message(get_lang('ItemUpdate successful')));
- header('Location: '.$url);
- exit;
- break;
- case 'toggle_seriousgame':
- // activate/deactive seriousgame_mode
- if (!$is_allowed_to_edit) {
- api_not_allowed(true);
- }
- if (!$lp_found) {
- require 'lp_list.php';
- }
- Session::write('refresh', 1);
- $_SESSION['oLP']->set_seriousgame_mode();
- require 'lp_list.php';
- break;
- case 'create_forum':
- if (!isset($_GET['id'])) {
- break;
- }
- $selectedItem = null;
- foreach ($_SESSION['oLP']->items as $item) {
- if ($item->db_id == $_GET['id']) {
- $selectedItem = $item;
- }
- }
- if (!empty($selectedItem)) {
- $forumThread = $selectedItem->getForumThread(
- $_SESSION['oLP']->course_int_id,
- $_SESSION['oLP']->lp_session_id
- );
- if (empty($forumThread)) {
- require '../forum/forumfunction.inc.php';
- $forumCategory = getForumCategoryByTitle(
- get_lang('Learning paths'),
- $_SESSION['oLP']->course_int_id,
- $_SESSION['oLP']->lp_session_id
- );
- $forumCategoryId = !empty($forumCategory) ? $forumCategory['cat_id'] : 0;
- if (empty($forumCategoryId)) {
- $forumCategoryId = store_forumcategory(
- [
- 'lp_id' => 0,
- 'forum_category_title' => get_lang('Learning paths'),
- 'forum_category_comment' => null,
- ],
- [],
- false
- );
- }
- if (!empty($forumCategoryId)) {
- $forum = $_SESSION['oLP']->getForum(
- $_SESSION['oLP']->lp_session_id
- );
- $forumId = !empty($forum) ? $forum['forum_id'] : 0;
- if (empty($forumId)) {
- $forumId = $_SESSION['oLP']->createForum($forumCategoryId);
- }
- if (!empty($forumId)) {
- $selectedItem->createForumThread($forumId);
- }
- }
- }
- }
- header('Location:'.api_get_self().'?'.http_build_query([
- 'action' => 'add_item',
- 'type' => 'step',
- 'lp_id' => $_SESSION['oLP']->lp_id,
- ]));
- exit;
- break;
- case 'report':
- require 'lp_report.php';
- break;
- case 'dissociate_forum':
- if (!isset($_GET['id'])) {
- break;
- }
- $selectedItem = null;
- foreach ($_SESSION['oLP']->items as $item) {
- if ($item->db_id != $_GET['id']) {
- continue;
- }
- $selectedItem = $item;
- }
- if (!empty($selectedItem)) {
- $forumThread = $selectedItem->getForumThread(
- $_SESSION['oLP']->course_int_id,
- $_SESSION['oLP']->lp_session_id
- );
- if (!empty($forumThread)) {
- $dissociated = $selectedItem->dissociateForumThread($forumThread['iid']);
- if ($dissociated) {
- Display::addFlash(
- Display::return_message(get_lang('Dissociate forum'), 'success')
- );
- }
- }
- }
- header('Location:'.api_get_self().'?'.http_build_query([
- 'action' => 'add_item',
- 'type' => 'step',
- 'lp_id' => $_SESSION['oLP']->lp_id,
- ]));
- exit;
- break;
- case 'add_final_item':
- if (!$lp_found) {
- Display::addFlash(
- Display::return_message(get_lang('No learning path found'), 'error')
- );
- break;
- }
- Session::write('refresh', 1);
- if (!isset($_POST['submit']) || empty($post_title)) {
- break;
- }
- $_SESSION['oLP']->getFinalItemForm();
- $redirectTo = api_get_self().'?'.api_get_cidreq().'&'.http_build_query([
- 'action' => 'add_item',
- 'type' => 'step',
- 'lp_id' => intval($_SESSION['oLP']->lp_id),
- ]);
- break;
- default:
- require 'lp_list.php';
- break;
- }
- if (!empty($_SESSION['oLP'])) {
- $_SESSION['lpobject'] = serialize($_SESSION['oLP']);
- if ($debug > 0) {
- error_log('lpobject is serialized in session', 0);
- }
- }
- if (!empty($redirectTo)) {
- header("Location: $redirectTo");
- exit;
- }
|