The core_backup_renderer does not need the full backup information any more
[moodle.git] / backup / util / ui / renderer.php
CommitLineData
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 */
37class 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).'&nbsp;'.$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
3a076721 164 * @param bool $wholecourse true if we are restoring whole course (as with backup::TYPE_1COURSE), false otherwise
ad93ddd5
SH
165 * @param restore_category_search $categories
166 * @param restore_course_search $courses
167 * @param int $currentcourse
168 * @return string
169 */
3a076721 170 public function course_selector(moodle_url $nextstageurl, $wholecourse = true, 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
33d34b4b 181 $hasrestoreoption = false;
785d6603 182
33d34b4b 183 $html = html_writer::start_tag('div', array('class'=>'backup-course-selector backup-restore'));
3a076721 184 if ($wholecourse && !empty($categories) && ($categories->get_count() > 0 || $categories->get_search())) {
39bc4c6f 185 // New course
33d34b4b 186 $hasrestoreoption = true;
39bc4c6f
SH
187 $html .= $form;
188 $html .= html_writer::start_tag('div', array('class'=>'bcs-new-course backup-section'));
189 $html .= $this->output->heading(get_string('restoretonewcourse', 'backup'), 2, array('class'=>'header'));
190 $html .= $this->backup_detail_input(get_string('restoretonewcourse', 'backup'), 'radio', 'target', backup::TARGET_NEW_COURSE, array('checked'=>'checked'));
3acc9b81 191 $html .= $this->backup_detail_pair(get_string('selectacategory', 'backup'), $this->render($categories));
39bc4c6f
SH
192 $html .= $this->backup_detail_pair('', html_writer::empty_tag('input', array('type'=>'submit', 'value'=>get_string('continue'))));
193 $html .= html_writer::end_tag('div');
194 $html .= html_writer::end_tag('form');
195 }
785d6603 196
3a076721 197 if ($wholecourse && !empty($currentcourse)) {
33d34b4b
SH
198 // Current course
199 $hasrestoreoption = true;
10618448
SH
200 $html .= $form;
201 $html .= html_writer::empty_tag('input', array('type'=>'hidden', 'name'=>'targetid', 'value'=>$currentcourse));
202 $html .= html_writer::start_tag('div', array('class'=>'bcs-current-course backup-section'));
203 $html .= $this->output->heading(get_string('restoretocurrentcourse', 'backup'), 2, array('class'=>'header'));
204 $html .= $this->backup_detail_input(get_string('restoretocurrentcourseadding', 'backup'), 'radio', 'target', backup::TARGET_CURRENT_ADDING, array('checked'=>'checked'));
205 $html .= $this->backup_detail_input(get_string('restoretocurrentcoursedeleting', 'backup'), 'radio', 'target', backup::TARGET_CURRENT_DELETING);
206 $html .= $this->backup_detail_pair('', html_writer::empty_tag('input', array('type'=>'submit', 'value'=>get_string('continue'))));
207 $html .= html_writer::end_tag('div');
208 $html .= html_writer::end_tag('form');
209 }
210
33d34b4b 211 if (!empty($courses) && ($courses->get_count() > 0 || $courses->get_search())) {
39bc4c6f 212 // Existing course
33d34b4b 213 $hasrestoreoption = true;
39bc4c6f
SH
214 $html .= $form;
215 $html .= html_writer::start_tag('div', array('class'=>'bcs-existing-course backup-section'));
216 $html .= $this->output->heading(get_string('restoretoexistingcourse', 'backup'), 2, array('class'=>'header'));
3a076721 217 if ($wholecourse) {
165b7bd9
EL
218 $html .= $this->backup_detail_input(get_string('restoretoexistingcourseadding', 'backup'), 'radio', 'target', backup::TARGET_EXISTING_ADDING, array('checked'=>'checked'));
219 $html .= $this->backup_detail_input(get_string('restoretoexistingcoursedeleting', 'backup'), 'radio', 'target', backup::TARGET_EXISTING_DELETING);
220 $html .= $this->backup_detail_pair(get_string('selectacourse', 'backup'), $this->render($courses));
221 } else {
222 // We only allow restore adding to existing for now. Enforce it here.
223 $html .= html_writer::empty_tag('input', array('type'=>'hidden', 'name'=>'target', 'value'=>backup::TARGET_EXISTING_ADDING));
224 $courses->invalidate_results(); // Clean list of courses
225 $courses->set_include_currentcourse(); // Show current course in the list
226 $html .= $this->backup_detail_pair(get_string('selectacourse', 'backup'), $this->render($courses));
227 }
39bc4c6f
SH
228 $html .= $this->backup_detail_pair('', html_writer::empty_tag('input', array('type'=>'submit', 'value'=>get_string('continue'))));
229 $html .= html_writer::end_tag('div');
230 $html .= html_writer::end_tag('form');
231 }
785d6603 232
33d34b4b
SH
233 if (!$hasrestoreoption) {
234 echo $this->output->notification(get_string('norestoreoptions','backup'));
235 }
236
785d6603
SH
237 $html .= html_writer::end_tag('div');
238 return $html;
239 }
240
ad93ddd5
SH
241 /**
242 * Displays the import course selector
243 *
244 * @param moodle_url $nextstageurl
245 * @param import_course_search $courses
246 * @return string
247 */
248 public function import_course_selector(moodle_url $nextstageurl, import_course_search $courses=null) {
249 $html = html_writer::start_tag('div', array('class'=>'import-course-selector backup-restore'));
250 $html .= html_writer::start_tag('form', array('method'=>'post', 'action'=>$nextstageurl->out_omit_querystring()));
251 foreach ($nextstageurl->params() as $key=>$value) {
252 $html .= html_writer::empty_tag('input', array('type'=>'hidden', 'name'=>$key, 'value'=>$value));
253 }
dc2abd40
EL
254 // We only allow import adding for now. Enforce it here.
255 $html .= html_writer::empty_tag('input', array('type'=>'hidden', 'name'=>'target', 'value'=>backup::TARGET_CURRENT_ADDING));
ad93ddd5
SH
256 $html .= html_writer::start_tag('div', array('class'=>'ics-existing-course backup-section'));
257 $html .= $this->output->heading(get_string('importdatafrom'), 2, array('class'=>'header'));
ad93ddd5
SH
258 $html .= $this->backup_detail_pair(get_string('selectacourse', 'backup'), $this->render($courses));
259 $html .= $this->backup_detail_pair('', html_writer::empty_tag('input', array('type'=>'submit', 'value'=>get_string('continue'))));
260 $html .= html_writer::end_tag('div');
261 $html .= html_writer::end_tag('form');
262 $html .= html_writer::end_tag('div');
263 return $html;
264 }
265
266 /**
267 * Creates a detailed pairing (key + value)
268 *
269 * @staticvar int $count
270 * @param string $label
271 * @param string $value
272 * @return string
273 */
785d6603
SH
274 protected function backup_detail_pair($label, $value) {
275 static $count= 0;
276 $count++;
277 $html = html_writer::start_tag('div', array('class'=>'detail-pair'));
278 $html .= html_writer::tag('label', $label, array('class'=>'detail-pair-label', 'for'=>'detail-pair-value-'.$count));
279 $html .= html_writer::tag('div', $value, array('class'=>'detail-pair-value', 'name'=>'detail-pair-value-'.$count));
280 $html .= html_writer::end_tag('div');
281 return $html;
282 }
283
ad93ddd5
SH
284 /**
285 * Created a detailed pairing with an input
286 *
287 * @param string $label
288 * @param string $type
289 * @param string $name
290 * @param string $value
291 * @param array $attributes
292 * @param string|null $description
293 * @return string
294 */
3acc9b81
SH
295 protected function backup_detail_input($label, $type, $name, $value, array $attributes=array(), $description=null) {
296 if (!empty ($description)) {
297 $description = html_writer::tag('span', $description, array('class'=>'description'));
298 } else {
299 $description = '';
300 }
301 return $this->backup_detail_pair($label, html_writer::empty_tag('input', $attributes+array('name'=>$name, 'type'=>$type, 'value'=>$value)).$description);
785d6603
SH
302 }
303
ad93ddd5
SH
304 /**
305 * Creates a detailed pairing with a select
306 *
307 * @param string $label
308 * @param string $name
309 * @param array $options
310 * @param string $selected
311 * @param bool $nothing
312 * @param array $attributes
313 * @param string|null $description
314 * @return string
315 */
3acc9b81
SH
316 protected function backup_detail_select($label, $name, $options, $selected='', $nothing=false, array $attributes=array(), $description=null) {
317 if (!empty ($description)) {
318 $description = html_writer::tag('span', $description, array('class'=>'description'));
319 } else {
320 $description = '';
321 }
322 return $this->backup_detail_pair($label, html_writer::select($options, $name, $selected, false, $attributes).$description);
785d6603
SH
323 }
324
ad93ddd5
SH
325 /**
326 * Displays precheck notices
327 *
328 * @param array $results
329 * @return string
330 */
785d6603
SH
331 public function precheck_notices($results) {
332 $output = html_writer::start_tag('div', array('class'=>'restore-precheck-notices'));
333 if (array_key_exists('errors', $results)) {
334 foreach ($results['errors'] as $error) {
335 $output .= $this->output->notification($error);
336 }
337 }
338 if (array_key_exists('warnings', $results)) {
339 foreach ($results['warnings'] as $warning) {
340 $output .= $this->output->notification($warning, 'notifywarning notifyproblem');
341 }
342 }
343 return $output.html_writer::end_tag('div');
344 }
345
ad93ddd5
SH
346 /**
347 * Displays substage buttons
348 *
349 * @param bool $haserrors
350 * @return string
351 */
3acc9b81
SH
352 public function substage_buttons($haserrors) {
353 $output = html_writer::start_tag('div', array('continuebutton'));
354 if (!$haserrors) {
355 $output .= html_writer::empty_tag('input', array('type'=>'submit', 'value'=>get_string('continue')));
356 }
357 $output .= html_writer::empty_tag('input', array('type'=>'submit', 'name'=>'cancel', 'value'=>get_string('cancel')));
358 $output .= html_writer::end_tag('div');
359 return $output;
360 }
361
ad93ddd5
SH
362 /**
363 * Displays a role mapping interface
364 *
365 * @param array $rolemappings
366 * @param array $roles
367 * @return string
368 */
3acc9b81
SH
369 public function role_mappings($rolemappings, $roles) {
370 $roles[0] = get_string('none');
371 $output = html_writer::start_tag('div', array('class'=>'restore-rolemappings'));
372 $output .= $this->output->heading(get_string('restorerolemappings', 'backup'), 2);
373 foreach ($rolemappings as $id=>$mapping) {
374 $label = $mapping->name;
375 $name = 'mapping'.$id;
376 $selected = $mapping->targetroleid;
377 $output .= $this->backup_detail_select($label, $name, $roles, $mapping->targetroleid, false, array(), $mapping->description);
378 }
379 $output .= html_writer::end_tag('div');
380 return $output;
381 }
382
ad93ddd5
SH
383 /**
384 * Displays a continue button
385 *
386 * @param string|moodle_url $url
387 * @param string $method
388 * @return string
389 */
39bc4c6f 390 public function continue_button($url, $method='post') {
785d6603
SH
391 if (!($url instanceof moodle_url)) {
392 $url = new moodle_url($url);
393 }
39bc4c6f
SH
394 if ($method != 'post') {
395 $method = 'get';
396 }
785d6603 397 $url->param('sesskey', sesskey());
39bc4c6f 398 $button = new single_button($url, get_string('continue'), $method);
785d6603
SH
399 $button->class = 'continuebutton';
400 return $this->render($button);
401 }
72f38ce7
DC
402 /**
403 * Print a backup files tree
72f38ce7
DC
404 * @param array $options
405 * @return string
406 */
30ad8cdd 407 public function backup_files_viewer(array $options = null) {
6aef525d
DC
408 $files = new backup_files_viewer($options);
409 return $this->render($files);
72f38ce7
DC
410 }
411
ad93ddd5
SH
412 /**
413 * Displays a backup files viewer
414 *
415 * @global stdClass $USER
416 * @param backup_files_viewer $tree
417 * @return string
418 */
6aef525d
DC
419 public function render_backup_files_viewer(backup_files_viewer $viewer) {
420 global $CFG;
421 $files = $viewer->files;
72f38ce7 422
6aef525d 423 $table = new html_table();
bac233d3 424 $table->attributes['class'] = 'backup-files-table generaltable';
6aef525d 425 $table->head = array(get_string('filename', 'backup'), get_string('time'), get_string('size'), get_string('download'), get_string('restore'));
6aef525d
DC
426 $table->width = '100%';
427 $table->data = array();
428
429 foreach ($files as $file) {
430 if ($file->is_directory()) {
431 continue;
72f38ce7 432 }
6aef525d
DC
433 $fileurl = moodle_url::make_pluginfile_url($file->get_contextid(), $file->get_component(), $file->get_filearea(), null, $file->get_filepath(), $file->get_filename(), true);
434 $params = array();
435 $params['action'] = 'choosebackupfile';
436 $params['filename'] = $file->get_filename();
437 $params['filepath'] = $file->get_filepath();
438 $params['component'] = $file->get_component();
439 $params['filearea'] = $file->get_filearea();
440 $params['filecontextid'] = $file->get_contextid();
441 $params['contextid'] = $viewer->currentcontext->id;
442 $params['itemid'] = $file->get_itemid();
443 $restoreurl = new moodle_url('/backup/restorefile.php', $params);
444 $table->data[] = array(
445 $file->get_filename(),
446 userdate($file->get_timemodified()),
447 display_size($file->get_filesize()),
448 html_writer::link($fileurl, get_string('download')),
449 html_writer::link($restoreurl, get_string('restore')),
450 );
72f38ce7 451 }
6aef525d
DC
452
453 $html = html_writer::table($table);
1a22a422 454 $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 455
72f38ce7
DC
456 return $html;
457 }
3acc9b81 458
ad93ddd5
SH
459 /**
460 * Renders a restore course search object
461 *
462 * @param restore_course_search $component
463 * @return string
464 */
3acc9b81
SH
465 public function render_restore_course_search(restore_course_search $component) {
466 $url = $component->get_url();
467
468 $output = html_writer::start_tag('div', array('class' => 'restore-course-search'));
3acc9b81 469 $output .= html_writer::start_tag('div', array('class' => 'rcs-results'));
3acc9b81
SH
470
471 $table = new html_table();
29cbe431 472 $table->head = array('', get_string('shortnamecourse'), get_string('fullnamecourse'));
3acc9b81 473 $table->data = array();
33d34b4b
SH
474 if ($component->get_count() !== 0) {
475 foreach ($component->get_results() as $course) {
476 $row = new html_table_row();
477 $row->attributes['class'] = 'rcs-course';
478 if (!$course->visible) {
479 $row->attributes['class'] .= ' dimmed';
480 }
481 $row->cells = array(
482 html_writer::empty_tag('input', array('type'=>'radio', 'name'=>'targetid', 'value'=>$course->id)),
483 $course->shortname,
484 $course->fullname
485 );
486 $table->data[] = $row;
3acc9b81 487 }
33d34b4b
SH
488 if ($component->has_more_results()) {
489 $cell = new html_table_cell(get_string('moreresults', 'backup'));
490 $cell->colspan = 3;
491 $cell->attributes['class'] = 'notifyproblem';
492 $row = new html_table_row(array($cell));
493 $row->attributes['class'] = 'rcs-course';
494 $table->data[] = $row;
495 }
496 } else {
497 $cell = new html_table_cell(get_string('nomatchingcourses', 'backup'));
498 $cell->colspan = 3;
499 $cell->attributes['class'] = 'notifyproblem';
500 $row = new html_table_row(array($cell));
501 $row->attributes['class'] = 'rcs-course';
3acc9b81
SH
502 $table->data[] = $row;
503 }
504 $output .= html_writer::table($table);
3acc9b81
SH
505 $output .= html_writer::end_tag('div');
506
507 $output .= html_writer::start_tag('div', array('class'=>'rcs-search'));
508 $output .= html_writer::empty_tag('input', array('type'=>'text', 'name'=>restore_course_search::$VAR_SEARCH, 'value'=>$component->get_search()));
509 $output .= html_writer::empty_tag('input', array('type'=>'submit', 'name'=>'searchcourses', 'value'=>get_string('search')));
510 $output .= html_writer::end_tag('div');
30ad8cdd 511
3acc9b81
SH
512 $output .= html_writer::end_tag('div');
513 return $output;
514 }
515
ad93ddd5
SH
516 /**
517 * Renders an import course search object
518 *
519 * @param import_course_search $component
520 * @return string
521 */
522 public function render_import_course_search(import_course_search $component) {
523 $url = $component->get_url();
524
525 $output = html_writer::start_tag('div', array('class' => 'import-course-search'));
33d34b4b 526 if ($component->get_count() === 0) {
ad93ddd5
SH
527 $output .= $this->output->notification(get_string('nomatchingcourses', 'backup'));
528 $output .= html_writer::end_tag('div');
529 return $output;
530 }
531
33d34b4b 532 $output .= html_writer::tag('div', get_string('totalcoursesearchresults', 'backup', $component->get_count()), array('class'=>'ics-totalresults'));
ad93ddd5
SH
533
534 $output .= html_writer::start_tag('div', array('class' => 'ics-results'));
ad93ddd5
SH
535
536 $table = new html_table();
29cbe431 537 $table->head = array('', get_string('shortnamecourse'), get_string('fullnamecourse'));
ad93ddd5
SH
538 $table->data = array();
539 foreach ($component->get_results() as $course) {
540 $row = new html_table_row();
541 $row->attributes['class'] = 'ics-course';
542 if (!$course->visible) {
543 $row->attributes['class'] .= ' dimmed';
544 }
545 $row->cells = array(
546 html_writer::empty_tag('input', array('type'=>'radio', 'name'=>'importid', 'value'=>$course->id)),
547 $course->shortname,
548 $course->fullname
549 );
550 $table->data[] = $row;
551 }
552 $output .= html_writer::table($table);
ad93ddd5
SH
553 $output .= html_writer::end_tag('div');
554
555 $output .= html_writer::start_tag('div', array('class'=>'ics-search'));
556 $output .= html_writer::empty_tag('input', array('type'=>'text', 'name'=>restore_course_search::$VAR_SEARCH, 'value'=>$component->get_search()));
557 $output .= html_writer::empty_tag('input', array('type'=>'submit', 'name'=>'searchcourses', 'value'=>get_string('search')));
558 $output .= html_writer::end_tag('div');
559
560 $output .= html_writer::end_tag('div');
561 return $output;
562 }
563
564 /**
565 * Renders a restore category search object
6aef525d 566 *
ad93ddd5
SH
567 * @param restore_category_search $component
568 * @return string
569 */
3acc9b81
SH
570 public function render_restore_category_search(restore_category_search $component) {
571 $url = $component->get_url();
572
573 $output = html_writer::start_tag('div', array('class' => 'restore-course-search'));
3acc9b81 574 $output .= html_writer::start_tag('div', array('class' => 'rcs-results'));
3acc9b81
SH
575
576 $table = new html_table();
577 $table->head = array('', get_string('name'), get_string('description'));
578 $table->data = array();
33d34b4b
SH
579
580 if ($component->get_count() !== 0) {
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,
590 format_text($category->description, $category->descriptionformat, array('overflowdiv'=>true))
591 );
592 $table->data[] = $row;
3acc9b81 593 }
33d34b4b
SH
594 if ($component->has_more_results()) {
595 $cell = new html_table_cell(get_string('moreresults', 'backup'));
596 $cell->attributes['class'] = 'notifyproblem';
597 $cell->colspan = 3;
598 $row = new html_table_row(array($cell));
599 $row->attributes['class'] = 'rcs-course';
600 $table->data[] = $row;
601 }
602 } else {
603 $cell = new html_table_cell(get_string('nomatchingcourses', 'backup'));
604 $cell->colspan = 3;
605 $cell->attributes['class'] = 'notifyproblem';
606 $row = new html_table_row(array($cell));
607 $row->attributes['class'] = 'rcs-course';
3acc9b81
SH
608 $table->data[] = $row;
609 }
610 $output .= html_writer::table($table);
3acc9b81
SH
611 $output .= html_writer::end_tag('div');
612
613 $output .= html_writer::start_tag('div', array('class'=>'rcs-search'));
614 $output .= html_writer::empty_tag('input', array('type'=>'text', 'name'=>restore_category_search::$VAR_SEARCH, 'value'=>$component->get_search()));
615 $output .= html_writer::empty_tag('input', array('type'=>'submit', 'name'=>'searchcourses', 'value'=>get_string('search')));
616 $output .= html_writer::end_tag('div');
617
618 $output .= html_writer::end_tag('div');
619 return $output;
620 }
d94bb343
SH
621
622 public function invalid_format($format) {
623 $html = html_writer::start_tag('div', array('class'=>'invalidformat'));
624 $html .= html_writer::tag('h2', get_string('errorinvalidformat', 'backup'), array('class'=>'notifyproblem'));
625 if ($format == 'moodle1') {
626 // Moodle 1.x backups
f9bbe3c9
SH
627 $icon = $this->output->help_icon('errormoodle1format', 'backup');
628 $message = get_string('errormoodle1formatdesc', 'backup').' '.$icon;
629
d94bb343
SH
630 } else {
631 // Totally unknown format
f9bbe3c9 632 $message = get_string('errorinvalidformatdesc', 'backup');
d94bb343 633 }
f9bbe3c9 634 $html .= html_writer::tag('div', $message, array('class'=>'notifyproblem'));
d94bb343
SH
635 $html .= html_writer::end_tag('div');
636 return $html;
637 }
72f38ce7 638}
6aef525d 639
72f38ce7
DC
640/**
641 * Data structure representing backup files viewer
642 *
643 * @copyright 2010 Dongsheng Cai
644 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
645 * @since Moodle 2.0
646 */
647class backup_files_viewer implements renderable {
6aef525d
DC
648 public $files;
649 public $filecontext;
650 public $component;
651 public $filearea;
652 public $currentcontext;
72f38ce7
DC
653
654 /**
655 * Constructor of backup_files_viewer class
72f38ce7
DC
656 * @param array $options
657 */
30ad8cdd
DC
658 public function __construct(array $options = null) {
659 global $CFG, $USER;
6aef525d
DC
660 $fs = get_file_storage();
661 $this->currentcontext = $options['currentcontext'];
662 $this->filecontext = $options['filecontext'];
663 $this->component = $options['component'];
664 $this->filearea = $options['filearea'];
665 $files = $fs->get_area_files($this->filecontext->id, $this->component, $this->filearea, false, 'timecreated');
666 $this->files = array_reverse($files);
72f38ce7 667 }
30ad8cdd 668}