Diff for /loncom/homework/inputtags.pm between versions 1.173 and 1.188

version 1.173, 2005/08/02 18:05:25 version 1.188, 2006/03/09 00:41:24
Line 36  BEGIN { Line 36  BEGIN {
     &Apache::lonxml::register('Apache::inputtags',('hiddenline','textfield','textline'));      &Apache::lonxml::register('Apache::inputtags',('hiddenline','textfield','textline'));
 }  }
   
   #   Initializes a set of global variables used during the parse of the problem.
   #
   #  @Apache::inputtags::input        - List of current input ids.
   #  @Apache::inputtags::inputlist    - List of all input ids seen this problem.
   #  @Apache::inputtags::response     - List of all current resopnse ids.
   #  @Apache::inputtags::responselist - List of all response ids seen this 
   #                                       problem.
   #  @Apache::inputtags::hint         - List of all hint ids.
   #  @Apache::inputtags::hintlist     - List of all hint ids seen this problem.
   #  @Apache::inputtags::previous     - List describing if specific responseds
   #                                       have been used
   #  @Apache::inputtags::previous_version - Submission responses were used in.
   #  $Apache::inputtags::part         - Current part id (valid only in 
   #                                       <problem>)
   #                                     0 if not in a part.
   #  @Apache::inputtags::partlist     - List of part ids seen in the current
   #                                       <problem>
   #  @Apache::inputtags::status       - List of problem  statuses. First 
   #                                     element is the status of the <problem>
   #                                     the remainder are for individual <part>s.
   #  %Apache::inputtags::params       - Hash of defined parameters for the
   #                                     current response.
   #  @Apache::inputtags::import       - List of all ids for <import> thes get
   #                                     join()ed and prepended.
   #  @Apache::inputtags::importlist   - List of all import ids seen.
   #  $Apache::inputtags::response_with_no_part
   #                                   - Flag set true if we have seen a response
   #                                     that is not inside a <part>
   #  %Apache::inputtags::answertxt    - <*response> tags store correct
   #                                     answer strings for display by <textline/>
   #                                     in this hash.
   
 sub initialize_inputtags {  sub initialize_inputtags {
     # list of current input ids  
     @Apache::inputtags::input=();      @Apache::inputtags::input=();
     # list of all input ids seen in this problem  
     @Apache::inputtags::inputlist=();      @Apache::inputtags::inputlist=();
     # list of all current response ids  
     @Apache::inputtags::hint=();  
     # list of all response ids seen in this problem  
     @Apache::inputtags::responselist=();  
     # list of all current hint ids  
     @Apache::inputtags::response=();      @Apache::inputtags::response=();
     # list of all hint ids seen in this problem      @Apache::inputtags::responselist=();
       @Apache::inputtags::hint=();
     @Apache::inputtags::hintlist=();      @Apache::inputtags::hintlist=();
     # list of whether or not a specific response was previously used  
     @Apache::inputtags::previous=();      @Apache::inputtags::previous=();
     # submission it was used in  
     @Apache::inputtags::previous_version=();      @Apache::inputtags::previous_version=();
     # id of current part, 0 means that no part is current   
     # (inside <problem> only  
     $Apache::inputtags::part='';      $Apache::inputtags::part='';
     # list of all part ids seen  
     @Apache::inputtags::partlist=();      @Apache::inputtags::partlist=();
     # list of problem date statuses, the first element is for <problem>  
     # if there is a second element it is for the current <part>  
     @Apache::inputtags::status=();      @Apache::inputtags::status=();
     # hash of defined params for the current response  
     %Apache::inputtags::params=();      %Apache::inputtags::params=();
     # list of all ids, for <import>, these get join()ed and prepended  
     @Apache::inputtags::import=();      @Apache::inputtags::import=();
     # list of all import ids seen  
     @Apache::inputtags::importlist=();      @Apache::inputtags::importlist=();
     # just used to note whether we have seen a response that isn't in a part  
     $Apache::inputtags::response_with_no_part=0;      $Apache::inputtags::response_with_no_part=0;
     # storage location so the begin <*response> tag can generate the correct  
     # answer string for display by the <textline />  
     %Apache::inputtags::answertxt=();      %Apache::inputtags::answertxt=();
 }  }
   
Line 119  sub addchars { Line 131  sub addchars {
 }  }
   
 sub start_textfield {  sub start_textfield {
     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;      my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
     my $result = "";      my $result = "";
     my $id = &start_input($parstack,$safeeval);      my $id = &start_input($parstack,$safeeval);
     my $resid=$Apache::inputtags::response[-1];      my $resid=$Apache::inputtags::response[-1];
Line 143  sub start_textfield { Line 155  sub start_textfield {
     if ($oldresponse ne '') {      if ($oldresponse ne '') {
   
  #get rid of any startup text if the user has already responded   #get rid of any startup text if the user has already responded
  &Apache::lonxml::get_all_text("/textfield",$parser);   &Apache::lonxml::get_all_text("/textfield",$parser,$style);
     }      }
  } else {   } else {
     #right or wrong don't show it      #right or wrong don't show it
     #$result='<table border="1"><tr><td><i>'.$oldresponse.'</i></td></tr></table>';      #$result='<table border="1"><tr><td><i>'.$oldresponse.'</i></td></tr></table>';
     $result='';      $result='';
     #get rid of any startup text      #get rid of any startup text
     &Apache::lonxml::get_all_text("/textfield",$parser);      &Apache::lonxml::get_all_text("/textfield",$parser,$style);
  }   }
     } elsif ($target eq 'grade') {      } elsif ($target eq 'grade') {
  my $seedtext=&Apache::lonxml::get_all_text("/textfield",$parser);   my $seedtext=&Apache::lonxml::get_all_text("/textfield",$parser,
      $style);
  if ($seedtext eq $env{'form.HWVAL_'.$resid}) {   if ($seedtext eq $env{'form.HWVAL_'.$resid}) {
     # if the seed text is still there it wasn't a real submission      # if the seed text is still there it wasn't a real submission
     $env{'form.HWVAL_'.$resid}='';      $env{'form.HWVAL_'.$resid}='';
Line 164  sub start_textfield { Line 177  sub start_textfield {
  $result.=&Apache::edit::text_arg('Columns:','cols',$token,4);   $result.=&Apache::edit::text_arg('Columns:','cols',$token,4);
  $result.=&Apache::edit::text_arg   $result.=&Apache::edit::text_arg
     ('Click-On Texts (comma sep):','addchars',$token,10);      ('Click-On Texts (comma sep):','addchars',$token,10);
  my $bodytext=&Apache::lonxml::get_all_text("/textfield",$parser);   my $bodytext=&Apache::lonxml::get_all_text("/textfield",$parser,
      $style);
  $result.=&Apache::edit::editfield($token->[1],$bodytext,'Text you want to appear by default:',80,2);   $result.=&Apache::edit::editfield($token->[1],$bodytext,'Text you want to appear by default:',80,2);
     } elsif ($target eq 'modified') {      } elsif ($target eq 'modified') {
  my $constructtag=&Apache::edit::get_new_args($token,$parstack,   my $constructtag=&Apache::edit::get_new_args($token,$parstack,
Line 208  sub end_textfield { Line 222  sub end_textfield {
     return $result;      return $result;
 }  }
   
   sub exam_box {
       my ($target) = @_;
       my $result;
   
       if ($target eq 'tex') {
    $result.='\fbox{\fbox{\parbox{\textwidth-5mm}{\strut\\\\\strut\\\\\strut\\\\\strut\\\\}}}';
    my $repetition = &Apache::response::repetition();
    $result.='\begin{enumerate}';
    foreach my $i (0..$repetition-1) {
       $result.='\item[\textbf{'.
    ($Apache::lonxml::counter+$i).
    '}.]\textit{Leave blank on scoring form}\vskip 0 mm';
    }
    $result.= '\end{enumerate}';
   
       } elsif ($target eq 'web') {
    my $id=$Apache::inputtags::response[-1];
    $result.= '<br /><br />
                      <textarea name="HWVAL_'.$id.'" rows="4" cols="50">
                      </textarea> <br /><br />';
       }
       return $result;
   }
   
   sub needs_exam_box {
       my ($tagstack) = @_;
       my @tags = ('formularesponse',
    'stringresponse',
    'reactionresponse',
    'organicresponse',
    'imageresponse',
    );
   
       foreach my $tag (@tags) {
    if (grep(/\Q$tag\E/,@$tagstack)) {
       return 1;
    }
       }
       return 0;
   }
   
 sub start_textline {  sub start_textline {
     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;      my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
     my $result = "";      my $result = "";
Line 238  sub start_textline { Line 293  sub start_textline {
  $result.= '<input type="text" '.$readonly.' name="HWVAL_'.$id.'" value="'.   $result.= '<input type="text" '.$readonly.' name="HWVAL_'.$id.'" value="'.
     $oldresponse.'" size="'.$size.'" maxlength="'.$maxlength.'" />';      $oldresponse.'" size="'.$size.'" maxlength="'.$maxlength.'" />';
     }      }
       if ($Apache::lonhomework::type eq 'exam'
    && &needs_exam_box($tagstack)) {
    $result.=&exam_box($target);
       }
  } else {   } else {
     #right or wrong don't show what was last typed in.      #right or wrong don't show what was last typed in.
     $result='<b>'.$Apache::inputtags::answertxt{$id}.'</b>';      $result='<b>'.$Apache::inputtags::answertxt{$id}.'</b>';
Line 257  sub start_textline { Line 316  sub start_textline {
      $safeeval,'size',       $safeeval,'size',
      'addchars','readonly');       'addchars','readonly');
  if ($constructtag) { $result = &Apache::edit::rebuild_tag($token); }   if ($constructtag) { $result = &Apache::edit::rebuild_tag($token); }
     } elsif ($target eq 'tex' and $Apache::lonhomework::type ne 'exam') {      } elsif ($target eq 'tex' 
        && $Apache::lonhomework::type ne 'exam') {
  my $size = &Apache::lonxml::get_param('size',$parstack,$safeeval);   my $size = &Apache::lonxml::get_param('size',$parstack,$safeeval);
  if ($size != 0) {$size=$size*2; $size.=' mm';} else {$size='40 mm';}   if ($size != 0) {$size=$size*2; $size.=' mm';} else {$size='40 mm';}
  $result='\framebox['.$size.'][s]{\tiny\strut}';   $result='\framebox['.$size.'][s]{\tiny\strut}';
   
       } elsif ($target eq 'tex' 
        && $Apache::lonhomework::type eq 'exam'
        && &needs_exam_box($tagstack)) {
    $result.=&exam_box($target);
     }      }
     return $result;      return $result;
 }  }
Line 306  sub end_hiddenline { Line 371  sub end_hiddenline {
 # $which -> 'uploadedonly'  -> only newly uploaded files  # $which -> 'uploadedonly'  -> only newly uploaded files
 #           'portfolioonly' -> only allow files from portfolio  #           'portfolioonly' -> only allow files from portfolio
 #           'both' -> allow files from either location  #           'both' -> allow files from either location
   # $extratext -> additional text to go between the link and the input box
 # returns a table row <tr>   # returns a table row <tr> 
 sub file_selector {  sub file_selector {
     my ($part,$id,$uploadedfiletypes,$which)=@_;      my ($part,$id,$uploadedfiletypes,$which,$extratext)=@_;
     if (!$uploadedfiletypes) { return ''; }      if (!$uploadedfiletypes) { return ''; }
   
     my $jspart=$part;      my $jspart=$part;
Line 329  sub file_selector { Line 395  sub file_selector {
   
  if ($uploadedfile) {   if ($uploadedfile) {
     my $url=$Apache::lonhomework::history{"resource.$part.$id.uploadedurl"};      my $url=$Apache::lonhomework::history{"resource.$part.$id.uploadedurl"};
     push (@Apache::lonxml::extlinks,$url);      &Apache::lonxml::extlink($url);
     &Apache::lonnet::allowuploaded('/adm/essayresponse',$url);      &Apache::lonnet::allowuploaded('/adm/essayresponse',$url);
     my $icon=&Apache::loncommon::icon($url);      my $icon=&Apache::loncommon::icon($url);
     my $curfile='<a href="'.$url.'"><img src="'.$icon.      my $curfile='<a href="'.$url.'"><img src="'.$icon.
Line 343  sub file_selector { Line 409  sub file_selector {
  $result.='<br />'.'<strong>'.&mt('OR:').'</strong><br />';   $result.='<br />'.'<strong>'.&mt('OR:').'</strong><br />';
     }      }
     if ($which eq 'portfolioonly' || $which eq 'both') {       if ($which eq 'portfolioonly' || $which eq 'both') { 
  $result.='<a href='."'".'javascript:void(window.open("/adm/portfolio?mode=selectfile&amp;fieldname=HWPORT'.$jspart.'_'.$id.'","cat","height=600,width=800,scrollbars=1,resizable=1,menubar=2,location=1"))'."'".'>'.   $result.=$extratext.'<a href='."'".'javascript:void(window.open("/adm/portfolio?mode=selectfile&amp;fieldname=HWPORT'.$jspart.'_'.$id.'","cat","height=600,width=800,scrollbars=1,resizable=1,menubar=2,location=1"))'."'".'>'.
     &mt('Select Portfolio Files').'</a><br />'.      &mt('Select Portfolio Files').'</a><br />'.
     '<input type="text" size="50" name="HWPORT'.$jspart.'_'.$id.'" value="" />'.      '<input type="text" size="50" name="HWPORT'.$jspart.'_'.$id.'" value="" />'.
     '<br />';      '<br />';
  if ($Apache::lonhomework::history{"resource.$part.$id.portfiles"}=~/[^\s]/){   if ($Apache::lonhomework::history{"resource.$part.$id.portfiles"}=~/[^\s]/){
     my @filelist;      my (@filelist,@bad_file_list);
     foreach my $file (split(',',&Apache::lonnet::unescape($Apache::lonhomework::history{"resource.$part.$id.portfiles"}))) {      foreach my $file (split(',',&Apache::lonnet::unescape($Apache::lonhomework::history{"resource.$part.$id.portfiles"}))) {
  my (undef,undef,$domain,$user)=&Apache::lonxml::whichuser();   my (undef,undef,$domain,$user)=&Apache::lonxml::whichuser();
  my $url="/uploaded/$domain/$user/portfolio$file";   my $url="/uploaded/$domain/$user/portfolio$file";
  my $icon=&Apache::loncommon::icon($url);   my $icon=&Apache::loncommon::icon($url);
  push(@filelist,'<a href="'.$url.'"><img src="'.$icon.   push(@filelist,'<a href="'.$url.'"><img src="'.$icon.
      '" border="0" />'.$file.'</a>');       '" border="0" />'.$file.'</a>');
    if (! &Apache::lonnet::stat_file($url)) {
       push(@bad_file_list,'<a href="'.$url.'"><img src="'.$icon.
    '" border="0" />'.$file.'</a>');
    }
     }      }
     $result.=&mt("Portfolio files previously selected: <strong>[_1]</strong>",join(', ',@filelist));      $result.=&mt("Portfolio files previously selected: <strong>[_1]</strong>",join(', ',@filelist));
       if (@bad_file_list) {
    $result.='<br />'.&mt('<font color="red">These file(s) don\'t exist:</font> <strong>[_1]</strong>',join(', ',@bad_file_list));
       }
  }   }
     }      }
     $result.='</td></tr>';       $result.='</td></tr>'; 
Line 373  sub checkstatus { Line 446  sub checkstatus {
     return(undef,undef);      return(undef,undef);
 }  }
   
   sub valid_award {
       my ($award) =@_;
       foreach my $possibleaward ('EXTRA_ANSWER','MISSING_ANSWER', 'ERROR',
          'NO_RESPONSE',
          'TOO_LONG', 'UNIT_INVALID_INSTRUCTOR',
          'UNIT_INVALID_STUDENT', 'UNIT_IRRECONCIBLE',
          'UNIT_FAIL', 'NO_UNIT',
          'UNIT_NOTNEEDED', 'WANTED_NUMERIC',
          'BAD_FORMULA', 'SIG_FAIL', 'INCORRECT', 
          'MISORDERED_RANK', 'INVALID_FILETYPE',
          'DRAFT', 'SUBMITTED', 'ASSIGNED_SCORE',
          'APPROX_ANS', 'EXACT_ANS','COMMA_FAIL') {
    if ($award eq $possibleaward) { return 1; }
       }
       return 0;
   }
   
 sub finalizeawards {  sub finalizeawards {
     my ($awardref,$msgref)=@_;      my ($awardref,$msgref,$nameref,$reverse)=@_;
     my $result=undef;      my $result=undef;
     my $award;      my $award;
     my $msg;      my $msg;
Line 390  sub finalizeawards { Line 480  sub finalizeawards {
  if ($blankcount == ($#$awardref + 1)) { $result = 'NO_RESPONSE'; }   if ($blankcount == ($#$awardref + 1)) { $result = 'NO_RESPONSE'; }
     }      }
     if (defined($result)) { return ($result,$msg); }      if (defined($result)) { return ($result,$msg); }
     foreach my $possibleaward ('MISSING_ANSWER', 'ERROR', 'NO_RESPONSE',  
        'TOO_LONG', 'UNIT_INVALID_INSTRUCTOR',      # these awards are ordered from most important error through best correct
        'UNIT_INVALID_STUDENT', 'UNIT_IRRECONCIBLE',      
        'UNIT_FAIL', 'NO_UNIT',      my @awards = ('EXTRA_ANSWER', 'MISSING_ANSWER', 'ERROR', 'NO_RESPONSE',
        'UNIT_NOTNEEDED', 'WANTED_NUMERIC',    'TOO_LONG',
        'BAD_FORMULA', 'SIG_FAIL', 'INCORRECT',     'UNIT_INVALID_INSTRUCTOR', 'UNIT_INVALID_STUDENT',
        'MISORDERED_RANK', 'INVALID_FILETYPE',    'UNIT_IRRECONCIBLE', 'UNIT_FAIL', 'NO_UNIT',
        'DRAFT', 'SUBMITTED', 'ASSIGNED_SCORE',    'UNIT_NOTNEEDED', 'WANTED_NUMERIC', 'BAD_FORMULA',
        'APPROX_ANS', 'EXACT_ANS','COMMA_FAIL') {    'COMMA_FAIL', 'SIG_FAIL', 'INCORRECT', 'MISORDERED_RANK',
     'INVALID_FILETYPE', 'DRAFT', 'SUBMITTED', 'ASSIGNED_SCORE',
     'APPROX_ANS', 'EXACT_ANS');
       if ($reverse) { @awards=reverse(@awards); }
       foreach my $possibleaward (@awards) {
  ($result,$msg)=&checkstatus($possibleaward,$awardref,$msgref);   ($result,$msg)=&checkstatus($possibleaward,$awardref,$msgref);
  if (defined($result)) { return ($result,$msg); }   if (defined($result)) { return ($result,$msg); }
     }      }
Line 419  sub decideoutput { Line 513  sub decideoutput {
   'no_message' => '#fffff',    'no_message' => '#fffff',
   );    );
   
       my $part = $Apache::inputtags::part;
       my $handgrade = 
    ('yes' eq lc(&Apache::lonnet::EXT("resource.$part.handgrade")));
       
       my $computer = ($handgrade)? ''
                          : " ".&mt("Computer's answer now shown above.");
       &Apache::lonxml::debug("handgrade has :$handgrade:");
   
     if ($previous) { $previousmsg=&mt('You have entered that answer before'); }      if ($previous) { $previousmsg=&mt('You have entered that answer before'); }
           
     if      ($solved =~ /^correct/) {      if      ($solved =~ /^correct/) {
Line 440  sub decideoutput { Line 542  sub decideoutput {
  $message = '\textbf{'.$message.'}';   $message = '\textbf{'.$message.'}';
     } else {      } else {
  $message = "<b>".$message."</b>";   $message = "<b>".$message."</b>";
  $message.=" ".&mt("Computer's answer now shown above.");   $message.= $computer;
     }      }
     $added_computer_text=1;      $added_computer_text=1;
     unless ($env{'course.'.      unless ($env{'course.'.
Line 472  sub decideoutput { Line 574  sub decideoutput {
  $message = '\textbf{'.&mt('You are correct.').'}';   $message = '\textbf{'.&mt('You are correct.').'}';
     } else {      } else {
  $message = "<b>".&mt('You are correct.')."</b>";   $message = "<b>".&mt('You are correct.')."</b>";
  $message.=" ".&mt("Computer's answer now shown above.");   $message.= $computer;
     }      }
     $added_computer_text=1;      $added_computer_text=1;
     unless ($env{'course.'.      unless ($env{'course.'.
Line 490  sub decideoutput { Line 592  sub decideoutput {
  $message = '';   $message = '';
  $bgcolor=$possiblecolors{'no_feedback'};   $bgcolor=$possiblecolors{'no_feedback'};
  $button=1;   $button=1;
       } elsif ($award eq 'EXTRA_ANSWER') {
    $message = &mt('Some extra items were submitted.');
    $bgcolor=$possiblecolors{'not_charged_try'};
    $button = 1;
     } elsif ($award eq 'MISSING_ANSWER') {      } elsif ($award eq 'MISSING_ANSWER') {
  $message = &mt('Some items were not submitted.');   $message = &mt('Some items were not submitted.');
  $bgcolor=$possiblecolors{'not_charged_try'};   $bgcolor=$possiblecolors{'not_charged_try'};
Line 574  sub decideoutput { Line 680  sub decideoutput {
  $bgcolor=$possiblecolors{'correct'};   $bgcolor=$possiblecolors{'correct'};
  $button=0;   $button=0;
     } elsif ($award eq '') {      } elsif ($award eq '') {
  $bgcolor=$possiblecolors{'not_charged_try'};   if ($handgrade && $Apache::inputtags::status[-1] eq 'SHOW_ANSWER') {
       $message = &mt("Nothing submitted.");
       $bgcolor=$possiblecolors{'charged_try'};
    } else {
       $bgcolor=$possiblecolors{'not_charged_try'};
    }
  $button=1;   $button=1;
     } else {      } else {
  $message = &mt("Unknown message").": $award";   $message = &mt("Unknown message").": $award";
Line 588  sub decideoutput { Line 699  sub decideoutput {
     }      }
     if ($Apache::inputtags::status[-1] eq 'SHOW_ANSWER' &&       if ($Apache::inputtags::status[-1] eq 'SHOW_ANSWER' && 
  !$added_computer_text && $target ne 'tex') {   !$added_computer_text && $target ne 'tex') {
  $message.=" ".&mt("Computer's answer now shown above.");   $message.= $computer;
  $added_computer_text=1;   $added_computer_text=1;
     }      }
     return ($button,$bgcolor,$message,$previousmsg);      return ($button,$bgcolor,$message,$previousmsg);
Line 744  sub setgradedata { Line 855  sub setgradedata {
  return '';   return '';
     }      }
     $Apache::lonhomework::results{"resource.$id.award"} = $award;      $Apache::lonhomework::results{"resource.$id.award"} = $award;
       if ($award eq 'SUBMITTED') {
    &Apache::response::add_to_gradingqueue();
       }
 }  }
   
 sub grade {  sub grade {
Line 800  sub gradestatus { Line 914  sub gradestatus {
   
     my $status = $Apache::inputtags::status['-1'];      my $status = $Apache::inputtags::status['-1'];
     &Apache::lonxml::debug("gradestatus has :$status:");      &Apache::lonxml::debug("gradestatus has :$status:");
     if ( $status ne 'CLOSED' && $status ne 'UNAVAILABLE' &&      if ( $status ne 'CLOSED' 
  $status ne 'INVALID_ACCESS') {     && $status ne 'UNAVAILABLE' 
    && $status ne 'INVALID_ACCESS' 
    && $status ne 'NEEDS_CHECKIN' 
    && $status ne 'NOT_IN_A_SLOT') {  
  my $award = $Apache::lonhomework::history{"resource.$id.award"};   my $award = $Apache::lonhomework::history{"resource.$id.award"};
  my $awarded = $Apache::lonhomework::history{"resource.$id.awarded"};   my $awarded = $Apache::lonhomework::history{"resource.$id.awarded"};
  my $solved = $Apache::lonhomework::history{"resource.$id.solved"};   my $solved = $Apache::lonhomework::history{"resource.$id.solved"};

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


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