@ -78,7 +78,7 @@ class learnpathItem {
if (!isset($user_id)) { $user_id = api_get_user_id(); }
if (!isset($user_id)) { $user_id = api_get_user_id(); }
if (self::debug > 0) { error_log("learnpathItem constructor: id: $id user_id: $user_id course_id: $course_id item_content: $item_content", 0); }
if (self::debug > 0) { error_log("learnpathItem constructor: id: $id user_id: $user_id course_id: $course_id item_content: $item_content", 0); }
$id = intval($id);
$id = intval($id);
if (empty($item_content)) {
if (empty($item_content)) {
$items_table = Database::get_course_table(TABLE_LP_ITEM);
$items_table = Database::get_course_table(TABLE_LP_ITEM);
if (empty($course_id)) {
if (empty($course_id)) {
@ -90,14 +90,14 @@ class learnpathItem {
//error_log('New LP - Creating item object from DB: '.$sql, 0);
//error_log('New LP - Creating item object from DB: '.$sql, 0);
$res = Database::query($sql);
$res = Database::query($sql);
if (Database::num_rows($res) < 1 ) {
if (Database::num_rows($res) < 1 ) {
$this->error = 'Could not find given learnpath item in learnpath_item table';
$this->error = 'Could not find given learnpath item in learnpath_item table';
return false;
return false;
}
}
$row = Database::fetch_array($res);
$row = Database::fetch_array($res);
} else {
} else {
$row = $item_content;
$row = $item_content;
}
}
$this->lp_id = $row['lp_id'];
$this->lp_id = $row['lp_id'];
$this->max_score = $row['max_score'];
$this->max_score = $row['max_score'];
$this->min_score = $row['min_score'];
$this->min_score = $row['min_score'];
@ -123,7 +123,7 @@ class learnpathItem {
$this->seriousgame_mode = 0;
$this->seriousgame_mode = 0;
// Get search_did.
// Get search_did.
if (api_get_setting('search_enabled') == 'true') {
if (api_get_setting('search_enabled') == 'true') {
$tbl_se_ref = Database::get_main_table(TABLE_MAIN_SEARCH_ENGINE_REF);
$tbl_se_ref = Database::get_main_table(TABLE_MAIN_SEARCH_ENGINE_REF);
$sql = 'SELECT * FROM %s WHERE course_code=\'%s\' AND tool_id=\'%s\' AND ref_id_high_level=%s AND ref_id_second_level=%d LIMIT 1';
$sql = 'SELECT * FROM %s WHERE course_code=\'%s\' AND tool_id=\'%s\' AND ref_id_high_level=%s AND ref_id_second_level=%d LIMIT 1';
// TODO: Verify if it's possible to assume the actual course instead of getting it from db.
// TODO: Verify if it's possible to assume the actual course instead of getting it from db.
@ -231,11 +231,11 @@ class learnpathItem {
$sql_sel = "SELECT * FROM $lp_item WHERE c_id = $course_id AND id = ".$this->db_id;
$sql_sel = "SELECT * FROM $lp_item WHERE c_id = $course_id AND id = ".$this->db_id;
$res_sel = Database::query($sql_sel);
$res_sel = Database::query($sql_sel);
if (Database::num_rows($res_sel) < 1 ) {
if (Database::num_rows($res_sel) < 1 ) {
return false;
return false;
}
}
$sql_del_item = "DELETE FROM $lp_item WHERE c_id = $course_id AND id = ".$this->db_id;
$sql_del_item = "DELETE FROM $lp_item WHERE c_id = $course_id AND id = ".$this->db_id;
Database::query($sql_del_item);
Database::query($sql_del_item);
if (self::debug > 0) { error_log('Deleting from lp_item: '.$sql_del_view); }
if (self::debug > 0) { error_log('Deleting from lp_item: '.$sql_del_view); }
@ -668,7 +668,7 @@ class learnpathItem {
* @author ndiechburg < noel @ cblue . be >
* @author ndiechburg < noel @ cblue . be >
**/
**/
public function get_seriousgame_mode() {
public function get_seriousgame_mode() {
if(self::debug>2){error_log('learnpathItem::get_seriousgame_mode()',0);}
if(self::debug>2){error_log('learnpathItem::get_seriousgame_mode()',0);}
$course_id = api_get_course_int_id();
$course_id = api_get_course_int_id();
if (!isset($this->seriousgame_mode)) {
if (!isset($this->seriousgame_mode)) {
if (!empty($this->lp_id)) {
if (!empty($this->lp_id)) {
@ -731,7 +731,7 @@ class learnpathItem {
//error_log(str_repeat(' ',$recursivity).'Analyse file '.$abs_path, 0);
//error_log(str_repeat(' ',$recursivity).'Analyse file '.$abs_path, 0);
$files_list = array();
$files_list = array();
$type = $this->get_type();
$type = $this->get_type();
switch ($type) {
switch ($type) {
case TOOL_DOCUMENT :
case TOOL_DOCUMENT :
case TOOL_QUIZ:
case TOOL_QUIZ:
@ -741,9 +741,9 @@ class learnpathItem {
if (is_file($abs_path)) {
if (is_file($abs_path)) {
// for now, read the whole file in one go (that's gonna be a problem when the file is too big).
// for now, read the whole file in one go (that's gonna be a problem when the file is too big).
$info = pathinfo($abs_path);
$info = pathinfo($abs_path);
$ext = $info['extension'];
$ext = $info['extension'];
switch (strtolower($ext)) {
switch (strtolower($ext)) {
case 'html':
case 'html':
case 'htm':
case 'htm':
@ -754,13 +754,13 @@ class learnpathItem {
$file_content = file_get_contents($abs_path);
$file_content = file_get_contents($abs_path);
// Get an array of attributes from the HTML source.
// Get an array of attributes from the HTML source.
$attributes = DocumentManager::parse_HTML_attributes($file_content, $wanted_attributes);
$attributes = DocumentManager::parse_HTML_attributes($file_content, $wanted_attributes);
// Look at 'src' attributes in this file
// Look at 'src' attributes in this file
foreach ($wanted_attributes as $attr) {
foreach ($wanted_attributes as $attr) {
if (isset($attributes[$attr])) {
if (isset($attributes[$attr])) {
// Find which kind of path these are (local or remote).
// Find which kind of path these are (local or remote).
$sources = $attributes[$attr];
$sources = $attributes[$attr];
foreach ($sources as $source) {
foreach ($sources as $source) {
// Skip what is obviously not a resource.
// Skip what is obviously not a resource.
if (strpos($source, "+this.")) continue; // javascript code - will still work unaltered.
if (strpos($source, "+this.")) continue; // javascript code - will still work unaltered.
@ -769,7 +769,7 @@ class learnpathItem {
if (strpos($source, ';') & & !strpos($source, '& ')) continue; // Avoid code - that should help.
if (strpos($source, ';') & & !strpos($source, '& ')) continue; // Avoid code - that should help.
if ($attr == 'value') {
if ($attr == 'value') {
if (strpos($source , 'mp3file')) {
if (strpos($source , 'mp3file')) {
$files_list[] = array(substr($source, 0, strpos($source , '.swf') + 4), 'local', 'abs');
$files_list[] = array(substr($source, 0, strpos($source , '.swf') + 4), 'local', 'abs');
$mp3file = substr($source , strpos($source , 'mp3file=') + 8);
$mp3file = substr($source , strpos($source , 'mp3file=') + 8);
if (substr($mp3file, 0, 1) == '/')
if (substr($mp3file, 0, 1) == '/')
@ -777,7 +777,7 @@ class learnpathItem {
else
else
$files_list[] = array($mp3file, 'local', 'rel');
$files_list[] = array($mp3file, 'local', 'rel');
} elseif (strpos($source, 'flv=') === 0) {
} elseif (strpos($source, 'flv=') === 0) {
$source = substr($source, 4);
$source = substr($source, 4);
if (strpos($source, '& ') > 0) {
if (strpos($source, '& ') > 0) {
$source = substr($source, 0, strpos($source, '&'));
$source = substr($source, 0, strpos($source, '&'));
@ -796,7 +796,7 @@ class learnpathItem {
continue; // Skipping anything else to avoid two entries (while the others can have sub-files in their url, flv's can't).
continue; // Skipping anything else to avoid two entries (while the others can have sub-files in their url, flv's can't).
}
}
}
}
if (strpos($source, '://') > 0) {
if (strpos($source, '://') > 0) {
// Cut at '?' in a URL with params.
// Cut at '?' in a URL with params.
@ -898,7 +898,7 @@ class learnpathItem {
}
}
}
}
}
}
// Found some protocol there.
// Found some protocol there.
if (strpos($source, api_get_path(WEB_PATH)) !== false) {
if (strpos($source, api_get_path(WEB_PATH)) !== false) {
// We found the current portal url.
// We found the current portal url.
@ -913,7 +913,7 @@ class learnpathItem {
}
}
} else {
} else {
// No protocol found, make link local.
// No protocol found, make link local.
if (substr($source, 0, 1) === '/') {
if (substr($source, 0, 1) === '/') {
// Link starts with a /, making it absolute (relative to DocumentRoot).
// Link starts with a /, making it absolute (relative to DocumentRoot).
$files_list[] = array($source, 'local', 'abs');
$files_list[] = array($source, 'local', 'abs');
$in_files_list[] = learnpathItem::get_resources_from_source(TOOL_DOCUMENT, $source, $recursivity + 1);
$in_files_list[] = learnpathItem::get_resources_from_source(TOOL_DOCUMENT, $source, $recursivity + 1);
@ -930,15 +930,15 @@ class learnpathItem {
$files_list = array_merge($files_list, $in_files_list);
$files_list = array_merge($files_list, $in_files_list);
}
}
} else {
} else {
// No starting '/', making it relative to current document's path.
// No starting '/', making it relative to current document's path.
if (strpos($source, 'width=') || strpos($source, 'autostart=')) {
if (strpos($source, 'width=') || strpos($source, 'autostart=')) {
continue;
continue;
}
}
if (substr($source, 0, 2) == './') {
if (substr($source, 0, 2) == './') {
$source = substr($source, 2);
$source = substr($source, 2);
}
}
$files_list[] = array($source, 'local', 'rel');
$files_list[] = array($source, 'local', 'rel');
$dir = dirname($abs_path);
$dir = dirname($abs_path);
$new_abs_path = realpath($dir.'/'.$source);
$new_abs_path = realpath($dir.'/'.$source);
@ -975,7 +975,7 @@ class learnpathItem {
$checked_array_list[] = $files_list[$idx];
$checked_array_list[] = $files_list[$idx];
}
}
}
}
}
}
return $checked_array_list;
return $checked_array_list;
}
}
@ -1006,7 +1006,7 @@ class learnpathItem {
if (self::debug > 2) { error_log('learnpathItem::get_status(): checking db', 0); }
if (self::debug > 2) { error_log('learnpathItem::get_status(): checking db', 0); }
if (!empty($this->db_item_view_id)) {
if (!empty($this->db_item_view_id)) {
$table = Database::get_course_table(TABLE_LP_ITEM_VIEW);
$table = Database::get_course_table(TABLE_LP_ITEM_VIEW);
$sql = "SELECT status FROM $table WHERE c_id = $course_id AND id = '".$this->db_item_view_id."' AND view_count = '".$this->get_attempt_id()."'";
$sql = "SELECT status FROM $table WHERE c_id = $course_id AND id = '".$this->db_item_view_id."' AND view_count = '".$this->get_attempt_id()."'";
if (self::debug > 2) { error_log('learnpathItem::get_status() - Checking DB: '.$sql, 0); }
if (self::debug > 2) { error_log('learnpathItem::get_status() - Checking DB: '.$sql, 0); }
$res = Database::query($sql);
$res = Database::query($sql);
@ -1015,7 +1015,7 @@ class learnpathItem {
if ($update_local) {
if ($update_local) {
$this->set_status($row['status']);
$this->set_status($row['status']);
}
}
if (self::debug > 2) { error_log('learnpathItem::get_status() - Returning db value '.$row['status'], 0); }
if (self::debug > 2) { error_log('learnpathItem::get_status() - Returning db value '.$row['status'], 0); }
return $row['status'];
return $row['status'];
}
}
}
}
@ -1063,7 +1063,7 @@ class learnpathItem {
} else {
} else {
$start = $this->current_start_time;
$start = $this->current_start_time;
$stop = $this->current_stop_time;
$stop = $this->current_stop_time;
}
}
if (!empty($start)) {
if (!empty($start)) {
if (!empty($stop)) {
if (!empty($stop)) {
$time = $stop - $start;
$time = $stop - $start;
@ -1142,8 +1142,8 @@ class learnpathItem {
* @return string The item type (can be doc, dir, sco, asset)
* @return string The item type (can be doc, dir, sco, asset)
*/
*/
public function get_type() {
public function get_type() {
$res = 'asset';
$res = 'asset';
if (!empty($this->type)) {
if (!empty($this->type)) {
$res = $this->type;
$res = $this->type;
}
}
if (self::debug > 2) { error_log('learnpathItem::get_type() - Returning '.$res.' for item '.$this->db_id, 0); }
if (self::debug > 2) { error_log('learnpathItem::get_type() - Returning '.$res.' for item '.$this->db_id, 0); }
@ -1535,7 +1535,7 @@ class learnpathItem {
} else {
} else {
if (self::debug > 1) { error_log('New LP - Prerequisite '.$prereqs_string.' complete', 0); }
if (self::debug > 1) { error_log('New LP - Prerequisite '.$prereqs_string.' complete', 0); }
}
}
//$returnstatus = true;
//$returnstatus = true;
if ($returnstatus & & $this->prevent_reinit == 1) {
if ($returnstatus & & $this->prevent_reinit == 1) {
// I would prefer check in the database.
// I would prefer check in the database.
@ -1703,7 +1703,7 @@ class learnpathItem {
* @return boolean True on success, false on failure
* @return boolean True on success, false on failure
*/
*/
public function save($from_outside = true, $prereqs_complete = false) {
public function save($from_outside = true, $prereqs_complete = false) {
if (self::debug > 0) { error_log('learnpathItem::save()', 0); }
if (self::debug > 0) { error_log('learnpathItem::save()', 0); }
// First check if parameters passed via GET can be saved here
// First check if parameters passed via GET can be saved here
// in case it's a SCORM, we should get:
// in case it's a SCORM, we should get:
if ($this->type == 'sco' || $this->type== 'au') {
if ($this->type == 'sco' || $this->type== 'au') {
@ -1890,10 +1890,10 @@ class learnpathItem {
$item_view_table = Database::get_course_table(TABLE_LP_ITEM_VIEW);
$item_view_table = Database::get_course_table(TABLE_LP_ITEM_VIEW);
// Get the lp_item_view with the highest view_count.
// Get the lp_item_view with the highest view_count.
$sql = "SELECT * FROM $item_view_table
$sql = "SELECT * FROM $item_view_table
WHERE c_id = $course_id AND
WHERE c_id = $course_id AND
lp_item_id = ".$this->get_id()." AND
lp_item_id = ".$this->get_id()." AND
lp_view_id = ".$lp_view_id."
lp_view_id = ".$lp_view_id."
ORDER BY view_count DESC";
ORDER BY view_count DESC";
if (self::debug > 2) { error_log('learnpathItem::set_lp_view() - Querying lp_item_view: '.$sql, 0); }
if (self::debug > 2) { error_log('learnpathItem::set_lp_view() - Querying lp_item_view: '.$sql, 0); }
@ -1904,9 +1904,9 @@ class learnpathItem {
$this->attempt_id = $row['view_count'];
$this->attempt_id = $row['view_count'];
$this->current_score = $row['score'];
$this->current_score = $row['score'];
$this->current_data = $row['suspend_data'];
$this->current_data = $row['suspend_data'];
$this->view_max_score = $row['max_score'];
$this->view_max_score = $row['max_score'];
$this->status = $row['status'];
$this->status = $row['status'];
$this->current_start_time = $row['start_time'];
$this->current_start_time = $row['start_time'];
$this->current_stop_time = $this->current_start_time + $row['total_time'];
$this->current_stop_time = $this->current_start_time + $row['total_time'];
$this->lesson_location = $row['lesson_location'];
$this->lesson_location = $row['lesson_location'];
$this->core_exit = $row['core_exit'];
$this->core_exit = $row['core_exit'];
@ -1968,7 +1968,7 @@ class learnpathItem {
* it, then set the status to 'passed'.
* it, then set the status to 'passed'.
* @param float Score
* @param float Score
* @return boolean True on success, false otherwise
* @return boolean True on success, false otherwise
*/
*/
public function set_score($score) {
public function set_score($score) {
//$possible_status = array('not attempted','incomplete','completed','passed','failed','browsed');
//$possible_status = array('not attempted','incomplete','completed','passed','failed','browsed');
$debug = self::debug;
$debug = self::debug;
@ -1977,18 +1977,18 @@ class learnpathItem {
$this->current_score = $score;
$this->current_score = $score;
$master = $this->get_mastery_score();
$master = $this->get_mastery_score();
$current_status = $this->get_status(false);
$current_status = $this->get_status(false);
//Fixes bug when SCORM doesn't send a mastery score even if they sent a score!
//Fixes bug when SCORM doesn't send a mastery score even if they sent a score!
if ($master == -1) {
if ($master == -1) {
$master = $this->max_score;
$master = $this->max_score;
}
}
if ($debug > 0) {
if ($debug > 0) {
error_log('get_mastery_score: '.$master);
error_log('get_mastery_score: '.$master);
error_log('current_status: '.$current_status);
error_log('current_status: '.$current_status);
error_log('current score : '.$this->current_score);
error_log('current score : '.$this->current_score);
}
}
// If mastery_score is set AND the current score reaches the mastery score AND the current status is different from 'completed', then set it to 'passed'.
// If mastery_score is set AND the current score reaches the mastery score AND the current status is different from 'completed', then set it to 'passed'.
/*
/*
if ($master != -1 & & $this->current_score >= $master & & $current_status != $this->possible_status[2]) {
if ($master != -1 & & $this->current_score >= $master & & $current_status != $this->possible_status[2]) {
@ -1997,7 +1997,7 @@ class learnpathItem {
} elseif ($master != -1 & & $this->current_score < $master) {
} elseif ($master != -1 & & $this->current_score < $master) {
if ($debug > 0) error_log('Status changed to: '.$this->possible_status[4]);
if ($debug > 0) error_log('Status changed to: '.$this->possible_status[4]);
$this->set_status($this->possible_status[4]); //failed
$this->set_status($this->possible_status[4]); //failed
}*/
}*/
return true;
return true;
}
}
return false;
return false;
@ -2085,7 +2085,7 @@ class learnpathItem {
* @param string Time as given by SCORM
* @param string Time as given by SCORM
* @return void
* @return void
*/
*/
public function set_time($scorm_time, $format = 'scorm') {
public function set_time($scorm_time, $format = 'scorm') {
if (self::debug > 0) { error_log('learnpathItem::set_time('.$scorm_time.')', 0); }
if (self::debug > 0) { error_log('learnpathItem::set_time('.$scorm_time.')', 0); }
if ($scorm_time == 0 and ($this->type != 'sco') and $this->current_start_time != 0) {
if ($scorm_time == 0 and ($this->type != 'sco') and $this->current_start_time != 0) {
$my_time = time() - $this->current_start_time;
$my_time = time() - $this->current_start_time;
@ -2095,7 +2095,7 @@ class learnpathItem {
}
}
} else {
} else {
switch ($format) {
switch ($format) {
case 'scorm':
case 'scorm':
$res = array();
$res = array();
if (preg_match('/^(\d{1,4}):(\d{2}):(\d{2})(\.\d{1,4})?/', $scorm_time, $res)) {
if (preg_match('/^(\d{1,4}):(\d{2}):(\d{2})(\.\d{1,4})?/', $scorm_time, $res)) {
$time = time();
$time = time();
@ -2203,16 +2203,16 @@ class learnpathItem {
public function scorm_update_time($total_sec = 0) {
public function scorm_update_time($total_sec = 0) {
if (self::debug > 0) error_log('Funcion called: scorm_update_time');
if (self::debug > 0) error_log('Funcion called: scorm_update_time');
if (self::debug > 0) error_log("total_sec: $total_sec");
if (self::debug > 0) error_log("total_sec: $total_sec");
//Step 1 : get actual total time stored in db
//Step 1 : get actual total time stored in db
$item_view_table = Database::get_course_table(TABLE_LP_ITEM_VIEW);
$item_view_table = Database::get_course_table(TABLE_LP_ITEM_VIEW);
$course_id = api_get_course_int_id();
$course_id = api_get_course_int_id();
$get_view_sql = 'SELECT total_time, status FROM '.$item_view_table.'
$get_view_sql = 'SELECT total_time, status FROM '.$item_view_table.'
WHERE c_id = '.$course_id.' AND lp_item_id="'.$this->db_id.'" AND lp_view_id="'.$this->view_id.'" AND view_count="'.$this->attempt_id.'" ;';
WHERE c_id = '.$course_id.' AND lp_item_id="'.$this->db_id.'" AND lp_view_id="'.$this->view_id.'" AND view_count="'.$this->attempt_id.'" ;';
$result=Database::query($get_view_sql);
$result=Database::query($get_view_sql);
$row=Database::fetch_array($result);
$row=Database::fetch_array($result);
if (!isset($row['total_time'])) {
if (!isset($row['total_time'])) {
$total_time = 0;
$total_time = 0;
} else {
} else {
@ -2238,7 +2238,7 @@ class learnpathItem {
$result=Database::query($update_view_sql);
$result=Database::query($update_view_sql);
}
}
}
}
/**
/**
* Set the total_time to 0 into db
* Set the total_time to 0 into db
**/
**/
@ -2246,10 +2246,10 @@ class learnpathItem {
$item_view_table = Database::get_course_table(TABLE_LP_ITEM_VIEW);
$item_view_table = Database::get_course_table(TABLE_LP_ITEM_VIEW);
$course_id = api_get_course_int_id();
$course_id = api_get_course_int_id();
$update_view_sql='UPDATE '.$item_view_table.' SET total_time = 0, start_time='.time().'
$update_view_sql='UPDATE '.$item_view_table.' SET total_time = 0, start_time='.time().'
WHERE c_id = '.$course_id.' AND lp_item_id="'.$this->db_id.'" AND lp_view_id="'.$this->view_id.'" AND view_count="'.$this->attempt_id.'" ;';
WHERE c_id = '.$course_id.' AND lp_item_id="'.$this->db_id.'" AND lp_view_id="'.$this->view_id.'" AND view_count="'.$this->attempt_id.'" ;';
Database::query($update_view_sql);
Database::query($update_view_sql);
}
}
/**
/**
* Write objectives to DB. This method is separate from write_to_db() because otherwise
* Write objectives to DB. This method is separate from write_to_db() because otherwise
* objectives are lost as a side effect to AJAX and session concurrent access
* objectives are lost as a side effect to AJAX and session concurrent access
@ -2315,10 +2315,10 @@ class learnpathItem {
*/
*/
public function write_to_db() {
public function write_to_db() {
if (self::debug > 0) { error_log('learnpathItem::write_to_db()', 0); }
if (self::debug > 0) { error_log('learnpathItem::write_to_db()', 0); }
// Check the session visibility.
// Check the session visibility.
if (!api_is_allowed_to_session_edit()) {
if (!api_is_allowed_to_session_edit()) {
if (self::debug > 0) { error_log('return false api_is_allowed_to_session_edit'); }
if (self::debug > 0) { error_log('return false api_is_allowed_to_session_edit'); }
return false;
return false;
}
}
$course_id = api_get_course_int_id();
$course_id = api_get_course_int_id();
@ -2330,22 +2330,22 @@ class learnpathItem {
WHERE c_id = '.$course_id.' AND lp_item_id="'.$this->db_id.'" AND lp_view_id="'.$this->view_id.'" AND view_count="'.$this->get_attempt_id().'" ;';
WHERE c_id = '.$course_id.' AND lp_item_id="'.$this->db_id.'" AND lp_view_id="'.$this->view_id.'" AND view_count="'.$this->get_attempt_id().'" ;';
$rs_verified = Database::query($sql_verified);
$rs_verified = Database::query($sql_verified);
$row_verified = Database::fetch_array($rs_verified);
$row_verified = Database::fetch_array($rs_verified);
$my_case_completed = array('completed', 'passed', 'browsed', 'failed'); // Added by Isaac Flores.
$my_case_completed = array('completed', 'passed', 'browsed', 'failed'); // Added by Isaac Flores.
$save = true;
$save = true;
if (isset($row_verified) & & isset($row_verified['status'])) {
if (isset($row_verified) & & isset($row_verified['status'])) {
if (in_array($row_verified['status'], $my_case_completed)) {
if (in_array($row_verified['status'], $my_case_completed)) {
$save = false;
$save = false;
}
}
}
}
if ((($save === false & & $this->type == 'sco') ||
if ((($save === false & & $this->type == 'sco') ||
($this->type == 'sco' & & ($credit == 'no-credit' OR $mode == 'review' OR $mode == 'browse'))
($this->type == 'sco' & & ($credit == 'no-credit' OR $mode == 'review' OR $mode == 'browse'))
) & & ($this->seriousgame_mode != 1 & & $this->type == 'sco')
) & & ($this->seriousgame_mode != 1 & & $this->type == 'sco')
){
){
if (self::debug>1) {
if (self::debug>1) {
error_log("This info shouldn't be saved as the credit or lesson mode info prevent it");
error_log("This info shouldn't be saved as the credit or lesson mode info prevent it");
error_log('learnpathItem::write_to_db() - credit('.$credit.') or lesson_mode('.$mode.') prevent recording!',0);
error_log('learnpathItem::write_to_db() - credit('.$credit.') or lesson_mode('.$mode.') prevent recording!',0);
}
}
@ -2398,7 +2398,7 @@ class learnpathItem {
// Depending on what we want (really), we'll update or insert a new row
// Depending on what we want (really), we'll update or insert a new row
// now save into DB.
// now save into DB.
$res = 0;
$res = 0;
if (!$inserted & & Database::num_rows($check_res) < 1 ) {
if (!$inserted & & Database::num_rows($check_res) < 1 ) {
$sql = "INSERT INTO $item_view_table " .
$sql = "INSERT INTO $item_view_table " .
"(c_id, total_time, " .
"(c_id, total_time, " .
"start_time, " .
"start_time, " .
@ -2523,7 +2523,7 @@ class learnpathItem {
$total_time = " total_time = total_time +".$this->get_total_time().", ";
$total_time = " total_time = total_time +".$this->get_total_time().", ";
}
}
}
}
}
}
}
}
if ($this->type == 'sco') { //IF scorm scorm_update_time has already updated total_tim in db
if ($this->type == 'sco') { //IF scorm scorm_update_time has already updated total_tim in db
@ -2538,7 +2538,7 @@ class learnpathItem {
"WHERE c_id = $course_id AND lp_item_id = ".$this->db_id." " .
"WHERE c_id = $course_id AND lp_item_id = ".$this->db_id." " .
"AND lp_view_id = ".$this->view_id." " .
"AND lp_view_id = ".$this->view_id." " .
"AND view_count = ".$this->get_attempt_id();
"AND view_count = ".$this->get_attempt_id();
} else {
} else {
$sql = "UPDATE $item_view_table " .
$sql = "UPDATE $item_view_table " .
"SET " .$total_time.
"SET " .$total_time.
" start_time = ".$this->get_current_start_time().", " .
" start_time = ".$this->get_current_start_time().", " .
@ -2557,7 +2557,7 @@ class learnpathItem {
if (self::debug > 2) { error_log('learnpathItem::write_to_db() - Updating item_view: '.$sql, 0); }
if (self::debug > 2) { error_log('learnpathItem::write_to_db() - Updating item_view: '.$sql, 0); }
$res = Database::query($sql);
$res = Database::query($sql);
}
}
if (is_array($this->interactions) & & count($this->interactions) > 0) {
if (is_array($this->interactions) & & count($this->interactions) > 0) {
// Save interactions.
// Save interactions.
$tbl = Database::get_course_table(TABLE_LP_ITEM_VIEW);
$tbl = Database::get_course_table(TABLE_LP_ITEM_VIEW);
@ -2621,63 +2621,63 @@ class learnpathItem {
if (self::debug > 2) { error_log('End of learnpathItem::write_to_db()', 0); }
if (self::debug > 2) { error_log('End of learnpathItem::write_to_db()', 0); }
return true;
return true;
}
}
function add_audio() {
function add_audio() {
$course_info = api_get_course_info();
$course_info = api_get_course_info();
$filepath = api_get_path(SYS_COURSE_PATH).$course_info['path'].'/document/';
$filepath = api_get_path(SYS_COURSE_PATH).$course_info['path'].'/document/';
if (!is_dir($filepath.'audio')) {
if (!is_dir($filepath.'audio')) {
mkdir($filepath.'audio', api_get_permissions_for_new_directories());
mkdir($filepath.'audio', api_get_permissions_for_new_directories());
$audio_id = add_document($course_info, '/audio', 'folder', 0, 'audio');
$audio_id = add_document($course_info, '/audio', 'folder', 0, 'audio');
api_item_property_update($course_info, TOOL_DOCUMENT, $audio_id, 'FolderCreated', api_get_user_id(), null, null, null, null, api_get_session_id());
api_item_property_update($course_info, TOOL_DOCUMENT, $audio_id, 'FolderCreated', api_get_user_id(), null, null, null, null, api_get_session_id());
api_item_property_update($course_info, TOOL_DOCUMENT, $audio_id, 'invisible', api_get_user_id(), null, null, null, null, api_get_session_id());
api_item_property_update($course_info, TOOL_DOCUMENT, $audio_id, 'invisible', api_get_user_id(), null, null, null, null, api_get_session_id());
}
}
$key = 'file';
$key = 'file';
if (!isset($_FILES[$key]['name']) || !isset($_FILES[$key]['tmp_name'])) {
if (!isset($_FILES[$key]['name']) || !isset($_FILES[$key]['tmp_name'])) {
return false;
return false;
}
}
$result = DocumentManager::upload_document($_FILES, '/audio', null, null, 0, 'rename', false, false);
$result = DocumentManager::upload_document($_FILES, '/audio', null, null, 0, 'rename', false, false);
$file_path = null;
$file_path = null;
if ($result) {
if ($result) {
$file_path = basename($result['path']);
$file_path = basename($result['path']);
// Store the mp3 file in the lp_item table.
// Store the mp3 file in the lp_item table.
$tbl_lp_item = Database::get_course_table(TABLE_LP_ITEM);
$tbl_lp_item = Database::get_course_table(TABLE_LP_ITEM);
$sql_insert_audio = "UPDATE $tbl_lp_item SET audio = '".Database::escape_string($file_path)."'
$sql_insert_audio = "UPDATE $tbl_lp_item SET audio = '".Database::escape_string($file_path)."'
WHERE c_id = {$course_info['real_id']} AND id = '".Database::escape_string($this->db_id)."'";
WHERE c_id = {$course_info['real_id']} AND id = '".Database::escape_string($this->db_id)."'";
Database::query($sql_insert_audio);
Database::query($sql_insert_audio);
}
}
return $file_path;
return $file_path;
}
}
function add_audio_from_documents($doc_id) {
function add_audio_from_documents($doc_id) {
$course_info = api_get_course_info();
$course_info = api_get_course_info();
$document_data = DocumentManager::get_document_data_by_id($doc_id, $course_info['code']);
$document_data = DocumentManager::get_document_data_by_id($doc_id, $course_info['code']);
if (!empty($document_data)) {
if (!empty($document_data)) {
$file_path = basename($document_data['path']);
$file_path = basename($document_data['path']);
// Store the mp3 file in the lp_item table.
// Store the mp3 file in the lp_item table.
$tbl_lp_item = Database::get_course_table(TABLE_LP_ITEM);
$tbl_lp_item = Database::get_course_table(TABLE_LP_ITEM);
$sql_insert_audio = "UPDATE $tbl_lp_item SET audio = '".Database::escape_string($file_path)."'
$sql_insert_audio = "UPDATE $tbl_lp_item SET audio = '".Database::escape_string($file_path)."'
WHERE c_id = {$course_info['real_id']} AND id = '".Database::escape_string($this->db_id)."'";
WHERE c_id = {$course_info['real_id']} AND id = '".Database::escape_string($this->db_id)."'";
Database::query($sql_insert_audio);
Database::query($sql_insert_audio);
}
}
return $file_path;
return $file_path;
}
}
function remove_audio() {
function remove_audio() {
$tbl_lp_item = Database::get_course_table(TABLE_LP_ITEM);
$tbl_lp_item = Database::get_course_table(TABLE_LP_ITEM);
$course_id = api_get_course_int_id();
$course_id = api_get_course_int_id();
if (empty($this->db_id)) {
if (empty($this->db_id)) {
return false;
return false;
}
}
$sql = "UPDATE $tbl_lp_item SET audio = '' WHERE c_id = $course_id AND id IN (".$this->db_id.")";
$sql = "UPDATE $tbl_lp_item SET audio = '' WHERE c_id = $course_id AND id IN (".$this->db_id.")";
Database::query($sql);
Database::query($sql);
}
}
static function humanize_status($status, $decorate = true) {
static function humanize_status($status, $decorate = true) {
$mylanglist = array(
$mylanglist = array(
'completed' => 'ScormCompstatus',
'completed' => 'ScormCompstatus',
@ -2687,9 +2687,9 @@ class learnpathItem {
'browsed' => 'ScormBrowsed',
'browsed' => 'ScormBrowsed',
'not attempted' => 'ScormNotAttempted'
'not attempted' => 'ScormNotAttempted'
);
);
$my_lesson_status = get_lang($mylanglist[$status]);
$my_lesson_status = get_lang($mylanglist[$status]);
switch ($status) {
switch ($status) {
case 'completed':
case 'completed':
case 'browsed':
case 'browsed':
@ -2706,9 +2706,9 @@ class learnpathItem {
break;
break;
default:
default:
$class_status = 'default';
$class_status = 'default';
break;
break;
}
}
if ($decorate) {
if ($decorate) {
return Display::label($my_lesson_status, $class_status);
return Display::label($my_lesson_status, $class_status);
} else {
} else {
return $my_lesson_status;
return $my_lesson_status;