diff --git a/main/newscorm/learnpath.class.php b/main/newscorm/learnpath.class.php index b6aa564a04..50ecf592d3 100644 --- a/main/newscorm/learnpath.class.php +++ b/main/newscorm/learnpath.class.php @@ -7259,7 +7259,14 @@ function display_thread_form($action = 'add', $id = 0, $extra_info = '') $organizations->setAttribute('default','dokeos_scorm_export'); $organization = $xmldoc->createElement('organization'); $organization->setAttribute('identifier','dokeos_scorm_export'); - $org_title = $xmldoc->createElement('title',htmlspecialchars($this->get_name(),ENT_QUOTES)); //filter data for XML? + //to set the title of the SCORM entity (=organization), we take the name given + //in Dokeos and convert it to HTML entities using the Dokeos charset (not the + //learning path charset) as it is the encoding that defines how it is stored + //in the database. Then we convert it to HTML entities again as the "&" character + //alone is not authorized in XML (must be &) + //The title is then decoded twice when extracting (see scorm::parse_manifest) + global $charset; + $org_title = $xmldoc->createElement('title',htmlentities(htmlentities($this->get_name(),ENT_QUOTES,$charset))); $organization->appendChild($org_title); //For each element, add it to the imsmanifest structure, then add it to the zip. @@ -7954,7 +7961,7 @@ EOD; //Send file to client //$name = 'scorm_export_'.$this->lp_id.'.zip'; require_once(api_get_path(LIBRARY_PATH).'fileUpload.lib.php'); - $name = replace_dangerous_char($this->get_name()).'.zip'; + $name = preg_replace('([^a-zA-Z0-9_\.])','',html_entity_decode($this->get_name(),ENT_QUOTES)).'.zip'; DocumentManager::file_send_for_download($temp_zip_file,true,$name); } /** diff --git a/main/newscorm/scorm.class.php b/main/newscorm/scorm.class.php index 48eee772c2..3b21b1671f 100644 --- a/main/newscorm/scorm.class.php +++ b/main/newscorm/scorm.class.php @@ -82,7 +82,7 @@ class scorm extends learnpath { if(!empty($doc->encoding)){ $this->manifest_encoding = strtoupper($doc->encoding); } - if($this->debug>1){error_log('New LP - Called xmldoc() (encoding:'.strtoupper($doc->encoding).')',0);} + if($this->debug>1){error_log('New LP - Called xmldoc() (encoding:'.strtoupper($doc->encoding).' - saved: '.$this->manifest_encoding.')',0);} if(!$doc) { if($this->debug>1){error_log('New LP - File '.$file.' is not an XML file',0);} @@ -151,7 +151,7 @@ class scorm extends learnpath { //$found_an_org = true; $this->organizations_att[$organizations_attributes[$d1]->name] = $organizations_attributes[$d1]->value; } - $oOrganization = new scormOrganization('manifest',$orgnode); + $oOrganization = new scormOrganization('manifest',$orgnode,$this->manifest_encoding); if($oOrganization->identifier != ''){ $name = $oOrganization->get_name(); if(empty($name)){ @@ -218,7 +218,7 @@ class scorm extends learnpath { if(!empty($doc->xmlEncoding)){ $this->manifest_encoding = strtoupper($doc->xmlEncoding); } - if($this->debug>1){error_log('New LP - Called (encoding:'.$doc->xmlEncoding.')',0);} + if($this->debug>1){error_log('New LP - Called (encoding:'.$doc->xmlEncoding.' - saved: '.$this->manifest_encoding.')',0);} $root = $doc->documentElement; if($root->hasAttributes()){ @@ -282,7 +282,7 @@ class scorm extends learnpath { { $this->organizations_att[$orgs_attr->name] = $orgs_attr->value; } - $oOrganization = new scormOrganization('manifest',$orgnode); + $oOrganization = new scormOrganization('manifest',$orgnode,$this->manifest_encoding); if($oOrganization->identifier != ''){ $name = $oOrganization->get_name(); if(empty($name)){ @@ -379,9 +379,10 @@ class scorm extends learnpath { $dsp = $row[0]+1; } $myname = $oOrganization->get_name(); - $this->manifest_encoding = 'UTF-8'; - if($this->manifest_encoding != 'ISO-8859-1'){ - $myname = mb_convert_encoding($myname,'ISO-8859-1',$this->manifest_encoding); + //$this->manifest_encoding = 'UTF-8'; + global $charset; + if($this->manifest_encoding != $charset){ + $myname = mb_convert_encoding($myname,$charset,$this->manifest_encoding); //error_log('New LP - Converting name from '.$this->manifest_encoding.' to ISO-8859-1',0); } $sql = "INSERT INTO $new_lp (lp_type, name, ref, description, path, force_commit, default_view_mod, default_encoding, js_lib,display_order)" . @@ -440,8 +441,14 @@ class scorm extends learnpath { $value_add .= "'".$item['maxtimeallowed']."',"; } $title = mysql_real_escape_string($item['title']); - //if($this->manifest_encoding != 'ISO-8859-1'){ - //$title = mb_convert_encoding($title,'ISO-8859-1',$this->manifest_encoding); + //DOM in PHP5 is always recovering data as UTF-8, somehow, no matter what + //the XML document encoding is. This means that we have to convert + //the data to the declared encoding when it is not UTF-8 + if($this->manifest_encoding != 'UTF-8'){ + $title = mb_convert_encoding($title,$this->manifest_encoding,'UTF-8'); + } + //if($this->manifest_encoding != $charset){ + // $title = mb_convert_encoding($title,$charset,$this->manifest_encoding); //} $identifier = mysql_real_escape_string($item['identifier']); $prereq = mysql_real_escape_string($item['prerequisites']); diff --git a/main/newscorm/scormOrganization.class.php b/main/newscorm/scormOrganization.class.php index 1b8f52e179..985e9e96da 100644 --- a/main/newscorm/scormOrganization.class.php +++ b/main/newscorm/scormOrganization.class.php @@ -19,7 +19,7 @@ class scormOrganization { * @param string Type of construction needed ('db' or 'manifest', default = 'manifest') * @param mixed Depending on the type given, DB id for the lp_item or reference to the DOM element */ - function scormOrganization($type='manifest',&$element) { + function scormOrganization($type='manifest',&$element,$scorm_charset='UTF-8') { if(isset($element)) { $v = substr(phpversion(),0,1); @@ -107,7 +107,7 @@ class scormOrganization { $tmp_children = $child->childNodes; if($tmp_children->length==1 and $child->firstChild->nodeValue != '' ) { - $this->title = $child->firstChild->nodeValue; + $this->title = html_entity_decode(html_entity_decode($child->firstChild->nodeValue,ENT_QUOTES,$scorm_charset)); } break; }