--- loncom/homework/lonhomework.pm 2016/09/14 16:13:17 1.365 +++ loncom/homework/lonhomework.pm 2016/09/20 19:28:08 1.366 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # The LON-CAPA Homework handler # -# $Id: lonhomework.pm,v 1.365 2016/09/14 16:13:17 raeburn Exp $ +# $Id: lonhomework.pm,v 1.366 2016/09/20 19:28:08 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -1439,12 +1439,31 @@ sub newproblem { &renderpage($request,$dest); return; } + my $errormsg; if ($env{'form.template'}) { - my $file = $env{'form.template'}; - my $dest = &Apache::lonnet::filelocation("",$request->uri); - &File::Copy::copy($file,$dest); - &renderpage($request,$dest); - return; + my $file; + my ($extension) = ($env{'form.template'} =~ /\.(\w+)$/); + if ($extension) { + my @files = &get_template_list($extension); + foreach my $poss (@files) { + if (ref($poss) eq 'ARRAY') { + if ($env{'form.template'} eq $poss->[0]) { + $file = $env{'form.template'}; + last; + } + } + } + if ($file) { + my $dest = &Apache::lonnet::filelocation("",$request->uri); + &File::Copy::copy($file,$dest); + &renderpage($request,$dest); + return; + } else { + $errormsg = '
'.&mt('Invalid template file.').'
'; + } + } else { + $errormsg = ''.&mt('Invalid template file; template needs to be a .problem, .library, or .task file.').'
'; + } } my ($extension) = ($request->uri =~ m/\.(\w+)$/); @@ -1461,7 +1480,6 @@ sub newproblem { } else { my $url=&HTML::Entities::encode($request->uri,'<>&"'); my $dest = &Apache::lonnet::filelocation("",$request->uri); - my $errormsg; my $instructions; my $brcrum = [{'href' => &Apache::loncommon::authorspace($request->uri), 'text' => 'Authoring Space'},