version 1.148, 2003/09/19 12:26:56
|
version 1.167, 2004/02/16 19:19:31
|
Line 24
|
Line 24
|
# /home/httpd/html/adm/gpl.txt |
# /home/httpd/html/adm/gpl.txt |
# |
# |
# http://www.lon-capa.org/ |
# http://www.lon-capa.org/ |
# |
|
# Guy Albertelli |
|
# 11/30 Gerd Kortemeyer |
|
# 6/1,8/17,8/18 Gerd Kortemeyer |
|
# 7/18 Jeremy Bowers |
|
|
|
package Apache::lonhomework; |
package Apache::lonhomework; |
use strict; |
use strict; |
Line 90 sub get_target {
|
Line 86 sub get_target {
|
return ('web'); |
return ('web'); |
} |
} |
} else { |
} else { |
if ( $ENV{'form.problemmode'} eq 'View' || |
if ( $ENV{'form.problemmode'} eq &mt('View') || |
$ENV{'form.problemmode'} eq 'Discard Edits and View') { |
$ENV{'form.problemmode'} eq &mt('Discard Edits and View')) { |
if ( defined($ENV{'form.submitted'}) && |
if ( defined($ENV{'form.submitted'}) && |
(!defined($ENV{'form.resetdata'})) && |
(!defined($ENV{'form.resetdata'})) && |
(!defined($ENV{'form.newrandomization'}))) { |
(!defined($ENV{'form.newrandomization'}))) { |
Line 99 sub get_target {
|
Line 95 sub get_target {
|
} else { |
} else { |
return ('web','answer'); |
return ('web','answer'); |
} |
} |
} elsif ( $ENV{'form.problemmode'} eq 'Edit' ) { |
} elsif ( $ENV{'form.problemmode'} eq &mt('Edit') ) { |
if ( $ENV{'form.submitted'} eq 'edit' ) { |
if ( $ENV{'form.submitted'} eq 'edit' ) { |
if ( $ENV{'form.submit'} eq 'Submit Changes and View' ) { |
if ( $ENV{'form.submit'} eq &mt('Submit Changes and View') ) { |
return ('modified','web','answer'); |
return ('modified','web','answer'); |
} else { |
} else { |
return ('modified','edit'); |
return ('modified','edit'); |
Line 147 sub send_footer {
|
Line 143 sub send_footer {
|
|
|
$Apache::lonxml::browse=''; |
$Apache::lonxml::browse=''; |
|
|
|
sub check_ip_acc { |
|
my ($acc)=@_; |
|
if (!defined($acc) || $acc =~ /^\s*$/) { return 1; } |
|
my $allowed=0; |
|
my $ip=$ENV{'REMOTE_ADDR'}; |
|
my $name; |
|
foreach my $pattern (split(',',$acc)) { |
|
if ($pattern =~ /\*$/) { |
|
#35.8.* |
|
$pattern=~s/\*//; |
|
if ($ip =~ /^\Q$pattern\E/) { $allowed=1; } |
|
} elsif ($pattern =~ /(\d+\.\d+\.\d+)\.\[(\d+)-(\d+)\]$/) { |
|
#35.8.3.[34-56] |
|
my $low=$2; |
|
my $high=$3; |
|
$pattern=$1; |
|
if ($ip =~ /^\Q$pattern\E/) { |
|
my $last=(split(/\./,$ip))[3]; |
|
if ($last <=$high && $last >=$low) { $allowed=1; } |
|
} |
|
} elsif ($pattern =~ /^\*/) { |
|
#*.msu.edu |
|
$pattern=~s/\*//; |
|
if (!defined($name)) { |
|
use Socket; |
|
my $netaddr=inet_aton($ip); |
|
($name)=gethostbyaddr($netaddr,AF_INET); |
|
} |
|
if ($name =~ /\Q$pattern\E$/i) { $allowed=1; } |
|
} elsif ($pattern =~ /\d+\.\d+\.\d+\.\d+/) { |
|
#127.0.0.1 |
|
if ($ip =~ /^\Q$pattern\E/) { $allowed=1; } |
|
} else { |
|
#some.name.com |
|
if (!defined($name)) { |
|
use Socket; |
|
my $netaddr=inet_aton($ip); |
|
($name)=gethostbyaddr($netaddr,AF_INET); |
|
} |
|
if ($name =~ /\Q$pattern\E$/i) { $allowed=1; } |
|
} |
|
if ($allowed) { last; } |
|
} |
|
return $allowed; |
|
} |
# JB, 9/24/2002: Any changes in this function may require a change |
# JB, 9/24/2002: Any changes in this function may require a change |
# in lonnavmaps::resource::getDateStatus. |
# in lonnavmaps::resource::getDateStatus. |
sub check_access { |
sub check_access { |
Line 160 sub check_access {
|
Line 201 sub check_access {
|
my $passed; |
my $passed; |
|
|
if ($ENV{'request.state'} eq "construct") { |
if ($ENV{'request.state'} eq "construct") { |
|
if ($ENV{'form.problemstate'}) { |
|
if ($ENV{'form.problemstate'} =~ /^CANNOT_ANSWER/) { |
|
if ( ! ($ENV{'form.problemstate'} eq 'CANNOT_ANSWER_correct' && |
|
lc($Apache::lonhomework::problemstatus) eq 'no')) { |
|
return ('CANNOT_ANSWER','is in this state by royal decree.'); |
|
} |
|
} else { |
|
return ($ENV{'form.problemstate'}, |
|
'is in this state by royal decree.'); |
|
} |
|
} |
&Apache::lonxml::debug("in construction ignoring dates"); |
&Apache::lonxml::debug("in construction ignoring dates"); |
$status='CAN_ANSWER'; |
$status='CAN_ANSWER'; |
$datemsg=&mt('is in under construction'); |
$datemsg=&mt('is in under construction'); |
return ($status,$datemsg); |
# return ($status,$datemsg); |
} |
} |
|
|
&Apache::lonxml::debug("checking for part :$id:"); |
&Apache::lonxml::debug("checking for part :$id:"); |
&Apache::lonxml::debug("time:".time); |
&Apache::lonxml::debug("time:".time); |
foreach $temp ("opendate","duedate","answerdate") { |
|
$lastdate = $date; |
if ($ENV{'request.state'} ne "construct") { |
$date = &Apache::lonnet::EXT("resource.$id.$temp"); |
my $allowed=&check_ip_acc(&Apache::lonnet::EXT("resource.$id.acc")); |
my $thistype = &Apache::lonnet::EXT("resource.$id.$temp.type"); |
if (!$allowed && ($Apache::lonhomework::browse ne 'F')) { |
if ($thistype =~ /^(con_lost|no_such_host)/ || |
$status='INVALID_ACCESS'; |
$date =~ /^(con_lost|no_such_host)/) { |
$date=&mt("can not be accessed from your location."); |
$status='UNAVAILABLE'; |
|
$date=&mt("may open later."); |
|
return($status,$date); |
return($status,$date); |
} |
} |
if ($thistype eq 'date_interval') { |
|
if ($temp eq 'opendate') { |
foreach $temp ("opendate","duedate","answerdate") { |
$date=&Apache::lonnet::EXT("resource.$id.duedate")-$date; |
$lastdate = $date; |
} |
$date = &Apache::lonnet::EXT("resource.$id.$temp"); |
if ($temp eq 'answerdate') { |
my $thistype = &Apache::lonnet::EXT("resource.$id.$temp.type"); |
$date=&Apache::lonnet::EXT("resource.$id.duedate")+$date; |
if ($thistype =~ /^(con_lost|no_such_host)/ || |
|
$date =~ /^(con_lost|no_such_host)/) { |
|
$status='UNAVAILABLE'; |
|
$date=&mt("may open later."); |
|
return($status,$date); |
|
} |
|
if ($thistype eq 'date_interval') { |
|
if ($temp eq 'opendate') { |
|
$date=&Apache::lonnet::EXT("resource.$id.duedate")-$date; |
|
} |
|
if ($temp eq 'answerdate') { |
|
$date=&Apache::lonnet::EXT("resource.$id.duedate")+$date; |
|
} |
} |
} |
|
&Apache::lonxml::debug("found :$date: for :$temp:"); |
|
if ($date eq '') { |
|
$date = &mt("an unknown date"); $passed = 0; |
|
} elsif ($date eq 'con_lost') { |
|
$date = &mt("an indeterminate date"); $passed = 0; |
|
} else { |
|
if (time < $date) { $passed = 0; } else { $passed = 1; } |
|
$date = localtime $date; |
|
} |
|
if (!$passed) { $type=$temp; last; } |
} |
} |
&Apache::lonxml::debug("found :$date: for :$temp:"); |
&Apache::lonxml::debug("have :$type:$passed:"); |
if ($date eq '') { |
if ($passed) { |
$date = &mt("an unknown date"); $passed = 0; |
$status='SHOW_ANSWER'; |
} elsif ($date eq 'con_lost') { |
$datemsg=$date; |
$date = &mt("an indeterminate date"); $passed = 0; |
} elsif ($type eq 'opendate') { |
} else { |
$status='CLOSED'; |
if (time < $date) { $passed = 0; } else { $passed = 1; } |
$datemsg = &mt("will open on")." $date"; |
$date = localtime $date; |
} elsif ($type eq 'duedate') { |
|
$status='CAN_ANSWER'; |
|
$datemsg = &mt("is due at")." $date"; |
|
} elsif ($type eq 'answerdate') { |
|
$status='CLOSED'; |
|
$datemsg = &mt("was due on")." $lastdate".&mt(", and answers will be available on")." $date"; |
} |
} |
if (!$passed) { $type=$temp; last; } |
|
} |
|
&Apache::lonxml::debug("have :$type:$passed:"); |
|
if ($passed) { |
|
$status='SHOW_ANSWER'; |
|
$datemsg=$date; |
|
} elsif ($type eq 'opendate') { |
|
$status='CLOSED'; |
|
$datemsg = &mt("will open on")." $date"; |
|
} elsif ($type eq 'duedate') { |
|
$status='CAN_ANSWER'; |
|
$datemsg = &mt("is due at")." $date"; |
|
} elsif ($type eq 'answerdate') { |
|
$status='CLOSED'; |
|
$datemsg = &mt("was due on")." $lastdate".&mt(", and answers will be available on")." $date"; |
|
} |
} |
if ($status eq 'CAN_ANSWER') { |
if ($status eq 'CAN_ANSWER') { |
#check #tries, and if correct. |
#check #tries, and if correct. |
my $tries = $Apache::lonhomework::history{"resource.$id.tries"}; |
my $tries = $Apache::lonhomework::history{"resource.$id.tries"}; |
my $maxtries = &Apache::lonnet::EXT("resource.$id.maxtries"); |
my $maxtries = &Apache::lonnet::EXT("resource.$id.maxtries"); |
if ( $tries eq '' ) { $tries = '0'; } |
if ( $tries eq '' ) { $tries = '0'; } |
if ( $maxtries eq '' ) { $maxtries = '2'; } |
if ( $maxtries eq '' && |
if ($tries >= $maxtries) { $status = 'CANNOT_ANSWER'; } |
$ENV{'request.state'} ne 'construct') { $maxtries = '2'; } |
|
if ($maxtries && $tries >= $maxtries) { $status = 'CANNOT_ANSWER'; } |
# if (correct and show prob status) or excused then CANNOT_ANSWER |
# if (correct and show prob status) or excused then CANNOT_ANSWER |
if(($Apache::lonhomework::history{"resource.$id.solved"}=~/^correct/ |
if(($Apache::lonhomework::history{"resource.$id.solved"}=~/^correct/ |
&& |
&& |
Line 307 sub setuppermissions {
|
Line 370 sub setuppermissions {
|
sub setupheader { |
sub setupheader { |
my $request=$_[0]; |
my $request=$_[0]; |
if ($ENV{'browser.mathml'}) { |
if ($ENV{'browser.mathml'}) { |
$request->content_type('text/xml'); |
&Apache::loncommon::content_type($request,'text/xml'); |
} else { |
} else { |
$request->content_type('text/html'); |
&Apache::loncommon::content_type($request,'text/html'); |
} |
} |
$request->content_encoding('UTF-8'); |
|
if (!$Apache::lonxml::debug && ($ENV{'REQUEST_METHOD'} eq 'GET')) { |
if (!$Apache::lonxml::debug && ($ENV{'REQUEST_METHOD'} eq 'GET')) { |
&Apache::loncommon::no_cache($request); |
&Apache::loncommon::no_cache($request); |
} |
} |
Line 327 sub handle_save_or_undo {
|
Line 389 sub handle_save_or_undo {
|
my $filetmp =$file.".tmp"; |
my $filetmp =$file.".tmp"; |
my $error=0; |
my $error=0; |
|
|
if ($ENV{'form.Undo'} eq 'undo') { |
&Apache::lonnet::correct_line_ends($result); |
|
|
|
if ($ENV{'form.Undo'} eq &mt('undo')) { |
my $error=0; |
my $error=0; |
if (!copy($file,$filetmp)) { $error=1; } |
if (!copy($file,$filetmp)) { $error=1; } |
if ((!$error) && (!copy($filebak,$file))) { $error=1; } |
if ((!$error) && (!copy($filebak,$file))) { $error=1; } |
Line 440 sub analyze {
|
Line 504 sub analyze {
|
} |
} |
$request->print('</table>'); |
$request->print('</table>'); |
} else { |
} else { |
$request->print('<p>'.&mt('Part').' '.$part.' '. |
$request->print('<p>'.&mt('Response').' '.$part.' '. |
&mt('is not analyzable at this time').'</p>'); |
&mt('is not analyzable at this time').'</p>'); |
} |
} |
} |
} |
if (scalar(keys(%allparts)) == 0 ) { |
if (scalar(keys(%allparts)) == 0 ) { |
$request->print('<p>'.&mt('Found no analyzable parts in this problem, |
$request->print('<p>'.&mt('Found no analyzable respones in this problem, currently only Numerical, Formula and String response styles are supported.').'</p>'); |
currently only Numerical, Formula and String response |
|
styles are supported.').'</p>'); |
|
} |
} |
&Apache::lonhtmlcommon::Close_PrgWin($request,\%prog_state); |
&Apache::lonhtmlcommon::Close_PrgWin($request,\%prog_state); |
&analyze_footer($request); |
&analyze_footer($request); |
Line 470 sub editxmlmode {
|
Line 532 sub editxmlmode {
|
if (!$error) { $problem=&Apache::lonnet::getfile($file); } |
if (!$error) { $problem=&Apache::lonnet::getfile($file); } |
} |
} |
&Apache::lonhomework::showhashsubset(\%ENV,'^form'); |
&Apache::lonhomework::showhashsubset(\%ENV,'^form'); |
if ( $ENV{'form.submit'} eq 'Submit Changes and View' ) { |
if ( $ENV{'form.submit'} eq &mt('Submit Changes and View') ) { |
&Apache::lonhomework::showhashsubset(\%ENV,'^form'); |
&Apache::lonhomework::showhashsubset(\%ENV,'^form'); |
$ENV{'form.problemmode'}='View'; |
$ENV{'form.problemmode'}='View'; |
&renderpage($request,$file); |
&renderpage($request,$file); |
} else { |
} else { |
my ($rows,$cols) = &Apache::edit::textarea_sizes(\$problem); |
my ($rows,$cols) = &Apache::edit::textarea_sizes(\$problem); |
my $xml_help = Apache::loncommon::helpLatexCheatsheet("Problem_Editor_XML_Index", |
my $xml_help = '<table><tr><td>'. |
"Problem Editing Help"); |
&Apache::loncommon::helpLatexCheatsheet("Problem_Editor_XML_Index", |
|
"Problem Editing Help"). |
|
'</td><td>'. |
|
&Apache::loncommon::help_open_faq(5). |
|
&Apache::loncommon::help_open_bug('Authoring').'</td></tr></table>'; |
if ($cols > 80) { $cols = 80; } |
if ($cols > 80) { $cols = 80; } |
if ($cols < 70) { $cols = 70; } |
if ($cols < 70) { $cols = 70; } |
if ($rows < 20) { $rows = 20; } |
if ($rows < 20) { $rows = 20; } |
Line 505 sub renderpage {
|
Line 571 sub renderpage {
|
my ($request,$file) = @_; |
my ($request,$file) = @_; |
|
|
my (@targets) = &get_target(); |
my (@targets) = &get_target(); |
|
&Apache::lonhomework::showhashsubset(\%ENV,'form.'); |
&Apache::lonxml::debug("Running targets ".join(':',@targets)); |
&Apache::lonxml::debug("Running targets ".join(':',@targets)); |
foreach my $target (@targets) { |
foreach my $target (@targets) { |
#my $t0 = [&gettimeofday()]; |
#my $t0 = [&gettimeofday()]; |
Line 592 sub newproblem {
|
Line 659 sub newproblem {
|
&renderpage($request,$dest); |
&renderpage($request,$dest); |
} else { |
} else { |
my $url=$request->uri; |
my $url=$request->uri; |
|
my $shownurl=$url; |
|
$shownurl=~s-^/~-/priv/-; |
my $dest = &Apache::lonnet::filelocation("",$request->uri); |
my $dest = &Apache::lonnet::filelocation("",$request->uri); |
my $errormsg; |
my $errormsg; |
if ($ENV{'form.newfile'}) { |
if ($ENV{'form.newfile'}) { |
$errormsg='<p><font color="red">'.&mt('You did not select a template.').'</font></p>'."\n"; |
$errormsg='<p><font color="red">'.&mt('You did not select a template.').'</font></p>'."\n"; |
} |
} |
my $instructions; |
my $instructions; |
|
my $bodytag=&Apache::loncommon::bodytag(undef,undef,undef,1); |
if ($templatelist) { $instructions=&mt(", select a template from the pull-down menu below.").'<br />'.&mt("Then");} |
if ($templatelist) { $instructions=&mt(", select a template from the pull-down menu below.").'<br />'.&mt("Then");} |
my %lt=&Apache::lonlocal::texthash( 'create' => 'Creating a new', |
my %lt=&Apache::lonlocal::texthash( 'create' => 'Creating a new', |
'resource' => 'resource', |
'resource' => 'resource', |
Line 608 sub newproblem {
|
Line 678 sub newproblem {
|
'Create' => 'Create', |
'Create' => 'Create', |
'button' => 'button'); |
'button' => 'button'); |
$request->print(<<ENDNEWPROBLEM); |
$request->print(<<ENDNEWPROBLEM); |
<body bgcolor="#FFFFFF"> |
$bodytag |
<h1>$lt{'create'} $extension $lt{'resource'}</h1> |
<h1>$lt{'create'} $extension $lt{'resource'}</h1> |
$errormsg |
$errormsg |
$lt{'requested'} <tt>$url</tt> $lt{'not exist'}. |
$lt{'requested'} <tt>$shownurl</tt> $lt{'not exist'}. |
<p> |
<p> |
<b>$lt{'createnew'} $extension$instructions $lt{'click'} "$lt{'Create'} $extension" $lt{'button'}.</b> |
<b>$lt{'createnew'} $extension$instructions $lt{'click'} "$lt{'Create'} $extension" $lt{'button'}.</b> |
</p> |
</p> |
Line 650 sub handler {
|
Line 720 sub handler {
|
my $request=$_[0]; |
my $request=$_[0]; |
|
|
$Apache::lonxml::debug=$ENV{'user.debug'}; |
$Apache::lonxml::debug=$ENV{'user.debug'}; |
|
|
if (&setupheader($request)) { return OK; } |
if (&setupheader($request)) { return OK; } |
$ENV{'request.uri'}=$request->uri; |
$ENV{'request.uri'}=$request->uri; |
|
|
Line 686 sub handler {
|
Line 755 sub handler {
|
my ($symb) = &Apache::lonxml::whichuser(); |
my ($symb) = &Apache::lonxml::whichuser(); |
&Apache::lonxml::debug('symb is '.$symb); |
&Apache::lonxml::debug('symb is '.$symb); |
if ($ENV{'request.state'} eq "construct" || $symb eq '') { |
if ($ENV{'request.state'} eq "construct" || $symb eq '') { |
if ($ENV{'form.resetdata'} eq 'Reset Submissions' || |
if ($ENV{'form.resetdata'} eq &mt('Reset Submissions') || |
$ENV{'form.resetdata'} eq 'New Problem Variation' || |
$ENV{'form.resetdata'} eq &mt('New Problem Variation') || |
$ENV{'form.newrandomization'} eq 'New Randomization') { |
$ENV{'form.newrandomization'} eq &mt('New Randomization')) { |
my ($symb,$courseid,$domain,$name) = &Apache::lonxml::whichuser(); |
my ($symb,$courseid,$domain,$name) = &Apache::lonxml::whichuser(); |
&Apache::lonnet::tmpreset($symb,'',$domain,$name); |
&Apache::lonnet::tmpreset($symb,'',$domain,$name); |
&Apache::lonxml::debug("Attempt reset"); |
&Apache::lonxml::debug("Attempt reset"); |
Line 703 sub handler {
|
Line 772 sub handler {
|
#&view_or_edit_menu($request); |
#&view_or_edit_menu($request); |
$ENV{'form.problemmode'}='View'; |
$ENV{'form.problemmode'}='View'; |
&renderpage($request,$file); |
&renderpage($request,$file); |
} elsif ($ENV{'form.problemmode'} eq 'EditXML') { |
} elsif ($ENV{'form.problemmode'} eq &mt('EditXML')) { |
&editxmlmode($request,$file); |
&editxmlmode($request,$file); |
} elsif ($ENV{'form.problemmode'} eq 'Calculate answers') { |
} elsif ($ENV{'form.problemmode'} eq &mt('Calculate answers')) { |
&analyze($request,$file); |
&analyze($request,$file); |
} else { |
} else { |
&renderpage($request,$file); |
&renderpage($request,$file); |