NOMDL backup: added missing string
[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
105 $html .= html_writer::start_tag('div', array('class'=>'backup-section'));
106 $html .= $this->output->heading(get_string('backupcoursedetails', 'backup'), 2, array('class'=>'header'));
107 $html .= $this->backup_detail_pair(get_string('coursetitle', 'backup'), $details->course->title);
108 $html .= $this->backup_detail_pair(get_string('courseid', 'backup'), $details->course->courseid);
109
110 $html .= html_writer::start_tag('div', array('class'=>'backup-sub-section'));
111 $html .= $this->output->heading(get_string('backupcoursesections', 'backup'), 3, array('class'=>'subheader'));
112 foreach ($details->sections as $key=>$section) {
113 $included = $key.'_included';
114 $userinfo = $key.'_userinfo';
115 if ($section->settings[$included] && $section->settings[$userinfo]) {
116 $value = get_string('sectionincanduser','backup');
117 } else if ($section->settings[$included]) {
118 $value = get_string('sectioninc','backup');
119 } else {
120 continue;
121 }
122 $html .= $this->backup_detail_pair(get_string('backupcoursesection', 'backup', $section->title), $value);
123 $table = null;
124 foreach ($details->activities as $activitykey=>$activity) {
125 if ($activity->sectionid != $section->sectionid) {
126 continue;
127 }
128 if (empty($table)) {
129 $table = new html_table();
130 $table->head = array('Module', 'Title', 'Userinfo');
131 $table->colclasses = array('modulename', 'moduletitle', 'userinfoincluded');
132 $table->align = array('left','left', 'center');
133 $table->attributes = array('class'=>'activitytable generaltable');
134 $table->data = array();
135 }
83c000d9
SH
136 $name = get_string('pluginname', $activity->modulename);
137 $icon = new pix_icon('icon', $name, $activity->modulename);
785d6603 138 $table->data[] = array(
83c000d9 139 $this->output->render($icon).'&nbsp;'.$name,
785d6603
SH
140 $activity->title,
141 ($activity->settings[$activitykey.'_userinfo'])?$yestick:$notick,
142 );
143 }
144 if (!empty($table)) {
145 $html .= $this->backup_detail_pair(get_string('sectionactivities','backup'), html_writer::table($table));
146 }
30ad8cdd 147
785d6603
SH
148 }
149 $html .= html_writer::end_tag('div');
150 $html .= html_writer::end_tag('div');
785d6603
SH
151
152 $html .= $this->output->single_button($nextstageurl, get_string('continue'), 'post');
83a9c866 153 $html .= html_writer::end_tag('div');
785d6603
SH
154
155 return $html;
156 }
157
ad93ddd5
SH
158 /**
159 * Displays a course selector for restore
160 *
161 * @param moodle_url $nextstageurl
162 * @param stdClass $details
163 * @param restore_category_search $categories
164 * @param restore_course_search $courses
165 * @param int $currentcourse
166 * @return string
167 */
168 public function course_selector(moodle_url $nextstageurl, $details, restore_category_search $categories = null, restore_course_search $courses=null, $currentcourse = null) {
785d6603
SH
169 global $CFG;
170 require_once($CFG->dirroot.'/course/lib.php');
171
172 $nextstageurl->param('sesskey', sesskey());
173
174 $form = html_writer::start_tag('form', array('method'=>'post', 'action'=>$nextstageurl->out_omit_querystring()));
175 foreach ($nextstageurl->params() as $key=>$value) {
176 $form .= html_writer::empty_tag('input', array('type'=>'hidden', 'name'=>$key, 'value'=>$value));
177 }
178
179 $html = html_writer::start_tag('div', array('class'=>'backup-course-selector backup-restore'));
180
ad93ddd5 181 if (!empty($categories) && ($categories->get_resultscount() > 0 || $categories->get_search() == '')) {
39bc4c6f
SH
182 // New course
183 $html .= $form;
184 $html .= html_writer::start_tag('div', array('class'=>'bcs-new-course backup-section'));
185 $html .= $this->output->heading(get_string('restoretonewcourse', 'backup'), 2, array('class'=>'header'));
186 $html .= $this->backup_detail_input(get_string('restoretonewcourse', 'backup'), 'radio', 'target', backup::TARGET_NEW_COURSE, array('checked'=>'checked'));
3acc9b81
SH
187 //$html .= $this->backup_detail_select(get_string('coursecategory', 'backup'), 'targetid', $categories);
188 $html .= $this->backup_detail_pair(get_string('selectacategory', 'backup'), $this->render($categories));
39bc4c6f
SH
189 $html .= $this->backup_detail_pair('', html_writer::empty_tag('input', array('type'=>'submit', 'value'=>get_string('continue'))));
190 $html .= html_writer::end_tag('div');
191 $html .= html_writer::end_tag('form');
192 }
785d6603 193
10618448
SH
194 // Current course
195 if (!empty($currentcourse)) {
196 $html .= $form;
197 $html .= html_writer::empty_tag('input', array('type'=>'hidden', 'name'=>'targetid', 'value'=>$currentcourse));
198 $html .= html_writer::start_tag('div', array('class'=>'bcs-current-course backup-section'));
199 $html .= $this->output->heading(get_string('restoretocurrentcourse', 'backup'), 2, array('class'=>'header'));
200 $html .= $this->backup_detail_input(get_string('restoretocurrentcourseadding', 'backup'), 'radio', 'target', backup::TARGET_CURRENT_ADDING, array('checked'=>'checked'));
201 $html .= $this->backup_detail_input(get_string('restoretocurrentcoursedeleting', 'backup'), 'radio', 'target', backup::TARGET_CURRENT_DELETING);
202 $html .= $this->backup_detail_pair('', html_writer::empty_tag('input', array('type'=>'submit', 'value'=>get_string('continue'))));
203 $html .= html_writer::end_tag('div');
204 $html .= html_writer::end_tag('form');
205 }
206
ad93ddd5 207 if (!empty($courses) && ($courses->get_resultscount() > 0 || $courses->get_search() == '')) {
39bc4c6f
SH
208 // Existing course
209 $html .= $form;
210 $html .= html_writer::start_tag('div', array('class'=>'bcs-existing-course backup-section'));
211 $html .= $this->output->heading(get_string('restoretoexistingcourse', 'backup'), 2, array('class'=>'header'));
3acc9b81 212 $html .= $this->backup_detail_input(get_string('restoretoexistingcourseadding', 'backup'), 'radio', 'target', backup::TARGET_EXISTING_ADDING, array('checked'=>'checked'));
39bc4c6f 213 $html .= $this->backup_detail_input(get_string('restoretoexistingcoursedeleting', 'backup'), 'radio', 'target', backup::TARGET_EXISTING_DELETING);
3acc9b81 214 $html .= $this->backup_detail_pair(get_string('selectacourse', 'backup'), $this->render($courses));
39bc4c6f
SH
215 $html .= $this->backup_detail_pair('', html_writer::empty_tag('input', array('type'=>'submit', 'value'=>get_string('continue'))));
216 $html .= html_writer::end_tag('div');
217 $html .= html_writer::end_tag('form');
218 }
785d6603
SH
219
220 $html .= html_writer::end_tag('div');
221 return $html;
222 }
223
ad93ddd5
SH
224 /**
225 * Displays the import course selector
226 *
227 * @param moodle_url $nextstageurl
228 * @param import_course_search $courses
229 * @return string
230 */
231 public function import_course_selector(moodle_url $nextstageurl, import_course_search $courses=null) {
232 $html = html_writer::start_tag('div', array('class'=>'import-course-selector backup-restore'));
233 $html .= html_writer::start_tag('form', array('method'=>'post', 'action'=>$nextstageurl->out_omit_querystring()));
234 foreach ($nextstageurl->params() as $key=>$value) {
235 $html .= html_writer::empty_tag('input', array('type'=>'hidden', 'name'=>$key, 'value'=>$value));
236 }
237 $html .= html_writer::start_tag('div', array('class'=>'ics-existing-course backup-section'));
238 $html .= $this->output->heading(get_string('importdatafrom'), 2, array('class'=>'header'));
239 $html .= $this->backup_detail_input(get_string('importadding', 'backup'), 'radio', 'target', backup::TARGET_CURRENT_ADDING, array('checked'=>'checked'), get_string('importaddingdesc', 'backup'));
240 $html .= $this->backup_detail_input(get_string('importdeleting', 'backup'), 'radio', 'target', backup::TARGET_CURRENT_DELETING, array(), get_string('importdeletingdesc', 'backup'));
241 $html .= $this->backup_detail_pair(get_string('selectacourse', 'backup'), $this->render($courses));
242 $html .= $this->backup_detail_pair('', html_writer::empty_tag('input', array('type'=>'submit', 'value'=>get_string('continue'))));
243 $html .= html_writer::end_tag('div');
244 $html .= html_writer::end_tag('form');
245 $html .= html_writer::end_tag('div');
246 return $html;
247 }
248
249 /**
250 * Creates a detailed pairing (key + value)
251 *
252 * @staticvar int $count
253 * @param string $label
254 * @param string $value
255 * @return string
256 */
785d6603
SH
257 protected function backup_detail_pair($label, $value) {
258 static $count= 0;
259 $count++;
260 $html = html_writer::start_tag('div', array('class'=>'detail-pair'));
261 $html .= html_writer::tag('label', $label, array('class'=>'detail-pair-label', 'for'=>'detail-pair-value-'.$count));
262 $html .= html_writer::tag('div', $value, array('class'=>'detail-pair-value', 'name'=>'detail-pair-value-'.$count));
263 $html .= html_writer::end_tag('div');
264 return $html;
265 }
266
ad93ddd5
SH
267 /**
268 * Created a detailed pairing with an input
269 *
270 * @param string $label
271 * @param string $type
272 * @param string $name
273 * @param string $value
274 * @param array $attributes
275 * @param string|null $description
276 * @return string
277 */
3acc9b81
SH
278 protected function backup_detail_input($label, $type, $name, $value, array $attributes=array(), $description=null) {
279 if (!empty ($description)) {
280 $description = html_writer::tag('span', $description, array('class'=>'description'));
281 } else {
282 $description = '';
283 }
284 return $this->backup_detail_pair($label, html_writer::empty_tag('input', $attributes+array('name'=>$name, 'type'=>$type, 'value'=>$value)).$description);
785d6603
SH
285 }
286
ad93ddd5
SH
287 /**
288 * Creates a detailed pairing with a select
289 *
290 * @param string $label
291 * @param string $name
292 * @param array $options
293 * @param string $selected
294 * @param bool $nothing
295 * @param array $attributes
296 * @param string|null $description
297 * @return string
298 */
3acc9b81
SH
299 protected function backup_detail_select($label, $name, $options, $selected='', $nothing=false, array $attributes=array(), $description=null) {
300 if (!empty ($description)) {
301 $description = html_writer::tag('span', $description, array('class'=>'description'));
302 } else {
303 $description = '';
304 }
305 return $this->backup_detail_pair($label, html_writer::select($options, $name, $selected, false, $attributes).$description);
785d6603
SH
306 }
307
ad93ddd5
SH
308 /**
309 * Displays precheck notices
310 *
311 * @param array $results
312 * @return string
313 */
785d6603
SH
314 public function precheck_notices($results) {
315 $output = html_writer::start_tag('div', array('class'=>'restore-precheck-notices'));
316 if (array_key_exists('errors', $results)) {
317 foreach ($results['errors'] as $error) {
318 $output .= $this->output->notification($error);
319 }
320 }
321 if (array_key_exists('warnings', $results)) {
322 foreach ($results['warnings'] as $warning) {
323 $output .= $this->output->notification($warning, 'notifywarning notifyproblem');
324 }
325 }
326 return $output.html_writer::end_tag('div');
327 }
328
ad93ddd5
SH
329 /**
330 * Displays substage buttons
331 *
332 * @param bool $haserrors
333 * @return string
334 */
3acc9b81
SH
335 public function substage_buttons($haserrors) {
336 $output = html_writer::start_tag('div', array('continuebutton'));
337 if (!$haserrors) {
338 $output .= html_writer::empty_tag('input', array('type'=>'submit', 'value'=>get_string('continue')));
339 }
340 $output .= html_writer::empty_tag('input', array('type'=>'submit', 'name'=>'cancel', 'value'=>get_string('cancel')));
341 $output .= html_writer::end_tag('div');
342 return $output;
343 }
344
ad93ddd5
SH
345 /**
346 * Displays a role mapping interface
347 *
348 * @param array $rolemappings
349 * @param array $roles
350 * @return string
351 */
3acc9b81
SH
352 public function role_mappings($rolemappings, $roles) {
353 $roles[0] = get_string('none');
354 $output = html_writer::start_tag('div', array('class'=>'restore-rolemappings'));
355 $output .= $this->output->heading(get_string('restorerolemappings', 'backup'), 2);
356 foreach ($rolemappings as $id=>$mapping) {
357 $label = $mapping->name;
358 $name = 'mapping'.$id;
359 $selected = $mapping->targetroleid;
360 $output .= $this->backup_detail_select($label, $name, $roles, $mapping->targetroleid, false, array(), $mapping->description);
361 }
362 $output .= html_writer::end_tag('div');
363 return $output;
364 }
365
ad93ddd5
SH
366 /**
367 * Displays a continue button
368 *
369 * @param string|moodle_url $url
370 * @param string $method
371 * @return string
372 */
39bc4c6f 373 public function continue_button($url, $method='post') {
785d6603
SH
374 if (!($url instanceof moodle_url)) {
375 $url = new moodle_url($url);
376 }
39bc4c6f
SH
377 if ($method != 'post') {
378 $method = 'get';
379 }
785d6603 380 $url->param('sesskey', sesskey());
39bc4c6f 381 $button = new single_button($url, get_string('continue'), $method);
785d6603
SH
382 $button->class = 'continuebutton';
383 return $this->render($button);
384 }
72f38ce7
DC
385 /**
386 * Print a backup files tree
72f38ce7
DC
387 * @param array $options
388 * @return string
389 */
30ad8cdd 390 public function backup_files_viewer(array $options = null) {
6aef525d
DC
391 $files = new backup_files_viewer($options);
392 return $this->render($files);
72f38ce7
DC
393 }
394
ad93ddd5
SH
395 /**
396 * Displays a backup files viewer
397 *
398 * @global stdClass $USER
399 * @param backup_files_viewer $tree
400 * @return string
401 */
6aef525d
DC
402 public function render_backup_files_viewer(backup_files_viewer $viewer) {
403 global $CFG;
404 $files = $viewer->files;
72f38ce7 405
6aef525d
DC
406 $table = new html_table();
407 $table->head = array(get_string('filename', 'backup'), get_string('time'), get_string('size'), get_string('download'), get_string('restore'));
408 $table->align = array('left', 'left', 'left', 'center', 'left', 'center');
409 $table->width = '100%';
410 $table->data = array();
411
412 foreach ($files as $file) {
413 if ($file->is_directory()) {
414 continue;
72f38ce7 415 }
6aef525d
DC
416 $fileurl = moodle_url::make_pluginfile_url($file->get_contextid(), $file->get_component(), $file->get_filearea(), null, $file->get_filepath(), $file->get_filename(), true);
417 $params = array();
418 $params['action'] = 'choosebackupfile';
419 $params['filename'] = $file->get_filename();
420 $params['filepath'] = $file->get_filepath();
421 $params['component'] = $file->get_component();
422 $params['filearea'] = $file->get_filearea();
423 $params['filecontextid'] = $file->get_contextid();
424 $params['contextid'] = $viewer->currentcontext->id;
425 $params['itemid'] = $file->get_itemid();
426 $restoreurl = new moodle_url('/backup/restorefile.php', $params);
427 $table->data[] = array(
428 $file->get_filename(),
429 userdate($file->get_timemodified()),
430 display_size($file->get_filesize()),
431 html_writer::link($fileurl, get_string('download')),
432 html_writer::link($restoreurl, get_string('restore')),
433 );
72f38ce7 434 }
6aef525d
DC
435
436 $html = html_writer::table($table);
1a22a422 437 $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 438
72f38ce7
DC
439 return $html;
440 }
3acc9b81 441
ad93ddd5
SH
442 /**
443 * Renders a restore course search object
444 *
445 * @param restore_course_search $component
446 * @return string
447 */
3acc9b81
SH
448 public function render_restore_course_search(restore_course_search $component) {
449 $url = $component->get_url();
450
451 $output = html_writer::start_tag('div', array('class' => 'restore-course-search'));
452 if ($component->get_totalcount() === 0) {
453 $output .= $this->output->notification(get_string('nomatchingcourses', 'backup'));
454 $output .= html_writer::end_tag('div');
455 return $output;
456 }
457
458 $output .= html_writer::tag('div', get_string('totalcoursesearchresults', 'backup', $component->get_totalcount()), array('class'=>'rcs-totalresults'));
459
460 $output .= html_writer::start_tag('div', array('class' => 'rcs-results'));
461 if ($component->get_totalpages()>1) {
462 $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);
463 $output .= $this->output->render($pagingbar);
464 }
465
466 $table = new html_table();
467 $table->head = array('', get_string('shortname'), get_string('fullname'));
468 $table->data = array();
469 foreach ($component->get_results() as $course) {
470 $row = new html_table_row();
471 $row->attributes['class'] = 'rcs-course';
472 if (!$course->visible) {
473 $row->attributes['class'] .= ' dimmed';
474 }
475 $row->cells = array(
476 html_writer::empty_tag('input', array('type'=>'radio', 'name'=>'targetid', 'value'=>$course->id)),
477 $course->shortname,
478 $course->fullname
479 );
480 $table->data[] = $row;
481 }
482 $output .= html_writer::table($table);
483 if (isset($pagingbar)) {
484 $output .= $this->output->render($pagingbar);
485 }
486 $output .= html_writer::end_tag('div');
487
488 $output .= html_writer::start_tag('div', array('class'=>'rcs-search'));
489 $output .= html_writer::empty_tag('input', array('type'=>'text', 'name'=>restore_course_search::$VAR_SEARCH, 'value'=>$component->get_search()));
490 $output .= html_writer::empty_tag('input', array('type'=>'submit', 'name'=>'searchcourses', 'value'=>get_string('search')));
491 $output .= html_writer::end_tag('div');
30ad8cdd 492
3acc9b81
SH
493 $output .= html_writer::end_tag('div');
494 return $output;
495 }
496
ad93ddd5
SH
497 /**
498 * Renders an import course search object
499 *
500 * @param import_course_search $component
501 * @return string
502 */
503 public function render_import_course_search(import_course_search $component) {
504 $url = $component->get_url();
505
506 $output = html_writer::start_tag('div', array('class' => 'import-course-search'));
507 if ($component->get_totalcount() === 0) {
508 $output .= $this->output->notification(get_string('nomatchingcourses', 'backup'));
509 $output .= html_writer::end_tag('div');
510 return $output;
511 }
512
513 $output .= html_writer::tag('div', get_string('totalcoursesearchresults', 'backup', $component->get_totalcount()), array('class'=>'ics-totalresults'));
514
515 $output .= html_writer::start_tag('div', array('class' => 'ics-results'));
516 if ($component->get_totalpages()>1) {
517 $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);
518 $output .= $this->output->render($pagingbar);
519 }
520
521 $table = new html_table();
522 $table->head = array('', get_string('shortname'), get_string('fullname'));
523 $table->data = array();
524 foreach ($component->get_results() as $course) {
525 $row = new html_table_row();
526 $row->attributes['class'] = 'ics-course';
527 if (!$course->visible) {
528 $row->attributes['class'] .= ' dimmed';
529 }
530 $row->cells = array(
531 html_writer::empty_tag('input', array('type'=>'radio', 'name'=>'importid', 'value'=>$course->id)),
532 $course->shortname,
533 $course->fullname
534 );
535 $table->data[] = $row;
536 }
537 $output .= html_writer::table($table);
538 if (isset($pagingbar)) {
539 $output .= $this->output->render($pagingbar);
540 }
541 $output .= html_writer::end_tag('div');
542
543 $output .= html_writer::start_tag('div', array('class'=>'ics-search'));
544 $output .= html_writer::empty_tag('input', array('type'=>'text', 'name'=>restore_course_search::$VAR_SEARCH, 'value'=>$component->get_search()));
545 $output .= html_writer::empty_tag('input', array('type'=>'submit', 'name'=>'searchcourses', 'value'=>get_string('search')));
546 $output .= html_writer::end_tag('div');
547
548 $output .= html_writer::end_tag('div');
549 return $output;
550 }
551
552 /**
553 * Renders a restore category search object
6aef525d 554 *
ad93ddd5
SH
555 * @param restore_category_search $component
556 * @return string
557 */
3acc9b81
SH
558 public function render_restore_category_search(restore_category_search $component) {
559 $url = $component->get_url();
560
561 $output = html_writer::start_tag('div', array('class' => 'restore-course-search'));
562 if ($component->get_totalcount() === 0) {
563 $output .= $this->output->notification(get_string('nomatchingcourses', 'backup'));
564 $output .= html_writer::end_tag('div');
565 return $output;
566 }
567
568 $output .= html_writer::tag('div', get_string('totalcategorysearchresults', 'backup', $component->get_totalcount()), array('class'=>'rcs-totalresults'));
569
570 $output .= html_writer::start_tag('div', array('class' => 'rcs-results'));
571 if ($component->get_totalpages()>1) {
572 $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);
573 $output .= $this->output->render($pagingbar);
574 }
575
576 $table = new html_table();
577 $table->head = array('', get_string('name'), get_string('description'));
578 $table->data = array();
579 foreach ($component->get_results() as $category) {
580 $row = new html_table_row();
581 $row->attributes['class'] = 'rcs-course';
582 if (!$category->visible) {
583 $row->attributes['class'] .= ' dimmed';
584 }
585 $row->cells = array(
586 html_writer::empty_tag('input', array('type'=>'radio', 'name'=>'targetid', 'value'=>$category->id)),
587 $category->name,
588 format_text($category->description, $category->descriptionformat)
589 );
590 $table->data[] = $row;
591 }
592 $output .= html_writer::table($table);
593 if (isset($pagingbar)) {
594 $output .= $this->output->render($pagingbar);
595 }
596 $output .= html_writer::end_tag('div');
597
598 $output .= html_writer::start_tag('div', array('class'=>'rcs-search'));
599 $output .= html_writer::empty_tag('input', array('type'=>'text', 'name'=>restore_category_search::$VAR_SEARCH, 'value'=>$component->get_search()));
600 $output .= html_writer::empty_tag('input', array('type'=>'submit', 'name'=>'searchcourses', 'value'=>get_string('search')));
601 $output .= html_writer::end_tag('div');
602
603 $output .= html_writer::end_tag('div');
604 return $output;
605 }
d94bb343
SH
606
607 public function invalid_format($format) {
608 $html = html_writer::start_tag('div', array('class'=>'invalidformat'));
609 $html .= html_writer::tag('h2', get_string('errorinvalidformat', 'backup'), array('class'=>'notifyproblem'));
610 if ($format == 'moodle1') {
611 // Moodle 1.x backups
f9bbe3c9
SH
612 $icon = $this->output->help_icon('errormoodle1format', 'backup');
613 $message = get_string('errormoodle1formatdesc', 'backup').' '.$icon;
614
d94bb343
SH
615 } else {
616 // Totally unknown format
f9bbe3c9 617 $message = get_string('errorinvalidformatdesc', 'backup');
d94bb343 618 }
f9bbe3c9 619 $html .= html_writer::tag('div', $message, array('class'=>'notifyproblem'));
d94bb343
SH
620 $html .= html_writer::end_tag('div');
621 return $html;
622 }
72f38ce7 623}
6aef525d 624
72f38ce7
DC
625/**
626 * Data structure representing backup files viewer
627 *
628 * @copyright 2010 Dongsheng Cai
629 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
630 * @since Moodle 2.0
631 */
632class backup_files_viewer implements renderable {
6aef525d
DC
633 public $files;
634 public $filecontext;
635 public $component;
636 public $filearea;
637 public $currentcontext;
72f38ce7
DC
638
639 /**
640 * Constructor of backup_files_viewer class
72f38ce7
DC
641 * @param array $options
642 */
30ad8cdd
DC
643 public function __construct(array $options = null) {
644 global $CFG, $USER;
6aef525d
DC
645 $fs = get_file_storage();
646 $this->currentcontext = $options['currentcontext'];
647 $this->filecontext = $options['filecontext'];
648 $this->component = $options['component'];
649 $this->filearea = $options['filearea'];
650 $files = $fs->get_area_files($this->filecontext->id, $this->component, $this->filearea, false, 'timecreated');
651 $this->files = array_reverse($files);
72f38ce7 652 }
30ad8cdd 653}