--- loncom/interface/londocs.pm 2018/04/14 02:29:44 1.653 +++ loncom/interface/londocs.pm 2018/04/24 11:17:58 1.654 @@ -1,7 +1,7 @@ # The LearningOnline Network # Documents # -# $Id: londocs.pm,v 1.653 2018/04/14 02:29:44 raeburn Exp $ +# $Id: londocs.pm,v 1.654 2018/04/24 11:17:58 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -5460,6 +5460,8 @@ sub handler { $r->internal_redirect($redirect); return OK; } + } else { + $r->internal_redirect($redirect); } } } @@ -8637,7 +8639,7 @@ sub makenewproblem { if ($env{'form.newsubdir'}) { if ($env{'form.newsubdirname'} ne '') { $newsubdir = $env{'form.newsubdirname'}; - } + } } if ($env{'form.newresourcename'}) { $filename = $env{'form.newresourcename'}; @@ -8720,61 +8722,34 @@ END END - close($fh); - } - if ((-e $sourcerights) && (-e "$sourcerights.meta")) { - if (!-e "$docroot/res/$coursedom") { - mkdir("$docroot/res/$coursedom",0755); - } - if (!-e "$docroot/res/$coursedom/$coursenum") { - mkdir("$docroot/res/$coursedom/$coursenum",0755); - } - if ((-e "$docroot/res/$coursedom/$coursenum") && (!-e $targetrights)) { - my $nokeyref = &Apache::lonpublisher::getnokey($r->dir_config('lonIncludes')); - my $output = &Apache::lonpublisher::batchpublish($r,$sourcerights,$targetrights,$nokeyref,1); - } + close($fh); } } - if ($env{'form.newresourceadd'}) { - my $template = $env{'form.template'}; - my $source = $docroot.$redirect; - my $target = $redirect; - $target =~ s{^/priv/}{/res/}; - $target = $docroot.$target; - if (!-e $source) { - my $copyfrom; - if ($template) { - my %templates; - my @files = &Apache::lonhomework::get_template_list('problem'); - foreach my $poss (@files) { - if (ref($poss) eq 'ARRAY') { - if ($template eq $poss->[0]) { - $templates{$template} = 1; - last; - } - } - } - if ($templates{$template}) { - $copyfrom = $template; - } - } - unless ($copyfrom) { - $copyfrom = $r->dir_config('lonIncludes').'/templates/blank.problem'; - } - &File::Copy::copy($copyfrom,$source); + if ((-e $sourcerights) && (-e "$sourcerights.meta")) { + if (!-e "$docroot/res/$coursedom") { + mkdir("$docroot/res/$coursedom",0755); } - if (!-e "$source.meta") { - my $cid = $coursedom.'_'.$coursenum; - my $now = time; - if (open(my $fh,">$source.meta")) { - my $author=$env{'environment.firstname'}.' '. - $env{'environment.middlename'}.' '. - $env{'environment.lastname'}.' '. - $env{'environment.generation'}; - $author =~ s/\s+$//; - my $title = $env{'form.newresourcetitle'}; - $title =~ s/^\s+|\s+$//g; - print $fh <dir_config('lonIncludes')); + my $output = &Apache::lonpublisher::batchpublish($r,$sourcerights,$targetrights,$nokeyref,1); + } + } + my $source = $docroot.$redirect; + if (!-e "$source.meta") { + my $cid = $coursedom.'_'.$coursenum; + my $now = time; + if (open(my $fh,">$source.meta")) { + my $author=$env{'environment.firstname'}.' '. + $env{'environment.middlename'}.' '. + $env{'environment.lastname'}.' '. + $env{'environment.generation'}; + $author =~ s/\s+$//; + my $title = $env{'form.newresourcetitle'}; + $title =~ s/^\s+|\s+$//g; + print $fh < $author @@ -8800,8 +8775,7 @@ END $title END - close($fh); - } + close($fh); } } } @@ -8829,7 +8803,7 @@ END } sub finishnewprob { - my ($url,$path,$subdir,$newsubdir,$filename) = @_; + my ($url,$path,$subdir,$newsubdir,$filename,$context) = @_; unless (-d $path) { unless (mkdir($path,02770)) { return; @@ -8872,6 +8846,31 @@ sub finishnewprob { $redirect = "$url/$filename"; } } + if ((!-e $dest) && ($context ne 'upload')) { + my $template = $env{'form.template'}; + my $copyfrom; + if ($template ne '') { + my %templates; + my @files = &Apache::lonhomework::get_template_list('problem'); + foreach my $poss (@files) { + if (ref($poss) eq 'ARRAY') { + if ($template eq $poss->[0]) { + $templates{$template} = 1; + last; + } + } + } + if ($templates{$template}) { + $copyfrom = $template; + } + } + if ($filename =~ /\.problem$/) { + unless ($copyfrom) { + $copyfrom = $Apache::lonnet::perlvar{'lonIncludes'}.'/templates/blank.problem'; + } + &File::Copy::copy($copyfrom,$dest); + } + } return $redirect; }