version 1.39, 2001/02/19 20:35:21
|
version 1.49, 2001/07/18 18:45:37
|
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 ('edit'); |
if ( $ENV{'form.problemmode'} eq 'View' ) { |
#edit is currently broken |
if ( defined $ENV{'form.submitted'}) { |
return ('web'); |
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 { |
|
return ('web'); |
|
} |
} |
} |
} |
} |
return (); |
return (); |
Line 47 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 128 sub check_date {
|
Line 144 sub check_date {
|
return ($status,$datemsg); |
return ($status,$datemsg); |
} |
} |
|
|
sub handler { |
sub showhash { |
my $request=$_[0]; |
my (%hash) = @_; |
|
my $resultkey; |
if ( $ENV{'user.name'} eq 'albertel' ) {$Apache::lonxml::debug=1;} else {$Apache::lonxml::debug=0;} |
foreach $resultkey (sort keys %hash) { |
|
&Apache::lonxml::debug("$resultkey ---- $hash{$resultkey}"); |
my (@targets) = &get_target(); |
} |
|
&Apache::lonxml::debug("\n<br />restored values^</br>\n"); |
|
return ''; |
|
} |
|
|
|
sub setuppermissions { |
|
$Apache::lonhomework::browse= &Apache::lonnet::allowed('bre',$ENV{'request.filename'}); |
|
$Apache::lonhomework::viewgrades=&Apache::lonnet::allowed('vgr',$ENV{'request.course.id'}); |
|
return '' |
|
} |
|
|
|
sub setupheader { |
|
my $request=$_[0]; |
if ($ENV{'browser.mathml'}) { |
if ($ENV{'browser.mathml'}) { |
$request->content_type('text/xml'); |
$request->content_type('text/xml'); |
} else { |
} else { |
Line 142 sub handler {
|
Line 169 sub handler {
|
} |
} |
$request->send_http_header; |
$request->send_http_header; |
return OK if $request->header_only; |
return OK if $request->header_only; |
|
return '' |
|
} |
|
|
#setup permissions |
sub handle_save_or_undo { |
$Apache::lonhomework::browse= &Apache::lonnet::allowed('bre',$ENV{'request.filename'}); |
my ($request,$problem,$result) = @_; |
$Apache::lonhomework::viewgrades=&Apache::lonnet::allowed('vgr',$ENV{'request.course.id'}); |
my $fileout = &Apache::lonnet::filelocation("",$request->uri); |
|
my $filesave=$fileout.".bak"; |
#check if we know where we are |
|
if ($ENV{'request.course.fn'} && !&Apache::lonnet::symbread()) { |
if ($ENV{'form.Undo'} eq 'undo') { |
# if we are browsing we might not be able to know where we are |
if (copy($filesave,$fileout)) { |
if ($Apache::lonhomework::browse ne 'F') { |
$request->print("<b>Undid changes, Copied $filesave to $fileout<br /></b>"); |
#should know where we are, so ask |
} else { |
$request->internal_redirect('/adm/ambiguous'); return; |
$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>"); |
} |
} |
} |
} |
|
} |
|
|
&Apache::lonhomework::send_header($request); |
sub renderpage { |
&Apache::lonxml::debug("Permissions:$Apache::lonhomework::browse:$Apache::lonhomework::viewgrades:"); |
my ($request,$file) = @_; |
|
|
|
my (@targets) = &get_target(); |
foreach my $target (@targets) { |
foreach my $target (@targets) { |
my $file=&Apache::lonnet::filelocation("",$request->uri); |
#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>"); |
$problem=''; |
$problem=''; |
} |
} |
|
|
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 |
my ($temp)=keys %Apache::lonhomework::history ; |
my ($temp)=keys %Apache::lonhomework::history ; |
if ($temp =~ m/^error:.*/) { %Apache::lonhomework::history=(); } |
if ($temp =~ m/^error:.*/) { %Apache::lonhomework::history=(); } |
Line 183 sub handler {
|
Line 230 sub handler {
|
$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') { |
|
my $resultkey; |
|
foreach $resultkey (sort keys %Apache::lonhomework::history) { |
|
&Apache::lonxml::debug("$resultkey ---- $Apache::lonhomework::history{$resultkey}"); |
|
} |
|
&Apache::lonxml::debug("\n<br />restored values^</br>\n"); |
|
} |
} |
|
if ($target eq 'grade') { &showhash(%Apache::lonhomework::history); } |
|
|
my $default=&Apache::lonnet::getfile('/home/httpd/html/res/adm/includes/default_homework.lcpm'); |
my $default=&Apache::lonnet::getfile('/home/httpd/html/res/adm/includes/default_homework.lcpm'); |
if ($default == -1) { |
if ($default == -1) { |
&Apache::lonxml::error("<b>Unable to find <i>default_homework.lcpm</i></b>"); |
&Apache::lonxml::error("<b>Unable to find <i>default_homework.lcpm</i></b>"); |
Line 201 sub handler {
|
Line 243 sub handler {
|
$default.&setup_vars($target),%mystyle); |
$default.&setup_vars($target),%mystyle); |
|
|
#$request->print("Result follows:"); |
#$request->print("Result follows:"); |
$request->print($result); |
if ($target eq 'modified') { |
|
&handle_save_or_undo($request,\$problem,\$result); |
|
} 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 ends"); |
#$request->print(":Result ends"); |
if ($target eq 'grade') { |
if ($target eq 'grade') { &showhash(%Apache::lonhomework::results); } |
|
|
my $resultkey; |
#store new values |
foreach $resultkey (sort keys %Apache::lonhomework::results) { |
|
&Apache::lonxml::debug("$resultkey ---- $Apache::lonhomework::results{$resultkey}"); |
|
} |
|
&Apache::lonxml::debug("\n<br />storing values^</br>\n"); |
|
} |
|
|
|
my ($temp) = keys %Apache::lonhomework::results; |
my ($temp) = keys %Apache::lonhomework::results; |
if ( $temp ne '' ) { |
if ( $temp ne '' ) { |
&Apache::lonxml::debug("Store return message:".&Apache::lonnet::cstore(%Apache::lonhomework::results)); |
&Apache::lonxml::debug("Store return message:". |
|
&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,$extension) = @_; |
|
my $result; |
|
&Apache::lonxml::debug("Looking for :$extension:"); |
|
foreach my $file (</home/httpd/html/res/adm/includes/templates/*.$extension>) { |
|
my $name=&Apache::lonnet::metadata($file,'title'); |
|
if ($namewanted && ($name eq $namewanted)) { |
|
$result=$file; |
|
last; |
|
} else { |
|
$result.="<option>$name</option>"; |
} |
} |
} |
} |
&Apache::lonhomework::send_footer($request); |
return $result; |
|
} |
|
|
|
sub newproblem { |
|
my ($request) = @_; |
|
|
|
if ($ENV{'form.template'}) { |
|
use File::Copy; |
|
my $extension=$request->uri; |
|
$extension=~s:\.([\w]+)$:$1:; |
|
my $file = &get_template_list($ENV{'form.template'},$extension); |
|
my $dest = &Apache::lonnet::filelocation("",$request->uri); |
|
copy($file,$dest); |
|
&renderpage($request,$file); |
|
} else { |
|
my $templatelist=&get_template_list(); |
|
my $url=$request->uri; |
|
my $dest = &Apache::lonnet::filelocation("",$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 { |
|
#my $t0 = [&gettimeofday()]; |
|
my $request=$_[0]; |
|
|
|
if ( $ENV{'user.name'} eq 'albertel' ) {$Apache::lonxml::debug=1;} |
|
|
|
if (&setupheader($request)) { return OK; } |
|
$ENV{'request.uri'}=$request->uri; |
|
|
|
#setup permissions |
|
$Apache::lonhomework::browse= &Apache::lonnet::allowed('bre',$ENV{'request.filename'}); |
|
$Apache::lonhomework::viewgrades=&Apache::lonnet::allowed('vgr',$ENV{'request.course.id'}); |
|
&Apache::lonxml::debug("Permissions:$Apache::lonhomework::browse:$Apache::lonhomework::viewgrades:"); |
|
|
|
my $file=&Apache::lonnet::filelocation("",$request->uri); |
|
|
|
#check if we know where we are |
|
if ($ENV{'request.course.fn'} && !&Apache::lonnet::symbread()) { |
|
# if we are browsing we might not be able to know where we are |
|
if ($Apache::lonhomework::browse ne 'F') { |
|
#should know where we are, so ask |
|
$request->internal_redirect('/adm/ambiguous'); return; |
|
} |
|
} |
|
|
|
if ($ENV{'request.state'} eq "construct") { |
|
if ( -e $file ) { |
|
if (!(defined $ENV{'form.problemmode'})) { |
|
#first visit to problem in construction space |
|
&view_or_edit_menu($request); |
|
#&renderpage($request,$file); |
|
} else { |
|
&renderpage($request,$file); |
|
} |
|
} else { |
|
# requested file doesn't exist in contruction space |
|
&newproblem($request); |
|
} |
|
} else { |
|
# just render the page normally outside of construction space |
|
&renderpage($request,$file); |
|
} |
|
#my $td=&tv_interval($t0); |
|
#&Apache::lonxml::debug("Spent $td seconds processing"); |
|
# &Apache::lonhomework::send_footer($request); |
|
# always turn off debug messages |
|
$Apache::lonxml::debug=0; |
return OK; |
return OK; |
|
|
} |
} |