--- loncom/homework/lonhomework.pm 2016/07/18 19:29:11 1.363 +++ 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.363 2016/07/18 19:29:11 raeburn Exp $ +# $Id: lonhomework.pm,v 1.366 2016/09/20 19:28:08 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -231,7 +231,7 @@ sub check_slot_access { my ($returned_slot,$slot_name,$checkinslot,$ipused,$blockip,$now,$ip, $consumed_uniq); $now = time; - $ip=$env{'request.host'} || $ENV{'REMOTE_ADDR'}; + $ip=$ENV{'REMOTE_ADDR'} || $env{'request.host'}; if ($checkedin) { $checkinslot = $Apache::lonhomework::history{"$checkin.slot"}; @@ -1431,18 +1431,39 @@ sub get_template_html { sub newproblem { my ($request) = @_; - if ($env{'form.mode'} eq 'blank'){ + if ($env{'form.mode'} eq 'blank'){ my $dest = &Apache::lonnet::filelocation("",$request->uri); - &File::Copy::copy('/home/httpd/html/res/adm/includes/templates/blank.problem',$dest); + my $templatefilename = + $request->dir_config('lonIncludes').'/templates/blank.problem'; + &File::Copy::copy($templatefilename,$dest); &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+)$/); @@ -1459,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'},