Explorar el Código

Updating main/newscorm from 1.9.4 not big changes were made in 1.10

Julio Montoya hace 12 años
padre
commit
26c56c91d2

La diferencia del archivo ha sido suprimido porque es demasiado grande
+ 336 - 389
main/newscorm/learnpath.class.php


+ 175 - 151
main/newscorm/learnpathItem.class.php

@@ -33,6 +33,7 @@ class learnpathItem {
 	public $launch_data = '';
 	public $lesson_location = '';
 	public $level = 0;
+    public $core_exit = '';
 	//var $location; // Only set this for SCORM?
 	public $lp_id;
 	public $max_score;
@@ -75,7 +76,7 @@ class learnpathItem {
 	public function __construct($id, $user_id = null, $course_id = null, $item_content = null) {
 		// Get items table.
 		if (!isset($user_id)) { $user_id = api_get_user_id(); }
-		if (self::debug > 0) { error_log("New LP - In 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);
         
         if (empty($item_content)) {
@@ -89,8 +90,7 @@ class learnpathItem {
             //error_log('New LP - Creating item object from DB: '.$sql, 0);
             $res = Database::query($sql);
             if (Database::num_rows($res) < 1) {
-                $this->error = 'Could not find given learnpath item in learnpath_item table';
-                //error_log('New LP - '.$this->error, 0);
+                $this->error = 'Could not find given learnpath item in learnpath_item table';                
                 return false;
             }
             $row = Database::fetch_array($res);
@@ -144,7 +144,7 @@ class learnpathItem {
 	 * Adds a child to the current item
 	 */
 	public function add_child($item) {
-		if (self::debug > 0) { error_log('New LP - In learnpathItem::add_child()', 0); }
+		if (self::debug > 0) { error_log('learnpathItem::add_child()', 0); }
 		if (!empty($item)) {
 			// Do not check in DB as we expect the call to come from the learnpath class which should
 			// be aware of any fake.
@@ -198,7 +198,7 @@ class learnpathItem {
 	 * @return	boolean	True on success, false otherwise
 	 */
 	public function close() {
-		if (self::debug > 0) { error_log('New LP - In learnpathItem::close()', 0); }
+		if (self::debug > 0) { error_log('learnpathItem::close()', 0); }
 	   	$this->current_stop_time = time();
 	   	$type = $this->get_type();
 		if ($type != 'sco') {
@@ -219,24 +219,25 @@ class learnpathItem {
 	 * @return	boolean	true. Doesn't check for errors yet.
 	 */
 	public function delete() {
-		if (self::debug > 0) { error_log('New LP - In learnpath_item::delete() for item '.$this->db_id, 0); }
+		if (self::debug > 0) { error_log('learnpath_item::delete() for item '.$this->db_id, 0); }
 		$lp_item_view = Database::get_course_table(TABLE_LP_ITEM_VIEW);
 		$lp_item = Database::get_course_table(TABLE_LP_ITEM);
 
         $course_id = api_get_course_int_id();
 
 		$sql_del_view = "DELETE FROM $lp_item_view WHERE c_id = $course_id AND lp_item_id = ".$this->db_id;
-		//error_log('New LP - Deleting from lp_item_view: '.$sql_del_view, 0);
-		$res_del_view = Database::query($sql_del_view);
+		if (self::debug > 0) { error_log('Deleting from lp_item_view: '.$sql_del_view, 0); }
+		Database::query($sql_del_view);
 
 		$sql_sel = "SELECT * FROM $lp_item WHERE c_id = $course_id AND id = ".$this->db_id;
 		$res_sel = Database::query($sql_sel);
-		if (Database::num_rows($res_sel) < 1) { return false; }
-		$row = Database::fetch_array($res_sel);
-
-		$sql_del_item = "DELETE FROM $lp_item WHERE c_id = $course_id AND id = ".$this->db_id;
-		//error_log('New LP - Deleting from lp_item: '.$sql_del_view, 0);
-		$res_del_item = Database::query($sql_del_item);
+		if (Database::num_rows($res_sel) < 1) { 
+            return false; 
+        }
+		
+		$sql_del_item = "DELETE FROM $lp_item WHERE c_id = $course_id AND id = ".$this->db_id;        		
+		Database::query($sql_del_item);
+        if (self::debug > 0) { error_log('Deleting from lp_item: '.$sql_del_view); }
 
 		if (api_get_setting('search_enabled') == 'true') {
 			if (!is_null($this->search_did)) {
@@ -245,7 +246,6 @@ class learnpathItem {
 				$di->remove_document($this->search_did);
 			}
 		}
-
 		return true;
 	}
 
@@ -255,7 +255,7 @@ class learnpathItem {
 	 * @return 	void
 	 */
 	public function drop_child($item) {
-		if (self::debug > 0) { error_log('New LP - In learnpathItem::drop_child()', 0); }
+		if (self::debug > 0) { error_log('learnpathItem::drop_child()', 0); }
 		if (!empty($item)) {
 			foreach ($this->children as $index => $child) {
 				if ($child == $item) {
@@ -270,7 +270,7 @@ class learnpathItem {
 	 * @return	integer	The attempt_id for this item view by this user, or 1 if none defined
 	 */
 	public function get_attempt_id() {
-		if (self::debug > 0) { error_log('New LP - In learnpathItem::get_attempt_id() on item '.$this->db_id, 0); }
+		if (self::debug > 0) { error_log('learnpathItem::get_attempt_id() on item '.$this->db_id, 0); }
 		$res = 1;
 		if (!empty($this->attempt_id)) {
 			$res = $this->attempt_id;
@@ -284,7 +284,7 @@ class learnpathItem {
 	 * @return	array	Array of children items IDs
 	 */
 	public function get_children() {
-		if (self::debug > 0) { error_log('New LP - In learnpathItem::get_children()', 0); }
+		if (self::debug > 0) { error_log('learnpathItem::get_children()', 0); }
 		$list = array();
 		foreach ($this->children as $child) {
 			if (!empty($child)) {
@@ -308,7 +308,7 @@ class learnpathItem {
 	 * @return	string	'credit' or 'no-credit'. Defaults to 'credit' because if we don't know enough about this item, it's probably because it was never used before.
 	 */
 	public function get_credit() {
-		if (self::debug > 1) {error_log('New LP - In learnpathItem::get_credit()', 0); }
+		if (self::debug > 1) {error_log('learnpathItem::get_credit()', 0); }
 		$credit = 'credit';
 		// Now check the value of prevent_reinit (if it's 0, return credit as the default was).
 		if ($this->get_prevent_reinit() != 0) { // If prevent_reinit == 1 (or more).
@@ -316,11 +316,13 @@ class learnpathItem {
 			// Check the status in the database rather than in the object, as checking in the object
 			// would always return "no-credit" when we want to set it to completed.
 			$status = $this->get_status(true);
-			if (self::debug > 2) { error_log('New LP - In learnpathItem::get_credit() - get_prevent_reinit!=0 and status is '.$status, 0); }
+			if (self::debug > 2) { error_log('learnpathItem::get_credit() - get_prevent_reinit!=0 and status is '.$status, 0); }
+            //0=not attempted - 1 = incomplete
 			if ($status != $this->possible_status[0] && $status != $this->possible_status[1]) {
 				$credit = 'no-credit';
 			}
 		}
+        if (self::debug > 1) {error_log("learnpathItem::get_credit() returns: $credit"); }
 		return $credit;
 	}
 
@@ -329,7 +331,7 @@ class learnpathItem {
 	 * @return	integer	Current start time, or current time if none
 	 */
 	public function get_current_start_time() {
-		if (self::debug > 0) { error_log('New LP - In learnpathItem::get_current_start_time()', 0); }
+		if (self::debug > 0) { error_log('learnpathItem::get_current_start_time()', 0); }
 		if (empty($this->current_start_time)) {
 			return time();
 		} else {
@@ -342,7 +344,7 @@ class learnpathItem {
 	 * @return	string	Description
 	 */
 	public function get_description() {
-		if (self::debug > 0) { error_log('New LP - In learnpathItem::get_description()', 0); }
+		if (self::debug > 0) { error_log('learnpathItem::get_description()', 0); }
 		if (empty($this->description)) { return ''; }
 		return $this->description;
 	}
@@ -353,7 +355,7 @@ class learnpathItem {
 	 */
 	public function get_file_path($path_to_scorm_dir = '') {
 	    $course_id = api_get_course_int_id();
-		if (self::debug > 0) { error_log('New LP - In learnpathItem::get_file_path()', 0); }
+		if (self::debug > 0) { error_log('learnpathItem::get_file_path()', 0); }
 		$path = $this->get_path();
    		$type = $this->get_type();
 		if (empty($path)) {
@@ -397,7 +399,7 @@ class learnpathItem {
 	 * @return	integer	Database ID for the current item
 	 */
 	public function get_id() {
-		if (self::debug > 1) {error_log('New LP - In learnpathItem::get_id()', 0); }
+		if (self::debug > 1) {error_log('learnpathItem::get_id()', 0); }
 		if (!empty($this->db_id)) {
 			return $this->db_id;
 		}
@@ -439,7 +441,7 @@ class learnpathItem {
 	 * @return	int	The current number of interactions recorder
 	 */
 	public function get_interactions_count($checkdb = false) {
-		if (self::debug > 1) { error_log('New LP - In learnpathItem::get_interactions_count()', 0); }
+		if (self::debug > 1) { error_log('learnpathItem::get_interactions_count()', 0); }
 		$return = 0;
         $course_id = api_get_course_int_id();
 
@@ -494,7 +496,7 @@ class learnpathItem {
 	 * @return	int	The current number of objectives recorder
 	 */
 	public function get_objectives_count() {
-		if (self::debug > 1) { error_log('New LP - In learnpathItem::get_objectives_count()', 0);}
+		if (self::debug > 1) { error_log('learnpathItem::get_objectives_count()', 0);}
 		$res = 0;
 		if (!empty($this->objectives_count)) {
 			$res = $this->objectives_count;
@@ -507,7 +509,7 @@ class learnpathItem {
 	 * @return	string	Launch data as found in imsmanifest and stored in Chamilo (read only). Defaults to ''.
 	 */
 	public function get_launch_data() {
-		if (self::debug > 0) { error_log('New LP - In learnpathItem::get_launch_data()', 0); }
+		if (self::debug > 0) { error_log('learnpathItem::get_launch_data()', 0); }
 		if (!empty($this->launch_data)) {
 			return $this->launch_data;
 		}
@@ -519,7 +521,7 @@ class learnpathItem {
 	 * @return string	lesson location as recorded by the SCORM and AICC elements. Defaults to ''
 	 */
 	public function get_lesson_location() {
-		if (self::debug > 0) { error_log('New LP - In learnpathItem::get_lesson_location()', 0); }
+		if (self::debug > 0) { error_log('learnpathItem::get_lesson_location()', 0); }
 		if (!empty($this->lesson_location)) { return $this->lesson_location; } else { return ''; }
 	}
 
@@ -545,7 +547,7 @@ class learnpathItem {
 	 * @return int	Level. Defaults to 0
 	 */
 	public function get_level() {
-		if (self::debug > 0) { error_log('New LP - In learnpathItem::get_level()', 0); }
+		if (self::debug > 0) { error_log('learnpathItem::get_level()', 0); }
 		if (empty($this->level)) { return 0; }
 		return $this->level;
 	}
@@ -554,7 +556,7 @@ class learnpathItem {
 	 * Gets the mastery score
 	 */
 	public function get_mastery_score() {
-		if (self::debug > 0) { error_log('New LP - In learnpathItem::get_mastery_score()', 0); }
+		if (self::debug > 0) { error_log('learnpathItem::get_mastery_score()', 0); }
 		if (isset($this->mastery_score)) { return $this->mastery_score; } else { return -1; }
 	}
 
@@ -563,7 +565,7 @@ class learnpathItem {
 	 * @return	int	Maximum score. Defaults to 100 if nothing else is defined
 	 */
 	public function get_max(){
-		if (self::debug > 0) { error_log('New LP - In learnpathItem::get_max()', 0); }
+		if (self::debug > 0) { error_log('learnpathItem::get_max()', 0); }
 		if ($this->type == 'sco') {
 			if (!empty($this->view_max_score) && $this->view_max_score > 0) {
 				return $this->view_max_score;
@@ -582,7 +584,7 @@ class learnpathItem {
 	 * @return	string	Time string in SCORM format (HH:MM:SS or HH:MM:SS.SS or HHHH:MM:SS.SS)
 	 */
 	public function get_max_time_allowed() {
-		if (self::debug > 0) {error_log('New LP - In learnpathItem::get_max_time_allowed()', 0); }
+		if (self::debug > 0) {error_log('learnpathItem::get_max_time_allowed()', 0); }
 		if (!empty($this->max_time_allowed)) { return $this->max_time_allowed; } else { return ''; }
 	}
 
@@ -591,7 +593,7 @@ class learnpathItem {
 	 * @return int	Minimum score. Defaults to 0
 	 */
 	public function get_min() {
-		if (self::debug > 0) { error_log('New LP - In learnpathItem::get_min()', 0); }
+		if (self::debug > 0) { error_log('learnpathItem::get_min()', 0); }
 		if (!empty($this->min_score)) { return $this->min_score; } else { return 0; }
 	}
 
@@ -600,7 +602,7 @@ class learnpathItem {
 	 * @return	int	Parent ID. Defaults to null
 	 */
 	public function get_parent(){
-		if (self::debug > 0) { error_log('New LP - In learnpathItem::get_parent()', 0); }
+		if (self::debug > 0) { error_log('learnpathItem::get_parent()', 0); }
 		if (!empty($this->parent)) {
 			return $this->parent;
 		}
@@ -613,7 +615,7 @@ class learnpathItem {
 	 * @return	string	Path. Defaults to ''
 	 */
 	public function get_path(){
-		if (self::debug > 0) { error_log('New LP - In learnpathItem::get_path()', 0); }
+		if (self::debug > 0) { error_log('learnpathItem::get_path()', 0); }
 		if (empty($this->path)) { return ''; }
 		return $this->path;
 	}
@@ -623,7 +625,7 @@ class learnpathItem {
 	 * @return	string	Empty string or prerequisites string if defined. Defaults to
 	 */
 	public function get_prereq_string() {
-		if (self::debug > 0) { error_log('New LP - In learnpathItem::get_prereq_string()', 0); }
+		if (self::debug > 0) { error_log('learnpathItem::get_prereq_string()', 0); }
 		if (!empty($this->prereq_string)) {
 			return $this->prereq_string;
 		} else {
@@ -637,7 +639,7 @@ class learnpathItem {
 	 */
 	public function get_prevent_reinit() {
 	    $course_id = api_get_course_int_id();
-		if (self::debug > 2) { error_log('New LP - In learnpathItem::get_prevent_reinit()', 0); }
+		if (self::debug > 2) { error_log('learnpathItem::get_prevent_reinit()', 0); }
 		if (!isset($this->prevent_reinit)) {
 			if (!empty($this->lp_id)) {
 				$table = Database::get_course_table(TABLE_LP_MAIN);
@@ -666,7 +668,7 @@ class learnpathItem {
      * @author ndiechburg <noel@cblue.be>
      **/
     public function get_seriousgame_mode() {
-        if(self::debug>2){error_log('New LP - In learnpathItem::get_seriousgame_mode()',0);}        
+        if(self::debug>2){error_log('learnpathItem::get_seriousgame_mode()',0);}        
         $course_id = api_get_course_int_id();
         if (!isset($this->seriousgame_mode)) {
             if (!empty($this->lp_id)) {
@@ -982,7 +984,7 @@ class learnpathItem {
 	 * @return	float	The current score or 0 if no score set yet
 	 */
 	public function get_score() {
-		if (self::debug > 0) { error_log('New LP - In learnpathItem::get_score()', 0); }
+		if (self::debug > 0) { error_log('learnpathItem::get_score()', 0); }
 		$res = 0;
 		if (!empty($this->current_score)) {
 			$res = $this->current_score;
@@ -999,12 +1001,12 @@ class learnpathItem {
 	 */
 	public function get_status($check_db = true, $update_local = false) {
 	    $course_id = api_get_course_int_id();
-		if (self::debug > 0) { error_log('New LP - In learnpathItem::get_status() on item '.$this->db_id, 0); }
+		if (self::debug > 0) { error_log('learnpathItem::get_status() on item '.$this->db_id, 0); }
 		if ($check_db) {
-			if (self::debug > 2) { error_log('New LP - In learnpathItem::get_status(): checking db', 0); }
+			if (self::debug > 2) { error_log('learnpathItem::get_status(): checking db', 0); }
 			$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()."'";            
-			if (self::debug > 2) { error_log('New LP - In learnpathItem::get_status() - Checking DB: '.$sql, 0); }
+			if (self::debug > 2) { error_log('learnpathItem::get_status() - Checking DB: '.$sql, 0); }
 
 			$res = Database::query($sql);
 			if (Database::num_rows($res) == 1) {
@@ -1012,17 +1014,17 @@ class learnpathItem {
 				if ($update_local) {
 					$this->set_status($row['status']);
 				}
-				if (self::debug > 2) { error_log('New LP - In 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'];
 			}
 		} else {
-			if (self::debug > 2) { error_log('New LP - In learnpathItem::get_status() - in get_status: using attrib', 0); }
+			if (self::debug > 2) { error_log('learnpathItem::get_status() - in get_status: using attrib', 0); }
 			if (!empty($this->status)) {
-				if (self::debug > 2) { error_log('New LP - In learnpathItem::get_status() - Returning attrib: '.$this->status, 0); }
+				if (self::debug > 2) { error_log('learnpathItem::get_status() - Returning attrib: '.$this->status, 0); }
 				return $this->status;
 			}
 		}
-   		if (self::debug > 2) { error_log('New LP - In learnpathItem::get_status() - Returning default '.$this->possible_status[0], 0); }
+   		if (self::debug > 2) { error_log('learnpathItem::get_status() - Returning default '.$this->possible_status[0], 0); }
 		return $this->possible_status[0];
 	}
 
@@ -1030,7 +1032,7 @@ class learnpathItem {
 	 * Gets the suspend data
 	 */
 	public function get_suspend_data() {
-		if (self::debug > 0) { error_log('New LP - In learnpathItem::get_suspend_data()', 0); }
+		if (self::debug > 0) { error_log('learnpathItem::get_suspend_data()', 0); }
 		// TODO: Improve cleaning of breaklines ... it works but is it really a beautiful way to do it ?
 		if (!empty($this->current_data)) { return str_replace(array("\r", "\n"), array('\r', '\n'), $this->current_data); } else { return ''; }
 	}
@@ -1044,7 +1046,7 @@ class learnpathItem {
 		$h = get_lang('h');
         $course_id = api_get_course_int_id();
 		if (!isset($given_time)) {
-			if (self::debug > 2) { error_log('New LP - In learnpathItem::get_scorm_time(): given time empty, current_start_time = '.$this->current_start_time, 0); }
+			if (self::debug > 2) { error_log('learnpathItem::get_scorm_time(): given time empty, current_start_time = '.$this->current_start_time, 0); }
 			if (is_object($this)) {
 				if ($query_db === true) {
 					$table = Database::get_course_table(TABLE_LP_ITEM_VIEW);
@@ -1077,7 +1079,7 @@ class learnpathItem {
 		} else {
 			$time = $given_time;
 		}
-		if (self::debug > 2) { error_log('New LP - In learnpathItem::get_scorm_time(): intermediate = '.$time, 0); }
+		if (self::debug > 2) { error_log('learnpathItem::get_scorm_time(): intermediate = '.$time, 0); }
 		$hours = $time/3600;
 		$mins  = ($time%3600)/60;
 		$secs  = ($time%60);
@@ -1086,7 +1088,7 @@ class learnpathItem {
   		} else {
 			$scorm_time = trim(sprintf("%4d$h%02d'%02d\"", $hours, $mins, $secs));
   		}
-		if (self::debug > 2) { error_log('New LP - In learnpathItem::get_scorm_time('.$scorm_time.')', 0); }
+		if (self::debug > 2) { error_log('learnpathItem::get_scorm_time('.$scorm_time.')', 0); }
   		return $scorm_time;
 	}
 
@@ -1104,7 +1106,7 @@ class learnpathItem {
 	 * @return	string	Title
 	 */
 	public function get_title() {
-		if (self::debug > 0) { error_log('New LP - In learnpathItem::get_title()', 0); }
+		if (self::debug > 0) { error_log('learnpathItem::get_title()', 0); }
 		if (empty($this->title)) { return ''; }
 		return $this->title;
 	}
@@ -1114,7 +1116,7 @@ class learnpathItem {
 	 * @return	integer	Total time
 	 */
 	public function get_total_time() {
-		if (self::debug > 0) { error_log('New LP - In learnpathItem::get_total_time()', 0); }
+		if (self::debug > 0) { error_log('learnpathItem::get_total_time()', 0); }
 		if ($this->current_start_time == 0) { // Shouldn't be necessary thanks to the open() method.
 			$this->current_start_time = time();
 		}
@@ -1128,7 +1130,7 @@ class learnpathItem {
 		if ($time < 0) {
 			return 0;
 		} else {
-			if (self::debug > 2) { error_log('New LP - In learnpathItem::get_total_time() - Current stop time = '.$this->current_stop_time.', current start time = '.$this->current_start_time.' Returning '.$time, 0); }
+			if (self::debug > 2) { error_log('learnpathItem::get_total_time() - Current stop time = '.$this->current_stop_time.', current start time = '.$this->current_start_time.' Returning '.$time, 0); }
 			return $time;
 		}
 	}
@@ -1142,7 +1144,7 @@ class learnpathItem {
 		if (!empty($this->type)) {			
 			$res = $this->type;
 		}
-		if (self::debug > 2) { error_log('New LP - In 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); }
 		return $res;
 	}
 
@@ -1151,7 +1153,7 @@ class learnpathItem {
 	 * @return  int     Number of attempts or 0
      */
 	public function get_view_count() {
-		if (self::debug > 0) { error_log('New LP - In learnpathItem::get_view_count()', 0); }
+		if (self::debug > 0) { error_log('learnpathItem::get_view_count()', 0); }
 		if (!empty($this->attempt_id)) {
 			return $this->attempt_id;
 		} else {
@@ -1165,10 +1167,10 @@ class learnpathItem {
 	 */
 	function is_done(){
    		if ($this->status_is(array('completed', 'passed', 'succeeded', 'failed'))) {
-   			if (self::debug > 2) { error_log('New LP - In learnpath::is_done() - Item '.$this->get_id().' is complete', 0); }
+   			if (self::debug > 2) { error_log('learnpath::is_done() - Item '.$this->get_id().' is complete', 0); }
    			return true;
    		}else{
-   			if (self::debug > 2) { error_log('New LP - In learnpath::is_done() - Item '.$this->get_id().' is not complete', 0); }
+   			if (self::debug > 2) { error_log('learnpath::is_done() - Item '.$this->get_id().' is not complete', 0); }
    			return false;
    		}
 	}
@@ -1180,7 +1182,7 @@ class learnpathItem {
 	 * 					 1 if it is allowed. Defaults to 1
 	 */
 	public function is_restart_allowed() {
-		if (self::debug > 2) { error_log('New LP - In learnpathItem::is_restart_allowed()', 0); }
+		if (self::debug > 2) { error_log('learnpathItem::is_restart_allowed()', 0); }
 		$restart = 1;
 		$mystatus = $this->get_status(true);
 		if ($this->get_prevent_reinit() > 0){ // If prevent_reinit == 1 (or more)
@@ -1204,7 +1206,7 @@ class learnpathItem {
 	 * @return	boolean	True on success, false on failure.
 	 */
 	public function open($allow_new_attempt = false) {
-		if (self::debug > 0) { error_log('New LP - In learnpathItem::open()', 0); }
+		if (self::debug > 0) { error_log('learnpathItem::open()', 0); }
 		if ($this->prevent_reinit == 0) {
 			$this->current_score = 0;
 			$this->current_start_time = time();
@@ -1239,7 +1241,7 @@ class learnpathItem {
 	 * @return	string	HTML file (displayable in an <iframe>) or empty string if no path defined
 	 */
 	function output() {
-		if (self::debug > 0) { error_log('New LP - In learnpathItem::output()', 0); }
+		if (self::debug > 0) { error_log('learnpathItem::output()', 0); }
 		if (!empty($this->path) and is_file($this->path)) {
 			$output = '';
 			$output .= file_get_contents($this->path);
@@ -1257,7 +1259,7 @@ class learnpathItem {
 	 * @return	boolean	True if the list of prerequisites given is entirely satisfied, false otherwise
 	 */
 	public function parse_prereq($prereqs_string, $items, $refs_list, $user_id) {
-		if (self::debug > 0) { error_log('New LP - In learnpathItem::parse_prereq() for learnpath '.$this->lp_id.' with string '.$prereqs_string, 0); }
+		if (self::debug > 0) { error_log('learnpathItem::parse_prereq() for learnpath '.$this->lp_id.' with string '.$prereqs_string, 0); }
 
         $course_id = api_get_course_int_id();
 		// Deal with &, |, ~, =, <>, {}, ,, X*, () in reverse order.
@@ -1644,7 +1646,7 @@ class learnpathItem {
 	 * @return	boolean	True on success, false otherwise
 	 */
 	public function restart() {
-        if (self::debug > 0) { error_log('New LP - In learnpathItem::restart()', 0); }
+        if (self::debug > 0) { error_log('learnpathItem::restart()', 0); }
         if ($this->type == 'sco') { //If this is a sco, chamilo can't update the time without explicit scorm call
             $this->current_start_time = 0;
             $this->current_stop_time = 0; //Those 0 value have this effect
@@ -1699,59 +1701,57 @@ class learnpathItem {
 	 * @return	boolean	True on success, false on failure
 	 */
 	public function save($from_outside = true, $prereqs_complete = false) {
-		if (self::debug > 0) { error_log('New LP - In learnpathItem::save()', 0); }
-		//$item_view_table = Database::get_course_table(COURSEID, LEARNPATH_ITEM_VIEW_TABLE);
-	 	$item_id = $this->get_id();
+		if (self::debug > 0) { error_log('learnpathItem::save()', 0); }			 	
 	 	// First check if parameters passed via GET can be saved here
 	 	// in case it's a SCORM, we should get:
 		if ($this->type == 'sco' || $this->type== 'au') {
-			$s = $this->get_status(true);
+			$status = $this->get_status(true);
 			if ($this->prevent_reinit == 1 AND
-				$s != $this->possible_status[0] AND $s != $this->possible_status[1]) {
-				if (self::debug > 1) { error_log('New LP - In learnpathItem::save() - save reinit blocked by setting', 0); }
+				$status != $this->possible_status[0] AND $status != $this->possible_status[1]) {
+				if (self::debug > 1) { error_log('learnpathItem::save() - save reinit blocked by setting', 0); }
 				// Do nothing because the status has already been set. Don't allow it to change.
 				// TODO: Check there isn't a special circumstance where this should be saved.
 			} else {
-				if (self::debug > 1) { error_log('New LP - In learnpathItem::save() - SCORM save request received', 0); }
+				if (self::debug > 1) { error_log('learnpathItem::save() - SCORM save request received', 0); }
 				//get all new settings from the URL
 				if ($from_outside) {
-					if (self::debug > 1) { error_log('New LP - In learnpathItem::save() - Getting item data from outside', 0); }
+					if (self::debug > 1) { error_log('learnpathItem::save() - Getting item data from outside', 0); }
 					foreach ($_GET as $param => $value) {
 						$value = Database::escape_string($value);
 						switch ($param) {
 							case 'score':
 								$this->set_score($value);
-								if (self::debug > 2) { error_log('New LP - In learnpathItem::save() - setting score to '.$value, 0); }
+								if (self::debug > 2) { error_log('learnpathItem::save() - setting score to '.$value, 0); }
 								break;
 							case 'max':
 								$this->set_max_score($value);
-								if (self::debug > 2) { error_log('New LP - In learnpathItem::save() - setting view_max_score to '.$value, 0); }
+								if (self::debug > 2) { error_log('learnpathItem::save() - setting view_max_score to '.$value, 0); }
 								break;
 			 				case 'min':
 			 					$this->min_score = $value;
-			 					if (self::debug > 2) { error_log('New LP - In learnpathItem::save() - setting min_score to '.$value, 0); }
+			 					if (self::debug > 2) { error_log('learnpathItem::save() - setting min_score to '.$value, 0); }
 			 					break;
 			 				case 'lesson_status':
-			 					if(!empty($value)){
+			 					if (!empty($value)) {
 				 					$this->set_status($value);
-				 						if (self::debug > 2) { error_log('New LP - In learnpathItem::save() - setting status to '.$value, 0); }
+                                    if (self::debug > 2) { error_log('learnpathItem::save() - setting status to '.$value, 0); }
 			 					}
 			 					break;
 			 				case 'time':
 			 					$this->set_time($value);
-			 					if (self::debug > 2) { error_log('New LP - In learnpathItem::save() - setting time to '.$value, 0); }
+			 					if (self::debug > 2) { error_log('learnpathItem::save() - setting time to '.$value, 0); }
 			 					break;
 			 				case 'suspend_data':
 			 					$this->current_data = $value;
-			 					if (self::debug > 2) { error_log('New LP - In learnpathItem::save() - setting suspend_data to '.$value, 0); }
+			 					if (self::debug > 2) { error_log('learnpathItem::save() - setting suspend_data to '.$value, 0); }
 			 					break;
 			 				case 'lesson_location':
 			 					$this->set_lesson_location($value);
-			 					if (self::debug > 2) { error_log('New LP - In learnpathItem::save() - setting lesson_location to '.$value, 0); }
+			 					if (self::debug > 2) { error_log('learnpathItem::save() - setting lesson_location to '.$value, 0); }
 			 					break;
 			 				case 'core_exit':
 			 					$this->set_core_exit($value);
-			 					if (self::debug > 2) { error_log('New LP - In learnpathItem::save() - setting core_exit to '.$value, 0); }
+			 					if (self::debug > 2) { error_log('learnpathItem::save() - setting core_exit to '.$value, 0); }
 			 					break;
 			 				case 'interactions':
 			 					//$interactions = unserialize($value);
@@ -1775,7 +1775,7 @@ class learnpathItem {
 						}
 			 		}
 				} else {
-					if (self::debug > 1) { error_log('New LP - In learnpathItem::save() - Using inside item status', 0); }
+					if (self::debug > 1) { error_log('learnpathItem::save() - Using inside item status', 0); }
 					// Do nothing, just let the local attributes be used.
 				}
 			}
@@ -1809,7 +1809,7 @@ class learnpathItem {
 	 * @return	boolean	TRUE on success, FALSE otherwise
 	 */
 	public function set_attempt_id($num) {
-		if (self::debug > 0) { error_log('New LP - In learnpathItem::set_attempt_id()', 0); }
+		if (self::debug > 0) { error_log('learnpathItem::set_attempt_id()', 0); }
 	 	if ($num == strval(intval($num)) && $num >= 0) {
 	 		$this->attempt_id = $num;
 	 		return true;
@@ -1842,7 +1842,7 @@ class learnpathItem {
 	 * @return  void
 	 */
 	public function set_description($string = '') {
-		if (self::debug > 0) { error_log('New LP - In learnpathItem::set_description()', 0); }
+		if (self::debug > 0) { error_log('learnpathItem::set_description()', 0); }
 		if (!empty($string)) { $this->description = $string; }
 	}
 
@@ -1852,7 +1852,7 @@ class learnpathItem {
 	 * @return	boolean	True on success, false otherwise
 	 */
 	public function set_lesson_location($location) {
-   		if (self::debug > 0) { error_log('New LP - In learnpathItem::set_lesson_location()', 0); }
+   		if (self::debug > 0) { error_log('learnpathItem::set_lesson_location()', 0); }
 		if (isset($location)) {
    			$this->lesson_location = Database::escape_string($location);
   			return true;
@@ -1866,7 +1866,7 @@ class learnpathItem {
 	 * @return  void
 	 */
 	public function set_level($int = 0) {
-		if (self::debug > 0) { error_log('New LP - In learnpathItem::set_level('.$int.')', 0); }
+		if (self::debug > 0) { error_log('learnpathItem::set_level('.$int.')', 0); }
 		if (!empty($int) AND $int == strval(intval($int))) { $this->level = $int; }
 	}
 
@@ -1882,7 +1882,7 @@ class learnpathItem {
 	    } else {
 	        $course_id = intval($course_id);
 	    }
-	    if (self::debug > 0) { error_log('New LP - In learnpathItem::set_lp_view('.$lp_view_id.')', 0); }
+	    if (self::debug > 0) { error_log('learnpathItem::set_lp_view('.$lp_view_id.')', 0); }
 		if (!empty($lp_view_id) and $lp_view_id = intval(strval($lp_view_id))) {
 	 		$this->view_id = $lp_view_id;
 
@@ -1894,7 +1894,7 @@ class learnpathItem {
                             lp_view_id = ".$lp_view_id." 
                     ORDER BY view_count DESC";
 
-		 	if (self::debug > 2) { error_log('New LP - In 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); }
 		 	$res = Database::query($sql);
 		 	if (Database::num_rows($res) > 0) {
 		 		$row = Database::fetch_array($res);
@@ -1908,7 +1908,7 @@ class learnpathItem {
                 $this->current_stop_time 	= $this->current_start_time + $row['total_time'];
 				$this->lesson_location      = $row['lesson_location'];
 				$this->core_exit            = $row['core_exit'];
-			 	if (self::debug > 2) { error_log('New LP - In learnpathItem::set_lp_view() - Updated item object with database values', 0); }
+			 	if (self::debug > 2) { error_log('learnpathItem::set_lp_view() - Updated item object with database values', 0); }
 
 			 	// Now get the number of interactions for this little guy.
 			 	$item_view_interaction_table = Database::get_course_table(TABLE_LP_IV_INTERACTION);
@@ -1942,7 +1942,7 @@ class learnpathItem {
 	 * @return  void
 	 */
 	public function set_path($string = '') {
-		if (self::debug > 0) { error_log('New LP - In learnpathItem::set_path()', 0); }
+		if (self::debug > 0) { error_log('learnpathItem::set_path()', 0); }
 		if (!empty($string)) { $this->path = $string; }
 	}
 
@@ -1953,7 +1953,7 @@ class learnpathItem {
 	 * @return  void
 	 */
 	public function set_prevent_reinit($prevent) {
-		if (self::debug > 0) { error_log('New LP - In learnpathItem::set_prevent_reinit()', 0); }
+		if (self::debug > 0) { error_log('learnpathItem::set_prevent_reinit()', 0); }
 		if ($prevent) {
 			$this->prevent_reinit = 1;
 		} else {
@@ -1966,18 +1966,32 @@ class learnpathItem {
 	 * it, then set the status to 'passed'.
 	 * @param	float	Score
 	 * @return	boolean	True on success, false otherwise
-	 */
+	 */    
 	public function set_score($score) {
-   		if (self::debug > 0) { error_log('New LP - In learnpathItem::set_score('.$score.')', 0); }
-   		if (($this->max_score<=0 || $score <= $this->max_score) && ($score >= $this->min_score)) {
+        //$possible_status = array('not attempted','incomplete','completed','passed','failed','browsed');
+   		if (self::debug > 0) { error_log('learnpathItem::set_score('.$score.')', 0); }
+   		if (($this->max_score <= 0 || $score <= $this->max_score) && ($score >= $this->min_score)) {
    			$this->current_score = $score;
    			$master = $this->get_mastery_score();
    			$current_status = $this->get_status(false);
+            
+            //Fixes bug when SCORM doesn't send a mastery score even if they sent a score!
+            if ($master == -1) {
+                $master = $this->max_score;
+            }
+            if (self::debug > 0) {
+                error_log('get_mastery_score: '.$master);
+                error_log('current_status: '.$current_status);
+                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 ($master != -1 && $this->current_score >= $master && $current_status != $this->possible_status[2]) {
-   				$this->set_status($this->possible_status[3]);
+                if (self::debug > 0) error_log('Status changed to: '.$this->possible_status[3]);
+   				$this->set_status($this->possible_status[3]); //passed
    			} elseif ($master != -1 && $this->current_score < $master) {
-   				$this->set_status($this->possible_status[4]);
+                if (self::debug > 0) error_log('Status changed to: '.$this->possible_status[4]);
+   				$this->set_status($this->possible_status[4]); //failed
    			}
   			return true;
   		}
@@ -1990,10 +2004,10 @@ class learnpathItem {
 	 * @return	boolean	True on success, false on error
 	 */
 	public function set_max_score($score) {
-   		if (self::debug > 0) { error_log('New LP - In learnpathItem::set_max_score('.$score.')', 0); }
+   		if (self::debug > 0) { error_log('learnpathItem::set_max_score('.$score.')', 0); }
 	 	if (is_int($score) or $score == '') {
 	 		$this->view_max_score = Database::escape_string($score);
-	 		if (self::debug > 1) { error_log('New LP - In learnpathItem::set_max_score() - Updated object score of item '.$this->db_id.' to '.$this->view_max_score, 0); }
+	 		if (self::debug > 1) { error_log('learnpathItem::set_max_score() - Updated object score of item '.$this->db_id.' to '.$this->view_max_score, 0); }
 	 		return true;
 	 	}
 	 	return false;
@@ -2005,7 +2019,7 @@ class learnpathItem {
 	 * @return	boolean	True on success, false on error
 	 */
 	public function set_status($status) {
-   		if (self::debug > 0) { error_log('New LP - In learnpathItem::set_status('.$status.')', 0); }
+   		if (self::debug > 0) { error_log('learnpathItem::set_status('.$status.')', 0); }
 	 	$found = false;
 	 	foreach ($this->possible_status  as $possible) {
 	 		if (preg_match('/^'.$possible.'$/i', $status)) {
@@ -2015,7 +2029,7 @@ class learnpathItem {
 	 	//if (in_array($status, $this->possible_status)) {
 	 	if ($found) {
 	 		$this->status = Database::escape_string($status);
-	 		if (self::debug > 1) { error_log('New LP - In learnpathItem::set_status() - Updated object status of item '.$this->db_id.' to '.$this->status, 0); }
+	 		if (self::debug > 1) { error_log('learnpathItem::set_status() - Updated object status of item '.$this->db_id.' to '.$this->status, 0); }
 	 		return true;
 	 	}
 	 	//error_log('New LP - '.$status.' was not in the possible status', 0);
@@ -2067,27 +2081,30 @@ class learnpathItem {
 	 * @return  void
 	 */
 	public function set_time($scorm_time, $format = 'scorm') {        
-   		if (self::debug > 0) { error_log('New LP - In learnpathItem::set_time('.$scorm_time.')', 0); }
-	 	if ($scorm_time == 0 and ($this->type!='sco') and $this->current_start_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) {
 	 		$my_time = time() - $this->current_start_time;
 	 		if ($my_time > 0) {
 	 			$this->update_time($my_time);
-	 			if (self::debug > 0) { error_log('New LP - In learnpathItem::set_time('.$scorm_time.') - found asset - set time to '.$my_time, 0); }
+	 			if (self::debug > 0) { error_log('learnpathItem::set_time('.$scorm_time.') - found asset - set time to '.$my_time, 0); }
 	 		}
 	 	} else {
-	 		if ($format == 'scorm') {
-			 	$res = array();
-			 	if (preg_match('/^(\d{1,4}):(\d{2}):(\d{2})(\.\d{1,4})?/', $scorm_time, $res)) {
-			 		$time = time();
-					$hour = $res[1];
-					$min = $res[2];
-					$sec = $res[3];
-					// Getting total number of seconds spent.
-			 		$total_sec = $hour*3600 + $min*60 + $sec;
-                    $this->scorm_update_time($total_sec);
-			 	}
-	 		} elseif ($format == 'int') {
-     			$this->scorm_update_time($scorm_time);
+            switch ($format) {
+                case 'scorm':                    
+                    $res = array();
+                    if (preg_match('/^(\d{1,4}):(\d{2}):(\d{2})(\.\d{1,4})?/', $scorm_time, $res)) {
+                        $time = time();
+                        $hour = $res[1];
+                        $min = $res[2];
+                        $sec = $res[3];
+                        // Getting total number of seconds spent.
+                        $total_sec = $hour*3600 + $min*60 + $sec;
+                        $this->scorm_update_time($total_sec);
+                    }
+                    break;
+                case 'int':
+                    $this->scorm_update_time($scorm_time);
+                    break;
 	 		}
 	 	}
 	}
@@ -2098,7 +2115,7 @@ class learnpathItem {
 	 * @return  void
 	 */
 	public function set_title($string = '') {
-   		if (self::debug > 0) { error_log('New LP - In learnpathItem::set_title()', 0); }
+   		if (self::debug > 0) { error_log('learnpathItem::set_title()', 0); }
 		if (!empty($string)) { $this->title = $string; }
 	}
 
@@ -2108,7 +2125,7 @@ class learnpathItem {
 	 * @return  void
 	 */
 	public function set_type($string = '') {
-   		if (self::debug > 0) { error_log('New LP - In learnpathItem::set_type()', 0); }
+   		if (self::debug > 0) { error_log('learnpathItem::set_type()', 0); }
 		if (!empty($string)) { $this->type = $string; }
 	}
 
@@ -2118,7 +2135,7 @@ class learnpathItem {
 	 * @return	boolean			True if the status was one of the given strings, false otherwise
 	 */
 	public function status_is($list = array()) {
-   		if (self::debug > 1) { error_log('New LP - In learnpathItem::status_is('.print_r($list,true).') on item '.$this->db_id, 0); }
+   		if (self::debug > 1) { error_log('learnpathItem::status_is('.print_r($list,true).') on item '.$this->db_id, 0); }
 		$mystatus = $this->get_status(true);
 		if (empty($mystatus)) {
 			return false;
@@ -2142,7 +2159,7 @@ class learnpathItem {
 	 * TODO: Make this method better by allowing better/multiple time slices.
 	 */
 	public function update_time($total_sec = 0) {
-   		if (self::debug > 0) { error_log('New LP - In learnpathItem::update_time('.$total_sec.')', 0); }
+   		if (self::debug > 0) { error_log('learnpathItem::update_time('.$total_sec.')', 0); }
 		if ($total_sec >= 0) {
 	 		// Getting start time from finish time. The only problem in the calculation is it might be
 	 		// modified by the scripts processing time.
@@ -2178,24 +2195,29 @@ class learnpathItem {
 	/**
      * Special scorm update time function. This function will update time directly into db for scorm objects
      **/
-    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("total_sec: $total_sec");
+        
         //Step 1 : get actual total time stored in db
         $item_view_table = Database::get_course_table(TABLE_LP_ITEM_VIEW);
-
         $course_id = api_get_course_int_id();
+        
         $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.'" ;';
         $result=Database::query($get_view_sql);
         $row=Database::fetch_array($result);
+        
         if (!isset($row['total_time'])) {
             $total_time = 0;
         } else {
             $total_time = $row['total_time'];
         }
+        if (self::debug > 0) error_log("total_time: $total_time");
 
         //Step 2.1 : if normal mode total_time = total_time + total_sec
         if (api_get_setting('scorm_cumulative_session_time') != 'false'){
-            $total_time +=$total_sec;
+            $total_time += $total_sec;
             //$this->last_scorm_session_time = $total_sec;
         } else {
             //Step 2.2 : if not cumulative mode total_time = total_time - last_update + total_sec
@@ -2203,10 +2225,11 @@ class learnpathItem {
             $this->last_scorm_session_time = $total_sec;
         }
         //Step 3 update db only if status != completed, passed, browsed or seriousgamemode not activated
-        $case_completed=array('completed','passed','browsed','failed'); //TODO COMPLETE
-        if ($this->seriousgame_mode!=1 || !in_array($row['status'], $case_completed)){
-            $update_view_sql='UPDATE '.$item_view_table." SET total_time =$total_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.'" ;';
+        $case_completed = array('completed','passed','browsed','failed'); //TODO COMPLETE
+        if ($this->seriousgame_mode!=1 || !in_array($row['status'], $case_completed)) {
+            $update_view_sql ="UPDATE $item_view_table SET total_time = '$total_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}";
+            if (self::debug > 0) error_log($update_view_sql);
             $result=Database::query($update_view_sql);
         }
     }
@@ -2218,16 +2241,17 @@ class learnpathItem {
       $item_view_table = Database::get_course_table(TABLE_LP_ITEM_VIEW);
       $course_id = api_get_course_int_id();
       $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.'" ;';
-      $result=Database::query($update_view_sql);
+                        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);
     }
+    
     /**
 	 * 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
 	 * @return	boolean		True or false on error
 	 */
 	public function write_objectives_to_db() {
-   		if (self::debug > 0) { error_log('New LP - In learnpathItem::write_objectives_to_db()', 0); }
+   		if (self::debug > 0) { error_log('learnpathItem::write_objectives_to_db()', 0); }
         $course_id = api_get_course_int_id();
 	 	if (is_array($this->objectives) && count($this->objectives) > 0) {
 	 		// Save objectives.
@@ -2240,7 +2264,7 @@ class learnpathItem {
 	 		if (Database::num_rows($res) > 0) {
 	 			$row = Database::fetch_array($res);
 	 			$lp_iv_id = $row[0];
-	 			if (self::debug > 2) { error_log('New LP - In learnpathItem::write_to_db() - Got item_view_id '.$lp_iv_id.', now checking objectives ', 0); }
+	 			if (self::debug > 2) { error_log('learnpathItem::write_to_db() - Got item_view_id '.$lp_iv_id.', now checking objectives ', 0); }
 		 		foreach($this->objectives as $index => $objective){
 		 			$iva_table = Database::get_course_table(TABLE_LP_IV_OBJECTIVE);
 		 			$iva_sql = "SELECT id FROM $iva_table " .
@@ -2285,16 +2309,17 @@ class learnpathItem {
 	 * @return	boolean	Query result
 	 */
 	 public function write_to_db() {
+         if (self::debug > 0) { error_log('learnpathItem::write_to_db()', 0); }
+         
 		// Check the session visibility.
 		if (!api_is_allowed_to_session_edit()) {
+            if (self::debug > 0) { error_log('return false api_is_allowed_to_session_edit'); }            
 			return false;
 		}
-		$course_id = api_get_course_int_id();
-
-   		if (self::debug > 0) { error_log('New LP - In learnpathItem::write_to_db()', 0); }
-   		$mode = $this->get_lesson_mode();
-   		$credit = $this->get_credit();
-   		$my_verified_status=$this->get_status(false);
+		$course_id  = api_get_course_int_id();
+   		$mode       = $this->get_lesson_mode();
+   		$credit     = $this->get_credit();
+   		//$my_verified_status=$this->get_status(false);
 
    		$item_view_table = Database::get_course_table(TABLE_LP_ITEM_VIEW);
 		$sql_verified = 'SELECT status FROM '.$item_view_table.'
@@ -2311,10 +2336,14 @@ class learnpathItem {
             }
         }
 
-   		if ((($save===false && $this->type == 'sco') || 
-            (($this->type == 'sco') && ($credit == 'no-credit' OR $mode == 'review' OR $mode == 'browse'))) && ($this->seriousgame_mode!=1 && $this->type == 'sco')){
-   			//this info shouldn't be saved as the credit or lesson mode info prevent it
-   			if (self::debug>1){error_log('New LP - In learnpathItem::write_to_db() - credit('.$credit.') or lesson_mode('.$mode.') prevent recording!',0);}
+   		if ((($save === false && $this->type == 'sco') || 
+                ($this->type == 'sco' && ($credit == 'no-credit' OR $mode == 'review' OR $mode == 'browse'))
+            ) && ($this->seriousgame_mode != 1 && $this->type == 'sco')
+           ){   			
+   			if (self::debug>1) { 
+                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);
+            }
    		} else {
 	  		// Check the row exists.
 	  		$inserted = false;
@@ -2348,7 +2377,7 @@ class learnpathItem {
 			 			"'".Database::escape_string($this->current_data)."'," .
 			 			//"'".$this->get_max_time_allowed()."'," .
 			 			"'".$this->lesson_location."')";
-	  			if (self::debug > 2) { error_log('New LP - In learnpathItem::write_to_db() - Inserting into item_view forced: '.$sql, 0); }
+	  			if (self::debug > 2) { error_log('learnpathItem::write_to_db() - Inserting into item_view forced: '.$sql, 0); }
 			 	$res = Database::query($sql);
 			 	$this->db_item_view_id = Database::insert_id();
 			 	$inserted = true;
@@ -2359,17 +2388,12 @@ 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();
-		 	if (self::debug > 2) { error_log('New LP - In learnpathItem::write_to_db() - Querying item_view: '.$check, 0); }
+		 	if (self::debug > 2) { error_log('learnpathItem::write_to_db() - Querying item_view: '.$check, 0); }
 		 	$check_res = Database::query($check);
 		 	// Depending on what we want (really), we'll update or insert a new row
 		 	// now save into DB.
 		 	$res = 0;
-		 	if (!$inserted && Database::num_rows($check_res) < 1) {
-				/*$my_status = '';
-		 		if ($this->type != TOOL_QUIZ) {
-		 			$my_status = $this->get_status(false);
-		 		}*/
-
+		 	if (!$inserted && Database::num_rows($check_res) < 1) {	
 			 	$sql = "INSERT INTO $item_view_table " .
 			 			"(c_id, total_time, " .
 			 			"start_time, " .
@@ -2394,7 +2418,7 @@ class learnpathItem {
 			 			"'".Database::escape_string($this->current_data)."'," .
 			 			//"'".$this->get_max_time_allowed()."'," .
 			 			"'".$this->lesson_location."')";
-			 	if (self::debug > 2) { error_log('New LP - In learnpathItem::write_to_db() - Inserting into item_view: '.$sql, 0); }
+			 	if (self::debug > 2) { error_log('learnpathItem::write_to_db() - Inserting into item_view: '.$sql, 0); }
 			 	$res = Database::query($sql);
 			 	$this->db_item_view_id = Database::insert_id();
 		 	} else {
@@ -2525,7 +2549,7 @@ class learnpathItem {
                     }
                     $this->current_start_time = time();
                 }
-                if (self::debug > 2) { error_log('New LP - In 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);
             }
                         
@@ -2540,7 +2564,7 @@ class learnpathItem {
 		 		if (Database::num_rows($res) > 0) {
 		 			$row = Database::fetch_array($res);
 		 			$lp_iv_id = $row[0];
-		 			if (self::debug > 2) { error_log('New LP - In learnpathItem::write_to_db() - Got item_view_id '.$lp_iv_id.', now checking interactions ', 0); }
+		 			if (self::debug > 2) { error_log('learnpathItem::write_to_db() - Got item_view_id '.$lp_iv_id.', now checking interactions ', 0); }
 			 		foreach ($this->interactions as $index => $interaction) {
 			 			$correct_resp = '';
 			 			if (is_array($interaction[4]) && !empty($interaction[4][0])) {
@@ -2589,7 +2613,7 @@ class learnpathItem {
 		 		}
 		 	}
    		}
-		if (self::debug > 2) { error_log('New LP - End of learnpathItem::write_to_db()', 0); }
+		if (self::debug > 2) { error_log('End of learnpathItem::write_to_db()', 0); }
 	 	return true;
 	 }
      

+ 8 - 11
main/newscorm/lp_ajax_initialize.php

@@ -31,7 +31,6 @@ function initialize_item($lp_id, $user_id, $view_id, $next_item) {
     $debug = 0;
     $return = '';
     if ($debug > 0) { error_log('In initialize_item('.$lp_id.','.$user_id.','.$view_id.','.$next_item.')', 0); }
-    //$objResponse = new xajaxResponse();
     /*$item_id may be one of:
      * -'next'
      * -'previous'
@@ -47,16 +46,16 @@ function initialize_item($lp_id, $user_id, $view_id, $next_item) {
     require_once 'aiccItem.class.php';
     $mylp = '';
     if (isset($_SESSION['lpobject'])) {
-        if ($debug > 1) { error_log('////$_SESSION[lpobject] is set', 0); }
+        if ($debug > 1) { error_log('$_SESSION[lpobject] is set', 0); }
         $oLP = unserialize($_SESSION['lpobject']);
         if (!is_object($oLP)) {
             if ($debug > 1) { error_log(print_r($oLP,true), 0); }
-            if ($debug > 2) { error_log('////Building new lp', 0); }
+            if ($debug > 2) { error_log('Building new LP', 0); }
             unset($oLP);
             $code = api_get_course_id();
             $mylp = new learnpath($code,$lp_id,$user_id);
         } else {
-            if ($debug > 1) { error_log('////Reusing session lp', 0); }
+            if ($debug > 1) { error_log('Reusing session LP', 0); }
             $mylp = $oLP;
         }
     }
@@ -68,10 +67,10 @@ function initialize_item($lp_id, $user_id, $view_id, $next_item) {
         $mylp->save_current();
     }
     */
-    //$objResponse->addAlert(api_get_path(REL_CODE_PATH).'newscorm/learnpathItem.class.php');
+    
     if (is_object($mylp->items[$next_item])) {
         if ($debug > 1) { error_log('In initialize_item - recovering existing item object '.$next_item, 0); }
-        $mylpi = & $mylp->items[$next_item];
+        $mylpi = $mylp->items[$next_item];
     } else {
         if ($debug > 1) { error_log('In initialize_item - generating new item object '.$next_item, 0); }
         $mylpi = new learnpathItem($next_item, $user_id);
@@ -90,8 +89,8 @@ function initialize_item($lp_id, $user_id, $view_id, $next_item) {
     $mymax = $mylpi->get_max();
     if ($mymax === '') { $mymax = "''"; }
     $mymin = $mylpi->get_min();
-    $mylesson_status = $mylpi->get_status();
-    $mylesson_location = $mylpi->get_lesson_location();
+    
+    $mylesson_status = $mylpi->get_status();    
     $mytotal_time = $mylpi->get_scorm_time('js', null, true);
     $mymastery_score = $mylpi->get_mastery_score();
     $mymax_time_allowed = $mylpi->get_max_time_allowed();
@@ -189,9 +188,7 @@ function initialize_item($lp_id, $user_id, $view_id, $next_item) {
 
     $mylp->set_error_msg('');
     $mylp->prerequisites_match(); // Check the prerequisites are all complete.
-    if ($debug > 1) { error_log('Prereq_match() returned '.htmlentities($mylp->error), 0); }
-    //$_SESSION['scorm_item_id'] = $new_item_id; // Save the new item ID for the exercise tool to use/
-    //$_SESSION['lpobject'] = serialize($mylp);
+    if ($debug > 1) { error_log('Prereq_match() returned '.htmlentities($mylp->error), 0); }    
     return $return;
 }
 echo initialize_item($_POST['lid'], $_POST['uid'], $_POST['vid'], $_POST['iid']);

+ 3 - 3
main/newscorm/lp_ajax_last_update_status.php

@@ -51,16 +51,16 @@ function last_update_status($lp_id, $user_id, $view_id, $item_id) {
     require_once 'scormItem.class.php';
     $mylp = '';
     if (isset($_SESSION['lpobject'])) {
-        if ($debug > 1) { error_log('////$_SESSION[lpobject] is set', 0); }
+        if ($debug > 1) { error_log('$_SESSION[lpobject] is set', 0); }
         $oLP = unserialize($_SESSION['lpobject']);
         if (!is_object($oLP)) {
             if ($debug > 2) { error_log(print_r($oLP, true), 0); }
-            if ($debug > 2) { error_log('////Building new lp', 0); }
+            if ($debug > 2) { error_log('Building new lp', 0); }
             unset($oLP);
             $code = api_get_course_id();
             $mylp = new learnpath($code,$lp_id,$user_id);
         } else {
-            if ($debug > 2) { error_log('////Reusing session lp', 0); }
+            if ($debug > 2) { error_log('Reusing session lp', 0); }
             $mylp = & $oLP;
         }
     }

+ 113 - 73
main/newscorm/lp_ajax_save_item.php

@@ -18,6 +18,12 @@ $use_anonymous = true;
 $language_file[] = 'learnpath';
 
 require_once 'back_compat.inc.php';
+require_once 'learnpath.class.php';
+require_once 'scorm.class.php';
+require_once 'aicc.class.php';
+require_once 'learnpathItem.class.php';
+require_once 'scormItem.class.php';
+require_once 'aiccItem.class.php';
 
 /**
  * Writes an item's new values into the database and returns the operation result
@@ -38,32 +44,29 @@ require_once 'back_compat.inc.php';
 function save_item($lp_id, $user_id, $view_id, $item_id, $score = -1, $max = -1, $min = -1, $status = '', $time = 0, $suspend = '', $location = '', $interactions = array(), $core_exit = 'none') {
     global $_configuration;    
     $return = '';
-    if ($debug > 0) { error_log('In save_item('.$lp_id.','.$user_id.','.$view_id.','.$item_id.','.$score.','.$max.','.$min.',"'.$status.'",'.$time.',"'.$suspend.'","'.$location.'","'.(count($interactions) > 0 ? $interactions[0] : '').'","'.$core_exit.'")', 0); }
+    $debug = 0;
     
-    require_once 'learnpath.class.php';
-    require_once 'scorm.class.php';
-    require_once 'aicc.class.php';
-    require_once 'learnpathItem.class.php';
-    require_once 'scormItem.class.php';
-    require_once 'aiccItem.class.php';
+    if ($debug > 0) { 
+        error_log('lp_ajax_save_item.php : save_item params: ');
+        error_log("lp_id: $lp_id - user_id: - $user_id - view_id: $view_id - item_id: $item_id");
+        error_log("score: $score - max:$max - min: $min - status:$status - time:$time - suspend: $suspend - location: $location - core_exit: $core_exit");
+    }    
     
-    $mylp = '';
-    if (isset($_SESSION['lpobject'])) {
-        if ($debug > 1) { error_log('////$_SESSION[lpobject] is set', 0); }
+    $mylp = null;
+    if (isset($_SESSION['lpobject'])) {        
         $oLP = unserialize($_SESSION['lpobject']);
-        if (!is_object($oLP)) {
-            if ($debug > 2) { error_log(print_r($oLP,true), 0); }
-            if ($debug > 2) { error_log('////Building new lp', 0); }
+        if (!is_object($oLP)) {            
             unset($oLP);
             $code = api_get_course_id();
             $mylp = new learnpath($code, $lp_id, $user_id);
         } else {
-            if ($debug > 2) { error_log('////Reusing session lp', 0); }
             $mylp = & $oLP;
         }
+    }    
+    
+    if (!is_a($mylp, 'learnpath')) { 
+        return ''; 
     }
-    //$objResponse->addAlert(api_get_path(REL_CODE_PATH).'newscorm/learnpathItem.class.php');
-    if (!is_a($mylp, 'learnpath')) { return ''; }
 
     $prereq_check = $mylp->prerequisites_match($item_id);
     
@@ -71,66 +74,97 @@ function save_item($lp_id, $user_id, $view_id, $item_id, $score = -1, $max = -1,
     //This functions sets the $this->db_item_view_id variable needed in get_status() see BT#5069
     $mylpi->set_lp_view($view_id);
     
-    if ($prereq_check === true) { 
-        // Launch the prerequisites check and set error if needed
-        //$mylpi =& $mylp->items[$item_id];
-        //$mylpi->set_lp_view($view_id);
+    if ($prereq_check === true) {
+        if ($debug > 1) { error_log('Prereq are check'); }
+        
+        // Launch the prerequisites check and set error if needed   
         if (isset($max) && $max != -1)  {
             $mylpi->max_score = $max;
             $mylpi->set_max_score($max);
+            if ($debug > 1) { error_log("Setting max_score: $max"); }
         }
+        
         if (isset($min) && $min != -1 && $min != 'undefined') {
             $mylpi->min_score = $min;
+            if ($debug > 1) { error_log("Setting min_score: $min"); }
         }
+        
+        //set_score function already saves the status
         if (isset($score) && $score != -1) {
-            if ($debug > 1) { error_log('Calling set_score('.$score.') from xajax', 0); }
+            if ($debug > 1) { error_log('Calling set_score('.$score.')', 0); }            
             $mylpi->set_score($score);
-            if ($debug > 1) { error_log('Done calling set_score from xajax - now '.$mylpi->get_score(), 0); }
-        }
-        if (isset($status) && $status != '' && $status != 'undefined') {
-            if ($debug > 1) { error_log('Calling set_status('.$status.') from xajax', 0); }
-            $mylpi->set_status($status);
-            if ($debug > 1) { error_log('Done calling set_status from xajax - now '.$mylpi->get_status(false), 0); }
+            if ($debug > 1) { error_log('Done calling set_score '.$mylpi->get_score(), 0); }
+        } else {
+            if ($debug > 1) { error_log("Score not updated"); }
+            
+            //Default behaviour
+            if (isset($status) && $status != '' && $status != 'undefined') {           
+                //Implements scorm 1.2 constraint
+                //If SCO_MasteryScore does not evaluate to a number, passed/failed status won't be set at all
+                //Score was not set 
+                //@todo remove the switch
+                switch ($status) {
+                    case 'failed':
+                    case 'passed':                        
+                        $mylpi->set_status($status);   
+                        //if ($debug > 1) { error_log("Cant't set status to these values only if a score was set"); }        
+                        break;
+                    default:                        
+                        if ($debug > 1) { error_log('Calling set_status('.$status.')', 0); }
+                        $mylpi->set_status($status);
+                        if ($debug > 1) { error_log('Done calling set_status: checking from memory:'.$mylpi->get_status(false), 0); }
+                        break;                        
+                }
+            } else {
+                if ($debug > 1) { error_log("Status not updated"); }
+            }
         }
+        
         // Hack to set status to completed for hotpotatoes if score > 80%.
         $my_type = $mylpi->get_type();
+        
         if ($my_type == 'hotpotatoes') {
             if ((empty($status) || $status == 'undefined' || $status == 'not attempted') && $max > 0) {
                 if (($score/$max) > 0.8) {
                     $mystatus = 'completed';
-                    if ($debug > 1) { error_log('Calling set_status('.$mystatus.') from xajax for hotpotatoes', 0); }
+                    if ($debug > 1) { error_log('Calling set_status('.$mystatus.') for hotpotatoes', 0); }
                     $mylpi->set_status($mystatus);
-                    if ($debug > 1) { error_log('Done calling set_status from xajax for hotpotatoes - now '.$mylpi->get_status(false), 0); }
+                    if ($debug > 1) { error_log('Done calling set_status for hotpotatoes - now '.$mylpi->get_status(false), 0); }
                 }
             } elseif ($status == 'completed' && $max > 0 && ($score/$max) < 0.8) {
                 $mystatus = 'failed';
-                if ($debug > 1) { error_log('Calling set_status('.$mystatus.') from xajax for hotpotatoes', 0); }
+                if ($debug > 1) { error_log('Calling set_status('.$mystatus.') for hotpotatoes', 0); }
                 $mylpi->set_status($mystatus);
-                if ($debug > 1) { error_log('Done calling set_status from xajax for hotpotatoes - now '.$mylpi->get_status(false), 0); }
+                if ($debug > 1) { error_log('Done calling set_status for hotpotatoes - now '.$mylpi->get_status(false), 0); }
             }
         }
+        
         if (isset($time) && $time!='' && $time!='undefined') {
             // If big integer, then it's a timestamp, otherwise it's normal scorm time.
-            if ($debug > 1) { error_log('Calling set_time('.$time.') from xajax', 0); }
+            if ($debug > 1) { error_log('Calling set_time('.$time.') ', 0); }
             if ($time == intval(strval($time)) && $time > 1000000) {
-                $real_time = time() - $time;
-                //$real_time += $mylpi->get_total_time();
+                if ($debug > 1) { error_log("Time is INT"); }
+                $real_time = time() - $time;                
                 if ($debug > 1) { error_log('Calling $real_time '.$real_time.' ', 0); }
                 $mylpi->set_time($real_time, 'int');
             } else {
+                if ($debug > 1) { error_log("Time is in SCORM format"); }
                 if ($debug > 1) { error_log('Calling $time '.$time.' ', 0); }
-                $mylpi->set_time($time);
+                $mylpi->set_time($time, 'scorm');
             }
-            if ($debug > 1) { error_log('Done calling set_time from xajax - now '.$mylpi->get_total_time(), 0); }
+            //if ($debug > 1) { error_log('Done calling set_time - now '.$mylpi->get_total_time(), 0); }
         } else {
             $time = $mylpi->get_total_time();
         }
+        
         if (isset($suspend) && $suspend != '' && $suspend != 'undefined') {
             $mylpi->current_data = $suspend; //escapetxt($suspend);
         }
+        
         if (isset($location) && $location != '' && $location!='undefined') {
             $mylpi->set_lesson_location($location);
         }
+        
         // Deal with interactions provided in arrays in the following format:
         // id(0), type(1), time(2), weighting(3), correct_responses(4), student_response(5), result(6), latency(7)
         if (is_array($interactions) && count($interactions) > 0) {
@@ -141,16 +175,19 @@ function save_item($lp_id, $user_id, $view_id, $item_id, $score = -1, $max = -1,
                 $mylpi->add_interaction($index, $clean_interaction);
             }
         }
+        
         if ($core_exit != 'undefined') {
             $mylpi->set_core_exit($core_exit);
         }
+        
         $mylp->save_item($item_id, false);
-    } else {
-        //return $objResponse;
+    } else {        
         return $return;
     }
     
     $mystatus_in_db = $mylpi->get_status(true);
+    error_log("Status in DB: $mystatus_in_db");
+    
     if ($mystatus_in_db != 'completed' && $mystatus_in_db != 'passed' && $mystatus_in_db != 'browsed' && $mystatus_in_db != 'failed') {
          $mystatus_in_memory = $mylpi->get_status(false);
          if ($mystatus_in_memory != $mystatus_in_db) {
@@ -161,48 +198,49 @@ function save_item($lp_id, $user_id, $view_id, $item_id, $score = -1, $max = -1,
     } else {
         $mystatus = $mystatus_in_db;
     }
+    
     $mytotal = $mylp->get_total_items_count_without_chapters();
     $mycomplete = $mylp->get_complete_items_count();    
     $myprogress_mode = $mylp->get_progress_bar_mode();
-    $myprogress_mode = ($myprogress_mode == '' ? '%' : $myprogress_mode);
-    if ($debug > 1) { error_log("myprogress_mode $myprogress_mode", 0); }
-    if ($debug > 1) { error_log("mytotal $mytotal", 0); }
-    if ($debug > 1) { error_log("mycomplete $mycomplete", 0); }
-    //$mylpi->write_to_db();
+    $myprogress_mode = $myprogress_mode == '' ? '%' : $myprogress_mode;
+    
+    if ($debug > 1) { error_log("mystatus: $mystatus", 0); }
+    if ($debug > 1) { error_log("myprogress_mode: $myprogress_mode", 0); }
+    if ($debug > 1) { error_log("mytotal: $mytotal", 0); }
+    if ($debug > 1) { error_log("mycomplete: $mycomplete", 0); }
+    
+    
     $_SESSION['lpobject'] = serialize($mylp);
     if ($mylpi->get_type() != 'sco') {
-        // If this object's JS status has not been updated by the SCORM API, update now.
-        //$objResponse->addScript("lesson_status='".$mystatus."';");
+        // If this object's JS status has not been updated by the SCORM API, update now.        
         $return .= "olms.lesson_status='".$mystatus."';";
-    }
-    //$objResponse->addScript("update_toc('".$mystatus."','".$item_id."');");
+    }    
     $return .= "update_toc('".$mystatus."','".$item_id."');";
     $update_list = $mylp->get_update_queue();
     foreach ($update_list as $my_upd_id => $my_upd_status)  {
-        if ($my_upd_id != $item_id){ // Only update the status from other items (i.e. parents and brothers), do not update current as we just did it already.
-            //$objResponse->addScript("update_toc('".$my_upd_status."','".$my_upd_id."');");
+        if ($my_upd_id != $item_id) { // Only update the status from other items (i.e. parents and brothers), do not update current as we just did it already.            
             $return .= "update_toc('".$my_upd_status."','".$my_upd_id."');";
         }
-    }
-    //$objResponse->addScript("update_progress_bar('$mycomplete','$mytotal','$myprogress_mode');");
+    }    
     $return .= "update_progress_bar('$mycomplete','$mytotal','$myprogress_mode');";
 
-    if ($debug > 0) {
-        //$objResponse->addScript("logit_lms('Saved data for item ".$item_id.", user ".$user_id." (status=".$mystatus.")',2);");
+    if ($debug > 0) {        
         $return .= "logit_lms('Saved data for item ".$item_id.", user ".$user_id." (status=".$mystatus.")',2);";
         if ($debug > 1) { error_log('End of save_item()', 0); }
     }
 
     if (!isset($_SESSION['login_as'])) {
         // If $_SESSION['login_as'] is set, then the user is an admin logged as the user.
-
         $tbl_track_login = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_LOGIN);
 
-        $sql_last_connection = "SELECT login_id, login_date FROM $tbl_track_login WHERE login_user_id='".api_get_user_id()."' ORDER BY login_date DESC LIMIT 0,1";
+        $sql_last_connection = "SELECT login_id, login_date
+            FROM $tbl_track_login 
+            WHERE login_user_id='".api_get_user_id()."' 
+            ORDER BY login_date DESC LIMIT 0,1";
 
         $q_last_connection = Database::query($sql_last_connection);
         if (Database::num_rows($q_last_connection) > 0) {
-            $current_time = date('Y-m-d H:i:s');
+            $current_time = api_get_utc_datetime();
             $row = Database::fetch_array($q_last_connection);
             $i_id_last_connection = $row['login_id'];
             $s_sql_update_logout_date = "UPDATE $tbl_track_login SET logout_date='".$current_time."' WHERE login_id='$i_id_last_connection'";
@@ -210,14 +248,16 @@ function save_item($lp_id, $user_id, $view_id, $item_id, $score = -1, $max = -1,
         }
     }
 
-   if ($mylp->get_type() == 2) {
-           $return .= "update_stats();";
-   }
+    if ($mylp->get_type() == 2) {
+         $return .= "update_stats();";
+    }
     //To be sure progress is updated
     $mylp->save_last();
-    return $return;
-    //return $objResponse;
+    
+   if ($debug > 0) { error_log('lp_ajax_save_item.php : save_item end ----- '); }   
+    return $return;    
 }
+
 $interactions = array();
 if (isset($_REQUEST['interact'])) {
     if (is_array($_REQUEST['interact'])) {
@@ -231,16 +271,16 @@ if (isset($_REQUEST['interact'])) {
 }
 
 echo save_item(
-            $_REQUEST['lid'],
-            $_REQUEST['uid'],
-            $_REQUEST['vid'],
-            $_REQUEST['iid'],
-            $_REQUEST['s'],
-            $_REQUEST['max'],
-            $_REQUEST['min'],
-            $_REQUEST['status'],
-            $_REQUEST['t'],
-            $_REQUEST['suspend'],
-            $_REQUEST['loc'],
+            (!empty($_REQUEST['lid'])?$_REQUEST['lid']:null),
+            (!empty($_REQUEST['uid'])?$_REQUEST['uid']:null),
+            (!empty($_REQUEST['vid'])?$_REQUEST['vid']:null),
+            (!empty($_REQUEST['iid'])?$_REQUEST['iid']:null),
+            (!empty($_REQUEST['s'])?$_REQUEST['s']:null),
+            (!empty($_REQUEST['max'])?$_REQUEST['max']:null),
+            (!empty($_REQUEST['min'])?$_REQUEST['min']:null),
+            (!empty($_REQUEST['status'])?$_REQUEST['status']:null),
+            (!empty($_REQUEST['t'])?$_REQUEST['t']:null),
+            (!empty($_REQUEST['suspend'])?$_REQUEST['suspend']:null),
+            (!empty($_REQUEST['loc'])?$_REQUEST['loc']:null),
             $interactions,
-            $_REQUEST['core_exit']);
+            (!empty($_REQUEST['core_exit'])?$_REQUEST['core_exit']:''));

+ 3 - 3
main/newscorm/lp_ajax_save_objectives.php

@@ -40,16 +40,16 @@ function save_objectives($lp_id, $user_id, $view_id, $item_id, $objectives = arr
     require_once 'aiccItem.class.php';
     $mylp = '';
     if (isset($_SESSION['lpobject'])) {
-        if ($debug > 1) { error_log('////$_SESSION[lpobject] is set', 0); }
+        if ($debug > 1) { error_log('$_SESSION[lpobject] is set', 0); }
         $oLP =unserialize($_SESSION['lpobject']);
         if (!is_object($oLP)) {
             if ($debug > 2) { error_log(print_r($oLP,true), 0); }
-            if ($debug > 2) { error_log('////Building new lp', 0); }
+            if ($debug > 2) { error_log('Building new lp', 0); }
             unset($oLP);
             $code = api_get_course_id();
             $mylp = new learnpath($code, $lp_id, $user_id);
         }else{
-            if ($debug > 2) { error_log('////Reusing session lp', 0); }
+            if ($debug > 2) { error_log('Reusing session lp', 0); }
             $mylp = & $oLP;
         }
     }

+ 3 - 3
main/newscorm/lp_ajax_switch_item.php

@@ -47,16 +47,16 @@ function switch_item_details($lp_id, $user_id, $view_id, $current_item, $next_it
     require_once 'aiccItem.class.php';
     $mylp = '';
     if (isset($_SESSION['lpobject'])) {
-        if ($debug > 1) { error_log('////$_SESSION[lpobject] is set', 0); }
+        if ($debug > 1) { error_log('$_SESSION[lpobject] is set', 0); }
         $oLP = unserialize($_SESSION['lpobject']);
         if (!is_object($oLP)) {
             if ($debug > 1) { error_log(print_r($oLP,true), 0); }
-            if ($debug > 2) { error_log('////Building new lp', 0); }
+            if ($debug > 2) { error_log('Building new lp', 0); }
             unset($oLP);
             $code = api_get_course_id();
             $mylp = new learnpath($code,$lp_id,$user_id);
         } else {
-            if ($debug > 1) { error_log('////Reusing session lp', 0); }
+            if ($debug > 1) { error_log('Reusing session lp', 0); }
             $mylp = & $oLP;
         }
     }

+ 3 - 3
main/newscorm/lp_ajax_switch_item_toc.php

@@ -38,16 +38,16 @@ function switch_item_toc($lp_id, $user_id, $view_id, $current_item, $next_item)
     require_once 'aiccItem.class.php';
     $mylp = '';
     if (isset($_SESSION['lpobject'])) {
-        if ($debug > 1) { error_log('////$_SESSION[lpobject] is set', 0); }
+        if ($debug > 1) { error_log('$_SESSION[lpobject] is set', 0); }
         $oLP = unserialize($_SESSION['lpobject']);
         if (!is_object($oLP)) {
             if ($debug > 1) { error_log(print_r($oLP, true), 0); }
-            if ($debug > 2) { error_log('////Building new lp', 0); }
+            if ($debug > 2) { error_log('Building new lp', 0); }
             unset($oLP);
             $code = api_get_course_id();
             $mylp = new learnpath($code,$lp_id,$user_id);
         } else {
-            if ($debug > 1) { error_log('////Reusing session lp', 0); }
+            if ($debug > 1) { error_log('Reusing session lp', 0); }
             $mylp = & $oLP;
         }
     }

+ 9 - 9
main/newscorm/lp_comm.server.php

@@ -75,16 +75,16 @@ function save_item($lp_id, $user_id, $view_id, $item_id, $score = -1, $max = -1,
     require_once 'aiccItem.class.php';
     $mylp = '';
     if (isset($_SESSION['lpobject'])) {
-        if ($debug > 1) { error_log('////$_SESSION[lpobject] is set', 0); }
+        if ($debug > 1) { error_log('$_SESSION[lpobject] is set', 0); }
         $oLP = unserialize($_SESSION['lpobject']);
         if (!is_object($oLP)) {
             if ($debug > 2) { error_log(print_r($oLP, true), 0); }
-            if ($debug > 2) { error_log('////Building new lp', 0); }
+            if ($debug > 2) { error_log('Building new lp', 0); }
             unset($oLP);
             $code = api_get_course_id();
             $mylp = new learnpath($code, $lp_id, $user_id);
         } else {
-            if ($debug > 2) { error_log('////Reusing session lp', 0); }
+            if ($debug > 2) { error_log('Reusing session lp', 0); }
             $mylp = & $oLP;
         }
     }
@@ -207,16 +207,16 @@ function save_objectives($lp_id, $user_id, $view_id, $item_id, $objectives = arr
     require_once 'aiccItem.class.php';
     $mylp = '';
     if (isset($_SESSION['lpobject'])) {
-        if ($debug > 1) { error_log('////$_SESSION[lpobject] is set', 0); }
+        if ($debug > 1) { error_log('$_SESSION[lpobject] is set', 0); }
         $oLP = unserialize($_SESSION['lpobject']);
         if (!is_object($oLP)) {
             if ($debug > 2) { error_log(print_r($oLP, true), 0); }
-            if ($debug > 2) { error_log('////Building new lp', 0); }
+            if ($debug > 2) { error_log('Building new lp', 0); }
             unset($oLP);
             $code = api_get_course_id();
             $mylp = new learnpath($code,$lp_id,$user_id);
         } else {
-            if ($debug > 2) { error_log('////Reusing session lp', 0); }
+            if ($debug > 2) { error_log('Reusing session lp', 0); }
             $mylp = & $oLP;
         }
     }
@@ -261,16 +261,16 @@ function switch_item_details($lp_id, $user_id, $view_id, $current_item, $next_it
     require_once 'aiccItem.class.php';
     $mylp = '';
     if (isset($_SESSION['lpobject'])) {
-        if ($debug > 1) { error_log('////$_SESSION[lpobject] is set', 0); }
+        if ($debug > 1) { error_log('$_SESSION[lpobject] is set', 0); }
         $oLP = unserialize($_SESSION['lpobject']);
         if (!is_object($oLP)) {
             if ($debug > 1) { error_log(print_r($oLP, true), 0); }
-            if ($debug > 2) { error_log('////Building new lp', 0); }
+            if ($debug > 2) { error_log('Building new lp', 0); }
             unset($oLP);
             $code = api_get_course_id();
             $mylp = new learnpath($code,$lp_id,$user_id);
         } else {
-            if ($debug > 1) { error_log('////Reusing session lp', 0); }
+            if ($debug > 1) { error_log('Reusing session lp', 0); }
             $mylp = & $oLP;
         }
     }

+ 5 - 3
main/newscorm/lp_controller.php

@@ -122,8 +122,8 @@ if (isset($_SESSION['lpobject'])) {
     $oLP = unserialize($_SESSION['lpobject']);
     if (isset($oLP) && is_object($oLP)) {
         if ($debug > 0) error_log('New LP - oLP is object', 0);
-        if ($myrefresh == 1 OR (empty($oLP->cc)) OR $oLP->cc != api_get_course_id() OR $oLP->lp_view_session_id != $session_id OR $oLP->scorm_debug == '1') {
-            if ($debug > 0) error_log('New LP - Course has changed, discard lp object', 0);
+        if ($myrefresh == 1 OR empty($oLP->cc) OR $oLP->cc != api_get_course_id() OR $oLP->lp_view_session_id != $session_id OR $oLP->scorm_debug == '1') {
+            if ($debug > 0) error_log('New LP - Course has changed, discard lp object', 0);     
             if ($myrefresh == 1) { $myrefresh_id = $oLP->get_id(); }
             $oLP = null;
             Session::erase('oLP');
@@ -135,6 +135,7 @@ if (isset($_SESSION['lpobject'])) {
     }
 }
 
+
 $course_id = api_get_course_int_id();
 
 if ($debug>0) error_log('New LP - Passed data remains check', 0);
@@ -820,9 +821,10 @@ switch ($action) {
         break;
 
     case 'stats':
+        
         if ($debug > 0) error_log('New LP - stats action triggered', 0);
         if (!$lp_found) { error_log('New LP - No learnpath given for stats', 0); require 'lp_list.php'; }
-        else {
+        else {            
             $_SESSION['oLP']->save_current();
             $_SESSION['oLP']->save_last();                   
             require 'lp_stats.php';

+ 6 - 6
main/newscorm/lp_list.php

@@ -9,7 +9,7 @@
 * @package chamilo.learnpath
 * @author Yannick Warnier <ywarnier@beeznest.org>
 */
-//use \ChamiloSession as Session;
+use \ChamiloSession as Session;
 
 $this_section = SECTION_COURSES;
 //@todo who turns on $lp_controller_touched?
@@ -487,7 +487,7 @@ if (!empty($flat_list)) {
         echo "</tr>";
         $current ++; //counter for number of elements treated
     } // end foreach ($flat_list)
-    // TODO: Erint some user-friendly message if counter is still = 0 to tell nothing can be displayd yet.
+    // TODO: Erint some user-friendly message if counter is still = 0 to tell nothing can be display yet.
     echo "</table>";
 } else {
     if ($is_allowed_to_edit) {
@@ -501,9 +501,9 @@ if (!empty($flat_list)) {
     }
 }
 $course_info = api_get_course_info();
-$result = learnpath::generate_learning_path_folder($course_info);
+learnpath::generate_learning_path_folder($course_info);
 
 //Deleting the objects
-//Session::erase('oLP');
-//Session::erase('lpobject');
-Display::display_footer();
+Session::erase('oLP');
+Session::erase('lpobject');
+Display::display_footer();

+ 64 - 30
main/newscorm/lp_stats.php

@@ -23,8 +23,12 @@ if (empty($user_id)) {
 
 // Declare variables to be used in lp_stats.php
 //When checking the reporting myspace/lp_tracking.php
-if (isset($_GET['lp_id']) && isset($lp_id) && !empty($lp_id)) {
+//isset($_GET['lp_id']) &&
+if (isset($lp_id) && !empty($lp_id)) {
     $lp_id = intval($lp_id);
+    if (!isset($list)) {
+        $list = learnpath::get_flat_ordered_items_list($lp_id);
+    }
 } else {
     if (isset($_SESSION['oLP'])) {
         $lp_id = $_SESSION['oLP']->get_id();
@@ -259,7 +263,8 @@ if (is_array($list) && count($list) > 0) {
             }
             $extend_link = '';
             if (!empty($inter_num)) {
-                $extend_link = '<a href="' . api_get_self() . '?action=stats&fold_id=' . $my_item_id . $url_suffix . '"><img src="../img/visible.gif" alt="' . get_lang('HideAttemptView') . '" title="' . get_lang('HideAttemptView') . '"  border="0"></a>' . "\n";
+                $extend_link = '<a href="' . api_get_self() . '?action=stats&fold_id=' . $my_item_id . $url_suffix . '">
+                                <img src="../img/visible.gif" alt="' . get_lang('HideAttemptView') . '" title="' . get_lang('HideAttemptView') . '"  border="0"></a>';
             }
             $title = $row['mytitle'];
 
@@ -269,7 +274,7 @@ if (is_array($list) && count($list) > 0) {
 
             if ($row['item_type'] != 'dokeos_chapter') {
                 $correct_test_link = '-';
-                $title = Security::remove_XSS($title);
+                $title = Security::remove_XSS($title);                
                 $output .= '<tr class="'.$oddclass.'">
                                 <td>'.$extend_link.'</td>
                                 <td colspan="4">
@@ -639,18 +644,33 @@ if (is_array($list) && count($list) > 0) {
 
                     if ($origin != 'tracking' && $origin != 'tracking_course') {
                         $my_url_suffix = '&course=' . api_get_course_id() . '&student_id=' . api_get_user_id() . '&lp_id=' . Security::remove_XSS($row['mylpid']);
-                        $sql_last_attempt = 'SELECT * FROM ' . $tbl_stats_exercices . ' WHERE exe_exo_id="' . $row['path'] . '" AND exe_user_id="' . api_get_user_id() . '" AND orig_lp_id = "' . $lp_id . '" AND orig_lp_item_id = "' . $row['myid'] . '" AND exe_cours_id="' . $course_code . '" AND status <> "incomplete" AND session_id = ' . $session_id . ' ORDER BY exe_date DESC ';
+                        $sql_last_attempt = 'SELECT * FROM ' . $tbl_stats_exercices . ' 
+                                             WHERE  exe_exo_id="' . $row['path'] . '" AND 
+                                                    exe_user_id="' . api_get_user_id() . '" AND 
+                                                    orig_lp_id = "' . $lp_id . '" AND 
+                                                    orig_lp_item_id = "' . $row['myid'] . '" AND 
+                                                    exe_cours_id="' . $course_code . '" AND 
+                                                    status <> "incomplete" AND 
+                                                    session_id = ' . $session_id . ' 
+                                            ORDER BY exe_date DESC ';
                     } else {
                         $my_url_suffix = '&course=' . Security::remove_XSS($_GET['course']) . '&student_id=' . $student_id . '&lp_id=' . Security::remove_XSS($row['mylpid']) . '&origin=' . Security::remove_XSS($_GET['origin'] . $from_link);
-                        $sql_last_attempt = 'SELECT * FROM ' . $tbl_stats_exercices . ' WHERE exe_exo_id="' . $row['path'] . '" AND exe_user_id="' . $student_id . '" AND orig_lp_id = "' . $lp_id . '" AND orig_lp_item_id = "' . $row['myid'] . '" AND exe_cours_id="' . Database :: escape_string($_GET['course']) . '" AND status <> "incomplete" AND session_id = ' . $session_id . '  ORDER BY exe_date DESC ';
+                        $sql_last_attempt = 'SELECT * FROM ' . $tbl_stats_exercices . ' 
+                                             WHERE   exe_exo_id="' . $row['path'] . '" AND 
+                                                    exe_user_id="' . $student_id . '" AND 
+                                                    orig_lp_id = "' . $lp_id . '" AND 
+                                                    orig_lp_item_id = "' . $row['myid'] . '" AND 
+                                                    exe_cours_id="' . Database :: escape_string($_GET['course']) . '" AND 
+                                                    status <> "incomplete" AND 
+                                                    session_id = ' . $session_id . '  
+                                             ORDER BY exe_date DESC ';
                     }
 
                     $resultLastAttempt = Database::query($sql_last_attempt);
                     $num = Database :: num_rows($resultLastAttempt);
                     if ($num > 0) {
                         if (isset($_GET['extend_attempt']) && $_GET['extend_attempt'] == 1 && (isset($_GET['lp_id']) && $_GET['lp_id'] == $my_lp_id) && (isset($_GET['lp_item_id']) && $_GET['lp_item_id'] == $my_id)) {
-                            $correct_test_link = '<a href="' . api_get_self() . '?action=stats' . $my_url_suffix . '&session_id=' . api_get_session_id() . '&lp_item_id=' . $my_id . '"><img src="../img/view_less_stats.gif" alt="fold_view" border="0" title="' . get_lang('HideAllAttempts') . '"></a>';
-                            $extend_attempt = 1;
+                            $correct_test_link = '<a href="' . api_get_self() . '?action=stats' . $my_url_suffix . '&session_id=' . api_get_session_id() . '&lp_item_id=' . $my_id . '"><img src="../img/view_less_stats.gif" alt="fold_view" border="0" title="' . get_lang('HideAllAttempts') . '"></a>';                            
                         } else {
                             $correct_test_link = '<a href="' . api_get_self() . '?action=stats&extend_attempt=1' . $my_url_suffix . '&session_id=' . api_get_session_id() . '&lp_item_id=' . $my_id . '"><img src="../img/view_more_stats.gif" alt="extend_view" border="0" title="' . get_lang('ShowAllAttemptsByExercise') . '"></a>';
                         }
@@ -664,29 +684,48 @@ if (is_array($list) && count($list) > 0) {
                 $title = Security::remove_XSS($title);
 
                 if ((isset($_GET['lp_id']) && $_GET['lp_id'] == $my_lp_id && false)) {
-                    $output .= '<tr class=' . $oddclass . '><td>' . $extend_link . '</td><td colspan="4"><div class="mystatus">' . $title . '</div></td>';
-                    $output .= '<td colspan="2">&nbsp;</td><td colspan="2">&nbsp;</td><td colspan="2">&nbsp;</td><td>' . $correct_test_link . '</td></tr>';
-                    $output .= "</tr>";
+                    
+                    $output .= '<tr class =' . $oddclass . '>
+                                    <td>' . $extend_link . '</td>
+                                    <td colspan="4">' . $title . '</td>
+                                    <td colspan="2">&nbsp;</td>
+                                    <td colspan="2">&nbsp;</td>
+                                    <td colspan="2">&nbsp;</td>
+                                    <td>' . $correct_test_link . '</td>
+                                </tr>';
+                    $output .= '</tr>';
                 } else {
                     if ((isset($_GET['lp_id']) && $_GET['lp_id'] == $my_lp_id ) && (isset($_GET['lp_item_id']) && $_GET['lp_item_id'] == $my_id)) {
                         $output .= "<tr class='$oddclass'>";
                     } else {
                         $output .= "<tr class='$oddclass'>";
                     }
-                    $output .= '<td>' . $extend_link . '</td><td colspan="4"><div class="mystatus">' . $title . '</div></td>';
-                    $output .= '<td colspan="2">' . Display::label($my_lesson_status, $class_status) . "</td>" . '<td colspan="2"><div class="mystatus" align="center">';
+                    
+                    if (($is_allowed_to_edit || api_is_drh()) && isset($_GET['lp_id']) && isset($course_code)) {                        
+                        $lp = new learnpath($course_code, $_GET['lp_id'], api_get_user_id());                                         
+                        $lp->set_course_int_id($course_id);
+                        $item_path_url = $lp->get_link('http', $my_id, false);                    
+                        $item_path_url .= "&width=600";
+                        $title = Display::url($title, $item_path_url, array('class' => 'ajax'));
+                    }
+                    
+                    $output .= '<td>'.$extend_link.'</td>
+                                <td colspan="4">' . $title . '</td>
+                                <td colspan="2">' . Display::label($my_lesson_status, $class_status) .'</td>
+                                <td colspan="2">';
                     if ($row['item_type'] == 'quiz') {
                         if (!$is_allowed_to_edit && $result_disabled_ext_all) {
                             $output .= Display::return_icon('invisible.gif', get_lang('ResultsHiddenByExerciseSetting'));
-                        } else {
-                            //   $output .= ($score == 0 ? '0/'.float_format($maxscore, 1) : ($maxscore == 0 ? $score : float_format($score, 1) . '/' . float_format($maxscore, 1)));
+                        } else {                            
                             $output .= show_score($score, $maxscore, false);
                         }
                     } else {
                         $output .= ($score == 0 ? '/' : ($maxscore == 0 ? $score : $score . '/' . $maxscore));
                     }
-                    $output .= '</div></td><td colspan="2"><div class="mystatus">' . $time .'</div></td><td>'.$correct_test_link.'</td>';
-                    $output .= "</tr>";
+                    $output .= '</td>
+                                <td colspan="2">'.$time.'</td>
+                                 <td>'.$correct_test_link.'</td>';
+                    $output .= '</tr>';
                 }
 
                 if (!empty($export_csv)) {
@@ -784,21 +823,16 @@ if (is_array($list) && count($list) > 0) {
                             if (!$is_allowed_to_edit && $result_disabled_ext_all) {
                                 $view_score = Display::return_icon('invisible.gif', get_lang('ResultsHiddenByExerciseSetting'));
                             } else {
-                                // Show only float when need it.
-                                //$my_score  = float_format( $my_score, 1);
-                                //$my_maxscore =float_format($my_maxscore, 1);
-                                if ($my_score == 0) {
-                                    //$view_score = 	'0/'.$my_maxscore;
+                                // Show only float when need it                                
+                                if ($my_score == 0) {                                    
                                     $view_score = show_score(0, $my_maxscore, false);
                                 } else {
                                     if ($my_maxscore == 0) {
                                         $view_score = $my_score;
-                                    } else {
-                                        //$view_score = $my_score . '/' . $my_maxscore;
+                                    } else {                                        
                                         $view_score = show_score($my_score, $my_maxscore, false);
                                     }
-                                }
-                                //$view_score = ($my_score == 0 ? '0.00/'.$my_maxscore : ($my_maxscore == 0 ? $my_score : $my_score . '/' . $my_maxscore));
+                                }                                
                             }
                             $my_lesson_status = $row_attempts['status'];
 
@@ -824,14 +858,14 @@ if (is_array($list) && count($list) > 0) {
                                     $output .= '<td><img src="' . api_get_path(WEB_IMG_PATH) . 'quiz_na.gif" alt="' . get_lang('ShowAttempt') . '" title="' . get_lang('ShowAttempt') . '"></td>';
                                 } else {
                                     $output .= '<td><a href="../exercice/exercise_show.php?origin=' . $origin . '&id=' . $my_exe_id . '&cidReq=' . $course_code . $from_link . '" target="_parent">
-                                        <img src="' . api_get_path(WEB_IMG_PATH) . 'quiz.gif" alt="' . get_lang('ShowAttempt') . '" title="' . get_lang('ShowAttempt') . '"></a></td>';
+                                                    <img src="' . api_get_path(WEB_IMG_PATH) . 'quiz.gif" alt="' . get_lang('ShowAttempt') . '" title="' . get_lang('ShowAttempt') . '"></a></td>';
                                 }
                             } else {
                                 if (!$is_allowed_to_edit && $result_disabled_ext_all) {
                                     $output .= '<td><img src="' . api_get_path(WEB_IMG_PATH) . 'quiz_na.gif" alt="' . get_lang('ShowAndQualifyAttempt') . '" title="' . get_lang('ShowAndQualifyAttempt') . '"></td>';
                                 } else {
                                     $output .= '<td><a href="../exercice/exercise_show.php?cidReq=' . $course_code . '&origin=correct_exercise_in_lp&id=' . $my_exe_id . '" target="_parent">
-                                        <img src="' . api_get_path(WEB_IMG_PATH) . 'quiz.gif" alt="' . get_lang('ShowAndQualifyAttempt') . '" title="' . get_lang('ShowAndQualifyAttempt') . '"></a></td>';
+                                                     <img src="' . api_get_path(WEB_IMG_PATH) . 'quiz.gif" alt="' . get_lang('ShowAndQualifyAttempt') . '" title="' . get_lang('ShowAndQualifyAttempt') . '"></a></td>';
                                 }
                             }
                             $output .= '</tr>';
@@ -910,13 +944,13 @@ if (($counter % 2) == 0) {
 $output .= '<tr class="'.$oddclass.'">
                 <td></td>
                 <td colspan="4">
-                    <div class="mystatus"><i>' . get_lang('AccomplishedStepsTotal') .'</i></div>
+                    <i>' . get_lang('AccomplishedStepsTotal') .'</i>
                 </td>
                 <td colspan="2"></td>
                 <td colspan="2">
-                    <div class="mystatus" align="center">' . $final_score.'</div>
+                    ' . $final_score.'
                 </td>
-                <td colspan="2"><div class="mystatus">' . $total_time . '</div></td><td></td>
+                <td colspan="2">' . $total_time . '</div><td></td>
            </tr>';
 //}
 

+ 2 - 3
main/newscorm/lp_view.php

@@ -142,7 +142,7 @@ foreach ($get_toc_list as $toc) {
 }
 
 if (!isset($src)) {
-    $src = '';
+    $src = null;
     switch ($lp_type) {
         case 1:
             $_SESSION['oLP']->stop_previous_item();
@@ -154,8 +154,7 @@ if (!isset($src)) {
                 //Prevents FF 3.6 + Adobe Reader 9 bug see BT#794 when calling a pdf file in a LP.
                 $file_info = parse_url($src);
                 $file_info = pathinfo($file_info['path']);
-                if (api_strtolower(substr($file_info['extension'], 0, 3) == 'pdf')) {
-                    //$src = api_get_path(WEB_CODE_PATH).'newscorm/lp_view_item.php?src='.$src;
+                if (api_strtolower(substr($file_info['extension'], 0, 3) == 'pdf')) {                    
                     $src = api_get_path(WEB_CODE_PATH).'newscorm/lp_view_item.php?lp_item_id='.$lp_item_id;
                 }
                 $_SESSION['oLP']->start_current_item(); // starts time counter manually if asset

+ 7 - 5
main/newscorm/resourcelinker.inc.php

@@ -1608,14 +1608,16 @@ function rl_get_html_resource_link($course_code, $type, $id, $style='', $new_win
  * @param id          - that is the correspondent id in the mirror tool (like Agenda item 2)
  * @param id_in_path  - the unique index in the items table
  */
-function rl_get_resource_link_for_learnpath($course_code, $learnpath_id, $id_in_path) {
-    $_course 		= Database::get_course_info($course_code);
+function rl_get_resource_link_for_learnpath($course_id, $learnpath_id, $id_in_path) {
     $tbl_lp_item 	= Database::get_course_table(TABLE_LP_ITEM);
+    
+    $course_info = api_get_course_info_by_id($course_id);    
+    $course_id = $course_info['real_id'];
+    $course_code = $course_info['code'];
+    
     $learnpath_id 	= intval($learnpath_id);
     $id_in_path		= intval($id_in_path);
     
-    $course_id = $_course['real_id'];
-    
     $sql_item = "SELECT * FROM $tbl_lp_item WHERE c_id = $course_id AND lp_id = $learnpath_id AND id = $id_in_path";
     $res_item = Database::query($sql_item);
     if (Database::num_rows($res_item) < 1) return -1; //exit
@@ -1625,7 +1627,7 @@ function rl_get_resource_link_for_learnpath($course_code, $learnpath_id, $id_in_
     $id = (strcmp($row_item['path'], '') == 0) ? '0' : $row_item['path'];
     $origin = 'learnpath';
     $main_dir_path = api_get_path(WEB_CODE_PATH);
-    $main_course_path = api_get_path(WEB_COURSE_PATH).$_course['directory'].'/';
+    $main_course_path = api_get_path(WEB_COURSE_PATH).$course_info['directory'].'/';
 
     $link = '';
 

+ 147 - 153
main/newscorm/scorm_api.php

@@ -34,11 +34,9 @@ require_once 'learnpath.class.php';
 require_once 'learnpathItem.class.php';
 require_once 'scorm.class.php';
 
-// Is this needed? This is probabaly done in the header file
-//$_user							= $_SESSION['_user'];
-$file							= (empty($_SESSION['file'])?'':$_SESSION['file']);
-$oLP							= unserialize($_SESSION['lpobject']);
-$oItem 							= $oLP->items[$oLP->current];
+$file   = (empty($_SESSION['file'])?'':$_SESSION['file']);
+$oLP    = unserialize($_SESSION['lpobject']);
+$oItem 	= $oLP->items[$oLP->current];
 
 if (!is_object($oItem)) {
     error_log('New LP - scorm_api - Could not load oItem item',0);
@@ -56,25 +54,25 @@ var lms_logs=0; //debug log level for LMS actions. 0=none, 1=light, 2=a lot, 3=a
 
 // API Object initialization (eases access later on)
 function APIobject() {
-  this.LMSInitialize=LMSInitialize;  //for Scorm 1.2
-  this.Initialize=LMSInitialize;     //for Scorm 1.3
-  this.LMSGetValue=LMSGetValue;
-  this.GetValue=LMSGetValue;
-  this.LMSSetValue=LMSSetValue;
-  this.SetValue=LMSSetValue;
-  this.LMSCommit=LMSCommit;
-  this.Commit=LMSCommit;
-  this.LMSFinish=LMSFinish;
-  this.Finish=LMSFinish;
-  this.LMSGetLastError=LMSGetLastError;
-  this.GetLastError=LMSGetLastError;
-  this.LMSGetErrorString=LMSGetErrorString;
-  this.GetErrorString=LMSGetErrorString;
-  this.LMSGetDiagnostic=LMSGetDiagnostic;
-  this.GetDiagnostic=LMSGetDiagnostic;
-  this.Terminate=Terminate;  //only in Scorm 1.3
-  this.save_asset = lms_save_asset;
-  this.void_save_asset = chamilo_void_save_asset;
+    this.LMSInitialize=LMSInitialize;  //for Scorm 1.2
+    this.Initialize=LMSInitialize;     //for Scorm 1.3
+    this.LMSGetValue=LMSGetValue;
+    this.GetValue=LMSGetValue;
+    this.LMSSetValue=LMSSetValue;
+    this.SetValue=LMSSetValue;
+    this.LMSCommit=LMSCommit;
+    this.Commit=LMSCommit;
+    this.LMSFinish=LMSFinish;
+    this.Finish=LMSFinish;
+    this.LMSGetLastError=LMSGetLastError;
+    this.GetLastError=LMSGetLastError;
+    this.LMSGetErrorString=LMSGetErrorString;
+    this.GetErrorString=LMSGetErrorString;
+    this.LMSGetDiagnostic=LMSGetDiagnostic;
+    this.GetDiagnostic=LMSGetDiagnostic;
+    this.Terminate=Terminate;  //only in Scorm 1.3
+    this.save_asset = lms_save_asset;
+    this.void_save_asset = chamilo_void_save_asset;
 }
 
 // it is not sure that the scos use the above declarations. The following
@@ -200,7 +198,6 @@ olms.userlname = '<?php echo str_replace("'","\\'",$user['lastname']); ?>';
 
 olms.execute_stats = false;
 
-
 // Initialize stuff when the page is loaded
 $(document).ready( function() {
 
@@ -216,12 +213,13 @@ $(document).ready( function() {
             frames['content_name'].document.body.style.margin="0 12px 0px 5px";
         } catch (ex) { }
     }*/
+    
     olms.info_lms_item[0]=olms.info_lms_item[1];
 
     if (olms.lms_item_types['i'+olms.info_lms_item[1]] != 'sco') {
-      LMSInitialize();
+        LMSInitialize();
     }
-  });
+    });
 });
 
 
@@ -230,10 +228,10 @@ $(document).ready( function() {
  */
 /**
  * Function called mandatorily by the SCORM content to start the SCORM comm
- * @return  string  'true' or 'false'. Returning a string is mandatory (SCORM).
+ * This is the initialize function of all APIobjects
+ * @return  string  'true' or 'false'. Returning a string is mandatory (SCORM).  
  */
-function LMSInitialize() {  //this is the initialize function of all APIobjects
-
+function LMSInitialize() {
     /* load info for this new item by calling the js_api_refresh command in
      * the message frame. The message frame will update the JS variables by
      * itself, in JS, by doing things like top.lesson_status = 'not attempted'
@@ -243,8 +241,6 @@ function LMSInitialize() {  //this is the initialize function of all APIobjects
     olms.G_LastError = G_NoError ;
     olms.G_LastErrorMessage = 'No error';
 
-
-
     olms.lms_initialized=0;
     // if there are more parameters than ""
     if (arguments.length>1) {
@@ -305,10 +301,10 @@ function LMSInitialize() {  //this is the initialize function of all APIobjects
 
 /**
  * Twin sister of LMSInitialize(). Only provided for backwards compatibility.
+ * this is the initialize function of all APIobjects
  */
-function Initialize()
-{  //this is the initialize function of all APIobjects
-  return LMSInitialize();
+function Initialize() {    
+    return LMSInitialize();
 }
 
 /**
@@ -478,9 +474,7 @@ function LMSGetValue(param)
                 }else if(req_type == 'status'){
                     result = 'not attempted';
                 }
-            }
-            else
-            {
+           } else {
                 //the object is not null
                 if(req_type == 'id')
                 {
@@ -778,7 +772,7 @@ function LMSSetValue(param, val) {
                     }
                 }
             }
-        }else{
+        } else {
             olms.G_LastError = G_NotImplementedError;
             olms.G_LastErrorString = G_NotImplementedErrorMessage;
         }
@@ -796,23 +790,35 @@ function LMSSetValue(param, val) {
 function SetValue(param, val) {
     return LMSSetValue(param, val);
 }
+
 /**
  * Saves the current data from JS memory to the LMS database
  * @param   string  The origin of the call to save the data ('commit','finish', 'unload' or 'terminate')
  * @note    origin actually seems deprecated now
  */
 function savedata(origin) {
-    //origin can be 'commit', 'finish' or 'terminate' (depending on the calling function)
-    if ((olms.lesson_status != 'completed') && (olms.lesson_status != 'passed') && (olms.mastery_score >=0) && (olms.score >= olms.mastery_score)) {
-        olms.lesson_status = 'passed';
+    //origin can be 'commit', 'finish' or 'terminate' (depending on the calling function)    
+    
+   /* console.log('savedata');
+    console.log(olms.lesson_status);
+    console.log(olms.mastery_score);
+    console.log(olms.score);
+    */
+    
+    if (olms.lesson_status != '') {        
         olms.updatable_vars_list['cmi.core.lesson_status']=true;
+    }
+    
+    //If lesson_status is empty we left the status like that
+    if (olms.lesson_status != '' && olms.lesson_status != 'completed' && olms.lesson_status != 'passed' && olms.mastery_score >=0 && olms.score >= olms.mastery_score) {
+        //olms.lesson_status = 'passed';
+        //olms.updatable_vars_list['cmi.core.lesson_status']=true;
     } else if( (olms.mastery_score < 0) && (olms.lms_lp_type != '2') && ( olms.lesson_status == 'incomplete') && (olms.score >= (0.8*olms.max) ) ) {
         //the status cannot be modified automatically by the LMS under SCORM 1.2's rules
     <?php if ($autocomplete_when_80pct){ ?>
-              olms.lesson_status = 'completed';
-              olms.updatable_vars_list['cmi.core.lesson_status']=true;
-    <?php }?>
-    ;
+              //olms.lesson_status = 'completed';
+              //olms.updatable_vars_list['cmi.core.lesson_status']=true;
+    <?php } ?>    
     } else {
         /* DEPRECATED
          * See notes in switch_item for why this has been disabled
@@ -835,20 +841,18 @@ function savedata(origin) {
         }
         */
     }
-
+    //console.log(olms.lesson_status);
+    
     logit_lms('saving data (status='+olms.lesson_status+' - interactions: '+ olms.interactions.length +')',1);
 
     old_item_id=olms.info_lms_item[0];
 
-    xajax_save_item_scorm(olms.lms_lp_id, olms.lms_user_id, olms.lms_view_id, old_item_id);
-    //olms.info_lms_item[0] is old_item_id and olms.info_lms_item[1] is current_item_id
+    xajax_save_item_scorm(olms.lms_lp_id, olms.lms_user_id, olms.lms_view_id, old_item_id);    
     olms.info_lms_item[1]=olms.lms_item_id;
-
-    if(olms.item_objectives.length>0) {
+    if (olms.item_objectives.length>0) {
         xajax_save_objectives(olms.lms_lp_id,olms.lms_user_id,olms.lms_view_id,old_item_id,olms.item_objectives);
     }
     olms.execute_stats = false;
-
     //clean array
     olms.variable_to_send=new Array();
 }
@@ -1016,6 +1020,7 @@ function addEvent(elm, evType, fn, useCapture){
         elm['on'+evType] = fn;
     }
 }
+
 /**
  * Add listeners to the page objects. This has to be defined for
  * the current context as it acts on objects that should exist
@@ -1049,9 +1054,8 @@ function addListeners(){
  * Save a Chamilo learnpath item's time and mark as completed upon
  * leaving it
  */
-function lms_save_asset(){
+function lms_save_asset() {
     // only for Chamilo lps
-  
     if (olms.execute_stats) {    
         olms.execute_stats = false;
     } else {
@@ -1060,13 +1064,13 @@ function lms_save_asset(){
     
     //For scorms do not show stats
     if (olms.lms_lp_type == 2) {
-        olms.execute_stats = false;
+       olms.execute_stats = false;
     }
     
-    if (olms.lms_lp_type == 1 || olms.lms_item_type == 'asset'){
-        logit_lms('lms_save_asset', 2);
+    if (olms.lms_lp_type == 1 || olms.lms_item_type == 'asset') {
+        logit_lms('lms_save_asset', 2);        
         xajax_save_item(olms.lms_lp_id, olms.lms_user_id, olms.lms_view_id, olms.lms_item_id, olms.score, olms.max, olms.min, olms.lesson_status, olms.session_time, olms.suspend_data, olms.lesson_location,olms.interactions, olms.lms_item_core_exit);
-        if(olms.item_objectives.length>0) {
+        if (olms.item_objectives.length>0) {
             xajax_save_objectives(olms.lms_lp_id,olms.lms_user_id,olms.lms_view_id,olms.lms_item_id,olms.item_objectives);
         }
     }
@@ -1092,27 +1096,25 @@ function chamilo_void_save_asset(myscore,mymax)
  * @param	string	Message to log
  * @param	integer Priority (0 for top priority, 3 for lowest)
  */
-function logit_scorm(message,priority) {
-    //scorm_logs = 10000;
+function logit_scorm(message,priority) {    
     if (scorm_logs == 0) { return false; }
-    if (scorm_logs > priority) { 
+    if (scorm_logs > priority) {
         /* fixed see http://support.chamilo.org/issues/370 */
         if ($("#lp_log_name") && $("#log_content")){
             $("#log_content").append("SCORM: " + message + "<br/>");
         }
-        params = {
-            msg: "SCORM: " + message,
-            debug: scorm_logs
-        };
-        $.ajax({
-            type: "POST",
-            data: params,
-            url: "lp_ajax_log.php",
-            dataType: "script",
-            async: true
-        });
-        //console.log(message);
     }
+    params = {
+        msg: "SCORM: " + message,
+        debug: scorm_logs
+    };
+    $.ajax({
+        type: "POST",
+        data: params,
+        url: "lp_ajax_log.php",
+        dataType: "script",
+        async: true
+    });
 }
 
 /**
@@ -1122,11 +1124,12 @@ function logit_scorm(message,priority) {
  */
 function logit_lms(message, priority){
     if (lms_logs >= priority) {
-    if ($("#lp_log_name") && $("#log_content")) {
-        $("#log_content").append("LMS: " + message + "<br />");
-    }
+        if ($("#lp_log_name") && $("#log_content")) {
+            $("#log_content").append("LMS: " + message + "<br />");
+        }
+    }    
     params = {
-    msg: "LMS: " + message,
+        msg: "LMS: " + message,
         debug: lms_logs
     };
     $.ajax({
@@ -1135,8 +1138,7 @@ function logit_lms(message, priority){
         url: "lp_ajax_log.php",
         dataType: "script",
         async: true
-        });
-    }
+    });    
     //console.log(message);
 }
 
@@ -1146,86 +1148,81 @@ function logit_lms(message, priority){
  * @param	integer	Item id to update
  */
 function update_toc(update_action, update_id, change_ids) {
-        if (!change_ids || change_ids != 'no') {
-            change_ids = 'yes';
-        }        
-        var myelem = $("#toc_"+update_id);
-        var myelemimg = $("#toc_img_"+update_id);
-        logit_lms('update_toc("'+update_action+'",'+update_id+')',2);
-
-        if(update_id != 0)
-        {
-            switch(update_action)
-            {
-                case 'unhighlight':
-                    if (update_id%2==0)
-                    {
-                        myelem.attr('class',"scorm_item_2");
-                    }
-                    else
-                    {
-                        myelem.attr('class',"scorm_item_1");
-                    }
-                    break;
-                case 'highlight':
-                    if (change_ids=='yes') {
-                       olms.lms_next_item = update_id;
-                       olms.lms_previous_item = update_id;
-                    }
-                    myelem.attr('class',"scorm_item_highlight"); 
-                    break;
-                case 'not attempted':
-                    if( myelemimg.attr('src') != '../img/notattempted.gif') {
-                        myelemimg.attr('src','../img/notattempted.gif');
-                        myelemimg.attr('alt','n');
-                    }
-                    break;
-                case 'incomplete':
-                    if( myelemimg.attr('src') != '../img/incomplete.png') {
-                        myelemimg.attr('src','../img/incomplete.png');
-                        myelemimg.attr('alt','i');
-                    }
-                    break;
-                case 'completed':
-                    if( myelemimg.attr('src') != '../img/completed.png') {
-                        myelemimg.attr('src','../img/completed.png');
-                        myelemimg.attr('alt','c');
-                    }
-                    break;
-                case 'failed':
-                    if( myelemimg.attr('src') != '../img/delete.png') {
-                        myelemimg.attr('src','../img/delete.png');
-                        myelemimg.attr('alt','f');
-                    }
-                    break;
-                case 'passed':
-                    if( myelemimg.attr('src') != '../img/completed.png' && myelemimg.attr('alt') != 'passed') {
-                        myelemimg.attr('src','../img/completed.png');
-                        myelemimg.attr('alt','p');
-                    }
-                    break;
-                case 'browsed':
-                    if( myelemimg.attr('src') != '../img/completed.png' && myelemimg.attr('alt') != 'browsed') {
-                        myelemimg.attr('src','../img/completed.png');
-                        myelemimg.attr('alt','b');
-                    }
-                    break;
-                default:
-                    logit_lms('Update action unknown',2);
-                    break;
-            }
+    if (!change_ids || change_ids != 'no') {
+        change_ids = 'yes';
+    }        
+    var myelem = $("#toc_"+update_id);
+    var myelemimg = $("#toc_img_"+update_id);
+    logit_lms('update_toc("'+update_action+'",'+update_id+')',2);
+
+    if(update_id != 0) {
+        switch(update_action) {
+            case 'unhighlight':
+                if (update_id%2==0) {
+                    myelem.attr('class',"scorm_item_2");
+                } else {
+                    myelem.attr('class',"scorm_item_1");
+                }
+                break;
+            case 'highlight':
+                if (change_ids=='yes') {
+                   olms.lms_next_item = update_id;
+                   olms.lms_previous_item = update_id;
+                }
+                myelem.attr('class',"scorm_item_highlight"); 
+                break;
+            case 'not attempted':
+                if( myelemimg.attr('src') != '../img/notattempted.gif') {
+                    myelemimg.attr('src','../img/notattempted.gif');
+                    myelemimg.attr('alt','n');
+                }
+                break;
+            case 'incomplete':
+                if( myelemimg.attr('src') != '../img/incomplete.png') {
+                    myelemimg.attr('src','../img/incomplete.png');
+                    myelemimg.attr('alt','i');
+                }
+                break;
+            case 'completed':
+                if( myelemimg.attr('src') != '../img/completed.png') {
+                    myelemimg.attr('src','../img/completed.png');
+                    myelemimg.attr('alt','c');
+                }
+                break;
+            case 'failed':
+                if( myelemimg.attr('src') != '../img/delete.png') {
+                    myelemimg.attr('src','../img/delete.png');
+                    myelemimg.attr('alt','f');
+                }
+                break;
+            case 'passed':
+                if( myelemimg.attr('src') != '../img/completed.png' && myelemimg.attr('alt') != 'passed') {
+                    myelemimg.attr('src','../img/completed.png');
+                    myelemimg.attr('alt','p');
+                }
+                break;
+            case 'browsed':
+                if( myelemimg.attr('src') != '../img/completed.png' && myelemimg.attr('alt') != 'browsed') {
+                    myelemimg.attr('src','../img/completed.png');
+                    myelemimg.attr('alt','b');
+                }
+                break;
+            default:
+                logit_lms('Update action unknown',2);
+                break;
         }
-        return true;
+    }
+    return true;
 }
 
 /**
  * Update the stats frame using a reload of the frame to avoid unsynched data
  */
-function update_stats() {
+function update_stats() {    
     if (olms.execute_stats) {
         try {
             cont_f = document.getElementById('content_id');
-            cont_f.src="lp_controller.php?action=stats";
+            cont_f.src = "lp_controller.php?action=stats";            
             cont_f.reload();
         } catch (e) {
             return false;
@@ -1303,9 +1300,7 @@ function update_progress_bar(nbr_complete, nbr_total, mode) {
  * @return  array   Array of SCO variables
  */
 function process_scorm_values () {
-
     for (i=0;i<olms.scorm_variables.length;i++) {
-
         if (olms.updatable_vars_list[olms.scorm_variables[i]]) {
             olms.variable_to_send.push(olms.scorm_variables[i]);
         }
@@ -1320,7 +1315,6 @@ function process_scorm_values () {
 function reinit_updatable_vars_list () {
 
     for (i=0;i<olms.scorm_variables.length;i++) {
-
         if (olms.updatable_vars_list[olms.scorm_variables[i]]) {
             olms.updatable_vars_list[olms.scorm_variables[i]]=false;
         }

Algunos archivos no se mostraron porque demasiados archivos cambiaron en este cambio