3 // Manage all uploaded files in a course file area
5 // All the Moodle-specific stuff is in this top section
6 // Configuration and access control occurs here.
7 // Must define: USER, basedir, baseweb, html_header and html_footer
8 // USER is a persistent variable using sessions
10 require('../config.php');
11 require_once($CFG->libdir
. '/filelib.php');
12 require_once($CFG->libdir
. '/adminlib.php');
14 $id = required_param('id', PARAM_INT
);
15 $file = optional_param('file', '', PARAM_PATH
);
16 $wdir = optional_param('wdir', '', PARAM_PATH
);
17 $action = optional_param('action', '', PARAM_ACTION
);
18 $name = optional_param('name', '', PARAM_FILE
);
19 $oldname = optional_param('oldname', '', PARAM_FILE
);
20 $choose = optional_param('choose', '', PARAM_FILE
); //in fact it is always 'formname.inputname'
21 $userfile= optional_param('userfile','',PARAM_FILE
);
22 $save = optional_param('save', 0, PARAM_BOOL
);
23 $text = optional_param('text', '', PARAM_RAW
);
24 $confirm = optional_param('confirm', 0, PARAM_BOOL
);
27 if (count(explode('.', $choose)) > 2) {
28 error('Incorrect format for choose parameter');
33 if (! $course = get_record("course", "id", $id) ) {
34 error("That's an invalid course id");
37 require_login($course);
39 require_capability('moodle/course:managefiles', get_context_instance(CONTEXT_COURSE
, $course->id
));
41 function html_footer() {
42 global $COURSE, $choose;
44 echo '</td></tr></table>';
46 print_footer($COURSE);
49 function html_header($course, $wdir, $formfield=""){
50 global $CFG, $ME, $choose;
53 // $navlinks[] = array('name' => $course->shortname, 'link' => "../course/view.php?id=$course->id", 'type' => 'misc');
55 if ($course->id
== SITEID
) {
56 $strfiles = get_string("sitefiles");
58 $strfiles = get_string("files");
62 $navlinks[] = array('name' => $strfiles, 'link' => null, 'type' => 'misc');
64 $dirs = explode("/", $wdir);
65 $numdirs = count($dirs);
67 $navlinks[] = array('name' => $strfiles,
68 'link' => $ME."?id=$course->id&wdir=/&choose=$choose",
71 for ($i=1; $i<$numdirs-1; $i++
) {
72 $link .= "/".urlencode($dirs[$i]);
73 $navlinks[] = array('name' => $dirs[$i],
74 'link' => $ME."?id=$course->id&wdir=$link&choose=$choose",
77 $navlinks[] = array('name' => $dirs[$numdirs-1], 'link' => null, 'type' => 'misc');
80 $navigation = build_navigation($navlinks);
85 $chooseparts = explode('.', $choose);
86 if (count($chooseparts)==2){
88 <script type
="text/javascript">
90 function set_value(txt
) {
91 opener
.document
.forms
['<?php echo $chooseparts[0]."'].".$chooseparts[1] ?>.value = txt;
98 } elseif (count($chooseparts)==1){
100 <script type="text
/javascript
">
102 function set_value(txt) {
103 opener.document.getElementById('<?php echo $chooseparts[0] ?>').value = txt;
114 foreach ($navlinks as $navlink) {
115 // If this is the last link do not link
116 if ($i == count($navlinks) - 1) {
117 $fullnav .= $navlink['name'];
119 $fullnav .= '<a href="'.$navlink['link
'].'">'.$navlink['name'].'</a>';
124 $fullnav = substr($fullnav, 0, -4);
125 $fullnav = str_replace('->', '»', format_string($course->shortname) . " -> " . $fullnav);
126 echo '<div id="nav
-bar
">'.$fullnav.'</div>';
128 if ($course->id == SITEID and $wdir != "/backupdata
") {
129 print_heading(get_string("publicsitefileswarning3
"), "center
", 2);
134 if ($course->id == SITEID) {
136 if ($wdir == "/backupdata
") {
137 admin_externalpage_setup('frontpagerestore');
138 admin_externalpage_print_header();
140 admin_externalpage_setup('sitefiles');
141 admin_externalpage_print_header();
143 print_heading(get_string("publicsitefileswarning3
"), "center
", 2);
148 print_header("$course->shortname
: $strfiles", $course->fullname, $navigation, $formfield);
153 echo "<table border
=\"0\" style
=\"margin
-left
:auto
;margin
-right
:auto\" cellspacing
=\"3\" cellpadding
=\"3\" width
=\"640\">";
155 echo "<td colspan
=\"2\">";
160 if (! $basedir = make_upload_directory("$course->id
")) {
161 error("The site administrator needs to fix the file permissions
");
164 // make sure site files contain the backupdata or else people put backups into public area!!
165 if ($course->id == SITEID) {
166 if (!file_exists("$CFG->dataroot
/$course->id
/backupdata
")) {
167 make_upload_directory("$course->id
/backupdata
");
171 $baseweb = $CFG->wwwroot;
173 // End of configuration and access control
180 if ($wdir{0} != '/') { //make sure $wdir starts with slash
184 if ($wdir == "/backupdata
") {
185 if (! make_upload_directory("$course->id
/backupdata
")) { // Backup folder
186 error("Could not create backupdata folder
. The site administrator needs to fix the file permissions
");
190 if (!is_dir($basedir.$wdir)) {
191 html_header($course, $wdir);
192 error("Requested directory does not exist
.", "$CFG->wwwroot
/files
/index
.php?id
=$id");
198 html_header($course, $wdir);
199 require_once($CFG->dirroot.'/lib/uploadlib.php');
201 if ($save and confirm_sesskey()) {
202 $course->maxbytes = 0; // We are ignoring course limits
203 $um = new upload_manager('userfile',false,false,$course,false,0);
204 $dir = "$basedir$wdir";
205 if ($um->process_file_uploads($dir)) {
206 notify(get_string('uploadedfile'));
208 // um will take care of error reporting.
211 $upload_max_filesize = get_max_upload_file_size($CFG->maxbytes);
212 $filesize = display_size($upload_max_filesize);
214 $struploadafile = get_string("uploadafile
");
215 $struploadthisfile = get_string("uploadthisfile
");
216 $strmaxsize = get_string("maxsize
", "", $filesize);
217 $strcancel = get_string("cancel
");
219 echo "<p
>$struploadafile ($strmaxsize) --> <b
>$wdir</b
></p
>";
220 echo "<form enctype
=\"multipart
/form
-data\" method
=\"post\" action
=\"index
.php\"
>";
222 echo "<table
><tr
><td colspan
=\"2\">";
223 echo ' <input type="hidden
" name="choose
" value="'.$choose.'" />';
224 echo " <input type
=\"hidden\" name
=\"id\" value
=\"$id\" />";
225 echo " <input type
=\"hidden\" name
=\"wdir\" value
=\"$wdir\" />";
226 echo " <input type
=\"hidden\" name
=\"action\" value
=\"upload\"
/>";
227 echo " <input type
=\"hidden\" name
=\"sesskey\" value
=\"$USER->sesskey\"
/>";
228 upload_print_form_fragment(1,array('userfile'),null,false,null,$upload_max_filesize,0,false);
229 echo " </td
></tr
></table
>";
230 echo " <input type
=\"submit\" name
=\"save\" value
=\"$struploadthisfile\" />";
233 echo "<form action
=\"index
.php\" method
=\"get\"
>";
235 echo ' <input type="hidden
" name="choose
" value="'.$choose.'" />';
236 echo " <input type
=\"hidden\" name
=\"id\" value
=\"$id\" />";
237 echo " <input type
=\"hidden\" name
=\"wdir\" value
=\"$wdir\" />";
238 echo " <input type
=\"hidden\" name
=\"action\" value
=\"cancel\"
/>";
239 echo " <input type
=\"submit\" value
=\"$strcancel\" />";
247 if ($confirm and confirm_sesskey()) {
248 html_header($course, $wdir);
249 if (!empty($USER->filelist)) {
250 foreach ($USER->filelist as $file) {
251 $fullfile = $basedir.'/'.$file;
252 if (! fulldelete($fullfile)) {
253 echo "<br
/>Error
: Could not delete
: $fullfile";
262 html_header($course, $wdir);
264 if (setfilelist($_POST)) {
265 notify(get_string('deletecheckwarning').':');
266 print_simple_box_start("center
");
267 printfilelist($USER->filelist);
268 print_simple_box_end();
271 require_once($CFG->dirroot.'/mod/resource/lib.php');
272 $block = resource_delete_warning($course, $USER->filelist);
274 if (empty($CFG->resource_blockdeletingfile) or $block == '') {
275 $optionsyes = array('id'=>$id, 'wdir'=>$wdir, 'action'=>'delete', 'confirm'=>1, 'sesskey'=>sesskey(), 'choose'=>$choose);
276 $optionsno = array('id'=>$id, 'wdir'=>$wdir, 'action'=>'cancel', 'choose'=>$choose);
277 notice_yesno (get_string('deletecheckfiles'), 'index.php', 'index.php', $optionsyes, $optionsno, 'post', 'get');
280 notify(get_string('warningblockingdelete', 'resource'));
281 $options = array('id'=>$id, 'wdir'=>$wdir, 'action'=>'cancel', 'choose'=>$choose);
282 print_continue("index
.php?id
=$id&
;wdir
=$wdir&
;action
=cancel
&
;choose
=$choose");
292 html_header($course, $wdir);
293 if (($count = setfilelist($_POST)) and confirm_sesskey()) {
294 $USER->fileop = $action;
295 $USER->filesource = $wdir;
296 echo "<p
class=\"centerpara\"
>";
297 print_string("selectednowmove
", "moodle
", $count);
305 html_header($course, $wdir);
306 if (isset($USER->fileop) and ($USER->fileop == "move
") and confirm_sesskey()) {
307 foreach ($USER->filelist as $file) {
308 $shortfile = basename($file);
309 $oldfile = $basedir.'/'.$file;
310 $newfile = $basedir.$wdir."/".$shortfile;
311 if (!rename($oldfile, $newfile)) {
312 echo "<p
>Error
: $shortfile not moved
</p
>";
322 if (($name != '') and confirm_sesskey()) {
323 html_header($course, $wdir);
324 $name = clean_filename($name);
325 if (file_exists($basedir.$wdir."/".$name)) {
326 echo "<center
>Error
: $name already exists
!</center
>";
327 } else if (!rename($basedir.$wdir."/".$oldname, $basedir.$wdir."/".$name)) {
328 echo "<p align
=\"center\"
>Error
: could not rename
$oldname to
$name</p
>";
330 //file was renamed now update resources if needed
331 require_once($CFG->dirroot.'/mod/resource/lib.php');
332 resource_renamefiles($course, $wdir, $oldname, $name);
337 $strrename = get_string("rename
");
338 $strcancel = get_string("cancel
");
339 $strrenamefileto = get_string("renamefileto
", "moodle
", $file);
340 html_header($course, $wdir, "form
.name
");
341 echo "<p
>$strrenamefileto:</p
>";
342 echo "<table
><tr
><td
>";
343 echo "<form action
=\"index
.php\" method
=\"post\"
>";
344 echo "<fieldset
class=\"invisiblefieldset\"
>";
345 echo ' <input type="hidden
" name="choose
" value="'.$choose.'" />';
346 echo " <input type
=\"hidden\" name
=\"id\" value
=\"$id\" />";
347 echo " <input type
=\"hidden\" name
=\"wdir\" value
=\"$wdir\" />";
348 echo " <input type
=\"hidden\" name
=\"action\" value
=\"rename\"
/>";
349 echo " <input type
=\"hidden\" name
=\"oldname\" value
=\"$file\" />";
350 echo " <input type
=\"hidden\" name
=\"sesskey\" value
=\"$USER->sesskey\"
/>";
351 echo " <input type
=\"text\" name
=\"name\" size
=\"35\" value
=\"$file\" />";
352 echo " <input type
=\"submit\" value
=\"$strrename\" />";
356 echo "<form action
=\"index
.php\" method
=\"get\"
>";
358 echo ' <input type="hidden
" name="choose
" value="'.$choose.'" />';
359 echo " <input type
=\"hidden\" name
=\"id\" value
=\"$id\" />";
360 echo " <input type
=\"hidden\" name
=\"wdir\" value
=\"$wdir\" />";
361 echo " <input type
=\"hidden\" name
=\"action\" value
=\"cancel\"
/>";
362 echo " <input type
=\"submit\" value
=\"$strcancel\" />";
365 echo "</td
></tr
></table
>";
371 if (($name != '') and confirm_sesskey()) {
372 html_header($course, $wdir);
373 $name = clean_filename($name);
374 if (file_exists("$basedir$wdir/$name")) {
375 echo "Error
: $name already exists
!";
376 } else if (! make_upload_directory("$course->id
$wdir/$name")) {
377 echo "Error
: could not create
$name";
382 $strcreate = get_string("create
");
383 $strcancel = get_string("cancel
");
384 $strcreatefolder = get_string("createfolder
", "moodle
", $wdir);
385 html_header($course, $wdir, "form
.name
");
386 echo "<p
>$strcreatefolder:</p
>";
387 echo "<table
><tr
><td
>";
388 echo "<form action
=\"index
.php\" method
=\"post\"
>";
389 echo "<fieldset
class=\"invisiblefieldset\"
>";
390 echo ' <input type="hidden
" name="choose
" value="'.$choose.'" />';
391 echo " <input type
=\"hidden\" name
=\"id\" value
=\"$id\" />";
392 echo " <input type
=\"hidden\" name
=\"wdir\" value
=\"$wdir\" />";
393 echo " <input type
=\"hidden\" name
=\"action\" value
=\"makedir\"
/>";
394 echo " <input type
=\"text\" name
=\"name\" size
=\"35\" />";
395 echo " <input type
=\"hidden\" name
=\"sesskey\" value
=\"$USER->sesskey\"
/>";
396 echo " <input type
=\"submit\" value
=\"$strcreate\" />";
400 echo "<form action
=\"index
.php\" method
=\"get\"
>";
402 echo ' <input type="hidden
" name="choose
" value="'.$choose.'" />';
403 echo " <input type
=\"hidden\" name
=\"id\" value
=\"$id\" />";
404 echo " <input type
=\"hidden\" name
=\"wdir\" value
=\"$wdir\" />";
405 echo " <input type
=\"hidden\" name
=\"action\" value
=\"cancel\"
/>";
406 echo " <input type
=\"submit\" value
=\"$strcancel\" />";
409 echo "</td
></tr
></table
>";
415 html_header($course, $wdir);
416 if (($text != '') and confirm_sesskey()) {
417 $fileptr = fopen($basedir.'/'.$file,"w
");
418 $text = preg_replace('/\x0D/', '', $text); // http://moodle.org/mod/forum/discuss.php?d=38860
419 fputs($fileptr, stripslashes($text));
424 $streditfile = get_string("edit
", "", "<b
>$file</b
>");
425 $fileptr = fopen($basedir.'/'.$file, "r
");
426 $contents = fread($fileptr, filesize($basedir.'/'.$file));
429 if (mimeinfo("type
", $file) == "text
/html
") {
430 $usehtmleditor = can_use_html_editor();
432 $usehtmleditor = false;
434 $usehtmleditor = false; // Always keep it off for now
436 print_heading("$streditfile");
438 echo "<table
><tr
><td colspan
=\"2\">";
439 echo "<form action
=\"index
.php\" method
=\"post\"
>";
441 echo ' <input type="hidden
" name="choose
" value="'.$choose.'" />';
442 echo " <input type
=\"hidden\" name
=\"id\" value
=\"$id\" />";
443 echo " <input type
=\"hidden\" name
=\"wdir\" value
=\"$wdir\" />";
444 echo " <input type
=\"hidden\" name
=\"file\" value
=\"$file\" />";
445 echo " <input type
=\"hidden\" name
=\"action\" value
=\"edit\"
/>";
446 echo " <input type
=\"hidden\" name
=\"sesskey\" value
=\"$USER->sesskey\"
/>";
447 print_textarea($usehtmleditor, 25, 80, 680, 400, "text
", $contents);
448 echo "</td
></tr
><tr
><td
>";
449 echo " <input type
=\"submit\" value
=\"".get_string("savechanges
")."\"
/>";
453 echo "<form action
=\"index
.php\" method
=\"get\"
>";
455 echo ' <input type="hidden
" name="choose
" value="'.$choose.'" />';
456 echo " <input type
=\"hidden\" name
=\"id\" value
=\"$id\" />";
457 echo " <input type
=\"hidden\" name
=\"wdir\" value
=\"$wdir\" />";
458 echo " <input type
=\"hidden\" name
=\"action\" value
=\"cancel\"
/>";
459 echo " <input type
=\"submit\" value
=\"".get_string("cancel
")."\"
/>";
462 echo "</td
></tr
></table
>";
464 if ($usehtmleditor) {
474 if (($name != '') and confirm_sesskey()) {
475 html_header($course, $wdir);
476 $name = clean_filename($name);
479 foreach ($USER->filelist as $file) {
480 $files[] = "$basedir/$file";
483 if (!zip_files($files,"$basedir$wdir/$name")) {
484 print_error("zipfileserror
","error
");
491 html_header($course, $wdir, "form
.name
");
493 if (setfilelist($_POST)) {
494 echo "<p align
=\"center\"
>".get_string("youareabouttocreatezip
").":</p
>";
495 print_simple_box_start("center
");
496 printfilelist($USER->filelist);
497 print_simple_box_end();
499 echo "<p align
=\"center\"
>".get_string("whattocallzip
")."</p
>";
500 echo "<table
><tr
><td
>";
501 echo "<form action
=\"index
.php\" method
=\"post\"
>";
502 echo "<fieldset
class=\"invisiblefieldset\"
>";
503 echo ' <input type="hidden
" name="choose
" value="'.$choose.'" />';
504 echo " <input type
=\"hidden\" name
=\"id\" value
=\"$id\" />";
505 echo " <input type
=\"hidden\" name
=\"wdir\" value
=\"$wdir\" />";
506 echo " <input type
=\"hidden\" name
=\"action\" value
=\"zip\"
/>";
507 echo " <input type
=\"text\" name
=\"name\" size
=\"35\" value
=\"new.zip\"
/>";
508 echo " <input type
=\"hidden\" name
=\"sesskey\" value
=\"$USER->sesskey\"
/>";
509 echo " <input type
=\"submit\" value
=\"".get_string("createziparchive
")."\"
/>";
513 echo "<form action
=\"index
.php\" method
=\"get\"
>";
515 echo ' <input type="hidden
" name="choose
" value="'.$choose.'" />';
516 echo " <input type
=\"hidden\" name
=\"id\" value
=\"$id\" />";
517 echo " <input type
=\"hidden\" name
=\"wdir\" value
=\"$wdir\" />";
518 echo " <input type
=\"hidden\" name
=\"action\" value
=\"cancel\"
/>";
519 echo " <input type
=\"submit\" value
=\"".get_string("cancel
")."\"
/>";
522 echo "</td
></tr
></table
>";
532 html_header($course, $wdir);
533 if (($file != '') and confirm_sesskey()) {
534 $strok = get_string("ok
");
535 $strunpacking = get_string("unpacking
", "", $file);
537 echo "<p align
=\"center\"
>$strunpacking:</p
>";
539 $file = basename($file);
541 if (!unzip_file("$basedir$wdir/$file")) {
542 print_error("unzipfileserror
","error
");
545 echo "<div style
=\"text
-align
:center\"
><form action
=\"index
.php\" method
=\"get\"
>";
547 echo ' <input type="hidden
" name="choose
" value="'.$choose.'" />';
548 echo " <input type
=\"hidden\" name
=\"id\" value
=\"$id\" />";
549 echo " <input type
=\"hidden\" name
=\"wdir\" value
=\"$wdir\" />";
550 echo " <input type
=\"hidden\" name
=\"action\" value
=\"cancel\"
/>";
551 echo " <input type
=\"submit\" value
=\"$strok\" />";
562 html_header($course, $wdir);
563 if (($file != '') and confirm_sesskey()) {
564 $strname = get_string("name
");
565 $strsize = get_string("size
");
566 $strmodified = get_string("modified
");
567 $strok = get_string("ok
");
568 $strlistfiles = get_string("listfiles
", "", $file);
570 echo "<p align
=\"center\"
>$strlistfiles:</p
>";
571 $file = basename($file);
573 include_once("$CFG->libdir
/pclzip
/pclzip
.lib
.php
");
574 $archive = new PclZip(cleardoubleslashes("$basedir$wdir/$file"));
575 if (!$list = $archive->listContent(cleardoubleslashes("$basedir$wdir"))) {
576 notify($archive->errorInfo(true));
579 echo "<table cellpadding
=\"4\" cellspacing
=\"2\" border
=\"0\" width
=\"640\" class=\"files\"
>";
580 echo "<tr
class=\"file\"
><th align
=\"left\"
class=\"header name\" scope
=\"col\"
>$strname</th
><th align
=\"right\"
class=\"header size\" scope
=\"col\"
>$strsize</th
><th align
=\"right\"
class=\"header date\" scope
=\"col\"
>$strmodified</th
></tr
>";
581 foreach ($list as $item) {
583 print_cell("left
", s($item['filename']), 'name');
584 if (! $item['folder']) {
585 print_cell("right
", display_size($item['size']), 'size');
587 echo "<td
> 
;</td
>";
589 $filedate = userdate($item['mtime'], get_string("strftimedatetime
"));
590 print_cell("right
", $filedate, 'date');
595 echo "<br
/><center
><form action
=\"index
.php\" method
=\"get\"
>";
597 echo ' <input type="hidden
" name="choose
" value="'.$choose.'" />';
598 echo " <input type
=\"hidden\" name
=\"id\" value
=\"$id\" />";
599 echo " <input type
=\"hidden\" name
=\"wdir\" value
=\"$wdir\" />";
600 echo " <input type
=\"hidden\" name
=\"action\" value
=\"cancel\"
/>";
601 echo " <input type
=\"submit\" value
=\"$strok\" />";
612 html_header($course, $wdir);
613 if (($file != '') and confirm_sesskey()) {
614 echo "<p align
=\"center\"
>".get_string("youaregoingtorestorefrom
").":</p
>";
615 print_simple_box_start("center
");
617 print_simple_box_end();
619 echo "<p align
=\"center\"
>".get_string("areyousuretorestorethisinfo
")."</p
>";
620 $restore_path = "$CFG->wwwroot
/backup
/restore
.php
";
621 notice_yesno (get_string("areyousuretorestorethis
"),
622 $restore_path."?id
=".$id."&
;file
=".cleardoubleslashes($id.$wdir."/".$file)."&
;method
=manual
",
623 "index
.php?id
=$id&
;wdir
=$wdir&
;action
=cancel
");
634 html_header($course, $wdir);
641 /// FILE FUNCTIONS ///////////////////////////////////////////////////////////
644 function setfilelist($VARS) {
647 $USER->filelist = array ();
651 foreach ($VARS as $key => $val) {
652 if (substr($key,0,4) == "file
") {
654 $val = rawurldecode($val);
655 $USER->filelist[] = clean_param($val, PARAM_PATH);
661 function clearfilelist() {
664 $USER->filelist = array ();
669 function printfilelist($filelist) {
670 global $CFG, $basedir;
672 $strfolder = get_string("folder
");
673 $strfile = get_string("file
");
675 foreach ($filelist as $file) {
676 if (is_dir($basedir.'/'.$file)) {
677 echo '<img src="'. $CFG->pixpath .'/f
/folder
.gif
" class="icon
" alt="'. $strfolder .'" /> '. htmlspecialchars($file) .'<br />';
678 $subfilelist = array();
679 $currdir = opendir($basedir.'/'.$file);
680 while (false !== ($subfile = readdir($currdir))) {
681 if ($subfile <> ".." && $subfile <> ".") {
682 $subfilelist[] = $file."/".$subfile;
685 printfilelist($subfilelist);
688 $icon = mimeinfo("icon
", $file);
689 echo '<img src="'. $CFG->pixpath .'/f
/'. $icon .'" class="icon
" alt="'. $strfile .'" /> '. htmlspecialchars($file) .'<br />';
695 function print_cell($alignment='center', $text=' ', $class='') {
697 $class = ' class="'.$class.'"';
699 echo '<td align="'.$alignment.'" style="white
-space
:nowrap
"'.$class.'>'.$text.'</td>';
702 function displaydir ($wdir) {
703 // $wdir == / or /a or /a/b/c/d etc
710 $fullpath = $basedir.$wdir;
713 $directory = opendir($fullpath); // Find all files
714 while (false !== ($file = readdir($directory))) {
715 if ($file == "." || $file == "..") {
719 if (is_dir($fullpath."/".$file)) {
725 closedir($directory);
727 $strname = get_string("name
");
728 $strsize = get_string("size
");
729 $strmodified = get_string("modified
");
730 $straction = get_string("action
");
731 $strmakeafolder = get_string("makeafolder
");
732 $struploadafile = get_string("uploadafile
");
733 $strselectall = get_string("selectall
");
734 $strselectnone = get_string("deselectall
");
735 $strwithchosenfiles = get_string("withchosenfiles
");
736 $strmovetoanotherfolder = get_string("movetoanotherfolder
");
737 $strmovefilestohere = get_string("movefilestohere
");
738 $strdeletecompletely = get_string("deletecompletely
");
739 $strcreateziparchive = get_string("createziparchive
");
740 $strrename = get_string("rename
");
741 $stredit = get_string("edit
");
742 $strunzip = get_string("unzip
");
743 $strlist = get_string("list");
744 $strrestore= get_string("restore
");
745 $strchoose = get_string("choose
");
746 $strfolder = get_string("folder
");
747 $strfile = get_string("file
");
750 echo "<form action
=\"index
.php\" method
=\"post\" id
=\"dirform\"
>";
752 echo '<input type="hidden
" name="choose
" value="'.$choose.'" />';
753 // echo "<hr align
=\"center\" noshade
=\"noshade\" size
=\"1\" />";
755 echo "<table border
=\"0\" cellspacing
=\"2\" cellpadding
=\"2\" width
=\"640\" class=\"files\"
>";
757 echo "<th
class=\"header\" scope
=\"col\"
></th
>";
758 echo "<th
class=\"header name\" scope
=\"col\"
>$strname</th
>";
759 echo "<th
class=\"header size\" scope
=\"col\"
>$strsize</th
>";
760 echo "<th
class=\"header date\" scope
=\"col\"
>$strmodified</th
>";
761 echo "<th
class=\"header commands\" scope
=\"col\"
>$straction</th
>";
770 if (!empty($dirlist)) {
772 foreach ($dirlist as $dir) {
773 echo "<tr
class=\"folder\"
>";
776 $fileurl = rawurlencode(dirname($wdir));
778 // alt attribute intentionally empty to prevent repetition in screen reader
779 print_cell('left', '<a href="index
.php?id
='.$id.'&
;wdir
='.$fileurl.'&
;choose
='.$choose.'"><img src="'.$CFG->pixpath.'/f
/parent
.gif
" class="icon
" alt="" /> '.get_string('parentfolder').'</a>', 'name');
786 $filename = $fullpath."/".$dir;
787 $fileurl = rawurlencode($wdir."/".$dir);
788 $filesafe = rawurlencode($dir);
789 $filesize = display_size(get_directory_size("$fullpath/$dir"));
790 $filedate = userdate(filemtime($filename), get_string("strftimedatetime
"));
791 if ($wdir.$dir === '/moddata') {
794 print_cell("center
", "<input type
=\"checkbox\" name
=\"file
$count\" value
=\"$fileurl\" />", 'checkbox');
796 print_cell("left
", "<a href
=\"index
.php?id
=$id&
;wdir
=$fileurl&
;choose
=$choose\"><img src
=\"$CFG->pixpath
/f
/folder
.gif\"
class=\"icon\" alt
=\"$strfolder\" /> 
;".htmlspecialchars($dir)."</a
>", 'name');
797 print_cell("right
", $filesize, 'size');
798 print_cell("right
", $filedate, 'date');
799 if ($wdir.$dir === '/moddata') {
802 print_cell("right
", "<a href
=\"index
.php?id
=$id&
;wdir
=$wdir&
;file
=$filesafe&
;action
=rename
&
;choose
=$choose\">$strrename</a
>", 'commands');
811 if (!empty($filelist)) {
813 foreach ($filelist as $file) {
815 $icon = mimeinfo("icon
", $file);
818 $filename = $fullpath."/".$file;
819 $fileurl = trim($wdir, "/")."/$file";
820 $filesafe = rawurlencode($file);
821 $fileurlsafe = rawurlencode($fileurl);
822 $filedate = userdate(filemtime($filename), get_string("strftimedatetime
"));
824 $selectfile = trim($fileurl, "/");
826 echo "<tr
class=\"file\"
>";
828 print_cell("center
", "<input type
=\"checkbox\" name
=\"file
$count\" value
=\"$fileurl\" />", 'checkbox');
829 echo "<td align
=\"left\" style
=\"white
-space
:nowrap\"
class=\"name\"
>";
831 $ffurl = get_file_url($id.'/'.$fileurl);
832 link_to_popup_window ($ffurl, "display
",
833 "<img src
=\"$CFG->pixpath
/f
/$icon\" class=\"icon\" alt
=\"$strfile\" /> 
;".htmlspecialchars($file),
837 $file_size = filesize($filename);
838 print_cell("right
", display_size($file_size), 'size');
839 print_cell("right
", $filedate, 'date');
842 $edittext = "<strong
><a onclick
=\"return set_value('$selectfile')\" href
=\"#\">$strchoose</a></strong> ";
848 if ($icon == "text.gif" ||
$icon == "html.gif") {
849 $edittext .= "<a href=\"index.php?id=$id&wdir=$wdir&file=$fileurl&action=edit&choose=$choose\">$stredit</a>";
850 } else if ($icon == "zip.gif") {
851 $edittext .= "<a href=\"index.php?id=$id&wdir=$wdir&file=$fileurl&action=unzip&sesskey=$USER->sesskey&choose=$choose\">$strunzip</a> ";
852 $edittext .= "<a href=\"index.php?id=$id&wdir=$wdir&file=$fileurl&action=listzip&sesskey=$USER->sesskey&choose=$choose\">$strlist</a> ";
853 if (!empty($CFG->backup_version
) and has_capability('moodle/site:restore', get_context_instance(CONTEXT_COURSE
, $id))) {
854 $edittext .= "<a href=\"index.php?id=$id&wdir=$wdir&file=$filesafe&action=restore&sesskey=$USER->sesskey&choose=$choose\">$strrestore</a> ";
858 print_cell("right", "$edittext <a href=\"index.php?id=$id&wdir=$wdir&file=$filesafe&action=rename&choose=$choose\">$strrename</a>", 'commands');
865 //echo "<hr width=\"640\" align=\"center\" noshade=\"noshade\" size=\"1\" />";
867 echo "<table border=\"0\" cellspacing=\"2\" cellpadding=\"2\" width=\"640\">";
869 echo "<input type=\"hidden\" name=\"id\" value=\"$id\" />";
870 echo '<input type="hidden" name="choose" value="'.$choose.'" />';
871 echo "<input type=\"hidden\" name=\"wdir\" value=\"$wdir\" /> ";
872 echo "<input type=\"hidden\" name=\"sesskey\" value=\"$USER->sesskey\" />";
874 "move" => "$strmovetoanotherfolder",
875 "delete" => "$strdeletecompletely",
876 "zip" => "$strcreateziparchive"
878 if (!empty($count)) {
880 choose_from_menu ($options, "action", "", "$strwithchosenfiles...", "javascript:getElementById('dirform').submit()");
881 echo '<div id="noscriptgo" style="display: inline;">';
882 echo '<input type="submit" value="'.get_string('go').'" />';
883 echo '<script type="text/javascript">'.
885 'document.getElementById("noscriptgo").style.display = "none";'.
886 "\n//]]>\n".'</script>';
890 echo "</td></tr></table>";
893 echo "<table border=\"0\" cellspacing=\"2\" cellpadding=\"2\" width=\"640\"><tr>";
894 echo "<td align=\"center\">";
895 if (!empty($USER->fileop
) and ($USER->fileop
== "move") and ($USER->filesource
<> $wdir)) {
896 echo "<form action=\"index.php\" method=\"get\">";
898 echo ' <input type="hidden" name="choose" value="'.$choose.'" />';
899 echo " <input type=\"hidden\" name=\"id\" value=\"$id\" />";
900 echo " <input type=\"hidden\" name=\"wdir\" value=\"$wdir\" />";
901 echo " <input type=\"hidden\" name=\"action\" value=\"paste\" />";
902 echo " <input type=\"hidden\" name=\"sesskey\" value=\"$USER->sesskey\" />";
903 echo " <input type=\"submit\" value=\"$strmovefilestohere\" />";
908 echo "<td align=\"right\">";
909 echo "<form action=\"index.php\" method=\"get\">";
911 echo ' <input type="hidden" name="choose" value="'.$choose.'" />';
912 echo " <input type=\"hidden\" name=\"id\" value=\"$id\" />";
913 echo " <input type=\"hidden\" name=\"wdir\" value=\"$wdir\" />";
914 echo " <input type=\"hidden\" name=\"action\" value=\"makedir\" />";
915 echo " <input type=\"submit\" value=\"$strmakeafolder\" />";
919 echo "<td align=\"right\">";
920 echo "<form action=\"index.php\" method=\"get\">"; //dummy form - alignment only
921 echo "<fieldset class=\"invisiblefieldset\">";
922 echo " <input type=\"button\" value=\"$strselectall\" onclick=\"checkall();\" />";
923 echo " <input type=\"button\" value=\"$strselectnone\" onclick=\"uncheckall();\" />";
927 echo "<td align=\"right\">";
928 echo "<form action=\"index.php\" method=\"get\">";
930 echo ' <input type="hidden" name="choose" value="'.$choose.'" />';
931 echo " <input type=\"hidden\" name=\"id\" value=\"$id\" />";
932 echo " <input type=\"hidden\" name=\"wdir\" value=\"$wdir\" />";
933 echo " <input type=\"hidden\" name=\"action\" value=\"upload\" />";
934 echo " <input type=\"submit\" value=\"$struploadafile\" />";
940 //echo "<hr width=\"640\" align=\"center\" noshade=\"noshade\" size=\"1\" />";