Source for file learnpath.class.php
Documentation is available at learnpath.class.php
* This (abstract?) class defines the parent attributes and methods for the dokeos learnpaths and scorm
* learnpaths. It is used by the scorm class as well as the dokeos_lp class.
* @package dokeos.learnpath
* @author Yannick Warnier <ywarnier@beeznest.org>
* @license GNU/GPL - See Dokeos license directory for details
* Defines the learnpath parent class
* @package dokeos.learnpath
var $attempt = 0; //the number for the current ID view
var $cc; //course (code) this learnpath is located in
var $current; //id of the current item the user is viewing
var $current_time_start; //the time the user loaded this resource (this does not mean he can see it yet)
var $extra_information = ''; //this string can be used by proprietary SCORM contents to store data about the current learnpath
var $force_commit = false; //for SCORM only - if set to true, will send a scorm LMSCommit() request on each LMSSetValue()
var $index; //the index of the active learnpath_item in $ordered_items array
var $last; //item_id of last item viewed in the learning path
var $last_item_seen = 0; //in case we have already come in this learnpath, reuse the last item seen if authorized
var $license; //which license this course has been given - not used yet on 20060522
var $lp_id; //DB ID for this learnpath
var $log_file; //file where to log learnpath API msg
var $maker; //which maker has conceived the content (ENI, Articulate, ...)
var $mode= 'embedded'; //holds the video display mode (fullscreen or embedded)
var $name; //learnpath name (they generally have one)
var $ordered_items = array(); //list of the learnpath items in the order they are to be read
var $path = ''; //path inside the scorm directory (if scorm)
var $theme; // the current theme of the learning path
// Tells if all the items of the learnpath can be tried again. Defaults to "no" (=1)
// Describes the mode of progress bar display
// Percentage progress as saved in the db
var $proximity; //wether the content is distant or local or unknown
var $refs_list = array(); //list of items by ref => db_id. Used only for prerequisites match.
//!!!This array (refs_list) is built differently depending on the nature of the LP.
//If SCORM, uses ref, if Dokeos, uses id to keep a unique value
var $type; //type of learnpath. Could be 'dokeos', 'scorm', 'scorm2004', 'aicc', ...
//TODO check if this type variable is useful here (instead of just in the controller script)
var $user_id; //ID of the user that is viewing/using the course
var $arrMenu = array(); //array for the menu items
var $debug = 0; //logging level
* Class constructor. Needs a database handler, a course code and a learnpath id from the database.
* Also builds the list of items into $this->items.
* @param string Course code
* @param integer Learnpath ID
* @return boolean True on success, false on error
function learnpath($course, $lp_id, $user_id) {
if($this->debug> 0){error_log('New LP - In learnpath::learnpath('. $course. ','. $lp_id. ','. $user_id. ')',0);}
$this->error = 'Course code is empty';
//$course = Database::escape_string($course);
$sql = "SELECT * FROM $main_table WHERE code = '$course'";
if($this->debug> 2){error_log('New LP - learnpath::learnpath() '.__LINE__. ' - Querying course: '. $sql,0);}
//$res = Database::query($sql);
$this->error = 'Course code does not exist in database ('. $sql. ')';
$this->error = 'Learnpath ID is empty';
//TODO make it flexible to use any course_code (still using env course code here)
//$id = Database::escape_integer($id);
$sql = "SELECT * FROM $lp_table WHERE id = '$lp_id'";
if($this->debug> 2){error_log('New LP - learnpath::learnpath() '.__LINE__. ' - Querying lp: '. $sql,0);}
//$res = Database::query($sql);
$this->type = $row['lp_type'];
$this->encoding = $row['default_encoding'];
$this->theme = $row['theme'];
$this->maker = $row['content_maker'];
$this->license = $row['content_license'];
$this->js_lib = $row['js_lib'];
$this->path = $row['path'];
if($row['force_commit'] == 1){
$this->mode = $row['default_view_mod'];
$this->error = 'Learnpath ID does not exist in database ('. $sql. ')';
$this->error = 'User ID is empty';
//$main_table = Database::get_main_user_table();
//$user_id = Database::escape_integer($user_id);
$sql = "SELECT * FROM $main_table WHERE user_id = '$user_id'";
if($this->debug> 2){error_log('New LP - learnpath::learnpath() '.__LINE__. ' - Querying user: '. $sql,0);}
//$res = Database::query($sql);
$this->error = 'User ID does not exist in database ('. $sql. ')';
//end of variables checking
//now get the latest attempt from this user on this LP, if available, otherwise create a new one
//selecting by view_count descending allows to get the highest view_count first
$sql = "SELECT * FROM $lp_table WHERE lp_id = '$lp_id' AND user_id = '$user_id' ORDER BY view_count DESC";
if($this->debug> 2){error_log('New LP - learnpath::learnpath() '.__LINE__. ' - querying lp_view: '. $sql,0);}
//$res = Database::query($sql);
$view_id = 0; //used later to query lp_item_view
if($this->debug> 2){error_log('New LP - learnpath::learnpath() '.__LINE__. ' - Found previous view',0);}
$this->attempt = $row['view_count'];
if($this->debug> 2){error_log('New LP - learnpath::learnpath() '.__LINE__. ' - NOT Found previous view',0);}
$sql_ins = "INSERT INTO $lp_table (lp_id,user_id,view_count) VALUES ($lp_id,$user_id,1)";
if($this->debug> 2){error_log('New LP - learnpath::learnpath() '.__LINE__. ' - inserting new lp_view: '. $sql_ins,0);}
$sql = "SELECT * FROM $lp_item_table WHERE lp_id = '". $this->lp_id. "' ORDER BY parent_item_id, display_order";
//$this->ordered_items[] = $row['id'];
$my_item_id = $oItem->get_id();
// Don't use reference here as the next loop will make the pointed object change
$this->items[$my_item_id] = $oItem;
if($this->debug> 2){error_log('New LP - learnpath::learnpath() - aicc object with id '. $my_item_id. ' set in items[]',0);}
require_once('scorm.class.php');
require_once('scormItem.class.php');
$my_item_id = $oItem->get_id();
// Don't use reference here as the next loop will make the pointed object change
$this->items[$my_item_id] = $oItem;
if($this->debug> 2){error_log('New LP - object with id '. $my_item_id. ' set in items[]',0);}
require_once('learnpathItem.class.php');
$my_item_id = $oItem->get_id();
//$oItem->set_lp_view($this->lp_view_id); moved down to when we are sure the item_view exists
// Don't use reference here as the next loop will make the pointed object change
$this->items[$my_item_id] = $oItem;
if($this->debug> 2){error_log('New LP - learnpath::learnpath() '.__LINE__. ' - object with id '. $my_item_id. ' set in items[]',0);}
//items is a list of pointers to all items, classified by DB ID, not SCO id
if($row['parent_item_id'] == 0 OR empty($this->items[$row['parent_item_id']])){
$this->items[$row['id']]->set_level(0);
$level = $this->items[$row['parent_item_id']]->get_level()+ 1;
$this->items[$row['id']]->set_level($level);
//items is a list of pointers from item DB ids to item objects
$this->items[$row['parent_item_id']]->add_child($row['id']);
if($this->debug> 2){error_log('New LP - learnpath::learnpath() '.__LINE__. ' - The parent item ('. $row['parent_item_id']. ') of item '. $row['id']. ' could not be found',0);}
//this query should only return one or zero result
"FROM $lp_item_view_table " .
"AND lp_item_id = ". $row['id']. " ORDER BY view_count DESC ";
if($this->debug> 2){error_log('New LP - learnpath::learnpath() - Selecting item_views: '. $sql,0);}
//if this learnpath has already been used by this user, get his last attempt count and
//the last item seen back into this object
if($this->debug> 2){error_log('New LP - learnpath::learnpath() - Got item_view: '. print_r($row2,true),0);}
$this->items[$row['id']]->set_status($row2['status']);
if(empty($row2['status'])){
//$this->attempt = $row['view_count'];
//$this->last_item = $row['id'];
else //no item found in lp_item_view for this view
//first attempt from this user. Set attempt to 1 and last_item to 0 (first item available)
//TODO if the learnpath has not got attempts activated, always use attempt '1'
//Add that row to the lp_item_view table so that we have something to show in the stats page
$sql_ins = "INSERT INTO $lp_item_view_table " .
"(lp_item_id, lp_view_id, view_count, status) VALUES " .
"(". $row['id']. ",". $this->lp_view_id. ",1,'not attempted')";
if($this->debug> 2){error_log('New LP - learnpath::learnpath() '.__LINE__. ' - Inserting blank item_view : '. $sql_ins,0);}
//setting the view in the item object
$this->max_ordered_items = 0;
if($index > $this->max_ordered_items AND !empty($dummy)){
$this->max_ordered_items = $index;
//TODO define the current item better
if($this->debug> 2){error_log('New LP - learnpath::learnpath() '.__LINE__. ' - End of learnpath constructor for learnpath '. $this->get_id(),0);}
* Function rewritten based on old_add_item() from Yannick Warnier. Due the fact that users can decide where the item should come, I had to overlook this function and
* I found it better to rewrite it. Old function is still available. Added also the possibility to add a description.
* @param string $description
function add_item($parent, $previous, $type = 'dokeos_chapter', $id, $title, $description, $prerequisites= 0)
if($this->debug> 0){error_log('New LP - In learnpath::add_item('. $parent. ','. $previous. ','. $type. ','. $id. ','. $title. ')',0);}
$previous = intval($previous);
FROM " . $tbl_lp_item . "
lp_id = " . $this->get_id() . " AND
parent_item_id = " . $parent;
FROM " . $tbl_lp_item . "
lp_id = " . $this->get_id() . " AND
parent_item_id = " . $parent . " AND
previous_item_id = 0 OR previous_item_id=". $parent;
$previous = (int) $previous;
FROM " . $tbl_lp_item . "
lp_id = " . $this->get_id() . " AND
$tmp_previous = $row['id'];
$next = $row['next_item_id'];
$display_order = $row['display_order'];
$sql = 'SELECT SUM(ponderation)
ON quiz_question.id = quiz_rel_question.question_id
AND quiz_rel_question.exercice_id = '. $id;
INSERT INTO " . $tbl_lp_item . " (
" . ($display_order + 1) . ",
INSERT INTO " . $tbl_lp_item . " (
" . ($display_order + 1) . "
if($this->debug> 2){error_log('New LP - Inserting dokeos_chapter: '. $sql_ins,0);}
//update the item that should come after the new item
UPDATE " . $tbl_lp_item . "
SET previous_item_id = " . $new_item_id . "
$res_update_next = api_sql_query($sql_update_next, __FILE__ , __LINE__ );
//update the item that should be before the new item
UPDATE " . $tbl_lp_item . "
SET next_item_id = " . $new_item_id . "
WHERE id = " . $tmp_previous;
$res_update_previous = api_sql_query($sql_update_previous, __FILE__ , __LINE__ );
//update all the items after the new item
UPDATE " . $tbl_lp_item . "
SET display_order = display_order + 1
lp_id = " . $this->get_id() . " AND
id <> " . $new_item_id . " AND
parent_item_id = " . $parent . " AND
display_order > " . $display_order;
$res_update_previous = api_sql_query($sql_update_order, __FILE__ , __LINE__ );
//update the item that should come after the new item
UPDATE " . $tbl_lp_item . "
SET ref = " . $new_item_id . "
WHERE id = " . $new_item_id;
* Static admin function allowing addition of a learnpath to a course.
* @param string Course code
* @param string Learnpath name
* @param string Learnpath description string, if provided
* @param string Type of learnpath (default = 'guess', others = 'dokeos', 'aicc',...)
* @param string Type of files origin (default = 'zip', others = 'dir','web_dir',...)
* @param string Zip file containing the learnpath or directory containing the learnpath
* @return integer The new learnpath ID on success, 0 on failure
function add_lp($course,$name,$description= '',$learnpath= 'guess',$origin= 'zip',$zipname= '')
//if($this->debug>0){error_log('New LP - In learnpath::add_lp()',0);}
//check course code exists
//check lp_name doesn't exist, otherwise append something
$check_name = "SELECT * FROM $tbl_lp WHERE name = '$name'";
//if($this->debug>2){error_log('New LP - Checking the name for new LP: '.$check_name,0);}
//there is already one such name, update the current one a bit
$check_name = "SELECT * FROM $tbl_lp WHERE name = '$name'";
//if($this->debug>2){error_log('New LP - Checking the name for new LP: '.$check_name,0);}
//new name does not exist yet; keep it
//check zipname string. If empty, we are currently creating a new Dokeos learnpath
$get_max = "SELECT MAX(display_order) FROM $tbl_lp";
$sql_insert = "INSERT INTO $tbl_lp " .
"(lp_type,name,description,path,default_view_mod," .
"default_encoding,display_order,content_maker," .
"content_local,js_lib) " .
"VALUES ($type,'$name','$description','','embedded'," .
"'UTF-8','$dsp','Dokeos'," .
//if($this->debug>2){error_log('New LP - Inserting new lp '.$sql_insert,0);}
//insert into item_property
* Appends a message to the message attribute
* @param string Message to append.
if($this->debug> 0){error_log('New LP - In learnpath::append_message()',0);}
* Autocompletes the parents of an item in case it's been completed or passed
* @param integer Optional ID of the item from which to look for parents
if($this->debug> 0){error_log('New LP - In learnpath::autocomplete_parents()',0);}
$parent_id = $this->items[$item]->get_parent();
if($this->debug> 2){error_log('New LP - autocompleting parent of item '. $item. ' (item '. $parent_id. ')',0);}
{//if $item points to an object and there is a parent
if($this->debug> 2){error_log('New LP - '. $item. ' is an item, proceed',0);}
$current_item = & $this->items[$item];
$parent = & $this->items[$parent_id]; //get the parent
//new experiment including failed and browsed in completed status
$current_status = $current_item->get_status();
if($current_item->is_done() || $current_status== 'browsed' || $current_status== 'failed')
//if the current item is completed or passes or succeeded
if($this->debug> 2){error_log('New LP - Status of current item is alright',0);}
foreach($parent->get_children() as $child)
//check all his brothers (his parent's children) for completion status
if($this->debug> 2){error_log('New LP - Looking at brother with ID '. $child. ', status is '. $this->items[$child]->get_status(),0);}
//if($this->items[$child]->status_is(array('completed','passed','succeeded')))
//Trying completing parents of failed and browsed items as well
if($this->items[$child]->status_is(array('completed','passed','succeeded','browsed','failed')))
//keep completion status to true
if($this->debug> 2){error_log('New LP - Found one incomplete child of '. $parent_id. ': '. $child. ' is '. $this->items[$child]->get_status(),0);}
{ //if all the children were completed
$parent->set_status('completed');
$this->update_queue[$parent->get_id()] = $parent->get_status();
//error_log('New LP - status of current item is not enough to get bothered with it',0);
* Autosaves the current results into the database for the whole learnpath
//TODO add aditionnal save operations for the learnpath itself
* Clears the message attribute
if($this->debug> 0){error_log('New LP - In learnpath::clear_message()',0);}
* Closes the current resource
* Saves into the database if required
* Clears the current resource data from this object
* @return boolean True on success, false on failure
$this->error = 'Trying to close this learnpath but no ID is set';
$sql = "UPDATE $learnpath_view_table " .
"stop_time = ".$this->current_time_stop.", " .
"score = ".$this->current_score.", ".
"WHERE learnpath_id = '".$this->lp_id."'";
//$res = Database::query($sql);
$res = api_sql_query($res);
if(mysql_affected_rows($res)<1)
$this->error = 'Could not update learnpath_view table while closing learnpath';
* Static admin function allowing removal of a learnpath
* @param string Course code
* @param integer Learnpath ID
* @param string Whether to delete data or keep it (default: 'keep', others: 'remove')
* @return boolean True on success, false on failure (might change that to return number of elements deleted)
function delete($course= null,$id= null,$delete= 'keep')
//TODO implement a way of getting this to work when the current object is not set
//In clear: implement this in the item class as well (abstract class) and use the given ID in queries
//if(empty($course)){$course = api_get_course_id();}
//if(empty($id)){$id = $this->get_id();}
//If an ID is specifically given and the current LP is not the same,
if(!empty($id) && ($id != $this->lp_id)){return false;}
//if($this->debug>0){error_log('New LP - In learnpath::delete()',0);}
foreach($this->items as $id => $dummy)
$this->items[$id]->delete();
$sql_del_view = "DELETE FROM $lp_view WHERE lp_id = ". $this->lp_id;
//if($this->debug>2){error_log('New LP - Deleting views bound to lp '.$this->lp_id.': '.$sql_del_view,0);}
$res_del_view = api_sql_query($sql_del_view, __FILE__ , __LINE__ );
//if($this->debug>2){error_log('New LP - Deleting lp '.$this->lp_id.' of type '.$this->type,0);}
//this is a scorm learning path, delete the files as well
$sql = "SELECT path FROM $lp WHERE id = ". $this->lp_id;
$sql = "SELECT id FROM $lp WHERE path = '$path' AND id != ". $this->lp_id;
{ //another learning path uses this directory, so don't delete it
if($this->debug> 2){error_log('New LP - In learnpath::delete(), found other LP using path '. $path. ', keeping directory',0);}
//no other LP uses that directory, delete it
if($delete == 'remove' && is_dir($course_scorm_dir. $path) and !empty($course_scorm_dir)){
if($this->debug> 2){error_log('New LP - In learnpath::delete(), found SCORM, deleting directory: '. $course_scorm_dir. $path,0);}
exec('rm -rf '. $course_scorm_dir. $path);
$sql_del_lp = "DELETE FROM $lp WHERE id = ". $this->lp_id;
//if($this->debug>2){error_log('New LP - Deleting lp '.$this->lp_id.': '.$sql_del_lp,0);}
//TODO: also delete items and item-views
* Removes all the children of one item - dangerous!
* @param integer Element ID of which children have to be removed
* @return integer Total number of children removed
if($this->debug> 0){error_log('New LP - In learnpath::delete_children_items('. $id. ')',0);}
$sql = "SELECT * FROM $lp_item WHERE parent_item_id = $id";
$sql_del = "DELETE FROM $lp_item WHERE id = ". $row['id'];
* Removes an item from the current learnpath
* @param integer Elem ID (0 if first)
* @param integer Whether to remove the resource/data from the system or leave it (default: 'keep', others 'remove')
* @return integer Number of elements moved
* @todo implement resource removal
if($this->debug> 0){error_log('New LP - In learnpath::delete_item()',0);}
//TODO - implement the resource removal
//first select item to get previous, next, and display order
$sql_sel = "SELECT * FROM $lp_item WHERE id = $id";
$previous = $row['previous_item_id'];
$next = $row['next_item_id'];
$display = $row['display_order'];
$parent = $row['parent_item_id'];
if($this->debug> 2){error_log('New LP - learnpath::delete_item() - deleted '. $num. ' children of element '. $id,0);}
$sql_del = "DELETE FROM $lp_item WHERE id = $id";
//now update surrounding items
$sql_upd = "UPDATE $lp_item SET next_item_id = $next WHERE id = $previous";
$sql_upd = "UPDATE $lp_item SET previous_item_id = $previous WHERE id = $next";
//now update all following items with new display order
$sql_all = "UPDATE $lp_item SET display_order = display_order-1 WHERE lp_id = $lp AND parent_item_id = $parent AND display_order > $display";
* Updates an item's content in place
* @param integer Element ID
* @param string New content
* @return boolean True on success, false on error
function edit_item($id, $parent, $previous, $title, $description, $prerequisites= 0)
if($this->debug > 0){error_log('New LP - In learnpath::edit_item()', 0);}
if(empty($id) or ($id != strval(intval($id))) or empty($title)){ return false; }
FROM " . $tbl_lp_item . "
$same_parent = ($row_select['parent_item_id'] == $parent) ? true : false;
$same_previous = ($row_select['previous_item_id'] == $previous) ? true : false;
if($same_parent && $same_previous)
//only update title and description
UPDATE " . $tbl_lp_item . "
prerequisite = '". $prerequisites. "',
$old_parent = $row_select['parent_item_id'];
$old_previous = $row_select['previous_item_id'];
$old_next = $row_select['next_item_id'];
$old_order = $row_select['display_order'];
$old_prerequisite= $row_select['prerequisite'];
/* BEGIN -- virtually remove the current item id */
/* for the next and previous item it is like the current item doesn't exist anymore */
UPDATE " . $tbl_lp_item . "
SET next_item_id = " . $old_next . "
WHERE id = " . $old_previous;
$res_update_next = api_sql_query($sql_update_next, __FILE__ , __LINE__ );
//echo '<p>' . $sql_update_next . '</p>';
UPDATE " . $tbl_lp_item . "
SET previous_item_id = " . $old_previous . "
WHERE id = " . $old_next;
$res_update_previous = api_sql_query($sql_update_previous, __FILE__ , __LINE__ );
//echo '<p>' . $sql_update_previous . '</p>';
//display_order - 1 for every item with a display_order bigger then the display_order of the current item
UPDATE " . $tbl_lp_item . "
SET display_order = display_order - 1
display_order > " . $old_order . " AND
parent_item_id = " . $old_parent;
$res_update_order = api_sql_query($sql_update_order, __FILE__ , __LINE__ );
//echo '<p>' . $sql_update_order . '</p>';
/* END -- virtually remove the current item id */
/* BEGIN -- update the current item id to his new location */
//select the data of the item that should come after the current item
FROM " . $tbl_lp_item . "
lp_id = " . $this->lp_id . " AND
parent_item_id = " . $parent . " AND
previous_item_id = " . $previous;
$res_select_old = api_sql_query($sql_select_old, __FILE__ , __LINE__ );
//echo '<p>' . $sql_select_old . '</p>';
//if the new parent didn't have children before
$new_next = $row_select_old['id'];
$new_order = $row_select_old['display_order'];
//echo 'New next_item_id of current item: ' . $new_next . '<br />';
//echo 'New previous_item_id of current item: ' . $previous . '<br />';
//echo 'New display_order of current item: ' . $new_order . '<br />';
//select the data of the item that should come before the current item
FROM " . $tbl_lp_item . "
WHERE id = " . $previous;
$res_select_old = api_sql_query($sql_select_old, __FILE__ , __LINE__ );
//echo '<p>' . $sql_select_old . '</p>';
//echo 'New next_item_id of current item: ' . $row_select_old['next_item_id'] . '<br />';
//echo 'New previous_item_id of current item: ' . $previous . '<br />';
//echo 'New display_order of current item: ' . ($row_select_old['display_order'] + 1) . '<br />';
$new_next = $row_select_old['next_item_id'];
$new_order = $row_select_old['display_order'] + 1;
//update the current item with the new data
UPDATE " . $tbl_lp_item . "
parent_item_id = " . $parent . ",
previous_item_id = " . $previous . ",
next_item_id = " . $new_next . ",
display_order = " . $new_order . "
$res_update_next = api_sql_query($sql_update, __FILE__ , __LINE__ );
//echo '<p>' . $sql_update . '</p>';
//update the previous item's next_item_id
UPDATE " . $tbl_lp_item . "
SET next_item_id = " . $id . "
WHERE id = " . $previous;
$res_update_next = api_sql_query($sql_update_previous, __FILE__ , __LINE__ );
//echo '<p>' . $sql_update_previous . '</p>';
//update the next item's previous_item_id
UPDATE " . $tbl_lp_item . "
SET previous_item_id = " . $id . "
WHERE id = " . $new_next;
$res_update_next = api_sql_query($sql_update_next, __FILE__ , __LINE__ );
//echo '<p>' . $sql_update_next . '</p>';
if($old_prerequisite!= $prerequisites){
UPDATE " . $tbl_lp_item . "
SET prerequisite = " . $prerequisites . "
$res_update_next = api_sql_query($sql_update_next, __FILE__ , __LINE__ );
//update all the items with the same or a bigger display_order than
UPDATE " . $tbl_lp_item . "
SET display_order = display_order + 1
lp_id = " . $this->get_id() . " AND
parent_item_id = " . $parent . " AND
display_order >= " . $new_order;
$res_update_next = api_sql_query($sql_update_order, __FILE__ , __LINE__ );
//echo '<p>' . $sql_update_order . '</p>';
/* END -- update the current item id to his new location */
* Updates an item's prereq in place
* @param integer Element ID
* @param string Prerequisite Element ID
* @param string Prerequisite item type
* @param string Prerequisite min score
* @param string Prerequisite max score
* @return boolean True on success, false on error
function edit_item_prereq($id, $prerequisite_id, $mastery_score = 0, $max_score = 100)
if($this->debug> 0){error_log('New LP - In learnpath::edit_item_prereq('. $id. ','. $prerequisite_id. ','. $mastery_score. ','. $max_score. ')',0);}
if(empty($id) or ($id != strval(intval($id))) or empty($prerequisite_id)){ return false; }
if(!is_numeric($mastery_score) || $mastery_score < 0)
if($mastery_score > $max_score)
$max_score = $mastery_score;
$prerequisite_id = 'NULL';
UPDATE " . $tbl_lp_item . "
SET prerequisite = ". $prerequisite_id. " WHERE id = ". $id;
if($prerequisite_id!= 'NULL' && $prerequisite_id!= '')
$sql_upd = " UPDATE ". $tbl_lp_item. " SET
mastery_score = " . $mastery_score .
//", max_score = " . $max_score . " " . //max score cannot be changed in the form anyway - see display_item_prerequisites_form()
" WHERE ref = '" . $prerequisite_id. "'" ; //will this be enough to ensure unicity?
//TODO update the item object (can be ignored for now because refreshed)
* Escapes a string with the available database escape function
* @param string String to escape
* @return string String escaped
//if($this->debug>0){error_log('New LP - In learnpath::escape_string('.$string.')',0);}
* Static admin function exporting a learnpath into a zip file
* @param string Export type (scorm, zip, cd)
* @param string Course code
* @param integer Learnpath ID
* @param string Zip file name
* @return string Zip file path (or false on error)
function export_lp($type, $course, $id, $zipname)
//if($this->debug>0){error_log('New LP - In learnpath::export_lp()',0);}
if(empty($type) OR empty($course) OR empty($id) OR empty($zipname)){return false;}
* Gets all the chapters belonging to the same parent as the item/chapter given
* Can also be called as abstract method
* @return array A list of all the "brother items" (or an empty array on failure)
if($this->debug> 0){error_log('New LP - In learnpath::get_brother_chapters()',0);}
if(empty($id) OR $id != strval(intval($id))){ return array();}
$sql_parent = "SELECT * FROM $lp_item WHERE id = $id AND item_type='dokeos_chapter'";
$parent = $row_parent['parent_item_id'];
$sql_bros = "SELECT * FROM $lp_item WHERE parent_item_id = $parent AND id = $id AND item_type='dokeos_chapter' ORDER BY display_order";
* Gets all the items belonging to the same parent as the item given
* Can also be called as abstract method
* @return array A list of all the "brother items" (or an empty array on failure)
if($this->debug> 0){error_log('New LP - In learnpath::get_brother_items('. $id. ')',0);}
if(empty($id) OR $id != strval(intval($id))){ return array();}
$sql_parent = "SELECT * FROM $lp_item WHERE id = $id";
$parent = $row_parent['parent_item_id'];
$sql_bros = "SELECT * FROM $lp_item WHERE parent_item_id = $parent ORDER BY display_order";
* Gets the number of items currently completed
* @return integer The number of items currently completed
if($this->debug> 0){error_log('New LP - In learnpath::get_complete_items_count()',0);}
foreach($this->items as $id => $dummy){
//if($this->items[$id]->status_is(array('completed','passed','succeeded'))){
//Trying failed and browsed considered "progressed" as well
if($this->items[$id]->status_is(array('completed','passed','succeeded','browsed','failed'))&& $this->items[$id]->get_type()!= 'dokeos_chapter'&& $this->items[$id]->get_type()!= 'dir'){
* Gets the current item ID
* @return integer The current learnpath item id
if($this->debug> 0){error_log('New LP - In learnpath::get_current_item_id()',0);}
if($this->debug> 2){error_log('New LP - In learnpath::get_current_item_id() - Returning '. $current,0);}
* Gets the total number of items available for viewing in this SCORM
* @return integer The total number of items
if($this->debug> 0){error_log('New LP - In learnpath::get_total_items_count()',0);}
* Gets the total number of items available for viewing in this SCORM but without chapters
* @return integer The total no-chapters number of items
if($this->debug> 0){error_log('New LP - In learnpath::get_total_items_count_without_chapters()',0);}
foreach($this->items as $temp=> $temp2){
if(!in_array($temp2->get_type(), array('dokeos_chapter','chapter','dir'))) $total++ ;
* Gets the first element URL.
* @return string URL to load into the viewer
//test if the last_item_seen exists and is not a dir
//index hasn't changed, so item not found - panic (this shouldn't happen)
if($this->debug> 2){error_log('New LP - In learnpath::first() - No last item seen',0);}
//loop through all ordered items and stop at the first item that is
//not a directory *and* that has not been completed yet
AND $index < $this->max_ordered_items)
* Gets the information about an item in a format usable as JavaScript to update
* the JS API by just printing this content into the <head> section of the message frame
if($this->debug> 0){error_log('New LP - In learnpath::get_js_info('. $item_id. ')',0);}
//if item is defined, return values from DB
$oItem = $this->items[$item_id];
$info .= '<script language="javascript">';
$info .= "top.set_score(". $oItem->get_score(). ");\n";
$info .= "top.set_max(". $oItem->get_max(). ");\n";
$info .= "top.set_min(". $oItem->get_min(). ");\n";
$info .= "top.set_lesson_status('". $oItem->get_status(). "');";
$info .= "top.set_session_time('". $oItem->get_scorm_time('js'). "');";
$info .= "top.set_suspend_data('". $oItem->get_suspend_data(). "');";
$info .= "top.set_saved_lesson_status('". $oItem->get_status(). "');";
$info .= "top.set_flag_synchronized();";
if($this->debug> 2){error_log('New LP - in learnpath::get_js_info('. $item_id. ') - returning: '. $info,0);}
//if item_id is empty, just update to default SCORM data
$info .= '<script language="javascript">';
$info .= "top.set_flag_synchronized();";
if($this->debug> 2){error_log('New LP - in learnpath::get_js_info('. $item_id. ') - returning: '. $info,0);}
* Gets the js library from the database
* @return string The name of the javascript library to be used
if(!empty($this->js_lib)){
* Gets the learnpath database ID
* @return integer Learnpath ID in the lp table
* Gets the last element URL.
* @return string URL to load into the viewer
* Gets the navigation bar for the learnpath display screen
* @return string The HTML string to use as a navigation bar
if($this->debug> 0){error_log('New LP - In learnpath::get_navigation_bar()',0);}
//TODO find a good value for the following variables
if($this->mode == 'fullscreen'){
$navbar = '<table cellpadding="0" cellspacing="0" align="left">'. "\n".
' <div class="buttons">'. "\n" .
' <a href="lp_controller.php?action=stats" onclick="window.parent.API.save_asset();return true;" target="content_name_blank" title="stats" id="stats_link"><img border="0" src="../img/lp_stats.gif" title="'. get_lang('ScormMystatus'). '"></a> '. "\n" .
' <a href="" onclick="dokeos_xajax_handler.switch_item('. $mycurrentitemid. ',\'previous\');return false;" title="previous"><img border="0" src="../img/lp_leftarrow.gif" title="'. get_lang('ScormPrevious'). '"></a> '. "\n" .
' <a href="" onclick="dokeos_xajax_handler.switch_item('. $mycurrentitemid. ',\'next\');return false;" title="next" ><img border="0" src="../img/lp_rightarrow.gif" title="'. get_lang('ScormNext'). '"></a> '. "\n" .
' <a href="lp_controller.php?action=mode&mode=embedded" target="_top" title="embedded mode"><img border="0" src="../img/view_choose.gif" title="'. get_lang('ScormExitFullScreen'). '"></a>'. "\n" .
//' <a href="lp_controller.php?action=list" target="_top" title="learnpaths list"><img border="0" src="../img/exit.png" title="Exit"></a>'."\n" .
$navbar = '<table cellpadding="0" cellspacing="0" align="left">'. "\n".
' <div class="buttons">'. "\n" .
' <a href="lp_controller.php?action=stats" onclick="window.parent.API.save_asset();return true;" target="content_name" title="stats" id="stats_link"><img border="0" src="../img/lp_stats.gif" title="'. get_lang('ScormMystatus'). '"></a> '. "\n" .
' <a href="" onclick="dokeos_xajax_handler.switch_item('. $mycurrentitemid. ',\'previous\');return false;" title="previous"><img border="0" src="../img/lp_leftarrow.gif" title="'. get_lang('ScormPrevious'). '"></a> '. "\n" .
' <a href="" onclick="dokeos_xajax_handler.switch_item('. $mycurrentitemid. ',\'next\');return false;" title="next" ><img border="0" src="../img/lp_rightarrow.gif" title="'. get_lang('ScormNext'). '"></a> '. "\n" .
' <a href="lp_controller.php?action=mode&mode=fullscreen" target="_top" title="fullscreen"><img border="0" src="../img/view_fullscreen.gif" width="18" height="18" title="'. get_lang('ScormFullScreen'). '"></a>'. "\n" .
* Gets the next resource in queue (url).
* @return string URL to load into the viewer
if($this->debug> 0){error_log('New LP - In learnpath::get_next_index()',0);}
if($index == $this->max_ordered_items)
* Gets item_id for the next element
* @return integer Next item (DB) ID
if($this->debug> 0){error_log('New LP - In learnpath::get_next_item_id()',0);}
if($this->debug> 2){error_log('New LP - In learnpath::get_next_index() - Problem - Returning 0',0);}
* Returns the package type ('scorm','aicc','scorm2004','dokeos','ppt'...)
* Generally, the package provided is in the form of a zip file, so the function
* has been written to test a zip file. If not a zip, the function will return the
* default return value: ''
* @param string the path to the file
* @param string the original name of the file
* @return string 'scorm','aicc','scorm2004','dokeos' or '' if the package cannot be recognized
//get name of the zip file without the extension
$filename = $file_info['basename'];//name including extension
$extension = $file_info['extension'];//extension only
if(!empty($_POST['ppt2lp']) && !in_array($extension,array('dll','exe')))
if(!empty($_POST['woogie']) && !in_array($extension,array('dll','exe')))
$file_base_name = str_replace('.'. $extension,'',$filename); //filename without its extension
$zipFile = new pclZip($file_path);
// Check the zip content (real size and file extension)
$zipContentArray = $zipFile->listContent();
//the following loop should be stopped as soon as we found the right imsmanifest.xml (how to recognize it?)
foreach($zipContentArray as $thisContent)
if ( preg_match('~.(php.*|phtml)$~i', $thisContent['filename']) )
//New behaviour: Don't do anything. These files will be removed in scorm::import_package
elseif(stristr($thisContent['filename'],'imsmanifest.xml')!== FALSE)
$manifest = $thisContent['filename']; //just the relative directory inside scorm/
break;//exit the foreach loop
elseif(preg_match('/aicc\//i',$thisContent['filename'])!= false)
{//if found an aicc directory... (!= false means it cannot be false (error) or 0 (no match))
//break;//don't exit the loop, because if we find an imsmanifest afterwards, we want it, not the AICC
* Gets the previous resource in queue (url). Also initialises time values for this viewing
* @return string URL to load into the viewer
if($this->debug> 0){error_log('New LP - In learnpath::get_previous_index()',0);}
if($this->debug> 2){error_log('New LP - get_previous_index() - there was no previous index available, reusing '. $index,0);}
* Gets item_id for the next element
* @return integer Previous item (DB) ID
* Gets the progress value from the progress_db attribute
* @return integer Current progress value
if($this->debug> 0){error_log('New LP - In learnpath::get_progress()',0);}
* Gets the progress value from the progress field in the database (allows use as abstract method)
* @param integer Learnpath ID
* @param string Mode of display ('%','abs' or 'both')
* @param string Course database name (optional, defaults to '')
* @param boolean Whether to return null if no record was found (true), or 0 (false) (optional, defaults to false)
* @return integer Current progress value as found in the database
function get_db_progress($lp_id,$user_id,$mode= '%', $course_db= '', $sincere= false)
//if($this->debug>0){error_log('New LP - In learnpath::get_db_progress()',0);}
$sql = "SELECT * FROM $table WHERE lp_id = $lp_id AND user_id = $user_id";
$progress = $row['progress'];
//get the number of items completed and the number of items total
$sql = "SELECT count(*) FROM $tbl WHERE lp_id = ". $lp_id. "
AND item_type NOT IN('dokeos_chapter','chapter','dir')";
//$sql = "SELECT count(distinct(lp_item_id)) FROM $tbl WHERE lp_view_id = ".$view_id." AND status IN ('passed','completed','succeeded')";
//trying as also counting browsed and failed items
$sql = "SELECT count(distinct(lp_item_id))
FROM $tbl_item_view as item_view
INNER JOIN $tbl_item as item
ON item.id = item_view.lp_item_id
AND item_type NOT IN('dokeos_chapter','chapter','dir')
WHERE lp_view_id = ". $view_id. "
AND status IN ('passed','completed','succeeded','browsed','failed')";
return $completed. '/'. $total;
if($progress< ($completed/ ($total? $total: 1)))
return $progress. '% ('. $completed. '/'. $total. ')';
* Gets a progress bar for the learnpath by counting the number of items in it and the number of items
* @param string Mode in which we want the values
* @param integer Progress value to display (optional but mandatory if used in abstract context)
* @param string Text to display near the progress value (optional but mandatory in abstract context)
* @return string HTML string containing the progress bar
// Setting up the CSS path of the current style if exists
if (!empty($lp_theme_css))
//if($this->debug>0){error_log('New LP - In learnpath::get_progress_bar()',0);}
if(is_object($this) && ($percentage== '-1' OR $text_add== ''))
$text = $percentage. $text_add;
//.htmlentities(get_lang('ScormCompstatus'),ENT_QUOTES,'ISO-8859-1')."<br />"
. '<table border="0" cellpadding="0" cellspacing="0"><tr><td>'
. '<img id="progress_img_limit_left" src="'. $css_path. 'bar_1.gif" width="1" height="12">'
. '<img id="progress_img_full" src="'. $css_path. 'bar_1u.gif" width="'. $size. 'px" height="12" id="full_portion">'
. '<img id="progress_img_limit_middle" src="'. $css_path. 'bar_1m.gif" width="1" height="12">';
$output .= '<img id="progress_img_empty" src="'. $css_path. 'bar_1r.gif" width="'. (100- $size). 'px" height="12" id="empty_portion">';
$output .= '<img id="progress_img_empty" src="'. $css_path. 'bar_1r.gif" width="0" height="12" id="empty_portion">';
$output .= '<img id="progress_bar_img_limit_right" src="'. $css_path. 'bar_1.gif" width="1" height="12"></td></tr></table>'
. '<div class="progresstext" id="progress_text">'. $text. '</div>';
* Gets the progress bar info to display inside the progress bar. Also used by scorm_api.php
* @param string Mode of display (can be '%' or 'abs').abs means we display a number of completed elements per total elements
* //@param integer Additional steps to fake as completed
* @return list Percentage or number and symbol (% or /xx)
if($this->debug> 0){error_log('New LP - In learnpath::get_progress_bar_text()',0);}
if($this->debug> 2){error_log('New LP - Total items available in this learnpath: '. $total_items,0);}
if($this->debug> 2){error_log('New LP - Items completed so far: '. $i,0);}
if($this->debug> 2){error_log('New LP - Items completed so far (+modifier): '. $i,0);}
$percentage = ((float) $i/(float) $total_items)* 100;
$text = '/'. $total_items;
return array($percentage,$text);
* Gets the progress bar mode
* @return string The progress bar mode attribute
if($this->debug> 0){error_log('New LP - In learnpath::get_progress_bar_mode()',0);}
* Gets the learnpath proximity (remote or local)
* @return string Learnpath proximity
if($this->debug> 0){error_log('New LP - In learnpath::get_proximity()',0);}
* Gets the learnpath theme (remote or local)
* @return string Learnpath theme
if($this->debug> 0){error_log('New LP - In learnpath::get_theme()',0);}
if(!empty($this->theme)){return $this->theme;}else{return '';}
* Generate a new prerequisites string for a given item. If this item was a sco and
* its prerequisites were strings (instead of IDs), then transform those strings into
* IDs, knowing that SCORM IDs are kept in the "ref" field of the lp_item table.
* Prefix all item IDs that end-up in the prerequisites string by "ITEM_" to use the
* same rule as the scorm_export() method
* @return string Prerequisites string ready for the export as SCORM
if($this->debug> 0){error_log('New LP - In learnpath::get_scorm_prereq_string()',0);}
$oItem = $this->items[$item_id];
$prereq = $oItem->get_prereq_string();
{ //if the prerequisite is a simple integer ID and this ID exists as an item ID,
//then simply return it (with the ITEM_ prefix)
//it's a simple string item from which the ID can be found in the refs list
//so we can transform it directly to an ID for export
//last case, if it's a complex form, then find all the IDs (SCORM strings)
//and replace them, one by one, by the internal IDs (dokeos db)
//TODO modify the '*' replacement to replace the multiplier in front of it
$find = array('&','|','~','=','<>','{','}','*','(',')');
$replace = array(' ',' ',' ',' ',' ',' ',' ',' ',' ',' ');
$ids = split(' ',$prereq_mod);
error_log('New LP - In learnpath::get_scorm_prereq_string(): returning modified string: '. $prereq,0);
* Returns the XML DOM document's node
* @param resource Reference to a list of objects to search for the given ITEM_*
* @param string The identifier to look for
* @return mixed The reference to the element found with that identifier. False if not found
for($i= 0;$i< $children->length;$i++ ){
$item_temp = $children->item($i);
if ($item_temp -> nodeName == 'item')
if($item_temp->getAttribute('identifier') == $id)
$subchildren = $item_temp->childNodes;
if($subchildren->length> 0)
* Returns a usable array of stats related to the current learnpath and user
* @return array Well-formatted array containing status for the current learnpath
if($this->debug> 0){error_log('New LP - In learnpath::get_stats()',0);}
* Static method. Can be re-implemented by children. Gives an array of statistics for
* the given course (for all learnpaths and all users)
* @param string Course code
* @return array Well-formatted array containing status for the course's learnpaths
//if($this->debug>0){error_log('New LP - In learnpath::get_stats_course()',0);}
* Static method. Can be re-implemented by children. Gives an array of statistics for
* the given course and learnpath (for all users)
* @param string Course code
* @param integer Learnpath ID
* @return array Well-formatted array containing status for the specified learnpath
//if($this->debug>0){error_log('New LP - In learnpath::get_stats_lp()',0);}
* Static method. Can be re-implemented by children. Gives an array of statistics for
* the given course, learnpath and user.
* @param string Course code
* @param integer Learnpath ID
* @return array Well-formatted array containing status for the specified learnpath and user
//if($this->debug>0){error_log('New LP - In learnpath::get_stats_lp_user()',0);}
* Static method. Can be re-implemented by children. Gives an array of statistics for
* the given course and learnpath (for all users)
* @param string Course code
* @return array Well-formatted array containing status for the user's learnpaths
//if($this->debug>0){error_log('New LP - In learnpath::get_stats_user()',0);}
* Gets the status list for all LP's items
* @return array Array of [index] => [item ID => current status]
if($this->debug> 0){error_log('New LP - In learnpath::get_items_status_list()',0);}
$list[]= array($item_id => $this->items[$item_id]->get_status());
* Return the number of interactions for the given learnpath Item View ID.
* This method can be used as static.
* @param integer Item View ID
* @return integer Number of interactions
if(empty($lp_iv_id)){return - 1;}
$sql = "SELECT count(*) FROM $table WHERE lp_iv_id = $lp_iv_id";
* Return the interactions as an array for the given lp_iv_id.
* This method can be used as static.
* @param integer Learnpath Item View ID
$sql = "SELECT * FROM $table WHERE lp_iv_id = $lp_iv_id ORDER BY order_id ASC";
"order_id"=> ($row['order_id']+ 1),
"id"=> urldecode($row['interaction_id']),//urldecode because they often have %2F or stuff like that
"type"=> $row['interaction_type'],
"time"=> $row['completion_time'],
//"correct_responses"=>$row['correct_responses'],
//hide correct responses from students
"student_response"=> $row['student_response'],
"result"=> $row['result'],
"latency"=> $row['latency']);
* Return the number of objectives for the given learnpath Item View ID.
* This method can be used as static.
* @param integer Item View ID
* @return integer Number of objectives
if(empty($lp_iv_id)){return - 1;}
$sql = "SELECT count(*) FROM $table WHERE lp_iv_id = $lp_iv_id";
* Return the objectives as an array for the given lp_iv_id.
* This method can be used as static.
* @param integer Learnpath Item View ID
$sql = "SELECT * FROM $table WHERE lp_iv_id = $lp_iv_id ORDER BY order_id ASC";
"order_id"=> ($row['order_id']+ 1),
"objective_id"=> urldecode($row['objective_id']),//urldecode because they often have %2F or stuff like that
"score_raw"=> $row['score_raw'],
"score_max"=> $row['score_max'],
"score_min"=> $row['score_min'],
"status"=> $row['status']);
* Generate and return the table of contents for this learnpath. The (flat) table returned can be
* used by get_html_toc() to be ready to display
* @return array TOC as a table with 4 elements per row: title, link, status and level
//echo "<pre>".print_r($this->items,true)."</pre>";
if($this->debug> 2){error_log('New LP - learnpath::get_toc(): getting info for item '. $item_id,0);}
//TODO change this link generation and use new function instead
'title'=> $this->items[$item_id]->get_title(),
//'link'=>get_addedresource_link_in_learnpath('document',$item_id,1),
'status'=> $this->items[$item_id]->get_status(),
'level'=> $this->items[$item_id]->get_level(),
'type' => $this->items[$item_id]->get_type(),
'description'=> $this->items[$item_id]->get_description(),
* Gets the learning path type
* @param boolean Return the name? If false, return the ID. Default is false.
* @return mixed Type ID or name, depending on the parameter
//get it from the lp_type table in main db
if($this->debug> 2){error_log('New LP - In learnpath::get_type() - Returning '. ($res== false? 'false': $res),0);}
* Gets the learning path type as static method
* @param boolean Return the name? If false, return the ID. Default is false.
* @return mixed Type ID or name, depending on the parameter
$sql = "SELECT lp_type FROM $tbl_lp WHERE id = '". $lp_id. "'";
if($res=== false){ return null;}
* Gets a flat list of item IDs ordered for display (level by level ordered by order_display)
* This method can be used as abstract and is recursive
* @param integer Learnpath ID
* @param integer Parent ID of the items to look for
* @return mixed Ordered list of item IDs or false on error
//if($this->debug>0){error_log('New LP - In learnpath::get_flat_ordered_items_list('.$lp.','.$parent.')',0);}
if(empty($lp)){return false;}
$sql = "SELECT * FROM $tbl_lp_item WHERE lp_id = $lp AND parent_item_id = $parent ORDER BY display_order";
foreach($sublist as $item){
* Uses the table generated by get_toc() and returns an HTML-formatted string ready to display
* @return string HTML TOC ready to display
/*function get_html_toc()
if($this->debug>0){error_log('New LP - In learnpath::get_html_toc()',0);}
$list = $this->get_toc();
//$parent = $this->items[$this->current]->get_parent();
//if(empty($parent)){$parent = $this->ordered_items[$this->items[$this->current]->get_previous_index()];}
$html = '<div class="inner_lp_toc">'."\n" ;
// " onchange=\"javascript:document.getElementById('toc_$parent').focus();\">\n";
require_once('resourcelinker.inc.php');
$mycurrentitemid = $this->get_current_item_id();
if($this->debug>2){error_log('New LP - learnpath::get_html_toc(): using item '.$item['id'],0);}
$icon_name = array('not attempted' => '../img/notattempted.gif',
'incomplete' => '../img/incomplete.gif',
'failed' => '../img/failed.gif',
'completed' => '../img/completed.gif',
'passed' => '../img/passed.gif',
'succeeded' => '../img/succeeded.gif',
'browsed' => '../img/completed.gif');
if($item['id'] == $this->current){
$style = 'scorm_item_highlight';
//the anchor will let us center the TOC on the currently viewed item &^D
$html .= '<a name="atoc_'.$item['id'].'" /><div class="'.$style.'" style="padding-left: '.($item['level']/2).'em; padding-right:'.($item['level']/2).'em" id="toc_'.$item['id'].'" >' .
'<img id="toc_img_'.$item['id'].'" class="scorm_status_img" src="'.$icon_name[$item['status']].'" alt="'.substr($item['status'],0,1).'" />';
//$title = htmlspecialchars($item['title'],ENT_QUOTES,$this->encoding);
$title = rl_get_resource_name(api_get_course_id(),$this->get_id(),$item['id']);
$title = htmlspecialchars($title,ENT_QUOTES,$this->encoding);
if(empty($title))$title = '-';
if($item['type']!='dokeos_chapter' and $item['type']!='dir'){
//$html .= "<a href='lp_controller.php?".api_get_cidReq()."&action=content&lp_id=".$this->get_id()."&item_id=".$item['id']."' target='lp_content_frame_name'>".$title."</a>" ;
$url = $this->get_link('http',$item['id']);
//$html .= '<a href="'.$url.'" target="content_name" onclick="top.load_item('.$item['id'].',\''.$url.'\');">'.$title.'</a>' ;
//$html .= '<a href="" onclick="top.load_item('.$item['id'].',\''.$url.'\');return false;">'.$title.'</a>' ;
$html .= '<a href="" onclick="dokeos_xajax_handler.switch_item(' .
'return false;" >'.$title.'</a>' ;
* Uses the table generated by get_toc() and returns an HTML-formatted string ready to display
* @return string HTML TOC ready to display
if($this->debug> 0){error_log('New LP - In learnpath::get_html_toc()',0);}
//$parent = $this->items[$this->current]->get_parent();
//if(empty($parent)){$parent = $this->ordered_items[$this->items[$this->current]->get_previous_index()];}
$html.= '<div class="inner_lp_toc">'. "\n" ;
// " onchange=\"javascript:document.getElementById('toc_$parent').focus();\">\n";
require_once('resourcelinker.inc.php');
if($this->debug> 2){error_log('New LP - learnpath::get_html_toc(): using item '. $item['id'],0);}
$icon_name = array('not attempted' => '../img/notattempted.gif',
'incomplete' => '../img/incomplete.gif',
'failed' => '../img/failed.gif',
'completed' => '../img/completed.gif',
'passed' => '../img/passed.gif',
'succeeded' => '../img/succeeded.gif',
'browsed' => '../img/completed.gif');
$scorm_color_background= 'scorm_item';
$style_item = 'scorm_item';
$style = 'scorm_item_highlight';
$scorm_color_background = 'scorm_item_highlight';
$scorm_color_background= 'scorm_item_1';
$scorm_color_background= 'scorm_item_2';
if ($scorm_color_background!= '')
$html .= '<div id="toc_'. $item['id']. '" class="'. $scorm_color_background. '">';
//the anchor will let us center the TOC on the currently viewed item &^D
if($item['type']!= 'dokeos_module' AND $item['type']!= 'dokeos_chapter')
$html .= '<a name="atoc_'. $item['id']. '" />';
$html .= '<div class="'. $style_item. '" style="padding-left: '. ($item['level']* 1.5). 'em; padding-right:'. ($item['level']/ 2). 'em" title="'. $item['description']. '" >';
$html .= '<div class="'. $style_item. '" style="padding-left: '. ($item['level']* 2). 'em; padding-right:'. ($item['level']* 1.5). 'em" title="'. $item['description']. '" >';
if($item['type']!= 'dokeos_chapter' and $item['type']!= 'dir' AND $item['type']!= 'dokeos_module')
//$html .= "<a href='lp_controller.php?".api_get_cidreq()."&action=content&lp_id=".$this->get_id()."&item_id=".$item['id']."' target='lp_content_frame_name'>".$title."</a>" ;
$url = $this->get_link('http',$item['id']);
//$html .= '<a href="'.$url.'" target="content_name" onclick="top.load_item('.$item['id'].',\''.$url.'\');">'.$title.'</a>' ;
//$html .= '<a href="" onclick="top.load_item('.$item['id'].',\''.$url.'\');return false;">'.$title.'</a>' ;
//<img align="absbottom" width="13" height="13" src="../img/lp_document.png">
$html .= '<a href="" onclick="dokeos_xajax_handler.switch_item(' .
elseif($item['type']== 'dokeos_module' || $item['type']== 'dokeos_chapter')
$html .= "<img align='absbottom' width='13' height='13' src='../img/lp_dokeos_module.png'> ". stripslashes($title);
elseif($item['type']== 'dir')
$html .= "<img id='toc_img_". $item['id']. "' src='". $icon_name[$item['status']]. "' alt='". substr($item['status'],0,1). "' />";
if ($scorm_color_background!= '')
* Gets the learnpath maker name - generally the editor's name
* @return string Learnpath maker name
if($this->debug> 0){error_log('New LP - In learnpath::get_maker()',0);}
if(!empty($this->maker)){return $this->maker;}else{return '';}
* Gets the user-friendly message stored in $this->message
if($this->debug> 0){error_log('New LP - In learnpath::get_message()',0);}
* Gets the learnpath name/title
* @return string Learnpath name/title
if(!empty($this->name)){return $this->name;}else{return 'N/A';}
* Gets a link to the resource from the present location, depending on item ID.
* @param string Type of link expected
* @param integer Learnpath item ID
* @return string Link to the lp_item resource
function get_link($type= 'http',$item_id= null)
if($this->debug> 0){error_log('New LP - In learnpath::get_link('. $type. ','. $item_id. ')',0);}
if($this->debug> 2){error_log('New LP - In learnpath::get_link() - no current item id found in learnpath object',0);}
//still empty, this means there was no item_id given and we are not in an object context or
//the object property is empty, return empty link
$item_id = $this->first();
$sel = "SELECT l.lp_type as ltype, l.path as lpath, li.item_type as litype, li.path as lipath, li.parameters as liparams " .
"FROM $lp_table l, $lp_item_table li WHERE li.id = $item_id AND li.lp_id = l.id";
if($this->debug> 2){error_log('New LP - In learnpath::get_link() - selecting item '. $sel,0);}
$lp_type = $row['ltype'];
$lp_path = $row['lpath'];
$lp_item_type = $row['litype'];
$lp_item_path = $row['lipath'];
$lp_item_params = $row['liparams'];
if(empty($lp_item_params))
list ($lp_item_path,$lp_item_params) = explode('?',$lp_item_path);
//$lp_item_params = '?'.$lp_item_params;
//add ? if none - left commented to give freedom to scorm implementation
//if(substr($lp_item_params,0,1)!='?'){
// $lp_item_params = '?'.$lp_item_params;
$course_path = $sys_course_path; //system path
//now go through the specific cases to get the end of the path
if($lp_item_type == 'dokeos_chapter'){
$file = 'lp_content.php?type=dir';
require_once('resourcelinker.inc.php');
$document_name= $tmp_array[count($tmp_array)- 1];
if(strpos($document_name,'_DELETED_')){
$file = 'blank.php?error=document_deleted';
if($this->debug> 2){error_log('New LP - In learnpath::get_link() '.__LINE__. ' - Item type: '. $lp_item_type,0);}
if($lp_item_type!= 'dir'){
//we want to make sure 'http://' (and similar) links can
//be loaded as is (withouth the Dokeos path in front) but
//some contents use this form: resource.htm?resource=http://blablabla
//which means we have to find a protocol at the path's start, otherwise
//it should not be considered as an external URL
//if($this->prerequisites_match($item_id)){
if(preg_match('#^[a-zA-Z]{2,5}://#',$lp_item_path)!= 0){
if($this->debug> 2){error_log('New LP - In learnpath::get_link() '.__LINE__. ' - Found match for protocol in '. $lp_item_path,0);}
//distant url, return as is
if($this->debug> 2){error_log('New LP - In learnpath::get_link() '.__LINE__. ' - No starting protocol in '. $lp_item_path,0);}
//prevent getting untranslatable urls
$file = $course_path. '/scorm/'. $lp_path. '/'. $lp_item_path;
//TODO fix this for urls with protocol header
$lp_path = substr($lp_path,0,- 1);
if(!is_file(realpath($sys_course_path. '/scorm/'. $lp_path. '/'. $lp_item_path)))
list ($decoded) = explode('?',$decoded);
require_once('resourcelinker.inc.php');
$document_name= $tmp_array[count($tmp_array)- 1];
if(strpos($document_name,'_DELETED_')){
$file = 'blank.php?error=document_deleted';
$file = $course_path. '/scorm/'. $lp_path. '/'. $decoded;
//prerequisites did not match
//We want to use parameters if they were defined in the imsmanifest
$file.= (strstr($file,'?')=== false? '?': ''). $lp_item_params;
$file = 'lp_content.php?type=dir';
if($this->debug> 2){error_log('New LP - In learnpath::get_link() '.__LINE__. ' - Item type: '. $lp_item_type,0);}
//formatting AICC HACP append URL
if($lp_item_type!= 'dir'){
//we want to make sure 'http://' (and similar) links can
//be loaded as is (withouth the Dokeos path in front) but
//some contents use this form: resource.htm?resource=http://blablabla
//which means we have to find a protocol at the path's start, otherwise
//it should not be considered as an external URL
if(preg_match('#^[a-zA-Z]{2,5}://#',$lp_item_path)!= 0){
if($this->debug> 2){error_log('New LP - In learnpath::get_link() '.__LINE__. ' - Found match for protocol in '. $lp_item_path,0);}
//distant url, return as is
if(stristr($file,'<servername>')!==false){
$file = str_replace('<servername>',$course_path.'/scorm/'.$lp_path.'/',$lp_item_path);
if($this->debug> 2){error_log('New LP - In learnpath::get_link() '.__LINE__. ' - No starting protocol in '. $lp_item_path,0);}
//prevent getting untranslatable urls
//prepare the path - lp_path might be unusable because it includes the "aicc" subdir name
$file = $course_path. '/scorm/'. $lp_path. '/'. $lp_item_path;
//TODO fix this for urls with protocol header
$file = 'lp_content.php?type=dir';
if($this->debug> 2){error_log('New LP - In learnpath::get_link() - returning "'. $file. '" from get_link',0);}
* Gets the latest usable view or generate a new one
* @param integer Optional attempt number. If none given, takes the highest from the lp_view table
* @return integer DB lp_view id
//use $attempt_num to enable multi-views management (disabled so far)
if($attempt_num != 0 AND intval(strval($attempt_num)) == $attempt_num)
$search = 'AND view_count = '. $attempt_num;
//when missing $attempt_num, search for a unique lp_view record for this lp and user
$sql = "SELECT id, view_count FROM $lp_view_table " .
"WHERE lp_id = ". $this->get_id(). " " .
" ORDER BY view_count DESC";
//no database record, create one
$sql = "INSERT INTO $lp_view_table(lp_id,user_id,view_count)" .
* Gets the current view id
* @return integer View ID (from lp_view)
if($this->debug> 0){error_log('New LP - In learnpath::get_view_id()',0);}
* @return array Array containing IDs of items to be updated by JavaScript
if($this->debug> 0){error_log('New LP - In learnpath::get_update_queue()',0);}
* @return integer User ID
if($this->debug> 0){error_log('New LP - In learnpath::get_user_id()',0);}
* Logs a message into a file
* @param string Message to log
* @return boolean True on success, false on error or if msg empty
$this->error .= $msg. "\n";
* Moves an item up and down at its level
* @param integer Item to move up and down
* @param string Direction 'up' or 'down'
* @return integer New display order, or false on error
if($this->debug> 0){error_log('New LP - In learnpath::move_item('. $id. ','. $direction. ')',0);}
if(empty($id) or empty($direction)){return false;}
FROM " . $tbl_lp_item . "
$previous = $row['previous_item_id'];
$next = $row['next_item_id'];
$display = $row['display_order'];
$parent = $row['parent_item_id'];
//update the item (switch with previous/next one)
if($display <= 1){/*do nothing*/}
$previous_previous = $row2['previous_item_id'];
//update previous_previous item (switch "next" with current)
if($previous_previous != 0)
$sql_upd2 = "UPDATE $tbl_lp_item SET next_item_id = $id WHERE id = $previous_previous";
//update previous item (switch with current)
$sql_upd2 = "UPDATE $tbl_lp_item SET next_item_id = $next, previous_item_id = $id, display_order = display_order +1 WHERE id = $previous";
//update current item (switch with previous)
$sql_upd2 = "UPDATE $tbl_lp_item SET next_item_id = $previous, previous_item_id = $previous_previous, display_order = display_order-1 WHERE id = $id";
//update next item (new previous item)
$sql_upd2 = "UPDATE $tbl_lp_item SET previous_item_id = $previous WHERE id = $next";
if($next == 0){/*do nothing*/}
$sql_sel2 = "SELECT * FROM $tbl_lp_item WHERE id = $next";
$next_next = $row2['next_item_id'];
//update previous item (switch with current)
$sql_upd2 = "UPDATE $tbl_lp_item SET next_item_id = $next WHERE id = $previous";
//update current item (switch with previous)
$sql_upd2 = "UPDATE $tbl_lp_item SET previous_item_id = $next, next_item_id = $next_next, display_order = display_order+1 WHERE id = $id";
//update next item (new previous item)
$sql_upd2 = "UPDATE $tbl_lp_item SET previous_item_id = $previous, next_item_id = $id, display_order = display_order-1 WHERE id = $next";
//update next_next item (switch "previous" with current)
$sql_upd2 = "UPDATE $tbl_lp_item SET previous_item_id = $id WHERE id = $next_next";
* Move a learnpath up (display_order)
* @param integer Learnpath ID
$sql = "SELECT * FROM $lp_table ORDER BY display_order";
if($res === false) return false;
//first check the order is correct, globally (might be wrong because
if($row['display_order'] != $i)
{ //if we find a gap in the order, we need to fix it
$sql_u = "UPDATE $lp_table SET display_order = $i WHERE id = ". $row['id'];
$row['display_order'] = $i;
$lp_order[$i] = $row['id'];
if($num> 1) //if there's only one element, no need to sort
$order = $lps[$lp_id]['display_order'];
if($order> 1) //if it's the first element, no need to move up
$sql_u1 = "UPDATE $lp_table SET display_order = $order WHERE id = ". $lp_order[$order- 1];
$sql_u2 = "UPDATE $lp_table SET display_order = ". ($order- 1). " WHERE id = ". $lp_id;
* Move a learnpath down (display_order)
* @param integer Learnpath ID
$sql = "SELECT * FROM $lp_table ORDER BY display_order";
if($res === false) return false;
//first check the order is correct, globally (might be wrong because
if($row['display_order'] != $i)
{ //if we find a gap in the order, we need to fix it
$sql_u = "UPDATE $lp_table SET display_order = $i WHERE id = ". $row['id'];
$row['display_order'] = $i;
$lp_order[$i] = $row['id'];
if($num> 1) //if there's only one element, no need to sort
$order = $lps[$lp_id]['display_order'];
if($order< $max) //if it's the first element, no need to move up
$sql_u1 = "UPDATE $lp_table SET display_order = $order WHERE id = ". $lp_order[$order+ 1];
$sql_u2 = "UPDATE $lp_table SET display_order = ". ($order+ 1). " WHERE id = ". $lp_id;
* Updates learnpath attributes to point to the next element
* The last part is similar to set_current_item but processing the other way around
$this->index = $new_index;
* Open a resource = initialise all local variables relative to this resource. Depending on the child
* class, this might be redefined to allow several behaviours depending on the document type.
* @param integer Resource ID
* @return boolean True on success, false otherwise
//set the current resource attribute to this resource
//switch on element type (redefine in child class?)
//set status for this item to "opened"
$this->index = 0; //or = the last item seen (see $this->last)
* Check that all prerequisites are fulfilled. Returns true and an empty string on succes, returns false
* and the prerequisite string on error.
* This function is based on the rules for aicc_script language as described in the SCORM 1.2 CAM documentation page 108.
* @param integer Optional item ID. If none given, uses the current open item.
* @return boolean True if prerequisites are matched, false otherwise
* @return string Empty string if true returned, prerequisites string otherwise.
if($this->debug> 0){error_log('New LP - In learnpath::prerequisites_match()',0);}
if(empty($item)){$item = $this->current;}
$prereq_string = $this->items[$item]->get_prereq_string();
if(empty($prereq_string)){return true;}
if($this->debug> 0){error_log('Found prereq_string: '. $prereq_string,0);}
//now send to the parse_prereq() function that will check this component's prerequisites
if($this->debug> 1){error_log('New LP - $this->items['. $item. '] was not an object',0);}
if($this->debug> 1){error_log('New LP - End of prerequisites_match(). Error message is now '. $this->error,0);}
* Updates learnpath attributes to point to the previous element
* The last part is similar to set_current_item but processing the other way around
$this->index = $new_index;
* Publishes a learnpath. This basically means show or hide the learnpath
* Can be used as abstract
* @param integer Learnpath ID
* @param string New visibility
//if($this->debug>0){error_log('New LP - In learnpath::toggle_visibility()',0);}
* Publishes a learnpath. This basically means show or hide the learnpath
* Can be used as abstract
* @param integer Learnpath ID
* @param string New visibility
//if($this->debug>0){error_log('New LP - In learnpath::toggle_publish()',0);}
$sql= "SELECT * FROM $tbl_lp where id=$lp_id";
if($set_visibility == 'i') {
if($set_visibility == 'v')
$link = 'newscorm/lp_controller.php?action=view&lp_id='. $lp_id;
$sql= "SELECT * FROM $tbl_tool where name='$name' and image='scormbuilder.gif' and link LIKE '$link%'";
//if($this->debug>2){error_log('New LP - '.$sql.' - '.$num,0);}
if(($set_visibility == 'i') && ($num> 0))
$sql = "DELETE FROM $tbl_tool WHERE (name='$name' and image='scormbuilder.gif' and link LIKE '$link%')";
elseif(($set_visibility == 'v') && ($num== 0))
$sql = "INSERT INTO $tbl_tool (name, link, image, visibility, admin, address, added_tool) VALUES ('$name','newscorm/lp_controller.php?action=view&lp_id=$lp_id','scormbuilder.gif','$v','0','pastillegris.gif',0)";
//parameter and database incompatible, do nothing
//if($this->debug>2){error_log('New LP - Leaving learnpath::toggle_visibility: '.$sql,0);}
* Restart the whole learnpath. Return the URL of the first element.
* Make sure the results are saved with anoter method. This method should probably be
* redefined in children classes.
* @return string URL to load in the viewer
//call autosave method to save the current progress
$sql = "INSERT INTO $lp_view_table (lp_id, user_id, view_count) " .
if($this->debug> 2){error_log('New LP - Inserting new lp_view for restart: '. $sql,0);}
$this->error = 'Could not insert into item_view table...';
foreach($this->items as $index=> $dummy){
$this->items[$index]->restart();
if($this->debug> 0){error_log('New LP - In learnpath::save_current()',0);}
//TODO do a better check on the index pointing to the right item (it is supposed to be working
// on $ordered_items[] but not sure it's always safe to use with $items[])
//$res = $this->items[$this->current]->save(false);
* @param integer Item ID. Optional (will take from $_REQUEST if null)
* @param boolean Save from url params (true) or from current attributes (false). Optional. Defaults to true
function save_item($item_id= null,$from_outside= true){
if($this->debug> 0){error_log('New LP - In learnpath::save_item('. $item_id. ','. $from_outside. ')',0);}
//TODO do a better check on the index pointing to the right item (it is supposed to be working
// on $ordered_items[] but not sure it's always safe to use with $items[])
if($this->debug> 2){error_log('New LP - save_current() saving item '. $item_id,0);}
//$res = $this->items[$item_id]->save($from_outside);
$status = $this->items[$item_id]->get_status();
* Saves the last item seen's ID only in case
if($this->debug> 0){error_log('New LP - In learnpath::save_last()',0);}
if($this->debug> 2){error_log('New LP - Saving last item seen : '. $sql,0);}
if($progress>= 0 AND $progress<= 100){
$progress= (int) $progress;
$sql = "UPDATE $table SET progress = $progress " .
"WHERE lp_id = ". $this->get_id(). " AND " .
$res = api_sql_query($sql,__FILE__ , __LINE__ ); //ignore errors as some tables might not have the progress field just yet
* Sets the current item ID (checks if valid and authorized first)
* @param integer New item ID. If not given or not authorized, defaults to current
if($this->debug> 0){error_log('New LP - In learnpath::set_current_item('. $item_id. ')',0);}
if($this->debug> 2){error_log('New LP - No new current item given, ignore...',0);}
if($this->debug> 2){error_log('New LP - New current item given is '. $item_id. '...',0);}
//TODO check in database here
//TODO update $this->index as well
if($this->debug> 2){error_log('New LP - set_current_item('. $item_id. ') done. Index is now : '. $this->index,0);}
* @param string New encoding
if($this->debug> 0){error_log('New LP - In learnpath::set_encoding()',0);}
$encodings = array('UTF-8','ISO-8859-1','ISO-8859-15','SHIFT-JIS');
$sql = "UPDATE $tbl_lp SET default_encoding = '$enc' WHERE id = ". $lp;
* Sets the JS lib setting in the database directly.
* This is the JavaScript library file this lp needs to load on startup
* @param string Proximity setting
if($this->debug> 0){error_log('New LP - In learnpath::set_jslib()',0);}
$sql = "UPDATE $tbl_lp SET js_lib = '$lib' WHERE id = ". $lp;
* Sets the name of the LP maker (publisher) (and save)
* @param string Optional string giving the new content_maker of this learnpath
if($this->debug> 0){error_log('New LP - In learnpath::set_maker()',0);}
if(empty($name))return false;
$sql = "UPDATE $lp_table SET content_maker = '". $this->maker. "' WHERE id = '$lp_id'";
//$res = Database::query($sql);
* Sets the name of the current learnpath (and save)
* @param string Optional string giving the new name of this learnpath
if(empty($name))return false;
$sql = "UPDATE $lp_table SET name = '". $this->name. "' WHERE id = '$lp_id'";
//$res = Database::query($sql);
// if the lp is visible on the homepage, change his name there
$sql = 'UPDATE '. $table. ' SET
WHERE link = "newscorm/lp_controller.php?action=view&lp_id='. $lp_id. '"';
* Sets the theme of the LP (local/remote) (and save)
* @param string Optional string giving the new theme of this learnpath
* @return bool returns true if theme name is not empty
if($this->debug> 0){error_log('New LP - In learnpath::set_theme()',0);}
if(empty($name))return false;
$sql = "UPDATE $lp_table SET theme = '". $this->theme. "' WHERE id = '$lp_id'";
//$res = Database::query($sql);
* Sets the location/proximity of the LP (local/remote) (and save)
* @param string Optional string giving the new location of this learnpath
if($this->debug> 0){error_log('New LP - In learnpath::set_proximity()',0);}
if(empty($name))return false;
$sql = "UPDATE $lp_table SET content_local = '". $this->proximity. "' WHERE id = '$lp_id'";
//$res = Database::query($sql);
* Sets the previous item ID to a given ID. Generally, this should be set to the previous 'current' item
* @param integer DB ID of the item
if($this->debug> 0){error_log('New LP - In learnpath::set_previous_item()',0);}
* Sets the object's error message
* @param string Error message. If empty, reinits the error string
if($this->debug> 0){error_log('New LP - In learnpath::set_error_msg()',0);}
* Launches the current item if not 'sco' (starts timer and make sure there is a record ready in the DB)
if($this->debug> 0){error_log('New LP - In learnpath::start_current_item()',0);}
($type == 2 && $item_type!= 'sco')
($type == 3 && $item_type!= 'au')
//$this->update_queue[$this->last] = $this->items[$this->last]->get_status();
//if sco, then it is supposed to have been updated by some other call
if($this->debug> 0){error_log('New LP - End of learnpath::start_current_item()',0);}
* Stops the processing and counters for the old item (as held in $this->last)
if($this->debug> 0){error_log('New LP - In learnpath::stop_previous_item()',0);}
if($this->debug> 2){error_log('New LP - In learnpath::stop_previous_item() - '. $this->last. ' is object',0);}
if($this->items[$this->last]->get_type()!= 'au')
if($this->debug> 2){error_log('New LP - In learnpath::stop_previous_item() - '. $this->last. ' in lp_type 3 is <> au',0);}
//$this->autocomplete_parents($this->last);
//$this->update_queue[$this->last] = $this->items[$this->last]->get_status();
if($this->debug> 2){error_log('New LP - In learnpath::stop_previous_item() - Item is an AU, saving is managed by AICC signals',0);}
if($this->items[$this->last]->get_type()!= 'sco')
if($this->debug> 2){error_log('New LP - In learnpath::stop_previous_item() - '. $this->last. ' in lp_type 2 is <> sco',0);}
//$this->autocomplete_parents($this->last);
//$this->update_queue[$this->last] = $this->items[$this->last]->get_status();
if($this->debug> 2){error_log('New LP - In learnpath::stop_previous_item() - Item is a SCO, saving is managed by SCO signals',0);}
if($this->debug> 2){error_log('New LP - In learnpath::stop_previous_item() - '. $this->last. ' in lp_type 1 is asset',0);}
if($this->debug> 2){error_log('New LP - In learnpath::stop_previous_item() - No previous element found, ignoring...',0);}
* Updates the default view mode from fullscreen to embedded and inversely
* @return string The current default view mode ('fullscreen' or 'embedded')
if($this->debug> 0){error_log('New LP - In learnpath::update_default_view_mode()',0);}
$sql = "SELECT * FROM $lp_table WHERE id = ". $this->get_id();
$view_mode = $row['default_view_mod'];
if($view_mode == 'fullscreen'){
}elseif($view_mode == 'embedded'){
$view_mode = 'fullscreen';
$sql = "UPDATE $lp_table SET default_view_mod = '$view_mode' WHERE id = ". $this->get_id();
$this->mode = $view_mode;
if($this->debug> 2){error_log('New LP - Problem in update_default_view() - could not find LP '. $this->get_id(). ' in DB',0);}
* Updates the default behaviour about auto-commiting SCORM updates
* @return boolean True if auto-commit has been set to 'on', false otherwise
if($this->debug> 0){error_log('New LP - In learnpath::update_default_scorm_commit()',0);}
$sql = "SELECT * FROM $lp_table WHERE id = ". $this->get_id();
$force = $row['force_commit'];
$sql = "UPDATE $lp_table SET force_commit = $force WHERE id = ". $this->get_id();
if($this->debug> 2){error_log('New LP - Problem in update_default_scorm_commit() - could not find LP '. $this->get_id(). ' in DB',0);}
* Updates the order of learning paths (goes through all of them by order and fills the gaps)
* @return bool True on success, false on failure
$sql = "SELECT * FROM $lp_table ORDER BY display_order";
if($res === false) return false;
//first check the order is correct, globally (might be wrong because
if($row['display_order'] != $i)
{ //if we find a gap in the order, we need to fix it
$sql_u = "UPDATE $lp_table SET display_order = $i WHERE id = ". $row['id'];
* Updates the "prevent_reinit" value that enables control on reinitialising items on second view
* @return boolean True if prevent_reinit has been set to 'on', false otherwise (or 1 or 0 in this case)
if($this->debug> 0){error_log('New LP - In learnpath::update_reinit()',0);}
$sql = "SELECT * FROM $lp_table WHERE id = ". $this->get_id();
$force = $row['prevent_reinit'];
$sql = "UPDATE $lp_table SET prevent_reinit = $force WHERE id = ". $this->get_id();
if($this->debug> 2){error_log('New LP - Problem in update_reinit() - could not find LP '. $this->get_id(). ' in DB',0);}
* Updates the "scorm_debug" value that shows or hide the debug window
* @return boolean True if scorm_debug has been set to 'on', false otherwise (or 1 or 0 in this case)
if($this->debug> 0){error_log('New LP - In learnpath::update_scorm_debug()',0);}
$sql = "SELECT * FROM $lp_table WHERE id = ". $this->get_id();
$sql = "UPDATE $lp_table SET debug = $force WHERE id = ". $this->get_id();
if($this->debug> 2){error_log('New LP - Problem in update_scorm_debug() - could not find LP '. $this->get_id(). ' in DB',0);}
* Function that makes a call to the function sort_tree_array and create_tree_array
* @author Kevin Van Den Haute
* @param unknown_type $array
* Creates an array with the elements of the learning path tree in it
* @author Kevin Van Den Haute
for($i = 0; $i < count($array); $i++ )
if($array[$i]['parent_item_id'] == $parent)
if(!in_array($array[$i]['parent_item_id'], $tmp))
$tmp[] = $array[$i]['parent_item_id'];
'id' => $array[$i]['id'],
'item_type' => $array[$i]['item_type'],
'title' => $array[$i]['title'],
'path' => $array[$i]['path'],
'description' => $array[$i]['description'],
'parent_item_id' => $array[$i]['parent_item_id'],
'previous_item_id' => $array[$i]['previous_item_id'],
'next_item_id' => $array[$i]['next_item_id'],
'min_score' => $array[$i]['min_score'],
'max_score' => $array[$i]['max_score'],
'mastery_score' => $array[$i]['mastery_score'],
'display_order' => $array[$i]['display_order'],
'prerequisite' => $array[$i]['prerequisite'],
* Sorts a multi dimensional array by parent id and display order
* @author Kevin Van Den Haute
* @param array $array (array with al the learning path items in it)
foreach($array as $key => $row)
$parent[$key] = $row['parent_item_id'];
$position[$key] = $row['display_order'];
* Function that creates a table structure with a learning path his modules, chapters and documents.
* Also the actions for the modules, chapters and documents are in this table.
* @author Kevin Van Den Haute
FROM " . $tbl_lp_item . "
lp_id = " . $this->lp_id;
'item_type' => $row['item_type'],
'title' => $row['title'],
'description' => $row['description'],
'parent_item_id' => $row['parent_item_id'],
'previous_item_id' => $row['previous_item_id'],
'next_item_id' => $row['next_item_id'],
'display_order' => $row['display_order']);
$return .= '<p><a href="' . api_get_self(). '?cidReq=' . $_GET['cidReq'] . '&action=build&lp_id=' . $this->lp_id . '">'. get_lang("Advanced"). '</a> | '. get_lang("BasicOverview"). ' | <a href="lp_controller.php?cidReq='. $_GET['cidReq']. '&action=view&lp_id='. $this->lp_id. '">'. get_lang("Display"). '</a></p>';
$return .= '<table class="data_table">' . "\n";
$return .= "\t" . '<tr>' . "\n";
$return .= "\t" . '<th width="75%">'. get_lang("Title"). '</th>' . "\n";
//$return .= "\t" . '<th>'.get_lang("Description").'</th>' . "\n";
$return .= "\t" . '<th>'. get_lang("Move"). '</th>' . "\n";
$return .= "\t" . '<th>'. get_lang("Actions"). '</th>' . "\n";
$return .= "\t" . '</tr>' . "\n";
for($i = 0; $i < count($arrLP); $i++ )
$title= $arrLP[$i]['title'];
if($arrLP[$i]['description'] == '')
$arrLP[$i]['description'] = ' ';
if (($i % 2)== 0) { $oddclass= "row_odd"; } else { $oddclass= "row_even"; }
$return .= "\t" . '<tr class="'. $oddclass. '">' . "\n";
$return .= "\t\t" . '<td style="padding-left:' . $arrLP[$i]['depth'] * 10 . 'px;"><img align="left" src="../img/lp_' . $arrLP[$i]['item_type'] . '.png" style="margin-right:3px;" />' . $title . '</td>' . "\n";
//$return .= "\t\t" . '<td>' . stripslashes($arrLP[$i]['description']) . '</td>' . "\n";
$return .= "\t\t" . '<td>' . "\n";
if($arrLP[$i]['previous_item_id'] != 0)
$return .= "\t\t\t" . '<a href="' . api_get_self(). '?cidReq=' . $_GET['cidReq'] . '&action=move_item&direction=up&id=' . $arrLP[$i]['id'] . '&lp_id=' . $this->lp_id . '">';
$return .= '<img alt="" src="../img/arrow_up_' . ($arrLP[$i]['depth'] % 3) . '.gif" />';
$return .= '</a>' . "\n";
$return .= "\t\t\t" . '<img alt="" src="../img/blanco.png" title="" />' . "\n";
if($arrLP[$i]['next_item_id'] != 0)
$return .= "\t\t\t" . '<a href="' . api_get_self(). '?cidReq=' . $_GET['cidReq'] . '&action=move_item&direction=down&id=' . $arrLP[$i]['id'] . '&lp_id=' . $this->lp_id . '">';
$return .= '<img src="../img/arrow_down_' . ($arrLP[$i]['depth'] % 3) . '.gif" />';
$return .= '</a>' . "\n";
$return .= "\t\t\t" . '<img alt="" src="../img/blanco.png" title="" />' . "\n";
$return .= "\t\t" . '</td>' . "\n";
$return .= "\t\t" . '<td>' . "\n";
if($arrLP[$i]['item_type'] != 'dokeos_chapter' && $arrLP[$i]['item_type'] != 'dokeos_module')
$return .= "\t\t\t" . '<a href="' . api_get_self(). '?cidReq=' . $_GET['cidReq'] . '&action=edit_item&view=build&id=' . $arrLP[$i]['id'] . '&lp_id=' . $this->lp_id . '">';
$return .= '<img alt="" src="../img/edit.gif" title="' . get_lang('_edit_learnpath_module') . '" />';
$return .= '</a>' . "\n";
$return .= "\t\t\t" . '<a href="' . api_get_self(). '?cidReq=' . $_GET['cidReq'] . '&action=edit_item&id=' . $arrLP[$i]['id'] . '&lp_id=' . $this->lp_id . '">';
$return .= '<img alt="" src="../img/edit.gif" title="' . get_lang('_edit_learnpath_module') . '" />';
$return .= '</a>' . "\n";
$return .= "\t\t\t" . '<a href="' . api_get_self(). '?cidReq=' . $_GET['cidReq'] . '&action=delete_item&id=' . $arrLP[$i]['id'] . '&lp_id=' . $this->lp_id . '" onclick="return confirmation(\'' . addslashes($title). '\');">';
$return .= '<img alt="" src="../img/delete.gif" title="' . get_lang('_delete_learnpath_module') . '" />';
$return .= '</a>' . "\n";
$return .= "\t\t" . '</td>' . "\n";
$return .= "\t" . '</tr>' . "\n";
$return .= "\t" . '<tr>' . "\n";
$return .= "\t\t" . '<td colspan="4">'. get_lang("NoItemsInLp"). '</td>' . "\n";
$return .= "\t" . '</tr>' . "\n";
$return .= '</table>' . "\n";
* This functions builds the LP tree based on data from the database.
* @uses dtree.js :: necessary javascript for building this tree
$return = "<script type=\"text/javascript\">\n";
$return .= "\tm = new dTree('m');\n\n";
$return .= "\tm.config.folderLinks = true;\n";
$return .= "\tm.config.useCookies = true;\n";
$return .= "\tm.config.useIcons = true;\n";
$return .= "\tm.config.useLines = true;\n";
$return .= "\tm.config.useSelection = true;\n";
$return .= "\tm.config.useStatustext = false;\n\n";
$return .= "\tm.add(" . $menu . ", -1, '" . addslashes($this->name) . "');\n";
FROM " . $tbl_lp_item . "
lp_id = " . $this->lp_id;
'item_type' => $row['item_type'],
'title' => $row['title'],
'description' => $row['description'],
'parent_item_id' => $row['parent_item_id'],
'previous_item_id' => $row['previous_item_id'],
'next_item_id' => $row['next_item_id'],
'display_order' => $row['display_order']);
for($i = 0; $i < count($arrLP); $i++ )
$menu_page = api_get_self() . '?cidReq=' . $_GET['cidReq'] . '&action=view_item&id=' . $arrLP[$i]['id'] . '&lp_id=' . $_SESSION['oLP']->lp_id;
if(file_exists("../img/lp_" . $arrLP[$i]['item_type'] . ".png"))
$return .= "\tm.add(" . $arrLP[$i]['id'] . ", " . $arrLP[$i]['parent_item_id'] . ", '" . $title . "', '" . $menu_page . "', '', '', '../img/lp_" . $arrLP[$i]['item_type'] . ".png', '../img/lp_" . $arrLP[$i]['item_type'] . ".png');\n";
else if(file_exists("../img/lp_" . $arrLP[$i]['item_type'] . ".gif"))
$return .= "\tm.add(" . $arrLP[$i]['id'] . ", " . $arrLP[$i]['parent_item_id'] . ", '" . $title . "', '" . $menu_page . "', '', '', '../img/lp_" . $arrLP[$i]['item_type'] . ".gif', '../img/lp_" . $arrLP[$i]['item_type'] . ".gif');\n";
$return .= "\tm.add(" . $arrLP[$i]['id'] . ", " . $arrLP[$i]['parent_item_id'] . ", '" . $title . "', '" . $menu_page . "', '', '', '../img/lp_document.png', '../img/lp_document.png');\n";
if($menu < $arrLP[$i]['id'])
$menu = $arrLP[$i]['id'];
$return .= "\n\tdocument.write(m);\n";
$return .= "\t if(!m.selectedNode) m.s(1);";
$return .= "</script>\n";
* Create a new document //still needs some finetuning
$dir = isset ($_GET['dir']) ? $_GET['dir'] : $_POST['dir']; // please do not modify this dirname formatting
if($dir[strlen($dir) - 1] != '/')
$filepath = api_get_path('SYS_COURSE_PATH') . $_course['path'] . '/document' . $dir;
$filepath = api_get_path('SYS_COURSE_PATH') . $_course['path'] . '/document/';
//stripslashes before calling replace_dangerous_char() because $_POST['title']
//is already escaped twice when it gets here
$content = $_POST['content_lp'];
$tmp_filename = $filename;
while(file_exists($filepath . $tmp_filename . '.html'))
$tmp_filename = $filename . '_' . ++ $i;
$filename = $tmp_filename . '.html';
//if flv player, change absolute paht temporarely to prevent from erasing it in the following lines
// for flv player : change back the url to absolute
// for flv player : to prevent edition problem with firefox, we have to use a strange tip (don't blame me please)
$content = str_replace('</body>','<style type="text/css">body{}</style></body>',$content);
if($fp = @fopen($filepath . $filename, 'w'))
$file_size = filesize($filepath . $filename);
$save_file_path = $dir . $filename;
$document_id = add_document($_course, $save_file_path, 'file', $file_size, $filename . '.html');
//item_property_update_on_folder($_course, $_GET['dir'], $_user['user_id']);
$new_comment = (isset ($_POST['comment'])) ? trim($_POST['comment']) : '';
$new_title = (isset ($_POST['title'])) ? trim($_POST['title']) : '';
if($new_comment || $new_title)
$ct .= ", comment='" . $new_comment . "'";
$ct .= ", title='" . $new_title . ".html '";
WHERE id = " . $document_id;
* Enter description here...
$dir = isset ($_GET['dir']) ? $_GET['dir'] : $_POST['dir']; // please do not modify this dirname formatting
if($dir[strlen($dir) - 1] != '/')
$filepath = api_get_path('SYS_COURSE_PATH') . $_course['path'] . '/document'. $dir;
$filepath = api_get_path('SYS_COURSE_PATH') . $_course['path'] . '/document/';
WHERE id = " . $_POST['path'];
$file = $filepath . $row['path'];
if($fp = @fopen($file, 'w'))
* Displays the selected item, with a panel for manipulating the item
global $_course; //will disappear
FROM " . $tbl_lp_item . " as lp
$return .= '<div style="padding:10px;">';
$return .= '<p class="lp_title">' . stripslashes($row['title']) . '</p>';
//$return .= '<p class="lp_text">' . ((trim($row['description']) == '') ? 'no description' : stripslashes($row['description'])) . '</p>';
$sql_doc = "SELECT path FROM " . $tbl_doc . " WHERE id = " . $row['path'];
if(in_array($path_parts['extension'],array('html','txt','png', 'jpg', 'JPG', 'jpeg', 'JPEG', 'gif', 'swf')))
* Shows the needed forms for editing a specific item
global $_course; //will disappear
FROM " . $tbl_lp_item . "
switch($row['item_type'])
case 'dokeos_chapter': case 'dir' : case 'asset' : case 'sco' :
if(isset ($_GET['view']) && $_GET['view'] == 'build')
FROM " . $tbl_lp_item . " as lp
LEFT JOIN " . $tbl_doc . " as doc ON doc.id = lp.path
if(isset ($_GET['view']) && $_GET['view'] == 'build')
* Function that displays a list with al the resources that could be added to the learning path
global $_course; //TODO: don't use globals
$return = '<div style="margin:3px 12px;">' . "\n";
$return .= '<p class="lp_title" style="margin-top:0;">'. get_lang("CreateNewStep"). '</p>';
$return .= '<div style="margin-left:7px;"><a href="' . api_get_self(). '?cidReq=' . $_GET['cidReq'] . '&action=add_item&type=' . TOOL_DOCUMENT . '&lp_id=' . $_SESSION['oLP']->lp_id . '">'. get_lang("NewDocument"). '</a></div>';
$return .= '<p class="lp_title" style="margin-top:10px;">'. get_lang("UseAnExistingResource"). '</p>';
/* get all the exercises */
/* get al the student publications */
$return .= '</div>' . "\n";
* Returns the extension of a document
* @param unknown_type $filename
$explode = explode('.', $filename);
return $explode[count($explode) - 1];
* Displays a document by id
* @param unknown_type $id
function display_document($id, $show_title = false, $iframe = true, $edit_link = false)
global $_course; //temporary
//$return .= '<p class="lp_title">' . $row_doc['title'] . ($edit_link ? ' [ <a href="' .api_get_self(). '?cidReq=' . $_GET['cidReq'] . '&action=add_item&type=' . TOOL_DOCUMENT . '&file=' . $_GET['file'] . '&edit=true&lp_id=' . $_GET['lp_id'] . '">Edit this document</a> ]' : '') . '</p>';
//TODO: add a path filter
* Enter description here...
* @param unknown_type $action
* @param unknown_type $id
* @param unknown_type $extra_info
$item_description = stripslashes($extra_info['description']);
WHERE id = " . $extra_info;
$item_title = $row['title'];
$item_description = $row['description'];
$return = '<div style="margin:3px 12px;">';
$parent = $extra_info['parent_item_id'];
FROM " . $tbl_lp_item . "
lp_id = " . $this->lp_id;
'item_type' => $row['item_type'],
'title' => $row['title'],
'description' => $row['description'],
'parent_item_id' => $row['parent_item_id'],
'previous_item_id' => $row['previous_item_id'],
'next_item_id' => $row['next_item_id'],
'display_order' => $row['display_order'],
'prerequisite' => $row['prerequisite']);
$return .= '<p class="lp_title">'. get_lang("CreateTheExercise"). ' :</p>' . "\n";
elseif($action == 'move')
$return .= '<p class="lp_title">'. get_lang("MoveTheCurrentExercise"). ' :</p>' . "\n";
$return .= '<p class="lp_title">'. get_lang("EditCurrentExecice"). ' :</p>' . "\n";
if(isset ($_GET['edit']) && $_GET['edit'] == 'true')
$return .= '<div class="lp_message" style="margin-bottom:15px;">';
$return .= '<p class="lp_title">'. get_lang("Warning"). ' !</p>';
$return .= get_lang("WarningEditingDocument");
$return .= '<form method="POST">' . "\n";
$return .= "\t" . '<table cellpadding="0" cellspacing="0" class="lp_form">' . "\n";
$return .= "\t\t" . '<tr>' . "\n";
$return .= "\t\t\t" . '<td class="label"><label for="idParent">'. get_lang("Parent"). ' :</label></td>' . "\n";
$return .= "\t\t\t" . '<td class="input">' . "\n";
$return .= "\t\t\t\t" . '<select id="idParent" name="parent" onchange="load_cbo(this.value);" size="1">';
$return .= "\t\t\t\t\t" . '<option class="top" value="0">' . $this->name . '</option>';
for($i = 0; $i < count($arrLP); $i++ )
if(($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir') && !in_array($arrLP[$i]['id'], $arrHide) && !in_array($arrLP[$i]['parent_item_id'], $arrHide))
$return .= "\t\t\t\t\t" . '<option ' . (($parent == $arrLP[$i]['id']) ? 'selected="selected" ' : '') . 'style="padding-left:' . ($arrLP[$i]['depth'] * 10) . 'px;" value="' . $arrLP[$i]['id'] . '">' . mb_convert_encoding($arrLP[$i]['title'],$charset,$this->encoding) . '</option>';
$arrHide[] = $arrLP[$i]['id'];
if($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir')
$return .= "\t\t\t\t\t" . '<option ' . (($parent == $arrLP[$i]['id']) ? 'selected="selected" ' : '') . 'style="padding-left:' . ($arrLP[$i]['depth'] * 10) . 'px;" value="' . $arrLP[$i]['id'] . '">' . mb_convert_encoding($arrLP[$i]['title'],$charset,$this->encoding) . '</option>';
$return .= "\t\t\t\t" . '</select>';
$return .= "\t\t\t" . '</td>' . "\n";
$return .= "\t\t" . '</tr>' . "\n";
$return .= "\t\t" . '<tr>' . "\n";
$return .= "\t\t\t" . '<td class="label"><label for="idPosition">'. get_lang("Position"). ' :</label></td>' . "\n";
$return .= "\t\t\t" . '<td class="input">' . "\n";
$return .= "\t\t\t\t" . '<select id="idPosition" name="previous" size="1">';
$return .= "\t\t\t\t\t" . '<option class="top" value="0">'. get_lang('FirstPosition'). '</option>';
for($i = 0; $i < count($arrLP); $i++ )
if($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id)
if($extra_info['previous_item_id'] == $arrLP[$i]['id'])
$selected = 'selected="selected" ';
$selected = 'selected="selected" ';
$return .= "\t\t\t\t\t" . '<option ' . $selected . 'value="' . $arrLP[$i]['id'] . '">'. get_lang("After"). ' "' . mb_convert_encoding($arrLP[$i]['title'],$charset,$this->encoding) . '"</option>';
$return .= "\t\t\t\t" . '</select>';
$return .= "\t\t\t" . '</td>' . "\n";
$return .= "\t\t" . '</tr>' . "\n";
$return .= "\t\t" . '<tr>' . "\n";
$return .= "\t\t\t" . '<td class="label"><label for="idTitle">'. get_lang("Title"). ' :</label></td>' . "\n";
$return .= "\t\t\t" . '<td class="input"><input id="idTitle" name="title" type="text" value="' . $item_title . '" /></td>' . "\n";
$return .= "\t\t" . '</tr>' . "\n";
foreach($arrLP as $key=> $value){
$id_prerequisite= $value['prerequisite'];
for($i = 0; $i < count($arrLP); $i++ )
if($arrLP[$i]['id'] != $id && $arrLP[$i]['item_type'] != 'dokeos_chapter')
if($extra_info['previous_item_id'] == $arrLP[$i]['id'])
$s_selected_position= $arrLP[$i]['id'];
$return .= "\t\t" . '<tr>' . "\n";
$return .= "\t\t\t" . '<td class="label"><label for="idPrerequisites">'. get_lang("Prerequisites"). ' :</label></td>' . "\n";
$return .= "\t\t\t" . '<td class="input"><select name="prerequisites" id="prerequisites" style="background:#F8F8F8; border:1px solid #999999; font-family:Arial, Verdana, Helvetica, sans-serif; font-size:12px; width:300px;"><option value="0">'. get_lang("NoPrerequisites"). '</option>';
foreach($arrHide as $key => $value){
if($key== $s_selected_position && $action == 'add'){
$return .= '<option value="'. $key. '" selected="selected">'. $value['value']. '</option>';
elseif($key== $id_prerequisite && $action == 'edit'){
$return .= '<option value="'. $key. '" selected="selected">'. $value['value']. '</option>';
$return .= '<option value="'. $key. '">'. $value['value']. '</option>';
$return .= "</select></td>";
$return .= "\t\t" . '</tr>' . "\n";
$return .= "\t\t" . '<tr>' . "\n";
//Remove temporaly the test description
//$return .= "\t\t\t" . '<td class="label"><label for="idDescription">'.get_lang("Description").' :</label></td>' . "\n";
//$return .= "\t\t\t" . '<td class="input"><textarea id="idDescription" name="description" rows="4">' . $item_description . '</textarea></td>' . "\n";
$return .= "\t\t" . '</tr>' . "\n";
$return .= "\t\t" . '<tr>' . "\n";
$return .= "\t\t\t" . '<td colspan="2"><input class="button" name="submit_button" type="submit" value="'. get_lang('Ok'). '" /></td>' . "\n";
$return .= "\t\t" . '</tr>' . "\n";
$return .= "\t" . '</table>' . "\n";
$return .= "\t" . '<input name="title" type="hidden" value="' . $item_title . '" />' . "\n";
$return .= "\t" . '<input name="description" type="hidden" value="' . $item_description . '" />' . "\n";
$return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info . '" />' . "\n";
$return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info['path'] . '" />' . "\n";
$return .= "\t" . '<input name="type" type="hidden" value="'. TOOL_QUIZ. '" />' . "\n";
$return .= "\t" . '<input name="post_time" type="hidden" value="' . time() . '" />' . "\n";
$return .= '</form>' . "\n";
$return .= '</div>' . "\n";
* Addition of Hotpotatoes tests
* @param integer Internal ID of the item
* @param mixed Extra information - can be an array with title and description indexes
* @return string HTML structure to display the hotpotatoes addition formular
$item_description = stripslashes($extra_info['description']);
$sql_hot = "SELECT * FROM ". $TBL_DOCUMENT. "
WHERE path LIKE '". $uploadPath. "/%/%htm%'
$item_title = $row['title'];
$item_description = $row['description'];
$return = '<div style="margin:3px 12px;">';
$parent = $extra_info['parent_item_id'];
FROM " . $tbl_lp_item . "
lp_id = " . $this->lp_id;
'item_type' => $row['item_type'],
'title' => $row['title'],
'description' => $row['description'],
'parent_item_id' => $row['parent_item_id'],
'previous_item_id' => $row['previous_item_id'],
'next_item_id' => $row['next_item_id'],
'display_order' => $row['display_order'],
'prerequisite' => $row['prerequisite']);
$return .= '<p class="lp_title">'. get_lang("CreateTheExercise"). ' :</p>' . "\n";
elseif($action == 'move')
$return .= '<p class="lp_title">'. get_lang("MoveTheCurrentExercise"). ' :</p>' . "\n";
$return .= '<p class="lp_title">'. get_lang("EditCurrentExecice"). ' :</p>' . "\n";
if(isset ($_GET['edit']) && $_GET['edit'] == 'true')
$return .= '<div class="lp_message" style="margin-bottom:15px;">';
$return .= '<p class="lp_title">'. get_lang("Warning"). ' !</p>';
$return .= get_lang("WarningEditingDocument");
$return .= '<form method="POST">' . "\n";
$return .= "\t" . '<table cellpadding="0" cellspacing="0" class="lp_form">' . "\n";
$return .= "\t\t" . '<tr>' . "\n";
$return .= "\t\t\t" . '<td class="label"><label for="idParent">'. get_lang("Parent"). ' :</label></td>' . "\n";
$return .= "\t\t\t" . '<td class="input">' . "\n";
$return .= "\t\t\t\t" . '<select id="idParent" name="parent" onchange="load_cbo(this.value);" size="1">';
$return .= "\t\t\t\t\t" . '<option class="top" value="0">' . $this->name . '</option>';
for($i = 0; $i < count($arrLP); $i++ )
if(($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir') && !in_array($arrLP[$i]['id'], $arrHide) && !in_array($arrLP[$i]['parent_item_id'], $arrHide))
$return .= "\t\t\t\t\t" . '<option ' . (($parent == $arrLP[$i]['id']) ? 'selected="selected" ' : '') . 'style="padding-left:' . ($arrLP[$i]['depth'] * 10) . 'px;" value="' . $arrLP[$i]['id'] . '">' . mb_convert_encoding($arrLP[$i]['title'],$charset,$this->encoding) . '</option>';
$arrHide[] = $arrLP[$i]['id'];
if($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir')
$return .= "\t\t\t\t\t" . '<option ' . (($parent == $arrLP[$i]['id']) ? 'selected="selected" ' : '') . 'style="padding-left:' . ($arrLP[$i]['depth'] * 10) . 'px;" value="' . $arrLP[$i]['id'] . '">' . mb_convert_encoding($arrLP[$i]['title'],$charset,$this->encoding) . '</option>';
$return .= "\t\t\t\t" . '</select>';
$return .= "\t\t\t" . '</td>' . "\n";
$return .= "\t\t" . '</tr>' . "\n";
$return .= "\t\t" . '<tr>' . "\n";
$return .= "\t\t\t" . '<td class="label"><label for="idPosition">'. get_lang("Position"). ' :</label></td>' . "\n";
$return .= "\t\t\t" . '<td class="input">' . "\n";
$return .= "\t\t\t\t" . '<select id="idPosition" name="previous" size="1">';
$return .= "\t\t\t\t\t" . '<option class="top" value="0">'. get_lang('FirstPosition'). '</option>';
for($i = 0; $i < count($arrLP); $i++ )
if($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id)
if($extra_info['previous_item_id'] == $arrLP[$i]['id'])
$selected = 'selected="selected" ';
$selected = 'selected="selected" ';
$return .= "\t\t\t\t\t" . '<option ' . $selected . 'value="' . $arrLP[$i]['id'] . '">'. get_lang("After"). ' "' . mb_convert_encoding($arrLP[$i]['title'],$charset,$this->encoding) . '"</option>';
$return .= "\t\t\t\t" . '</select>';
$return .= "\t\t\t" . '</td>' . "\n";
$return .= "\t\t" . '</tr>' . "\n";
$return .= "\t\t" . '<tr>' . "\n";
$return .= "\t\t\t" . '<td class="label"><label for="idTitle">'. get_lang("Title"). ' :</label></td>' . "\n";
$return .= "\t\t\t" . '<td class="input"><input id="idTitle" name="title" type="text" value="' . $item_title . '" /></td>' . "\n";
$return .= "\t\t" . '</tr>' . "\n";
foreach($arrLP as $key=> $value){
$id_prerequisite= $value['prerequisite'];
for($i = 0; $i < count($arrLP); $i++ )
if($arrLP[$i]['id'] != $id && $arrLP[$i]['item_type'] != 'dokeos_chapter')
if($extra_info['previous_item_id'] == $arrLP[$i]['id'])
$s_selected_position= $arrLP[$i]['id'];
$return .= "\t\t" . '<tr>' . "\n";
$return .= "\t\t\t" . '<td class="label"><label for="idPrerequisites">'. get_lang("Prerequisites"). ' :</label></td>' . "\n";
$return .= "\t\t\t" . '<td class="input"><select name="prerequisites" id="prerequisites" style="background:#F8F8F8; border:1px solid #999999; font-family:Arial, Verdana, Helvetica, sans-serif; font-size:12px; width:300px;"><option value="0">'. get_lang("NoPrerequisites"). '</option>';
foreach($arrHide as $key => $value){
if($key== $s_selected_position && $action == 'add'){
$return .= '<option value="'. $key. '" selected="selected">'. $value['value']. '</option>';
elseif($key== $id_prerequisite && $action == 'edit'){
$return .= '<option value="'. $key. '" selected="selected">'. $value['value']. '</option>';
$return .= '<option value="'. $key. '">'. $value['value']. '</option>';
$return .= "</select></td>";
$return .= "\t\t" . '</tr>' . "\n";
$return .= "\t\t" . '<tr>' . "\n";
//Remove temporaly the test description
//$return .= "\t\t\t" . '<td class="label"><label for="idDescription">'.get_lang("Description").' :</label></td>' . "\n";
//$return .= "\t\t\t" . '<td class="input"><textarea id="idDescription" name="description" rows="4">' . $item_description . '</textarea></td>' . "\n";
$return .= "\t\t" . '</tr>' . "\n";
$return .= "\t\t" . '<tr>' . "\n";
$return .= "\t\t\t" . '<td colspan="2"><input class="button" name="submit_button" type="submit" value="'. get_lang('Ok'). '" /></td>' . "\n";
$return .= "\t\t" . '</tr>' . "\n";
$return .= "\t" . '</table>' . "\n";
$return .= "\t" . '<input name="title" type="hidden" value="' . $item_title . '" />' . "\n";
$return .= "\t" . '<input name="description" type="hidden" value="' . $item_description . '" />' . "\n";
$return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info . '" />' . "\n";
$return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info['path'] . '" />' . "\n";
$return .= "\t" . '<input name="type" type="hidden" value="'. TOOL_HOTPOTATOES. '" />' . "\n";
$return .= "\t" . '<input name="post_time" type="hidden" value="' . time() . '" />' . "\n";
$return .= '</form>' . "\n";
$return .= '</div>' . "\n";
* Enter description here...
* @param unknown_type $action
* @param unknown_type $id
* @param unknown_type $extra_info
forum_title as title, forum_comment as comment
WHERE forum_id = " . $extra_info;
$item_title = $row['title'];
$item_description = $row['comment'];
$return = '<div style="margin:3px 12px;">';
$parent = $extra_info['parent_item_id'];
FROM " . $tbl_lp_item . "
lp_id = " . $this->lp_id;
'item_type' => $row['item_type'],
'title' => $row['title'],
'description' => $row['description'],
'parent_item_id' => $row['parent_item_id'],
'previous_item_id' => $row['previous_item_id'],
'next_item_id' => $row['next_item_id'],
'display_order' => $row['display_order'],
'prerequisite' => $row['prerequisite']);
$return .= '<p class="lp_title">'. get_lang("CreateTheForum"). ' :</p>' . "\n";
elseif($action == 'move')
$return .= '<p class="lp_title">'. get_lang("MoveTheCurrentForum"). ' :</p>' . "\n";
$return .= '<p class="lp_title">'. get_lang("EditCurrentForum"). ' :</p>' . "\n";
$return .= '<form method="POST">' . "\n";
$return .= "\t" . '<table cellpadding="0" cellspacing="0" class="lp_form">' . "\n";
$return .= "\t\t" . '<tr>' . "\n";
$return .= "\t\t\t" . '<td class="label"><label for="idParent">'. get_lang("Parent"). ' :</label></td>' . "\n";
$return .= "\t\t\t" . '<td class="input">' . "\n";
$return .= "\t\t\t\t" . '<select id="idParent" name="parent" onchange="load_cbo(this.value);" size="1">';
$return .= "\t\t\t\t\t" . '<option class="top" value="0">' . $this->name . '</option>';
for($i = 0; $i < count($arrLP); $i++ )
if(($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir') && !in_array($arrLP[$i]['id'], $arrHide) && !in_array($arrLP[$i]['parent_item_id'], $arrHide))
$return .= "\t\t\t\t\t" . '<option ' . (($parent == $arrLP[$i]['id']) ? 'selected="selected" ' : '') . 'style="padding-left:' . ($arrLP[$i]['depth'] * 10) . 'px;" value="' . $arrLP[$i]['id'] . '">' . mb_convert_encoding($arrLP[$i]['title'],$charset,$this->encoding) . '</option>';
$arrHide[] = $arrLP[$i]['id'];
if($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir')
$return .= "\t\t\t\t\t" . '<option ' . (($parent == $arrLP[$i]['id']) ? 'selected="selected" ' : '') . 'style="padding-left:' . ($arrLP[$i]['depth'] * 10) . 'px;" value="' . $arrLP[$i]['id'] . '">' . mb_convert_encoding($arrLP[$i]['title'],$charset,$this->encoding) . '</option>';
$return .= "\t\t\t\t" . '</select>';
$return .= "\t\t\t" . '</td>' . "\n";
$return .= "\t\t" . '</tr>' . "\n";
$return .= "\t\t" . '<tr>' . "\n";
$return .= "\t\t\t" . '<td class="label"><label for="idPosition">'. get_lang("Position"). ' :</label></td>' . "\n";
$return .= "\t\t\t" . '<td class="input">' . "\n";
$return .= "\t\t\t\t" . '<select id="idPosition" name="previous" size="1">';
$return .= "\t\t\t\t\t" . '<option class="top" value="0">'. get_lang('FirstPosition'). '</option>';
for($i = 0; $i < count($arrLP); $i++ )
if($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id)
if($extra_info['previous_item_id'] == $arrLP[$i]['id'])
$selected = 'selected="selected" ';
$selected = 'selected="selected" ';
$return .= "\t\t\t\t\t" . '<option ' . $selected . 'value="' . $arrLP[$i]['id'] . '">'. get_lang("After"). ' "' . mb_convert_encoding($arrLP[$i]['title'],$charset,$this->encoding) . '"</option>';
$return .= "\t\t\t\t" . '</select>';
$return .= "\t\t\t" . '</td>' . "\n";
$return .= "\t\t" . '</tr>' . "\n";
$return .= "\t\t" . '<tr>' . "\n";
$return .= "\t\t\t" . '<td class="label"><label for="idTitle">'. get_lang("Title"). ' :</label></td>' . "\n";
$return .= "\t\t\t" . '<td class="input"><input id="idTitle" name="title" type="text" value="' . $item_title . '" /></td>' . "\n";
$return .= "\t\t" . '</tr>' . "\n";
$return .= "\t\t" . '<tr>' . "\n";
//Remove temporaly the test description
//$return .= "\t\t\t" . '<td class="label"><label for="idDescription">'.get_lang("Description").' :</label></td>' . "\n";
//$return .= "\t\t\t" . '<td class="input"><textarea id="idDescription" name="description" rows="4">' . $item_description . '</textarea></td>' . "\n";
$return .= "\t\t" . '</tr>' . "\n";
foreach($arrLP as $key=> $value){
$id_prerequisite= $value['prerequisite'];
for($i = 0; $i < count($arrLP); $i++ )
if($arrLP[$i]['id'] != $id && $arrLP[$i]['item_type'] != 'dokeos_chapter')
if($extra_info['previous_item_id'] == $arrLP[$i]['id'])
$s_selected_position= $arrLP[$i]['id'];
$return .= "\t\t" . '<tr>' . "\n";
$return .= "\t\t\t" . '<td class="label"><label for="idPrerequisites">'. get_lang('Prerequisites'). ' :</label></td>' . "\n";
$return .= "\t\t\t" . '<td class="input"><select name="prerequisites" id="prerequisites" style="background:#F8F8F8; border:1px solid #999999; font-family:Arial, Verdana, Helvetica, sans-serif; font-size:12px; width:300px;"><option value="0">'. get_lang("NoPrerequisites"). '</option>';
foreach($arrHide as $key => $value){
if($key== $s_selected_position && $action == 'add'){
$return .= '<option value="'. $key. '" selected="selected">'. $value['value']. '</option>';
elseif($key== $id_prerequisite && $action == 'edit'){
$return .= '<option value="'. $key. '" selected="selected">'. $value['value']. '</option>';
$return .= '<option value="'. $key. '">'. $value['value']. '</option>';
$return .= "</select></td>";
$return .= "\t\t" . '</tr>' . "\n";
$return .= "\t\t" . '<tr>' . "\n";
$return .= "\t\t\t" . '<td colspan="2"><input class="button" name="submit_button" type="submit" value="'. get_lang('Ok'). '" /></td>' . "\n";
$return .= "\t\t" . '</tr>' . "\n";
$return .= "\t" . '</table>' . "\n";
$return .= "\t" . '<input name="title" type="hidden" value="' . $item_title . '" />' . "\n";
$return .= "\t" . '<input name="description" type="hidden" value="' . $item_description . '" />' . "\n";
$return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info . '" />' . "\n";
$return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info['path'] . '" />' . "\n";
$return .= "\t" . '<input name="type" type="hidden" value="'. TOOL_FORUM. '" />' . "\n";
$return .= "\t" . '<input name="post_time" type="hidden" value="' . time() . '" />' . "\n";
$return .= '</form>' . "\n";
$return .= '</div>' . "\n";
WHERE thread_id = " . $extra_info;
$item_title = $row['title'];
$return = '<div style="margin:3px 12px;">';
$parent = $extra_info['parent_item_id'];
FROM " . $tbl_lp_item . "
lp_id = " . $this->lp_id;
'item_type' => $row['item_type'],
'title' => $row['title'],
'description' => $row['description'],
'parent_item_id' => $row['parent_item_id'],
'previous_item_id' => $row['previous_item_id'],
'next_item_id' => $row['next_item_id'],
'display_order' => $row['display_order'],
'prerequisite' => $row['prerequisite']);
$return .= '<p class="lp_title">'. get_lang("CreateTheForum"). ' :</p>' . "\n";
elseif($action == 'move')
$return .= '<p class="lp_title">'. get_lang("MoveTheCurrentForum"). ' :</p>' . "\n";
$return .= '<p class="lp_title">'. get_lang("EditCurrentForum"). ' :</p>' . "\n";
$return .= '<form method="POST">' . "\n";
$return .= "\t" . '<table cellpadding="0" cellspacing="0" class="lp_form">' . "\n";
$return .= "\t\t" . '<tr>' . "\n";
$return .= "\t\t\t" . '<td class="label"><label for="idParent">'. get_lang("Parent"). ' :</label></td>' . "\n";
$return .= "\t\t\t" . '<td class="input">' . "\n";
$return .= "\t\t\t\t" . '<select id="idParent" name="parent" onchange="load_cbo(this.value);" size="1">';
$return .= "\t\t\t\t\t" . '<option class="top" value="0">' . $this->name . '</option>';
for($i = 0; $i < count($arrLP); $i++ )
if(($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir') && !in_array($arrLP[$i]['id'], $arrHide) && !in_array($arrLP[$i]['parent_item_id'], $arrHide))
$return .= "\t\t\t\t\t" . '<option ' . (($parent == $arrLP[$i]['id']) ? 'selected="selected" ' : '') . 'style="padding-left:' . ($arrLP[$i]['depth'] * 10) . 'px;" value="' . $arrLP[$i]['id'] . '">' . mb_convert_encoding($arrLP[$i]['title'],$charset,$this->encoding) . '</option>';
$arrHide[] = $arrLP[$i]['id'];
if($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir')
$return .= "\t\t\t\t\t" . '<option ' . (($parent == $arrLP[$i]['id']) ? 'selected="selected" ' : '') . 'style="padding-left:' . ($arrLP[$i]['depth'] * 10) . 'px;" value="' . $arrLP[$i]['id'] . '">' . mb_convert_encoding($arrLP[$i]['title'],$charset,$this->encoding) . '</option>';
$return .= "\t\t\t\t" . '</select>';
$return .= "\t\t\t" . '</td>' . "\n";
$return .= "\t\t" . '</tr>' . "\n";
$return .= "\t\t" . '<tr>' . "\n";
$return .= "\t\t\t" . '<td class="label"><label for="idPosition">'. get_lang("Position"). ' :</label></td>' . "\n";
$return .= "\t\t\t" . '<td class="input">' . "\n";
$return .= "\t\t\t\t" . '<select id="idPosition" name="previous" size="1">';
$return .= "\t\t\t\t\t" . '<option class="top" value="0">'. get_lang('FirstPosition'). '</option>';
for($i = 0; $i < count($arrLP); $i++ )
if($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id)
if($extra_info['previous_item_id'] == $arrLP[$i]['id'])
$selected = 'selected="selected" ';
$selected = 'selected="selected" ';
$return .= "\t\t\t\t\t" . '<option ' . $selected . 'value="' . $arrLP[$i]['id'] . '">'. get_lang("After"). ' "' . mb_convert_encoding($arrLP[$i]['title'],$charset,$this->encoding) . '"</option>';
$return .= "\t\t\t\t" . '</select>';
$return .= "\t\t\t" . '</td>' . "\n";
$return .= "\t\t" . '</tr>' . "\n";
$return .= "\t\t" . '<tr>' . "\n";
$return .= "\t\t\t" . '<td class="label"><label for="idTitle">'. get_lang("Title"). ' :</label></td>' . "\n";
$return .= "\t\t\t" . '<td class="input"><input id="idTitle" name="title" type="text" value="' . $item_title . '" /></td>' . "\n";
$return .= "\t\t" . '</tr>' . "\n";
$return .= "\t\t" . '<tr>' . "\n";
//Remove temporaly the test description
//$return .= "\t\t\t" . '<td class="label"><label for="idDescription">'.get_lang("Description").' :</label></td>' . "\n";
//$return .= "\t\t\t" . '<td class="input"><textarea id="idDescription" name="description" rows="4">' . $item_description . '</textarea></td>' . "\n";
$return .= "\t\t" . '</tr>' . "\n";
foreach($arrLP as $key=> $value){
$id_prerequisite= $value['prerequisite'];
for($i = 0; $i < count($arrLP); $i++ )
if($arrLP[$i]['id'] != $id && $arrLP[$i]['item_type'] != 'dokeos_chapter')
if($extra_info['previous_item_id'] == $arrLP[$i]['id'])
$s_selected_position= $arrLP[$i]['id'];
$return .= "\t\t" . '<tr>' . "\n";
$return .= "\t\t\t" . '<td class="label"><label for="idPrerequisites">'. get_lang("Prerequisites"). ' :</label></td>' . "\n";
$return .= "\t\t\t" . '<td class="input"><select name="prerequisites" id="prerequisites" style="background:#F8F8F8; border:1px solid #999999; font-family:Arial, Verdana, Helvetica, sans-serif; font-size:12px; width:300px;"><option value="0">'. get_lang("NoPrerequisites"). '</option>';
foreach($arrHide as $key => $value){
if($key== $s_selected_position && $action == 'add'){
$return .= '<option value="'. $key. '" selected="selected">'. $value['value']. '</option>';
elseif($key== $id_prerequisite && $action == 'edit'){
$return .= '<option value="'. $key. '" selected="selected">'. $value['value']. '</option>';
$return .= '<option value="'. $key. '">'. $value['value']. '</option>';
$return .= "</select></td>";
$return .= "\t\t" . '</tr>' . "\n";
$return .= "\t\t" . '<tr>' . "\n";
$return .= "\t\t\t" . '<td colspan="2"><input class="button" name="submit_button" type="submit" value="'. get_lang('Ok'). '" /></td>' . "\n";
$return .= "\t\t" . '</tr>' . "\n";
$return .= "\t" . '</table>' . "\n";
$return .= "\t" . '<input name="title" type="hidden" value="' . $item_title . '" />' . "\n";
$return .= "\t" . '<input name="description" type="hidden" value="' . $item_description . '" />' . "\n";
$return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info . '" />' . "\n";
$return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info['path'] . '" />' . "\n";
$return .= "\t" . '<input name="type" type="hidden" value="'. TOOL_THREAD. '" />' . "\n";
$return .= "\t" . '<input name="post_time" type="hidden" value="' . time() . '" />' . "\n";
$return .= '</form>' . "\n";
$return .= '</div>' . "\n";
* Enter description here...
* @param unknown_type $item_type
* @param unknown_type $title
* @param unknown_type $action
* @param unknown_type $id
* @param unknown_type $extra_info
function display_item_form($item_type, $title = '', $action = 'add', $id = 0, $extra_info = 'new')
$item_title = $extra_info['title'];
$item_description = $extra_info['description'];
$return = '<div style="margin:10px 12px;">';
$parent = $extra_info['parent_item_id'];
FROM " . $tbl_lp_item . "
WHERE lp_id = " . $this->lp_id. " AND id != " . $id. " ";
if($item_type == 'module')
$sql .= " AND parent_item_id = 0";
'item_type' => $row['item_type'],
'title' => $row['title'],
'description' => $row['description'],
'parent_item_id' => $row['parent_item_id'],
'previous_item_id' => $row['previous_item_id'],
'next_item_id' => $row['next_item_id'],
'display_order' => $row['display_order']);
$return .= '<p class="lp_title">' . $title . '</p>' . "\n";
$form->addElement('html',$return);
$arrHide[0]['value']= $this->name;
$arrHide[0]['padding']= 3;
if($item_type != 'module' && $item_type != 'dokeos_module')
for($i = 0; $i < count($arrLP); $i++ )
if(($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir') && !in_array($arrLP[$i]['id'], $arrHide) && !in_array($arrLP[$i]['parent_item_id'], $arrHide))
$arrHide[$arrLP[$i]['id']]['padding']= 3+ $arrLP[$i]['depth'] * 10;
if($parent == $arrLP[$i]['id'])
$s_selected_parent= $arrHide[$arrLP[$i]['id']];
if($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir')
$arrHide[$arrLP[$i]['id']]['padding']= 3+ $arrLP[$i]['depth'] * 10;
if($parent == $arrLP[$i]['id'])
$s_selected_parent= $arrHide[$arrLP[$i]['id']];
$parent_select = &$form->addElement('select', 'parent', get_lang("Parent"). " :", '', 'style="background:#F8F8F8; border:1px solid #999999; font-family:Arial, Verdana, Helvetica, sans-serif; font-size:12px; width:300px;" onchange="load_cbo(this.value);"');
foreach($arrHide as $key => $value)
$parent_select->addOption($value['value'],$key,'style="padding-left:'. $value['padding']. 'px;"');
$parent_select -> setSelected($s_selected_parent);
for($i = 0; $i < count($arrLP); $i++ )
if($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id)
if($extra_info['previous_item_id'] == $arrLP[$i]['id'])
$s_selected_position= $arrLP[$i]['id'];
$s_selected_position= $arrLP[$i]['id'];
$position = &$form->addElement('select', 'previous', get_lang("Position"). " :", '', 'id="idPosition" style="background:#F8F8F8; border:1px solid #999999; font-family:Arial, Verdana, Helvetica, sans-serif; font-size:12px; width:300px;"');
$position->addOption(get_lang('FirstPosition'),0,'style="padding-left:'. $value['padding']. 'px;"');
foreach($arrHide as $key => $value)
$position->addOption($value['value'],$key,'style="padding-left:'. $value['padding']. 'px;"');
if(!empty($s_selected_position)) { $position->setSelected($s_selected_position); }
$form->addElement('text','title', get_lang('Title'). ' :','id="idTitle" style="background:#F8F8F8; border:1px solid #999999; font-family:Arial, Verdana, Helvetica, sans-serif; font-size:12px; padding:1px 2px; width:300px;"');
//$form->addElement('textarea','description',get_lang("Description").' :', 'id="idDescription" style="background:#F8F8F8; border:1px solid #999999; font-family:Arial, Verdana, Helvetica, sans-serif; font-size:12px; padding:1px 2px; width:300px;"');
$form->addElement('hidden','title');
$form->addElement('submit', 'submit_button', get_lang('Ok'), 'style="padding:1px 2px; width:75px;"');
if($item_type == 'module' || $item_type == 'dokeos_module')
$form->addElement('hidden', 'parent', '0');
$extension = pathinfo($item_path, PATHINFO_EXTENSION);
if(($item_type== 'asset' || $item_type== 'sco') && ($extension == 'html' || $extension == 'htm'))
$form->addElement('html','<script type="text/javascript">alert("'. get_lang('WarningWhenEditingScorm'). '")</script>');
$renderer = $form->defaultRenderer();
$renderer->setElementTemplate('<br /> {label}<br />{element}','content_lp');
$form->addElement('html_editor','content_lp','');
//$form->addElement('html_editor','content_lp','');
$form->addElement('hidden', 'type', 'dokeos_'. $item_type);
$form->addElement('hidden', 'post_time', time());
$form->setDefaults($defaults);
$form->addElement('html','</div>');
return $form->return_form();
* Enter description here...
* @param unknown_type $action
* @param unknown_type $id
* @param unknown_type $extra_info
$path_parts = pathinfo($extra_info['dir']);
$no_display_edit_textarea= false;
//If action==edit document
//We don't display the document form if it's not an editable document (html or txt file)
if($path_parts['extension']!= "txt" && $path_parts['extension']!= "html"){
$no_display_edit_textarea= true;
//If action==add an existing document
//We don't display the document form if it's not an editable document (html or txt file)
$sql_doc = "SELECT path FROM " . $tbl_doc . "WHERE id = " . $extra_info;
if($path_parts['extension']!= "txt" && $path_parts['extension']!= "html"){
$item_description = stripslashes($extra_info['description']);
$path_parts = pathinfo($extra_info['path']);
WHERE id = " . $extra_info;
$explode = explode('.', $row['title']);
for($i = 0; $i < count($explode) - 1; $i++ )
$item_title .= $explode[$i];
$item_title= $row['title'];
$return = '<div style="margin:3px 12px;">';
$parent = $extra_info['parent_item_id'];
FROM " . $tbl_lp_item . "
lp_id = " . $this->lp_id;
'item_type' => $row['item_type'],
'title' => $row['title'],
'description' => $row['description'],
'parent_item_id' => $row['parent_item_id'],
'previous_item_id' => $row['previous_item_id'],
'next_item_id' => $row['next_item_id'],
'display_order' => $row['display_order'],
'prerequisite' => $row['prerequisite']);
$return .= '<p class="lp_title">'. get_lang("CreateTheDocument"). ' :</p>' . "\n";
elseif($action == 'move')
$return .= '<p class="lp_title">'. get_lang("MoveTheCurrentDocument"). ' :</p>' . "\n";
$return .= '<p class="lp_title">'. get_lang("EditTheCurrentDocument"). ' :</p>' . "\n";
if(isset ($_GET['edit']) && $_GET['edit'] == 'true')
$return .= '<div class="lp_message" style="margin-bottom:15px;">';
$return .= '<p class="lp_title">'. get_lang("Warning"). ' !</p>';
$return .= get_lang("WarningEditingDocument");
if($no_display_add==true){
$return .= '<div class="lp_message" style="margin-bottom:15px;">';
$return .= get_lang("CantEditDocument");
$form->addElement('html',$return);
$arrHide[0]['value']= $this->name;
$arrHide[0]['padding']= 3;
for($i = 0; $i < count($arrLP); $i++ )
if(($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir') && !in_array($arrLP[$i]['id'], $arrHide) && !in_array($arrLP[$i]['parent_item_id'], $arrHide)){
$arrHide[$arrLP[$i]['id']]['padding']= 3+ $arrLP[$i]['depth'] * 10;
if($parent == $arrLP[$i]['id']){
$s_selected_parent= $arrHide[$arrLP[$i]['id']];
if($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir'){
$arrHide[$arrLP[$i]['id']]['padding']= 3+ $arrLP[$i]['depth'] * 10;
if($parent == $arrLP[$i]['id']){
$s_selected_parent= $arrHide[$arrLP[$i]['id']];
$parent_select = &$form->addElement('select', 'parent', get_lang("Parent"). " :", '', 'style="background:#F8F8F8; border:1px solid #999999; font-family:Arial, Verdana, Helvetica, sans-serif; font-size:12px; width:300px;" onchange="load_cbo(this.value);"');
foreach($arrHide as $key => $value)
$parent_select->addOption($value['value'],$key,'style="padding-left:'. $value['padding']. 'px;"');
$parent_select -> setSelected($parent);
for($i = 0; $i < count($arrLP); $i++ )
if($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id)
if($extra_info['previous_item_id'] == $arrLP[$i]['id'])
$s_selected_position= $arrLP[$i]['id'];
$s_selected_position= $arrLP[$i]['id'];
$position = &$form->addElement('select', 'previous', get_lang("Position"). " :", '', 'id="idPosition" style="background:#F8F8F8; border:1px solid #999999; font-family:Arial, Verdana, Helvetica, sans-serif; font-size:12px; padding:1px 2px; width:300px;"');
$position->addOption(get_lang("FirstPosition"),0,'style="padding-left:3px;"');
foreach($arrHide as $key => $value)
$position->addOption($value['value'],$key,'style="padding-left:'. $value['padding']. 'px;"');
$position -> setSelected($s_selected_position);
$form->addElement('text','title', get_lang('Title'). ' :','id="idTitle" style="background:#F8F8F8; border:1px solid #999999; font-family:Arial, Verdana, Helvetica, sans-serif; font-size:12px; width:295px;"');
foreach($arrLP as $key=> $value){
$id_prerequisite= $value['prerequisite'];
$select_prerequisites= $form->addElement('select', 'prerequisites', get_lang('Prerequisites'). ' :', '', 'id="prerequisites" style="background:#F8F8F8; border:1px solid #999999; font-family:Arial, Verdana, Helvetica, sans-serif; font-size:12px; width:300px;"');
$select_prerequisites->addOption(get_lang("NoPrerequisites"),0,'style="padding-left:3px;"');
for($i = 0; $i < count($arrLP); $i++ )
if($arrLP[$i]['id'] != $id && $arrLP[$i]['item_type'] != 'dokeos_chapter')
if($extra_info['previous_item_id'] == $arrLP[$i]['id'])
$s_selected_position= $arrLP[$i]['id'];
$s_selected_position= $arrLP[$i]['id'];
foreach($arrHide as $key => $value){
$select_prerequisites->addOption($value['value'],$key,'style="padding-left:'. $value['padding']. 'px;"');
if($key== $s_selected_position && $action == 'add'){
$select_prerequisites -> setSelected(0);
elseif($key== $id_prerequisite && $action == 'edit'){
$select_prerequisites -> setSelected($id_prerequisite);
if(($extra_info == 'new' || $extra_info['item_type'] == TOOL_DOCUMENT || $_GET['edit'] == 'true'))
if(isset ($_POST['content']))
//If it's an html document or a text file
if(!$no_display_edit_textarea){
$form->addElement('submit', 'submit_button', get_lang('Ok'), 'style="padding:1px 2px; width:75px;"');
if(!$no_display_edit_textarea)
$renderer = $form->defaultRenderer();
$renderer->setElementTemplate('<br /> {label}<br />{element}','content_lp');
$form->addElement('html','<div style="margin:3px 12px">');
$form->addElement('html_editor','content_lp','');
$form->addElement('html','</div>');
$defaults["content_lp"]= $content;
$form->addElement('submit', 'submit_button', get_lang('Ok'), 'style="padding:1px 2px; width:75px;"');
$form->addElement('html',$return);
$form->addElement('hidden', 'title', $item_title);
$form->addElement('hidden', 'description', $item_description);
$form->addElement('submit', 'submit_button', get_lang('Ok'), 'style="padding:1px 2px; width:75px;"');
$form->addElement('hidden', 'path', $extra_info);
$form->addElement('submit', 'submit_button', get_lang('Ok'), 'style="padding:1px 2px; width:75px;"');
$form->addElement('hidden', 'path', $extra_info['path']);
$form->addElement('hidden', 'post_time', time());
$form->setDefaults($defaults);
return $form->return_form();
* Enter description here...
* @param unknown_type $action
* @param unknown_type $id
* @param unknown_type $extra_info
$item_description = stripslashes($extra_info['description']);
WHERE id = " . $extra_info;
$item_title = $row['title'];
$item_description = $row['description'];
$return = '<div style="margin:3px 12px;">';
$parent = $extra_info['parent_item_id'];
FROM " . $tbl_lp_item . "
lp_id = " . $this->lp_id;
'item_type' => $row['item_type'],
'title' => $row['title'],
'description' => $row['description'],
'parent_item_id' => $row['parent_item_id'],
'previous_item_id' => $row['previous_item_id'],
'next_item_id' => $row['next_item_id'],
'display_order' => $row['display_order'],
'prerequisite' => $row['prerequisite']);
$return .= '<p class="lp_title">'. get_lang("CreateTheLink"). ' :</p>' . "\n";
elseif($action == 'move')
$return .= '<p class="lp_title">'. get_lang("MoveCurrentLink"). ' :</p>' . "\n";
$return .= '<p class="lp_title">'. get_lang("EditCurrentLink"). ' :</p>' . "\n";
$return .= '<form method="POST">' . "\n";
$return .= "\t" . '<table cellpadding="0" cellspacing="0" class="lp_form">' . "\n";
$return .= "\t\t" . '<tr>' . "\n";
$return .= "\t\t\t" . '<td class="label"><label for="idParent">'. get_lang("Parent"). ' :</label></td>' . "\n";
$return .= "\t\t\t" . '<td class="input">' . "\n";
$return .= "\t\t\t\t" . '<select id="idParent" name="parent" onchange="load_cbo(this.value);" size="1">';
$return .= "\t\t\t\t\t" . '<option class="top" value="0">' . $this->name . '</option>';
for($i = 0; $i < count($arrLP); $i++ )
if(($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir') && !in_array($arrLP[$i]['id'], $arrHide) && !in_array($arrLP[$i]['parent_item_id'], $arrHide))
$return .= "\t\t\t\t\t" . '<option ' . (($parent == $arrLP[$i]['id']) ? 'selected="selected" ' : '') . 'style="padding-left:' . ($arrLP[$i]['depth'] * 10) . 'px;" value="' . $arrLP[$i]['id'] . '">' . mb_convert_encoding($arrLP[$i]['title'],$charset,$this->encoding) . '</option>';
$arrHide[] = $arrLP[$i]['id'];
if($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir')
$return .= "\t\t\t\t\t" . '<option ' . (($parent == $arrLP[$i]['id']) ? 'selected="selected" ' : '') . 'style="padding-left:' . ($arrLP[$i]['depth'] * 10) . 'px;" value="' . $arrLP[$i]['id'] . '">' . mb_convert_encoding($arrLP[$i]['title'],$charset,$this->encoding) . '</option>';
$return .= "\t\t\t\t" . '</select>';
$return .= "\t\t\t" . '</td>' . "\n";
$return .= "\t\t" . '</tr>' . "\n";
$return .= "\t\t" . '<tr>' . "\n";
$return .= "\t\t\t" . '<td class="label"><label for="idPosition">'. get_lang("Position"). ' :</label></td>' . "\n";
$return .= "\t\t\t" . '<td class="input">' . "\n";
$return .= "\t\t\t\t" . '<select id="idPosition" name="previous" size="1">';
$return .= "\t\t\t\t\t" . '<option class="top" value="0">'. get_lang("FirstPosition"). '</option>';
for($i = 0; $i < count($arrLP); $i++ )
if($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id)
if($extra_info['previous_item_id'] == $arrLP[$i]['id'])
$selected = 'selected="selected" ';
$selected = 'selected="selected" ';
$return .= "\t\t\t\t\t" . '<option ' . $selected . 'value="' . $arrLP[$i]['id'] . '">'. get_lang("After"). ' "' . mb_convert_encoding($arrLP[$i]['title'],$charset,$this->encoding) . '"</option>';
$return .= "\t\t\t\t" . '</select>';
$return .= "\t\t\t" . '</td>' . "\n";
$return .= "\t\t" . '</tr>' . "\n";
$return .= "\t\t" . '<tr>' . "\n";
$return .= "\t\t\t" . '<td class="label"><label for="idTitle">'. get_lang("Title"). ' :</label></td>' . "\n";
$return .= "\t\t\t" . '<td class="input"><input id="idTitle" name="title" type="text" value="' . $item_title . '" /></td>' . "\n";
$return .= "\t\t" . '</tr>' . "\n";
$return .= "\t\t" . '<tr>' . "\n";
$return .= "\t\t\t" . '<td class="label"><label for="idDescription">'. get_lang("Description"). ' :</label></td>' . "\n";
$return .= "\t\t\t" . '<td class="input"><textarea id="idDescription" name="description" rows="4">' . $item_description . '</textarea></td>' . "\n";
$return .= "\t\t" . '</tr>' . "\n";
$return .= "\t\t" . '<tr>' . "\n";
$return .= "\t\t\t" . '<td class="label"><label for="idURL">'. get_lang("Url"). ' :</label></td>' . "\n";
$return .= "\t\t\t" . '<td class="input"><input' . (is_numeric($extra_info) ? ' disabled="disabled"' : '') . ' id="idURL" name="url" type="text" value="' . $item_url . '" /></td>' . "\n";
$return .= "\t\t" . '</tr>' . "\n";
foreach($arrLP as $key=> $value){
$id_prerequisite= $value['prerequisite'];
for($i = 0; $i < count($arrLP); $i++ )
if($arrLP[$i]['id'] != $id && $arrLP[$i]['item_type'] != 'dokeos_chapter')
if($extra_info['previous_item_id'] == $arrLP[$i]['id'])
$s_selected_position= $arrLP[$i]['id'];
$return .= "\t\t" . '<tr>' . "\n";
$return .= "\t\t\t" . '<td class="label"><label for="idPrerequisites">'. get_lang("Prerequisites"). ' :</label></td>' . "\n";
$return .= "\t\t\t" . '<td class="input"><select name="prerequisites" id="prerequisites" style="background:#F8F8F8; border:1px solid #999999; font-family:Arial, Verdana, Helvetica, sans-serif; font-size:12px; width:300px;"><option value="0">'. get_lang("NoPrerequisites"). '</option>';
foreach($arrHide as $key => $value)
if($key== $s_selected_position && $action == 'add')
$return .= '<option value="'. $key. '" selected="selected">'. $value['value']. '</option>';
elseif($key== $id_prerequisite && $action == 'edit'){
$return .= '<option value="'. $key. '" selected="selected">'. $value['value']. '</option>';
$return .= '<option value="'. $key. '">'. $value['value']. '</option>';
$return .= "</select></td>";
$return .= "\t\t" . '</tr>' . "\n";
$return .= "\t\t" . '<tr>' . "\n";
$return .= "\t\t\t" . '<td colspan="2"><input class="button" name="submit_button" type="submit" value="'. get_lang("Ok"). '" /></td>' . "\n";
$return .= "\t\t" . '</tr>' . "\n";
$return .= "\t" . '</table>' . "\n";
$return .= "\t" . '<input name="title" type="hidden" value="' . $item_title . '" />' . "\n";
$return .= "\t" . '<input name="description" type="hidden" value="' . $item_description . '" />' . "\n";
$return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info . '" />' . "\n";
$return .= "\t" . '<input name="path" type="hidden" value="' . $extra_info['path'] . '" />' . "\n";
$return .= "\t" . '<input name="type" type="hidden" value="'. TOOL_LINK. '" />' . "\n";
$return .= "\t" . '<input name="post_time" type="hidden" value="' . time() . '" />' . "\n";
$return .= '</form>' . "\n";
$return .= '</div>' . "\n";
* Enter description here...
* @param unknown_type $action
* @param unknown_type $id
* @param unknown_type $extra_info
$item_description = stripslashes($extra_info['description']);
FROM " . $tbl_publication . "
WHERE id = " . $extra_info;
|