Diff for /loncom/homework/lonhomework.pm between versions 1.232 and 1.242

version 1.232, 2005/12/22 22:06:54 version 1.242, 2006/04/25 15:32:40
Line 143  sub setup_vars { Line 143  sub setup_vars {
 #  return ';$external::target='.$target.';';  #  return ';$external::target='.$target.';';
 }  }
   
 sub send_header {  
     my ($request)= @_;  
     $request->print(&Apache::lontexconvert::header());  
 #  $request->print('<form name='.$env{'form.request.prefix'}.'lonhomework method="POST" action="'.$request->uri.'">');  
 }  
   
 sub createmenu {  sub createmenu {
     my ($which,$request)=@_;      my ($which,$request)=@_;
     if ($which eq 'grade') {      if ($which eq 'grade') {
Line 159  sub createmenu { Line 153  sub createmenu {
     }      }
 }  }
   
 sub send_footer {  
     my ($request)= @_;  
 #  $request->print('</form>');  
     $request->print(&Apache::lontexconvert::footer());  
 }  
   
 sub proctor_checked_in {  sub proctor_checked_in {
     my ($slot_name,$slot,$type)=@_;      my ($slot_name,$slot,$type)=@_;
     my @possible_proctors=split(",",$slot->{'proctor'});      my @possible_proctors=split(",",$slot->{'proctor'});
Line 198  sub check_ip_acc { Line 186  sub check_ip_acc {
     my $ip=$ENV{'REMOTE_ADDR'};      my $ip=$ENV{'REMOTE_ADDR'};
     my $name;      my $name;
     foreach my $pattern (split(',',$acc)) {      foreach my $pattern (split(',',$acc)) {
    $pattern =~ s/^\s*//;
    $pattern =~ s/\s*$//;
  if ($pattern =~ /\*$/) {   if ($pattern =~ /\*$/) {
     #35.8.*      #35.8.*
     $pattern=~s/\*//;      $pattern=~s/\*//;
Line 244  sub check_slot_access { Line 234  sub check_slot_access {
     my ($status,$datemsg)=&check_access($id);      my ($status,$datemsg)=&check_access($id);
           
     my $useslots = &Apache::lonnet::EXT("resource.$id.useslots");      my $useslots = &Apache::lonnet::EXT("resource.$id.useslots");
     if ($useslots ne 'resource') {      if ($useslots ne 'resource' && $useslots ne 'sequence') {
  return ($status,$datemsg);   return ($status,$datemsg);
     }      }
   
Line 276  sub check_slot_access { Line 266  sub check_slot_access {
     my $slotstatus='NOT_IN_A_SLOT';      my $slotstatus='NOT_IN_A_SLOT';
     my ($returned_slot,$slot_name);      my ($returned_slot,$slot_name);
     foreach my $slot (@slots) {      foreach my $slot (@slots) {
    $slot =~ s/(^\s*|\s*$)//g;
  &Apache::lonxml::debug("getting $slot");   &Apache::lonxml::debug("getting $slot");
  my %slot=&Apache::lonnet::get_slot($slot);   my %slot=&Apache::lonnet::get_slot($slot);
  &Apache::lonhomework::showhash(%slot);   &Apache::lonhomework::showhash(%slot);
Line 295  sub check_slot_access { Line 286  sub check_slot_access {
  $slotstatus='CAN_ANSWER';   $slotstatus='CAN_ANSWER';
     }      }
   
     my ($got_grade,$checkedin);      my ($is_correct,$got_grade,$checkedin);
     if ($type eq 'Task') {      if ($type eq 'Task') {
  my $version=$Apache::lonhomework::history{'resource.0.version'};   my $version=$Apache::lonhomework::history{'resource.0.version'};
  $got_grade =    $got_grade = 
     ($Apache::lonhomework::history{"resource.$version.0.status"}       ($Apache::lonhomework::history{"resource.$version.0.status"} 
      =~ /^(?:pass|fail)$/);       =~ /^(?:pass|fail)$/);
    $is_correct =  
       ($Apache::lonhomework::history{"resource.$version.0.status"} eq 'pass'
        || $Apache::lonhomework::history{"resource.0.solved"} =~ /^correct_/ );
  $checkedin =   $checkedin =
     $Apache::lonhomework::history{"resource.$version.0.checkedin"};      $Apache::lonhomework::history{"resource.$version.0.checkedin"};
     } elsif ($type eq 'problem') {      } elsif ($type eq 'problem') {
Line 308  sub check_slot_access { Line 302  sub check_slot_access {
  $checkedin = $Apache::lonhomework::history{"resource.0.checkedin"};   $checkedin = $Apache::lonhomework::history{"resource.0.checkedin"};
     }      }
           
       &Apache::lonxml::debug(" slot is $slotstatus checkedin ($checkedin) got_grade ($got_grade) is_correct ($is_correct)");
       
       # has a current checked in recrd, but hasn't got a grade, must be awaiting
       # a grade
       if ($checkedin 
    && !$got_grade) {
    return ('WAITING_FOR_GRADE');
       }
   
     if ($slotstatus eq 'NOT_IN_A_SLOT'       if ($slotstatus eq 'NOT_IN_A_SLOT' 
  && $checkedin ) {   && $checkedin ) {
   
Line 318  sub check_slot_access { Line 321  sub check_slot_access {
  }   }
   
     }      }
       if ( $is_correct) {
    return ('SHOW_ANSWER');
       }
     if ( $status eq 'CANNOT_ANSWER' &&       if ( $status eq 'CANNOT_ANSWER' && 
  ($slotstatus ne 'NEEDS_CHECKIN' && $slotstatus ne 'NOT_IN_A_SLOT')) {   ($slotstatus ne 'NEEDS_CHECKIN' && $slotstatus ne 'NOT_IN_A_SLOT')) {
  return ($status,$datemsg);   return ($status,$datemsg);
Line 617  sub handle_save_or_undo { Line 623  sub handle_save_or_undo {
   
 sub analyze_header {  sub analyze_header {
     my ($request) = @_;      my ($request) = @_;
     my $bodytag=&Apache::loncommon::bodytag(undef,undef,undef,      my $result =
     ($env{'environment.remote'} ne 'off'));   &Apache::loncommon::start_page('Analyzing a problem',undef);
     my $html=&Apache::lonxml::xmlbegin();  
     my $result.=$html.'      $result .= 
             <head><title>'.&mt("Analyzing a problem").'</title></head>   &Apache::lonxml::message_location().'
             '.$bodytag.&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'},'<>&"').'">'.
     &Apache::structuretags::remember_problem_state().'      &Apache::structuretags::remember_problem_state().'
Line 639  sub analyze_header { Line 644  sub analyze_header {
   
 sub analyze_footer {  sub analyze_footer {
     my ($request) = @_;      my ($request) = @_;
     my $result='</body></html>';      $request->print(&Apache::loncommon::end_page());
     $request->print($result);  
     $request->rflush();      $request->rflush();
 }  }
   
Line 751  sub editxmlmode { Line 755  sub editxmlmode {
  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 $bodytag=&Apache::loncommon::bodytag(undef,undef,undef,   my $start_page = 
  ($env{'environment.remote'} ne 'off'));      &Apache::loncommon::start_page("EditXML $file",
  my $html=&Apache::lonxml::xmlbegin();     &Apache::edit::js_change_detection());
  my $head="<head><title>EditXML $file</title>".  
     &Apache::edit::js_change_detection()."</head>";  
   
  $result.=$html.$head.$bodytag.   $result.=$start_page.
     &renderpage($request,$file,['no_output_web'],1).      &renderpage($request,$file,['no_output_web'],1).
     &Apache::lonxml::message_location().'      &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="'.
Line 776  sub editxmlmode { Line 778  sub editxmlmode {
     &HTML::Entities::encode($problem,'<>&"').'</textarea><br />      &HTML::Entities::encode($problem,'<>&"').'</textarea><br />
             <input type="submit" name="submit" accesskey="s" value="'.&mt('Submit Changes').'" />              <input type="submit" name="submit" accesskey="s" value="'.&mt('Submit Changes').'" />
             <input type="submit" name="submit" accesskey="v" value="'.&mt('Submit Changes and View').'" />              <input type="submit" name="submit" accesskey="v" value="'.&mt('Submit Changes and View').'" />
             </form></body></html>';              </form>'.&Apache::loncommon::end_page();
  &Apache::lonxml::add_messages(\$result);   &Apache::lonxml::add_messages(\$result);
  $request->print($result);   $request->print($result);
     }      }
Line 908  sub newproblem { Line 910  sub newproblem {
     $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,   my $start_page = 
  ($env{'environment.remote'} ne 'off'));      &Apache::loncommon::start_page("Create New $extension");
  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 920  sub newproblem { Line 922  sub newproblem {
   'Create' => 'Create',    'Create' => 'Create',
   'button' => 'button');    'button' => 'button');
  $request->print(<<ENDNEWPROBLEM);   $request->print(<<ENDNEWPROBLEM);
 $bodytag  $start_page
 <h1>$lt{'create'} $extension $lt{'resource'}</h1>  <h1>$lt{'create'} $extension $lt{'resource'}</h1>
 $errormsg  $errormsg
 $lt{'requested'} <tt>$shownurl</tt> $lt{'not exist'}.  $lt{'requested'} <tt>$shownurl</tt> $lt{'not exist'}.
Line 933  ENDNEWPROBLEM Line 935  ENDNEWPROBLEM
     $request->print("<select name=\"template\">$templatelist</select>");      $request->print("<select name=\"template\">$templatelist</select>");
  }   }
  $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></body>");   $request->print("</form></p>".&Apache::loncommon::end_page());
     }      }
     return '';      return '';
 }  }
   
 sub view_or_edit_menu {  
     my ($request) = @_;  
     my $url=&HTML::Entities::encode($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);  
 <body bgcolor="#FFFFFF">  
 <form action="$url" method="POST">  
 $lt{'would'} <input type="submit" name="problemmode" accesskey="v" value="&lt{'view'}">  
 &lt{'or'} <input type="submit" name="problemmode" accesskey="e" value="&lt{'Edit'}">  
 &lt{'the problem'}.  
 </form>  
 </body>  
 EDITMENU  
 }  
   
 sub handler {  sub handler {
     #my $t0 = [&gettimeofday()];      #my $t0 = [&gettimeofday()];
     my $request=$_[0];      my $request=$_[0];
Line 988  sub handler { Line 971  sub handler {
     &Apache::lonxml::debug("Problem Mode ".$env{'form.problemmode'});      &Apache::lonxml::debug("Problem Mode ".$env{'form.problemmode'});
     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{'form.resetdata'} eq &mt('Reset Submissions') ||  
     $env{'form.resetdata'} eq &mt('New Problem Variation') ||  
     $env{'form.newrandomization'} eq &mt('New Randomization')) {  
     my ($symb,$courseid,$domain,$name) = &Apache::lonxml::whichuser();  
     &Apache::lonnet::tmpreset($symb,'',$domain,$name);  
     &Apache::lonxml::debug("Attempt reset");  
  }  
     }  
     if ($env{'request.state'} eq "construct") {      if ($env{'request.state'} eq "construct") {
  if ( -e $file ) {   if ( -e $file ) {
     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},      &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
     ['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
  #&view_or_edit_menu($request);  
  $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 &mt('EditXML') ||
Line 1025  sub handler { Line 998  sub handler {
     }      }
     #my $td=&tv_interval($t0);      #my $td=&tv_interval($t0);
     #&Apache::lonxml::debug("Spent $td seconds processing");      #&Apache::lonxml::debug("Spent $td seconds processing");
     # &Apache::lonhomework::send_footer($request);  
     # always turn off debug messages      # always turn off debug messages
     $Apache::lonxml::debug=0;      $Apache::lonxml::debug=0;
     return OK;      return OK;

Removed from v.1.232  
changed lines
  Added in v.1.242


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