Diff for /loncom/homework/lonhomework.pm between versions 1.183 and 1.188

version 1.183, 2004/11/13 20:40:32 version 1.188, 2004/12/20 12:16:47
Line 53  use HTML::Entities(); Line 53  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();
   #
   # FIXME!!!!!!!
   #   Be nice if someone 
   #    - Took credit/blame for this module.
   #    - At least commented the purpose of each major
   #      sub
   #    - Even better commented the major blocks.
   #
   #  I'll have a go at it for what I need.
   #     ?'s- mean maybe this is right.
   #          The number of ?'s represents the rough level
   #          of doubt I have about rightness, with ??? representing
   #          uncertainty based on the first blush interpretation.
   #          ?? - I have some code to back up this interpretation.
   #          ?  - I"m pretty sure I understand the code that backs up this
   #               interpretation.
   #         ???? - Absolutely clueless.
   #          .  - I'm pretty sure the interpretation is correct.
   #  RF.
   
   
   # 'Exported' Variables:
   
   #   viewgrades is 'F' if users are not allowed to view the grades.. T otherwise.
   
   $Apache::lonhomework::viewgrades = 'F'; # By default cannot.
   
   #  Internal variables.
   
   my $DEBUG=0; # set nonzero to enable debugging.
   
 BEGIN {  BEGIN {
     &Apache::lonxml::register_insert();      &Apache::lonxml::register_insert();
 }  }
   
   #
   #   Issue debug log messages.  
   # Parameters:
   #    The log message to issue.
   # Implicit Inputs:
   #    DEBUG   - If non zero the message is issued, otherwise not.
   #
   sub Debug {
       my ($message) = @_;
   
       if($DEBUG) {
    my @call_context = caller(1);
    my $prefix = "$call_context[3]:$call_context[2]:: ";
    &Apache::lonnet::logthis($prefix.$message);
       }
   }
   
   #
   #   I believe this sub defines how to render the
   #   problem based on the context of the rendering?
   # Implicit inputs:
   #   Various session environment variables:
   #      request.state - State of the resource actually ??
   #                       published  - Examining in resource space.
   #                       uploaded   - Not sure how this happens?????
   #                       contruct   - Rendering in construction space for viewing.
   #      form.grade_target - 
 sub get_target {  sub get_target {
       &Debug("request.state = $ENV{'request.state'}");
       if( defined($ENV{'form.grade_target'})) {
    &Debug("form.grade_target = $ENV{'form.grade_target'}");
       } else {
    &Debug("form.grade_target <undefined>");
       }
     if (($ENV{'request.state'} eq "published") ||      if (($ENV{'request.state'} eq "published") ||
  ($ENV{'request.state'} eq "uploaded")) {   ($ENV{'request.state'} eq "uploaded")) {
  if ( defined($ENV{'form.grade_target'}  )    if ( defined($ENV{'form.grade_target'}  ) 
Line 384  sub setuppermissions { Line 448  sub setuppermissions {
  $viewgrades = &Apache::lonnet::allowed('vgr',$ENV{'request.course.id'}.   $viewgrades = &Apache::lonnet::allowed('vgr',$ENV{'request.course.id'}.
                                                '/'.$ENV{'request.course.sec'});                                                 '/'.$ENV{'request.course.sec'});
     }      }
     $Apache::lonhomework::viewgrades = $viewgrades;      $Apache::lonhomework::viewgrades = $viewgrades; # File global variable...dirt.
       if ($Apache::lonhomework::browse eq 'F' && 
    $ENV{'form.devalidatecourseresdata'} eq 'on') {
    my (undef,$courseid) = &Apache::lonxml::whichuser();
    &Apache::lonnet::devalidatecourseresdata($ENV{"course.$courseid.num"},
         $ENV{"course.$courseid.domain"});
       }
     return ''      return ''
 }  }
   
Line 519  sub analyze { Line 589  sub analyze {
     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).'">'.&mt('Part').' '.$part.'</td></tr>');      $request->print('<table><tr><th colspan="'.($num_cols+1).'">'.&mt('Part').' '.$part.'</th></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).'">'.&mt('Answer').'</td><td>'.&mt('Frequency').'</td></tr>');      $request->print('<tr><th colspan="'.($num_cols).'">'.&mt('Answer').'</th><th>'.&mt('Frequency').'</th></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 601  sub editxmlmode { Line 671  sub editxmlmode {
     }      }
     return '';      return '';
 }  }
   #
   #    Render the page in whatever target desired.
   #
   
 sub renderpage {  sub renderpage {
     my ($request,$file) = @_;      my ($request,$file) = @_;
Line 714  sub newproblem { Line 787  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,1);   my $bodytag=&Apache::loncommon::bodytag(undef,undef,undef,
    ($ENV{'environment.remote'} ne 'off'));
  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 767  sub handler { Line 841  sub handler {
     my $request=$_[0];      my $request=$_[0];
           
     $Apache::lonxml::debug=$ENV{'user.debug'};      $Apache::lonxml::debug=$ENV{'user.debug'};
     if (&setupheader($request)) { return OK; }  
     $ENV{'request.uri'}=$request->uri;      $ENV{'request.uri'}=$request->uri;
     &setuppermissions();      &setuppermissions();
     &Apache::lonxml::debug("Permissions:$Apache::lonhomework::browse:$Apache::lonhomework::viewgrades:");      &Apache::lonxml::debug("Permissions:$Apache::lonhomework::browse:$Apache::lonhomework::viewgrades:");
Line 796  sub handler { Line 869  sub handler {
     $request->internal_redirect('/adm/ambiguous'); return;      $request->internal_redirect('/adm/ambiguous'); return;
  }   }
     }      }
       if (&setupheader($request)) { return OK; }
   
     my ($symb) = &Apache::lonxml::whichuser();      my ($symb) = &Apache::lonxml::whichuser();
     &Apache::lonxml::debug('symb is '.$symb);      &Apache::lonxml::debug('symb is '.$symb);

Removed from v.1.183  
changed lines
  Added in v.1.188


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