error("Only teachers can edit files");
}
- if (!$CFG->zip) {
- $CFG->zip = "/usr/bin/zip";
- }
-
- if (!$CFG->unzip) {
- $CFG->unzip = "/usr/bin/unzip";
- }
-
function html_footer() {
global $course;
echo "</td></tr></table></body></html>";
if (!empty($name)) {
html_header($course, $wdir);
$name = clean_filename($name);
- $files = "";
- foreach ($USER->filelist as $file) {
- $files .= basename($file);
- $files .= " ";
+ if (empty($CFG->zip)) { // Use built-in php-based zip function
+ $files = array();
+ foreach ($USER->filelist as $file) {
+ $files[] = "$basedir/$wdir$file";
+ }
+ include_once('../lib/pclzip/pclzip.lib.php');
+ $archive = new PclZip("$basedir/$wdir/$name");
+ if (($list = $archive->create($files,'',"$basedir/$wdir/")) == 0) {
+ error($archive->errorInfo(true));
+ }
+ } else { // Use external zip program
+ $files = "";
+ foreach ($USER->filelist as $file) {
+ $files .= basename($file);
+ $files .= " ";
+ }
+ $command = "cd $basedir/$wdir ; $CFG->zip -r $name $files";
+ Exec($command);
}
- $command = "cd $basedir/$wdir ; $CFG->zip -r $name $files";
- Exec($command);
clearfilelist();
displaydir($wdir);
case "unzip":
html_header($course, $wdir);
if (!empty($file)) {
- echo "<P ALIGN=CENTER>Unzipping $file:</P>";
- print_simple_box_start("center");
- echo "<PRE>";
+ $strname = get_string("name");
+ $strsize = get_string("size");
+ $strmodified = get_string("modified");
+ $strstatus = get_string("status");
+ $strok = get_string("ok");
+ $strunpacking = get_string("unpacking", "", $file);
+
+ echo "<P ALIGN=CENTER>$strunpacking:</P>";
+
$file = basename($file);
- $command = "cd $basedir/$wdir ; $CFG->unzip -o $file 2>&1";
- passthru($command);
- echo "</PRE>";
- print_simple_box_end();
+
+ if (empty($CFG->unzip)) { // Use built-in php-based unzip function
+ include_once('../lib/pclzip/pclzip.lib.php');
+ $archive = new PclZip("$basedir/$wdir/$file");
+ if (!$list = $archive->extract("$basedir/$wdir")) {
+ error($archive->errorInfo(true));
+ } else { // print some output
+ echo "<table cellpadding=\"4\" cellspacing=\"2\" border=\"0\" width=640>";
+ echo "<tr><th align=left>$strname</th>";
+ echo "<th align=right>$strsize</th>";
+ echo "<th align=right>$strmodified</th>";
+ echo "<th align=right>$strstatus</th></tr>";
+ foreach ($list as $item) {
+ echo "<tr>";
+ $item['filename'] = str_replace("$basedir/$wdir/", "", $item['filename']);
+ print_cell("left", $item['filename']);
+ if (! $item['folder']) {
+ print_cell("right", display_size($item['size']));
+ } else {
+ echo "<td> </td>";
+ }
+ $filedate = userdate($item['mtime'], get_string("strftimedatetime"));
+ print_cell("right", $filedate);
+ print_cell("right", $item['status']);
+ echo "</tr>";
+ }
+ echo "</table>";
+ }
+
+ } else { // Use external unzip program
+ print_simple_box_start("center");
+ echo "<PRE>";
+ $command = "cd $basedir/$wdir ; $CFG->unzip -o $file 2>&1";
+ passthru($command);
+ echo "</PRE>";
+ print_simple_box_end();
+ }
+
echo "<CENTER><FORM ACTION=index.php METHOD=get>";
echo " <INPUT TYPE=hidden NAME=id VALUE=$id>";
echo " <INPUT TYPE=hidden NAME=wdir VALUE=$wdir>";
echo " <INPUT TYPE=hidden NAME=action VALUE=cancel>";
- echo " <INPUT TYPE=submit VALUE=\"OK\">";
+ echo " <INPUT TYPE=submit VALUE=\"$strok\">";
echo "</FORM>";
echo "</CENTER>";
} else {
html_footer();
break;
+ case "listzip":
+ html_header($course, $wdir);
+ if (!empty($file)) {
+ $strname = get_string("name");
+ $strsize = get_string("size");
+ $strmodified = get_string("modified");
+ $strok = get_string("ok");
+ $strlistfiles = get_string("listfiles", "", $file);
+
+ echo "<P ALIGN=CENTER>$strlistfiles:</P>";
+ $file = basename($file);
+
+ include_once('../lib/pclzip/pclzip.lib.php');
+ $archive = new PclZip("$basedir/$wdir/$file");
+ if (!$list = $archive->listContent("$basedir/$wdir")) {
+ notify($archive->errorInfo(true));
+
+ } else {
+ echo "<table cellpadding=\"4\" cellspacing=\"2\" border=\"0\" width=640>";
+ echo "<tr><th align=left>$strname</th><th align=right>$strsize</th><th align=right>$strmodified</th></tr>";
+ foreach ($list as $item) {
+ echo "<tr>";
+ print_cell("left", $item['filename']);
+ if (! $item['folder']) {
+ print_cell("right", display_size($item['size']));
+ } else {
+ echo "<td> </td>";
+ }
+ $filedate = userdate($item['mtime'], get_string("strftimedatetime"));
+ print_cell("right", $filedate);
+ echo "</tr>";
+ }
+ echo "</table>";
+ }
+ echo "<br><center><form action=index.php method=get>";
+ echo " <INPUT TYPE=hidden NAME=id VALUE=$id>";
+ echo " <INPUT TYPE=hidden NAME=wdir VALUE=$wdir>";
+ echo " <INPUT TYPE=hidden NAME=action VALUE=cancel>";
+ echo " <INPUT TYPE=submit VALUE=\"$strok\">";
+ echo "</FORM>";
+ echo "</CENTER>";
+ } else {
+ displaydir($wdir);
+ }
+ html_footer();
+ break;
+
+
case "cancel";
clearfilelist();
$strrename = get_string("rename");
$stredit = get_string("edit");
$strunzip = get_string("unzip");
+ $strlist = get_string("list");
echo "<FORM ACTION=\"index.php\" METHOD=post NAME=dirform>";
if ($icon == "text.gif" || $icon == "html.gif") {
$edittext = "<A HREF=\"index.php?id=$id&wdir=$wdir&file=$fileurl&action=edit\">$stredit</A>";
} else if ($icon == "zip.gif") {
- $edittext = "<A HREF=\"index.php?id=$id&wdir=$wdir&file=$fileurl&action=unzip\">$strunzip</A>";
+ $edittext = "<A HREF=\"index.php?id=$id&wdir=$wdir&file=$fileurl&action=unzip\">$strunzip</A> ";
+ $edittext .= "<A HREF=\"index.php?id=$id&wdir=$wdir&file=$fileurl&action=listzip\">$strlist</A> ";
} else {
$edittext = "";
}
$string['configslasharguments'] = "Files (images, uploads etc) are provided via a script using 'slash arguments' (the second option here). This method allows files to be more easily cached in web browsers, proxy servers etc. Unfortunately, some PHP servers don't allow this method, so if you have trouble viewing uploaded files or images (eg user pictures), set this variable to the first option";
$string['configsmtphosts'] = "Give the full name of one or more local SMTP servers that Moodle should use to send mail (eg 'mail.a.com' or 'mail.a.com;mail.b.com'). If you leave it blank, Moodle will use the PHP default method of sending mail.";
$string['configsmtpuser'] = "If you have specified an SMTP server above, and the server requires authentication, then enter the username and password here.";
-$string['configunzip'] = "Indicate the location of your unzip program (Unix only). This is needed to unpack zip archives on the server.";
+$string['configunzip'] = "Indicate the location of your unzip program (Unix only, optional). If specified, this will be used to unpack zip archives on the server. If you leave this blank, then Moodle will use internal routines.";
$string['configvariables'] = "Configure variables";
-$string['configzip'] = "Indicate the location of your zip program (Unix only). This is needed to create zip archives on the server.";
+$string['configzip'] = "Indicate the location of your zip program (Unix only, optional). If specified, this will be used to create zip archives on the server. If you leave this blank, then Moodle will use internal routines.";
$string['confirmed'] = "Your registration has been confirmed";
$string['courseupdates'] = "Course updates";
$string['cookiesenabled'] = "Cookies must be enabled in your browser";
$string['lastmodified'] = "Last modified";
$string['lastname'] = "Last name";
$string['latestnews'] = "Latest news";
+$string['list'] = "List";
+$string['listfiles'] = "List of files in \$a";
$string['listofallpeople'] = "List of all people";
$string['license'] = "GPL License";
$string['livelogs'] = "Live logs from the past hour";
$string['unenrol'] = "Unenrol";
$string['unenrolme'] = "Unenrol me from \$a";
$string['unenrolsure'] = "Are you sure you want to unenrol \$a from this course?";
+$string['unpacking'] = "Unpacking \$a";
$string['unsafepassword'] = "Unsafe password - try something else";
$string['unusedaccounts'] = "Accounts unused for more than \$a days are automatically unenrolled";
$string['unzip'] = "Unzip";