--- loncom/publisher/lonupload.pm 2006/04/10 22:30:31 1.32
+++ loncom/publisher/lonupload.pm 2008/11/18 19:14:40 1.40
@@ -2,7 +2,7 @@
# The LearningOnline Network with CAPA
# Handler to upload files into construction space
#
-# $Id: lonupload.pm,v 1.32 2006/04/10 22:30:31 albertel Exp $
+# $Id: lonupload.pm,v 1.40 2008/11/18 19:14:40 jms Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -28,6 +28,92 @@
#
###
+=head1 NAME
+
+Apache::lonupload - upload files into construction space
+
+=head1 SYNOPSIS
+
+Invoked by /etc/httpd/conf/srm.conf:
+
+
+ PerlAccessHandler Apache::lonacc
+ SetHandler perl-script
+ PerlHandler Apache::lonupload
+ ErrorDocument 403 /adm/login
+ ErrorDocument 404 /adm/notfound.html
+ ErrorDocument 406 /adm/unauthorized.html
+ ErrorDocument 500 /adm/errorhandler
+
+
+=head1 INTRODUCTION
+
+This module uploads a file sitting on a client computer into
+library server construction space.
+
+This is part of the LearningOnline Network with CAPA project
+described at http://www.lon-capa.org.
+
+=head1 HANDLER SUBROUTINE
+
+This routine is called by Apache and mod_perl.
+
+=over 4
+
+=item *
+
+Initialize variables
+
+=item *
+
+Start page output
+
+=item *
+
+output relevant interface phase (phaseone or phasetwo or phasethree)
+
+=item *
+
+(phase one is to specify upload file; phase two is to handle conditions
+subsequent to specification--like overwriting an existing file; phase three
+is to handle processing of secondary uploads - of embedded objects in an
+html file).
+
+=back
+
+=head1 OTHER SUBROUTINES
+
+=over
+
+=item phaseone()
+
+Interface for specifying file to upload.
+
+=item phasetwo()
+
+Interface for handling post-conditions about uploading (such
+as overwriting an existing file).
+
+=item phasethree()
+
+Interface for handling secondary uploads of embedded objects
+in an html file.
+
+=item upfile_store()
+
+Store contents of uploaded file into temporary space. Invoked
+by phaseone subroutine.
+
+=item check_extension()
+
+Checks if filename extension is permitted and checks type
+ of file - if html file, calls parser to check for embedded objects.
+ Invoked by phasetwo subroutine.
+
+=back
+
+=cut
+
package Apache::lonupload;
use strict;
@@ -41,6 +127,7 @@ use Apache::lonnet;
use HTML::Entities();
use Apache::lonlocal;
use Apache::lonnet;
+use LONCAPA();
my $DEBUG=0;
@@ -70,7 +157,6 @@ sub upfile_store {
return $datatoken;
}
-
sub phaseone {
my ($r,$fn,$uname,$udom,$mode)=@_;
my $action = '/adm/upload';
@@ -98,49 +184,44 @@ sub phaseone {
''.
''.&mt('Store uploaded file as ').
- "/priv/$uname/".
+ '" />'.&mt('Save uploaded file as ').
+ "/priv/$uname/".
' ');
- $r->print(' '.&mt('Please indicate the type of file you are uploading. The possible types of file are as follows:').'
-
-
'.&mt('Regular file:').''.&mt(' A file that requires no special handling during upload. The "Regular file" designation applies to html files, image files etc., as well as to zip, tar or gzip files that you wish to decompress after upload. In the case of a zip/tar/gz file etc., once the file has been uploaded, a "Decompress" link will automatically be displayed adjacent to the name of the file in the display of construction space directory contents. You will be able to decompress this file by clicking the link.').'
-
'.&mt('Testbank file:').''.&mt(' a testbank file containing plain text (ascii) questions and answers, which you plan to convert to LON-CAPA problems. The following question types can be converted: 1 of N multiple choice questions, individual True/False questions, groups of True/False questions, Fill-in-the-blank questions, Ranking questions, and Essay/short answer questions. Specific information about the format of the questions, foils, and correct answers is available ').''.&mt('here').','.&mt(' and is also included in the pages displayed during step-by-step conversion of the testbank. The original testbank file can be removed from your construction space later, once the testbank questions have been converted.').'
-
'.&mt('IMS package').':'.&mt(' a file containing course content from another Course Management System (e.g., Blackboard or ANGEL) packaged according to the IMS 1.1 specification. The original IMS package file can be removed from your construction space later, once the package has been decompressed and the files converted to LON-CAPA sequence, page, problem, or bulletin board files, or stored as html, image or movie files etc., as appropriate.').'
'.&mt('Or [_1]continue[_2] the testbank import without these files','','').'
';
+ }
+ }
+ }
+ if (($mode ne 'imsimport') && ($mode ne 'testbank')) {
+ $result .= ' '.
+ &mt('View file').'';
+ }
+ } else {
+ $result .= &mt('Failed to copy: [_1].',$!);
+ }
+ if ($mode ne 'imsimport' && $mode ne 'testbank') {
+ $result .= ' '.
+ &mt('Back to Directory').' ';
}
- return $returnflag;
+ return ($result,$returnflag);
+}
+
+sub phasethree {
+ my ($r,$fn,$uname,$udom,$mode) = @_;
+ my $result;
+ my $dir_root = '/home/'.$uname.'/public_html';
+ my $url_root = '/priv/'.$uname;
+ my $base = &File::Basename::basename($fn);
+ my $path = &File::Basename::dirname($fn);
+ $result = &Apache::loncommon::upload_embedded($mode,$path,$uname,$udom,
+ $dir_root,$url_root);
+ if ($mode ne 'imsimport' && $mode ne 'testbank') {
+ $result = ' '.
+ &mt('View main file').''.
+ ' '.
+ &mt('Back to Directory').' ';
+ }
+ return $result;
}
# ---------------------------------------------------------------- Main Handler
@@ -249,20 +388,6 @@ sub handler {
}
unless ($env{'form.phase'} eq 'two') {
- my %body_layout = ('rightmargin' => "0",
- 'leftmargin' => "0",
- 'marginwidth' => "0",
- 'topmargin' => "0",
- 'marginheight' => "0");
- my $start_page =
- &Apache::loncommon::start_page('Importing a Testbank file into LON-CAPA',
- undef,
- {'only_body' => 1,
- 'add_entries' => \%body_layout,
- 'js_ready' => 1,});
- my $end_page =
- &Apache::loncommon::end_page({'js_ready' => 1,});
-
$javascript = qq|
function verifyForm() {
var mode = document.fileupload.filetype.options[document.fileupload.filetype.selectedIndex].value
@@ -277,32 +402,12 @@ function verifyForm() {
}
document.fileupload.submit();
}
-
-function testbankWin() {
- newWindow = window.open("","testbankinfo","HEIGHT=400,WIDTH=750,scrollbars=yes")
- newWindow.document.open()
- newWindow.document.write('$start_page')
- newWindow.document.write("\\n")
- newWindow.document.write("
\\n")
- newWindow.document.write("
\\n")
- newWindow.document.write("
Importing Testbank questions into LON-CAPA
")
- newWindow.document.write(" Four requirements must be met to ensure that you will succeed in building LON-CAPA problem files using your plain text file containing testbank questions.")
- newWindow.document.write("
The questions and answers you upload must be in plain text format. Any header lines should occur before the text containing the questions and answers.
")
- newWindow.document.write("
All questions must occur before any of the answers. Each question should be numbered sequentially using a number followed immediately by a space, a period, or enclosed in parentheses, i.e., 1 , 1., (1), 1), or (1 .
")
- newWindow.document.write("
One or more correct answers should be provided for all questions (although blank answers may be provided for essay questions). Answers should be numbered sequentially, using the same scheme as used for the questions, and must occur after all the questions.")
- newWindow.document.write("
Multiple choice and multiple answer correct questions should consist of (i) the question number followed by (ii) a question stem beginning on the same line and (iii) two or more foils, with each foil beginning on a new line and prefixed by a unique letter, or Roman numeral, listed in alphabetic or numeric order, beginning at a (alphabetic) or i (Roman numeral), followed by a period, or enclosed in parentheses, i.e., a., (a), i., or (i) .
")
- newWindow.document.write("
If fill-in-the-blank or multiple answer questions have more than one correct answer, each answer should appear in a comma-, tab-, space-, or new line-delimited list.
")
- newWindow.document.write("
\\n")
- newWindow.document.write("
")
- newWindow.document.write('$end_page')
- newWindow.document.close()
- newWindow.focus()
-}
-|;
+ |;
}
($uname,$udom)=
&Apache::loncacc::constructaccess($env{'form.filename'},
$r->dir_config('lonDefDomain'));
+
unless (($uname) && ($udom)) {
$r->log_reason($uname.' at '.$udom.
' trying to publish file '.$env{'form.filename'}.
@@ -316,7 +421,7 @@ function testbankWin() {
$fn=$env{'form.filename'};
$fn=~s/^http\:\/\/[^\/]+\///;
$fn=~s/^\///;
- $fn=~s/(\~|priv\/)(\w+)//;
+ $fn=~s{(~|priv/)($LONCAPA::username_re)}{};
$fn=~s/\/+/\//g;
} else {
$r->log_reason($env{'user.name'}.' at '.$env{'user.domain'}.
@@ -337,12 +442,16 @@ function testbankWin() {
$javascript));
if (($uname ne $env{'user.name'}) || ($udom ne $env{'user.domain'})) {
- $r->print('
'.&mt('Co-Author').': '.$uname.
- &mt(' at ').$udom.'
');
+ $r->print('
'.&mt('Co-Author').': '.$uname.
+ &mt(' at ').$udom.'
');
}
- if ($env{'form.phase'} eq 'two') {
- &phasetwo($r,$fn,$uname,$udom);
+ if ($env{'form.phase'} eq 'three') {
+ my $output = &phasethree($r,$fn,$uname,$udom,'author');
+ $r->print($output);
+ } elsif ($env{'form.phase'} eq 'two') {
+ my ($output,$returnflag) = &phasetwo($r,$fn,$uname,$udom);
+ $r->print($output);
} else {
&phaseone($r,$fn,$uname,$udom);
}
@@ -354,75 +463,4 @@ function testbankWin() {
1;
__END__
-=head1 NAME
-
-Apache::lonupload - upload files into construction space
-=head1 SYNOPSIS
-
-Invoked by /etc/httpd/conf/srm.conf:
-
-
- PerlAccessHandler Apache::lonacc
- SetHandler perl-script
- PerlHandler Apache::lonupload
- ErrorDocument 403 /adm/login
- ErrorDocument 404 /adm/notfound.html
- ErrorDocument 406 /adm/unauthorized.html
- ErrorDocument 500 /adm/errorhandler
-
-
-=head1 INTRODUCTION
-
-This module uploads a file sitting on a client computer into
-library server construction space.
-
-This is part of the LearningOnline Network with CAPA project
-described at http://www.lon-capa.org.
-
-=head1 HANDLER SUBROUTINE
-
-This routine is called by Apache and mod_perl.
-
-=over 4
-
-=item *
-
-Initialize variables
-
-=item *
-
-Start page output
-
-=item *
-
-output relevant interface phase (phaseone or phasetwo)
-
-=item *
-
-(phase one is to specify upload file; phase two is to handle conditions
-subsequent to specification--like overwriting an existing file)
-
-=back
-
-=head1 OTHER SUBROUTINES
-
-=over 4
-
-=item *
-
-phaseone() : Interface for specifying file to upload.
-
-=item *
-
-phasetwo() : Interface for handling post-conditions about uploading (such
-as overwriting an existing file).
-
-=item *
-
-upfile_store() : Store contents of uploaded file into temporary space. Invoked
-by phaseone subroutine.
-
-=back
-
-=cut