123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919 |
- <?php
- /* For licensing terms, see /license.txt */
- /**
- * Controller script. Prepares the common background variables to give to the scripts corresponding to
- * the requested action
- * @package chamilo.learnpath
- * @author Yannick Warnier <ywarnier@beeznest.org>
- */
- $debug = 0;
- if ($debug > 0) error_log('New LP -+- Entered lp_controller.php -+- (action: '.$_REQUEST['action'].')', 0);
- // Language files that needs to be included.
- if (isset($_GET['action'])) {
- if ($_GET['action'] == 'export') {
- // Only needed on export.
- $language_file[] = 'hotspot';
- }
- }
- $language_file[] = 'course_home';
- $language_file[] = 'scormdocument';
- $language_file[] = 'scorm';
- $language_file[] = 'learnpath';
- $language_file[] = 'resourcelinker';
- $language_file[] = 'registration';
- $language_file[] = 'exercice';
- // Including the global initialization file.
- require_once '../inc/global.inc.php';
- if (api_get_setting('show_glossary_in_documents') == 'ismanual' || api_get_setting('show_glossary_in_documents') == 'isautomatic' ) {
- $htmlHeadXtra[] = '<script type="text/javascript">
- <!--
- var jQueryFrameReadyConfigPath = \''.api_get_path(WEB_LIBRARY_PATH).'javascript/jquery.min.js\';
- -->
- </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 type="text/javascript">
- function setFocus(){
- $("#idTitle").focus();
- }
- $(window).load(function () {
- setFocus();
- });
- </script>';
- // Storage API
- $htmlHeadXtra[] = '<script type="text/javascript">
- var sv_user = \''.api_get_user_id().'\';
- var sv_course = \''.api_get_course_id().'\';
- var sv_sco = \''.$_REQUEST['lp_id'].'\';
- </script>';
- $htmlHeadXtra[] = '<script type="text/javascript" src="js/storageapi.js"></script>';
- // Flag to allow for anonymous user - needs to be set before global.inc.php.
- $use_anonymous = true;
- // Include class definitions before session_start() to ensure availability when touching
- // session vars containing learning paths.
- require_once 'learnpath.class.php';
- if ($debug > 0) error_log('New LP - Included learnpath', 0);
- require_once 'learnpathItem.class.php';
- if ($debug > 0) error_log('New LP - Included learnpathItem', 0);
- require_once 'scorm.class.php';
- if ($debug > 0) error_log('New LP - Included scorm', 0);
- require_once 'scormItem.class.php';
- if ($debug > 0) error_log('New LP - Included scormItem', 0);
- require_once 'aicc.class.php';
- if ($debug > 0) error_log('New LP - Included aicc', 0);
- require_once 'aiccItem.class.php';
- if ($debug > 0) error_log('New LP - Included aiccItem', 0);
- require_once 'back_compat.inc.php';
- if ($debug > 0) error_log('New LP - Included back_compat', 0);
- $session_id = api_get_session_id();
- if (!$is_allowed_in_course) {
- api_not_allowed(true);
- }
- require_once api_get_path(LIBRARY_PATH).'fckeditor/fckeditor.php';
- $lpfound = false;
- $myrefresh = 0;
- $myrefresh_id = 0;
- if (!empty($_SESSION['refresh']) && $_SESSION['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).
- api_session_unregister('refresh');
- $myrefresh = 1;
- if ($debug > 0) error_log('New LP - Refresh asked', 0);
- }
- if ($debug > 0) error_log('New LP - Passed refresh check', 0);
- if (!empty($_REQUEST['dialog_box'])) {
- $dialog_box = stripslashes(urldecode($_REQUEST['dialog_box']));
- }
- $lp_controller_touched = 1;
- $lp_found = false;
- if (isset($_SESSION['lpobject'])) {
- if ($debug > 0) error_log('New LP - SESSION[lpobject] is defined', 0);
- $oLP = unserialize($_SESSION['lpobject']);
- if (is_object($oLP)) {
- if ($debug > 0) error_log('New LP - oLP is object', 0);
- if ($myrefresh == 1 OR (empty($oLP->cc)) OR $oLP->cc != api_get_course_id() OR $oLP->lp_view_session_id != $session_id) {
- if ($debug > 0) error_log('New LP - Course has changed, discard lp object', 0);
- if ($myrefresh == 1) { $myrefresh_id = $oLP->get_id(); }
- $oLP = null;
- api_session_unregister('oLP');
- api_session_unregister('lpobject');
- } else {
- $_SESSION['oLP'] = $oLP;
- $lp_found = true;
- }
- }
- }
- $course_id = api_get_course_int_id();
- if ($debug>0) error_log('New LP - Passed data remains check', 0);
- if (!$lp_found || (!empty($_REQUEST['lp_id']) && $_SESSION['oLP']->get_id() != $_REQUEST['lp_id'])) {
- if ($debug > 0) error_log('New LP - oLP is not object, has changed or refresh been asked, getting new', 0);
- // 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)) {
- if ($debug > 0) error_log('New LP - lp_id is defined', 0);
- // Select the lp in the database and check which type it is (scorm/dokeos/aicc) to generate the
- // right object.
- $lp_table = Database::get_course_table(TABLE_LP_MAIN);
- if (!empty($_REQUEST['lp_id'])) {
- $lp_id = $_REQUEST['lp_id'];
- } else {
- $lp_id = $myrefresh_id;
- }
- if (is_numeric($lp_id)) {
- $lp_id = Database::escape_string($lp_id);
- $sel = "SELECT * FROM $lp_table WHERE c_id = $course_id AND id = $lp_id";
- if ($debug > 0) error_log('New LP - querying '.$sel, 0);
- $res = Database::query($sel);
- if (Database::num_rows($res)) {
- $row = Database::fetch_array($res);
- $type = $row['lp_type'];
- if ($debug > 0) error_log('New LP - found row - type '.$type. ' - Calling constructor with '.api_get_course_id().' - '.$lp_id.' - '.api_get_user_id(), 0);
- switch ($type) {
- case 1:
- if ($debug > 0) error_log('New LP - found row - type dokeos - Calling constructor with '.api_get_course_id().' - '.$lp_id.' - '.api_get_user_id(), 0);
- $oLP = new learnpath(api_get_course_id(),$lp_id,api_get_user_id());
- if ($oLP !== false) { $lp_found = true; } else { eror_log($oLP->error, 0); }
- break;
- case 2:
- if ($debug > 0) error_log('New LP - found row - type scorm - Calling constructor with '.api_get_course_id().' - '.$lp_id.' - '.api_get_user_id(), 0);
- $oLP = new scorm(api_get_course_id(),$lp_id,api_get_user_id());
- if ($oLP !== false) { $lp_found = true; } else { eror_log($oLP->error, 0); }
- break;
- case 3:
- if ($debug > 0) error_log('New LP - found row - type aicc - Calling constructor with '.api_get_course_id().' - '.$lp_id.' - '.api_get_user_id(), 0);
- $oLP = new aicc(api_get_course_id(),$lp_id,api_get_user_id());
- if ($oLP !== false) { $lp_found = true; } else { eror_log($oLP->error, 0); }
- break;
- default:
- if ($debug > 0) error_log('New LP - found row - type other - Calling constructor with '.api_get_course_id().' - '.$lp_id.' - '.api_get_user_id(), 0);
- $oLP = new learnpath(api_get_course_id(),$lp_id,api_get_user_id());
- if ($oLP !== false) { $lp_found = true; } else { eror_log($oLP->error, 0); }
- break;
- }
- }
- } else {
- if ($debug > 0) error_log('New LP - Request[lp_id] is not numeric', 0);
- }
- } else {
- if ($debug > 0) error_log('New LP - Request[lp_id] and refresh_id were empty', 0);
- }
- if ($lp_found) {
- $_SESSION['oLP'] = $oLP;
- }
- }
- if ($debug > 0) error_log('New LP - Passed oLP creation check', 0);
- /**
- * Actions switching
- */
- $_SESSION['oLP']->update_queue = array(); // Reinitialises array used by javascript to update items in the TOC.
- $_SESSION['oLP']->message = ''; // Should use ->clear_message() method but doesn't work.
- if (isset($_GET['isStudentView']) && $_GET['isStudentView'] == 'true') {
- if ($_REQUEST['action'] != 'list' AND $_REQUEST['action'] != 'view') {
- if (!empty($_REQUEST['lp_id'])) {
- $_REQUEST['action'] = 'view';
- } else {
- $_REQUEST['action'] = 'list';
- }
- }
- }
- $is_allowed_to_edit = api_is_allowed_to_edit(null, true);
- $action = (!empty($_REQUEST['action']) ? $_REQUEST['action'] : '');
- switch ($action) {
- case 'add_item':
- if (!$is_allowed_to_edit) {
- api_not_allowed(true);
- }
- if ($debug > 0) error_log('New LP - add item action triggered', 0);
- if (!$lp_found) {
- //check if the learnpath ID was defined, otherwise send back to list
- if ($debug > 0) error_log('New LP - No learnpath given for add item', 0);
- require 'lp_list.php';
- } else {
- $_SESSION['refresh'] = 1;
- if (isset($_POST['submit_button']) && !empty($_POST['title'])) {
- // If a title was sumbitted:
- //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['post_time'] = $_POST['post_time'];
- if ($_POST['type'] == TOOL_DOCUMENT) {
- if (isset($_POST['path']) && $_GET['edit'] != 'true') {
- $document_id = $_POST['path'];
- } else {
- $document_id = $_SESSION['oLP']->create_document($_course);
- }
- $new_item_id = $_SESSION['oLP']->add_item($_POST['parent'], $_POST['previous'], $_POST['type'], $document_id, $_POST['title'], $_POST['description'], $_POST['prerequisites']);
- } else {
- // For all other item types than documents, load the item using the item type and path rather than its ID.
- $new_item_id = $_SESSION['oLP']->add_item($_POST['parent'], $_POST['previous'], $_POST['type'], $_POST['path'], $_POST['title'], $_POST['description'], $_POST['prerequisites'], $_POST['maxTimeAllowed']);
- }
- // Display.
- require 'lp_add_item.php';
- }
- } else {
- require 'lp_add_item.php';
- }
- }
- break;
- case 'add_lp':
- if (!$is_allowed_to_edit) {
- api_not_allowed(true);
- }
- if ($debug > 0) error_log('New LP - add_lp action triggered', 0);
- $_REQUEST['lp_name'] = trim($_REQUEST['lp_name']);
- if (!empty($_REQUEST['lp_name'])) {
- $_SESSION['refresh'] = 1;
- if (isset($_SESSION['post_time']) && $_SESSION['post_time'] == $_REQUEST['post_time']) {
- require 'lp_add.php';
- } else {
- $_SESSION['post_time'] = $_REQUEST['post_time'];
- if (isset($_REQUEST['activate_start_date_check']) && $_REQUEST['activate_start_date_check'] == 1) {
- $publicated_on = $_REQUEST['publicated_on'];
- $publicated_on = $publicated_on['Y'].'-'.$publicated_on['F'].'-'.$publicated_on['d'].' '.$publicated_on['H'].':'.$publicated_on['i'].':00';
- } else {
- $publicated_on = null;
- }
-
- if (isset($_REQUEST['activate_end_date_check']) && $_REQUEST['activate_end_date_check'] == 1) {
- $expired_on = $_REQUEST['expired_on'];
- $expired_on = $expired_on['Y'].'-'.$expired_on['F'].'-'.$expired_on['d'].' '.$expired_on['H'].':'.$expired_on['i'].':00';
- } else {
- $expired_on = null;
- }
- $new_lp_id = learnpath::add_lp(api_get_course_id(), Security::remove_XSS($_REQUEST['lp_name']), '', 'chamilo', 'manual', '', $publicated_on, $expired_on);
- if (is_numeric($new_lp_id)) {
- // TODO: Maybe create a first module directly to avoid bugging the user with useless queries
- $_SESSION['oLP'] = new learnpath(api_get_course_id(),$new_lp_id,api_get_user_id());
- require 'lp_build.php';
- }
- }
- } else {
- require 'lp_add.php';
- }
- break;
- case 'admin_view':
- if (!$is_allowed_to_edit) {
- api_not_allowed(true);
- }
- if ($debug > 0) error_log('New LP - admin_view action triggered', 0);
- if (!$lp_found) { error_log('New LP - No learnpath given for admin_view', 0); require 'lp_list.php'; }
- else {
- $_SESSION['refresh'] = 1;
- require 'lp_admin_view.php';
- }
- break;
- case 'auto_launch':
- if (api_get_course_setting('enable_lp_auto_launch') == 1) { //Redirect to a specific LP
- if (!$is_allowed_to_edit) {
- api_not_allowed(true);
- }
- if ($debug > 0) error_log('New LP - export action triggered', 0);
- if (!$lp_found) { error_log('New LP - No learnpath given for set_autolunch', 0); require 'lp_list.php'; }
- else {
- $_SESSION['oLP']->set_autolunch($_GET['lp_id'], $_GET['status']);
- require 'lp_list.php';
- exit;
- }
- }
- break;
- case 'build':
- if (!$is_allowed_to_edit) {
- api_not_allowed(true);
- }
- if ($debug > 0) error_log('New LP - build action triggered', 0);
- if (!$lp_found) { error_log('New LP - No learnpath given for build', 0); require 'lp_list.php'; }
- else {
- $_SESSION['refresh'] = 1;
- require 'lp_build.php';
- }
- break;
- case 'delete_item':
- if (!$is_allowed_to_edit) {
- api_not_allowed(true);
- }
- if ($debug > 0) error_log('New LP - delete item action triggered', 0);
- if (!$lp_found) { error_log('New LP - No learnpath given for delete item', 0); require 'lp_list.php'; }
- else {
- $_SESSION['refresh'] = 1;
- if (is_numeric($_GET['id'])) {
- $_SESSION['oLP']->delete_item($_GET['id']);
- $is_success = true;
- }
- if (isset($_GET['view']) && $_GET['view'] == 'build') {
- require 'lp_build.php';
- } else {
- require 'lp_admin_view.php';
- }
- }
- break;
- case 'edit_item':
- if (!$is_allowed_to_edit) {
- api_not_allowed(true);
- }
- if ($debug > 0) error_log('New LP - edit item action triggered', 0);
- if (!$lp_found) { error_log('New LP - No learnpath given for edit item', 0); require 'lp_list.php'; }
- else {
- $_SESSION['refresh'] = 1;
- if (isset($_POST['submit_button']) && !empty($_POST['title'])) {
- //Updating the lp.modified_on
- $_SESSION['oLP']->set_modified_on();
- //$_SESSION['oLP']->edit_item($_GET['id'], $_POST['parent'], $_POST['previous'], $_POST['title'], $_POST['description'], $_POST['prerequisites']);
- // TODO: mp3 edit
- $audio = array();
- if (isset($_FILES['mp3'])) $audio = $_FILES['mp3'];
- $_SESSION['oLP']->edit_item($_GET['id'], $_POST['parent'], $_POST['previous'], $_POST['title'], $_POST['description'], $_POST['prerequisites'], $audio, $_POST['maxTimeAllowed']);
- if (isset($_POST['content_lp'])) {
- $_SESSION['oLP']->edit_document($_course);
- }
- $is_success = true;
- }
- 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 ($debug > 0) error_log('New LP - edit item prereq action triggered', 0);
- if (!$lp_found) { error_log('New LP - No learnpath given for edit item prereq', 0); require 'lp_list.php'; }
- else {
- if (isset($_POST['submit_button'])) {
- //Updating the lp.modified_on
- $_SESSION['oLP']->set_modified_on();
- $_SESSION['refresh'] = 1;
- $_SESSION['oLP']->edit_item_prereq($_GET['id'], $_POST['prerequisites'], $_POST['min_' . $_POST['prerequisites']], $_POST['max_' . $_POST['prerequisites']]);
- }
- require 'lp_edit_item_prereq.php';
- }
- break;
- case 'move_item':
- if (!$is_allowed_to_edit) {
- api_not_allowed(true);
- }
- if ($debug > 0) error_log('New LP - move item action triggered', 0);
- if (!$lp_found) { error_log('New LP - No learnpath given for move item', 0); require 'lp_list.php'; }
- else {
- $_SESSION['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']);
- $is_success = true;
- }
- 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 ($debug > 0) error_log('New LP - view_item action triggered', 0);
- if (!$lp_found) {
- error_log('New LP - No learnpath given for view item', 0); require 'lp_list.php';
- } else {
- $_SESSION['refresh'] = 1;
- require 'lp_view_item.php';
- }
- break;
- case 'upload':
- if (!$is_allowed_to_edit) {
- api_not_allowed(true);
- }
- if ($debug > 0) error_log('New LP - upload action triggered', 0);
- $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 'export':
- if (!$is_allowed_to_edit) {
- api_not_allowed(true);
- }
- if ($debug > 0) error_log('New LP - export action triggered', 0);
- if (!$lp_found) { error_log('New LP - No learnpath given for export', 0); require 'lp_list.php'; }
- else {
- $_SESSION['oLP']->scorm_export();
- exit();
- //require 'lp_list.php';
- }
- break;
- case 'export_to_pdf':
-
- if (!learnpath::is_lp_visible_for_student($_SESSION['oLP']->lp_id, api_get_user_id())) {
- api_not_allowed();
- }
-
- if ($debug > 0) error_log('New LP - export action triggered', 0);
- if (!$lp_found) { error_log('New LP - No learnpath given for export_to_pdf', 0); require 'lp_list.php';
- } else {
- $result = $_SESSION['oLP']->scorm_export_to_pdf($_GET['lp_id']);
- if (!$result) {
- require 'lp_list.php';
- }
- exit;
- }
- break;
- case 'delete':
- if (!$is_allowed_to_edit) {
- api_not_allowed(true);
- }
- if ($debug > 0) error_log('New LP - delete action triggered', 0);
- if (!$lp_found) { error_log('New LP - No learnpath given for delete', 0); require 'lp_list.php'; }
- else {
- $_SESSION['refresh'] = 1;
- // Remove lp from homepage if it is there.
- //$_SESSION['oLP']->toggle_visibility((int)$_GET['lp_id'],'i');
- $_SESSION['oLP']->delete(null,(int)$_GET['lp_id'],'remove');
- api_session_unregister('oLP');
- require 'lp_list.php';
- }
- break;
- case 'toggle_visible': // Change lp visibility (inside lp tool).
- if (!$is_allowed_to_edit) {
- api_not_allowed(true);
- }
- if ($debug > 0) error_log('New LP - visibility action triggered', 0);
- if (!$lp_found) { error_log('New LP - No learnpath given for visibility', 0); require 'lp_list.php'; }
- else {
- learnpath::toggle_visibility($_REQUEST['lp_id'], $_REQUEST['new_status']);
- 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 ($debug > 0) error_log('New LP - publish action triggered', 0);
- if (!$lp_found) { error_log('New LP - No learnpath given for publish', 0); require 'lp_list.php'; }
- else {
- learnpath::toggle_publish($_REQUEST['lp_id'],$_REQUEST['new_status']);
- 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 ($debug > 0) error_log('New LP - publish action triggered', 0);
- if (!$lp_found) {
- error_log('New LP - No learnpath given for publish', 0);
- require 'lp_list.php';
- } else {
- learnpath::move_up($_REQUEST['lp_id']);
- 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 ($debug > 0) error_log('New LP - publish action triggered', 0);
- if (!$lp_found) {
- error_log('New LP - No learnpath given for publish', 0);
- require 'lp_list.php';
- } else {
- learnpath::move_down($_REQUEST['lp_id']);
- require 'lp_list.php';
- }
- break;
- case 'edit':
- if (!$is_allowed_to_edit) {
- api_not_allowed(true);
- }
- if ($debug > 0) error_log('New LP - edit action triggered', 0);
- if (!$lp_found) { error_log('New LP - No learnpath given for edit', 0); require 'lp_list.php'; }
- else {
- $_SESSION['refresh'] = 1;
- require 'lp_edit.php';
- }
- break;
- case 'update_lp':
- if (!$is_allowed_to_edit) {
- api_not_allowed(true);
- }
- if ($debug > 0) error_log('New LP - update_lp action triggered', 0);
- if (!$lp_found) { error_log('New LP - No learnpath given for edit', 0); require 'lp_list.php'; }
- else {
- $_SESSION['refresh'] = 1;
- $lp_name = Security::remove_XSS($_REQUEST['lp_name']);
- $_SESSION['oLP']->set_name($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);
- //$author_fixed = $author;
- $_SESSION['oLP']->set_author($author_fixed);
- $_SESSION['oLP']->set_encoding($_REQUEST['lp_encoding']); // TODO (as of Chamilo 1.8.8): Check in the future whether this field is needed.
- $_SESSION['oLP']->set_maker($_REQUEST['lp_maker']);
- $_SESSION['oLP']->set_proximity($_REQUEST['lp_proximity']);
- $_SESSION['oLP']->set_theme($_REQUEST['lp_theme']);
- $_SESSION['oLP']->set_hide_toc_frame($_REQUEST['hide_toc_frame']);
- $_SESSION['oLP']->set_prerequisite($_REQUEST['prerequisites']);
- $_SESSION['oLP']->set_use_max_score($_REQUEST['use_max_score']);
-
- if (isset($_REQUEST['activate_start_date_check']) && $_REQUEST['activate_start_date_check'] == 1) {
- $publicated_on = $_REQUEST['publicated_on'];
- $publicated_on = $publicated_on['Y'].'-'.$publicated_on['F'].'-'.$publicated_on['d'].' '.$publicated_on['H'].':'.$publicated_on['i'].':00';
- } else {
- $publicated_on = null;
- }
-
- if (isset($_REQUEST['activate_end_date_check']) && $_REQUEST['activate_end_date_check'] == 1) {
- $expired_on = $_REQUEST['expired_on'];
- $expired_on = $expired_on['Y'].'-'.$expired_on['F'].'-'.$expired_on['d'].' '.$expired_on['H'].':'.$expired_on['i'].':00';
- } else {
- $expired_on = null;
- }
- $_SESSION['oLP']->set_modified_on();
- $_SESSION['oLP']->set_publicated_on($publicated_on);
- $_SESSION['oLP']->set_expired_on($expired_on);
- if ($_REQUEST['remove_picture']) {
- $_SESSION['oLP']->delete_lp_image();
- }
- if ($_FILES['lp_preview_image']['size'] > 0)
- $_SESSION['oLP']->upload_image($_FILES['lp_preview_image']);
- 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);
- }
- }
- }
- }
- }
- require 'lp_build.php';
- }
- break;
- case 'add_sub_item': // Add an item inside a chapter.
- if (!$is_allowed_to_edit) {
- api_not_allowed(true);
- }
- if ($debug > 0) error_log('New LP - add sub item action triggered', 0);
- if (!$lp_found) { error_log('New LP - No learnpath given for add sub item', 0); require 'lp_list.php'; }
- else {
- $_SESSION['refresh'] = 1;
- if (!empty($_REQUEST['parent_item_id'])) {
- $_SESSION['from_learnpath']='yes';
- $_SESSION['origintoolurl'] = 'lp_controller.php?action=admin_view&lp_id='.Security::remove_XSS($_REQUEST['lp_id']);
- require 'resourcelinker.php';
- //$_SESSION['oLP']->add_sub_item($_REQUEST['parent_item_id'], $_REQUEST['previous'], $_REQUEST['type'], $_REQUEST['path'], $_REQUEST['title']);
- } else {
- require 'lp_admin_view.php';
- }
- }
- break;
- case 'deleteitem':
- case 'delete_item':
- if (!$is_allowed_to_edit) {
- api_not_allowed(true);
- }
- if ($debug > 0) error_log('New LP - delete item action triggered', 0);
- if (!$lp_found) { error_log('New LP - No learnpath given for delete item', 0); require 'lp_list.php'; }
- else {
- $_SESSION['refresh'] = 1;
- if (!empty($_REQUEST['id'])) {
- $_SESSION['oLP']->delete_item($_REQUEST['id']);
- }
- require 'lp_admin_view.php';
- }
- break;
- case 'edititemprereq':
- case 'edit_item_prereq':
- if (!$is_allowed_to_edit) {
- api_not_allowed(true);
- }
- if ($debug > 0) error_log('New LP - edit item prereq action triggered', 0);
- if (!$lp_found) { error_log('New LP - No learnpath given for edit item prereq', 0); require 'lp_list.php'; }
- else {
- if (!empty($_REQUEST['id']) && !empty($_REQUEST['submit_item'])) {
- $_SESSION['refresh'] = 1;
- $_SESSION['oLP']->edit_item_prereq($_REQUEST['id'], $_REQUEST['prereq']);
- }
- require 'lp_admin_view.php';
- }
- break;
- case 'restart':
- if ($debug > 0) error_log('New LP - restart action triggered', 0);
- if (!$lp_found) { error_log('New LP - No learnpath given for restart', 0); require 'lp_list.php'; }
- else {
- $_SESSION['oLP']->restart();
- require 'lp_view.php';
- }
- break;
- case 'last':
- if ($debug > 0) error_log('New LP - last action triggered', 0);
- if (!$lp_found) { error_log('New LP - No learnpath given for last', 0); require 'lp_list.php'; }
- else {
- $_SESSION['oLP']->last();
- require 'lp_view.php';
- }
- break;
- case 'first':
- if ($debug > 0) error_log('New LP - first action triggered', 0);
- if (!$lp_found) { error_log('New LP - No learnpath given for first', 0); require 'lp_list.php'; }
- else {
- $_SESSION['oLP']->first();
- require 'lp_view.php';
- }
- break;
- case 'next':
- if ($debug > 0) error_log('New LP - next action triggered', 0);
- if (!$lp_found) { error_log('New LP - No learnpath given for next', 0); require 'lp_list.php'; }
- else {
- $_SESSION['oLP']->next();
- require 'lp_view.php';
- }
- break;
- case 'previous':
- if ($debug > 0) error_log('New LP - previous action triggered', 0);
- if (!$lp_found) { error_log('New LP - No learnpath given for previous', 0); require 'lp_list.php'; }
- else {
- $_SESSION['oLP']->previous();
- require 'lp_view.php';
- }
- break;
- case 'content':
- if ($debug > 0) error_log('New LP - content action triggered', 0);
- if ($debug > 0) error_log('New LP - Item id is '.$_GET['item_id'], 0);
- if (!$lp_found) { error_log('New LP - No learnpath given for content', 0); 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 ($debug > 0)
- error_log('New LP - view action triggered', 0);
- if (!$lp_found) {
- error_log('New LP - No learnpath given for view', 0);
- require 'lp_list.php';
- } else {
- if ($debug > 0) {error_log('New LP - Trying to set current item to ' . $_REQUEST['item_id'], 0); }
- if ( !empty($_REQUEST['item_id']) ) {
- $_SESSION['oLP']->set_current_item($_REQUEST['item_id']);
- }
- require 'lp_view.php';
- }
- break;
- case 'save':
- if ($debug > 0) error_log('New LP - save action triggered', 0);
- if (!$lp_found) { error_log('New LP - No learnpath given for save', 0); require 'lp_list.php'; }
- else {
- $_SESSION['oLP']->save_item();
- require 'lp_save.php';
- }
- break;
- case 'stats':
- if ($debug > 0) error_log('New LP - stats action triggered', 0);
- if (!$lp_found) { error_log('New LP - No learnpath given for stats', 0); require 'lp_list.php'; }
- else {
- $_SESSION['oLP']->save_current();
- $_SESSION['oLP']->save_last();
- // Declare variables to be used in lp_stats.php.
- $lp_id = $_SESSION['oLP']->get_id();
- $list = $_SESSION['oLP']->get_flat_ordered_items_list($lp_id);
- $user_id = api_get_user_id();
- require 'lp_stats.php';
- }
- break;
- case 'list':
- if ($debug > 0) error_log('New LP - list action triggered', 0);
- if ($lp_found) {
- $_SESSION['refresh'] = 1;
- $_SESSION['oLP']->save_last();
- }
- require 'lp_list.php';
- break;
- case 'mode':
- // Switch between fullscreen and embedded mode.
- if ($debug > 0) error_log('New LP - mode change triggered', 0);
- $mode = $_REQUEST['mode'];
- if ($mode == 'fullscreen') {
- $_SESSION['oLP']->mode = 'fullscreen';
- } elseif ($mode == 'embedded') {
- $_SESSION['oLP']->mode = 'embedded';
- } elseif ($mode == 'embedframe') {
- $_SESSION['oLP']->mode = 'embedframe';
- }
- require 'lp_view.php';
- break;
- case 'switch_view_mode':
- if ($debug > 0) error_log('New LP - switch_view_mode action triggered', 0);
- if (!$lp_found) { error_log('New LP - No learnpath given for switch', 0); require 'lp_list.php'; }
- $_SESSION['refresh'] = 1;
- $_SESSION['oLP']->update_default_view_mode();
- require 'lp_list.php';
- break;
- case 'switch_force_commit':
- if ($debug > 0) error_log('New LP - switch_force_commit action triggered', 0);
- if (!$lp_found) { error_log('New LP - No learnpath given for switch', 0); require 'lp_list.php'; }
- $_SESSION['refresh'] = 1;
- $_SESSION['oLP']->update_default_scorm_commit();
- require 'lp_list.php';
- break;
- /* Those 2 switches have been replaced by switc_attempt_mode switch
- case 'switch_reinit':
- if ($debug > 0) error_log('New LP - switch_reinit action triggered', 0);
- if (!$lp_found) { error_log('New LP - No learnpath given for switch', 0); require 'lp_list.php'; }
- $_SESSION['refresh'] = 1;
- $_SESSION['oLP']->update_reinit();
- require 'lp_list.php';
- break;
- case 'switch_seriousgame_mode':
- if($debug>0) error_log('New LP - switch_seriousgame_mode action triggered',0);
- if(!$lp_found){ error_log('New LP - No learnpath given for switch',0); require 'lp_list.php'; }
- $_SESSION['refresh'] = 1;
- $_SESSION['oLP']->set_seriousgame_mode();
- require 'lp_list.php';
- break;
- */
- case 'switch_attempt_mode':
- if($debug>0) error_log('New LP - switch_reinit action triggered',0);
- if(!$lp_found){ error_log('New LP - No learnpath given for switch',0); require 'lp_list.php'; }
- $_SESSION['refresh'] = 1;
- $_SESSION['oLP']->switch_attempt_mode();
- require 'lp_list.php';
- break;
- case 'switch_scorm_debug':
- if ($debug > 0) error_log('New LP - switch_scorm_debug action triggered', 0);
- if (!$lp_found) { error_log('New LP - No learnpath given for switch', 0); require 'lp_list.php'; }
- $_SESSION['refresh'] = 1;
- $_SESSION['oLP']->update_scorm_debug();
- require 'lp_list.php';
- break;
- case 'intro_cmdAdd':
- if ($debug > 0) error_log('New LP - intro_cmdAdd action triggered', 0);
- // Add introduction section page.
- break;
- case 'js_api_refresh':
- if ($debug > 0) error_log('New LP - js_api_refresh action triggered', 0);
- if (!$lp_found) { error_log('New LP - No learnpath given for js_api_refresh', 0); require 'lp_message.php'; }
- if (isset($_REQUEST['item_id'])) {
- $htmlHeadXtra[] = $_SESSION['oLP']->get_js_info($_REQUEST['item_id']);
- }
- require 'lp_message.php';
- break;
- case 'return_to_course_homepage':
- if (!$lp_found) { error_log('New LP - No learnpath given for stats', 0); require 'lp_list.php'; }
- else {
- $_SESSION['oLP']->save_current();
- $_SESSION['oLP']->save_last();
- // Declare variables to be used in lp_stats.php.
- $lp_id = $_SESSION['oLP']->get_id();
- $list = $_SESSION['oLP']->get_flat_ordered_items_list($lp_id);
- $user_id = api_get_user_id();
- header('location: '.api_get_path(WEB_COURSE_PATH).api_get_course_path().'/?id_session='.api_get_session_id());
- }
- 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;
- default:
- if ($debug > 0) error_log('New LP - default action triggered', 0);
- //$_SESSION['refresh'] = 1;
- require 'lp_list.php';
- break;
- }
- if (!empty($_SESSION['oLP'])) {
- $_SESSION['lpobject'] = serialize($_SESSION['oLP']);
- if ($debug > 0) error_log('New LP - lpobject is serialized in session', 0);
- }
|