|
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 00027 define('AJAX_SCRIPT', true); 00028 00029 require('../config.php'); 00030 require_once($CFG->libdir.'/filelib.php'); 00031 00032 $action = optional_param('action', 'list', PARAM_ALPHA); 00033 00034 $PAGE->set_context(get_system_context()); 00035 require_login(); 00036 00037 echo $OUTPUT->header(); // send headers 00038 00039 $err = new stdClass(); 00040 if (isguestuser()) { 00041 $err->error = get_string('noguest'); 00042 die(json_encode($err)); 00043 } 00044 00045 switch ($action) { 00046 // used by course file tree viewer 00047 case 'getfiletree': 00048 $contextid = required_param('contextid', PARAM_INT); 00049 $component = required_param('component', PARAM_COMPONENT); 00050 $filearea = required_param('filearea', PARAM_AREA); 00051 $itemid = required_param('itemid', PARAM_INT); 00052 $filepath = required_param('filepath', PARAM_PATH); 00053 00054 $browser = get_file_browser(); 00055 $fileinfo = $browser->get_file_info(get_context_instance_by_id($contextid), $component, $filearea, $itemid, $filepath); 00056 $children = $fileinfo->get_children(); 00057 $tree = array(); 00058 foreach ($children as $child) { 00059 $filedate = $child->get_timemodified(); 00060 $filesize = $child->get_filesize(); 00061 $mimetype = $child->get_mimetype(); 00062 $params = $child->get_params(); 00063 $url = new moodle_url('/files/index.php', $params); 00064 $fileitem = array( 00065 'params'=>$params, 00066 'filename'=>$child->get_visible_name(), 00067 'filedate'=>$filedate ? userdate($filedate) : '', 00068 'filesize'=>$filesize ? display_size($filesize) : '', 00069 ); 00070 if ($child->is_directory()) { 00071 $fileitem['isdir'] = true; 00072 $fileitem['url'] = $url->out(false); 00073 $fileitem['icon'] = $OUTPUT->pix_icon('f/folder', get_string('icon')); 00074 } else { 00075 $fileitem['url'] = $child->get_url(); 00076 $fileitem['icon'] = $OUTPUT->pix_icon('f/'.mimeinfo('icon', $child->get_visible_name()), get_string('icon')); 00077 } 00078 $tree[] = $fileitem; 00079 } 00080 echo json_encode($tree); 00081 break; 00082 00083 default: 00084 break; 00085 }