[LON-CAPA-dev] Suggestion of new author tool: upload of .ZIP files and unzip it in the current work directory in the Construction Space area

Ricardo Luis Kulzer lon-capa-dev@mail.lon-capa.org
Fri, 03 Oct 2003 21:49:11 -0300


--------------030908040402060709010907
Content-Type: text/plain; charset=windows-1252; format=flowed
Content-Transfer-Encoding: 8bit

   I saw a sample of file manager applied to Apache that allows to unzip 
a .ZIP file: it's the OpenIndex (the site is 
http://www.xorgate.com/Apache/OpenIndex/).

To see how it works, open the following URL:
http://www.xorgate.com/Apache/OpenIndex/demo/.XOI
(User=openindex  
Password=02sep02)

I took the sources of OpenIndex from 
http://www.cpan.org/authors/id/S/SA/SANDERSON/OpenIndex-1.05.tar.gz

Inside the distribution, the main code is in a file called OpenIndex.pm. 
and it uses the following function to unzip the files.

------------------------------------------------------------------------
sub Unzip {
 my ($r,$args,$cfg,$root,$src,$dst) = @_;
    $dst=~s:/$::;        # strip any trailing '/'
    use Archive::Zip qw( :ERROR_CODES :CONSTANTS );
    use Archive::Zip::Tree;
 my $lang = new Apache::Language($r) if $cfg->{language};
 my $msg;
 my $cmdname=$lang->{Unzip} || 'Unzip';
    chomp $cmdname;
    unless($dst) {
    $msg=$lang->{DestPath} || 'Bad destination path';
    errmsg("${cmdname}: $msg");
    return 0;
    }
    $src="$root$src";
    $dst="$root$dst";
 my $fgid=(stat $src)[5];
    unless(isagid($args->{gid},$fgid) || $args->{isadmin}) {
    $msg=$lang->{SourceAccess} || 'Source access denied';
    errmsg("${cmdname}: $msg");
    return 0;
    }
    $fgid=(stat $dst)[5];
    if(! -d _) {
    $msg=$lang->{DestDir} || 'Destination is not a directory';
    errmsg("${cmdname}: $msg");
    return 0;
    }
    unless(isagid($args->{gid},$fgid) || $args->{isadmin}) {
    $msg=$lang->{DestAccess} || 'Destination access denied';
    errmsg("${cmdname}: $msg");
    return 0;
    }
 my $zip=Archive::Zip->new($src);
    unless ($zip) {
    $msg=$lang->{FileRead} || 'file read';
    errmsg("${cmdname}: $msg");
    return 0;
    }
 my $files=0;
 my $name;
    $dst.='/';
    for my $member ($zip->members()) {
    ($name=$dst).=$member->fileName();
    if($member->isDirectory()) {
        mkdir $name,0775;
        chown(-1,$fgid,$name);
            next;
    }
    unless($member->extractToFileNamed($name)==AZ_OK) {
        errmsg("$cmdname: $name");
        return 0;
    }
    chown(-1,$fgid,$name);
    ++$files;
    }
    $r->log->notice(__PACKAGE__." $args->{user}: Unzip: $src files=$files");
    1;
}

------------------------------------------------------------------------

I think it's not difficult to implement similar feature in LON-CAPA 
Construction Space area.

I think that the first thing to do it's add the Unzip button in 
the publisher.html  file of the LON-CAPA sources. Am I right?

Ricardo L. Kulzer







Gerd Kortemeyer escreveu:

> Ricardo,
>
> Thank you very much for your input. There is actually a bug report 
> regarding ZIP files, see
>
>  http://bugs.lon-capa.org/show_bug.cgi?id=659
>
> I have changed the milestone on that enhancement request to "1.1" - I 
> had similar experiences trying to teach faculty about having to upload 
> ALL files associated with an HTML file.
>
> If you open an account on Bugzilla, you can put yourself on the 
> cc-list of the above bug to see what happens.
>
> Please let us know if you would like your machine connected to a cluster.
>
> - Gerd.
>
> On Thursday, September 11, 2003, at 09:58  PM, Ricardo Luis Kulzer wrote:
>
>>     Hello.  
>>     I’m a new user of LON-CAPA, and I don’t know many thinks about 
>> its code, but I’m investigating it. now.  
>>     In our laboratory, we used another e-learning software called 
>> TELEDUC (http://teleduc.nied.unicamp.br/teleduc/), very good, but it 
>> doesn't bring all the advantages offered by the LON-CAPA.  
>>     However, an important feature that is missing in LON-CAPA, and it 
>> exists TELEDUC, is a tool that allows to do upload of several files 
>> compacted in one only .ZIP file, and allow to unzip the .ZIP file in 
>> the server later.   
>>     So, when developing a page using some HTML editor like Netscape 
>> Composer, we used compact the file .HTML and << many >> images files 
>> (.GIF, .JPG) in only one .ZIP file. Soon after, through the WEB 
>> interface of TELEDUC, we transfer (upload) the .ZIP file in to the 
>> TELEDUC server. Then, the WEB interface provides a new button that 
>> allows unzip that file in the server and to publish them as a new 
>> Content Page, with the .HTML and images files totally decompressed.
>>     I tried to do the same task in LON-CAPA, but it doesn't present 
>> this resource. So I needed to do upload of file by file, using the 
>> tool Construction Space, and that is a annoying task (upload file by 
>> file…).
>>     I know that I can use SSH file transfer or Samba, but It’s 
>> difficult to teach all this thinks to a Geography teacher, for 
>> example, that usually don’t know and don’t like computer a lot. And 
>> another advantage is that we don’t need to open smb and ssh ports to 
>> every author. He can do all this thinks through http server, in a 
>> much more secure way, using the simple and easy Construction Space 
>> tool of LON-CAPA.
>>     Then I would like to propose to the LON-CAPA development, to 
>> create a new tool in the Construction Space area of LON-CAPA, that 
>> allows to upload a .ZIP file, and automatically unzip it into the 
>> server. Or alternatively, a tool that allows to upload of a whole 
>> paste with many files at the same time (like select many files in 
>> Windows Explorer using Shift key), without the need of currently file 
>> by file upload tool available today in LON-CAPA.  
>>     I saw in the TELEDUC code that the function responsible for unzip 
>> the .ZIP file in the server after the upload is implemented in PHP. 
>> The PHP code is more or less like this:  
>>  
>> / * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 
>> * * * *  
>>    DescompactarArquivoZip function - Unzip compressed cribs.  
>>    Input: $zip - path and name of the zip cribs  
>>              $destination - destination path to unzip   
>>    Output: true i all ok  
>> * /  
>> function DescompactarArquivoZip ($zip,$destination)  
>> {  
>>   $command = " unzip -q -o \"". $zip ". \ " -d \"". $destination ". 
>> \"";  
>>   system($command,$status);  
>>   CreateIndexFile ($destination);  
>>   SetPermissions($destination);  
>>   return (! $status);  
>> }  
>>  
>>     So, I think it’s not difficult to insert an equivalent function 
>> in LON-CAPA code, not in PHP, but in perl, the main LON-CAPA 
>> language. It would be enough to add a button in the Construction 
>> Space area to allow the upload of .ZIP files. After the upload, the 
>> system of the LON- CAPA will be able to automatically unzip the file 
>> in the current work directory of Construction Space area, or to show 
>> a new option for the .ZIP file that allows unzip it into the server, 
>> to be published later.  
>>     I await suggestions to implement this new tool. And sorry for my 
>> poor English.
>>
>>     Thanks,
>>     Ricardo Luis Kulzer.
>>
>>  
>>  
>>


--------------030908040402060709010907
Content-Type: text/html; charset=windows-1252
Content-Transfer-Encoding: 8bit

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <title></title>
</head>
<body>
 
<title></title>
      I saw a sample of file manager applied to Apache that allows to unzip
a .ZIP file: it's the <b>OpenIndex </b>(the site is <a
 class="moz-txt-link-freetext"
 href="http://www.xorgate.com/Apache/OpenIndex/">http://www.xorgate.com/Apache/OpenIndex/</a>).<br>
 <br>
 To see how it works, open the following URL: <br>
 <a class="moz-txt-link-freetext"
 href="http://www.xorgate.com/Apache/OpenIndex/demo/.XOI">http://www.xorgate.com/Apache/OpenIndex/demo/.XOI</a><br>
 (User=openindex    <br>
 Password=02sep02)<br>
 <br>
 I took the sources of OpenIndex from <a class="moz-txt-link-freetext" href="http://www.cpan.org/authors/id/S/SA/SANDERSON/OpenIndex-1.05.tar.gz">http://www.cpan.org/authors/id/S/SA/SANDERSON/OpenIndex-1.05.tar.gz</a><br>
<br>
Inside the distribution, the main code is in a file called OpenIndex.pm.
and it uses the following function to unzip the files.<br>
 <br>
 
<hr width="100%" size="9"><i>sub Unzip {<br>
 my ($r,$args,$cfg,$root,$src,$dst) = @_;<br>
    $dst=~s:/$::;        # strip any trailing '/'<br>
    use Archive::Zip qw( :ERROR_CODES :CONSTANTS );<br>
    use Archive::Zip::Tree;<br>
 my $lang = new Apache::Language($r) if $cfg-&gt;{language};<br>
 my $msg;<br>
 my $cmdname=$lang-&gt;{Unzip} || 'Unzip';<br>
    chomp $cmdname;<br>
    unless($dst) {<br>
    $msg=$lang-&gt;{DestPath} || 'Bad destination path';<br>
    errmsg("${cmdname}: $msg");<br>
    return 0;<br>
    }<br>
    $src="$root$src";<br>
    $dst="$root$dst";<br>
 my $fgid=(stat $src)[5];<br>
    unless(isagid($args-&gt;{gid},$fgid) || $args-&gt;{isadmin}) {<br>
    $msg=$lang-&gt;{SourceAccess} || 'Source access denied';<br>
    errmsg("${cmdname}: $msg");<br>
    return 0;<br>
    }<br>
    $fgid=(stat $dst)[5];<br>
    if(! -d _) {<br>
    $msg=$lang-&gt;{DestDir} || 'Destination is not a directory';<br>
    errmsg("${cmdname}: $msg");<br>
    return 0;<br>
    }<br>
    unless(isagid($args-&gt;{gid},$fgid) || $args-&gt;{isadmin}) {<br>
    $msg=$lang-&gt;{DestAccess} || 'Destination access denied';<br>
    errmsg("${cmdname}: $msg");<br>
    return 0;<br>
    }<br>
 my $zip=Archive::Zip-&gt;new($src);<br>
    unless ($zip) {<br>
    $msg=$lang-&gt;{FileRead} || 'file read';<br>
    errmsg("${cmdname}: $msg");<br>
    return 0;<br>
    }<br>
 my $files=0;<br>
 my $name;<br>
    $dst.='/';<br>
    for my $member ($zip-&gt;members()) {<br>
    ($name=$dst).=$member-&gt;fileName();<br>
    if($member-&gt;isDirectory()) {<br>
        mkdir $name,0775;<br>
        chown(-1,$fgid,$name);<br>
            next;<br>
    }<br>
    unless($member-&gt;extractToFileNamed($name)==AZ_OK) {<br>
        errmsg("$cmdname: $name");<br>
        return 0;<br>
    }<br>
    chown(-1,$fgid,$name);<br>
    ++$files;<br>
    }<br>
    $r-&gt;log-&gt;notice(__PACKAGE__." $args-&gt;{user}: Unzip: $src files=$files");<br>
    1;<br>
}<br>
</i><i><br>
 </i>
<hr width="100%" size="9"><br>
 I think it's not difficult to implement similar feature in LON-CAPA Construction 
Space area. <br>
<br>
I think that the first thing to do it's add the Unzip button in the<b> publisher.html </b> 
file of the LON-CAPA sources. Am I right?<br>
 <br>
 Ricardo L. Kulzer<br>
 <br>
 <br>
 <br>
 <br>
<br>
<br>
 <br>
 Gerd Kortemeyer escreveu:<br>
 
<blockquote type="cite"
 cite="mid4709A4D6-E4C7-11D7-8BC6-00039344B636@lite.msu.edu">Ricardo, <br>
  <br>
 Thank you very much for your input. There is actually a bug report  regarding 
ZIP files, see <br>
  <br>
  <a class="moz-txt-link-freetext"
 href="http://bugs.lon-capa.org/show_bug.cgi?id=659">http://bugs.lon-capa.org/show_bug.cgi?id=659</a>
  <br>
  <br>
 I have changed the milestone on that enhancement request to "1.1" - I  had 
similar experiences trying to teach faculty about having to upload  ALL files 
associated with an HTML file. <br>
  <br>
 If you open an account on Bugzilla, you can put yourself on the cc-list
 of the above bug to see what happens. <br>
  <br>
 Please let us know if you would like your machine connected to a  cluster.
   <br>
  <br>
 - Gerd. <br>
  <br>
 On Thursday, September 11, 2003, at 09:58  PM, Ricardo Luis Kulzer  wrote:
   <br>
  <br>
   
  <blockquote type="cite">    Hello.   <br>
     I’m a new user of LON-CAPA, and I don’t know many thinks about its 
code, but I’m investigating it. now.   <br>
     In our laboratory, we used another e-learning software called  TELEDUC 
(<a class="moz-txt-link-freetext"
 href="http://teleduc.nied.unicamp.br/teleduc/">http://teleduc.nied.unicamp.br/teleduc/</a>),
very good, but it  doesn't bring all the advantages offered by the LON-CAPA.
  <br>
     However, an important feature that is missing in LON-CAPA, and it  exists 
TELEDUC, is a tool that allows to do upload of several files  compacted in 
one only .ZIP file, and allow to unzip the .ZIP file in  the server later.  
  <br>
     So, when developing a page using some HTML editor like Netscape  Composer, 
we used compact the file .HTML and &lt;&lt; many &gt;&gt; images files  (.GIF, 
.JPG) in only one .ZIP file. Soon after, through the WEB  interface of TELEDUC, 
we transfer (upload) the .ZIP file in to the  TELEDUC server. Then, the WEB 
interface provides a new button that  allows unzip that file in the server 
and to publish them as a new  Content Page, with the .HTML and images files 
totally decompressed. <br>
     I tried to do the same task in LON-CAPA, but it doesn't present  this 
resource. So I needed to do upload of file by file, using the  tool Construction 
Space, and that is a annoying task (upload file by  file…). <br>
     I know that I can use SSH file transfer or Samba, but It’s  difficult 
to teach all this thinks to a Geography teacher, for  example, that usually 
don’t know and don’t like computer a lot. And  another advantage is that we
don’t need to open smb and ssh ports to  every author. He can do all this 
thinks through http server, in a much  more secure way, using the simple and
easy Construction Space tool of  LON-CAPA. <br>
     Then I would like to propose to the LON-CAPA development, to  create 
a new tool in the Construction Space area of LON-CAPA, that  allows to upload 
a .ZIP file, and automatically unzip it into the  server. Or alternatively, 
a tool that allows to upload of a whole  paste with many files at the same 
time (like select many files in  Windows Explorer using Shift key), without 
the need of currently file  by file upload tool available today in LON-CAPA. 
  <br>
     I saw in the TELEDUC code that the function responsible for unzip  the 
.ZIP file in the server after the upload is implemented in PHP.  The PHP code
is more or less like this:   <br>
   <br>
 / * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *  * 
* * *   <br>
    DescompactarArquivoZip function - Unzip compressed cribs.   <br>
    Input: $zip - path and name of the zip cribs   <br>
              $destination - destination path to unzip    <br>
    Output: true i all ok   <br>
 * /   <br>
 function DescompactarArquivoZip ($zip,$destination)   <br>
 {   <br>
   $command = " unzip -q -o \"". $zip ". \ " -d \"". $destination ".  \""; 
  <br>
   system($command,$status);   <br>
   CreateIndexFile ($destination);   <br>
   SetPermissions($destination);   <br>
   return (! $status);   <br>
 }   <br>
   <br>
     So, I think it’s not difficult to insert an equivalent function in 
LON-CAPA code, not in PHP, but in perl, the main LON-CAPA language. It  would
be enough to add a button in the Construction Space area to  allow the upload
of .ZIP files. After the upload, the system of the  LON- CAPA will be able
to automatically unzip the file in the current  work directory of Construction
Space area, or to show a new option for  the .ZIP file that allows unzip
it into the server, to be published  later.   <br>
     I await suggestions to implement this new tool. And sorry for my  poor 
English. <br>
  <br>
     Thanks, <br>
     Ricardo Luis Kulzer. <br>
    <br>
   <br>
   <br>
  <br>
   </blockquote>
  </blockquote>
<br>
 
</body>
</html>

--------------030908040402060709010907--