Exemplo n.º 1
0
 public function unitExport(EfrontUnit $unit)
 {
     $currentLesson = $this->getCurrentLesson();
     $unitExportFolder = $this->moduleBaseDir . "assets/";
     try {
         $dir = new EfrontDirectory($unitExportFolder);
         $dir->delete();
     } catch (Exception $e) {
     }
     $htmlExportFolder = $unitExportFolder . 'html/';
     $filesExportFolder = $unitExportFolder . 'html/files/';
     is_dir($filesExportFolder) or mkdir($filesExportFolder, 0755, true);
     //is_dir($htmlExportFolder)  OR mkdir($htmlExportFolder, 0755, true);
     $filelist = array();
     $unitFiles = $unit->getFiles(true);
     $units[] = $unit;
     $data = $unit['data'];
     foreach ($unitFiles as $file) {
         $filePath = str_replace($currentLesson->getDirectory(), "/", EfrontFile::encode($file['path']));
         //Added this line in case of a space in path(urlencode makes it + and rawurlencode convers also slashes ) (#2143)
         $data = str_replace("content/lessons/" . ($currentLesson->lesson['share_folder'] ? $currentLesson->lesson['share_folder'] : $currentLesson->lesson['id']) . str_replace(' ', '%20', $filePath), "files" . str_replace(' ', '%20', $filePath), $data);
         $data = str_replace("content/lessons/" . ($currentLesson->lesson['share_folder'] ? $currentLesson->lesson['share_folder'] : $currentLesson->lesson['id']) . $filePath, "files" . $filePath, $data);
         $data = str_replace("view_file.php?file=" . $file['id'], "files" . $filePath, $data);
     }
     $unitContent = $data;
     $unitFilename = $htmlExportFolder . $unit['name'] . ".html";
     file_put_contents(EfrontFile::encode($unitFilename), $unitContent);
     $filelist = array_merge($filelist, $unitFiles);
     foreach ($filelist as $file) {
         $filePath = str_replace($currentLesson->getDirectory(), "", $file['path']);
         if (!is_dir($filesExportFolder . dirname($filePath))) {
             mkdir($filesExportFolder . dirname($filePath), 0755, true);
         }
         $file->copy($filesExportFolder . $filePath);
     }
     $unitDirectory = new EfrontDirectory($unitExportFolder);
     if (eF_checkParameter($unit['name'], 'file')) {
         $filename = $unit['name'] . '.zip';
     } else {
         $filename = 'unit.zip';
     }
     $compressedFile = $unitDirectory->compress($filename, false);
     //$unitDirectory -> delete();
     return $compressedFile;
 }
Exemplo n.º 2
0
     throw new Exception(implode("<br>", $errors));
 }
 //Re-index $uploadedFiles
 $uploadedFiles = array_values($uploadedFiles);
 //We use for instead of foreach, because the 'uncompress_recursive' parameter may augment the $uploadedFiles array
 $unzipFlag = true;
 for ($i = 0; $i < sizeof($uploadedFiles); $i++) {
     $emptyUnits = array();
     $file = $uploadedFiles[$i];
     $pathParts = pathinfo($file['name']);
     if ($pathParts['extension'] == 'zip' && $unzipFlag == true) {
         $fileContents = $file->listContents();
         sort($fileContents);
         //Check if it is a SCORM file
         if (in_array("imsmanifest.xml", $fileContents)) {
             $scormFolderName = EfrontFile::encode(eFront_basename($file['name'], '.zip'));
             $scormPath = $currentLesson->getDirectory() . $scormFolderName . '/';
             is_dir($scormPath) or mkdir($scormPath, 0755);
             $file->rename($scormPath . $file['name'], true);
             $file->uncompress(false);
             $manifestFile = new EfrontFile($scormPath . 'imsmanifest.xml');
             EfrontScorm::import($currentLesson, $manifestFile, $scormFolderName);
         } elseif (in_array("data.dat", $fileContents)) {
             $currentLesson->import($file);
         } else {
             $file->uncompress();
             if ($values['uncompress_recursive']) {
                 $unzipFlag = false;
                 foreach ($fileContents as $additionalFile) {
                     if (!is_dir($uploadDir . $additionalFile)) {
                         //Add to the list of the uploaded files, all those that where extracted
Exemplo n.º 3
0
             $k += 5;
         }
     }
     $smarty->assign("T_DAYS_AFTER_ENROLLMENT", $days_after_enrollment);
     $smarty->assign("T_COURSE_LESSONS", EfrontCourse::convertLessonObjectsToArrays($courseLessons));
     //pr($courseLessons);
 } else {
     if ($_GET['op'] == 'export_course') {
         if (isset($currentUser->coreAccess['content']) && $currentUser->coreAccess['content'] != 'change') {
             eF_redirect("" . basename($_SERVER['PHP_SELF']) . "?ctg=control_panel&message=" . urlencode(_UNAUTHORIZEDACCESS) . "&message_type=failure");
         }
         /* Export part */
         $form = new HTML_QuickForm("export_course_form", "post", basename($_SERVER['PHP_SELF']) . '?' . $baseUrl . '&op=export_course', "", null, true);
         $form->addElement('submit', 'submit_export_course', _EXPORT, 'class = "flatButton"');
         try {
             $currentExportedFile = new EfrontFile($currentUser->user['directory'] . '/temp/' . EfrontFile::encode($currentCourse->course['name']) . '.zip');
             $smarty->assign("T_EXPORTED_FILE", $currentExportedFile);
         } catch (Exception $e) {
         }
         if ($form->isSubmitted() && $form->validate()) {
             try {
                 $file = $currentCourse->export();
                 $smarty->assign("T_NEW_EXPORTED_FILE", $file);
                 $message = _COURSEEXPORTEDSUCCESFULLY;
                 $message_type = 'success';
             } catch (Exception $e) {
                 $smarty->assign("T_EXCEPTION_TRACE", $e->getTraceAsString());
                 $message = $e->getMessage() . ' (' . $e->getCode() . ') &nbsp;<a href = "javascript:void(0)" onclick = "eF_js_showDivPopup(event, \'' . _ERRORDETAILS . '\', 2, \'error_details\')">' . _MOREINFO . '</a>';
             }
         }
         $renderer = new HTML_QuickForm_Renderer_ArraySmarty($smarty);
Exemplo n.º 4
0
 private function createCourseExportFile($courseTempDir)
 {
     $userTempDir = new EfrontDirectory($GLOBALS['currentUser']->user['directory'] . '/temp');
     $file = $courseTempDir->compress($this->course['id'] . '_exported.zip', false);
     //Compress the lesson files
     $newList = FileSystemTree::importFiles($file['path']);
     //Import the file to the database, so we can download it
     $file = new EfrontFile(current($newList));
     $newFileName = EfrontFile::encode($this->course['name']) . '.zip';
     if (!eF_checkParameter($newFileName, 'file')) {
         $newFileName = $file['name'];
     }
     $newFileName = str_replace(array('"', '>', '<', '*', '?', ':'), array('&quot;', '&gt;', '&lt;', '&#42;', '&#63;', '&#58;'), $newFileName);
     //$file -> rename($userTempDir['path'].'/'.$newFileName, true);
     //changed because of checkFile in rename
     if (is_file($userTempDir['path'] . '/' . $newFileName)) {
         $newfile = new EfrontFile($userTempDir['path'] . '/' . $newFileName);
         $newfile->delete();
     }
     rename($file['path'], $userTempDir['path'] . '/' . $newFileName);
     //FileSystemTree :: importFiles($userTempDir['path'].'/'.$newFileName);
     eF_updateTableData("files", array("path" => str_replace(G_ROOTPATH, '', $userTempDir['path'] . '/' . $newFileName)), "id=" . $file['id']);
     $returnFile = new EfrontFile($file['id']);
     //$file   -> rename($userTempDir['path'].'/'.EfrontFile :: encode($this -> course['name']).'.zip', true);
     $courseTempDir->delete();
     return $returnFile;
 }
Exemplo n.º 5
0
    private function buildSCORMManifestResources($units)
    {
        $resource_str = '';
        $dependency_str = '';
        for ($i = 0; $i < sizeof($units); $i++) {
            $resource_str .= '
			<resource identifier="' . $units[$i]['id'] . '" type="webcontent" adlcp:scormtype="sco" href="html/' . rawurlencode(EfrontFile::encode(str_replace('?', ' ', $units[$i]['name']))) . '.html">
				<metadata></metadata>
				<file href="html/' . rawurlencode(EfrontFile::encode(str_replace('?', ' ', $units[$i]['name']))) . '.html"/>
				<dependency identifierref="dep_SPECIAL"/>';
            $unitFiles = $units[$i]->getFiles(true);
            for ($j = 0; $j < sizeof($unitFiles); $j++) {
                $file = str_replace($this->getDirectory(), "", $unitFiles[$j]['path']);
                $resource_str .= '
				<dependency identifierref="dep_' . $i . '_' . $j . '"/>';
                $dependency_str .= '
					<resource identifier="dep_' . $i . '_' . $j . '" type="webcontent" adlcp:scormtype="asset" href="' . rawurlencode(EfrontFile::encode(str_replace('?', ' ', $file))) . '">
						<metadata></metadata>
						<file href="' . rawurlencode(EfrontFile::encode(str_replace('?', ' ', $file))) . '"/>
					</resource>';
            }
            $resource_str .= '
			</resource>';
        }
        $SPECIAL_str = '
			<resource identifier="dep_SPECIAL" adlcp:scormtype="asset" type="webcontent">
				<file href="SCOFunctions.js"/>
				<file href="APIWrapper.js"/>
			</resource>';
        $final_str = '
		<resources>' . $resource_str . $dependency_str . $SPECIAL_str . '
		</resources>';
        return $final_str;
    }
Exemplo n.º 6
0
             if (!in_array($value, $imsFiles)) {
                 //This way we bypass duplicates
                 try {
                     $imsFiles[$value] = $filesystem->uploadFile("ims_file", $currentLesson->getDirectory(), $key);
                 } catch (EfrontFileException $e) {
                     if ($e->getCode() != UPLOAD_ERR_NO_FILE) {
                         throw $e;
                     }
                 }
             }
         }
     }
     //pr($imsFiles);exit;
     foreach ($imsFiles as $imsFile) {
         /* Imports ims package to database */
         $imsFolderName = EfrontFile::encode(eFront_basename($imsFile['name'], '.zip'));
         $imsPath = $currentLesson->getDirectory() . $imsFolderName . '/';
         is_dir($imsPath) or mkdir($imsPath, 0755);
         //pr($imsPath.$imsFile['name']);
         //try {
         $imsFile->rename($imsPath . $imsFile['name'], true);
         //} catch (Exception $e) {pr($e);throw $e;}
         $fileList = $imsFile->uncompress(false);
         $imsFile->delete();
         $total_fields = array();
         $resources = array();
         $manifestFile = new EfrontFile($imsPath . 'imsmanifest.xml');
         EfrontIMS::import($currentLesson, $manifestFile, $imsFolderName, array('embed_type' => $values['embed_type'], 'popup_parameters' => $values['popup_parameters']));
     }
     eF_redirect("" . basename($_SERVER['PHP_SELF']) . "?ctg=ims&message=" . urlencode(_SUCCESSFULLYIMPORTEDIMSFILE) . "&message_type=success");
 } catch (Exception $e) {
Exemplo n.º 7
0
         $projectDir = $currentUser->user['directory'] . '/projects/' . $_GET['compress_user'];
         if (!is_dir($projectDir)) {
             mkdir($projectDir, 0755);
         }
         $projectDirectory = new EfrontDirectory($projectDir);
         foreach ($projectFiles as $title => $file) {
             try {
                 $projectFile = new EfrontFile($file['id']);
                 $newFileName = EfrontFile::encode($title . '_' . date("d.m.Y", $file['upload_timestamp']) . '_' . $projectFile['name']);
                 $projectFile->copy($projectDir . '/' . $newFileName);
             } catch (EfrontFileException $e) {
                 //Don't halt for a single file
                 $message .= $e->getMessage() . ' (' . $e->getCode() . ')';
             }
         }
         $zipFileName = $currentUser->user['directory'] . '/projects/' . EfrontFile::encode($_GET['compress_user']) . '.zip';
         $zipFile = $projectDirectory->compress($zipFileName, false, true);
         $projectDirectory->delete();
         eF_redirect("view_file.php?file=" . urlencode($zipFile['path']) . "&action=download");
     } catch (Exception $e) {
         $smarty->assign("T_EXCEPTION_TRACE", $e->getTraceAsString());
         $message = _FILESCOULDNOTBEDOWNLOADED . ': ' . $e->getMessage() . ' (' . $e->getCode() . ') &nbsp;<a href = "javascript:void(0)" onclick = "eF_js_showDivPopup(event, \'' . _ERRORDETAILS . '\', 2, \'error_details\')">' . _MOREINFO . '</a>';
         $message_type = 'failure';
     }
 } else {
     if ((isset($_GET['add_project']) || isset($_GET['edit_project']) && in_array($_GET['edit_project'], array_keys($projects))) && $_professor_) {
         //ajax request for inserting file in editor
         //This page has a file manager, so bring it on with the correct options
         $basedir = $currentLesson->getDirectory();
         //Default options for the file manager
         if (!isset($currentUser->coreAccess['files']) || $currentUser->coreAccess['files'] == 'change') {
Exemplo n.º 8
0
 /**
  * Import files to filesystem
  *
  * This function imports the specified files (in $list array) to the filesystem,
  * by creating a corresponding database representation. The $list
  * array should contain full paths to the files. The function returns an array
  * of the same size and contents as $list , but this time the file ids being the keys
  * <br/>Example:
  * <code>
  * $list = array('/var/www/text.txt', '/var/www/user.txt');
  * $newList = FileSystemTree :: importFiles($list);
  * </code>
  *
  * @param array $list The files list
  * @param array $options extra options to set for the files, such as whether they should be renamed, or the proper permissions
  * @return array An array with the new file ids
  * @access public
  * @since 3.0
  * @static
  */
 public static function importFiles($list, $options = array())
 {
     if (!is_array($list)) {
         $list = array($list);
     }
     $allFiles = eF_getTableDataFlat("files", "path");
     //Get all files, so that if a file already exists, a duplicate entry in the database won't be created
     for ($i = 0; $i < sizeof($list); $i++) {
         $list[$i] = EfrontFile::encode($list[$i]);
         if (!in_array($list[$i], $allFiles['path']) && strpos(dirname($list[$i]), rtrim(G_ROOTPATH, "/")) !== false) {
             $fileMetadata = array('title' => basename($list[$i]), 'creator' => $GLOBALS['currentUser']->user['name'] . ' ' . $GLOBALS['currentUser']->user['surname'], 'publisher' => $GLOBALS['currentUser']->user['name'] . ' ' . $GLOBALS['currentUser']->user['surname'], 'contributor' => $GLOBALS['currentUser']->user['name'] . ' ' . $GLOBALS['currentUser']->user['surname'], 'date' => date("Y/m/d", time()), 'type' => 'file');
             $fields = array('path' => str_replace(G_ROOTPATH, '', $list[$i]), 'users_LOGIN' => isset($_SESSION['s_login']) ? $_SESSION['s_login'] : '', 'timestamp' => time(), 'metadata' => serialize($fileMetadata));
             isset($options['access']) ? $fields['access'] = $options['access'] : null;
             $fileId = eF_insertTableData("files", $fields);
             if ($fileId) {
                 $newList[$fileId] = $list[$i];
                 foreach ($fileMetadata as $key => $value) {
                     EfrontSearch::insertText($value, $fileId, "files", "data");
                 }
             }
         }
     }
     return $newList;
 }
Exemplo n.º 9
0
            $message_type = 'failure';
        }
    }
    $renderer = new HTML_QuickForm_Renderer_ArraySmarty($smarty);
    $form->accept($renderer);
    $smarty->assign('T_IMPORT_LESSON_FORM', $renderer->toArray());
} elseif ($_GET['op'] == 'export_lesson') {
    if (isset($currentUser->coreAccess['content']) && $currentUser->coreAccess['content'] != 'change') {
        eF_redirect("" . basename($_SERVER['PHP_SELF']) . "?ctg=control_panel&message=" . urlencode(_UNAUTHORIZEDACCESS) . "&message_type=failure");
    }
    /* Export part */
    $form = new HTML_QuickForm("export_lesson_form", "post", basename($_SERVER['PHP_SELF']) . '?' . $baseUrl . '&op=export_lesson', "", null, true);
    $form->addElement('checkbox', 'export_files', _EXPORTFILES, null, 'class = "inputCheckBox"');
    $form->addElement('submit', 'submit_export_lesson', _EXPORT, 'class = "flatButton"');
    try {
        $currentExportedFile = new EfrontFile($currentUser->user['directory'] . '/temp/' . EfrontFile::encode($currentLesson->lesson['name']) . '.zip');
        $smarty->assign("T_EXPORTED_FILE", $currentExportedFile);
    } catch (Exception $e) {
    }
    if ($form->isSubmitted() && $form->validate()) {
        try {
            $file = $currentLesson->export(false, true, $form->exportValue('export_files'));
            $smarty->assign("T_NEW_EXPORTED_FILE", $file);
            $message = _LESSONEXPORTEDSUCCESFULLY;
            $message_type = 'success';
        } catch (Exception $e) {
            handleNormalFlowExceptions($e);
        }
    }
    $renderer = new HTML_QuickForm_Renderer_ArraySmarty($smarty);
    $form->accept($renderer);