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