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