Project

General

Profile

Bug #5426 ยป create_backup.php

Yoselyn Castillo, 07/09/2012 08:38

 
1
<?php
2
/* For licensing terms, see /license.txt */
3
/**
4
 * Create a backup.
5
 *
6
 * @author Bart Mollet <bart.mollet@hogent.be>
7
 * @package chamilo.backup
8
 */
9
/**
10
 * Code
11
 */
12
// Language files that need to be included
13
$language_file = array('exercice', 'admin', 'coursebackup');
14

    
15
// Including the global initialization file
16
require_once '../inc/global.inc.php';
17
$current_course_tool  = TOOL_COURSE_MAINTENANCE;
18

    
19
api_protect_course_script(true);
20

    
21
api_check_archive_dir();
22

    
23
// Check access rights (only teachers are allowed here)
24
if (!api_is_allowed_to_edit()) {
25
	api_not_allowed(true);
26
}
27

    
28
// Remove memory and time limits as much as possible as this might be a long process...
29
if (function_exists('ini_set')) {
30
    $memory_limit = ini_get('memory_limit');
31
    //$memorylimit_rev = strrev($memory_limit); 
32
    $um = substr($memory_limit, -1, 1);
33
    $value = substr($memory_limit,0,strlen($memory_limit)-1);
34
    if (strcasecmp($um,'m') == 0) {
35
      if ($value<256) {
36
        ini_set('memory_limit', '256M');
37
      } 
38
    } else {
39
        if (strcasecmp($um,'k') == 0 || strcasecmp($um,'b') == 0) {
40
            ini_set('memory_limit', '256M');
41
        }
42
    }
43
            
44
    if (ini_get('max_execution_time')<1800) {
45
        ini_set('max_execution_time',1800);
46
    }
47
}
48

    
49
// Section for the tabs
50
$this_section = SECTION_COURSES;
51

    
52
// Breadcrumbs
53
$interbreadcrumb[] = array('url' => '../course_info/maintenance.php', 'name' => get_lang('Maintenance'));
54

    
55
// Displaying the header
56
$nameTools = get_lang('CreateBackup');
57
Display::display_header($nameTools);
58

    
59
// Include additional libraries
60
require_once api_get_path(LIBRARY_PATH).'fileManage.lib.php';
61
require_once 'classes/CourseBuilder.class.php';
62
require_once 'classes/CourseArchiver.class.php';
63
require_once 'classes/CourseRestorer.class.php';
64
require_once 'classes/CourseSelectForm.class.php';
65

    
66
// Display the tool title
67
echo Display::page_header($nameTools);
68

    
69
/*	MAIN CODE */
70

    
71
if ((isset($_POST['action']) && $_POST['action'] == 'course_select_form') || (isset($_POST['backup_option']) && $_POST['backup_option'] == 'full_backup')) {
72
	if (isset ($_POST['action']) && $_POST['action'] == 'course_select_form') {
73
		$course = CourseSelectForm :: get_posted_course();
74
	} else {
75
		$cb = new CourseBuilder();
76
		$course = $cb->build();
77
	}
78
	$zip_file = CourseArchiver :: write_course($course); 
79
	Display::display_confirmation_message(get_lang('BackupCreated'));
80
	echo '<br /><a class="btn btn-primary btn-large" href="../course_info/download.php?archive='.$zip_file.'">'.get_lang('Download').'</a>';
81

    
82
} elseif (isset($_POST['backup_option']) && $_POST['backup_option'] == 'select_items') {
83
	$cb = new CourseBuilder('partial');
84
	$course = $cb->build();	
85
	CourseSelectForm :: display_form($course);
86
} else {
87
	$cb = new CourseBuilder();
88
	$course = $cb->build();
89
	if (!$course->has_resources()) {
90
		echo get_lang('NoResourcesToBackup');
91
	} else {		
92
		
93
		$form = new FormValidator('create_backup_form', 'post');
94
		$form->addElement('header',get_lang('SelectOptionForBackup'));
95
		
96
		$form->addElement('radio', 'backup_option', '', get_lang('CreateFullBackup'), 'full_backup');
97
		$form->addElement('radio', 'backup_option', '',  get_lang('LetMeSelectItems'), 'select_items');
98
		
99
		$form->addElement('style_submit_button', null, get_lang('CreateBackup'), 'class="save"');
100

    
101
		$form->add_progress_bar();
102
		// When progress bar appears we have to hide the title "Please select a backup-option".
103
		$form->updateAttributes(array('onsubmit' => str_replace('javascript: ', 'javascript: page_title = getElementById(\'page_title\'); if (page_title) { setTimeout(\'page_title.style.display = \\\'none\\\';\', 2000); } ', $form->getAttribute('onsubmit'))));
104

    
105
		$values['backup_option'] = 'full_backup';
106
		$form->setDefaults($values);
107
		$form->display();
108
	}
109
}
110

    
111
/*	FOOTER */
112
Display::display_footer();
    (1-1/1)