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