--- loncom/imspackages/imsimport.pm 2004/04/08 09:19:39 1.6 +++ loncom/imspackages/imsimport.pm 2014/12/11 01:07:38 1.46 @@ -1,29 +1,78 @@ +# The LearningOnline Network with CAPA +# +# $Id: imsimport.pm,v 1.46 2014/12/11 01:07:38 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::imsimport; use strict; use Apache::Constants qw(:common :http :methods); -use Apache::loncacc; use Apache::loncommon(); -use Apache::Log(); use Apache::lonnet; use Apache::imsprocessor; +use Apache::lonlocal; use HTML::Parser; use HTML::Entities(); use Apache::lonlocal; use Apache::lonupload; use File::Basename(); - +use LONCAPA; + # ---------------------------------------------------------------- Jscript One sub jscript_one { - my ($fullpath,$jsref) = @_; - $$jsref = <<"END_OF_ONE"; + my ($fullpath,$formname) = @_; + + my %body_layout = ('rightmargin' => "0", + 'leftmargin' => "0", + 'marginwidth' => "0", + 'topmargin' => "0", + 'marginheight' => "0"); + my $start_page = + &Apache::loncommon::start_page('Create IMS import directory',undef, + {'only_body' => 1, + 'add_entries' => \%body_layout, + 'js_ready' => 1,}); + my $end_page = + &Apache::loncommon::end_page({'js_ready' => 1,}); + + my %lt = &Apache::lonlocal::texthash( + ddir => 'You must choose a destination directory for the import', + cmss => 'You must choose the Course Management System from which the IMS package was exported', + loca => 'Location:', + newd => 'New Directory', + nndi => 'Enter the name of the new directory where you will store the contents of your IMS package.', + go => 'Go', + ); + return <<"END_OF_ONE"; function verify() { - if ((document.forms.dataForm.newdir.value == '') || (!document.forms.dataForm.newdir.value)) { - alert("You must choose a destination directory for the import") + if ((document.forms.$formname.newdir.value == '') || (!document.forms.$formname.newdir.value)) { + alert('$lt{'ddir'}') return false } - if (document.forms.dataForm.source.selectedIndex == 0) { - alert("You must choose the Course Management System from which the IMS package was exported"); + if (document.forms.$formname.source.selectedIndex == 0) { + alert('$lt{'cmss'}'); return false } return true @@ -31,30 +80,30 @@ function verify() { function nextPage() { if (verify()) { - document.forms.dataForm.submit() + document.forms.$formname.submit(); } } function createWin() { - document.dataForm.newdir.value = ""; + document.$formname.newdir.value = ""; newWindow = window.open("","CreateDir","HEIGHT=400,WIDTH=750,scrollbars=yes") newWindow.document.open() - newWindow.document.write("Create IMS import directory\\n") - newWindow.document.write("\\n") - newWindow.document.write("[Author Header]\\n") - newWindow.document.write("\\n") + newWindow.document.write('$start_page') + newWindow.document.write("\\n[Author Header]\\n") + newWindow.document.write("
\\n") newWindow.document.write("\\n") - newWindow.document.write("\\n") + newWindow.document.write("\\n") newWindow.document.write("\\n") newWindow.document.write("\\n") - newWindow.document.write("
  

Location: $fullpath

New Directory

$lt{'loca'} $fullpath

$lt{'newd'}

  
\\n") - newWindow.document.write("Enter the name of the new directory where you will store the contents of your IMS package.

") - newWindow.document.write("") - newWindow.document.write("") - newWindow.document.write("") - newWindow.document.write("$fullpath") - newWindow.document.write("") + newWindow.document.write("$lt{'nndi'}

") + newWindow.document.write("") + newWindow.document.write("") + newWindow.document.write("") + newWindow.document.write("$fullpath") + newWindow.document.write("") newWindow.document.write("
") + newWindow.document.write("") + newWindow.document.write('$end_page') newWindow.document.close() newWindow.focus() } @@ -65,7 +114,7 @@ END_OF_ONE # ---------------------------------------------------------------- Jscript Two sub jscript_two { - my ($javascript,$user,$dom,$numcrs) = @_; + my ($user,$dom,$numcrs) = @_; my %crsentry = (); my $course_list; my $title_list; @@ -84,7 +133,21 @@ sub jscript_two { $course_list = '"'.join('","',@crslist).'"'; $$numcrs = @crslist; - $$javascript = qq# + my %lt = &Apache::lonlocal::texthash( + sel => 'Please select', + impto => 'Import topics only', + imptpa => 'Import topics + posts (with author)', + imptpn => 'Import topics + posts (no author)', + enrst => 'Enroll students only', + enrall => 'Enroll all users', + notreq => 'Not required', + errao => 'You must select one of the additional options when importing Discussion Boards.', + errtd => 'You must select a target course when importing Discussion Boards.', + errap => 'You must select one of the additional options when importing Enrollment.', + errte => 'You must select a target course when importing enrollment information.', + errcc => 'You must check at least one Content Type.', + ); + return <<"END_OF_TWO"; function checkCourse() { courseID_array = new Array($course_list) @@ -132,7 +195,7 @@ function setCourse(step2Form,call) { step2Form.targetcourse.length = 0 if (call == 'add') { step2Form.targetcourse.length = 0 - step2Form.targetcourse.options[0] = new Option("Please Select","0",true,true) + step2Form.targetcourse.options[0] = new Option("$lt{'sel'}","0",true,true) for (var i=0; i 0) { @@ -185,7 +248,7 @@ 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{'errao'}") return false } if (numCrs == 0) { @@ -194,14 +257,14 @@ function verify(caller) { } else { if (opForm.targetcourse.selectedIndex == 0) { - alert("You must select a target course when importing Discussion Boards") + alert("$lt{'errtd'}") 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{'errap'}") return false } if (numCrs == 0) { @@ -210,7 +273,7 @@ function verify(caller) { } else { if (opForm.targetcourse.selectedIndex == 0) { - alert("You must select a target course when importing enrollment information") + alert("$lt{'errte'}") return false } } @@ -218,7 +281,7 @@ function verify(caller) { } } if (totcheck == 0) { - alert("You must check the Checkbox for at least one Content Type"); + alert("$lt{'errcc'}"); return false } return true @@ -230,119 +293,39 @@ function nextPage(caller) { } } -#; +END_OF_TWO } -# ---------------------------------------------------------------- Jscript Three -sub jscript_three { - my $javascript = shift; -} - # ---------------------------------------------------------------- Display One sub display_one { - my ($r,$uname,$fn,$fullpath) = @_; - $r->print(<<"END_OF_ONE"); - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  -
  -    - Specify the Course Management system used to create the package.   - -
 
  - -Please choose the CMS used to create your IMS content package.   + my ($r,$fn,$fullpath,$formname) = @_; + $r->print(''. + &Apache::lonhtmlcommon::topic_bar(1,&mt('Specify the Course Management system used to create the package')). + &mt('Choose the CMS used to create your IMS content package.').'   - -
 
 
-    - Create a directory where you will unpack your IMS package.  
 
  - -Please choose a destination LON-CAPA directory in which to store the contents of the IMS package file. -
 

 If you have selected the CMS used to create the IMS package, and have created a destination directory, click the 'Proceed' button to continue the IMS package upload process.
- - - -
 
- - - - - -
- - - -
-
-
- -END_OF_ONE + + + + + + +
'."\n". + &Apache::lonhtmlcommon::topic_bar(2,&mt('Create a directory where you will unpack your IMS package'))."\n". + &mt('Create a destination LON-CAPA directory in which to store the contents of the IMS package file.').'  

+ + +      + + '); } # ---------------------------------------------------------------- Display Two sub display_two { - my ($r,$zipupload,$areas,$areaname,$cmsmap,$uname,$newdir,$numcrs,$fullpath) = @_; + my ($r,$zipupload,$areas,$areaname,$cmsmap,$fn,$numcrs,$fullpath) = @_; &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['folder','source']); - my $cms = $ENV{'form.source'}; - my $dirname = $ENV{'form.newdir'}; - my $tempdir = &Apache::imsprocessor::create_tempdir('CSTR',$dirname,''); + my $cms = $env{'form.source'}; + my $tempdir = &Apache::imsprocessor::create_tempdir('CSTR',$env{'form.newdir'},''); my $fname = &Apache::imsprocessor::uploadzip('CSTR',$tempdir,$zipupload); my $unzip_result = ''; my $manifest_result = ''; @@ -350,11 +333,30 @@ sub display_two { $unzip_result = &Apache::imsprocessor::expand_zip($tempdir,$fname); } my %resources = (); + my %includedres = (); + my %includeditems = (); my %items = (); my %hrefs = (); my %resinfo = (); my %count = (); - my @bgcolors = ("#eeeeee","#dddddd"); + + my %lt = &Apache::lonlocal::texthash( + cont => 'Choose which content types you wish to import', + impo => 'Import', + type => 'Content type', + addo => 'Additional options', + chec => 'Check Import first', + bbus => 'Choose a course to receive discussion boards and user enrollment', + list => 'A listing of possible course targets will be displayed if import of discussion boards and/or enrollment is checked above (step 3). If you do not plan to import either of these content types, there is no need to specify a course.', + chco => 'Choose course:', + nreq => 'Not required', + yodo => 'You do not have active course coordinator status in any LON-CAPA courses currently, so discussion boards and enrollment information included in your IMS package will be discarded, regardless of your import choice for these two items above (step 3).', + ifyo => "If you wish to import discussion boards and/or user information into LON-CAPA please click 'Exit now' to quit the current IMS import process, and contact your domain coordinator and request a course coordinator role in a LON-CAPA course into which you can upload discussion boards and/or enroll users.", + impa => 'Import package', + unpa => 'Unpacking of your IMS package failed because an IMS manifest file was not located in the package', + proc => 'Processing of your IMS package failed because the file you uploaded could not be unzipped', + exit => 'Exit now', + ); my $counter = 0; my $iter = 0; @@ -371,19 +373,21 @@ sub display_two { users => 0, ); my $conditions; - 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') { - foreach my $area (keys %{$$cmsmap{$cms}}) { + foreach my $res (sort(keys(%resources))) { + if ($cms eq 'bb5' || $cms eq 'bb6' || $cms eq 'webctce4' + || $cms eq 'webctvista4') { + foreach my $area (keys(%{$$cmsmap{$cms}})) { if ($resources{$res}{type} eq $$cmsmap{$cms}{$area}) { $count{$area} ++; } } - } elsif ($cms eq 'angel') { - foreach my $area (keys %{$$cmsmap{$cms}}) { + } elsif ($cms eq 'angel5') { + foreach my $area (keys(%{$$cmsmap{$cms}})) { if ($area eq 'doc') { if (grep/^$resources{$res}{type}$/,@{$$cmsmap{$cms}{doc}}) { $count{$area} ++; @@ -406,202 +410,106 @@ sub display_two { $conditions = 'none'; } - $r->print(< - - - - -
- - - - - - - - - - - - - - - - - - -ENDBLOCKTWO + $r->print(&Apache::loncommon::end_data_table()); if ($count{board} + $count{users} > 0) { - $r->print(" - - - - - - - - "); + $r->print(&Apache::lonhtmlcommon::topic_bar(4,$lt{'bbus'})); if ($$numcrs > 0) { - $r->print(" - - - -"); + $r->print($lt{'list'}.'

'.$lt{'chco'}.'  '."\n". + ''); } else { - $r->print(" - - - - - - - - - - - - -
  -
-    - Choose which content types you wish to import -
 
  - - - - -
- - - - -
- - - - - - -ENDBLOCK + $r->print(''. + &Apache::lonhtmlcommon::topic_bar(3,$lt{'cont'}). + &Apache::loncommon::start_data_table(). + &Apache::loncommon::start_data_table_header_row(). + ''. + &Apache::loncommon::end_data_table_header_row()); foreach my $area (@{$areas}) { if ($count{$area} > 0) { my $count_tag = 'flag_'.$counter; - $r->print(" - - "); + $r->print('/>'. + ''); if ($area eq 'board') { - $r->print(" "); + $r->print(''); } elsif ($area eq 'users') { - $r->print(" "); + '); } else { - $r->print(" "); + $r->print(''); } $counter ++; - $iter = $counter%2; + $r->print(&Apache::loncommon::end_data_table_row()); } } - $r->print(< -
Import?Content typeAdditional options
'.$lt{'impo'}.''.$lt{'type'}.''. + $lt{'addo'}.'
print(&Apache::loncommon::start_data_table_row()."\n". + 'print(qq|onClick='javascript:setOptions("$area","$counter")'|); + $r->print('onclick="javascript:setOptions('."'$area','$counter'".');" '); } - $r->print("/>  $$areaname{$area}   - $count{$area} item(s)  '.$$areaname{$area}.'   - '. + &mt('[quant,_1,item]',$count{$area}).'   - -    + +    -    + - -   None  '.&mt('None')."\n". + '
-
-
-
  -
-    - Choose a course to receive bulletin boards and user enrollment. -
 
 A listing of possible course targets will be displayed if import of bulletin boards and/or enrollment is checked above (step 3). If you do not plan to import either of these content types, there is no need to specify a course. -

-Choose course:   -
-
 You do not have active course coordinator status in any LON-CAPA courses currently, so bulletin boards and enrollment information included in your IMS package will be discarded, regardless of your import choice for these two items above (step 3). If you wish to import bulletin boards and/or user information into LON-CAPA please click 'Exit now' to quit the current IMS import process, and contact your domain coordinator and request a course coordinator role in a LON-CAPA course into which you can upload bulletin boards and/or enroll users. - "); + $r->print($lt{'yodo'}.' '.$lt{'ifyo'}); } } - $r->print(< -  

 Once you have checked the checkboxes for all areas you wish to import from the IMS package, and selected additional options (if available) you should click the 'Import package' button.
  - - - - - - - -ENDBLOCK + $r->print('

+ + + + + + '."\n"); if ($count{board} == 0) { - $r->print(' '."\n"); + $r->print(''."\n"); } if ($count{users} == 0) { - $r->print(' '."\n"); + $r->print(''."\n"); } - $r->print(< -
- - - - - -
- - - -
-
-
-ENDDOCUMENT + $r->print('    + '); } else { - $r->print("Unpacking of your IMS package failed because an IMS manifest file was not located in the package\n"); + $r->print($lt{'unpa'}); } } else { - $r->print("Processing of your IMS package failed because the file you uploaded could not be unzipped\n"); + $r->print( + '
'.&Apache::loncommon::confirmwrapper( + &Apache::lonhtmlcommon::confirm_success($lt{'proc'},1) + .'
'.&mt('Error: [_1]',$unzip_result)) + ); } } # ---------------------------------------------------------------- Display Three sub display_three { - my ($r,$uname,$udom,$areas,$areaname,$cmsmap,$destdir,$newdir) = @_; + my ($r,$uname,$udom,$areas,$areaname,$cmsmap,$destdir,$dirpath) = @_; my $crs = ''; my $cdom = ''; - my $chome = ''; my $db_handling = ''; my $timenow = time; my $announce_handling = 'ok'; - my $cms = $ENV{'form.source'}; - if ( defined($ENV{'form.bb_crs'}) ) { - ($cdom,$crs) = split/\//,$ENV{'form.bb_crs'}; - $chome = &Apache::lonnet::homeserver($crs,$cdom); + my $cms = $env{'form.source'}; + if ( defined($env{'form.bb_crs'}) ) { + ($cdom,$crs) = split/\//,$env{'form.bb_crs'}; } - if ( defined($ENV{'form.bb_handling'}) ) { - $db_handling = $ENV{'form.bb_handling'}; - } my $user_crs = ''; my $user_cdom = ''; my $user_handling = ''; - if ( defined($ENV{'form.user_crs'}) ) { - ($user_cdom,$user_crs) = split/\//,$ENV{'form.user_crs'}; + if ( defined($env{'form.user_crs'}) ) { + ($user_cdom,$user_crs) = split/\//,$env{'form.user_crs'}; } - if ( defined($ENV{'form.user_handling'}) ) { - $user_handling = $ENV{'form.user_handling'}; - } - my $seqstem = "/res/$udom/$uname/$newdir"; - my %imports = (); + my $seqstem = "/res/$udom/$uname/$dirpath"; + my %importareas = (); + my %includedres = (); + my %includeditems = (); + my %randompicks = (); my @targets = (); my %resources = (); my %items = (); @@ -615,126 +523,170 @@ sub display_three { board => 0, quiz => 0, surv => 0, + file => 0, ); my @pages = (); my @sequences = (); my @resrcfiles = (); + my @assessmentfiles = (); - my $tempdir = $ENV{'form.tempdir'}; + my $tempdir = $env{'form.tempdir'}; foreach my $area (@{$areas}) { - if (defined($ENV{"form.$area"}) ) { - if ($cms eq 'angel' && $area eq 'doc') { + if (defined($env{"form.$area"}) ) { + if ($cms eq 'angel5' && $area eq 'doc') { foreach (@{$$cmsmap{$cms}{$area}}) { - $imports{$_} = 1; + $importareas{$_} = 1; } } else { - $imports{$$cmsmap{$cms}{$area}} = 1; + $importareas{$$cmsmap{$cms}{$area}} = 1; } if ($area eq 'board') { - $db_handling = $ENV{'form.db_handling'}; + $db_handling = $env{'form.db_handling'}; } elsif ($area eq 'users') { - $user_handling = $ENV{'form.user_handling'}; + $user_handling = $env{'form.user_handling'}; } } } - my $manifest_result = &Apache::imsprocessor::process_manifest($cms,$tempdir,\%resources,\%items,\%hrefs,\%resinfo); + + my %lt = &Apache::lonlocal::texthash ( + yims => 'Your IMS package has been processed successfully.', + plsv => 'Please view the imported items and use the LON-CAPA editing tools to make changes.', + tseq => "The sequences directory contains a file named 'Top.sequence' which includes links to the items found at the top level of your IMS package. From there you can follow links to display all the imported items. Alternatively, you can browse the pages, sequences, problems and resfiles directories directly. Note if you rename a file, you will need to modify any .sequence files or .page files which include a reference to the renamed file.", + tfin => 'The final step in the IMS import process is to publish the materials you have imported into your Authoring Space so that you can use them in a course. Once your files are published, subsequent re-publication will result in the storage of information about changes between the different versions.', + disp => 'Display new directory', + proc => 'Processing of your IMS package failed, because the IMS content package did not contain an IMS manifest file.' + ); + my $manifest_result = &Apache::imsprocessor::process_manifest($cms,$tempdir, + \%resources,\%items,\%hrefs,\%resinfo,'prepare', + \%includedres); + if ($manifest_result eq 'ok') { - &Apache::imsprocessor::target_resources(\%resources,\%imports,\@targets); - my $copy_result = &Apache::imsprocessor::copy_resources('CSTR',$cms,\%hrefs,$tempdir,\@targets,\%urls,$crs,$cdom,$chome,$destdir,$timenow); + my %possibledep; + foreach my $res (sort(keys(%resources))) { + if ($importareas{$resources{$res}{type}}) { + $includedres{$res} = 1; + if ($resources{$res}{type} eq 'webct.manifest' || + $resources{$res}{type} eq 'webct.assessment' || + $resources{$res}{type} eq 'webct.question') { + push(@assessmentfiles,$res); + } + } elsif ($resources{$res}{usedby}) { + $possibledep{$res} = 1; + } + } + foreach my $res (sort(keys(%possibledep))) { + if ($includedres{$resources{$res}{usedby}}) { + $includedres{$res} = 1; + } + } + foreach my $itm (sort(keys(%items))) { + &Apache::imsprocessor::get_imports(\%includeditems,\%items,\%resources,\%importareas,$itm); + } + } + + foreach my $itm (sort(keys(%includeditems))) { + &Apache::imsprocessor::get_parents(\%includeditems,\%items,$itm); + } + + $manifest_result = &Apache::imsprocessor::process_manifest($cms,$tempdir, + \%resources,\%items,\%hrefs,\%resinfo,'build', + \%includedres,\%includeditems); + + if ($manifest_result eq 'ok') { + &Apache::imsprocessor::target_resources(\%resources,\%importareas,\@targets); my @boards = (); my @announcements = (); my @quizzes = (); my @surveys = (); + my @pools = (); my @groups = (); my %messages = (); my @timestamp = (); my %boardnum = (); my @topurls = (); my @topnames = (); + my @packages = (); + + &Apache::imsprocessor::process_resinfo($cms,'CSTR',$tempdir,$destdir,\%items,\%resources,\@targets,\@boards,\@announcements,\@quizzes,\@surveys,\@pools,\@groups,\%messages,\@timestamp,\%boardnum,\%resinfo,$udom,$uname,$cdom,$crs,$db_handling,$user_handling,\%total,$seqstem,$seqstem,\@resrcfiles,\@packages,\%hrefs,\@pages,\@sequences,\%randompicks); - &Apache::imsprocessor::process_resinfo($cms,'CSTR',$tempdir,$destdir,\%items,\%resources,\@boards,\@announcements,\@quizzes,\@surveys,\@groups,\%messages,\@timestamp,\%boardnum,\%resinfo,$udom,$uname,$cdom,$crs,$db_handling,$user_handling,\%total,$newdir,$seqstem,\@resrcfiles); + my $copy_result = &Apache::imsprocessor::copy_resources('CSTR',$cms,\%hrefs,\%resources,$tempdir,\@targets,\%urls,$crs,$cdom,$destdir,$timenow,\@assessmentfiles,\%total); - &Apache::imsprocessor::build_structure($cms,'CSTR',$destdir,\%items,\%resinfo,\%resources,\%hrefs,$udom,$uname,$newdir,$timenow,$cdom,$crs,\@timestamp,\%total,\@boards,\@announcements,\@quizzes,\@surveys,\%boardnum,\@pages,\@sequences,\@topurls,\@topnames); + &Apache::imsprocessor::build_structure($cms,'CSTR',$destdir,\%items,\%resinfo,\%resources,\@targets,\%hrefs,$udom,$uname,$dirpath,$timenow,$cdom,$crs,\@timestamp,\%total,\@boards,\@announcements,\@quizzes,\@surveys,\@pools,\%boardnum,\@pages,\@sequences,\@topurls,\@topnames,\@packages,\%includeditems,\%randompicks); - $r->print("

Step 3: Publish your new LON-CAPA materials

"); + my $message = + &Apache::lonhtmlcommon::confirm_success( + &mt('IMS import completed')) + .'
'.$lt{'yims'}.' '; - if ($cms eq 'bb5') { - $r->print("Your IMS package has been processed successfully. A total of $total{seq} sequences, $total{page} pages, $total{board} bulletin boards, $total{quiz} quizzes, $total{surv} surveys and $total{prob} problems have been created.

\n"); - } elsif ($cms eq 'angel') { - $r->print("Your IMS package has been processed successfully. A total of $total{seq} sequences, $total{page} pages, and $total{board} bulletin boards have been created.

\n"); + if ($cms eq 'angel5') { + $message .= &mt('A total of [quant,_1,sequence], [quant,_2,composite page], and [quant,_3,discussion board] have been created, and [quant,_4,file] copied.',$total{seq},$total{page},$total{board},$total{file})."\n"; + } else { + $message .= &mt('A total of [quant,_1,sequence], [quant,_2,composite page], [quant,_3,discussion board], [quant,_4,quiz,quizzes], [quant,_5,survey], and [quant,_6,problem] have been created, and [quant,_7,file] copied.',$total{seq},$total{page},$total{board},$total{quiz},$total{surv},$total{prob},$total{file})."\n"; + } + $r->print( + '
'.&Apache::loncommon::confirmwrapper($message) + .'

'.$lt{'plsv'}.' '.$lt{'tseq'}.'

' + .'

'.$lt{'tfin'}.'

' + .&Apache::lonhtmlcommon::actionbox( + [''.$lt{'disp'}.'']) + ); + my $londocroot = $r->dir_config('lonDocRoot'); + if ($destdir =~ m{^\Q$londocroot/priv/$udom/$uname/$dirpath\E}) { + system (" rm -r -f $destdir/temp"); } -# system (" rm -r -f $destdir/temp"); } elsif ($manifest_result eq 'nomanifest') { - $r->print("Processing of your IMS package failed, because the IMS content package did not contain an IMS manifest file ."); + $r->print( + '
'.&Apache::loncommon::confirmwrapper( + &Apache::lonhtmlcommon::confirm_success($lt{'proc'},1)) + ); } } # ---------------------------------------------------------------- Get LON-CAPA Course Coordinator roles for this user sub get_ccroles { my ($user,$dom,$crsentry,$crslist) = @_; - my %roles = (); + my %roles; unless ($user eq '') { - %roles = &Apache::lonnet::dump('roles',$dom,$user); + my $ccrole = 'cc'; + %roles = &Apache::lonnet::get_my_roles($user,$dom,'userroles',undef,[$ccrole]); } my $iter = 0; my @codes = (); my %courses = (); my @crslist = (); my %descrip =(); - foreach my $key (keys %roles ) { - if ($key =~ m/^\/(\w+)\/(\w+)_cc$/) { + foreach my $key (keys(%roles)) { + if ($key =~ m{^/($LONCAPA::domain_re)/($LONCAPA::username_re)_cc$}) { my $cdom = $1; my $crs = $2; - my $role_end = 0; - my $role_start = 0; - my $active_chk = 1; - if ( $roles{$key} =~ m/^cc_(\d+)/ ) { - $role_end = $1; - if ( $roles{$key} =~ m/^cc_($role_end)_(\d+)$/ ) - { - $role_start = $2; - } - } - if ($role_start > 0) { - if (time < $role_start) { - $active_chk = 0; - } - } - if ($role_end > 0) { - if (time > $role_end) { - $active_chk = 0; - } + my $currcode = ''; + my %settings = &Apache::lonnet::get('environment',['internal.coursecode','description'],$cdom,$crs); + if (defined($settings{'description'}) ) { + $descrip{$crs} = $settings{'description'}; + } else { + $descrip{$crs} = 'Unknown'; } - if ($active_chk) { - my $currcode = ''; - my %settings = &Apache::lonnet::get('environment',['internal.coursecode','description'],$cdom,$crs); - if (defined($settings{'description'}) ) { - $descrip{$crs} = $settings{'description'}; - } else { - $descrip{$crs} = 'Unknown'; - } - if (defined($settings{'internal.coursecode'}) ) { - $currcode = $settings{'internal.coursecode'}; - if ($currcode eq '') { - $currcode = "____".$iter; - $iter ++; - } - } else { + if (defined($settings{'internal.coursecode'}) ) { + $currcode = $settings{'internal.coursecode'}; + if ($currcode eq '') { $currcode = "____".$iter; $iter ++; } - unless (grep/^$currcode$/,@codes) { - push @codes,$currcode; - @{$courses{$currcode}} = (); - } - push @{$courses{$currcode}}, $cdom.'/'.$crs; + } else { + $currcode = "____".$iter; + $iter ++; } + unless (grep/^$currcode$/,@codes) { + push @codes,$currcode; + @{$courses{$currcode}} = (); + } + push @{$courses{$currcode}}, $cdom.'/'.$crs; } } - foreach my $code (sort @codes) { + foreach my $code (sort(@codes)) { foreach my $crsdom (@{$courses{$code}}) { my ($cdom,$crs) = split/\//,$crsdom; my $showcode = ''; @@ -749,56 +701,43 @@ sub get_ccroles { # ---------------------------------------------------------------- Main Handler sub handler { my $r=shift; - my $uname; - my $udom; - my $javascript = ''; - my $page_name = ''; - my $current_page = ''; - my $loadentries = ''; - my $qcount = ''; -# get personal information for this user - my $user=$ENV{'user.name'}; - my $dom=$ENV{'user.domain'}; + my $fn=$env{'form.filename'}; -# -# re-attach user -# - if ($ENV{'form.uploaduname'}) { - $ENV{'form.filename'}='/priv/'.$ENV{'form.uploaduname'}.'/'. - $ENV{'form.filename'}; - } - ($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'}. - ' - not authorized', - $r->filename); - return HTTP_NOT_ACCEPTABLE; + if ($env{'form.filename1'}) { + $fn=$env{'form.filename1'}.$env{'form.filename2'}; } - - my $fn; - if ($ENV{'form.filename'}) { - $fn=$ENV{'form.filename'}; - $fn=~s/^http\:\/\/[^\/]+\///; - $fn=~s/^\///; - $fn=~s/(\~|priv\/)(\w+)//; - $fn=~s/\/+/\//g; - } else { - $r->log_reason($ENV{'user.name'}.' at '.$ENV{'user.domain'}. + $fn=~s{\+}{}g; + + unless ($fn) { + $r->log_reason($env{'user.name'}.' at '.$env{'user.domain'}. ' unspecified filename for upload', $r->filename); return HTTP_NOT_FOUND; } - my $zipupload = '/home/'.$uname.'/public_html'.$fn; - my $pathname = &File::Basename::dirname($fn); - my $fullpath = '/priv/'.$uname.$pathname; - unless ($pathname eq '/') { + + my ($uname,$udom) = &Apache::lonnet::constructaccess($fn); + if (($uname eq '') || ($udom eq '')) { + $r->log_reason($uname.' at '.$udom. + ' trying to publish file '.$fn.' - not authorized', + $r->filename); + return HTTP_NOT_ACCEPTABLE; + } + + my $londocroot = $r->dir_config('lonDocRoot'); + my $zipupload = $londocroot.$fn; + my $fullpath = &File::Basename::dirname($fn); + unless ($fullpath =~ m{/$}) { $fullpath .= '/'; } - my $loadentries = ''; +# get personal information for this user + my $user=$env{'user.name'}; + my $dom=$env{'user.domain'}; + + my $javascript = ''; + my $page_name = ''; + my $current_page = ''; + my $qcount = ''; my @areas = (); my %cmsmap = (); my %areaname = (); @@ -809,41 +748,58 @@ sub handler { &Apache::loncommon::content_type($r,'text/html'); $r->send_http_header; - if ($ENV{'form.phase'} eq 'two') { - &jscript_one($fullpath,\$javascript,$uname,$udom); - } elsif ($ENV{'form.phase'} eq 'three') { - &jscript_two(\$javascript,$user,$dom,\$numcrs); - } elsif ($ENV{'form.phase'} eq 'four') { - &jscript_three(\$javascript); - } - $r->print("LON-CAPA Construction Space\n"); - - $r->print(&Apache::loncommon::bodytag('Upload IMS package to Construction Space',undef,$loadentries)); - - if (($uname ne $ENV{'user.name'}) || ($udom ne $ENV{'user.domain'})) { - $r->print('

'.&mt('Co-Author').': '.$uname. - &mt(' at ').$udom.'

'); - } - if ($ENV{'form.phase'} eq 'two') { - my $flag = &Apache::lonupload::phasetwo($r,$fn,$uname,$udom,'imsimport'); + my $formname_one = 'info'; + if ($env{'form.phase'} eq 'two') { + $javascript = &jscript_one($fullpath,$formname_one); + } elsif ($env{'form.phase'} eq 'three') { + $javascript = &jscript_two($user,$dom,\$numcrs); + } + if ($javascript ne '') { + $javascript = <<"END_JS"; + +END_JS + } + + my $title = 'Upload IMS package to Authoring Space'; + $r->print(&Apache::loncommon::start_page($title, $javascript)); + + if (($uname ne $env{'user.name'}) || ($udom ne $env{'user.domain'})) { + $r->print('

' + .&mt('Co-Author [_1]',$uname.':'.$udom) + .'

' + ); + } + if ($env{'form.phase'} eq 'two') { + my $flag = &Apache::lonupload::phasetwo($r,$fn,'imsimport'); if ($flag eq 'ok') { - &display_one($r,$uname,$fn,$fullpath); - } - } elsif ( ($ENV{'form.phase'} eq 'three') || ($ENV{'form.phase'} eq 'four') ) { - my $docroot = $ENV{'form.newdir'}; - my $newdir = ''; - if ($docroot =~ m|public_html/(.+)$|) { - $newdir = $1; - } - if ($ENV{'form.phase'} eq 'three') { - &display_two ($r,$zipupload,\@areas,\%areaname,\%cmsmap,$uname,$newdir,\$numcrs,$fullpath); - } elsif ($ENV{'form.phase'} eq 'four') { - &display_three ($r,$uname,$udom,\@areas,\%areaname,\%cmsmap,$docroot,$newdir); + &display_one($r,$fn,$fullpath,$formname_one); + } else { + $r->print( + '
'.&Apache::loncommon::confirmwrapper( + &Apache::lonhtmlcommon::confirm_success( + &mt('Error uploading IMS package'),1)) + ); + } + } elsif ( ($env{'form.phase'} eq 'three') || ($env{'form.phase'} eq 'four') ) { + my $destdir = $env{'form.newdir'}; + my $dirpath = $destdir; + $dirpath =~ s{^\Q$londocroot/priv/$udom/$uname/\E}{}; + + if ($env{'form.phase'} eq 'three') { + &display_two($r,$zipupload,\@areas,\%areaname,\%cmsmap,$fn,\$numcrs,$fullpath); + } elsif ($env{'form.phase'} eq 'four') { + &display_three($r,$uname,$udom,\@areas,\%areaname,\%cmsmap,$destdir,$dirpath); } } else { - &Apache::lonupload::phaseone($r,$fn,$uname,$udom,'imsimport'); + &Apache::lonupload::phaseone($r,$fn,'imsimport',$uname,$udom); } - $r->print(''); + $r->print(&Apache::loncommon::end_page()); return OK; } 1;