Diff for /loncom/homework/inputtags.pm between versions 1.216 and 1.217

version 1.216, 2007/02/27 19:43:16 version 1.217, 2007/03/01 02:30:03
Line 70  BEGIN { Line 70  BEGIN {
 #  %Apache::inputtags::answertxt    - <*response> tags store correct  #  %Apache::inputtags::answertxt    - <*response> tags store correct
 #                                     answer strings for display by <textline/>  #                                     answer strings for display by <textline/>
 #                                     in this hash.  #                                     in this hash.
   #  %Apache::inputtags::submission_display
   #                                   - <*response> tags store improved display
   #                                     of submission strings for display by part
   #                                     end.
   
 sub initialize_inputtags {  sub initialize_inputtags {
     @Apache::inputtags::input=();      @Apache::inputtags::input=();
Line 88  sub initialize_inputtags { Line 92  sub initialize_inputtags {
     @Apache::inputtags::importlist=();      @Apache::inputtags::importlist=();
     $Apache::inputtags::response_with_no_part=0;      $Apache::inputtags::response_with_no_part=0;
     %Apache::inputtags::answertxt=();      %Apache::inputtags::answertxt=();
       %Apache::inputtags::submission_display=();
 }  }
   
 sub check_for_duplicate_ids {  sub check_for_duplicate_ids {
Line 994  sub grade { Line 999  sub grade {
     return '';      return '';
 }  }
   
   sub get_grade_messages {
       my ($id,$prefix,$target,$status) = @_;
   
       my ($message,$latemessage,$trystr,$previousmsg);
       my $showbutton = 1;
   
       my $award = $Apache::lonhomework::history{"$prefix.award"};
       my $awarded = $Apache::lonhomework::history{"$prefix.awarded"};
       my $solved = $Apache::lonhomework::history{"$prefix.solved"};
       my $previous = $Apache::lonhomework::history{"$prefix.previous"};
       my $awardmsg = $Apache::lonhomework::history{"$prefix.awardmsg"};
       &Apache::lonxml::debug("Found Award |$award|$solved|$awardmsg");
       if ( $award ne '' || $solved ne '' || $status eq 'SHOW_ANSWER') {
    &Apache::lonxml::debug('Getting message');
    ($showbutton,my $bgcolor,$message,$previousmsg) =
       &decideoutput($award,$awarded,$awardmsg,$solved,$previous,
     $target);
    if ($target eq 'tex') {
       $message='\vskip 2 mm '.$message.' ';
    } else {
       $message="<td bgcolor=\"$bgcolor\">$message</td>";
       if ($previousmsg) {
    $previousmsg="<td bgcolor=\"#aaaaff\">$previousmsg</td>";
       }
    }
       }
       my $tries = $Apache::lonhomework::history{"$prefix.tries"};
       my $maxtries = &Apache::lonnet::EXT("resource.$id.maxtries");
       &Apache::lonxml::debug("got maxtries of :$maxtries:");
       #if tries are set to negative turn off the Tries/Button and messages
       if (defined($maxtries) && $maxtries < 0) { return ''; }
       if ( $tries eq '' ) { $tries = '0'; }
       if ( $maxtries eq '' ) { $maxtries = '2'; } 
       if ( $maxtries eq 'con_lost' ) { $maxtries = '0'; } 
       my $tries_text=&mt('Tries');
       if ( $Apache::lonhomework::type eq 'survey' ||
    $Apache::lonhomework::parsing_a_task) {
    $tries_text=&mt('Submissions');
       }
   
       if ($showbutton) {
    if ($target eq 'tex') {
       if ($env{'request.state'} ne "construct"
    && $Apache::lonhomework::type ne 'exam'
    && $env{'form.suppress_tries'} ne 'yes') {
    $trystr = ' {\vskip 1 mm \small \textit{'.$tries_text.'} '.
       $tries.'/'.$maxtries.'} \vskip 2 mm ';
       } else {
    $trystr = '\vskip 0 mm ';
       }
    } else {
       $trystr = "<td><nobr>".$tries_text." $tries";
       if ($Apache::lonhomework::parsing_a_task) {
       } elsif($env{'request.state'} ne 'construct') {
    $trystr.="/$maxtries";
       } else {
    if (defined($Apache::inputtags::params{'maxtries'})) {
       $trystr.="/".$Apache::inputtags::params{'maxtries'};
    }
       }
       $trystr.="</nobr></td>";
    }
       }
       if ($Apache::lonhomework::history{"$prefix.afterduedate"}) {
    #last submissions was after due date
    $latemessage=&mt(' The last submission was after the Due Date ');;
    if ($target eq 'web') {
       $latemessage='<td bgcolor="#ffaaaa">'.$latemessage.'</td>';
    }
       }
       return ($previousmsg,$latemessage,$message,$trystr,$showbutton);
   }
   
 sub gradestatus {  sub gradestatus {
     my ($id,$target) = @_;      my ($id,$target) = @_;
     my $showbutton = 1;      my $showbutton = 1;
     my $bgcolor = '';  
     my $message = '';      my $message = '';
     my $latemessage = '';      my $latemessage = '';
     my $trystr='';      my $trystr='';
Line 1011  sub gradestatus { Line 1088  sub gradestatus {
  && $status ne 'INVALID_ACCESS'    && $status ne 'INVALID_ACCESS' 
  && $status ne 'NEEDS_CHECKIN'    && $status ne 'NEEDS_CHECKIN' 
  && $status ne 'NOT_IN_A_SLOT') {     && $status ne 'NOT_IN_A_SLOT') {  
  my $award = $Apache::lonhomework::history{"resource.$id.award"};  
  my $awarded = $Apache::lonhomework::history{"resource.$id.awarded"};   ($previousmsg,$latemessage,$message,$trystr) =
  my $solved = $Apache::lonhomework::history{"resource.$id.solved"};      &get_grade_messages($id,"resource.$id",$target,$status,
  my $previous = $Apache::lonhomework::history{"resource.$id.previous"};   $showbutton);
  my $awardmsg = $Apache::lonhomework::history{"resource.$id.awardmsg"};   if ( $status eq 'SHOW_ANSWER' || $status eq 'CANNOT_ANSWER') {
  &Apache::lonxml::debug("Found Award |$award|$solved|$awardmsg");      $showbutton = 0;
  if ( $award ne '' || $solved ne '' || $status eq 'SHOW_ANSWER') {  
     &Apache::lonxml::debug('Getting message');  
     ($showbutton,$bgcolor,$message,$previousmsg) =  
  &decideoutput($award,$awarded,$awardmsg,$solved,$previous,  
       $target);  
     if ($target eq 'tex') {  
  $message='\vskip 2 mm '.$message.' ';  
     } else {  
  $message="<td bgcolor=\"$bgcolor\">$message</td>";  
  if ($previousmsg) {  
     $previousmsg="<td bgcolor=\"#aaaaff\">$previousmsg</td>";  
  }  
     }  
  }  
  my $tries = $Apache::lonhomework::history{"resource.$id.tries"};  
  my $maxtries = &Apache::lonnet::EXT("resource.$id.maxtries");  
  &Apache::lonxml::debug("got maxtries of :$maxtries:");  
  #if tries are set to negative turn off the Tries/Button and messages  
  if (defined($maxtries) && $maxtries < 0) { return ''; }  
  if ( $tries eq '' ) { $tries = '0'; }  
  if ( $maxtries eq '' ) { $maxtries = '2'; }   
  if ( $maxtries eq 'con_lost' ) { $maxtries = '0'; }   
  my $tries_text=&mt('Tries');  
  if ( $Apache::lonhomework::type eq 'survey' ||  
      $Apache::lonhomework::parsing_a_task) {  
     $tries_text=&mt('Submissions');  
  }  
  if ( $showbutton ) {  
     if ($target eq 'tex') {  
  if ($env{'request.state'} ne "construct" && $Apache::lonhomework::type ne 'exam' && $env{'form.suppress_tries'} ne 'yes') {  
     $trystr = ' {\vskip 1 mm \small \textit{'.$tries_text.'} '.$tries.'/'.$maxtries.'} \vskip 2 mm ';  
  } else {  
     $trystr = '\vskip 0 mm ';  
  }  
     } else {  
  $trystr = "<td><nobr>".$tries_text." $tries";  
  if ($Apache::lonhomework::parsing_a_task) {  
  } elsif($env{'request.state'} ne 'construct') {  
     $trystr.="/$maxtries";  
  } else {  
     if (defined($Apache::inputtags::params{'maxtries'})) {  
  $trystr.="/".$Apache::inputtags::params{'maxtries'};  
     }  
  }  
  $trystr.="</nobr></td>";  
     }  
  }   }
  if ( $status eq 'SHOW_ANSWER' || $status eq 'CANNOT_ANSWER') {$showbutton = 0;}  
  if ( $showbutton ) {    if ( $showbutton ) { 
     if ($target ne 'tex') {      if ($target ne 'tex') {
  $button = '<input onsubmit="javascript:setSubmittedPart(\''.$id.'\')" type="submit" name="submit_'.$id.'" value="'.&mt('Submit Answer').'" />';   $button = '<input onsubmit="javascript:setSubmittedPart(\''.$id.'\')" type="submit" name="submit_'.$id.'" value="'.&mt('Submit Answer').'" />';
     }      }
  }   }
  if ($Apache::lonhomework::history{"resource.$id.afterduedate"}) {  
     #last submissions was after due date  
     $latemessage=&mt(' The last submission was after the Due Date ');;  
     if ($target eq 'web') {  
  $latemessage='<td bgcolor="#ffaaaa">'.$latemessage.'</td>';  
     }  
  }  
     }      }
     my $output= $previousmsg.$latemessage.$message.$trystr;      my $output= $previousmsg.$latemessage.$message.$trystr;
     if ($output =~ /^\s*$/) {      if ($output =~ /^\s*$/) {
Line 1085  sub gradestatus { Line 1109  sub gradestatus {
  if ($target eq 'tex') {   if ($target eq 'tex') {
     return $button.' \vskip 0 mm '.$output.' ';      return $button.' \vskip 0 mm '.$output.' ';
  } else {   } else {
     return '<table><tr><td>'.$button.'</td>'.$output.'</tr></table>';      return '<table><tr><td>'.$button.'</td>'.$output.'<td>'.&previous_tries($id,$target).'</td></tr></table>';
  }   }
     }      }
 }  }
   
   sub previous_tries {
       my ($id,$target) = @_;
       my $output;
       my $status = $Apache::inputtags::status['-1'];
       
       foreach my $i (1..$Apache::lonhomework::history{'version'}) {
    my $prefix = $i.":resource.$id";
   
    next if (!exists($Apache::lonhomework::history{"$prefix.award"}));
    my ($previousmsg,$latemessage,$message,$trystr);
   
    ($previousmsg,$latemessage,$message,$trystr) =
       &get_grade_messages($id,"$prefix",$target,$status);
    if (!exists($Apache::lonhomework::history{"$prefix.tries"})) {
       undef($trystr);
    }
   
    if ($previousmsg eq '') { $previousmsg='<td></td>'; }
    if ($trystr eq '') { $trystr = '<td></td>'; }
   
    $output.='<tr>';
    $output.=$message.$previousmsg.$trystr;
   
    foreach my $resid (@Apache::inputtags::response) {
       my $prefix = $prefix.".$resid";
       if (exists($Apache::lonhomework::history{"$prefix.submission"})) {
    my $submission =
       $Apache::inputtags::submission_display{"$prefix.submission"};
    if (!defined($submission)) {
       $submission = 
    $Apache::lonhomework::history{"$prefix.submission"};
    }
    $output.='<td>'.$submission.'</td>';
       } else {
    $output.='<td></td>';
       }
    }
    $output.='</tr>';
       }
       return if ($output eq '');
   
       $output ='<table class="LC_prior_tries">'.$output.'</table>';
       #return $output;
       $output=~s/\\/\\\\/g;
       $output=~s/\'/\\\'/g;
       $output=~s/\s+/ /g;
       my $windowopen=&Apache::lonhtmlcommon::javascript_docopen();
       my $start_page =
    &Apache::loncommon::start_page('Previous Tries', undef,
          {'only_body' => 1,
    'bgcolor'   => '#FFFFFF',
    'js_ready'  => 1,});
       my $end_page =
    &Apache::loncommon::end_page({'js_ready' => 1,});
       
       my $result ="<script type=\"text/javascript\">
   // <![CDATA[
       function LONCAPA_previous_tries_$Apache::lonxml::curdepth() {newWindow=open('','new_W','width=500,height=500,scrollbars=1,resizable=yes');newWindow.$windowopen;newWindow.document.writeln('$start_page $output $end_page');newWindow.document.close();newWindow.focus()}
   // ]]>
   </script><a href=\"javascript:LONCAPA_previous_tries_$Apache::lonxml::curdepth();void(0);\">".&mt("Previous Tries")."</a><br />";
       #use Data::Dumper;
       #&Apache::lonnet::logthis(&Dumper(\%Apache::inputtags::submission_display));
       return $result;
   }
   
 1;  1;
 __END__  __END__
     

Removed from v.1.216  
changed lines
  Added in v.1.217


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