--- loncom/interface/londocs.pm 2007/01/05 16:40:27 1.265 +++ loncom/interface/londocs.pm 2007/06/29 21:08:07 1.280 @@ -1,7 +1,7 @@ # The LearningOnline Network # Documents # -# $Id: londocs.pm,v 1.265 2007/01/05 16:40:27 albertel Exp $ +# $Id: londocs.pm,v 1.280 2007/06/29 21:08:07 albertel Exp $ # # Copyright Michigan State University Board of Trustees # @@ -235,7 +235,6 @@ sub dumpcourse { my ($ext)=($_=~/\.(\w+)$/); my $title=$hash{'title_'.$hash{ 'ids_/uploaded/'.$origcrsdata{'domain'}.'/'.$origcrsdata{'num'}.'/'.$_}}; - $title=~s/:/:/g; $r->print(''.($title?$title:' ').''); if (!$title) { $title=$_; @@ -905,15 +904,16 @@ sub store_template { # Imports the given (name, url) resources into the course # coursenum, coursedom, and folder must precede the list sub group_import { - my $coursenum = shift; - my $coursedom = shift; - my $folder = shift; - my $container = shift; - my $caller = shift; - while (@_) { - my $name = shift; - my $url = shift; - if (($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E/(default_\d+\.)(page|sequence)$}) && ($caller eq 'londocs')) { + my ($coursenum, $coursedom, $folder, $container, $caller, @files) = @_; + + while (@files) { + my $name = shift(@files); + my $url = shift(@files); + #FIXME check if file exists before overwriting, might be restoring it + if (($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E/(default_\d+\.)(page|sequence)$}) + && ($caller eq 'londocs') + && (!&Apache::lonnet::stat_file($url))) { + my $errtext = ''; my $fatal = 0; my $newmapstr = ''."\n". @@ -937,8 +937,8 @@ sub group_import { $LONCAPA::map::order[$#LONCAPA::map::order+1]=$idx; my $ext = 'false'; if ($url=~m{^http://} || $url=~m{^https://}) { $ext = 'true'; } - $url =~ s/:/\:/g; - $name =~ s/:/\:/g; + $url = &LONCAPA::map::qtunescape($url); + $name = &LONCAPA::map::qtunescape($name); $LONCAPA::map::resources[$idx] = join ':', ($name, $url, $ext, 'normal', 'res'); } @@ -988,7 +988,8 @@ sub breadcrumbs { {'href'=>$url.$cpinfo, 'title'=>$name, 'text'=>''. - $name.'' + $name.'', + 'no_mt'=>1, }); $plain.=$name.' > '; } @@ -1154,7 +1155,7 @@ sub docs_change_log { for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) { my $oldname=(split(/\:/,$docslog{$id}{'logentry'}{'before_resources_'.$idx}))[0]; my $newname=(split(/\:/,$docslog{$id}{'logentry'}{'after_resources_'.$idx}))[0]; - if ($oldname ne $newname) { + if ($oldname ne '' && $oldname ne $newname) { $r->print(&LONCAPA::map::qtescape($newname)); } } @@ -1184,7 +1185,6 @@ sub docs_change_log { || $shown<=$env{'form.show'})) { last; } } $r->print(&Apache::loncommon::end_data_table()); - $r->print(&Apache::loncommon::end_page()); } sub editor { @@ -1315,12 +1315,10 @@ sub editor { &Apache::lonnet::getfile($url)); $url=$newurl; } - $title=~s/\/\>\;/g; - $title=~s/\:/\:/g; + $title = &LONCAPA::map::qtunescape($title); my $ext='false'; if ($url=~/^http\:\/\//) { $ext='true'; } - $url=~s/\:/\:/g; + $url = &LONCAPA::map::qtunescape($url); # Now insert the URL at the bottom my $newidx=&LONCAPA::map::getresidx($url); $LONCAPA::map::resources[$newidx]= @@ -1372,19 +1370,14 @@ sub editor { my $ratstr = $LONCAPA::map::resources[$LONCAPA::map::order[$idx]]; my ($rtitle,@rrest)=split(/\:/, $LONCAPA::map::resources[$LONCAPA::map::order[$idx]]); - my $comment= - &HTML::Entities::decode($env{'form.title'}); - $comment=~s/\/\>\;/g; - $comment=~s/\:/\:/g; + my $comment=$env{'form.title'}; + $comment = &LONCAPA::map::qtunescape($comment); if ($comment=~/\S/) { $LONCAPA::map::resources[$LONCAPA::map::order[$idx]]= $comment.':'.join(':',@rrest); } # Devalidate title cache - my $renamed_url=$rrest[0]; -# Has the :-escaping - $renamed_url=~s/\&colon\;/\:/g; + my $renamed_url=&LONCAPA::map::qtescape($rrest[0]); &Apache::lonnet::devalidate_title_cache($renamed_url); } # Store the changed version @@ -1452,13 +1445,14 @@ sub editor { $r->print('

'.&mt('Caution: this folder is set to randomly pick a subset of resources. Adding or removing resources from this folder will change the set of resources that the students see, resulting in spurious or missing credit for completed problems, not limited to ones you modify. Do not modify the contents of this folder if it is in active student use.').'

'); } $r->print(''); - foreach (@LONCAPA::map::order) { - my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$_]); + foreach my $res (@LONCAPA::map::order) { + my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]); $name=&LONCAPA::map::qtescape($name); $url=&LONCAPA::map::qtescape($url); unless ($name) { $name=(split(/\//,$url))[-1]; } unless ($name) { $idx++; next; } - $r->print(&entryline($idx,$name,$url,$folder,$allowed,$_,$coursenum)); + $r->print(&entryline($idx,$name,$url,$folder,$allowed,$res, + $coursenum)); $idx++; $shown++; } @@ -1472,11 +1466,19 @@ sub editor { ENDPASTE - $r->print( - ' '.&Apache::loncommon::filedescription( - (split(/\./,$env{'form.markedcopy_url'}))[-1]).': '. - $env{'form.markedcopy_title'}); + $r->print(' '); + + my $type; + if ($env{'form.markedcopy_url'} =~ m{^/adm/wrapper/ext}) { + $type = &mt('External Resource'); + $r->print($type.': '. $env{'form.markedcopy_title'}); + } else { + my $extension = (split(/\./,$env{'form.markedcopy_url'}))[-1]; + my $type = &Apache::loncommon::filedescription($extension); + my $icon = ''; + $r->print($icon.$type.': '. $env{'form.markedcopy_title'}); + } if ($container eq 'page') { $r->print(< @@ -1538,11 +1540,9 @@ sub process_file_upload { $codebase); my $ext='false'; if ($url=~/^http\:\/\//) { $ext='true'; } - $url=~s/\:/\:/g; + $url = &LONCAPA::map::qtunescape($url); my $comment=$env{'form.comment'}; - $comment=~s/\/\>\;/g; - $comment=~s/\:/\:/g; + $comment = &LONCAPA::map::qtunescape($comment); if ($folder=~/^supplemental/) { $comment=time.'___&&&___'.$env{'user.name'}.'___&&&___'. $env{'user.domain'}.'___&&&___'.$comment; @@ -1561,38 +1561,18 @@ sub process_file_upload { 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.
-
- + my $state = ' + + '; - $$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 .= '

- - '; + $phase_status = 'phasetwo'; + + $$upload_output .= + 'This file contains embedded multimedia objects, which need to be uploaded to LON-CAPA.
'. + &ask_for_embedded_content('/adm/coursedocs', + $state,$allfiles,$codebase); } else { $$upload_output .= 'No embedded items identified
'; } @@ -1602,6 +1582,55 @@ sub process_file_upload { return $phase_status; } +sub ask_for_embedded_content { + my ($actionurl,$state,$allfiles,$codebase,$args)=@_; + my $upload_output = ' +
'; + $upload_output .= $state; + $upload_output .= 'Upload embedded files:
'. + &Apache::loncommon::start_data_table(); + + my $num = 0; + foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%{$allfiles})) { + $upload_output .= &Apache::loncommon::start_data_table_row(). + ''.$embed_file.''; + if ($args->{'ignore_remote_references'} + && $embed_file =~ m{^\w+://}) { + $upload_output.=''.&mt("URL points to other server.").''; + } elsif ($args->{'error_on_invalid_names'} + && $embed_file ne &Apache::lonnet::clean_filename($embed_file,{'keep_path' => 1,})) { + + $upload_output.=''.&mt("Invalid characters").''; + + } else { + + $upload_output .=' + + '; + my $attrib = join(':',@{$$allfiles{$embed_file}}); + $upload_output .= + "\n\t\t". + ''; + if (exists($$codebase{$embed_file})) { + $upload_output .= + "\n\t\t". + ''; + } + } + $upload_output .= ''.&Apache::loncommon::end_data_table_row(); + $num++; + } + $upload_output .= &Apache::loncommon::end_data_table().'
+ + + '.&mt('(only files for which a location has been provided will be uploaded)').' +
'; + return $upload_output; +} + sub process_secondary_uploads { my ($upload_output,$coursedom,$coursenum,$formname,$num,$newidx) = @_; my $folder=$env{'form.folder'}; @@ -1625,9 +1654,7 @@ sub process_secondary_uploads { sub entryline { my ($index,$title,$url,$folder,$allowed,$residx,$coursenum)=@_; - $title=~s/\&colon\;/\:/g; - $title=&HTML::Entities::encode(&HTML::Entities::decode( - &unescape($title)),'"<>&\''); + $title=&HTML::Entities::encode($title,'"<>&\''); my $renametitle=$title; my $foldertitle=$title; my $pagetitle=$title; @@ -1644,17 +1671,17 @@ sub entryline { my $line=''; # Edit commands my $container; - my $folderpath; + my ($container, $type, $esc_path, $path, $symb); if ($env{'form.folderpath'}) { + $type = 'folder'; $container = 'sequence'; - $folderpath=&escape($env{'form.folderpath'}); + $esc_path=&escape($path = $env{'form.folderpath'}); # $htmlfoldername=&HTML::Entities::encode($env{'form.foldername'},'<>&"'); } - my ($pagepath,$pagesymb); if ($env{'form.pagepath'}) { - $container = 'page'; - $pagepath=&escape($env{'form.pagepath'}); - $pagesymb=&escape($env{'form.pagesymb'}); + $type = $container = 'page'; + $esc_path=&escape($path = $env{'form.pagepath'}); + $symb=&escape($env{'form.pagesymb'}); } my $cpinfo=''; if ($env{'form.markedcopy_url'}) { @@ -1694,6 +1721,7 @@ sub entryline { 'rn' => 'Rename', 'cp' => 'Copy'); my $nocopy=0; + my $nocut=0; if ($url=~/\.(page|sequence)$/) { foreach (&Apache::lonsequence::attemptread(&Apache::lonnet::filelocation('',$url))) { my ($title,$url,$ext,$type)=split(/\:/,$_); @@ -1703,73 +1731,58 @@ sub entryline { } } } + if ($url=~/^\/res\/lib\/templates\//) { + $nocopy=1; + $nocut=1; + } my $copylink=' '; - if ($env{'form.pagepath'}) { - unless ($nocopy) { - $copylink=(< -$lt{'cp'} + my $cutlink=' '; + + if (!$nocopy) { + $copylink=(< +$lt{'cp'} ENDCOPY - } - $line.=(< - - - - - - - - - -
- -$lt{
- -$lt{
-$selectbox - - -$lt{'rm'} - -$lt{'ct'} - -$lt{'rn'} -$copylink -END - } else { - unless ($nocopy) { - $copylink=(< -$lt{'cp'} -ENDCOPY - } - $line.=(< - - - - - - - - -
- -$lt{
- -$lt{
-$selectbox - - -$lt{'rm'} - + } + if (!$nocut) { + $cutlink=(< $lt{'ct'} - -$lt{'rn'} +ENDCUT + } + $line.=(< + + + + + + + + + + + + + + +
+ $lt{ +
+ $lt{ +
+ + + $selectbox + + + $lt{'rm'} +$cutlink + $lt{'rn'} $copylink + END - } + } # Figure out what kind of a resource this is my ($extension)=($url=~/\.(\w+)$/); @@ -1852,7 +1865,7 @@ END (&LONCAPA::map::getparameter($orderidx, 'parameter_randompick'))[0]. '" />'. -''.&mt('Store').''; +''.&mt('Save').''; } if ($ispage) { @@ -2111,9 +2124,9 @@ sub checkversions { if (&Apache::lonnet::put('resourceversions',\%newsetversions, $env{'course.'.$env{'request.course.id'}.'.domain'}, $env{'course.'.$env{'request.course.id'}.'.num'}) eq 'ok') { - $r->print('

'.&mt('Your Version Settings have been Stored').'

'); + $r->print('

'.&mt('Your Version Settings have been Saved').'

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

'.&mt('An Error Occured while Attempting to Store your Version Settings').'

'); + $r->print('

'.&mt('An Error Occured while Attempting to Save your Version Settings').'

'); } &mark_hash_old(); }