Merge commit 'catalyst/MOODLE_19_STABLE' into mdl19-linuxchix
[moodle-linuxchix.git] / lib / editor / htmlarea / coursefiles.php
blob4c04eedb3ea6317d816ec5eb02748f493e7b762b
1 <?php // $Id$
3 // Manage all uploaded files in a course file area
5 // This file is a hack to files/index.php that removes
6 // the headers and adds some controls so that images
7 // can be selected within the Richtext editor.
9 // All the Moodle-specific stuff is in this top section
10 // Configuration and access control occurs here.
11 // Must define: USER, basedir, baseweb, html_header and html_footer
12 // USER is a persistent variable using sessions
14 require("../../../config.php");
15 require_once($CFG->libdir.'/filelib.php');
17 $id = required_param('id', PARAM_INT);
18 $file = optional_param('file', '', PARAM_PATH);
19 $wdir = optional_param('wdir', '', PARAM_PATH);
20 $action = optional_param('action', '', PARAM_ACTION);
21 $name = optional_param('name', '', PARAM_FILE);
22 $oldname = optional_param('oldname', '', PARAM_FILE);
23 $usecheckboxes = optional_param('usecheckboxes', 1, PARAM_INT);
24 $save = optional_param('save', 0, PARAM_BOOL);
25 $text = optional_param('text', '', PARAM_RAW);
26 $confirm = optional_param('confirm', 0, PARAM_BOOL);
29 if (! $course = get_record("course", "id", $id) ) {
30 error("That's an invalid course id");
33 require_login($course);
34 require_capability('moodle/course:managefiles', get_context_instance(CONTEXT_COURSE, $id));
36 function html_footer() {
37 echo "\n\n</body>\n</html>";
40 function html_header($course, $wdir, $formfield=""){
42 global $CFG;
45 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
46 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
47 <html>
48 <head>
49 <meta http-equiv="content-type" content="text/html; charset=utf-8" />
50 <title>coursefiles</title>
51 <script type="text/javascript">
52 //<![CDATA[
55 function set_value(params) {
56 /// function's argument is an object containing necessary values
57 /// to export parent window (url,isize,itype,iwidth,iheight, imodified)
58 /// set values when user click's an image name.
59 var upper = window.parent;
60 var insimg = upper.document.getElementById('f_url');
62 try {
63 if(insimg != null) {
64 if(params.itype.indexOf("image/gif") == -1 && params.itype.indexOf("image/jpeg") == -1 && params.itype.indexOf("image/png") == -1) {
65 alert("<?php print_string("notimage","editor");?>");
66 return false;
68 for(field in params) {
69 var value = params[field];
70 switch(field) {
71 case "url" : upper.document.getElementById('f_url').value = value;
72 upper.ipreview.location.replace('popups/preview.php?id='+ <?php print($course->id);?> +'&imageurl='+ value);
73 break;
74 case "isize" : upper.document.getElementById('isize').value = value; break;
75 case "itype" : upper.document.getElementById('itype').value = value; break;
76 case "iwidth": upper.document.getElementById('f_width').value = value; break;
77 case "iheight": upper.document.getElementById('f_height').value = value; break;
80 } else {
81 for(field in params) {
82 var value = params[field];
83 switch(field) {
84 case "url" :
85 //upper.document.getElementById('f_href').value = value;
86 upper.opener.document.getElementById('f_href').value = value;
87 upper.close();
88 break;
89 //case "imodified" : upper.document.getElementById('imodified').value = value; break;
90 //case "isize" : upper.document.getElementById('isize').value = value; break;
91 //case "itype" : upper.document.getElementById('itype').value = value; break;
95 } catch(e) {
96 if ( window.tinyMCE != "undefined" || window.TinyMCE != "undefined" ) {
97 upper.opener.Dialog._return(params.url);
98 upper.close();
99 } else {
100 alert("Something odd just occurred!!!");
103 return false;
106 function set_dir(strdir) {
107 // sets wdir values
108 var upper = window.parent.document;
109 if(upper) {
110 for(var i = 0; i < upper.forms.length; i++) {
111 var f = upper.forms[i];
112 try {
113 f.wdir.value = strdir;
114 } catch (e) {
121 function set_rename(strfile) {
122 var upper = window.parent.document;
123 upper.getElementById('irename').value = strfile;
124 return true;
127 function reset_value() {
128 var upper = window.parent.document;
129 for(var i = 0; i < upper.forms.length; i++) {
130 var f = upper.forms[i];
131 for(var j = 0; j < f.elements.length; j++) {
132 var e = f.elements[j];
133 if(e.type != "submit" && e.type != "button" && e.type != "hidden") {
134 try {
135 e.value = "";
136 } catch (e) {
141 upper.getElementById('irename').value = 'xx';
143 var prev = window.parent.ipreview;
144 if(prev != null) {
145 prev.location.replace('about:blank');
147 var uploader = window.parent.document.forms['uploader'];
148 if(uploader != null) {
149 uploader.reset();
151 set_dir('<?php print($wdir);?>');
152 return true;
154 //]]>
155 </script>
156 <style type="text/css">
157 body {
158 background-color: white;
159 margin-top: 2px;
160 margin-left: 4px;
161 margin-right: 4px;
163 body,p,table,td,input,select,a {
164 font-family: Tahoma, sans-serif;
165 font-size: 11px;
167 select {
168 position: absolute;
169 top: -20px;
170 left: 0px;
172 img.icon {
173 vertical-align:middle;
174 margin-right:4px;
175 width:16px;
176 height:16px;
177 border:0px;
179 </style>
180 </head>
181 <body onload="reset_value();">
183 <?php
186 if (! $basedir = make_upload_directory("$course->id")) {
187 error("The site administrator needs to fix the file permissions");
190 $baseweb = $CFG->wwwroot;
192 // End of configuration and access control
195 if ($wdir == '') {
196 $wdir='/';
199 switch ($action) {
201 case "upload":
202 html_header($course, $wdir);
203 require_once($CFG->dirroot.'/lib/uploadlib.php');
205 if ($save and confirm_sesskey()) {
206 $um = new upload_manager('userfile',false,false,$course,false,0);
207 $dir = "$basedir$wdir";
208 if ($um->process_file_uploads($dir)) {
209 notify(get_string('uploadedfile'));
211 // um will take care of error reporting.
212 displaydir($wdir);
213 } else {
214 $upload_max_filesize = get_max_upload_file_size($CFG->maxbytes);
215 $filesize = display_size($upload_max_filesize);
217 $struploadafile = get_string("uploadafile");
218 $struploadthisfile = get_string("uploadthisfile");
219 $strmaxsize = get_string("maxsize", "", $filesize);
220 $strcancel = get_string("cancel");
222 echo "<p>$struploadafile ($strmaxsize) --> <strong>$wdir</strong>";
223 echo "<table border=\"0\"><tr><td colspan=\"2\">\n";
224 echo "<form enctype=\"multipart/form-data\" method=\"post\" action=\"coursefiles.php\">\n";
225 upload_print_form_fragment(1,array('userfile'),null,false,null,$course->maxbytes,0,false);
226 echo " <input type=\"hidden\" name=\"id\" value=\"$id\" />\n";
227 echo " <input type=\"hidden\" name=\"wdir\" value=\"$wdir\" />\n";
228 echo " <input type=\"hidden\" name=\"action\" value=\"upload\" />\n";
229 echo " <input type=\"hidden\" name=\"sesskey\" value=\"$USER->sesskey\" />\n";
230 echo " </td><tr><td align=\"right\">";
231 echo " <input type=\"submit\" name=\"save\" value=\"$struploadthisfile\" />\n";
232 echo "</form>\n";
233 echo "</td>\n<td>\n";
234 echo "<form action=\"coursefiles.php\" method=\"get\">\n";
235 echo " <input type=\"hidden\" name=\"id\" value=\"$id\" />\n";
236 echo " <input type=\"hidden\" name=\"wdir\" value=\"$wdir\" />\n";
237 echo " <input type=\"hidden\" name=\"action\" value=\"cancel\" />\n";
238 echo " <input type=\"submit\" value=\"$strcancel\" />\n";
239 echo "</form>\n";
240 echo "</td>\n</tr>\n</table>\n";
242 html_footer();
243 break;
245 case "delete":
246 if ($confirm and confirm_sesskey()) {
247 html_header($course, $wdir);
248 foreach ($USER->filelist as $file) {
249 $fullfile = $basedir.$file;
250 if (! fulldelete($fullfile)) {
251 echo "<br />Error: Could not delete: $fullfile";
254 clearfilelist();
255 displaydir($wdir);
256 html_footer();
258 } else {
259 html_header($course, $wdir);
260 if (setfilelist($_POST)) {
261 echo "<p align=center>".get_string("deletecheckwarning").":</p>";
262 print_simple_box_start("center");
263 printfilelist($USER->filelist);
264 print_simple_box_end();
265 echo "<br />";
266 $frameold = $CFG->framename;
267 $CFG->framename = "ibrowser";
268 notice_yesno (get_string("deletecheckfiles"),
269 "coursefiles.php?id=$id&amp;wdir=$wdir&amp;action=delete&amp;confirm=1&amp;sesskey=$USER->sesskey",
270 "coursefiles.php?id=$id&amp;wdir=$wdir&amp;action=cancel");
271 $CFG->framename = $frameold;
272 } else {
273 displaydir($wdir);
275 html_footer();
277 break;
279 case "move":
280 html_header($course, $wdir);
281 if ($count = setfilelist($_POST) and confirm_sesskey()) {
282 $USER->fileop = $action;
283 $USER->filesource = $wdir;
284 echo "<p align=\"center\">";
285 print_string("selectednowmove", "moodle", $count);
286 echo "</p>";
288 displaydir($wdir);
289 html_footer();
290 break;
292 case "paste":
293 html_header($course, $wdir);
294 if (isset($USER->fileop) and $USER->fileop == "move" and confirm_sesskey()) {
295 foreach ($USER->filelist as $file) {
296 $shortfile = basename($file);
297 $oldfile = $basedir.$file;
298 $newfile = $basedir.$wdir."/".$shortfile;
299 if (!rename($oldfile, $newfile)) {
300 echo "<p>Error: $shortfile not moved";
304 clearfilelist();
305 displaydir($wdir);
306 html_footer();
307 break;
309 case "rename":
310 if (!empty($name) and confirm_sesskey()) {
311 html_header($course, $wdir);
312 $name = clean_filename($name);
313 if (file_exists($basedir.$wdir."/".$name)) {
314 echo "Error: $name already exists!";
315 } else if (!@rename($basedir.$wdir."/".$oldname, $basedir.$wdir."/".$name)) {
316 echo "Error: could not rename $oldname to $name";
318 displaydir($wdir);
320 } else {
321 $strrename = get_string("rename");
322 $strcancel = get_string("cancel");
323 $strrenamefileto = get_string("renamefileto", "moodle", $file);
324 html_header($course, $wdir, "form.name");
325 echo "<p>$strrenamefileto:";
326 echo "<table border=\"0\">\n<tr>\n<td>\n";
327 echo "<form action=\"coursefiles.php\" method=\"post\" id=\"form\">\n";
328 echo " <input type=\"hidden\" name=\"id\" value=\"$id\" />\n";
329 echo " <input type=\"hidden\" name=\"wdir\" value=\"$wdir\" />\n";
330 echo " <input type=\"hidden\" name=\"action\" value=\"rename\" />\n";
331 echo " <input type=\"hidden\" name=\"sesskey\" value=\"$USER->sesskey\" />\n";
332 echo " <input type=\"hidden\" name=\"oldname\" value=\"$file\" />\n";
333 echo " <input type=\"text\" name=\"name\" size=\"35\" value=\"$file\" />\n";
334 echo " <input type=\"submit\" value=\"$strrename\" />\n";
335 echo "</form>\n";
336 echo "</td><td>\n";
337 echo "<form action=\"coursefiles.php\" method=\"get\">\n";
338 echo " <input type=\"hidden\" name=\"id\" value=\"$id\" />\n";
339 echo " <input type=\"hidden\" name=\"wdir\" value=\"$wdir\" />\n";
340 echo " <input type=\"hidden\" name=\"action\" value=\"cancel\" />\n";
341 echo " <input type=\"submit\" value=\"$strcancel\" />\n";
342 echo "</form>";
343 echo "</td></tr>\n</table>\n";
345 html_footer();
346 break;
348 case "mkdir":
349 if (!empty($name) and confirm_sesskey()) {
350 html_header($course, $wdir);
351 $name = clean_filename($name);
352 if (file_exists("$basedir$wdir/$name")) {
353 echo "Error: $name already exists!";
354 } else if (! make_upload_directory("$course->id/$wdir/$name")) {
355 echo "Error: could not create $name";
357 displaydir($wdir);
359 } else {
360 $strcreate = get_string("create");
361 $strcancel = get_string("cancel");
362 $strcreatefolder = get_string("createfolder", "moodle", $wdir);
363 html_header($course, $wdir, "form.name");
364 echo "<p>$strcreatefolder:";
365 echo "<table border=\"0\">\n<tr><td>\n";
366 echo "<form action=\"coursefiles.php\" method=\"post\" name=\"form\">\n";
367 echo " <input type=\"hidden\" name=\"id\" value=\"$id\" />\n";
368 echo " <input type=\"hidden\" name=\"wdir\" value=\"$wdir\" />\n";
369 echo " <input type=\"hidden\" name=\"action\" value=\"mkdir\" />\n";
370 echo " <input type=\"hidden\" name=\"sesskey\" value=\"$USER->sesskey\" />\n";
371 echo " <input type=\"text\" name=\"name\" size=\"35\" />\n";
372 echo " <input type=\"submit\" value=\"$strcreate\" />\n";
373 echo "</form>\n";
374 echo "</td><td>\n";
375 echo "<form action=\"coursefiles.php\" method=\"get\">\n";
376 echo " <input type=\"hidden\" name=\"id\" value=\"$id\" />\n";
377 echo " <input type=\"hidden\" name=\"wdir\" value=\"$wdir\" />\n";
378 echo " <input type=\"hidden\" name=\"action\" value=\"cancel\" />\n";
379 echo " <input type=\"submit\" value=\"$strcancel\" />\n";
380 echo "</form>\n";
381 echo "</td>\n</tr>\n</table>\n";
383 html_footer();
384 break;
386 case "edit":
387 html_header($course, $wdir);
388 if (($text != '') and confirm_sesskey()) {
389 $fileptr = fopen($basedir.$file,"w");
390 fputs($fileptr, stripslashes($text));
391 fclose($fileptr);
392 displaydir($wdir);
394 } else {
395 $streditfile = get_string("edit", "", "<strong>$file</strong>");
396 $fileptr = fopen($basedir.$file, "r");
397 $contents = fread($fileptr, filesize($basedir.$file));
398 fclose($fileptr);
400 print_heading("$streditfile");
402 echo "<table><tr><td colspan=\"2\">\n";
403 echo "<form action=\"coursefiles.php\" method=\"post\" name=\"form\" $onsubmit>\n";
404 echo " <input type=\"hidden\" name=\"id\" value=\"$id\" />\n";
405 echo " <input type=\"hidden\" name=\"wdir\" value=\"$wdir\" />\n";
406 echo " <input type=\"hidden\" name=file value=\"$file\" />";
407 echo " <input type=\"hidden\" name=\"action\" value=\"edit\" />\n";
408 echo " <input type=\"hidden\" name=\"sesskey\" value=\"$USER->sesskey\" />\n";
409 print_textarea(false, 25, 80, 680, 400, "text", $contents);
410 echo "</td>\n</tr>\n<tr>\n<td>\n";
411 echo " <input type=\"submit\" value=\"".get_string("savechanges")."\" />\n";
412 echo "</form>\n";
413 echo "</td>\n<td>\n";
414 echo "<form action=\"coursefiles.php\" method=\"get\">\n";
415 echo " <input type=\"hidden\" name=\"id\" value=\"$id\" />\n";
416 echo " <input type=\"hidden\" name=\"wdir\" value=\"$wdir\" />\n";
417 echo " <input type=\"hidden\" name=\"action\" value=\"cancel\" />\n";
418 echo " <input type=\"submit\" value=\"".get_string("cancel")."\" />\n";
419 echo "</form>\n";
420 echo "</td></tr></table>\n";
422 if ($usehtmleditor) {
423 use_html_editor("text");
428 html_footer();
429 break;
431 case "zip":
432 if (!empty($name) and confirm_sesskey()) {
433 html_header($course, $wdir);
434 $name = clean_filename($name);
436 $files = array();
437 foreach ($USER->filelist as $file) {
438 $files[] = "$basedir/$file";
441 if (!zip_files($files,"$basedir/$wdir/$name")) {
442 print_error("zipfileserror","error");
445 clearfilelist();
446 displaydir($wdir);
448 } else {
449 html_header($course, $wdir, "form.name");
451 if (setfilelist($_POST)) {
452 echo "<p align=\"center\">".get_string("youareabouttocreatezip").":</p>";
453 print_simple_box_start("center");
454 printfilelist($USER->filelist);
455 print_simple_box_end();
456 echo "<br />";
457 echo "<p align=\"center\">".get_string("whattocallzip");
458 echo "<table border=\"0\">\n<tr>\n<td>\n";
459 echo "<form action=\"coursefiles.php\" method=\"post\" name=\"form\">\n";
460 echo " <input type=\"hidden\" name=\"id\" value=\"$id\" />\n";
461 echo " <input type=\"hidden\" name=\"wdir\" value=\"$wdir\" />\n";
462 echo " <input type=\"hidden\" name=\"action\" value=\"zip\" />\n";
463 echo " <input type=\"hidden\" name=\"sesskey\" value=\"$USER->sesskey\" />\n";
464 echo " <INPUT type=\"text\" name=\"name\" size=\"35\" value=\"new.zip\" />\n";
465 echo " <input type=\"submit\" value=\"".get_string("createziparchive")."\" />";
466 echo "</form>\n";
467 echo "</td>\n<td>\n";
468 echo "<form action=\"coursefiles.php\" method=\"get\">\n";
469 echo " <input type=\"hidden\" name=\"id\" value=\"$id\" />\n";
470 echo " <input type=\"hidden\" name=\"wdir\" value=\"$wdir\" />\n";
471 echo " <input type=\"hidden\" name=\"action\" value=\"cancel\" />\n";
472 echo " <input type=\"submit\" value=\"".get_string("cancel")."\" />\n";
473 echo "</form>\n";
474 echo "</td>\n</tr>\n</table>\n";
475 } else {
476 displaydir($wdir);
477 clearfilelist();
480 html_footer();
481 break;
483 case "unzip":
484 html_header($course, $wdir);
485 if (!empty($file) and confirm_sesskey()) {
486 $strok = get_string("ok");
487 $strunpacking = get_string("unpacking", "", $file);
489 echo "<p align=\"center\">$strunpacking:</p>";
491 $file = basename($file);
493 if (!unzip_file("$basedir/$wdir/$file")) {
494 print_error("unzipfileserror","error");
497 echo "<center><form action=\"coursefiles.php\" method=\"get\">\n";
498 echo " <input type=\"hidden\" name=\"id\" value=\"$id\" />\n";
499 echo " <input type=\"hidden\" name=\"wdir\" value=\"$wdir\" />\n";
500 echo " <input type=\"hidden\" name=\"action\" value=\"cancel\" />\n";
501 echo " <input type=\"submit\" value=\"$strok\" />\n";
502 echo "</form>\n";
503 echo "</center>\n";
504 } else {
505 displaydir($wdir);
507 html_footer();
508 break;
510 case "listzip":
511 html_header($course, $wdir);
512 if (!empty($file) and confirm_sesskey()) {
513 $strname = get_string("name");
514 $strsize = get_string("size");
515 $strmodified = get_string("modified");
516 $strok = get_string("ok");
517 $strlistfiles = get_string("listfiles", "", $file);
519 echo "<p align=\"center\">$strlistfiles:</p>";
520 $file = basename($file);
522 require_once($CFG->libdir.'/pclzip/pclzip.lib.php');
523 $archive = new PclZip("$basedir/$wdir/$file");
524 if (!$list = $archive->listContent("$basedir/$wdir")) {
525 notify($archive->errorInfo(true));
527 } else {
528 echo "<table cellpadding=\"4\" cellspacing=\"2\" border=\"0\">\n";
529 echo "<tr>\n<th align=\"left\" scope=\"col\">$strname</th><th align=\"right\" scope=\"col\">$strsize</th><th align=\"right\" scope=\"col\">$strmodified</th></tr>";
530 foreach ($list as $item) {
531 echo "<tr>";
532 print_cell("left", $item['filename']);
533 if (! $item['folder']) {
534 print_cell("right", display_size($item['size']));
535 } else {
536 echo "<td>&nbsp;</td>\n";
538 $filedate = userdate($item['mtime'], get_string("strftimedatetime"));
539 print_cell("right", $filedate);
540 echo "</tr>\n";
542 echo "</table>\n";
544 echo "<br /><center><form action=\"coursefiles.php\" method=\"get\">\n";
545 echo " <input type=\"hidden\" name=\"id\" value=\"$id\" />\n";
546 echo " <input type=\"hidden\" name=\"wdir\" value=\"$wdir\" />\n";
547 echo " <input type=\"hidden\" name=\"action\" value=\"cancel\" />\n";
548 echo " <input type=\"hidden\" name=\"sesskey\" value=\"$USER->sesskey\" />\n";
549 echo " <input type=\"submit\" value=\"$strok\" />\n";
550 echo "</form>\n";
551 echo "</center>\n";
552 } else {
553 displaydir($wdir);
555 html_footer();
556 break;
558 case "cancel":
559 clearfilelist();
561 default:
562 html_header($course, $wdir);
563 displaydir($wdir);
564 html_footer();
565 break;
569 /// FILE FUNCTIONS ///////////////////////////////////////////////////////////
572 function setfilelist($VARS) {
573 global $USER;
575 $USER->filelist = array ();
576 $USER->fileop = "";
578 $count = 0;
579 foreach ($VARS as $key => $val) {
580 if (substr($key,0,4) == "file") {
581 $count++;
582 $val = rawurldecode($val);
583 if (!detect_munged_arguments($val, 0)) {
584 $USER->filelist[] = $val;
588 return $count;
591 function clearfilelist() {
592 global $USER;
594 $USER->filelist = array ();
595 $USER->fileop = "";
599 function printfilelist($filelist) {
600 global $basedir, $CFG;
602 foreach ($filelist as $file) {
603 if (is_dir($basedir.$file)) {
604 echo "<img src=\"$CFG->pixpath/f/folder.gif\" class=\"icon\" alt=\"".get_string('folder')."\" /> $file<br />";
605 $subfilelist = array();
606 $currdir = opendir($basedir.$file);
607 while (false !== ($subfile = readdir($currdir))) {
608 if ($subfile <> ".." && $subfile <> ".") {
609 $subfilelist[] = $file."/".$subfile;
612 printfilelist($subfilelist);
614 } else {
615 $icon = mimeinfo("icon", $file);
616 echo "<img src=\"$CFG->pixpath/f/$icon\" class=\"icon\" alt=\"".get_string('file')."\" /> $file<br />";
622 function print_cell($alignment="center", $text="&nbsp;") {
623 echo "<td align=\"$alignment\" nowrap=\"nowrap\">\n";
624 echo "$text";
625 echo "</td>\n";
628 function get_image_size($filepath) {
629 /// This function get's the image size
631 /// Check if file exists
632 if(!file_exists($filepath)) {
633 return false;
634 } else {
635 /// Get the mime type so it really an image.
636 if(mimeinfo("icon", basename($filepath)) != "image.gif") {
637 return false;
638 } else {
639 $array_size = getimagesize($filepath);
640 return $array_size;
643 unset($filepath,$array_size);
646 function displaydir ($wdir) {
647 // $wdir == / or /a or /a/b/c/d etc
649 global $basedir;
650 global $usecheckboxes;
651 global $id;
652 global $USER, $CFG;
654 $fullpath = $basedir.$wdir;
656 $directory = opendir($fullpath); // Find all files
657 while (false !== ($file = readdir($directory))) {
658 if ($file == "." || $file == "..") {
659 continue;
662 if (is_dir($fullpath."/".$file)) {
663 $dirlist[] = $file;
664 } else {
665 $filelist[] = $file;
668 closedir($directory);
670 $strfile = get_string("file");
671 $strname = get_string("name");
672 $strsize = get_string("size");
673 $strmodified = get_string("modified");
674 $straction = get_string("action");
675 $strmakeafolder = get_string("makeafolder");
676 $struploadafile = get_string("uploadafile");
677 $strwithchosenfiles = get_string("withchosenfiles");
678 $strmovetoanotherfolder = get_string("movetoanotherfolder");
679 $strmovefilestohere = get_string("movefilestohere");
680 $strdeletecompletely = get_string("deletecompletely");
681 $strcreateziparchive = get_string("createziparchive");
682 $strrename = get_string("rename");
683 $stredit = get_string("edit");
684 $strunzip = get_string("unzip");
685 $strlist = get_string("list");
686 $strchoose = get_string("choose");
689 echo "<form action=\"coursefiles.php\" method=\"post\" name=\"dirform\">\n";
690 echo "<table border=\"0\" cellspacing=\"2\" cellpadding=\"2\" width=\"100%\">\n";
692 if ($wdir == "/") {
693 $wdir = "";
694 } else {
695 $bdir = str_replace("/".basename($wdir),"",$wdir);
696 if($bdir == "/") {
697 $bdir = "";
699 print "<tr>\n<td colspan=\"5\">";
700 print "<a href=\"coursefiles.php?id=$id&amp;wdir=$bdir&amp;usecheckboxes=$usecheckboxes\" onclick=\"return reset_value();\">";
701 print "<img src=\"$CFG->wwwroot/lib/editor/htmlarea/images/folderup.gif\" height=\"14\" width=\"24\" border=\"0\" alt=\"".get_string('parentfolder')."\" />";
702 print "</a></td>\n</tr>\n";
705 $count = 0;
707 if (!empty($dirlist)) {
708 asort($dirlist);
709 foreach ($dirlist as $dir) {
711 $count++;
713 $filename = $fullpath."/".$dir;
714 $fileurl = $wdir."/".$dir;
715 $filedate = userdate(filemtime($filename), "%d %b %Y, %I:%M %p");
717 echo "<tr>";
719 if ($usecheckboxes) {
720 print_cell("center", "<input type=\"checkbox\" name=\"file$count\" value=\"$fileurl\" onclick=\"return set_rename('$dir');\" />");
722 print_cell("left", "<a href=\"coursefiles.php?id=$id&amp;wdir=$fileurl\" onclick=\"return reset_value();\"><img src=\"$CFG->pixpath/f/folder.gif\" class=\"icon\" alt=\"".get_string('folder')."\" /></a> <a href=\"coursefiles.php?id=$id&amp;wdir=$fileurl&amp;usecheckboxes=$usecheckboxes\" onclick=\"return reset_value();\">".htmlspecialchars($dir)."</a>");
723 print_cell("right", "&nbsp;");
724 print_cell("right", $filedate);
726 echo "</tr>";
731 if (!empty($filelist)) {
732 asort($filelist);
733 foreach ($filelist as $file) {
735 $icon = mimeinfo("icon", $file);
736 $imgtype = mimeinfo("type",$file);
738 $count++;
739 $filename = $fullpath."/".$file;
740 $fileurl = "$wdir/$file";
741 $filedate = userdate(filemtime($filename), "%d %b %Y, %I:%M %p");
743 $dimensions = get_image_size($filename);
744 if($dimensions) {
745 $imgwidth = $dimensions[0];
746 $imgheight = $dimensions[1];
747 } else {
748 $imgwidth = "Unknown";
749 $imgheight = "Unknown";
751 unset($dimensions);
752 echo "<tr>\n";
754 if ($usecheckboxes) {
755 print_cell("center", "<input type=\"checkbox\" name=\"file$count\" value=\"$fileurl\" onclick=\";return set_rename('$file');\" />");
757 echo "<td align=\"left\" nowrap=\"nowrap\">";
758 $ffurl = get_file_url($id.$fileurl);
759 link_to_popup_window ($ffurl, "display",
760 "<img src=\"$CFG->pixpath/f/$icon\" class=\"icon\" alt=\"$strfile\" />",
761 480, 640);
762 $file_size = filesize($filename);
764 echo "<a onclick=\"return set_value(info = {url: '".$ffurl."',";
765 echo " isize: '".$file_size."', itype: '".$imgtype."', iwidth: '".$imgwidth."',";
766 echo " iheight: '".$imgheight."', imodified: '".$filedate."' })\" href=\"#\">$file</a>";
767 echo "</td>\n";
769 if ($icon == "zip.gif") {
770 $edittext = "<a href=\"coursefiles.php?id=$id&amp;wdir=$wdir&amp;file=$fileurl&amp;action=unzip&amp;sesskey=$USER->sesskey\">$strunzip</a>&nbsp;";
771 $edittext .= "<a href=\"coursefiles.php?id=$id&amp;wdir=$wdir&amp;file=$fileurl&amp;action=listzip&amp;sesskey=$USER->sesskey\">$strlist</a> ";
772 } else {
773 $edittext = "&nbsp;";
775 print_cell("right", "$edittext ");
776 print_cell("right", $filedate);
778 echo "</tr>\n";
781 echo "</table>\n";
783 if (empty($wdir)) {
784 $wdir = "/";
787 echo "<table border=\"0\" cellspacing=\"2\" cellpadding=\"2\">\n";
788 echo "<tr>\n<td>";
789 echo "<input type=\"hidden\" name=\"id\" value=\"$id\" />\n";
790 echo "<input type=\"hidden\" name=\"wdir\" value=\"$wdir\" />\n";
791 echo "<input type=\"hidden\" name=\"sesskey\" value=\"$USER->sesskey\" />\n";
792 $options = array (
793 "move" => "$strmovetoanotherfolder",
794 "delete" => "$strdeletecompletely",
795 "zip" => "$strcreateziparchive"
797 if (!empty($count)) {
798 choose_from_menu ($options, "action", "", "$strwithchosenfiles...", "javascript:getElementById('dirform').submit()");
800 if (!empty($USER->fileop) and ($USER->fileop == "move") and ($USER->filesource <> $wdir)) {
801 echo "<form action=\"coursefiles.php\" method=\"get\">\n";
802 echo " <input type=\"hidden\" name=\"id\" value=\"$id\" />\n";
803 echo " <input type=\"hidden\" name=\"wdir\" value=\"$wdir\" />\n";
804 echo " <input type=\"hidden\" name=\"action\" value=\"paste\" />\n";
805 echo " <input type=\"hidden\" name=\"sesskey\" value=\"$USER->sesskey\" />\n";
806 echo " <input type=\"submit\" value=\"$strmovefilestohere\" />\n";
807 echo "</form>";
809 echo "</td></tr>\n";
810 echo "</table>\n";
811 echo "</form>\n";