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, $adminroot;
44 echo '</td></tr></table>';
46 if ($course->id
== SITEID
) {
47 admin_externalpage_print_footer($adminroot);
49 print_footer($course);
53 function html_header($course, $wdir, $formfield=""){
54 global $CFG, $ME, $choose;
56 if ($course->id
== SITEID
) {
57 $strfiles = get_string("sitefiles");
59 $strfiles = get_string("files");
63 $fullnav = "$strfiles";
65 $dirs = explode("/", $wdir);
66 $numdirs = count($dirs);
69 for ($i=1; $i<$numdirs-1; $i++
) {
70 $navigation .= " -> ";
71 $link .= "/".urlencode($dirs[$i]);
72 $navigation .= "<a href=\"".$ME."?id=$course->id&wdir=$link&choose=$choose\">".$dirs[$i]."</a>";
74 $fullnav = "<a href=\"".$ME."?id=$course->id&wdir=/&choose=$choose\">$strfiles</a> $navigation -> ".$dirs[$numdirs-1];
81 $chooseparts = explode('.', $choose);
82 if (count($chooseparts)==2){
84 <script type
="text/javascript">
86 function set_value(txt
) {
87 opener
.document
.forms
['<?php echo $chooseparts[0]."'].".$chooseparts[1] ?>.value = txt;
94 } elseif (count($chooseparts)==1){
96 <script type="text
/javascript
">
98 function set_value(txt) {
99 opener.document.getElementById('<?php echo $chooseparts[0] ?>').value = txt;
108 $fullnav = str_replace('->', '»', "$course->shortname
-> $fullnav");
109 echo '<div id="nav
-bar
">'.$fullnav.'</div>';
111 if ($course->id == SITEID and $wdir != "/backupdata
") {
112 print_heading(get_string("publicsitefileswarning
"), "center
", 2);
117 if ($course->id == SITEID) {
119 if ($wdir == "/backupdata
") {
120 $adminroot = admin_get_root();
121 admin_externalpage_setup('frontpagerestore', $adminroot);
122 admin_externalpage_print_header($adminroot);
124 $adminroot = admin_get_root();
125 admin_externalpage_setup('sitefiles', $adminroot);
126 admin_externalpage_print_header($adminroot);
128 print_heading(get_string("publicsitefileswarning
"), "center
", 2);
133 print_header("$course->shortname
: $strfiles", $course->fullname,
134 "<a href
=\"../course
/view
.php?id
=$course->id\"
>$course->shortname
".
135 "</a
> -> $fullnav", $formfield);
140 echo "<table border
=\"0\" style
=\"margin
-left
:auto
;margin
-right
:auto\" cellspacing
=\"3\" cellpadding
=\"3\" width
=\"640\">";
142 echo "<td colspan
=\"2\">";
147 if (! $basedir = make_upload_directory("$course->id
")) {
148 error("The site administrator needs to fix the file permissions
");
151 $baseweb = $CFG->wwwroot;
153 // End of configuration and access control
160 if ($wdir{0} != '/') { //make sure $wdir starts with slash
164 if ($wdir == "/backupdata
") {
165 if (! make_upload_directory("$course->id
/backupdata
")) { // Backup folder
166 error("Could not create backupdata folder
. The site administrator needs to fix the file permissions
");
170 if (!is_dir($basedir.$wdir)) {
171 html_header($course, $wdir);
172 error("Requested directory does not exist
.", "$CFG->wwwroot
/files
/index
.php?id
=$id");
178 html_header($course, $wdir);
179 require_once($CFG->dirroot.'/lib/uploadlib.php');
181 if ($save and confirm_sesskey()) {
182 $course->maxbytes = 0; // We are ignoring course limits
183 $um = new upload_manager('userfile',false,false,$course,false,0);
184 $dir = "$basedir$wdir";
185 if ($um->process_file_uploads($dir)) {
186 notify(get_string('uploadedfile'));
188 // um will take care of error reporting.
191 $upload_max_filesize = get_max_upload_file_size($CFG->maxbytes);
192 $filesize = display_size($upload_max_filesize);
194 $struploadafile = get_string("uploadafile
");
195 $struploadthisfile = get_string("uploadthisfile
");
196 $strmaxsize = get_string("maxsize
", "", $filesize);
197 $strcancel = get_string("cancel
");
199 echo "<p
>$struploadafile ($strmaxsize) --> <b
>$wdir</b
></p
>";
200 echo "<form enctype
=\"multipart
/form
-data\" method
=\"post\" action
=\"index
.php\"
>";
202 echo "<table
><tr
><td colspan
=\"2\">";
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
=\"upload\"
/>";
207 echo " <input type
=\"hidden\" name
=\"sesskey\" value
=\"$USER->sesskey\"
/>";
208 upload_print_form_fragment(1,array('userfile'),null,false,null,$upload_max_filesize,0,false);
209 echo " </td
></tr
></table
>";
210 echo " <input type
=\"submit\" name
=\"save\" value
=\"$struploadthisfile\" />";
212 echo "<form action
=\"index
.php\" method
=\"get\"
>";
213 echo ' <input type="hidden
" name="choose
" value="'.$choose.'" />';
214 echo " <input type
=\"hidden\" name
=\"id\" value
=\"$id\" />";
215 echo " <input type
=\"hidden\" name
=\"wdir\" value
=\"$wdir\" />";
216 echo " <input type
=\"hidden\" name
=\"action\" value
=\"cancel\"
/>";
217 echo " <input type
=\"submit\" value
=\"$strcancel\" />";
225 if ($confirm and confirm_sesskey()) {
226 html_header($course, $wdir);
227 if (!empty($USER->filelist)) {
228 foreach ($USER->filelist as $file) {
229 $fullfile = $basedir.'/'.$file;
230 if (! fulldelete($fullfile)) {
231 echo "<br
/>Error
: Could not delete
: $fullfile";
240 html_header($course, $wdir);
242 if (setfilelist($_POST)) {
243 notify(get_string('deletecheckwarning').':');
244 print_simple_box_start("center
");
245 printfilelist($USER->filelist);
246 print_simple_box_end();
249 require_once($CFG->dirroot.'/mod/resource/lib.php');
250 $block = resource_delete_warning($course, $USER->filelist);
252 if (empty($CFG->resource_blockdeletingfile) or $block == '') {
253 $optionsyes = array('id'=>$id, 'wdir'=>$wdir, 'action'=>'delete', 'confirm'=>1, 'sesskey'=>sesskey(), 'choose'=>$choose);
254 $optionsno = array('id'=>$id, 'wdir'=>$wdir, 'action'=>'cancel', 'choose'=>$choose);
255 notice_yesno (get_string('deletecheckfiles'), 'index.php', 'index.php', $optionsyes, $optionsno, 'post', 'get');
258 notify(get_string('warningblockingdelete', 'resource'));
259 $options = array('id'=>$id, 'wdir'=>$wdir, 'action'=>'cancel', 'choose'=>$choose);
260 print_continue("index
.php?id
=$id&
;wdir
=$wdir&
;action
=cancel
&
;choose
=$choose");
270 html_header($course, $wdir);
271 if (($count = setfilelist($_POST)) and confirm_sesskey()) {
272 $USER->fileop = $action;
273 $USER->filesource = $wdir;
274 echo "<p
class=\"centerpara\"
>";
275 print_string("selectednowmove
", "moodle
", $count);
283 html_header($course, $wdir);
284 if (isset($USER->fileop) and ($USER->fileop == "move
") and confirm_sesskey()) {
285 foreach ($USER->filelist as $file) {
286 $shortfile = basename($file);
287 $oldfile = $basedir.'/'.$file;
288 $newfile = $basedir.$wdir."/".$shortfile;
289 if (!rename($oldfile, $newfile)) {
290 echo "<p
>Error
: $shortfile not moved
</p
>";
300 if (($name != '') and confirm_sesskey()) {
301 html_header($course, $wdir);
302 $name = clean_filename($name);
303 if (file_exists($basedir.$wdir."/".$name)) {
304 echo "<center
>Error
: $name already exists
!</center
>";
305 } else if (!rename($basedir.$wdir."/".$oldname, $basedir.$wdir."/".$name)) {
306 echo "<p align
=\"center\"
>Error
: could not rename
$oldname to
$name</p
>";
308 //file was renamed now update resources if needed
309 require_once($CFG->dirroot.'/mod/resource/lib.php');
310 resource_renamefiles($course, $wdir, $oldname, $name);
315 $strrename = get_string("rename
");
316 $strcancel = get_string("cancel
");
317 $strrenamefileto = get_string("renamefileto
", "moodle
", $file);
318 html_header($course, $wdir, "form
.name
");
319 echo "<p
>$strrenamefileto:</p
>";
320 echo "<table
><tr
><td
>";
321 echo "<form action
=\"index
.php\" method
=\"post\"
>";
322 echo "<fieldset
class=\"invisiblefieldset\"
>";
323 echo ' <input type="hidden
" name="choose
" value="'.$choose.'" />';
324 echo " <input type
=\"hidden\" name
=\"id\" value
=\"$id\" />";
325 echo " <input type
=\"hidden\" name
=\"wdir\" value
=\"$wdir\" />";
326 echo " <input type
=\"hidden\" name
=\"action\" value
=\"rename\"
/>";
327 echo " <input type
=\"hidden\" name
=\"oldname\" value
=\"$file\" />";
328 echo " <input type
=\"hidden\" name
=\"sesskey\" value
=\"$USER->sesskey\"
/>";
329 echo " <input type
=\"text\" name
=\"name\" size
=\"35\" value
=\"$file\" />";
330 echo " <input type
=\"submit\" value
=\"$strrename\" />";
334 echo "<form action
=\"index
.php\" method
=\"get\"
>";
336 echo ' <input type="hidden
" name="choose
" value="'.$choose.'" />';
337 echo " <input type
=\"hidden\" name
=\"id\" value
=\"$id\" />";
338 echo " <input type
=\"hidden\" name
=\"wdir\" value
=\"$wdir\" />";
339 echo " <input type
=\"hidden\" name
=\"action\" value
=\"cancel\"
/>";
340 echo " <input type
=\"submit\" value
=\"$strcancel\" />";
343 echo "</td
></tr
></table
>";
349 if (($name != '') and confirm_sesskey()) {
350 html_header($course, $wdir);
351 $name = clean_filename($name);
352 if (file_exists("$basedir$wdir/$name")) {
353 echo "Error
: $name already exists
!";
354 } else if (! make_upload_directory("$course->id
$wdir/$name")) {
355 echo "Error
: could not create
$name";
360 $strcreate = get_string("create
");
361 $strcancel = get_string("cancel
");
362 $strcreatefolder = get_string("createfolder
", "moodle
", $wdir);
363 html_header($course, $wdir, "form
.name
");
364 echo "<p
>$strcreatefolder:</p
>";
365 echo "<table
><tr
><td
>";
366 echo "<form action
=\"index
.php\" method
=\"post\"
>";
367 echo "<fieldset
class=\"invisiblefieldset\"
>";
368 echo ' <input type="hidden
" name="choose
" value="'.$choose.'" />';
369 echo " <input type
=\"hidden\" name
=\"id\" value
=\"$id\" />";
370 echo " <input type
=\"hidden\" name
=\"wdir\" value
=\"$wdir\" />";
371 echo " <input type
=\"hidden\" name
=\"action\" value
=\"makedir\"
/>";
372 echo " <input type
=\"text\" name
=\"name\" size
=\"35\" />";
373 echo " <input type
=\"hidden\" name
=\"sesskey\" value
=\"$USER->sesskey\"
/>";
374 echo " <input type
=\"submit\" value
=\"$strcreate\" />";
378 echo "<form action
=\"index
.php\" method
=\"get\"
>";
380 echo ' <input type="hidden
" name="choose
" value="'.$choose.'" />';
381 echo " <input type
=\"hidden\" name
=\"id\" value
=\"$id\" />";
382 echo " <input type
=\"hidden\" name
=\"wdir\" value
=\"$wdir\" />";
383 echo " <input type
=\"hidden\" name
=\"action\" value
=\"cancel\"
/>";
384 echo " <input type
=\"submit\" value
=\"$strcancel\" />";
387 echo "</td
></tr
></table
>";
393 html_header($course, $wdir);
394 if (($text != '') and confirm_sesskey()) {
395 $fileptr = fopen($basedir.'/'.$file,"w
");
396 $text = preg_replace('/\x0D/', '', $text); // http://moodle.org/mod/forum/discuss.php?d=38860
397 fputs($fileptr, stripslashes($text));
402 $streditfile = get_string("edit
", "", "<b
>$file</b
>");
403 $fileptr = fopen($basedir.'/'.$file, "r
");
404 $contents = fread($fileptr, filesize($basedir.'/'.$file));
407 if (mimeinfo("type
", $file) == "text
/html
") {
408 $usehtmleditor = can_use_html_editor();
410 $usehtmleditor = false;
412 $usehtmleditor = false; // Always keep it off for now
414 print_heading("$streditfile");
416 echo "<table
><tr
><td colspan
=\"2\">";
417 echo "<form action
=\"index
.php\" method
=\"post\"
>";
419 echo ' <input type="hidden
" name="choose
" value="'.$choose.'" />';
420 echo " <input type
=\"hidden\" name
=\"id\" value
=\"$id\" />";
421 echo " <input type
=\"hidden\" name
=\"wdir\" value
=\"$wdir\" />";
422 echo " <input type
=\"hidden\" name
=\"file\" value
=\"$file\" />";
423 echo " <input type
=\"hidden\" name
=\"action\" value
=\"edit\"
/>";
424 echo " <input type
=\"hidden\" name
=\"sesskey\" value
=\"$USER->sesskey\"
/>";
425 print_textarea($usehtmleditor, 25, 80, 680, 400, "text
", $contents);
426 echo "</td
></tr
><tr
><td
>";
427 echo " <input type
=\"submit\" value
=\"".get_string("savechanges
")."\"
/>";
431 echo "<form action
=\"index
.php\" method
=\"get\"
>";
433 echo ' <input type="hidden
" name="choose
" value="'.$choose.'" />';
434 echo " <input type
=\"hidden\" name
=\"id\" value
=\"$id\" />";
435 echo " <input type
=\"hidden\" name
=\"wdir\" value
=\"$wdir\" />";
436 echo " <input type
=\"hidden\" name
=\"action\" value
=\"cancel\"
/>";
437 echo " <input type
=\"submit\" value
=\"".get_string("cancel
")."\"
/>";
440 echo "</td
></tr
></table
>";
442 if ($usehtmleditor) {
452 if (($name != '') and confirm_sesskey()) {
453 html_header($course, $wdir);
454 $name = clean_filename($name);
457 foreach ($USER->filelist as $file) {
458 $files[] = "$basedir/$file";
461 if (!zip_files($files,"$basedir$wdir/$name")) {
462 error(get_string("zipfileserror
","error
"));
469 html_header($course, $wdir, "form
.name
");
471 if (setfilelist($_POST)) {
472 echo "<p align
=\"center\"
>".get_string("youareabouttocreatezip
").":</p
>";
473 print_simple_box_start("center
");
474 printfilelist($USER->filelist);
475 print_simple_box_end();
477 echo "<p align
=\"center\"
>".get_string("whattocallzip
")."</p
>";
478 echo "<table
><tr
><td
>";
479 echo "<form action
=\"index
.php\" method
=\"post\"
>";
480 echo "<fieldset
class=\"invisiblefieldset\"
>";
481 echo ' <input type="hidden
" name="choose
" value="'.$choose.'" />';
482 echo " <input type
=\"hidden\" name
=\"id\" value
=\"$id\" />";
483 echo " <input type
=\"hidden\" name
=\"wdir\" value
=\"$wdir\" />";
484 echo " <input type
=\"hidden\" name
=\"action\" value
=\"zip\"
/>";
485 echo " <input type
=\"text\" name
=\"name\" size
=\"35\" value
=\"new.zip\"
/>";
486 echo " <input type
=\"hidden\" name
=\"sesskey\" value
=\"$USER->sesskey\"
/>";
487 echo " <input type
=\"submit\" value
=\"".get_string("createziparchive
")."\"
/>";
491 echo "<form action
=\"index
.php\" method
=\"get\"
>";
493 echo ' <input type="hidden
" name="choose
" value="'.$choose.'" />';
494 echo " <input type
=\"hidden\" name
=\"id\" value
=\"$id\" />";
495 echo " <input type
=\"hidden\" name
=\"wdir\" value
=\"$wdir\" />";
496 echo " <input type
=\"hidden\" name
=\"action\" value
=\"cancel\"
/>";
497 echo " <input type
=\"submit\" value
=\"".get_string("cancel
")."\"
/>";
500 echo "</td
></tr
></table
>";
510 html_header($course, $wdir);
511 if (($file != '') and confirm_sesskey()) {
512 $strok = get_string("ok
");
513 $strunpacking = get_string("unpacking
", "", $file);
515 echo "<p align
=\"center\"
>$strunpacking:</p
>";
517 $file = basename($file);
519 if (!unzip_file("$basedir$wdir/$file")) {
520 error(get_string("unzipfileserror
","error
"));
523 echo "<div style
=\"text
-align
:center\"
><form action
=\"index
.php\" method
=\"get\"
>";
525 echo ' <input type="hidden
" name="choose
" value="'.$choose.'" />';
526 echo " <input type
=\"hidden\" name
=\"id\" value
=\"$id\" />";
527 echo " <input type
=\"hidden\" name
=\"wdir\" value
=\"$wdir\" />";
528 echo " <input type
=\"hidden\" name
=\"action\" value
=\"cancel\"
/>";
529 echo " <input type
=\"submit\" value
=\"$strok\" />";
540 html_header($course, $wdir);
541 if (($file != '') and confirm_sesskey()) {
542 $strname = get_string("name
");
543 $strsize = get_string("size
");
544 $strmodified = get_string("modified
");
545 $strok = get_string("ok
");
546 $strlistfiles = get_string("listfiles
", "", $file);
548 echo "<p align
=\"center\"
>$strlistfiles:</p
>";
549 $file = basename($file);
551 include_once("$CFG->libdir
/pclzip
/pclzip
.lib
.php
");
552 $archive = new PclZip(cleardoubleslashes("$basedir$wdir/$file"));
553 if (!$list = $archive->listContent(cleardoubleslashes("$basedir$wdir"))) {
554 notify($archive->errorInfo(true));
557 echo "<table cellpadding
=\"4\" cellspacing
=\"2\" border
=\"0\" width
=\"640\" class=\"files\"
>";
558 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
>";
559 foreach ($list as $item) {
561 print_cell("left
", s($item['filename']), 'name');
562 if (! $item['folder']) {
563 print_cell("right
", display_size($item['size']), 'size');
565 echo "<td
> 
;</td
>";
567 $filedate = userdate($item['mtime'], get_string("strftimedatetime
"));
568 print_cell("right
", $filedate, 'date');
573 echo "<br
/><center
><form action
=\"index
.php\" method
=\"get\"
>";
575 echo ' <input type="hidden
" name="choose
" value="'.$choose.'" />';
576 echo " <input type
=\"hidden\" name
=\"id\" value
=\"$id\" />";
577 echo " <input type
=\"hidden\" name
=\"wdir\" value
=\"$wdir\" />";
578 echo " <input type
=\"hidden\" name
=\"action\" value
=\"cancel\"
/>";
579 echo " <input type
=\"submit\" value
=\"$strok\" />";
590 html_header($course, $wdir);
591 if (($file != '') and confirm_sesskey()) {
592 echo "<p align
=\"center\"
>".get_string("youaregoingtorestorefrom
").":</p
>";
593 print_simple_box_start("center
");
595 print_simple_box_end();
597 echo "<p align
=\"center\"
>".get_string("areyousuretorestorethisinfo
")."</p
>";
598 $restore_path = "$CFG->wwwroot
/backup
/restore
.php
";
599 notice_yesno (get_string("areyousuretorestorethis
"),
600 $restore_path."?id
=".$id."&
;file
=".cleardoubleslashes($id.$wdir."/".$file)."&
;method
=manual
",
601 "index
.php?id
=$id&
;wdir
=$wdir&
;action
=cancel
");
612 html_header($course, $wdir);
619 /// FILE FUNCTIONS ///////////////////////////////////////////////////////////
622 function setfilelist($VARS) {
625 $USER->filelist = array ();
629 foreach ($VARS as $key => $val) {
630 if (substr($key,0,4) == "file
") {
632 $val = rawurldecode($val);
633 $USER->filelist[] = clean_param($val, PARAM_PATH);
639 function clearfilelist() {
642 $USER->filelist = array ();
647 function printfilelist($filelist) {
648 global $CFG, $basedir;
650 $strfolder = get_string("folder
");
651 $strfile = get_string("file
");
653 foreach ($filelist as $file) {
654 if (is_dir($basedir.'/'.$file)) {
655 echo "<img src
=\"$CFG->pixpath
/f
/folder
.gif\"
class=\"icon\" alt
=\"$strfolder\" /> $file<br
/>";
656 $subfilelist = array();
657 $currdir = opendir($basedir.'/'.$file);
658 while (false !== ($subfile = readdir($currdir))) {
659 if ($subfile <> ".." && $subfile <> ".") {
660 $subfilelist[] = $file."/".$subfile;
663 printfilelist($subfilelist);
666 $icon = mimeinfo("icon
", $file);
667 echo "<img src
=\"$CFG->pixpath
/f
/$icon\" class=\"icon\" alt
=\"$strfile\" /> $file<br
/>";
673 function print_cell($alignment='center', $text=' ', $class='') {
675 $class = ' class="'.$class.'"';
677 echo '<td align="'.$alignment.'" style="white
-space
:nowrap
"'.$class.'>'.$text.'</td>';
680 function displaydir ($wdir) {
681 // $wdir == / or /a or /a/b/c/d etc
688 $fullpath = $basedir.$wdir;
691 $directory = opendir($fullpath); // Find all files
692 while (false !== ($file = readdir($directory))) {
693 if ($file == "." || $file == "..") {
697 if (is_dir($fullpath."/".$file)) {
703 closedir($directory);
705 $strname = get_string("name
");
706 $strsize = get_string("size
");
707 $strmodified = get_string("modified
");
708 $straction = get_string("action
");
709 $strmakeafolder = get_string("makeafolder
");
710 $struploadafile = get_string("uploadafile
");
711 $strselectall = get_string("selectall
");
712 $strselectnone = get_string("deselectall
");
713 $strwithchosenfiles = get_string("withchosenfiles
");
714 $strmovetoanotherfolder = get_string("movetoanotherfolder
");
715 $strmovefilestohere = get_string("movefilestohere
");
716 $strdeletecompletely = get_string("deletecompletely
");
717 $strcreateziparchive = get_string("createziparchive
");
718 $strrename = get_string("rename
");
719 $stredit = get_string("edit
");
720 $strunzip = get_string("unzip
");
721 $strlist = get_string("list");
722 $strrestore= get_string("restore
");
723 $strchoose = get_string("choose
");
724 $strfolder = get_string("folder
");
725 $strfile = get_string("file
");
728 echo "<form action
=\"index
.php\" method
=\"post\" id
=\"dirform\"
>";
730 echo '<input type="hidden
" name="choose
" value="'.$choose.'" />';
731 // echo "<hr align
=\"center\" noshade
=\"noshade\" size
=\"1\" />";
733 echo "<table border
=\"0\" cellspacing
=\"2\" cellpadding
=\"2\" width
=\"640\" class=\"files\"
>";
735 echo "<th scope
=\"col\"
></th
>";
736 echo "<th
class=\"header name\" scope
=\"col\"
>$strname</th
>";
737 echo "<th
class=\"header size\" scope
=\"col\"
>$strsize</th
>";
738 echo "<th
class=\"header date\" scope
=\"col\"
>$strmodified</th
>";
739 echo "<th
class=\"header commands\" scope
=\"col\"
>$straction</th
>";
748 if (!empty($dirlist)) {
750 foreach ($dirlist as $dir) {
751 echo "<tr
class=\"folder\"
>";
754 $fileurl = rawurlencode(dirname($wdir));
756 // alt attribute intentionally empty to prevent repetition in screen reader
757 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');
764 $filename = $fullpath."/".$dir;
765 $fileurl = rawurlencode($wdir."/".$dir);
766 $filesafe = rawurlencode($dir);
767 $filesize = display_size(get_directory_size("$fullpath/$dir"));
768 $filedate = userdate(filemtime($filename), "%d %b %Y
, %I
:%M %p
");
769 print_cell("center
", "<input type
=\"checkbox\" name
=\"file
$count\" value
=\"$fileurl\" />", 'checkbox');
770 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');
771 print_cell("right
", $filesize, 'size');
772 print_cell("right
", $filedate, 'date');
773 print_cell("right
", "<a href
=\"index
.php?id
=$id&
;wdir
=$wdir&
;file
=$filesafe&
;action
=rename
&
;choose
=$choose\">$strrename</a
>", 'commands');
781 if (!empty($filelist)) {
783 foreach ($filelist as $file) {
785 $icon = mimeinfo("icon
", $file);
788 $filename = $fullpath."/".$file;
789 $fileurl = trim($wdir, "/")."/$file";
790 $filesafe = rawurlencode($file);
791 $fileurlsafe = rawurlencode($fileurl);
792 $filedate = userdate(filemtime($filename), "%d %b %Y
, %I
:%M %p
");
794 $selectfile = trim($fileurl, "/");
796 echo "<tr
class=\"file\"
>";
798 print_cell("center
", "<input type
=\"checkbox\" name
=\"file
$count\" value
=\"$fileurl\" />", 'checkbox');
799 echo "<td align
=\"left\" style
=\"white
-space
:nowrap\"
class=\"name\"
>";
800 if ($CFG->slasharguments) {
801 $ffurl = str_replace('//', '/', "/file
.php
/$id/$fileurl");
803 $ffurl = str_replace('//', '/', "/file
.php?file
=/$id/$fileurl");
805 link_to_popup_window ($ffurl, "display
",
806 "<img src
=\"$CFG->pixpath
/f
/$icon\" class=\"icon\" alt
=\"$strfile\" /> 
;".htmlspecialchars($file),
810 $file_size = filesize($filename);
811 print_cell("right
", display_size($file_size), 'size');
812 print_cell("right
", $filedate, 'date');
815 $edittext = "<strong
><a onclick
=\"return set_value('$selectfile')\" href
=\"#\">$strchoose</a></strong> ";
821 if ($icon == "text.gif" ||
$icon == "html.gif") {
822 $edittext .= "<a href=\"index.php?id=$id&wdir=$wdir&file=$fileurl&action=edit&choose=$choose\">$stredit</a>";
823 } else if ($icon == "zip.gif") {
824 $edittext .= "<a href=\"index.php?id=$id&wdir=$wdir&file=$fileurl&action=unzip&sesskey=$USER->sesskey&choose=$choose\">$strunzip</a> ";
825 $edittext .= "<a href=\"index.php?id=$id&wdir=$wdir&file=$fileurl&action=listzip&sesskey=$USER->sesskey&choose=$choose\">$strlist</a> ";
826 if (!empty($CFG->backup_version
) and has_capability('moodle/site:restore', get_context_instance(CONTEXT_COURSE
, $id))) {
827 $edittext .= "<a href=\"index.php?id=$id&wdir=$wdir&file=$filesafe&action=restore&sesskey=$USER->sesskey&choose=$choose\">$strrestore</a> ";
831 print_cell("right", "$edittext <a href=\"index.php?id=$id&wdir=$wdir&file=$filesafe&action=rename&choose=$choose\">$strrename</a>", 'commands');
838 //echo "<hr width=\"640\" align=\"center\" noshade=\"noshade\" size=\"1\" />";
840 echo "<table border=\"0\" cellspacing=\"2\" cellpadding=\"2\" width=\"640\">";
842 echo "<input type=\"hidden\" name=\"id\" value=\"$id\" />";
843 echo '<input type="hidden" name="choose" value="'.$choose.'" />';
844 echo "<input type=\"hidden\" name=\"wdir\" value=\"$wdir\" /> ";
845 echo "<input type=\"hidden\" name=\"sesskey\" value=\"$USER->sesskey\" />";
847 "move" => "$strmovetoanotherfolder",
848 "delete" => "$strdeletecompletely",
849 "zip" => "$strcreateziparchive"
851 if (!empty($count)) {
852 choose_from_menu ($options, "action", "", "$strwithchosenfiles...", "javascript:getElementById('dirform').submit()");
854 echo "</td></tr></table>";
857 echo "<table border=\"0\" cellspacing=\"2\" cellpadding=\"2\" width=\"640\"><tr>";
858 echo "<td align=\"center\">";
859 if (!empty($USER->fileop
) and ($USER->fileop
== "move") and ($USER->filesource
<> $wdir)) {
860 echo "<form action=\"index.php\" method=\"get\">";
862 echo ' <input type="hidden" name="choose" value="'.$choose.'" />';
863 echo " <input type=\"hidden\" name=\"id\" value=\"$id\" />";
864 echo " <input type=\"hidden\" name=\"wdir\" value=\"$wdir\" />";
865 echo " <input type=\"hidden\" name=\"action\" value=\"paste\" />";
866 echo " <input type=\"hidden\" name=\"sesskey\" value=\"$USER->sesskey\" />";
867 echo " <input type=\"submit\" value=\"$strmovefilestohere\" />";
872 echo "<td align=\"right\">";
873 echo "<form action=\"index.php\" method=\"get\">";
875 echo ' <input type="hidden" name="choose" value="'.$choose.'" />';
876 echo " <input type=\"hidden\" name=\"id\" value=\"$id\" />";
877 echo " <input type=\"hidden\" name=\"wdir\" value=\"$wdir\" />";
878 echo " <input type=\"hidden\" name=\"action\" value=\"makedir\" />";
879 echo " <input type=\"submit\" value=\"$strmakeafolder\" />";
883 echo "<td align=\"right\">";
884 echo "<form action=\"index.php\" method=\"get\">"; //dummy form - alignment only
885 echo "<fieldset class=\"invisiblefieldset\">";
886 echo " <input type=\"button\" value=\"$strselectall\" onclick=\"checkall();\" />";
887 echo " <input type=\"button\" value=\"$strselectnone\" onclick=\"uncheckall();\" />";
891 echo "<td align=\"right\">";
892 echo "<form action=\"index.php\" method=\"get\">";
894 echo ' <input type="hidden" name="choose" value="'.$choose.'" />';
895 echo " <input type=\"hidden\" name=\"id\" value=\"$id\" />";
896 echo " <input type=\"hidden\" name=\"wdir\" value=\"$wdir\" />";
897 echo " <input type=\"hidden\" name=\"action\" value=\"upload\" />";
898 echo " <input type=\"submit\" value=\"$struploadafile\" />";
904 //echo "<hr width=\"640\" align=\"center\" noshade=\"noshade\" size=\"1\" />";