function removeCommonPath($items){
$common_path;
$quit = false; //a flag that is set if it's not the first time being run.
-
- foreach($items as $index=>$item){
- if (isset($item['new_path']) && $item['new_path']!=''){
- $path = $item['new_path'];
- } else {
- continue;
- }
+ $filearray = array();
+ //get all files listed in the manifest
+ foreach($items as $name=>$fileinfo){
+ if(isset($fileinfo['file']) && is_array($fileinfo['file']) && !empty($fileinfo['file'])){
+ foreach($fileinfo['file'] as $fn){
+ if (!in_array($fn, $filearray)){
+ if (preg_match('/^http[s]?\:/', $fn) == 0){
+ $filearray[] = $fn;
+ }
+ }
+ }
+ }
+ }
+
+ foreach($filearray as $index=>$path){
//hack
//check if this is a XML file; if so, skip through,
//cause XML most likely isn't a content resource.
- $ext = substr($item['href'], (strrpos($item['href'], '.')+1));
+ $ext = substr($path, (strrpos($path, '.')+1));
if($ext=='xml'){
continue;
}
}
**/
//--- harris edit for path thing
-$file = TR_CONTENT_DIR . 'import/'.$_course_id.DIRECTORY_SEPARATOR.$common_path;
+$file = $import_path.$common_path;
if (is_dir($file)) {
- rename($file, TR_CONTENT_DIR .$_course_id.'/'.$package_base_name);
+ rename($file, TR_CONTENT_DIR.$_course_id.DIRECTORY_SEPARATOR.$package_base_name);
}
//--- end
//takes care of the condition where the whole package doesn't have any contents but question banks
$all_package_base_path = implode('/', $all_package_base_path);
if(strpos($all_package_base_path, 'http:/')===false){
- if (@rename($import_path.$all_package_base_path, TR_CONTENT_DIR .$_course_id.'/'.$package_base_name) === false) {
+ if (rename($import_path.$all_package_base_path, $course_dir.$package_base_name) === false) {
if (!$msg->containsErrors()) {
if ($oauth_import) {
echo "error=".urlencode('Cannot move lesson directory into content directory');
}
}
//check if there are still resources missing
+/*
foreach($items as $idetails){
$temp_path = pathinfo($idetails['href']);
@rename($import_path.$temp_path['dirname'], $course_dir.$package_base_name . '/' . $temp_path['dirname']);
}
+*/
FileUtility::clr_dir($import_path);
if (file_exists($full_filename)) @unlink($full_filename);
* @param array The list of relative files that is used in the question contents. Default empty.
*/
function copyMedia($files, $xml_items = array()){
- global $msg;
+ global $msg, $_course_id;
foreach($files as $file_num => $file_loc){
//skip test xml files
if (preg_match('/tests\_[0-9]+\.xml/', $file_loc)){
//we only want to touch the files that the test/surveys use
if ($new_file_loc!=$file_loc){
//check if new folder is there, if not, create it.
- createDir(TR_CONTENT_DIR .$_SESSION['course_id'].'/'.$new_file_loc );
+ createDir(TR_CONTENT_DIR .$_course_id.'/'.$new_file_loc );
//overwrite files
- if (file_exists(TR_CONTENT_DIR .$_SESSION['course_id'].'/'.$new_file_loc)){
- unlink(TR_CONTENT_DIR .$_SESSION['course_id'].'/'.$new_file_loc);
+ if (file_exists(TR_CONTENT_DIR .$_course_id.'/'.$new_file_loc)){
+ unlink(TR_CONTENT_DIR .$_course_id.'/'.$new_file_loc);
}
if (file_exists($this->import_path.$file_loc)){
if (copy($this->import_path.$file_loc,
- TR_CONTENT_DIR .$_SESSION['course_id'].'/'.$new_file_loc) === false) {
+ TR_CONTENT_DIR .$_course_id.'/'.$new_file_loc) === false) {
//TODO: Print out file already exist error.
if (!$msg->containsErrors()) {
// $msg->addError('FILE_EXISTED');