--- loncom/interface/londocs.pm 2005/06/08 19:36:54 1.180 +++ loncom/interface/londocs.pm 2006/07/20 01:46:14 1.239 @@ -1,7 +1,7 @@ # The LearningOnline Network # Documents # -# $Id: londocs.pm,v 1.180 2005/06/08 19:36:54 raeburn Exp $ +# $Id: londocs.pm,v 1.239 2006/07/20 01:46:14 www Exp $ # # Copyright Michigan State University Board of Trustees # @@ -42,6 +42,8 @@ use HTML::Entities; use GDBM_File; use Apache::lonlocal; use Cwd; +use lib '/home/httpd/lib/perl/'; +use LONCAPA; my $iconpath; @@ -119,16 +121,18 @@ sub authorhosts { sub dumpbutton { my ($home,$other,%outhash)=&authorhosts(); + my $type = &Apache::loncommon::course_type(); if ($home+$other==0) { return ''; } my $output=''; if ($home) { return ''. ''. + &mt('Dump '.$type.' DOCS to Construction Space').'" />'. &Apache::loncommon::help_open_topic('Docs_Dump_Course_Docs'); } else { return''. - &mt('Dump Course DOCS to Construction Space: available on other servers'); + &mt('Dump '.$type. + ' DOCS to Construction Space: available on other servers'); } } @@ -140,10 +144,9 @@ sub clean { # -------------------------------------------------------- Actually dump course sub dumpcourse { - my $r=shift; - my $html=&Apache::lonxml::xmlbegin(); - $r->print($html.'Dump DOCS'. - &Apache::loncommon::bodytag('Dump Course DOCS to Construction Space'). + my ($r) = @_; + my $type = &Apache::loncommon::course_type(); + $r->print(&Apache::loncommon::start_page('Dump '.$type.' DOCS to Construction Space'). '
'); my ($home,$other,%outhash)=&authorhosts(); unless ($home) { return ''; } @@ -166,7 +169,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; @@ -219,7 +225,7 @@ sub dumpcourse { $r->print(''); } my $title=$origcrsdata{'description'}; - $title=~s/\s+/\_/gs; + $title=~s/[\/\s]+/\_/gs; $title=&clean($title); $r->print('

'.&mt('Folder in Construction Space').'


'); &tiehash(); @@ -231,8 +237,10 @@ sub dumpcourse { 'ids_/uploaded/'.$origcrsdata{'domain'}.'/'.$origcrsdata{'num'}.'/'.$_}}; $title=~s/:/:/g; $r->print(''.($title?$title:' ').''); - unless ($title) { + if (!$title) { $title=$_; + } else { + $title=~s|/|_|g; } $title=~s/\.(\w+)$//; $title=&clean($title); @@ -242,22 +250,23 @@ sub dumpcourse { $r->print("\n"); &untiehash(); $r->print( - '

'); + '

'); } } # ------------------------------------------------------ Generate "export" button sub exportbutton { - return ''; + my $type = &Apache::loncommon::course_type(); return ''. ''. - &Apache::loncommon::help_open_topic('Docs_Export_Course_Docs'); + &mt('Export '.$type.' to IMS').'" />'. + &Apache::loncommon::help_open_topic('Docs_Export_Course_Docs'); } sub exportcourse { my $r=shift; + my $type = &Apache::loncommon::course_type(); my %discussiontime = &Apache::lonnet::dump('discussiontimes', $env{'course.'.$env{'request.course.id'}.'.domain'}, $env{'course.'.$env{'request.course.id'}.'.num'}); my $numdisc = keys %discussiontime; @@ -298,7 +307,7 @@ sub exportcourse { open(OUTPUT, "zip -r $imszip * 2> /dev/null |"); close(OUTPUT); chdir $cwd; - $outcome .= 'Download the zip file from IMS course archive
'; + $outcome .= &mt('Download the zip file from IMS '.lc($type).' archive
',$imszipfile,); if ($copyresult) { $outcome .= 'The following errors occurred during export - '.$copyresult; } @@ -306,15 +315,13 @@ sub exportcourse { $outcome = '
Unfortunately you will not be able to retrieve an IMS archive of this posts at this time, because there was a problem creating a manifest file.
'; } } - my $html=&Apache::lonxml::xmlbegin(); - $r->print($html.'Export Course'. - &Apache::loncommon::bodytag('Export course to IMS content package')); + $r->print(&Apache::loncommon::start_page('Export '.lc($type).' to IMS content package')); $r->print($outcome); - $r->print(''); + $r->print(&Apache::loncommon::end_page()); } else { my $display; $display = '
'."\n"; - $display .= 'Choose which items you wish to export from your course.

'; + $display .= &mt('Choose which items you wish to export from your '.$type.'.

'); $display .= ''. '
 Content items'. ' |; - my $html=&Apache::lonxml::xmlbegin(); - $r->print($html.'Export Course'.$scripttag.''. - &Apache::loncommon::bodytag('Export course to IMS content package' -)); - - $r->print($display.'
'. + $r->print(&Apache::loncommon::start_page('Export '.lc($type).' to IMS content package', + $scripttag)); + $r->print($display.''. '

'. '

'); + &mt('Export '.$type.' DOCS').'" />

'. + &Apache::loncommon::end_page()); } } @@ -491,10 +496,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 +558,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 +580,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 +628,6 @@ sub build_package { } } $pkgdepth = $depth; - } else { - $included = 0; } } } @@ -646,7 +662,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 +694,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 +715,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 +764,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 +778,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 +793,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 +892,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 +920,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. '; @@ -877,11 +956,10 @@ sub breadcrumbs { my $folderpath; my $cpinfo=''; if ($env{'form.markedcopy_url'}) { - &Apache::lonnet::logthis('Found '.$env{'form.markedcopy_url'}); $cpinfo='&markedcopy_url='. - &Apache::lonnet::escape($env{'form.markedcopy_url'}). + &escape($env{'form.markedcopy_url'}). '&markedcopy_title='. - &Apache::lonnet::escape($env{'form.markedcopy_title'}); + &escape($env{'form.markedcopy_title'}); } while (@folders) { my $folder=shift(@folders); @@ -889,22 +967,22 @@ sub breadcrumbs { if ($folderpath) {$folderpath.='&';} $folderpath.=$folder.'&'.$foldername; my $url='/adm/coursedocs?folderpath='. - &Apache::lonnet::escape($folderpath); + &escape($folderpath); &Apache::lonhtmlcommon::add_breadcrumb( {'href'=>$url.$cpinfo, - 'title'=>&Apache::lonnet::unescape($foldername), + 'title'=>&unescape($foldername), 'text'=>''. - &Apache::lonnet::unescape($foldername).'' + &unescape($foldername).'' }); } - return &Apache::lonhtmlcommon::breadcrumbs(undef,undef,undef,undef,undef, - 0,'nohelp'); + return &Apache::lonhtmlcommon::breadcrumbs(undef,undef,0,'nohelp', + 'LC_docs_path'); } 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,52 +1110,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::resources+1; - $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]; @@ -1120,6 +1163,8 @@ sub editor { $Apache::lonratedt::order[$idx]]= $comment.':'.join(':',@rrest); } +# Devalidate title cache + &Apache::lonnet::devalidate_title_cache(&unescape($rrest[0])); } # Store the changed version ($errtext,$fatal)=&storemap($coursenum,$coursedom, @@ -1132,11 +1177,12 @@ sub editor { # Group import/search if ($env{'form.importdetail'}) { my @imports; + &Apache::lonnet::logthis("imp detail ".$env{'form.importdetail'}); foreach (split(/\&/,$env{'form.importdetail'})) { if (defined($_)) { my ($name,$url)=split(/\=/,$_); - $name=&Apache::lonnet::unescape($name); - $url=&Apache::lonnet::unescape($url); + $name=&unescape($name); + $url=&unescape($url); push @imports, $name, $url; } } @@ -1149,22 +1195,25 @@ sub editor { } } # Loading a complete map - if (($env{'form.importmap'}) && ($env{'form.loadmap'})) { - foreach (&Apache::lonsequence::attemptread(&Apache::lonnet::filelocation('',$env{'form.importmap'}))) { - my $idx=$#Apache::lonratedt::resources; - $idx++; - $Apache::lonratedt::resources[$idx]=$_; - $Apache::lonratedt::order - [$#Apache::lonratedt::order+1]=$idx; - } - + if ($env{'form.loadmap'}) { + if ($env{'form.importmap'}=~/\w/) { + foreach (&Apache::lonsequence::attemptread(&Apache::lonnet::filelocation('',$env{'form.importmap'}))) { + my ($title,$url,$ext,$type)=split(/\:/,$_); + my $idx=&Apache::lonratedt::getresidx($url); + $Apache::lonratedt::resources[$idx]=$_; + $Apache::lonratedt::order + [$#Apache::lonratedt::order+1]=$idx; + } # Store the changed version - ($errtext,$fatal)=&storemap($coursenum,$coursedom, + ($errtext,$fatal)=&storemap($coursenum,$coursedom, $folder.'.'.$container); - if ($fatal) { - $r->print('

'.$errtext.'

'); - return; - } + if ($fatal) { + $r->print('

'.$errtext.'

'); + return; + } + } else { + $r->print('

'.&mt('No map selected.').'

'); + } } } # ---------------------------------------------------------------- End commands @@ -1174,6 +1223,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)); @@ -1210,13 +1261,142 @@ 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 { my ($index,$title,$url,$folder,$allowed,$residx,$coursenum)=@_; $title=~s/\&colon\;/\:/g; $title=&HTML::Entities::encode(&HTML::Entities::decode( - &Apache::lonnet::unescape($title)),'"<>&\''); + &unescape($title)),'"<>&\''); my $renametitle=$title; my $foldertitle=$title; my $pagetitle=$title; @@ -1228,6 +1408,7 @@ sub entryline { &Apache::loncommon::plainname($2,$3).':
'. $foldertitle; } + $renametitle=~s/\\/\\\\/g; $renametitle=~s/\"\;/\\\"/g; my $line=''; # Edit commands @@ -1235,21 +1416,21 @@ sub entryline { my $folderpath; if ($env{'form.folderpath'}) { $container = 'sequence'; - $folderpath=&Apache::lonnet::escape($env{'form.folderpath'}); + $folderpath=&escape($env{'form.folderpath'}); # $htmlfoldername=&HTML::Entities::encode($env{'form.foldername'},'<>&"'); } my ($pagepath,$pagesymb); if ($env{'form.pagepath'}) { $container = 'page'; - $pagepath=&Apache::lonnet::escape($env{'form.pagepath'}); - $pagesymb=&Apache::lonnet::escape($env{'form.pagesymb'}); + $pagepath=&escape($env{'form.pagepath'}); + $pagesymb=&escape($env{'form.pagesymb'}); } my $cpinfo=''; if ($env{'form.markedcopy_url'}) { $cpinfo='&markedcopy_url='. - &Apache::lonnet::escape($env{'form.markedcopy_url'}). + &escape($env{'form.markedcopy_url'}). '&markedcopy_title='. - &Apache::lonnet::escape($env{'form.markedcopy_title'}); + &escape($env{'form.markedcopy_title'}); } if ($allowed) { my $incindex=$index+1; @@ -1281,7 +1462,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.=(< @@ -1305,10 +1503,15 @@ sub entryline { $lt{'ct'} $lt{'rn'} - -$lt{'cp'} +$copylink END } else { + unless ($nocopy) { + $copylink=(< +$lt{'cp'} +ENDCOPY + } $line.=(< @@ -1331,8 +1534,7 @@ END $lt{'ct'} $lt{'rn'} - -$lt{'cp'} +$copylink END } } @@ -1362,7 +1564,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/'. @@ -1386,21 +1588,21 @@ END } elsif ($url=~m|^/ext/|) { $url='/adm/wrapper'.$url; } - $url.=(($url=~/\?/)?'&':'?').'symb='.&Apache::lonnet::escape($symb); + $url.=(($url=~/\?/)?'&':'?').'symb='.&escape($symb); if ($container eq 'page') { my $symb=$env{'form.pagesymb'}; $url=&Apache::lonnet::clutter((&Apache::lonnet::decode_symb($symb))[2]); - $url.=(($url=~/\?/)?'&':'?').'symb='.&Apache::lonnet::escape($symb); + $url.=(($url=~/\?/)?'&':'?').'symb='.&escape($symb); } } my $parameterset=' '; - if ($isfolder) { - my $foldername=&Apache::lonnet::escape($foldertitle); + if ($isfolder || $extension eq 'sequence') { + my $foldername=&escape($foldertitle); my $folderpath=$env{'form.folderpath'}; if ($folderpath) { $folderpath.='&' }; $folderpath.=$folderarg.'&'.$foldername; - $url.='folderpath='.&Apache::lonnet::escape($folderpath).$cpinfo; + $url.='folderpath='.&escape($folderpath).$cpinfo; $parameterset='