Diff for /loncom/homework/grades.pm between versions 1.755 and 1.765

version 1.755, 2019/01/27 23:16:25 version 1.765, 2020/05/06 15:01:15
Line 48  use Apache::lonquickgrades; Line 48  use Apache::lonquickgrades;
 use Apache::bridgetask();  use Apache::bridgetask();
 use Apache::lontexconvert();  use Apache::lontexconvert();
 use String::Similarity;  use String::Similarity;
   use HTML::Parser();
   use File::MMagic;
 use LONCAPA;  use LONCAPA;
   
 use POSIX qw(floor);  use POSIX qw(floor);
Line 653  sub canmodify { Line 655  sub canmodify {
  #can modify the requested section   #can modify the requested section
  return 1;   return 1;
     } else {      } else {
  # can't modify the request section   # can't modify the requested section
  return 0;   return 0;
     }      }
  }   }
Line 666  sub canview { Line 668  sub canview {
     my ($sec)=@_;      my ($sec)=@_;
     if ($perm{'vgr'}) {      if ($perm{'vgr'}) {
  if (!defined($perm{'vgr_section'})) {   if (!defined($perm{'vgr_section'})) {
     # can modify whole class      # can view whole class
     return 1;      return 1;
  } else {   } else {
     if ($sec eq $perm{'vgr_section'}) {      if ($sec eq $perm{'vgr_section'}) {
  #can modify the requested section   #can view the requested section
  return 1;   return 1;
     } else {      } else {
  # can't modify the request section   # can't view the requested section
  return 0;   return 0;
     }      }
  }   }
     }      }
     #can't modify      #can't view
     return 0;      return 0;
 }  }
   
Line 4923  LISTJAVASCRIPT Line 4925  LISTJAVASCRIPT
     my $cdom      = $env{"course.$env{'request.course.id'}.domain"};      my $cdom      = $env{"course.$env{'request.course.id'}.domain"};
     my $cnum      = $env{"course.$env{'request.course.id'}.num"};      my $cnum      = $env{"course.$env{'request.course.id'}.num"};
     my $getsec    = $env{'form.section'} eq '' ? 'all' : $env{'form.section'};      my $getsec    = $env{'form.section'} eq '' ? 'all' : $env{'form.section'};
       my $getgroup  = $env{'form.group'} eq '' ? 'all' : $env{'form.group'};
   
     my $result='<h3><span class="LC_info">&nbsp;'.      my $result='<h3><span class="LC_info">&nbsp;'.
  &mt('Manual Grading by Page or Sequence').'</span></h3>';   &mt('Manual Grading by Page or Sequence').'</span></h3>';
Line 5012  LISTJAVASCRIPT Line 5015  LISTJAVASCRIPT
  '<th>'.&nameUserString('header').'</th>'.   '<th>'.&nameUserString('header').'</th>'.
  &Apache::loncommon::end_data_table_header_row();   &Apache::loncommon::end_data_table_header_row();
     
     my (undef,undef,$fullname) = &getclasslist($getsec,'1');      my (undef,undef,$fullname) = &getclasslist($getsec,'1',$getgroup);
     my $ptr = 1;      my $ptr = 1;
     foreach my $student (sort       foreach my $student (sort 
  {   {
Line 5902  sub scantron_selectphase { Line 5905  sub scantron_selectphase {
   
         $r->print('          $r->print('
     <br />');      <br />');
     my $default_form_data=&defaultFormData($symb);  
     my $cdom= $env{'course.'.$env{'request.course.id'}.'.domain'};      my $cdom= $env{'course.'.$env{'request.course.id'}.'.domain'};
     my $cnum= $env{'course.'.$env{'request.course.id'}.'.num'};      my $cnum= $env{'course.'.$env{'request.course.id'}.'.num'};
     my $alertmsg = &mt('Please use the browse button to select a file from your local directory.');      my $alertmsg = &mt('Please use the browse button to select a file from your local directory.');
Line 5915  sub scantron_selectphase { Line 5917  sub scantron_selectphase {
     return false;      return false;
  }   }
  formname.submit();   formname.submit();
     }'.$formatjs));      }'."\n".$formatjs));
     $r->print('      $r->print('
               <form enctype="multipart/form-data" action="/adm/grades" name="rules" method="post">                <form enctype="multipart/form-data" action="/adm/grades" name="rules" method="post">
                 '.$default_form_data.'                  '.$default_form_data.'
Line 9099  END Line 9101  END
             if (keys(%{$domconfig{'scantron'}{'config'}}) > 1) {              if (keys(%{$domconfig{'scantron'}{'config'}}) > 1) {
                 if (($domconfig{'scantron'}{'config'}{'dat'}) &&                  if (($domconfig{'scantron'}{'config'}{'dat'}) &&
                     (ref($domconfig{'scantron'}{'config'}{'csv'}) eq 'HASH')) {                      (ref($domconfig{'scantron'}{'config'}{'csv'}) eq 'HASH')) {
                     if (keys(%{$domconfig{'scantron'}{'config'}{'csv'}})) {                      if (ref($domconfig{'scantron'}{'config'}{'csv'}{'fields'}) eq 'HASH') {  
                         my ($onclick,$formatextra,$singleline);                          if (keys(%{$domconfig{'scantron'}{'config'}{'csv'}{'fields'}})) {
                         my @lines = &Apache::lonnet::get_scantronformat_file();                              my ($onclick,$formatextra,$singleline);
                         my $count = 0;                              my @lines = &Apache::lonnet::get_scantronformat_file();
                         foreach my $line (@lines) {                              my $count = 0;
                             next if ($line =~ /^#/);                              foreach my $line (@lines) {
                             $singleline = $line;                                  next if ($line =~ /^#/);
                             $count ++;                                  $singleline = $line;
                         }                                  $count ++;
                         if ($count > 1) {                              }
                             $formatextra = '<div style="display:none" id="bubbletype">'.                              if ($count > 1) {
                                            &scantron_scantab().'</div>';                                  $formatextra = '<div style="display:none" id="bubbletype">'.
                             $onclick = ' onclick="toggleScantab(this.form);"';                                                 '<span class="LC_nobreak">'.
                             $formatjs = <<"END";                                                 &mt('Bubblesheet type:').'&nbsp;'.
                                                  &scantron_scantab().'</span></div>';
                                   $onclick = ' onclick="toggleScantab(this.form);"';
                                   $formatjs = <<"END";
 function toggleScantab(form) {  function toggleScantab(form) {
     var divid = 'bubbletype';      var divid = 'bubbletype';
     if (document.getElementById(divid)) {      if (document.getElementById(divid)) {
Line 9125  function toggleScantab(form) { Line 9130  function toggleScantab(form) {
                     if (chosen == 'dat') {                      if (chosen == 'dat') {
                         document.getElementById(divid).style.display = 'none';                          document.getElementById(divid).style.display = 'none';
                     } else if (chosen == 'csv') {                      } else if (chosen == 'csv') {
                         document.getElementById(divid).style.display = 'inline-block';                          document.getElementById(divid).style.display = 'block';
                     }                      }
                 }                  }
             }              }
Line 9135  function toggleScantab(form) { Line 9140  function toggleScantab(form) {
 }  }
   
 END  END
                         } elsif ($count == 1) {                              } elsif ($count == 1) {
                             my $formatname = (split(/:/,$singleline,2))[0];                                  my $formatname = (split(/:/,$singleline,2))[0];
                             $formatextra = '<input type="hidden" name="scantron_format" value="'.$formatname.'" />';                                  $formatextra = '<input type="hidden" name="scantron_format" value="'.$formatname.'" />';
                               }
                               $formattitle = &mt('File format');
                               $formatoptions = '<label><input name="fileformat" type="radio" value="dat" checked="checked"'.$onclick.' />'.
                                                &mt('Plain Text (no delimiters)').
                                                '</label>'.('&nbsp;'x2).
                                                '<label><input name="fileformat" type="radio" value="csv"'.$onclick.' />'.
                                                &mt('Comma separated values').'</label>'.$formatextra;
                         }                          }
                         $formattitle = &mt('File format');  
                         $formatoptions = '<label><input name="fileformat" type="radio" value="dat" checked="checked"'.$onclick.' />'.  
                                          &mt('Plain Text (no delimiters)').  
                                          '</label>'.('&nbsp;'x2).  
                                          '<label><input name="fileformat" type="radio" value="csv"'.$onclick.' />'.  
                                          &mt('Comma separated values').'</label>'.$formatextra;  
                     }                      }
                 }                  }
             } elsif (keys(%{$domconfig{'scantron'}{'config'}}) == 1) {              } elsif (keys(%{$domconfig{'scantron'}{'config'}}) == 1) {
                 if (keys(%{$domconfig{'scantron'}{'config'}{'csv'}})) {                  if (ref($domconfig{'scantron'}{'config'}{'csv'}{'fields'}) eq 'HASH') {
                     $formattitle = &mt('Format of bubblesheet data file:');                      if (keys(%{$domconfig{'scantron'}{'config'}{'csv'}{'fields'}})) {
                     $formatoptions = &scantron_scantab();                          $formattitle = &mt('Bubblesheet type');
                           $formatoptions = &scantron_scantab();
                       }
                 }                  }
             }              }
         }          }
Line 9192  sub scantron_upload_scantron_data_save { Line 9200  sub scantron_upload_scantron_data_save {
                 if (@possibles > 1) {                  if (@possibles > 1) {
                     if ($env{'form.fileformat'} eq 'csv') {                      if ($env{'form.fileformat'} eq 'csv') {
                         if (ref($domconfig{'scantron'}{'config'}{'csv'}) eq 'HASH') {                          if (ref($domconfig{'scantron'}{'config'}{'csv'}) eq 'HASH') {
                             if (keys(%{$domconfig{'scantron'}{'config'}{'csv'}}) > 1) {                              if (ref($domconfig{'scantron'}{'config'}{'csv'}{'fields'}) eq 'HASH') {
                                 $is_csv = 1;                                  if (keys(%{$domconfig{'scantron'}{'config'}{'csv'}{'fields'}}) > 1) {
                                       $is_csv = 1;
                                   }
                             }                              }
                         }                          }
                     }                      }
                 } elsif (@possibles == 1) {                  } elsif (@possibles == 1) {
                     if (ref($domconfig{'scantron'}{'config'}{'csv'}) eq 'HASH') {                      if (ref($domconfig{'scantron'}{'config'}{'csv'}) eq 'HASH') {
                         if (keys(%{$domconfig{'scantron'}{'config'}{'csv'}}) > 1) {                          if (ref($domconfig{'scantron'}{'config'}{'csv'}{'fields'}) eq 'HASH') {
                             $is_csv = 1;                              if (keys(%{$domconfig{'scantron'}{'config'}{'csv'}{'fields'}}) > 1) {
                                   $is_csv = 1;
                               }
                         }                          }
                     }                      }
                 }                  }
Line 9782  sub grading_menu { Line 9794  sub grading_menu {
                     icon => 'grade_students.png',                      icon => 'grade_students.png',
                     linktitle => 'Grade current resource for a selection of students.'                      linktitle => 'Grade current resource for a selection of students.'
                         },                           }, 
                         {       linktext => 'Grade ungraded submissions.',                          {       linktext => 'Grade ungraded submissions',
                                 url => $url1b,                                  url => $url1b,
                                 permission => 'F',                                  permission => 'F',
                                 icon => 'ungrade_sub.png',                                  icon => 'ungrade_sub.png',
Line 10286  sub process_clicker_file { Line 10298  sub process_clicker_file {
                         '<span class="LC_filename">'.&HTML::Entities::encode($env{'form.upfile.filename'},'<>&"').'</span>'),1);                          '<span class="LC_filename">'.&HTML::Entities::encode($env{'form.upfile.filename'},'<>&"').'</span>'),1);
         return $result;          return $result;
     }      }
       my $mimetype;
       if ($env{'form.upfiletype'} eq 'iclicker') {
           my $mm = new File::MMagic;
           $mimetype = $mm->checktype_contents($env{'form.upfile'});
           unless (($mimetype eq 'text/plain') || ($mimetype eq 'text/html')) {
               $result.= '<p>'.
                   &Apache::lonhtmlcommon::confirm_success(
                       &mt('File format is neither csv (iclicker 6) nor xml (iclicker 7)'),1).'</p>';
               return $result;
           }
       } elsif (($env{'form.upfiletype'} ne 'interwrite') && ($env{'form.upfiletype'} ne 'turning')) {
           $result .= '<p>'.
               &Apache::lonhtmlcommon::confirm_success(
                   &mt('Invalid clicker type: choose one of: i>clicker, Interwrite PRS, or Turning Technologies.'),1).'</p>';
           return $result;
       }
   
 # Were able to get all the info needed, now analyze the file  # Were able to get all the info needed, now analyze the file
   
Line 10312  ENDHEADER Line 10340  ENDHEADER
     my $errormsg='';      my $errormsg='';
     my $number=0;      my $number=0;
     if ($env{'form.upfiletype'} eq 'iclicker') {      if ($env{'form.upfiletype'} eq 'iclicker') {
  ($errormsg,$number)=&iclicker_eval(\@questiontitles,\%responses);          if ($mimetype eq 'text/plain') {
     }              ($errormsg,$number)=&iclicker_eval(\@questiontitles,\%responses);
     if ($env{'form.upfiletype'} eq 'interwrite') {          } elsif ($mimetype eq 'text/html') {
               ($errormsg,$number)=&iclickerxml_eval(\@questiontitles,\%responses);
           }
       } elsif ($env{'form.upfiletype'} eq 'interwrite') {
         ($errormsg,$number)=&interwrite_eval(\@questiontitles,\%responses);          ($errormsg,$number)=&interwrite_eval(\@questiontitles,\%responses);
     }      } elsif ($env{'form.upfiletype'} eq 'turning') {
     if ($env{'form.upfiletype'} eq 'turning') {  
         ($errormsg,$number)=&turning_eval(\@questiontitles,\%responses);          ($errormsg,$number)=&turning_eval(\@questiontitles,\%responses);
     }      }
     $result.='<br />'.&mt('Found [_1] question(s)',$number).'<br />'.      $result.='<br />'.&mt('Found [_1] question(s)',$number).'<br />'.
Line 10370  ENDHEADER Line 10400  ENDHEADER
                    "\n".&mt("Username").": <input type='text' name='uname".$id."' />&nbsp;".                     "\n".&mt("Username").": <input type='text' name='uname".$id."' />&nbsp;".
                    "\n".&mt("Domain").": ".                     "\n".&mt("Domain").": ".
                    &Apache::loncommon::select_dom_form($env{'course.'.$env{'request.course.id'}.'.domain'},'udom'.$id).'&nbsp;'.                     &Apache::loncommon::select_dom_form($env{'course.'.$env{'request.course.id'}.'.domain'},'udom'.$id).'&nbsp;'.
                    &Apache::loncommon::selectstudent_link('clickeranalysis','uname'.$id,'udom'.$id,0,$id);                     &Apache::loncommon::selectstudent_link('clickeranalysis','uname'.$id,'udom'.$id,'',$id);
           $unknown_count++;            $unknown_count++;
        }         }
     }      }
Line 10425  sub iclicker_eval { Line 10455  sub iclicker_eval {
     return ($errormsg,$number);      return ($errormsg,$number);
 }  }
   
   sub iclickerxml_eval {
       my ($questiontitles,$responses)=@_;
       my $number=0;
       my $errormsg='';
       my @state;
       my %respbyid;
       my $p = HTML::Parser->new
       (
           xml_mode => 1,
           start_h =>
               [sub {
                    my ($tagname,$attr) = @_;
                    push(@state,$tagname);
                    if ("@state" eq "ssn p") {
                        my $title = $attr->{qn};
                        $title =~ s/(^\s+|\s+$)//g;
                        $questiontitles->[$number]=$title;
                    } elsif ("@state" eq "ssn p v") {
                        my $id = $attr->{id};
                        my $entry = $attr->{ans};
                        $id=~s/^[\#0]+//;
                        $entry =~s/[^a-zA-Z0-9\.\*\-\+]+//g;
                        $respbyid{$id}[$number] = $entry;
                    }
               }, "tagname, attr"],
            end_h =>
                  [sub {
                      my ($tagname) = @_;
                      if ("@state" eq "ssn p") {
                          $number++;
                      }
                      pop(@state);
                   }, "tagname"],
       );
   
       $p->parse($env{'form.upfile'});
       $p->eof;
       foreach my $id (keys(%respbyid)) {
           $responses->{$id}=join(',',@{$respbyid{$id}});
       }
       return ($errormsg,$number);
   }
   
 sub interwrite_eval {  sub interwrite_eval {
     my ($questiontitles,$responses)=@_;      my ($questiontitles,$responses)=@_;
     my $number=0;      my $number=0;
Line 10629  sub startpage { Line 10702  sub startpage {
     }      }
     if ($nomenu) {      if ($nomenu) {
         $args{'only_body'} = 1;           $args{'only_body'} = 1; 
         $r->print(&Apache::loncommon::start_page("Student's Version",$js,\%args);          $r->print(&Apache::loncommon::start_page("Student's Version",$js,\%args));
     } else {      } else {
         unshift(@$crumbs,{href=>&href_symb_cmd($symb,'gradingmenu'),text=>"Grading"});          unshift(@$crumbs,{href=>&href_symb_cmd($symb,'gradingmenu'),text=>"Grading"});
         $args{'bread_crumbs'} = $crumbs;          $args{'bread_crumbs'} = $crumbs;
         $r->print(&Apache::loncommon::start_page('Grading',$js,\%args));          $r->print(&Apache::loncommon::start_page('Grading',$js,\%args));
         &Apache::lonquickgrades::startGradeScreen($r,($env{'form.symb'}?'probgrading':'grading'));          if ($env{'request.course.id'}) {
               &Apache::lonquickgrades::startGradeScreen($r,($env{'form.symb'}?'probgrading':'grading'));
           }
     }      }
     unless ($nodisplayflag) {      unless ($nodisplayflag) {
        $r->print(&Apache::lonhtmlcommon::resource_info_box($symb,$onlyfolderflag,$stuvcurrent,$stuvdisp));          $r->print(&Apache::lonhtmlcommon::resource_info_box($symb,$onlyfolderflag,$stuvcurrent,$stuvdisp));
     }      }
 }  }
   
Line 10865  sub handler { Line 10940  sub handler {
     }      }
     if ($env{'form.inhibitmenu'}) {      if ($env{'form.inhibitmenu'}) {
         $request->print(&Apache::loncommon::end_page());          $request->print(&Apache::loncommon::end_page());
     } else {      } elsif ($env{'request.course.id'}) {
         &Apache::lonquickgrades::endGradeScreen($request);          &Apache::lonquickgrades::endGradeScreen($request);
     }      }
     &reset_caches();      &reset_caches();
Line 11016  Side Effects: None. Line 11091  Side Effects: None.
     $r           - Apache request object      $r           - Apache request object
     $i           - number of the current scanline      $i           - number of the current scanline
     $scan_record - hash ref as returned from &scantron_parse_scanline()      $scan_record - hash ref as returned from &scantron_parse_scanline()
     $scan_config - hash ref as returned from &get_scantron_config()      $scan_config - hash ref as returned from &Apache::lonnet::get_scantron_config()
     $line        - full contents of the current scanline      $line        - full contents of the current scanline
     $error       - error condition, valid values are      $error       - error condition, valid values are
                    'incorrectCODE', 'duplicateCODE',                     'incorrectCODE', 'duplicateCODE',

Removed from v.1.755  
changed lines
  Added in v.1.765


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