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;
52 if ($course->id
== SITEID
) {
53 $strfiles = get_string("sitefiles");
55 $strfiles = get_string("files");
59 $fullnav = "$strfiles";
61 $dirs = explode("/", $wdir);
62 $numdirs = count($dirs);
65 for ($i=1; $i<$numdirs-1; $i++
) {
66 $navigation .= " -> ";
67 $link .= "/".urlencode($dirs[$i]);
68 $navigation .= "<a href=\"".$ME."?id=$course->id&wdir=$link&choose=$choose\">".$dirs[$i]."</a>";
70 $fullnav = "<a href=\"".$ME."?id=$course->id&wdir=/&choose=$choose\">$strfiles</a> $navigation -> ".$dirs[$numdirs-1];
77 $chooseparts = explode('.', $choose);
78 if (count($chooseparts)==2){
80 <script type
="text/javascript">
82 function set_value(txt
) {
83 opener
.document
.forms
['<?php echo $chooseparts[0]."'].".$chooseparts[1] ?>.value = txt;
90 } elseif (count($chooseparts)==1){
92 <script type="text
/javascript
">
94 function set_value(txt) {
95 opener.document.getElementById('<?php echo $chooseparts[0] ?>').value = txt;
104 $fullnav = str_replace('->', '»', format_string($course->shortname) . " -> $fullnav");
105 echo '<div id="nav
-bar
">'.$fullnav.'</div>';
107 if ($course->id == SITEID and $wdir != "/backupdata
") {
108 print_heading(get_string("publicsitefileswarning
"), "center
", 2);
113 if ($course->id == SITEID) {
115 if ($wdir == "/backupdata
") {
116 admin_externalpage_setup('frontpagerestore');
117 admin_externalpage_print_header();
119 admin_externalpage_setup('sitefiles');
120 admin_externalpage_print_header();
122 print_heading(get_string("publicsitefileswarning
"), "center
", 2);
127 print_header("$course->shortname
: $strfiles", $course->fullname,
128 "<a href
=\"../course
/view
.php?id
=$course->id\"
>$course->shortname
".
129 "</a
> -> $fullnav", $formfield);
134 echo "<table border
=\"0\" style
=\"margin
-left
:auto
;margin
-right
:auto\" cellspacing
=\"3\" cellpadding
=\"3\" width
=\"640\">";
136 echo "<td colspan
=\"2\">";
141 if (! $basedir = make_upload_directory("$course->id
")) {
142 error("The site administrator needs to fix the file permissions
");
145 $baseweb = $CFG->wwwroot;
147 // End of configuration and access control
154 if ($wdir{0} != '/') { //make sure $wdir starts with slash
158 if ($wdir == "/backupdata
") {
159 if (! make_upload_directory("$course->id
/backupdata
")) { // Backup folder
160 error("Could not create backupdata folder
. The site administrator needs to fix the file permissions
");
164 if (!is_dir($basedir.$wdir)) {
165 html_header($course, $wdir);
166 error("Requested directory does not exist
.", "$CFG->wwwroot
/files
/index
.php?id
=$id");
172 html_header($course, $wdir);
173 require_once($CFG->dirroot.'/lib/uploadlib.php');
175 if ($save and confirm_sesskey()) {
176 $course->maxbytes = 0; // We are ignoring course limits
177 $um = new upload_manager('userfile',false,false,$course,false,0);
178 $dir = "$basedir$wdir";
179 if ($um->process_file_uploads($dir)) {
180 notify(get_string('uploadedfile'));
182 // um will take care of error reporting.
185 $upload_max_filesize = get_max_upload_file_size($CFG->maxbytes);
186 $filesize = display_size($upload_max_filesize);
188 $struploadafile = get_string("uploadafile
");
189 $struploadthisfile = get_string("uploadthisfile
");
190 $strmaxsize = get_string("maxsize
", "", $filesize);
191 $strcancel = get_string("cancel
");
193 echo "<p
>$struploadafile ($strmaxsize) --> <b
>$wdir</b
></p
>";
194 echo "<form enctype
=\"multipart
/form
-data\" method
=\"post\" action
=\"index
.php\"
>";
196 echo "<table
><tr
><td colspan
=\"2\">";
197 echo ' <input type="hidden
" name="choose
" value="'.$choose.'" />';
198 echo " <input type
=\"hidden\" name
=\"id\" value
=\"$id\" />";
199 echo " <input type
=\"hidden\" name
=\"wdir\" value
=\"$wdir\" />";
200 echo " <input type
=\"hidden\" name
=\"action\" value
=\"upload\"
/>";
201 echo " <input type
=\"hidden\" name
=\"sesskey\" value
=\"$USER->sesskey\"
/>";
202 upload_print_form_fragment(1,array('userfile'),null,false,null,$upload_max_filesize,0,false);
203 echo " </td
></tr
></table
>";
204 echo " <input type
=\"submit\" name
=\"save\" value
=\"$struploadthisfile\" />";
207 echo "<form action
=\"index
.php\" method
=\"get\"
>";
209 echo ' <input type="hidden
" name="choose
" value="'.$choose.'" />';
210 echo " <input type
=\"hidden\" name
=\"id\" value
=\"$id\" />";
211 echo " <input type
=\"hidden\" name
=\"wdir\" value
=\"$wdir\" />";
212 echo " <input type
=\"hidden\" name
=\"action\" value
=\"cancel\"
/>";
213 echo " <input type
=\"submit\" value
=\"$strcancel\" />";
221 if ($confirm and confirm_sesskey()) {
222 html_header($course, $wdir);
223 if (!empty($USER->filelist)) {
224 foreach ($USER->filelist as $file) {
225 $fullfile = $basedir.'/'.$file;
226 if (! fulldelete($fullfile)) {
227 echo "<br
/>Error
: Could not delete
: $fullfile";
236 html_header($course, $wdir);
238 if (setfilelist($_POST)) {
239 notify(get_string('deletecheckwarning').':');
240 print_simple_box_start("center
");
241 printfilelist($USER->filelist);
242 print_simple_box_end();
245 require_once($CFG->dirroot.'/mod/resource/lib.php');
246 $block = resource_delete_warning($course, $USER->filelist);
248 if (empty($CFG->resource_blockdeletingfile) or $block == '') {
249 $optionsyes = array('id'=>$id, 'wdir'=>$wdir, 'action'=>'delete', 'confirm'=>1, 'sesskey'=>sesskey(), 'choose'=>$choose);
250 $optionsno = array('id'=>$id, 'wdir'=>$wdir, 'action'=>'cancel', 'choose'=>$choose);
251 notice_yesno (get_string('deletecheckfiles'), 'index.php', 'index.php', $optionsyes, $optionsno, 'post', 'get');
254 notify(get_string('warningblockingdelete', 'resource'));
255 $options = array('id'=>$id, 'wdir'=>$wdir, 'action'=>'cancel', 'choose'=>$choose);
256 print_continue("index
.php?id
=$id&
;wdir
=$wdir&
;action
=cancel
&
;choose
=$choose");
266 html_header($course, $wdir);
267 if (($count = setfilelist($_POST)) and confirm_sesskey()) {
268 $USER->fileop = $action;
269 $USER->filesource = $wdir;
270 echo "<p
class=\"centerpara\"
>";
271 print_string("selectednowmove
", "moodle
", $count);
279 html_header($course, $wdir);
280 if (isset($USER->fileop) and ($USER->fileop == "move
") and confirm_sesskey()) {
281 foreach ($USER->filelist as $file) {
282 $shortfile = basename($file);
283 $oldfile = $basedir.'/'.$file;
284 $newfile = $basedir.$wdir."/".$shortfile;
285 if (!rename($oldfile, $newfile)) {
286 echo "<p
>Error
: $shortfile not moved
</p
>";
296 if (($name != '') and confirm_sesskey()) {
297 html_header($course, $wdir);
298 $name = clean_filename($name);
299 if (file_exists($basedir.$wdir."/".$name)) {
300 echo "<center
>Error
: $name already exists
!</center
>";
301 } else if (!rename($basedir.$wdir."/".$oldname, $basedir.$wdir."/".$name)) {
302 echo "<p align
=\"center\"
>Error
: could not rename
$oldname to
$name</p
>";
304 //file was renamed now update resources if needed
305 require_once($CFG->dirroot.'/mod/resource/lib.php');
306 resource_renamefiles($course, $wdir, $oldname, $name);
311 $strrename = get_string("rename
");
312 $strcancel = get_string("cancel
");
313 $strrenamefileto = get_string("renamefileto
", "moodle
", $file);
314 html_header($course, $wdir, "form
.name
");
315 echo "<p
>$strrenamefileto:</p
>";
316 echo "<table
><tr
><td
>";
317 echo "<form action
=\"index
.php\" method
=\"post\"
>";
318 echo "<fieldset
class=\"invisiblefieldset\"
>";
319 echo ' <input type="hidden
" name="choose
" value="'.$choose.'" />';
320 echo " <input type
=\"hidden\" name
=\"id\" value
=\"$id\" />";
321 echo " <input type
=\"hidden\" name
=\"wdir\" value
=\"$wdir\" />";
322 echo " <input type
=\"hidden\" name
=\"action\" value
=\"rename\"
/>";
323 echo " <input type
=\"hidden\" name
=\"oldname\" value
=\"$file\" />";
324 echo " <input type
=\"hidden\" name
=\"sesskey\" value
=\"$USER->sesskey\"
/>";
325 echo " <input type
=\"text\" name
=\"name\" size
=\"35\" value
=\"$file\" />";
326 echo " <input type
=\"submit\" value
=\"$strrename\" />";
330 echo "<form action
=\"index
.php\" method
=\"get\"
>";
332 echo ' <input type="hidden
" name="choose
" value="'.$choose.'" />';
333 echo " <input type
=\"hidden\" name
=\"id\" value
=\"$id\" />";
334 echo " <input type
=\"hidden\" name
=\"wdir\" value
=\"$wdir\" />";
335 echo " <input type
=\"hidden\" name
=\"action\" value
=\"cancel\"
/>";
336 echo " <input type
=\"submit\" value
=\"$strcancel\" />";
339 echo "</td
></tr
></table
>";
345 if (($name != '') and confirm_sesskey()) {
346 html_header($course, $wdir);
347 $name = clean_filename($name);
348 if (file_exists("$basedir$wdir/$name")) {
349 echo "Error
: $name already exists
!";
350 } else if (! make_upload_directory("$course->id
$wdir/$name")) {
351 echo "Error
: could not create
$name";
356 $strcreate = get_string("create
");
357 $strcancel = get_string("cancel
");
358 $strcreatefolder = get_string("createfolder
", "moodle
", $wdir);
359 html_header($course, $wdir, "form
.name
");
360 echo "<p
>$strcreatefolder:</p
>";
361 echo "<table
><tr
><td
>";
362 echo "<form action
=\"index
.php\" method
=\"post\"
>";
363 echo "<fieldset
class=\"invisiblefieldset\"
>";
364 echo ' <input type="hidden
" name="choose
" value="'.$choose.'" />';
365 echo " <input type
=\"hidden\" name
=\"id\" value
=\"$id\" />";
366 echo " <input type
=\"hidden\" name
=\"wdir\" value
=\"$wdir\" />";
367 echo " <input type
=\"hidden\" name
=\"action\" value
=\"makedir\"
/>";
368 echo " <input type
=\"text\" name
=\"name\" size
=\"35\" />";
369 echo " <input type
=\"hidden\" name
=\"sesskey\" value
=\"$USER->sesskey\"
/>";
370 echo " <input type
=\"submit\" value
=\"$strcreate\" />";
374 echo "<form action
=\"index
.php\" method
=\"get\"
>";
376 echo ' <input type="hidden
" name="choose
" value="'.$choose.'" />';
377 echo " <input type
=\"hidden\" name
=\"id\" value
=\"$id\" />";
378 echo " <input type
=\"hidden\" name
=\"wdir\" value
=\"$wdir\" />";
379 echo " <input type
=\"hidden\" name
=\"action\" value
=\"cancel\"
/>";
380 echo " <input type
=\"submit\" value
=\"$strcancel\" />";
383 echo "</td
></tr
></table
>";
389 html_header($course, $wdir);
390 if (($text != '') and confirm_sesskey()) {
391 $fileptr = fopen($basedir.'/'.$file,"w
");
392 $text = preg_replace('/\x0D/', '', $text); // http://moodle.org/mod/forum/discuss.php?d=38860
393 fputs($fileptr, stripslashes($text));
398 $streditfile = get_string("edit
", "", "<b
>$file</b
>");
399 $fileptr = fopen($basedir.'/'.$file, "r
");
400 $contents = fread($fileptr, filesize($basedir.'/'.$file));
403 if (mimeinfo("type
", $file) == "text
/html
") {
404 $usehtmleditor = can_use_html_editor();
406 $usehtmleditor = false;
408 $usehtmleditor = false; // Always keep it off for now
410 print_heading("$streditfile");
412 echo "<table
><tr
><td colspan
=\"2\">";
413 echo "<form action
=\"index
.php\" method
=\"post\"
>";
415 echo ' <input type="hidden
" name="choose
" value="'.$choose.'" />';
416 echo " <input type
=\"hidden\" name
=\"id\" value
=\"$id\" />";
417 echo " <input type
=\"hidden\" name
=\"wdir\" value
=\"$wdir\" />";
418 echo " <input type
=\"hidden\" name
=\"file\" value
=\"$file\" />";
419 echo " <input type
=\"hidden\" name
=\"action\" value
=\"edit\"
/>";
420 echo " <input type
=\"hidden\" name
=\"sesskey\" value
=\"$USER->sesskey\"
/>";
421 print_textarea($usehtmleditor, 25, 80, 680, 400, "text
", $contents);
422 echo "</td
></tr
><tr
><td
>";
423 echo " <input type
=\"submit\" value
=\"".get_string("savechanges
")."\"
/>";
427 echo "<form action
=\"index
.php\" method
=\"get\"
>";
429 echo ' <input type="hidden
" name="choose
" value="'.$choose.'" />';
430 echo " <input type
=\"hidden\" name
=\"id\" value
=\"$id\" />";
431 echo " <input type
=\"hidden\" name
=\"wdir\" value
=\"$wdir\" />";
432 echo " <input type
=\"hidden\" name
=\"action\" value
=\"cancel\"
/>";
433 echo " <input type
=\"submit\" value
=\"".get_string("cancel
")."\"
/>";
436 echo "</td
></tr
></table
>";
438 if ($usehtmleditor) {
448 if (($name != '') and confirm_sesskey()) {
449 html_header($course, $wdir);
450 $name = clean_filename($name);
453 foreach ($USER->filelist as $file) {
454 $files[] = "$basedir/$file";
457 if (!zip_files($files,"$basedir$wdir/$name")) {
458 error(get_string("zipfileserror
","error
"));
465 html_header($course, $wdir, "form
.name
");
467 if (setfilelist($_POST)) {
468 echo "<p align
=\"center\"
>".get_string("youareabouttocreatezip
").":</p
>";
469 print_simple_box_start("center
");
470 printfilelist($USER->filelist);
471 print_simple_box_end();
473 echo "<p align
=\"center\"
>".get_string("whattocallzip
")."</p
>";
474 echo "<table
><tr
><td
>";
475 echo "<form action
=\"index
.php\" method
=\"post\"
>";
476 echo "<fieldset
class=\"invisiblefieldset\"
>";
477 echo ' <input type="hidden
" name="choose
" value="'.$choose.'" />';
478 echo " <input type
=\"hidden\" name
=\"id\" value
=\"$id\" />";
479 echo " <input type
=\"hidden\" name
=\"wdir\" value
=\"$wdir\" />";
480 echo " <input type
=\"hidden\" name
=\"action\" value
=\"zip\"
/>";
481 echo " <input type
=\"text\" name
=\"name\" size
=\"35\" value
=\"new.zip\"
/>";
482 echo " <input type
=\"hidden\" name
=\"sesskey\" value
=\"$USER->sesskey\"
/>";
483 echo " <input type
=\"submit\" value
=\"".get_string("createziparchive
")."\"
/>";
487 echo "<form action
=\"index
.php\" method
=\"get\"
>";
489 echo ' <input type="hidden
" name="choose
" value="'.$choose.'" />';
490 echo " <input type
=\"hidden\" name
=\"id\" value
=\"$id\" />";
491 echo " <input type
=\"hidden\" name
=\"wdir\" value
=\"$wdir\" />";
492 echo " <input type
=\"hidden\" name
=\"action\" value
=\"cancel\"
/>";
493 echo " <input type
=\"submit\" value
=\"".get_string("cancel
")."\"
/>";
496 echo "</td
></tr
></table
>";
506 html_header($course, $wdir);
507 if (($file != '') and confirm_sesskey()) {
508 $strok = get_string("ok
");
509 $strunpacking = get_string("unpacking
", "", $file);
511 echo "<p align
=\"center\"
>$strunpacking:</p
>";
513 $file = basename($file);
515 if (!unzip_file("$basedir$wdir/$file")) {
516 error(get_string("unzipfileserror
","error
"));
519 echo "<div style
=\"text
-align
:center\"
><form action
=\"index
.php\" method
=\"get\"
>";
521 echo ' <input type="hidden
" name="choose
" value="'.$choose.'" />';
522 echo " <input type
=\"hidden\" name
=\"id\" value
=\"$id\" />";
523 echo " <input type
=\"hidden\" name
=\"wdir\" value
=\"$wdir\" />";
524 echo " <input type
=\"hidden\" name
=\"action\" value
=\"cancel\"
/>";
525 echo " <input type
=\"submit\" value
=\"$strok\" />";
536 html_header($course, $wdir);
537 if (($file != '') and confirm_sesskey()) {
538 $strname = get_string("name
");
539 $strsize = get_string("size
");
540 $strmodified = get_string("modified
");
541 $strok = get_string("ok
");
542 $strlistfiles = get_string("listfiles
", "", $file);
544 echo "<p align
=\"center\"
>$strlistfiles:</p
>";
545 $file = basename($file);
547 include_once("$CFG->libdir
/pclzip
/pclzip
.lib
.php
");
548 $archive = new PclZip(cleardoubleslashes("$basedir$wdir/$file"));
549 if (!$list = $archive->listContent(cleardoubleslashes("$basedir$wdir"))) {
550 notify($archive->errorInfo(true));
553 echo "<table cellpadding
=\"4\" cellspacing
=\"2\" border
=\"0\" width
=\"640\" class=\"files\"
>";
554 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
>";
555 foreach ($list as $item) {
557 print_cell("left
", s($item['filename']), 'name');
558 if (! $item['folder']) {
559 print_cell("right
", display_size($item['size']), 'size');
561 echo "<td
> 
;</td
>";
563 $filedate = userdate($item['mtime'], get_string("strftimedatetime
"));
564 print_cell("right
", $filedate, 'date');
569 echo "<br
/><center
><form action
=\"index
.php\" method
=\"get\"
>";
571 echo ' <input type="hidden
" name="choose
" value="'.$choose.'" />';
572 echo " <input type
=\"hidden\" name
=\"id\" value
=\"$id\" />";
573 echo " <input type
=\"hidden\" name
=\"wdir\" value
=\"$wdir\" />";
574 echo " <input type
=\"hidden\" name
=\"action\" value
=\"cancel\"
/>";
575 echo " <input type
=\"submit\" value
=\"$strok\" />";
586 html_header($course, $wdir);
587 if (($file != '') and confirm_sesskey()) {
588 echo "<p align
=\"center\"
>".get_string("youaregoingtorestorefrom
").":</p
>";
589 print_simple_box_start("center
");
591 print_simple_box_end();
593 echo "<p align
=\"center\"
>".get_string("areyousuretorestorethisinfo
")."</p
>";
594 $restore_path = "$CFG->wwwroot
/backup
/restore
.php
";
595 notice_yesno (get_string("areyousuretorestorethis
"),
596 $restore_path."?id
=".$id."&
;file
=".cleardoubleslashes($id.$wdir."/".$file)."&
;method
=manual
",
597 "index
.php?id
=$id&
;wdir
=$wdir&
;action
=cancel
");
608 html_header($course, $wdir);
615 /// FILE FUNCTIONS ///////////////////////////////////////////////////////////
618 function setfilelist($VARS) {
621 $USER->filelist = array ();
625 foreach ($VARS as $key => $val) {
626 if (substr($key,0,4) == "file
") {
628 $val = rawurldecode($val);
629 $USER->filelist[] = clean_param($val, PARAM_PATH);
635 function clearfilelist() {
638 $USER->filelist = array ();
643 function printfilelist($filelist) {
644 global $CFG, $basedir;
646 $strfolder = get_string("folder
");
647 $strfile = get_string("file
");
649 foreach ($filelist as $file) {
650 if (is_dir($basedir.'/'.$file)) {
651 echo "<img src
=\"$CFG->pixpath
/f
/folder
.gif\"
class=\"icon\" alt
=\"$strfolder\" /> $file<br
/>";
652 $subfilelist = array();
653 $currdir = opendir($basedir.'/'.$file);
654 while (false !== ($subfile = readdir($currdir))) {
655 if ($subfile <> ".." && $subfile <> ".") {
656 $subfilelist[] = $file."/".$subfile;
659 printfilelist($subfilelist);
662 $icon = mimeinfo("icon
", $file);
663 echo "<img src
=\"$CFG->pixpath
/f
/$icon\" class=\"icon\" alt
=\"$strfile\" /> $file<br
/>";
669 function print_cell($alignment='center', $text=' ', $class='') {
671 $class = ' class="'.$class.'"';
673 echo '<td align="'.$alignment.'" style="white
-space
:nowrap
"'.$class.'>'.$text.'</td>';
676 function displaydir ($wdir) {
677 // $wdir == / or /a or /a/b/c/d etc
684 $fullpath = $basedir.$wdir;
687 $directory = opendir($fullpath); // Find all files
688 while (false !== ($file = readdir($directory))) {
689 if ($file == "." || $file == "..") {
693 if (is_dir($fullpath."/".$file)) {
699 closedir($directory);
701 $strname = get_string("name
");
702 $strsize = get_string("size
");
703 $strmodified = get_string("modified
");
704 $straction = get_string("action
");
705 $strmakeafolder = get_string("makeafolder
");
706 $struploadafile = get_string("uploadafile
");
707 $strselectall = get_string("selectall
");
708 $strselectnone = get_string("deselectall
");
709 $strwithchosenfiles = get_string("withchosenfiles
");
710 $strmovetoanotherfolder = get_string("movetoanotherfolder
");
711 $strmovefilestohere = get_string("movefilestohere
");
712 $strdeletecompletely = get_string("deletecompletely
");
713 $strcreateziparchive = get_string("createziparchive
");
714 $strrename = get_string("rename
");
715 $stredit = get_string("edit
");
716 $strunzip = get_string("unzip
");
717 $strlist = get_string("list");
718 $strrestore= get_string("restore
");
719 $strchoose = get_string("choose
");
720 $strfolder = get_string("folder
");
721 $strfile = get_string("file
");
724 echo "<form action
=\"index
.php\" method
=\"post\" id
=\"dirform\"
>";
726 echo '<input type="hidden
" name="choose
" value="'.$choose.'" />';
727 // echo "<hr align
=\"center\" noshade
=\"noshade\" size
=\"1\" />";
729 echo "<table border
=\"0\" cellspacing
=\"2\" cellpadding
=\"2\" width
=\"640\" class=\"files\"
>";
731 echo "<th scope
=\"col\"
></th
>";
732 echo "<th
class=\"header name\" scope
=\"col\"
>$strname</th
>";
733 echo "<th
class=\"header size\" scope
=\"col\"
>$strsize</th
>";
734 echo "<th
class=\"header date\" scope
=\"col\"
>$strmodified</th
>";
735 echo "<th
class=\"header commands\" scope
=\"col\"
>$straction</th
>";
744 if (!empty($dirlist)) {
746 foreach ($dirlist as $dir) {
747 echo "<tr
class=\"folder\"
>";
750 $fileurl = rawurlencode(dirname($wdir));
752 // alt attribute intentionally empty to prevent repetition in screen reader
753 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');
760 $filename = $fullpath."/".$dir;
761 $fileurl = rawurlencode($wdir."/".$dir);
762 $filesafe = rawurlencode($dir);
763 $filesize = display_size(get_directory_size("$fullpath/$dir"));
764 $filedate = userdate(filemtime($filename), "%d %b %Y
, %I
:%M %p
");
765 print_cell("center
", "<input type
=\"checkbox\" name
=\"file
$count\" value
=\"$fileurl\" />", 'checkbox');
766 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');
767 print_cell("right
", $filesize, 'size');
768 print_cell("right
", $filedate, 'date');
769 print_cell("right
", "<a href
=\"index
.php?id
=$id&
;wdir
=$wdir&
;file
=$filesafe&
;action
=rename
&
;choose
=$choose\">$strrename</a
>", 'commands');
777 if (!empty($filelist)) {
779 foreach ($filelist as $file) {
781 $icon = mimeinfo("icon
", $file);
784 $filename = $fullpath."/".$file;
785 $fileurl = trim($wdir, "/")."/$file";
786 $filesafe = rawurlencode($file);
787 $fileurlsafe = rawurlencode($fileurl);
788 $filedate = userdate(filemtime($filename), "%d %b %Y
, %I
:%M %p
");
790 $selectfile = trim($fileurl, "/");
792 echo "<tr
class=\"file\"
>";
794 print_cell("center
", "<input type
=\"checkbox\" name
=\"file
$count\" value
=\"$fileurl\" />", 'checkbox');
795 echo "<td align
=\"left\" style
=\"white
-space
:nowrap\"
class=\"name\"
>";
796 if ($CFG->slasharguments) {
797 $ffurl = str_replace('//', '/', "/file
.php
/$id/$fileurl");
799 $ffurl = str_replace('//', '/', "/file
.php?file
=/$id/$fileurl");
801 link_to_popup_window ($ffurl, "display
",
802 "<img src
=\"$CFG->pixpath
/f
/$icon\" class=\"icon\" alt
=\"$strfile\" /> 
;".htmlspecialchars($file),
806 $file_size = filesize($filename);
807 print_cell("right
", display_size($file_size), 'size');
808 print_cell("right
", $filedate, 'date');
811 $edittext = "<strong
><a onclick
=\"return set_value('$selectfile')\" href
=\"#\">$strchoose</a></strong> ";
817 if ($icon == "text.gif" ||
$icon == "html.gif") {
818 $edittext .= "<a href=\"index.php?id=$id&wdir=$wdir&file=$fileurl&action=edit&choose=$choose\">$stredit</a>";
819 } else if ($icon == "zip.gif") {
820 $edittext .= "<a href=\"index.php?id=$id&wdir=$wdir&file=$fileurl&action=unzip&sesskey=$USER->sesskey&choose=$choose\">$strunzip</a> ";
821 $edittext .= "<a href=\"index.php?id=$id&wdir=$wdir&file=$fileurl&action=listzip&sesskey=$USER->sesskey&choose=$choose\">$strlist</a> ";
822 if (!empty($CFG->backup_version
) and has_capability('moodle/site:restore', get_context_instance(CONTEXT_COURSE
, $id))) {
823 $edittext .= "<a href=\"index.php?id=$id&wdir=$wdir&file=$filesafe&action=restore&sesskey=$USER->sesskey&choose=$choose\">$strrestore</a> ";
827 print_cell("right", "$edittext <a href=\"index.php?id=$id&wdir=$wdir&file=$filesafe&action=rename&choose=$choose\">$strrename</a>", 'commands');
834 //echo "<hr width=\"640\" align=\"center\" noshade=\"noshade\" size=\"1\" />";
836 echo "<table border=\"0\" cellspacing=\"2\" cellpadding=\"2\" width=\"640\">";
838 echo "<input type=\"hidden\" name=\"id\" value=\"$id\" />";
839 echo '<input type="hidden" name="choose" value="'.$choose.'" />';
840 echo "<input type=\"hidden\" name=\"wdir\" value=\"$wdir\" /> ";
841 echo "<input type=\"hidden\" name=\"sesskey\" value=\"$USER->sesskey\" />";
843 "move" => "$strmovetoanotherfolder",
844 "delete" => "$strdeletecompletely",
845 "zip" => "$strcreateziparchive"
847 if (!empty($count)) {
848 choose_from_menu ($options, "action", "", "$strwithchosenfiles...", "javascript:getElementById('dirform').submit()");
850 echo "</td></tr></table>";
853 echo "<table border=\"0\" cellspacing=\"2\" cellpadding=\"2\" width=\"640\"><tr>";
854 echo "<td align=\"center\">";
855 if (!empty($USER->fileop
) and ($USER->fileop
== "move") and ($USER->filesource
<> $wdir)) {
856 echo "<form action=\"index.php\" method=\"get\">";
858 echo ' <input type="hidden" name="choose" value="'.$choose.'" />';
859 echo " <input type=\"hidden\" name=\"id\" value=\"$id\" />";
860 echo " <input type=\"hidden\" name=\"wdir\" value=\"$wdir\" />";
861 echo " <input type=\"hidden\" name=\"action\" value=\"paste\" />";
862 echo " <input type=\"hidden\" name=\"sesskey\" value=\"$USER->sesskey\" />";
863 echo " <input type=\"submit\" value=\"$strmovefilestohere\" />";
868 echo "<td align=\"right\">";
869 echo "<form action=\"index.php\" method=\"get\">";
871 echo ' <input type="hidden" name="choose" value="'.$choose.'" />';
872 echo " <input type=\"hidden\" name=\"id\" value=\"$id\" />";
873 echo " <input type=\"hidden\" name=\"wdir\" value=\"$wdir\" />";
874 echo " <input type=\"hidden\" name=\"action\" value=\"makedir\" />";
875 echo " <input type=\"submit\" value=\"$strmakeafolder\" />";
879 echo "<td align=\"right\">";
880 echo "<form action=\"index.php\" method=\"get\">"; //dummy form - alignment only
881 echo "<fieldset class=\"invisiblefieldset\">";
882 echo " <input type=\"button\" value=\"$strselectall\" onclick=\"checkall();\" />";
883 echo " <input type=\"button\" value=\"$strselectnone\" onclick=\"uncheckall();\" />";
887 echo "<td align=\"right\">";
888 echo "<form action=\"index.php\" method=\"get\">";
890 echo ' <input type="hidden" name="choose" value="'.$choose.'" />';
891 echo " <input type=\"hidden\" name=\"id\" value=\"$id\" />";
892 echo " <input type=\"hidden\" name=\"wdir\" value=\"$wdir\" />";
893 echo " <input type=\"hidden\" name=\"action\" value=\"upload\" />";
894 echo " <input type=\"submit\" value=\"$struploadafile\" />";
900 //echo "<hr width=\"640\" align=\"center\" noshade=\"noshade\" size=\"1\" />";