version 1.280, 2007/10/31 01:37:52
|
version 1.287, 2007/12/24 06:35:18
|
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 149 sub get_target {
|
Line 149 sub get_target {
|
} elsif ( $env{'form.problemmode'} eq &mt('Edit') || |
} elsif ( $env{'form.problemmode'} eq &mt('Edit') || |
$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.submit'} 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 494 sub check_access {
|
Line 494 sub check_access {
|
$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 532 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 683 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 882 sub analyze {
|
Line 887 sub analyze {
|
|
|
sub show_problem_status { |
sub show_problem_status { |
return ($show_problem_status eq 'yes' |
return ($show_problem_status eq 'yes' |
|
|| $show_problem_status eq 'answer' |
|| $show_problem_status eq ''); |
|| $show_problem_status eq ''); |
} |
} |
|
|
Line 892 sub analyze {
|
Line 898 sub analyze {
|
sub show_no_problem_status { |
sub show_no_problem_status { |
return ($show_problem_status eq 'no_feedback_ever'); |
return ($show_problem_status eq 'no_feedback_ever'); |
} |
} |
|
|
|
sub show_answer_problem_status { |
|
return ($show_problem_status eq 'answer'); |
|
} |
} |
} |
|
|
sub editxmlmode { |
sub editxmlmode { |
Line 909 sub editxmlmode {
|
Line 919 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.submit'} 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); |
Line 939 sub editxmlmode {
|
Line 949 sub editxmlmode {
|
|
|
$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().' |
<div class="LC_edit_problem_editxml_header"> |
<div class="LC_edit_problem_editxml_header"> |
Line 961 sub editxmlmode {
|
Line 970 sub editxmlmode {
|
<input type="submit" name="submit" accesskey="v" value="'.&mt('Save and View').'" /> |
<input type="submit" name="submit" 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().' |
</div> |
</div> |
' . ' |
' . ' |
<textarea '.&Apache::edit::element_change_detection(). |
<textarea '.&Apache::edit::element_change_detection(). |
Line 1059 sub finished_parsing {
|
Line 1069 sub finished_parsing {
|
undef($Apache::lonhomework::parsing_a_task); |
undef($Apache::lonhomework::parsing_a_task); |
} |
} |
|
|
# 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 { |
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'))]} (@files); |
} else { |
@files = sort {$a->[1] cmp $b->[1]} (@files); |
if ($name) { push (@allnames, $name); } |
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; |
|
foreach my $file (@files) { |
|
next if ($file->[1] !~ /\S/); |
|
$result .= |
|
'<label><input type="radio" name="template" value="'.$file->[0].'" />'. |
|
$file->[1].'</label><br />'."\n"; |
|
$count ++; |
|
if ((!$seconddiv) && ($count >= $midpoint)) { |
|
$result .= '</div>'."\n".'<div class="LC_left_float">'."\n"; |
|
$seconddiv = 1; |
|
} |
} |
} |
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 1112 sub newproblem {
|
Line 1141 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 1127 $errormsg
|
Line 1153 $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 { |