|
Moodle
2.2.1
http://www.collinsharper.com
|
00001 <?php 00002 00003 // This file is part of Moodle - http://moodle.org/ 00004 // 00005 // Moodle is free software: you can redistribute it and/or modify 00006 // it under the terms of the GNU General Public License as published by 00007 // the Free Software Foundation, either version 3 of the License, or 00008 // (at your option) any later version. 00009 // 00010 // Moodle is distributed in the hope that it will be useful, 00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 // GNU General Public License for more details. 00014 // 00015 // You should have received a copy of the GNU General Public License 00016 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 00017 00025 require_once('../config.php'); 00026 require_once(dirname(__FILE__) . '/restorefile_form.php'); 00027 require_once($CFG->dirroot . '/backup/util/includes/restore_includes.php'); 00028 00029 // current context 00030 $contextid = required_param('contextid', PARAM_INT); 00031 $filecontextid = optional_param('filecontextid', 0, PARAM_INT); 00032 // action 00033 $action = optional_param('action', '', PARAM_ALPHA); 00034 // file parameters 00035 // non js interface may require these parameters 00036 $component = optional_param('component', null, PARAM_COMPONENT); 00037 $filearea = optional_param('filearea', null, PARAM_AREA); 00038 $itemid = optional_param('itemid', null, PARAM_INT); 00039 $filepath = optional_param('filepath', null, PARAM_PATH); 00040 $filename = optional_param('filename', null, PARAM_FILE); 00041 00042 list($context, $course, $cm) = get_context_info_array($contextid); 00043 00044 // will be used when restore 00045 if (!empty($filecontextid)) { 00046 $filecontext = get_context_instance_by_id($filecontextid); 00047 } 00048 00049 $url = new moodle_url('/backup/restorefile.php', array('contextid'=>$contextid)); 00050 00051 switch ($context->contextlevel) { 00052 case CONTEXT_MODULE: 00053 $heading = get_string('restoreactivity', 'backup'); 00054 break; 00055 case CONTEXT_COURSE: 00056 default: 00057 $heading = get_string('restorecourse', 'backup'); 00058 } 00059 00060 00061 require_login($course, false, $cm); 00062 require_capability('moodle/restore:restorecourse', $context); 00063 00064 $browser = get_file_browser(); 00065 00066 // check if tmp dir exists 00067 $tmpdir = $CFG->tempdir . '/backup'; 00068 if (!check_dir_exists($tmpdir, true, true)) { 00069 throw new restore_controller_exception('cannot_create_backup_temp_dir'); 00070 } 00071 00072 // choose the backup file from backup files tree 00073 if ($action == 'choosebackupfile') { 00074 if ($fileinfo = $browser->get_file_info($filecontext, $component, $filearea, $itemid, $filepath, $filename)) { 00075 $filename = restore_controller::get_tempdir_name($course->id, $USER->id); 00076 $pathname = $tmpdir . '/' . $filename; 00077 $fileinfo->copy_to_pathname($pathname); 00078 $restore_url = new moodle_url('/backup/restore.php', array('contextid'=>$contextid, 'filename'=>$filename)); 00079 redirect($restore_url); 00080 } else { 00081 redirect($url, get_string('filenotfound', 'error')); 00082 } 00083 die; 00084 } 00085 00086 $PAGE->set_url($url); 00087 $PAGE->set_context($context); 00088 $PAGE->set_title(get_string('course') . ': ' . $course->fullname); 00089 $PAGE->set_heading($heading); 00090 $PAGE->set_pagelayout('admin'); 00091 00092 $form = new course_restore_form(null, array('contextid'=>$contextid)); 00093 $data = $form->get_data(); 00094 if ($data && has_capability('moodle/restore:uploadfile', $context)) { 00095 $filename = restore_controller::get_tempdir_name($course->id, $USER->id); 00096 $pathname = $tmpdir . '/' . $filename; 00097 $form->save_file('backupfile', $pathname); 00098 $restore_url = new moodle_url('/backup/restore.php', array('contextid'=>$contextid, 'filename'=>$filename)); 00099 redirect($restore_url); 00100 die; 00101 } 00102 00103 00104 00105 echo $OUTPUT->header(); 00106 00107 // require uploadfile cap to use file picker 00108 if (has_capability('moodle/restore:uploadfile', $context)) { 00109 echo $OUTPUT->heading(get_string('importfile', 'backup')); 00110 echo $OUTPUT->container_start(); 00111 $form->display(); 00112 echo $OUTPUT->container_end(); 00113 } 00114 00115 if ($context->contextlevel == CONTEXT_MODULE) { 00116 echo $OUTPUT->heading_with_help(get_string('choosefilefromactivitybackup', 'backup'), 'choosefilefromuserbackup', 'backup'); 00117 echo $OUTPUT->container_start(); 00118 $treeview_options = array(); 00119 $user_context = get_context_instance(CONTEXT_USER, $USER->id); 00120 $treeview_options['filecontext'] = $context; 00121 $treeview_options['currentcontext'] = $context; 00122 $treeview_options['component'] = 'backup'; 00123 $treeview_options['context'] = $context; 00124 $treeview_options['filearea'] = 'activity'; 00125 $renderer = $PAGE->get_renderer('core', 'backup'); 00126 echo $renderer->backup_files_viewer($treeview_options); 00127 echo $OUTPUT->container_end(); 00128 } 00129 00130 echo $OUTPUT->heading_with_help(get_string('choosefilefromcoursebackup', 'backup'), 'choosefilefromcoursebackup', 'backup'); 00131 echo $OUTPUT->container_start(); 00132 $treeview_options = array(); 00133 $treeview_options['filecontext'] = $context; 00134 $treeview_options['currentcontext'] = $context; 00135 $treeview_options['component'] = 'backup'; 00136 $treeview_options['context'] = $context; 00137 $treeview_options['filearea'] = 'course'; 00138 $renderer = $PAGE->get_renderer('core', 'backup'); 00139 echo $renderer->backup_files_viewer($treeview_options); 00140 echo $OUTPUT->container_end(); 00141 00142 echo $OUTPUT->heading_with_help(get_string('choosefilefromuserbackup', 'backup'), 'choosefilefromuserbackup', 'backup'); 00143 echo $OUTPUT->container_start(); 00144 $treeview_options = array(); 00145 $user_context = get_context_instance(CONTEXT_USER, $USER->id); 00146 $treeview_options['filecontext'] = $user_context; 00147 $treeview_options['currentcontext'] = $context; 00148 $treeview_options['component'] = 'user'; 00149 $treeview_options['context'] = 'backup'; 00150 $treeview_options['filearea'] = 'backup'; 00151 $renderer = $PAGE->get_renderer('core', 'backup'); 00152 echo $renderer->backup_files_viewer($treeview_options); 00153 echo $OUTPUT->container_end(); 00154 00155 $automatedbackups = get_config('backup', 'backup_auto_active'); 00156 if (!empty($automatedbackups)) { 00157 echo $OUTPUT->heading_with_help(get_string('choosefilefromautomatedbackup', 'backup'), 'choosefilefromautomatedbackup', 'backup'); 00158 echo $OUTPUT->container_start(); 00159 $treeview_options = array(); 00160 $user_context = get_context_instance(CONTEXT_USER, $USER->id); 00161 $treeview_options['filecontext'] = $context; 00162 $treeview_options['currentcontext'] = $context; 00163 $treeview_options['component'] = 'backup'; 00164 $treeview_options['context'] = $context; 00165 $treeview_options['filearea'] = 'automated'; 00166 $renderer = $PAGE->get_renderer('core', 'backup'); 00167 echo $renderer->backup_files_viewer($treeview_options); 00168 echo $OUTPUT->container_end(); 00169 } 00170 00171 echo $OUTPUT->footer();