--- loncom/interface/londocs.pm 2016/06/19 04:27:49 1.606 +++ loncom/interface/londocs.pm 2016/10/31 19:48:59 1.610 @@ -1,7 +1,7 @@ # The LearningOnline Network # Documents # -# $Id: londocs.pm,v 1.606 2016/06/19 04:27:49 raeburn Exp $ +# $Id: londocs.pm,v 1.610 2016/10/31 19:48:59 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -3888,7 +3888,7 @@ END } } - my ($editlink,$extresform); + my ($editlink,$extresform,$anchor); my $orig_url = $url; $orig_url=~s{http(:|:)//https(:|:)//}{https$2//}; $url=~s{^http(|s)(:|:)//}{/adm/wrapper/ext/}; @@ -3912,11 +3912,28 @@ END $url='/adm/wrapper'.$url; } if (&Apache::lonnet::symbverify($symb,$url)) { - $url.=(($url=~/\?/)?'&':'?').'symb='.&escape($symb); + my $shownsymb = $symb; + if ($isexternal) { + if ($url =~ /^([^#]+)#([^#]+)$/) { + $url = $1; + $anchor = $2; + if ($symb =~ m{^([^#]+)\Q#$anchor\E$}) { + $shownsymb = $1.&escape('#').$anchor; + } + } + } + $url.=(($url=~/\?/)?'&':'?').'symb='.&HTML::Entities::encode($shownsymb,'"<>&'); } else { $url=''; } } + } elsif ($supplementalflag) { + if ($isexternal) { + if ($url =~ /^([^#]+)#([^#]+)$/) { + $url = $1; + $anchor = $2; + } + } } my ($rand_pick_text,$rand_order_text); if ($isfolder || $ispage || $extension eq 'sequence' || $extension eq 'page') { @@ -3989,6 +4006,9 @@ $form_end; if ((($isexternal) || ($isexttool)) && $orderidx) { $url .= '&idx='.$orderidx; } + if ($anchor ne '') { + $url .= '&anchor='.&HTML::Entities::encode($anchor,'"<>&'); + } } my ($tdalign,$tdwidth); if ($allowed) { @@ -4006,13 +4026,17 @@ $form_end; my ($cfile,$home,$switchserver,$forceedit,$forceview) = &Apache::lonnet::can_edit_resource($fileloc,$coursenum,$coursedom,$orig_url); if (($cfile ne '') && ($symb ne '' || $supplementalflag)) { + my $suppanchor; + if ($supplementalflag) { + $suppanchor = $anchor; + } my $jscall = &Apache::lonhtmlcommon::jump_to_editres($cfile,$home, $switchserver, $forceedit, undef,$symb, &escape($env{'form.folderpath'}), - $renametitle,'','',1); + $renametitle,'','',1,$suppanchor); if ($jscall) { $editlink = ''.&mt('Edit').' '."\n"; @@ -4032,7 +4056,15 @@ $form_end; if (($url=~m{/adm/(coursedocs|supplemental)}) || (!$allowed && $url)) { $line.=''; } elsif ($url) { - $line.=&Apache::loncommon::modal_link($url.(($url=~/\?/)?'&':'?').'inhibitmenu=yes', + if ($anchor ne '') { + if ($supplementalflag) { + $anchor = '&anchor='.&HTML::Entities::encode($anchor,'"<>&'); + } else { + $anchor = '#'.&HTML::Entities::encode($anchor,'"<>&'); + } + } + $line.=&Apache::loncommon::modal_link($url.(($url=~/\?/)?'&':'?').'inhibitmenu=yes'. + (($anchor ne '')?$anchor:''), '',600,500); } else { $line.=''; @@ -4041,7 +4073,8 @@ $form_end; if (($url=~m{/adm/(coursedocs|supplemental)}) || (!$allowed && $url)) { $line.=''.$title.''; } elsif ($url) { - $line.=&Apache::loncommon::modal_link($url.(($url=~/\?/)?'&':'?').'inhibitmenu=yes', + $line.=&Apache::loncommon::modal_link($url.(($url=~/\?/)?'&':'?').'inhibitmenu=yes'. + (($anchor ne '')?$anchor:''), $title,600,500); } else { $line.=$title.' '.$reinit.''; @@ -4908,8 +4941,6 @@ sub handler { my $output = &Apache::lonpublisher::batchpublish($r,$srcfile,$targetfile,$nokeyref,1); $env{'form.folder'} = $folder; &snapshotbefore(); - my $url = $redirect; - $url =~ s{^/priv/}{/res/}; my $title = &LONCAPA::map::qtunescape($env{'form.newresourcetitle'}); my $ext = 'false'; my $newidx = &LONCAPA::map::getresidx(&LONCAPA::map::qtunescape($url)); @@ -5394,61 +5425,11 @@ FUFORM SEDFFORM - my $is_home; - my $crshome = $env{'course.'.$env{'request.course.id'}.'.home'}; - my @ids=&Apache::lonnet::current_machine_ids(); - if (grep(/^\Q$crshome\E$/,@ids)) { - $is_home = 1; - } - my (%subdirs,%files,%selimport_menus); - my $pickfile; - my $relpath = "/res/$coursedom/$coursenum"; - &recursedirs($is_home,'res',$londocroot,$relpath,'',\%subdirs,\%files); - my $numdirs = scalar(keys(%files)); - if ($numdirs > 1) { - my @order = sort { lc($a) cmp lc($b) } (keys(%files)); - foreach my $key (@order) { - if (ref($files{$key}) eq 'HASH') { - my $shown = $key; - if ($key eq '') { - $shown = '/'; - } - $selimport_menus{$key}->{'text'} = $shown; - $selimport_menus{$key}->{'default'} = ''; - my @ordered = (''); - $selimport_menus{$key}->{'select2'}->{''} = ''; - foreach my $file (sort { lc($a) cmp lc($b) } (keys(%{$files{$key}}))) { - $selimport_menus{$key}->{'select2'}->{$file} = $file; - push(@ordered,$file); - } - $selimport_menus{$key}->{'order'} = \@ordered; - } - } - $pickfile = $lt{'dire'}. - &Apache::loncommon::linked_select_forms('crsresimportform','
'. - &mt('Filename: '),'', - 'coursepath','coursefile', - \%selimport_menus,\@order, - "resize_scrollbox('contentscroll','1','0');",'','res'). - '
'; - } elsif ($numdirs == 1) { - my $singledir = (keys(%files))[0]; - my $showdir = $singledir; - if ($singledir eq '') { - $showdir = '/'; - } - $pickfile = $lt{'dire'}. - '
'. - &mt('Filename: ').'
'."\n"; - } my $importcrsresform; + my ($numdirs,$pickfile) = + &Apache::loncommon::import_crsauthor_form('crsresimportform','coursepath','coursefile', + "resize_scrollbox('contentscroll','1','0');", + undef,'res'); if ($pickfile) { $importcrsresform=(< @@ -5675,7 +5656,7 @@ NWEBFORM if (grep(/^\Q$env{'user.home'}\E$/,@ids)) { my $is_home = 1; my %subdirs; - &recursedirs($is_home,'priv',$londocroot,$toppath,'',\%subdirs); + &Apache::lonnet::recursedirs($is_home,'priv',$londocroot,$toppath,'',\%subdirs); $select_menus{'author'}->{'default'} = '/'; $select_menus{'author'}->{'select2'}->{'/'} = '/'; my @ordered = ('/'); @@ -5706,7 +5687,7 @@ NWEBFORM my $is_home = 1; my (%subdirs,@ordered); my $toppath="/priv/$audom/$auname"; - &recursedirs($is_home,'priv',$londocroot,$toppath,'',\%subdirs); + &Apache::lonnet::recursedirs($is_home,'priv',$londocroot,$toppath,'',\%subdirs); $select_menus{$key}->{'default'} = '/'; $select_menus{$key}->{'select2'}->{'/'} = '/'; my @ordered = ('/'); @@ -5748,7 +5729,7 @@ NWEBFORM my $is_home = 1; my %subdirs; my $toppath="/priv/$coursedom/$coursenum"; - &recursedirs($is_home,'priv',$londocroot,$toppath,'',\%subdirs); + &Apache::lonnet::recursedirs($is_home,'priv',$londocroot,$toppath,'',\%subdirs); $numcrsdirs = keys(%subdirs); $select_menus{'course'}->{'default'} = '/'; $select_menus{'course'}->{'select2'}->{'/'} = '/'; @@ -5778,13 +5759,13 @@ NWEBFORM $pickdir .= ''; my $toppath="/priv/$coursedom/$coursenum'}"; my %subdirs; - &recursedirs($is_home,'priv',$londocroot,$toppath,'',\%subdirs); + &Apache::lonnet::recursedirs($is_home,'priv',$londocroot,$toppath,'',\%subdirs); $numcrsdirs = keys(%subdirs); if ($numcrsdirs) { $pickdir .= &mt('Directory: ').''; } else { @@ -6594,8 +6575,19 @@ sub editing_js { my ($map,$id,$res)=&Apache::lonnet::decode_symb($caller); $res = &Apache::lonnet::clutter($res); if (&Apache::lonnet::is_on_map($res)) { - $backtourl = &HTML::Entities::encode(&Apache::lonnet::clutter($res),'<>&"').'?symb='. + my ($url,$anchor); + if ($res =~ /^([^#]+)#([^#]+)$/) { + $url = $1; + $anchor = $2; + if (($caller =~ m{^([^#]+)\Q#$anchor\E$})) { + $caller = $1.&escape('#').$anchor; + } + } + $backtourl = &HTML::Entities::encode(&Apache::lonnet::clutter($url),'<>&"').'?symb='. &HTML::Entities::encode($caller,'<>&"'); + if ($anchor ne '') { + $backtourl .= '#'.&HTML::Entities::encode($anchor,'<>&"'); + } $backtourl = &Apache::loncommon::escape_single($backtourl); } else { $backtourl = '/adm/navmaps'; @@ -7838,87 +7830,6 @@ sub makesimpleeditform { SIMPFORM } -sub recursedirs { - my ($is_home,$context,$docroot,$toppath,$relpath,$dirhashref,$filehashref) = @_; - return unless (ref($dirhashref) eq 'HASH'); - my $currpath = $docroot.$toppath; - if ($relpath) { - $currpath .= "/$relpath"; - } - my $savefile; - if (ref($filehashref)) { - $savefile = 1; - } - if ($is_home) { - if (opendir(my $dirh,$currpath)) { - foreach my $item (sort { lc($a) cmp lc($b) } grep(!/^\.+$/,readdir($dirh))) { - next if ($item eq ''); - if (-d "$currpath/$item") { - my $newpath; - if ($relpath) { - $newpath = "$relpath/$item"; - } else { - $newpath = $item; - } - $dirhashref->{&js_escape($newpath)} = 1; - &recursedirs($is_home,$context,$docroot,$toppath,$newpath,$dirhashref,$filehashref); - } elsif ($savefile) { - if ($context eq 'priv') { - unless ($item =~ /\.(meta|save|log|bak|DS_Store)$/) { - $filehashref->{&js_escape($relpath)}{$item} = 1; - } - } else { - unless (($item =~ /\.meta$/) || ($item =~ /\.\d+\.\w+$/) || ($item =~ /\.rights$/)) { - $filehashref->{&js_escape($relpath)}{$item} = 1; - } - } - } - } - closedir($dirh); - } - } else { - my ($dirlistref,$listerror) = - &Apache::lonnet::dirlist($toppath.$relpath); - my @dir_lines; - my $dirptr=16384; - if (ref($dirlistref) eq 'ARRAY') { - foreach my $dir_line (sort - { - my ($afile)=split('&',$a,2); - my ($bfile)=split('&',$b,2); - return (lc($afile) cmp lc($bfile)); - } (@{$dirlistref})) { - my ($item,$dom,undef,$testdir,undef,undef,undef,undef,$size,undef,$mtime,undef,undef,undef,$obs,undef) = - split(/\&/,$dir_line,16); - $item =~ s/\s+$//; - next if (($item =~ /^\.\.?$/) || ($obs)); - if ($dirptr&$testdir) { - my $newpath; - if ($relpath) { - $newpath = "$relpath/$item"; - } else { - $relpath = '/'; - $newpath = $item; - } - $dirhashref->{&js_escape($newpath)} = 1; - &recursedirs($is_home,$context,$docroot,$toppath,$newpath,$dirhashref,$filehashref); - } elsif ($savefile) { - if ($context eq 'priv') { - unless ($item =~ /\.(meta|save|log|bak|DS_Store)$/) { - $filehashref->{$relpath}{$item} = 1; - } - } else { - unless (($item =~ /\.meta$/) || ($item =~ /\.\d+\.\w+$/)) { - $filehashref->{$relpath}{$item} = 1; - } - } - } - } - } - } - return; -} - sub makenewproblem { my ($r,$coursedom,$coursenum) = @_; # Creating a new problem @@ -8121,6 +8032,11 @@ END sub finishnewprob { my ($url,$path,$subdir,$newsubdir,$filename) = @_; + unless (-d $path) { + unless (mkdir($path,02770)) { + return; + } + } my $redirect; if ($subdir ne '/') { $subdir = &cleandir($subdir);