--- loncom/imspackages/imsimportdocs.pm 2004/03/09 16:34:34 1.2 +++ loncom/imspackages/imsimportdocs.pm 2005/02/16 20:24:15 1.10 @@ -1,3 +1,26 @@ +# Copyright Michigan State University Board of Trustees +# +# This file is part of the LearningOnline Network with CAPA (LON-CAPA). +# +# LON-CAPA is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# LON-CAPA is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with LON-CAPA; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# /home/httpd/html/adm/gpl.txt +# +# http://www.lon-capa.org/ +# + package Apache::imsimportdocs; use Apache::Constants qw(:common :http :methods); @@ -44,8 +67,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 +137,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'}; @@ -154,7 +158,7 @@ sub handler { my $allowed=&Apache::lonnet::allowed('mdc',$ENV{'request.course.id'}); unless ($allowed) { $r->print("The LearningOnline Network with CAPA"); - $r->print(&Apache::loncommon::bodytag('Import IMS package')); + $r->print(&Apache::loncommon::bodytag('Import IMS package',undef,'',1)); $r->print('

'.&mt('Modification of Course Contents Disallowed').'

'.&mt('Your current role does not grant you the right to modify course content in this course.').''); return OK; } @@ -183,11 +187,11 @@ $javascript ENDHEAD # -------------------------------------------------------------------- Body tag - $r->print(&Apache::loncommon::bodytag('Import IMS package')); + $r->print(&Apache::loncommon::bodytag('Import IMS package',undef,'',1)); 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 +199,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) = @_; @@ -250,6 +233,7 @@ Please choose the CMS used to create you @@ -313,18 +297,20 @@ 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 '') { $unzip_result = &Apache::imsprocessor::expand_zip($tempdir,$fname); } my %resources = (); + my %includedres = (); + my %includeditems = (); my %items = (); my %hrefs = (); my %resinfo = (); @@ -346,23 +332,11 @@ 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); + $manifest_result = &Apache::imsprocessor::process_manifest($cms,$tempdir,\%resources,\%items,\%hrefs,\%resinfo,'choose',\%includedres,\%includeditems); if ($manifest_result eq 'ok') { foreach my $res (sort keys %resources) { - if ($cms eq 'bb5') { + if ($cms eq 'bb5' || $cms eq 'bb6') { foreach my $area (keys %{$cmsmap{$cms}}) { if ($resources{$res}{type} eq $cmsmap{$cms}{$area}) { $count{$area} ++; @@ -425,7 +399,7 @@ ENDBLOCK $r->print(qq|onClick='javascript:setOptions("$area","$counter")'|); } $r->print("/> -   $areaname{$area}   - $count{$area} item(s)"); +   $$areaname{$area}   - $count{$area} item(s)"); if ($area eq 'board') { $r->print("    |; - $initblock .= &mt('or the next time you log in.'); + $initblock .= ', '.&mt('or the next time you log in.'); $initblock .= qq||; $r->print($initblock); $r->print(<