version 1.272, 2007/08/24 22:58:18
|
version 1.295, 2008/07/07 11:02:25
|
Line 49 use Apache::matchresponse();
|
Line 49 use Apache::matchresponse();
|
use Apache::chemresponse(); |
use Apache::chemresponse(); |
use Apache::drawimage(); |
use Apache::drawimage(); |
use Apache::Constants qw(:common); |
use Apache::Constants qw(:common); |
use HTML::Entities(); |
|
use Apache::loncommon(); |
use Apache::loncommon(); |
use Apache::lonlocal; |
use Apache::lonlocal; |
use Time::HiRes qw( gettimeofday tv_interval ); |
use Time::HiRes qw( gettimeofday tv_interval ); |
use Apache::lonnet(); |
use HTML::Entities(); |
|
use File::Copy(); |
|
|
# FIXME - improve commenting |
# FIXME - improve commenting |
|
|
Line 63 BEGIN {
|
Line 63 BEGIN {
|
} |
} |
|
|
|
|
|
=pod |
|
|
|
=item set_bubble_lines() |
|
|
|
Called at analysis time to set the bubble lines |
|
hash for the problem.. This should be called in the |
|
end_problemtype tag in analysis mode. |
|
|
|
We fetch the hash of part id counters from lonxml |
|
and push them into analyze:{part_id.bubble_lines}. |
|
|
|
=cut |
|
|
|
sub set_bubble_lines { |
|
my %bubble_counters = &Apache::lonxml::get_bubble_line_hash(); |
|
|
|
foreach my $key (keys(%bubble_counters)) { |
|
$Apache::lonhomework::analyze{"$key.bubble_lines"} = |
|
$bubble_counters{"$key"}; |
|
} |
|
} |
|
|
# |
# |
# Decides what targets to render for. |
# Decides what targets to render for. |
# Implicit inputs: |
# Implicit inputs: |
Line 115 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 124 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('Submit Changes 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 270 sub check_slot_access {
|
Line 291 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 376 sub check_access {
|
Line 397 sub check_access {
|
if ($env{'request.state'} eq "construct") { |
if ($env{'request.state'} eq "construct") { |
if ($env{'form.problemstate'}) { |
if ($env{'form.problemstate'}) { |
if ($env{'form.problemstate'} =~ /^CANNOT_ANSWER/) { |
if ($env{'form.problemstate'} =~ /^CANNOT_ANSWER/) { |
if ( ! ($env{'form.problemstate'} eq 'CANNOT_ANSWER_correct' && |
if ( ! ($env{'form.problemstate'} eq 'CANNOT_ANSWER_correct' |
lc($Apache::lonhomework::problemstatus) eq 'no')) { |
&& &hide_problem_status())) { |
return ('CANNOT_ANSWER', |
return ('CANNOT_ANSWER', |
&mt('is in this state due to author settings.')); |
&mt('is in this state due to author settings.')); |
} |
} |
Line 399 sub check_access {
|
Line 420 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=&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 436 sub check_access {
|
Line 458 sub check_access {
|
$date = &mt("an indeterminate date"); $passed = 0; |
$date = &mt("an indeterminate date"); $passed = 0; |
} else { |
} else { |
if (time < $date) { $passed = 0; } else { $passed = 1; } |
if (time < $date) { $passed = 0; } else { $passed = 1; } |
$date = localtime $date; |
$date = &Apache::lonlocal::locallocaltime($date); |
} |
} |
if (!$passed) { $type=$temp; last; } |
if (!$passed) { $type=$temp; last; } |
} |
} |
Line 467 sub check_access {
|
Line 489 sub check_access {
|
# 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/ |
&& |
&& |
lc($Apache::lonhomework::problemstatus) ne 'no') |
&show_problem_status()) |
|| |
|| |
$Apache::lonhomework::history{"resource.$id.solved"}=~/^excused/) { |
$Apache::lonhomework::history{"resource.$id.solved"}=~/^excused/) { |
$status = 'CANNOT_ANSWER'; |
$status = 'CANNOT_ANSWER'; |
} |
} |
|
if ($status eq 'CANNOT_ANSWER' |
|
&& &show_answer_problem_status()) { |
|
$status = 'SHOW_ANSWER'; |
|
} |
} |
} |
if ($status eq 'CAN_ANSWER' || $status eq 'CANNOT_ANSWER') { |
if ($status eq 'CAN_ANSWER' || $status eq 'CANNOT_ANSWER') { |
my $interval=&Apache::lonnet::EXT("resource.$id.interval"); |
my @interval=&Apache::lonnet::EXT("resource.$id.interval"); |
&Apache::lonxml::debug("looking for interval $interval"); |
&Apache::lonxml::debug("looking for interval @interval"); |
if ($interval) { |
if ($interval[0]) { |
my $first_access=&Apache::lonnet::get_first_access('map'); |
my $first_access=&Apache::lonnet::get_first_access($interval[1]); |
&Apache::lonxml::debug("looking for accesstime $first_access"); |
&Apache::lonxml::debug("looking for accesstime $first_access"); |
if (!$first_access) { |
if (!$first_access) { |
$status='NOT_YET_VIEWED'; |
$status='NOT_YET_VIEWED'; |
my $due_date = &due_date($id); |
my $due_date = &due_date($id); |
my $seconds_left = $due_date - time; |
my $seconds_left = $due_date - time; |
if ($seconds_left > $interval || $due_date eq '') { |
if ($seconds_left > $interval[0] || $due_date eq '') { |
$seconds_left = $interval; |
$seconds_left = $interval[0]; |
} |
} |
$datemsg=&seconds_to_human_length($seconds_left); |
$datemsg=&seconds_to_human_length($seconds_left); |
} |
} |
Line 510 sub check_access {
|
Line 536 sub check_access {
|
sub due_date { |
sub due_date { |
my ($part_id,$symb,$udom,$uname)=@_; |
my ($part_id,$symb,$udom,$uname)=@_; |
my $date; |
my $date; |
my $interval= &Apache::lonnet::EXT("resource.$part_id.interval",$symb, |
my @interval= &Apache::lonnet::EXT("resource.$part_id.interval",$symb, |
$udom,$uname); |
$udom,$uname); |
&Apache::lonxml::debug("looking for interval $part_id $symb $interval"); |
&Apache::lonxml::debug("looking for interval $part_id $symb @interval"); |
my $due_date= &Apache::lonnet::EXT("resource.$part_id.duedate",$symb, |
my $due_date= &Apache::lonnet::EXT("resource.$part_id.duedate",$symb, |
$udom,$uname); |
$udom,$uname); |
&Apache::lonxml::debug("looking for due_date $part_id $symb $due_date"); |
&Apache::lonxml::debug("looking for due_date $part_id $symb $due_date"); |
if ($interval =~ /\d+/) { |
if ($interval[0] =~ /\d+/) { |
my $first_access=&Apache::lonnet::get_first_access('map',$symb); |
my $first_access=&Apache::lonnet::get_first_access($interval[1],$symb); |
&Apache::lonxml::debug("looking for first_access $first_access"); |
&Apache::lonxml::debug("looking for first_access $first_access ($interval[1])"); |
if (defined($first_access)) { |
if (defined($first_access)) { |
$interval = $first_access+$interval; |
my $interval = $first_access+$interval[0]; |
$date = ($interval < $due_date)? $interval : $due_date; |
$date = (!$due_date || $interval < $due_date) ? $interval |
|
: $due_date; |
} else { |
} else { |
$date = $due_date; |
$date = $due_date; |
} |
} |
Line 661 sub handle_save_or_undo {
|
Line 688 sub handle_save_or_undo {
|
my $error=0; |
my $error=0; |
if ($env{'form.Undo'} eq &mt('undo')) { |
if ($env{'form.Undo'} eq &mt('undo')) { |
my $error=0; |
my $error=0; |
if (!copy($file,$filetmp)) { $error=1; } |
if (!&File::Copy::copy($file,$filetmp)) { $error=1; } |
if ((!$error) && (!copy($filebak,$file))) { $error=1; } |
if ((!$error) && (!&File::Copy::copy($filebak,$file))) { $error=1; } |
if ((!$error) && (!move($filetmp,$filebak))) { $error=1; } |
if ((!$error) && (!&File::Copy::move($filetmp,$filebak))) { $error=1; } |
if (!$error) { |
if (!$error) { |
&Apache::lonxml::info("<p><b>". |
&Apache::lonxml::info("<p><b>". |
&mt("Undid changes, Switched [_1] and [_2]", |
&mt("Undid changes, Switched [_1] and [_2]", |
Line 685 sub handle_save_or_undo {
|
Line 712 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 699 sub handle_save_or_undo {
|
Line 722 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 716 sub handle_save_or_undo {
|
Line 736 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().' |
<input type="submit" name="problemmode" value="'.&mt("EditXML").'" /> |
<div class="LC_edit_problem_analyze_header"> |
<input type="submit" name="problemmode" value="'.&mt('Edit').'" /> |
<input type="button" name="submitmode" value="'.&mt("EditXML").'" '. |
<hr /> |
'onclick="javascript:setmode(this.form,'."'editxml'".')" /> |
<input type="submit" name="submit" value="'.&mt("View").'" /> |
<input type="button" name="submitmode" value="'.&mt('Edit').'" '. |
<hr /> |
'onclick="javascript:setmode(this.form,'."'edit'".')" /> |
|
<hr class="LC_edit_problem_divide" /> |
|
<input type="button" name="submitmode" value="'.&mt("View").'" '. |
|
'onclick="javascript:setmode(this.form,'."'view'".')" /> |
|
<hr class="LC_edit_problem_divide" /> |
|
</div> |
</form>'; |
</form>'; |
&Apache::lonxml::add_messages(\$result); |
&Apache::lonxml::add_messages(\$result); |
$request->print($result); |
$request->print($result); |
Line 788 sub analyze {
|
Line 816 sub analyze {
|
$i++; |
$i++; |
} |
} |
} |
} |
|
if (!keys(%{ $analyze{$part.'.answer'} })) { |
|
my $answer_part = |
|
['<span class="LC_error">'.&mt('Error').'</span>']; |
|
$seedexample{join("\0",$part,0,@{$answer_part})}= |
|
$thisseed; |
|
push( @{ $overall{$part.'.answer'}[0] }, |
|
$answer_part); |
|
} |
} |
} |
} |
} |
} |
} |
&Apache::lonhtmlcommon::Update_PrgWin($request,\%prog_state, |
&Apache::lonhtmlcommon::Update_PrgWin($request,\%prog_state, |
&mt('Analyzing Results')); |
&mt('Analyzing Results')); |
$request->print('<hr />'.&mt('List of possible answers').': '); |
$request->print('<hr class="LC_edit_problem_divide" />'.&mt('List of possible answers').': '); |
foreach my $part (sort(keys(%allparts))) { |
foreach my $part (sort(keys(%allparts))) { |
if (defined(@{ $overall{$part.'.answer'} })) { |
if (defined(@{ $overall{$part.'.answer'} })) { |
for (my $i=0;$i<scalar(@{ $overall{$part.'.answer'} });$i++) { |
for (my $i=0;$i<scalar(@{ $overall{$part.'.answer'} });$i++) { |
Line 831 sub analyze {
|
Line 867 sub analyze {
|
return $result; |
return $result; |
} |
} |
|
|
|
{ |
|
my $show_problem_status; |
|
sub reset_show_problem_status { |
|
undef($show_problem_status); |
|
} |
|
|
|
sub set_show_problem_status { |
|
my ($new_status) = @_; |
|
$show_problem_status = lc($new_status); |
|
} |
|
|
|
sub hide_problem_status { |
|
return ($show_problem_status eq 'no' |
|
|| $show_problem_status eq 'no_feedback_ever'); |
|
} |
|
|
|
sub show_problem_status { |
|
return ($show_problem_status eq 'yes' |
|
|| $show_problem_status eq 'answer' |
|
|| $show_problem_status eq ''); |
|
} |
|
|
|
sub show_some_problem_status { |
|
return ($show_problem_status eq 'no'); |
|
} |
|
|
|
sub show_no_problem_status { |
|
return ($show_problem_status eq 'no_feedback_ever'); |
|
} |
|
|
|
sub show_answer_problem_status { |
|
return ($show_problem_status eq 'answer'); |
|
} |
|
} |
|
|
sub editxmlmode { |
sub editxmlmode { |
my ($request,$file) = @_; |
my ($request,$file) = @_; |
my $result; |
my $result; |
Line 846 sub editxmlmode {
|
Line 917 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('Submit Changes 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); |
Line 863 sub editxmlmode {
|
Line 934 sub editxmlmode {
|
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(); |
my $only_body = ($env{'environment.remote'} eq 'off')? 0 : 1; |
my $only_body = ($env{'environment.remote'} eq 'off')? 0 : 1; |
|
my $dragmath = &Apache::lonhtmlcommon::dragmath("LC_editxmltext"); |
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 873 sub editxmlmode {
|
Line 946 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). |
&Apache::lonxml::message_location().' |
'<form '.&Apache::edit::form_change_detection().' name="lonhomework" method="POST" action="'. |
<form '.&Apache::edit::form_change_detection().' name="lonhomework" method="POST" action="'. |
|
&HTML::Entities::encode($env{'request.uri'},'<>&"').'">'. |
&HTML::Entities::encode($env{'request.uri'},'<>&"').'">'. |
&Apache::structuretags::remember_problem_state().' |
&Apache::structuretags::remember_problem_state().' |
<input type="hidden" name="problemmode" value="'.&mt('EditXML').'" /> |
<div class="LC_edit_problem_editxml_header"> |
<input type="submit" name="problemmode" accesskey="d" value="'.&mt('Discard Edits and View').'" /> |
<table class="LC_edit_problem_header_title"><tr><td> |
<input type="submit" '.&Apache::edit::submit_ask_anyway().'name="problemmode" accesskey="e" value="'.&mt('Edit').'" /> |
'.&mt('Problem Editing').&Apache::loncommon::help_open_topic('Problem_Editor_XML_Index').' |
<input type="submit" name="Undo" accesskey="u" value="'.&mt('undo').'" /> |
</td><td align="right"> |
<hr /> |
'.&Apache::loncommon::helpLatexCheatsheet().' |
<input type="submit" name="submit" accesskey="s" value="'.&mt('Submit Changes').'" /> |
</td></tr> |
<input type="submit" name="submit" accesskey="v" value="'.&mt('Submit Changes and View').'" /> |
</table> |
<hr /> |
<div class="LC_edit_problem_discards"> |
' . $xml_help . ' |
<input type="hidden" name="problemmode" value="editxml" /> |
|
|
|
<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').'" /> |
|
</div> |
|
<div class="LC_edit_problem_saves"> |
|
<input type="submit" name="submitbutton" accesskey="s" value="'.&mt('Save').'" /> |
|
<input type="submit" name="submitbutton" accesskey="v" value="'.&mt('Save and View').'" />' |
|
.$dragmath.' |
|
</div> |
|
<hr class="LC_edit_problem_divide" /> |
|
'.&Apache::lonxml::message_location().' |
|
</div> |
|
' . ' |
<textarea '.&Apache::edit::element_change_detection(). |
<textarea '.&Apache::edit::element_change_detection(). |
' rows="'.$rows.'" cols="'.$cols.'" style="width:100%" '. |
' rows="'.$rows.'" cols="'.$cols.'" style="width:100%" '. |
' name="editxmltext" id="LC_editxmltext">'. |
' name="editxmltext" id="LC_editxmltext">'. |
&HTML::Entities::encode($problem,'<>&"').'</textarea> |
&HTML::Entities::encode($problem,'<>&"').'</textarea> |
<div id="LC_aftertextarea"> |
<div id="LC_aftertextarea"> |
<input type="submit" name="submit" accesskey="s" value="'.&mt('Submit Changes').'" /> |
|
<input type="submit" name="submit" accesskey="v" value="'.&mt('Submit Changes and View').'" /> |
|
</div> |
</div> |
</form>'.&Apache::loncommon::end_page(); |
</form>'.&Apache::loncommon::end_page(); |
&Apache::lonxml::add_messages(\$result); |
&Apache::lonxml::add_messages(\$result); |
Line 951 sub renderpage {
|
Line 1035 sub renderpage {
|
&Apache::lonxml::debug("Should be parsing now"); |
&Apache::lonxml::debug("Should be parsing now"); |
$result .= &Apache::lonxml::xmlparse($request, $target, $problem, |
$result .= &Apache::lonxml::xmlparse($request, $target, $problem, |
&setup_vars($target),%mystyle); |
&setup_vars($target),%mystyle); |
undef($Apache::lonhomework::parsing_a_problem); |
&finished_parsing(); |
if (!$output) { $result = ''; } |
if (!$output) { $result = ''; } |
#$request->print("Result follows:"); |
#$request->print("Result follows:"); |
if ($target eq 'modified') { |
if ($target eq 'modified') { |
Line 982 sub renderpage {
|
Line 1066 sub renderpage {
|
} |
} |
} |
} |
|
|
# with no arg it returns a HTML <option> list of the template titles |
sub finished_parsing { |
# with one arg it returns the filename associated with the arg passed |
undef($Apache::lonhomework::parsing_a_problem); |
|
undef($Apache::lonhomework::parsing_a_task); |
|
} |
|
|
sub get_template_list { |
sub get_template_list { |
my ($namewanted,$extension) = @_; |
my ($extension) = @_; |
my $result; |
my $result; |
my @allnames; |
my @allnames; |
&Apache::lonxml::debug("Looking for :$extension:"); |
&Apache::lonxml::debug("Looking for :$extension:"); |
foreach my $file (</home/httpd/html/res/adm/includes/templates/*.$extension>) { |
my $glob_extension = $extension; |
&Apache::lonxml::debug("Looking at $file"); |
if ($extension eq 'survey' || $extension eq 'exam') { |
my $name=&Apache::lonnet::metadata($file,'title'); |
$glob_extension = 'problem'; |
&Apache::lonxml::debug("Got a name $name"); |
} |
if ($namewanted && ($name eq $namewanted)) { |
my @files = glob($Apache::lonnet::perlvar{'lonIncludes'}. |
$result=$file; |
'/templates/*.'.$glob_extension); |
last; |
@files = map {[$_,&mt(&Apache::lonnet::metadata($_, 'title')), |
} else { |
(&Apache::lonnet::metadata($_, 'category')?&mt(&Apache::lonnet::metadata($_, 'category')):&mt('Miscellaneous')), |
if ($name) { push (@allnames, $name); } |
&mt(&Apache::lonnet::metadata($_, 'help'))]} (@files); |
} |
@files = sort {$a->[2].$a->[1] cmp $b->[2].$b->[1]} (@files); |
|
my ($midpoint,$seconddiv,$numfiles); |
|
$numfiles = 0; |
|
foreach my $file (@files) { |
|
next if ($file->[1] !~ /\S/); |
|
$numfiles ++; |
|
} |
|
if ($numfiles > 0) { |
|
$result = '<div class="LC_left_float">'; |
|
$midpoint = int($numfiles/2); |
|
if ($numfiles%2) { |
|
$midpoint ++; |
|
} |
|
} |
|
my $count = 0; |
|
my $currentcategory=''; |
|
foreach my $file (@files) { |
|
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 .= |
|
'<label><input type="radio" name="template" value="'.$file->[0].'" />'. |
|
$file->[1].'</label>'; |
|
if ($file->[3]) { |
|
$result.=&Apache::loncommon::help_open_topic($file->[3]); |
|
} |
|
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 (@allnames && !$result) { |
if ($numfiles > 0) { |
$result="<option>".&mt("Select a")." $extension ".&mt('template')."</option>\n<option>". |
$result .= '</div>'."\n".'<div class="LC_clear_float_footer"></div>'."\n"; |
join('</option><option>',sort(@allnames)).'</option>'; |
|
} |
} |
return $result; |
return $result; |
} |
} |
|
|
sub newproblem { |
sub newproblem { |
my ($request) = @_; |
my ($request) = @_; |
my $extension=$request->uri; |
|
$extension=~s:^.*\.([\w]+)$:$1:; |
if ($env{'form.template'}) { |
&Apache::lonxml::debug("Looking for :$extension:"); |
my $file = $env{'form.template'}; |
my $templatelist=&get_template_list('',$extension); |
|
if ($env{'form.template'} && |
|
$env{'form.template'} ne "Select a $extension template") { |
|
use File::Copy; |
|
my $file = &get_template_list($env{'form.template'},$extension); |
|
my $dest = &Apache::lonnet::filelocation("",$request->uri); |
my $dest = &Apache::lonnet::filelocation("",$request->uri); |
copy($file,$dest); |
&File::Copy::copy($file,$dest); |
&renderpage($request,$dest); |
&renderpage($request,$dest); |
} elsif($env{'form.newfile'} && !$templatelist) { |
return; |
# I don't like hard-coded filenames but for now, this will work. |
} |
use File::Copy; |
|
|
my ($extension) = ($request->uri =~ m/\.(\w+)$/); |
|
&Apache::lonxml::debug("Looking for :$extension:"); |
|
my $templatelist=&get_template_list($extension); |
|
if ($env{'form.newfile'} && !$templatelist) { |
|
# no templates found |
my $templatefilename = |
my $templatefilename = |
$request->dir_config('lonIncludes').'/templates/blank.'.$extension; |
$request->dir_config('lonIncludes').'/templates/blank.'.$extension; |
&Apache::lonxml::debug("$templatefilename"); |
&Apache::lonxml::debug("$templatefilename"); |
my $dest = &Apache::lonnet::filelocation("",$request->uri); |
my $dest = &Apache::lonnet::filelocation("",$request->uri); |
copy($templatefilename,$dest); |
&File::Copy::copy($templatefilename,$dest); |
&renderpage($request,$dest); |
&renderpage($request,$dest); |
} else { |
} else { |
my $url=&HTML::Entities::encode($request->uri,'<>&"'); |
my $url=&HTML::Entities::encode($request->uri,'<>&"'); |
Line 1035 sub newproblem {
|
Line 1157 sub newproblem {
|
$shownurl=~s-^/~-/priv/-; |
$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'}) { |
|
$errormsg='<p><span class="LC_error">'.&mt('You did not select a template.').'</span></p>'."\n"; |
|
} |
|
my $instructions; |
my $instructions; |
my $start_page = |
my $start_page = |
&Apache::loncommon::start_page("Create New $extension"); |
&Apache::loncommon::start_page("Create New $extension"); |
Line 1050 $errormsg
|
Line 1169 $errormsg
|
<p> |
<p> |
<b> |
<b> |
".&mt("To create a new $extension, select a template from the". |
".&mt("To create a new $extension, select a template from the". |
"pull-down menu below. Then click on the \"Create $extension\" button.")."</b> |
" list below. Then click on the \"Create $extension\" button.")."</b> |
</p><form action=\"$url\" method=\"POST\">"); |
</p><form action=\"$url\" method=\"POST\">"); |
|
|
if (defined($templatelist)) { |
if (defined($templatelist)) { |
$request->print("<select name=\"template\">$templatelist</select>"); |
$request->print($templatelist); |
} |
} |
$request->print("<br /><input type=\"submit\" name=\"newfile\" value=\"".&mt('Create')." $extension\" />"); |
$request->print('<br /><input type="submit" name="newfile" value="'. |
|
&mt("Create $extension").'" />'); |
$request->print("</form></p>".&Apache::loncommon::end_page()); |
$request->print("</form></p>".&Apache::loncommon::end_page()); |
} |
} |
return ''; |
return; |
} |
} |
|
|
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'})) { |
Line 1073 sub update_construct_style {
|
Line 1193 sub update_construct_style {
|
&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 1087 sub handler {
|
Line 1207 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 1122 sub handler {
|
Line 1235 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(); |