Diff for /loncom/homework/lonhomework.pm between versions 1.145 and 1.150

version 1.145, 2003/09/18 19:59:15 version 1.150, 2003/09/19 20:29:29
Line 54  use Apache::chemresponse(); Line 54  use Apache::chemresponse();
 use Apache::Constants qw(:common);  use Apache::Constants qw(:common);
 use HTML::Entities();  use HTML::Entities();
 use Apache::loncommon();  use Apache::loncommon();
   use Apache::lonlocal;
 #use Time::HiRes qw( gettimeofday tv_interval );  #use Time::HiRes qw( gettimeofday tv_interval );
   
 BEGIN {  BEGIN {
Line 89  sub get_target { Line 90  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 98  sub get_target { Line 99  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 161  sub check_access { Line 162  sub check_access {
     if ($ENV{'request.state'} eq "construct") {      if ($ENV{'request.state'} eq "construct") {
  &Apache::lonxml::debug("in construction ignoring dates");   &Apache::lonxml::debug("in construction ignoring dates");
  $status='CAN_ANSWER';   $status='CAN_ANSWER';
  $datemsg='is in under construction';   $datemsg=&mt('is in under construction');
  return ($status,$datemsg);   return ($status,$datemsg);
     }      }
   
Line 174  sub check_access { Line 175  sub check_access {
  if ($thistype =~ /^(con_lost|no_such_host)/ ||   if ($thistype =~ /^(con_lost|no_such_host)/ ||
     $date     =~ /^(con_lost|no_such_host)/) {      $date     =~ /^(con_lost|no_such_host)/) {
     $status='UNAVAILABLE';      $status='UNAVAILABLE';
     $date="may open later.";      $date=&mt("may open later.");
     return($status,$date);      return($status,$date);
  }   }
  if ($thistype eq 'date_interval') {   if ($thistype eq 'date_interval') {
Line 187  sub check_access { Line 188  sub check_access {
  }   }
  &Apache::lonxml::debug("found :$date: for :$temp:");   &Apache::lonxml::debug("found :$date: for :$temp:");
  if ($date eq '') {   if ($date eq '') {
     $date = "an unknown date"; $passed = 0;      $date = &mt("an unknown date"); $passed = 0;
  } elsif ($date eq 'con_lost') {   } elsif ($date eq 'con_lost') {
     $date = "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 = localtime $date;
Line 202  sub check_access { Line 203  sub check_access {
  $datemsg=$date;   $datemsg=$date;
     } elsif ($type eq 'opendate') {      } elsif ($type eq 'opendate') {
  $status='CLOSED';   $status='CLOSED';
  $datemsg = "will open on $date";   $datemsg = &mt("will open on")." $date";
     } elsif ($type eq 'duedate') {      } elsif ($type eq 'duedate') {
  $status='CAN_ANSWER';   $status='CAN_ANSWER';
  $datemsg = "is due at $date";   $datemsg = &mt("is due at")." $date";
     } elsif ($type eq 'answerdate') {      } elsif ($type eq 'answerdate') {
  $status='CLOSED';   $status='CLOSED';
  $datemsg = "was due on $lastdate, and answers will be available on $date";   $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.
Line 237  sub check_access { Line 238  sub check_access {
     if (($Apache::lonhomework::browse eq 'F') && ($status eq 'CLOSED')) {      if (($Apache::lonhomework::browse eq 'F') && ($status eq 'CLOSED')) {
  &Apache::lonxml::debug("should be allowed to browse a resource when closed");   &Apache::lonxml::debug("should be allowed to browse a resource when closed");
  $status='CAN_ANSWER';   $status='CAN_ANSWER';
  $datemsg='is closed but you are allowed to view it';   $datemsg=&mt('is closed but you are allowed to view it');
     }      }
   
     return ($status,$datemsg);      return ($status,$datemsg);
Line 326  sub handle_save_or_undo { Line 327  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') {      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; }
  if ((!$error) && (!move($filetmp,$filebak))) { $error=1; }   if ((!$error) && (!move($filetmp,$filebak))) { $error=1; }
  if (!$error) {   if (!$error) {
     $request->print("<p><b>Undid changes, Switched $filebak and $file</b></p>");      $request->print("<p><b>".&mt("Undid changes, Switched")." $filebak ".&mt("and")." $file</b></p>");
  } else {   } else {
     $request->print("<p><font color=\"red\" size=\"+1\"><b>Unable to undo, unable to switch $filebak and $file</b></font></p>");      $request->print("<p><font color=\"red\" size=\"+1\"><b>".&mt("Unable to undo, unable to switch")." $filebak ".&mt("and")." $file</b></font></p>");
     $error=1;      $error=1;
  }   }
     } else {      } else {
  my $fs=Apache::File->new(">$filebak");   my $fs=Apache::File->new(">$filebak");
  if (defined($fs)) {   if (defined($fs)) {
     print $fs $$problem;      print $fs $$problem;
     $request->print("<b>Making Backup to $filebak</b><br />");      $request->print("<b>".&mt("Making Backup to").
       " $filebak</b><br />");
  } else {   } else {
     $request->print("<font color=\"red\" size=\"+1\"><b>Unable to make backup $filebak</b></font>");      $request->print("<font color=\"red\" size=\"+1\"><b>".&mt("Unable to make backup")." $filebak</b></font>");
     $error=2;      $error=2;
  }   }
  my $fh=Apache::File->new(">$file");   my $fh=Apache::File->new(">$file");
  if (defined($fh)) {   if (defined($fh)) {
     print $fh $$result;      print $fh $$result;
     $request->print("<b>Saving Modifications to $file</b><br />");      $request->print("<b>".&mt("Saving Modifications to").
       " $file</b><br />");
  } else {   } else {
     $request->print("<font color=\"red\" size=\"+1\"><b>Unable to write to $file</b></font>");      $request->print("<font color=\"red\" size=\"+1\"><b>".
       &mt("Unable to write to")." $file</b></font>");
     $error|=4;      $error|=4;
  }   }
     }      }
Line 361  sub handle_save_or_undo { Line 365  sub handle_save_or_undo {
 sub analyze_header {  sub analyze_header {
     my ($request) = @_;      my ($request) = @_;
     my $result.='<html>      my $result.='<html>
             <head><title>Analyzing a problem</title></head>              <head><title>'.&mt("Analyzing a problem").'</title></head>
             <body bgcolor="#FFFFFF">              <body bgcolor="#FFFFFF">
             <form name="lonhomework" method="POST" action="'.              <form name="lonhomework" method="POST" action="'.
     $ENV{'request.uri'}.'">      $ENV{'request.uri'}.'">
             <input type="submit" name="problemmode" value="EditXML" />              <input type="submit" name="problemmode" value="'.&mt("EditXML").'" />
             <input type="submit" name="problemmode" value="Edit" />              <input type="submit" name="problemmode" value="'.&mt('Edit').'" />
             <hr />              <hr />
             <input type="submit" name="submit" value="View" />              <input type="submit" name="submit" value="'.&mt("View").'" />
             <hr />              <hr />
             List of possible answers:              '.&mt('List of possible answers').':
             </form>';              </form>';
     $request->print($result);      $request->print($result);
     $request->rflush();      $request->rflush();
Line 392  sub analyze { Line 396  sub analyze {
     my $rndseed=$ENV{'form.rndseed'};      my $rndseed=$ENV{'form.rndseed'};
     &analyze_header($request);      &analyze_header($request);
     my %prog_state=      my %prog_state=
  &Apache::lonhtmlcommon::Create_PrgWin($request,'Analyze Progress',   &Apache::lonhtmlcommon::Create_PrgWin($request,&mt('Analyze Progress'),
       'Getting Problem Variants',        &mt('Getting Problem Variants'),
       $ENV{'form.numtoanalyze'});        $ENV{'form.numtoanalyze'});
     for(my $i=1;$i<$ENV{'form.numtoanalyze'}+1;$i++) {      for(my $i=1;$i<$ENV{'form.numtoanalyze'}+1;$i++) {
  &Apache::lonhtmlcommon::Increment_PrgWin($request,\%prog_state,   &Apache::lonhtmlcommon::Increment_PrgWin($request,\%prog_state,
  'last problem');   &mt('last problem'));
  my $subresult=&Apache::lonnet::ssi($request->uri,   my $subresult=&Apache::lonnet::ssi($request->uri,
    ('grade_target' => 'analyze'),     ('grade_target' => 'analyze'),
    ('rndseed' => $i+$rndseed));     ('rndseed' => $i+$rndseed));
Line 418  sub analyze { Line 422  sub analyze {
  }   }
     }      }
     &Apache::lonhtmlcommon::Update_PrgWin($request,\%prog_state,      &Apache::lonhtmlcommon::Update_PrgWin($request,\%prog_state,
   'Analyzing Results');    &mt('Analyzing Results'));
     foreach my $part (sort(keys(%allparts))) {      foreach my $part (sort(keys(%allparts))) {
  if (defined(@{ $overall{$part.'.answer'} })) {   if (defined(@{ $overall{$part.'.answer'} })) {
     my $num_cols=scalar(@{ $overall{$part.'.answer'}->[0] });      my $num_cols=scalar(@{ $overall{$part.'.answer'}->[0] });
     $request->print('<table><tr><td colspan="'.($num_cols+1).'">Part '.$part.'</td></tr>');      $request->print('<table><tr><td colspan="'.($num_cols+1).'">'.&mt('Part').' '.$part.'</td></tr>');
     my %frequency;      my %frequency;
     foreach my $answer (sort {$a->[0] <=> $b->[0]} (@{ $overall{$part.'.answer'} })) {      foreach my $answer (sort {$a->[0] <=> $b->[0]} (@{ $overall{$part.'.answer'} })) {
  $frequency{join("\0",@{ $answer })}++;   $frequency{join("\0",@{ $answer })}++;
     }      }
     $request->print('<tr><td colspan="'.($num_cols).'">Answer</td><td>Frequency</td></tr>');      $request->print('<tr><td colspan="'.($num_cols).'">'.&mt('Answer').'</td><td>'.&mt('Frequency').'</td></tr>');
     foreach my $answer (sort {(split("\0",$a))[0] <=> (split("\0",$b))[0]} (keys(%frequency))) {      foreach my $answer (sort {(split("\0",$a))[0] <=> (split("\0",$b))[0]} (keys(%frequency))) {
  $request->print('<tr><td align="right">'.   $request->print('<tr><td align="right">'.
  join('</td><td align="right">',split("\0",$answer)).   join('</td><td align="right">',split("\0",$answer)).
Line 436  sub analyze { Line 440  sub analyze {
     }      }
     $request->print('</table>');      $request->print('</table>');
  } else {   } else {
     $request->print('<p>Part '.$part.      $request->print('<p>'.&mt('Part').' '.$part.' '.
     ' 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>Found no analyzable parts in this problem,   $request->print('<p>'.&mt('Found no analyzable parts 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 456  sub editxmlmode { Line 458  sub editxmlmode {
     my $result;      my $result;
     my $problem=&Apache::lonnet::getfile($file);      my $problem=&Apache::lonnet::getfile($file);
     if ($problem eq -1) {      if ($problem eq -1) {
  &Apache::lonxml::error("<b> Unable to find <i>$file</i></b>");   &Apache::lonxml::error("<b> ".&mt('Unable to find').
          " <i>$file</i></b>");
  $problem='';   $problem='';
     }      }
     if (defined($ENV{'form.editxmltext'}) || defined($ENV{'form.Undo'})) {      if (defined($ENV{'form.editxmltext'}) || defined($ENV{'form.Undo'})) {
Line 465  sub editxmlmode { Line 468  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);
Line 479  sub editxmlmode { Line 482  sub editxmlmode {
  $result.='<html><body bgcolor="#FFFFFF">   $result.='<html><body bgcolor="#FFFFFF">
             <form name="lonhomework" method="POST" action="'.              <form name="lonhomework" method="POST" action="'.
     $ENV{'request.uri'}.'">      $ENV{'request.uri'}.'">
             <input type="hidden" name="problemmode" value="EditXML" />              <input type="hidden" name="problemmode" value="'.&mt('EditXML').'" />
             <input type="submit" name="problemmode" value="Discard Edits and View" />              <input type="submit" name="problemmode" value="'.&mt('Discard Edits and View').'" />
             <input type="submit" name="problemmode" value="Edit" />              <input type="submit" name="problemmode" value="'.&mt('Edit').'" />
             <hr />              <hr />
             <input type="submit" name="submit" value="Submit Changes" />              <input type="submit" name="submit" value="'.&mt('Submit Changes').'" />
             <input type="submit" name="submit" value="Submit Changes and View" />              <input type="submit" name="submit" value="'.&mt('Submit Changes and View').'" />
             <input type="submit" name="Undo" value="undo" />              <input type="submit" name="Undo" value="'.&mt('undo').'" />
             <hr />              <hr />
             ' . $xml_help . '              ' . $xml_help . '
             <textarea rows="'.$rows.'" cols="'.$cols.'" name="editxmltext">'.              <textarea rows="'.$rows.'" cols="'.$cols.'" name="editxmltext">'.
Line 505  sub renderpage { Line 508  sub renderpage {
  #my $t0 = [&gettimeofday()];   #my $t0 = [&gettimeofday()];
  my $problem=&Apache::lonnet::getfile($file);   my $problem=&Apache::lonnet::getfile($file);
  if ($problem eq -1) {   if ($problem eq -1) {
     &Apache::lonxml::error("<b> Unable to find <i>$file</i></b>");      &Apache::lonxml::error("<b> ".&mt('Unable to find')." <i>$file</i></b>");
     $problem='';      $problem='';
  }   }
   
Line 557  sub get_template_list { Line 560  sub get_template_list {
  }   }
     }      }
     if (@allnames && !$result) {      if (@allnames && !$result) {
  $result="<option>Select a $extension template</option>\n<option>".   $result="<option>".&mt("Select a")." $extension ".&mt('template')."</option>\n<option>".
     join('</option><option>',sort(@allnames)).'</option>';      join('</option><option>',sort(@allnames)).'</option>';
     }      }
     return $result;      return $result;
Line 590  sub newproblem { Line 593  sub newproblem {
  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">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;
  if ($templatelist) { $instructions=", select a template from the pull-down menu below.<br />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',
     'resource' => 'resource',
     'requested' => 'The requested file',
     'not exist' => 'currently does not exist',
     'createnew' => 'To create a new',
     'click' => 'click on the',
     'Create' => 'Create',
     'button' => 'button');
  $request->print(<<ENDNEWPROBLEM);   $request->print(<<ENDNEWPROBLEM);
 <body bgcolor="#FFFFFF">  <body bgcolor="#FFFFFF">
 <h1>Creating a new $extension resource</h1>  <h1>$lt{'create'} $extension $lt{'resource'}</h1>
 $errormsg  $errormsg
 The requested file <tt>$url</tt> currently does not exist.  $lt{'requested'} <tt>$url</tt> $lt{'not exist'}.
 <p>  <p>
 <b>To create a new $extension$instructions click on the "Create $extension" button.</b>  <b>$lt{'createnew'} $extension$instructions $lt{'click'} "$lt{'Create'} $extension" $lt{'button'}.</b>
 </p>  </p>
 <p><form action="$url" method="POST">  <p><form action="$url" method="POST">
 ENDNEWPROBLEM  ENDNEWPROBLEM
  if (defined($templatelist)) {   if (defined($templatelist)) {
     $request->print("<select name=\"template\">$templatelist</select>");      $request->print("<select name=\"template\">$templatelist</select>");
  }   }
  $request->print("<br /><input type=\"submit\" name=\"newfile\" value=\"Create $extension\" />");   $request->print("<br /><input type=\"submit\" name=\"newfile\" value=\"".&mt('Create')." $extension\" />");
  $request->print("</form></p></body>");   $request->print("</form></p></body>");
     }      }
     return '';      return '';
Line 616  ENDNEWPROBLEM Line 627  ENDNEWPROBLEM
 sub view_or_edit_menu {  sub view_or_edit_menu {
     my ($request) = @_;      my ($request) = @_;
     my $url=$request->uri;      my $url=$request->uri;
       my %lt=&Apache::lonlocal::texthash( 'would' => 'Would you like to',
         'view' => 'View',
         'Edit' => 'edit',
         'or' => 'or',
         'the problem' => 'the problem');
     $request->print(<<EDITMENU);      $request->print(<<EDITMENU);
 <body bgcolor="#FFFFFF">  <body bgcolor="#FFFFFF">
 <form action="$url" method="POST">  <form action="$url" method="POST">
 Would you like to <input type="submit" name="problemmode" value="View"> or  $lt{'would'} <input type="submit" name="problemmode" value="&lt{'view'}">
 <input type="submit" name="problemmode" value="Edit"> the problem.  &lt{'or'} <input type="submit" name="problemmode" value="&lt{'Edit'}">
   &lt{'the problem'}.
 </form>  </form>
 </body>  </body>
 EDITMENU  EDITMENU
Line 667  sub handler { Line 684  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 684  sub handler { Line 701  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);

Removed from v.1.145  
changed lines
  Added in v.1.150


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>