Source for file CourseArchiver.class.php
Documentation is available at CourseArchiver.class.php
// $Id: CourseArchiver.class.php 15429 2008-05-26 20:34:37Z yannoo $
==============================================================================
Dokeos - elearning and course management software
Copyright (c) 2004-2008 Dokeos SPRL
Copyright (c) 2003 Ghent University (UGent)
Copyright (c) 2001 Universite catholique de Louvain (UCL)
Copyright (c) Bart Mollet (bart.mollet@hogent.be)
For a full list of contributors, see "credits.txt".
The full license can be read in "license.txt".
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
See the GNU General Public License for more details.
Contact address: Dokeos, rue du Corbeau, 108, B-1030 Brussels, Belgium
==============================================================================
require_once ('Course.class.php');
require_once ('mkdirr.php');
require_once ('rmdirr.php');
require_once (api_get_path(LIBRARY_PATH). 'pclzip/pclzip.lib.php');
* Some functions to write a course-object to a zip-file and to read a course-
* object from such a zip-file.
* @author Bart Mollet <bart.mollet@hogent.be>
* @todo Use archive-folder of Dokeos?
while (($file = readdir($handle)) !== false)
if ($file != "." && $file != ".." && strpos($file,'CourseArchiver_') == 0 && is_dir($dir. '/'. $file))
* Write a course and all its resources to a zip-file.
* @return string A pointer to the zip-file
// Create a temp directory
$tmp_dir_name = 'CourseArchiver_'. uniqid('');
// All course-information will be stored in course_info.dat
$course_info_file = $backup_dir. 'course_info.dat';
$zip_file = $user['user_id']. '_'. $course->code. '_'. date("YmdHis"). '.zip';
$res = @mkdir($backup_dir, 0755);
//TODO set and handle an error message telling the user to review the permissions on the archive directory
error_log(__FILE__. ' line '.__LINE__. ': '. (ini_get('track_errors')!= false? $php_errormsg: 'error not recorded because track_errors is off in your php.ini'). ' - This error, occuring because your archive directory will not let this script write data into it, will prevent courses backups to be created',0);
// Write the course-object to the file
$fp = @fopen($course_info_file, 'w');
error_log(__FILE__. ' line '.__LINE__. ': '. (ini_get('track_errors')!= false? $php_errormsg: 'error not recorded because track_errors is off in your php.ini'),0);
error_log(__FILE__. ' line '.__LINE__. ': '. (ini_get('track_errors')!= false? $php_errormsg: 'error not recorded because track_errors is off in your php.ini'),0);
error_log(__FILE__. ' line '.__LINE__. ': '. (ini_get('track_errors')!= false? $php_errormsg: 'error not recorded because track_errors is off in your php.ini'),0);
// Copy all documents to the temp-dir
$doc_dir = $backup_dir. $document->path;
copy($course->path. $document->path, $doc_dir);
mkdirr($backup_dir. $document->path, 0755);
// Copy all scorm documents to the temp-dir
$doc_dir= dirname($backup_dir. $document->path);
copyDirTo($course->path. $document->path, $doc_dir, false);
// Zip the course-contents
$zip = new PclZip($zip_dir. $zip_file);
//$zip->deleteByIndex(0);
global $dateTimeFormatLong;
while (($file = readdir($dir)) !== false) {
if(count($file_parts) == 3)
$owner_id = $file_parts[0];
$course_code = $file_parts[1];
$file_parts = explode('.',$file_parts[2]);
if($ext == 'zip' && ($user_id != null && $owner_id == $user_id || $user_id == null) )
$date = substr($date,0,4). '-'. substr($date,4,2). '-'. substr($date,6,2). ' '. substr($date,8,2). ':'. substr($date,10,2). ':'. substr($date,12,2);
$backup_files[] = array('file' => $file, 'date' => $date, 'course_code' => $course_code);
$new_filename = uniqid(''). '.zip';
* 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 Dokeos-export
// Create a temp directory
$tmp_dir_name = 'CourseArchiver_'. uniqid('');
$zip = new PclZip($unzip_dir. '/backup.zip');
// remove the archive-file
$fp = @fopen('course_info.dat', "r");
$course->backup_path = $unzip_dir;
|