--- loncom/imspackages/imsimport.pm 2011/10/24 21:58:04 1.34 +++ loncom/imspackages/imsimport.pm 2011/11/03 17:54:53 1.36 @@ -1,6 +1,6 @@ # The LearningOnline Network with CAPA # -# $Id: imsimport.pm,v 1.34 2011/10/24 21:58:04 www Exp $ +# $Id: imsimport.pm,v 1.36 2011/11/03 17:54:53 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -43,7 +43,7 @@ use LONCAPA; # ---------------------------------------------------------------- Jscript One sub jscript_one { - my ($fullpath,$jsref,$formname) = @_; + my ($fullpath,$formname) = @_; my %body_layout = ('rightmargin' => "0", 'leftmargin' => "0", @@ -66,7 +66,7 @@ sub jscript_one { nndi => 'Enter the name of the new directory where you will store the contents of your IMS package.', go => 'Go', ); - $$jsref = <<"END_OF_ONE"; + return <<"END_OF_ONE"; function verify() { if ((document.forms.$formname.newdir.value == '') || (!document.forms.$formname.newdir.value)) { alert('$lt{'ddir'}') @@ -115,7 +115,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; @@ -134,7 +134,7 @@ sub jscript_two { $course_list = '"'.join('","',@crslist).'"'; $$numcrs = @crslist; - $$javascript = qq# + return <<"END_OF_TWO"; function checkCourse() { courseID_array = new Array($course_list) @@ -280,18 +280,13 @@ function nextPage(caller) { } } -#; +END_OF_TWO } -# ---------------------------------------------------------------- Jscript Three -sub jscript_three { - my $javascript = shift; -} - # ---------------------------------------------------------------- Display One sub display_one { - my ($r,$uname,$fn,$fullpath,$formname) = @_; + 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.').'   @@ -305,7 +300,6 @@ sub display_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.').'  

-      @@ -315,11 +309,10 @@ sub display_one { # ---------------------------------------------------------------- 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 $tempdir = &Apache::imsprocessor::create_tempdir('CSTR',$env{'form.newdir'},''); my $fname = &Apache::imsprocessor::uploadzip('CSTR',$tempdir,$zipupload); my $unzip_result = ''; my $manifest_result = ''; @@ -459,8 +452,7 @@ sub display_two { - - + '."\n"); if ($count{board} == 0) { $r->print(''."\n"); @@ -480,7 +472,7 @@ sub display_two { # ---------------------------------------------------------------- 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 $db_handling = ''; @@ -496,7 +488,7 @@ sub display_three { if ( defined($env{'form.user_crs'}) ) { ($user_cdom,$user_crs) = split/\//,$env{'form.user_crs'}; } - my $seqstem = "/res/$udom/$uname/$newdir"; + my $seqstem = "/res/$udom/$uname/$dirpath"; my %importareas = (); my %includedres = (); my %includeditems = (); @@ -595,7 +587,7 @@ sub display_three { my $copy_result = &Apache::imsprocessor::copy_resources('CSTR',$cms,\%hrefs,$tempdir,\@targets,\%urls,$crs,$cdom,$destdir,$timenow,\@assessmentfiles,\%total); - &Apache::imsprocessor::build_structure($cms,'CSTR',$destdir,\%items,\%resinfo,\%resources,\@targets,\%hrefs,$udom,$uname,$newdir,$timenow,$cdom,$crs,\@timestamp,\%total,\@boards,\@announcements,\@quizzes,\@surveys,\@pools,\%boardnum,\@pages,\@sequences,\@topurls,\@topnames,\@packages,\%includeditems,\%randompicks); + &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("

IMS import completed

"); @@ -604,8 +596,9 @@ sub display_three { } else { $r->print($lt{'yims'}.' '.&mt('A total of [quant,_1,sequence], [quant,_2,composite page], [quant,_3,bulletin 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('

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

'.$lt{'tfin'}.'

'.$lt{'disp'}.''); - if ($destdir =~ m-^/home/httpd/html/priv/$udom/$uname/-) { + $r->print('

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

'.$lt{'tfin'}.'

'.$lt{'disp'}.''); + my $londocroot = $r->dir_config('lonDocRoot'); + if ($destdir =~ m{^\Q$londocroot/priv/$udom/$uname/$dirpath\E}) { system (" rm -r -f $destdir/temp"); } } elsif ($manifest_result eq 'nomanifest') { @@ -669,54 +662,43 @@ sub get_ccroles { # ---------------------------------------------------------------- Main Handler sub handler { my $r=shift; - my $uname; - my $udom; - my $javascript = ''; - my $page_name = ''; - my $current_page = ''; - 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/'.$dom.'/'.$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/^https?\:\/\/[^\/]+\///; - $fn=~s/^\///; - $fn=~s/(priv\/)($LONCAPA::domain_re)\/($LONCAPA::username_re)//; - $fn=~s/\/+/\//g; - } else { + $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/httpd/html/priv/'.$udom.'/'.$uname.$fn; - my $pathname = &File::Basename::dirname($fn); - my $fullpath = '/priv/'.$udom.'/'.$uname.$pathname; - unless ($pathname eq '/') { + + my ($uname,$udom) = &Apache::loncacc::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 .= '/'; } +# 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 = (); @@ -729,13 +711,21 @@ sub handler { my $formname_one = 'info'; if ($env{'form.phase'} eq 'two') { - &jscript_one($fullpath,\$javascript,$formname_one); + $javascript = &jscript_one($fullpath,$formname_one); } elsif ($env{'form.phase'} eq 'three') { - &jscript_two(\$javascript,$user,$dom,\$numcrs); - } elsif ($env{'form.phase'} eq 'four') { - &jscript_three(\$javascript); + $javascript = &jscript_two($user,$dom,\$numcrs); + } + if ($javascript ne '') { + $javascript = <<"END_JS"; + +END_JS } - $javascript = "\n"; my $title = 'Upload IMS package to Construction Space'; $r->print(&Apache::loncommon::start_page($title, $javascript)); @@ -745,25 +735,24 @@ sub handler { .&mt('Co-Author [_1]',$uname.':'.$udom) .'

' ); - } + } if ($env{'form.phase'} eq 'two') { - my $flag = &Apache::lonupload::phasetwo($r,$fn,$uname,$udom,'imsimport'); + my $flag = &Apache::lonupload::phasetwo($r,$fn,'imsimport'); if ($flag eq 'ok') { - &display_one($r,$uname,$fn,$fullpath,$formname_one); + &display_one($r,$fn,$fullpath,$formname_one); } } 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; - } + 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,$uname,$newdir,\$numcrs,$fullpath); + &display_two($r,$zipupload,\@areas,\%areaname,\%cmsmap,$fn,\$numcrs,$fullpath); } elsif ($env{'form.phase'} eq 'four') { - &display_three ($r,$uname,$udom,\@areas,\%areaname,\%cmsmap,$docroot,$newdir); + &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'); } $r->print(&Apache::loncommon::end_page()); return OK;