|
Moodle
2.2.1
http://www.collinsharper.com
|
00001 <?php 00002 00003 // This file is part of Moodle - http://moodle.org/ 00004 // 00005 // Moodle is free software: you can redistribute it and/or modify 00006 // it under the terms of the GNU General Public License as published by 00007 // the Free Software Foundation, either version 3 of the License, or 00008 // (at your option) any later version. 00009 // 00010 // Moodle is distributed in the hope that it will be useful, 00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 // GNU General Public License for more details. 00014 // 00015 // You should have received a copy of the GNU General Public License 00016 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 00017 00037 class core_backup_renderer extends plugin_renderer_base { 00044 public function progress_bar(array $items) { 00045 foreach ($items as &$item) { 00046 $text = $item['text']; 00047 unset($item['text']); 00048 if (array_key_exists('link', $item)) { 00049 $link = $item['link']; 00050 unset($item['link']); 00051 $item = html_writer::link($link, $text, $item); 00052 } else { 00053 $item = html_writer::tag('span', $text, $item); 00054 } 00055 } 00056 return html_writer::tag('div', join(get_separator(), $items), array('class'=>'backup_progress clearfix')); 00057 } 00063 public function dependency_notification($message) { 00064 return html_writer::tag('div', $message, array('class'=>'notification dependencies_enforced')); 00065 } 00066 00074 public function backup_details($details, $nextstageurl) { 00075 $yestick = $this->output->pix_icon('i/tick_green_big', get_string('yes')); 00076 $notick = $this->output->pix_icon('i/cross_red_big', get_string('no')); 00077 00078 $html = html_writer::start_tag('div', array('class'=>'backup-restore')); 00079 00080 $html .= html_writer::start_tag('div', array('class'=>'backup-section')); 00081 $html .= $this->output->heading(get_string('backupdetails', 'backup'), 2, array('class'=>'header')); 00082 $html .= $this->backup_detail_pair(get_string('backuptype', 'backup'), get_string('backuptype'.$details->type, 'backup')); 00083 $html .= $this->backup_detail_pair(get_string('backupformat', 'backup'), get_string('backupformat'.$details->format, 'backup')); 00084 $html .= $this->backup_detail_pair(get_string('backupmode', 'backup'), get_string('backupmode'.$details->mode, 'backup')); 00085 $html .= $this->backup_detail_pair(get_string('backupdate', 'backup'), userdate($details->backup_date)); 00086 $html .= $this->backup_detail_pair(get_string('moodleversion', 'backup'), 00087 html_writer::tag('span', $details->moodle_release, array('class'=>'moodle_release')). 00088 html_writer::tag('span', '['.$details->moodle_version.']', array('class'=>'moodle_version sub-detail'))); 00089 $html .= $this->backup_detail_pair(get_string('backupversion', 'backup'), 00090 html_writer::tag('span', $details->backup_release, array('class'=>'moodle_release')). 00091 html_writer::tag('span', '['.$details->backup_version.']', array('class'=>'moodle_version sub-detail'))); 00092 $html .= $this->backup_detail_pair(get_string('originalwwwroot', 'backup'), 00093 html_writer::tag('span', $details->original_wwwroot, array('class'=>'originalwwwroot')). 00094 html_writer::tag('span', '['.$details->original_site_identifier_hash.']', array('class'=>'sitehash sub-detail'))); 00095 $html .= html_writer::end_tag('div'); 00096 00097 $html .= html_writer::start_tag('div', array('class'=>'backup-section settings-section')); 00098 $html .= $this->output->heading(get_string('backupsettings', 'backup'), 2, array('class'=>'header')); 00099 foreach ($details->root_settings as $label=>$value) { 00100 if ($label == 'filename') continue; 00101 $html .= $this->backup_detail_pair(get_string('rootsetting'.str_replace('_','',$label), 'backup'), $value?$yestick:$notick); 00102 } 00103 $html .= html_writer::end_tag('div'); 00104 00105 if ($details->type === 'course') { 00106 $html .= html_writer::start_tag('div', array('class'=>'backup-section')); 00107 $html .= $this->output->heading(get_string('backupcoursedetails', 'backup'), 2, array('class'=>'header')); 00108 $html .= $this->backup_detail_pair(get_string('coursetitle', 'backup'), $details->course->title); 00109 $html .= $this->backup_detail_pair(get_string('courseid', 'backup'), $details->course->courseid); 00110 00111 $html .= html_writer::start_tag('div', array('class'=>'backup-sub-section')); 00112 $html .= $this->output->heading(get_string('backupcoursesections', 'backup'), 3, array('class'=>'subheader')); 00113 foreach ($details->sections as $key=>$section) { 00114 $included = $key.'_included'; 00115 $userinfo = $key.'_userinfo'; 00116 if ($section->settings[$included] && $section->settings[$userinfo]) { 00117 $value = get_string('sectionincanduser','backup'); 00118 } else if ($section->settings[$included]) { 00119 $value = get_string('sectioninc','backup'); 00120 } else { 00121 continue; 00122 } 00123 $html .= $this->backup_detail_pair(get_string('backupcoursesection', 'backup', $section->title), $value); 00124 $table = null; 00125 foreach ($details->activities as $activitykey=>$activity) { 00126 if ($activity->sectionid != $section->sectionid) { 00127 continue; 00128 } 00129 if (empty($table)) { 00130 $table = new html_table(); 00131 $table->head = array('Module', 'Title', 'Userinfo'); 00132 $table->colclasses = array('modulename', 'moduletitle', 'userinfoincluded'); 00133 $table->align = array('left','left', 'center'); 00134 $table->attributes = array('class'=>'activitytable generaltable'); 00135 $table->data = array(); 00136 } 00137 $name = get_string('pluginname', $activity->modulename); 00138 $icon = new pix_icon('icon', $name, $activity->modulename); 00139 $table->data[] = array( 00140 $this->output->render($icon).' '.$name, 00141 $activity->title, 00142 ($activity->settings[$activitykey.'_userinfo'])?$yestick:$notick, 00143 ); 00144 } 00145 if (!empty($table)) { 00146 $html .= $this->backup_detail_pair(get_string('sectionactivities','backup'), html_writer::table($table)); 00147 } 00148 00149 } 00150 $html .= html_writer::end_tag('div'); 00151 $html .= html_writer::end_tag('div'); 00152 } 00153 00154 $html .= $this->output->single_button($nextstageurl, get_string('continue'), 'post'); 00155 $html .= html_writer::end_tag('div'); 00156 00157 return $html; 00158 } 00159 00167 public function backup_details_nonstandard($nextstageurl, array $details) { 00168 00169 $html = html_writer::start_tag('div', array('class' => 'backup-restore nonstandardformat')); 00170 $html .= html_writer::start_tag('div', array('class' => 'backup-section')); 00171 $html .= $this->output->heading(get_string('backupdetails', 'backup'), 2, 'header'); 00172 $html .= $this->output->box(get_string('backupdetailsnonstandardinfo', 'backup'), 'noticebox'); 00173 $html .= $this->backup_detail_pair( 00174 get_string('backupformat', 'backup'), 00175 get_string('backupformat'.$details['format'], 'backup')); 00176 $html .= $this->backup_detail_pair( 00177 get_string('backuptype', 'backup'), 00178 get_string('backuptype'.$details['type'], 'backup')); 00179 $html .= html_writer::end_tag('div'); 00180 $html .= $this->output->single_button($nextstageurl, get_string('continue'), 'post'); 00181 $html .= html_writer::end_tag('div'); 00182 00183 return $html; 00184 } 00185 00192 public function backup_details_unknown(moodle_url $nextstageurl) { 00193 00194 $html = html_writer::start_tag('div', array('class' => 'unknownformat')); 00195 $html .= $this->output->heading(get_string('errorinvalidformat', 'backup'), 2, 'notifyproblem'); 00196 $html .= html_writer::tag('div', get_string('errorinvalidformatinfo', 'backup'), array('class' => 'notifyproblem')); 00197 $html .= $this->output->single_button($nextstageurl, get_string('continue'), 'post'); 00198 $html .= html_writer::end_tag('div'); 00199 00200 return $html; 00201 } 00202 00213 public function course_selector(moodle_url $nextstageurl, $wholecourse = true, restore_category_search $categories = null, restore_course_search $courses=null, $currentcourse = null) { 00214 global $CFG, $PAGE; 00215 require_once($CFG->dirroot.'/course/lib.php'); 00216 00217 $nextstageurl->param('sesskey', sesskey()); 00218 00219 $form = html_writer::start_tag('form', array('method'=>'post', 'action'=>$nextstageurl->out_omit_querystring())); 00220 foreach ($nextstageurl->params() as $key=>$value) { 00221 $form .= html_writer::empty_tag('input', array('type'=>'hidden', 'name'=>$key, 'value'=>$value)); 00222 } 00223 00224 $hasrestoreoption = false; 00225 00226 $html = html_writer::start_tag('div', array('class'=>'backup-course-selector backup-restore')); 00227 if ($wholecourse && !empty($categories) && ($categories->get_count() > 0 || $categories->get_search())) { 00228 // New course 00229 $hasrestoreoption = true; 00230 $html .= $form; 00231 $html .= html_writer::start_tag('div', array('class'=>'bcs-new-course backup-section')); 00232 $html .= $this->output->heading(get_string('restoretonewcourse', 'backup'), 2, array('class'=>'header')); 00233 $html .= $this->backup_detail_input(get_string('restoretonewcourse', 'backup'), 'radio', 'target', backup::TARGET_NEW_COURSE, array('checked'=>'checked')); 00234 $html .= $this->backup_detail_pair(get_string('selectacategory', 'backup'), $this->render($categories)); 00235 $html .= $this->backup_detail_pair('', html_writer::empty_tag('input', array('type'=>'submit', 'value'=>get_string('continue')))); 00236 $html .= html_writer::end_tag('div'); 00237 $html .= html_writer::end_tag('form'); 00238 } 00239 00240 if ($wholecourse && !empty($currentcourse)) { 00241 // Current course 00242 $hasrestoreoption = true; 00243 $html .= $form; 00244 $html .= html_writer::empty_tag('input', array('type'=>'hidden', 'name'=>'targetid', 'value'=>$currentcourse)); 00245 $html .= html_writer::start_tag('div', array('class'=>'bcs-current-course backup-section')); 00246 $html .= $this->output->heading(get_string('restoretocurrentcourse', 'backup'), 2, array('class'=>'header')); 00247 $html .= $this->backup_detail_input(get_string('restoretocurrentcourseadding', 'backup'), 'radio', 'target', backup::TARGET_CURRENT_ADDING, array('checked'=>'checked')); 00248 $html .= $this->backup_detail_input(get_string('restoretocurrentcoursedeleting', 'backup'), 'radio', 'target', backup::TARGET_CURRENT_DELETING); 00249 $html .= $this->backup_detail_pair('', html_writer::empty_tag('input', array('type'=>'submit', 'value'=>get_string('continue')))); 00250 $html .= html_writer::end_tag('div'); 00251 $html .= html_writer::end_tag('form'); 00252 } 00253 00254 if (!empty($courses) && ($courses->get_count() > 0 || $courses->get_search())) { 00255 // Existing course 00256 $hasrestoreoption = true; 00257 $html .= $form; 00258 $html .= html_writer::start_tag('div', array('class'=>'bcs-existing-course backup-section')); 00259 $html .= $this->output->heading(get_string('restoretoexistingcourse', 'backup'), 2, array('class'=>'header')); 00260 if ($wholecourse) { 00261 $html .= $this->backup_detail_input(get_string('restoretoexistingcourseadding', 'backup'), 'radio', 'target', backup::TARGET_EXISTING_ADDING, array('checked'=>'checked')); 00262 $html .= $this->backup_detail_input(get_string('restoretoexistingcoursedeleting', 'backup'), 'radio', 'target', backup::TARGET_EXISTING_DELETING); 00263 $html .= $this->backup_detail_pair(get_string('selectacourse', 'backup'), $this->render($courses)); 00264 } else { 00265 // We only allow restore adding to existing for now. Enforce it here. 00266 $html .= html_writer::empty_tag('input', array('type'=>'hidden', 'name'=>'target', 'value'=>backup::TARGET_EXISTING_ADDING)); 00267 $courses->invalidate_results(); // Clean list of courses 00268 $courses->set_include_currentcourse(); // Show current course in the list 00269 $html .= $this->backup_detail_pair(get_string('selectacourse', 'backup'), $this->render($courses)); 00270 } 00271 $html .= $this->backup_detail_pair('', html_writer::empty_tag('input', array('type'=>'submit', 'value'=>get_string('continue')))); 00272 $html .= html_writer::end_tag('div'); 00273 $html .= html_writer::end_tag('form'); 00274 } 00275 00276 if (!$hasrestoreoption) { 00277 echo $this->output->notification(get_string('norestoreoptions','backup')); 00278 } 00279 00280 $html .= html_writer::end_tag('div'); 00281 return $html; 00282 } 00283 00291 public function import_course_selector(moodle_url $nextstageurl, import_course_search $courses=null) { 00292 $html = html_writer::start_tag('div', array('class'=>'import-course-selector backup-restore')); 00293 $html .= html_writer::start_tag('form', array('method'=>'post', 'action'=>$nextstageurl->out_omit_querystring())); 00294 foreach ($nextstageurl->params() as $key=>$value) { 00295 $html .= html_writer::empty_tag('input', array('type'=>'hidden', 'name'=>$key, 'value'=>$value)); 00296 } 00297 // We only allow import adding for now. Enforce it here. 00298 $html .= html_writer::empty_tag('input', array('type'=>'hidden', 'name'=>'target', 'value'=>backup::TARGET_CURRENT_ADDING)); 00299 $html .= html_writer::start_tag('div', array('class'=>'ics-existing-course backup-section')); 00300 $html .= $this->output->heading(get_string('importdatafrom'), 2, array('class'=>'header')); 00301 $html .= $this->backup_detail_pair(get_string('selectacourse', 'backup'), $this->render($courses)); 00302 $html .= $this->backup_detail_pair('', html_writer::empty_tag('input', array('type'=>'submit', 'value'=>get_string('continue')))); 00303 $html .= html_writer::end_tag('div'); 00304 $html .= html_writer::end_tag('form'); 00305 $html .= html_writer::end_tag('div'); 00306 return $html; 00307 } 00308 00317 protected function backup_detail_pair($label, $value) { 00318 static $count= 0; 00319 $count++; 00320 $html = html_writer::start_tag('div', array('class'=>'detail-pair')); 00321 $html .= html_writer::tag('label', $label, array('class'=>'detail-pair-label', 'for'=>'detail-pair-value-'.$count)); 00322 $html .= html_writer::tag('div', $value, array('class'=>'detail-pair-value', 'name'=>'detail-pair-value-'.$count)); 00323 $html .= html_writer::end_tag('div'); 00324 return $html; 00325 } 00326 00338 protected function backup_detail_input($label, $type, $name, $value, array $attributes=array(), $description=null) { 00339 if (!empty ($description)) { 00340 $description = html_writer::tag('span', $description, array('class'=>'description')); 00341 } else { 00342 $description = ''; 00343 } 00344 return $this->backup_detail_pair($label, html_writer::empty_tag('input', $attributes+array('name'=>$name, 'type'=>$type, 'value'=>$value)).$description); 00345 } 00346 00359 protected function backup_detail_select($label, $name, $options, $selected='', $nothing=false, array $attributes=array(), $description=null) { 00360 if (!empty ($description)) { 00361 $description = html_writer::tag('span', $description, array('class'=>'description')); 00362 } else { 00363 $description = ''; 00364 } 00365 return $this->backup_detail_pair($label, html_writer::select($options, $name, $selected, false, $attributes).$description); 00366 } 00367 00374 public function precheck_notices($results) { 00375 $output = html_writer::start_tag('div', array('class'=>'restore-precheck-notices')); 00376 if (array_key_exists('errors', $results)) { 00377 foreach ($results['errors'] as $error) { 00378 $output .= $this->output->notification($error); 00379 } 00380 } 00381 if (array_key_exists('warnings', $results)) { 00382 foreach ($results['warnings'] as $warning) { 00383 $output .= $this->output->notification($warning, 'notifywarning notifyproblem'); 00384 } 00385 } 00386 return $output.html_writer::end_tag('div'); 00387 } 00388 00395 public function substage_buttons($haserrors) { 00396 $output = html_writer::start_tag('div', array('continuebutton')); 00397 if (!$haserrors) { 00398 $output .= html_writer::empty_tag('input', array('type'=>'submit', 'value'=>get_string('continue'))); 00399 } 00400 $output .= html_writer::empty_tag('input', array('type'=>'submit', 'name'=>'cancel', 'value'=>get_string('cancel'))); 00401 $output .= html_writer::end_tag('div'); 00402 return $output; 00403 } 00404 00412 public function role_mappings($rolemappings, $roles) { 00413 $roles[0] = get_string('none'); 00414 $output = html_writer::start_tag('div', array('class'=>'restore-rolemappings')); 00415 $output .= $this->output->heading(get_string('restorerolemappings', 'backup'), 2); 00416 foreach ($rolemappings as $id=>$mapping) { 00417 $label = $mapping->name; 00418 $name = 'mapping'.$id; 00419 $selected = $mapping->targetroleid; 00420 $output .= $this->backup_detail_select($label, $name, $roles, $mapping->targetroleid, false, array(), $mapping->description); 00421 } 00422 $output .= html_writer::end_tag('div'); 00423 return $output; 00424 } 00425 00433 public function continue_button($url, $method='post') { 00434 if (!($url instanceof moodle_url)) { 00435 $url = new moodle_url($url); 00436 } 00437 if ($method != 'post') { 00438 $method = 'get'; 00439 } 00440 $url->param('sesskey', sesskey()); 00441 $button = new single_button($url, get_string('continue'), $method); 00442 $button->class = 'continuebutton'; 00443 return $this->render($button); 00444 } 00450 public function backup_files_viewer(array $options = null) { 00451 $files = new backup_files_viewer($options); 00452 return $this->render($files); 00453 } 00454 00462 public function render_backup_files_viewer(backup_files_viewer $viewer) { 00463 global $CFG; 00464 $files = $viewer->files; 00465 00466 $table = new html_table(); 00467 $table->attributes['class'] = 'backup-files-table generaltable'; 00468 $table->head = array(get_string('filename', 'backup'), get_string('time'), get_string('size'), get_string('download'), get_string('restore')); 00469 $table->width = '100%'; 00470 $table->data = array(); 00471 00472 foreach ($files as $file) { 00473 if ($file->is_directory()) { 00474 continue; 00475 } 00476 $fileurl = moodle_url::make_pluginfile_url($file->get_contextid(), $file->get_component(), $file->get_filearea(), null, $file->get_filepath(), $file->get_filename(), true); 00477 $params = array(); 00478 $params['action'] = 'choosebackupfile'; 00479 $params['filename'] = $file->get_filename(); 00480 $params['filepath'] = $file->get_filepath(); 00481 $params['component'] = $file->get_component(); 00482 $params['filearea'] = $file->get_filearea(); 00483 $params['filecontextid'] = $file->get_contextid(); 00484 $params['contextid'] = $viewer->currentcontext->id; 00485 $params['itemid'] = $file->get_itemid(); 00486 $restoreurl = new moodle_url('/backup/restorefile.php', $params); 00487 $table->data[] = array( 00488 $file->get_filename(), 00489 userdate($file->get_timemodified()), 00490 display_size($file->get_filesize()), 00491 html_writer::link($fileurl, get_string('download')), 00492 html_writer::link($restoreurl, get_string('restore')), 00493 ); 00494 } 00495 00496 $html = html_writer::table($table); 00497 $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'); 00498 00499 return $html; 00500 } 00501 00508 public function render_restore_course_search(restore_course_search $component) { 00509 $url = $component->get_url(); 00510 00511 $output = html_writer::start_tag('div', array('class' => 'restore-course-search')); 00512 $output .= html_writer::start_tag('div', array('class' => 'rcs-results')); 00513 00514 $table = new html_table(); 00515 $table->head = array('', get_string('shortnamecourse'), get_string('fullnamecourse')); 00516 $table->data = array(); 00517 if ($component->get_count() !== 0) { 00518 foreach ($component->get_results() as $course) { 00519 $row = new html_table_row(); 00520 $row->attributes['class'] = 'rcs-course'; 00521 if (!$course->visible) { 00522 $row->attributes['class'] .= ' dimmed'; 00523 } 00524 $row->cells = array( 00525 html_writer::empty_tag('input', array('type'=>'radio', 'name'=>'targetid', 'value'=>$course->id)), 00526 format_string($course->shortname, true, array('context' => get_context_instance(CONTEXT_COURSE, $course->id))), 00527 format_string($course->fullname, true, array('context' => get_context_instance(CONTEXT_COURSE, $course->id))) 00528 ); 00529 $table->data[] = $row; 00530 } 00531 if ($component->has_more_results()) { 00532 $cell = new html_table_cell(get_string('moreresults', 'backup')); 00533 $cell->colspan = 3; 00534 $cell->attributes['class'] = 'notifyproblem'; 00535 $row = new html_table_row(array($cell)); 00536 $row->attributes['class'] = 'rcs-course'; 00537 $table->data[] = $row; 00538 } 00539 } else { 00540 $cell = new html_table_cell(get_string('nomatchingcourses', 'backup')); 00541 $cell->colspan = 3; 00542 $cell->attributes['class'] = 'notifyproblem'; 00543 $row = new html_table_row(array($cell)); 00544 $row->attributes['class'] = 'rcs-course'; 00545 $table->data[] = $row; 00546 } 00547 $output .= html_writer::table($table); 00548 $output .= html_writer::end_tag('div'); 00549 00550 $output .= html_writer::start_tag('div', array('class'=>'rcs-search')); 00551 $output .= html_writer::empty_tag('input', array('type'=>'text', 'name'=>restore_course_search::$VAR_SEARCH, 'value'=>$component->get_search())); 00552 $output .= html_writer::empty_tag('input', array('type'=>'submit', 'name'=>'searchcourses', 'value'=>get_string('search'))); 00553 $output .= html_writer::end_tag('div'); 00554 00555 $output .= html_writer::end_tag('div'); 00556 return $output; 00557 } 00558 00565 public function render_import_course_search(import_course_search $component) { 00566 $url = $component->get_url(); 00567 00568 $output = html_writer::start_tag('div', array('class' => 'import-course-search')); 00569 if ($component->get_count() === 0) { 00570 $output .= $this->output->notification(get_string('nomatchingcourses', 'backup')); 00571 $output .= html_writer::end_tag('div'); 00572 return $output; 00573 } 00574 00575 $output .= html_writer::tag('div', get_string('totalcoursesearchresults', 'backup', $component->get_count()), array('class'=>'ics-totalresults')); 00576 00577 $output .= html_writer::start_tag('div', array('class' => 'ics-results')); 00578 00579 $table = new html_table(); 00580 $table->head = array('', get_string('shortnamecourse'), get_string('fullnamecourse')); 00581 $table->data = array(); 00582 foreach ($component->get_results() as $course) { 00583 $row = new html_table_row(); 00584 $row->attributes['class'] = 'ics-course'; 00585 if (!$course->visible) { 00586 $row->attributes['class'] .= ' dimmed'; 00587 } 00588 $row->cells = array( 00589 html_writer::empty_tag('input', array('type'=>'radio', 'name'=>'importid', 'value'=>$course->id)), 00590 format_string($course->shortname, true, array('context' => get_context_instance(CONTEXT_COURSE, $course->id))), 00591 format_string($course->fullname, true, array('context' => get_context_instance(CONTEXT_COURSE, $course->id))) 00592 ); 00593 $table->data[] = $row; 00594 } 00595 $output .= html_writer::table($table); 00596 $output .= html_writer::end_tag('div'); 00597 00598 $output .= html_writer::start_tag('div', array('class'=>'ics-search')); 00599 $output .= html_writer::empty_tag('input', array('type'=>'text', 'name'=>restore_course_search::$VAR_SEARCH, 'value'=>$component->get_search())); 00600 $output .= html_writer::empty_tag('input', array('type'=>'submit', 'name'=>'searchcourses', 'value'=>get_string('search'))); 00601 $output .= html_writer::end_tag('div'); 00602 00603 $output .= html_writer::end_tag('div'); 00604 return $output; 00605 } 00606 00613 public function render_restore_category_search(restore_category_search $component) { 00614 $url = $component->get_url(); 00615 00616 $output = html_writer::start_tag('div', array('class' => 'restore-course-search')); 00617 $output .= html_writer::start_tag('div', array('class' => 'rcs-results')); 00618 00619 $table = new html_table(); 00620 $table->head = array('', get_string('name'), get_string('description')); 00621 $table->data = array(); 00622 00623 if ($component->get_count() !== 0) { 00624 foreach ($component->get_results() as $category) { 00625 $row = new html_table_row(); 00626 $row->attributes['class'] = 'rcs-course'; 00627 if (!$category->visible) { 00628 $row->attributes['class'] .= ' dimmed'; 00629 } 00630 $row->cells = array( 00631 html_writer::empty_tag('input', array('type'=>'radio', 'name'=>'targetid', 'value'=>$category->id)), 00632 format_string($category->name, true, array('context' => get_context_instance(CONTEXT_COURSECAT, $category->id))), 00633 format_text($category->description, $category->descriptionformat, array('overflowdiv'=>true)) 00634 ); 00635 $table->data[] = $row; 00636 } 00637 if ($component->has_more_results()) { 00638 $cell = new html_table_cell(get_string('moreresults', 'backup')); 00639 $cell->attributes['class'] = 'notifyproblem'; 00640 $cell->colspan = 3; 00641 $row = new html_table_row(array($cell)); 00642 $row->attributes['class'] = 'rcs-course'; 00643 $table->data[] = $row; 00644 } 00645 } else { 00646 $cell = new html_table_cell(get_string('nomatchingcourses', 'backup')); 00647 $cell->colspan = 3; 00648 $cell->attributes['class'] = 'notifyproblem'; 00649 $row = new html_table_row(array($cell)); 00650 $row->attributes['class'] = 'rcs-course'; 00651 $table->data[] = $row; 00652 } 00653 $output .= html_writer::table($table); 00654 $output .= html_writer::end_tag('div'); 00655 00656 $output .= html_writer::start_tag('div', array('class'=>'rcs-search')); 00657 $output .= html_writer::empty_tag('input', array('type'=>'text', 'name'=>restore_category_search::$VAR_SEARCH, 'value'=>$component->get_search())); 00658 $output .= html_writer::empty_tag('input', array('type'=>'submit', 'name'=>'searchcourses', 'value'=>get_string('search'))); 00659 $output .= html_writer::end_tag('div'); 00660 00661 $output .= html_writer::end_tag('div'); 00662 return $output; 00663 } 00664 } 00665 00673 class backup_files_viewer implements renderable { 00674 public $files; 00675 public $filecontext; 00676 public $component; 00677 public $filearea; 00678 public $currentcontext; 00679 00684 public function __construct(array $options = null) { 00685 global $CFG, $USER; 00686 $fs = get_file_storage(); 00687 $this->currentcontext = $options['currentcontext']; 00688 $this->filecontext = $options['filecontext']; 00689 $this->component = $options['component']; 00690 $this->filearea = $options['filearea']; 00691 $files = $fs->get_area_files($this->filecontext->id, $this->component, $this->filearea, false, 'timecreated'); 00692 $this->files = array_reverse($files); 00693 } 00694 }