--- loncom/interface/londocs.pm 2005/04/07 06:56:23 1.174
+++ loncom/interface/londocs.pm 2005/06/11 13:38:47 1.188
@@ -1,7 +1,7 @@
# The LearningOnline Network
# Documents
#
-# $Id: londocs.pm,v 1.174 2005/04/07 06:56:23 albertel Exp $
+# $Id: londocs.pm,v 1.188 2005/06/11 13:38:47 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -272,22 +272,8 @@ sub exportcourse {
&Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
['archive','discussion']);
- my @exportitems = ();
- if (defined($env{'form.archive'})) {
- if (ref($env{'form.archive'}) eq 'ARRAY') {
- @exportitems = @{$env{'form.archive'}};
- } else {
- $exportitems[0] = $env{'form.archive'};
- }
- }
- my @discussions = ();
- if (defined($env{'form.discussion'})) {
- if (ref($env{'form.discussion'}) eq 'ARRAY') {
- @discussions = $env{'form.discussion'};
- } else {
- $discussions[0] = $env{'form.discussion'};
- }
- }
+ my @exportitems = &Apache::loncommon::get_env_multiple('form.archive');
+ my @discussions = &Apache::loncommon::get_env_multiple('form.discussion');
if (@exportitems == 0 && @discussions == 0) {
$outcome = '
As you did not select any content items or discussions for export, an IMS package has not been created. Please go back to select either content items or discussions for export';
} else {
@@ -693,7 +679,7 @@ sub process_content {
if ($contents) {
$$content_file = &store_template($contents,$tempexport,$count,$content_type);
}
- } elsif ($symb =~ m-lib/templates/examupload\.problem-m) {
+ } elsif ($symb =~ m-lib/templates/examupload\.problem$-) {
$content_type = 'examupload';
} elsif ($symb =~ m-adm/(\w+)/(\w+)/(\d+)/bulletinboard$-) {
$content_type = 'bulletinboard';
@@ -866,7 +852,7 @@ sub group_import {
}
}
if ($url) {
- my $idx = $#Apache::lonratedt::resources + 1;
+ my $idx = &Apache::lonratedt::getresidx($url);
$Apache::lonratedt::order[$#Apache::lonratedt::order+1]=$idx;
my $ext = 'false';
if ($url=~/^http:\/\//) { $ext = 'true'; }
@@ -918,7 +904,7 @@ sub breadcrumbs {
}
sub editor {
- my ($r,$coursenum,$coursedom,$folder,$allowed)=@_;
+ my ($r,$coursenum,$coursedom,$folder,$allowed,$upload_output)=@_;
my $errtext='';
my $fatal=0;
my $container='sequence';
@@ -928,8 +914,10 @@ sub editor {
($errtext,$fatal)=
&mapread($coursenum,$coursedom,$folder.'.'.$container);
if ($#Apache::lonratedt::order<1) {
- $Apache::lonratedt::order[0]=1;
- $Apache::lonratedt::resources[1]='';
+ my $idx=&Apache::lonratedt::getresidx();
+ if ($idx<=0) { $idx=1; }
+ $Apache::lonratedt::order[0]=$idx;
+ $Apache::lonratedt::resources[$idx]='';
}
if (defined($env{'form.markcopy'})) {
# Mark for copying
@@ -1032,7 +1020,7 @@ sub editor {
if ($url=~/^http\:\/\//) { $ext='true'; }
$url=~s/\:/\:/g;
# Now insert the URL at the bottom
- my $newidx=1+$#Apache::lonratedt::resources;
+ my $newidx=&Apache::lonratedt::getresidx($url);
$Apache::lonratedt::resources[$newidx]=
$title.':'.$url.':'.$ext.':normal:res';
$Apache::lonratedt::order[1+$#Apache::lonratedt::order]=$newidx;
@@ -1044,43 +1032,16 @@ sub editor {
}
}
-# upload a file, if present
- if (($env{'form.uploaddoc.filename'}) &&
- ($env{'form.cmd'}=~/^upload_(\w+)/)) {
- if ( ($folder=~/^$1/) || ($1 eq 'default') ) {
-# this is for a course, not a user, so set coursedoc flag
-# probably the only place in the system where this should be "1"
- my $newidx=$#Apache::lonratedt::resources+1;
- my $url=&Apache::lonnet::userfileupload('uploaddoc',1,'docs/'.$newidx);
- my $ext='false';
- if ($url=~/^http\:\/\//) { $ext='true'; }
- $url=~s/\:/\:/g;
- my $comment=$env{'form.comment'};
- $comment=~s/\\<\;/g;
- $comment=~s/\>/\>\;/g;
- $comment=~s/\:/\:/g;
- if ($folder=~/^supplemental/) {
- $comment=time.'___&&&___'.$env{'user.name'}.'___&&&___'.
- $env{'user.domain'}.'___&&&___'.$comment;
- }
- $Apache::lonratedt::resources[$newidx]=
- $comment.':'.$url.':'.$ext.':normal:res';
- $Apache::lonratedt::order[$#Apache::lonratedt::order+1]=
- $newidx;
-
- ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container);
- if ($fatal) {
- $r->print('
'.$errtext.'
'); - return; - } - } - } + $r->print($upload_output); if ($env{'form.cmd'}) { my ($cmd,$idx)=split(/\_/,$env{'form.cmd'}); if ($cmd eq 'del') { my (undef,$url)=split(':',$Apache::lonratedt::resources[$Apache::lonratedt::order[$idx]]); - if ($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) { + if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) && + ($url!~/\.(page|sequence|problem|exam|quiz|assess|survey|form|library)$/)) { &Apache::lonnet::removeuploadedurl($url); + } else { + &Apache::lonratedt::makezombie($Apache::lonratedt::order[$idx]); } for (my $i=$idx;$i<$#Apache::lonratedt::order;$i++) { $Apache::lonratedt::order[$i]= @@ -1089,6 +1050,7 @@ sub editor { $#Apache::lonratedt::order--; } elsif ($cmd eq 'cut') { my (undef,$url)=split(':',$Apache::lonratedt::resources[$Apache::lonratedt::order[$idx]]); + &Apache::lonratedt::makezombie($Apache::lonratedt::order[$idx]); for (my $i=$idx;$i<$#Apache::lonratedt::order;$i++) { $Apache::lonratedt::order[$i]= $Apache::lonratedt::order[$i+1]; @@ -1154,8 +1116,8 @@ sub editor { # Loading a complete map if (($env{'form.importmap'}) && ($env{'form.loadmap'})) { foreach (&Apache::lonsequence::attemptread(&Apache::lonnet::filelocation('',$env{'form.importmap'}))) { - my $idx=$#Apache::lonratedt::resources; - $idx++; + my ($title,$url,$ext,$type)=split(/\:/,$_); + my $idx=&Apache::lonratedt::getresidx($url); $Apache::lonratedt::resources[$idx]=$_; $Apache::lonratedt::order [$#Apache::lonratedt::order+1]=$idx; @@ -1213,6 +1175,127 @@ FOLDERINFO } } +sub process_file_upload { + my ($upload_output,$coursenum,$coursedom,$allfiles,$codebase) = @_; +# upload a file, if present + my $parseaction; + if ($env{'form.parserflag'}) { + $parseaction = 'parse'; + } + my $phase_status; + my $folder=$env{'form.folder'}; + if ($folder eq '' || $folder eq 'supplemental') { + $folder='default'; + } + if ( ($folder=~/^$1/) || ($1 eq 'default') ) { + my $errtext=''; + my $fatal=0; + my $container='sequence'; + if ($env{'form.pagepath'}) { + $container='page'; + } + ($errtext,$fatal)= + &mapread($coursenum,$coursedom,$folder.'.'.$container); + if ($#Apache::lonratedt::order<1) { + $Apache::lonratedt::order[0]=1; + $Apache::lonratedt::resources[1]=''; + } + if ($fatal) { + return 'failed'; + } + my $destination = 'docs/'; + if ($folder eq 'default') { + $destination .= 'default/'; + } elsif ($folder =~ /^default_(\d+)$/) { + $destination .= $1.'/'; + } +# this is for a course, not a user, so set coursedoc flag +# probably the only place in the system where this should be "1" + my $newidx=&Apache::lonratedt::getresidx(); + $destination .= $newidx; + my $url=&Apache::lonnet::userfileupload('uploaddoc',1,$destination,$parseaction,$allfiles,$codebase); + my $ext='false'; + if ($url=~/^http\:\/\//) { $ext='true'; } + $url=~s/\:/\:/g; + my $comment=$env{'form.comment'}; + $comment=~s/\\<\;/g; + $comment=~s/\>/\>\;/g; + $comment=~s/\:/\:/g; + if ($folder=~/^supplemental/) { + $comment=time.'___&&&___'.$env{'user.name'}.'___&&&___'. + $env{'user.domain'}.'___&&&___'.$comment; + } + + $Apache::lonratedt::resources[$newidx]= + $comment.':'.$url.':'.$ext.':normal:res'; + $Apache::lonratedt::order[$#Apache::lonratedt::order+1]= + $newidx; + ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container); + if ($fatal) { + $$upload_output .= ''.$errtext.'
'; + return 'failed'; + } else { + if ($parseaction eq 'parse') { + my $total_embedded = keys %{$allfiles}; + if ($total_embedded > 0) { + my $num = 0; + $$upload_output .= 'This file contains embedded multimedia objects, which need to be uploaded to LON-CAPA.'. &mt('It is recommended that you use an up-to-date virus scanner before handling this file.')."