--- loncom/interface/londocs.pm 2005/06/08 21:38:44 1.182 +++ loncom/interface/londocs.pm 2006/01/16 23:42:39 1.218 @@ -1,7 +1,7 @@ # The LearningOnline Network # Documents # -# $Id: londocs.pm,v 1.182 2005/06/08 21:38:44 albertel Exp $ +# $Id: londocs.pm,v 1.218 2006/01/16 23:42:39 albertel Exp $ # # Copyright Michigan State University Board of Trustees # @@ -166,7 +166,10 @@ sub dumpcourse { $crs=~s/\_/\//g; foreach (keys %replacehash) { my $newfilename=$title.'/'.$replacehash{$_}; + $newfilename=~s/\.(\w+)$//; + my $ext=$1; $newfilename=&clean($newfilename); + $newfilename.='.'.$ext; my @dirs=split(/\//,$newfilename); my $path='/home/'.$ca.'/public_html'; my $makepath=$path; @@ -249,11 +252,10 @@ sub dumpcourse { # ------------------------------------------------------ Generate "export" button sub exportbutton { - return ''; return ''. ''. - &Apache::loncommon::help_open_topic('Docs_Export_Course_Docs'); + &Apache::loncommon::help_open_topic('Docs_Export_Course_Docs'); } sub exportcourse { @@ -491,10 +493,21 @@ sub create_ims_store { ' identifier="MANIFEST-'.$env{'request.course.id'}.'-'.$now.'"'. ' xsi:schemaLocation="http://www.imsglobal.org/xsd/imscp_v1p1imscp_v1p1.xsd'. ' http://www.imsglobal.org/xsd/imsmd_v1p2 imsmd_v1p2p2.xsd">'."\n". +' + + + + '.$env{'request.course.id'}.' + + '.$env{'course.'.$env{'request.course.id'}.'.description'}.' + + + + '."\n". ' '."\n". ' '."\n". -' '.$env{'request.'.$env{'request.course.id'}.'.description'}.'' +' '.$env{'course.'.$env{'request.course.id'}.'.description'}.'' } else { $$outcome .= 'An error occurred opening the IMS manifest file.
' ; @@ -542,7 +555,6 @@ sub build_package { $count = 0; my $imsresources; my $pkgdepth; - my $included = 0; while ($curRes = $it->next()) { if ($curRes == $it->BEGIN_MAP()) { $prevdepth = $depth; @@ -565,10 +577,13 @@ sub build_package { unless ($curRes->is_sequence()) { $resourceref = 'identifierref="RES-'.$env{'request.course.id'}.'-'.$count.'"'; } - if (($depth <= $prevdepth) && ($count > 1) && ($included)) { - print $ims_manifest "\n".' '."\n"; + my $step = $prevdepth - $depth; + if (($step >= 0) && ($count > 1)) { + while ($step >= 0) { + print $ims_manifest "\n".' '."\n"; + $step --; + } } - $included = 1; $prevdepth = $depth; my $itementry = @@ -610,8 +625,6 @@ sub build_package { } } $pkgdepth = $depth; - } else { - $included = 0; } } } @@ -646,7 +659,6 @@ sub process_content { my ($count,$curRes,$cdom,$cnum,$symb,$content_file,$href,$copyresult,$tempexport) = @_; my $content_type; my $message; -# find where user is author or co-author my @uploads = (); if ($curRes->is_sequence()) { $content_type = 'sequence'; @@ -679,7 +691,7 @@ sub process_content { if ($contents) { $$content_file = &store_template($contents,$tempexport,$count,$content_type); } - } elsif ($symb =~ m-lib/templates/examupload\.problem-m) { + } elsif ($symb =~ m-lib/templates/examupload\.problem$-) { $content_type = 'examupload'; } elsif ($symb =~ m-adm/(\w+)/(\w+)/(\d+)/bulletinboard$-) { $content_type = 'bulletinboard'; @@ -700,6 +712,7 @@ sub process_content { if ($2 eq $env{'user.domain'} && $3 eq $env{'user.name'}) { $canedit= 1; } +# only include problem code where current user is author if ($canedit) { $$content_file = &replicate_content($cdom,$cnum,$tempexport,$symb,$count,\$message,$href,'resource'); } else { @@ -748,11 +761,13 @@ sub replicate_content { if ($copiedfile = Apache::File->new('>'.$destination)) { my $content; if ($caller eq 'resource') { - $content = &Apache::lonnet::getfile('/home/httpd/html/res/'.$url); + my $respath = $Apache::lonnet::perlvar{'lonDocRoot'}.'/res'; + my $filepath = &Apache::lonnet::filelocation($respath,$url); + $content = &Apache::lonnet::getfile($filepath); if ($content eq -1) { $$message = 'Could not copy file '.$filename; } else { - &extract_media($content,$count,$tempexport,$href,'resource'); + &extract_media($url,$cdom,$cnum,\$content,$count,$tempexport,$href,$message,'resource'); $repstatus = 'ok'; } } elsif ($caller eq 'uploaded' || $caller eq 'templateupload') { @@ -760,10 +775,10 @@ sub replicate_content { $repstatus = &Apache::lonnet::getuploaded('GET',$url,$cdom,$cnum,\$content,$rtncode); if ($repstatus eq 'ok') { if ($url =~ /\.html?$/i) { - &extract_media(\$content,$count,$tempexport,$href,'uploaded'); + &extract_media($url,$cdom,$cnum,\$content,$count,$tempexport,$href,$message,'uploaded'); } } else { - $$message = 'Could not render '.$url.' server message - '.$rtncode; + $$message = 'Could not render '.$url.' server message - '.$rtncode."
\n"; } } elsif ($caller eq 'noedit') { # Need to render the resource without the LON-CAPA Internal header and the Post discussion footer, and then set $content equal to this. @@ -775,23 +790,85 @@ sub replicate_content { } close($copiedfile); } else { - $$message = 'Could not open destination file for '.$filename."\n"; + $$message = 'Could not open destination file for '.$filename."
\n"; } } else { - $$message = 'Could not determine name of file for '.$symb."\n"; + $$message = 'Could not determine name of file for '.$symb."
\n"; } if ($repstatus eq 'ok') { - $content_name = $count.'/'.$filename; + $content_name = 'resources/'.$count.'/'.$filename; } return $content_name; } sub extract_media { - my ($content,$count,$tempexport,$href,$caller) = @_; -# @$href will contain path to any embedded resources in the content. -# For LON-CAPA problems this would be images. applets etc. -# For uploaded HTML files this would be images etc. -# paths will be in the form $count/res/$file, and urls in the $content will be rewritten with the new paths. + my ($url,$cdom,$cnum,$content,$count,$tempexport,$href,$message,$caller) = @_; + my ($dirpath,$container); + my %allfiles = (); + my %codebase = (); + if ($url =~ m-(.*/)([^/]+)$-) { + $dirpath = $1; + $container = $2; + } else { + $dirpath = $url; + $container = ''; + } + &Apache::lonnet::extract_embedded_items(undef,undef,\%allfiles,\%codebase,$content); + foreach my $embed_file (keys(%allfiles)) { + my $filename; + if ($embed_file =~ m#([^/]+)$#) { + $filename = $1; + } else { + $filename = $embed_file; + } + my $newname = 'res/'.$filename; + my ($rtncode,$embed_content,$repstatus); + my $embed_url; + if ($embed_file =~ m-^/-) { + $embed_url = $embed_file; # points to absolute path + } else { + if ($embed_file =~ m-https?://-) { + next; # points to url + } else { + $embed_url = $dirpath.$embed_file; # points to relative path + } + } + if ($caller eq 'resource') { + my $respath = $Apache::lonnet::perlvar{'lonDocRoot'}.'/res'; + my $embed_path = &Apache::lonnet::filelocation($respath,$embed_url); + $embed_content = &Apache::lonnet::getfile($embed_path); + unless ($embed_content eq -1) { + $repstatus = 'ok'; + } + } elsif ($caller eq 'uploaded') { + + $repstatus = &Apache::lonnet::getuploaded('GET',$embed_url,$cdom,$cnum,\$embed_content,$rtncode); + } + if ($repstatus eq 'ok') { + my $destination = $tempexport.'/resources/'.$count.'/res'; + if (!-e "$destination") { + mkdir($destination,0755); + } + $destination .= '/'.$filename; + my $copiedfile; + if ($copiedfile = Apache::File->new('>'.$destination)) { + print $copiedfile $embed_content; + push @{$href}, 'resources/'.$count.'/res/'.$filename; + my $attrib_regexp = ''; + if (@{$allfiles{$embed_file}} > 1) { + $attrib_regexp = join('|',@{$allfiles{$embed_file}}); + } else { + $attrib_regexp = $allfiles{$embed_file}[0]; + } + $$content =~ s#($attrib_regexp\s*=\s*['"]?)\Q$embed_file\E(['"]?)#$1$newname$2#gi; + if ($caller eq 'resource' && $container =~ /\.(problem|library)$/) { + $$content =~ s#\Q$embed_file\E#$newname#gi; + } + } + } else { + $$message .= 'replication of embedded file - '.$embed_file.' in '.$url.' failed, reason -'.$rtncode."
\n"; + } + } return; } @@ -812,9 +889,9 @@ sub store_template { close($storetemplate); } if ($content_type eq 'external') { - return $count.'/'.$content_type.'.html'; + return 'resources/'.$count.'/'.$content_type.'.html'; } else { - return $count.'/'.$content_type.'.xml'; + return 'resources/'.$count.'/'.$content_type.'.xml'; } } } @@ -840,8 +917,7 @@ sub group_import { ''."\n". ''; $env{'form.output'}=$newmapstr; - my $home=&Apache::lonnet::homeserver($coursenum,$coursedom); - my $result=&Apache::lonnet::finishuserfileupload($coursenum,$coursedom,$home, + my $result=&Apache::lonnet::finishuserfileupload($coursenum,$coursedom, 'output',$1.$2); if ($result != m|^/uploaded/|) { $errtext.='Map not saved: A network error occured when trying to save the new map. '; @@ -904,7 +980,7 @@ sub breadcrumbs { } sub editor { - my ($r,$coursenum,$coursedom,$folder,$allowed)=@_; + my ($r,$coursenum,$coursedom,$folder,$allowed,$upload_output)=@_; my $errtext=''; my $fatal=0; my $container='sequence'; @@ -1032,54 +1108,17 @@ sub editor { } } -# upload a file, if present - if (($env{'form.uploaddoc.filename'}) && - ($env{'form.cmd'}=~/^upload_(\w+)/)) { - if ( ($folder=~/^$1/) || ($1 eq 'default') ) { - my $destination = 'docs/'; - if ($folder eq 'default') { - $destination .= 'default/'; - } elsif ($folder =~ /^default_(\d+)$/) { - $destination .= $1.'/'; - } -# this is for a course, not a user, so set coursedoc flag -# probably the only place in the system where this should be "1" - - my $newidx=&Apache::lonratedt::getresidx(); - $destination .= $newidx; - my $url=&Apache::lonnet::userfileupload('uploaddoc',1,$destination); - - my $ext='false'; - if ($url=~/^http\:\/\//) { $ext='true'; } - $url=~s/\:/\:/g; - my $comment=$env{'form.comment'}; - $comment=~s/\/\>\;/g; - $comment=~s/\:/\:/g; - if ($folder=~/^supplemental/) { - $comment=time.'___&&&___'.$env{'user.name'}.'___&&&___'. - $env{'user.domain'}.'___&&&___'.$comment; - } - $Apache::lonratedt::resources[$newidx]= - $comment.':'.$url.':'.$ext.':normal:res'; - $Apache::lonratedt::order[$#Apache::lonratedt::order+1]= - $newidx; - - ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container); - if ($fatal) { - $r->print('

'.$errtext.'

'); - return; - } - } - } + $r->print($upload_output); if ($env{'form.cmd'}) { my ($cmd,$idx)=split(/\_/,$env{'form.cmd'}); if ($cmd eq 'del') { my (undef,$url)=split(':',$Apache::lonratedt::resources[$Apache::lonratedt::order[$idx]]); - if ($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) { + if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) && + ($url!~/\.(page|sequence|problem|exam|quiz|assess|survey|form|library|task)$/)) { &Apache::lonnet::removeuploadedurl($url); + } else { + &Apache::lonratedt::makezombie($Apache::lonratedt::order[$idx]); } - &Apache::lonratedt::makezombie($Apache::lonratedt::order[$idx]); for (my $i=$idx;$i<$#Apache::lonratedt::order;$i++) { $Apache::lonratedt::order[$i]= $Apache::lonratedt::order[$i+1]; @@ -1176,6 +1215,8 @@ sub editor { $r->print(''); foreach (@Apache::lonratedt::order) { my ($name,$url)=split(/\:/,$Apache::lonratedt::resources[$_]); + $name=&Apache::lonratsrv::qtescape($name); + $url=&Apache::lonratsrv::qtescape($url); unless ($name) { $name=(split(/\//,$url))[-1]; } unless ($name) { $idx++; next; } $r->print(&entryline($idx,$name,$url,$folder,$allowed,$_,$coursenum)); @@ -1212,6 +1253,135 @@ FOLDERINFO } } +sub process_file_upload { + my ($upload_output,$coursenum,$coursedom,$allfiles,$codebase,$uploadcmd) = @_; +# upload a file, if present + my $parseaction; + if ($env{'form.parserflag'}) { + $parseaction = 'parse'; + } + my $phase_status; + my $folder=$env{'form.folder'}; + if ($folder eq '') { + $folder='default'; + } + if ( ($folder=~/^$uploadcmd/) || ($uploadcmd eq 'default') ) { + my $errtext=''; + my $fatal=0; + my $container='sequence'; + if ($env{'form.pagepath'}) { + $container='page'; + } + ($errtext,$fatal)= + &mapread($coursenum,$coursedom,$folder.'.'.$container); + if ($#Apache::lonratedt::order<1) { + $Apache::lonratedt::order[0]=1; + $Apache::lonratedt::resources[1]=''; + } + if ($fatal) { + return 'failed'; + } + my $destination = 'docs/'; + if ($folder =~ /^supplemental/) { + $destination = 'supplemental/'; + } + if (($folder eq 'default') || ($folder eq 'supplemental')) { + $destination .= 'default/'; + } elsif ($folder =~ /^(default|supplemental)_(\d+)$/) { + $destination .= $2.'/'; + } +# this is for a course, not a user, so set coursedoc flag +# probably the only place in the system where this should be "1" + my $newidx=&Apache::lonratedt::getresidx(); + $destination .= $newidx; + my $url=&Apache::lonnet::userfileupload('uploaddoc',1,$destination, + $parseaction,$allfiles, + $codebase); + my $ext='false'; + if ($url=~/^http\:\/\//) { $ext='true'; } + $url=~s/\:/\:/g; + my $comment=$env{'form.comment'}; + $comment=~s/\/\>\;/g; + $comment=~s/\:/\:/g; + if ($folder=~/^supplemental/) { + $comment=time.'___&&&___'.$env{'user.name'}.'___&&&___'. + $env{'user.domain'}.'___&&&___'.$comment; + } + + $Apache::lonratedt::resources[$newidx]= + $comment.':'.$url.':'.$ext.':normal:res'; + $Apache::lonratedt::order[$#Apache::lonratedt::order+1]= $newidx; + ($errtext,$fatal)=&storemap($coursenum,$coursedom, + $folder.'.'.$container); + if ($fatal) { + $$upload_output .= '

'.$errtext.'

'; + return 'failed'; + } else { + if ($parseaction eq 'parse') { + my $total_embedded = keys(%{$allfiles}); + if ($total_embedded > 0) { + my $num = 0; + $$upload_output .= 'This file contains embedded multimedia objects, which need to be uploaded to LON-CAPA.
+ + + + + '; + $$upload_output .= 'Upload embedded files:
+
'; + foreach my $embed_file (keys(%{$allfiles})) { + $$upload_output .= ''; + $num ++; + } + $phase_status = 'phasetwo'; + $$upload_output .= '
'.$embed_file. + ' + '; + my $attrib; + if (@{$$allfiles{$embed_file}} > 1) { + $attrib = join(':',@{$$allfiles{$embed_file}}); + } else { + $attrib = $$allfiles{$embed_file}[0]; + } + $$upload_output .= + ''; + if (exists($$codebase{$embed_file})) { + $$upload_output .= + ''; + } + $$upload_output .= '

+ + '; + } else { + $$upload_output .= 'No embedded items identified
'; + } + } + } + } + return $phase_status; +} + +sub process_secondary_uploads { + my ($upload_output,$coursedom,$coursenum,$formname,$num,$newidx) = @_; + my $folder=$env{'form.folder'}; + my $destination = 'docs/'; + if ($folder =~ /^supplemental/) { + $destination = 'supplemental/'; + } + if (($folder eq 'default') || ($folder eq 'supplemental')) { + $destination .= 'default/'; + } elsif ($folder =~ /^(default|supplemental)_(\d+)$/) { + $destination .= $2.'/'; + } + $destination .= $newidx; + my ($url,$filename); + $url=&Apache::lonnet::userfileupload($formname.$num,1,$destination); + ($filename) = ($url =~ m-^/uploaded/$coursedom/$coursenum/$destination/(.+)$-); + return $filename; +} + # --------------------------------------------------------------- An entry line sub entryline { @@ -1283,7 +1453,24 @@ sub entryline { 'ct' => 'Cut', 'rn' => 'Rename', 'cp' => 'Copy'); + my $nocopy=0; + if ($url=~/\.(page|sequence)$/) { + foreach (&Apache::lonsequence::attemptread(&Apache::lonnet::filelocation('',$url))) { + my ($title,$url,$ext,$type)=split(/\:/,$_); + if (($url=~/\.(page|sequence)/) && ($type ne 'zombie')) { + $nocopy=1; + last; + } + } + } + my $copylink=' '; if ($env{'form.pagepath'}) { + unless ($nocopy) { + $copylink=(< +$lt{'cp'} +ENDCOPY + } $line.=(< @@ -1307,10 +1494,15 @@ sub entryline { $lt{'ct'} $lt{'rn'} - -$lt{'cp'} +$copylink END } else { + unless ($nocopy) { + $copylink=(< +$lt{'cp'} +ENDCOPY + } $line.=(< @@ -1333,8 +1525,7 @@ END $lt{'ct'} $lt{'rn'} - -$lt{'cp'} +$copylink END } } @@ -1364,7 +1555,7 @@ END &Apache::lonnet::allowuploaded('/adm/coursedoc',$url); } } - $url=~s/^http\&colon\;\/\//\/adm\/wrapper\/ext\//; + $url=~s-^http(\&colon\;|:)//-/adm/wrapper/ext/-; if ((!$isfolder) && ($residx) && ($folder!~/supplemental/) && (!$ispage)) { my $symb=&Apache::lonnet::symbclean( &Apache::lonnet::declutter('uploaded/'. @@ -1397,7 +1588,7 @@ END } } my $parameterset=' '; - if ($isfolder) { + if ($isfolder || $extension eq 'sequence') { my $foldername=&Apache::lonnet::escape($foldertitle); my $folderpath=$env{'form.folderpath'}; if ($folderpath) { $folderpath.='&' }; @@ -1431,7 +1622,7 @@ END } $line.=''. - "$title"; + "$title"; if (($allowed) && ($folder!~/^supplemental/)) { my %lt=&Apache::lonlocal::texthash( 'hd' => 'Hidden', @@ -1551,6 +1742,24 @@ sub checkonthis { # +# ----------------------------------------------------------------- List Symbs +# +sub list_symbs { + my $r=shift; + my $html=&Apache::lonxml::xmlbegin(); + $r->print($html.'Symb List'. + &Apache::loncommon::bodytag('Symb List')); + my $navmap = Apache::lonnavmaps::navmap->new(); + $r->print("
\n");
+   foreach my $res ($navmap->retrieveResources()) {
+       $r->print($res->compTitle()."\t".$res->symb()."\n");
+   }
+   $r->print("\n
\n"); + $r->print(''.&mt('Return to DOCS').''); +} + + +# # -------------------------------------------------------------- Verify Content # sub verifycontent { @@ -1582,8 +1791,15 @@ sub verifycontent { &mt('Return to DOCS').''); } + # -------------------------------------------------------------- Check Versions +sub devalidateversioncache { + my $src=shift; + &Apache::lonnet::devalidate_cache_new('courseresversion',$env{'request.course.id'}.'_'. + &Apache::lonnet::clutter($src)); +} + sub checkversions { my $r=shift; my $html=&Apache::lonxml::xmlbegin(); @@ -1610,6 +1826,7 @@ sub checkversions { foreach (keys %hash) { if ($_=~/^ids\_(\/res\/.+)$/) { $newsetversions{$1}='mostrecent'; + &devalidateversioncache($1); } } } elsif ($env{'form.setcurrent'}) { @@ -1619,6 +1836,7 @@ sub checkversions { my $getvers=&Apache::lonnet::getversion($1); if ($getvers>0) { $newsetversions{$1}=$getvers; + &devalidateversioncache($1); } } } @@ -1629,6 +1847,7 @@ sub checkversions { my $src=$1; if (($env{$_}) && ($env{$_} ne $setversions{$src})) { $newsetversions{$src}=$env{$_}; + &devalidateversioncache($src); } } } @@ -1858,22 +2077,22 @@ sub changewarning { if (defined($env{'form.pagepath'})) { $pathvar='pagepath'; $path=&Apache::lonnet::escape($env{'form.pagepath'}); - $path.='&symb='.&Apache::lonnet::escape($env{'form.pagesymb'}); + $path.='&pagesymb='.&Apache::lonnet::escape($env{'form.pagesymb'}); } $url='/adm/coursedocs?'.$pathvar.'='.$path; } if (!defined($message)) { $message='Changes will become active for your current session after [_1], or the next time you log in.'; } - $r->print( -''. -'
'. + $r->print("\n\n". +''."\n". +''. '

'. &mt($message,' '). -$help{'Caching'}.'

'); +$help{'Caching'}.''."\n\n"); } # ================================================================ Main Handler @@ -1884,14 +2103,14 @@ sub handler { return OK if $r->header_only; # --------------------------------------------- Initialize help topics for this - foreach ('Adding_Course_Doc','Main_Course_Documents', - 'Adding_External_Resource','Navigate_Content', - 'Adding_Folders','Docs_Overview', 'Load_Map', - 'Supplemental','Score_Upload_Form','Adding_Pages', - 'Importing_LON-CAPA_Resource','Uploading_From_Harddrive', - 'Check_Resource_Versions','Verify_Content') { - $help{$_}=&Apache::loncommon::help_open_topic('Docs_'.$_); - } + foreach ('Adding_Course_Doc','Main_Course_Documents', + 'Adding_External_Resource','Navigate_Content', + 'Adding_Folders','Docs_Overview', 'Load_Map', + 'Supplemental','Score_Upload_Form','Adding_Pages', + 'Importing_LON-CAPA_Resource','Uploading_From_Harddrive', + 'Check_Resource_Versions','Verify_Content') { + $help{$_}=&Apache::loncommon::help_open_topic('Docs_'.$_); + } # Composite help files $help{'Syllabus'} = &Apache::loncommon::help_open_topic( 'Docs_About_Syllabus,Docs_Editing_Templated_Pages'); @@ -1905,13 +2124,18 @@ sub handler { 'Docs_About_My_Personal_Info,Docs_Editing_Templated_Pages'); $help{'Caching'} = &Apache::loncommon::help_open_topic('Caching'); - if ($env{'form.verify'}) { +# does this user have privileges to modify docs + my $allowed=&Apache::lonnet::allowed('mdc',$env{'request.course.id'}); + + if ($allowed && $env{'form.verify'}) { &verifycontent($r); - } elsif ($env{'form.versions'}) { + } elsif ($allowed && $env{'form.listsymbs'}) { + &list_symbs($r); + } elsif ($allowed && $env{'form.versions'}) { &checkversions($r); - } elsif ($env{'form.dumpcourse'}) { + } elsif ($allowed && $env{'form.dumpcourse'}) { &dumpcourse($r); - } elsif ($env{'form.exportcourse'}) { + } elsif ($allowed && $env{'form.exportcourse'}) { &exportcourse($r); } else { # is this a standard course? @@ -1920,7 +2144,6 @@ sub handler { my $forcestandard = 0; my $forcesupplement; my $script=''; - my $allowed; my $events=''; my $showdoc=0; my $containertag; @@ -1946,13 +2169,11 @@ sub handler { } unless ($showdoc) { # got called from remote if (($env{'form.folder'}=~/^default_/) || - ($env{'form.folder'} =~ m#^\d+/(pages|sequences)/#)) { + ($env{'form.folder'} =~ m:^\d+/(pages|sequences)/:)) { $forcestandard = 1; } $forcesupplement=($env{'form.folder'}=~/^supplemental_/); -# does this user have privileges to post, etc? - $allowed=&Apache::lonnet::allowed('mdc',$env{'request.course.id'}); if ($allowed) { &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['cmd']); $script=&Apache::lonratedt::editscript('simple'); @@ -2118,7 +2339,7 @@ function removeres(folderpath,index,oldt } function cutres(folderpath,index,oldtitle,container,pagesymb) { - if (confirm('WARNING: Cutting a resource makes associated grades and scores inaccessible,\\neven if it is pasted in again elsewhere!\\nCut "'+oldtitle+'"?')) { + if (confirm('WARNING: Cutting a resource makes associated grades and scores inaccessible!\\nGrades remain inaccessible if resource is pasted into another folder.\\nCut "'+oldtitle+'"?')) { this.document.forms.renameform.cmd.value='cut_'+index; this.document.forms.renameform.markcopy.value=index; if (container == 'sequence') { @@ -2153,7 +2374,89 @@ ENDNEWSCRIPT &Apache::loncommon::bodytag('Course Documents','',$events, '','',$showdoc). &Apache::loncommon::help_open_menu('','','','',273,'RAT')); - unless ($showdoc) { + my %allfiles = (); + my %codebase = (); + my ($upload_result,$upload_output); + if ($allowed) { + if (($env{'form.uploaddoc.filename'}) && ($env{'form.cmd'}=~/^upload_(\w+)/)) { +# Process file upload - phase one - upload and parse primary file. + $upload_result = &process_file_upload(\$upload_output,$coursenum, + $coursedom,\%allfiles, + \%codebase,$1); + if ($upload_result eq 'phasetwo') { + $r->print($upload_output); + } + } elsif ($env{'form.phasetwo'}) { + my %newname = (); + my %origname = (); + my %attribs = (); + my $updateflag = 0; + my $residx = $env{'form.newidx'}; + my $primary_url = &Apache::lonnet::unescape($env{'form.primaryurl'}); +# Process file upload - phase two - gather secondary files. + for (my $i=0; $i<$env{'form.phasetwo'}; $i++) { + if ($env{'form.embedded_item_'.$i.'.filename'}) { + my $javacodebase; + $newname{$i} = &process_secondary_uploads(\$upload_output,$coursedom,$coursenum,'embedded_item_',$i,$residx); + $origname{$i} = &Apache::lonnet::unescape($env{'form.embedded_orig_'.$i}); + if (exists($env{'form.embedded_codebase_'.$i})) { + $javacodebase = &Apache::lonnet::unescape($env{'form.embedded_codebase_'.$i}); + $origname{$i} =~ s#^\Q$javacodebase\E/##; + } + my @attributes = (); + if ($env{'form.embedded_attrib_'.$i} =~ /:/) { + @attributes = split/:/,$env{'form.embedded_attrib_'.$i}; + } else { + @attributes = ($env{'form.embedded_attrib_'.$i}); + } + foreach (@attributes) { + push(@{$attribs{$i}},&Apache::lonnet::unescape($_)); + } + if ($javacodebase) { + $codebase{$i} = $javacodebase; + $codebase{$i} =~ s#/$##; + $updateflag = 1; + } + } + unless ($newname{$i} eq $origname{$i}) { + $updateflag = 1; + } + } +# Process file upload - phase three - modify primary file + if ($updateflag) { + my ($content,$rtncode); + my $updateflag = 0; + my $getstatus = &Apache::lonnet::getuploaded('GET',$primary_url,$coursedom,$coursenum,\$content,\$rtncode); + if ($getstatus eq 'ok') { + foreach my $item (keys %newname) { + if ($newname{$item} ne $origname{$item}) { + my $attrib_regexp = ''; + if (@{$attribs{$item}} > 1) { + $attrib_regexp = join('|',@{$attribs{$item}}); + } else { + $attrib_regexp = $attribs{$item}[0]; + } + if ($content =~ m#($attrib_regexp\s*=\s*['"]?)\Q$origname{$item}\E(['"]?)#) { + } + $content =~ s#($attrib_regexp\s*=\s*['"]?)\Q$origname{$item}\E(['"]?)#$1$newname{$item}$2#gi; + } + if (exists($codebase{$item})) { + $content =~ s/(codebase\s*=\s*["']?)\Q$codebase{$item}\E(["']?)/$1.$2/i; + } + } +# Save edited file. + my $saveresult; + my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'}; + my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'}; + my $url = &Apache::lonnet::store_edited_file($primary_url,$content,$docudom,$docuname,\$saveresult); + } else { + &Apache::lonnet::logthis('retrieval of uploaded file - '.$primary_url.' - for editing, failed: '.$getstatus); + } + } + } + } + + unless ($showdoc || $upload_result eq 'phasetwo') { # ----------------------------------------------------------------------------- my %lt=&Apache::lonlocal::texthash( 'uplm' => 'Upload a new main course document', @@ -2167,6 +2470,7 @@ ENDNEWSCRIPT 'impo' => 'Import', 'selm' => 'Select Map', 'load' => 'Load Map', + 'reco' => 'Recover Deleted Resources', 'newf' => 'New Folder', 'newp' => 'New Composite Page', 'extr' => 'External Resource', @@ -2181,7 +2485,8 @@ ENDNEWSCRIPT 'imsf' => 'Import IMS package', 'file' => 'File', 'title' => 'Title', - 'comment' => 'Comment' + 'comment' => 'Comment', + 'parse' => 'If HTML file, upload embedded images/multimedia files' ); # ----------------------------------------------------------------------------- if ($allowed) { @@ -2190,6 +2495,7 @@ ENDNEWSCRIPT my %lt=&Apache::lonlocal::texthash( 'vc' => 'Verify Content', 'cv' => 'Check/Set Resource Versions', + 'ls' => 'List Symbs', ); my $folderpath=$env{'form.folderpath'}; @@ -2224,6 +2530,8 @@ $uploadtag $help{'Check_Resource_Versions'} $dumpbut $exportbut + + ENDCOURSEVERIFY @@ -2248,7 +2556,7 @@ ENDCOURSEVERIFY #$postexec='self.close();'; } $hadchanges=0; - &editor($r,$coursenum,$coursedom,$folder,$allowed); + &editor($r,$coursenum,$coursedom,$folder,$allowed,$upload_output); if ($hadchanges) { &mark_hash_old() } @@ -2257,7 +2565,11 @@ ENDCOURSEVERIFY '.sequence'; my $pageseq = '/uploaded/'.$coursedom.'/'.$coursenum.'/default_'.time. '.page'; - + my $container='sequence'; + if ($env{'form.pagepath'}) { + $container='page'; + } + my $readfile='/uploaded/'.$coursedom.'/'.$coursenum.'/'.$folder.'.'.$container; $r->print(< $lt{'uplm'} @@ -2273,6 +2585,14 @@ $lt{'title'}:
$uploadtag +
+ + + +
+
$help{'Uploading_From_Harddrive'} @@ -2298,6 +2618,10 @@ value="$lt{'selm'}"> + + ENDFORM unless ($env{'form.pagepath'}) { $r->print(< $help{'Adding_External_Resource'} -
+
@@ -2320,7 +2644,7 @@ ENDFORM $r->print(''); unless ($env{'form.pagepath'}) { $r->print(< +
@@ -2329,7 +2653,7 @@ onClick="javascript:makenewfolder(this.f value="$lt{'newf'}" />$help{'Adding_Folders'} -
+
@@ -2338,7 +2662,7 @@ onClick="javascript:makenewpage(this.for value="$lt{'newp'}" />$help{'Adding_Pages'}
-
+
$uploadtag @@ -2347,7 +2671,7 @@ value="Syllabus=/public/$coursedom/$cour $help{'Syllabus'}
-
+
$uploadtag @@ -2356,7 +2680,7 @@ value="Navigate Content=/adm/navmaps"> $help{'Navigate_Content'}
-
+
$uploadtag @@ -2364,7 +2688,7 @@ $uploadtag onClick="javascript:makesmppage();" /> $help{'Simple Page'}
-
+
$uploadtag @@ -2372,7 +2696,7 @@ $uploadtag onClick="javascript:makesmpproblem();" />$help{'Simple Problem'}
-
+
$uploadtag @@ -2381,7 +2705,7 @@ onClick="javascript:makeexamupload();" / $help{'Score_Upload_Form'}
-
+
$uploadtag @@ -2390,7 +2714,7 @@ onClick="javascript:makebulboard();" /> $help{'Bulletin Board'}
-
+
$uploadtag @@ -2399,7 +2723,7 @@ value="$plainname=/adm/$udom/$uname/abou $help{'My Personal Info'}
-
+
$uploadtag @@ -2419,7 +2743,7 @@ $uploadtag onClick="javascript:makesmpproblem();" />$help{'Simple Problem'}
-
+
$uploadtag @@ -2462,7 +2786,15 @@ ENDBLOCK -
$lt{'comment'}:
+
+
+
+ + +

+$lt{'comment'}:

@@ -2484,7 +2816,7 @@ onClick="javascript:makenewfolder(this.f value="$lt{'newf'}" /> $help{'Adding_Folders'}
-
+
@@ -2493,7 +2825,7 @@ onClick="javascript:makenewext('supnewex value="$lt{'extr'}" /> $help{'Adding_External_Resource'}
-
+
@@ -2502,7 +2834,7 @@ value="Syllabus=/public/$coursedom/$cour $help{'Syllabus'}
-
+
@@ -2521,11 +2853,13 @@ ENDSUPFORM } $r->print(''); } else { + unless ($upload_result eq 'phasetwo') { # -------------------------------------------------------- This is showdoc mode - $r->print("

".&mt('Uploaded Document').' - '. + $r->print("

".&mt('Uploaded Document').' - '. &Apache::lonnet::gettitle($r->uri).'

'. &mt('It is recommended that you use an up-to-date virus scanner before handling this file.')."

". - &entryline(0,&mt("Click to download or use your browser's Save Link function"),$showdoc).'

'); + &entryline(0,&mt("Click to download or use your browser's Save Link function"),$showdoc).'

'); + } } } $r->print('');