Source for file lp_controller.php
Documentation is available at lp_controller.php
* Controller script. Prepares the common background variables to give to the scripts corresponding to
* @package dokeos.learnpath
* @author Yannick Warnier <ywarnier@beeznest.org>
if($debug> 0) error_log('New LP -+- Entered lp_controller.php -+-',0);
// name of the language file that needs to be included
if (isset ($_GET['action']))
if($_GET['action'] == 'export')
{ //only needed on export
$language_file[] = 'hotspot';
$language_file[] = 'exercice';
$language_file[] = "course_home";
$language_file[] = "scormdocument";
$language_file[] = "scorm";
$language_file[] = "learnpath";
$language_file[] = 'resourcelinker';
//flag to allow for anonymous user - needs to be set before global.inc.php
//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);
if ($is_allowed_in_course == false){
require_once(api_get_path(LIBRARY_PATH) . "/fckeditor/fckeditor.php");
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)
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'])){
$lp_controller_touched = 1;
if(isset ($_SESSION['lpobject']))
if($debug> 0) error_log('New LP - SESSION[lpobject] is defined',0);
if($debug> 0) error_log('New LP - oLP is object',0);
if($debug> 0) error_log('New LP - Course has changed, discard lp object',0);
if($myrefresh == 1){$myrefresh_id = $oLP->get_id();}
if($debug> 0) error_log('New LP - Passed data remains check',0);
|| ($_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
if(!empty($_REQUEST['lp_id'])){
$sel = "SELECT * FROM $lp_table WHERE id = $lp_id";
if($debug> 0) error_log('New LP - querying '. $sel,0);
if($oLP !== false){ $lp_found = true; }else{eror_log($oLP->error,0);}
if($oLP !== false){ $lp_found = true; }else{eror_log($oLP->error,0);}
if($oLP !== false){ $lp_found = true; }else{eror_log($oLP->error,0);}
if($oLP !== false){ $lp_found = true; }else{eror_log($oLP->error,0);}
if($debug> 0) error_log('New LP - Request[lp_id] and refresh_id were empty',0);
if($debug> 0) error_log('New LP - Passed oLP creation check',0);
$_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
$fck_attribute['Width'] = '100%';
$fck_attribute['Height'] = '950';
$fck_attribute['ToolbarSet'] = 'Full';
$fck_attribute['Config']['FullPage'] = true;
if($_GET['isStudentView'] == 'true')
if($_REQUEST['action'] != 'list' AND $_REQUEST['action'] != 'view')
if(!empty($_REQUEST['lp_id']))
$_REQUEST['action'] = 'view';
$_REQUEST['action'] = 'list';
switch($_REQUEST['action'])
if($debug > 0) error_log('New LP - add item action triggered', 0);
{ //check if the learnpath ID was defined, otherwise send back to list
error_log('New LP - No learnpath given for add item', 0);
$_SESSION['refresh'] = 1;
if(isset ($_POST['submit_button']) && !empty($_POST['title']))
{ //if a title was sumbitted
if(isset ($_SESSION['post_time']) && $_SESSION['post_time'] == $_POST['post_time'])
{ //check post_time to ensure ??? (counter-hacking measure?)
require ('lp_add_item.php');
$_SESSION['post_time'] = $_POST['post_time'];
if(isset ($_POST['path']) && $_GET['edit'] != 'true')
$document_id = $_POST['path'];
$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']);
{ //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']);
require ('lp_add_item.php');
require ('lp_add_item.php');
if($debug > 0) error_log('New LP - add_lp action triggered', 0);
$_REQUEST['learnpath_name'] = trim($_REQUEST['learnpath_name']);
if(!empty($_REQUEST['learnpath_name']))
$_SESSION['refresh'] = 1;
if(isset ($_SESSION['post_time']) && $_SESSION['post_time'] == $_REQUEST['post_time'])
$_SESSION['post_time'] = $_REQUEST['post_time'];
//Kevin Van Den Haute: changed $_REQUEST['learnpath_description'] by '' because it's not used
//old->$new_lp_id = learnpath::add_lp(api_get_course_id(), $_REQUEST['learnpath_name'], $_REQUEST['learnpath_description'], 'dokeos', 'manual', '');
//learnpath::toggle_visibility($new_lp_id,'v');
//Kevin Van Den Haute: only go further if learnpath::add_lp has returned an id
//TODO maybe create a first module directly to avoid bugging the user with useless queries
//$_SESSION['oLP']->add_item(0,-1,'dokeos_chapter',$_REQUEST['path'],'Default');
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'); }
$_SESSION['refresh'] = 1;
require ('lp_admin_view.php');
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'); }
$_SESSION['refresh'] = 1;
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'); }
$_SESSION['refresh'] = 1;
$_SESSION['oLP']->delete_item($_GET['id']);
if(isset ($_GET['view']) && $_GET['view'] == 'build')
require ('lp_admin_view.php');
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'); }
$_SESSION['refresh'] = 1;
if(isset ($_POST['submit_button']) && !empty($_POST['title']))
$_SESSION['oLP']->edit_item($_GET['id'], $_POST['parent'], $_POST['previous'], $_POST['title'], $_POST['description'], $_POST['prerequisites']);
if(isset ($_POST['content_lp']))
$_SESSION['oLP']->edit_document($_course);
if(isset ($_GET['view']) && $_GET['view'] == 'build')
require ('lp_edit_item.php');
require ('lp_admin_view.php');
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'); }
if(isset ($_POST['submit_button']))
$_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');
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'); }
$_SESSION['refresh'] = 1;
if(isset ($_POST['submit_button']))
$_SESSION['oLP']->edit_item($_GET['id'], $_POST['parent'], $_POST['previous'], $_POST['title'], $_POST['description']);
if(isset ($_GET['view']) && $_GET['view'] == 'build')
require ('lp_move_item.php');
$_SESSION['oLP']->move_item($_GET['id'], $_GET['direction']);
require ('lp_admin_view.php');
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'); }
$_SESSION['refresh'] = 1;
require ('lp_view_item.php');
if($debug> 0) error_log('New LP - upload action triggered',0);
require ('lp_upload.php');
//reinit current working directory as many functions in upload change it
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'); }
$_SESSION['oLP']->scorm_export();
//require('lp_list.php');
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'); }
$_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');
case 'toggle_visible': //change lp visibility (inside lp tool)
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'); }
case 'toggle_publish': //change lp published status (visibility on homepage)
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'); }
case 'move_lp_up': //change lp published status (visibility on homepage)
if($debug> 0) error_log('New LP - publish action triggered',0);
error_log('New LP - No learnpath given for publish',0);
case 'move_lp_down': //change lp published status (visibility on homepage)
if($debug> 0) error_log('New LP - publish action triggered',0);
error_log('New LP - No learnpath given for publish',0);
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'); }
$_SESSION['refresh'] = 1;
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'); }
$_SESSION['refresh'] = 1;
$_SESSION['oLP']->set_name($_REQUEST['lp_name']);
$_SESSION['oLP']->set_encoding($_REQUEST['lp_encoding']);
$_SESSION['oLP']->set_maker($_REQUEST['lp_maker']);
$_SESSION['oLP']->set_proximity($_REQUEST['lp_proximity']);
$_SESSION['oLP']->set_theme($_REQUEST['lp_theme']);
case 'add_sub_item': //add an item inside a chapter
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'); }
$_SESSION['refresh'] = 1;
if(!empty($_REQUEST['parent_item_id'])){
$_SESSION['from_learnpath']= 'yes';
$_SESSION['origintoolurl'] = 'lp_controller.php?action=admin_view&lp_id='. $_REQUEST['lp_id'];
require ('resourcelinker.php');
//$_SESSION['oLP']->add_sub_item($_REQUEST['parent_item_id'],$_REQUEST['previous'],$_REQUEST['type'],$_REQUEST['path'],$_REQUEST['title']);
require ('lp_admin_view.php');
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'); }
$_SESSION['refresh'] = 1;
if(!empty($_REQUEST['id'])){
$_SESSION['oLP']->delete_item($_REQUEST['id']);
require ('lp_admin_view.php');
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'); }
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');
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'); }
$_SESSION['oLP']->restart();
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'); }
$_SESSION['oLP']->last();
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'); }
$_SESSION['oLP']->first();
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'); }
$_SESSION['oLP']->next();
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'); }
$_SESSION['oLP']->previous();
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'); }
$_SESSION['oLP']->save_last();
$_SESSION['oLP']->set_current_item($_GET['item_id']);
$_SESSION['oLP']->start_current_item();
require ('lp_content.php');
error_log('New LP - view action triggered', 0);
error_log('New LP - No learnpath given for view', 0);
if($debug > 0){error_log('New LP - Trying to set current item to ' . $_REQUEST['item_id'], 0);}
$_SESSION['oLP']->set_current_item($_REQUEST['item_id']);
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'); }
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'); }
$_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);
$stats_charset = $_SESSION['oLP']->encoding;
if($debug> 0) error_log('New LP - list action triggered',0);
$_SESSION['refresh'] = 1;
$_SESSION['oLP']->save_last();
//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';
$_SESSION['oLP']->mode = 'embedded';
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();
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();
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();
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();
if($debug> 0) error_log('New LP - intro_cmdAdd action triggered',0);
//add introduction section page
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');
case 'return_to_course_homepage':
if(!$lp_found){ error_log('New LP - No learnpath given for stats',0); require ('lp_list.php'); }
$_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);
$stats_charset = $_SESSION['oLP']->encoding;
if($debug> 0) error_log('New LP - default action triggered',0);
//$_SESSION['refresh'] = 1;
if(!empty($_SESSION['oLP'])){
$_SESSION['lpobject'] = serialize($_SESSION['oLP']);
if($debug> 0) error_log('New LP - lpobject is serialized in session',0);
|