Пример #1
0
            Display::display_warning_message(get_lang('NoResourcesInBackupFile'));
            echo '<a class="btn" href="import_backup.php?' . api_get_cidreq() . '">' . get_lang('TryAgain') . '</a>';
        } elseif ($filename === false) {
            Display::display_error_message(get_lang('ArchivesDirectoryNotWriteableContactAdmin'));
            echo '<a class="btn" href="import_backup.php?' . api_get_cidreq() . '">' . get_lang('TryAgain') . '</a>';
        } else {
            if ($filename == '') {
                Display::display_error_message(get_lang('SelectBackupFile'));
                echo '<a class="btn" href="import_backup.php?' . api_get_cidreq() . '">' . get_lang('TryAgain') . '</a>';
            } else {
                Display::display_error_message(get_lang('UploadError'));
                echo '<a class="btn" href="import_backup.php?' . api_get_cidreq() . '">' . get_lang('TryAgain') . '</a>';
            }
        }
    }
    CourseArchiver::clean_backup_dir();
} elseif (Security::check_token('post') && (isset($_POST['import_option']) && $_POST['import_option'] == 'select_items')) {
    // Clear token
    Security::clear_token();
    if ($_POST['backup_type'] == 'server') {
        $filename = $_POST['backup_server'];
        $delete_file = false;
    } else {
        $filename = CourseArchiver::import_uploaded_file($_FILES['backup']['tmp_name']);
        $delete_file = true;
    }
    $course = CourseArchiver::read_course($filename, $delete_file);
    if ($course->has_resources() && $filename !== false) {
        $hiddenFields['same_file_name_option'] = $_POST['same_file_name_option'];
        // Add token to Course select form
        $hiddenFields['sec_token'] = Security::get_token();
 /**
  * Read a course-object from a zip-file
  * @return course The course
  * @param boolean $delete Delete the file after reading the course?
  * @todo Check if the archive is a correct Chamilo-export
  */
 static function read_course($filename, $delete = false)
 {
     CourseArchiver::clean_backup_dir();
     // Create a temp directory
     $tmp_dir_name = 'CourseArchiver_' . uniqid('');
     $unzip_dir = api_get_path(SYS_ARCHIVE_PATH) . $tmp_dir_name;
     mkdir($unzip_dir, api_get_permissions_for_new_directories(), true);
     copy(api_get_path(SYS_ARCHIVE_PATH) . $filename, $unzip_dir . '/backup.zip');
     // unzip the archive
     $zip = new PclZip($unzip_dir . '/backup.zip');
     chdir($unzip_dir);
     $list = $zip->extract(PCLZIP_OPT_TEMP_FILE_ON);
     if ($list == 0) {
         /*global $app;
           $errorMessage = $zip->errorInfo(true);
           $app['session']->getFlashBag()->add('warning', $errorMessage);*/
     }
     // remove the archive-file
     if ($delete) {
         if (file_exists(api_get_path(SYS_ARCHIVE_PATH) . $filename)) {
             unlink(api_get_path(SYS_ARCHIVE_PATH) . $filename);
         }
     }
     // Read the course
     if (!is_file('course_info.dat')) {
         return new Course();
     }
     $contents = file_get_contents('course_info.dat');
     // CourseCopyLearnpath class appeared in Chamilo 1.8.7, it is the former Learnpath class in the "Copy course" tool.
     // For backward comaptibility with archives created on Chamilo 1.8.6.2 or older systems, we have to do the following:
     // Before unserialization, if class name "Learnpath" was found, it should be renamed as "CourseCopyLearnpath".
     $course = unserialize(str_replace('O:9:"Learnpath":', 'O:19:"CourseCopyLearnpath":', base64_decode($contents)));
     if (get_class($course) != 'Course') {
         return new Course();
     }
     $course->backup_path = $unzip_dir;
     return $course;
 }
 /**
  * Read a course-object from a zip-file
  * @param string $filename
  * @param boolean $delete Delete the file after reading the course?
  *
  * @return course The course
  * @todo Check if the archive is a correct Chamilo-export
  */
 public static function read_course($filename, $delete = false)
 {
     CourseArchiver::clean_backup_dir();
     // Create a temp directory
     $tmp_dir_name = 'CourseArchiver_' . uniqid('');
     $unzip_dir = api_get_path(SYS_ARCHIVE_PATH) . '' . $tmp_dir_name;
     @mkdir($unzip_dir, api_get_permissions_for_new_directories(), true);
     @copy(api_get_path(SYS_ARCHIVE_PATH) . '' . $filename, $unzip_dir . '/backup.zip');
     // unzip the archive
     $zip = new PclZip($unzip_dir . '/backup.zip');
     @chdir($unzip_dir);
     $zip->extract(PCLZIP_OPT_TEMP_FILE_ON);
     // remove the archive-file
     if ($delete) {
         @unlink(api_get_path(SYS_ARCHIVE_PATH) . '' . $filename);
     }
     // read the course
     if (!is_file('course_info.dat')) {
         return new Course();
     }
     $fp = @fopen('course_info.dat', "r");
     $contents = @fread($fp, filesize('course_info.dat'));
     @fclose($fp);
     // CourseCopyLearnpath class appeared in Chamilo 1.8.7, it is the former Learnpath class in the "Copy course" tool.
     // For backward comaptibility with archives created on Chamilo 1.8.6.2 or older systems, we have to do the following:
     // Before unserialization, if class name "Learnpath" was found, it should be renamed as "CourseCopyLearnpath".
     $course = unserialize(str_replace('O:9:"Learnpath":', 'O:19:"CourseCopyLearnpath":', base64_decode($contents)));
     if (get_class($course) != 'Course') {
         return new Course();
     }
     $course->backup_path = $unzip_dir;
     return $course;
 }