12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028 |
- <?php
- require_once('scormItem.class.php');
- require_once('scormMetadata.class.php');
- require_once('scormOrganization.class.php');
- require_once('scormResource.class.php');
- class scorm extends learnpath {
- var $manifest = array();
- var $resources = array();
- var $resources_att = array();
- var $organizations = array();
- var $organizations_att = array();
- var $metadata = array();
- var $idrefs = array();
- var $refurls = array();
- var $subdir = '';
- var $items = array();
- var $zipname = '';
- var $lastzipnameindex = 0;
- var $manifest_encoding = 'UTF-8';
- var $debug = 0;
-
- function scorm($course_code=null,$resource_id=null,$user_id=null) {
- if($this->debug>0){error_log('New LP - scorm::scorm('.$course_code.','.$resource_id.','.$user_id.') - In scorm constructor',0);}
- if(!empty($course_code) and !empty($resource_id) and !empty($user_id))
- {
- parent::learnpath($course_code, $resource_id, $user_id);
- }else{
-
- }
- }
-
- function open($id)
- {
- if($this->debug>0){error_log('New LP - scorm::open() - In scorm::open method',0);}
-
- }
-
-
-
- function parse_manifest($file='')
- {
- if($this->debug>0){error_log('In scorm::parse_manifest('.$file.')',0);}
- if(empty($file)){
-
- }
- if(is_file($file) and is_readable($file))
- {
- $v = substr(phpversion(),0,1);
- if($v == 4){
- if($this->debug>0){error_log('In scorm::parse_manifest() - Parsing using PHP4 method',0);}
- $var = file_get_contents($file);
-
- $var = preg_replace('/xml:id=["\']id_\d{1,4}["\']/i','',$var);
- $doc = xmldoc($var);
-
-
- if(!empty($doc->encoding)){
- $this->manifest_encoding = strtoupper($doc->encoding);
- }
- 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);}
-
- return null;
- }else{
- if($this->debug>1){error_log('New LP - File '.$file.' is XML',0);}
- $root = $doc->root();
- $attributes = $root->attributes();
- for($a=0; $a<sizeof($attributes);$a++)
- {
- if($attributes[$a]->type == XML_ATTRIBUTE_NODE){
- $this->manifest[$attributes[$a]->name] = $attributes[$a]->value;
- }
- }
- $this->manifest['name'] = $root->name;
- $children = $root->children();
- for($b=0; $b<sizeof($children);$b++)
- {
-
- if($children[$b]->type == XML_ELEMENT_NODE){
- switch($children[$b]->tagname){
- case 'metadata':
-
- $this->metadata = new scormMetadata('manifest',$children[$b]);
- break;
- case 'organizations':
-
- $orgs_attribs = $children[$b]->attributes();
- for($c=0; $c<sizeof($orgs_attribs);$c++)
- {
- if($orgs_attribs[$c]->type == XML_ATTRIBUTE_NODE){
- $this->manifest['organizations'][$orgs_attribs[$c]->name] = $orgs_attribs[$c]->value;
- }
- }
- $orgs_nodes = $children[$b]->children();
- $i = 0;
- $found_an_org = false;
- foreach($orgs_nodes as $c => $dummy)
- {
-
-
-
-
-
-
-
- $found_an_org = false;
- $orgnode =& $orgs_nodes[$c];
- switch($orgnode->type){
- case XML_TEXT_NODE:
-
- break;
- case XML_ATTRIBUTE_NODE:
-
-
-
-
- break;
- case XML_ELEMENT_NODE:
-
- $organizations_attributes = $orgnode->attributes();
- foreach($organizations_attributes as $d1 => $dummy)
- {
-
-
- $this->organizations_att[$organizations_attributes[$d1]->name] = $organizations_attributes[$d1]->value;
- }
- $oOrganization = new scormOrganization('manifest',$orgnode,$this->manifest_encoding);
- if($oOrganization->identifier != ''){
- $name = $oOrganization->get_name();
- if(empty($name)){
-
- $myname = $this->zipname;
- if($this->lastzipnameindex != 0){
- $myname = $myname + $this->lastzipnameindex;
- $this->lastzipnameindex++;
- }
- $oOrganization->set_name($this->zipname);
- }
- $this->organizations[$oOrganization->identifier] = $oOrganization;
- }
- break;
- }
- }
- break;
- case 'resources':
- $resources_attribs = $children[$b]->attributes();
- for($c=0; $c<sizeof($resources_attribs);$c++)
- {
- if($resources_attribs[$c]->type == XML_ATTRIBUTE_NODE){
- $this->manifest['resources'][$resources_attribs[$c]->name] = $resources_attribs[$c]->value;
- }
- }
- $resources_nodes = $children[$b]->children();
- $i = 0;
- foreach($resources_nodes as $c => $dummy)
- {
-
- $oResource = new scormResource('manifest',$resources_nodes[$c]);
- if($oResource->identifier != ''){
- $this->resources[$oResource->identifier] = $oResource;
- $i++;
- }
- }
-
- break;
- case 'manifest':
-
- break;
- }
- }
- }
- }
- unset($doc);
- }elseif($v==5){
- if($this->debug>0){error_log('In scorm::parse_manifest() - Parsing using PHP5 method',0);}
- $doc = new DOMDocument();
- $res = $doc->load($file);
- if($res===false){
- if($this->debug>0){error_log('New LP - In scorm::parse_manifest() - Exception thrown when loading '.$file.' in DOMDocument',0);}
-
- return null;
- }
- if(!empty($doc->xmlEncoding)){
- $this->manifest_encoding = strtoupper($doc->xmlEncoding);
- }
- if($this->debug>1){error_log('New LP - Called (encoding:'.$doc->xmlEncoding.' - saved: '.$this->manifest_encoding.')',0);}
- $root = $doc->documentElement;
- if($root->hasAttributes()){
- $attributes = $root->attributes;
- if($attributes->length !== 0){
- foreach($attributes as $attrib)
- {
- $this->manifest[$attrib->name] = $attrib->value;
- }
- }
- }
- $this->manifest['name'] = $root->tagName;
- if($root->hasChildNodes()){
- $children = $root->childNodes;
- if($children->length !== 0){
- foreach($children as $child)
- {
-
- if($child->nodeType == XML_ELEMENT_NODE){
- switch($child->tagName){
- case 'metadata':
-
- $this->metadata = new scormMetadata('manifest',$child);
- break;
- case 'organizations':
-
- $orgs_attribs = $child->attributes;
- foreach($orgs_attribs as $orgs_attrib)
- {
- if($orgs_attrib->nodeType == XML_ATTRIBUTE_NODE){
- $this->manifest['organizations'][$orgs_attrib->name] = $orgs_attrib->value;
- }
- }
- $orgs_nodes = $child->childNodes;
- $i = 0;
- $found_an_org = false;
- foreach($orgs_nodes as $orgnode)
- {
-
-
-
-
-
-
-
- $found_an_org = false;
- switch($orgnode->nodeType){
- case XML_TEXT_NODE:
-
- break;
- case XML_ATTRIBUTE_NODE:
-
-
-
-
- break;
- case XML_ELEMENT_NODE:
-
- $organizations_attributes = $orgnode->attributes;
- foreach($organizations_attributes as $orgs_attr)
- {
- $this->organizations_att[$orgs_attr->name] = $orgs_attr->value;
- }
- $oOrganization = new scormOrganization('manifest',$orgnode,$this->manifest_encoding);
- if($oOrganization->identifier != ''){
- $name = $oOrganization->get_name();
- if(empty($name)){
-
- $myname = $this->zipname;
- if($this->lastzipnameindex != 0){
- $myname = $myname + $this->lastzipnameindex;
- $this->lastzipnameindex++;
- }
- $oOrganization->set_name($this->zipname);
- }
- $this->organizations[$oOrganization->identifier] = $oOrganization;
- }
- break;
- }
- }
- break;
- case 'resources':
- if($child->hasAttributes()){
- $resources_attribs = $child->attributes;
- foreach($resources_attribs as $res_attr)
- {
- if($res_attr->type == XML_ATTRIBUTE_NODE){
- $this->manifest['resources'][$res_attr->name] = $res_attr->value;
- }
- }
- }
- if($child->hasChildNodes()){
- $resources_nodes = $child->childNodes;
- $i = 0;
- foreach($resources_nodes as $res_node)
- {
- $oResource = new scormResource('manifest',$res_node);
- if($oResource->identifier != ''){
- $this->resources[$oResource->identifier] = $oResource;
- $i++;
- }
- }
- }
-
- break;
- case 'manifest':
-
- break;
- }
- }
- }
- }
- }
- unset($doc);
- }else{
- if($this->debug>0){error_log('In scorm::parse_manifest() - PHP version is not 4 nor 5, cannot parse',0);}
- $this->set_error_msg("Parsing impossible because PHP version is not 4 nor 5");
- return null;
- }
- }else{
- if($this->debug>1){error_log('New LP - Could not open/read file '.$file,0);}
- $this->set_error_msg("File $file could not be read");
- return null;
- }
-
- return $this->manifest;
- }
-
- function import_manifest($course_code){
- if($this->debug>0){error_log('New LP - Entered import_manifest('.$course_code.')',0);}
- $sql = "SELECT * FROM ".Database::get_main_table(TABLE_MAIN_COURSE)." WHERE code='$course_code'";
- $res = Database::query($sql,__FILE__,__LINE__);
- if(Database::num_rows($res)<1){ error_log('Database for '.$course_code.' not found '.__FILE__.' '.__LINE__,0);return -1;}
- $row = Database::fetch_array($res);
- $dbname = $row['db_name'];
-
- $new_lp = Database::get_course_table(TABLE_LP_MAIN, $dbname);
- $new_lp_item = Database::get_course_table(TABLE_LP_ITEM, $dbname);
- foreach($this->organizations as $id => $dummy)
- {
- $oOrganization =& $this->organizations[$id];
-
-
-
-
- $get_max = "SELECT MAX(display_order) FROM $new_lp";
- $res_max = Database::query($get_max);
- $dsp = 1;
- if(Database::num_rows($res_max)>0){
- $row = Database::fetch_array($res_max);
- $dsp = $row[0]+1;
- }
- $myname = $oOrganization->get_name();
-
- global $charset;
- if(!empty($charset) && !empty($this->manifest_encoding) && $this->manifest_encoding != $charset){
- $myname = api_convert_encoding($myname,$charset,$this->manifest_encoding);
- }
- $sql = "INSERT INTO $new_lp (lp_type, name, ref, description, path, force_commit, default_view_mod, default_encoding, js_lib,display_order)" .
- "VALUES (2,'".$myname."', '".$oOrganization->get_ref()."','','".$this->subdir."', 0, 'embedded', '".$this->manifest_encoding."','scorm_api.php',$dsp)";
- if($this->debug>1){error_log('New LP - In import_manifest(), inserting path: '. $sql,0);}
- $res = Database::query($sql,__FILE__,__LINE__);
- $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());
-
-
- $list = $oOrganization->get_flat_items_list();
- $parents_stack = array(0);
- $parent = 0;
- $previous = 0;
- $level = 0;
- foreach($list as $item){
- if($item['level'] > $level){
-
- array_push($parents_stack,$previous);
- $parent = $previous;
- }elseif($item['level'] < $level){
- $diff = $level - $item['level'];
-
- for($j=1;$j<=$diff;$j++){
- $outdated_parent = array_pop($parents_stack);
- }
- $parent = array_pop($parents_stack);
- array_push($parents_stack,$parent);
- }
- $path = '';
- $type = 'dir';
- if(isset($this->resources[$item['identifierref']])){
- $oRes =& $this->resources[$item['identifierref']];
- $path = @$oRes->get_path();
- if(!empty($path)){
- $temptype = $oRes->get_scorm_type();
- if(!empty($temptype)){
- $type = $temptype;
- }
- }
- }
- $level = $item['level'];
- $field_add = '';
- $value_add = '';
- if(!empty($item['masteryscore'])){
- $field_add .= 'mastery_score, ';
- $value_add .= $item['masteryscore'].',';
- }
- if(!empty($item['maxtimeallowed']))
- {
- $field_add .= 'max_time_allowed, ';
- $value_add .= "'".$item['maxtimeallowed']."',";
- }
- $title = Database::escape_string($item['title']);
- $max_score = Database::escape_string($item['max_score']);
- if ($max_score==0 || is_null($max_score) || $max_score=='') {
- $max_score=100;
- }
-
-
-
- if($this->manifest_encoding != 'UTF-8'){
- $title = api_convert_encoding($title,$this->manifest_encoding,'UTF-8');
- }
-
-
-
- $identifier = Database::escape_string($item['identifier']);
- $prereq = Database::escape_string($item['prerequisites']);
- $sql_item = "INSERT INTO $new_lp_item " .
- "(lp_id,item_type,ref,title," .
- "path,min_score,max_score, $field_add" .
- "parent_item_id,previous_item_id,next_item_id," .
- "prerequisite,display_order,launch_data," .
- "parameters) " .
- "VALUES " .
- "($lp_id, '$type','".$identifier."','".$title."'," .
- "'$path',0,'$max_score', $value_add" .
- "$parent, $previous, 0, " .
- "'$prereq', ".$item['rel_order'] .", '".$item['datafromlms']."'," .
- "'".$item['parameters']."'" .
- ")";
- $res_item = Database::query($sql_item);
- if($this->debug>1){error_log('New LP - In import_manifest(), inserting item : '.$sql_item.' : '.mysql_error(),0);}
- $item_id = Database::insert_id();
-
- $upd = "UPDATE $new_lp_item SET next_item_id = $item_id WHERE id = $previous";
- $upd_res = Database::query($upd);
-
- $previous = $item_id;
-
- if (!empty($_POST['index_document'])) {
- require_once(api_get_path(LIBRARY_PATH).'search/DokeosIndexer.class.php');
- require_once(api_get_path(LIBRARY_PATH).'search/IndexableChunk.class.php');
- require_once(api_get_path(LIBRARY_PATH).'specific_fields_manager.lib.php');
- $di = new DokeosIndexer();
- isset($_POST['language'])? $lang=Database::escape_string($_POST['language']): $lang = 'english';
- $di->connectDb(NULL, NULL, $lang);
- $ic_slide = new IndexableChunk();
- $ic_slide->addValue("title", $title);
- $specific_fields = get_specific_field_list();
- $all_specific_terms = '';
- foreach ($specific_fields as $specific_field) {
- if (isset($_REQUEST[$specific_field['code']])) {
- $sterms = trim($_REQUEST[$specific_field['code']]);
- $all_specific_terms .= ' '. $sterms;
- if (!empty($sterms)) {
- $sterms = explode(',', $sterms);
- foreach ($sterms as $sterm) {
- $ic_slide->addTerm(trim($sterm), $specific_field['code']);
- }
- }
- }
- }
- $body_to_index = $all_specific_terms .' '. $title;
- $ic_slide->addValue("content", $body_to_index);
-
- $courseid = api_get_course_id();
- $ic_slide->addCourseId($courseid);
- $ic_slide->addToolId(TOOL_LEARNPATH);
- $xapian_data = array(
- SE_COURSE_ID => $courseid,
- SE_TOOL_ID => TOOL_LEARNPATH,
- SE_DATA => array('lp_id' => $lp_id, 'lp_item'=> $previous, 'document_id' => ''),
- SE_USER => (int)api_get_user_id(),
- );
- $ic_slide->xapian_data = serialize($xapian_data);
- $di->addChunk($ic_slide);
-
- $did = $di->index();
- if ($did) {
-
- $tbl_se_ref = Database::get_main_table(TABLE_MAIN_SEARCH_ENGINE_REF);
- $sql = 'INSERT INTO %s (id, course_code, tool_id, ref_id_high_level, ref_id_second_level, search_did)
- VALUES (NULL , \'%s\', \'%s\', %s, %s, %s)';
- $sql = sprintf($sql, $tbl_se_ref, api_get_course_id(), TOOL_LEARNPATH, $lp_id, $previous, $did);
- Database::query($sql,__FILE__,__LINE__);
- }
- }
- }
- }
- }
-
- function import_local_package($file_path,$current_dir='')
- {
-
- $file_info = array();
- $file_info['tmp_name'] = $file_path;
- $file_info['name'] = basename($file_path);
-
- return $this->import_package($file_info,$current_dir);
- }
-
- function import_package($zip_file_info,$current_dir = '')
- {
- if($this->debug>0){error_log('In scorm::import_package('.print_r($zip_file_info,true).',"'.$current_dir.'") method',0);}
- $maxFilledSpace = 1000000000;
- $zip_file_path = $zip_file_info['tmp_name'];
- $zip_file_name = $zip_file_info['name'];
- if($this->debug>1){error_log('New LP - import_package() - zip file path = '.$zip_file_path.', zip file name = '.$zip_file_name,0);}
- $course_rel_dir = api_get_course_path().'/scorm';
- $course_sys_dir = api_get_path(SYS_COURSE_PATH).$course_rel_dir;
- $current_dir = replace_dangerous_char(trim($current_dir),'strict');
- if($this->debug>1){error_log('New LP - import_package() - current_dir = '.$current_dir,0);}
-
-
- if($this->debug>1){error_log('New LP - 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);
- $this->zipname = $file_base_name;
- if($this->debug>1){error_log("New LP - 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>1){error_log("New LP - subdir is first set to : ".$this->subdir,0);}
- $zipFile = new pclZip($zip_file_path);
-
- $zipContentArray = $zipFile->listContent();
- $package_type='';
- $at_root = false;
- $manifest = '';
- $manifest_list = array();
-
- foreach($zipContentArray as $thisContent)
- {
-
- if ( preg_match('~.(php.*|phtml)$~i', $thisContent['filename']) )
- {
- $this->set_error_msg("File $file contains a PHP script");
-
- }
- elseif(stristr($thisContent['filename'],'imsmanifest.xml'))
- {
-
- if($thisContent['filename'] == basename($thisContent['filename'])){
- $at_root = true;
- }else{
-
- if($this->debug>2){error_log("New LP - subdir is now ".$this->subdir,0);}
- }
- $package_type = 'scorm';
- $manifest_list[] = $thisContent['filename'];
- $manifest = $thisContent['filename'];
- }
- else
- {
-
- }
- $realFileSize += $thisContent['size'];
- }
-
- $shortest_path = $manifest_list[0];
- $slash_count = substr_count($shortest_path,'/');
- foreach($manifest_list as $manifest_path){
- $tmp_slash_count = substr_count($manifest_path,'/');
- if($tmp_slash_count<$slash_count){
- $shortest_path = $manifest_path;
- $slash_count = $tmp_slash_count;
- }
- }
- $this->subdir .= '/'.dirname($shortest_path);
- $manifest = $shortest_path;
- if($this->debug>1){error_log('New LP - Package type is now '.$package_type,0);}
- if($package_type== '')
-
- {
- return api_failure::set_failure('not_scorm_content');
- }
- if (! enough_size($realFileSize, $course_sys_dir, $maxFilledSpace) )
- {
- return api_failure::set_failure('not_enough_space');
- }
-
- if($new_dir[0] != '/')
- {
- $new_dir='/'.$new_dir;
- }
- if($new_dir[strlen($new_dir)-1] == '/')
- {
- $new_dir=substr($new_dir,0,-1);
- }
-
-
- if(is_dir($course_sys_dir.$new_dir) OR @mkdir($course_sys_dir.$new_dir))
- {
-
- 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;$j<count($unzippingState);$j++)
- {
- $state=$unzippingState[$j];
-
- $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))
- {
- $new_dir = $new_dir.'/';
- }
-
- 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";
-
-
- $find_str = array('\\','.php','.phtml');
- $repl_str = array('/', '.txt','.txt');
- $safe_file = str_replace($find_str,$repl_str,$file);
- if($safe_file != $file){
-
- $mydir = dirname($course_sys_dir.$new_dir.$safe_file);
- if(!is_dir($mydir)){
- $mysubdirs = split('/',$mydir);
- $mybasedir = '/';
- foreach($mysubdirs as $mysubdir){
- if(!empty($mysubdir)){
- $mybasedir = $mybasedir.$mysubdir.'/';
- if(!is_dir($mybasedir)){
- @mkdir($mybasedir);
- 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);}
- }
-
- }
- }
- closedir($dir);
- chdir($saved_dir);
- $perm = api_get_setting('permissions_for_new_directories');
- $perm = octdec(!empty($perm)?$perm:'0770');
- api_chmod_R($course_sys_dir.$new_dir , $perm);
- }
- }else{
- return '';
- }
- return $course_sys_dir.$new_dir.$manifest;
- }
-
- function set_proximity($proxy=''){
- if($this->debug>0){error_log('In scorm::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_theme($theme=''){
- if($this->debug>0){error_log('In scorm::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_preview_image($preview_image=''){
- if($this->debug>0){error_log('In scorm::set_theme('.$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_author($author=''){
- if($this->debug>0){error_log('In scorm::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_maker($maker=''){
- if($this->debug>0){error_log('In scorm::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;
- }
- }
-
- function export_zip($lp_id=null){
- if($this->debug>0){error_log('In scorm::export_zip method('.$lp_id.')',0);}
- if(empty($lp_id)){
- if(!is_object($this))
- {
- return false;
- }
- else{
- $id = $this->get_id();
- if(empty($id)){
- return false;
- }
- else{
- $lp_id = $this->get_id();
- }
- }
- }
-
-
-
- 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");
- require_once (api_get_path(LIBRARY_PATH)."pclzip/pclzip.lib.php");
- require_once ("learnpath_functions.inc.php");
- $tbl_lp = Database::get_course_table(TABLE_LP_MAIN);
- $_course = Database::get_course_info(api_get_course_id());
- $sql = "SELECT * FROM $tbl_lp WHERE id=".$lp_id;
- $result = Database::query($sql, __FILE__, __LINE__);
- $row = Database::fetch_array($result);
- $LPname = $row['path'];
- $list = split('/',$LPname);
- $LPnamesafe = $list[0];
-
-
- $zipfoldername = api_get_path('SYS_COURSE_PATH').$_course['directory']."/temp/".$LPnamesafe;
- $scormfoldername = api_get_path('SYS_COURSE_PATH').$_course['directory']."/scorm/".$LPnamesafe;
- $zipfilename = $zipfoldername."/".$LPnamesafe.".zip";
-
-
- deldir($zipfoldername);
- $res = mkdir($zipfoldername);
-
-
- $zip_folder = new PclZip($zipfilename);
- $zip_folder->create($scormfoldername.'/', PCLZIP_OPT_REMOVE_PATH, $scormfoldername.'/');
-
-
-
- DocumentManager :: file_send_for_download($zipfilename, true);
-
- my_delete($zipfilename);
- my_delete($zipfoldername);
- return true;
- }
-
- function get_res_path($id){
- if($this->debug>0){error_log('In scorm::get_res_path('.$id.') method',0);}
- $path = '';
- if(isset($this->resources[$id])){
- $oRes =& $this->resources[$id];
- $path = @$oRes->get_path();
- }
- return $path;
- }
-
- function get_res_type($id){
- if($this->debug>0){error_log('In scorm::get_res_type('.$id.') method',0);}
- $type = '';
- if(isset($this->resources[$id])){
- $oRes =& $this->resources[$id];
- $temptype = $oRes->get_scorm_type();
- if(!empty($temptype)){
- $type = $temptype;
- }
- }
- return $type;
- }
-
- function get_title(){
- if($this->debug>0){error_log('In scorm::get_title() method',0);}
- $title = '';
- if(isset($this->manifest['organizations']['default'])){
- $title = $this->organizations[$this->manifest['organizations']['default']]->get_name();
- }elseif(count($this->organizations)==1){
-
- foreach($this->organizations as $id => $value){
- $title = $this->organizations[$id]->get_name();
- break;
- }
- }
- return $title;
- }
-
- function reimport_manifest($course,$lp_id=null,$imsmanifest_path=''){
- if($this->debug>0){error_log('In scorm::reimport_manifest() method',0);}
- global $_course;
-
- $main_table = Database::get_main_table(TABLE_MAIN_COURSE);
-
- $course = $this->escape_string($course);
- $sql = "SELECT * FROM $main_table WHERE code = '$course'";
- if($this->debug>2){error_log('New LP - scorm::reimport_manifest() '.__LINE__.' - Querying course: '.$sql,0);}
-
- $res = Database::query($sql);
- if(Database::num_rows($res)>0)
- {
- $this->cc = $course;
- }
- else
- {
- $this->error = 'Course code does not exist in database ('.$sql.')';
- return false;
- }
-
-
- $lp_table = Database::get_course_table(TABLE_LP_MAIN);
-
- $lp_id = $this->escape_string($lp_id);
- $sql = "SELECT * FROM $lp_table WHERE id = '$lp_id'";
- if($this->debug>2){error_log('New LP - scorm::reimport_manifest() '.__LINE__.' - Querying lp: '.$sql,0);}
-
- $res = Database::query($sql);
- if(Database::num_rows($res)>0)
- {
- $this->lp_id = $lp_id;
- $row = Database::fetch_array($res);
- $this->type = $row['lp_type'];
- $this->name = stripslashes($row['name']);
- $this->encoding = $row['default_encoding'];
- $this->proximity = $row['content_local'];
- $this->maker = $row['content_maker'];
- $this->prevent_reinit = $row['prevent_reinit'];
- $this->license = $row['content_license'];
- $this->scorm_debug = $row['debug'];
- $this->js_lib = $row['js_lib'];
- $this->path = $row['path'];
- if($this->type == 2){
- if($row['force_commit'] == 1){
- $this->force_commit = true;
- }
- }
- $this->mode = $row['default_view_mod'];
- $this->subdir = $row['path'];
- }
-
- $manifest_file = api_get_path('SYS_COURSE_PATH').$_course['directory'].'/scorm/'.$this->subdir.'/imsmanifest.xml';
- if($this->subdir == ''){
- $manifest_file = api_get_path('SYS_COURSE_PATH').$_course['directory'].'/scorm/imsmanifest.xml';
- }
- echo $manifest_file;
- if(is_file($manifest_file) && is_readable($manifest_file)){
-
- if($this->debug>1){error_log('New LP - In scorm::reimport_manifest() - Parsing manifest '.$manifest_file,0);}
- $manifest = $this->parse_manifest($manifest_file);
-
- if($this->debug>1){error_log('New LP - In scorm::reimport_manifest() - Importing manifest '.$manifest_file,0);}
- $this->import_manifest(api_get_course_id());
- }else{
- if($this->debug>0){error_log('New LP - In scorm::reimport_manifest() - Could not find manifest file at '.$manifest_file,0);}
- }
- return false;
- }
- }
- ?>
|