Beispiel #1
0
 /**
  * Copy files needed in the export for this module
  *
  * @copyright   (c) 2001-2011, Universite catholique de Louvain (UCL)
  * @param string $docId name of the document
  * @param object $item item of the path
  * @param string $destDir path when the files need to be copied
  * @param int $deepness deepness of the destinationd directory
  * @return boolean
  */
 public function prepareFiles($docId, &$item, $destDir, $deepness)
 {
     $completionThresold = $item->getCompletionThreshold();
     if (empty($completionThresold)) {
         $completionThresold = 50;
     }
     $docPath = $this->srcDirDocument . '/' . $docId;
     if (!file_exists($docPath)) {
         $this->error = get_lang('The file %file doesn\'t exist', array('%file' => $docId));
         return false;
     }
     if (!claro_copy_file($docPath, $destDir)) {
         $this->error = get_lang('Unable to copy file %file in temporary directory', array('%file' => $docId));
         return false;
     }
     $frameName = 'frame_for_' . $item->getId() . '.html';
     if (!parent::createFrameFile($frameName, $docId, $item, $destDir, $deepness)) {
         $this->error = get_lang('Unable to create frame for document %file.', array('%file' => $docId));
         return false;
     }
     return true;
 }
Beispiel #2
0
        /**
         * Prepare the temporary destination directory that'll be zipped and exported.
         * Existing SCORM, documents, as well as required or helper javascript files and XML schemas
         * are copied into the directory.
         * No manifest created yet.
         *
         * @return False on error, true otherwise.
         * @see createManifest
         * @author Thanos Kyritsis <*****@*****.**>
         * @author Amand Tihon <*****@*****.**>
         */
        function prepare() {
            global $clarolineRepositorySys, $claro_stylesheet;
            global $langErrorCopyScormFiles, $langErrorCreatingDirectory, $langErrorCopyingScorm, $langErrorCopyAttachedFile;
            // (re)create fresh directory

            claro_delete_file($this->destDir);
            if (
                    !claro_mkdir($this->destDir, CLARO_FILE_PERMISSIONS, true) || !claro_mkdir($this->destDir . "/common", CLARO_FILE_PERMISSIONS, true) || !claro_mkdir($this->destDir . "/extend", CLARO_FILE_PERMISSIONS, true) || !claro_mkdir($this->destDir . "/unique", CLARO_FILE_PERMISSIONS, true) || !claro_mkdir($this->destDir . "/vocab", CLARO_FILE_PERMISSIONS, true)
            ) {
                $this->error[] = $langErrorCreatingDirectory . $this->destDir;
                return false;
            }

            // Copy usual files (.css, .js, .xsd, etc)
            if (
                    !claro_copy_file('modules/learnPath/export/APIWrapper.js', $this->destDir) || !claro_copy_file('template/default/CSS/bootstrap-custom.css', $this->destDir) || !claro_copy_file('modules/learnPath/export/XMLSchema.dtd', $this->destDir) || !claro_copy_file('modules/learnPath/export/adlcp_v1p3.xsd', $this->destDir) || !claro_copy_file('modules/learnPath/export/adlnav_v1p3.xsd', $this->destDir) || !claro_copy_file('modules/learnPath/export/adlseq_v1p3.xsd', $this->destDir) || !claro_copy_file('modules/learnPath/export/datatypes.dtd', $this->destDir) || !claro_copy_file('modules/learnPath/export/ims_xml.xsd', $this->destDir) || !claro_copy_file('modules/learnPath/export/imscp_v1p1.xsd', $this->destDir) || !claro_copy_file('modules/learnPath/export/imsss_v1p0.xsd', $this->destDir) || !claro_copy_file('modules/learnPath/export/imsss_v1p0auxresource.xsd', $this->destDir) || !claro_copy_file('modules/learnPath/export/imsss_v1p0control.xsd', $this->destDir) || !claro_copy_file('modules/learnPath/export/imsss_v1p0delivery.xsd', $this->destDir) || !claro_copy_file('modules/learnPath/export/imsss_v1p0limit.xsd', $this->destDir) || !claro_copy_file('modules/learnPath/export/imsss_v1p0objective.xsd', $this->destDir) || !claro_copy_file('modules/learnPath/export/imsss_v1p0random.xsd', $this->destDir) || !claro_copy_file('modules/learnPath/export/imsss_v1p0rollup.xsd', $this->destDir) || !claro_copy_file('modules/learnPath/export/imsss_v1p0seqrule.xsd', $this->destDir) || !claro_copy_file('modules/learnPath/export/imsss_v1p0util.xsd', $this->destDir) || !claro_copy_file('modules/learnPath/export/lom.xsd', $this->destDir) || !claro_copy_file('modules/learnPath/export/lomCustom.xsd', $this->destDir) || !claro_copy_file('modules/learnPath/export/lomLoose.xsd', $this->destDir) || !claro_copy_file('modules/learnPath/export/lomStrict.xsd', $this->destDir) || !claro_copy_file('modules/learnPath/export/scores.js', $this->destDir) || !claro_copy_file('modules/learnPath/export/xml.xsd', $this->destDir) || !claro_copy_file('modules/learnPath/export/common/anyElement.xsd', $this->destDir . "/common") || !claro_copy_file('modules/learnPath/export/common/dataTypes.xsd', $this->destDir . "/common") || !claro_copy_file('modules/learnPath/export/common/elementNames.xsd', $this->destDir . "/common") || !claro_copy_file('modules/learnPath/export/common/elementTypes.xsd', $this->destDir . "/common") || !claro_copy_file('modules/learnPath/export/common/rootElement.xsd', $this->destDir . "/common") || !claro_copy_file('modules/learnPath/export/common/vocabTypes.xsd', $this->destDir . "/common") || !claro_copy_file('modules/learnPath/export/common/vocabValues.xsd', $this->destDir . "/common") || !claro_copy_file('modules/learnPath/export/extend/custom.xsd', $this->destDir . "/extend") || !claro_copy_file('modules/learnPath/export/extend/strict.xsd', $this->destDir . "/extend") || !claro_copy_file('modules/learnPath/export/unique/loose.xsd', $this->destDir . "/unique") || !claro_copy_file('modules/learnPath/export/unique/strict.xsd', $this->destDir . "/unique") || !claro_copy_file('modules/learnPath/export/vocab/custom.xsd', $this->destDir . "/vocab") || !claro_copy_file('modules/learnPath/export/vocab/loose.xsd', $this->destDir . "/vocab") || !claro_copy_file('modules/learnPath/export/vocab/strict.xsd', $this->destDir . "/vocab")
            ) {
                $this->error[] = $langErrorCopyScormFiles;
                return false;
            }


            // Copy SCORM package, if needed
            if ($this->fromScorm) {
                // Copy the scorm directory as OrigScorm/
                if (
                        !claro_copy_file($this->srcDirScorm, $this->destDir) || !claro_rename_file($this->destDir . '/path_' . $this->id, $this->destDir . '/OrigScorm')) {
                    $this->error[] = $langErrorCopyingScorm;
                    return false;
                }
            }

            // Create destination directory for "pure" documents
            claro_mkdir($this->destDir . '/Documents', CLARO_FILE_PERMISSIONS, true);

            // And for exercises
            claro_mkdir($this->destDir . '/Exercises', CLARO_FILE_PERMISSIONS, true);

            // Copy documents into the created directory
            foreach ($this->resourceMap as $module) {
                if ($module['contentType'] == 'DOCUMENT') {
                    $documentName = basename($module['path']);
                    if (dirname($module['path']) != '/') {
                        $destinationDir = $this->destDir . '/Documents' . dirname($module['path']) . '/';
                    } else {
                        $destinationDir = $this->destDir . '/Documents/';
                    }
                    if (!is_dir($destinationDir)) {
                        claro_mkdir($destinationDir, CLARO_FILE_PERMISSIONS, true);
                    }
                    @copy($this->srcDirDocument . $module['path'], $destinationDir . $documentName);
                } elseif ($module['contentType'] == 'EXERCISE') {
                    if (!$this->prepareQuiz($module['path'], $module['raw_to_pass']))
                        return false;
                }
                elseif ($module['contentType'] == 'MEDIA') {
                    $documentName = basename($module['path']);
                    $destinationDir = $this->destDir . '/Documents/';
                    if (!is_dir($destinationDir)) {
                        claro_mkdir($destinationDir, CLARO_FILE_PERMISSIONS, true);
                    }
                    @copy($this->srcDirVideo . $module['path'], $destinationDir . $documentName);
                }
            }

            // Did we find an mp3 ?
            /* if ( $this->mp3Found)
              {
              if ( !claro_copy_file($clarolineRepositorySys . '/exercise/claroPlayer.swf', $this->destDir) )
              {
              $this->error[] = $langErrorCopyAttachedFile . $clarolineRepositorySys . '/exercise/claroPlayer.swf';

              // This is *NOT* a fatal error.
              // Do *NOT* return false.
              }
              } */


            return true;
        }
        /**
         * Prepare the temporary destination directory that'll be zipped and exported.
         * Existing SCORM, documents, as well as required or helper javascript files and XML schemas
         * are copied into the directory.
         * No manifest created yet.
         *
         * @return False on error, true otherwise.
         * @see createManifest
         * @author Thanos Kyritsis <*****@*****.**>
         * @author Amand Tihon <*****@*****.**>
         */
        function prepare() {
            global $clarolineRepositorySys, $claro_stylesheet;
            global $langErrorCopyScormFiles, $langErrorCreatingDirectory, $langErrorCopyingScorm, $langErrorCopyAttachedFile;

            // (re)create fresh directory
            claro_delete_file($this->destDir);
            if (!claro_mkdir($this->destDir, CLARO_FILE_PERMISSIONS, true)) {
                $this->error[] = $langErrorCreatingDirectory . $this->destDir;
                return false;
            }
            // Copy usual files (.css, .js, .xsd, etc)
            if (
                    !claro_copy_file('modules/learnPath/export12/APIWrapper.js', $this->destDir) || !claro_copy_file('template/default/CSS/bootstrap-custom.css', $this->destDir) || !claro_copy_file('modules/learnPath/export12/scores.js', $this->destDir) || !claro_copy_file('modules/learnPath/export12/ims_xml.xsd', $this->destDir) || !claro_copy_file('modules/learnPath/export12/imscp_rootv1p1p2.xsd', $this->destDir) || !claro_copy_file('modules/learnPath/export12/imsmd_rootv1p2p1.xsd', $this->destDir) || !claro_copy_file('modules/learnPath/export12/adlcp_rootv1p2.xsd', $this->destDir)) {
                $this->error[] = $langErrorCopyScormFiles;
                return false;
            }


            // Copy SCORM package, if needed
            if ($this->fromScorm) {
                // Copy the scorm directory as OrigScorm/
                if (
                        !claro_copy_file($this->srcDirScorm, $this->destDir) || !claro_rename_file($this->destDir . '/path_' . $this->id, $this->destDir . '/OrigScorm')) {
                    $this->error[] = $langErrorCopyingScorm;
                    return false;
                }
            }

            // Create destination directory for "pure" documents
            claro_mkdir($this->destDir . '/Documents', CLARO_FILE_PERMISSIONS, true);

            // And for exercises
            claro_mkdir($this->destDir . '/Exercises', CLARO_FILE_PERMISSIONS, true);

            // Copy documents into the created directory
            foreach ($this->resourceMap as $module) {
                if ($module['contentType'] == 'DOCUMENT') {
                    $documentName = basename($module['path']);
                    if (dirname($module['path']) != '/') {
                        $destinationDir = $this->destDir . '/Documents' . dirname($module['path']) . '/';
                    } else {
                        $destinationDir = $this->destDir . '/Documents/';
                    }
                    if (!is_dir($destinationDir)) {
                        claro_mkdir($destinationDir, CLARO_FILE_PERMISSIONS, true);
                    }
                    @copy($this->srcDirDocument . $module['path'], $destinationDir . $documentName);
                } elseif ($module['contentType'] == 'EXERCISE') {
                    if (!$this->prepareQuiz($module['path'], $module['raw_to_pass'])) {
                        return false;
                    }
                }
                elseif ($module['contentType'] == 'MEDIA') {
                    $documentName = basename($module['path']);
                    $destinationDir = $this->destDir . '/Documents/';
                    if (!is_dir($destinationDir)) {
                        claro_mkdir($destinationDir, CLARO_FILE_PERMISSIONS, true);
                    }
                    @copy($this->srcDirVideo . $module['path'], $destinationDir . $documentName);
                }
            }

            // Did we find an mp3 ?
            if ($this->mp3Found) {
                if (!claro_copy_file($clarolineRepositorySys . '/exercise/claroPlayer.swf', $this->destDir)) {
                    $this->error[] = $langErrorCopyAttachedFile . $clarolineRepositorySys . '/exercise/claroPlayer.swf';

                    // This is *NOT* a fatal error.
                    // Do *NOT* return false.
                }
            }


            return true;
        }
Beispiel #4
0
/**
 * Copy a file or a directory and its content to an other directory
 *
 * @param  - $sourcePath (String) - the path of the directory or the path of the file to move
 * @param  - $targetPath (String) - the path of the destination directory
 * @return - void no return !!
 */
function claro_copy_file($sourcePath, $targetPath)
{
    $fileName = basename($sourcePath);
    $sourcePath = realpath($sourcePath);
    $targetPath = realpath($targetPath);
    if (!is_readable($sourcePath)) {
        Console::warning($sourcePath . 'not readable');
    }
    if (!is_writable($targetPath)) {
        Console::warning($targetPath . 'not writable');
    }
    if (is_file($sourcePath)) {
        return copy($sourcePath, $targetPath . '/' . $fileName);
    } elseif (is_dir($sourcePath)) {
        if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
            // fix windows path for regexp
            $sourcePath = str_replace('\\', '\\\\', $sourcePath);
            $targetPath = str_replace('\\', '\\\\', $targetPath);
        }
        // check to not copy the directory inside itself
        if (preg_match('/^' . str_replace('/', '\\/', $sourcePath) . '\\//', str_replace('/', '\\/', $targetPath) . '/')) {
            return false;
        }
        if (!claro_mkdir($targetPath . '/' . $fileName, CLARO_FILE_PERMISSIONS)) {
            return false;
        }
        $dirHandle = opendir($sourcePath);
        if (!$dirHandle) {
            return false;
        }
        $copiableFileList = array();
        while (false !== ($element = readdir($dirHandle))) {
            if ($element == '.' || $element == '..' || $element == '.svn') {
                continue;
            }
            $copiableFileList[] = $sourcePath . '/' . $element;
        }
        closedir($dirHandle);
        if (count($copiableFileList) > 0) {
            foreach ($copiableFileList as $thisFile) {
                if (!claro_copy_file($thisFile, $targetPath . '/' . $fileName)) {
                    return false;
                }
            }
        }
        return true;
    }
    // end elseif is_dir()
}
Beispiel #5
0
     }
 } elseif (array_key_exists('packageCandidatePath', $_REQUEST)) {
     // If the target is a zip file, it must be unpack
     // If it's a unziped package, We copye the content
     if (is_package_file($_REQUEST['packageCandidatePath'])) {
         pushClaroMessage(__LINE__ . 'packageCandidatePath is a package', 'dbg');
         $modulePath = unzip_package($_REQUEST['packageCandidatePath']);
         pushClaroMessage(__LINE__ . '<pre>$modulePath =' . var_export($modulePath, 1) . '</pre>', 'dbg');
     } elseif (file_exists($_REQUEST['packageCandidatePath'])) {
         // COPY THE FILE TO WORK REPOSITORY
         pushClaroMessage(__LINE__ . 'packageCandidatePath is a path', 'dbg');
         claro_mkdir(get_package_path());
         $modulePath = create_unexisting_directory(get_package_path() . basename($_REQUEST['packageCandidatePath']));
         claro_mkdir($modulePath);
         pushClaroMessage(__LINE__ . 'create target' . $modulePath, 'dbg');
         if (claro_copy_file($_REQUEST['packageCandidatePath'], $modulePath . '/')) {
             $modulePath .= '/' . basename($_REQUEST['packageCandidatePath']);
             $moduleInstallable = true;
         } else {
             $dialogBox->error(get_lang('Module catching failed. Check your path'));
             $moduleInstallable = false;
         }
     }
 }
 pushClaroMessage(__LINE__ . '<pre>$modulePath =' . var_export($modulePath, 1) . '</pre>', 'dbg');
 // OK TO TRY TO INSTALL ?
 if ($moduleInstallable) {
     list($backlog, $module_id) = install_module($modulePath);
     $details = $backlog->output();
     if (false !== $module_id) {
         $summary = get_lang('Module installation succeeded');
function claro_copy_file($sourcePath, $targetPath)
{
    $fileName = my_basename($sourcePath);
    if (is_file($sourcePath)) {
        return copy($sourcePath, $targetPath . '/' . $fileName);
    } elseif (is_dir($sourcePath)) {
        // check to not copy the directory inside itself
        if (preg_match('|^' . $sourcePath . '/|', $targetPath . '/')) {
            return false;
        }
        if (!claro_mkdir($targetPath . '/' . $fileName, CLARO_FILE_PERMISSIONS)) {
            return false;
        }
        $dirHandle = opendir($sourcePath);
        if (!$dirHandle) {
            return false;
        }
        $copiableFileList = array();
        while ($element = readdir($dirHandle)) {
            if ($element == '.' || $element == '..') {
                continue;
            }
            $copiableFileList[] = $sourcePath . '/' . $element;
        }
        closedir($dirHandle);
        if (count($copiableFileList) > 0) {
            foreach ($copiableFileList as $thisFile) {
                if (!claro_copy_file($thisFile, $targetPath . '/' . $fileName)) {
                    return false;
                }
            }
        }
        return true;
    }
    // end elseif is_dir()
}
Beispiel #7
0
 public function copyAttachment($sourceFile)
 {
     if (!empty($this->questionDirSys) && file_exists($sourceFile)) {
         // delete current attachment
         $this->deleteAttachment();
         $this->attachment = basename($sourceFile);
         if (claro_copy_file($sourceFile, $this->questionDirSys)) {
             return true;
         } else {
             $this->attachment = '';
             return false;
         }
     } else {
         return false;
     }
 }
Beispiel #8
0
 /**
  * Prepare the temporary destination directory that'll be zipped and exported.
  * Existing SCORM, documents, as well as required or helper javascript files and XML schemas
  * are copied into the directory.
  * No manifest created yet.
  *
  * @return False on error, true otherwise.
  * @see createManifest
  * @author Amand Tihon <*****@*****.**>
  */
 public function prepare()
 {
     global $claro_stylesheet;
     // (re)create fresh directory
     claro_delete_file($this->destDir);
     if (!claro_mkdir($this->destDir, CLARO_FILE_PERMISSIONS, true)) {
         $this->error[] = get_lang('Unable to create directory : ') . $this->destDir;
         return false;
     }
     // Copy SCORM package, if needed
     if ($this->fromScorm && file_exists($this->srcDirScorm)) {
         // Copy the scorm directory as OrigScorm/
         if (!claro_copy_file($this->srcDirScorm, $this->destDir) || !claro_rename_file($this->destDir . '/path_' . $this->id, $this->destDir . '/OrigScorm')) {
             $this->error[] = get_lang('Error copying existing SCORM content');
             return false;
         } else {
             return true;
         }
     }
     // Check css to use
     if (file_exists(get_path('clarolineRepositorySys') . '../platform/css/' . $claro_stylesheet)) {
         $claro_stylesheet_path = get_path('clarolineRepositorySys') . '../platform/css/' . $claro_stylesheet;
     } elseif (file_exists(get_path('clarolineRepositorySys') . '../web/css/' . $claro_stylesheet)) {
         $claro_stylesheet_path = get_path('clarolineRepositorySys') . '../web/css/' . $claro_stylesheet;
     }
     // Copy usual files (.css, .js, .xsd, etc)
     if (!claro_copy_file($claro_stylesheet_path, $this->destDir) || !claro_copy_file(dirname(__FILE__) . '/../export/APIWrapper.js', $this->destDir) || !claro_copy_file(dirname(__FILE__) . '/../export/scores.js', $this->destDir) || !claro_copy_file(dirname(__FILE__) . '/../export/ims_xml.xsd', $this->destDir) || !claro_copy_file(dirname(__FILE__) . '/../export/imscp_rootv1p1p2.xsd', $this->destDir) || !claro_copy_file(dirname(__FILE__) . '/../export/imsmd_rootv1p2p1.xsd', $this->destDir) || !claro_copy_file(dirname(__FILE__) . '/../export/adlcp_rootv1p2.xsd', $this->destDir) || !claro_copy_file(get_path('clarolineRepositorySys') . '../web/js/jquery.js', $this->destDir) || !claro_copy_file(get_path('clarolineRepositorySys') . '../web/js/claroline.js', $this->destDir) || !claro_copy_file(get_path('clarolineRepositorySys') . '../web/js/claroline.ui.js', $this->destDir)) {
         $this->error[] = get_lang('Error when copying needed SCORM files');
         return false;
     }
     // Copy SCORM package, if needed
     if ($this->fromScorm && file_exists($this->srcDirScorm)) {
         // Copy the scorm directory as OrigScorm/
         if (!claro_copy_file($this->srcDirScorm, $this->destDir) || !claro_rename_file($this->destDir . '/path_' . $this->id, $this->destDir . '/OrigScorm')) {
             $this->error[] = get_lang('Error copying existing SCORM content');
             return false;
         }
     }
     // Create destination directory for "pure" documents
     claro_mkdir($this->destDir . '/Documents');
     // And for exercises
     claro_mkdir($this->destDir . '/Exercises');
     // Copy documents into the created directory
     foreach ($this->resourceMap as $module) {
         if ($module['contentType'] == 'DOCUMENT') {
             if (dirname($module['path']) != '/') {
                 $destinationDir = $this->destDir . '/Documents' . dirname($module['path']);
             } else {
                 $destinationDir = $this->destDir . '/Documents';
             }
             if (!is_dir($destinationDir)) {
                 claro_mkdir($destinationDir, CLARO_FILE_PERMISSIONS, true);
             }
             if (!empty($module['path'])) {
                 claro_copy_file($this->srcDirDocument . $module['path'], $destinationDir);
             }
             // TODO : If it's an html document, parse it and add the embed object (img, ...)
         } elseif ($module['contentType'] == 'EXERCISE') {
             if (!$this->prepareQuiz($module['path'], $module['raw_to_pass'])) {
                 return false;
             }
         }
     }
     // Did we find an mp3 ?
     if ($this->mp3Found) {
         if (!claro_copy_file(get_module_path('CLQWZ') . '/claroPlayer.swf', $this->destDir)) {
             $this->error[] = get_lang('Unable to copy file : %filename', array('%filename' => get_module_path('CLQWZ') . '/claroPlayer.swf'));
             // This is *NOT* a fatal error.
             // Do *NOT* return false.
         }
     }
     return true;
 }