--- loncom/interface/londependencies.pm 2012/07/06 22:46:06 1.2 +++ loncom/interface/londependencies.pm 2017/08/13 20:52:59 1.5 @@ -2,7 +2,7 @@ # Handler to manage dependencies for HTML files uploaded directly # to a course. # -# $Id: londependencies.pm,v 1.2 2012/07/06 22:46:06 raeburn Exp $ +# $Id: londependencies.pm,v 1.5 2017/08/13 20:52:59 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -94,28 +94,50 @@ sub handler { $r->send_http_header; &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'}, - ['action','symb','title','url']); + ['action','symb','title','url','folderpath']); my $action = $env{'form.action'}; my $symb = $env{'form.symb'}; my $docs_title = $env{'form.title'}; my $docs_url = $env{'form.url'}; + my $folderpath = &unescape($env{'form.folderpath'}); my ($mimetype,$numpathchgs,$numrefchanges,%allfiles,%codebase,$url); + my $earlyout; if ($symb) { (undef,undef,$url) = &Apache::lonnet::decode_symb($symb); - } elsif (($docs_url) && ($env{'httpref.'.$docs_url} ne '')) { + unless (&Apache::lonnet::is_on_map($url)) { + $earlyout = 1; + } + } elsif (($docs_url) && (($env{'httpref.'.$docs_url} ne '') || + ($docs_url =~ m{^\Q/uploaded/$cdom/$cnum/\E(portfolio/syllabus)/}))) { $url = $docs_url; $url =~ s{^/}{}; } my $title = &mt('Manage Dependencies'); my $state = ''."\n". + ''."\n". ''."\n". ''."\n"; my $dir_root = '/userfiles'; - my ($destination) = - ($url =~ m{^\Quploaded/$cdom/$cnum/\E((?:docs|supplemental)/(?:default|\d+)/\d+)/}); + my ($destination,$context); + if ($url =~ m{^\Quploaded/$cdom/$cnum/\E(portfolio/syllabus)/}) { + $destination = $1; + $context = 'syllabus'; + } else { + ($destination) = + ($url =~ m{^\Quploaded/$cdom/$cnum/\E((?:docs|supplemental)/(?:default|\d+)/\d+)/}); + $context = 'coursedoc'; + if ($destination eq '') { + $earlyout = 1; + } + } my $js = &Apache::loncommon::ask_embedded_js(); my $output = &Apache::loncommon::start_page($title,$js, {'only_body' => 1}); + if ($earlyout) { + $r->print($output.&mt('Cannot display dependency information - invalid file: [_1].',$url). + &Apache::loncommon::end_page()); + return OK; + } if ($action eq 'modifyhrefs') { my ($result,$count,$codebasecount) = &Apache::loncommon::modify_html_refs('manage_dependencies',$destination, @@ -124,7 +146,7 @@ sub handler { $numrefchanges = $count + $codebasecount; } elsif ($action eq 'process_changes') { (my $result,$numpathchgs) = - &process_changes($cdom,$cnum,$chome,$url,$destination,$dir_root,$state); + &process_changes($cdom,$cnum,$chome,$url,$destination,$dir_root,$state,$context); $output .= $result; } unless ((($action eq 'process_changes') && ($numpathchgs > 0)) || @@ -146,7 +168,7 @@ sub handler { } sub process_changes { - my ($cdom,$cnum,$chome,$url,$destination,$dir_root,$state) = @_; + my ($cdom,$cnum,$chome,$url,$destination,$dir_root,$state,$context) = @_; my ($output,$numpathchgs); my ($numnew,$numtodelete,$numtomod) = (0,0,0); my $url_root = "/uploaded/$cdom/$cnum"; @@ -197,11 +219,20 @@ sub process_changes { } if ((@modifications > 0) || ($numnew > 0)) { (my $result,my $flag,$numpathchgs) = - &Apache::loncommon::upload_embedded('coursedoc',$destination,$cnum,$cdom, + &Apache::loncommon::upload_embedded($context,$destination,$cnum,$cdom, $dir_root,$url_root,undef,undef,undef, $state,'/adm/dependencies'); $output .= '

'.&mt('Uploaded files').'

'. $result; + unless ($numpathchgs) { + if ($context eq 'syllabus') { + my $modres = + &Apache::loncommon::modify_html_refs($context,'portfolio/syllabus', + $cnum,$cdom, + '/userfiles',"/$url"); + $result .= $modres; + } + } } } else { $output .= ''.