version 1.41, 2001/04/26 21:28:33
|
version 1.47, 2001/06/26 21:39:15
|
Line 14 use Apache::response;
|
Line 14 use Apache::response;
|
use Apache::hint; |
use Apache::hint; |
use Apache::outputtags; |
use Apache::outputtags; |
use Apache::Constants qw(:common); |
use Apache::Constants qw(:common); |
|
#use Time::HiRes qw( gettimeofday tv_interval ); |
|
|
|
sub BEGIN { |
|
&Apache::lonxml::register_insert(); |
|
} |
|
|
sub get_target { |
sub get_target { |
if ( $ENV{'request.state'} eq "published") { |
if ( $ENV{'request.state'} eq "published") { |
Line 30 sub get_target {
|
Line 35 sub get_target {
|
return ('web'); |
return ('web'); |
} |
} |
} else { |
} else { |
return ('grade','web'); |
if ( $ENV{'form.problemmode'} eq 'View' ) { |
if ( $ENV{'form.submitted'} eq 'edit' ) { |
if ( defined $ENV{'form.submitted'}) { |
return ('modified','edit'); |
return ('grade', 'web'); |
|
} else { |
|
return ('web'); |
|
} |
|
} elsif ( $ENV{'form.problemmode'} eq 'Edit' ) { |
|
if ( $ENV{'form.submitted'} eq 'edit' ) { |
|
return ('modified','edit'); |
|
} else { |
|
return ('edit'); |
|
} |
} else { |
} else { |
return ('edit'); |
return ('web'); |
} |
} |
} |
} |
} |
} |
Line 50 sub setup_vars {
|
Line 64 sub setup_vars {
|
sub send_header { |
sub send_header { |
my ($request)= @_; |
my ($request)= @_; |
$request->print(&Apache::lontexconvert::header()); |
$request->print(&Apache::lontexconvert::header()); |
$ENV{'request.uri'}=$request->uri; |
|
# $request->print('<form name='.$ENV{'form.request.prefix'}.'lonhomework method="POST" action="'.$request->uri.'">'); |
# $request->print('<form name='.$ENV{'form.request.prefix'}.'lonhomework method="POST" action="'.$request->uri.'">'); |
} |
} |
|
|
Line 156 sub setupheader {
|
Line 169 sub setupheader {
|
} |
} |
$request->send_http_header; |
$request->send_http_header; |
return OK if $request->header_only; |
return OK if $request->header_only; |
&Apache::lonhomework::send_header($request); |
|
return '' |
return '' |
} |
} |
|
|
|
sub handle_save_or_undo { |
|
my ($request,$problem,$result) = @_; |
|
my $fileout = &Apache::lonnet::filelocation("",$request->uri); |
|
my $filesave=$fileout.".bak"; |
|
|
|
if ($ENV{'form.Undo'} eq 'undo') { |
|
if (copy($filesave,$fileout)) { |
|
$request->print("<b>Undid changes, Copied $filesave to $fileout<br /></b>"); |
|
} else { |
|
$request->print("<font color=\"red\" size=\"+1\"><b>Unable to undo, unable to copy $filesave to $fileout<br /></b></font>"); |
|
} |
|
} else { |
|
my $fs=Apache::File->new(">$filesave"); |
|
if (defined($fs)) { |
|
print $fs $$problem; |
|
$request->print("<b>Making Backup to $filesave</b><br />"); |
|
} else { |
|
$request->print("<font color=\"red\" size=\"+1\"><b>Unable to make backup $filesave</b></font>"); |
|
} |
|
my $fh=Apache::File->new(">$fileout"); |
|
if (defined($fh)) { |
|
print $fh $$result; |
|
$request->print("<b>Saving Modifications to $fileout</b><br />"); |
|
} else { |
|
$request->print("<font color=\"red\" size=\"+1\"><b>Unable to write to $fileout</b></font>"); |
|
} |
|
} |
|
} |
|
|
sub renderpage { |
sub renderpage { |
my ($request,$file) = @_; |
my ($request,$file) = @_; |
|
|
my (@targets) = &get_target(); |
my (@targets) = &get_target(); |
foreach my $target (@targets) { |
foreach my $target (@targets) { |
|
#my $t0 = [&gettimeofday()]; |
my $problem=&Apache::lonnet::getfile($file); |
my $problem=&Apache::lonnet::getfile($file); |
if ($problem == -1) { |
if ($problem == -1) { |
&Apache::lonxml::error("<b> Unable to find <i>$file</i></b>"); |
&Apache::lonxml::error("<b> Unable to find <i>$file</i></b>"); |
Line 174 sub renderpage {
|
Line 216 sub renderpage {
|
my %mystyle; |
my %mystyle; |
my $result = ''; |
my $result = ''; |
&Apache::inputtags::initialize_inputtags; |
&Apache::inputtags::initialize_inputtags; |
|
&Apache::edit::initialize_edit; |
%Apache::lonhomework::results=(); |
%Apache::lonhomework::results=(); |
%Apache::lonhomework::history=&Apache::lonnet::restore(); |
%Apache::lonhomework::history=&Apache::lonnet::restore(); |
#ignore error conditions |
#ignore error conditions |
Line 187 sub renderpage {
|
Line 230 sub renderpage {
|
$request->print("Browsing or <a href=\"/adm/ambiguous\">ambiguous</a> reference, submissions ignored<br />"); |
$request->print("Browsing or <a href=\"/adm/ambiguous\">ambiguous</a> reference, submissions ignored<br />"); |
} |
} |
} |
} |
if ($Apache::lonhomework::viewgrades eq 'F') {&createmenu('grade',$request); } |
#if ($Apache::lonhomework::viewgrades eq 'F') {&createmenu('grade',$request); } |
} |
} |
if ($target eq 'grade') { &showhash(%Apache::lonhomework::history); } |
if ($target eq 'grade') { &showhash(%Apache::lonhomework::history); } |
|
|
Line 201 sub renderpage {
|
Line 244 sub renderpage {
|
|
|
#$request->print("Result follows:"); |
#$request->print("Result follows:"); |
if ($target eq 'modified') { |
if ($target eq 'modified') { |
my $fileout = &Apache::lonnet::filelocation("",$request->uri); |
&handle_save_or_undo($request,\$problem,\$result); |
my $filesave=$fileout.".bak"; |
|
|
|
my $fs=Apache::File->new(">$filesave"); |
|
print $fs $problem; |
|
$request->print("<b>Making Backup to $filesave</b><br />"); |
|
|
|
my $fh=Apache::File->new(">$fileout"); |
|
print $fh $result; |
|
$request->print("<b>Saving Modifications to $fileout</b><br />"); |
|
} else { |
} else { |
|
#my $td=&tv_interval($t0); |
|
#if ( $Apache::lonxml::debug) { |
|
#$result =~ s:</body>::; |
|
#$result.="<br />Spent $td seconds processing target $target\n</body>"; |
|
#} |
$request->print($result); |
$request->print($result); |
} |
} |
#$request->print(":Result ends"); |
#$request->print(":Result ends"); |
Line 223 sub renderpage {
|
Line 262 sub renderpage {
|
&Apache::lonxml::debug("Store return message:". |
&Apache::lonxml::debug("Store return message:". |
&Apache::lonnet::cstore(\%Apache::lonhomework::results)); |
&Apache::lonnet::cstore(\%Apache::lonhomework::results)); |
} |
} |
|
#my $td=&tv_interval($t0); |
|
} |
|
} |
|
|
|
# with no arg it returns a HTML <option> list of the template titles |
|
# with one arg it returns the filename associated with the arg passed |
|
sub get_template_list { |
|
my ($namewanted) = @_; |
|
my $result; |
|
foreach my $file (</home/httpd/html/res/adm/includes/templates/*.problem>) { |
|
my $name=&Apache::lonnet::metadata($file,'title'); |
|
if ($namewanted && ($name eq $namewanted)) { |
|
$result=$file; |
|
last; |
|
} else { |
|
$result.="<option>$name</option>"; |
|
} |
|
} |
|
return $result; |
|
} |
|
|
|
sub newproblem { |
|
my ($request) = @_; |
|
|
|
if ($ENV{'form.template'}) { |
|
use File::Copy; |
|
my $file = &get_template_list($ENV{'form.template'}); |
|
my $dest = &Apache::lonnet::filelocation("",$request->uri); |
|
copy($file,$dest); |
|
&renderpage($request,$file); |
|
} else { |
|
my $templatelist=&get_template_list(); |
|
my $url=$request->uri; |
|
$request->print(<<ENDNEWPROBLEM); |
|
<body bgcolor="#FFFFFF"> |
|
The request file $url doesn\'t exist. You can create a new problem <br /> |
|
<form action="$url" method="POST"> |
|
<input type="submit" value="New Problem"><br /> |
|
<select name="template"> |
|
$templatelist |
|
</select> |
|
</form> |
|
</body> |
|
ENDNEWPROBLEM |
} |
} |
|
|
|
return ''; |
|
} |
|
|
|
sub view_or_edit_menu { |
|
my ($request) = @_; |
|
my $url=$request->uri; |
|
$request->print(<<EDITMENU); |
|
<body bgcolor="#FFFFFF"> |
|
<form action="$url" method="POST"> |
|
Would you like to <input type="submit" name="problemmode" value="View"> or |
|
<input type="submit" name="problemmode" value="Edit"> the problem. |
|
</form> |
|
</body> |
|
EDITMENU |
} |
} |
|
|
sub handler { |
sub handler { |
|
#my $t0 = [&gettimeofday()]; |
my $request=$_[0]; |
my $request=$_[0]; |
|
|
if ( $ENV{'user.name'} eq 'albertel' ) {$Apache::lonxml::debug=1;} |
#if ( $ENV{'user.name'} eq 'albertel' ) {$Apache::lonxml::debug=1;} |
|
|
if (&setupheader($request)) { return OK; } |
if (&setupheader($request)) { return OK; } |
|
$ENV{'request.uri'}=$request->uri; |
|
|
#setup permissions |
#setup permissions |
$Apache::lonhomework::browse= &Apache::lonnet::allowed('bre',$ENV{'request.filename'}); |
$Apache::lonhomework::browse= &Apache::lonnet::allowed('bre',$ENV{'request.filename'}); |
Line 251 sub handler {
|
Line 351 sub handler {
|
|
|
if ($ENV{'request.state'} eq "construct") { |
if ($ENV{'request.state'} eq "construct") { |
if ( -e $file ) { |
if ( -e $file ) { |
if (!(defined $ENV{'form.showproblem'})) { |
if (!(defined $ENV{'form.problemmode'})) { |
#first visit to problem in construction space |
#first visit to problem in construction space |
&view_or_edit_menu($request); |
&view_or_edit_menu($request); |
|
#&renderpage($request,$file); |
} else { |
} else { |
&renderpage($request,$file); |
&renderpage($request,$file); |
} |
} |
Line 265 sub handler {
|
Line 366 sub handler {
|
# just render the page normally outside of construction space |
# just render the page normally outside of construction space |
&renderpage($request,$file); |
&renderpage($request,$file); |
} |
} |
|
#my $td=&tv_interval($t0); |
&Apache::lonhomework::send_footer($request); |
#&Apache::lonxml::debug("Spent $td seconds processing"); |
|
# &Apache::lonhomework::send_footer($request); |
# always turn off debug messages |
# always turn off debug messages |
$Apache::lonxml::debug=0; |
$Apache::lonxml::debug=0; |
return OK; |
return OK; |