|
|
|
@ -2,9 +2,12 @@ |
|
|
|
|
|
|
|
|
|
/* For licensing terms, see /license.txt */ |
|
|
|
|
|
|
|
|
|
use Chamilo\CoreBundle\Entity\Asset; |
|
|
|
|
use Chamilo\CoreBundle\Framework\Container; |
|
|
|
|
use Chamilo\CourseBundle\Entity\CLp; |
|
|
|
|
use Chamilo\CourseBundle\Entity\CLpItem; |
|
|
|
|
use Symfony\Component\DomCrawler\Crawler; |
|
|
|
|
use League\Flysystem\ZipArchive\ZipArchiveAdapter; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Defines the scorm class, which is meant to contain the scorm items (nuclear elements). |
|
|
|
@ -26,14 +29,16 @@ class scorm extends learnpath |
|
|
|
|
/* Path between the scorm/ directory and the imsmanifest.xml e.g. |
|
|
|
|
maritime_nav/maritime_nav. This is the path that will be used in the |
|
|
|
|
lp_path when importing a package. */ |
|
|
|
|
public $subdir = ''; |
|
|
|
|
public $items = []; |
|
|
|
|
public $subdir; |
|
|
|
|
public $manifestToString; |
|
|
|
|
public $items; |
|
|
|
|
// Keeps the zipfile safe for the object's life so that we can use it if no title avail. |
|
|
|
|
public $zipname = ''; |
|
|
|
|
// Keeps an index of the number of uses of the zipname so far. |
|
|
|
|
public $lastzipnameindex = 0; |
|
|
|
|
public $manifest_encoding = 'UTF-8'; |
|
|
|
|
public $debug = false; |
|
|
|
|
public $asset = true; |
|
|
|
|
public $debug = true; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Class constructor. Based on the parent constructor. |
|
|
|
@ -42,9 +47,12 @@ class scorm extends learnpath |
|
|
|
|
* @param int Learnpath ID in DB |
|
|
|
|
* @param int User ID |
|
|
|
|
*/ |
|
|
|
|
public function __construct($course_code = null, $resource_id = null, $user_id = null) |
|
|
|
|
public function __construct($courseCode = null, $resource_id = null, $user_id = null) |
|
|
|
|
{ |
|
|
|
|
parent::__construct($course_code, $resource_id, $user_id); |
|
|
|
|
$this->items = []; |
|
|
|
|
$this->subdir = ''; |
|
|
|
|
$this->manifestToString = ''; |
|
|
|
|
parent::__construct($courseCode, $resource_id, $user_id); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
@ -55,7 +63,7 @@ class scorm extends learnpath |
|
|
|
|
public function open($id) |
|
|
|
|
{ |
|
|
|
|
if ($this->debug > 0) { |
|
|
|
|
error_log('New LP - scorm::open() - In scorm::open method', 0); |
|
|
|
|
error_log('scorm::open() - In scorm::open method', 0); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -70,20 +78,10 @@ class scorm extends learnpath |
|
|
|
|
* |
|
|
|
|
* @return array Structured array representing the imsmanifest's contents |
|
|
|
|
*/ |
|
|
|
|
public function parse_manifest($file = '') |
|
|
|
|
public function parse_manifest() |
|
|
|
|
{ |
|
|
|
|
if ($this->debug > 0) { |
|
|
|
|
error_log('In scorm::parse_manifest('.$file.')', 0); |
|
|
|
|
} |
|
|
|
|
if (empty($file)) { |
|
|
|
|
// Get the path of the imsmanifest file. |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (is_file($file) && is_readable($file) && ($xml = @file_get_contents($file))) { |
|
|
|
|
// Parsing using PHP5 DOMXML methods. |
|
|
|
|
if ($this->debug > 0) { |
|
|
|
|
error_log('In scorm::parse_manifest() - Parsing using PHP5 method'); |
|
|
|
|
} |
|
|
|
|
if ($this->manifestToString) { |
|
|
|
|
$xml = $this->manifestToString; |
|
|
|
|
// $this->manifest_encoding = api_detect_encoding_xml($xml); |
|
|
|
|
// This is the usual way for reading the encoding. |
|
|
|
|
// This method reads the encoding, it tries to be correct even in cases |
|
|
|
@ -92,26 +90,23 @@ class scorm extends learnpath |
|
|
|
|
|
|
|
|
|
// UTF-8 is supported by DOMDocument class, this is for sure. |
|
|
|
|
$xml = api_utf8_encode_xml($xml, $this->manifest_encoding); |
|
|
|
|
|
|
|
|
|
$crawler = new Crawler(); |
|
|
|
|
$crawler->addXmlContent($xml); |
|
|
|
|
|
|
|
|
|
$xmlErrors = libxml_get_errors(); |
|
|
|
|
|
|
|
|
|
if (!empty($xmlErrors)) { |
|
|
|
|
if ($this->debug > 0) { |
|
|
|
|
error_log('New LP - In scorm::parse_manifest() - Exception thrown when loading '.$file.' in DOMDocument'); |
|
|
|
|
error_log('In scorm::parse_manifest() - Exception thrown when loading '.$file.' in DOMDocument'); |
|
|
|
|
} |
|
|
|
|
// Throw exception? |
|
|
|
|
return null; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if ($this->debug > 1) { |
|
|
|
|
error_log('New LP - Called (encoding:'.$this->manifest_encoding.' - saved: '.$this->manifest_encoding.')', 0); |
|
|
|
|
error_log('Called (encoding:'.$this->manifest_encoding.' - saved: '.$this->manifest_encoding.')', 0); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$root = $crawler->getNode(0); |
|
|
|
|
|
|
|
|
|
if ($root->hasAttributes()) { |
|
|
|
|
$attributes = $root->attributes; |
|
|
|
|
if (0 !== $attributes->length) { |
|
|
|
@ -226,16 +221,18 @@ class scorm extends learnpath |
|
|
|
|
// End parsing using PHP5 DOMXML methods. |
|
|
|
|
} else { |
|
|
|
|
if ($this->debug > 1) { |
|
|
|
|
error_log('New LP - Could not open/read file '.$file); |
|
|
|
|
error_log('Could not open/read file '.$file); |
|
|
|
|
} |
|
|
|
|
$this->set_error_msg("File $file could not be read"); |
|
|
|
|
|
|
|
|
|
return null; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// @todo implement learnpath_fix_xerte_template |
|
|
|
|
|
|
|
|
|
$fixTemplate = api_get_configuration_value('learnpath_fix_xerte_template'); |
|
|
|
|
$proxyPath = api_get_configuration_value('learnpath_proxy_url'); |
|
|
|
|
if ($fixTemplate && !empty($proxyPath)) { |
|
|
|
|
/*if ($fixTemplate && !empty($proxyPath)) { |
|
|
|
|
// Check organisations: |
|
|
|
|
if (isset($this->manifest['organizations'])) { |
|
|
|
|
foreach ($this->manifest['organizations'] as $data) { |
|
|
|
@ -309,7 +306,7 @@ class scorm extends learnpath |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}*/ |
|
|
|
|
|
|
|
|
|
// TODO: Close the DOM handler. |
|
|
|
|
return $this->manifest; |
|
|
|
@ -321,31 +318,26 @@ class scorm extends learnpath |
|
|
|
|
* @param string $courseCode |
|
|
|
|
* @param int $userMaxScore |
|
|
|
|
* @param int $sessionId |
|
|
|
|
* @param int $userId |
|
|
|
|
* |
|
|
|
|
* @return bool Returns -1 on error |
|
|
|
|
*/ |
|
|
|
|
public function import_manifest( |
|
|
|
|
$courseCode, |
|
|
|
|
$userMaxScore = 1, |
|
|
|
|
$sessionId = 0, |
|
|
|
|
$userId = 0 |
|
|
|
|
) { |
|
|
|
|
public function import_manifest($courseCode, $userMaxScore = 1, $sessionId = 0) |
|
|
|
|
{ |
|
|
|
|
if ($this->debug > 0) { |
|
|
|
|
error_log('New LP - Entered import_manifest('.$courseCode.')', 0); |
|
|
|
|
error_log('Entered import_manifest('.$courseCode.')', 0); |
|
|
|
|
} |
|
|
|
|
$courseInfo = api_get_course_info($courseCode); |
|
|
|
|
$courseId = $courseInfo['real_id']; |
|
|
|
|
|
|
|
|
|
$userId = (int) $userId; |
|
|
|
|
if (empty($userId)) { |
|
|
|
|
$userId = api_get_user_id(); |
|
|
|
|
} |
|
|
|
|
// Get table names. |
|
|
|
|
$new_lp = Database::get_course_table(TABLE_LP_MAIN); |
|
|
|
|
$new_lp_item = Database::get_course_table(TABLE_LP_ITEM); |
|
|
|
|
$userMaxScore = (int) $userMaxScore; |
|
|
|
|
$sessionId = empty($sessionId) ? api_get_session_id() : (int) $sessionId; |
|
|
|
|
|
|
|
|
|
$repo = Container::getLpRepository(); |
|
|
|
|
$em = Database::getManager(); |
|
|
|
|
$lp = null; |
|
|
|
|
foreach ($this->organizations as $id => $dummy) { |
|
|
|
|
$oOrganization = &$this->organizations[$id]; |
|
|
|
|
// Prepare and execute insert queries: |
|
|
|
@ -365,7 +357,7 @@ class scorm extends learnpath |
|
|
|
|
$lp = new CLp(); |
|
|
|
|
$lp |
|
|
|
|
->setCId($courseId) |
|
|
|
|
->setLpType(2) |
|
|
|
|
->setLpType(CLp::SCORM_TYPE) |
|
|
|
|
->setName($myname) |
|
|
|
|
->setRef($oOrganization->get_ref()) |
|
|
|
|
->setPath($this->subdir) |
|
|
|
@ -373,37 +365,15 @@ class scorm extends learnpath |
|
|
|
|
->setJsLib('scorm_api.php') |
|
|
|
|
->setDisplayOrder($dsp) |
|
|
|
|
->setUseMaxScore($userMaxScore) |
|
|
|
|
->setAsset($this->asset) |
|
|
|
|
->setSessionId($sessionId) |
|
|
|
|
->setParent($courseEntity) |
|
|
|
|
->addCourseLink($courseEntity, api_get_session_entity()) |
|
|
|
|
; |
|
|
|
|
|
|
|
|
|
$repo = Container::getLpRepository(); |
|
|
|
|
$repo->create($lp); |
|
|
|
|
|
|
|
|
|
/*if ($lp_id) { |
|
|
|
|
$sql = "UPDATE $new_lp SET id = iid WHERE iid = $lp_id"; |
|
|
|
|
Database::query($sql); |
|
|
|
|
|
|
|
|
|
$this->lp_id = $lp_id; |
|
|
|
|
|
|
|
|
|
// Insert into item_property. |
|
|
|
|
api_item_property_update( |
|
|
|
|
$courseInfo, |
|
|
|
|
TOOL_LEARNPATH, |
|
|
|
|
$this->lp_id, |
|
|
|
|
'LearnpathAdded', |
|
|
|
|
$userId |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
api_item_property_update( |
|
|
|
|
$courseInfo, |
|
|
|
|
TOOL_LEARNPATH, |
|
|
|
|
$this->lp_id, |
|
|
|
|
'visible', |
|
|
|
|
$userId |
|
|
|
|
); |
|
|
|
|
}*/ |
|
|
|
|
$lp_id = $lp->getIid(); |
|
|
|
|
|
|
|
|
|
// Now insert all elements from inside that learning path. |
|
|
|
|
// Make sure we also get the href and sco/asset from the resources. |
|
|
|
@ -412,7 +382,6 @@ class scorm extends learnpath |
|
|
|
|
$parent = 0; |
|
|
|
|
$previous = 0; |
|
|
|
|
$level = 0; |
|
|
|
|
|
|
|
|
|
foreach ($list as $item) { |
|
|
|
|
if ($item['level'] > $level) { |
|
|
|
|
// Push something into the parents array. |
|
|
|
@ -440,22 +409,9 @@ class scorm extends learnpath |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
$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']); |
|
|
|
|
$title = $item['title']; |
|
|
|
|
$title = api_utf8_decode($title); |
|
|
|
|
$max_score = (int) $item['max_score']; |
|
|
|
|
|
|
|
|
|
if (0 === $max_score) { |
|
|
|
|
// If max score is not set The use_max_score parameter |
|
|
|
|
// is check in order to use 100 (chamilo style) or '' (strict scorm) |
|
|
|
@ -468,29 +424,41 @@ class scorm extends learnpath |
|
|
|
|
$max_score = "'$max_score'"; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$identifier = Database::escape_string($item['identifier']); |
|
|
|
|
|
|
|
|
|
if (empty($title)) { |
|
|
|
|
$title = get_lang('Untitled'); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$prereq = Database::escape_string($item['prerequisites']); |
|
|
|
|
$item['datafromlms'] = Database::escape_string($item['datafromlms']); |
|
|
|
|
$item['parameters'] = Database::escape_string($item['parameters']); |
|
|
|
|
$lpItem = new CLpItem(); |
|
|
|
|
$lpItem |
|
|
|
|
->setTitle($title) |
|
|
|
|
->setCId($courseId) |
|
|
|
|
->setItemType($type) |
|
|
|
|
->setRef($item['identifier']) |
|
|
|
|
->setPath($path) |
|
|
|
|
->setMinScore(0) |
|
|
|
|
->setMaxScore($max_score) |
|
|
|
|
->setParentItemId($parent) |
|
|
|
|
->setPreviousItemId($previous) |
|
|
|
|
->setNextItemId(0) |
|
|
|
|
->setPrerequisite($item['prerequisites']) |
|
|
|
|
->setDisplayOrder($item['rel_order']) |
|
|
|
|
->setLaunchData($item['datafromlms']) |
|
|
|
|
->setParameters($item['parameters']) |
|
|
|
|
->setLp($lp) |
|
|
|
|
; |
|
|
|
|
|
|
|
|
|
$sql = "INSERT INTO $new_lp_item (c_id, 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 ($courseId, $lp_id, '$type', '$identifier', '$title', '$path' , 0, $max_score, $value_add $parent, $previous, 0, '$prereq', ".$item['rel_order'].", '".$item['datafromlms']."', '".$item['parameters']."' )"; |
|
|
|
|
if (!empty($item['masteryscore'])) { |
|
|
|
|
$lpItem->setMasteryScore($item['masteryscore']); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Database::query($sql); |
|
|
|
|
if ($this->debug > 1) { |
|
|
|
|
error_log('New LP - In import_manifest(), inserting item : '.$sql); |
|
|
|
|
if (!empty($item['maxtimeallowed'])) { |
|
|
|
|
$lpItem->setMaxTimeAllowed($item['maxtimeallowed']); |
|
|
|
|
} |
|
|
|
|
$item_id = Database::insert_id(); |
|
|
|
|
$em->persist($lpItem); |
|
|
|
|
$em->flush(); |
|
|
|
|
|
|
|
|
|
$item_id = $lpItem->getIid(); |
|
|
|
|
if ($item_id) { |
|
|
|
|
$sql = "UPDATE $new_lp_item SET id = iid WHERE iid = $item_id"; |
|
|
|
|
Database::query($sql); |
|
|
|
|
|
|
|
|
|
// Now update previous item to change next_item_id. |
|
|
|
|
$upd = "UPDATE $new_lp_item SET next_item_id = $item_id |
|
|
|
|
WHERE iid = $previous"; |
|
|
|
@ -502,7 +470,6 @@ class scorm extends learnpath |
|
|
|
|
// Code for indexing, now only index specific fields like terms and the title. |
|
|
|
|
if (!empty($_POST['index_document'])) { |
|
|
|
|
require_once api_get_path(LIBRARY_PATH).'specific_fields_manager.lib.php'; |
|
|
|
|
|
|
|
|
|
$di = new ChamiloIndexer(); |
|
|
|
|
isset($_POST['language']) ? $lang = Database::escape_string($_POST['language']) : $lang = 'english'; |
|
|
|
|
$di->connectDb(null, null, $lang); |
|
|
|
@ -550,6 +517,8 @@ class scorm extends learnpath |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return $lp; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
@ -590,7 +559,7 @@ class scorm extends learnpath |
|
|
|
|
$lpToCheck = null, |
|
|
|
|
$allowHtaccess = false |
|
|
|
|
) { |
|
|
|
|
if ($this->debug > 0) { |
|
|
|
|
if ($this->debug) { |
|
|
|
|
error_log( |
|
|
|
|
'In scorm::import_package('.print_r($zipFileInfo, true).',"'.$currentDir.'") method' |
|
|
|
|
); |
|
|
|
@ -598,23 +567,22 @@ class scorm extends learnpath |
|
|
|
|
|
|
|
|
|
$courseInfo = empty($courseInfo) ? api_get_course_info() : $courseInfo; |
|
|
|
|
$maxFilledSpace = DocumentManager::get_course_quota($courseInfo['code']); |
|
|
|
|
|
|
|
|
|
$zipFilePath = $zipFileInfo['tmp_name']; |
|
|
|
|
$zipFileName = $zipFileInfo['name']; |
|
|
|
|
|
|
|
|
|
if ($this->debug > 1) { |
|
|
|
|
error_log( |
|
|
|
|
'New LP - import_package() - zip file path = '.$zipFilePath.', zip file name = '.$zipFileName, |
|
|
|
|
'import_package() - zip file path = '.$zipFilePath.', zip file name = '.$zipFileName, |
|
|
|
|
0 |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$courseRelDir = api_get_course_path($courseInfo['code']).'/scorm'; // scorm dir web path starting from /courses |
|
|
|
|
$courseSysDir = api_get_path(SYS_COURSE_PATH).$courseRelDir; // Absolute system path for this course. |
|
|
|
|
//$courseRelDir = api_get_course_path($courseInfo['code']).'/scorm'; // scorm dir web path starting from /courses |
|
|
|
|
//$courseSysDir = api_get_path(SYS_COURSE_PATH).$courseRelDir; // Absolute system path for this course. |
|
|
|
|
$currentDir = api_replace_dangerous_char(trim($currentDir)); // Current dir we are in, inside scorm/ |
|
|
|
|
|
|
|
|
|
if ($this->debug > 1) { |
|
|
|
|
error_log('New LP - import_package() - current_dir = '.$currentDir, 0); |
|
|
|
|
error_log('import_package() - current_dir = '.$currentDir, 0); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Get name of the zip file without the extension. |
|
|
|
@ -626,33 +594,38 @@ class scorm extends learnpath |
|
|
|
|
$newDir = api_replace_dangerous_char(trim($fileBaseName)); |
|
|
|
|
$this->subdir = $newDir; |
|
|
|
|
if ($this->debug > 1) { |
|
|
|
|
error_log('New LP - Received zip file name: '.$zipFilePath); |
|
|
|
|
error_log("New LP - subdir is first set to : ".$this->subdir); |
|
|
|
|
error_log("New LP - base file name is : ".$fileBaseName); |
|
|
|
|
error_log('Received zip file name: '.$zipFilePath); |
|
|
|
|
error_log("subdir is first set to : ".$this->subdir); |
|
|
|
|
error_log("base file name is : ".$fileBaseName); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$zipFile = new PclZip($zipFilePath); |
|
|
|
|
// Check the zip content (real size and file extension). |
|
|
|
|
$zipContentArray = $zipFile->listContent(); |
|
|
|
|
$zipAdapter = new ZipArchiveAdapter($zipFilePath); |
|
|
|
|
$filesystem = new \League\Flysystem\Filesystem($zipAdapter); |
|
|
|
|
$zipContentArray = $filesystem->listContents(); |
|
|
|
|
|
|
|
|
|
$packageType = ''; |
|
|
|
|
$manifestList = []; |
|
|
|
|
// The following loop should be stopped as soon as we found the right imsmanifest.xml (how to recognize it?). |
|
|
|
|
$realFileSize = 0; |
|
|
|
|
foreach ($zipContentArray as $thisContent) { |
|
|
|
|
if (preg_match('~.(php.*|phtml)$~i', $thisContent['filename'])) { |
|
|
|
|
$file = $thisContent['filename']; |
|
|
|
|
$fileName = $thisContent['path']; |
|
|
|
|
if (preg_match('~.(php.*|phtml)$~i', $fileName)) { |
|
|
|
|
$file = $fileName; |
|
|
|
|
$this->set_error_msg("File $file contains a PHP script"); |
|
|
|
|
} elseif (stristr($thisContent['filename'], 'imsmanifest.xml')) { |
|
|
|
|
if ($thisContent['filename'] == basename($thisContent['filename'])) { |
|
|
|
|
} elseif (stristr($fileName, 'imsmanifest.xml')) { |
|
|
|
|
if ($fileName == basename($fileName)) { |
|
|
|
|
} else { |
|
|
|
|
if ($this->debug > 2) { |
|
|
|
|
error_log("New LP - subdir is now ".$this->subdir); |
|
|
|
|
error_log("subdir is now ".$this->subdir); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
$packageType = 'scorm'; |
|
|
|
|
$manifestList[] = $thisContent['filename']; |
|
|
|
|
$manifestList[] = $fileName; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (isset($thisContent['size'])) { |
|
|
|
|
$realFileSize += $thisContent['size']; |
|
|
|
|
} |
|
|
|
|
$realFileSize += $thisContent['size']; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Now get the shortest path (basically, the imsmanifest that is the closest to the root). |
|
|
|
@ -667,11 +640,12 @@ class scorm extends learnpath |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$this->subdir .= '/'.dirname($shortestPath); // Do not concatenate because already done above. |
|
|
|
|
$manifest = $shortestPath; |
|
|
|
|
$this->manifestToString = $filesystem->read($shortestPath); |
|
|
|
|
|
|
|
|
|
if ($this->debug) { |
|
|
|
|
error_log("New LP - Package type is now: '$packageType'"); |
|
|
|
|
error_log("Package type is now: '$packageType'"); |
|
|
|
|
} |
|
|
|
|
if ('' == $packageType) { |
|
|
|
|
if ('' === $packageType) { |
|
|
|
|
Display::addFlash( |
|
|
|
|
Display::return_message(get_lang('This is not a valid SCORM ZIP file !')) |
|
|
|
|
); |
|
|
|
@ -679,9 +653,10 @@ class scorm extends learnpath |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (!enough_size($realFileSize, $courseSysDir, $maxFilledSpace)) { |
|
|
|
|
// Todo check filesize |
|
|
|
|
/*if (!enough_size($realFileSize, $courseSysDir, $maxFilledSpace)) { |
|
|
|
|
if ($this->debug > 1) { |
|
|
|
|
error_log('New LP - Not enough space to store package'); |
|
|
|
|
error_log('Not enough space to store package'); |
|
|
|
|
} |
|
|
|
|
Display::addFlash( |
|
|
|
|
Display::return_message( |
|
|
|
@ -692,9 +667,9 @@ class scorm extends learnpath |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
}*/ |
|
|
|
|
|
|
|
|
|
if ($updateDirContents && $lpToCheck) { |
|
|
|
|
/*if ($updateDirContents && $lpToCheck) { |
|
|
|
|
$originalPath = str_replace('/.', '', $lpToCheck->path); |
|
|
|
|
if ($originalPath != $newDir) { |
|
|
|
|
Display::addFlash(Display::return_message(get_lang('The file to upload is not valid.'))); |
|
|
|
@ -704,13 +679,14 @@ class scorm extends learnpath |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// It happens on Linux that $newDir sometimes doesn't start with '/' |
|
|
|
|
if ('/' != $newDir[0]) { |
|
|
|
|
if ('/' !== $newDir[0]) { |
|
|
|
|
$newDir = '/'.$newDir; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if ('/' == $newDir[strlen($newDir) - 1]) { |
|
|
|
|
if ('/' === $newDir[strlen($newDir) - 1]) { |
|
|
|
|
$newDir = substr($newDir, 0, -1); |
|
|
|
|
} |
|
|
|
|
}*/ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Uncompressing phase */ |
|
|
|
|
/* |
|
|
|
@ -719,7 +695,31 @@ class scorm extends learnpath |
|
|
|
|
- parse & change relative html links |
|
|
|
|
- make sure the filenames are secure (filter funny characters or php extensions) |
|
|
|
|
*/ |
|
|
|
|
if (is_dir($courseSysDir.$newDir) || |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 1. Upload zip file |
|
|
|
|
$request = Container::getRequest(); |
|
|
|
|
$uploadFile = null; |
|
|
|
|
if ($request->files->has('user_file')) { |
|
|
|
|
$uploadFile = $request->files->get('user_file'); |
|
|
|
|
} |
|
|
|
|
$em = Database::getManager(); |
|
|
|
|
$asset = new Asset(); |
|
|
|
|
$asset |
|
|
|
|
->setCategory(Asset::SCORM) |
|
|
|
|
->setTitle($zipFileName) |
|
|
|
|
->setFile($uploadFile) |
|
|
|
|
->setCompressed(true) |
|
|
|
|
; |
|
|
|
|
$em->persist($asset); |
|
|
|
|
$em->flush(); |
|
|
|
|
|
|
|
|
|
// 2. Unzip file |
|
|
|
|
$repo = Container::getAssetRepository(); |
|
|
|
|
$repo->unZipFile($asset, $zipAdapter); |
|
|
|
|
$this->asset = $asset; |
|
|
|
|
|
|
|
|
|
/*if (is_dir($courseSysDir.$newDir) || |
|
|
|
|
@mkdir( |
|
|
|
|
$courseSysDir.$newDir, |
|
|
|
|
api_get_permissions_for_new_directories() |
|
|
|
@ -727,7 +727,7 @@ class scorm extends learnpath |
|
|
|
|
) { |
|
|
|
|
// PHP method - slower... |
|
|
|
|
if ($this->debug >= 1) { |
|
|
|
|
error_log('New LP - Changing dir to '.$courseSysDir.$newDir); |
|
|
|
|
error_log('Changing dir to '.$courseSysDir.$newDir); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
chdir($courseSysDir.$newDir); |
|
|
|
@ -752,9 +752,11 @@ class scorm extends learnpath |
|
|
|
|
api_chmod_R($courseSysDir.$newDir, api_get_permissions_for_new_directories()); |
|
|
|
|
} else { |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
}*/ |
|
|
|
|
|
|
|
|
|
//return $courseSysDir.$newDir.$manifest; |
|
|
|
|
|
|
|
|
|
return $courseSysDir.$newDir.$manifest; |
|
|
|
|
return $asset; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
@ -798,7 +800,7 @@ class scorm extends learnpath |
|
|
|
|
$zipfilename = $zipfoldername.'/'.$LPnamesafe.'.zip'; |
|
|
|
|
|
|
|
|
|
// Get a temporary dir for creating the zip file. |
|
|
|
|
//error_log('New LP - cleaning dir '.$zipfoldername, 0); |
|
|
|
|
//error_log('cleaning dir '.$zipfoldername, 0); |
|
|
|
|
my_delete($zipfoldername); // Make sure the temp dir is cleared. |
|
|
|
|
mkdir($zipfoldername, api_get_permissions_for_new_directories()); |
|
|
|
|
|
|
|
|
@ -917,7 +919,7 @@ class scorm extends learnpath |
|
|
|
|
$lp_id = intval($lp_id); |
|
|
|
|
$sql = "SELECT * FROM $lp_table WHERE iid = $lp_id"; |
|
|
|
|
if ($this->debug > 2) { |
|
|
|
|
error_log('New LP - scorm::reimport_manifest() '.__LINE__.' - Querying lp: '.$sql); |
|
|
|
|
error_log('scorm::reimport_manifest() '.__LINE__.' - Querying lp: '.$sql); |
|
|
|
|
} |
|
|
|
|
$res = Database::query($sql); |
|
|
|
|
if (Database::num_rows($res) > 0) { |
|
|
|
@ -950,17 +952,17 @@ class scorm extends learnpath |
|
|
|
|
if (is_file($manifest_file) && is_readable($manifest_file)) { |
|
|
|
|
// Re-parse the manifest file. |
|
|
|
|
if ($this->debug > 1) { |
|
|
|
|
error_log('New LP - In scorm::reimport_manifest() - Parsing manifest '.$manifest_file); |
|
|
|
|
error_log('In scorm::reimport_manifest() - Parsing manifest '.$manifest_file); |
|
|
|
|
} |
|
|
|
|
$manifest = $this->parse_manifest($manifest_file); |
|
|
|
|
// Import new LP in DB (ignore the current one). |
|
|
|
|
if ($this->debug > 1) { |
|
|
|
|
error_log('New LP - In scorm::reimport_manifest() - Importing manifest '.$manifest_file); |
|
|
|
|
error_log('In scorm::reimport_manifest() - Importing manifest '.$manifest_file); |
|
|
|
|
} |
|
|
|
|
$this->import_manifest($this->cc); |
|
|
|
|
} else { |
|
|
|
|
if ($this->debug > 0) { |
|
|
|
|
error_log('New LP - In scorm::reimport_manifest() - Could not find manifest file at '.$manifest_file); |
|
|
|
|
error_log('In scorm::reimport_manifest() - Could not find manifest file at '.$manifest_file); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|