--- loncom/imspackages/imsimportdocs.pm 2004/03/09 16:34:34 1.2 +++ loncom/imspackages/imsimportdocs.pm 2004/04/08 09:19:39 1.6 @@ -44,8 +44,8 @@ function setOptions(caller,itemnum) { if (caller == "board") { opForm.elements[menu].options[0] = new Option("Select","-1",true,true) opForm.elements[menu].options[1] = new Option("Import topics only","topics",true,true) - opForm.elements[menu].options[2] = new Option("Import topics & posts (with author)","allpost",true,true) - opForm.elements[menu].options[3] = new Option("Import topics & posts (no author)","allanon",true,true) + opForm.elements[menu].options[2] = new Option("Import topics + posts (with author)","allpost",true,true) + opForm.elements[menu].options[3] = new Option("Import topics + posts (no author)","allanon",true,true) } else { if (caller == "users") { @@ -114,29 +114,10 @@ sub handler { $r->send_http_header; return OK if $r->header_only; - my @areas = ("doc","extlink","announce","staff","board","quiz","survey","pool","users"); + my @areas = (); my %cmsmap = (); - %{$cmsmap{bb5}} = ( - announce => 'resource/x-bb-announcement', - board => 'resource/x-bb-discussionboard', - doc => 'resource/x-bb-document', - extlink => 'resource/x-bb-externallink', - pool => 'assessment/x-bb-pool', - quiz => 'assessment/x-bb-quiz', - staff => 'resource/x-bb-staffinfo', - survey => 'assessment/x-bb-survey', - users => 'course/x-bb-user', - ); - - %{$cmsmap{angel}} = ( - board => 'BOARD', - extlink => 'LINK', - msg => 'MESSAGE', - quiz => 'QUIZ', - survey => 'FORM', - ); - - @{$cmsmap{angel}{doc}} = ('FILE','PAGE'); + my %areaname = (); + &Apache::imsprocessor::ims_config(\@areas,\%cmsmap,\%areaname); # get course data my $coursenum=$ENV{'course.'.$ENV{'request.course.id'}.'.num'}; @@ -187,7 +168,7 @@ ENDHEAD if ($ENV{'form.phase'} eq 'one') { &display_one($r); } elsif ($ENV{'form.phase'} eq 'two') { - &display_two($r,$coursenum,\@areas,%cmsmap); + &display_two($r,$coursenum,\@areas,\%areaname,%cmsmap); } elsif ($ENV{'form.phase'} eq 'three') { &display_three($r,$coursenum,$coursedom,$coursehome,$uname,$udom,\@areas,%cmsmap); } @@ -195,27 +176,6 @@ ENDHEAD return OK; } -sub uploadzip { - my $tempdir = shift; - my $fname=$ENV{'form.uploadname.filename'}; -# Replace Windows backslashes by forward slashes - $fname=~s/\\/\//g; -# Get rid of everything but the actual filename - $fname=~s/^.*\/([^\/]+)$/$1/; -# Replace spaces by underscores - $fname=~s/\s+/\_/g; -# Replace all other weird characters by nothing - $fname=~s/[^\w\.\-]//g; -# See if there is anything left - unless ($fname) { return 'error: no uploaded file'; } - -# Save the file - chomp($ENV{'form.uploadname'}); - open(my $fh,'>'.$tempdir.'/'.$fname); - print $fh $ENV{'form.uploadname'}; - close($fh); - return $fname; -} sub display_one { my ($r) = @_; @@ -313,12 +273,12 @@ ENDBLOCK sub display_two { - my ($r,$crs,$areasref,%cmsmap) = @_; + my ($r,$crs,$areasref,$areaname,%cmsmap) = @_; &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['folder','source']); my $cms = $ENV{'form.source'}; my $timenow = time; my $tempdir = &Apache::imsprocessor::create_tempdir('DOCS',$crs,$timenow); - my $fname = &uploadzip($tempdir); + my $fname = &Apache::imsprocessor::uploadzip('DOCS',$tempdir); my $unzip_result = ''; my $manifest_result = ''; unless ($tempdir eq '') { @@ -346,18 +306,6 @@ sub display_two { users => 0, ); - my %areaname = ( - announce => 'Announcements', - board => 'Discussion Boards', - doc => 'Documents, pages & folders', - extlink => 'Links to external sites', - pool => 'Question pools', - quiz => 'Quizzes', - staff => 'Staff information', - survey => 'Surveys', - users => 'Enrollment', - ); - if ($unzip_result eq 'ok') { $manifest_result = &Apache::imsprocessor::process_manifest($cms,$tempdir,\%resources,\%items,\%hrefs,\%resinfo); if ($manifest_result eq 'ok') { @@ -425,7 +373,7 @@ ENDBLOCK $r->print(qq|onClick='javascript:setOptions("$area","$counter")'|); } $r->print("/></font></td> - <td align='left'><font face='arial,helvetica,sans-serif'> $areaname{$area} - $count{$area} item(s)</font></td>"); + <td align='left'><font face='arial,helvetica,sans-serif'> $$areaname{$area} - $count{$area} item(s)</font></td>"); if ($area eq 'board') { $r->print(" <td align='left'><font face='arial,helvetica,sans-serif'> <select name='db_handling'> @@ -557,7 +505,6 @@ sub display_three { my $timenow = time; my $destdir = $Apache::lonnet::perlvar{'lonDocRoot'}.'/userfiles/'.$cdom.'/'.$crs.'/'.$timenow; - my $dirname = $cdom.'/'.$crs.'/'.$timenow; my $seqstem = "/uploaded/$cdom/$crs/$timenow"; my $db_handling = ''; my $user_handling = ''; @@ -591,6 +538,20 @@ sub display_three { my $manifest_result = &Apache::imsprocessor::process_manifest($cms,$tempdir,\%resources,\%items,\%hrefs,\%resinfo); if ($manifest_result eq 'ok') { + my @path = ($cdom,$crs,$timenow); + my $fullpath = $Apache::lonnet::perlvar{'lonDocRoot'}.'/userfiles'; + foreach my $item (@path) { + $fullpath .= '/'.$item; + if (!-e "$fullpath") { + mkdir("$fullpath",0770); + } + } + my @namedirs = ("resfiles","sequences","pages","problems"); + foreach my $name (@namedirs) { + if (!-e "$fullpath/$name") { + mkdir("$fullpath/$name",0770); + } + } &Apache::imsprocessor::target_resources(\%resources,\%imports,\@targets); my $copy_result = &Apache::imsprocessor::copy_resources('DOCS',$cms,\%hrefs,$tempdir,\@targets,\%urls,$crs,$cdom,$chome,$destdir,$timenow); @@ -605,23 +566,23 @@ sub display_three { my @topurls = (); my @topnames = (); - &Apache::imsprocessor::process_resinfo($cms,$tempdir,$destdir,\%items,\%resources,\@boards,\@announcements,\@quizzes,\@surveys,\@groups,\%messages,\@timestamp,\%boardnum,\%resinfo,$udom,$uname,$cdom,$crs,$db_handling,$user_handling,\%total,$dirname,$seqstem,\@resrcfiles); + &Apache::imsprocessor::process_resinfo($cms,'DOCS',$tempdir,$destdir,\%items,\%resources,\@boards,\@announcements,\@quizzes,\@surveys,\@groups,\%messages,\@timestamp,\%boardnum,\%resinfo,$udom,$uname,$cdom,$crs,$db_handling,$user_handling,\%total,$seqstem,$seqstem,\@resrcfiles); - &Apache::imsprocessor::build_structure($cms,'DOCS',$destdir,\%resinfo,\%items,\%resources,\%hrefs,$udom,$uname,'',$timenow,$cdom,$crs,\@timestamp,\%total,\@boards,\@announcements,\@quizzes,\@surveys,\%boardnum,\@pages,\@sequences,\@topurls,\@topnames); + &Apache::imsprocessor::build_structure($cms,'DOCS',$destdir,\%items,\%resinfo,\%resources,\%hrefs,$udom,$uname,'',$timenow,$cdom,$crs,\@timestamp,\%total,\@boards,\@announcements,\@quizzes,\@surveys,\%boardnum,\@pages,\@sequences,\@topurls,\@topnames); foreach my $item (@pages) { - my $path = $timenow.'/pages/'; - ©_items($item,$path,$cdom,$chome,$crs); + my $filename = $timenow.'/pages/'.$item; + my $fetchresult= &Apache::lonnet::process_coursefile('propagate',$crs,$cdom,$chome,$filename,''); } foreach my $item (@sequences) { unless ($item eq 'Top.sequence' && $toplevel eq 'oldfolder') { - my $path = $timenow.'/sequences/'; - ©_items($item,$path,$cdom,$chome,$crs); + my $filename = $timenow.'/sequences/'.$item; + my $fetchresult= &Apache::lonnet::process_coursefile('propagate',$crs,$cdom,$chome,$filename,''); } } foreach my $item (@resrcfiles) { - my $path = $timenow.'/resfiles/'; - ©_items($item,$path,$cdom,$chome,$crs); + my $filename = $timenow.'/resfiles/'.$item; + my $fetchresult= &Apache::lonnet::process_coursefile('propagate',$crs,$cdom,$chome,$filename,''); } my @imports = (); @@ -648,6 +609,9 @@ sub display_three { print STDERR "Fatal error during group_import\n"; } } + if ($tempdir =~ m/^\/home\/httpd\/perl\/tmp\/$crs\/\d{10}/) { + system("rm -r -f $tempdir"); + } $r->print(<<ENDBLOCK); <table border='0' bgcolor='#F6F6F6'' cellspacing='0' cellpadding ='0' width='100%'> <tr> @@ -691,10 +655,5 @@ ENDBLOCK ENDBLOCKTWO } -sub copy_items { - my ($filename,$fpath,$cdom,$chome,$crs) = @_; - my $fetchresult= &Apache::lonnet::reply('fetchuserfile:'.$cdom.'/'.$crs.'/'.$filename.':'.$fpath,$chome); -} - 1; __END__