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');
12 require($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("publicsitefileswarning
"), "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("publicsitefileswarning
"), "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 $baseweb = $CFG->wwwroot;
166 // End of configuration and access control
173 if ($wdir{0} != '/') { //make sure $wdir starts with slash
177 if ($wdir == "/backupdata
") {
178 if (! make_upload_directory("$course->id
/backupdata
")) { // Backup folder
179 error("Could not create backupdata folder
. The site administrator needs to fix the file permissions
");
183 if (!is_dir($basedir.$wdir)) {
184 html_header($course, $wdir);
185 error("Requested directory does not exist
.", "$CFG->wwwroot
/files
/index
.php?id
=$id");
191 html_header($course, $wdir);
192 require_once($CFG->dirroot.'/lib/uploadlib.php');
194 if ($save and confirm_sesskey()) {
195 $course->maxbytes = 0; // We are ignoring course limits
196 $um = new upload_manager('userfile',false,false,$course,false,0);
197 $dir = "$basedir$wdir";
198 if ($um->process_file_uploads($dir)) {
199 notify(get_string('uploadedfile'));
201 // um will take care of error reporting.
204 $upload_max_filesize = get_max_upload_file_size($CFG->maxbytes);
205 $filesize = display_size($upload_max_filesize);
207 $struploadafile = get_string("uploadafile
");
208 $struploadthisfile = get_string("uploadthisfile
");
209 $strmaxsize = get_string("maxsize
", "", $filesize);
210 $strcancel = get_string("cancel
");
212 echo "<p
>$struploadafile ($strmaxsize) --> <b
>$wdir</b
></p
>";
213 echo "<form enctype
=\"multipart
/form
-data\" method
=\"post\" action
=\"index
.php\"
>";
215 echo "<table
><tr
><td colspan
=\"2\">";
216 echo ' <input type="hidden
" name="choose
" value="'.$choose.'" />';
217 echo " <input type
=\"hidden\" name
=\"id\" value
=\"$id\" />";
218 echo " <input type
=\"hidden\" name
=\"wdir\" value
=\"$wdir\" />";
219 echo " <input type
=\"hidden\" name
=\"action\" value
=\"upload\"
/>";
220 echo " <input type
=\"hidden\" name
=\"sesskey\" value
=\"$USER->sesskey\"
/>";
221 upload_print_form_fragment(1,array('userfile'),null,false,null,$upload_max_filesize,0,false);
222 echo " </td
></tr
></table
>";
223 echo " <input type
=\"submit\" name
=\"save\" value
=\"$struploadthisfile\" />";
226 echo "<form action
=\"index
.php\" method
=\"get\"
>";
228 echo ' <input type="hidden
" name="choose
" value="'.$choose.'" />';
229 echo " <input type
=\"hidden\" name
=\"id\" value
=\"$id\" />";
230 echo " <input type
=\"hidden\" name
=\"wdir\" value
=\"$wdir\" />";
231 echo " <input type
=\"hidden\" name
=\"action\" value
=\"cancel\"
/>";
232 echo " <input type
=\"submit\" value
=\"$strcancel\" />";
240 if ($confirm and confirm_sesskey()) {
241 html_header($course, $wdir);
242 if (!empty($USER->filelist)) {
243 foreach ($USER->filelist as $file) {
244 $fullfile = $basedir.'/'.$file;
245 if (! fulldelete($fullfile)) {
246 echo "<br
/>Error
: Could not delete
: $fullfile";
255 html_header($course, $wdir);
257 if (setfilelist($_POST)) {
258 notify(get_string('deletecheckwarning').':');
259 print_simple_box_start("center
");
260 printfilelist($USER->filelist);
261 print_simple_box_end();
264 require_once($CFG->dirroot.'/mod/resource/lib.php');
265 $block = resource_delete_warning($course, $USER->filelist);
267 if (empty($CFG->resource_blockdeletingfile) or $block == '') {
268 $optionsyes = array('id'=>$id, 'wdir'=>$wdir, 'action'=>'delete', 'confirm'=>1, 'sesskey'=>sesskey(), 'choose'=>$choose);
269 $optionsno = array('id'=>$id, 'wdir'=>$wdir, 'action'=>'cancel', 'choose'=>$choose);
270 notice_yesno (get_string('deletecheckfiles'), 'index.php', 'index.php', $optionsyes, $optionsno, 'post', 'get');
273 notify(get_string('warningblockingdelete', 'resource'));
274 $options = array('id'=>$id, 'wdir'=>$wdir, 'action'=>'cancel', 'choose'=>$choose);
275 print_continue("index
.php?id
=$id&
;wdir
=$wdir&
;action
=cancel
&
;choose
=$choose");
285 html_header($course, $wdir);
286 if (($count = setfilelist($_POST)) and confirm_sesskey()) {
287 $USER->fileop = $action;
288 $USER->filesource = $wdir;
289 echo "<p
class=\"centerpara\"
>";
290 print_string("selectednowmove
", "moodle
", $count);
298 html_header($course, $wdir);
299 if (isset($USER->fileop) and ($USER->fileop == "move
") and confirm_sesskey()) {
300 foreach ($USER->filelist as $file) {
301 $shortfile = basename($file);
302 $oldfile = $basedir.'/'.$file;
303 $newfile = $basedir.$wdir."/".$shortfile;
304 if (!rename($oldfile, $newfile)) {
305 echo "<p
>Error
: $shortfile not moved
</p
>";
315 if (($name != '') and confirm_sesskey()) {
316 html_header($course, $wdir);
317 $name = clean_filename($name);
318 if (file_exists($basedir.$wdir."/".$name)) {
319 echo "<center
>Error
: $name already exists
!</center
>";
320 } else if (!rename($basedir.$wdir."/".$oldname, $basedir.$wdir."/".$name)) {
321 echo "<p align
=\"center\"
>Error
: could not rename
$oldname to
$name</p
>";
323 //file was renamed now update resources if needed
324 require_once($CFG->dirroot.'/mod/resource/lib.php');
325 resource_renamefiles($course, $wdir, $oldname, $name);
330 $strrename = get_string("rename
");
331 $strcancel = get_string("cancel
");
332 $strrenamefileto = get_string("renamefileto
", "moodle
", $file);
333 html_header($course, $wdir, "form
.name
");
334 echo "<p
>$strrenamefileto:</p
>";
335 echo "<table
><tr
><td
>";
336 echo "<form action
=\"index
.php\" method
=\"post\"
>";
337 echo "<fieldset
class=\"invisiblefieldset\"
>";
338 echo ' <input type="hidden
" name="choose
" value="'.$choose.'" />';
339 echo " <input type
=\"hidden\" name
=\"id\" value
=\"$id\" />";
340 echo " <input type
=\"hidden\" name
=\"wdir\" value
=\"$wdir\" />";
341 echo " <input type
=\"hidden\" name
=\"action\" value
=\"rename\"
/>";
342 echo " <input type
=\"hidden\" name
=\"oldname\" value
=\"$file\" />";
343 echo " <input type
=\"hidden\" name
=\"sesskey\" value
=\"$USER->sesskey\"
/>";
344 echo " <input type
=\"text\" name
=\"name\" size
=\"35\" value
=\"$file\" />";
345 echo " <input type
=\"submit\" value
=\"$strrename\" />";
349 echo "<form action
=\"index
.php\" method
=\"get\"
>";
351 echo ' <input type="hidden
" name="choose
" value="'.$choose.'" />';
352 echo " <input type
=\"hidden\" name
=\"id\" value
=\"$id\" />";
353 echo " <input type
=\"hidden\" name
=\"wdir\" value
=\"$wdir\" />";
354 echo " <input type
=\"hidden\" name
=\"action\" value
=\"cancel\"
/>";
355 echo " <input type
=\"submit\" value
=\"$strcancel\" />";
358 echo "</td
></tr
></table
>";
364 if (($name != '') and confirm_sesskey()) {
365 html_header($course, $wdir);
366 $name = clean_filename($name);
367 if (file_exists("$basedir$wdir/$name")) {
368 echo "Error
: $name already exists
!";
369 } else if (! make_upload_directory("$course->id
$wdir/$name")) {
370 echo "Error
: could not create
$name";
375 $strcreate = get_string("create
");
376 $strcancel = get_string("cancel
");
377 $strcreatefolder = get_string("createfolder
", "moodle
", $wdir);
378 html_header($course, $wdir, "form
.name
");
379 echo "<p
>$strcreatefolder:</p
>";
380 echo "<table
><tr
><td
>";
381 echo "<form action
=\"index
.php\" method
=\"post\"
>";
382 echo "<fieldset
class=\"invisiblefieldset\"
>";
383 echo ' <input type="hidden
" name="choose
" value="'.$choose.'" />';
384 echo " <input type
=\"hidden\" name
=\"id\" value
=\"$id\" />";
385 echo " <input type
=\"hidden\" name
=\"wdir\" value
=\"$wdir\" />";
386 echo " <input type
=\"hidden\" name
=\"action\" value
=\"makedir\"
/>";
387 echo " <input type
=\"text\" name
=\"name\" size
=\"35\" />";
388 echo " <input type
=\"hidden\" name
=\"sesskey\" value
=\"$USER->sesskey\"
/>";
389 echo " <input type
=\"submit\" value
=\"$strcreate\" />";
393 echo "<form action
=\"index
.php\" method
=\"get\"
>";
395 echo ' <input type="hidden
" name="choose
" value="'.$choose.'" />';
396 echo " <input type
=\"hidden\" name
=\"id\" value
=\"$id\" />";
397 echo " <input type
=\"hidden\" name
=\"wdir\" value
=\"$wdir\" />";
398 echo " <input type
=\"hidden\" name
=\"action\" value
=\"cancel\"
/>";
399 echo " <input type
=\"submit\" value
=\"$strcancel\" />";
402 echo "</td
></tr
></table
>";
408 html_header($course, $wdir);
409 if (($text != '') and confirm_sesskey()) {
410 $fileptr = fopen($basedir.'/'.$file,"w
");
411 $text = preg_replace('/\x0D/', '', $text); // http://moodle.org/mod/forum/discuss.php?d=38860
412 fputs($fileptr, stripslashes($text));
417 $streditfile = get_string("edit
", "", "<b
>$file</b
>");
418 $fileptr = fopen($basedir.'/'.$file, "r
");
419 $contents = fread($fileptr, filesize($basedir.'/'.$file));
422 if (mimeinfo("type
", $file) == "text
/html
") {
423 $usehtmleditor = can_use_html_editor();
425 $usehtmleditor = false;
427 $usehtmleditor = false; // Always keep it off for now
429 print_heading("$streditfile");
431 echo "<table
><tr
><td colspan
=\"2\">";
432 echo "<form action
=\"index
.php\" method
=\"post\"
>";
434 echo ' <input type="hidden
" name="choose
" value="'.$choose.'" />';
435 echo " <input type
=\"hidden\" name
=\"id\" value
=\"$id\" />";
436 echo " <input type
=\"hidden\" name
=\"wdir\" value
=\"$wdir\" />";
437 echo " <input type
=\"hidden\" name
=\"file\" value
=\"$file\" />";
438 echo " <input type
=\"hidden\" name
=\"action\" value
=\"edit\"
/>";
439 echo " <input type
=\"hidden\" name
=\"sesskey\" value
=\"$USER->sesskey\"
/>";
440 print_textarea($usehtmleditor, 25, 80, 680, 400, "text
", $contents);
441 echo "</td
></tr
><tr
><td
>";
442 echo " <input type
=\"submit\" value
=\"".get_string("savechanges
")."\"
/>";
446 echo "<form action
=\"index
.php\" method
=\"get\"
>";
448 echo ' <input type="hidden
" name="choose
" value="'.$choose.'" />';
449 echo " <input type
=\"hidden\" name
=\"id\" value
=\"$id\" />";
450 echo " <input type
=\"hidden\" name
=\"wdir\" value
=\"$wdir\" />";
451 echo " <input type
=\"hidden\" name
=\"action\" value
=\"cancel\"
/>";
452 echo " <input type
=\"submit\" value
=\"".get_string("cancel
")."\"
/>";
455 echo "</td
></tr
></table
>";
457 if ($usehtmleditor) {
467 if (($name != '') and confirm_sesskey()) {
468 html_header($course, $wdir);
469 $name = clean_filename($name);
472 foreach ($USER->filelist as $file) {
473 $files[] = "$basedir/$file";
476 if (!zip_files($files,"$basedir$wdir/$name")) {
477 print_error("zipfileserror
","error
");
484 html_header($course, $wdir, "form
.name
");
486 if (setfilelist($_POST)) {
487 echo "<p align
=\"center\"
>".get_string("youareabouttocreatezip
").":</p
>";
488 print_simple_box_start("center
");
489 printfilelist($USER->filelist);
490 print_simple_box_end();
492 echo "<p align
=\"center\"
>".get_string("whattocallzip
")."</p
>";
493 echo "<table
><tr
><td
>";
494 echo "<form action
=\"index
.php\" method
=\"post\"
>";
495 echo "<fieldset
class=\"invisiblefieldset\"
>";
496 echo ' <input type="hidden
" name="choose
" value="'.$choose.'" />';
497 echo " <input type
=\"hidden\" name
=\"id\" value
=\"$id\" />";
498 echo " <input type
=\"hidden\" name
=\"wdir\" value
=\"$wdir\" />";
499 echo " <input type
=\"hidden\" name
=\"action\" value
=\"zip\"
/>";
500 echo " <input type
=\"text\" name
=\"name\" size
=\"35\" value
=\"new.zip\"
/>";
501 echo " <input type
=\"hidden\" name
=\"sesskey\" value
=\"$USER->sesskey\"
/>";
502 echo " <input type
=\"submit\" value
=\"".get_string("createziparchive
")."\"
/>";
506 echo "<form action
=\"index
.php\" method
=\"get\"
>";
508 echo ' <input type="hidden
" name="choose
" value="'.$choose.'" />';
509 echo " <input type
=\"hidden\" name
=\"id\" value
=\"$id\" />";
510 echo " <input type
=\"hidden\" name
=\"wdir\" value
=\"$wdir\" />";
511 echo " <input type
=\"hidden\" name
=\"action\" value
=\"cancel\"
/>";
512 echo " <input type
=\"submit\" value
=\"".get_string("cancel
")."\"
/>";
515 echo "</td
></tr
></table
>";
525 html_header($course, $wdir);
526 if (($file != '') and confirm_sesskey()) {
527 $strok = get_string("ok
");
528 $strunpacking = get_string("unpacking
", "", $file);
530 echo "<p align
=\"center\"
>$strunpacking:</p
>";
532 $file = basename($file);
534 if (!unzip_file("$basedir$wdir/$file")) {
535 print_error("unzipfileserror
","error
");
538 echo "<div style
=\"text
-align
:center\"
><form action
=\"index
.php\" method
=\"get\"
>";
540 echo ' <input type="hidden
" name="choose
" value="'.$choose.'" />';
541 echo " <input type
=\"hidden\" name
=\"id\" value
=\"$id\" />";
542 echo " <input type
=\"hidden\" name
=\"wdir\" value
=\"$wdir\" />";
543 echo " <input type
=\"hidden\" name
=\"action\" value
=\"cancel\"
/>";
544 echo " <input type
=\"submit\" value
=\"$strok\" />";
555 html_header($course, $wdir);
556 if (($file != '') and confirm_sesskey()) {
557 $strname = get_string("name
");
558 $strsize = get_string("size
");
559 $strmodified = get_string("modified
");
560 $strok = get_string("ok
");
561 $strlistfiles = get_string("listfiles
", "", $file);
563 echo "<p align
=\"center\"
>$strlistfiles:</p
>";
564 $file = basename($file);
566 include_once("$CFG->libdir
/pclzip
/pclzip
.lib
.php
");
567 $archive = new PclZip(cleardoubleslashes("$basedir$wdir/$file"));
568 if (!$list = $archive->listContent(cleardoubleslashes("$basedir$wdir"))) {
569 notify($archive->errorInfo(true));
572 echo "<table cellpadding
=\"4\" cellspacing
=\"2\" border
=\"0\" width
=\"640\" class=\"files\"
>";
573 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
>";
574 foreach ($list as $item) {
576 print_cell("left
", s($item['filename']), 'name');
577 if (! $item['folder']) {
578 print_cell("right
", display_size($item['size']), 'size');
580 echo "<td
> 
;</td
>";
582 $filedate = userdate($item['mtime'], get_string("strftimedatetime
"));
583 print_cell("right
", $filedate, 'date');
588 echo "<br
/><center
><form action
=\"index
.php\" method
=\"get\"
>";
590 echo ' <input type="hidden
" name="choose
" value="'.$choose.'" />';
591 echo " <input type
=\"hidden\" name
=\"id\" value
=\"$id\" />";
592 echo " <input type
=\"hidden\" name
=\"wdir\" value
=\"$wdir\" />";
593 echo " <input type
=\"hidden\" name
=\"action\" value
=\"cancel\"
/>";
594 echo " <input type
=\"submit\" value
=\"$strok\" />";
605 html_header($course, $wdir);
606 if (($file != '') and confirm_sesskey()) {
607 echo "<p align
=\"center\"
>".get_string("youaregoingtorestorefrom
").":</p
>";
608 print_simple_box_start("center
");
610 print_simple_box_end();
612 echo "<p align
=\"center\"
>".get_string("areyousuretorestorethisinfo
")."</p
>";
613 $restore_path = "$CFG->wwwroot
/backup
/restore
.php
";
614 notice_yesno (get_string("areyousuretorestorethis
"),
615 $restore_path."?id
=".$id."&
;file
=".cleardoubleslashes($id.$wdir."/".$file)."&
;method
=manual
",
616 "index
.php?id
=$id&
;wdir
=$wdir&
;action
=cancel
");
627 html_header($course, $wdir);
634 /// FILE FUNCTIONS ///////////////////////////////////////////////////////////
637 function setfilelist($VARS) {
640 $USER->filelist = array ();
644 foreach ($VARS as $key => $val) {
645 if (substr($key,0,4) == "file
") {
647 $val = rawurldecode($val);
648 $USER->filelist[] = clean_param($val, PARAM_PATH);
654 function clearfilelist() {
657 $USER->filelist = array ();
662 function printfilelist($filelist) {
663 global $CFG, $basedir;
665 $strfolder = get_string("folder
");
666 $strfile = get_string("file
");
668 foreach ($filelist as $file) {
669 if (is_dir($basedir.'/'.$file)) {
670 echo '<img src="'. $CFG->pixpath .'/f
/folder
.gif
" class="icon
" alt="'. $strfolder .'" /> '. htmlspecialchars($file) .'<br />';
671 $subfilelist = array();
672 $currdir = opendir($basedir.'/'.$file);
673 while (false !== ($subfile = readdir($currdir))) {
674 if ($subfile <> ".." && $subfile <> ".") {
675 $subfilelist[] = $file."/".$subfile;
678 printfilelist($subfilelist);
681 $icon = mimeinfo("icon
", $file);
682 echo '<img src="'. $CFG->pixpath .'/f
/'. $icon .'" class="icon
" alt="'. $strfile .'" /> '. htmlspecialchars($file) .'<br />';
688 function print_cell($alignment='center', $text=' ', $class='') {
690 $class = ' class="'.$class.'"';
692 echo '<td align="'.$alignment.'" style="white
-space
:nowrap
"'.$class.'>'.$text.'</td>';
695 function displaydir ($wdir) {
696 // $wdir == / or /a or /a/b/c/d etc
703 $fullpath = $basedir.$wdir;
706 $directory = opendir($fullpath); // Find all files
707 while (false !== ($file = readdir($directory))) {
708 if ($file == "." || $file == "..") {
712 if (is_dir($fullpath."/".$file)) {
718 closedir($directory);
720 $strname = get_string("name
");
721 $strsize = get_string("size
");
722 $strmodified = get_string("modified
");
723 $straction = get_string("action
");
724 $strmakeafolder = get_string("makeafolder
");
725 $struploadafile = get_string("uploadafile
");
726 $strselectall = get_string("selectall
");
727 $strselectnone = get_string("deselectall
");
728 $strwithchosenfiles = get_string("withchosenfiles
");
729 $strmovetoanotherfolder = get_string("movetoanotherfolder
");
730 $strmovefilestohere = get_string("movefilestohere
");
731 $strdeletecompletely = get_string("deletecompletely
");
732 $strcreateziparchive = get_string("createziparchive
");
733 $strrename = get_string("rename
");
734 $stredit = get_string("edit
");
735 $strunzip = get_string("unzip
");
736 $strlist = get_string("list");
737 $strrestore= get_string("restore
");
738 $strchoose = get_string("choose
");
739 $strfolder = get_string("folder
");
740 $strfile = get_string("file
");
743 echo "<form action
=\"index
.php\" method
=\"post\" id
=\"dirform\"
>";
745 echo '<input type="hidden
" name="choose
" value="'.$choose.'" />';
746 // echo "<hr align
=\"center\" noshade
=\"noshade\" size
=\"1\" />";
748 echo "<table border
=\"0\" cellspacing
=\"2\" cellpadding
=\"2\" width
=\"640\" class=\"files\"
>";
750 echo "<th
class=\"header\" scope
=\"col\"
></th
>";
751 echo "<th
class=\"header name\" scope
=\"col\"
>$strname</th
>";
752 echo "<th
class=\"header size\" scope
=\"col\"
>$strsize</th
>";
753 echo "<th
class=\"header date\" scope
=\"col\"
>$strmodified</th
>";
754 echo "<th
class=\"header commands\" scope
=\"col\"
>$straction</th
>";
763 if (!empty($dirlist)) {
765 foreach ($dirlist as $dir) {
766 echo "<tr
class=\"folder\"
>";
769 $fileurl = rawurlencode(dirname($wdir));
771 // alt attribute intentionally empty to prevent repetition in screen reader
772 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');
779 $filename = $fullpath."/".$dir;
780 $fileurl = rawurlencode($wdir."/".$dir);
781 $filesafe = rawurlencode($dir);
782 $filesize = display_size(get_directory_size("$fullpath/$dir"));
783 $filedate = userdate(filemtime($filename), "%d %b %Y
, %I
:%M %p
");
784 print_cell("center
", "<input type
=\"checkbox\" name
=\"file
$count\" value
=\"$fileurl\" />", 'checkbox');
785 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');
786 print_cell("right
", $filesize, 'size');
787 print_cell("right
", $filedate, 'date');
788 print_cell("right
", "<a href
=\"index
.php?id
=$id&
;wdir
=$wdir&
;file
=$filesafe&
;action
=rename
&
;choose
=$choose\">$strrename</a
>", 'commands');
796 if (!empty($filelist)) {
798 foreach ($filelist as $file) {
800 $icon = mimeinfo("icon
", $file);
803 $filename = $fullpath."/".$file;
804 $fileurl = trim($wdir, "/")."/$file";
805 $filesafe = rawurlencode($file);
806 $fileurlsafe = rawurlencode($fileurl);
807 $filedate = userdate(filemtime($filename), "%d %b %Y
, %I
:%M %p
");
809 $selectfile = trim($fileurl, "/");
811 echo "<tr
class=\"file\"
>";
813 print_cell("center
", "<input type
=\"checkbox\" name
=\"file
$count\" value
=\"$fileurl\" />", 'checkbox');
814 echo "<td align
=\"left\" style
=\"white
-space
:nowrap\"
class=\"name\"
>";
815 if ($CFG->slasharguments) {
816 $ffurl = str_replace('//', '/', "/file
.php
/$id/$fileurl");
818 $ffurl = str_replace('//', '/', "/file
.php?file
=/$id/$fileurl");
820 link_to_popup_window ($ffurl, "display
",
821 "<img src
=\"$CFG->pixpath
/f
/$icon\" class=\"icon\" alt
=\"$strfile\" /> 
;".htmlspecialchars($file),
825 $file_size = filesize($filename);
826 print_cell("right
", display_size($file_size), 'size');
827 print_cell("right
", $filedate, 'date');
830 $edittext = "<strong
><a onclick
=\"return set_value('$selectfile')\" href
=\"#\">$strchoose</a></strong> ";
836 if ($icon == "text.gif" ||
$icon == "html.gif") {
837 $edittext .= "<a href=\"index.php?id=$id&wdir=$wdir&file=$fileurl&action=edit&choose=$choose\">$stredit</a>";
838 } else if ($icon == "zip.gif") {
839 $edittext .= "<a href=\"index.php?id=$id&wdir=$wdir&file=$fileurl&action=unzip&sesskey=$USER->sesskey&choose=$choose\">$strunzip</a> ";
840 $edittext .= "<a href=\"index.php?id=$id&wdir=$wdir&file=$fileurl&action=listzip&sesskey=$USER->sesskey&choose=$choose\">$strlist</a> ";
841 if (!empty($CFG->backup_version
) and has_capability('moodle/site:restore', get_context_instance(CONTEXT_COURSE
, $id))) {
842 $edittext .= "<a href=\"index.php?id=$id&wdir=$wdir&file=$filesafe&action=restore&sesskey=$USER->sesskey&choose=$choose\">$strrestore</a> ";
846 print_cell("right", "$edittext <a href=\"index.php?id=$id&wdir=$wdir&file=$filesafe&action=rename&choose=$choose\">$strrename</a>", 'commands');
853 //echo "<hr width=\"640\" align=\"center\" noshade=\"noshade\" size=\"1\" />";
855 echo "<table border=\"0\" cellspacing=\"2\" cellpadding=\"2\" width=\"640\">";
857 echo "<input type=\"hidden\" name=\"id\" value=\"$id\" />";
858 echo '<input type="hidden" name="choose" value="'.$choose.'" />';
859 echo "<input type=\"hidden\" name=\"wdir\" value=\"$wdir\" /> ";
860 echo "<input type=\"hidden\" name=\"sesskey\" value=\"$USER->sesskey\" />";
862 "move" => "$strmovetoanotherfolder",
863 "delete" => "$strdeletecompletely",
864 "zip" => "$strcreateziparchive"
866 if (!empty($count)) {
868 choose_from_menu ($options, "action", "", "$strwithchosenfiles...", "javascript:getElementById('dirform').submit()");
869 echo '<div id="noscriptgo" style="display: inline;">';
870 echo '<input type="submit" value="'.get_string('go').'" />';
871 echo '<script type="text/javascript">'.
873 'document.getElementById("noscriptgo").style.display = "none";'.
874 "\n//]]>\n".'</script>';
878 echo "</td></tr></table>";
881 echo "<table border=\"0\" cellspacing=\"2\" cellpadding=\"2\" width=\"640\"><tr>";
882 echo "<td align=\"center\">";
883 if (!empty($USER->fileop
) and ($USER->fileop
== "move") and ($USER->filesource
<> $wdir)) {
884 echo "<form action=\"index.php\" method=\"get\">";
886 echo ' <input type="hidden" name="choose" value="'.$choose.'" />';
887 echo " <input type=\"hidden\" name=\"id\" value=\"$id\" />";
888 echo " <input type=\"hidden\" name=\"wdir\" value=\"$wdir\" />";
889 echo " <input type=\"hidden\" name=\"action\" value=\"paste\" />";
890 echo " <input type=\"hidden\" name=\"sesskey\" value=\"$USER->sesskey\" />";
891 echo " <input type=\"submit\" value=\"$strmovefilestohere\" />";
896 echo "<td align=\"right\">";
897 echo "<form action=\"index.php\" method=\"get\">";
899 echo ' <input type="hidden" name="choose" value="'.$choose.'" />';
900 echo " <input type=\"hidden\" name=\"id\" value=\"$id\" />";
901 echo " <input type=\"hidden\" name=\"wdir\" value=\"$wdir\" />";
902 echo " <input type=\"hidden\" name=\"action\" value=\"makedir\" />";
903 echo " <input type=\"submit\" value=\"$strmakeafolder\" />";
907 echo "<td align=\"right\">";
908 echo "<form action=\"index.php\" method=\"get\">"; //dummy form - alignment only
909 echo "<fieldset class=\"invisiblefieldset\">";
910 echo " <input type=\"button\" value=\"$strselectall\" onclick=\"checkall();\" />";
911 echo " <input type=\"button\" value=\"$strselectnone\" onclick=\"uncheckall();\" />";
915 echo "<td align=\"right\">";
916 echo "<form action=\"index.php\" method=\"get\">";
918 echo ' <input type="hidden" name="choose" value="'.$choose.'" />';
919 echo " <input type=\"hidden\" name=\"id\" value=\"$id\" />";
920 echo " <input type=\"hidden\" name=\"wdir\" value=\"$wdir\" />";
921 echo " <input type=\"hidden\" name=\"action\" value=\"upload\" />";
922 echo " <input type=\"submit\" value=\"$struploadafile\" />";
928 //echo "<hr width=\"640\" align=\"center\" noshade=\"noshade\" size=\"1\" />";