Commit | Line | Data |
---|---|---|
1904e9b3 SH |
1 | <?php |
2 | ||
3 | // This file is part of Moodle - http://moodle.org/ | |
4 | // | |
5 | // Moodle is free software: you can redistribute it and/or modify | |
6 | // it under the terms of the GNU General Public License as published by | |
7 | // the Free Software Foundation, either version 3 of the License, or | |
8 | // (at your option) any later version. | |
9 | // | |
10 | // Moodle is distributed in the hope that it will be useful, | |
11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | // GNU General Public License for more details. | |
14 | // | |
15 | // You should have received a copy of the GNU General Public License | |
16 | // along with Moodle. If not, see <http://www.gnu.org/licenses/>. | |
17 | ||
18 | /** | |
19 | * This file contains backup and restore output renderers | |
20 | * | |
21 | * @package moodlecore | |
22 | * @copyright 2010 Sam Hemelryk | |
23 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | |
24 | */ | |
25 | ||
26 | /** | |
27 | * The primary renderer for the backup. | |
28 | * | |
29 | * Can be retrieved with the following code: | |
30 | * <?php | |
31 | * $renderer = $PAGE->get_renderer('core','backup'); | |
32 | * ?> | |
33 | * | |
34 | * @copyright 2010 Sam Hemelryk | |
35 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | |
36 | */ | |
37 | class core_backup_renderer extends plugin_renderer_base { | |
38 | /** | |
39 | * Renderers a progress bar for the backup or restore given the items that | |
40 | * make it up. | |
41 | * @param array $items An array of items | |
42 | * @return string | |
43 | */ | |
44 | public function progress_bar(array $items) { | |
45 | foreach ($items as &$item) { | |
46 | $text = $item['text']; | |
47 | unset($item['text']); | |
4886029c SH |
48 | if (array_key_exists('link', $item)) { |
49 | $link = $item['link']; | |
50 | unset($item['link']); | |
51 | $item = html_writer::link($link, $text, $item); | |
52 | } else { | |
53 | $item = html_writer::tag('span', $text, $item); | |
54 | } | |
1904e9b3 SH |
55 | } |
56 | return html_writer::tag('div', join(get_separator(), $items), array('class'=>'backup_progress clearfix')); | |
57 | } | |
58 | /** | |
59 | * Prints a dependency notification | |
60 | * @param string $message | |
61 | * @return string | |
62 | */ | |
63 | public function dependency_notification($message) { | |
64 | return html_writer::tag('div', $message, array('class'=>'notification dependencies_enforced')); | |
65 | } | |
785d6603 | 66 | |
ad93ddd5 SH |
67 | /** |
68 | * Displays the details of a backup file | |
69 | * | |
70 | * @param stdClass $details | |
71 | * @param moodle_url $nextstageurl | |
72 | * @return string | |
73 | */ | |
785d6603 SH |
74 | public function backup_details($details, $nextstageurl) { |
75 | $yestick = $this->output->pix_icon('i/tick_green_big', get_string('yes')); | |
76 | $notick = $this->output->pix_icon('i/cross_red_big', get_string('no')); | |
77 | ||
78 | $html = html_writer::start_tag('div', array('class'=>'backup-restore')); | |
79 | ||
80 | $html .= html_writer::start_tag('div', array('class'=>'backup-section')); | |
81 | $html .= $this->output->heading(get_string('backupdetails', 'backup'), 2, array('class'=>'header')); | |
82 | $html .= $this->backup_detail_pair(get_string('backuptype', 'backup'), get_string('backuptype'.$details->type, 'backup')); | |
83 | $html .= $this->backup_detail_pair(get_string('backupformat', 'backup'), get_string('backupformat'.$details->format, 'backup')); | |
84 | $html .= $this->backup_detail_pair(get_string('backupmode', 'backup'), get_string('backupmode'.$details->mode, 'backup')); | |
85 | $html .= $this->backup_detail_pair(get_string('backupdate', 'backup'), userdate($details->backup_date)); | |
30ad8cdd | 86 | $html .= $this->backup_detail_pair(get_string('moodleversion', 'backup'), |
785d6603 SH |
87 | html_writer::tag('span', $details->moodle_release, array('class'=>'moodle_release')). |
88 | html_writer::tag('span', '['.$details->moodle_version.']', array('class'=>'moodle_version sub-detail'))); | |
89 | $html .= $this->backup_detail_pair(get_string('backupversion', 'backup'), | |
90 | html_writer::tag('span', $details->backup_release, array('class'=>'moodle_release')). | |
91 | html_writer::tag('span', '['.$details->backup_version.']', array('class'=>'moodle_version sub-detail'))); | |
92 | $html .= $this->backup_detail_pair(get_string('originalwwwroot', 'backup'), | |
93 | html_writer::tag('span', $details->original_wwwroot, array('class'=>'originalwwwroot')). | |
94 | html_writer::tag('span', '['.$details->original_site_identifier_hash.']', array('class'=>'sitehash sub-detail'))); | |
95 | $html .= html_writer::end_tag('div'); | |
96 | ||
97 | $html .= html_writer::start_tag('div', array('class'=>'backup-section settings-section')); | |
98 | $html .= $this->output->heading(get_string('backupsettings', 'backup'), 2, array('class'=>'header')); | |
99 | foreach ($details->root_settings as $label=>$value) { | |
100 | if ($label == 'filename') continue; | |
573cdf85 | 101 | $html .= $this->backup_detail_pair(get_string('rootsetting'.str_replace('_','',$label), 'backup'), $value?$yestick:$notick); |
785d6603 SH |
102 | } |
103 | $html .= html_writer::end_tag('div'); | |
104 | ||
1b42bc07 DM |
105 | if ($details->type === 'course') { |
106 | $html .= html_writer::start_tag('div', array('class'=>'backup-section')); | |
107 | $html .= $this->output->heading(get_string('backupcoursedetails', 'backup'), 2, array('class'=>'header')); | |
108 | $html .= $this->backup_detail_pair(get_string('coursetitle', 'backup'), $details->course->title); | |
109 | $html .= $this->backup_detail_pair(get_string('courseid', 'backup'), $details->course->courseid); | |
785d6603 | 110 | |
1b42bc07 DM |
111 | $html .= html_writer::start_tag('div', array('class'=>'backup-sub-section')); |
112 | $html .= $this->output->heading(get_string('backupcoursesections', 'backup'), 3, array('class'=>'subheader')); | |
113 | foreach ($details->sections as $key=>$section) { | |
114 | $included = $key.'_included'; | |
115 | $userinfo = $key.'_userinfo'; | |
116 | if ($section->settings[$included] && $section->settings[$userinfo]) { | |
117 | $value = get_string('sectionincanduser','backup'); | |
118 | } else if ($section->settings[$included]) { | |
119 | $value = get_string('sectioninc','backup'); | |
120 | } else { | |
785d6603 SH |
121 | continue; |
122 | } | |
1b42bc07 DM |
123 | $html .= $this->backup_detail_pair(get_string('backupcoursesection', 'backup', $section->title), $value); |
124 | $table = null; | |
125 | foreach ($details->activities as $activitykey=>$activity) { | |
126 | if ($activity->sectionid != $section->sectionid) { | |
127 | continue; | |
128 | } | |
129 | if (empty($table)) { | |
130 | $table = new html_table(); | |
131 | $table->head = array('Module', 'Title', 'Userinfo'); | |
132 | $table->colclasses = array('modulename', 'moduletitle', 'userinfoincluded'); | |
133 | $table->align = array('left','left', 'center'); | |
134 | $table->attributes = array('class'=>'activitytable generaltable'); | |
135 | $table->data = array(); | |
136 | } | |
137 | $name = get_string('pluginname', $activity->modulename); | |
138 | $icon = new pix_icon('icon', $name, $activity->modulename); | |
139 | $table->data[] = array( | |
140 | $this->output->render($icon).' '.$name, | |
141 | $activity->title, | |
142 | ($activity->settings[$activitykey.'_userinfo'])?$yestick:$notick, | |
143 | ); | |
144 | } | |
145 | if (!empty($table)) { | |
146 | $html .= $this->backup_detail_pair(get_string('sectionactivities','backup'), html_writer::table($table)); | |
785d6603 | 147 | } |
30ad8cdd | 148 | |
1b42bc07 DM |
149 | } |
150 | $html .= html_writer::end_tag('div'); | |
151 | $html .= html_writer::end_tag('div'); | |
785d6603 | 152 | } |
785d6603 SH |
153 | |
154 | $html .= $this->output->single_button($nextstageurl, get_string('continue'), 'post'); | |
83a9c866 | 155 | $html .= html_writer::end_tag('div'); |
785d6603 SH |
156 | |
157 | return $html; | |
158 | } | |
159 | ||
ad93ddd5 SH |
160 | /** |
161 | * Displays a course selector for restore | |
162 | * | |
163 | * @param moodle_url $nextstageurl | |
164 | * @param stdClass $details | |
165 | * @param restore_category_search $categories | |
166 | * @param restore_course_search $courses | |
167 | * @param int $currentcourse | |
168 | * @return string | |
169 | */ | |
170 | public function course_selector(moodle_url $nextstageurl, $details, restore_category_search $categories = null, restore_course_search $courses=null, $currentcourse = null) { | |
785d6603 SH |
171 | global $CFG; |
172 | require_once($CFG->dirroot.'/course/lib.php'); | |
173 | ||
174 | $nextstageurl->param('sesskey', sesskey()); | |
175 | ||
176 | $form = html_writer::start_tag('form', array('method'=>'post', 'action'=>$nextstageurl->out_omit_querystring())); | |
177 | foreach ($nextstageurl->params() as $key=>$value) { | |
178 | $form .= html_writer::empty_tag('input', array('type'=>'hidden', 'name'=>$key, 'value'=>$value)); | |
179 | } | |
180 | ||
181 | $html = html_writer::start_tag('div', array('class'=>'backup-course-selector backup-restore')); | |
182 | ||
ad93ddd5 | 183 | if (!empty($categories) && ($categories->get_resultscount() > 0 || $categories->get_search() == '')) { |
39bc4c6f SH |
184 | // New course |
185 | $html .= $form; | |
186 | $html .= html_writer::start_tag('div', array('class'=>'bcs-new-course backup-section')); | |
187 | $html .= $this->output->heading(get_string('restoretonewcourse', 'backup'), 2, array('class'=>'header')); | |
188 | $html .= $this->backup_detail_input(get_string('restoretonewcourse', 'backup'), 'radio', 'target', backup::TARGET_NEW_COURSE, array('checked'=>'checked')); | |
3acc9b81 SH |
189 | //$html .= $this->backup_detail_select(get_string('coursecategory', 'backup'), 'targetid', $categories); |
190 | $html .= $this->backup_detail_pair(get_string('selectacategory', 'backup'), $this->render($categories)); | |
39bc4c6f SH |
191 | $html .= $this->backup_detail_pair('', html_writer::empty_tag('input', array('type'=>'submit', 'value'=>get_string('continue')))); |
192 | $html .= html_writer::end_tag('div'); | |
193 | $html .= html_writer::end_tag('form'); | |
194 | } | |
785d6603 | 195 | |
10618448 SH |
196 | // Current course |
197 | if (!empty($currentcourse)) { | |
198 | $html .= $form; | |
199 | $html .= html_writer::empty_tag('input', array('type'=>'hidden', 'name'=>'targetid', 'value'=>$currentcourse)); | |
200 | $html .= html_writer::start_tag('div', array('class'=>'bcs-current-course backup-section')); | |
201 | $html .= $this->output->heading(get_string('restoretocurrentcourse', 'backup'), 2, array('class'=>'header')); | |
202 | $html .= $this->backup_detail_input(get_string('restoretocurrentcourseadding', 'backup'), 'radio', 'target', backup::TARGET_CURRENT_ADDING, array('checked'=>'checked')); | |
203 | $html .= $this->backup_detail_input(get_string('restoretocurrentcoursedeleting', 'backup'), 'radio', 'target', backup::TARGET_CURRENT_DELETING); | |
204 | $html .= $this->backup_detail_pair('', html_writer::empty_tag('input', array('type'=>'submit', 'value'=>get_string('continue')))); | |
205 | $html .= html_writer::end_tag('div'); | |
206 | $html .= html_writer::end_tag('form'); | |
207 | } | |
208 | ||
ad93ddd5 | 209 | if (!empty($courses) && ($courses->get_resultscount() > 0 || $courses->get_search() == '')) { |
39bc4c6f SH |
210 | // Existing course |
211 | $html .= $form; | |
212 | $html .= html_writer::start_tag('div', array('class'=>'bcs-existing-course backup-section')); | |
213 | $html .= $this->output->heading(get_string('restoretoexistingcourse', 'backup'), 2, array('class'=>'header')); | |
3acc9b81 | 214 | $html .= $this->backup_detail_input(get_string('restoretoexistingcourseadding', 'backup'), 'radio', 'target', backup::TARGET_EXISTING_ADDING, array('checked'=>'checked')); |
39bc4c6f | 215 | $html .= $this->backup_detail_input(get_string('restoretoexistingcoursedeleting', 'backup'), 'radio', 'target', backup::TARGET_EXISTING_DELETING); |
3acc9b81 | 216 | $html .= $this->backup_detail_pair(get_string('selectacourse', 'backup'), $this->render($courses)); |
39bc4c6f SH |
217 | $html .= $this->backup_detail_pair('', html_writer::empty_tag('input', array('type'=>'submit', 'value'=>get_string('continue')))); |
218 | $html .= html_writer::end_tag('div'); | |
219 | $html .= html_writer::end_tag('form'); | |
220 | } | |
785d6603 SH |
221 | |
222 | $html .= html_writer::end_tag('div'); | |
223 | return $html; | |
224 | } | |
225 | ||
ad93ddd5 SH |
226 | /** |
227 | * Displays the import course selector | |
228 | * | |
229 | * @param moodle_url $nextstageurl | |
230 | * @param import_course_search $courses | |
231 | * @return string | |
232 | */ | |
233 | public function import_course_selector(moodle_url $nextstageurl, import_course_search $courses=null) { | |
234 | $html = html_writer::start_tag('div', array('class'=>'import-course-selector backup-restore')); | |
235 | $html .= html_writer::start_tag('form', array('method'=>'post', 'action'=>$nextstageurl->out_omit_querystring())); | |
236 | foreach ($nextstageurl->params() as $key=>$value) { | |
237 | $html .= html_writer::empty_tag('input', array('type'=>'hidden', 'name'=>$key, 'value'=>$value)); | |
238 | } | |
239 | $html .= html_writer::start_tag('div', array('class'=>'ics-existing-course backup-section')); | |
240 | $html .= $this->output->heading(get_string('importdatafrom'), 2, array('class'=>'header')); | |
241 | $html .= $this->backup_detail_input(get_string('importadding', 'backup'), 'radio', 'target', backup::TARGET_CURRENT_ADDING, array('checked'=>'checked'), get_string('importaddingdesc', 'backup')); | |
242 | $html .= $this->backup_detail_input(get_string('importdeleting', 'backup'), 'radio', 'target', backup::TARGET_CURRENT_DELETING, array(), get_string('importdeletingdesc', 'backup')); | |
243 | $html .= $this->backup_detail_pair(get_string('selectacourse', 'backup'), $this->render($courses)); | |
244 | $html .= $this->backup_detail_pair('', html_writer::empty_tag('input', array('type'=>'submit', 'value'=>get_string('continue')))); | |
245 | $html .= html_writer::end_tag('div'); | |
246 | $html .= html_writer::end_tag('form'); | |
247 | $html .= html_writer::end_tag('div'); | |
248 | return $html; | |
249 | } | |
250 | ||
251 | /** | |
252 | * Creates a detailed pairing (key + value) | |
253 | * | |
254 | * @staticvar int $count | |
255 | * @param string $label | |
256 | * @param string $value | |
257 | * @return string | |
258 | */ | |
785d6603 SH |
259 | protected function backup_detail_pair($label, $value) { |
260 | static $count= 0; | |
261 | $count++; | |
262 | $html = html_writer::start_tag('div', array('class'=>'detail-pair')); | |
263 | $html .= html_writer::tag('label', $label, array('class'=>'detail-pair-label', 'for'=>'detail-pair-value-'.$count)); | |
264 | $html .= html_writer::tag('div', $value, array('class'=>'detail-pair-value', 'name'=>'detail-pair-value-'.$count)); | |
265 | $html .= html_writer::end_tag('div'); | |
266 | return $html; | |
267 | } | |
268 | ||
ad93ddd5 SH |
269 | /** |
270 | * Created a detailed pairing with an input | |
271 | * | |
272 | * @param string $label | |
273 | * @param string $type | |
274 | * @param string $name | |
275 | * @param string $value | |
276 | * @param array $attributes | |
277 | * @param string|null $description | |
278 | * @return string | |
279 | */ | |
3acc9b81 SH |
280 | protected function backup_detail_input($label, $type, $name, $value, array $attributes=array(), $description=null) { |
281 | if (!empty ($description)) { | |
282 | $description = html_writer::tag('span', $description, array('class'=>'description')); | |
283 | } else { | |
284 | $description = ''; | |
285 | } | |
286 | return $this->backup_detail_pair($label, html_writer::empty_tag('input', $attributes+array('name'=>$name, 'type'=>$type, 'value'=>$value)).$description); | |
785d6603 SH |
287 | } |
288 | ||
ad93ddd5 SH |
289 | /** |
290 | * Creates a detailed pairing with a select | |
291 | * | |
292 | * @param string $label | |
293 | * @param string $name | |
294 | * @param array $options | |
295 | * @param string $selected | |
296 | * @param bool $nothing | |
297 | * @param array $attributes | |
298 | * @param string|null $description | |
299 | * @return string | |
300 | */ | |
3acc9b81 SH |
301 | protected function backup_detail_select($label, $name, $options, $selected='', $nothing=false, array $attributes=array(), $description=null) { |
302 | if (!empty ($description)) { | |
303 | $description = html_writer::tag('span', $description, array('class'=>'description')); | |
304 | } else { | |
305 | $description = ''; | |
306 | } | |
307 | return $this->backup_detail_pair($label, html_writer::select($options, $name, $selected, false, $attributes).$description); | |
785d6603 SH |
308 | } |
309 | ||
ad93ddd5 SH |
310 | /** |
311 | * Displays precheck notices | |
312 | * | |
313 | * @param array $results | |
314 | * @return string | |
315 | */ | |
785d6603 SH |
316 | public function precheck_notices($results) { |
317 | $output = html_writer::start_tag('div', array('class'=>'restore-precheck-notices')); | |
318 | if (array_key_exists('errors', $results)) { | |
319 | foreach ($results['errors'] as $error) { | |
320 | $output .= $this->output->notification($error); | |
321 | } | |
322 | } | |
323 | if (array_key_exists('warnings', $results)) { | |
324 | foreach ($results['warnings'] as $warning) { | |
325 | $output .= $this->output->notification($warning, 'notifywarning notifyproblem'); | |
326 | } | |
327 | } | |
328 | return $output.html_writer::end_tag('div'); | |
329 | } | |
330 | ||
ad93ddd5 SH |
331 | /** |
332 | * Displays substage buttons | |
333 | * | |
334 | * @param bool $haserrors | |
335 | * @return string | |
336 | */ | |
3acc9b81 SH |
337 | public function substage_buttons($haserrors) { |
338 | $output = html_writer::start_tag('div', array('continuebutton')); | |
339 | if (!$haserrors) { | |
340 | $output .= html_writer::empty_tag('input', array('type'=>'submit', 'value'=>get_string('continue'))); | |
341 | } | |
342 | $output .= html_writer::empty_tag('input', array('type'=>'submit', 'name'=>'cancel', 'value'=>get_string('cancel'))); | |
343 | $output .= html_writer::end_tag('div'); | |
344 | return $output; | |
345 | } | |
346 | ||
ad93ddd5 SH |
347 | /** |
348 | * Displays a role mapping interface | |
349 | * | |
350 | * @param array $rolemappings | |
351 | * @param array $roles | |
352 | * @return string | |
353 | */ | |
3acc9b81 SH |
354 | public function role_mappings($rolemappings, $roles) { |
355 | $roles[0] = get_string('none'); | |
356 | $output = html_writer::start_tag('div', array('class'=>'restore-rolemappings')); | |
357 | $output .= $this->output->heading(get_string('restorerolemappings', 'backup'), 2); | |
358 | foreach ($rolemappings as $id=>$mapping) { | |
359 | $label = $mapping->name; | |
360 | $name = 'mapping'.$id; | |
361 | $selected = $mapping->targetroleid; | |
362 | $output .= $this->backup_detail_select($label, $name, $roles, $mapping->targetroleid, false, array(), $mapping->description); | |
363 | } | |
364 | $output .= html_writer::end_tag('div'); | |
365 | return $output; | |
366 | } | |
367 | ||
ad93ddd5 SH |
368 | /** |
369 | * Displays a continue button | |
370 | * | |
371 | * @param string|moodle_url $url | |
372 | * @param string $method | |
373 | * @return string | |
374 | */ | |
39bc4c6f | 375 | public function continue_button($url, $method='post') { |
785d6603 SH |
376 | if (!($url instanceof moodle_url)) { |
377 | $url = new moodle_url($url); | |
378 | } | |
39bc4c6f SH |
379 | if ($method != 'post') { |
380 | $method = 'get'; | |
381 | } | |
785d6603 | 382 | $url->param('sesskey', sesskey()); |
39bc4c6f | 383 | $button = new single_button($url, get_string('continue'), $method); |
785d6603 SH |
384 | $button->class = 'continuebutton'; |
385 | return $this->render($button); | |
386 | } | |
72f38ce7 DC |
387 | /** |
388 | * Print a backup files tree | |
72f38ce7 DC |
389 | * @param array $options |
390 | * @return string | |
391 | */ | |
30ad8cdd | 392 | public function backup_files_viewer(array $options = null) { |
6aef525d DC |
393 | $files = new backup_files_viewer($options); |
394 | return $this->render($files); | |
72f38ce7 DC |
395 | } |
396 | ||
ad93ddd5 SH |
397 | /** |
398 | * Displays a backup files viewer | |
399 | * | |
400 | * @global stdClass $USER | |
401 | * @param backup_files_viewer $tree | |
402 | * @return string | |
403 | */ | |
6aef525d DC |
404 | public function render_backup_files_viewer(backup_files_viewer $viewer) { |
405 | global $CFG; | |
406 | $files = $viewer->files; | |
72f38ce7 | 407 | |
6aef525d | 408 | $table = new html_table(); |
bac233d3 | 409 | $table->attributes['class'] = 'backup-files-table generaltable'; |
6aef525d | 410 | $table->head = array(get_string('filename', 'backup'), get_string('time'), get_string('size'), get_string('download'), get_string('restore')); |
6aef525d DC |
411 | $table->width = '100%'; |
412 | $table->data = array(); | |
413 | ||
414 | foreach ($files as $file) { | |
415 | if ($file->is_directory()) { | |
416 | continue; | |
72f38ce7 | 417 | } |
6aef525d DC |
418 | $fileurl = moodle_url::make_pluginfile_url($file->get_contextid(), $file->get_component(), $file->get_filearea(), null, $file->get_filepath(), $file->get_filename(), true); |
419 | $params = array(); | |
420 | $params['action'] = 'choosebackupfile'; | |
421 | $params['filename'] = $file->get_filename(); | |
422 | $params['filepath'] = $file->get_filepath(); | |
423 | $params['component'] = $file->get_component(); | |
424 | $params['filearea'] = $file->get_filearea(); | |
425 | $params['filecontextid'] = $file->get_contextid(); | |
426 | $params['contextid'] = $viewer->currentcontext->id; | |
427 | $params['itemid'] = $file->get_itemid(); | |
428 | $restoreurl = new moodle_url('/backup/restorefile.php', $params); | |
429 | $table->data[] = array( | |
430 | $file->get_filename(), | |
431 | userdate($file->get_timemodified()), | |
432 | display_size($file->get_filesize()), | |
433 | html_writer::link($fileurl, get_string('download')), | |
434 | html_writer::link($restoreurl, get_string('restore')), | |
435 | ); | |
72f38ce7 | 436 | } |
6aef525d DC |
437 | |
438 | $html = html_writer::table($table); | |
1a22a422 | 439 | $html .= $this->output->single_button(new moodle_url('/backup/backupfilesedit.php', array('currentcontext'=>$viewer->currentcontext->id, 'contextid'=>$viewer->filecontext->id, 'filearea'=>$viewer->filearea, 'component'=>$viewer->component, 'returnurl'=>$this->page->url->out())), get_string('managefiles', 'backup'), 'post'); |
6aef525d | 440 | |
72f38ce7 DC |
441 | return $html; |
442 | } | |
3acc9b81 | 443 | |
ad93ddd5 SH |
444 | /** |
445 | * Renders a restore course search object | |
446 | * | |
447 | * @param restore_course_search $component | |
448 | * @return string | |
449 | */ | |
3acc9b81 SH |
450 | public function render_restore_course_search(restore_course_search $component) { |
451 | $url = $component->get_url(); | |
452 | ||
453 | $output = html_writer::start_tag('div', array('class' => 'restore-course-search')); | |
454 | if ($component->get_totalcount() === 0) { | |
455 | $output .= $this->output->notification(get_string('nomatchingcourses', 'backup')); | |
456 | $output .= html_writer::end_tag('div'); | |
457 | return $output; | |
458 | } | |
459 | ||
460 | $output .= html_writer::tag('div', get_string('totalcoursesearchresults', 'backup', $component->get_totalcount()), array('class'=>'rcs-totalresults')); | |
461 | ||
462 | $output .= html_writer::start_tag('div', array('class' => 'rcs-results')); | |
463 | if ($component->get_totalpages()>1) { | |
464 | $pagingbar = new paging_bar($component->get_totalcount(), $component->get_page(), $component->get_pagelimit(), new moodle_url($url, array('searchcourses'=>1)), restore_course_search::$VAR_PAGE); | |
465 | $output .= $this->output->render($pagingbar); | |
466 | } | |
467 | ||
468 | $table = new html_table(); | |
469 | $table->head = array('', get_string('shortname'), get_string('fullname')); | |
470 | $table->data = array(); | |
471 | foreach ($component->get_results() as $course) { | |
472 | $row = new html_table_row(); | |
473 | $row->attributes['class'] = 'rcs-course'; | |
474 | if (!$course->visible) { | |
475 | $row->attributes['class'] .= ' dimmed'; | |
476 | } | |
477 | $row->cells = array( | |
478 | html_writer::empty_tag('input', array('type'=>'radio', 'name'=>'targetid', 'value'=>$course->id)), | |
479 | $course->shortname, | |
480 | $course->fullname | |
481 | ); | |
482 | $table->data[] = $row; | |
483 | } | |
484 | $output .= html_writer::table($table); | |
485 | if (isset($pagingbar)) { | |
486 | $output .= $this->output->render($pagingbar); | |
487 | } | |
488 | $output .= html_writer::end_tag('div'); | |
489 | ||
490 | $output .= html_writer::start_tag('div', array('class'=>'rcs-search')); | |
491 | $output .= html_writer::empty_tag('input', array('type'=>'text', 'name'=>restore_course_search::$VAR_SEARCH, 'value'=>$component->get_search())); | |
492 | $output .= html_writer::empty_tag('input', array('type'=>'submit', 'name'=>'searchcourses', 'value'=>get_string('search'))); | |
493 | $output .= html_writer::end_tag('div'); | |
30ad8cdd | 494 | |
3acc9b81 SH |
495 | $output .= html_writer::end_tag('div'); |
496 | return $output; | |
497 | } | |
498 | ||
ad93ddd5 SH |
499 | /** |
500 | * Renders an import course search object | |
501 | * | |
502 | * @param import_course_search $component | |
503 | * @return string | |
504 | */ | |
505 | public function render_import_course_search(import_course_search $component) { | |
506 | $url = $component->get_url(); | |
507 | ||
508 | $output = html_writer::start_tag('div', array('class' => 'import-course-search')); | |
509 | if ($component->get_totalcount() === 0) { | |
510 | $output .= $this->output->notification(get_string('nomatchingcourses', 'backup')); | |
511 | $output .= html_writer::end_tag('div'); | |
512 | return $output; | |
513 | } | |
514 | ||
515 | $output .= html_writer::tag('div', get_string('totalcoursesearchresults', 'backup', $component->get_totalcount()), array('class'=>'ics-totalresults')); | |
516 | ||
517 | $output .= html_writer::start_tag('div', array('class' => 'ics-results')); | |
518 | if ($component->get_totalpages()>1) { | |
519 | $pagingbar = new paging_bar($component->get_totalcount(), $component->get_page(), $component->get_pagelimit(), new moodle_url($url, array('searchcourses'=>1)), restore_course_search::$VAR_PAGE); | |
520 | $output .= $this->output->render($pagingbar); | |
521 | } | |
522 | ||
523 | $table = new html_table(); | |
524 | $table->head = array('', get_string('shortname'), get_string('fullname')); | |
525 | $table->data = array(); | |
526 | foreach ($component->get_results() as $course) { | |
527 | $row = new html_table_row(); | |
528 | $row->attributes['class'] = 'ics-course'; | |
529 | if (!$course->visible) { | |
530 | $row->attributes['class'] .= ' dimmed'; | |
531 | } | |
532 | $row->cells = array( | |
533 | html_writer::empty_tag('input', array('type'=>'radio', 'name'=>'importid', 'value'=>$course->id)), | |
534 | $course->shortname, | |
535 | $course->fullname | |
536 | ); | |
537 | $table->data[] = $row; | |
538 | } | |
539 | $output .= html_writer::table($table); | |
540 | if (isset($pagingbar)) { | |
541 | $output .= $this->output->render($pagingbar); | |
542 | } | |
543 | $output .= html_writer::end_tag('div'); | |
544 | ||
545 | $output .= html_writer::start_tag('div', array('class'=>'ics-search')); | |
546 | $output .= html_writer::empty_tag('input', array('type'=>'text', 'name'=>restore_course_search::$VAR_SEARCH, 'value'=>$component->get_search())); | |
547 | $output .= html_writer::empty_tag('input', array('type'=>'submit', 'name'=>'searchcourses', 'value'=>get_string('search'))); | |
548 | $output .= html_writer::end_tag('div'); | |
549 | ||
550 | $output .= html_writer::end_tag('div'); | |
551 | return $output; | |
552 | } | |
553 | ||
554 | /** | |
555 | * Renders a restore category search object | |
6aef525d | 556 | * |
ad93ddd5 SH |
557 | * @param restore_category_search $component |
558 | * @return string | |
559 | */ | |
3acc9b81 SH |
560 | public function render_restore_category_search(restore_category_search $component) { |
561 | $url = $component->get_url(); | |
562 | ||
563 | $output = html_writer::start_tag('div', array('class' => 'restore-course-search')); | |
564 | if ($component->get_totalcount() === 0) { | |
565 | $output .= $this->output->notification(get_string('nomatchingcourses', 'backup')); | |
566 | $output .= html_writer::end_tag('div'); | |
567 | return $output; | |
568 | } | |
569 | ||
570 | $output .= html_writer::tag('div', get_string('totalcategorysearchresults', 'backup', $component->get_totalcount()), array('class'=>'rcs-totalresults')); | |
571 | ||
572 | $output .= html_writer::start_tag('div', array('class' => 'rcs-results')); | |
573 | if ($component->get_totalpages()>1) { | |
574 | $pagingbar = new paging_bar($component->get_totalcount(), $component->get_page(), $component->get_pagelimit(), new moodle_url($url, array('searchcourses'=>1)), restore_category_search::$VAR_PAGE); | |
575 | $output .= $this->output->render($pagingbar); | |
576 | } | |
577 | ||
578 | $table = new html_table(); | |
579 | $table->head = array('', get_string('name'), get_string('description')); | |
580 | $table->data = array(); | |
581 | foreach ($component->get_results() as $category) { | |
582 | $row = new html_table_row(); | |
583 | $row->attributes['class'] = 'rcs-course'; | |
584 | if (!$category->visible) { | |
585 | $row->attributes['class'] .= ' dimmed'; | |
586 | } | |
587 | $row->cells = array( | |
588 | html_writer::empty_tag('input', array('type'=>'radio', 'name'=>'targetid', 'value'=>$category->id)), | |
589 | $category->name, | |
367a75fa | 590 | format_text($category->description, $category->descriptionformat, array('overflowdiv'=>true)) |
3acc9b81 SH |
591 | ); |
592 | $table->data[] = $row; | |
593 | } | |
594 | $output .= html_writer::table($table); | |
595 | if (isset($pagingbar)) { | |
596 | $output .= $this->output->render($pagingbar); | |
597 | } | |
598 | $output .= html_writer::end_tag('div'); | |
599 | ||
600 | $output .= html_writer::start_tag('div', array('class'=>'rcs-search')); | |
601 | $output .= html_writer::empty_tag('input', array('type'=>'text', 'name'=>restore_category_search::$VAR_SEARCH, 'value'=>$component->get_search())); | |
602 | $output .= html_writer::empty_tag('input', array('type'=>'submit', 'name'=>'searchcourses', 'value'=>get_string('search'))); | |
603 | $output .= html_writer::end_tag('div'); | |
604 | ||
605 | $output .= html_writer::end_tag('div'); | |
606 | return $output; | |
607 | } | |
d94bb343 SH |
608 | |
609 | public function invalid_format($format) { | |
610 | $html = html_writer::start_tag('div', array('class'=>'invalidformat')); | |
611 | $html .= html_writer::tag('h2', get_string('errorinvalidformat', 'backup'), array('class'=>'notifyproblem')); | |
612 | if ($format == 'moodle1') { | |
613 | // Moodle 1.x backups | |
f9bbe3c9 SH |
614 | $icon = $this->output->help_icon('errormoodle1format', 'backup'); |
615 | $message = get_string('errormoodle1formatdesc', 'backup').' '.$icon; | |
616 | ||
d94bb343 SH |
617 | } else { |
618 | // Totally unknown format | |
f9bbe3c9 | 619 | $message = get_string('errorinvalidformatdesc', 'backup'); |
d94bb343 | 620 | } |
f9bbe3c9 | 621 | $html .= html_writer::tag('div', $message, array('class'=>'notifyproblem')); |
d94bb343 SH |
622 | $html .= html_writer::end_tag('div'); |
623 | return $html; | |
624 | } | |
72f38ce7 | 625 | } |
6aef525d | 626 | |
72f38ce7 DC |
627 | /** |
628 | * Data structure representing backup files viewer | |
629 | * | |
630 | * @copyright 2010 Dongsheng Cai | |
631 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | |
632 | * @since Moodle 2.0 | |
633 | */ | |
634 | class backup_files_viewer implements renderable { | |
6aef525d DC |
635 | public $files; |
636 | public $filecontext; | |
637 | public $component; | |
638 | public $filearea; | |
639 | public $currentcontext; | |
72f38ce7 DC |
640 | |
641 | /** | |
642 | * Constructor of backup_files_viewer class | |
72f38ce7 DC |
643 | * @param array $options |
644 | */ | |
30ad8cdd DC |
645 | public function __construct(array $options = null) { |
646 | global $CFG, $USER; | |
6aef525d DC |
647 | $fs = get_file_storage(); |
648 | $this->currentcontext = $options['currentcontext']; | |
649 | $this->filecontext = $options['filecontext']; | |
650 | $this->component = $options['component']; | |
651 | $this->filearea = $options['filearea']; | |
652 | $files = $fs->get_area_files($this->filecontext->id, $this->component, $this->filearea, false, 'timecreated'); | |
653 | $this->files = array_reverse($files); | |
72f38ce7 | 654 | } |
30ad8cdd | 655 | } |