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($CFG->libdir
.'/filelib.php');
13 $id = required_param('id', PARAM_INT
);
14 $file = optional_param('file', '', PARAM_PATH
);
15 $wdir = optional_param('wdir', '', PARAM_PATH
);
16 $action = optional_param('action', '', PARAM_ACTION
);
17 $name = optional_param('name', '', PARAM_FILE
);
18 $oldname = optional_param('oldname', '', PARAM_FILE
);
19 $choose = optional_param('choose', '', PARAM_FILE
); //in fact it is always 'formname.inputname'
20 $userfile= optional_param('userfile','',PARAM_FILE
);
21 $save = optional_param('save', 0, PARAM_BOOL
);
22 $text = optional_param('text', '', PARAM_RAW
);
23 $confirm = optional_param('confirm', 0, PARAM_BOOL
);
26 if (count(explode('.', $choose)) > 2) {
27 error('Incorrect format for choose parameter');
32 if (! $course = get_record("course", "id", $id) ) {
33 error("That's an invalid course id");
36 require_login($course->id
);
38 require_capability('moodle/course:managefiles', get_context_instance(CONTEXT_COURSE
, $course->id
));
40 function html_footer() {
41 global $course, $choose;
43 echo '</td></tr></table>';
45 print_footer($course);
48 function html_header($course, $wdir, $formfield=""){
49 global $CFG, $ME, $choose;
51 if (! $site = get_site()) {
52 error("Invalid site!");
55 if ($course->id
== $site->id
) {
56 $strfiles = get_string("sitefiles");
58 $strfiles = get_string("files");
62 $fullnav = "$strfiles";
64 $dirs = explode("/", $wdir);
65 $numdirs = count($dirs);
68 for ($i=1; $i<$numdirs-1; $i++
) {
69 $navigation .= " -> ";
70 $link .= "/".urlencode($dirs[$i]);
71 $navigation .= "<a href=\"".$ME."?id=$course->id&wdir=$link&choose=$choose\">".$dirs[$i]."</a>";
73 $fullnav = "<a href=\"".$ME."?id=$course->id&wdir=/&choose=$choose\">$strfiles</a> $navigation -> ".$dirs[$numdirs-1];
80 $chooseparts = explode('.', $choose);
81 if (count($chooseparts)==2){
83 <script type
="text/javascript">
85 function set_value(txt
) {
86 opener
.document
.forms
['<?php echo $chooseparts[0]."'].".$chooseparts[1] ?>.value = txt;
93 } elseif (count($chooseparts)==1){
95 <script type="text
/javascript
">
97 function set_value(txt) {
98 opener.document.getElementById('<?php echo $chooseparts[0] ?>').value = txt;
107 $fullnav = str_replace('->', '»', "$course->shortname
-> $fullnav");
108 echo '<div id="nav
-bar
">'.$fullnav.'</div>';
110 if ($course->id == $site->id) {
111 print_heading(get_string("publicsitefileswarning
"), "center
", 2);
116 if ($course->id == $site->id) {
117 print_header("$course->shortname
: $strfiles", "$course->fullname
",
118 "<a href
=\"../$CFG->admin
/index
.php\"
>".get_string("administration
").
119 "</a
> -> $fullnav", $formfield);
121 print_heading(get_string("publicsitefileswarning
"), "center
", 2);
124 print_header("$course->shortname
: $strfiles", "$course->fullname
",
125 "<a href
=\"../course
/view
.php?id
=$course->id\"
>$course->shortname
".
126 "</a
> -> $fullnav", $formfield);
131 echo "<table border
=\"0\" align
=\"center\" cellspacing
=\"3\" cellpadding
=\"3\" width
=\"640\">";
133 echo "<td colspan
=\"2\">";
138 if (! $basedir = make_upload_directory("$course->id
")) {
139 error("The site administrator needs to fix the file permissions
");
142 $baseweb = $CFG->wwwroot;
144 // End of configuration and access control
151 if ($wdir{0} != '/') { //make sure $wdir starts with slash
155 if ($wdir == "/backupdata
") {
156 if (! make_upload_directory("$course->id
/backupdata
")) { // Backup folder
157 error("Could not create backupdata folder
. The site administrator needs to fix the file permissions
");
161 if (!is_dir($basedir.$wdir)) {
162 html_header($course, $wdir);
163 error("Requested directory does not exist
.", "$CFG->wwwroot
/files
/index
.php?id
=$id");
169 html_header($course, $wdir);
170 require_once($CFG->dirroot.'/lib/uploadlib.php');
172 if ($save and confirm_sesskey()) {
173 $course->maxbytes = 0; // We are ignoring course limits
174 $um = new upload_manager('userfile',false,false,$course,false,0);
175 $dir = "$basedir$wdir";
176 if ($um->process_file_uploads($dir)) {
177 notify(get_string('uploadedfile'));
179 // um will take care of error reporting.
182 $upload_max_filesize = get_max_upload_file_size($CFG->maxbytes);
183 $filesize = display_size($upload_max_filesize);
185 $struploadafile = get_string("uploadafile
");
186 $struploadthisfile = get_string("uploadthisfile
");
187 $strmaxsize = get_string("maxsize
", "", $filesize);
188 $strcancel = get_string("cancel
");
190 echo "<p
>$struploadafile ($strmaxsize) --> <b
>$wdir</b
></p
>";
191 echo "<form enctype
=\"multipart
/form
-data\" method
=\"post\" action
=\"index
.php\"
>";
192 echo "<table
><tr
><td colspan
=\"2\">";
193 echo ' <input type="hidden
" name="choose
" value="'.$choose.'" />';
194 echo " <input type
=\"hidden\" name
=\"id\" value
=\"$id\" />";
195 echo " <input type
=\"hidden\" name
=\"wdir\" value
=\"$wdir\" />";
196 echo " <input type
=\"hidden\" name
=\"action\" value
=\"upload\"
/>";
197 echo " <input type
=\"hidden\" name
=\"sesskey\" value
=\"$USER->sesskey\"
/>";
198 upload_print_form_fragment(1,array('userfile'),null,false,null,$upload_max_filesize,0,false);
199 echo " </td
></tr
></table
>";
200 echo " <input type
=\"submit\" name
=\"save\" value
=\"$struploadthisfile\" />";
202 echo "<form action
=\"index
.php\" method
=\"get\"
>";
203 echo ' <input type="hidden
" name="choose
" value="'.$choose.'" />';
204 echo " <input type
=\"hidden\" name
=\"id\" value
=\"$id\" />";
205 echo " <input type
=\"hidden\" name
=\"wdir\" value
=\"$wdir\" />";
206 echo " <input type
=\"hidden\" name
=\"action\" value
=\"cancel\"
/>";
207 echo " <input type
=\"submit\" value
=\"$strcancel\" />";
214 if ($confirm and confirm_sesskey()) {
215 html_header($course, $wdir);
216 if (!empty($USER->filelist)) {
217 foreach ($USER->filelist as $file) {
218 $fullfile = $basedir.'/'.$file;
219 if (! fulldelete($fullfile)) {
220 echo "<br
/>Error
: Could not delete
: $fullfile";
229 html_header($course, $wdir);
231 if (setfilelist($_POST)) {
232 notify(get_string('deletecheckwarning').':');
233 print_simple_box_start("center
");
234 printfilelist($USER->filelist);
235 print_simple_box_end();
238 require_once($CFG->dirroot.'/mod/resource/lib.php');
239 $block = resource_delete_warning($course, $USER->filelist);
241 if (empty($CFG->resource_blockdeletingfile) or $block == '') {
242 $optionsyes = array('id'=>$id, 'wdir'=>$wdir, 'action'=>'delete', 'confirm'=>1, 'sesskey'=>sesskey(), 'choose'=>$choose);
243 $optionsno = array('id'=>$id, 'wdir'=>$wdir, 'action'=>'cancel', 'choose'=>$choose);
244 notice_yesno (get_string('deletecheckfiles'), 'index.php', 'index.php', $optionsyes, $optionsno, 'post', 'get');
247 notify(get_string('warningblockingdelete', 'resource'));
248 $options = array('id'=>$id, 'wdir'=>$wdir, 'action'=>'cancel', 'choose'=>$choose);
249 print_continue("index
.php?id
=$id&
;wdir
=$wdir&
;action
=cancel
&
;choose
=$choose");
259 html_header($course, $wdir);
260 if (($count = setfilelist($_POST)) and confirm_sesskey()) {
261 $USER->fileop = $action;
262 $USER->filesource = $wdir;
263 echo "<p align
=\"center\"
>";
264 print_string("selectednowmove
", "moodle
", $count);
272 html_header($course, $wdir);
273 if (isset($USER->fileop) and ($USER->fileop == "move
") and confirm_sesskey()) {
274 foreach ($USER->filelist as $file) {
275 $shortfile = basename($file);
276 $oldfile = $basedir.'/'.$file;
277 $newfile = $basedir.$wdir."/".$shortfile;
278 if (!rename($oldfile, $newfile)) {
279 echo "<p
>Error
: $shortfile not moved
</p
>";
289 if (($name != '') and confirm_sesskey()) {
290 html_header($course, $wdir);
291 $name = clean_filename($name);
292 if (file_exists($basedir.$wdir."/".$name)) {
293 echo "<center
>Error
: $name already exists
!</center
>";
294 } else if (!rename($basedir.$wdir."/".$oldname, $basedir.$wdir."/".$name)) {
295 echo "<p align
=\"center\"
>Error
: could not rename
$oldname to
$name</p
>";
297 //file was renamed now update resources if needed
298 require_once($CFG->dirroot.'/mod/resource/lib.php');
299 resource_renamefiles($course, $wdir, $oldname, $name);
304 $strrename = get_string("rename
");
305 $strcancel = get_string("cancel
");
306 $strrenamefileto = get_string("renamefileto
", "moodle
", $file);
307 html_header($course, $wdir, "form
.name
");
308 echo "<p
>$strrenamefileto:</p
>";
309 echo "<table
><tr
><td
>";
310 echo "<form action
=\"index
.php\" method
=\"post\"
>";
311 echo ' <input type="hidden
" name="choose
" value="'.$choose.'" />';
312 echo " <input type
=\"hidden\" name
=\"id\" value
=\"$id\" />";
313 echo " <input type
=\"hidden\" name
=\"wdir\" value
=\"$wdir\" />";
314 echo " <input type
=\"hidden\" name
=\"action\" value
=\"rename\"
/>";
315 echo " <input type
=\"hidden\" name
=\"oldname\" value
=\"$file\" />";
316 echo " <input type
=\"hidden\" name
=\"sesskey\" value
=\"$USER->sesskey\"
/>";
317 echo " <input type
=\"text\" name
=\"name\" size
=\"35\" value
=\"$file\" />";
318 echo " <input type
=\"submit\" value
=\"$strrename\" />";
321 echo "<form action
=\"index
.php\" method
=\"get\"
>";
322 echo ' <input type="hidden
" name="choose
" value="'.$choose.'" />';
323 echo " <input type
=\"hidden\" name
=\"id\" value
=\"$id\" />";
324 echo " <input type
=\"hidden\" name
=\"wdir\" value
=\"$wdir\" />";
325 echo " <input type
=\"hidden\" name
=\"action\" value
=\"cancel\"
/>";
326 echo " <input type
=\"submit\" value
=\"$strcancel\" />";
328 echo "</td
></tr
></table
>";
334 if (($name != '') and confirm_sesskey()) {
335 html_header($course, $wdir);
336 $name = clean_filename($name);
337 if (file_exists("$basedir$wdir/$name")) {
338 echo "Error
: $name already exists
!";
339 } else if (! make_upload_directory("$course->id
$wdir/$name")) {
340 echo "Error
: could not create
$name";
345 $strcreate = get_string("create
");
346 $strcancel = get_string("cancel
");
347 $strcreatefolder = get_string("createfolder
", "moodle
", $wdir);
348 html_header($course, $wdir, "form
.name
");
349 echo "<p
>$strcreatefolder:</p
>";
350 echo "<table
><tr
><td
>";
351 echo "<form action
=\"index
.php\" method
=\"post\"
>";
352 echo ' <input type="hidden
" name="choose
" value="'.$choose.'" />';
353 echo " <input type
=\"hidden\" name
=\"id\" value
=\"$id\" />";
354 echo " <input type
=\"hidden\" name
=\"wdir\" value
=\"$wdir\" />";
355 echo " <input type
=\"hidden\" name
=\"action\" value
=\"makedir\"
/>";
356 echo " <input type
=\"text\" name
=\"name\" size
=\"35\" />";
357 echo " <input type
=\"hidden\" name
=\"sesskey\" value
=\"$USER->sesskey\"
/>";
358 echo " <input type
=\"submit\" value
=\"$strcreate\" />";
361 echo "<form action
=\"index
.php\" method
=\"get\"
>";
362 echo ' <input type="hidden
" name="choose
" value="'.$choose.'" />';
363 echo " <input type
=\"hidden\" name
=\"id\" value
=\"$id\" />";
364 echo " <input type
=\"hidden\" name
=\"wdir\" value
=\"$wdir\" />";
365 echo " <input type
=\"hidden\" name
=\"action\" value
=\"cancel\"
/>";
366 echo " <input type
=\"submit\" value
=\"$strcancel\" />";
368 echo "</td
></tr
></table
>";
374 html_header($course, $wdir);
375 if (($text != '') and confirm_sesskey()) {
376 $fileptr = fopen($basedir.'/'.$file,"w
");
377 $text = preg_replace('/\x0D/', '', $text); // http://moodle.org/mod/forum/discuss.php?d=38860
378 fputs($fileptr, stripslashes($text));
383 $streditfile = get_string("edit
", "", "<b
>$file</b
>");
384 $fileptr = fopen($basedir.'/'.$file, "r
");
385 $contents = fread($fileptr, filesize($basedir.'/'.$file));
388 if (mimeinfo("type
", $file) == "text
/html
") {
389 $usehtmleditor = can_use_html_editor();
391 $usehtmleditor = false;
393 $usehtmleditor = false; // Always keep it off for now
395 print_heading("$streditfile");
397 echo "<table
><tr
><td colspan
=\"2\">";
398 echo "<form action
=\"index
.php\" method
=\"post\"
>";
399 echo ' <input type="hidden
" name="choose
" value="'.$choose.'" />';
400 echo " <input type
=\"hidden\" name
=\"id\" value
=\"$id\" />";
401 echo " <input type
=\"hidden\" name
=\"wdir\" value
=\"$wdir\" />";
402 echo " <input type
=\"hidden\" name
=\"file\" value
=\"$file\" />";
403 echo " <input type
=\"hidden\" name
=\"action\" value
=\"edit\"
/>";
404 echo " <input type
=\"hidden\" name
=\"sesskey\" value
=\"$USER->sesskey\"
/>";
405 print_textarea($usehtmleditor, 25, 80, 680, 400, "text
", $contents);
406 echo "</td
></tr
><tr
><td
>";
407 echo " <input type
=\"submit\" value
=\"".get_string("savechanges
")."\"
/>";
410 echo "<form action
=\"index
.php\" method
=\"get\"
>";
411 echo ' <input type="hidden
" name="choose
" value="'.$choose.'" />';
412 echo " <input type
=\"hidden\" name
=\"id\" value
=\"$id\" />";
413 echo " <input type
=\"hidden\" name
=\"wdir\" value
=\"$wdir\" />";
414 echo " <input type
=\"hidden\" name
=\"action\" value
=\"cancel\"
/>";
415 echo " <input type
=\"submit\" value
=\"".get_string("cancel
")."\"
/>";
417 echo "</td
></tr
></table
>";
419 if ($usehtmleditor) {
429 if (($name != '') and confirm_sesskey()) {
430 html_header($course, $wdir);
431 $name = clean_filename($name);
434 foreach ($USER->filelist as $file) {
435 $files[] = "$basedir/$file";
438 if (!zip_files($files,"$basedir$wdir/$name")) {
439 error(get_string("zipfileserror
","error
"));
446 html_header($course, $wdir, "form
.name
");
448 if (setfilelist($_POST)) {
449 echo "<p align
=\"center\"
>".get_string("youareabouttocreatezip
").":</p
>";
450 print_simple_box_start("center
");
451 printfilelist($USER->filelist);
452 print_simple_box_end();
454 echo "<p align
=\"center\"
>".get_string("whattocallzip
")."</p
>";
455 echo "<table
><tr
><td
>";
456 echo "<form action
=\"index
.php\" method
=\"post\"
>";
457 echo ' <input type="hidden
" name="choose
" value="'.$choose.'" />';
458 echo " <input type
=\"hidden\" name
=\"id\" value
=\"$id\" />";
459 echo " <input type
=\"hidden\" name
=\"wdir\" value
=\"$wdir\" />";
460 echo " <input type
=\"hidden\" name
=\"action\" value
=\"zip\"
/>";
461 echo " <input type
=\"text\" name
=\"name\" size
=\"35\" value
=\"new.zip\"
/>";
462 echo " <input type
=\"hidden\" name
=\"sesskey\" value
=\"$USER->sesskey\"
/>";
463 echo " <input type
=\"submit\" value
=\"".get_string("createziparchive
")."\"
/>";
466 echo "<form action
=\"index
.php\" method
=\"get\"
>";
467 echo ' <input type="hidden
" name="choose
" value="'.$choose.'" />';
468 echo " <input type
=\"hidden\" name
=\"id\" value
=\"$id\" />";
469 echo " <input type
=\"hidden\" name
=\"wdir\" value
=\"$wdir\" />";
470 echo " <input type
=\"hidden\" name
=\"action\" value
=\"cancel\"
/>";
471 echo " <input type
=\"submit\" value
=\"".get_string("cancel
")."\"
/>";
473 echo "</td
></tr
></table
>";
483 html_header($course, $wdir);
484 if (($file != '') and confirm_sesskey()) {
485 $strok = get_string("ok
");
486 $strunpacking = get_string("unpacking
", "", $file);
488 echo "<p align
=\"center\"
>$strunpacking:</p
>";
490 $file = basename($file);
492 if (!unzip_file("$basedir$wdir/$file")) {
493 error(get_string("unzipfileserror
","error
"));
496 echo "<center
><form action
=\"index
.php\" method
=\"get\"
>";
497 echo ' <input type="hidden
" name="choose
" value="'.$choose.'" />';
498 echo " <input type
=\"hidden\" name
=\"id\" value
=\"$id\" />";
499 echo " <input type
=\"hidden\" name
=\"wdir\" value
=\"$wdir\" />";
500 echo " <input type
=\"hidden\" name
=\"action\" value
=\"cancel\"
/>";
501 echo " <input type
=\"submit\" value
=\"$strok\" />";
511 html_header($course, $wdir);
512 if (($file != '') and confirm_sesskey()) {
513 $strname = get_string("name
");
514 $strsize = get_string("size
");
515 $strmodified = get_string("modified
");
516 $strok = get_string("ok
");
517 $strlistfiles = get_string("listfiles
", "", $file);
519 echo "<p align
=\"center\"
>$strlistfiles:</p
>";
520 $file = basename($file);
522 include_once("$CFG->libdir
/pclzip
/pclzip
.lib
.php
");
523 $archive = new PclZip(cleardoubleslashes("$basedir$wdir/$file"));
524 if (!$list = $archive->listContent(cleardoubleslashes("$basedir$wdir"))) {
525 notify($archive->errorInfo(true));
528 echo "<table cellpadding
=\"4\" cellspacing
=\"2\" border
=\"0\" width
=\"640\" class=\"files\"
>";
529 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
>";
530 foreach ($list as $item) {
532 print_cell("left
", s($item['filename']), 'name');
533 if (! $item['folder']) {
534 print_cell("right
", display_size($item['size']), 'size');
536 echo "<td
> 
;</td
>";
538 $filedate = userdate($item['mtime'], get_string("strftimedatetime
"));
539 print_cell("right
", $filedate, 'date');
544 echo "<br
/><center
><form action
=\"index
.php\" method
=\"get\"
>";
545 echo ' <input type="hidden
" name="choose
" value="'.$choose.'" />';
546 echo " <input type
=\"hidden\" name
=\"id\" value
=\"$id\" />";
547 echo " <input type
=\"hidden\" name
=\"wdir\" value
=\"$wdir\" />";
548 echo " <input type
=\"hidden\" name
=\"action\" value
=\"cancel\"
/>";
549 echo " <input type
=\"submit\" value
=\"$strok\" />";
559 html_header($course, $wdir);
560 if (($file != '') and confirm_sesskey()) {
561 echo "<p align
=\"center\"
>".get_string("youaregoingtorestorefrom
").":</p
>";
562 print_simple_box_start("center
");
564 print_simple_box_end();
566 echo "<p align
=\"center\"
>".get_string("areyousuretorestorethisinfo
")."</p
>";
567 $restore_path = "$CFG->wwwroot
/backup
/restore
.php
";
568 notice_yesno (get_string("areyousuretorestorethis
"),
569 $restore_path."?id
=".$id."&
;file
=".cleardoubleslashes($id.$wdir."/".$file)."&
;method
=manual
",
570 "index
.php?id
=$id&
;wdir
=$wdir&
;action
=cancel
");
581 html_header($course, $wdir);
588 /// FILE FUNCTIONS ///////////////////////////////////////////////////////////
591 function setfilelist($VARS) {
594 $USER->filelist = array ();
598 foreach ($VARS as $key => $val) {
599 if (substr($key,0,4) == "file
") {
601 $val = rawurldecode($val);
602 $USER->filelist[] = clean_param($val, PARAM_PATH);
608 function clearfilelist() {
611 $USER->filelist = array ();
616 function printfilelist($filelist) {
617 global $CFG, $basedir;
619 $strfolder = get_string("folder
");
620 $strfile = get_string("file
");
622 foreach ($filelist as $file) {
623 if (is_dir($basedir.'/'.$file)) {
624 echo "<img src
=\"$CFG->pixpath
/f
/folder
.gif\"
class=\"icon\" alt
=\"$strfolder\" /> $file<br
/>";
625 $subfilelist = array();
626 $currdir = opendir($basedir.'/'.$file);
627 while (false !== ($subfile = readdir($currdir))) {
628 if ($subfile <> ".." && $subfile <> ".") {
629 $subfilelist[] = $file."/".$subfile;
632 printfilelist($subfilelist);
635 $icon = mimeinfo("icon
", $file);
636 echo "<img src
=\"$CFG->pixpath
/f
/$icon\" class=\"icon\" alt
=\"$strfile\" /> $file<br
/>";
642 function print_cell($alignment='center', $text=' ', $class='') {
644 $class = ' class="'.$class.'"';
646 echo '<td align="'.$alignment.'" nowrap="nowrap
"'.$class.'>'.$text.'</td>';
649 function displaydir ($wdir) {
650 // $wdir == / or /a or /a/b/c/d etc
657 $fullpath = $basedir.$wdir;
660 $directory = opendir($fullpath); // Find all files
661 while (false !== ($file = readdir($directory))) {
662 if ($file == "." || $file == "..") {
666 if (is_dir($fullpath."/".$file)) {
672 closedir($directory);
674 $strname = get_string("name
");
675 $strsize = get_string("size
");
676 $strmodified = get_string("modified
");
677 $straction = get_string("action
");
678 $strmakeafolder = get_string("makeafolder
");
679 $struploadafile = get_string("uploadafile
");
680 $strselectall = get_string("selectall
");
681 $strselectnone = get_string("deselectall
");
682 $strwithchosenfiles = get_string("withchosenfiles
");
683 $strmovetoanotherfolder = get_string("movetoanotherfolder
");
684 $strmovefilestohere = get_string("movefilestohere
");
685 $strdeletecompletely = get_string("deletecompletely
");
686 $strcreateziparchive = get_string("createziparchive
");
687 $strrename = get_string("rename
");
688 $stredit = get_string("edit
");
689 $strunzip = get_string("unzip
");
690 $strlist = get_string("list");
691 $strrestore= get_string("restore
");
692 $strchoose = get_string("choose
");
693 $strfolder = get_string("folder
");
694 $strfile = get_string("file
");
697 echo "<form action
=\"index
.php\" method
=\"post\" id
=\"dirform\"
>";
698 echo '<input type="hidden
" name="choose
" value="'.$choose.'" />';
699 echo "<hr width
=\"640\" align
=\"center\" noshade
=\"noshade\" size
=\"1\" />";
700 echo "<table border
=\"0\" cellspacing
=\"2\" cellpadding
=\"2\" width
=\"640\" class=\"files\"
>";
702 echo "<th width
=\"5\" scope
=\"col\"
></th
>";
703 echo "<th align
=\"left\"
class=\"header name\" scope
=\"col\"
>$strname</th
>";
704 echo "<th align
=\"right\"
class=\"header size\" scope
=\"col\"
>$strsize</th
>";
705 echo "<th align
=\"right\"
class=\"header date\" scope
=\"col\"
>$strmodified</th
>";
706 echo "<th align
=\"right\"
class=\"header commands\" scope
=\"col\"
>$straction</th
>";
715 if (!empty($dirlist)) {
717 foreach ($dirlist as $dir) {
718 echo "<tr
class=\"folder\"
>";
721 $fileurl = rawurlencode(dirname($wdir));
723 // alt attribute intentionally empty to prevent repetition in screen reader
724 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');
731 $filename = $fullpath."/".$dir;
732 $fileurl = rawurlencode($wdir."/".$dir);
733 $filesafe = rawurlencode($dir);
734 $filesize = display_size(get_directory_size("$fullpath/$dir"));
735 $filedate = userdate(filemtime($filename), "%d %b %Y
, %I
:%M %p
");
736 print_cell("center
", "<input type
=\"checkbox\" name
=\"file
$count\" value
=\"$fileurl\" />", 'checkbox');
737 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');
738 print_cell("right
", $filesize, 'size');
739 print_cell("right
", $filedate, 'date');
740 print_cell("right
", "<a href
=\"index
.php?id
=$id&
;wdir
=$wdir&
;file
=$filesafe&
;action
=rename
&
;choose
=$choose\">$strrename</a
>", 'commands');
748 if (!empty($filelist)) {
750 foreach ($filelist as $file) {
752 $icon = mimeinfo("icon
", $file);
755 $filename = $fullpath."/".$file;
756 $fileurl = trim($wdir, "/")."/$file";
757 $filesafe = rawurlencode($file);
758 $fileurlsafe = rawurlencode($fileurl);
759 $filedate = userdate(filemtime($filename), "%d %b %Y
, %I
:%M %p
");
761 $selectfile = trim($fileurl, "/");
763 echo "<tr
class=\"file\"
>";
765 print_cell("center
", "<input type
=\"checkbox\" name
=\"file
$count\" value
=\"$fileurl\" />", 'checkbox');
766 echo "<td align
=\"left\" nowrap
=\"nowrap\"
class=\"name\"
>";
767 if ($CFG->slasharguments) {
768 $ffurl = str_replace('//', '/', "/file
.php
/$id/$fileurl");
770 $ffurl = str_replace('//', '/', "/file
.php?file
=/$id/$fileurl");
772 link_to_popup_window ($ffurl, "display
",
773 "<img src
=\"$CFG->pixpath
/f
/$icon\" class=\"icon\" alt
=\"$strfile\" /> 
;".htmlspecialchars($file),
777 $file_size = filesize($filename);
778 print_cell("right
", display_size($file_size), 'size');
779 print_cell("right
", $filedate, 'date');
782 $edittext = "<strong
><a onclick
=\"return set_value('$selectfile')\" href
=\"#\">$strchoose</a></strong> ";
788 if ($icon == "text.gif" ||
$icon == "html.gif") {
789 $edittext .= "<a href=\"index.php?id=$id&wdir=$wdir&file=$fileurl&action=edit&choose=$choose\">$stredit</a>";
790 } else if ($icon == "zip.gif") {
791 $edittext .= "<a href=\"index.php?id=$id&wdir=$wdir&file=$fileurl&action=unzip&sesskey=$USER->sesskey&choose=$choose\">$strunzip</a> ";
792 $edittext .= "<a href=\"index.php?id=$id&wdir=$wdir&file=$fileurl&action=listzip&sesskey=$USER->sesskey&choose=$choose\">$strlist</a> ";
793 if (!empty($CFG->backup_version
) and has_capability('moodle/site:restore', get_context_instance(CONTEXT_COURSE
, $id))) {
794 $edittext .= "<a href=\"index.php?id=$id&wdir=$wdir&file=$filesafe&action=restore&sesskey=$USER->sesskey&choose=$choose\">$strrestore</a> ";
798 print_cell("right", "$edittext <a href=\"index.php?id=$id&wdir=$wdir&file=$filesafe&action=rename&choose=$choose\">$strrename</a>", 'commands');
804 echo "<hr width=\"640\" align=\"center\" noshade=\"noshade\" size=\"1\" />";
806 echo "<table border=\"0\" cellspacing=\"2\" cellpadding=\"2\" width=\"640\">";
808 echo "<input type=\"hidden\" name=\"id\" value=\"$id\" />";
809 echo '<input type="hidden" name="choose" value="'.$choose.'" />';
810 echo "<input type=\"hidden\" name=\"wdir\" value=\"$wdir\" /> ";
811 echo "<input type=\"hidden\" name=\"sesskey\" value=\"$USER->sesskey\" />";
813 "move" => "$strmovetoanotherfolder",
814 "delete" => "$strdeletecompletely",
815 "zip" => "$strcreateziparchive"
817 if (!empty($count)) {
818 choose_from_menu ($options, "action", "", "$strwithchosenfiles...", "javascript:getElementById('dirform').submit()");
820 echo "</td></tr></table>";
822 echo "<table border=\"0\" cellspacing=\"2\" cellpadding=\"2\" width=\"640\"><tr>";
823 echo "<td align=\"center\">";
824 if (!empty($USER->fileop
) and ($USER->fileop
== "move") and ($USER->filesource
<> $wdir)) {
825 echo "<form action=\"index.php\" method=\"get\">";
826 echo ' <input type="hidden" name="choose" value="'.$choose.'" />';
827 echo " <input type=\"hidden\" name=\"id\" value=\"$id\" />";
828 echo " <input type=\"hidden\" name=\"wdir\" value=\"$wdir\" />";
829 echo " <input type=\"hidden\" name=\"action\" value=\"paste\" />";
830 echo " <input type=\"hidden\" name=\"sesskey\" value=\"$USER->sesskey\" />";
831 echo " <input type=\"submit\" value=\"$strmovefilestohere\" />";
835 echo "<td align=\"right\">";
836 echo "<form action=\"index.php\" method=\"get\">";
837 echo ' <input type="hidden" name="choose" value="'.$choose.'" />';
838 echo " <input type=\"hidden\" name=\"id\" value=\"$id\" />";
839 echo " <input type=\"hidden\" name=\"wdir\" value=\"$wdir\" />";
840 echo " <input type=\"hidden\" name=\"action\" value=\"makedir\" />";
841 echo " <input type=\"submit\" value=\"$strmakeafolder\" />";
844 echo "<td align=\"right\">";
845 echo "<form action=\"index.php\" method=\"get\">"; //dummy form - alignment only
846 echo " <input type=\"button\" value=\"$strselectall\" onclick=\"checkall();\" />";
847 echo " <input type=\"button\" value=\"$strselectnone\" onclick=\"uncheckall();\" />";
850 echo "<td align=\"right\">";
851 echo "<form action=\"index.php\" method=\"get\">";
852 echo ' <input type="hidden" name="choose" value="'.$choose.'" />';
853 echo " <input type=\"hidden\" name=\"id\" value=\"$id\" />";
854 echo " <input type=\"hidden\" name=\"wdir\" value=\"$wdir\" />";
855 echo " <input type=\"hidden\" name=\"action\" value=\"upload\" />";
856 echo " <input type=\"submit\" value=\"$struploadafile\" />";
860 echo "<hr width=\"640\" align=\"center\" noshade=\"noshade\" size=\"1\" />";