Exemplo n.º 1
0
require_once 'include/lib/hierarchy.class.php';
require_once 'archive_functions.php';
require_once 'restore_functions.php';

$toolName = $langCloneCourse;
$treeObj = new Hierarchy();
$_POST['restoreThis'] = null; // satisfy course_details_form()

if (isset($_POST['create_restored_course'])) {
    if (!isset($_POST['token']) || !validate_csrf_token($_POST['token'])) csrf_token_error();
    $currentCourseCode = $course_code;

    $restoreThis = $webDir . '/courses/tmpUnzipping/' .
        $uid . '/' . safe_filename();
    mkdir($restoreThis, 0755, true);
    archiveTables($course_id, $course_code, $restoreThis);
    recurse_copy($webDir . '/courses/' . $course_code,
        $restoreThis . '/html');

    register_posted_variables(array(
        'course_code' => true,
        'course_lang' => true,
        'course_title' => true,
        'course_desc' => true,
        'course_vis' => true,
        'course_prof' => true), 'all');

    create_restored_course($tool_content, $restoreThis, $course_code, $course_lang, $course_title, $course_desc, $course_vis, $course_prof);
    $course_code = $currentCourseCode; // revert course code to the correct value
} else {
    $desc = Database::get()->querySingle("SELECT description FROM course WHERE id = ?d", $course_id)->description;
Exemplo n.º 2
0
/**
 * Do the main task of archiving a course.
 * 
 * @param int $course_id
 * @param string $course_code
 */
function doArchive($course_id, $course_code) {
    global $webDir, $urlServer, $urlAppend, $siteName, $tool_content;
    
    if (extension_loaded('zlib')) {
        include 'include/pclzip/pclzip.lib.php';
    }

    $basedir = "$webDir/courses/archive/$course_code";
    file_exists($basedir) or mkdir($basedir, 0755, true);

    // Remove previous back-ups older than 10 minutes
    cleanup("$webDir/courses/archive", 600);

    $backup_date = date('Ymd-His');
    $backup_date_short = date('Ymd');

    $archivedir = $basedir . '/' . $backup_date;
    file_exists($archivedir) or mkdir($archivedir, 0755, true);

    archiveTables($course_id, $course_code, $archivedir);

    $zipfile = $basedir . "/$course_code-$backup_date_short.zip";

    // create zip file
    $zipCourse = new PclZip($zipfile);
    $result = $zipCourse->create($archivedir, PCLZIP_OPT_REMOVE_PATH, "$webDir/courses/archive") &&
        $zipCourse->add("$webDir/courses/$course_code", PCLZIP_OPT_REMOVE_PATH, "$webDir/courses/$course_code", PCLZIP_OPT_ADD_PATH, "$course_code/$backup_date/html") &&
        $zipCourse->add("$webDir/video/$course_code", PCLZIP_OPT_REMOVE_PATH, "$webDir/video/$course_code", PCLZIP_OPT_ADD_PATH, "$course_code/$backup_date/video_files");
    
    removeDir($archivedir);

    if (!$result) {
        $tool_content .= "Error: " . $zipCourse->errorInfo(true);
        draw($tool_content, 2);
        exit;
    }
}