index.php 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php
  2. // This file is part of Moodle - http://moodle.org/
  3. //
  4. // Moodle is free software: you can redistribute it and/or modify
  5. // it under the terms of the GNU General Public License as published by
  6. // the Free Software Foundation, either version 3 of the License, or
  7. // (at your option) any later version.
  8. //
  9. // Moodle is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU General Public License
  15. // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
  16. /**
  17. * Moodle file tree viewer based on YUI2 Treeview
  18. *
  19. * @package core
  20. * @subpackage file
  21. * @copyright 2010 Dongsheng Cai <dongsheng@moodle.com>
  22. * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23. */
  24. require('../config.php');
  25. $contextid = optional_param('contextid', 0, PARAM_INT);
  26. $filepath = optional_param('filepath', '', PARAM_PATH);
  27. $filename = optional_param('filename', '', PARAM_FILE);
  28. // hard-coded to course legacy area
  29. $component = 'course';
  30. $filearea = 'legacy';
  31. $itemid = 0;
  32. if (empty($contextid)) {
  33. $contextid = context_course::instance(SITEID)->id;
  34. }
  35. $PAGE->set_url('/files/index.php', array('contextid'=>$contextid, 'filepath'=>$filepath, 'filename'=>$filename));
  36. navigation_node::override_active_url(new moodle_url('/files/index.php', array('contextid'=>$contextid)));
  37. if ($filepath === '') {
  38. $filepath = null;
  39. }
  40. if ($filename === '') {
  41. $filename = null;
  42. }
  43. list($context, $course, $cm) = get_context_info_array($contextid);
  44. $PAGE->set_context($context);
  45. require_login($course, false, $cm);
  46. require_capability('moodle/course:managefiles', $context);
  47. $browser = get_file_browser();
  48. $file_info = $browser->get_file_info($context, $component, $filearea, $itemid, $filepath, $filename);
  49. $strfiles = get_string("files");
  50. if ($node = $PAGE->settingsnav->find('coursefiles', navigation_node::TYPE_SETTING)) {
  51. $node->make_active();
  52. } else {
  53. $PAGE->navbar->add($strfiles);
  54. }
  55. $PAGE->set_title("$course->shortname: $strfiles");
  56. $PAGE->set_heading($course->fullname);
  57. $PAGE->set_pagelayout('incourse');
  58. $output = $PAGE->get_renderer('core', 'files');
  59. echo $output->header();
  60. echo $output->box_start();
  61. if ($file_info) {
  62. $options = array();
  63. $options['context'] = $context;
  64. //$options['visible_areas'] = array('backup'=>array('section', 'course'), 'course'=>array('legacy'), 'user'=>array('backup'));
  65. echo $output->files_tree_viewer($file_info, $options);
  66. } else {
  67. echo $output->notification(get_string('nofilesavailable', 'repository'));
  68. }
  69. echo $output->box_end();
  70. echo $output->footer();