[LON-CAPA-cvs] cvs: loncom /imspackages imsimport.pm imsprocessor.pm
raeburn
raeburn at source.lon-capa.org
Thu Nov 3 13:54:54 EDT 2011
raeburn Thu Nov 3 17:54:54 2011 EDT
Modified files:
/loncom/imspackages imsimport.pm imsprocessor.pm
Log:
- Clean-up after changes for bug 1320.
- Restore support for import of IMS content packages into CSTR.
imsimport.pm
- loncacc::constructaccess() args changed in rev 1.55.
- args changed for &jscript_one(), &jscript_two()
no longer pass ref to scalar;
instead set $javascript to return value from routines.
- eliminate unused routine.
- &display_one() eliminate unused arg: $uname.
- &display_two() replace $uname with $fn as sixth arg.
- &display_three() replace $newdir with $dirpath as final arg
- this is the part of path to the directory after /priv/dom/uname where IMS
content is stored.
- Eliminate $uname and $udom from args passed to lonupload::phaseone() and
lonupload::phasetwo() - eliminated in lonupload.pm rev. 1.58.
- use lonDocRoot perlvar in place of static string: '/home/httpd/html'
- coding style
- eliminate leaning toothpicks
imsprocessor.pm
- use lonDocRoot perlvar in place of static string: '/home/httpd/html'
- coding style
- use {} as delimiter in calls to substitution where default of / is
inappropriate ("leaning toothpicks").
-------------- next part --------------
Index: loncom/imspackages/imsimport.pm
diff -u loncom/imspackages/imsimport.pm:1.35 loncom/imspackages/imsimport.pm:1.36
--- loncom/imspackages/imsimport.pm:1.35 Mon Oct 24 22:02:38 2011
+++ loncom/imspackages/imsimport.pm Thu Nov 3 17:54:53 2011
@@ -1,6 +1,6 @@
# The LearningOnline Network with CAPA
#
-# $Id: imsimport.pm,v 1.35 2011/10/24 22:02:38 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 @@
# ---------------------------------------------------------------- Jscript One
sub jscript_one {
- my ($fullpath,$jsref,$formname) = @_;
+ my ($fullpath,$formname) = @_;
my %body_layout = ('rightmargin' => "0",
'leftmargin' => "0",
@@ -66,7 +66,7 @@
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 @@
# ---------------------------------------------------------------- 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 @@
$course_list = '"'.join('","', at crslist).'"';
$$numcrs = @crslist;
- $$javascript = qq#
+ return <<"END_OF_TWO";
function checkCourse() {
courseID_array = new Array($course_list)
@@ -280,18 +280,13 @@
}
}
-#;
+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('<form name="'.$formname.'" method="post">'.
&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 @@
</select><br />'."\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.').' <input type="button" name="createdir" value="Create Directory" onClick="javascript:createWin()" /><input type="hidden" name="newdir" value="" /><br /><br />
- <input type="hidden" name="uploaduname" value="'.$uname.'" />
<input type="hidden" name="filename" value="'.$fn.'" />
<input type="hidden" name="phase" value="three" />
<input type="button" name="nextpage" value="'.&mt('Proceed').'" onClick="javascript:nextPage();" />
@@ -315,11 +309,10 @@
# ---------------------------------------------------------------- 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 @@
<input type="hidden" name="conditions" value="'.$conditions.'" />
<input type="hidden" name="source" value="'.$cms.'" />
<input type="hidden" name="tempdir" value="'.$tempdir.'" />
- <input type="hidden" name="uploaduname" value="'.$uname.'" />
- <input type="hidden" name="filename" value="'.$fname.'" />
+ <input type="hidden" name="filename" value="'.$fn.'" />
<input type="hidden" name="phase" value="four" />'."\n");
if ($count{board} == 0) {
$r->print('<input type="hidden" name="board" value="" />'."\n");
@@ -480,7 +472,7 @@
# ---------------------------------------------------------------- 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 @@
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 @@
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("<h3>IMS import completed</h3>");
@@ -604,8 +596,9 @@
} 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('<br /><br />'.$lt{'plsv'}.' '.$lt{'tseq'}.'<br /><br />'.$lt{'tfin'}.'<br /><br /><a href="/priv/'.$udom.'/'.$uname.'/'.$newdir.'">'.$lt{'disp'}.'</a>');
- if ($destdir =~ m-^/home/httpd/html/priv/$udom/$uname/-) {
+ $r->print('<br /><br />'.$lt{'plsv'}.' '.$lt{'tseq'}.'<br /><br />'.$lt{'tfin'}.'<br /><br /><a href="/priv/'.$udom.'/'.$uname.'/'.$dirpath.'/">'.$lt{'disp'}.'</a>');
+ 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 @@
# ---------------------------------------------------------------- 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 @@
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";
+<script type="text/javascript">
+// <![CDATA[
+
+$javascript
+
+// ]]>
+</script>
+END_JS
}
- $javascript = "<script type=\"text/javascript\">\n//<!--\n$javascript\n// --></script>\n";
my $title = 'Upload IMS package to Construction Space';
$r->print(&Apache::loncommon::start_page($title, $javascript));
@@ -745,25 +735,24 @@
.&mt('Co-Author [_1]',$uname.':'.$udom)
.'</span></p>'
);
- }
+ }
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|/(.+)$|) {
- $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;
Index: loncom/imspackages/imsprocessor.pm
diff -u loncom/imspackages/imsprocessor.pm:1.49 loncom/imspackages/imsprocessor.pm:1.50
--- loncom/imspackages/imsprocessor.pm:1.49 Mon Oct 24 23:41:52 2011
+++ loncom/imspackages/imsprocessor.pm Thu Nov 3 17:54:53 2011
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Processor for IMS Packages
#
-# $Id: imsprocessor.pm,v 1.49 2011/10/24 23:41:52 www Exp $
+# $Id: imsprocessor.pm,v 1.50 2011/11/03 17:54:53 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -679,10 +679,11 @@
$cid = $env{'request.course.id'};
}
my $destresdir = $destdir;
+ my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
if ($context eq 'CSTR') {
- $destresdir =~ s|/home/httpd/html/priv/|/res/|;
+ $destresdir =~ s{^\Q$londocroot/priv/\E}{/res/};
} elsif ($context eq 'DOCS') {
- $destresdir =~ s|^/home/httpd/html/userfiles|/uploaded|;
+ $destresdir =~ s{^\Q$londocroot/userfiles\E}{/uploaded};
}
foreach my $res (sort(keys(%allquestions))) {
my $parent = $allquestions{$res};
@@ -3217,10 +3218,11 @@
($cdom,$cnum) = split/_/,$cid;
}
my $destresdir = $destdir;
+ my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
if ($context eq 'CSTR') {
- $destresdir =~ s|/home/httpd/html/priv/|/res/|;
+ $destresdir =~ s{^\Q$londocroot/priv/\E}{/res/};
} elsif ($context eq 'DOCS') {
- $destresdir =~ s|^/home/httpd/html/userfiles|/uploaded|;
+ $destresdir =~ s{^\Q$londocroot/userfiles\E}{/uploaded};
}
if ($cms eq 'bb5') {
&parse_bb5_assessment($res,$docroot,$container,$settings,\%allanswers,\%allchoices,\@allids);
@@ -3367,8 +3369,8 @@
push @{$sequencesfiles},$mapname.'.sequence';
} else {
$$containerdir = $pagedir.'/'.$mapname.'.page';
- if (!-e "$destdir/pages") {
- mkdir("$destdir/pages",0770);
+ if (!-e "$pagedir") {
+ mkdir("$pagedir",0770);
}
open($fh,">$$containerdir");
$$total{page} ++;
@@ -3462,6 +3464,7 @@
my ($allids,$containerdir,$context,$settings,$dirname,$destdir,$res,$allanswers,$allchoices,$total,$newdir,$cid,$cdom,$cnum,$docroot) = @_;
my $qnum = 0;
my $pathstart;
+ my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
if ($context eq 'CSTR') {
$pathstart = '../..';
} else {
@@ -3481,7 +3484,7 @@
$qnum ++;
my $output;
my $permcontainer = $containerdir;
- $permcontainer =~ s#/home/httpd/html/userfiles#uploaded#;
+ $permcontainer =~ s{^\Q$londocroot/userfiles\E}{uploaded};
my $symb = $cid.'.'.$permcontainer.'___'.$qnum.'___lib/templates/simpleproblem.problem.0.';
my %resourcedata = ();
for (my $i=0; $i<10; $i++) {
@@ -3838,6 +3841,7 @@
sub write_webct4_questions {
my ($cms,$alldbquestids,$context,$settings,$dirname,$allanswers,$allchoices,$total,$cid,$cdom,$cnum,$destdir,$catinfo,$dirtitle) = @_;
+ my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
my $qnum = 0;
foreach my $id (@{$alldbquestids}) {
$qnum ++;
@@ -3870,7 +3874,7 @@
}
}
}
- $permcontainer =~ s#/home/httpd/html/userfiles#uploaded#;
+ $permcontainer =~ s{\Q$londocroot/userfiles\E}{uploaded};
my $symb = $cid.'.'.$permcontainer.'___'.$qnum.'___lib/templates/simpleproblem.problem.0.';
my %resourcedata = ();
for (my $i=0; $i<10; $i++) {
@@ -4477,6 +4481,7 @@
sub write_bb6_questions {
my ($allids,$containerdir,$context,$settings,$dirname,$destdir,$res,$total,$newdir,$cid,$cdom,$cnum,$docroot) = @_;
+ my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
my $qnum = 0;
foreach my $id (@{$allids}) {
my $questiontext = $$settings{$id}{question}{text};
@@ -4485,7 +4490,7 @@
$qnum ++;
my $output;
my $permcontainer = $containerdir;
- $permcontainer =~ s#/home/httpd/html/userfiles#uploaded#;
+ $permcontainer =~ s{\Q$londocroot/userfiles\E}{uploaded};
my $symb = $cid.'.'.$permcontainer.'___'.$qnum.'___lib/templates/simpleproblem.problem.0.';
my %resourcedata = ();
for (my $i=0; $i<10; $i++) {
@@ -4979,10 +4984,11 @@
my ($cms,$res,$context,$docroot,$destdir,$settings,$dom,$user,$resrcfiles,$packages,$hrefs) = @_;
my $xmlfile = $docroot.'/'.$res.".dat";
my $destresdir = $destdir;
+ my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
if ($context eq 'CSTR') {
- $destresdir =~ s|/home/httpd/html/priv/|/res/|;
+ $destresdir =~ s{^\Q$londocroot/priv/\E}{/res/};
} elsif ($context eq 'DOCS') {
- $destresdir =~ s|^/home/httpd/html/userfiles|/uploaded|;
+ $destresdir =~ s{^\Q$londocroot/userfiles\E}{/uploaded};
}
my $filetag = '';
if ($cms eq 'bb5') {
More information about the LON-CAPA-cvs
mailing list