survey MDL-23324 made use of user_picture::fields()
[moodle.git] / repository / filepicker.php
CommitLineData
761265ad 1<?php
6f2cd52a 2
761265ad 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
6f2cd52a
DC
19/**
20 * This file is used to browse repositories in non-javascript mode
21 *
22 * @since 2.0
23 * @package moodlecore
24 * @subpackage repository
25 * @copyright 2009 Dongsheng Cai <dongsheng@moodle.com>
26 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
27 */
28
761265ad 29require_once('../config.php');
30require_once($CFG->libdir.'/filelib.php');
31require_once('lib.php');
b6fd5aee 32/// Wait as long as it takes for this script to finish
33set_time_limit(0);
34
49147814 35debugging('TODO: needs to be converted to use new component and security rules', DEBUG_DEVELOPER);
64f93798 36
b6fd5aee 37require_login();
761265ad 38
8ea068a2 39// disable blocks in this page
78946b9b 40$PAGE->set_pagelayout('embedded');
8ea068a2 41
42// general parameters
43$action = optional_param('action', '', PARAM_ALPHA);
d10c92f3 44$client_id = optional_param('client_id', '', PARAM_RAW); // client ID
761265ad 45$itemid = optional_param('itemid', '', PARAM_INT);
8ea068a2 46
47// parameters for repository
761265ad 48$callback = optional_param('callback', '', PARAM_CLEANHTML);
ad137107 49$contextid = optional_param('ctx_id', SYSCONTEXTID, PARAM_INT); // context ID
a14a933c 50$courseid = optional_param('course', SITEID, PARAM_INT); // course ID
8ea068a2 51$env = optional_param('env', 'filepicker', PARAM_ALPHA); // opened in file picker, file manager or html editor
52$filename = optional_param('filename', '', PARAM_FILE);
e5051df3 53$fileurl = optional_param('fileurl', '', PARAM_RAW);
8ea068a2 54$thumbnail = optional_param('thumbnail', '', PARAM_RAW);
af804e3e 55$targetpath = optional_param('targetpath', '', PARAM_PATH);
8ea068a2 56$repo_id = optional_param('repo_id', 0, PARAM_INT); // repository ID
57$req_path = optional_param('p', '', PARAM_RAW); // the path in repository
6f2cd52a 58$curr_page = optional_param('page', '', PARAM_RAW); // What page in repository?
761265ad 59$search_text = optional_param('s', '', PARAM_CLEANHTML);
60
8ea068a2 61// draft area
62$newdirname = optional_param('newdirname', '', PARAM_FILE);
af804e3e 63$newfilename = optional_param('newfilename', '', PARAM_FILE);
8ea068a2 64// path in draft area
65$draftpath = optional_param('draftpath', '/', PARAM_PATH);
66
67
68// user context
69$user_context = get_context_instance(CONTEXT_USER, $USER->id);
70
c33aa23b 71$PAGE->set_url('/repository/filepicker.php');
a14a933c
DC
72if (!$course = $DB->get_record('course', array('id'=>$courseid))) {
73 print_error('invalidcourseid');
74}
75$PAGE->set_course($course);
c33aa23b 76
761265ad 77// init repository plugin
8ea068a2 78//
761265ad 79$sql = 'SELECT i.name, i.typeid, r.type FROM {repository} r, {repository_instances} i '.
80 'WHERE i.id=? AND i.typeid=r.id';
009a97ce 81if ($repository = $DB->get_record_sql($sql, array($repo_id))) {
761265ad 82 $type = $repository->type;
e35194be
DC
83 if (file_exists($CFG->dirroot.'/repository/'.$type.'/lib.php')) {
84 require_once($CFG->dirroot.'/repository/'.$type.'/lib.php');
009a97ce 85 $classname = 'repository_' . $type;
86 try {
8ea068a2 87 $repo = new $classname($repo_id, $contextid, array('ajax'=>false, 'name'=>$repository->name));
009a97ce 88 } catch (repository_exception $e){
89 print_error('pluginerror', 'repository');
90 }
91 } else {
92 print_error('invalidplugin', 'repository');
761265ad 93 }
761265ad 94}
8ea068a2 95
64f93798 96$url = new moodle_url($CFG->httpswwwroot."/repository/filepicker.php", array('ctx_id' => $contextid, 'itemid' => $itemid, 'env' => $env, 'course'=>$courseid));
af804e3e 97$home_url = new moodle_url($url, array('action' => 'browse'));
b6fd5aee 98
14f3c882 99switch ($action) {
ab9cdbb9 100case 'upload':
009a97ce 101 // The uploaded file has been processed in plugin construct function
8ea068a2 102 // redirect to default page
9cbced1d 103 $repo->upload();
ab9cdbb9 104 redirect($url, get_string('uploadsucc','repository'));
105 break;
8ea068a2 106
14f3c882 107case 'deletedraft':
8ea068a2 108 $contextid = $user_context->id;
14f3c882 109 $fs = get_file_storage();
64f93798 110 if ($file = $fs->get_file($contextid, 'user', 'draft', $itemid, $draftpath, $filename)) {
af804e3e 111 if ($file->is_directory()) {
112 if ($file->get_parent_directory()) {
113 $draftpath = $file->get_parent_directory()->get_filepath();
114 } else {
115 $draftpath = '/';
116 }
117 }
14f3c882 118 if($result = $file->delete()) {
af804e3e 119 $url->param('draftpath', $draftpath);
120 $url->param('action', 'browse');
121 redirect($url);
14f3c882 122 } else {
b6fd5aee 123 print_error('cannotdelete', 'repository');
14f3c882 124 }
125 }
14f3c882 126 break;
8ea068a2 127
78ff2983 128case 'search':
c33aa23b 129 echo '<div><a href="' . $home_url->out() . '">'.get_string('back', 'repository')."</a></div>";
78ff2983 130 try {
131 $search_result = $repo->search($search_text);
132 $search_result['search_result'] = true;
133 $search_result['repo_id'] = $repo_id;
009a97ce 134
135 // TODO: need a better solution
ef3e1fbc 136 $purl = new moodle_url($url, array('search_paging' => 1, 'action' => 'search', 'repo_id' => $repo_id));
929d7a83
PS
137 $pagingbar = new paging_bar($search_result['total'], $search_result['page'] - 1, $search_result['perpage'], $purl, 'p');
138 echo $OUTPUT->render($pagingbar);
009a97ce 139
78ff2983 140 echo '<table>';
141 foreach ($search_result['list'] as $item) {
142 echo '<tr>';
143 echo '<td><img src="'.$item['thumbnail'].'" />';
144 echo '</td><td>';
145 if (!empty($item['url'])) {
146 echo '<a href="'.$item['url'].'" target="_blank">'.$item['title'].'</a>';
147 } else {
148 echo $item['title'];
149 }
150 echo '</td>';
151 echo '<td>';
009a97ce 152 echo '<form method="post">';
8ea068a2 153 echo '<input type="hidden" name="fileurl" value="'.$item['source'].'"/>';
009a97ce 154 echo '<input type="hidden" name="action" value="confirm"/>';
8ea068a2 155 echo '<input type="hidden" name="filename" value="'.$item['title'].'"/>';
156 echo '<input type="hidden" name="thumbnail" value="'.$item['thumbnail'].'"/>';
009a97ce 157 echo '<input type="submit" value="'.get_string('select','repository').'" />';
158 echo '</form>';
78ff2983 159 echo '</td>';
009a97ce 160 echo '</tr>';
78ff2983 161 }
162 echo '</table>';
163 } catch (repository_exception $e) {
164 }
165 break;
8ea068a2 166
14f3c882 167case 'list':
168case 'sign':
af804e3e 169 echo $OUTPUT->header();
c33aa23b 170 echo '<div><a href="' . $home_url->out() . '">'.get_string('back', 'repository')."</a></div>";
761265ad 171 if ($repo->check_login()) {
6f2cd52a 172 $list = $repo->get_listing($req_path, $curr_page);
761265ad 173 $dynload = !empty($list['dynload'])?true:false;
174 if (!empty($list['upload'])) {
47ce714b 175 echo '<form action="'.$url->out().'" method="post" enctype="multipart/form-data" style="display:inline">';
ab9cdbb9 176 echo '<label>'.$list['upload']['label'].': </label>';
761265ad 177 echo '<input type="file" name="repo_upload_file" /><br />';
ab9cdbb9 178 echo '<input type="hidden" name="action" value="upload" /><br />';
8ea068a2 179 echo '<input type="hidden" name="draftpath" value="'.$draftpath.'" /><br />';
ab9cdbb9 180 echo '<input type="hidden" name="repo_id" value="'.$repo_id.'" /><br />';
b6fd5aee 181 echo '<input type="submit" value="'.get_string('upload', 'repository').'" />';
761265ad 182 echo '</form>';
183 } else {
5e98ab96 184 if (!empty($list['path'])) {
185 foreach ($list['path'] as $p) {
186 echo '<form method="post" style="display:inline">';
187 echo '<input type="hidden" name="p" value="'.$p['path'].'"';
188 echo '<input type="hidden" name="action" value="list"';
8ea068a2 189 echo '<input type="hidden" name="draftpath" value="'.$draftpath.'" /><br />';
5e98ab96 190 echo '<input type="submit" value="'.$p['name'].'" />';
191 echo '</form>';
b6fd5aee 192 echo '<strong> / </strong>';
5e98ab96 193 }
761265ad 194 }
009a97ce 195 if (!empty($list['page'])) {
196 // TODO: need a better solution
a14a933c 197 $pagingurl = new moodle_url("$CFG->httpswwwroot/repository/filepicker.php?action=list&itemid=$itemid&ctx_id=$contextid&repo_id=$repo_id&course=$courseid");
929d7a83 198 echo $OUTPUT->paging_bar($list['total'], $list['page'] - 1, $list['perpage'], $pagingurl);
009a97ce 199 }
761265ad 200 echo '<table>';
201 foreach ($list['list'] as $item) {
202 echo '<tr>';
203 echo '<td><img src="'.$item['thumbnail'].'" />';
204 echo '</td><td>';
205 if (!empty($item['url'])) {
206 echo '<a href="'.$item['url'].'" target="_blank">'.$item['title'].'</a>';
207 } else {
208 echo $item['title'];
209 }
210 echo '</td>';
211 echo '<td>';
212 if (!isset($item['children'])) {
213 echo '<form method="post">';
8ea068a2 214 echo '<input type="hidden" name="fileurl" value="'.$item['source'].'"/>';
761265ad 215 echo '<input type="hidden" name="action" value="confirm"/>';
8ea068a2 216 echo '<input type="hidden" name="draftpath" value="'.$draftpath.'" /><br />';
217 echo '<input type="hidden" name="filename" value="'.$item['title'].'"/>';
218 echo '<input type="hidden" name="thumbnail" value="'.$item['thumbnail'].'"/>';
b6fd5aee 219 echo '<input type="submit" value="'.get_string('select','repository').'" />';
761265ad 220 echo '</form>';
221 } else {
222 echo '<form method="post">';
223 echo '<input type="hidden" name="p" value="'.$item['path'].'"/>';
b6fd5aee 224 echo '<input type="submit" value="'.get_string('enter', 'repository').'" />';
761265ad 225 echo '</form>';
226 }
227 echo '</td>';
009a97ce 228 echo '</tr>';
761265ad 229 }
230 echo '</table>';
231 }
232 } else {
233 echo '<form method="post">';
761265ad 234 echo '<input type="hidden" name="action" value="sign" />';
235 echo '<input type="hidden" name="repo_id" value="'.$repo_id.'" />';
78ff2983 236 $repo->print_login();
761265ad 237 echo '</form>';
238 }
6fd42112 239 echo $OUTPUT->footer();
14f3c882 240 break;
8ea068a2 241
14f3c882 242case 'download':
14469892
DC
243 $thefile = $repo->get_file($fileurl, $filename, $itemid);
244 if (!empty($thefile)) {
e5051df3
DC
245 $record = new stdclass;
246 $record->filepath = $draftpath;
247 $record->filename = $filename;
64f93798
PS
248 $record->component = 'user';
249 $record->filearea = 'draft';
e5051df3
DC
250 $record->itemid = $itemid;
251 $record->license = '';
252 $record->author = '';
253 $record->source = $thefile['url'];
254 $info = repository::move_to_filepool($thefile['path'], $record);
14f3c882 255 redirect($url, get_string('downloadsucc','repository'));
009a97ce 256 } else {
257 print_error('cannotdownload', 'repository');
14f3c882 258 }
259
260 break;
8ea068a2 261
af804e3e 262case 'downloaddir':
263 $zipper = new zip_packer();
264 $fs = get_file_storage();
265
64f93798 266 $file = $fs->get_file($user_context->id, 'user', 'draft', $itemid, $draftpath, '.');
af804e3e 267 if ($file->get_parent_directory()) {
268 $parent_path = $file->get_parent_directory()->get_filepath();
269 $filename = trim($draftpath, '/').'.zip';
270 } else {
271 $parent_path = '/';
b2c8e7a7 272 $filename = get_string('files').'.zip';
af804e3e 273 }
274
275 if ($newfile = $zipper->archive_to_storage(array($file), $user_context->id, 'user_draft', $itemid, $parent_path, $filename, $USER->id)) {
276 $fileurl = $CFG->wwwroot . '/draftfile.php/' . $user_context->id .'/user_draft/'.$itemid.$parent_path.$filename;
277 header('Location: ' . $fileurl );
278 } else {
279 print_error('cannotdownloaddir', 'repository');
280 }
281 break;
282
14f3c882 283case 'confirm':
af804e3e 284 echo $OUTPUT->header();
b6fd5aee 285 echo '<div><a href="'.me().'">'.get_string('back', 'repository').'</a></div>';
8ea068a2 286 echo '<img src="'.$thumbnail.'" />';
287 echo '<form method="post">';
288 echo '<table>';
289 echo ' <tr>';
290 echo ' <td><label>'.get_string('filename', 'repository').'</label></td>';
291 echo ' <td><input type="text" name="filename" value="'.$filename.'" /></td>';
292 echo ' <td><input type="hidden" name="fileurl" value="'.$fileurl.'" /></td>';
293 echo ' <td><input type="hidden" name="action" value="download" /></td>';
294 echo ' <td><input type="hidden" name="itemid" value="'.$itemid.'" /></td>';
295 echo ' </tr>';
14f3c882 296 echo '</table>';
297 echo '<div>';
8ea068a2 298 // the save path
299 echo ' <input name="draftpath" type="hidden" value="'.$draftpath.'" />';
300 echo ' <input type="submit" value="'.get_string('download', 'repository').'" />';
14f3c882 301 echo '</div>';
302 echo '</form>';
6fd42112 303 echo $OUTPUT->footer();
14f3c882 304 break;
8ea068a2 305
ab9cdbb9 306case 'plugins':
307 $user_context = get_context_instance(CONTEXT_USER, $USER->id);
6f2cd52a
DC
308 $params = array();
309 $params['context'] = array($user_context, get_system_context());
310 $params['currentcontext'] = $PAGE->context;
311 $params['returntypes'] = 2;
312 $repos = repository::get_instances($params);
af804e3e 313 echo $OUTPUT->header();
8ea068a2 314 echo '<div><a href="' . $home_url->out() . '">'.get_string('back', 'repository')."</a></div>";
315 echo '<div>';
316 echo '<ul>';
ab9cdbb9 317 foreach($repos as $repo) {
318 $info = $repo->get_meta();
8ae8bf8a
PS
319
320 $aurl = clone($url);
321 $aurl->params(array('action' => 'list', 'repo_id' => $info->id, 'draftpath'=>$draftpath));
322
f0e5f031 323 if ($env == 'filemanager' && $info->type == 'draft') {
324 continue;
325 }
e5051df3
DC
326 echo '<li>';
327 echo html_writer::link($aurl, $info->name);
328 echo '</li>';
ab9cdbb9 329 }
8ea068a2 330 echo '</ul>';
331 echo '</div>';
332 echo $OUTPUT->footer();
333 break;
334
8ea068a2 335case 'zip':
336 $zipper = new zip_packer();
337 $fs = get_file_storage();
338
64f93798 339 $file = $fs->get_file($user_context->id, 'user', 'draft', $itemid, $draftpath, '.');
8ea068a2 340 if (!$file->get_parent_directory()) {
341 $parent_path = '/';
342 } else {
343 $parent_path = $file->get_parent_directory()->get_filepath();
344 }
345
64f93798 346 $newfile = $zipper->archive_to_storage(array($file), $user_context->id, 'user', 'draft', $itemid, $parent_path, $file->get_filepath().'.zip', $USER->id);
8ea068a2 347
348 $url->param('action', 'browse');
349 $url->param('draftpath', $parent_path);
350 redirect($url, get_string('ziped','repository'));
351 break;
352
353case 'unzip':
354 $zipper = new zip_packer();
355 $fs = get_file_storage();
64f93798 356 $file = $fs->get_file($user_context->id, 'user', 'draft', $itemid, $draftpath, $filename);
8ea068a2 357
64f93798 358 if ($newfile = $file->extract_to_storage($zipper, $user_context->id, 'user', 'draft', $itemid, $draftpath, $USER->id)) {
8ea068a2 359 $str = get_string('unziped','repository');
360 } else {
361 $str = get_string('cannotunzip', 'repository');
362 }
363 $url->param('action', 'browse');
364 $url->param('draftpath', $draftpath);
365 redirect($url, $str);
366 break;
367
af804e3e 368case 'movefile':
369 if (!empty($targetpath)) {
370 $fb = get_file_browser();
64f93798
PS
371 $file = $fb->get_file_info($user_context, 'user', 'draft', $itemid, $draftpath, $filename);
372 $file->copy_to_storage($user_context->id, 'user', 'draft', $itemid, $targetpath, $filename);
af804e3e 373 if ($file->delete()) {
374 $url->param('action', 'browse');
375 $url->param('draftpath', $targetpath);
376 redirect($url, '');
377 exit;
378 }
379 }
380 echo $OUTPUT->header();
381 echo '<div><a href="' . $home_url->out() . '">'.get_string('back', 'repository')."</a></div>";
382 $data = new stdclass;
383 $url->param('action', 'movefile');
384 $url->param('draftpath', $draftpath);
385 $url->param('filename', $filename);
64f93798 386 file_get_drafarea_folders($itemid, '/', $data);
af804e3e 387 print_draft_area_tree($data, true, $url);
388 echo $OUTPUT->footer();
389 break;
390case 'mkdirform':
391 echo $OUTPUT->header();
392 echo '<div><a href="' . $home_url->out() . '">'.get_string('back', 'repository')."</a></div>";
393 $url->param('draftpath', $draftpath);
394 $url->param('action', 'mkdir');
395 echo ' <form method="post" action="'.$url->out().'">';
396 echo ' <input name="newdirname" type="text" />';
397 echo ' <input name="draftpath" type="hidden" value="'.$draftpath.'" />';
398 echo ' <input type="submit" value="'.get_string('makeafolder', 'moodle').'" />';
399 echo ' </form>';
400 echo $OUTPUT->footer();
401 break;
8ea068a2 402
af804e3e 403case 'mkdir':
404 $fs = get_file_storage();
64f93798 405 $fs->create_directory($user_context->id, 'user', 'draft', $itemid, file_correct_filepath(file_correct_filepath($draftpath).trim($newdirname, '/')));
af804e3e 406 $url->param('action', 'browse');
407 $url->param('draftpath', $draftpath);
408 if (!empty($newdirname)) {
409 $str = get_string('createfoldersuccess', 'repository');
410 } else {
411 $str = get_string('createfolderfail', 'repository');
412 }
413 redirect($url, $str);
414 break;
415
416case 'rename':
417 $fs = get_file_storage();
64f93798 418 if ($file = $fs->get_file($user_context->id, 'user', 'draft', $itemid, $draftpath, $filename)) {
af804e3e 419 if ($file->is_directory()) {
420 if ($file->get_parent_directory()) {
421 $draftpath = $file->get_parent_directory()->get_filepath();
422 } else {
423 $draftpath = '/';
8ea068a2 424 }
af804e3e 425 // use file storage to create new folder
426 $newdir = $draftpath . trim($newfilename , '/') . '/';
64f93798 427 $fs->create_directory($user_context->id, 'user', 'draft', $itemid, $newdir);
af804e3e 428 } else {
429 // use file browser to copy file
430 $fb = get_file_browser();
64f93798
PS
431 $file = $fb->get_file_info($user_context, 'user', 'draft', $itemid, $draftpath, $filename);
432 $file->copy_to_storage($user_context->id, 'user', 'draft', $itemid, $draftpath, $newfilename);
8ea068a2 433 }
434 }
af804e3e 435 $file->delete();
436 $url->param('action', 'browse');
437 $url->param('draftpath', $draftpath);
438 redirect($url);
439 break;
8ea068a2 440
af804e3e 441case 'renameform':
442 echo $OUTPUT->header();
443 echo '<div><a href="' . $home_url->out() . '">'.get_string('back', 'repository')."</a></div>";
444 $url->param('draftpath', $draftpath);
445 $url->param('action', 'rename');
446 echo ' <form method="post" action="'.$url->out().'">';
447 echo ' <input name="newfilename" type="text" value="'.$filename.'" />';
448 echo ' <input name="filename" type="hidden" value="'.$filename.'" />';
449 echo ' <input name="draftpath" type="hidden" value="'.$draftpath.'" />';
450 echo ' <input type="submit" value="'.get_string('rename', 'moodle').'" />';
451 echo ' </form>';
452 echo $OUTPUT->footer();
453 break;
8ea068a2 454
af804e3e 455case 'browse':
456default:
457 $user_context = get_context_instance(CONTEXT_USER, $USER->id);
6f2cd52a
DC
458 $params = array();
459 $params['context'] = array($user_context, get_system_context());
460 $params['currentcontext'] = $PAGE->context;
461 $params['returntypes'] = 2;
462 $repos = repository::get_instances($params);
b6fd5aee 463 $fs = get_file_storage();
64f93798 464 $files = $fs->get_directory_files($user_context->id, 'user', 'draft', $itemid, $draftpath, false);
8ea068a2 465
af804e3e 466 echo $OUTPUT->header();
4ba3169d 467 if ((!empty($files) or $draftpath != '/') and $env == 'filemanager') {
af804e3e 468 echo '<div class="fm-breadcrumb">';
469 $url->param('action', 'browse');
470 $url->param('draftpath', '/');
471 echo '<a href="'.$url->out().'">'.'Files</a> ▶';
472 $trail = '';
473 if ($draftpath !== '/') {
474 $path = file_correct_filepath($draftpath);
475 $parts = explode('/', $path);
476 foreach ($parts as $part) {
477 if (!empty($part)) {
478 $trail .= ('/'.$part.'/');
479 $data->path[] = array('name'=>$part, 'path'=>$trail);
480 $url->param('draftpath', $trail);
481 echo ' <a href="'.$url->out().'">'.$part.'</a> ▶ ';
482 }
483 }
484 }
485 echo '</div>';
486 }
8ea068a2 487
af804e3e 488 $url->param('draftpath', $draftpath);
489 $url->param('action', 'plugins');
490 echo '<div class="filemanager-toolbar">';
4ba3169d 491 if ($env == 'filepicker' and sizeof($files) > 0) {
492 } else {
493 echo ' <a href="'.$url->out().'">'.get_string('addfile', 'repository').'</a>';
494 }
495 if ($env == 'filemanager') {
496 $url->param('action', 'mkdirform');
497 echo ' <a href="'.$url->out().'">'.get_string('makeafolder', 'moodle').'</a>';
498 $url->param('action', 'downloaddir');
499 echo ' <a href="'.$url->out().'" target="_blank">'.get_string('downloadfolder', 'repository').'</a>';
500 }
af804e3e 501 echo '</div>';
502
503 if (!empty($files)) {
b6fd5aee 504 echo '<ul>';
505 foreach ($files as $file) {
64f93798 506 $drafturl = new moodle_url($CFG->httpswwwroot.'/draftfile.php/'.$user_context->id.'/user/draft/'.$itemid.'/'.$file->get_filename());
af804e3e 507 if ($file->get_filename() != '.') {
8ea068a2 508 // a file
509 $fileicon = $CFG->wwwroot.'/pix/'.(file_extension_icon($file->get_filename()));
510 $type = str_replace('.gif', '', mimeinfo('icon', $file->get_filename()));
511 echo '<li>';
512 echo '<img src="'.$fileicon. '" class="iconsmall" />';
513 echo ' <a href="'.$drafturl->out().'">'.$file->get_filename().'</a> ';
514
515 $url->param('filename', $file->get_filename());
af804e3e 516
8ea068a2 517 $url->param('action', 'deletedraft');
af804e3e 518 $url->param('draftpath', $file->get_filepath());
519 echo ' [<a href="'.$url->out().'" class="fm-operation">'.get_string('delete').'</a>]';
520
521 $url->param('action', 'movefile');
522 echo ' [<a href="'.$url->out().'" class="fm-operation">'.get_string('move').'</a>]';
523
524 $url->param('action', 'renameform');
525 echo ' [<a href="'.$url->out().'" class="fm-operation">'.get_string('rename').'</a>]';
8ea068a2 526
527 if ($type == 'zip') {
528 $url->param('action', 'unzip');
529 $url->param('draftpath', $file->get_filepath());
af804e3e 530 echo ' [<a href="'.$url->out().'" class="fm-operation">'.get_string('unzip').'</a>]';
8ea068a2 531 }
532
533 echo '</li>';
534 } else {
535 // a folder
536 echo '<li>';
b5d0cafc 537 echo '<img src="'.$OUTPUT->pix_url('f/folder') . '" class="iconsmall" />';
8ea068a2 538
539 $url->param('action', 'browse');
540 $url->param('draftpath', $file->get_filepath());
541 $foldername = trim(array_pop(explode('/', trim($file->get_filepath(), '/'))), '/');
542 echo ' <a href="'.$url->out().'">'.$foldername.'</a>';
543
544 $url->param('draftpath', $file->get_filepath());
545 $url->param('filename', $file->get_filename());
546 $url->param('action', 'deletedraft');
af804e3e 547 echo ' [<a href="'.$url->out().'" class="fm-operation">'.get_string('delete').'</a>]';
548
549 // file doesn't support rename yet
550 // for folder with existing files, we need to move these files one by one
551 //$url->param('action', 'renameform');
552 //echo ' [<a href="'.$url->out().'" class="fm-operation">'.get_string('rename').'</a>]';
8ea068a2 553
554 $url->param('action', 'zip');
af804e3e 555 echo ' [<a href="'.$url->out().'" class="fm-operation">Zip</a>]';
8ea068a2 556 echo '</li>';
b6fd5aee 557 }
558 }
559 echo '</ul>';
af804e3e 560 } else {
561 //echo get_string('nofilesattached', 'repository');
b6fd5aee 562 }
6fd42112 563 echo $OUTPUT->footer();
14f3c882 564 break;
761265ad 565}
af804e3e 566function print_draft_area_tree($tree, $root, $url) {
567 echo '<ul>';
568 if ($root) {
569 $url->param('targetpath', '/');
570 if ($url->param('draftpath') == '/') {
571 echo '<li>'.get_string('files').'</li>';
572 } else {
573 echo '<li><a href="'.$url->out().'">'.get_string('files').'</a></li>';
574 }
575 echo '<ul>';
576 if (isset($tree->children)) {
577 $tree = $tree->children;
578 }
579 }
580
581 if (!empty($tree)) {
582 foreach ($tree as $node) {
583 echo '<li>';
584 $url->param('targetpath', $node->filepath);
585 if ($url->param('draftpath') != $node->filepath) {
586 echo '<a href="'.$url->out().'">'.$node->fullname.'</a>';
587 } else {
588 echo $node->fullname;
589 }
590 echo '</li>';
591 if (!empty($node->children)) {
592 print_draft_area_tree($node->children, false, $url);
593 }
594 }
595 }
596 if ($root) {
597 echo '</ul>';
598 }
af804e3e 599 echo '</ul>';
600}
601