Browse Source

Task #1765 - LP tool, cleaning files (11).

Ivan Tcholakov 14 years ago
parent
commit
bed9e7a700

File diff suppressed because it is too large
+ 482 - 511
main/newscorm/scorm.class.php


+ 78 - 93
main/newscorm/scorm.lib.php

@@ -1,6 +1,8 @@
-<?php //$id:$
-//TODO migrate this into the scorm.class.php file
+<?php
 /* For licensing terms, see /license.txt */
+
+// TODO: Migrate this into the scorm.class.php file.
+
 /**
  * This file is a container for functions related to SCORM and other
  * standard or common course content types. It might later become a class
@@ -10,83 +12,73 @@
  * @author Yannick Warnier <ywarnier@beeznest.org>
  * @author Based on work from Denes NAgy, Isthvan Mandak and Roan Embrechts
  */
+
 /**
  * Delete a scorm directory (check for imsmanifest and if found, deletes the related rows in scorm tables also)
- * @param               string          Dir path
- * @return      boolean True on success, false otherwise
+ * @param  string	Dir path
+ * @return boolean	True on success, false otherwise
  */
-function removescormDir($dir)
-{
-  global $_course;
-  if(!@$opendir = opendir($dir))
-  {
-    return false;
-  }
-  while($readdir = readdir($opendir))
-  {
-    if($readdir != '..' && $readdir != '.')
-    {
-      if(is_file($dir.'/'.$readdir))
-      {
-        $pos=strpos('/'.$readdir, 'imsmanifest.xml');
-        if ($pos) {  //so we have the imsmanifest in this dir
-                     //from d:/myworks/dokeos/dokeos_cvs/dokeos/dokeos/courses/CVSCODE4/scorm/LP2/LP2
-                    //we have to get /LP2/LP2
-          $path=api_get_path(SYS_COURSE_PATH).$_course['official_code'].'/scorm';
-          $pos=strpos($dir,$path);
-          if ($pos==0) {
-            $scormdir=substr($dir,strlen($path),strlen($dir)-strlen($path));
-            $courseid=$_course['official_code'];
-            $sql="SELECT * FROM ".Database::get_scorm_table(TABLE_SCORM_MAIN)." where (contentTitle='$scormdir' and dokeosCourse='$courseid')";
-            $result=Database::query($sql);
-            while ($row=Database::fetch_array($result))
-            {
-	      $c=$row['contentId'];
-	      $sql2="DELETE FROM ".Database::get_scorm_table(TABLE_SCORM_SCO_DATA)." where contentId=$c";
-	      $result2=Database::query($sql2);
-	    }
-	    $sql="DELETE FROM ".Database::get_scorm_table(TABLE_SCORM_MAIN)." where (contentTitle='$scormdir' and dokeosCourse='$courseid')";
-	    $result=Database::query($sql);
-	  }
+function removescormDir($dir) {
+	global $_course;
+	if(!@$opendir = opendir($dir)) {
+		return false;
 	}
-	if(!@unlink($dir.'/'.$readdir))
-	{
-	  return false;
+	while($readdir = readdir($opendir)) {
+		if($readdir != '..' && $readdir != '.') {
+			if(is_file($dir.'/'.$readdir)) {
+				$pos = strpos('/'.$readdir, 'imsmanifest.xml');
+				if ($pos) {	// So we have the imsmanifest in this dir
+							// from d:/myworks/dokeos/dokeos_cvs/dokeos/dokeos/courses/CVSCODE4/scorm/LP2/LP2
+							// We have to get /LP2/LP2
+					$path = api_get_path(SYS_COURSE_PATH).$_course['official_code'].'/scorm';
+					$pos = strpos($dir, $path);
+					if ($pos == 0) {
+						$scormdir = substr($dir, strlen($path), strlen($dir) - strlen($path));
+						$courseid = $_course['official_code'];
+						$sql = "SELECT * FROM ".Database::get_scorm_table(TABLE_SCORM_MAIN)." where (contentTitle='$scormdir' and dokeosCourse='$courseid')";
+						$result = Database::query($sql);
+						while ($row = Database::fetch_array($result)) {
+							$c = $row['contentId'];
+							$sql2 = "DELETE FROM ".Database::get_scorm_table(TABLE_SCORM_SCO_DATA)." where contentId=$c";
+							$result2 = Database::query($sql2);
+						}
+						$sql = "DELETE FROM ".Database::get_scorm_table(TABLE_SCORM_MAIN)." where (contentTitle='$scormdir' and dokeosCourse='$courseid')";
+						$result = Database::query($sql);
+					}
+				}
+				if (!@unlink($dir.'/'.$readdir)) {
+					return false;
+				}
+			} elseif (is_dir($dir.'/'.$readdir)) {
+				if(!removescormDir($dir.'/'.$readdir)) {
+					return false;
+				}
+			}
+		}
 	}
-      } elseif(is_dir($dir.'/'.$readdir)) {
-        if(!removescormDir($dir.'/'.$readdir))
-        {
-	  return false;
+	closedir($opendir);
+	if (!@rmdir($dir)) {
+		return false;
 	}
-      }
-    }
-  }
-  closedir($opendir);
-  if(!@rmdir($dir)) {
-    return false;
-  }
-  return true;
+	return true;
 }
+
 /**
  * This function removes a directory if it exists
- * @param               string          Dir path
- * @return      boolean True on success, false otherwise
- * @uses        removescormDir()        to actually remove the directory
+ * @param string			Dir path
+ * @return boolean			True on success, false otherwise
+ * @uses removescormDir()	to actually remove the directory
  */
-function scorm_delete($file)
-{
-  if ( check_name_exist($file) )
-  {
-    if ( is_dir($file) )
-    {
-      return removescormDir($file);
-    }
-  }
-  else
-  {
-    return false; // no file or directory to delete
-  }
+function scorm_delete($file) {
+	if (check_name_exist($file)) {
+		if (is_dir($file)) {
+			return removescormDir($file);
+		}
+	} else {
+		return false; // No file or directory to delete.
+	}
 }
+
 /**
  * This function gets a list of scorm paths located in a given directory
  * @param	string	Base directory path
@@ -95,60 +87,52 @@ function scorm_delete($file)
  * @return	array	Array(type=>array(),size=>array(),date=>array())
  */
 function get_scorm_paths_from_dir($basedir, $curdir, &$attribute){
-	$scormcontent=false;
+	$scormcontent = false;
 	$saved_dir = getcwd();
 	$res = @chdir (realpath($basedir.$curdir));
-	if($res === false){ return(null);}
-	$handle = opendir(".");
+	if ($res === false) { return(null); }
+	$handle = opendir('.');
 
 	define('A_DIRECTORY', 1);
 	define('A_FILE',      2);
 
 	$fileList = array();
-	// fill up $fileList for displaying the files list later on
-	while ($file = readdir($handle))
-	{
-		if ($file == "." || $file == ".." || $file == '.htaccess')
-		{
-			continue;						// Skip current and parent directories
+	// Fill up $fileList for displaying the files list later on.
+	while ($file = readdir($handle)) {
+		if ($file == '.' || $file == '..' || $file == '.htaccess') {
+			continue; // Skip current and parent directories
 		}
 
 		$fileList['name'][] = $file;
 
 		//if ($file=='imsmanifest.xml') { $scormcontent=true; }
 
-		if(is_dir($file))
-		{
+		if(is_dir($file)) {
 			$fileList['type'][] = A_DIRECTORY;
 			$fileList['size'][] = false;
 			$fileList['date'][] = false;
-		}
-		elseif(is_file($file))
-		{
+		} elseif (is_file($file)) {
 			$fileList['type'][] = A_FILE;
 			$fileList['size'][] = filesize($file);
 			$fileList['date'][] = filectime($file);
 		}
+
 		/*
 		 * Make the correspondance between
 		 * info given by the file system
 		 * and info given by the DB
 		 */
-		if (is_array($attribute) && count($attribute['path'])>0)
-		{
-			$keyAttribute = array_search($curdir."/".$file, $attribute['path']);
+		if (is_array($attribute) && count($attribute['path']) > 0) {
+			$keyAttribute = array_search($curdir.'/'.$file, $attribute['path']);
 		}
 
-		if ($keyAttribute !== false)
-		{
+		if ($keyAttribute !== false) {
 			$fileList['comment'   ][] = $attribute['comment'   ][$keyAttribute];
 			$fileList['visibility'][] = $attribute['visibility'][$keyAttribute];
 			unset ($attribute['comment'   ][$keyAttribute],
-			  $attribute['visibility'][$keyAttribute],
-			  $attribute['path'      ][$keyAttribute]);
-		}
-		else
-		{
+			$attribute['visibility'][$keyAttribute],
+			$attribute['path'      ][$keyAttribute]);
+		} else {
 			$fileList['comment'   ][] = false;
 			$fileList['visibility'][] = false;
 		}
@@ -157,6 +141,7 @@ function get_scorm_paths_from_dir($basedir, $curdir, &$attribute){
 	chdir($saved_dir);
 	return $fileList;
 }
+
 /**
  * Detects the SCORM version from an imsmanifest.xml file
  * @param	string	Path to imsmanifest.xml
@@ -166,4 +151,4 @@ function get_scorm_paths_from_dir($basedir, $curdir, &$attribute){
 function get_scorm_version($path){
 	return '1.2';
 }
-?>
+

+ 226 - 243
main/newscorm/scormItem.class.php

@@ -1,15 +1,17 @@
-<?php 
+<?php
 /* For licensing terms, see /license.txt */
+
 /**
  * Container for the scormItem class that deals with <item> elements in an imsmanifest file
  * @package	chamilo.learnpath.scorm
  * @author	Yannick Warnier	<ywarnier@beeznest.org>
  */
+
 /**
  * This class handles the <item> elements from an imsmanifest file.
  */
 require_once 'learnpathItem.class.php';
-class scormItem extends learnpathItem{
+class scormItem extends learnpathItem {
 	public $identifier = '';
 	public $identifierref = '';
 	public $isvisible = '';
@@ -27,250 +29,232 @@ class scormItem extends learnpathItem{
 	public $mastery_score = '';
 	public $scorm_contact;
 
-    /**
-     * Class constructor. Depending of the type of construction called ('db' or 'manifest'), will create a scormItem
-     * object from database records or from the DOM element given as parameter
-     * @param	string	Type of construction needed ('db' or 'manifest', default = 'manifest')
-     * @param	mixed	Depending on the type given, DB id for the lp_item or reference to the DOM element
-     */
-    public function __construct($type='manifest',&$element) {
-    	if(isset($element))
-    	{
+	/**
+	 * Class constructor. Depending of the type of construction called ('db' or 'manifest'), will create a scormItem
+	 * object from database records or from the DOM element given as parameter
+	 * @param	string	Type of construction needed ('db' or 'manifest', default = 'manifest')
+	 * @param	mixed	Depending on the type given, DB id for the lp_item or reference to the DOM element
+	 */
+	public function __construct($type='manifest',&$element) {
+		if (isset($element)) {
 
-			$v = substr(phpversion(),0,1);
-			if($v == 4){
-	    		switch($type){
-	    			case 'db':
-	    				parent::__construct($element,api_get_user_id());
-	    				$this->scorm_contact = false;
-	    				//TODO implement this way of metadata object creation
-	    				return false;
-	    			case 'manifest': //do the same as the default
-	    			default:
-				     	//if($first_item->type == XML_ELEMENT_NODE) this is already check prior to the call to this function
-				     	$children = $element->children();
-				    	foreach($children as $a => $dummy)
-				     	{
-				     		$child =& $children[$a];
-				     		switch($child->type)
-				     		{
-				     			case XML_ELEMENT_NODE:
-									switch($child->tagname){
-				     					case 'title':
-						     				$tmp_children = $child->children();
-						     				if(count($tmp_children)==1 and $tmp_children[0]->content!='' )
-						     				{
-						     					$this->title = $tmp_children[0]->content;
-						     				}
-						     				break;
-				     					case 'maxtimeallowed':
-						     				$tmp_children = $child->children();
-						     				if(count($tmp_children)==1 and $tmp_children[0]->content!='' )
-						     				{
-						     					$this->max_time_allowed = $tmp_children[0]->content;
-						     				}
-						     				break;
+			$v = substr(phpversion(), 0, 1);
+			if ($v == 4) {
+				switch ($type) {
+					case 'db':
+						parent::__construct($element,api_get_user_id());
+						$this->scorm_contact = false;
+						// TODO: Implement this way of metadata object creation.
+						return false;
+					case 'manifest': // Do the same as the default.
+					default:
+					 	// if ($first_item->type == XML_ELEMENT_NODE) this is already check prior to the call to this function.
+					 	$children = $element->children();
+						foreach($children as $a => $dummy) {
+					 		$child =& $children[$a];
+					 		switch($child->type) {
+					 			case XML_ELEMENT_NODE:
+									switch($child->tagname) {
+					 					case 'title':
+							 				$tmp_children = $child->children();
+							 				if (count($tmp_children) == 1 && $tmp_children[0]->content != '') {
+							 					$this->title = $tmp_children[0]->content;
+							 				}
+							 				break;
+					 					case 'maxtimeallowed':
+							 				$tmp_children = $child->children();
+							 				if (count($tmp_children) == 1 && $tmp_children[0]->content != '') {
+							 					$this->max_time_allowed = $tmp_children[0]->content;
+							 				}
+							 				break;
 										case 'prerequisites':
-						     				$tmp_children = $child->children();
-						     				if(count($tmp_children)==1 and $tmp_children[0]->content!='' )
-						     				{
-						     					$this->prereq_string = $tmp_children[0]->content;
-						     				}
-						     				break;
+							 				$tmp_children = $child->children();
+							 				if (count($tmp_children) == 1 && $tmp_children[0]->content != '') {
+							 					$this->prereq_string = $tmp_children[0]->content;
+							 				}
+							 				break;
 										case 'timelimitaction':
-						     				$tmp_children = $child->children();
-						     				if(count($tmp_children)==1 and $tmp_children[0]->content!='' )
-						     				{
-						     					$this->timelimitaction = $tmp_children[0]->content;
-						     				}
-						     				break;
+							 				$tmp_children = $child->children();
+							 				if (count($tmp_children) == 1 && $tmp_children[0]->content != '') {
+							 					$this->timelimitaction = $tmp_children[0]->content;
+							 				}
+							 				break;
 										case 'datafromlms':
-						     				$tmp_children = $child->children();
-						     				if(count($tmp_children)==1 and $tmp_children[0]->content!='' )
-						     				{
-						     					$this->datafromlms = $tmp_children[0]->content;
-						     				}
-						     				break;
+							 				$tmp_children = $child->children();
+							 				if (count($tmp_children) == 1 && $tmp_children[0]->content != '') {
+							 					$this->datafromlms = $tmp_children[0]->content;
+							 				}
+							 				break;
 										case 'masteryscore':
-						     				$tmp_children = $child->children();
-						     				if(count($tmp_children)==1 and $tmp_children[0]->content!='' )
-						     				{
-						     					$this->mastery_score = $tmp_children[0]->content;
-						     				}
-						     				break;
-				     					case 'item':
-				     						$oItem = new scormItem('manifest',$child);
-				     						if($oItem->identifier != ''){
-				     							$this->sub_items[$oItem->identifier] = $oItem;
-				     						}
+							 				$tmp_children = $child->children();
+							 				if (count($tmp_children) == 1 && $tmp_children[0]->content != '') {
+							 					$this->mastery_score = $tmp_children[0]->content;
+							 				}
+							 				break;
+					 					case 'item':
+					 						$oItem = new scormItem('manifest', $child);
+					 						if ($oItem->identifier != ''){
+					 							$this->sub_items[$oItem->identifier] = $oItem;
+					 						}
 											break;
-				     					case 'metadata':
-				     						$this->metadata = new scormMetadata('manifest',$child);
-				     						break;
-				     				}
-				     				break;
-				     			case XML_TEXT_NODE:
-				     				//this case is actually treated by looking into ELEMENT_NODEs above
-				     				break;
-				     		}
-				     	}
-				     	$attributes = $element->attributes();
-				     	//$keep_href = '';
-				     	foreach($attributes as $a1 => $dummy)
-				     	{
-				     		$attrib =& $attributes[$a1];
-				     		switch($attrib->name){
-				     			case 'identifier':
-				     				$this->identifier = $attrib->value;
-				     				break;
-				     			case 'identifierref':
-				     				$this->identifierref = $attrib->value;
-				     				break;
-				     			case 'isvisible':
-				     				$this->isvisible = $attrib->value;
-				     				break;
-				     			case 'parameters':
-				     				$this->parameters = $attrib->value;
-				     				break;
-				     		}
-				     	}
+					 					case 'metadata':
+					 						$this->metadata = new scormMetadata('manifest', $child);
+					 						break;
+					 				}
+					 				break;
+					 			case XML_TEXT_NODE:
+					 				// This case is actually treated by looking into ELEMENT_NODEs above.
+					 				break;
+					 		}
+					 	}
+					 	$attributes = $element->attributes();
+					 	//$keep_href = '';
+					 	foreach ($attributes as $a1 => $dummy) {
+					 		$attrib =& $attributes[$a1];
+					 		switch($attrib->name){
+					 			case 'identifier':
+					 				$this->identifier = $attrib->value;
+					 				break;
+					 			case 'identifierref':
+					 				$this->identifierref = $attrib->value;
+					 				break;
+					 			case 'isvisible':
+					 				$this->isvisible = $attrib->value;
+					 				break;
+					 			case 'parameters':
+					 				$this->parameters = $attrib->value;
+					 				break;
+					 		}
+					 	}
 						return true;
 
-	    		}
-	    	}elseif($v == 5){
-	    		//parsing using PHP5 DOMXML methods
-	    		switch($type){
-	    			case 'db':
-	    				parent::__construct($element,api_get_user_id());
-	    				$this->scorm_contact = false;
-	    				//TODO implement this way of metadata object creation
-	    				return false;
-	    			case 'manifest': //do the same as the default
-	    			default:
-				     	//if($first_item->type == XML_ELEMENT_NODE) this is already check prior to the call to this function
-				     	$children = $element->childNodes;
-				    	foreach($children as $child)
-				     	{
-				     		switch($child->nodeType)
-				     		{
-				     			case XML_ELEMENT_NODE:
-									switch($child->tagName){
-				     					case 'title':
-						     				$tmp_children = $child->childNodes;
-						     				//if(count($tmp_children)==1 and $tmp_children[0]->textContent!='' )
-						     				if($tmp_children->length==1 and $child->firstChild->nodeValue!='' )
-						     				{
-						     					$this->title = $child->firstChild->nodeValue;
-						     				}
-						     				break;
-						     			case 'max_score':
-					     					if($tmp_children->length==1 and $child->firstChild->nodeValue!='' ) {
-						     					$this->max_score = $child->firstChild->nodeValue;
-						     				}
-						     				break;
-				     					case 'maxtimeallowed':
-				     					case 'adlcp:maxtimeallowed':
-						     				$tmp_children = $child->childNodes;
-						     				//if(count($tmp_children)==1 and $tmp_children[0]->textContent!='' )
-						     				if($tmp_children->length==1 and $child->firstChild->nodeValue!='' )
-						     				{
-						     					$this->max_time_allowed = $child->firstChild->nodeValue;
-						     				}
-						     				break;
+				}
+			} elseif ($v == 5) {
+				// Parsing using PHP5 DOMXML methods.
+				switch ($type) {
+					case 'db':
+						parent::__construct($element,api_get_user_id());
+						$this->scorm_contact = false;
+						//TODO: Implement this way of metadata object creation.
+						return false;
+					case 'manifest': // Do the same as the default.
+					default:
+					 	//if ($first_item->type == XML_ELEMENT_NODE) this is already check prior to the call to this function.
+					 	$children = $element->childNodes;
+						foreach ($children as $child) {
+					 		switch ($child->nodeType) {
+					 			case XML_ELEMENT_NODE:
+									switch ($child->tagName) {
+					 					case 'title':
+							 				$tmp_children = $child->childNodes;
+							 				//if (count($tmp_children) == 1 && $tmp_children[0]->textContent != '') {
+							 				if ($tmp_children->length == 1 && $child->firstChild->nodeValue != '') {
+							 					$this->title = $child->firstChild->nodeValue;
+							 				}
+							 				break;
+							 			case 'max_score':
+						 					if ($tmp_children->length == 1 && $child->firstChild->nodeValue != '') {
+							 					$this->max_score = $child->firstChild->nodeValue;
+							 				}
+							 				break;
+					 					case 'maxtimeallowed':
+					 					case 'adlcp:maxtimeallowed':
+							 				$tmp_children = $child->childNodes;
+							 				//if (count($tmp_children) == 1 && $tmp_children[0]->textContent != '') {
+							 				if ($tmp_children->length == 1 && $child->firstChild->nodeValue != '') {
+							 					$this->max_time_allowed = $child->firstChild->nodeValue;
+							 				}
+							 				break;
 										case 'prerequisites':
 										case 'adlcp:prerequisites':
-						     				$tmp_children = $child->childNodes;
-						     				//if(count($tmp_children)==1 and $tmp_children[0]->textContent!='' )
-						     				if($tmp_children->length==1 and $child->firstChild->nodeValue!='' )
-						     				{
-						     					$this->prereq_string = $child->firstChild->nodeValue;
-						     				}
-						     				break;
+							 				$tmp_children = $child->childNodes;
+							 				//if (count($tmp_children) == 1 && $tmp_children[0]->textContent != '') {
+							 				if ($tmp_children->length == 1 && $child->firstChild->nodeValue != '') {
+							 					$this->prereq_string = $child->firstChild->nodeValue;
+							 				}
+							 				break;
 										case 'timelimitaction':
 										case 'adlcp:timelimitaction':
-						     				$tmp_children = $child->childNodes;
-						     				//if(count($tmp_children)==1 and $tmp_children[0]->textContent!='' )
-						     				if($tmp_children->length==1 and $child->firstChild->nodeValue!='' )
-						     				{
-						     					$this->timelimitaction = $child->firstChild->nodeValue;
-						     				}
-						     				break;
+							 				$tmp_children = $child->childNodes;
+							 				//if (count($tmp_children) == 1 && $tmp_children[0]->textContent != '') {
+							 				if ($tmp_children->length == 1 && $child->firstChild->nodeValue != '') {
+							 					$this->timelimitaction = $child->firstChild->nodeValue;
+							 				}
+							 				break;
 										case 'datafromlms':
 										case 'adlcp:datafromlms':
 										case 'adlcp:launchdata': //in some cases (Wouters)
-						     				$tmp_children = $child->childNodes;
-						     				//if(count($tmp_children)==1 and $tmp_children[0]->textContent!='' )
-						     				if($tmp_children->length==1 and $child->firstChild->nodeValue!='' )
-						     				{
-						     					$this->datafromlms = $child->firstChild->nodeValue;
-						     				}
-						     				break;
+							 				$tmp_children = $child->childNodes;
+							 				//if (count($tmp_children) == 1 && $tmp_children[0]->textContent != '') {
+							 				if ($tmp_children->length == 1 && $child->firstChild->nodeValue != '') {
+							 					$this->datafromlms = $child->firstChild->nodeValue;
+							 				}
+							 				break;
 										case 'masteryscore':
 										case 'adlcp:masteryscore':
-						     				$tmp_children = $child->childNodes;
-						     				//if(count($tmp_children)==1 and $tmp_children[0]->textContent!='' )
-						     				if($tmp_children->length==1 and $child->firstChild->nodeValue!='' )
-						     				{
-						     					$this->mastery_score = $child->firstChild->nodeValue;
-						     				}
-						     				break;
-				     					case 'item':
-				     						$oItem = new scormItem('manifest',$child);
-				     						if($oItem->identifier != ''){
-				     							$this->sub_items[$oItem->identifier] = $oItem;
-				     						}
+							 				$tmp_children = $child->childNodes;
+							 				//if (count($tmp_children) == 1 && $tmp_children[0]->textContent != '') {
+							 				if ($tmp_children->length == 1 && $child->firstChild->nodeValue != '') {
+							 					$this->mastery_score = $child->firstChild->nodeValue;
+							 				}
+							 				break;
+					 					case 'item':
+					 						$oItem = new scormItem('manifest',$child);
+					 						if ($oItem->identifier != '') {
+					 							$this->sub_items[$oItem->identifier] = $oItem;
+					 						}
 											break;
-				     					case 'metadata':
-				     						$this->metadata = new scormMetadata('manifest',$child);
-				     						break;
-				     				}
-				     				break;
-				     			case XML_TEXT_NODE:
-				     				//this case is actually treated by looking into ELEMENT_NODEs above
-				     				break;
-				     		}
-				     	}
-				     	if($element->hasAttributes()){
-					     	$attributes = $element->attributes;
-					     	//$keep_href = '';
-					     	foreach($attributes as $attrib)
-					     	{
-					     		switch($attrib->name){
-					     			case 'identifier':
-					     				$this->identifier = $attrib->value;
-					     				break;
-					     			case 'identifierref':
-					     				$this->identifierref = $attrib->value;
-					     				break;
-					     			case 'isvisible':
-					     				$this->isvisible = $attrib->value;
-					     				break;
-					     			case 'parameters':
-					     				$this->parameters = $attrib->value;
-					     				break;
-					     		}
-					     	}
-				     	}
+					 					case 'metadata':
+					 						$this->metadata = new scormMetadata('manifest', $child);
+					 						break;
+					 				}
+					 				break;
+					 			case XML_TEXT_NODE:
+					 				// This case is actually treated by looking into ELEMENT_NODEs above.
+					 				break;
+					 		}
+					 	}
+					 	if ($element->hasAttributes()) {
+						 	$attributes = $element->attributes;
+						 	//$keep_href = '';
+						 	foreach ($attributes as $attrib) {
+						 		switch($attrib->name){
+						 			case 'identifier':
+						 				$this->identifier = $attrib->value;
+						 				break;
+						 			case 'identifierref':
+						 				$this->identifierref = $attrib->value;
+						 				break;
+						 			case 'isvisible':
+						 				$this->isvisible = $attrib->value;
+						 				break;
+						 			case 'parameters':
+						 				$this->parameters = $attrib->value;
+						 				break;
+						 		}
+						 	}
+					 	}
 						return true;
 
-	    		}
-			}else{
-				//cannot parse because not PHP4 nor PHP5... We should not even be here anyway...
+				}
+			} else {
+				// Cannot parse because not PHP4 nor PHP5... We should not even be here anyway...
 				return false;
 			}
-    	}
-    	return false;
-    }
-    /**
-     * Builds a flat list with the current item and calls itself recursively on all children
-     * @param	array	Reference to the array to complete with the current item
-     * @param	integer	Optional absolute order (pointer) of the item in this learning path
-     * @param	integer	Optional relative order of the item at this level
-     * @param	integer	Optional level. If not given, assumes it's level 0
-     */
-    public function get_flat_list(&$list,&$abs_order,$rel_order=1,$level=0) {
-    	$list[] = array(
-    		'abs_order' => $abs_order,
+		}
+		return false;
+	}
+
+	/**
+	 * Builds a flat list with the current item and calls itself recursively on all children
+	 * @param	array	Reference to the array to complete with the current item
+	 * @param	integer	Optional absolute order (pointer) of the item in this learning path
+	 * @param	integer	Optional relative order of the item at this level
+	 * @param	integer	Optional level. If not given, assumes it's level 0
+	 */
+	public function get_flat_list(&$list, &$abs_order, $rel_order = 1, $level = 0) {
+		$list[] = array(
+			'abs_order' => $abs_order,
 			'datafromlms' => $this->datafromlms,
 			'identifier' => $this->identifier,
 			'identifierref' => $this->identifierref,
@@ -280,32 +264,31 @@ class scormItem extends learnpathItem{
 			'maxtimeallowed' => $this->max_time_allowed,
 			'metadata' => $this->metadata,
 			'parameters' => $this->parameters,
-			'prerequisites' => (!empty($this->prereq_string)?$this->prereq_string:''),
+			'prerequisites' => (!empty($this->prereq_string) ? $this->prereq_string : ''),
 			'rel_order' => $rel_order,
 			'timelimitaction' => $this->timelimitaction,
 			'title' => $this->title,
 			'max_score' => $this->max_score
-			);
+		);
 		$abs_order++;
 		$i = 1;
-		foreach($this->sub_items as $id => $dummy)
-		{
+		foreach($this->sub_items as $id => $dummy) {
 			$oSubitem =& $this->sub_items[$id];
-			$oSubitem->get_flat_list($list,$abs_order,$i,$level+1);
+			$oSubitem->get_flat_list($list, $abs_order, $i, $level + 1);
 			$i++;
 		}
-    }
-    /**
-     * Save function. Uses the parent save function and adds a layer for SCORM.
-     * @param	boolean	Save from URL params (1) or from object attributes (0)
-     */
-    public function save($from_outside=true,$prereqs_complete=false) {
-    	parent::save($from_outside,$prereqs_complete);
-    	//under certain conditions, the scorm_contact should not be set, because no scorm signal was sent
-    	$this->scorm_contact = true;
-    	if(!$this->scorm_contact){
-    		//error_log('New LP - was expecting SCORM message but none received',0);
-    	}
-    }
+	}
+
+	/**
+	 * Save function. Uses the parent save function and adds a layer for SCORM.
+	 * @param	boolean	Save from URL params (1) or from object attributes (0)
+	 */
+	public function save($from_outside = true, $prereqs_complete = false) {
+		parent::save($from_outside, $prereqs_complete);
+		// Under certain conditions, the scorm_contact should not be set, because no scorm signal was sent.
+		$this->scorm_contact = true;
+		if (!$this->scorm_contact){
+			//error_log('New LP - was expecting SCORM message but none received', 0);
+		}
+	}
 }
-?>

+ 156 - 167
main/newscorm/scormMetadata.class.php

@@ -1,9 +1,11 @@
 <?php
 /* For licensing terms, see /license.txt */
+
 /**
  * Container for the scormMetadata class, setup to hold information about the <metadata> element in imsmanifest files
  * @package chamilo.learnpath.scorm
  */
+
 /**
  * scormMetadata class, handling each <metadata> element found in an imsmanifest file
  */
@@ -17,183 +19,170 @@ class scormMetadata {
 
 	/**
 	 * Class constructor. Works in two different ways defined by the first element, being 'db' or 'manifest'.
-	 * If 'db', then it is built using the information available in the Dokeos database. If 'manifest', then it
+	 * If 'db', then it is built using the information available in the Chamilo database. If 'manifest', then it
 	 * is built using the element given as a parameter, expecting it to be a <metadata> element pointer from the
 	 * DOM parser.
 	 * @param	string	Type of creation required. Can be 'db' or 'manifest' (default)
 	 * @param	mixed	Depending on the type, can be the DB ID of the learnpath item or the pointer to the <metadata> element in the imsmanifest.xml file
 	 * @return	boolean	True on success, false on failure
 	 */
-    public function __construct($type='manifest', &$element) {
-    	if (isset($element)) {
-    		$v = substr(phpversion(),0,1);
+	public function __construct($type = 'manifest', &$element) {
+		if (isset($element)) {
+			$v = substr(phpversion(), 0, 1);
 			if ($v == 4) {
-	    		switch ($type) {
-	    			case 'db':
-	    				//TODO implement this way of metadata object creation
-	    				return false;
-	    				//break;
-	    			case 'manifest': //do the same as the default
-				     	//if($first_item->type == XML_ELEMENT_NODE) this is already check prior to the call to this function
-				     	$children = $element->children();
-				    	foreach ($children as $a => $dummy) {
-				     		$child =& $children[$a];
-				     		switch ($child->type) {
-				     			case XML_ELEMENT_NODE:
-									//could be 'lom','schema','schemaversion' or 'location'
-				     				switch ($child->tagname) {
-				     					case 'lom':
-				     						$childchildren = $child->children();
-				     						foreach ($childchildren as $index => $dummy)
-				     						{
-				     							$my_elem = $childchildren[$index];
-				     							//there is generally only one child here
-				     							//$this->lom[] = $my_elem->content;
-				     							$this->lom = $my_elem->content;
-				     						}
-				     						break;
-				     					case 'schema':
-				     						$childchildren = $child->children();
-				     						foreach ($childchildren as $index => $dummy)
-				     						{
-				     							$my_elem = $childchildren[$index];
-				     							//there is generally only one child here
-				     							//$this->schema[] = $my_elem->content;
-				     							$this->schema = $my_elem->content;
-				     						}
-				     						break;
-				     					case 'schemaversion':
-				     						$childchildren = $child->children();
-				     						foreach ($childchildren as $index => $dummy)
-				     						{
-				     							$my_elem = $childchildren[$index];
-				     							//there is generally only one child here
-				     							//$this->schemaversion[] = $my_elem->content;
-				     							$this->schemaversion = $my_elem->content;
-				     						}
-				     						break;
-				     					case 'location':
-				     						$childchildren = $child->children();
-				     						foreach ($childchildren as $index => $dummy)
-				     						{
-				     							$my_elem = $childchildren[$index];
-				     							//there is generally only one child here
-				     							//$this->location[] = $my_elem->content;
-				     							$this->location = $my_elem->content;
-				     						}
-				     						break;
-				     				}
-				     				break;
-				     			case XML_TEXT_NODE:
-				     				if(trim($child->content) != '') {
-				     					if (count($children == 1)) {
-				     						//if this is the only child at this level and it is a content... save differently
-				     						$this->text = $child->content;
-				     					} else {
-				     						$this->text[$element->tagname] = $child->content;
-				     					}
-				     				}
-				     				break;
-				     		}
-				     	}
-				     	$attributes = $element->attributes();
-				     	//$keep_href = '';
-				     	if (is_array($attributes)) {
-					     	foreach ($attributes as $a1 => $dummy)
-					     	{
-					     		$attrib =& $attributes[$a1];
-					     		if(trim($attrib->value) != ''){
-					     			$this->attribs[$attrib->name] = $attrib->value;
-					     		}
-					     	}
-				     	}
+				switch ($type) {
+					case 'db':
+						// TODO: Implement this way of metadata object creation
+						return false;
+						//break;
+					case 'manifest': // Do the same as the default.
+					 	//if ($first_item->type == XML_ELEMENT_NODE) this is already check prior to the call to this function.
+					 	$children = $element->children();
+						foreach ($children as $a => $dummy) {
+					 		$child =& $children[$a];
+					 		switch ($child->type) {
+					 			case XML_ELEMENT_NODE:
+									// Could be 'lom', 'schema', 'schemaversion' or 'location'.
+					 				switch ($child->tagname) {
+					 					case 'lom':
+					 						$childchildren = $child->children();
+					 						foreach ($childchildren as $index => $dummy) {
+					 							$my_elem = $childchildren[$index];
+					 							// There is generally only one child here.
+					 							//$this->lom[] = $my_elem->content;
+					 							$this->lom = $my_elem->content;
+					 						}
+					 						break;
+					 					case 'schema':
+					 						$childchildren = $child->children();
+					 						foreach ($childchildren as $index => $dummy) {
+					 							$my_elem = $childchildren[$index];
+					 							// There is generally only one child here.
+					 							//$this->schema[] = $my_elem->content;
+					 							$this->schema = $my_elem->content;
+					 						}
+					 						break;
+					 					case 'schemaversion':
+					 						$childchildren = $child->children();
+					 						foreach ($childchildren as $index => $dummy) {
+					 							$my_elem = $childchildren[$index];
+					 							// There is generally only one child here.
+					 							//$this->schemaversion[] = $my_elem->content;
+					 							$this->schemaversion = $my_elem->content;
+					 						}
+					 						break;
+					 					case 'location':
+					 						$childchildren = $child->children();
+					 						foreach ($childchildren as $index => $dummy) {
+					 							$my_elem = $childchildren[$index];
+					 							// There is generally only one child here.
+					 							//$this->location[] = $my_elem->content;
+					 							$this->location = $my_elem->content;
+					 						}
+					 						break;
+					 				}
+					 				break;
+					 			case XML_TEXT_NODE:
+					 				if (trim($child->content) != '') {
+					 					if (count($children == 1)) {
+					 						// If this is the only child at this level and it is a content... save differently.
+					 						$this->text = $child->content;
+					 					} else {
+					 						$this->text[$element->tagname] = $child->content;
+					 					}
+					 				}
+					 				break;
+					 		}
+					 	}
+					 	$attributes = $element->attributes();
+					 	//$keep_href = '';
+					 	if (is_array($attributes)) {
+						 	foreach ($attributes as $a1 => $dummy) {
+						 		$attrib =& $attributes[$a1];
+						 		if (trim($attrib->value) != '') {
+						 			$this->attribs[$attrib->name] = $attrib->value;
+						 		}
+						 	}
+					 	}
 						return true;
-	    				//break;
-	    		}
-	    	} elseif ($v == 5) {
-	    		//parsing using PHP5 DOMXML methods
-	    		switch ($type) {
-	    			case 'db':
-	    				//TODO implement this way of metadata object creation
-	    				return false;
-	    				//break;
-	    			case 'manifest': //do the same as the default
-				     	$children = $element->childNodes;
-				    	foreach ($children as $child)
-				     	{
-				     		switch ($child->nodeType)
-				     		{
-				     			case XML_ELEMENT_NODE:
-									//could be 'lom','schema','schemaversion' or 'location'
-				     				switch ($child->tagName) {
-				     					case 'lom':
-				     						$childchildren = $child->childNodes;
-				     						foreach ($childchildren as $childchild)
-				     						{
-				     							//$this->lom = $childchild->textContent;
-				     							$this->lom = $childchild->nodeValue;
-				     						}
-				     						break;
-				     					case 'schema':
-				     						$childchildren = $child->childNodes;
-				     						foreach ($childchildren as $childchild)
-				     						{
-				     							//there is generally only one child here
-				     							//$this->schema = $childchildren[$index]->textContent;
-				     							$this->schema = $childchild->nodeValue;
-				     						}
-				     						break;
-				     					case 'schemaversion':
-				     						$childchildren = $child->childNodes;
-				     						foreach ($childchildren as $childchild)
-				     						{
-				     							//there is generally only one child here
-				     							//$this->schemaversion = $childchildren[$index]->textContent;
-				     							$this->schemaversion = $childchild->nodeValue;
-				     						}
-				     						break;
-				     					case 'location':
-				     						$childchildren = $child->childNodes;
-				     						foreach ($childchildren as $childchild)
-				     						{
-				     							//there is generally only one child here
-				     							//$this->location = $childchildren[$index]->textContent;
-				     							$this->location = $childchild->nodeValue;
-				     						}
-				     						break;
-				     				}
-				     				break;
-				     			case XML_TEXT_NODE:
-				     				if (trim($child->textContent) != '') {
-				     					if (count($children == 1)){
-				     						//if this is the only child at this level and it is a content... save differently
-				     						$this->text = $child->textContent;
-				     					} else {
-				     						$this->text[$element->tagName] = $child->textContent;
-				     					}
-				     				}
-				     				break;
-				     		}
-				     	}
-				     	$attributes = $element->attributes;
-				     	//$keep_href = '';
-				     	if (is_array($attributes)) {
-					     	foreach($attributes as $attrib)
-					     	{
-					     		if(trim($attrib->value) != ''){
-					     			$this->attribs[$attrib->name] = $attrib->value;
-					     		}
-					     	}
-				     	}
+						//break;
+				}
+			} elseif ($v == 5) {
+				// Parsing using PHP5 DOMXML methods.
+				switch ($type) {
+					case 'db':
+						// TODO: Implement this way of metadata object creation.
+						return false;
+						//break;
+					case 'manifest': // Do the same as the default.
+					 	$children = $element->childNodes;
+						foreach ($children as $child) {
+					 		switch ($child->nodeType) {
+					 			case XML_ELEMENT_NODE:
+									// Could be 'lom','schema','schemaversion' or 'location'.
+					 				switch ($child->tagName) {
+					 					case 'lom':
+					 						$childchildren = $child->childNodes;
+					 						foreach ($childchildren as $childchild) {
+					 							//$this->lom = $childchild->textContent;
+					 							$this->lom = $childchild->nodeValue;
+					 						}
+					 						break;
+					 					case 'schema':
+					 						$childchildren = $child->childNodes;
+					 						foreach ($childchildren as $childchild) {
+					 							// There is generally only one child here.
+					 							//$this->schema = $childchildren[$index]->textContent;
+					 							$this->schema = $childchild->nodeValue;
+					 						}
+					 						break;
+					 					case 'schemaversion':
+					 						$childchildren = $child->childNodes;
+					 						foreach ($childchildren as $childchild) {
+					 							// There is generally only one child here.
+					 							//$this->schemaversion = $childchildren[$index]->textContent;
+					 							$this->schemaversion = $childchild->nodeValue;
+					 						}
+					 						break;
+					 					case 'location':
+					 						$childchildren = $child->childNodes;
+					 						foreach ($childchildren as $childchild) {
+					 							// There is generally only one child here.
+					 							//$this->location = $childchildren[$index]->textContent;
+					 							$this->location = $childchild->nodeValue;
+					 						}
+					 						break;
+					 				}
+					 				break;
+					 			case XML_TEXT_NODE:
+					 				if (trim($child->textContent) != '') {
+					 					if (count($children == 1)) {
+					 						// If this is the only child at this level and it is a content... save differently.
+					 						$this->text = $child->textContent;
+					 					} else {
+					 						$this->text[$element->tagName] = $child->textContent;
+					 					}
+					 				}
+					 				break;
+					 		}
+					 	}
+					 	$attributes = $element->attributes;
+					 	//$keep_href = '';
+					 	if (is_array($attributes)) {
+						 	foreach ($attributes as $attrib) {
+						 		if (trim($attrib->value) != ''){
+						 			$this->attribs[$attrib->name] = $attrib->value;
+						 		}
+						 	}
+					 	}
 						return true;
-	    				//break;
-	    		}
+						//break;
+				}
 			} else {
-				//cannot parse because not PHP4 nor PHP5... We should not even be here anyway...
+				// Cannot parse because not PHP4 nor PHP5... We should not even be here anyway...
 				return false;
 			}
-    	}
-    	return false;
-    }
+		}
+		return false;
+	}
 }
-?>

+ 142 - 138
main/newscorm/scormOrganization.class.php

@@ -1,10 +1,12 @@
 <?php
 /* For licensing terms, see /license.txt */
+
 /**
  * Container for the scormOrganization class
  * @package chamilo.learnpath.scorm
  * @author	Yannick Warnier <ywarnier@beeznest.org>
  */
+
 /**
  * Class defining the <organization> tag in an imsmanifest.xml file
  */
@@ -14,125 +16,125 @@ class scormOrganization {
 	public $title = '';
 	public $items = array();
 	public $metadata;
-    /**
-     * Class constructor. Depending of the type of construction called ('db' or 'manifest'), will create a scormOrganization
-     * object from database records or from the DOM element given as parameter
-     * @param	string	Type of construction needed ('db' or 'manifest', default = 'manifest')
-     * @param	mixed	Depending on the type given, DB id for the lp_item or reference to the DOM element
-     */
-    public function __construct($type='manifest',&$element,$scorm_charset='UTF-8') {
-    	if (isset($element))	{
-			$v = substr(phpversion(),0,1);
+	/**
+	 * Class constructor. Depending of the type of construction called ('db' or 'manifest'), will create a scormOrganization
+	 * object from database records or from the DOM element given as parameter
+	 * @param	string	Type of construction needed ('db' or 'manifest', default = 'manifest')
+	 * @param	mixed	Depending on the type given, DB id for the lp_item or reference to the DOM element
+	 */
+	public function __construct($type = 'manifest', &$element, $scorm_charset = 'UTF-8') {
+		if (isset($element))	{
+			$v = substr(phpversion(), 0, 1);
 			if ($v == 4) {
-	    		switch ($type) {
-	    			case 'db':
-	    				//TODO implement this way of metadata object creation
-	    				return false;
-	    			case 'manifest': //do the same as the default
-	    			default:
-				     	//if($first_item->type == XML_ELEMENT_NODE) this is already check prior to the call to this function
-				     	$children = $element->children();
-				    	foreach ($children as $a => $dummy) {
-				     		$child =& $children[$a];
-				     		switch ($child->type) {
-				     			case XML_ELEMENT_NODE:
+				switch ($type) {
+					case 'db':
+						// TODO: Implement this way of metadata object creation
+						return false;
+					case 'manifest': // Do the same as the default.
+					default:
+					 	//if ($first_item->type == XML_ELEMENT_NODE) this is already check prior to the call to this function
+					 	$children = $element->children();
+						foreach ($children as $a => $dummy) {
+					 		$child =& $children[$a];
+					 		switch ($child->type) {
+					 			case XML_ELEMENT_NODE:
 									switch ($child->tagname) {
-				     					case 'item':
-				     						$oItem = new scormItem('manifest',$child);
-				     						if ($oItem->identifier != '') {
+					 					case 'item':
+					 						$oItem = new scormItem('manifest', $child);
+					 						if ($oItem->identifier != '') {
 												$this->items[$oItem->identifier] = $oItem;
-				     						}
+					 						}
 											break;
-				     					case 'metadata':
-				     						$this->metadata = new scormMetadata('manifest',$child);
-				     						break;
-				     					case 'title':
-						     				$tmp_children = $child->children();
-						     				if (count($tmp_children)==1 and $tmp_children[0]->content!='' ) {
-						     					$this->title = $tmp_children[0]->content;
-						     				}
-						     				break;
-				     				}
-				     				break;
-				     			case XML_TEXT_NODE:
-				     				break;
-				     		}
-				     	}
-				     	$attributes = $element->attributes();
-				     	//$keep_href = '';
-				     	foreach ($attributes as $a1 => $dummy) {
-				     		$attrib =& $attributes[$a1];
-				     		switch ($attrib->name) {
-				     			case 'identifier':
-				     				$this->identifier = $attrib->value;
-				     				break;
-				     			case 'structure':
-				     				$this->structure = $attrib->value;
-				     				break;
-				     		}
-				     	}
+					 					case 'metadata':
+					 						$this->metadata = new scormMetadata('manifest', $child);
+					 						break;
+					 					case 'title':
+							 				$tmp_children = $child->children();
+							 				if (count($tmp_children) == 1 && $tmp_children[0]->content != '') {
+							 					$this->title = $tmp_children[0]->content;
+							 				}
+							 				break;
+					 				}
+					 				break;
+					 			case XML_TEXT_NODE:
+					 				break;
+					 		}
+					 	}
+					 	$attributes = $element->attributes();
+					 	//$keep_href = '';
+					 	foreach ($attributes as $a1 => $dummy) {
+					 		$attrib =& $attributes[$a1];
+					 		switch ($attrib->name) {
+					 			case 'identifier':
+					 				$this->identifier = $attrib->value;
+					 				break;
+					 			case 'structure':
+					 				$this->structure = $attrib->value;
+					 				break;
+					 		}
+					 	}
 						return true;
 
-	    		}
-	    	} elseif ($v == 5) {
-	    		//parsing using PHP5 DOMXML methods
-	    		switch($type){
-	    			case 'db':
-	    				//TODO implement this way of metadata object creation
-	    				return false;
-	    			case 'manifest': //do the same as the default
-	    			default:
-				     	//if($first_item->type == XML_ELEMENT_NODE) this is already check prior to the call to this function
-				     	$children = $element->childNodes;
-				    	foreach ($children as $child) {
-				     		switch ($child->nodeType) {
-				     			case XML_ELEMENT_NODE:
+				}
+			} elseif ($v == 5) {
+				// Parsing using PHP5 DOMXML methods.
+				switch ($type) {
+					case 'db':
+						// TODO: Implement this way of metadata object creation.
+						return false;
+					case 'manifest': // Do the same as the default.
+					default:
+					 	//if($first_item->type == XML_ELEMENT_NODE) this is already check prior to the call to this function.
+					 	$children = $element->childNodes;
+						foreach ($children as $child) {
+					 		switch ($child->nodeType) {
+					 			case XML_ELEMENT_NODE:
 									switch ($child->tagName) {
-				     					case 'item':
-				     						$oItem = new scormItem('manifest',$child);
-				     						if($oItem->identifier != ''){
+					 					case 'item':
+					 						$oItem = new scormItem('manifest', $child);
+					 						if ($oItem->identifier != '') {
 												$this->items[$oItem->identifier] = $oItem;
-				     						}
+					 						}
 											break;
-				     					case 'metadata':
-				     						$this->metadata = new scormMetadata('manifest',$child);
-				     						break;
-				     					case 'title':
-						     				$tmp_children = $child->childNodes;
-						     				if ($tmp_children->length==1 and $child->firstChild->nodeValue != '' ) {
-						     					$this->title = html_entity_decode(html_entity_decode($child->firstChild->nodeValue,ENT_QUOTES,$scorm_charset));
-						     				}
-						     				break;
-				     				}
-				     				break;
-				     			case XML_TEXT_NODE:
-				     				break;
-				     		}
-				     	}
+					 					case 'metadata':
+					 						$this->metadata = new scormMetadata('manifest', $child);
+					 						break;
+					 					case 'title':
+							 				$tmp_children = $child->childNodes;
+							 				if ($tmp_children->length == 1 && $child->firstChild->nodeValue != '') {
+							 					$this->title = html_entity_decode(html_entity_decode($child->firstChild->nodeValue, ENT_QUOTES, $scorm_charset)); // TODO: This conversion from html-entities looks strange.
+							 				}
+							 				break;
+					 				}
+					 				break;
+					 			case XML_TEXT_NODE:
+					 				break;
+					 		}
+					 	}
 						if ($element->hasAttributes()) {
-					     	$attributes = $element->attributes;
-					     	//$keep_href = '';
-					     	foreach ($attributes as $attrib) {
-					     		switch ($attrib->name) {
-					     			case 'identifier':
-					     				$this->identifier = $attrib->value;
-					     				break;
-					     			case 'structure':
-					     				$this->structure = $attrib->value;
-					     				break;
-					     		}
-					     	}
+						 	$attributes = $element->attributes;
+						 	//$keep_href = '';
+						 	foreach ($attributes as $attrib) {
+						 		switch ($attrib->name) {
+						 			case 'identifier':
+						 				$this->identifier = $attrib->value;
+						 				break;
+						 			case 'structure':
+						 				$this->structure = $attrib->value;
+						 				break;
+						 		}
+						 	}
 						}
 						return true;
-
-	    		}
+				}
 			} else {
-				//cannot parse because not PHP4 nor PHP5... We should not even be here anyway...
+				// Cannot parse because not PHP4 nor PHP5... We should not even be here anyway...
 				return false;
 			}
-    	}
-    	return false;
-    }
+		}
+		return false;
+	}
+
 	/**
 	 * Get a flat list of items in the organization
 	 * @return	array	Array containing an ordered list of all items with their level and all information related to each item
@@ -140,43 +142,45 @@ class scormOrganization {
 	public function get_flat_items_list() {
 		$list = array();
 		$i = 1;
-		foreach ($this->items as $id=>$dummy) {
+		foreach ($this->items as $id => $dummy) {
 			$abs_order = 0;
-			$this->items[$id]->get_flat_list($list,$abs_order,$i,0); //passes the array as a pointer so it is modified in $list directly
+			$this->items[$id]->get_flat_list($list,$abs_order, $i, 0); // Passes the array as a pointer so it is modified in $list directly.
 			$i++;
 		}
 		return $list;
 	}
-    /**
-     * Name getter
-     * @return	string	Name or empty string
-     */
-    public function get_name() {
-    	if (!empty($this->title)) {
-    		return Database::escape_string($this->title);
-    	} else {
-    		return '';
-    	}
-    }
-    /**
-     * Reference identifier getter
-     * @return	string	Identifier or empty string
-     */
-    public function get_ref() {
-    	if (!empty($this->identifier)) {
-    		return Database::escape_string($this->identifier);
-    	} else {
-    		return '';
-    	}
-    }
-    /**
-     * Sets the title element
-     * @param	string	New title to set
-     */
-    public function set_name($title) {
-    	if (!empty($title)) {
-    		$this->title = Database::escape_string($title);
-    	}
-    }
+
+	/**
+	 * Name getter
+	 * @return	string	Name or empty string
+	 */
+	public function get_name() {
+		if (!empty($this->title)) {
+			return Database::escape_string($this->title);
+		} else {
+			return '';
+		}
+	}
+
+	/**
+	 * Reference identifier getter
+	 * @return	string	Identifier or empty string
+	 */
+	public function get_ref() {
+		if (!empty($this->identifier)) {
+			return Database::escape_string($this->identifier);
+		} else {
+			return '';
+		}
+	}
+
+	/**
+	 * Sets the title element
+	 * @param	string	New title to set
+	 */
+	public function set_name($title) {
+		if (!empty($title)) {
+			$this->title = Database::escape_string($title);
+		}
+	}
 }
-?>

+ 173 - 178
main/newscorm/scormResource.class.php

@@ -1,10 +1,12 @@
 <?php
 /* For licensing terms, see /license.txt */
+
 /**
  * Container for the scormResource class
  * @package chamilo.learnpath.scorm
  * @author	Yannick Warnier <ywarnier@beeznest.org>
  */
+
 /**
  * Class defining the <resource> tag in an imsmanifest.xml file
  *
@@ -13,7 +15,7 @@ class scormResource {
 	public $identifier = '';
 	public $type = 'webcontent';
 	//public $identifierref = '';
-	public $scormtype = 'sco'; //fix problems with ENI content where asset is not defined
+	public $scormtype = 'sco'; // Fix problems with ENI content where asset is not defined.
 	public $base = '';
 	public $href = '';
 	public $metadata;
@@ -22,188 +24,181 @@ class scormResource {
 	public $files = array();
 	public $dependencies = array();
 
-    /**
-     * Class constructor. Depending of the type of construction called ('db' or 'manifest'), will create a scormResource
-     * object from database records or from the DOM element given as parameter
-     * @param	string	Type of construction needed ('db' or 'manifest', default = 'manifest')
-     * @param	mixed	Depending on the type given, DB id for the lp_item or reference to the DOM element
-     */
-    public function __construct($type='manifest',&$element) {
-    	/*
-    	echo "<pre>Analysing resource:<br />\n";
-    	var_dump($element);
-    	echo "</pre><br />\n";
-    	*/
-    	if(isset($element))
-    	{
-			$v = substr(phpversion(),0,1);
-			if($v == 4){
-	    		switch($type){
-	    			case 'db':
-	    				//TODO implement this way of metadata object creation
-	    				return false;
-	    			case 'manifest': //do the same as the default
-	    			default:
-				     	//if($first_item->type == XML_ELEMENT_NODE) this is already check prior to the call to this function
-				     	$children = $element->children();
-				    	foreach($children as $a => $dummy)
-				     	{
-				     		$child =& $children[$a];
-				     		switch($child->type)
-				     		{
-				     			case XML_ELEMENT_NODE:
-									switch($child->tagname){
-				     					case 'file':
-				     						//echo "Child is a file tag<br />\n";
-				     						$this->files[] = $child->get_attribute('href');
-				     						//var_dump($this->files);
-				     						//ignoring file metadata
+	/**
+	 * Class constructor. Depending of the type of construction called ('db' or 'manifest'), will create a scormResource
+	 * object from database records or from the DOM element given as parameter
+	 * @param	string	Type of construction needed ('db' or 'manifest', default = 'manifest')
+	 * @param	mixed	Depending on the type given, DB id for the lp_item or reference to the DOM element
+	 */
+	public function __construct($type = 'manifest', &$element) {
+		/*
+		echo "<pre>Analysing resource:<br />\n";
+		var_dump($element);
+		echo "</pre><br />\n";
+		*/
+		if (isset($element)) {
+			$v = substr(phpversion(), 0, 1);
+			if ($v == 4) {
+				switch ($type) {
+					case 'db':
+						// TODO: Implement this way of metadata object creation.
+						return false;
+					case 'manifest': //do the same as the default
+					default:
+						//if ($first_item->type == XML_ELEMENT_NODE) this is already check prior to the call to this function.
+						$children = $element->children();
+						foreach ($children as $a => $dummy) {
+							$child =& $children[$a];
+							switch ($child->type) {
+								case XML_ELEMENT_NODE:
+									switch ($child->tagname) {
+										case 'file':
+											//echo "Child is a file tag<br />\n";
+											$this->files[] = $child->get_attribute('href');
+											//var_dump($this->files);
+											//ignoring file metadata
 											//files[] array contains all <file href='x'> tags one by one
 											break;
-				     					case 'metadata':
-				     						//echo "Child is a metadata tag<br />\n";
-				     						$this->metadata = new scormMetadata('manifest',$child);
-				     						break;
-				     					case 'dependency':
-				     						//echo "Child is a dependency tag<br />\n";
-				     						//need to get identifierref attribute inside dependency node
-				     						//dependencies[] array represents all <dependency identifierref='x'> tags united
-				     						$this->dependencies[] = $child->get_attribute('identifierref');
-				     						break;
-				     				}
-				     				break;
-				     		}
-				     	}
-				     	$attributes = $element->attributes();
-				     	//$keep_href = '';
-				     	if(count($attributes)>0){ //in some cases we get here with an empty attributes array
-				     	//TODO find when and why we get such a case (empty array)
-					     	foreach($attributes as $a1 => $dummy)
-					     	{
-					     		$attrib =& $attributes[$a1];
-					     		switch($attrib->name){
-					     			case 'identifier':
-					     				$this->identifier = $attrib->value;
-					     				break;
-					     			case 'type':
-					     				if(!empty($attrib->value)){
-					     					$this->type = $attrib->value;
-					     				}
-					     				break;
-					     			case 'scormtype':
-					     				if(!empty($attrib->value)){
-					     					$this->scormtype = $attrib->value;
-					     				}
-					     				break;
-					     			case 'base':
-					     				$this->base = $attrib->value;
-					     				break;
-					     			case 'href':
-					     				$this->href = $attrib->value;
-					     				break;
-					     		}
-					     	}
-				     	}
+										case 'metadata':
+											//echo "Child is a metadata tag<br />\n";
+											$this->metadata = new scormMetadata('manifest', $child);
+											break;
+										case 'dependency':
+											//echo "Child is a dependency tag<br />\n";
+											//need to get identifierref attribute inside dependency node
+											//dependencies[] array represents all <dependency identifierref='x'> tags united
+											$this->dependencies[] = $child->get_attribute('identifierref');
+											break;
+									}
+									break;
+							}
+						}
+						$attributes = $element->attributes();
+						//$keep_href = '';
+						if (count($attributes) > 0) { // In some cases we get here with an empty attributes array.
+						//TODO find when and why we get such a case (empty array)
+							foreach ($attributes as $a1 => $dummy) {
+								$attrib =& $attributes[$a1];
+								switch ($attrib->name) {
+									case 'identifier':
+										$this->identifier = $attrib->value;
+										break;
+									case 'type':
+										if (!empty($attrib->value)) {
+											$this->type = $attrib->value;
+										}
+										break;
+									case 'scormtype':
+										if (!empty($attrib->value)) {
+											$this->scormtype = $attrib->value;
+										}
+										break;
+									case 'base':
+										$this->base = $attrib->value;
+										break;
+									case 'href':
+										$this->href = $attrib->value;
+										break;
+								}
+							}
+						}
 						return true;
 
-	    		}
-	    	}elseif($v == 5){
-	    		//parsing using PHP5 DOMXML methods
-	    		switch($type){
-	    			case 'db':
-	    				//TODO implement this way of metadata object creation
-	    				return false;
-	    			case 'manifest': //do the same as the default
-	    			default:
-				     	//if($first_item->type == XML_ELEMENT_NODE) this is already check prior to the call to this function
-				     	$children = $element->childNodes;
-				    	if(is_array($children)){
-					    	foreach($children as $child)
-					     	{
-					     		switch($child->nodeType)
-					     		{
-					     			case XML_ELEMENT_NODE:
-										switch($child->tagName){
-					     					case 'file':
-					     						//echo "Child is a file tag<br />\n";
-					     						$this->files[] = $child->getAttribute('href');
+				}
+			} elseif ($v == 5) {
+				// Parsing using PHP5 DOMXML methods.
+				switch($type){
+					case 'db':
+						// TODO: Implement this way of metadata object creation.
+						return false;
+					case 'manifest': // Do the same as the default.
+					default:
+						//if ($first_item->type == XML_ELEMENT_NODE) this is already check prior to the call to this function.
+						$children = $element->childNodes;
+						if (is_array($children)) {
+							foreach ($children as $child) {
+								switch ($child->nodeType) {
+									case XML_ELEMENT_NODE:
+										switch ($child->tagName) {
+											case 'file':
+												//echo "Child is a file tag<br />\n";
+												$this->files[] = $child->getAttribute('href');
+												break;
+											case 'metadata':
+												//echo "Child is a metadata tag<br />\n";
+												$this->metadata = new scormMetadata('manifest', $child);
 												break;
-					     					case 'metadata':
-					     						//echo "Child is a metadata tag<br />\n";
-					     						$this->metadata = new scormMetadata('manifest',$child);
-					     						break;
-					     					case 'dependency':
-					     						//need to get identifierref attribute inside dependency node
-					     						//dependencies[] array represents all <dependency identifierref='x'> tags united
-					     						$this->dependencies[] = $child->getAttribute('identifierref');
-					     						break;
-					     				}
-					     				break;
-					     		}
-					     	}
-				     	}
-				     	//$keep_href = '';
-				     	if($element->hasAttributes()){ //in some cases we get here with an empty attributes array
-				     	//TODO find when and why we get such a case (empty array)
-					     	$attributes = $element->attributes;
-					     	foreach($attributes as $attrib)
-					     	{
-					     		switch($attrib->name){
-					     			case 'identifier':
-					     				$this->identifier = $attrib->value;
-					     				break;
-					     			case 'type':
-					     				if(!empty($attrib->value)){
-					     					$this->type = $attrib->value;
-					     				}
-					     				break;
-					     			case 'scormtype':
-					     				if(!empty($attrib->value)){
-					     					$this->scormtype = $attrib->value;
-					     				}
-					     				break;
-					     			case 'base':
-					     				$this->base = $attrib->value;
-					     				break;
-					     			case 'href':
-					     				$this->href = $attrib->value;
-					     				break;
-					     		}
-					     	}
-				     	}
+											case 'dependency':
+												// Need to get identifierref attribute inside dependency node.
+												// dependencies[] array represents all <dependency identifierref='x'> tags united.
+												$this->dependencies[] = $child->getAttribute('identifierref');
+												break;
+										}
+										break;
+								}
+							}
+						}
+						//$keep_href = '';
+						if ($element->hasAttributes()){ //in some cases we get here with an empty attributes array
+						// TODO: Find when and why we get such a case (empty array).
+							$attributes = $element->attributes;
+							foreach ($attributes as $attrib) {
+								switch ($attrib->name) {
+									case 'identifier':
+										$this->identifier = $attrib->value;
+										break;
+									case 'type':
+										if (!empty($attrib->value)) {
+											$this->type = $attrib->value;
+										}
+										break;
+									case 'scormtype':
+										if (!empty($attrib->value)) {
+											$this->scormtype = $attrib->value;
+										}
+										break;
+									case 'base':
+										$this->base = $attrib->value;
+										break;
+									case 'href':
+										$this->href = $attrib->value;
+										break;
+								}
+							}
+						}
 						return true;
-
-	    		}
-			}else{
-				//cannot parse because not PHP4 nor PHP5... We should not even be here anyway...
+				}
+			} else {
+				// Cannot parse because not PHP4 nor PHP5... We should not even be here anyway...
 				return false;
 			}
-    	}
-    	return false;
-     }
-     /**
-      * Path getter
-      * @return	string	Path for this resource
-      */
-     public function get_path() {
-     	if(!empty($this->href))
-     	{
-     		require_once 'learnpath.class.php';
-     		return learnpath::escape_string($this->href);
-     	}else{
-     		return '';
-     	}
-     }
-     /**
-      * Scorm type getter
-      * @return	string	generally 'asset' or 'sco' as these are the only two values defined in SCORM 1.2
-      */
-     public function get_scorm_type() {
-     	if(!empty($this->scormtype)){
-     		require_once 'learnpath.class.php';
-     		return learnpath::escape_string($this->scormtype);
-     	}else{
-     		return '';
-     	}
-     }
-}
+		}
+		return false;
+	}
+
+	/**
+	 * Path getter
+	 * @return	string	Path for this resource
+	 */
+	public function get_path() {
+		if (!empty($this->href)) {
+			require_once 'learnpath.class.php';
+			return learnpath::escape_string($this->href);
+		} else {
+			return '';
+		}
+	}
+
+	/**
+	 * Scorm type getter
+	 * @return	string	generally 'asset' or 'sco' as these are the only two values defined in SCORM 1.2
+	 */
+	public function get_scorm_type() {
+		if (!empty($this->scormtype)){
+			require_once 'learnpath.class.php';
+			return learnpath::escape_string($this->scormtype);
+		} else {
+			return '';
+		}
+	}
+}

+ 224 - 301
main/newscorm/scorm_admin.php

@@ -1,6 +1,7 @@
 <?php
 /* For licensing terms, see /license.txt */
-//This file is probably deprecated - 2009-05-14 - ywarnier
+
+// This file is probably deprecated - 2009-05-14 - ywarnier
 /**
 * This script handles SCO administration features
 * @package chamilo.learnpath.scorm
@@ -9,15 +10,14 @@
 * @author Roan Embrechts, code improvements and refactoring
 * @author Yannick Warnier, complete refactoring <ywarnier@beeznest.org>
 */
-/**
- * Script init
- */
-//flag to allow for anonymous user - needs to be set before global.inc.php
+
+// Flag to allow for anonymous user - needs to be set before global.inc.php.
 $use_anonymous = true;
 
-// name of the language file that needs to be included
-$language_file = "scormdocument";
-$uncompress=1; //this variable shouldn't be found here (find its usage before removal)
+// Name of the language file that needs to be included.
+$language_file = 'scormdocument';
+
+$uncompress = 1; // TODO: This variable shouldn't be found here (find its usage before removal).
 
 require_once 'back_compat.inc.php';
 include 'learnpath_functions.inc.php';
@@ -25,39 +25,36 @@ include_once 'scorm.lib.php';
 
 $is_allowedToEdit = api_is_allowed_to_edit();
 
-/**
- * Variables
- */
-//escapable integers
-if ($_REQUEST['id'] != strval(intval($_REQUEST['id']))) {$id = $_REQUEST['id'];} else {$id=null;}
+/* Variables */
 
-//imported strings
-$path 					= (!empty($_REQUEST['path'])?$_REQUEST['path']:null);
-$Submit 				= (!empty($_POST['Submit'])?$_POST['Submit']:null);
-$submitImage 			= (!empty($_POST['submitImage'])?$_POST['submitImage']:null);
-$cancelSubmitImage 		= (!empty($_POST['cancelSubmitImage'])?$_POST['cancelSubmitImage']:null);
-$action					= (!empty($_REQUEST['action'])?$_REQUEST['action']:null);
-$delete					= (!empty($_REQUEST['delete'])?$_REQUEST['delete']:null);
-$createDir				= (!empty($_REQUEST['createDir'])?$_REQUEST['createDir']:null);
-$make_directory_visible = (!empty($_REQUEST['make_directory_visible'])?$_REQUEST['make_directory_visible']:'');
-$make_directory_invisible = (!empty($_REQUEST['make_directory_invisible'])?$_REQUEST['make_directory_invisible']:'');
+// Escapable integers.
+if ($_REQUEST['id'] != strval(intval($_REQUEST['id']))) { $id = $_REQUEST['id']; } else { $id = null; }
 
-//values from POST form to add directory
-$newDirPath				= (!empty($_POST['newDirPath'])?$_POST['newDirPath']:null);
-$newDirName				= (!empty($_POST['newDirName'])?$_POST['newDirName']:null);
-//initialising internal variables
+// Imported strings.
+$path 					= (!empty($_REQUEST['path']) ? $_REQUEST['path'] : null);
+$Submit 				= (!empty($_POST['Submit']) ? $_POST['Submit'] : null);
+$submitImage 			= (!empty($_POST['submitImage']) ? $_POST['submitImage'] : null);
+$cancelSubmitImage 		= (!empty($_POST['cancelSubmitImage']) ? $_POST['cancelSubmitImage'] : null);
+$action					= (!empty($_REQUEST['action']) ? $_REQUEST['action'] : null);
+$delete					= (!empty($_REQUEST['delete']) ? $_REQUEST['delete'] : null);
+$createDir				= (!empty($_REQUEST['createDir']) ? $_REQUEST['createDir'] : null);
+$make_directory_visible = (!empty($_REQUEST['make_directory_visible']) ? $_REQUEST['make_directory_visible'] : '');
+$make_directory_invisible = (!empty($_REQUEST['make_directory_invisible']) ? $_REQUEST['make_directory_invisible'] : '');
+
+// Values from POST form to add directory.
+$newDirPath				= (!empty($_POST['newDirPath']) ? $_POST['newDirPath'] : null);
+$newDirName				= (!empty($_POST['newDirName']) ? $_POST['newDirName'] : null);
+// Initialising internal variables.
 $dialogbox = '';
 
 if (! $is_allowed_in_course) api_not_allowed();
 $is_allowedToUnzip = $is_courseAdmin;
 
+/* Main code */
 
-/**
- * Main code
- */
 switch ($action) {
 	case 'exportpath':
-		if(!empty($id)){
+		if (!empty($id)) {
   			$export = exportpath($id);
   			$dialogBox .= "This LP has been exported to the Document folder "
   						."of your course.";
@@ -67,11 +64,11 @@ switch ($action) {
 		exportSCORM($path);
 		break;
 	case 'deletepath':
-		/*==================================================
+		/*
 			DELETE A DOKEOS LEARNPATH
 			and all the items in it
-		 ==================================================*/
-		if(!empty($id)){
+		*/
+		if (!empty($id)){
 			$l="learnpath/learnpath_handler.php?learnpath_id=$id";
 			$sql="DELETE FROM $tbl_tool where (link='$l' AND image='scormbuilder.gif')";
 			$result=Database::query($sql);
@@ -90,303 +87,229 @@ switch ($action) {
 		}
 		break;
 	case 'publishpath':
-		/*==================================================================
-		  PUBLISHING (SHOWING) A DOKEOS LEARNPATH
-		  ==================================================================*/
-		if(!empty($id)){
-			$sql="SELECT * FROM $tbl_learnpath_main where learnpath_id=$id";
-			$result=Database::query($sql);
-			$row=Database::fetch_array($result);
-			$name=domesticate($row['learnpath_name']);
+		/* PUBLISHING (SHOWING) A DOKEOS LEARNPATH */
+		if (!empty($id)){
+			$sql = "SELECT * FROM $tbl_learnpath_main where learnpath_id=$id";
+			$result = Database::query($sql);
+			$row = Database::fetch_array($result);
+			$name = domesticate($row['learnpath_name']);
 			if ($set_visibility == 'i') {
-				$s=$name." ".get_lang('_no_published');
-				$dialogBox=$s;
-				$v=0;
+				$s = $name.' '.get_lang('_no_published');
+				$dialogBox = $s;
+				$v = 0;
 			}
 			if ($set_visibility == 'v') {
-				$s=$name." ".get_lang('_published');
-				$dialogBox=$s;
-				$v=1;
+				$s=$name.' '.get_lang('_published');
+				$dialogBox = $s;
+				$v = 1;
 			}
-			$sql="SELECT * FROM $tbl_tool where (name='$name' and image='scormbuilder.gif')";
-			$result=Database::query($sql);
-			$row2=Database::fetch_array($result);
-			$num=Database::num_rows($result);
-			if (($set_visibility == 'i') && ($num>0))
-			{
-				//it is visible or hidden but once was published
-				if (($row2['visibility'])==1)
-				{
-					$sql ="DELETE FROM $tbl_tool WHERE (name='$name' and image='scormbuilder.gif')";
+			$sql = "SELECT * FROM $tbl_tool where (name='$name' and image='scormbuilder.gif')";
+			$result = Database::query($sql);
+			$row2 = Database::fetch_array($result);
+			$num = Database::num_rows($result);
+			if (($set_visibility == 'i') && ($num > 0)) {
+				// It is visible or hidden but once was published.
+				if (($row2['visibility']) == 1) {
+					$sql = "DELETE FROM $tbl_tool WHERE (name='$name' and image='scormbuilder.gif')";
+				} else {
+					$sql = "UPDATE $tbl_tool set visibility=1 WHERE (name='$name' and image='scormbuilder.gif')";
 				}
-				else
-				{
-					$sql ="UPDATE $tbl_tool set visibility=1 WHERE (name='$name' and image='scormbuilder.gif')";
-				}
-			}
-			elseif (($set_visibility == 'v') && ($num==0))
-			{
+			} elseif (($set_visibility == 'v') && ($num == 0)) {
 				$sql ="INSERT INTO $tbl_tool (id, name, link, image, visibility, admin, address, added_tool) VALUES ('$theid','$name','learnpath/learnpath_handler.php?learnpath_id=$id','scormbuilder.gif','$v','0','pastillegris.gif',0)";
+			} else {
+				// Parameter and database incompatible, do nothing.
 			}
-			else
-			{
-				//parameter and database incompatible, do nothing
-			}
-			$result=Database::query($sql);
-
+			$result = Database::query($sql);
 		}
 		break;
 	case 'editpath':
-		/*==================================================================
-		  EDITING A DOKEOS NEW LEARNPATH
-  		==================================================================*/
-		if(!empty($Submit))
-		{
-		  $l="learnpath/learnpath_handler.php?learnpath_id=$id";
-		  $sql="UPDATE $tbl_tool set name='".domesticate($learnpath_name)."' where (link='$l' and image='scormbuilder.gif')";
-		  $result=Database::query($sql);
-		  $sql ="UPDATE $tbl_learnpath_main SET learnpath_name='".domesticate($learnpath_name)."', learnpath_description='".domesticate($learnpath_description)."' WHERE learnpath_id=$id";
-		  $result=Database::query($sql);
-		  $dialogBox=get_lang('_learnpath_edited');
+		/* EDITING A DOKEOS NEW LEARNPATH */
+		if (!empty($Submit)) {
+			$l = "learnpath/learnpath_handler.php?learnpath_id=$id";
+			$sql = "UPDATE $tbl_tool set name='".domesticate($learnpath_name)."' where (link='$l' and image='scormbuilder.gif')";
+			$result = Database::query($sql);
+			$sql = "UPDATE $tbl_learnpath_main SET learnpath_name='".domesticate($learnpath_name)."', learnpath_description='".domesticate($learnpath_description)."' WHERE learnpath_id=$id";
+			$result = Database::query($sql);
+			$dialogBox = get_lang('_learnpath_edited');
 		}
 		break;
 	case 'add':
-		/*==================================================================
-		  		ADDING A NEW LEARNPATH : treating the form
-		 ==================================================================*/
-		if (!empty($Submit))
-		{
-		  $sql ="INSERT INTO $tbl_learnpath_main (learnpath_name, learnpath_description) VALUES ('".domesticate($learnpath_name)."','".domesticate($learnpath_description)."')";
-		  Database::query($sql);
-		  $my_lp_id = Database::insert_id();
-		  $sql ="INSERT INTO $tbl_tool (name, link, image, visibility, admin, address, added_tool) VALUES ('".domesticate($learnpath_name)."','learnpath/learnpath_handler.php?learnpath_id=$my_lp_id','scormbuilder.gif','1','0','pastillegris.gif',0)";
-		  Database::query($sql);
-		  //instead of displaying this info text, get the user directly to the learnpath edit page
-		  //$dialogBox=get_lang('_learnpath_added');
-		  header('location:../learnpath/learnpath_handler.php?'.api_get_cidreq().'&learnpath_id='.$my_lp_id);
-		  exit();
+		/* ADDING A NEW LEARNPATH : treating the form */
+		if (!empty($Submit)) {
+			$sql = "INSERT INTO $tbl_learnpath_main (learnpath_name, learnpath_description) VALUES ('".domesticate($learnpath_name)."','".domesticate($learnpath_description)."')";
+			Database::query($sql);
+			$my_lp_id = Database::insert_id();
+			$sql = "INSERT INTO $tbl_tool (name, link, image, visibility, admin, address, added_tool) VALUES ('".domesticate($learnpath_name)."','learnpath/learnpath_handler.php?learnpath_id=$my_lp_id','scormbuilder.gif','1','0','pastillegris.gif',0)";
+			Database::query($sql);
+			// Instead of displaying this info text, get the user directly to the learnpath edit page.
+			//$dialogBox = get_lang('_learnpath_added');
+			header('location:../learnpath/learnpath_handler.php?'.api_get_cidreq().'&learnpath_id='.$my_lp_id);
+			exit();
 		}
 		break;
 	case 'editscorm':
-		/*==================================================================
-		EDITING A SCORM PACKAGE
- 		==================================================================*/
-		if (!empty($Submit))
-		{
-			$sql ="UPDATE $tbl_document SET comment='".domesticate($learnpath_description)."', name='".domesticate($learnpath_name)."' WHERE path='$path'";
-			$result=Database::query($sql);
-			$dialogBox=get_lang('_learnpath_edited');
+		/* EDITING A SCORM PACKAGE */
+		if (!empty($Submit)) {
+			$sql = "UPDATE $tbl_document SET comment='".domesticate($learnpath_description)."', name='".domesticate($learnpath_name)."' WHERE path='$path'";
+			$result = Database::query($sql);
+			$dialogBox = get_lang('_learnpath_edited');
 		}
 		break;
 	default:
 		break;
 }
 
-/*============================================================================*/
+if ($is_allowedToEdit) { // TEACHER ONLY
 
-if($is_allowedToEdit) // TEACHER ONLY
-{
-  /*======================================
-	 UPLOAD SCORM
-   ======================================*/
-  /*
-   * Check the request method instead of a variable from POST
-   * because if the file size exceeds the maximum file upload
-   * size set in php.ini, all variables from POST are cleared !
-   */
+	/* UPLOAD SCORM */
 
-  if ($_SERVER['REQUEST_METHOD'] == 'POST'
-  	&& count($_FILES)>0
-  	&& empty($submitImage)
-  	&& empty($cancelSubmitImage)
-  	&& empty($action))
-  {
-    // A SCORM upload has been detected, now deal with the file...
-    //directory creation
-    $s=$_FILES['userFile']['name'];
-    $pathInfo = pathinfo($s);
-    //Check the filename has at least several letters in it :-)
-    //This is a very loose check as later on we might accept other formats of packages
-    //sent than just "zip"
-    if(preg_match('/[\w-_]+/',$pathInfo['basename'])){
-	    //get the basename without extension
-	    $newDirName=substr(
-	    	$pathInfo['basename'],
-	    	0,
-	    	strlen($pathInfo['basename'])-(strlen($pathInfo['extension'])+1));
-	    $newDirName = replace_dangerous_char(trim($newDirName),'strict');
-	    if( check_name_exist($baseWorkDir.$newDirPath.$openDir."/".$newDirName) )
-	    {
-	      /** @todo change this output. Inaccurate at least in french. In this case, the
-	       * file might not exist or the transfer might have been wrong (no $_FILES at all)
-	       * but we still get the error message
-	       */
-	      $dialogBox = get_lang('FileExists');
-	      $createDir = $newDirPath; unset($newDirPath);// return to step 1
-	    }
-	    else
-	    {
-	      if(mkdir($baseWorkDir.$newDirPath.$openDir."/".$newDirName, api_get_permissions_for_new_directories())){
-	        FileManager::set_default_settings($newDirPath.$openDir, $newDirName, "folder", $tbl_document);
-	        // RH: was:  set_default_settings($newDirPath.$openDir,$newDirName,"folder");
-	        $dialogBox = get_lang('DirCr');
-	      }else{
-	      	//Display msg "could not create dir..."
-	        //exit();
-	    }
-	    //directory creation end
+	/*
+	 * Check the request method instead of a variable from POST
+	 * because if the file size exceeds the maximum file upload
+	 * size set in php.ini, all variables from POST are cleared !
+	 */
 
-	    $uploadPath=$openDir.'/'.$newDirName;
-	    if(!$_FILES['userFile']['size'])
-        {
-	        $dialogBox .= get_lang('FileError').'<br />'.get_lang('Notice').' : '.get_lang('MaxFileSize').' '.ini_get('upload_max_filesize');
-	    }
-	    else //the file size is alright, we can assume the file is OK too
-	    {
-	      if($uncompress == 1 && $is_allowedToUnzip)
-	      {
-		    $unzip = 'unzip';
-	      }
-	      else
-	      {
-	        $unzip = '';
-	      }
-	      if (treat_uploaded_file($_FILES['userFile'], $baseWorkDir,
-		        $uploadPath, $maxFilledSpace, $unzip))
-	      {
-	        if ($uncompress == 1)
-		    {
-	          //$dialogBox .= get_lang('DownloadAndZipEnd');
-	          //modified by darkden : I omitted this part, so the user can see
-		      //the scorm content message at once
-		    }
-	        else
-		    {
-		      $dialogBox = get_lang('DownloadEnd');
-		    }
-	        // "WHAT'S NEW" notification: update table last_tooledit
-	        //update_last_tooledit($_course, $nameTools, $id, get_lang('_new_document'), $_user['user_id']);
-	        item_property_update($_course, TOOL_LEARNPATH, $id, "LearnpathAdded", $_user['user_id']);
-	      }
-	      else
-	      {
-	        if(api_failure::get_last_failure() == 'not_enough_space')
-	        {
-	          $dialogBox = get_lang('NoSpace');
-		    }
-		    elseif (api_failure::get_last_failure() == 'php_file_in_zip_file')
-		    {
-		      $dialogBox = get_lang('ZipNoPhp');
-		    }
-		    elseif(api_failure::get_last_failure() == 'not_scorm_content')
-		    {
-		      $dialogBox = get_lang('NotScormContent');
-		    }
-	      }
-	    }
-	    $uploadPath='';
-	    if (api_failure::get_last_failure())
-	    {
-	      rmdir($baseWorkDir.$newDirPath.$openDir."/".$newDirName);
-	    }
+	if ($_SERVER['REQUEST_METHOD'] == 'POST' && count($_FILES) > 0 && empty($submitImage) && empty($cancelSubmitImage) && empty($action)) {
 
-    }
-  }//
-  else
-  {//the filename doesn't contain any alphanum chars (empty filename?)
-  	//get a more detailed message?
-    $dialogBox .= get_lang('FileError').'<br />';
-  }
+		// A SCORM upload has been detected, now deal with the file...
+		// Directory creation.
+		$s = $_FILES['userFile']['name'];
+		$pathInfo = pathinfo($s);
+		// Check the filename has at least several letters in it :-)
+		// This is a very loose check as later on we might accept other formats of packages.
+		// Sent than just "zip".
+		if (preg_match('/[\w-_]+/', $pathInfo['basename'])) {
+			// get the basename without extension.
+			$newDirName = substr($pathInfo['basename'], 0, strlen($pathInfo['basename']) - (strlen($pathInfo['extension']) + 1));
+			$newDirName = replace_dangerous_char(trim($newDirName), 'strict');
+			if (check_name_exist($baseWorkDir.$newDirPath.$openDir.'/'.$newDirName)) {
+				/** @todo change this output. Inaccurate at least in french. In this case, the
+				 * file might not exist or the transfer might have been wrong (no $_FILES at all)
+				 * but we still get the error message
+				 */
+				$dialogBox = get_lang('FileExists');
+				$createDir = $newDirPath; unset($newDirPath); // Return to step 1.
+			} else {
+				if (mkdir($baseWorkDir.$newDirPath.$openDir.'/'.$newDirName, api_get_permissions_for_new_directories())) {
+					FileManager::set_default_settings($newDirPath.$openDir, $newDirName, 'folder', $tbl_document);
+					// RH: was:  set_default_settings($newDirPath.$openDir, $newDirName, 'folder');
+					$dialogBox = get_lang('DirCr');
+				} else {
+					//Display msg "could not create dir..."
+					//exit();
+				}
+				// Directory creation end.
 
-  /*======================================
-	DELETE FILE OR DIRECTORY
-    ======================================*/
+				$uploadPath = $openDir.'/'.$newDirName;
+				if (!$_FILES['userFile']['size']) {
+					$dialogBox .= get_lang('FileError').'<br />'.get_lang('Notice').' : '.get_lang('MaxFileSize').' '.ini_get('upload_max_filesize');
+				} else { // The file size is alright, we can assume the file is OK too.
+					if ($uncompress == 1 && $is_allowedToUnzip) {
+						$unzip = 'unzip';
+					} else {
+						$unzip = '';
+					}
+					if (treat_uploaded_file($_FILES['userFile'], $baseWorkDir, $uploadPath, $maxFilledSpace, $unzip)) {
+						if ($uncompress == 1) {
+							//$dialogBox .= get_lang('DownloadAndZipEnd');
+							// Modified by darkden : I omitted this part, so the user can see
+							// the scorm content message at once.
+						} else {
+							$dialogBox = get_lang('DownloadEnd');
+						}
+						// "WHAT'S NEW" notification: update table last_tooledit.
+						//update_last_tooledit($_course, $nameTools, $id, get_lang('_new_document'), $_user['user_id']);
+						item_property_update($_course, TOOL_LEARNPATH, $id, "LearnpathAdded", $_user['user_id']);
+					} else {
+						if (api_failure::get_last_failure() == 'not_enough_space') {
+							$dialogBox = get_lang('NoSpace');
+						} elseif (api_failure::get_last_failure() == 'php_file_in_zip_file') {
+							$dialogBox = get_lang('ZipNoPhp');
+						} elseif (api_failure::get_last_failure() == 'not_scorm_content') {
+							$dialogBox = get_lang('NotScormContent');
+						}
+					}
+				}
+				$uploadPath = '';
+				if (api_failure::get_last_failure()) {
+					rmdir($baseWorkDir.$newDirPath.$openDir.'/'.$newDirName);
+				}
+
+			}
+		} else { // The filename doesn't contain any alphanum chars (empty filename?)
+			// Get a more detailed message?
+			$dialogBox .= get_lang('FileError').'<br />';
+		}
+
+		/* DELETE FILE OR DIRECTORY */
+
+		if (isset($delete)) {
+			if ( scorm_delete($baseWorkDir.$delete)) {
+				//$tbl_document = substr($tbl_document, 1, strlen($tbl_document) - 2);  // RH...
+				update_db_info('delete', $delete);
+				$dialogBox = get_lang('DocDeleted');
+			}
+		}
 
-  if ( isset($delete) )
-  {
-    if ( scorm_delete($baseWorkDir.$delete))
-    {
-      //$tbl_document = substr($tbl_document, 1, strlen($tbl_document) - 2);  // RH...
-      update_db_info("delete", $delete);
-      $dialogBox = get_lang('DocDeleted');
-    }
-  }
-  /*======================================
-	CREATE DIRECTORY
-  ======================================*/
-  /*
-   * The code begin with STEP 2 so it allows to return to STEP 1
-   * if STEP 2 unsucceds
-   */
+		/* CREATE DIRECTORY */
 
-  /*-------------------------------------
-	STEP 2
-  --------------------------------------*/
-  if (isset($newDirPath) && isset($newDirName))
-  {
-    // echo $newDirPath . $newDirName;
-    $newDirName = replace_dangerous_char(trim(stripslashes($newDirName)),'strict');
-    if( check_name_exist($baseWorkDir.$newDirPath."/".$newDirName) )
-    {
-      $dialogBox = get_lang('FileExists');
-      $createDir = $newDirPath; unset($newDirPath);// return to step 1
-    }
-    else
-    {
-      if(mkdir($baseWorkDir.$newDirPath."/".$newDirName, api_get_permissions_for_new_directories()))
-        FileManager::set_default_settings($newDirPath, $newDirName, "folder", $tbl_document);
-      // RH: was:  set_default_settings($newDirPath,$newDirName,"folder");
-			$dialogBox = get_lang('DirCr');
-    }
-  }
+		/*
+		 * The code begin with STEP 2 so it allows to return to STEP 1 if STEP 2 unsucceds.
+		 */
 
-  /*-------------------------------------
-	 STEP 1
-   --------------------------------------*/
-  if (isset($createDir))
-  {
-    $dialogBox .= "<!-- create dir -->\n"
-	."<form name='createdir' action='' method='POST'>\n"
-	."<input type=\"hidden\" name=\"newDirPath\" value=\"$createDir\" />\n"
-	.get_lang('NameDir')." : \n"
-	."<input type=\"text\" name=\"newDirName\" />\n"
-	."<input type=\"submit\" value=\"".get_lang('Ok')."\" />\n"
-	."</form>\n";
-  }
+		/* STEP 2 */
 
-  /*======================================
-  	  VISIBILITY COMMANDS
-  ======================================*/
-  if (!empty($make_directory_visible) || !empty($make_directory_invisible))
-  {
-    $visibilityPath = $make_directory_visible.$make_directory_invisible;
-    // At least one of these variables are empty. So it's okay to proceed this way
-    /* Check if there is yet a record for this file in the DB */
-    $result = Database::query ("SELECT * FROM $tbl_document WHERE path LIKE '".$visibilityPath."'");
-    while($row = Database::fetch_array($result, 'ASSOC'))
-    {
-      $attribute['path'      ] = $row['path'      ];
-      $attribute['visibility'] = $row['visibility'];
-      $attribute['comment'   ] = $row['comment'   ];
-    }
+		if (isset($newDirPath) && isset($newDirName)) {
+			// echo $newDirPath . $newDirName;
+			$newDirName = replace_dangerous_char(trim(stripslashes($newDirName)), 'strict');
+			if (check_name_exist($baseWorkDir.$newDirPath.'/'.$newDirName)) {
+				$dialogBox = get_lang('FileExists');
+				$createDir = $newDirPath; unset($newDirPath);// return to step 1
+			} else {
+				if (mkdir($baseWorkDir.$newDirPath.'/'.$newDirName, api_get_permissions_for_new_directories()))
+				FileManager::set_default_settings($newDirPath, $newDirName, 'folder', $tbl_document);
+				// RH: was:  set_default_settings($newDirPath, $newDirName, 'folder');
+				$dialogBox = get_lang('DirCr');
+			}
+		}
+
+		/* STEP 1 */
+
+		if (isset($createDir)) {
+			$dialogBox .= "<!-- create dir -->\n"
+				."<form name='createdir' action='' method='POST'>\n"
+				."<input type=\"hidden\" name=\"newDirPath\" value=\"$createDir\" />\n"
+				.get_lang('NameDir')." : \n"
+				."<input type=\"text\" name=\"newDirName\" />\n"
+				."<input type=\"submit\" value=\"".get_lang('Ok')."\" />\n"
+				."</form>\n";
+  		}
+
+		/* VISIBILITY COMMANDS */
 
-    if ($make_directory_visible)
-    {
-      $newVisibilityStatus = "v";
-    }
-    elseif ($make_directory_invisible)
-    {
-      $newVisibilityStatus = "i";
-    }
-    $query = "UPDATE $tbl_document SET visibility='$newVisibilityStatus' WHERE path=\"".$visibilityPath."\""; //added by Toon
-    Database::query($query);
-    if (Database::affected_rows() == 0) // extra check added by Toon, normally not necessary anymore because all files are in the db
-    {
-      Database::query("INSERT INTO $tbl_document SET path=\"".$visibilityPath."\", visibility=\"".$newVisibilityStatus."\"");
-    }
-    unset($attribute);
-    $dialogBox = get_lang('ViMod');
-  }
- } // END is Allowed to Edit;
+  		if (!empty($make_directory_visible) || !empty($make_directory_invisible)) {
+  			$visibilityPath = $make_directory_visible.$make_directory_invisible;
+			// At least one of these variables are empty. So it's okay to proceed this way
+			/* Check if there is yet a record for this file in the DB */
+			$result = Database::query ("SELECT * FROM $tbl_document WHERE path LIKE '".$visibilityPath."'");
+			while($row = Database::fetch_array($result, 'ASSOC')) {
+				$attribute['path'      ] = $row['path'      ];
+				$attribute['visibility'] = $row['visibility'];
+				$attribute['comment'   ] = $row['comment'   ];
+			}
+
+			if ($make_directory_visible) {
+				$newVisibilityStatus = 'v';
+			} elseif ($make_directory_invisible) {
+				$newVisibilityStatus = 'i';
+			}
+			$query = "UPDATE $tbl_document SET visibility='$newVisibilityStatus' WHERE path=\"".$visibilityPath."\""; // Added by Toon.
+			Database::query($query);
+			if (Database::affected_rows() == 0) { // Extra check added by Toon, normally not necessary anymore because all files are in the db.
+				Database::query("INSERT INTO $tbl_document SET path=\"".$visibilityPath."\", visibility=\"".$newVisibilityStatus."\"");
+			}
+			unset($attribute);
+			$dialogBox = get_lang('ViMod');
+  		}
+	} // END is Allowed to edit;.
 }
-?>

Some files were not shown because too many files changed in this diff