--- loncom/interface/londocs.pm 2007/07/12 01:04:36 1.288 +++ loncom/interface/londocs.pm 2007/07/13 23:08:07 1.291 @@ -1,7 +1,7 @@ # The LearningOnline Network # Documents # -# $Id: londocs.pm,v 1.288 2007/07/12 01:04:36 albertel Exp $ +# $Id: londocs.pm,v 1.291 2007/07/13 23:08:07 albertel Exp $ # # Copyright Michigan State University Board of Trustees # @@ -1242,6 +1242,52 @@ ENDPASTE $r->print('

'); } +sub do_paste_from_buffer { + my ($coursenum,$coursedom,$folder,$container) = @_; +# paste resource to end of list + my $url=&LONCAPA::map::qtescape($env{'docs.markedcopy_url'}); + my $title=&LONCAPA::map::qtescape($env{'docs.markedcopy_title'}); +# Maps need to be copied first + if (($url=~/\.(page|sequence)$/) && ($url=~/^\/uploaded\//)) { + $title=&mt('Copy of').' '.$title; + my $newid=$$.time; + $url=~/^(.+)\.(\w+)$/; + my $newurl=$1.$newid.'.'.$2; + my $storefn=$newurl; + $storefn=~s{^/\w+/$match_domain/$match_username/}{}; + &Apache::lonclonecourse::writefile($env{'request.course.id'},$storefn, + &Apache::lonnet::getfile($url)); + $url = $newurl; + } +# published maps can only exists once, so remove it from paste buffer when done + if (($url=~/\.(page|sequence)$/) && ($url=~m {^/res/})) { + &Apache::lonnet::delenv('docs\\.markedcopy'); + } + if ($url=~ m{/smppg$}) { + my $db_name = &Apache::lonsimplepage::get_db_name($url); + if ($db_name =~ /^smppage_/) { + #simple pages, need to copy the db contents to a new one. + my %contents=&Apache::lonnet::dump($db_name,$coursedom,$coursenum); + my $now = time(); + $db_name =~ s{_\d*$ }{_$now}x; + my $result=&Apache::lonnet::put($db_name,\%contents, + $coursedom,$coursenum); + $url =~ s{/(\d*)/smppg$ }{/$now/smppg}x; + $title=&mt('Copy of').' '.$title; + } + } + $title = &LONCAPA::map::qtunescape($title); + my $ext='false'; + if ($url=~m{^http(|s)://}) { $ext='true'; } + $url = &LONCAPA::map::qtunescape($url); +# Now insert the URL at the bottom + my $newidx = &LONCAPA::map::getresidx($url); + $LONCAPA::map::resources[$newidx]= $title.':'.$url.':'.$ext.':normal:res'; + push(@LONCAPA::map::order, $newidx); +# Store the result + return &storemap($coursenum,$coursedom,$folder.'.'.$container); +} + sub editor { my ($r,$coursenum,$coursedom,$folder,$allowed,$upload_output,$which)=@_; my $errtext=''; @@ -1348,38 +1394,13 @@ sub editor { } if ($env{'form.pastemarked'}) { -# paste resource to end of list - my $url=&LONCAPA::map::qtescape($env{'docs.markedcopy_url'}); - my $title=&LONCAPA::map::qtescape($env{'docs.markedcopy_title'}); -# Maps need to be copied first - if (($url=~/\.(page|sequence)$/) || ($url=~/^\/uploaded\//)) { - $title=&mt('Copy of').' '.$title; - my $newid=$$.time; - $url=~/^(.+)\.(\w+)$/; - my $newurl=$1.$newid.'.'.$2; - my $storefn=$newurl; - $storefn=~s{^/\w+/$match_domain/$match_username/}{}; - &Apache::lonclonecourse::writefile - ($env{'request.course.id'},$storefn, - &Apache::lonnet::getfile($url)); - $url=$newurl; - } - $title = &LONCAPA::map::qtunescape($title); - my $ext='false'; - if ($url=~m{^http(|s)://}) { $ext='true'; } - $url = &LONCAPA::map::qtunescape($url); -# Now insert the URL at the bottom - my $newidx=&LONCAPA::map::getresidx($url); - $LONCAPA::map::resources[$newidx]= - $title.':'.$url.':'.$ext.':normal:res'; - $LONCAPA::map::order[1+$#LONCAPA::map::order]=$newidx; -# Store the result - ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container); + my ($errtext,$fatal) = + &do_paste_from_buffer($coursenum,$coursedom,$folder, + $container); if ($fatal) { $r->print('

'.$errtext.'

'); return; } - } $r->print($upload_output); if ($env{'form.cmd'}) { @@ -1771,11 +1792,16 @@ sub entryline { my $nocopy=0; my $nocut=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; + if ($url =~ m{/res/}) { + # no copy for published maps + $nocopy = 1; + } else { + foreach (&Apache::lonsequence::attemptread(&Apache::lonnet::filelocation('',$url))) { + my ($title,$url,$ext,$type)=split(/\:/,$_); + if (($url=~/\.(page|sequence)/) && ($type ne 'zombie')) { + $nocopy=1; + last; + } } } } @@ -1786,6 +1812,18 @@ sub entryline { my $copylink=' '; my $cutlink=' '; + my $skip_confirm = 0; + if ( $folder =~ /^supplemental/ + || ($url =~ m{( /smppg$ + |/syllabus$ + |/aboutme$ + |/navmaps$ + |/bulletinboard$ + |\.html$ + |^/adm/wrapper/ext)}x)) { + $skip_confirm = 1; + } + if (!$nocopy) { $copylink=(<$lt{'cp'} @@ -1793,7 +1831,7 @@ ENDCOPY } if (!$nocut) { $cutlink=(<$lt{'ct'} +$lt{'ct'} ENDCUT } $form_start = (< - $lt{'rm'} + $lt{'rm'} $cutlink $lt{'rn'} $copylink @@ -3237,8 +3275,8 @@ function changename(folderpath,index,old } } -function removeres(folderpath,index,oldtitle,container,pagesymb) { - if (confirm('WARNING: Removing a resource makes associated grades and scores inaccessible!\\nRemove "'+oldtitle+'"?')) { +function removeres(folderpath,index,oldtitle,container,pagesymb,skip_confirm) { + if (skip_confirm || confirm('WARNING: Removing a resource makes associated grades and scores inaccessible!\\nRemove "'+oldtitle+'"?')) { this.document.forms.renameform.markcopy.value=-1; this.document.forms.renameform.cmd.value='del_'+index; if (container == 'sequence') { @@ -3252,8 +3290,8 @@ function removeres(folderpath,index,oldt } } -function cutres(folderpath,index,oldtitle,container,pagesymb,folder) { - if (confirm('WARNING: Cutting a resource makes associated grades and scores inaccessible!\\nGrades remain inaccessible if resource is pasted into another folder.\\nCut "'+oldtitle+'"?')) { +function cutres(folderpath,index,oldtitle,container,pagesymb,folder,skip_confirm) { + if (skip_confirm || 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; this.document.forms.renameform.copyfolder.value=folder+'.'+container;