fixed log action inserts
[moodle.git] / coursefiles.php
CommitLineData
02039379
PS
1<?php // $Id: coursefiles.php,v 1.1 2006/03/12 18:39:59 skodak Exp $
2
3// Manage all uploaded files in a course file area
4
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
9
10 require('../../config.php');
11 require($CFG->libdir.'/filelib.php');
12
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 = required_param('choose', PARAM_CLEAN);
20
21 if ($choose) {
22 if (count(explode('.', $choose)) != 2) {
23 error('Incorrect format for choose parameter');
24 }
25 }
26
27
28 if (! $course = get_record("course", "id", $id) ) {
29 error("That's an invalid course id");
30 }
31
32 require_login($course->id);
33
34 if (! isteacheredit($course->id) ) {
35 error("You need to be a teacher with editing privileges");
36 }
37
38 function html_footer() {
39
40 global $course, $choose;
41
42 if ($choose) {
43 echo "</td></tr></table></body></html>";
44 } else {
45 echo "</td></tr></table></body></html>";
46 print_footer($course);
47 }
48 }
49
50 function html_header($course, $wdir, $formfield=""){
51 global $CFG, $ME, $choose;
52
53 if (! $site = get_site()) {
54 error("Invalid site!");
55 }
56
57 if ($course->id == $site->id) {
58 $strfiles = get_string("sitefiles");
59 } else {
60 $strfiles = get_string("files");
61 }
62
63 if ($wdir == "/") {
64 $fullnav = "$strfiles";
65 } else {
66 $dirs = explode("/", $wdir);
67 $numdirs = count($dirs);
68 $link = "";
69 $navigation = "";
70 for ($i=1; $i<$numdirs-1; $i++) {
71 $navigation .= " -> ";
72 $link .= "/".urlencode($dirs[$i]);
73 $navigation .= "<a href=\"".$ME."?id=$course->id&amp;wdir=$link&amp;choose=$choose\">".$dirs[$i]."</a>";
74 }
75 $fullnav = "<a href=\"".$ME."?id=$course->id&amp;wdir=/&amp;choose=$choose\">$strfiles</a> $navigation -> ".$dirs[$numdirs-1];
76 }
77
78
79 if ($choose) {
80 print_header();
81
82 $chooseparts = explode('.', $choose);
83
84 ?>
85 <script language="javascript" type="text/javascript">
86 <!--
87 function set_value(txt) {
88 opener.document.forms['<?php echo $chooseparts[0]."'].".$chooseparts[1] ?>.value = txt;
89 window.close();
90 }
91 -->
92 </script>
93
94 <?php
95 $fullnav = str_replace('->', '&raquo;', "$course->shortname -> $fullnav");
96 echo '<div id="nav-bar">'.$fullnav.'</div>';
97
98 if ($course->id == $site->id) {
99 print_heading(get_string("publicsitefileswarning"), "center", 2);
100 }
101
102 } else {
103
104 if ($course->id == $site->id) {
105 print_header("$course->shortname: $strfiles", "$course->fullname",
106 "<a href=\"../$CFG->admin/index.php\">".get_string("administration").
107 "</a> -> $fullnav", $formfield);
108
109 print_heading(get_string("publicsitefileswarning"), "center", 2);
110
111 } else {
112 print_header("$course->shortname: $strfiles", "$course->fullname",
113 "<a href=\"../course/view.php?id=$course->id\">$course->shortname".
114 "</a> -> $fullnav", $formfield);
115 }
116 }
117
118
119 echo "<table border=\"0\" align=\"center\" cellspacing=\"3\" cellpadding=\"3\" width=\"640\">";
120 echo "<tr>";
121 echo "<td colspan=\"2\">";
122
123 }
124
125
126 if (! $basedir = make_upload_directory("$course->id")) {
127 error("The site administrator needs to fix the file permissions");
128 }
129
130 $baseweb = $CFG->wwwroot;
131
132// End of configuration and access control
133
134
135 if (!$wdir) {
136 $wdir="/";
137 }
138
139 if (($wdir != '/' and detect_munged_arguments($wdir, 0))
140 or ($file != '' and detect_munged_arguments($file, 0))) {
141 $message = "Error: Directories can not contain \"..\"";
142 $wdir = "/";
143 $action = "";
144 }
145
146 if ($wdir == "/backupdata") {
147 if (! make_upload_directory("$course->id/backupdata")) { // Backup folder
148 error("Could not create backupdata folder. The site administrator needs to fix the file permissions");
149 }
150 }
151
152 switch ($action) {
153
154 case "upload":
155 html_header($course, $wdir);
156 require_once($CFG->dirroot.'/lib/uploadlib.php');
157
158 if (!empty($save) and confirm_sesskey()) {
159 $course->maxbytes = 0; // We are ignoring course limits
160 $um = new upload_manager('userfile',false,false,$course,false,0);
161 $dir = "$basedir$wdir";
162 if ($um->process_file_uploads($dir)) {
163 notify(get_string('uploadedfile'));
164 }
165 // um will take care of error reporting.
166 displaydir($wdir);
167 } else {
168 $upload_max_filesize = get_max_upload_file_size($CFG->maxbytes);
169 $filesize = display_size($upload_max_filesize);
170
171 $struploadafile = get_string("uploadafile");
172 $struploadthisfile = get_string("uploadthisfile");
173 $strmaxsize = get_string("maxsize", "", $filesize);
174 $strcancel = get_string("cancel");
175
176 echo "<p>$struploadafile ($strmaxsize) --> <b>$wdir</b>";
177 echo "<table><tr><td colspan=\"2\">";
178 echo "<form enctype=\"multipart/form-data\" method=\"post\" action=\"coursefiles.php\">";
179 echo ' <input type="hidden" name="choose" value="'.$choose.'">';
180 echo " <input type=\"hidden\" name=\"id\" value=\"$id\" />";
181 echo " <input type=\"hidden\" name=\"wdir\" value=\"$wdir\" />";
182 echo " <input type=\"hidden\" name=\"action\" value=\"upload\" />";
183 echo " <input type=\"hidden\" name=\"sesskey\" value=\"$USER->sesskey\" />";
184 upload_print_form_fragment(1,array('userfile'),null,false,null,$upload_max_filesize,0,false);
185 echo " </td><tr><td width=\"10\">";
186 echo " <input type=\"submit\" name=\"save\" value=\"$struploadthisfile\" />";
187 echo "</form>";
188 echo "</td><td width=\"100%\">";
189 echo "<form action=\"coursefiles.php\" method=\"get\">";
190 echo ' <input type="hidden" name="choose" value="'.$choose.'">';
191 echo " <input type=\"hidden\" name=\"id\" value=\"$id\" />";
192 echo " <input type=\"hidden\" name=\"wdir\" value=\"$wdir\" />";
193 echo " <input type=\"hidden\" name=\"action\" value=\"cancel\" />";
194 echo " <input type=\"submit\" value=\"$strcancel\" />";
195 echo "</form>";
196 echo "</td></tr></table>";
197 }
198 html_footer();
199 break;
200
201 case "delete":
202 if (!empty($confirm) and confirm_sesskey()) {
203 html_header($course, $wdir);
204 foreach ($USER->filelist as $file) {
205 $fullfile = $basedir.$file;
206 if (! fulldelete($fullfile)) {
207 echo "<br />Error: Could not delete: $fullfile";
208 }
209 }
210 clearfilelist();
211 displaydir($wdir);
212 html_footer();
213
214 } else {
215 html_header($course, $wdir);
216 if (setfilelist($_POST)) {
217 echo "<p align=\"center\">".get_string("deletecheckwarning").":</p>";
218 print_simple_box_start("center");
219 printfilelist($USER->filelist);
220 print_simple_box_end();
221 echo "<br />";
222 notice_yesno (get_string("deletecheckfiles"),
223 "coursefiles.php?id=$id&amp;wdir=$wdir&amp;action=delete&amp;confirm=1&amp;sesskey=$USER->sesskey&amp;choose=$choose",
224 "coursefiles.php?id=$id&amp;wdir=$wdir&amp;action=cancel&amp;choose=$choose");
225 } else {
226 displaydir($wdir);
227 }
228 html_footer();
229 }
230 break;
231
232 case "move":
233 html_header($course, $wdir);
234 if (($count = setfilelist($_POST)) and confirm_sesskey()) {
235 $USER->fileop = $action;
236 $USER->filesource = $wdir;
237 echo "<p align=\"center\">";
238 print_string("selectednowmove", "moodle", $count);
239 echo "</p>";
240 }
241 displaydir($wdir);
242 html_footer();
243 break;
244
245 case "paste":
246 html_header($course, $wdir);
247 if (isset($USER->fileop) and ($USER->fileop == "move") and confirm_sesskey()) {
248 foreach ($USER->filelist as $file) {
249 $shortfile = basename($file);
250 $oldfile = $basedir.$file;
251 $newfile = $basedir.$wdir."/".$shortfile;
252 if (!rename($oldfile, $newfile)) {
253 echo "<p>Error: $shortfile not moved";
254 }
255 }
256 }
257 clearfilelist();
258 displaydir($wdir);
259 html_footer();
260 break;
261
262 case "rename":
263 if (!empty($name) and confirm_sesskey()) {
264 html_header($course, $wdir);
265 $name = clean_filename($name);
266 if (file_exists($basedir.$wdir."/".$name)) {
267 echo "Error: $name already exists!";
268 } else if (!rename($basedir.$wdir."/".$oldname, $basedir.$wdir."/".$name)) {
269 echo "Error: could not rename $oldname to $name";
270 }
271 displaydir($wdir);
272
273 } else {
274 $strrename = get_string("rename");
275 $strcancel = get_string("cancel");
276 $strrenamefileto = get_string("renamefileto", "moodle", $file);
277 html_header($course, $wdir, "form.name");
278 echo "<p>$strrenamefileto:";
279 echo "<table><tr><td>";
280 echo "<form action=\"coursefiles.php\" method=\"post\" name=\"form\">";
281 echo ' <input type="hidden" name="choose" value="'.$choose.'">';
282 echo " <input type=\"hidden\" name=\"id\" value=\"$id\" />";
283 echo " <input type=\"hidden\" name=\"wdir\" value=\"$wdir\" />";
284 echo " <input type=\"hidden\" name=\"action\" value=\"rename\" />";
285 echo " <input type=\"hidden\" name=\"oldname\" value=\"$file\" />";
286 echo " <input type=\"hidden\" name=\"sesskey\" value=\"$USER->sesskey\" />";
287 echo " <input type=\"text\" name=\"name\" size=\"35\" value=\"$file\" />";
288 echo " <input type=\"submit\" value=\"$strrename\" />";
289 echo "</form>";
290 echo "</td><td>";
291 echo "<form action=\"coursefiles.php\" method=\"get\">";
292 echo ' <input type="hidden" name="choose" value="'.$choose.'">';
293 echo " <input type=\"hidden\" name=\"id\" value=\"$id\" />";
294 echo " <input type=\"hidden\" name=\"wdir\" value=\"$wdir\" />";
295 echo " <input type=\"hidden\" name=\"action\" value=\"cancel\" />";
296 echo " <input type=\"submit\" value=\"$strcancel\" />";
297 echo "</form>";
298 echo "</td></tr></table>";
299 }
300 html_footer();
301 break;
302
303 case "mkdir":
304 if (!empty($name) and confirm_sesskey()) {
305 html_header($course, $wdir);
306 $name = clean_filename($name);
307 if (file_exists("$basedir$wdir/$name")) {
308 echo "Error: $name already exists!";
309 } else if (! make_upload_directory("$course->id/$wdir/$name")) {
310 echo "Error: could not create $name";
311 }
312 displaydir($wdir);
313
314 } else {
315 $strcreate = get_string("create");
316 $strcancel = get_string("cancel");
317 $strcreatefolder = get_string("createfolder", "moodle", $wdir);
318 html_header($course, $wdir, "form.name");
319 echo "<p>$strcreatefolder:";
320 echo "<table><tr><td>";
321 echo "<form action=\"coursefiles.php\" method=\"post\" name=\"form\">";
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=\"mkdir\" />";
326 echo " <input type=\"text\" name=\"name\" size=\"35\" />";
327 echo " <input type=\"hidden\" name=\"sesskey\" value=\"$USER->sesskey\" />";
328 echo " <input type=\"submit\" value=\"$strcreate\" />";
329 echo "</form>";
330 echo "</td><td>";
331 echo "<form action=\"coursefiles.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\" />";
337 echo "</form>";
338 echo "</td></tr></table>";
339 }
340 html_footer();
341 break;
342
343 case "edit":
344 html_header($course, $wdir);
345 if (isset($text) and confirm_sesskey()) {
346 $fileptr = fopen($basedir.$file,"w");
347 fputs($fileptr, stripslashes($text));
348 fclose($fileptr);
349 displaydir($wdir);
350
351 } else {
352 $streditfile = get_string("edit", "", "<b>$file</b>");
353 $fileptr = fopen($basedir.$file, "r");
354 $contents = fread($fileptr, filesize($basedir.$file));
355 fclose($fileptr);
356
357 if (mimeinfo("type", $file) == "text/html") {
358 $usehtmleditor = can_use_html_editor();
359 } else {
360 $usehtmleditor = false;
361 }
362 $usehtmleditor = false; // Always keep it off for now
363
364 print_heading("$streditfile");
365
366 echo "<table><tr><td colspan=\"2\">";
367 echo "<form action=\"coursefiles.php\" method=\"post\" name=\"form\">";
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=\"file\" value=\"$file\" />";
372 echo " <input type=\"hidden\" name=\"action\" value=\"edit\" />";
373 echo " <input type=\"hidden\" name=\"sesskey\" value=\"$USER->sesskey\" />";
374 print_textarea($usehtmleditor, 25, 80, 680, 400, "text", $contents);
375 echo "</td></tr><tr><td>";
376 echo " <input type=\"submit\" value=\"".get_string("savechanges")."\" />";
377 echo "</form>";
378 echo "</td><td>";
379 echo "<form action=\"coursefiles.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=\"".get_string("cancel")."\" />";
385 echo "</form>";
386 echo "</td></tr></table>";
387
388 if ($usehtmleditor) {
389 use_html_editor();
390 }
391
392
393 }
394 html_footer();
395 break;
396
397 case "zip":
398 if (!empty($name) and confirm_sesskey()) {
399 html_header($course, $wdir);
400 $name = clean_filename($name);
401
402 $files = array();
403 foreach ($USER->filelist as $file) {
404 $files[] = "$basedir/$file";
405 }
406
407 if (!zip_files($files,"$basedir/$wdir/$name")) {
408 error(get_string("zipfileserror","error"));
409 }
410
411 clearfilelist();
412 displaydir($wdir);
413
414 } else {
415 html_header($course, $wdir, "form.name");
416
417 if (setfilelist($_POST)) {
418 echo "<p align=\"center\">".get_string("youareabouttocreatezip").":</p>";
419 print_simple_box_start("center");
420 printfilelist($USER->filelist);
421 print_simple_box_end();
422 echo "<br />";
423 echo "<p align=\"center\">".get_string("whattocallzip");
424 echo "<table><tr><td>";
425 echo "<form action=\"coursefiles.php\" method=\"post\" name=\"form\">";
426 echo ' <input type="hidden" name="choose" value="'.$choose.'">';
427 echo " <input type=\"hidden\" name=\"id\" value=\"$id\" />";
428 echo " <input type=\"hidden\" name=\"wdir\" value=\"$wdir\" />";
429 echo " <input type=\"hidden\" name=\"action\" value=\"zip\" />";
430 echo " <input type=\"text\" name=\"name\" size=\"35\" value=\"new.zip\" />";
431 echo " <input type=\"hidden\" name=\"sesskey\" value=\"$USER->sesskey\" />";
432 echo " <input type=\"submit\" value=\"".get_string("createziparchive")."\" />";
433 echo "</form>";
434 echo "</td><td>";
435 echo "<form action=\"coursefiles.php\" method=\"get\">";
436 echo ' <input type="hidden" name="choose" value="'.$choose.'">';
437 echo " <input type=\"hidden\" name=\"id\" value=\"$id\" />";
438 echo " <input type=\"hidden\" name=\"wdir\" value=\"$wdir\" />";
439 echo " <input type=\"hidden\" name=\"action\" value=\"cancel\" />";
440 echo " <input type=\"submit\" value=\"".get_string("cancel")."\" />";
441 echo "</form>";
442 echo "</td></tr></table>";
443 } else {
444 displaydir($wdir);
445 clearfilelist();
446 }
447 }
448 html_footer();
449 break;
450
451 case "unzip":
452 html_header($course, $wdir);
453 if (!empty($file) and confirm_sesskey()) {
454 $strok = get_string("ok");
455 $strunpacking = get_string("unpacking", "", $file);
456
457 echo "<p align=\"center\">$strunpacking:</p>";
458
459 $file = basename($file);
460
461 if (!unzip_file("$basedir/$wdir/$file")) {
462 error(get_string("unzipfileserror","error"));
463 }
464
465 echo "<center><form action=\"coursefiles.php\" method=\"get\">";
466 echo ' <input type="hidden" name="choose" value="'.$choose.'">';
467 echo " <input type=\"hidden\" name=\"id\" value=\"$id\" />";
468 echo " <input type=\"hidden\" name=\"wdir\" value=\"$wdir\" />";
469 echo " <input type=\"hidden\" name=\"action\" value=\"cancel\" />";
470 echo " <input type=\"submit\" value=\"$strok\" />";
471 echo "</form>";
472 echo "</center>";
473 } else {
474 displaydir($wdir);
475 }
476 html_footer();
477 break;
478
479 case "listzip":
480 html_header($course, $wdir);
481 if (!empty($file) and confirm_sesskey()) {
482 $strname = get_string("name");
483 $strsize = get_string("size");
484 $strmodified = get_string("modified");
485 $strok = get_string("ok");
486 $strlistfiles = get_string("listfiles", "", $file);
487
488 echo "<p align=\"center\">$strlistfiles:</p>";
489 $file = basename($file);
490
491 include_once("$CFG->libdir/pclzip/pclzip.lib.php");
492 $archive = new PclZip(cleardoubleslashes("$basedir/$wdir/$file"));
493 if (!$list = $archive->listContent(cleardoubleslashes("$basedir/$wdir"))) {
494 notify($archive->errorInfo(true));
495
496 } else {
497 echo "<table cellpadding=\"4\" cellspacing=\"2\" border=\"0\" width=\"640\" class=\"files\">";
498 echo "<tr class=\"file\"><th align=\"left\" class=\"header name\">$strname</th><th align=\"right\" class=\"header size\">$strsize</th><th align=\"right\" class=\"header date\">$strmodified</th></tr>";
499 foreach ($list as $item) {
500 echo "<tr>";
501 print_cell("left", $item['filename'], 'name');
502 if (! $item['folder']) {
503 print_cell("right", display_size($item['size']), 'size');
504 } else {
505 echo "<td>&nbsp;</td>";
506 }
507 $filedate = userdate($item['mtime'], get_string("strftimedatetime"));
508 print_cell("right", $filedate, 'date');
509 echo "</tr>";
510 }
511 echo "</table>";
512 }
513 echo "<br /><center><form action=\"coursefiles.php\" method=\"get\">";
514 echo ' <input type="hidden" name="choose" value="'.$choose.'">';
515 echo " <input type=\"hidden\" name=\"id\" value=\"$id\" />";
516 echo " <input type=\"hidden\" name=\"wdir\" value=\"$wdir\" />";
517 echo " <input type=\"hidden\" name=\"action\" value=\"cancel\" />";
518 echo " <input type=\"submit\" value=\"$strok\" />";
519 echo "</form>";
520 echo "</center>";
521 } else {
522 displaydir($wdir);
523 }
524 html_footer();
525 break;
526
527 case "restore":
528 html_header($course, $wdir);
529 if (!empty($file) and confirm_sesskey()) {
530 echo "<p align=\"center\">".get_string("youaregoingtorestorefrom").":</p>";
531 print_simple_box_start("center");
532 echo $file;
533 print_simple_box_end();
534 echo "<br />";
535 echo "<p align=\"center\">".get_string("areyousuretorestorethisinfo")."</p>";
536 $restore_path = "$CFG->wwwroot/backup/restore.php";
537 notice_yesno (get_string("areyousuretorestorethis"),
538 $restore_path."?id=".$id."&amp;file=".cleardoubleslashes($id.$wdir."/".$file),
539 "coursefiles.php?id=$id&amp;wdir=$wdir&amp;action=cancel");
540 } else {
541 displaydir($wdir);
542 }
543 html_footer();
544 break;
545
546 case "cancel":
547 clearfilelist();
548
549 default:
550 html_header($course, $wdir);
551 displaydir($wdir);
552 html_footer();
553 break;
554}
555
556
557/// FILE FUNCTIONS ///////////////////////////////////////////////////////////
558
559
560function setfilelist($VARS) {
561 global $USER;
562
563 $USER->filelist = array ();
564 $USER->fileop = "";
565
566 $count = 0;
567 foreach ($VARS as $key => $val) {
568 if (substr($key,0,4) == "file") {
569 $count++;
570 $val = rawurldecode($val);
571 if (!detect_munged_arguments($val, 0)) {
572 $USER->filelist[] = $val;
573 }
574 }
575 }
576 return $count;
577}
578
579function clearfilelist() {
580 global $USER;
581
582 $USER->filelist = array ();
583 $USER->fileop = "";
584}
585
586
587function printfilelist($filelist) {
588 global $CFG, $basedir;
589
590 foreach ($filelist as $file) {
591 if (is_dir($basedir.$file)) {
592 echo "<img src=\"$CFG->pixpath/f/folder.gif\" height=\"16\" width=\"16\" alt=\"\" /> $file<br />";
593 $subfilelist = array();
594 $currdir = opendir($basedir.$file);
595 while (false !== ($subfile = readdir($currdir))) {
596 if ($subfile <> ".." && $subfile <> ".") {
597 $subfilelist[] = $file."/".$subfile;
598 }
599 }
600 printfilelist($subfilelist);
601
602 } else {
603 $icon = mimeinfo("icon", $file);
604 echo "<img src=\"$CFG->pixpath/f/$icon\" height=\"16\" width=\"16\" alt=\"\" /> $file<br />";
605 }
606 }
607}
608
609
610function print_cell($alignment='center', $text='&nbsp;', $class='') {
611 if ($class) {
612 $class = ' class="'.$class.'"';
613 }
614 echo '<td align="'.$alignment.'" nowrap="nowrap"'.$class.'>'.$text.'</td>';
615}
616
617function displaydir ($wdir) {
618// $wdir == / or /a or /a/b/c/d etc
619
620 global $basedir;
621 global $id;
622 global $USER, $CFG;
623 global $choose;
624
625 $fullpath = $basedir.$wdir;
626
627 $directory = opendir($fullpath); // Find all files
628 while (false !== ($file = readdir($directory))) {
629 if ($file == "." || $file == "..") {
630 continue;
631 }
632
633 if (is_dir($fullpath."/".$file)) {
634 $dirlist[] = $file;
635 } else {
636 $filelist[] = $file;
637 }
638 }
639 closedir($directory);
640
641 $strname = get_string("name");
642 $strsize = get_string("size");
643 $strmodified = get_string("modified");
644 $straction = get_string("action");
645 $strmakeafolder = get_string("makeafolder");
646 $struploadafile = get_string("uploadafile");
647 $strwithchosenfiles = get_string("withchosenfiles");
648 $strmovetoanotherfolder = get_string("movetoanotherfolder");
649 $strmovefilestohere = get_string("movefilestohere");
650 $strdeletecompletely = get_string("deletecompletely");
651 $strcreateziparchive = get_string("createziparchive");
652 $strrename = get_string("rename");
653 $stredit = get_string("edit");
654 $strunzip = get_string("unzip");
655 $strlist = get_string("list");
656 $strrestore= get_string("restore");
657 $strchoose = get_string("choose");
658
659
660 echo "<form action=\"coursefiles.php\" method=\"post\" name=\"dirform\">";
661 echo '<input type="hidden" name="choose" value="'.$choose.'">';
662 echo "<hr width=\"640\" align=\"center\" noshade=\"noshade\" size=\"1\" />";
663 echo "<table border=\"0\" cellspacing=\"2\" cellpadding=\"2\" width=\"640\" class=\"files\">";
664 echo "<tr>";
665 echo "<th width=\"5\"></th>";
666 echo "<th align=\"left\" class=\"header name\">$strname</th>";
667 echo "<th align=\"right\" class=\"header size\">$strsize</th>";
668 echo "<th align=\"right\" class=\"header date\">$strmodified</th>";
669 echo "<th align=\"right\" class=\"header commands\">$straction</th>";
670 echo "</tr>\n";
671
672 if ($wdir == "/") {
673 $wdir = "";
674 }
675 if (!empty($wdir)) {
676 $dirlist[] = '..';
677 }
678
679 $count = 0;
680
681 if (!empty($dirlist)) {
682 asort($dirlist);
683 foreach ($dirlist as $dir) {
684 echo "<tr class=\"folder\">";
685
686 $dirurl = "$wdir/$dir";
687 if (substr($dirurl,0,1) == '/') {
688 $selectdir = substr($dirurl,1);
689 } else {
690 $selectdir = $dirurl;
691 }
692
693 if ($dir == '..') {
694 $fileurl = rawurlencode(dirname($wdir));
695 print_cell();
696 print_cell('left', '<a href="coursefiles.php?id='.$id.'&amp;wdir='.$fileurl.'&amp;choose='.$choose.'"><img src="'.$CFG->pixpath.'/f/parent.gif" height="16" width="16" alt="'.get_string('parentfolder').'" /></a> <a href="coursefiles.php?id='.$id.'&amp;wdir='.$fileurl.'&amp;choose='.$choose.'">'.get_string('parentfolder').'</a>', 'name');
697 print_cell();
698 print_cell();
699 print_cell();
700
701 } else {
702 $count++;
703 $filename = $fullpath."/".$dir;
704 $fileurl = rawurlencode($wdir."/".$dir);
705 $filesafe = rawurlencode($dir);
706 $filesize = display_size(get_directory_size("$fullpath/$dir"));
707 $filedate = userdate(filemtime($filename), "%d %b %Y, %I:%M %p");
708 print_cell("center", "<input type=\"checkbox\" name=\"file$count\" value=\"$fileurl\" />", 'checkbox');
709 print_cell("left", "<a href=\"coursefiles.php?id=$id&amp;wdir=$fileurl&amp;choose=$choose\"><img src=\"$CFG->pixpath/f/folder.gif\" height=\"16\" width=\"16\" border=\"0\" alt=\"Folder\" /></a> <a href=\"coursefiles.php?id=$id&amp;wdir=$fileurl&amp;choose=$choose\">".htmlspecialchars($dir)."</a>", 'name');
710 print_cell("right", $filesize, 'size');
711 print_cell("right", $filedate, 'date');
712 if ($choose) {
713 $edittext = "<b><a onMouseDown=\"return set_value('$selectdir')\" href=\"\">$strchoose</a></b>&nbsp;";
714 } else {
715 $edittext = '';
716 }
717 print_cell("right", "$edittext <a href=\"coursefiles.php?id=$id&amp;wdir=$wdir&amp;file=$filesafe&amp;action=rename&amp;choose=$choose\">$strrename</a>", 'commands');
718 }
719
720 echo "</tr>";
721 }
722 }
723
724
725 if (!empty($filelist)) {
726 asort($filelist);
727 foreach ($filelist as $file) {
728
729 $icon = mimeinfo("icon", $file);
730
731 $count++;
732 $filename = $fullpath."/".$file;
733 $fileurl = "$wdir/$file";
734 $filesafe = rawurlencode($file);
735 $fileurlsafe = rawurlencode($fileurl);
736 $filedate = userdate(filemtime($filename), "%d %b %Y, %I:%M %p");
737
738 if (substr($fileurl,0,1) == '/') {
739 $selectfile = substr($fileurl,1);
740 } else {
741 $selectfile = $fileurl;
742 }
743
744 echo "<tr class=\"file\">";
745
746 print_cell("center", "<input type=\"checkbox\" name=\"file$count\" value=\"$fileurl\" />", 'checkbox');
747 echo "<td align=\"left\" nowrap=\"nowrap\" class=\"name\">";
748 if ($CFG->slasharguments) {
749 $ffurl = "/file.php/$id$fileurl";
750 } else {
751 $ffurl = "/file.php?file=/$id$fileurl";
752 }
753 link_to_popup_window ($ffurl, "display",
754 "<img src=\"$CFG->pixpath/f/$icon\" height=\"16\" width=\"16\" border=\"0\" alt=\"File\" />",
755 480, 640);
756 echo '&nbsp;';
757 link_to_popup_window ($ffurl, "display",
758 htmlspecialchars($file),
759 480, 640);
760 echo "</td>";
761
762 $file_size = filesize($filename);
763 print_cell("right", display_size($file_size), 'size');
764 print_cell("right", $filedate, 'date');
765
766 if ($choose && $icon == "html.gif") {
767 $edittext = "<b><a onMouseDown=\"return set_value('$selectfile')\" href=\"\">$strchoose</a></b>&nbsp;";
768 } else {
769 $edittext = '';
770 }
771
772
773 if ($icon == "text.gif" || $icon == "html.gif") {
774 $edittext .= "<a href=\"coursefiles.php?id=$id&amp;wdir=$wdir&amp;file=$fileurl&amp;action=edit&amp;choose=$choose\">$stredit</a>";
775 } else if ($icon == "zip.gif") {
776 $edittext .= "<a href=\"coursefiles.php?id=$id&amp;wdir=$wdir&amp;file=$fileurl&amp;action=unzip&amp;sesskey=$USER->sesskey&amp;choose=$choose\">$strunzip</a>&nbsp;";
777 $edittext .= "<a href=\"coursefiles.php?id=$id&amp;wdir=$wdir&amp;file=$fileurl&amp;action=listzip&amp;sesskey=$USER->sesskey&amp;choose=$choose\">$strlist</a> ";
778 }
779
780 print_cell("right", "$edittext <a href=\"coursefiles.php?id=$id&amp;wdir=$wdir&amp;file=$filesafe&amp;action=rename&amp;choose=$choose\">$strrename</a>", 'commands');
781
782 echo "</tr>";
783 }
784 }
785 echo "</table>";
786 echo "<hr width=\"640\" align=\"center\" noshade=\"noshade\" size=\"1\" />";
787
788 if (empty($wdir)) {
789 $wdir = "/";
790 }
791
792 echo "<table border=\"0\" cellspacing=\"2\" cellpadding=\"2\" width=\"640\">";
793 echo "<tr><td>";
794 echo "<input type=\"hidden\" name=\"id\" value=\"$id\" />";
795 echo '<input type="hidden" name="choose" value="'.$choose.'">';
796 echo "<input type=\"hidden\" name=\"wdir\" value=\"$wdir\" /> ";
797 echo "<input type=\"hidden\" name=\"sesskey\" value=\"$USER->sesskey\" />";
798 $options = array (
799 "move" => "$strmovetoanotherfolder",
800 "delete" => "$strdeletecompletely",
801 "zip" => "$strcreateziparchive"
802 );
803 if (!empty($count)) {
804 choose_from_menu ($options, "action", "", "$strwithchosenfiles...", "javascript:document.dirform.submit()");
805 }
806
807 echo "</form>";
808 echo "<td align=\"center\">";
809 if (!empty($USER->fileop) and ($USER->fileop == "move") and ($USER->filesource <> $wdir)) {
810 echo "<form action=\"coursefiles.php\" method=\"get\">";
811 echo ' <input type="hidden" name="choose" value="'.$choose.'">';
812 echo " <input type=\"hidden\" name=\"id\" value=\"$id\" />";
813 echo " <input type=\"hidden\" name=\"wdir\" value=\"$wdir\" />";
814 echo " <input type=\"hidden\" name=\"action\" value=\"paste\" />";
815 echo " <input type=\"hidden\" name=\"sesskey\" value=\"$USER->sesskey\" />";
816 echo " <input type=\"submit\" value=\"$strmovefilestohere\" />";
817 echo "</form>";
818 }
819 echo "<td align=\"right\">";
820 echo "<form action=\"coursefiles.php\" method=\"get\">";
821 echo ' <input type="hidden" name="choose" value="'.$choose.'">';
822 echo " <input type=\"hidden\" name=\"id\" value=\"$id\" />";
823 echo " <input type=\"hidden\" name=\"wdir\" value=\"$wdir\" />";
824 echo " <input type=\"hidden\" name=\"action\" value=\"mkdir\" />";
825 echo " <input type=\"submit\" value=\"$strmakeafolder\" />";
826 echo "</form>";
827 echo "</td>";
828 echo "<td align=\"right\">";
829 echo "<form action=\"coursefiles.php\" method=\"get\">";
830 echo ' <input type="hidden" name="choose" value="'.$choose.'">';
831 echo " <input type=\"hidden\" name=\"id\" value=\"$id\" />";
832 echo " <input type=\"hidden\" name=\"wdir\" value=\"$wdir\" />";
833 echo " <input type=\"hidden\" name=\"action\" value=\"upload\" />";
834 echo " <input type=\"submit\" value=\"$struploadafile\" />";
835 echo "</form>";
836 echo "</td></tr>";
837 echo "</table>";
838 echo "<hr width=\"640\" align=\"center\" noshade=\"noshade\" size=\"1\" />";
839
840}
841
842?>