Diff for /loncom/homework/essayresponse.pm between versions 1.62 and 1.74

version 1.62, 2005/04/07 06:56:21 version 1.74, 2006/09/21 21:23:19
Line 31  use strict; Line 31  use strict;
 use Apache::lonxml();  use Apache::lonxml();
 use Apache::lonnet;  use Apache::lonnet;
 use Apache::lonlocal;  use Apache::lonlocal;
   use lib '/home/httpd/lib/perl/';
   use LONCAPA;
    
   
 BEGIN {  BEGIN {
     &Apache::lonxml::register('Apache::essayresponse',('essayresponse'));      &Apache::lonxml::register('Apache::essayresponse',('essayresponse'));
Line 42  sub start_essayresponse { Line 45  sub start_essayresponse {
     my $id = &Apache::response::start_response($parstack,$safeeval);      my $id = &Apache::response::start_response($parstack,$safeeval);
     if ($target eq 'meta') {      if ($target eq 'meta') {
  $result=&Apache::response::meta_package_write('essayresponse');   $result=&Apache::response::meta_package_write('essayresponse');
     } elsif ($target eq 'web') {      } elsif ($target eq 'web' &&
        $Apache::inputtags::status[-1] eq 'CAN_ANSWER') {
  my $part= $Apache::inputtags::part;   my $part= $Apache::inputtags::part;
  my $ncol= &Apache::lonnet::EXT("resource.$part".'_'."$id.maxcollaborators");   my $ncol= &Apache::lonnet::EXT("resource.$part".'_'."$id.maxcollaborators");
  my $coll= &HTML::Entities::encode($Apache::lonhomework::history{"resource.$part.$id.collaborators"},'<>&"');   my $coll= &HTML::Entities::encode($Apache::lonhomework::history{"resource.$part.$id.collaborators"},'<>&"');
Line 50  sub start_essayresponse { Line 54  sub start_essayresponse {
         $uploadedfiletypes=~s/[^\w\,]//g;          $uploadedfiletypes=~s/[^\w\,]//g;
  $result='<br /><table border="1">';   $result='<br /><table border="1">';
  $result.='<tr><td>'.   $result.='<tr><td>'.
               '<label>'.
     '<input type="radio" name="HWDRAFT'.$part.'_'.$id.'" value="yes" checked="checked" /> '.      '<input type="radio" name="HWDRAFT'.$part.'_'.$id.'" value="yes" checked="checked" /> '.
     &mt('Submit entries below as answer to receive credit').' <br />'.      &mt('Submit entries below as answer to receive credit').
     '<input type="radio" name="HWDRAFT'.$part.'_'.$id.'" value="no" /> '.              '</label> <br />'.
       '<label>'.
               '<input type="radio" name="HWDRAFT'.$part.'_'.$id.'" value="no" /> '.
     &mt('Save entries below as a draft answer (not submitting them for credit yet)').      &mt('Save entries below as a draft answer (not submitting them for credit yet)').
     ' </td></tr>';      '</label>'.
               ' </td></tr>';
  if ($ncol > 0) {   if ($ncol > 0) {
     $result .='<tr><td>'.      $result .='<tr><td>'.'<label>'.
  'Collaborators: <input type="text" size="70" max="80" name="HWCOL'.   'Collaborators: <input type="text" size="70" max="80" name="HWCOL'.
  $part.'_'.$id.'" value="'.$coll.'" /><br />'.   $part.'_'.$id.'" value="'.$coll.'" /><br />'.
  &mt('(Enter maximum [_1] collaborators using username or username@domain, e.g. smithje or smithje@[_2].)',$ncol,$env{'user.domain'}).'<br />';   &mt('(Enter maximum [_1] collaborators using username or username@domain, e.g. smithje or smithje@[_2].)',$ncol,$env{'user.domain'}).
                   '</label><br />';
     $result .= &check_collaborators($ncol,$coll) if ($coll =~ /\w+/);      $result .= &check_collaborators($ncol,$coll) if ($coll =~ /\w+/);
     $result .='</td></tr>';      $result .='</td></tr>';
  }   }
  $result.=&Apache::inputtags::file_selector($part,$id,   $result.=&Apache::inputtags::file_selector($part,$id,
    $uploadedfiletypes,'both');     $uploadedfiletypes,'both');
         $result.='</table>';          $result.='</table>';
       } elsif ($target eq 'web' &&
        $Apache::inputtags::status[-1] ne 'CAN_ANSWER') {
    my $part= $Apache::inputtags::part;
    my @msgs;
    if ($Apache::lonhomework::history{"resource.$part.$id.collaborators"} =~ /\S/) {
       my $coll= &HTML::Entities::encode($Apache::lonhomework::history{"resource.$part.$id.collaborators"},'<>&"');
       $result .= '<td>'.&mt('Collaborated with [_1]',$coll).'</td>';
    }
   
    my $file_submission = 
       &Apache::inputtags::show_past_file_submission($part,$id);
    if ($file_submission) {
       $result .= '<td>'.$file_submission.'</td>';
    }
   
    my $port_submission = 
       &Apache::inputtags::show_past_portfile_submission($part,$id);
    if ($port_submission) {
       $result .= '<td>'.$port_submission.'</td>';
    }
   
    if ($result ne '') {
       $result = 
    '<table class="LC_pastsubmission"><tr>'.$result.
    '</tr></table>';
    }
     }      }
     return $result;      return $result;
 }  }
Line 74  sub end_essayresponse { Line 109  sub end_essayresponse {
     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;      my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
     my $part          = $Apache::inputtags::part;      my $part          = $Apache::inputtags::part;
     my $id            = $Apache::inputtags::response[-1];      my $id            = $Apache::inputtags::response[-1];
     my $increment     = 1;      my $increment     = &Apache::response::repetition();
     my $result;      my $result;
     if ( $target eq 'grade' ) {      if ( $target eq 'grade' ) {
  my $collaborators = $env{'form.HWCOL'.$part.'_'.$id};   my $collaborators = $env{'form.HWCOL'.$part.'_'.$id};
Line 95  sub end_essayresponse { Line 130  sub end_essayresponse {
     $award='SUBMITTED';      $award='SUBMITTED';
  }   }
                 my $uploadedflag=0;                  my $uploadedflag=0;
  &file_submission($part,$id,'filename',$award,\$uploadedflag);   &file_submission($part,$id,'filename',\$award,\$uploadedflag);
  &file_submission($part,$id,'portfiles',$award,\$uploadedflag);   &file_submission($part,$id,'portfiles',\$award,\$uploadedflag);
  $Apache::lonhomework::results{"resource.$part.$id.submission"}=$response;   $Apache::lonhomework::results{"resource.$part.$id.submission"}=$response;
  $Apache::lonhomework::results{"resource.$part.$id.awarddetail"}=$award;   $Apache::lonhomework::results{"resource.$part.$id.awarddetail"}=$award;
  my %previous=&Apache::response::check_for_previous($response,$part,$id);   my %previous=&Apache::response::check_for_previous($response,$part,$id);
Line 113  sub end_essayresponse { Line 148  sub end_essayresponse {
     &Apache::lonnet::declutter($ENV{'REQUEST_URI'});      &Apache::lonnet::declutter($ENV{'REQUEST_URI'});
  my ($adom,$aname,$apath)=   my ($adom,$aname,$apath)=
     ($essayurl=~/^(\w+)\/(\w+)\/(.*)$/);      ($essayurl=~/^(\w+)\/(\w+)\/(.*)$/);
                         $apath=&Apache::lonnet::escape($apath);                          $apath=&escape($apath);
  $apath=~s/\W/\_/gs;   $apath=~s/\W/\_/gs;
  &Apache::lonnet::put('nohist_essay_'.$apath,   &Apache::lonnet::put('nohist_essay_'.$apath,
  { $akey => $response },$adom,$aname);   { $akey => $response },$adom,$aname);
Line 123  sub end_essayresponse { Line 158  sub end_essayresponse {
  }    } 
     } elsif ($target eq 'edit') {      } elsif ($target eq 'edit') {
  $result.=&Apache::edit::end_table();   $result.=&Apache::edit::end_table();
     } elsif ($target eq 'tex') {  
  if ($Apache::lonhomework::type eq 'exam') {      } elsif ($target eq 'tex'
     my $repetition=&Apache::response::repetition();       && $Apache::lonhomework::type eq 'exam') {
     $result.='\begin{enumerate}';   $result .= &Apache::inputtags::exam_score_line($target);
     if ($env{'request.state'} eq "construct" ) {$result.='\item[\strut]';}  
     for (my $i=0;$i<$repetition;$i++) {      } elsif ($target eq 'answer') {
  $result.='\item[\textbf{'.($Apache::lonxml::counter+$i).   $result.=&Apache::response::answer_header($$tagstack[-1]);
     '}.]\textit{'.&mt('Leave blank on scoring form').   $result.=&Apache::response::answer_part($$tagstack[-1],'');
     '}\vskip 0 mm';   $result.=&Apache::response::answer_footer($$tagstack[-1]);
     }  
     $result.= '\end{enumerate}';  
     $increment=$repetition;  
  }  
     }      }
   
     if ($target eq 'grade' || $target eq 'web' || $target eq 'answer' ||      if ($target eq 'grade' || $target eq 'web' || $target eq 'answer' ||
  $target eq 'tex' || $target eq 'analyze') {   $target eq 'tex' || $target eq 'analyze') {
  &Apache::lonxml::increment_counter($increment);   &Apache::lonxml::increment_counter($increment);
Line 149  sub end_essayresponse { Line 181  sub end_essayresponse {
 sub file_submission {  sub file_submission {
     my ($part,$id,$which,$award,$uploadedflag)=@_;      my ($part,$id,$which,$award,$uploadedflag)=@_;
     my $files;      my $files;
     if ($which eq 'portfiles') { $files= $env{'form.HWPORT'.$part.'_'.$id}; }      my $jspart=$part;
       $jspart=~s/\./_/g;
       if ($which eq 'portfiles') { $files= $env{'form.HWPORT'.$jspart.'_'.$id}; }
     if ($which eq 'filename') {      if ($which eq 'filename') {
  $files = $env{'form.HWFILE'.$part.'_'.$id.'.filename'};   $files = $env{'form.HWFILE'.$jspart.'_'.$id.'.filename'};
     }      }
           
     if ($files =~ /[^\s]/) {      if ($files =~ /[^\s]/) {
  $files =~s/,$//;   $files =~s/,$//;
  $Apache::lonhomework::results{"resource.$part.$id.$which"}=$files;   $Apache::lonhomework::results{"resource.$part.$id.$which"}=$files;
  my @submitted_files = split(/,/,$files);  
    my @submitted_files = ($files);
    if ( $which eq 'portfiles' ) {
       @submitted_files = split(/\s*,\s*/,$files);
    }
   
  my $uploadedfiletypes= &Apache::lonnet::EXT("resource.$part".'_'."$id.uploadedfiletypes");   my $uploadedfiletypes= &Apache::lonnet::EXT("resource.$part".'_'."$id.uploadedfiletypes");
  $uploadedfiletypes=~s/[^\w\,]//g;   if ($uploadedfiletypes) {
  $uploadedfiletypes=','.$uploadedfiletypes.',';      $uploadedfiletypes=~s/[^\w\,]//g;
  foreach my $file (@submitted_files) {      $uploadedfiletypes=','.$uploadedfiletypes.',';
     my ($extension)=($file=~/\.(\w+)$/);      foreach my $file (@submitted_files) {
     unless ($uploadedfiletypes=~/\,$extension\,/i) {   my ($extension)=($file=~/\.(\w+)$/);
  $award='INVALID_FILETYPE';   unless ($uploadedfiletypes=~/\,$extension\,/i) {
       $$award='INVALID_FILETYPE';
    }
     }      }
  }   }
  if ($award ne 'INVALID_FILETYPE' && ref($uploadedflag)) {   if ($$award ne 'INVALID_FILETYPE' && ref($uploadedflag)) {
     $$uploadedflag=1;      $$uploadedflag=1;
  }   }
  if ($award ne 'INVALID_FILETYPE' && $which eq 'portfiles') {   if ($$award ne 'INVALID_FILETYPE' && $which eq 'portfiles') {
     my ($symb,$crsid,$domain,$name)=&Apache::lonxml::whichuser();      my ($symb,$crsid,$domain,$name)=&Apache::lonxml::whichuser();
     &Apache::lonnet::unmark_as_readonly($domain,$name,$symb.$crsid);      &Apache::lonnet::unmark_as_readonly($domain,$name,[$symb,$crsid]);
     &Apache::lonnet::mark_as_readonly($domain,$name,\@submitted_files,$symb.$crsid);      &Apache::lonnet::mark_as_readonly($domain,$name,\@submitted_files,[$symb,$crsid]);
     &Apache::lonnet::clear_selected_files($name);      &Apache::lonnet::clear_selected_files($name);
  }   }
  if ($award ne 'INVALID_FILETYPE' && $which eq 'filename') {   if ($$award ne 'INVALID_FILETYPE' && $which eq 'filename') {
     $Apache::lonhomework::results{"resource.$part.$id.uploadedfile"}=      $Apache::lonhomework::results{"resource.$part.$id.uploadedfile"}=
  $files;   $files;
     $Apache::lonhomework::results{"resource.$part.$id.uploadedurl"}=      $Apache::lonhomework::results{"resource.$part.$id.uploadedurl"}=
  &Apache::lonnet::userfileupload('HWFILE'.$part.'_'.$id,undef,   &Apache::lonnet::userfileupload('HWFILE'.$jspart.'_'.$id,undef,
  'essayresponse');   'essayresponse');
  }   }
     } elsif ($which eq 'portfiles' &&      } elsif ($which eq 'portfiles' &&
      $Apache::lonhomework::history{"resource.$part.$id.$which"}) {       $Apache::lonhomework::history{"resource.$part.$id.$which"}) {
  my ($symb,$crsid,$domain,$name)=&Apache::lonxml::whichuser();   my ($symb,$crsid,$domain,$name)=&Apache::lonxml::whichuser();
  &Apache::lonnet::unmark_as_readonly($domain,$name,$symb.$crsid);   &Apache::lonnet::unmark_as_readonly($domain,$name,[$symb,$crsid]);
  $Apache::lonhomework::results{"resource.$part.$id.$which"}="";   $Apache::lonhomework::results{"resource.$part.$id.$which"}="";
     }      }
 }  }

Removed from v.1.62  
changed lines
  Added in v.1.74


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