diff --git a/main/newscorm/aicc.class.php b/main/newscorm/aicc.class.php
index 621ca8d8a6..5f384e4431 100755
--- a/main/newscorm/aicc.class.php
+++ b/main/newscorm/aicc.class.php
@@ -1,11 +1,13 @@
* @license GNU/GPL
*/
+
require_once 'aiccItem.class.php';
//require_once 'aiccMetadata.class.php';
//require_once 'aiccOrganization.class.php';
@@ -15,18 +17,18 @@ require_once 'aiccBlock.class.php';
class aicc extends learnpath {
public $config = array();
- public $config_basename = ''; //the configuration files might be multiple and might have
- //funny names. We need to keep the name of that file while we
- //install the content.
+ public $config_basename = ''; // The configuration files might be multiple and might have
+ // funny names. We need to keep the name of that file while we
+ // install the content.
public $config_files = array();
public $config_exts = array(
- 'crs'=>0, //Course description file (mandatory)
- 'au' =>0, //Assignable Unit file (mandatory)
- 'des'=>0, //Descriptor file (mandatory)
- 'cst'=>0, //Course structure file (mandatory)
- 'ore'=>0, //Objectives relationshops file (optional)
- 'pre'=>0, //Prerequisites file (optional)
- 'cmp'=>0 //Completion Requirements file (optional)
+ 'crs' => 0, // Course description file (mandatory)
+ 'au' => 0, // Assignable Unit file (mandatory)
+ 'des' => 0, // Descriptor file (mandatory)
+ 'cst' => 0, // Course structure file (mandatory)
+ 'ore' => 0, // Objectives relationshops file (optional)
+ 'pre' => 0, // Prerequisites file (optional)
+ 'cmp' => 0 // Completion Requirements file (optional)
);
public $aulist = array();
public $au_order_list = array();
@@ -35,214 +37,213 @@ class aicc extends learnpath {
public $cstlist = array();
public $orelist = array();
- public $subdir = ''; //path between the scorm/ directory and the config files e.g. maritime_nav/maritime_nav. This is the path that will be used in the lp_path when importing a package
- public $zipname = ''; //keeps the zipfile safe for the object's life so that we can use it if no title avail
- public $lastzipnameindex = 0; //keeps an index of the number of uses of the zipname so far
+ public $subdir = ''; // Path between the scorm/ directory and the config files e.g. maritime_nav/maritime_nav. This is the path that will be used in the lp_path when importing a package.
+ public $zipname = ''; // Keeps the zipfile safe for the object's life so that we can use it if there is no title available.
+ public $lastzipnameindex = 0; // Keeps an index of the number of uses of the zipname so far.
public $config_encoding = 'ISO-8859-1';
public $debug = 0;
+
/**
* Class constructor. Based on the parent constructor.
* @param string Course code
* @param integer Learnpath ID in DB
* @param integer User ID
*/
- public function __construct($course_code=null,$resource_id=null,$user_id=null) {
- if($this->debug>0){error_log('In aicc::aicc()',0);}
- if(!empty($course_code) and !empty($resource_id) and !empty($user_id))
- {
- parent::__construct($course_code, $resource_id, $user_id);
- }else{
- //do nothing but still build the aicc object
- }
- }
- /**
- * Opens a resource
- * @param integer Database ID of the resource
- */
- public function open($id)
- {
- if($this->debug>0){error_log('In aicc::open()',0);}
- // redefine parent method
- }
- /**
- * Parses a set of AICC config files and puts everything into the $config array
- * @param string Path to the config files dir on the system. If not defined, uses the base path of the course's scorm dir
+ public function __construct($course_code = null, $resource_id = null, $user_id = null) {
+ if ($this->debug > 0) { error_log('In aicc::aicc()', 0); }
+ if (!empty($course_code) && !empty($resource_id) && !empty($user_id)) {
+ parent::__construct($course_code, $resource_id, $user_id);
+ } else {
+ //do nothing but still build the aicc object
+ }
+ }
+
+ /**
+ * Opens a resource
+ * @param integer Database ID of the resource
+ */
+ public function open($id) {
+ if ($this->debug > 0) { error_log('In aicc::open()', 0); }
+ // Redefine parent method.
+ }
+
+ /**
+ * Parses a set of AICC config files and puts everything into the $config array
+ * @param string Path to the config files dir on the system. If not defined, uses the base path of the course's scorm dir
* @return array Structured array representing the config files' contents
- */
- function parse_config_files($dir='')
- {
- if($this->debug>0){error_log('New LP - In aicc::parse_config_files('.$dir.')',0);}
- if(empty($dir)){
- //get the path of the AICC config files dir
+ */
+ function parse_config_files($dir = '') {
+ if ($this->debug > 0) {error_log('New LP - In aicc::parse_config_files('.$dir.')', 0); }
+ if (empty($dir)) {
+ // Get the path of the AICC config files dir.
$dir = $this->subdir;
- }
- if(is_dir($dir) and is_readable($dir))
- {
- // Now go through all the config files one by one and parse everything into
- // AICC objects.
-
- // The basename for the config files is stored in $this->config_basename
-
- // Parse the Course Description File (.crs) - ini-type
- $crs_file = $dir.'/'.$this->config_files['crs'];
- $crs_params = $this->parse_ini_file_quotes_safe($crs_file);
- //echo '
crs:'.print_r($crs_params,true).'
';
- if($this->debug>1){error_log('New LP - In aicc::parse_config_files() - '.$crs_file.' has been parsed',0);}
-
- //CRS distribute crs params into the aicc object
- if(!empty($crs_params['course']['course_creator'])){
+ }
+ if (is_dir($dir) && is_readable($dir)) {
+ // Now go through all the config files one by one and parse everything into AICC objects.
+
+ // The basename for the config files is stored in $this->config_basename.
+
+ // Parse the Course Description File (.crs) - ini-type.
+ $crs_file = $dir.'/'.$this->config_files['crs'];
+ $crs_params = $this->parse_ini_file_quotes_safe($crs_file);
+ //echo 'crs:'.print_r($crs_params, true).'
';
+ if ($this->debug > 1) { error_log('New LP - In aicc::parse_config_files() - '.$crs_file.' has been parsed', 0); }
+
+ // CRS distribute crs params into the aicc object.
+ if (!empty($crs_params['course']['course_creator'])) {
$this->course_creator = Database::escape_string($crs_params['course']['course_creator']);
}
- if(!empty($crs_params['course']['course_id'])){
+ if (!empty($crs_params['course']['course_id'])) {
$this->course_id = Database::escape_string($crs_params['course']['course_id']);
}
- if(!empty($crs_params['course']['course_system'])){
+ if (!empty($crs_params['course']['course_system'])) {
$this->course_system = $crs_params['course']['course_system'];
}
- if(!empty($crs_params['course']['course_title'])){
+ if (!empty($crs_params['course']['course_title'])) {
$this->course_title = Database::escape_string($crs_params['course']['course_title']);
}
- if(!empty($crs_params['course']['course_level'])){
+ if (!empty($crs_params['course']['course_level'])) {
$this->course_level = $crs_params['course']['course_level'];
}
- if(!empty($crs_params['course']['max_fields_cst'])){
+ if (!empty($crs_params['course']['max_fields_cst'])) {
$this->course_max_fields_cst = $crs_params['course']['max_fields_cst'];
}
- if(!empty($crs_params['course']['max_fields_ort'])){
+ if (!empty($crs_params['course']['max_fields_ort'])) {
$this->course_max_fields_ort = $crs_params['course']['max_fields_ort'];
}
- if(!empty($crs_params['course']['total_aus'])){
+ if (!empty($crs_params['course']['total_aus'])) {
$this->course_total_aus = $crs_params['course']['total_aus'];
}
- if(!empty($crs_params['course']['total_blocks'])){
+ if (!empty($crs_params['course']['total_blocks'])) {
$this->course_total_blocks = $crs_params['course']['total_blocks'];
}
- if(!empty($crs_params['course']['total_objectives'])){
+ if (!empty($crs_params['course']['total_objectives'])) {
$this->course_total_objectives = $crs_params['course']['total_objectives'];
}
- if(!empty($crs_params['course']['total_complex_objectives'])){
+ if (!empty($crs_params['course']['total_complex_objectives'])) {
$this->course_total_complex_objectives = $crs_params['course']['total_complex_objectives'];
}
- if(!empty($crs_params['course']['version'])){
+ if (!empty($crs_params['course']['version'])) {
$this->course_version = $crs_params['course']['version'];
}
- if(!empty($crs_params['course_description'])){
+ if (!empty($crs_params['course_description'])) {
$this->course_description = Database::escape_string($crs_params['course_description']);
}
- // Parse the Descriptor File (.des) - csv-type
- $des_file = $dir.'/'.$this->config_files['des'];
- $des_params = $this->parse_csv_file($des_file);
- //echo 'des:'.print_r($des_params,true).'
';
- if($this->debug>1){error_log('New LP - In aicc::parse_config_files() - '.$des_file.' has been parsed',0);}
- //distribute des params into the aicc object
- foreach($des_params as $des){
- //one AU in AICC is equivalent to one SCO in SCORM (scormItem class)
- $oDes = new aiccResource('config',$des);
+ // Parse the Descriptor File (.des) - csv-type.
+ $des_file = $dir.'/'.$this->config_files['des'];
+ $des_params = $this->parse_csv_file($des_file);
+ //echo 'des:'.print_r($des_params, true).'
';
+ if ($this->debug > 1) { error_log('New LP - In aicc::parse_config_files() - '.$des_file.' has been parsed', 0); }
+ // Distribute des params into the aicc object.
+ foreach ($des_params as $des){
+ // One AU in AICC is equivalent to one SCO in SCORM (scormItem class).
+ $oDes = new aiccResource('config', $des);
$this->deslist[$oDes->identifier] = $oDes;
}
- // Parse the Assignable Unit File (.au) - csv-type
- $au_file = $dir.'/'.$this->config_files['au'];
- $au_params = $this->parse_csv_file($au_file);
- //echo 'au:'.print_r($au_params,true).'
';
- if($this->debug>1){error_log('New LP - In aicc::parse_config_files() - '.$au_file.' has been parsed',0);}
- //distribute au params into the aicc object
- foreach($au_params as $au){
- $oAu = new aiccItem('config',$au);
+ // Parse the Assignable Unit File (.au) - csv-type.
+ $au_file = $dir.'/'.$this->config_files['au'];
+ $au_params = $this->parse_csv_file($au_file);
+ //echo 'au:'.print_r($au_params, true).'
';
+ if ($this->debug > 1) { error_log('New LP - In aicc::parse_config_files() - '.$au_file.' has been parsed', 0); }
+ // Distribute au params into the aicc object.
+ foreach ($au_params as $au) {
+ $oAu = new aiccItem('config', $au);
$this->aulist[$oAu->identifier] = $oAu;
$this->au_order_list[] = $oAu->identifier;
}
- // Parse the Course Structure File (.cst) - csv-type
- $cst_file = $dir.'/'.$this->config_files['cst'];
- $cst_params = $this->parse_csv_file($cst_file,',','"',true);
- //echo 'cst:'.print_r($cst_params,true).'
';
- if($this->debug>1){error_log('New LP - In aicc::parse_config_files() - '.$cst_file.' has been parsed',0);}
- //distribute cst params into the aicc object
- foreach($cst_params as $cst){
- $oCst = new aiccBlock('config',$cst);
+ // Parse the Course Structure File (.cst) - csv-type.
+ $cst_file = $dir.'/'.$this->config_files['cst'];
+ $cst_params = $this->parse_csv_file($cst_file, ',', '"', true);
+ //echo 'cst:'.print_r($cst_params, true).'
';
+ if ($this->debug > 1) { error_log('New LP - In aicc::parse_config_files() - '.$cst_file.' has been parsed', 0); }
+ // Distribute cst params into the aicc object.
+ foreach ($cst_params as $cst) {
+ $oCst = new aiccBlock('config', $cst);
$this->cstlist[$oCst->identifier] = $oCst;
}
- // Parse the Objectives Relationships File (.ore) - csv-type - if exists
- //TODO @TODO implement these objectives. For now they're just parsed
- if(!empty($this->config_files['ore'])){
- $ore_file = $dir.'/'.$this->config_files['ore'];
- $ore_params = $this->parse_csv_file($ore_file,',','"',true);
- //echo 'ore:'.print_r($ore_params,true).'
';
- if($this->debug>1){error_log('New LP - In aicc::parse_config_files() - '.$ore_file.' has been parsed',0);}
- //distribute ore params into the aicc object
- foreach($ore_params as $ore){
- $oOre = new aiccObjective('config',$ore);
+ // Parse the Objectives Relationships File (.ore) - csv-type - if exists.
+ // TODO: Implement these objectives. For now they're just parsed.
+ if (!empty($this->config_files['ore'])) {
+ $ore_file = $dir.'/'.$this->config_files['ore'];
+ $ore_params = $this->parse_csv_file($ore_file, ',', '"', true);
+ //echo 'ore:'.print_r($ore_params,true).'
';
+ if ($this->debug > 1) { error_log('New LP - In aicc::parse_config_files() - '.$ore_file.' has been parsed', 0); }
+ // Distribute ore params into the aicc object.
+ foreach ($ore_params as $ore) {
+ $oOre = new aiccObjective('config', $ore);
$this->orelist[$oOre->identifier] = $oOre;
}
- }
-
- // Parse the Prerequisites File (.pre) - csv-type - if exists
- if(!empty($this->config_files['pre'])){
- $pre_file = $dir.'/'.$this->config_files['pre'];
- $pre_params = $this->parse_csv_file($pre_file);
- //echo 'pre:'.print_r($pre_params,true).'
';
- if($this->debug>1){error_log('New LP - In aicc::parse_config_files() - '.$pre_file.' has been parsed',0);}
- //distribute pre params into the aicc object
- foreach($pre_params as $pre){
- //place a constraint on the corresponding block or AU
- if(in_array(strtolower($pre['structure_element']),array_keys($this->cstlist))){
- //if this references a block element
+ }
+
+ // Parse the Prerequisites File (.pre) - csv-type - if exists.
+ if (!empty($this->config_files['pre'])) {
+ $pre_file = $dir.'/'.$this->config_files['pre'];
+ $pre_params = $this->parse_csv_file($pre_file);
+ //echo 'pre:'.print_r($pre_params, true).'
';
+ if ($this->debug > 1) { error_log('New LP - In aicc::parse_config_files() - '.$pre_file.' has been parsed', 0); }
+ // Distribute pre params into the aicc object.
+ foreach ($pre_params as $pre) {
+ // Place a constraint on the corresponding block or AU.
+ if (in_array(strtolower($pre['structure_element']), array_keys($this->cstlist))) {
+ // If this references a block element:
$this->cstlist[strtolower($pre['structure_element'])]->prereq_string = strtolower($pre['prerequisite']);
}
- if(in_array(strtolower($pre['structure_element']),array_keys($this->aulist))){
- //if this references a block element
+ if (in_array(strtolower($pre['structure_element']), array_keys($this->aulist))) {
+ // If this references a block element:
$this->aulist[strtolower($pre['structure_element'])]->prereq_string = strtolower($pre['prerequisite']);
}
}
- }
-
- // Parse the Completion Requirements File (.cmp) - csv-type - if exists
- //TODO @TODO implement this set of requirements (needs database changes)
- if(!empty($this->config_files['cmp'])){
- $cmp_file = $dir.'/'.$this->config_files['cmp'];
- $cmp_params = $this->parse_csv_file($cmp_file);
- //echo 'cmp:'.print_r($cmp_params,true).'
';
- if($this->debug>1){error_log('New LP - In aicc::parse_config_files() - '.$cmp_file.' has been parsed',0);}
- //distribute cmp params into the aicc object
- foreach($cmp_params as $cmp){
- //$oCmp = new aiccCompletionRequirements('config',$cmp);
+ }
+
+ // Parse the Completion Requirements File (.cmp) - csv-type - if exists.
+ // TODO: Implement this set of requirements (needs database changes).
+ if (!empty($this->config_files['cmp'])) {
+ $cmp_file = $dir.'/'.$this->config_files['cmp'];
+ $cmp_params = $this->parse_csv_file($cmp_file);
+ //echo 'cmp:'.print_r($cmp_params, true).'
';
+ if ($this->debug > 1) { error_log('New LP - In aicc::parse_config_files() - '.$cmp_file.' has been parsed', 0); }
+ // Distribute cmp params into the aicc object.
+ foreach ($cmp_params as $cmp) {
+ //$oCmp = new aiccCompletionRequirements('config', $cmp);
//$this->cmplist[$oCmp->identifier] =& $oCmp;
}
- }
- }
- return $this->config;
- }
- /**
- * Import the aicc object (as a result from the parse_config_files function) into the database structure
- * @param string Unique course code
- * @return bool Returns -1 on error
- */
- function import_aicc($course_code){
- if($this->debug>0){error_log('New LP - In aicc::import_aicc('.$course_code.')',0);}
- //get table names
- $new_lp = 'lp';
- $new_lp_item = 'lp_item';
-
- //The previous method wasn't safe to get the database name, so do it manually with the course_code
- $sql = "SELECT * FROM ".Database::get_main_table(TABLE_MAIN_COURSE)." WHERE code='$course_code'";
- $res = Database::query($sql);
- if(Database::num_rows($res)<1){ error_log('New LP - Database for '.$course_code.' not found '.__FILE__.' '.__LINE__,0);return -1;}
- $row = Database::fetch_array($res);
- $dbname = Database::get_course_table_prefix().$row['db_name'].Database::get_database_glue();
+ }
+ }
+ return $this->config;
+ }
+
+ /**
+ * Import the aicc object (as a result from the parse_config_files function) into the database structure
+ * @param string Unique course code
+ * @return bool Returns -1 on error
+ */
+ function import_aicc($course_code) {
+ if ($this->debug > 0) { error_log('New LP - In aicc::import_aicc('.$course_code.')', 0); }
+ // Get table names.
+ $new_lp = 'lp';
+ $new_lp_item = 'lp_item';
+
+ // The previous method wasn't safe to get the database name, so do it manually with the course_code.
+ $sql = "SELECT * FROM ".Database::get_main_table(TABLE_MAIN_COURSE)." WHERE code='$course_code'";
+ $res = Database::query($sql);
+ if (Database::num_rows($res) < 1) { error_log('New LP - Database for '.$course_code.' not found '.__FILE__.' '.__LINE__, 0); return -1; }
+ $row = Database::fetch_array($res);
+ $dbname = Database::get_course_table_prefix().$row['db_name'].Database::get_database_glue();
$new_lp = Database::get_course_table(TABLE_LP_MAIN);
$new_lp_item = Database::get_course_table(TABLE_LP_ITEM);
- $get_max = "SELECT MAX(display_order) FROM $new_lp";
- $res_max = Database::query($get_max);
- if(Database::num_rows($res_max)<1){
- $dsp = 1;
- }else{
- $row = Database::fetch_array($res_max);
- $dsp = $row[0]+1;
- }
+ $get_max = "SELECT MAX(display_order) FROM $new_lp";
+ $res_max = Database::query($get_max);
+ if (Database::num_rows($res_max) < 1) {
+ $dsp = 1;
+ } else {
+ $row = Database::fetch_array($res_max);
+ $dsp = $row[0] + 1;
+ }
$this->config_encoding = "ISO-8859-1";
@@ -254,35 +255,34 @@ class aicc extends learnpath {
"(3,'".$this->course_title."', '".$this->course_id."','".$this->course_description."'," .
"'".$this->subdir."', 0, 'embedded', '".$this->config_encoding."'," .
"'aicc_api.php','".$this->course_creator."',$dsp)";
- if($this->debug>2){error_log('New LP - In import_aicc(), inserting path: '. $sql,0);}
+ if ($this->debug > 2) { error_log('New LP - In import_aicc(), inserting path: '. $sql, 0); }
$res = Database::query($sql);
$lp_id = Database::insert_id();
$this->lp_id = $lp_id;
- api_item_property_update(api_get_course_info($course_code),TOOL_LEARNPATH,$this->lp_id,'LearnpathAdded',api_get_user_id());
- api_item_property_update(api_get_course_info($course_code),TOOL_LEARNPATH,$this->lp_id,'visible',api_get_user_id());
+ api_item_property_update(api_get_course_info($course_code), TOOL_LEARNPATH, $this->lp_id, 'LearnpathAdded', api_get_user_id());
+ api_item_property_update(api_get_course_info($course_code), TOOL_LEARNPATH, $this->lp_id, 'visible', api_get_user_id());
$previous = 0;
- foreach($this->aulist as $identifier => $dummy)
- {
+ foreach ($this->aulist as $identifier => $dummy) {
$oAu =& $this->aulist[$identifier];
//echo "Item ".$oAu->identifier;
$field_add = '';
$value_add = '';
- if(!empty($oAu->masteryscore)){
+ if (!empty($oAu->masteryscore)) {
$field_add = 'mastery_score, ';
$value_add = $oAu->masteryscore.',';
}
$title = $oAu->identifier;
- if(is_object($this->deslist[$identifier])){
+ if (is_object($this->deslist[$identifier])) {
$title = $this->deslist[$identifier]->title;
}
$path = $oAu->path;
- //$max_score = $oAu->max_score //TODO check if special constraint exists for this item
- //$min_score = $oAu->min_score //TODO check if special constraint exists for this item
- $parent = 0; //TODO deal with parent
+ //$max_score = $oAu->max_score // TODO: Check if special constraint exists for this item.
+ //$min_score = $oAu->min_score // TODO: Check if special constraint exists for this item.
+ $parent = 0; // TODO: Deal with the parent.
$previous = 0;
$prereq = $oAu->prereq_string;
- //$previous = (!empty($this->au_order_list_new_id[x])?$this->au_order_list_new_id[x]:0); //TODO deal with previous
+ //$previous = (!empty($this->au_order_list_new_id[x]) ? $this->au_order_list_new_id[x] : 0); // TODO: Deal with the previous.
$sql_item = "INSERT INTO $new_lp_item " .
"(lp_id,item_type,ref,title," .
"path,min_score,max_score, $field_add" .
@@ -295,372 +295,353 @@ class aicc extends learnpath {
"'$prereq', 0" .
")";
$res_item = Database::query($sql_item);
- if($this->debug>1){error_log('New LP - In aicc::import_aicc() - inserting item : '.$sql_item.' : '.Database::error(),0);}
+ if ($this->debug > 1) { error_log('New LP - In aicc::import_aicc() - inserting item : '.$sql_item.' : '.Database::error(), 0); }
$item_id = Database::insert_id();
- //now update previous item to change next_item_id
- if($previous != 0){
+ // Now update previous item to change next_item_id.
+ if ($previous != 0) {
$upd = "UPDATE $new_lp_item SET next_item_id = $item_id WHERE id = $previous";
$upd_res = Database::query($upd);
- //update previous item id
+ // Update the previous item id.
}
$previous = $item_id;
}
- }
- /**
- * Intermediate to import_package only to allow import from local zip files
- * @param string Path to the zip file, from the dokeos sys root
- * @param string Current path (optional)
- * @return string Absolute path to the AICC description files or empty string on error
- */
- function import_local_package($file_path,$current_dir='')
- {
- //todo prepare info as given by the $_FILES[''] vector
- $file_info = array();
- $file_info['tmp_name'] = $file_path;
- $file_info['name'] = basename($file_path);
- //call the normal import_package function
- return $this->import_package($file_info,$current_dir);
- }
- /**
- * Imports a zip file (presumably AICC) into the Dokeos structure
- * @param string Zip file info as given by $_FILES['userFile']
- * @return string Absolute path to the AICC config files directory or empty string on error
- */
- function import_package($zip_file_info,$current_dir = '')
- {
- if($this->debug>0){error_log('In aicc::import_package('.print_r($zip_file_info,true).',"'.$current_dir.'") method',0);}
- //ini_set('error_log','E_ALL');
- $maxFilledSpace = 1000000000;
- $zip_file_path = $zip_file_info['tmp_name'];
- $zip_file_name = $zip_file_info['name'];
-
- if($this->debug>0){error_log('New LP - aicc::import_package() - Zip file path = '.$zip_file_path.', zip file name = '.$zip_file_name,0);}
- $course_rel_dir = api_get_course_path().'/scorm'; //scorm dir web path starting from /courses
- $course_sys_dir = api_get_path(SYS_COURSE_PATH).$course_rel_dir; //absolute system path for this course
- $current_dir = replace_dangerous_char(trim($current_dir),'strict'); //current dir we are in, inside scorm/
- if($this->debug>0){error_log('New LP - aicc::import_package() - Current_dir = '.$current_dir,0);}
+ }
+
+ /**
+ * Intermediate to import_package only to allow import from local zip files
+ * @param string Path to the zip file, from the dokeos sys root
+ * @param string Current path (optional)
+ * @return string Absolute path to the AICC description files or empty string on error
+ */
+ function import_local_package($file_path, $current_dir = '') {
+ // TODO: Prepare info as given by the $_FILES[''] vector.
+ $file_info = array();
+ $file_info['tmp_name'] = $file_path;
+ $file_info['name'] = basename($file_path);
+ // Call the normal import_package function.
+ return $this->import_package($file_info,$current_dir);
+ }
+
+ /**
+ * Imports a zip file (presumably AICC) into the Dokeos structure
+ * @param string Zip file info as given by $_FILES['userFile']
+ * @return string Absolute path to the AICC config files directory or empty string on error
+ */
+ function import_package($zip_file_info, $current_dir = '') {
+ if ($this->debug > 0) { error_log('In aicc::import_package('.print_r($zip_file_info, true).',"'.$current_dir.'") method', 0); }
+ //ini_set('error_log', 'E_ALL');
+ $maxFilledSpace = 1000000000;
+ $zip_file_path = $zip_file_info['tmp_name'];
+ $zip_file_name = $zip_file_info['name'];
+
+ if ($this->debug > 0) { error_log('New LP - aicc::import_package() - Zip file path = '.$zip_file_path.', zip file name = '.$zip_file_name, 0); }
+ $course_rel_dir = api_get_course_path().'/scorm'; // Scorm dir web path starting from /courses
+ $course_sys_dir = api_get_path(SYS_COURSE_PATH).$course_rel_dir; // The absolute system path of this course.
+ $current_dir = replace_dangerous_char(trim($current_dir),'strict'); // Current dir we are in, inside scorm/
+ if ($this->debug > 0) { error_log('New LP - aicc::import_package() - Current_dir = '.$current_dir, 0); }
//$uploaded_filename = $_FILES['userFile']['name'];
- //get name of the zip file without the extension
- if($this->debug>0){error_log('New LP - aicc::import_package() - Received zip file name: '.$zip_file_path,0);}
+ // Get the name of the zip file without the extension.
+ if ($this->debug > 0) { error_log('New LP - aicc::import_package() - Received zip file name: '.$zip_file_path, 0); }
$file_info = pathinfo($zip_file_name);
$filename = $file_info['basename'];
$extension = $file_info['extension'];
- $file_base_name = str_replace('.'.$extension,'',$filename); //filename without its extension
- $this->zipname = $file_base_name; //save for later in case we don't have a title
+ $file_base_name = str_replace('.'.$extension, '', $filename); // Filename without its extension.
+ $this->zipname = $file_base_name; // Save for later in case we don't have a title.
- if($this->debug>0){error_log('New LP - aicc::import_package() - Base file name is : '.$file_base_name,0);}
+ if ($this->debug > 0) { error_log('New LP - aicc::import_package() - Base file name is : '.$file_base_name, 0); }
$new_dir = replace_dangerous_char(trim($file_base_name),'strict');
$this->subdir = $new_dir;
- if($this->debug>0){error_log('New LP - aicc::import_package() - Subdir is first set to : '.$this->subdir,0);}
+ if($this->debug > 0) { error_log('New LP - aicc::import_package() - Subdir is first set to : '.$this->subdir, 0); }
-/*
- if( check_name_exist($course_sys_dir.$current_dir."/".$new_dir) )
- {
+ /*
+ if (check_name_exist($course_sys_dir.$current_dir.'/'.$new_dir)) {
$dialogBox = get_lang('FileExists');
$stopping_error = true;
}
-*/
+ */
$zipFile = new pclZip($zip_file_path);
- // Check the zip content (real size and file extension)
+ // Check the zip content (real size and file extension).
$zipContentArray = $zipFile->listContent();
- $package_type=''; //the type of the package. Should be 'aicc' after the next few lines
- $package = ''; //the basename of the config files (if 'courses.crs' => 'courses')
- $at_root = false; //check if the config files are at zip root
- $config_dir = ''; //the directory in which the config files are. May remain empty
+ $package_type = ''; // The type of the package. Should be 'aicc' after the next few lines.
+ $package = ''; // The basename of the config files (if 'courses.crs' => 'courses').
+ $at_root = false; // Check if the config files are at zip root.
+ $config_dir = ''; // The directory in which the config files are. May remain empty.
$files_found = array();
$subdir_isset = false;
- //the following loop should be stopped as soon as we found the right config files (.crs, .au, .des and .cst)
- foreach($zipContentArray as $thisContent)
- {
- if ( preg_match('~.(php.*|phtml)$~i', $thisContent['filename']) )
- {
- //if a php file is found, do not authorize (security risk)
- if($this->debug>1){error_log('New LP - aicc::import_package() - Found unauthorized file: '.$thisContent['filename'],0);}
+ // The following loop should be stopped as soon as we found the right config files (.crs, .au, .des and .cst).
+ foreach ($zipContentArray as $thisContent) {
+ if (preg_match('~.(php.*|phtml)$~i', $thisContent['filename'])) {
+ // If a php file is found, do not authorize (security risk).
+ if ($this->debug > 1) {error_log('New LP - aicc::import_package() - Found unauthorized file: '.$thisContent['filename'], 0); }
return api_failure::set_failure('php_file_in_zip_file');
- }elseif(preg_match('?.*/aicc/$?',$thisContent['filename'])){
- //if a directory named 'aicc' is found, package type = aicc, but continue
- //because we need to find the right AICC files
- if($this->debug>1){error_log('New LP - aicc::import_package() - Found aicc directory: '.$thisContent['filename'],0);}
+ } elseif (preg_match('?.*/aicc/$?', $thisContent['filename'])) {
+ // If a directory named 'aicc' is found, package type = aicc, but continue,
+ // because we need to find the right AICC files;
+ if ($this->debug > 1) { error_log('New LP - aicc::import_package() - Found aicc directory: '.$thisContent['filename'], 0); }
$package_type = 'aicc';
- }else{
- //else, look for one of the files we're searching for (something.crs case insensitive)
+ } else {
+ // else, look for one of the files we're searching for (something.crs case insensitive).
$res = array();
- if(preg_match('?^(.*)\.(crs|au|des|cst|ore|pre|cmp)$?i',$thisContent['filename'],$res))
- {
- if($this->debug>1){error_log('New LP - aicc::import_package() - Found AICC config file: '.$thisContent['filename'].'. Now splitting: '.$res[1].' and '.$res[2],0);}
- if($thisContent['filename'] == basename($thisContent['filename'])){
- if($this->debug>2){error_log('New LP - aicc::import_package() - '.$thisContent['filename'].' is at root level',0);}
+ if (preg_match('?^(.*)\.(crs|au|des|cst|ore|pre|cmp)$?i', $thisContent['filename'], $res)) {
+ if ($this->debug > 1) { error_log('New LP - aicc::import_package() - Found AICC config file: '.$thisContent['filename'].'. Now splitting: '.$res[1].' and '.$res[2], 0); }
+ if ($thisContent['filename'] == basename($thisContent['filename'])) {
+ if ($this->debug > 2) { error_log('New LP - aicc::import_package() - '.$thisContent['filename'].' is at root level', 0); }
$at_root = true;
- if(!is_array($files_found[$res[1]])){
- $files_found[$res[1]] = $this->config_exts; //initialise list of expected extensions (defined in class definition)
+ if (!is_array($files_found[$res[1]])) {
+ $files_found[$res[1]] = $this->config_exts; // Initialise list of expected extensions (defined in class definition).
}
$files_found[$res[1]][strtolower($res[2])] = $thisContent['filename'];
$subdir_isset = true;
- }else{
- if(!$subdir_isset){
- if(preg_match('?^.*/aicc$?i',dirname($thisContent['filename']))){
+ } else {
+ if (!$subdir_isset) {
+ if (preg_match('?^.*/aicc$?i',dirname($thisContent['filename']))) {
//echo "Cutting subdir
";
- $this->subdir .= '/'.substr(dirname($thisContent['filename']),0,-5);
- }else{
+ $this->subdir .= '/'.substr(dirname($thisContent['filename']), 0, -5);
+ } else {
//echo "Not cutting subdir
";
$this->subdir .= '/'.dirname($thisContent['filename']);
}
$subdir_isset = true;
}
- if($this->debug>2){error_log('New LP - aicc::import_package() - '.$thisContent['filename'].' is not at root level - recording subdir '.$this->subdir,0);}
- $config_dir = dirname($thisContent['filename']); //just the relative directory inside scorm/
- if(!is_array($files_found[basename($res[1])])){
+ if ($this->debug > 2) { error_log('New LP - aicc::import_package() - '.$thisContent['filename'].' is not at root level - recording subdir '.$this->subdir, 0); }
+ $config_dir = dirname($thisContent['filename']); // Just the relative directory inside scorm/
+ if (!is_array($files_found[basename($res[1])])) {
$files_found[basename($res[1])] = $this->config_exts;
}
$files_found[basename($res[1])][strtolower($res[2])] = basename($thisContent['filename']);
}
$package_type = 'aicc';
- }else{
- if($this->debug>3){error_log('New LP - aicc::import_package() - File '.$thisContent['filename'].' didnt match any check',0);}
+ } else {
+ if ($this->debug > 3) { error_log('New LP - aicc::import_package() - File '.$thisContent['filename'].' didnt match any check', 0); }
}
}
$realFileSize += $thisContent['size'];
}
- if($this->debug>2){error_log('New LP - aicc::import_package() - $files_found: '.print_r($files_found,true),0);}
- if($this->debug>1){error_log('New LP - aicc::import_package() - Package type is now '.$package_type,0);}
+ if ($this->debug > 2) { error_log('New LP - aicc::import_package() - $files_found: '.print_r($files_found, true), 0); }
+ if ($this->debug > 1) { error_log('New LP - aicc::import_package() - Package type is now '.$package_type, 0); }
$mandatory = false;
- foreach($files_found as $file_name => $file_exts){
+ foreach ($files_found as $file_name => $file_exts) {
$temp = (
!empty($files_found[$file_name]['crs'])
AND !empty($files_found[$file_name]['au'])
AND !empty($files_found[$file_name]['des'])
AND !empty($files_found[$file_name]['cst'])
);
- if($temp){
- if($this->debug>1){error_log('New LP - aicc::import_package() - Found all config files for '.$file_name,0);}
+ if ($temp) {
+ if ($this->debug > 1) { error_log('New LP - aicc::import_package() - Found all config files for '.$file_name, 0); }
$mandatory = true;
$package = $file_name;
- //store base config file name for reuse in parse_config_files()
+ // Store base config file name for reuse in parse_config_files().
$this->config_basename = $file_name;
- //store filenames for reuse in parse_config_files()
+ // Store filenames for reuse in parse_config_files().
$this->config_files = $files_found[$file_name];
- //get out, we only want one config files set
+ // Get out, we only want one config files set.
break;
}
}
if ($package_type == '' || !$mandatory)
- // && defined('CHECK_FOR_AICC') && CHECK_FOR_AICC)
+ // && defined('CHECK_FOR_AICC') && CHECK_FOR_AICC)
{
return api_failure::set_failure('not_aicc_content');
}
- if (! enough_size($realFileSize, $course_sys_dir, $maxFilledSpace) )
- {
+ if (!enough_size($realFileSize, $course_sys_dir, $maxFilledSpace)) {
return api_failure::set_failure('not_enough_space');
}
- // it happens on Linux that $new_dir sometimes doesn't start with '/'
- if($new_dir[0] != '/')
- {
- $new_dir='/'.$new_dir;
+ // It happens on Linux that $new_dir sometimes doesn't start with '/'
+ if ($new_dir[0] != '/') {
+ $new_dir = '/'.$new_dir;
}
- //cut trailing slash
- if($new_dir[strlen($new_dir)-1] == '/')
- {
- $new_dir=substr($new_dir,0,-1);
+ // Cut trailing slash.
+ if ($new_dir[strlen($new_dir) - 1] == '/') {
+ $new_dir = substr($new_dir, 0, -1);
}
- /*
- --------------------------------------
- Uncompressing phase
- --------------------------------------
- */
+ /* Uncompressing phase */
+
/*
We need to process each individual file in the zip archive to
- add it to the database
- parse & change relative html links
- make sure the filenames are secure (filter funny characters or php extensions)
*/
- if(is_dir($course_sys_dir.$new_dir) OR @mkdir($course_sys_dir.$new_dir, api_get_permissions_for_new_directories()))
- {
+ if (is_dir($course_sys_dir.$new_dir) OR @mkdir($course_sys_dir.$new_dir, api_get_permissions_for_new_directories())) {
// PHP method - slower...
- if($this->debug>=1){error_log('New LP - Changing dir to '.$course_sys_dir.$new_dir,0);}
+ if ($this->debug >= 1) { error_log('New LP - Changing dir to '.$course_sys_dir.$new_dir, 0); }
$saved_dir = getcwd();
chdir($course_sys_dir.$new_dir);
$unzippingState = $zipFile->extract();
- for($j=0;$jdebug>1){error_log('New LP - found extension '.$extension.' in '.$state['stored_filename'],0);}
+ // TODO: Fix relative links in html files (?)
+ $extension = strrchr($state["stored_filename"], '.');
+ //if ($this->debug > 1) { error_log('New LP - found extension '.$extension.' in '.$state['stored_filename'], 0); }
}
- if(!empty($new_dir))
- {
+ if (!empty($new_dir)) {
$new_dir = $new_dir.'/';
}
- //rename files, for example with \\ in it
- if($dir=@opendir($course_sys_dir.$new_dir))
- {
- if($this->debug==1){error_log('New LP - Opened dir '.$course_sys_dir.$new_dir,0);}
- while($file=readdir($dir))
- {
- if($file != '.' && $file != '..')
- {
- $filetype="file";
+ // Rename files, for example with \\ in it.
+ if ($dir = @opendir($course_sys_dir.$new_dir)) {
+ if ($this->debug == 1) { error_log('New LP - Opened dir '.$course_sys_dir.$new_dir, 0); }
+ while ($file = readdir($dir)) {
+ if ($file != '.' && $file != '..') {
+ $filetype = 'file';
- if(is_dir($course_sys_dir.$new_dir.$file)) $filetype="folder";
+ if (is_dir($course_sys_dir.$new_dir.$file)) $filetype = 'folder';
- //TODO RENAMING FILES CAN BE VERY DANGEROUS AICC-WISE, avoid that as much as possible!
- //$safe_file=replace_dangerous_char($file,'strict');
+ // TODO: RENAMING FILES CAN BE VERY DANGEROUS AICC-WISE, avoid that as much as possible!
+ //$safe_file = replace_dangerous_char($file, 'strict');
$find_str = array('\\','.php','.phtml');
$repl_str = array('/', '.txt','.txt');
- $safe_file = str_replace($find_str,$repl_str,$file);
+ $safe_file = str_replace($find_str, $repl_str, $file);
- if($safe_file != $file){
- //@rename($course_sys_dir.$new_dir,$course_sys_dir.'/'.$safe_file);
+ if ($safe_file != $file) {
+ //@rename($course_sys_dir.$new_dir, $course_sys_dir.'/'.$safe_file);
$mydir = dirname($course_sys_dir.$new_dir.$safe_file);
- if(!is_dir($mydir)){
- $mysubdirs = split('/',$mydir);
+ if (!is_dir($mydir)) {
+ $mysubdirs = split('/', $mydir);
$mybasedir = '/';
- foreach($mysubdirs as $mysubdir){
- if(!empty($mysubdir)){
+ foreach ($mysubdirs as $mysubdir) {
+ if (!empty($mysubdir)) {
$mybasedir = $mybasedir.$mysubdir.'/';
- if(!is_dir($mybasedir)){
+ if (!is_dir($mybasedir)) {
@mkdir($mybasedir, api_get_permissions_for_new_directories());
- if($this->debug==1){error_log('New LP - Dir '.$mybasedir.' doesnt exist. Creating.',0);}
+ if ($this->debug == 1) { error_log('New LP - Dir '.$mybasedir.' doesnt exist. Creating.', 0); }
}
}
}
}
- @rename($course_sys_dir.$new_dir.$file,$course_sys_dir.$new_dir.$safe_file);
- if($this->debug==1){error_log('New LP - Renaming '.$course_sys_dir.$new_dir.$file.' to '.$course_sys_dir.$new_dir.$safe_file,0);}
+ @rename($course_sys_dir.$new_dir.$file, $course_sys_dir.$new_dir.$safe_file);
+ if ($this->debug == 1) { error_log('New LP - Renaming '.$course_sys_dir.$new_dir.$file.' to '.$course_sys_dir.$new_dir.$safe_file, 0); }
}
- //set_default_settings($course_sys_dir,$safe_file,$filetype);
+ //set_default_settings($course_sys_dir, $safe_file, $filetype);
}
}
closedir($dir);
chdir($saved_dir);
}
- }else{
+ } else {
return '';
}
return $course_sys_dir.$new_dir.$config_dir;
}
+
/**
* Sets the proximity setting in the database
* @param string Proximity setting
*/
- function set_proximity($proxy=''){
- if($this->debug>0){error_log('In aicc::set_proximity('.$proxy.') method',0);}
- $lp = $this->get_id();
- if($lp!=0){
- $tbl_lp = Database::get_course_table(TABLE_LP_MAIN);
- $sql = "UPDATE $tbl_lp SET content_local = '$proxy' WHERE id = ".$lp;
- $res = Database::query($sql);
- return $res;
- }else{
- return false;
- }
- }
-
- /**
+ function set_proximity($proxy = '') {
+ if ($this->debug > 0) { error_log('In aicc::set_proximity('.$proxy.') method', 0); }
+ $lp = $this->get_id();
+ if ($lp != 0) {
+ $tbl_lp = Database::get_course_table(TABLE_LP_MAIN);
+ $sql = "UPDATE $tbl_lp SET content_local = '$proxy' WHERE id = ".$lp;
+ $res = Database::query($sql);
+ return $res;
+ } else {
+ return false;
+ }
+ }
+
+ /**
* Sets the theme setting in the database
* @param string Theme setting
*/
- function set_theme($theme=''){
- if($this->debug>0){error_log('In aicc::set_theme('.$theme.') method',0);}
- $lp = $this->get_id();
- if($lp!=0){
- $tbl_lp = Database::get_course_table(TABLE_LP_MAIN);
- $sql = "UPDATE $tbl_lp SET theme = '$theme' WHERE id = ".$lp;
- $res = Database::query($sql);
- return $res;
- }else{
- return false;
- }
- }
-
- /**
+ function set_theme($theme = '') {
+ if ($this->debug > 0) { error_log('In aicc::set_theme('.$theme.') method', 0); }
+ $lp = $this->get_id();
+ if ($lp != 0) {
+ $tbl_lp = Database::get_course_table(TABLE_LP_MAIN);
+ $sql = "UPDATE $tbl_lp SET theme = '$theme' WHERE id = ".$lp;
+ $res = Database::query($sql);
+ return $res;
+ } else {
+ return false;
+ }
+ }
+
+ /**
* Sets the image LP in the database
* @param string Theme setting
*/
- function set_preview_image($preview_image=''){
- if($this->debug>0){error_log('In aicc::set_preview_image('.$preview_image.') method',0);}
- $lp = $this->get_id();
- if($lp!=0){
- $tbl_lp = Database::get_course_table(TABLE_LP_MAIN);
- $sql = "UPDATE $tbl_lp SET preview_image = '$preview_image' WHERE id = ".$lp;
- $res = Database::query($sql);
- return $res;
- }else{
- return false;
- }
- }
-
- /**
+ function set_preview_image($preview_image = '') {
+ if ($this->debug > 0) {error_log('In aicc::set_preview_image('.$preview_image.') method', 0); }
+ $lp = $this->get_id();
+ if ($lp != 0) {
+ $tbl_lp = Database::get_course_table(TABLE_LP_MAIN);
+ $sql = "UPDATE $tbl_lp SET preview_image = '$preview_image' WHERE id = ".$lp;
+ $res = Database::query($sql);
+ return $res;
+ } else {
+ return false;
+ }
+ }
+
+ /**
* Sets the Author LP in the database
* @param string Theme setting
*/
- function set_author($author=''){
- if($this->debug>0){error_log('In aicc::set_author('.$author.') method',0);}
- $lp = $this->get_id();
- if($lp!=0){
- $tbl_lp = Database::get_course_table(TABLE_LP_MAIN);
- $sql = "UPDATE $tbl_lp SET author = '$author' WHERE id = ".$lp;
- $res = Database::query($sql);
- return $res;
- }else{
- return false;
- }
- }
-
-
+ function set_author($author = '') {
+ if ($this->debug > 0) { error_log('In aicc::set_author('.$author.') method', 0); }
+ $lp = $this->get_id();
+ if ($lp != 0) {
+ $tbl_lp = Database::get_course_table(TABLE_LP_MAIN);
+ $sql = "UPDATE $tbl_lp SET author = '$author' WHERE id = ".$lp;
+ $res = Database::query($sql);
+ return $res;
+ } else {
+ return false;
+ }
+ }
/**
* Sets the content maker setting in the database
* @param string Proximity setting
*/
- function set_maker($maker=''){
- if($this->debug>0){error_log('In aicc::set_maker method('.$maker.')',0);}
- $lp = $this->get_id();
- if($lp!=0){
- $tbl_lp = Database::get_course_table(TABLE_LP_MAIN);
- $sql = "UPDATE $tbl_lp SET content_maker = '$maker' WHERE id = ".$lp;
- $res = Database::query($sql);
- return $res;
- }else{
- return false;
- }
- }
- /**
- * Exports the current AICC object's files as a zip. Excerpts taken from learnpath_functions.inc.php::exportpath()
- * @param integer Learnpath ID (optional, taken from object context if not defined)
- */
- function export_zip($lp_id=null){
- if($this->debug>0){error_log('In aicc::export_zip method('.$lp_id.')',0);}
- if(empty($lp_id)){
- if(!is_object($this))
- {
+ function set_maker($maker = '') {
+ if ($this->debug > 0) { error_log('In aicc::set_maker method('.$maker.')', 0); }
+ $lp = $this->get_id();
+ if ($lp != 0) {
+ $tbl_lp = Database::get_course_table(TABLE_LP_MAIN);
+ $sql = "UPDATE $tbl_lp SET content_maker = '$maker' WHERE id = ".$lp;
+ $res = Database::query($sql);
+ return $res;
+ } else {
+ return false;
+ }
+ }
+
+ /**
+ * Exports the current AICC object's files as a zip. Excerpts taken from learnpath_functions.inc.php::exportpath()
+ * @param integer Learnpath ID (optional, taken from object context if not defined)
+ */
+ function export_zip($lp_id = null) {
+ if ($this->debug > 0) { error_log('In aicc::export_zip method('.$lp_id.')', 0); }
+ if (empty($lp_id)) {
+ if (!is_object($this)) {
return false;
- }
- else{
+ } else {
$id = $this->get_id();
- if(empty($id)){
+ if (empty($id)) {
return false;
+ } else {
+ $lp_id = $this->get_id();
}
- else{
- $lp_id = $this->get_id();
- }
- }
- }
- //error_log('New LP - in export_zip()',0);
- //zip everything that is in the corresponding scorm dir
- //write the zip file somewhere (might be too big to return)
+ }
+ }
+ //error_log('New LP - in export_zip()', 0);
+ // Zip everything that is in the corresponding scorm dir.
+ // Write the zip file somewhere (might be too big to return).
require_once api_get_path(LIBRARY_PATH).'fileUpload.lib.php';
require_once api_get_path(LIBRARY_PATH).'fileManage.lib.php';
require_once api_get_path(LIBRARY_PATH).'document.lib.php';
@@ -681,14 +662,14 @@ class aicc extends learnpath {
$scormfoldername = api_get_path(SYS_COURSE_PATH).$_course['directory'].'/scorm/'.$LPnamesafe;
$zipfilename = $zipfoldername.'/'.$LPnamesafe.'.zip';
- // Get a temporary dir for creating the zip file
+ // Get a temporary dir for creating the zip file.
//error_log('New LP - cleaning dir '.$zipfoldername, 0);
deldir($zipfoldername); //make sure the temp dir is cleared
mkdir($zipfoldername, api_get_permissions_for_new_directories());
//error_log('New LP - made dir '.$zipfoldername, 0);
- //create zipfile of given directory
+ // Create zipfile of given directory.
$zip_folder = new PclZip($zipfilename);
$zip_folder->create($scormfoldername.'/', PCLZIP_OPT_REMOVE_PATH, $scormfoldername.'/');
@@ -701,279 +682,253 @@ class aicc extends learnpath {
my_delete($zipfilename);
my_delete($zipfoldername);
-
return true;
}
+
/**
- * Gets a resource's path if available, otherwise return empty string
- * @param string Resource ID as used in resource array
- * @return string The resource's path as declared in config file course.crs
- */
- function get_res_path($id){
- if($this->debug>0){error_log('In aicc::get_res_path('.$id.') method',0);}
- $path = '';
- if(isset($this->resources[$id])){
+ * Gets a resource's path if available, otherwise return empty string
+ * @param string Resource ID as used in resource array
+ * @return string The resource's path as declared in config file course.crs
+ */
+ function get_res_path($id) {
+ if ($this->debug > 0) { error_log('In aicc::get_res_path('.$id.') method', 0); }
+ $path = '';
+ if (isset($this->resources[$id])) {
$oRes =& $this->resources[$id];
$path = @$oRes->get_path();
}
return $path;
- }
- /**
- * Gets a resource's type if available, otherwise return empty string
- * @param string Resource ID as used in resource array
- * @return string The resource's type as declared in the assignable unit (.au) file
- */
- function get_res_type($id){
- if($this->debug>0){error_log('In aicc::get_res_type('.$id.') method',0);}
- $type = '';
- if(isset($this->resources[$id])){
+ }
+
+ /**
+ * Gets a resource's type if available, otherwise return empty string
+ * @param string Resource ID as used in resource array
+ * @return string The resource's type as declared in the assignable unit (.au) file
+ */
+ function get_res_type($id) {
+ if ($this->debug > 0) { error_log('In aicc::get_res_type('.$id.') method', 0); }
+ $type = '';
+ if (isset($this->resources[$id])) {
$oRes =& $this->resources[$id];
$temptype = $oRes->get_scorm_type();
- if(!empty($temptype)){
+ if (!empty($temptype)) {
$type = $temptype;
}
}
return $type;
- }
- /**
- * Gets the default organisation's title
- * @return string The organization's title
- */
- function get_title(){
- if($this->debug>0){error_log('In aicc::get_title() method',0);}
- $title = '';
- if(isset($this->config['organizations']['default'])){
- $title = $this->organizations[$this->config['organizations']['default']]->get_name();
- }elseif(count($this->organizations)==1){
- //this will only get one title but so we don't need to know the index
- foreach($this->organizations as $id => $value){
- $title = $this->organizations[$id]->get_name();
- break;
- }
- }
- return $title;
- }
- /**
- * //TODO @TODO implement this function to restore items data from a set of AICC config files,
- * updating the existing table... This will prove very useful in case initial data
- * from config files were not imported well enough
- */
- function reimport_aicc(){
- if($this->debug>0){error_log('In aicc::reimport_aicc() method',0);}
- //query current items list
- //get the identifiers
- //parse the config files
- //match both
- //update DB accordingly
- return true;
- }
- /**
- * Static function to parse AICC ini files.
- * Based on work by sinedeo at gmail dot com published on php.net (parse_ini_file())
- * @param string File path
- * @return array Structured array
- */
- function parse_ini_file_quotes_safe($f)
- {
- $null = "";
- $r=$null;
- $sec=$null;
- $f=@file($f);
- for ($i=0;$i<@count($f);$i++)
- {
- $newsec=0;
- $w=@trim($f[$i]);
- if ($w)
- {
- if ((!$r) or ($sec))
- {
- if ((@substr($w,0,1)=="[") and (@substr($w,-1,1))=="]")
- {
- $sec=@substr($w,1,@strlen($w)-2);
- $newsec=1;
- }
+ }
+
+ /**
+ * Gets the default organisation's title
+ * @return string The organization's title
+ */
+ function get_title(){
+ if ($this->debug > 0) { error_log('In aicc::get_title() method', 0); }
+ $title = '';
+ if (isset($this->config['organizations']['default'])) {
+ $title = $this->organizations[$this->config['organizations']['default']]->get_name();
+ } elseif (count($this->organizations) == 1) {
+ // This will only get one title but so we don't need to know the index.
+ foreach ($this->organizations as $id => $value) {
+ $title = $this->organizations[$id]->get_name();
+ break;
+ }
+ }
+ return $title;
+ }
+
+ /**
+ * TODO: Implement this function to restore items data from a set of AICC config files,
+ * updating the existing table... This will prove very useful in case initial data
+ * from config files were not imported well enough.
+ */
+ function reimport_aicc() {
+ if ($this->debug > 0) { error_log('In aicc::reimport_aicc() method', 0); }
+ //query current items list
+ //get the identifiers
+ //parse the config files
+ //match both
+ //update DB accordingly
+ return true;
+ }
+
+ /**
+ * Static function to parse AICC ini files.
+ * Based on work by sinedeo at gmail dot com published on php.net (parse_ini_file()).
+ * @param string File path
+ * @return array Structured array
+ */
+ function parse_ini_file_quotes_safe($f) {
+ $null = '';
+ $r = $null;
+ $sec = $null;
+ $f = @file($f);
+ for ($i = 0; $i < @count($f); $i++) {
+ $newsec = 0;
+ $w = @trim($f[$i]);
+ if ($w) {
+ if ((!$r) or ($sec)) {
+ if ((@substr($w, 0, 1) == '[') and (@substr($w, -1, 1)) == ']') {
+ $sec = @substr($w, 1, @strlen($w) - 2);
+ $newsec = 1;
}
- if (!$newsec)
- {
- $w=@explode("=",$w);
- $k=@trim($w[0]);
- unset($w[0]);
- $v=@trim(@implode("=",$w));
- if ((@substr($v,0,1)=="\"") and (@substr($v,-1,1)=="\""))
- {
- $v=@substr($v,1,@strlen($v)-2);
- }
- if ($sec)
- {
- if(strtolower($sec)=='course_description'){//special case
- $r[strtolower($sec)]=$k;
- }else{
- $r[strtolower($sec)][strtolower($k)]=$v;
- }
- } else
- {
- $r[strtolower($k)]=$v;
+ }
+ if (!$newsec) {
+ $w = @explode('=', $w);
+ $k = @trim($w[0]);
+ unset($w[0]);
+ $v = @trim(@implode('=', $w));
+ if ((@substr($v, 0, 1) == "\"") and (@substr($v, -1, 1) == "\"")) {
+ $v = @substr($v, 1, @strlen($v) - 2);
+ }
+ if ($sec) {
+ if (strtolower($sec) == 'course_description') { //A special case.
+ $r[strtolower($sec)] = $k;
+ } else {
+ $r[strtolower($sec)][strtolower($k)] = $v;
}
+ } else {
+ $r[strtolower($k)] = $v;
}
}
}
- return $r;
}
- /**
- * Static function to parse AICC ini strings.
- * Based on work by sinedeo at gmail dot com published on php.net (parse_ini_file())
- * @param string INI File string
- * @param array List of names of sections that should be considered as containing only hard string data (no variables), provided in lower case
- * @return array Structured array
- */
- function parse_ini_string_quotes_safe($s,$pure_strings=array())
- {
- $null = "";
- $r=$null;
- $sec=$null;
- $f = split("\r\n",$s);
- for ($i=0;$i<@count($f);$i++)
- {
- $newsec=0;
- $w=@trim($f[$i]);
- if ($w)
- {
- if ((!$r) or ($sec))
- {
- if ((@substr($w,0,1)=="[") and (@substr($w,-1,1))=="]")
- {
- $sec=@substr($w,1,@strlen($w)-2);
- $pure_data = 0;
- if(in_array(strtolower($sec),$pure_strings)){
- //this section can only be considered as pure string data (until the next section)
- $pure_data = 1;
- $r[strtolower($sec)] = '';
- }
- $newsec=1;
+ return $r;
+ }
+
+ /**
+ * Static function to parse AICC ini strings.
+ * Based on work by sinedeo at gmail dot com published on php.net (parse_ini_file()).
+ * @param string INI File string
+ * @param array List of names of sections that should be considered as containing only hard string data (no variables), provided in lower case
+ * @return array Structured array
+ */
+ function parse_ini_string_quotes_safe($s, $pure_strings = array()) {
+ $null = '';
+ $r = $null;
+ $sec = $null;
+ $f = split("\r\n", $s);
+ for ($i = 0; $i < @count($f); $i++) {
+ $newsec = 0;
+ $w = @trim($f[$i]);
+ if ($w) {
+ if ((!$r) or ($sec)) {
+ if ((@substr($w, 0, 1) == '[') and (@substr($w, -1, 1)) == ']') {
+ $sec = @substr($w, 1, @strlen($w) - 2);
+ $pure_data = 0;
+ if (in_array(strtolower($sec), $pure_strings)) {
+ // This section can only be considered as pure string data (until the next section).
+ $pure_data = 1;
+ $r[strtolower($sec)] = '';
}
+ $newsec = 1;
}
- if (!$newsec)
- {
- $w=@explode("=",$w);
- $k=@trim($w[0]);
- unset($w[0]);
- $v=@trim(@implode("=",$w));
- if ((@substr($v,0,1)=="\"") and (@substr($v,-1,1)=="\""))
- {
- $v=@substr($v,1,@strlen($v)-2);
- }
- if ($sec)
- {
- if($pure_data){
- $r[strtolower($sec)] .= $f[$i];
- }else{
- if(strtolower($sec)=='course_description'){//special case
- $r[strtolower($sec)]=$k;
- }else{
- $r[strtolower($sec)][strtolower($k)]=$v;
- }
+ }
+ if (!$newsec) {
+ $w = @explode('=', $w);
+ $k = @trim($w[0]);
+ unset($w[0]);
+ $v = @trim(@implode('=', $w));
+ if ((@substr($v, 0, 1) == "\"") and (@substr($v, -1, 1) == "\"")) {
+ $v = @substr($v, 1, @strlen($v) - 2);
+ }
+ if ($sec) {
+ if ($pure_data) {
+ $r[strtolower($sec)] .= $f[$i];
+ } else {
+ if (strtolower($sec) == 'course_description') { // A special case.
+ $r[strtolower($sec)] = $k;
+ } else {
+ $r[strtolower($sec)][strtolower($k)] = $v;
}
- } else
- {
- $r[strtolower($k)]=$v;
}
+ } else {
+ $r[strtolower($k)] = $v;
}
}
}
- return $r;
}
- /**
- * Static function that parses CSV files into simple arrays, based on a function
- * by spam at cyber-space dot nl published on php.net (fgetcsv())
- * @param string Filepath
- * @param string CSV delimiter
- * @param string CSV enclosure
- * @param boolean Might one field name happen more than once on the same line? (then split by comma in the values)
- * @return array Simple structured array
- */
- function parse_csv_file($f,$delim=',',$enclosure='"',$multiples=false)
- {
- $data = file_get_contents($f);
- $enclosed=false;
- $fldcount=0;
- $linecount=0;
- $fldval='';
- for($i=0;$i $line){
- if($line_idx == 0){
- $titles = $line;
- }else{
- $ret_ret_array[$line_idx] = array();
- foreach($line as $idx=>$val)
- {
- if($multiples && !empty($ret_ret_array[$line_idx][strtolower($titles[$idx])])){
- $ret_ret_array[$line_idx][strtolower($titles[$idx])].=",".$val;
- }else{
- $ret_ret_array[$line_idx][strtolower($titles[$idx])]=$val;
- }
+ }
+ if ($fldval) {
+ $ret_array[$linecount][$fldcount] = $fldval;
+ }
+ // Transform the array to use the first line as titles.
+ $titles = array();
+ $ret_ret_array = array();
+ foreach ($ret_array as $line_idx => $line) {
+ if ($line_idx == 0) {
+ $titles = $line;
+ } else {
+ $ret_ret_array[$line_idx] = array();
+ foreach ($line as $idx => $val) {
+ if ($multiples && !empty($ret_ret_array[$line_idx][strtolower($titles[$idx])])) {
+ $ret_ret_array[$line_idx][strtolower($titles[$idx])] .= ','.$val;
+ } else {
+ $ret_ret_array[$line_idx][strtolower($titles[$idx])] = $val;
}
}
}
- return $ret_ret_array;
}
-
+ return $ret_ret_array;
+ }
}
-?>
diff --git a/main/newscorm/aiccBlock.class.php b/main/newscorm/aiccBlock.class.php
index 693f6cd513..32b19fbd2c 100755
--- a/main/newscorm/aiccBlock.class.php
+++ b/main/newscorm/aiccBlock.class.php
@@ -1,60 +1,55 @@
* @license GNU/GPL
*/
+
/**
- * Class defining the Block elements in an AICC Course Structure file
- *
+ * Class defining the Block elements in an AICC Course Structure file.
*/
require_once 'learnpathItem.class.php';
-class aiccBlock extends learnpathItem{
+class aiccBlock extends learnpathItem {
public $identifier = '';
public $members = array();
- /**
- * Class constructor. Depending of the type of construction called ('db' or 'manifest'), will create a scormResource
- * object from database records or from the array given as second param
- * @param string Type of construction needed ('db' or 'config', default = 'config')
- * @param mixed Depending on the type given, DB id for the lp_item or parameters array
- */
- function aiccBlock($type='config',$params) {
-
- if(isset($params))
- {
- switch($type){
- case 'db':
- //TODO implement this way of object creation
- return false;
- case 'config': //do the same as the default
- default:
- foreach($params as $a => $value)
- {
- switch($a)
- {
- case 'system_id':
- $this->identifier = strtolower($value);
- break;
- case 'member':
- if(strstr($value,',')!==false){
- $temp = split(',',$value);
- foreach($temp as $val){
- if(!empty($val)){
- $this->members[] = $val;
- }
- }
- }
- break;
- }
- }
+ /**
+ * Class constructor. Depending of the type of construction called ('db' or 'manifest'), will create a scormResource
+ * object from database records or from the array given as second param
+ * @param string Type of construction needed ('db' or 'config', default = 'config')
+ * @param mixed Depending on the type given, DB id for the lp_item or parameters array
+ */
+ function aiccBlock($type = 'config', $params) {
+ if (isset($params)) {
+ switch ($type) {
+ case 'db':
+ //TODO: Implement this way of object creation.
+ return false;
+ case 'config': // Do the same as the default.
+ default:
+ foreach ($params as $a => $value) {
+ switch ($a) {
+ case 'system_id':
+ $this->identifier = strtolower($value);
+ break;
+ case 'member':
+ if (strstr($value, ',') !== false) {
+ $temp = split(',', $value);
+ foreach ($temp as $val) {
+ if (!empty($val)) {
+ $this->members[] = $val;
+ }
+ }
+ }
+ break;
+ }
+ }
return true;
-
- }
- }
- return false;
- }
+ }
+ }
+ return false;
+ }
}
-?>
\ No newline at end of file
diff --git a/main/newscorm/aiccItem.class.php b/main/newscorm/aiccItem.class.php
index 52d591dd6c..336db834ca 100755
--- a/main/newscorm/aiccItem.class.php
+++ b/main/newscorm/aiccItem.class.php
@@ -1,138 +1,135 @@
* @license GNU/GPL
*/
+
/**
* This class handles the elements from an AICC Descriptor file.
*/
require_once 'learnpathItem.class.php';
-class aiccItem extends learnpathItem{
- public $identifier = '';//AICC AU's system_id
+class aiccItem extends learnpathItem {
+ public $identifier = ''; // AICC AU's system_id
public $identifierref = '';
- public $parameters = ''; //AICC AU's web_launch
- public $title = ''; //no AICC equivalent
- public $sub_items = array(); //AICC elements (des)
- //public $prerequisites = ''; - defined in learnpathItem.class.php
- //public $max_score = ''; //defined in learnpathItem
- //public $path = ''; //defined in learnpathItem
- public $maxtimeallowed = '00:00:00'; //AICC AU's max_time_allowed
- public $timelimitaction = ''; //AICC AU's time_limit_action
- public $masteryscore = ''; //AICC AU's mastery_score
- public $core_vendor = ''; //AICC AU's core_vendor
- public $system_vendor = ''; //AICC AU's system_vendor
- public $au_type = ''; //AICC AU's type
- public $command_line = ''; //AICC AU's command_line
- public $debug=0;
+ public $parameters = ''; // AICC AU's web_launch
+ public $title = ''; // no AICC equivalent
+ public $sub_items = array(); // AICC elements (des)
+ //public $prerequisites = ''; // defined in learnpathItem.class.php
+ //public $max_score = ''; // defined in learnpathItem
+ //public $path = ''; // defined in learnpathItem
+ public $maxtimeallowed = '00:00:00'; // AICC AU's max_time_allowed
+ public $timelimitaction = ''; // AICC AU's time_limit_action
+ public $masteryscore = ''; // AICC AU's mastery_score
+ public $core_vendor = ''; // AICC AU's core_vendor
+ public $system_vendor = ''; // AICC AU's system_vendor
+ public $au_type = ''; // AICC AU's type
+ public $command_line = ''; // AICC AU's command_line
+ public $debug = 0;
- /**
- * Class constructor. Depending of the type of construction called ('db' or 'manifest'), will create a scormItem
- * object from database records or from the array given as second parameter
- * @param string Type of construction needed ('db' or 'config', default = 'config')
- * @param mixed Depending on the type given, DB id for the lp_item or parameters array
- */
- public function aiccItem($type='config',$params) {
- if(isset($params))
- {
- switch($type){
- case 'db':
- parent::__construct($params,api_get_user_id());
- $this->aicc_contact = false;
- //TODO implement this way of metadata object creation
- return false;
- case 'config': //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
- foreach($params as $a => $value)
- {
- switch($a)
- {
- case 'system_id':
- $this->identifier = Database::escape_string(strtolower($value));
- break;
- case 'type':
- $this->au_type = Database::escape_string($value);
- break;
- case 'command_line':
- $this->command_line = Database::escape_string($value);
- break;
- case 'max_time_allowed':
- $this->maxtimeallowed = Database::escape_string($value);
- break;
- case 'time_limit_action':
- $this->timelimitaction = Database::escape_string($value);
- break;
- case 'max_score':
- $this->max_score = Database::escape_string($value);
- break;
- case 'core_vendor':
- $this->core_vendor = Database::escape_string($value);
- break;
- case 'system_vendor':
- $this->system_vendor = Database::escape_string($value);
- break;
- case 'file_name':
- $this->path = Database::escape_string($value);
- break;
- case 'mastery_score':
- $this->masteryscore = Database::escape_string($value);
- break;
- case 'web_launch':
- $this->parameters = Database::escape_string($value);
- break;
- }
- }
+ /**
+ * Class constructor. Depending of the type of construction called ('db' or 'manifest'), will create a scormItem
+ * object from database records or from the array given as second parameter
+ * @param string Type of construction needed ('db' or 'config', default = 'config')
+ * @param mixed Depending on the type given, DB id for the lp_item or parameters array
+ */
+ public function aiccItem($type = 'config', $params) {
+ if (isset($params)) {
+ switch ($type) {
+ case 'db':
+ parent::__construct($params,api_get_user_id());
+ $this->aicc_contact = false;
+ //TODO: Implement this way of metadata object creation.
+ return false;
+ case 'config': // 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
+ foreach ($params as $a => $value) {
+ switch ($a) {
+ case 'system_id':
+ $this->identifier = Database::escape_string(strtolower($value));
+ break;
+ case 'type':
+ $this->au_type = Database::escape_string($value);
+ break;
+ case 'command_line':
+ $this->command_line = Database::escape_string($value);
+ break;
+ case 'max_time_allowed':
+ $this->maxtimeallowed = Database::escape_string($value);
+ break;
+ case 'time_limit_action':
+ $this->timelimitaction = Database::escape_string($value);
+ break;
+ case 'max_score':
+ $this->max_score = Database::escape_string($value);
+ break;
+ case 'core_vendor':
+ $this->core_vendor = Database::escape_string($value);
+ break;
+ case 'system_vendor':
+ $this->system_vendor = Database::escape_string($value);
+ break;
+ case 'file_name':
+ $this->path = Database::escape_string($value);
+ break;
+ case 'mastery_score':
+ $this->masteryscore = Database::escape_string($value);
+ break;
+ case 'web_launch':
+ $this->parameters = Database::escape_string($value);
+ break;
+ }
+ }
return true;
- }
- }
- 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
- */
- function get_flat_list(&$list,&$abs_order,$rel_order=1,$level=0)
- {
- $list[] = array(
- 'au_type' => $this->au_type,
+ }
+ }
+ 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
+ */
+ function get_flat_list(&$list, &$abs_order, $rel_order = 1, $level = 0) {
+ $list[] = array(
+ 'au_type' => $this->au_type,
'command_line' => $this->command_line,
- 'core_vendor' => $this->core_vendor,
+ 'core_vendor' => $this->core_vendor,
'identifier' => $this->identifier,
'identifierref' => $this->identifierref,
'masteryscore' => $this->masteryscore,
'maxtimeallowed' => $this->maxtimeallowed,
'level' => $level,
'parameters' => $this->parameters,
- 'prerequisites' => (!empty($this->prereq_string)?$this->prereq_string:''),
+ 'prerequisites' => (!empty($this->prereq_string) ? $this->prereq_string : ''),
'timelimitaction' => $this->timelimitaction,
- );
+ );
$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 AICC.
- * @param boolean Save from URL params (1) or from object attributes (0)
- */
- function save($from_outside=true, $prereqs_complete=false)
- {
- parent::save($from_outside, $prereqs_complete=false);
- //under certain conditions, the scorm_contact should not be set, because no scorm signal was sent
- $this->aicc_contact = true;
- if(!$this->aicc_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 AICC.
+ * @param boolean Save from URL params (1) or from object attributes (0)
+ */
+ function save($from_outside = true, $prereqs_complete = false) {
+ parent::save($from_outside, $prereqs_complete = false);
+ // Under certain conditions, the scorm_contact should not be set, because no scorm signal was sent.
+ $this->aicc_contact = true;
+ if (!$this->aicc_contact) {
+ //error_log('New LP - was expecting SCORM message but none received', 0);
+ }
+ }
}
-?>
\ No newline at end of file
diff --git a/main/newscorm/aiccObjective.class.php b/main/newscorm/aiccObjective.class.php
index bf2e6acf9b..38f0ee0a56 100755
--- a/main/newscorm/aiccObjective.class.php
+++ b/main/newscorm/aiccObjective.class.php
@@ -1,60 +1,56 @@
* @license GNU/GPL
*/
+
/**
- * Class defining the Block elements in an AICC Course Structure file
- *
+ * Class defining the Block elements in an AICC Course Structure file.
*/
require_once 'learnpathItem.class.php';
-class aiccObjective extends learnpathItem{
+class aiccObjective extends learnpathItem {
public $identifier = '';
public $members = array();
- /**
- * Class constructor. Depending of the type of construction called ('db' or 'manifest'), will create a scormResource
- * object from database records or from the array given as second param
- * @param string Type of construction needed ('db' or 'config', default = 'config')
- * @param mixed Depending on the type given, DB id for the lp_item or parameters array
- */
- function aiccObjective($type='config',$params) {
+ /**
+ * Class constructor. Depending of the type of construction called ('db' or 'manifest'), will create a scormResource
+ * object from database records or from the array given as second param
+ * @param string Type of construction needed ('db' or 'config', default = 'config')
+ * @param mixed Depending on the type given, DB id for the lp_item or parameters array
+ */
+ function aiccObjective($type = 'config', $params) {
- if(isset($params))
- {
- switch($type){
- case 'db':
- //TODO implement this way of object creation
- return false;
- case 'config': //do the same as the default
- default:
- foreach($params as $a => $value)
- {
- switch($a)
- {
- case 'system_id':
- $this->identifier = strtolower($value);
- break;
- case 'member':
- if(strstr($value,',')!==false){
- $temp = split(',',$value);
- foreach($temp as $val){
- if(!empty($val)){
- $this->members[] = $val;
- }
- }
- }
- break;
- }
- }
+ if (isset($params)) {
+ switch ($type) {
+ case 'db':
+ // TODO: Implement this way of object creation.
+ return false;
+ case 'config': // Do the same as the default.
+ default:
+ foreach ($params as $a => $value) {
+ switch ($a) {
+ case 'system_id':
+ $this->identifier = strtolower($value);
+ break;
+ case 'member':
+ if (strstr($value, ',') !== false) {
+ $temp = split(',', $value);
+ foreach ($temp as $val) {
+ if (!empty($val)) {
+ $this->members[] = $val;
+ }
+ }
+ }
+ break;
+ }
+ }
return true;
-
- }
- }
- return false;
- }
+ }
+ }
+ return false;
+ }
}
-?>
\ No newline at end of file
diff --git a/main/newscorm/aiccResource.class.php b/main/newscorm/aiccResource.class.php
index 0b8a26e693..ecf38948cf 100755
--- a/main/newscorm/aiccResource.class.php
+++ b/main/newscorm/aiccResource.class.php
@@ -1,13 +1,15 @@
* @license GNU/GPL
*/
+
/**
- * Class defining the elements from an AICC Descriptor file
+ * Class defining the elements from an AICC Descriptor file.
*/
class aiccResource {
public $identifier = '';
@@ -15,44 +17,39 @@ class aiccResource {
public $description = '';
public $developer_id = '';
- /**
- * Class constructor. Depending of the type of construction called ('db' or 'manifest'), will create a scormResource
- * object from database records or from the array given as second param
- * @param string Type of construction needed ('db' or 'config', default = 'config')
- * @param mixed Depending on the type given, DB id for the lp_item or parameters array
- */
- public function aiccResource($type='config',$params) {
+ /**
+ * Class constructor. Depending of the type of construction called ('db' or 'manifest'), will create a scormResource
+ * object from database records or from the array given as second param
+ * @param string Type of construction needed ('db' or 'config', default = 'config')
+ * @param mixed Depending on the type given, DB id for the lp_item or parameters array
+ */
+ public function aiccResource($type = 'config', $params) {
- if(isset($params))
- {
- switch($type){
- case 'db':
- //TODO implement this way of object creation
- return false;
- case 'config': //do the same as the default
- default:
- foreach($params as $a => $value)
- {
- switch($a)
- {
- case 'system_id':
- $this->identifier = strtolower($value);
- break;
- case 'title':
- $this->title = $value;
- case 'description':
- $this->description = $value;
- break;
- case 'developer_id':
- $this->developer_id = $value;
- break;
- }
- }
+ if (isset($params)) {
+ switch ($type) {
+ case 'db':
+ // TODO: Implement this way of object creation.
+ return false;
+ case 'config': // Do the same as the default.
+ default:
+ foreach ($params as $a => $value) {
+ switch ($a) {
+ case 'system_id':
+ $this->identifier = strtolower($value);
+ break;
+ case 'title':
+ $this->title = $value;
+ case 'description':
+ $this->description = $value;
+ break;
+ case 'developer_id':
+ $this->developer_id = $value;
+ break;
+ }
+ }
return true;
-
- }
- }
- return false;
- }
+ }
+ }
+ return false;
+ }
}
-?>
\ No newline at end of file
diff --git a/main/newscorm/aicc_api.php b/main/newscorm/aicc_api.php
index 6386059ba2..1c2d88f8da 100755
--- a/main/newscorm/aicc_api.php
+++ b/main/newscorm/aicc_api.php
@@ -1,57 +1,54 @@
-* @author Yannick Warnier
-* @version v 1.0
-* @access public
-* @package chamilo.learnpath
-* @license GNU/GPL
-*/
+ * API event handler functions for AICC / CMIv4 in API communication mode
+ *
+ * @author Denes Nagy
+ * @author Yannick Warnier
+ * @version v 1.0
+ * @access public
+ * @package chamilo.learnpath
+ * @license GNU/GPL
+ */
+
/**
* This script is divided into three sections.
* The first section (below) is the initialisation part.
* The second section is the AICC object part
- * The third section defines the event handlers for Dokeos' internal messaging
+ * The third section defines the event handlers for Chamilo's internal messaging
* and frames refresh
*
* This script implements the API messaging for AICC. The HACP messaging is
* made by another set of scripts.
*/
-/*
- * INIT SECTION
- */
-//flag to allow for anonymous user - needs to be set before global.inc.php
+/* INIT SECTION */
+
+// Flag to allow for anonymous user - needs to be set before global.inc.php.
$use_anonymous = true;
-//Load common libraries using a compatibility script to bridge between 1.6 and 1.8
+// Load common libraries using a compatibility script to bridge between 1.6 and 1.8.
require_once 'back_compat.inc.php';
-//Load learning path libraries so we can use the objects to define the initial values
-//of the API
+// Load learning path libraries so we can use the objects to define the initial values of the API.
require_once 'learnpath.class.php';
require_once 'learnpathItem.class.php';
require_once 'aicc.class.php';
-// Is this needed? This is probabaly done in the header file
+// Is this needed? This is probabaly done in the header file.
// $_user = $_SESSION['_user'];
$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);
+if (!is_object($oItem)) {
+ error_log('New LP - scorm_api - Could not load oItem item', 0);
exit;
}
$autocomplete_when_80pct = 0;
-/*
-==============================================================================
- JavaScript Functions
-==============================================================================
-*/
-?>var scorm_logs=scorm_debug)?'0':'3');?>; //debug log level for SCORM. 0 = none, 1=light, 2=a lot, 3=all - displays logs in log frame
+/* JavaScript Functions */
+
+?>var scorm_logs=scorm_debug) ? '0' : '3'); ?>; //debug log level for SCORM. 0 = none, 1=light, 2=a lot, 3=all - displays logs in log frame
var lms_logs=0; //debug log level for LMS actions. 0=none, 1=light, 2=a lot, 3=all
//logit_lms('scormfunctions.php included',0);
@@ -66,7 +63,7 @@ function APIobject() {
this.LMSGetDiagnostic=LMSGetDiagnostic;
}
-//it is not sure that the scos use the above declarations
+// It is not sure that the scos use the above declarations.
API = new APIobject(); //for scorm 1.2
@@ -87,7 +84,7 @@ var G_LastError = G_NoError ;
var commit = false ;
-//Strictly scorm variables
+// Strictly SCORM variables.
var score=get_score();?>;
var max=get_max();?>;
var min=get_min();?>;
@@ -97,7 +94,7 @@ var suspend_data = 'get_suspend_data();?>';
var lesson_location = 'get_lesson_location();?>';
var total_time = 'get_scorm_time('js');?>';
-//Dokeos internal variables
+// Chamilo internal variables.
var saved_lesson_status = 'not attempted';
var lms_lp_id = get_id();?>;
var lms_item_id = get_id();?>;
@@ -116,7 +113,7 @@ var lms_previous_item = 'get_previous_item_id();?>';
var lms_lp_type = 'get_type();?>';
var lms_item_type = 'get_type();?>';
-//Backup for old values
+// Backup for old values.
var old_score = 0;
var old_max = 0;
var old_min = 0;
@@ -140,18 +137,18 @@ function LMSGetValue(param) {
}else if(param == 'cmi.core.exit'){
result='';
}else if(param == 'cmi.core.lesson_status'){
- if(lesson_status != '') {
- result=lesson_status;
- }
- else{
- result='not attempted';
- }
+ if(lesson_status != '') {
+ result=lesson_status;
+ }
+ else{
+ result='not attempted';
+ }
}else if(param == 'cmi.core.student_id'){
result='';
}else if(param == 'cmi.core.student_name'){
}else if(param == 'cmi.core.lesson_location'){
result=lesson_location;
@@ -179,7 +176,7 @@ function LMSGetValue(param) {
result='get_view_count();?>';
}
/*
- //Switch not working??? WTF???
+ // Switch not working??? WTF???
switch(param) {
case 'cmi.core._children' :
result='entry, exit, lesson_status, student_id, student_name, lesson_location, total_time, credit, lesson_mode, score, session_time';
@@ -194,20 +191,20 @@ function LMSGetValue(param) {
result='';
break;
case 'cmi.core.lesson_status' :
- if(lesson_status != '') {
- result=lesson_status;
- }
- else{
- result='not attempted';
- }
- break;
+ if(lesson_status != '') {
+ result=lesson_status;
+ }
+ else{
+ result='not attempted';
+ }
+ break;
case 'cmi.core.student_id' :
result='';
break;
case 'cmi.core.student_name' :
break;
case 'cmi.core.lesson_location' :
result='';
@@ -263,9 +260,9 @@ function LMSSetValue(param, val) {
case 'cmi.core.lesson_status' :
saved_lesson_status = lesson_status;
lesson_status = val;
- mode != 'fullscreen'){ ?>
- //var update = update_toc(lesson_status,lms_item_id);
-
+ mode != 'fullscreen') { ?>
+ //var update = update_toc(lesson_status,lms_item_id);
+
break;
case 'cmi.completion_status' : lesson_status = val; break; //1.3
case 'cmi.core.session_time' : session_time = val; break;
@@ -273,29 +270,29 @@ function LMSSetValue(param, val) {
case 'cmi.success_status' : success_status = val; break; //1.3
case 'cmi.suspend_data' : suspend_data = val; break;
}
- //var update = update_toc();
+ //var update = update_toc();
//var update_progress = update_progress_bar();
force_commit == 1){
- echo " var mycommit = LMSCommit('force');";
+ if ($oLP->force_commit == 1) {
+ echo " var mycommit = LMSCommit('force');";
}
?>
return(true);
}
function savedata(origin) { //origin can be 'commit', 'finish' or 'terminate'
-
- if( ( lesson_status == 'incomplete') && (score >= (0.8*max) ) ){
- lesson_status = 'completed';
- }
-
- param = 'id='+lms_item_id+'&origin='+origin+'&score='+score+'&max='+max+'&min='+min+'&lesson_status='+lesson_status+'&time='+session_time+'&suspend_data='+suspend_data;
+
+ if( ( lesson_status == 'incomplete') && (score >= (0.8*max) ) ){
+ lesson_status = 'completed';
+ }
+
+ param = 'id='+lms_item_id+'&origin='+origin+'&score='+score+'&max='+max+'&min='+min+'&lesson_status='+lesson_status+'&time='+session_time+'&suspend_data='+suspend_data;
- url="http:///lp_controller.php?cidReq=&action=save&lp_id=get_id();?>&" + param + "";
+ url="http:///lp_controller.php?cidReq=&action=save&lp_id=get_id();?>&" + param + "";
logit_lms('saving data (status='+lesson_status+')',1);
xajax_save_item(lms_lp_id, lms_user_id, lms_view_id, lms_item_id, score, max, min, lesson_status, session_time, suspend_data, lesson_location);
//xajax_update_pgs();
@@ -304,7 +301,7 @@ function savedata(origin) { //origin can be 'commit', 'finish' or 'terminate'
function LMSCommit(val) {
logit_scorm('LMSCommit()',0);
- commit = true ;
+ commit = true ;
savedata('commit');
return('true');
}
@@ -331,17 +328,16 @@ function LMSGetDiagnostic(errCode){
return(API.LMSGetLastError());
}
/**
- * Defining the AJAX-object class to be made available from other frames
+ * Defining the AJAX-object class to be made available from other frames.
*/
function XAJAXobject() {
this.xajax_switch_item_details=xajax_switch_item_details;
@@ -389,8 +385,8 @@ function addListeners(){
//assign event handlers to objects
if(lms_lp_type==1 || lms_item_type=='asset'){
logit_lms('Dokeos LP or asset',2);
- //if this path is a Dokeos learnpath, then start manual save
- //when something is loaded in there
+ // If this path is a Chamilo learnpath, then start manual save
+ // when something is loaded in there.
var myelem = document.getElementById('content_id');
if(!myelem){logit_lms("Impossible to find content_id element in document",2);}
addEvent(myelem,'unload',dokeos_save_asset,false);
@@ -433,15 +429,15 @@ function load_item(item_id,url){
return false;
}
/**
- * Save a Dokeos learnpath item's time and mark as completed upon
+ * Save a Chamilo learnpath item's time and mark as completed upon
* leaving it
*/
function dokeos_save_asset(){
- //var linkparams = 'id='+lms_item_id+'&score='+score+'&max='+max+'&min='+min+'&lesson_status='+lesson_status+'&time='+session_time+'&suspend_data='+suspend_data;
- //var url = "?action=save&" + linkparams + "";
+ //var linkparams = 'id='+lms_item_id+'&score='+score+'&max='+max+'&min='+min+'&lesson_status='+lesson_status+'&time='+session_time+'&suspend_data='+suspend_data;
+ //var url = "?action=save&" + linkparams + "";
logit_lms('dokeos_save_asset: '+url,0);
- //frames["message_name"].src = url;
- xajax_save_item(lms_lp_id, lms_user_id, lms_view_id, lms_item_id, score, max, min, lesson_status, session_time, suspend_data, lesson_location);
+ //frames["message_name"].src = url;
+ xajax_save_item(lms_lp_id, lms_user_id, lms_view_id, lms_item_id, score, max, min, lesson_status, session_time, suspend_data, lesson_location);
}
/**
* Logs information about SCORM messages into the log frame
@@ -471,7 +467,7 @@ function logit_lms(message,priority){
*/
function update_toc(update_action,update_id)
{
- mode != 'fullscreen'){ ?>
+ mode != 'fullscreen') { ?>
var myframe = frames["toc_name"];
var myelem = myframe.document.getElementById("toc_"+update_id);
var myelemimg = myframe.document.getElementById("toc_img_"+update_id);
@@ -526,7 +522,7 @@ function update_toc(update_action,update_id)
}
}
return true;
-
+
return true;
}
/**
@@ -598,7 +594,7 @@ function update_message_frame(msg_msg)
* current item, (2) refresh all the values inside the SCORM API object, (3) open the
* new item into the content_id frame, (4) refresh the table of contents, (5) refresh
* the progress bar (completion), (6) refresh the message frame
- * @param integer Dokeos ID for the current item
+ * @param integer Chamilo ID for the current item
* @param string This parameter can be a string specifying the next
* item (like 'next', 'previous', 'first' or 'last') or the id to the next item
*/
@@ -662,106 +658,106 @@ function switch_item(current_item, next_item){
* manually into GET[]
*/
function xajax_save_item(lms_lp_id, lms_user_id, lms_view_id, lms_item_id, score, max, min, lesson_status, session_time, suspend_data, lesson_location, interactions, lms_item_core_exit) {
- params='';
- params += 'lid='+lms_lp_id+'&uid='+lms_user_id+'&vid='+lms_view_id;
- params += '&iid='+lms_item_id+'&s='+score+'&max='+max+'&min='+min;
- params += '&status='+lesson_status+'&t='+session_time;
- params += '&suspend='+suspend_data+'&loc='+lesson_location;
- params += '&core_exit='+lms_item_core_exit;
- interact_string = '';
- for (i in interactions){
- interact_string += '&interact['+i+']=';
- interact_temp = '[';
- for (j in interactions[i]) {
- interact_temp += interactions[i][j]+',';
- }
- interact_temp = interact_temp.substr(0,(interact_temp.length-2)) + ']';
- interact_string += encodeURIComponent(interact_temp);
- }
- //interact_string = encodeURIComponent(interact_string.substr(0,(interact_string.length-1)));
- params += interact_string;
- /*params = {
- 'lid': lms_lp_id,
- 'uid': lms_user_id,
- 'vid': lms_view_id,
- 'iid': lms_item_id,
- 's': score,
- 'max': max,
- 'min': min,
- 'status': lesson_status,
- 't': session_time,
- 'suspend': suspend_data,
- 'loc': lesson_location,
- 'interact': interac_string,
- 'core_exit': lms_item_core_exit
- }
- */
- $.ajax({
- type:"POST",
- data: params,
- url: "lp_ajax_save_item.php",
- dataType: "script",
- async: false
- }
- );
+ params='';
+ params += 'lid='+lms_lp_id+'&uid='+lms_user_id+'&vid='+lms_view_id;
+ params += '&iid='+lms_item_id+'&s='+score+'&max='+max+'&min='+min;
+ params += '&status='+lesson_status+'&t='+session_time;
+ params += '&suspend='+suspend_data+'&loc='+lesson_location;
+ params += '&core_exit='+lms_item_core_exit;
+ interact_string = '';
+ for (i in interactions){
+ interact_string += '&interact['+i+']=';
+ interact_temp = '[';
+ for (j in interactions[i]) {
+ interact_temp += interactions[i][j]+',';
+ }
+ interact_temp = interact_temp.substr(0,(interact_temp.length-2)) + ']';
+ interact_string += encodeURIComponent(interact_temp);
+ }
+ //interact_string = encodeURIComponent(interact_string.substr(0,(interact_string.length-1)));
+ params += interact_string;
+ /*params = {
+ 'lid': lms_lp_id,
+ 'uid': lms_user_id,
+ 'vid': lms_view_id,
+ 'iid': lms_item_id,
+ 's': score,
+ 'max': max,
+ 'min': min,
+ 'status': lesson_status,
+ 't': session_time,
+ 'suspend': suspend_data,
+ 'loc': lesson_location,
+ 'interact': interac_string,
+ 'core_exit': lms_item_core_exit
+ }
+ */
+ $.ajax({
+ type:"POST",
+ data: params,
+ url: "lp_ajax_save_item.php",
+ dataType: "script",
+ async: false
+ }
+ );
}
/**
* Starts the timer with the server clock time.
* Originally, we used the xajax library. Now we use jQuery
*/
function xajax_start_timer() {
- $.ajax({
- type: "GET",
- url: "lp_ajax_start_timer.php",
- dataType: "script",
- async: false
- });
+ $.ajax({
+ type: "GET",
+ url: "lp_ajax_start_timer.php",
+ dataType: "script",
+ async: false
+ });
}
/**
* Save a specific item's objectives into the LMS through
* an AJAX call. Originally, we used the xajax library. Now we use jQuery
*/
function xajax_save_objectives(lms_lp_id,lms_user_id,lms_view_id,lms_item_id,item_objectives) {
- params='';
- params += 'lid='+lms_lp_id+'&uid='+lms_user_id+'&vid='+lms_view_id;
- params += '&iid='+lms_item_id;
- obj_string = '';
- for (i in item_objectives){
- obj_string += '&objectives['+i+']=';
- obj_temp = '[';
- for (j in item_objectives[i]) {
- obj_temp += item_objectives[i][j]+',';
- }
- obj_temp = obj_temp.substr(0,(obj_temp.length-2)) + ']';
- obj_string += encodeURIComponent(obj_temp);
- }
- params += obj_string;
- $.ajax({
- type: "POST",
- data: params,
- url: "lp_ajax_save_objectives.php",
- dataType: "script",
- async: false
- });
+ params='';
+ params += 'lid='+lms_lp_id+'&uid='+lms_user_id+'&vid='+lms_view_id;
+ params += '&iid='+lms_item_id;
+ obj_string = '';
+ for (i in item_objectives){
+ obj_string += '&objectives['+i+']=';
+ obj_temp = '[';
+ for (j in item_objectives[i]) {
+ obj_temp += item_objectives[i][j]+',';
+ }
+ obj_temp = obj_temp.substr(0,(obj_temp.length-2)) + ']';
+ obj_string += encodeURIComponent(obj_temp);
+ }
+ params += obj_string;
+ $.ajax({
+ type: "POST",
+ data: params,
+ url: "lp_ajax_save_objectives.php",
+ dataType: "script",
+ async: false
+ });
}
/**
* Switch between two items through
* an AJAX call. Originally, we used the xajax library. Now we use jQuery
*/
function xajax_switch_item_details(lms_lp_id,lms_user_id,lms_view_id,lms_item_id,next_item) {
- params = {
- 'lid': lms_lp_id,
- 'uid': lms_user_id,
- 'vid': lms_view_id,
- 'iid': lms_item_id,
- 'next': next_item
- }
- $.ajax({
- type: "POST",
- data: params,
- url: "lp_ajax_switch_item.php",
- dataType: "script",
- async: false
- });
+ params = {
+ 'lid': lms_lp_id,
+ 'uid': lms_user_id,
+ 'vid': lms_view_id,
+ 'iid': lms_item_id,
+ 'next': next_item
+ }
+ $.ajax({
+ type: "POST",
+ data: params,
+ url: "lp_ajax_switch_item.php",
+ dataType: "script",
+ async: false
+ });
}
addEvent(window,'load',addListeners,false);
diff --git a/main/newscorm/aicc_hacp.php b/main/newscorm/aicc_hacp.php
index 9eb8f8fd5d..0eba1700e2 100755
--- a/main/newscorm/aicc_hacp.php
+++ b/main/newscorm/aicc_hacp.php
@@ -1,15 +1,17 @@
-
- * @author Yannick Warnier
+ * @author Yannick Warnier
* @version v 1.0
* @access public
* @package chamilo.learnpath
* @license GNU/GPL
*/
+
/**
* This script is divided into three sections.
* The first section (below) is the initialisation part.
@@ -29,48 +31,44 @@
* Only suspend_data and core.lesson_location should be sent updated to a late GetParam
* request. All other params should be as when the AU was launched.
*/
-/*
-==============================================================================
- INIT SECTION
-==============================================================================
-*/
+
+/* INIT SECTION */
+
$debug = 0;
-//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;
-//Use session ID as provided by the request
-if(!empty($_REQUEST['aicc_sid']))
-{
+// Use session ID as provided by the request.
+if (!empty($_REQUEST['aicc_sid'])) {
session_id($_REQUEST['aicc_sid']);
- if($debug>1){error_log('New LP - '.__FILE__.','.__LINE__.' - reusing session ID '.$_REQUEST['aicc_sid'],0);}
+ if ($debug > 1) { error_log('New LP - '.__FILE__.','.__LINE__.' - reusing session ID '.$_REQUEST['aicc_sid'], 0); }
}
-//Load common libraries using a compatibility script to bridge between 1.6 and 1.8
+//Load common libraries using a compatibility script to bridge between 1.6 and 1.8.
require_once 'back_compat.inc.php';
-if($debug>2){error_log('New LP - '.__FILE__.','.__LINE__.' - Current session ID: '.session_id(),0);}
-//Load learning path libraries so we can use the objects to define the initial values
-//of the API
+if ($debug > 2) { error_log('New LP - '.__FILE__.','.__LINE__.' - Current session ID: '.session_id(), 0); }
+//Load learning path libraries so we can use the objects to define the initial values of the API.
require_once 'learnpath.class.php';
require_once 'learnpathItem.class.php';
require_once 'aicc.class.php';
-// Is this needed? This is probabaly done in the header file
+// Is this needed? This is probabaly done in the header file.
//$_user = $_SESSION['_user'];
$file = $_SESSION['file'];
$oLP = unserialize($_SESSION['lpobject']);
$oItem =& $oLP->items[$oLP->current];
-if(!is_object($oItem)){
- error_log('New LP - aicc_hacp - Could not load oItem item',0);
+if (!is_object($oItem)) {
+ error_log('New LP - aicc_hacp - Could not load oItem item', 0);
exit;
}
$autocomplete_when_80pct = 0;
$result = array(
- 'core'=>array(),
- 'core_lesson'=>array(),
- 'core_vendor'=>array(),
- 'evaluation'=>array(),
- 'student_data'=>array(),
+ 'core' => array(),
+ 'core_lesson' => array(),
+ 'core_vendor' => array(),
+ 'evaluation' => array(),
+ 'student_data' => array(),
);
$convert_enc = array('%25','%0D','%0A','%09','%20','%2D','%2F','%3B','%3F','%7B','%7D','%7C','%5C','%5E','%7E','%5B','%5D','%60','%23','%3E','%3C','%22');
$convert_dec = array('%',"\r","\n","\t",' ','-','/',';','?','{','}','|','\\','^','~','[',']','`','#','>','<','"');
@@ -80,24 +78,22 @@ $s_ec = 'error='; //string for error code
$s_et = 'error_text='; //string for error text
$s_ad = 'aicc_data='; //string for aicc_data
-$errors = array(0=>'Successful',1=>'Invalid Command',2=>'Invalid AU password',3=>'Invalid Session ID');
+$errors = array(0 => 'Successful', 1 => 'Invalid Command', 2 => 'Invalid AU password', 3 => 'Invalid Session ID');
$error_code = 0;
$error_text = '';
$aicc_data = '';
$result = '';
-//GET REQUEST
-if(!empty($_REQUEST['command']))
-{
- //error_log('In '.__FILE__.', '.__LINE__.' - request is '.$_REQUEST['command'],0);
- switch(strtolower($_REQUEST['command']))
- {
+// Get REQUEST
+if (!empty($_REQUEST['command'])) {
+ //error_log('In '.__FILE__.', '.__LINE__.' - request is '.$_REQUEST['command'], 0);
+ switch (strtolower($_REQUEST['command'])) {
case 'getparam':
- //request for all available data to be printed out in the answer
- if(!empty($_REQUEST['version'])){
+ // Request for all available data to be printed out in the answer.
+ if (!empty($_REQUEST['version'])) {
$hacp_version = learnpath::escape_string($_REQUEST['version']);
}
- if(!empty($_REQUEST['session_id'])){
+ if (!empty($_REQUEST['session_id'])) {
$hacp_session_id = learnpath::escape_string($_REQUEST['session_id']);
}
$error_code = 0;
@@ -127,18 +123,16 @@ if(!empty($_REQUEST['command']))
//$result .= '[Student_Preferences]'.$crlf;
//error_log('Returning message: '.$result,0);
- $result = str_replace($convert_dec,$convert_enc,$result);
+ $result = str_replace($convert_dec, $convert_enc, $result);
//error_log('Returning message (encoded): '.$result,0);
break;
case 'putparam':
$hacp_version = '';
$hacp_session_id = '';
$hacp_aicc_data = '';
- foreach($_REQUEST as $name => $value)
- {
+ foreach ($_REQUEST as $name => $value) {
//escape the value as described in the AICC documentation p170
- switch(strtolower($name))
- {
+ switch (strtolower($name)) {
case 'version':
$hacp_version = $value;
break;
@@ -146,43 +140,43 @@ if(!empty($_REQUEST['command']))
$hacp_session_id = $value;
break;
case 'aicc_data':
- //error_log('In '.__FILE__.', '.__LINE__.' - aicc data before translation is '.$value,0);
- $value = str_replace('+',' ',$value);
- $value = str_replace($convert_enc,$convert_dec,$value);
+ //error_log('In '.__FILE__.', '.__LINE__.' - aicc data before translation is '.$value, 0);
+ $value = str_replace('+', ' ', $value);
+ $value = str_replace($convert_enc, $convert_dec, $value);
$hacp_aicc_data = $value;
break;
}
}
- //error_log('In '.__FILE__.', '.__LINE__.' - aicc data is '.$hacp_aicc_data,0);
- //treat the incoming request:
- $msg_array = aicc::parse_ini_string_quotes_safe($hacp_aicc_data,array('core_lesson','core_vendor'));
- //error_log('Message is now in this form: '.print_r($msg_array,true),0);
- foreach($msg_array as $key=>$dummy){
- switch (strtolower($key)){
+ //error_log('In '.__FILE__.', '.__LINE__.' - aicc data is '.$hacp_aicc_data, 0);
+ // Treat the incoming request:
+ $msg_array = aicc::parse_ini_string_quotes_safe($hacp_aicc_data, array('core_lesson', 'core_vendor'));
+ //error_log('Message is now in this form: '.print_r($msg_array, true), 0);
+ foreach ($msg_array as $key => $dummy) {
+ switch (strtolower($key)) {
case 'core':
- foreach($msg_array[$key] as $subkey => $value){
- switch(strtolower($subkey)){
+ foreach ($msg_array[$key] as $subkey => $value){
+ switch (strtolower($subkey)) {
case 'lesson_location':
- //error_log('Setting lesson_location to '.$value,0);
+ //error_log('Setting lesson_location to '.$value, 0);
$oItem->set_lesson_location($value);
break;
case 'lesson_status':
- //error_log('Setting lesson_status to '.$value,0);
+ //error_log('Setting lesson_status to '.$value, 0);
$oItem->set_status($value);
break;
case 'score':
- //error_log('Setting lesson_score to '.$value,0);
+ //error_log('Setting lesson_score to '.$value, 0);
$oItem->set_score($value);
break;
case 'time':
- //error_log('Setting lesson_time to '.$value,0);
+ //error_log('Setting lesson_time to '.$value, 0);
$oItem->set_time($value);
break;
}
}
break;
case 'core_lesson':
- //error_log('Setting suspend_data to '.print_r($msg_array[$key],true),0);
+ //error_log('Setting suspend_data to '.print_r($msg_array[$key], true), 0);
$oItem->current_data = $msg_array[$key];
break;
case 'comments':
@@ -238,7 +232,6 @@ if(!empty($_REQUEST['command']))
}
}
$_SESSION['lpobject'] = serialize($oLP);
-//content type must be text/plain
+// Content type must be text/plain.
header('Content-type: text/plain');
echo $result;
-?>
\ No newline at end of file
diff --git a/main/newscorm/js/api_wrapper.js b/main/newscorm/js/api_wrapper.js
index 0b514da98c..daa1ed0355 100755
--- a/main/newscorm/js/api_wrapper.js
+++ b/main/newscorm/js/api_wrapper.js
@@ -1,5 +1,5 @@
/**
- * Wrapper to the SCORM API provided by Dokeos
+ * Wrapper to the SCORM API provided by Chamilo
* The complete set of functions and variables are in this file to avoid unnecessary file
* accesses.
* Only event triggers and answer data are inserted into the final document.
@@ -9,7 +9,7 @@
/**
* Initialisation of the SCORM API section.
* Find the SCO functions (startTimer, computeTime, etc in the second section)
- * Find the Dokeos-proper functions (checkAnswers, etc in the third section)
+ * Find the Chamilo-proper functions (checkAnswers, etc in the third section)
*/
var _debug = false;
var findAPITries = 0;
@@ -413,7 +413,7 @@ function unloadPage(status)
}
}
/**
- * Third section - depending on Dokeos - check answers and set score
+ * Third section - depending on Chamilo - check answers and set score
*/
var questions = new Array();
var questions_answers = new Array();