Diff for /loncom/homework/grades.pm between versions 1.596.2.12.2.41.2.6 and 1.596.2.12.2.42

version 1.596.2.12.2.41.2.6, 2019/02/23 17:34:59 version 1.596.2.12.2.42, 2018/04/29 15:05:25
Line 44  use Apache::Constants qw(:common :http); Line 44  use Apache::Constants qw(:common :http);
 use Apache::lonlocal;  use Apache::lonlocal;
 use Apache::lonenc;  use Apache::lonenc;
 use Apache::bridgetask();  use Apache::bridgetask();
 use HTML::Parser();  
 use File::MMagic;  
 use String::Similarity;  use String::Similarity;
 use LONCAPA;  use LONCAPA;
   
Line 4216  sub editgrades { Line 4214  sub editgrades {
  my ($uname,$udom)=split(/:/,$user);   my ($uname,$udom)=split(/:/,$user);
  my %newrecord;   my %newrecord;
  my $updateflag = 0;   my $updateflag = 0;
  my $usec=$classlist->{"$uname:$udom"}[5];          my $usec=$classlist->{"$uname:$udom"}[5];
         my $canmodify = &canmodify($usec);          my $canmodify = &canmodify($usec);
         my $line = '<td'.($canmodify?'':' colspan="2"').'>'.          my $line = '<td'.($canmodify?'':' colspan="2"').'>'.
                    &nameUserString(undef,$$fullname{$user},$uname,$udom).'</td>';                     &nameUserString(undef,$$fullname{$user},$uname,$udom).'</td>';
Line 4608  sub csvuploadmap { Line 4606  sub csvuploadmap {
     if (!$env{'form.datatoken'}) {      if (!$env{'form.datatoken'}) {
  $datatoken=&Apache::loncommon::upfile_store($request);   $datatoken=&Apache::loncommon::upfile_store($request);
     } else {      } else {
         $datatoken=&Apache::loncommon::valid_datatoken($env{'form.datatoken'});   $datatoken=$env{'form.datatoken'};
         if ($datatoken ne '') {   &Apache::loncommon::load_tmp_file($request);
             &Apache::loncommon::load_tmp_file($request,$datatoken);  
         }  
     }      }
     my @records=&Apache::loncommon::upfile_record_sep();      my @records=&Apache::loncommon::upfile_record_sep();
     if ($env{'form.noFirstLine'}) { shift(@records); }      if ($env{'form.noFirstLine'}) { shift(@records); }
Line 4715  sub csvuploadassign { Line 4711  sub csvuploadassign {
     my ($symb)=&get_symb($request);      my ($symb)=&get_symb($request);
     if (!$symb) {return '';}      if (!$symb) {return '';}
     my $error_msg = '';      my $error_msg = '';
     my $datatoken = &Apache::loncommon::valid_datatoken($env{'form.datatoken'});      &Apache::loncommon::load_tmp_file($request);
     if ($datatoken ne '') {  
         &Apache::loncommon::load_tmp_file($request,$datatoken);  
     }  
     my @gradedata = &Apache::loncommon::upfile_record_sep();      my @gradedata = &Apache::loncommon::upfile_record_sep();
     if ($env{'form.noFirstLine'}) { shift(@gradedata); }      if ($env{'form.noFirstLine'}) { shift(@gradedata); }
     my %fields=&get_fields();      my %fields=&get_fields();
Line 5718  sub scantron_uploads { Line 5711  sub scantron_uploads {
 sub scantron_scantab {  sub scantron_scantab {
     my $result='<select name="scantron_format">'."\n";      my $result='<select name="scantron_format">'."\n";
     $result.='<option></option>'."\n";      $result.='<option></option>'."\n";
     my @lines = &Apache::lonnet::get_scantronformat_file();      my @lines = &get_scantronformat_file();
     if (@lines > 0) {      if (@lines > 0) {
         foreach my $line (@lines) {          foreach my $line (@lines) {
             next if (($line =~ /^\#/) || ($line eq ''));              next if (($line =~ /^\#/) || ($line eq ''));
Line 5730  sub scantron_scantab { Line 5723  sub scantron_scantab {
     return $result;      return $result;
 }  }
   
   =pod
   
   =item get_scantronformat_file
   
     Returns an array containing lines from the scantron format file for
     the domain of the course.
   
     If a url for a custom.tab file is listed in domain's configuration.db, 
     lines are from this file.
   
     Otherwise, if a default.tab has been published in RES space by the 
     domainconfig user, lines are from this file.
   
     Otherwise, fall back to getting lines from the legacy file on the
     local server:  /home/httpd/lonTabs/default_scantronformat.tab    
   
   =cut
   
   sub get_scantronformat_file {
       my $cdom= $env{'course.'.$env{'request.course.id'}.'.domain'};
       my %domconfig = &Apache::lonnet::get_dom('configuration',['scantron'],$cdom);
       my $gottab = 0;
       my @lines;
       if (ref($domconfig{'scantron'}) eq 'HASH') {
           if ($domconfig{'scantron'}{'scantronformat'} ne '') {
               my $formatfile = &Apache::lonnet::getfile($Apache::lonnet::perlvar{'lonDocRoot'}.$domconfig{'scantron'}{'scantronformat'});
               if ($formatfile ne '-1') {
                   @lines = split("\n",$formatfile,-1);
                   $gottab = 1;
               }
           }
       }
       if (!$gottab) {
           my $confname = $cdom.'-domainconfig';
           my $default = $Apache::lonnet::perlvar{'lonDocRoot'}.'/res/'.$cdom.'/'.$confname.'/default.tab';
           my $formatfile =  &Apache::lonnet::getfile($default);
           if ($formatfile ne '-1') {
               @lines = split("\n",$formatfile,-1);
               $gottab = 1;
           }
       }
       if (!$gottab) {
           my @domains = &Apache::lonnet::current_machine_domains();
           if (grep(/^\Q$cdom\E$/,@domains)) {
               my $fh=Apache::File->new($Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab');
               @lines = <$fh>;
               close($fh);
           } else {
               my $fh=Apache::File->new($Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab');
               @lines = <$fh>;
               close($fh);
           }
       }
       return @lines;
   }
   
 =pod   =pod 
   
 =item scantron_CODElist  =item scantron_CODElist
Line 5816  sub scantron_selectphase { Line 5865  sub scantron_selectphase {
         # Chunk of form to prompt for a scantron file upload.          # Chunk of form to prompt for a scantron file upload.
   
         $r->print('          $r->print('
     <br />');      <br />
       '.&Apache::loncommon::start_data_table('LC_scantron_action').'
          '.&Apache::loncommon::start_data_table_header_row().'
               <th>
                 &nbsp;'.&mt('Specify a bubblesheet data file to upload.').'
               </th>
          '.&Apache::loncommon::end_data_table_header_row().'
          '.&Apache::loncommon::start_data_table_row().'
               <td>
   ');
       my $default_form_data=&defaultFormData(&get_symb($r,1));
     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.');
     &js_escape(\$alertmsg);      &js_escape(\$alertmsg);
     my ($formatoptions,$formattitle,$formatjs) = &scantron_upload_dataformat($cdom);      $r->print('
     $r->print(&Apache::lonhtmlcommon::scripttag('                <script type="text/javascript" language="javascript">
     function checkUpload(formname) {      function checkUpload(formname) {
         if (formname.upfile.value == "") {          if (formname.upfile.value == "") {
             alert("'.$alertmsg.'");              alert("'.$alertmsg.'");
             return false;              return false;
         }          }
         formname.submit();          formname.submit();
     }'."\n".$formatjs));      }
     $r->print('                </script>
   
               <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.'
                 <input name="courseid" type="hidden" value="'.$cnum.'" />                  <input name="courseid" type="hidden" value="'.$cnum.'" />
                 <input name="domainid" type="hidden" value="'.$cdom.'" />                  <input name="domainid" type="hidden" value="'.$cdom.'" />
                 <input name="command" value="scantronupload_save" type="hidden" />                  <input name="command" value="scantronupload_save" type="hidden" />
               '.&Apache::loncommon::start_data_table('LC_scantron_action').'                  '.&mt('File to upload: [_1]','<input type="file" name="upfile" size="50" />').'
               '.&Apache::loncommon::start_data_table_header_row().'                  <br />
                 <th>                  <input type="button" onclick="javascript:checkUpload(this.form);" value="'.&mt('Upload Bubblesheet Data').'" />
                 &nbsp;'.&mt('Specify a bubblesheet data file to upload.').'                </form>
                 </th>  ');
               '.&Apache::loncommon::end_data_table_header_row().'  
               '.&Apache::loncommon::start_data_table_row().'  
             <td>  
                 '.&mt('File to upload: [_1]','<input type="file" name="upfile" size="50" />').'<br />'."\n");  
     if ($formatoptions) {  
         $r->print('</td>  
                  '.&Apache::loncommon::end_data_table_row().'  
                  '.&Apache::loncommon::start_data_table_row().'  
                  <td>'.$formattitle.('&nbsp;'x2).$formatoptions.'  
                  </td>  
                  '.&Apache::loncommon::end_data_table_row().'  
                  '.&Apache::loncommon::start_data_table_row().'  
                  <td>'  
         );  
     } else {  
         $r->print(' <br />');  
     }  
     $r->print('<input type="button" onclick="javascript:checkUpload(this.form);" value="'.&mt('Upload Bubblesheet Data').'" />  
               </td>  
              '.&Apache::loncommon::end_data_table_row().'  
              '.&Apache::loncommon::end_data_table().'  
              </form>'  
     );  
   
           $r->print('
               </td>
          '.&Apache::loncommon::end_data_table_row().'
          '.&Apache::loncommon::end_data_table().'
   ');
     }      }
   
     # Chunk of form to prompt for a file to grade and how:      # Chunk of form to prompt for a file to grade and how:
Line 5976  sub scantron_selectphase { Line 6018  sub scantron_selectphase {
     return;      return;
 }  }
   
   =pod
   
   =item get_scantron_config
   
      Parse and return the scantron configuration line selected as a
      hash of configuration file fields.
   
    Arguments:
       which - the name of the configuration to parse from the file.
   
   
    Returns:
               If the named configuration is not in the file, an empty
               hash is returned.
       a hash with the fields
         name         - internal name for the this configuration setup
         description  - text to display to operator that describes this config
         CODElocation - if 0 or the string 'none'
                             - no CODE exists for this config
                        if -1 || the string 'letter'
                             - a CODE exists for this config and is
                               a string of letters
                        Unsupported value (but planned for future support)
                             if a positive integer
                                  - The CODE exists as the first n items from
                                    the question section of the form
                             if the string 'number'
                                  - The CODE exists for this config and is
                                    a string of numbers
         CODEstart   - (only matter if a CODE exists) column in the line where
                        the CODE starts
         CODElength  - length of the CODE
         IDstart     - column where the student/employee ID starts
         IDlength    - length of the student/employee ID info
         Qstart      - column where the information from the bubbled
                       'questions' start
         Qlength     - number of columns comprising a single bubble line from
                       the sheet. (usually either 1 or 10)
         Qon         - either a single character representing the character used
                       to signal a bubble was chosen in the positional setup, or
                       the string 'letter' if the letter of the chosen bubble is
                       in the final, or 'number' if a number representing the
                       chosen bubble is in the file (1->A 0->J)
         Qoff        - the character used to represent that a bubble was
                       left blank
         PaperID     - if the scanning process generates a unique number for each
                       sheet scanned the column that this ID number starts in
         PaperIDlength - number of columns that comprise the unique ID number
                         for the sheet of paper
         FirstName   - column that the first name starts in
         FirstNameLength - number of columns that the first name spans
    
         LastName    - column that the last name starts in
         LastNameLength - number of columns that the last name spans
         BubblesPerRow - number of bubbles available in each row used to
                         bubble an answer. (If not specified, 10 assumed).
   
   =cut
   
   sub get_scantron_config {
       my ($which) = @_;
       my @lines = &get_scantronformat_file();
       my %config;
       #FIXME probably should move to XML it has already gotten a bit much now
       foreach my $line (@lines) {
    my ($name,$descrip)=split(/:/,$line);
    if ($name ne $which ) { next; }
    chomp($line);
    my @config=split(/:/,$line);
    $config{'name'}=$config[0];
    $config{'description'}=$config[1];
    $config{'CODElocation'}=$config[2];
    $config{'CODEstart'}=$config[3];
    $config{'CODElength'}=$config[4];
    $config{'IDstart'}=$config[5];
    $config{'IDlength'}=$config[6];
    $config{'Qstart'}=$config[7];
     $config{'Qlength'}=$config[8];
    $config{'Qoff'}=$config[9];
    $config{'Qon'}=$config[10];
    $config{'PaperID'}=$config[11];
    $config{'PaperIDlength'}=$config[12];
    $config{'FirstName'}=$config[13];
    $config{'FirstNamelength'}=$config[14];
    $config{'LastName'}=$config[15];
    $config{'LastNamelength'}=$config[16];
           $config{'BubblesPerRow'}=$config[17];
    last;
       }
       return %config;
   }
   
 =pod   =pod 
   
 =item username_to_idmap  =item username_to_idmap
Line 6021  sub username_to_idmap { Line 6155  sub username_to_idmap {
    Process a requested correction to a scanline.     Process a requested correction to a scanline.
   
   Arguments:    Arguments:
     $scantron_config   - hash from &Apache::lonnet::get_scantron_config()      $scantron_config   - hash from &get_scantron_config()
     $scan_data         - hash of correction information       $scan_data         - hash of correction information 
                           (see &scantron_getfile())                            (see &scantron_getfile())
     $line              - existing scanline      $line              - existing scanline
Line 6704  sub scantron_filter { Line 6838  sub scantron_filter {
   
 sub scantron_process_corrections {  sub scantron_process_corrections {
     my ($r) = @_;      my ($r) = @_;
     my %scantron_config=&Apache::lonnet::get_scantron_config($env{'form.scantron_format'});      my %scantron_config=&get_scantron_config($env{'form.scantron_format'});
     my ($scanlines,$scan_data)=&scantron_getfile();      my ($scanlines,$scan_data)=&scantron_getfile();
     my $classlist=&Apache::loncoursedata::get_classlist();      my $classlist=&Apache::loncoursedata::get_classlist();
     my $which=$env{'form.scantron_line'};      my $which=$env{'form.scantron_line'};
Line 6873  sub check_for_error { Line 7007  sub check_for_error {
 sub scantron_warning_screen {  sub scantron_warning_screen {
     my ($button_text)=@_;      my ($button_text)=@_;
     my $title=&Apache::lonnet::gettitle($env{'form.selectpage'});      my $title=&Apache::lonnet::gettitle($env{'form.selectpage'});
     my %scantron_config=&Apache::lonnet::get_scantron_config($env{'form.scantron_format'});      my %scantron_config=&get_scantron_config($env{'form.scantron_format'});
     my $CODElist;      my $CODElist;
     if ($scantron_config{'CODElocation'} &&      if ($scantron_config{'CODElocation'} &&
  $scantron_config{'CODEstart'} &&   $scantron_config{'CODEstart'} &&
Line 7032  sub scantron_validate_file { Line 7166  sub scantron_validate_file {
     #get the student pick code ready      #get the student pick code ready
     $r->print(&Apache::loncommon::studentbrowser_javascript());      $r->print(&Apache::loncommon::studentbrowser_javascript());
     my $nav_error;      my $nav_error;
     my %scantron_config=&Apache::lonnet::get_scantron_config($env{'form.scantron_format'});      my %scantron_config=&get_scantron_config($env{'form.scantron_format'});
     my $max_bubble=&scantron_get_maxbubble(\$nav_error,\%scantron_config);      my $max_bubble=&scantron_get_maxbubble(\$nav_error,\%scantron_config);
     if ($nav_error) {      if ($nav_error) {
         $r->print(&navmap_errormsg());          $r->print(&navmap_errormsg());
Line 7491  sub scantron_validate_ID { Line 7625  sub scantron_validate_ID {
     my %idmap=&username_to_idmap($classlist);      my %idmap=&username_to_idmap($classlist);
   
     #get scantron line setup      #get scantron line setup
     my %scantron_config=&Apache::lonnet::get_scantron_config($env{'form.scantron_format'});      my %scantron_config=&get_scantron_config($env{'form.scantron_format'});
     my ($scanlines,$scan_data)=&scantron_getfile();      my ($scanlines,$scan_data)=&scantron_getfile();
   
     my $nav_error;      my $nav_error;
Line 7955  sub prompt_for_corrections { Line 8089  sub prompt_for_corrections {
   
  Arguments:   Arguments:
     $r           - Apache request object      $r           - Apache request object
     $scan_config - hash from &Apache::lonnet::get_scantron_config()      $scan_config - hash from &get_scantron_config()
     $line        - Number of the line being displayed.      $line        - Number of the line being displayed.
     $questionnum - Question number (may include subquestion)      $questionnum - Question number (may include subquestion)
     $error       - Type of error.      $error       - Type of error.
Line 8119  sub get_codes { Line 8253  sub get_codes {
   
 sub scantron_validate_CODE {  sub scantron_validate_CODE {
     my ($r,$currentphase) = @_;      my ($r,$currentphase) = @_;
     my %scantron_config=&Apache::lonnet::get_scantron_config($env{'form.scantron_format'});      my %scantron_config=&get_scantron_config($env{'form.scantron_format'});
     if ($scantron_config{'CODElocation'} &&      if ($scantron_config{'CODElocation'} &&
  $scantron_config{'CODEstart'} &&   $scantron_config{'CODEstart'} &&
  $scantron_config{'CODElength'}) {   $scantron_config{'CODElength'}) {
Line 8193  sub scantron_validate_doublebubble { Line 8327  sub scantron_validate_doublebubble {
         &Apache::lonnet::decode_symb($env{'form.selectpage'});          &Apache::lonnet::decode_symb($env{'form.selectpage'});
   
     #get scantron line setup      #get scantron line setup
     my %scantron_config=&Apache::lonnet::get_scantron_config($env{'form.scantron_format'});      my %scantron_config=&get_scantron_config($env{'form.scantron_format'});
     my ($scanlines,$scan_data)=&scantron_getfile();      my ($scanlines,$scan_data)=&scantron_getfile();
   
     my $navmap = Apache::lonnavmaps::navmap->new();      my $navmap = Apache::lonnavmaps::navmap->new();
Line 8375  sub scantron_validate_missingbubbles { Line 8509  sub scantron_validate_missingbubbles {
         &Apache::lonnet::decode_symb($env{'form.selectpage'});          &Apache::lonnet::decode_symb($env{'form.selectpage'});
   
     #get scantron line setup      #get scantron line setup
     my %scantron_config=&Apache::lonnet::get_scantron_config($env{'form.scantron_format'});      my %scantron_config=&get_scantron_config($env{'form.scantron_format'});
     my ($scanlines,$scan_data)=&scantron_getfile();      my ($scanlines,$scan_data)=&scantron_getfile();
   
     my $navmap = Apache::lonnavmaps::navmap->new();      my $navmap = Apache::lonnavmaps::navmap->new();
Line 8504  sub hand_bubble_option { Line 8638  sub hand_bubble_option {
         }          }
     }      }
     if ($needs_hand_bubbles) {      if ($needs_hand_bubbles) {
         my %scantron_config=&Apache::lonnet::get_scantron_config($env{'form.scantron_format'});          my %scantron_config=&get_scantron_config($env{'form.scantron_format'});
         my $bubbles_per_row = &bubblesheet_bubbles_per_row(\%scantron_config);          my $bubbles_per_row = &bubblesheet_bubbles_per_row(\%scantron_config);
         return &mt('The sequence to be graded contains response types which are handgraded.').'<p>'.          return &mt('The sequence to be graded contains response types which are handgraded.').'<p>'.
                &mt('If you have already graded these by bubbling sheets to indicate points awarded, [_1]what point value is assigned to a filled last bubble in each row?','<br />').                 &mt('If you have already graded these by bubbling sheets to indicate points awarded, [_1]what point value is assigned to a filled last bubble in each row?','<br />').
Line 8524  sub scantron_process_students { Line 8658  sub scantron_process_students {
     }      }
     my $default_form_data=&defaultFormData($symb);      my $default_form_data=&defaultFormData($symb);
   
     my %scantron_config=&Apache::lonnet::get_scantron_config($env{'form.scantron_format'});      my %scantron_config=&get_scantron_config($env{'form.scantron_format'});
     my $bubbles_per_row = &bubblesheet_bubbles_per_row(\%scantron_config);      my $bubbles_per_row = &bubblesheet_bubbles_per_row(\%scantron_config);
     my ($scanlines,$scan_data)=&scantron_getfile();      my ($scanlines,$scan_data)=&scantron_getfile();
     my $classlist=&Apache::loncoursedata::get_classlist();      my $classlist=&Apache::loncoursedata::get_classlist();
Line 8594  SCANTRONFORM Line 8728  SCANTRONFORM
  return ''; # Dunno why the other returns return '' rather than just returning.   return ''; # Dunno why the other returns return '' rather than just returning.
     }      }
   
     my %lettdig = &Apache::lonnet::letter_to_digits();      my %lettdig = &letter_to_digits();
     my $numletts = scalar(keys(%lettdig));      my $numletts = scalar(keys(%lettdig));
     my %orderedforcode;      my %orderedforcode;
   
Line 8925  sub grade_student_bubbles { Line 9059  sub grade_student_bubbles {
 sub scantron_upload_scantron_data {  sub scantron_upload_scantron_data {
     my ($r)=@_;      my ($r)=@_;
     my $dom = $env{'request.role.domain'};      my $dom = $env{'request.role.domain'};
     my ($formatoptions,$formattitle,$formatjs) = &scantron_upload_dataformat($dom);  
     my $domdesc = &Apache::lonnet::domain($dom,'description');      my $domdesc = &Apache::lonnet::domain($dom,'description');
     $r->print(&Apache::loncommon::coursebrowser_javascript($dom));      $r->print(&Apache::loncommon::coursebrowser_javascript($dom));
     my $select_link=&Apache::loncommon::selectcourse_link('rules','courseid',      my $select_link=&Apache::loncommon::selectcourse_link('rules','courseid',
Line 8939  sub scantron_upload_scantron_data { Line 9072  sub scantron_upload_scantron_data {
     &js_escape(\$nofile_alert);      &js_escape(\$nofile_alert);
     my $nocourseid_alert = &mt("Please use the 'Select Course' link to open a separate window where you can search for a course to which a file can be uploaded.");      my $nocourseid_alert = &mt("Please use the 'Select Course' link to open a separate window where you can search for a course to which a file can be uploaded.");
     &js_escape(\$nocourseid_alert);      &js_escape(\$nocourseid_alert);
     $r->print(&Apache::lonhtmlcommon::scripttag('      $r->print('
   <script type="text/javascript" language="javascript">
     function checkUpload(formname) {      function checkUpload(formname) {
  if (formname.upfile.value == "") {   if (formname.upfile.value == "") {
     alert("'.$nofile_alert.'");      alert("'.$nofile_alert.'");
Line 8966  sub scantron_upload_scantron_data { Line 9100  sub scantron_upload_scantron_data {
         return;          return;
     }      }
   
     '.$formatjs.'  </script>
 '));  
     $r->print('  
 <h3>'.&mt('Send bubblesheet data to a course').'</h3>  <h3>'.&mt('Send bubblesheet data to a course').'</h3>
   
 <form enctype="multipart/form-data" action="/adm/grades" name="rules" method="post">  <form enctype="multipart/form-data" action="/adm/grades" name="rules" method="post">
Line 8982  sub scantron_upload_scantron_data { Line 9115  sub scantron_upload_scantron_data {
   &Apache::lonhtmlcommon::row_closure().    &Apache::lonhtmlcommon::row_closure().
   &Apache::lonhtmlcommon::row_title(&mt('Domain')).    &Apache::lonhtmlcommon::row_title(&mt('Domain')).
   '<input name="domainid" type="hidden" />'.$domdesc.    '<input name="domainid" type="hidden" />'.$domdesc.
   &Apache::lonhtmlcommon::row_closure());    &Apache::lonhtmlcommon::row_closure().
     if ($formatoptions) {  
         $r->print(&Apache::lonhtmlcommon::row_title($formattitle).$formatoptions.  
                   &Apache::lonhtmlcommon::row_closure());  
     }  
     $r->print(  
   &Apache::lonhtmlcommon::row_title(&mt('File to upload')).    &Apache::lonhtmlcommon::row_title(&mt('File to upload')).
   '<input type="file" name="upfile" size="50" />'.    '<input type="file" name="upfile" size="50" />'.
   &Apache::lonhtmlcommon::row_closure(1).    &Apache::lonhtmlcommon::row_closure(1).
Line 9000  sub scantron_upload_scantron_data { Line 9128  sub scantron_upload_scantron_data {
     return '';      return '';
 }  }
   
 sub scantron_upload_dataformat {  
     my ($dom) = @_;  
     my ($formatoptions,$formattitle,$formatjs);  
     $formatjs = <<'END';  
 function toggleScantab(form) {  
    return;  
 }  
 END  
     my %domconfig = &Apache::lonnet::get_dom('configuration',['scantron'],$dom);  
     if (ref($domconfig{'scantron'}) eq 'HASH') {  
         if (ref($domconfig{'scantron'}{'config'}) eq 'HASH') {  
             if (keys(%{$domconfig{'scantron'}{'config'}}) > 1) {  
                 if (($domconfig{'scantron'}{'config'}{'dat'}) &&  
                     (ref($domconfig{'scantron'}{'config'}{'csv'}) eq 'HASH')) {  
                     if (ref($domconfig{'scantron'}{'config'}{'csv'}{'fields'}) eq 'HASH') {  
                         if (keys(%{$domconfig{'scantron'}{'config'}{'csv'}{'fields'}})) {  
                             my ($onclick,$formatextra,$singleline);  
                             my @lines = &Apache::lonnet::get_scantronformat_file();  
                             my $count = 0;  
                             foreach my $line (@lines) {  
                                 next if ($line =~ /^#/);  
                                 $singleline = $line;  
                                 $count ++;  
                             }  
                             if ($count > 1) {  
                                 $formatextra = '<div style="display:none" id="bubbletype">'.  
                                                '<span class="LC_nobreak">'.  
                                                &mt('Bubblesheet type:').'&nbsp;'.  
                                                &scantron_scantab().'</span></div>';  
                                 $onclick = ' onclick="toggleScantab(this.form);"';  
                                 $formatjs = <<"END";  
 function toggleScantab(form) {  
     var divid = 'bubbletype';  
     if (document.getElementById(divid)) {  
         var radioname = 'fileformat';  
         var num = form.elements[radioname].length;  
         if (num) {  
             for (var i=0; i<num; i++) {  
                 if (form.elements[radioname][i].checked) {  
                     var chosen = form.elements[radioname][i].value;  
                     if (chosen == 'dat') {  
                         document.getElementById(divid).style.display = 'none';  
                     } else if (chosen == 'csv') {  
                         document.getElementById(divid).style.display = 'block';  
                     }  
                 }  
             }  
         }  
     }  
     return;  
 }  
   
 END  
                             } elsif ($count == 1) {  
                                 my $formatname = (split(/:/,$singleline,2))[0];  
                                 $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;  
                         }  
                     }  
                 }  
             } elsif (keys(%{$domconfig{'scantron'}{'config'}}) == 1) {  
                 if (ref($domconfig{'scantron'}{'config'}{'csv'}{'fields'}) eq 'HASH') {  
                     if (keys(%{$domconfig{'scantron'}{'config'}{'csv'}{'fields'}})) {  
                         $formattitle = &mt('Bubblesheet type');  
                         $formatoptions = &scantron_scantab();  
                     }  
                 }  
             }  
         }  
     }  
     return ($formatoptions,$formattitle,$formatjs);  
 }  
   
 sub scantron_upload_scantron_data_save {  sub scantron_upload_scantron_data_save {
     my($r)=@_;      my($r)=@_;
Line 9107  sub scantron_upload_scantron_data_save { Line 9157  sub scantron_upload_scantron_data_save {
                 &mt('The file: [_1] you attempted to upload contained no information. Please check that you entered the correct filename.',                  &mt('The file: [_1] you attempted to upload contained no information. Please check that you entered the correct filename.',
                         '<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));
     } else {      } else {
         my %domconfig = &Apache::lonnet::get_dom('configuration',['scantron'],$env{'form.domainid'});          my $result = 
         my $parser;              &Apache::lonnet::userfileupload('upfile','','scantron','','','',
         if (ref($domconfig{'scantron'}) eq 'HASH') {  
             if (ref($domconfig{'scantron'}{'config'}) eq 'HASH') {  
                 my $is_csv;  
                 my @possibles = keys(%{$domconfig{'scantron'}{'config'}});  
                 if (@possibles > 1) {  
                     if ($env{'form.fileformat'} eq 'csv') {  
                         if (ref($domconfig{'scantron'}{'config'}{'csv'}) eq 'HASH') {  
                             if (ref($domconfig{'scantron'}{'config'}{'csv'}{'fields'}) eq 'HASH') {  
                                 if (keys(%{$domconfig{'scantron'}{'config'}{'csv'}{'fields'}}) > 1) {  
                                     $is_csv = 1;  
                                 }  
                             }  
                         }  
                     }  
                 } elsif (@possibles == 1) {  
                     if (ref($domconfig{'scantron'}{'config'}{'csv'}) eq 'HASH') {  
                         if (ref($domconfig{'scantron'}{'config'}{'csv'}{'fields'}) eq 'HASH') {  
                             if (keys(%{$domconfig{'scantron'}{'config'}{'csv'}{'fields'}}) > 1) {  
                                 $is_csv = 1;  
                             }  
                         }  
                     }  
                 }  
                 if ($is_csv) {  
                    $parser = $domconfig{'scantron'}{'config'}{'csv'};  
                 }  
             }  
         }  
         my $result =  
             &Apache::lonnet::userfileupload('upfile','scantron','scantron',$parser,'','',  
                                             $env{'form.courseid'},$env{'form.domainid'});                                              $env{'form.courseid'},$env{'form.domainid'});
  if ($result =~ m{^/uploaded/}) {   if ($result =~ m{^/uploaded/}) {
             $r->print(              $r->print(
Line 9183  sub validate_uploaded_scantron_file { Line 9203  sub validate_uploaded_scantron_file {
             $idmap{$lckey} = $idmap{$key};              $idmap{$lckey} = $idmap{$key};
         }          }
         my %unique_formats;          my %unique_formats;
         my @formatlines = &Apache::lonnet::get_scantronformat_file();          my @formatlines = &get_scantronformat_file();
         foreach my $line (@formatlines) {          foreach my $line (@formatlines) {
             chomp($line);              chomp($line);
             my @config = split(/:/,$line);              my @config = split(/:/,$line);
Line 9329  sub checkscantron_results { Line 9349  sub checkscantron_results {
     if (!$symb) {return '';}      if (!$symb) {return '';}
     my $grading_menu_button=&show_grading_menu_form($symb);      my $grading_menu_button=&show_grading_menu_form($symb);
     my $cid = $env{'request.course.id'};      my $cid = $env{'request.course.id'};
     my %lettdig = &Apache::lonnet::letter_to_digits();      my %lettdig = &letter_to_digits();
     my $numletts = scalar(keys(%lettdig));      my $numletts = scalar(keys(%lettdig));
     my $cnum = $env{'course.'.$cid.'.num'};      my $cnum = $env{'course.'.$cid.'.num'};
     my $cdom = $env{'course.'.$cid.'.domain'};      my $cdom = $env{'course.'.$cid.'.domain'};
     my (undef, undef, $sequence) = &Apache::lonnet::decode_symb($env{'form.selectpage'});      my (undef, undef, $sequence) = &Apache::lonnet::decode_symb($env{'form.selectpage'});
     my %record;      my %record;
     my %scantron_config =      my %scantron_config =
         &Apache::lonnet::get_scantron_config($env{'form.scantron_format'});          &Apache::grades::get_scantron_config($env{'form.scantron_format'});
     my $bubbles_per_row = &bubblesheet_bubbles_per_row(\%scantron_config);      my $bubbles_per_row = &bubblesheet_bubbles_per_row(\%scantron_config);
     my ($scanlines,$scan_data)=&Apache::grades::scantron_getfile();      my ($scanlines,$scan_data)=&Apache::grades::scantron_getfile();
     my $classlist=&Apache::loncoursedata::get_classlist();      my $classlist=&Apache::loncoursedata::get_classlist();
Line 9660  sub verify_scantron_grading { Line 9680  sub verify_scantron_grading {
     return ($counter,$record);      return ($counter,$record);
 }  }
   
   sub letter_to_digits {
       my %lettdig = (
                       A => 1,
                       B => 2,
                       C => 3,
                       D => 4,
                       E => 5,
                       F => 6,
                       G => 7,
                       H => 8,
                       I => 9,
                       J => 0,
                     );
       return %lettdig;
   }
   
   
 #-------- end of section for handling grading scantron forms -------  #-------- end of section for handling grading scantron forms -------
 #  #
 #-------------------------------------------------------------------  #-------------------------------------------------------------------
Line 10264  sub process_clicker_file { Line 10301  sub process_clicker_file {
             $result .=              $result .=
                  &Apache::lonhtmlcommon::confirm_success(                   &Apache::lonhtmlcommon::confirm_success(
                      &mt('No IDs found to determine correct answer'),1);                       &mt('No IDs found to determine correct answer'),1);
             return $result.&show_grading_menu_form($symb);              return $result,.&show_grading_menu_form($symb);
         }          }
     }      }
     if (length($env{'form.upfile'}) < 2) {      if (length($env{'form.upfile'}) < 2) {
Line 10274  sub process_clicker_file { Line 10311  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.&show_grading_menu_form($symb);          return $result.&show_grading_menu_form($symb);
     }      }
     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.&show_grading_menu_form($symb);  
         }  
     } 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.&show_grading_menu_form($symb);  
     }  
   
 # 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 10317  ENDHEADER Line 10338  ENDHEADER
     my $errormsg='';      my $errormsg='';
     my $number=0;      my $number=0;
     if ($env{'form.upfiletype'} eq 'iclicker') {      if ($env{'form.upfiletype'} eq 'iclicker') {
         if ($mimetype eq 'text/plain') {   ($errormsg,$number)=&iclicker_eval(\@questiontitles,\%responses);
             ($errormsg,$number)=&iclicker_eval(\@questiontitles,\%responses);      }
         } elsif ($mimetype eq 'text/html') {      if ($env{'form.upfiletype'} eq 'interwrite') {
             ($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 10427  sub iclicker_eval { Line 10446  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 10668  sub navmap_errormsg { Line 10644  sub navmap_errormsg {
 }  }
   
 sub startpage {  sub startpage {
     my ($r,$symb,$crumbs,$onlyfolderflag,$nodisplayflag,$stuvcurrent,$stuvdisp,$nomenu,$js,$onload) = @_;      my ($r,$symb,$crumbs,$onlyfolderflag,$nodisplayflag,$stuvcurrent,$stuvdisp,$nomenu,$js) = @_;
     my %args;  
     if ($onload) {  
          my %loaditems = (  
                         'onload' => $onload,  
                       );  
          $args{'add_entries'} = \%loaditems;  
     }  
     if ($nomenu) {      if ($nomenu) {
         $args{'only_body'} = 1;          $r->print(&Apache::loncommon::start_page("Student's Version",$js,{'only_body' => '1'}));
         $r->print(&Apache::loncommon::start_page("Student's Version",$js,\%args));  
     } else {      } else {
         $args{'bread_crumbs'} = $crumbs;          $r->print(&Apache::loncommon::start_page('Grading',$js,
         $r->print(&Apache::loncommon::start_page('Grading',$js,\%args));                                                   {'bread_crumbs' => $crumbs}));
     }      }
     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 10763  sub handler { Line 10731  sub handler {
         }          }
         &Apache::loncommon::content_type($request,'text/html');          &Apache::loncommon::content_type($request,'text/html');
         $request->send_http_header;          $request->send_http_header;
         if (($command eq 'scantron_selectphase' && $perm{'mgr'}) ||           unless ((($command eq 'submission' || $command eq 'versionsub')) && ($perm{'vgr'})) {
             (($command eq 'scantronupload') &&              $request->print($start_page); 
              (&Apache::lonnet::allowed('usc',$env{'request.role.domain'}) ||  
               &Apache::lonnet::allowed('usc',$env{'request.course.id'})))) {  
             &startpage($request,$symb,[{href=>'/adm/grades', text=>"Grading"}],1,1,  
                        undef,undef,undef,undef,'toggleScantab(document.rules);');  
         } else {  
             unless ((($command eq 'submission' || $command eq 'versionsub')) && ($perm{'vgr'})) {  
                 $request->print($start_page);   
             }  
         }          }
  if ($command eq 'submission' && $perm{'vgr'}) {   if ($command eq 'submission' && $perm{'vgr'}) {
             my ($stuvcurrent,$stuvdisp,$versionform,$js);              my ($stuvcurrent,$stuvdisp,$versionform,$js);
Line 10951  ssi_with_retries() Line 10911  ssi_with_retries()
     $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 &Apache::lonnet::get_scantron_config()      $scan_config - hash ref as returned from &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.596.2.12.2.41.2.6  
changed lines
  Added in v.1.596.2.12.2.42


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