version 1.287, 2007/12/24 06:35:18
|
version 1.304, 2009/03/04 16:00:14
|
Line 137 sub get_target {
|
Line 137 sub get_target {
|
if ($env{'form.problemstate'} eq 'WEB_GRADE') { |
if ($env{'form.problemstate'} eq 'WEB_GRADE') { |
#$env{'form.webgrade'} = 'yes'; |
#$env{'form.webgrade'} = 'yes'; |
return ('grade','webgrade','answer'); |
return ('grade','webgrade','answer'); |
} elsif ( $env{'form.problemmode'} eq &mt('View') || |
} elsif (($env{'form.problemmode'} eq 'view') || |
$env{'form.problemmode'} eq &mt('Discard Edits and View')) { |
($env{'form.problemmode'} eq 'discard')) { |
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 146 sub get_target {
|
Line 146 sub get_target {
|
} else { |
} else { |
return ('web','answer'); |
return ('web','answer'); |
} |
} |
} elsif ( $env{'form.problemmode'} eq &mt('Edit') || |
} elsif ($env{'form.problemmode'} eq 'edit') { |
$env{'form.problemmode'} eq 'Edit') { |
|
if ( $env{'form.submitted'} eq 'edit' ) { |
if ( $env{'form.submitted'} eq 'edit' ) { |
if ( $env{'form.submit'} eq &mt('Save and View') ) { |
if ( $env{'form.submitbutton'} eq &mt('Save and View') ) { |
return ('modified','web','answer'); |
return ('modified','web','answer'); |
} else { |
} else { |
return ('modified','no_output_web','edit'); |
return ('modified','no_output_web','edit'); |
Line 210 sub proctor_checked_in {
|
Line 209 sub proctor_checked_in {
|
return 0; |
return 0; |
} |
} |
|
|
sub check_ip_acc { |
|
my ($acc)=@_; |
|
&Apache::lonxml::debug("acc is $acc"); |
|
if (!defined($acc) || $acc =~ /^\s*$/ || $acc =~/^\s*no\s*$/i) { |
|
return 1; |
|
} |
|
my $allowed=0; |
|
my $ip=$env{'request.host'} || $ENV{'REMOTE_ADDR'}; |
|
|
|
my $name; |
|
foreach my $pattern (split(',',$acc)) { |
|
$pattern =~ s/^\s*//; |
|
$pattern =~ s/\s*$//; |
|
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; |
|
} |
|
|
|
sub check_slot_access { |
sub check_slot_access { |
my ($id,$type)=@_; |
my ($id,$type)=@_; |
|
|
Line 292 sub check_slot_access {
|
Line 239 sub check_slot_access {
|
} |
} |
} |
} |
|
|
my @slots= |
my $availablestudent = &Apache::lonnet::EXT("resource.0.availablestudent"); |
(split(':',&Apache::lonnet::EXT("resource.0.availablestudent")), |
my $available = &Apache::lonnet::EXT("resource.0.available"); |
split(':',&Apache::lonnet::EXT("resource.0.available"))); |
my @slots= (split(':',$availablestudent),split(':',$available)); |
|
|
# if (!@slots) { |
# if (!@slots) { |
# return ($status,$datemsg); |
# return ($status,$datemsg); |
Line 308 sub check_slot_access {
|
Line 255 sub check_slot_access {
|
&Apache::lonhomework::showhash(%slot); |
&Apache::lonhomework::showhash(%slot); |
if ($slot{'starttime'} < time && |
if ($slot{'starttime'} < time && |
$slot{'endtime'} > time && |
$slot{'endtime'} > time && |
&check_ip_acc($slot{'ip'})) { |
&Apache::loncommon::check_ip_acc($slot{'ip'})) { |
&Apache::lonxml::debug("$slot is good"); |
&Apache::lonxml::debug("$slot is good"); |
$slotstatus='NEEDS_CHECKIN'; |
$slotstatus='NEEDS_CHECKIN'; |
$returned_slot=\%slot; |
$returned_slot=\%slot; |
Line 421 sub check_access {
|
Line 368 sub check_access {
|
&Apache::lonxml::debug("symb:".$symb); |
&Apache::lonxml::debug("symb:".$symb); |
#if ($env{'request.state'} ne "construct" && $symb ne '') { |
#if ($env{'request.state'} ne "construct" && $symb ne '') { |
if ($env{'request.state'} ne "construct") { |
if ($env{'request.state'} ne "construct") { |
my $allowed=&check_ip_acc(&Apache::lonnet::EXT("resource.$id.acc")); |
my $idacc = &Apache::lonnet::EXT("resource.$id.acc"); |
|
my $allowed=&Apache::loncommon::check_ip_acc($idacc); |
if (!$allowed && ($Apache::lonhomework::browse ne 'F')) { |
if (!$allowed && ($Apache::lonhomework::browse ne 'F')) { |
$status='INVALID_ACCESS'; |
$status='INVALID_ACCESS'; |
$date=&mt("can not be accessed from your location."); |
$date=&mt("can not be accessed from your location."); |
Line 712 sub handle_save_or_undo {
|
Line 660 sub handle_save_or_undo {
|
my $fs=Apache::File->new(">$filebak"); |
my $fs=Apache::File->new(">$filebak"); |
if (defined($fs)) { |
if (defined($fs)) { |
print $fs $$problem; |
print $fs $$problem; |
&Apache::lonxml::info("<b>".&mt("Making Backup to [_1]", |
|
'<span class="LC_filename">'. |
|
$filebak.'</span>'). |
|
"</b>"); |
|
} else { |
} else { |
&Apache::lonxml::info("<span class=\"LC_error\">". |
&Apache::lonxml::info("<span class=\"LC_error\">". |
&mt("Unable to make backup [_1]", |
&mt("Unable to make backup [_1]", |
Line 726 sub handle_save_or_undo {
|
Line 670 sub handle_save_or_undo {
|
my $fh=Apache::File->new(">$file"); |
my $fh=Apache::File->new(">$file"); |
if (defined($fh)) { |
if (defined($fh)) { |
print $fh $$result; |
print $fh $$result; |
&Apache::lonxml::info("<b>".&mt("Saving Modifications to [_1]", |
|
'<span class="LC_filename">'. |
|
$file.'</span>' )."</b>"); |
|
} else { |
} else { |
&Apache::lonxml::info('<span class="LC_error">'. |
&Apache::lonxml::info('<span class="LC_error">'. |
&mt("Unable to write to [_1]", |
&mt("Unable to write to [_1]", |
Line 743 sub handle_save_or_undo {
|
Line 684 sub handle_save_or_undo {
|
|
|
sub analyze_header { |
sub analyze_header { |
my ($request) = @_; |
my ($request) = @_; |
|
my $js = &Apache::structuretags::setmode_javascript(); |
my $result = |
my $result = |
&Apache::loncommon::start_page('Analyzing a problem',undef); |
&Apache::loncommon::start_page('Analyzing a problem',$js); |
|
|
$result .= |
$result .= |
&Apache::lonxml::message_location().' |
&Apache::lonxml::message_location().' |
<form name="lonhomework" method="POST" action="'. |
<form name="lonhomework" method="POST" action="'. |
&HTML::Entities::encode($env{'request.uri'},'<>&"').'">'. |
&HTML::Entities::encode($env{'request.uri'},'<>&"').'">'. |
|
'<input type="hidden" name="problemmode" value="'. |
|
$env{'form.problemmode'}.'" />'. |
&Apache::structuretags::remember_problem_state().' |
&Apache::structuretags::remember_problem_state().' |
<div class="LC_edit_problem_analyze_header"> |
<div class="LC_edit_problem_analyze_header"> |
<input type="submit" name="problemmode" value="'.&mt("EditXML").'" /> |
<input type="button" name="submitmode" value="'.&mt("EditXML").'" '. |
<input type="submit" name="problemmode" value="'.&mt('Edit').'" /> |
'onclick="javascript:setmode(this.form,'."'editxml'".')" /> |
|
<input type="button" name="submitmode" value="'.&mt('Edit').'" '. |
|
'onclick="javascript:setmode(this.form,'."'edit'".')" /> |
<hr class="LC_edit_problem_divide" /> |
<hr class="LC_edit_problem_divide" /> |
|
<input type="button" name="submitmode" value="'.&mt("View").'" '. |
<input type="submit" name="submit" value="'.&mt("View").'" /> |
'onclick="javascript:setmode(this.form,'."'view'".')" /> |
<hr class="LC_edit_problem_divide" /> |
<hr class="LC_edit_problem_divide" /> |
</div> |
</div> |
</form>'; |
</form>'; |
Line 919 sub editxmlmode {
|
Line 865 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 &mt('Save and View') ) { |
if ( $env{'form.submitbutton'} eq &mt('Save 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 = '<table><tr><td>'. |
|
&Apache::loncommon::helpLatexCheatsheet("Problem_Editor_XML_Index", |
|
"Problem Editing Help"). |
|
'</td><td>'. |
|
&Apache::loncommon::help_open_menu(undef,undef,5,'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; } |
my $js = |
my $js = |
&Apache::edit::js_change_detection(). |
&Apache::edit::js_change_detection(). |
&Apache::loncommon::resize_textarea_js(); |
&Apache::loncommon::resize_textarea_js(). |
|
&Apache::structuretags::setmode_javascript(). |
|
&Apache::lonhtmlcommon::dragmath_js("EditMathPopup"); |
my $only_body = ($env{'environment.remote'} eq 'off')? 0 : 1; |
my $only_body = ($env{'environment.remote'} eq 'off')? 0 : 1; |
|
my $dragmath_button = |
|
&Apache::lonhtmlcommon::dragmath_button("LC_editxmltext",1); |
my $start_page = |
my $start_page = |
&Apache::loncommon::start_page(&mt("EditXML [_1]",$file),$js, |
&Apache::loncommon::start_page(&mt("EditXML [_1]",$file),$js, |
{'no_auto_mt_title' => 1, |
{'no_auto_mt_title' => 1, |
Line 946 sub editxmlmode {
|
Line 890 sub editxmlmode {
|
'onresize' => q[resize_textarea('LC_editxmltext','LC_aftertextarea')], |
'onresize' => q[resize_textarea('LC_editxmltext','LC_aftertextarea')], |
'onload' => q[resize_textarea('LC_editxmltext','LC_aftertextarea')], |
'onload' => q[resize_textarea('LC_editxmltext','LC_aftertextarea')], |
}}); |
}}); |
|
|
$result.=$start_page. |
$result.=$start_page. |
&renderpage($request,$file,['no_output_web'],1). |
&renderpage($request,$file,['no_output_web'],1). |
'<form '.&Apache::edit::form_change_detection().' name="lonhomework" method="POST" action="'. |
'<form '.&Apache::edit::form_change_detection().' name="lonhomework" method="POST" action="'. |
Line 956 sub editxmlmode {
|
Line 899 sub editxmlmode {
|
<table class="LC_edit_problem_header_title"><tr><td> |
<table class="LC_edit_problem_header_title"><tr><td> |
'.&mt('Problem Editing').&Apache::loncommon::help_open_topic('Problem_Editor_XML_Index').' |
'.&mt('Problem Editing').&Apache::loncommon::help_open_topic('Problem_Editor_XML_Index').' |
</td><td align="right"> |
</td><td align="right"> |
'.&Apache::loncommon::helpLatexCheatsheet().' |
'.&Apache::loncommon::helpLatexCheatsheet('Problem_LON-CAPA_Functions','Script Functions').' |
</td></tr> |
</td></tr> |
</table> |
</table> |
<div class="LC_edit_problem_discards"> |
<div class="LC_edit_problem_discards"> |
<input type="hidden" name="problemmode" value="'.&mt('EditXML').'" /> |
<input type="hidden" name="problemmode" value="editxml" /> |
<input type="submit" name="problemmode" accesskey="d" value="'.&mt('Discard Edits and View').'" /> |
|
<input type="submit" '.&Apache::edit::submit_ask_anyway().'name="problemmode" accesskey="e" value="'.&mt('Edit').'" /> |
<input type="button" name="submitmode" accesskey="d" value="'.&mt('Discard Edits and View').'" '. |
|
'onclick="javascript:setmode(this.form,'."'discard'".')" /> |
|
<input type="button" '.&Apache::edit::submit_ask_anyway('setmode(this.form,'."'edit'".')').'name="submitmode" accesskey="e" value="'.&mt('Edit').'" /> |
<input type="submit" name="Undo" accesskey="u" value="'.&mt('undo').'" /> |
<input type="submit" name="Undo" accesskey="u" value="'.&mt('undo').'" /> |
|
'.$dragmath_button.' |
</div> |
</div> |
<div class="LC_edit_problem_saves"> |
<div class="LC_edit_problem_saves"> |
<input type="submit" name="submit" accesskey="s" value="'.&mt('Save').'" /> |
<input type="submit" name="submitbutton" accesskey="s" value="'.&mt('Save').'" /> |
<input type="submit" name="submit" accesskey="v" value="'.&mt('Save and View').'" /> |
<input type="submit" name="submitbutton" accesskey="v" value="'.&mt('Save and View').'" /> |
</div> |
</div> |
<hr class="LC_edit_problem_divide" /> |
<hr class="LC_edit_problem_divide" /> |
'.&Apache::lonxml::message_location().' |
'.&Apache::lonxml::message_location().' |
Line 1080 sub get_template_list {
|
Line 1026 sub get_template_list {
|
} |
} |
my @files = glob($Apache::lonnet::perlvar{'lonIncludes'}. |
my @files = glob($Apache::lonnet::perlvar{'lonIncludes'}. |
'/templates/*.'.$glob_extension); |
'/templates/*.'.$glob_extension); |
@files = map {[$_,&mt(&Apache::lonnet::metadata($_, 'title'))]} (@files); |
@files = map {[$_,&mt(&Apache::lonnet::metadata($_, 'title')), |
@files = sort {$a->[1] cmp $b->[1]} (@files); |
(&Apache::lonnet::metadata($_, 'category')?&mt(&Apache::lonnet::metadata($_, 'category')):&mt('Miscellaneous')), |
|
&mt(&Apache::lonnet::metadata($_, 'help'))]} (@files); |
|
@files = sort {$a->[2].$a->[1] cmp $b->[2].$b->[1]} (@files); |
my ($midpoint,$seconddiv,$numfiles); |
my ($midpoint,$seconddiv,$numfiles); |
$numfiles = 0; |
$numfiles = 0; |
foreach my $file (@files) { |
foreach my $file (@files) { |
Line 1096 sub get_template_list {
|
Line 1044 sub get_template_list {
|
} |
} |
} |
} |
my $count = 0; |
my $count = 0; |
|
my $currentcategory=''; |
foreach my $file (@files) { |
foreach my $file (@files) { |
next if ($file->[1] !~ /\S/); |
next if ($file->[1] !~ /\S/); |
|
if ($file->[2] ne $currentcategory) { |
|
$currentcategory=$file->[2]; |
|
if ((!$seconddiv) && ($count >= $midpoint)) { |
|
$result .= '</div>'."\n".'<div class="LC_left_float">'."\n"; |
|
$seconddiv = 1; |
|
} |
|
$result.='<h3>'.$currentcategory.'</h3>'; |
|
$count++; |
|
} |
$result .= |
$result .= |
'<label><input type="radio" name="template" value="'.$file->[0].'" />'. |
'<label><input type="radio" name="template" value="'.$file->[0].'" />'. |
$file->[1].'</label><br />'."\n"; |
$file->[1].'</label>'; |
$count ++; |
if ($file->[3]) { |
if ((!$seconddiv) && ($count >= $midpoint)) { |
$result.=&Apache::loncommon::help_open_topic($file->[3]); |
$result .= '</div>'."\n".'<div class="LC_left_float">'."\n"; |
|
$seconddiv = 1; |
|
} |
} |
|
my $filename=$file->[0]; |
|
$filename=~s/^\/home\/httpd\/html//; |
|
$result.=' <font size="-2"><a href="'.$filename.'" target="sample">'.&mt('Example').'</font></a><br />'."\n"; |
|
$count ++; |
} |
} |
if ($numfiles > 0) { |
if ($numfiles > 0) { |
$result .= '</div>'."\n".'<div class="LC_clear_float_footer"></div>'."\n"; |
$result .= '</div>'."\n".'<div class="LC_clear_float_footer"></div>'."\n"; |
Line 1168 $errormsg
|
Line 1128 $errormsg
|
|
|
sub update_construct_style { |
sub update_construct_style { |
if ($env{'request.state'} eq "construct" |
if ($env{'request.state'} eq "construct" |
&& $env{'form.problemmode'} eq &mt('View') |
&& $env{'form.problemmode'} eq 'view' |
&& defined($env{'form.submitted'}) |
&& defined($env{'form.submitted'}) |
&& !defined($env{'form.resetdata'}) |
&& !defined($env{'form.resetdata'}) |
&& !defined($env{'form.newrandomization'})) { |
&& !defined($env{'form.newrandomization'})) { |
if ((!$env{'form.style_file'} && $env{'construct.style'}) |
if ((!$env{'form.style_file'} && $env{'construct.style'}) |
||$env{'form.clear_style_file'}) { |
||$env{'form.clear_style_file'}) { |
&Apache::lonnet::delenv('construct\\.style'); |
&Apache::lonnet::delenv('construct.style'); |
} elsif ($env{'form.style_file'} |
} elsif ($env{'form.style_file'} |
&& $env{'construct.style'} ne $env{'form.style_file'}) { |
&& $env{'construct.style'} ne $env{'form.style_file'}) { |
&Apache::lonnet::appenv('construct.style' => |
&Apache::lonnet::appenv({'construct.style' => |
$env{'form.style_file'}); |
$env{'form.style_file'}}); |
} |
} |
} |
} |
} |
} |
Line 1191 sub handler {
|
Line 1151 sub handler {
|
$Apache::lonxml::debug=$env{'user.debug'}; |
$Apache::lonxml::debug=$env{'user.debug'}; |
$env{'request.uri'}=$request->uri; |
$env{'request.uri'}=$request->uri; |
&setuppermissions(); |
&setuppermissions(); |
# some times multiple problemmodes are submitted, need to select |
|
# the last one |
|
if ( defined($env{'form.problemmode'}) && ref($env{'form.problemmode'}) ) { |
|
my $mode=$env{'form.problemmode'}->[-1]; |
|
undef $env{'form.problemmode'}; |
|
$env{'form.problemmode'}=$mode; |
|
} |
|
|
|
my $file=&Apache::lonnet::filelocation("",$request->uri); |
my $file=&Apache::lonnet::filelocation("",$request->uri); |
|
|
Line 1226 sub handler {
|
Line 1179 sub handler {
|
['problemmode']); |
['problemmode']); |
if (!(defined $env{'form.problemmode'})) { |
if (!(defined $env{'form.problemmode'})) { |
#first visit to problem in construction space |
#first visit to problem in construction space |
$env{'form.problemmode'}='View'; |
$env{'form.problemmode'}= 'view'; |
&renderpage($request,$file); |
&renderpage($request,$file); |
} elsif ($env{'form.problemmode'} eq &mt('EditXML') || |
} elsif ($env{'form.problemmode'} eq 'editxml') { |
$env{'form.problemmode'} eq 'EditXML') { |
|
&editxmlmode($request,$file); |
&editxmlmode($request,$file); |
} elsif ($env{'form.problemmode'} eq &mt('Calculate answers')) { |
} elsif ($env{'form.problemmode'} eq 'calcanswers') { |
&analyze($request,$file); |
&analyze($request,$file); |
} else { |
} else { |
&update_construct_style(); |
&update_construct_style(); |