--- loncom/imspackages/imsimportdocs.pm 2004/03/09 16:34:34 1.2 +++ loncom/imspackages/imsimportdocs.pm 2012/10/31 12:54:17 1.30 @@ -1,3 +1,30 @@ +# The LearningOnline Network with CAPA +# +# $Id: imsimportdocs.pm,v 1.30 2012/10/31 12:54:17 raeburn Exp $ +# +# 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); @@ -6,58 +33,48 @@ use Apache::londocs; use Apache::loncommon; use Apache::lonlocal; use Apache::imsprocessor; -use LONCAPA::Configuration; +use LONCAPA::map(); +use lib '/home/httpd/lib/perl/'; +use LONCAPA; + use strict; sub jscript_one { - my $javascript = shift; - $$javascript = qq# -function verify() { - if ((document.forms.pickcms.uploadname.value == '') || (!document.forms.pickcms.uploadname.value)) { - alert("You must provide the name of the IMS package to be imported") - return false - } - if (document.forms.pickcms.source.selectedIndex == 0) { - alert("You must choose the Course Management System from which the IMS package was exported"); - return false - } - return true -} - -function nextPage() { - if (verify()) { - document.forms.pickcms.submit() - } -} -#; - -} - -sub jscript_two { - my $javascript = shift; - $$javascript = qq# + my %lt = &Apache::lonlocal::texthash( + se => 'Select', + to => 'Import topics only', + tp => 'Import topics + posts (with author)', + tn => 'Import topics + posts (no author)', + es => 'Enroll students only', + ea => 'Enroll all users', + nr => 'Not required', + id => 'You must select one of the additional options when importing Disussion Boards', + ie => 'You must select one of the additional options when importing Enrollment', + ct => 'You must check at least one Content Type', + ); + return <<"ENDJS"; function setOptions(caller,itemnum) { var opForm = document.forms.pickoptions var menu = 1 + itemnum*2 opForm.elements[menu].length = 0 if (opForm.elements[itemnum*2].checked == true) { 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[0] = new Option("$lt{'se'}","-1",true,true) + opForm.elements[menu].options[1] = new Option("$lt{'to'}","topics",true,true) + opForm.elements[menu].options[2] = new Option("$lt{'tp'}","allpost",true,true) + opForm.elements[menu].options[3] = new Option("$lt{'tn'}","allanon",true,true) } else { if (caller == "users") { opForm.elements[menu].length = 0 - opForm.elements[menu].options[0] = new Option("Select","-1",true,true) - opForm.elements[menu].options[1] = new Option("Enroll students only","students",true,true) - opForm.elements[menu].options[2] = new Option("Enroll all users","all",true,true) + opForm.elements[menu].options[0] = new Option("$lt{'se'}","-1",true,true) + opForm.elements[menu].options[1] = new Option("$lt{'es'}","students",true,true) + opForm.elements[menu].options[2] = new Option("$lt{'ea'}","all",true,true) } } } else { - opForm.elements[menu].options[0] = new Option("Not required","0",true,true) + opForm.elements[menu].options[0] = new Option("$lt{'nr'}","0",true,true) } opForm.elements[menu].selectedIndex = 0 } @@ -70,20 +87,20 @@ function verify(caller) { totcheck ++ if (opForm.elements[2*i].name == "board") { if (opForm.elements[2*i+1].selectedIndex == 0) { - alert("You must select one of the additional options when importing Discussion Boards ") + alert("$lt{'id'}") return false } } if (opForm.elements[2*i].name == "users") { if (opForm.elements[2*i+1].selectedIndex == 0) { - alert("You must select one of the additional options when importing Enrollment") + alert("$lt{'ie'}") return false } } } } if (totcheck == 0) { - alert("You must check the Checkbox for at least one Content Type"); + alert("$lt{'ct'}"); return false } return true @@ -94,245 +111,105 @@ function nextPage(caller) { document.forms.pickoptions.submit() } } -#; + +ENDJS + } -sub jscript_three { - my $javascript = shift; - $$javascript = qq| +sub jscript_two { + return <<"ENDJS"; function init(tf) { setTimeout("self.close()",3000) tf.submit(); } - |; + +ENDJS } sub handler { my $r = shift; - my $javascript = ''; &Apache::loncommon::content_type($r,'text/html'); $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'}; - my $coursedom=$ENV{'course.'.$ENV{'request.course.id'}.'.domain'}; - my $coursehome=$ENV{'course.'.$ENV{'request.course.id'}.'.home'}; + my $coursenum=$env{'course.'.$env{'request.course.id'}.'.num'}; + my $coursedom=$env{'course.'.$env{'request.course.id'}.'.domain'}; # get personal data - my $uname=$ENV{'user.name'}; - my $udom=$ENV{'user.domain'}; - my $plainname=&Apache::lonnet::escape( + my $uname=$env{'user.name'}; + my $udom=$env{'user.domain'}; + my $plainname=&escape( &Apache::loncommon::plainname($uname,$udom)); # does this user have privileges to post, etc? - my $allowed=&Apache::lonnet::allowed('mdc',$ENV{'request.course.id'}); + my $allowed=&Apache::lonnet::allowed('mdc',$env{'request.course.id'}); unless ($allowed) { - $r->print("