Diff for /loncom/interface/domainprefs.pm between versions 1.160.6.84.2.9 and 1.160.6.84.2.10

version 1.160.6.84.2.9, 2017/11/16 23:33:05 version 1.160.6.84.2.10, 2019/02/03 20:43:00
Line 377  sub handler { Line 377  sub handler {
                     modify => \&modify_usermodification,                      modify => \&modify_usermodification,
                   },                    },
         'scantron' =>          'scantron' =>
                   { text => 'Bubblesheet format file',                    { text => 'Bubblesheet format',
                     help => 'Domain_Configuration_Scantron_Format',                      help => 'Domain_Configuration_Scantron_Format',
                     header => [ {col1 => 'Item',                      header => [ {col1 => 'Bubblesheet format file',
                                  col2 => '',                                   col2 => ''},
                               }],                                  {col1 => 'Bubblesheet data upload formats',
                                    col2 => 'Settings'}],
                     print => \&print_scantron,                      print => \&print_scantron,
                     modify => \&modify_scantron,                      modify => \&modify_scantron,
                   },                    },
Line 553  END Line 554  END
         if (grep(/^contacts$/,@actions)) {          if (grep(/^contacts$/,@actions)) {
             $js .= &contacts_javascript();              $js .= &contacts_javascript();
         }          }
           if (grep(/^scantron$/,@actions)) {
               $js .= &scantron_javascript();
           }
         &Apache::lonconfigsettings::display_settings($r,$dom,$phase,$context,\@prefs_order,\%prefs,\%domconfig,$confname,$js);          &Apache::lonconfigsettings::display_settings($r,$dom,$phase,$context,\@prefs_order,\%prefs,\%domconfig,$confname,$js);
     } else {      } else {
 # check if domconfig user exists for the domain.  # check if domconfig user exists for the domain.
Line 743  sub print_config_box { Line 747  sub print_config_box {
             $output .= $item->{'print'}->('top',$dom,$settings,\$rowtotal);              $output .= $item->{'print'}->('top',$dom,$settings,\$rowtotal);
         } elsif ($action eq 'coursecategories') {          } elsif ($action eq 'coursecategories') {
             $output .= $item->{'print'}->('top',$dom,$item,$settings,\$rowtotal);              $output .= $item->{'print'}->('top',$dom,$item,$settings,\$rowtotal);
           } elsif ($action eq 'scantron') {
               $output .= $item->{'print'}->($r,'top',$dom,$confname,$settings,\$rowtotal);
         } elsif ($action eq 'login') {          } elsif ($action eq 'login') {
             if ($numheaders == 4) {              if ($numheaders == 4) {
                 $colspan = ' colspan="2"';                  $colspan = ' colspan="2"';
Line 798  sub print_config_box { Line 804  sub print_config_box {
                  ($action eq 'defaults') || ($action eq 'directorysrch') ||                   ($action eq 'defaults') || ($action eq 'directorysrch') ||
                  ($action eq 'helpsettings')) {                   ($action eq 'helpsettings')) {
             $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);              $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
           } elsif ($action eq 'scantron') {
               $output .= $item->{'print'}->($r,'bottom',$dom,$confname,$settings,\$rowtotal);
         } elsif ($action eq 'login') {          } elsif ($action eq 'login') {
             if ($numheaders == 4) {              if ($numheaders == 4) {
                 $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal).'                  $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal).'
Line 957  sub print_config_box { Line 965  sub print_config_box {
                  ($action eq 'serverstatuses') || ($action eq 'loadbalancing') ||                   ($action eq 'serverstatuses') || ($action eq 'loadbalancing') ||
                  ($action eq 'ltitools')) {                   ($action eq 'ltitools')) {
             $output .= $item->{'print'}->($dom,$settings,\$rowtotal);              $output .= $item->{'print'}->($dom,$settings,\$rowtotal);
         } elsif ($action eq 'scantron') {  
             $output .= &print_scantronformat($r,$dom,$confname,$settings,\$rowtotal);  
         }          }
     }      }
     $output .= '      $output .= '
Line 6292  sub defaults_titles { Line 6298  sub defaults_titles {
     return (\%titles);      return (\%titles);
 }  }
   
   sub print_scantron {
       my ($r,$position,$dom,$confname,$settings,$rowtotal) = @_;
       if ($position eq 'top') {
           return &print_scantronformat($r,$dom,$confname,$settings,\$rowtotal);
       } else {
           return &print_scantronconfig($dom,$settings,\$rowtotal);
       }
   }
   
   sub scantron_javascript {
       return <<"ENDSCRIPT";
   
   <script type="text/javascript">
   // <![CDATA[
   
   function toggleScantron(form) {
       var csvfieldset = new Array();
       if (document.getElementById('scantroncsv_cols')) {
           csvfieldset.push(document.getElementById('scantroncsv_cols'));
       }
       if (document.getElementById('scantroncsv_options')) {
           csvfieldset.push(document.getElementById('scantroncsv_options'));
       }
       if (csvfieldset.length) {
           if (document.getElementById('scantronconfcsv')) {
               var scantroncsv = document.getElementById('scantronconfcsv');
               if (scantroncsv.checked) {
                   for (var i=0; i<csvfieldset.length; i++) {
                       csvfieldset[i].style.display = 'block';
                   }
               } else {
                   for (var i=0; i<csvfieldset.length; i++) {
                       csvfieldset[i].style.display = 'none';
                   }
                   var csvselects = document.getElementsByClassName('scantronconfig_csv');
                   if (csvselects.length) {
                       for (var j=0; j<csvselects.length; j++) {
                           csvselects[j].selectedIndex = 0;
                       }
                   }
               }
           }
       }
       return;
   }
   // ]]>
   </script>
   
   ENDSCRIPT
   
   }
   
 sub print_scantronformat {  sub print_scantronformat {
     my ($r,$dom,$confname,$settings,$rowtotal) = @_;      my ($r,$dom,$confname,$settings,$rowtotal) = @_;
     my $itemcount = 1;      my $itemcount = 1;
Line 6318  sub print_scantronformat { Line 6376  sub print_scantronformat {
             if ($configuserok eq 'ok') {              if ($configuserok eq 'ok') {
                 if ($author_ok eq 'ok') {                  if ($author_ok eq 'ok') {
                     my %legacyfile = (                      my %legacyfile = (
  default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab',    default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab',
  custom  => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab',    custom  => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab',
                     );                      );
                     my %md5chk;                      my %md5chk;
                     foreach my $type (keys(%legacyfile)) {                      foreach my $type (keys(%legacyfile)) {
Line 6328  sub print_scantronformat { Line 6386  sub print_scantronformat {
                     }                      }
                     if ($md5chk{'default'} ne $md5chk{'custom'}) {                      if ($md5chk{'default'} ne $md5chk{'custom'}) {
                         foreach my $type (keys(%legacyfile)) {                          foreach my $type (keys(%legacyfile)) {
                             ($scantronurls{$type},my $error) =                               ($scantronurls{$type},my $error) =
                                 &legacy_scantronformat($r,$dom,$confname,                                  &legacy_scantronformat($r,$dom,$confname,
                                                  $type,$legacyfile{$type},                                                   $type,$legacyfile{$type},
                                                  $scantronurls{$type},                                                   $scantronurls{$type},
Line 6339  sub print_scantronformat { Line 6397  sub print_scantronformat {
                         }                          }
                         if (keys(%error) == 0) {                          if (keys(%error) == 0) {
                             $is_custom = 1;                              $is_custom = 1;
                             $confhash{'scantron'}{'scantronformat'} =                               $confhash{'scantron'}{'scantronformat'} =
                                 $scantronurls{'custom'};                                  $scantronurls{'custom'};
                             my $putresult =                               my $putresult =
                                 &Apache::lonnet::put_dom('configuration',                                  &Apache::lonnet::put_dom('configuration',
                                                          \%confhash,$dom);                                                           \%confhash,$dom);
                             if ($putresult ne 'ok') {                              if ($putresult ne 'ok') {
                                 $error{'custom'} =                                   $error{'custom'} =
                                     '<span class="LC_error">'.                                      '<span class="LC_error">'.
                                     &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';                                      &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
                             }                              }
Line 6465  sub legacy_scantronformat { Line 6523  sub legacy_scantronformat {
     return ($url,$error);      return ($url,$error);
 }  }
   
   sub print_scantronconfig {
       my ($dom,$settings,$rowtotal) = @_;
       my $itemcount = 2;
       my $is_checked = ' checked="checked"';
       my %optionson = (
                        hdr => ' checked="checked"',
                        pad => ' checked="checked"',
                        rem => ' checked="checked"',
                       );
       my %optionsoff = (
                         hdr => '',
                         pad => '',
                         rem => '',
                        );
       my $currcsvsty = 'none';
       my ($datatable,%csvfields,%checked,%onclick,%csvoptions);
       my @fields = &scantroncsv_fields();
       my %titles = &scantronconfig_titles();
       if (ref($settings) eq 'HASH') {
           if (ref($settings->{config}) eq 'HASH') {
               if ($settings->{config}->{dat}) {
                   $checked{'dat'} = $is_checked;
               }
               if (ref($settings->{config}->{csv}) eq 'HASH') {
                   if (ref($settings->{config}->{csv}->{fields}) eq 'HASH') {
                       %csvfields = %{$settings->{config}->{csv}->{fields}};
                       if (keys(%csvfields) > 0) {
                           $checked{'csv'} = $is_checked;
                           $currcsvsty = 'block';
                       }
                   }
                   if (ref($settings->{config}->{csv}->{options}) eq 'HASH') {
                       %csvoptions = %{$settings->{config}->{csv}->{options}};
                       foreach my $option (keys(%optionson)) {
                           unless ($csvoptions{$option}) {
                               $optionsoff{$option} = $optionson{$option};
                               $optionson{$option} = '';
                           }
                       }
                   }
               }
           } else {
               $checked{'dat'} = $is_checked;
           }
       } else {
           $checked{'dat'} = $is_checked;
       }
       $onclick{'csv'} = ' onclick="toggleScantron(this.form);"';
       my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
       $datatable = '<tr '.$css_class.'><td>'.&mt('Supported formats').'</td>'.
                    '<td class="LC_left_item" valign="top"><span class="LC_nobreak">';
       foreach my $item ('dat','csv') {
           my $id;
           if ($item eq 'csv') {
               $id = 'id="scantronconfcsv" ';
           }
           $datatable .= '<label><input type="checkbox" name="scantronconfig" '.$id.'value="'.$item.'"'.$checked{$item}.$onclick{$item}.' />'.
                         $titles{$item}.'</label>'.('&nbsp;'x3);
           if ($item eq 'csv') {
               $datatable .= '<fieldset style="display:'.$currcsvsty.'" id="scantroncsv_cols">'.
                             '<legend>'.&mt('CSV Column Mapping').'</legend>'.
                             '<table><tr><th>'.&mt('Field').'</th><th>'.&mt('Location').'</th></tr>'."\n";
               foreach my $col (@fields) {
                   my $selnone;
                   if ($csvfields{$col} eq '') {
                       $selnone = ' selected="selected"';
                   }
                   $datatable .= '<tr><td>'.$titles{$col}.'</td>'.
                                 '<td><select name="scantronconfig_csv_'.$col.'" class="scantronconfig_csv">'.
                                 '<option value=""'.$selnone.'></option>';
                   for (my $i=0; $i<20; $i++) {
                       my $shown = $i+1;
                       my $sel;
                       unless ($selnone) {
                           if (exists($csvfields{$col})) {
                               if ($csvfields{$col} == $i) {
                                   $sel = ' selected="selected"';
                               }
                           }
                       }
                       $datatable .= '<option value="'.$i.'"'.$sel.'>'.$shown.'</option>';
                   }
                   $datatable .= '</select></td></tr>';
              }
              $datatable .= '</table></fieldset>'.
                            '<fieldset style="display:'.$currcsvsty.'" id="scantroncsv_options">'.
                            '<legend>'.&mt('CSV Options').'</legend>';
              foreach my $option ('hdr','pad','rem') {
                  $datatable .= '<span class="LC_nobreak">'.$titles{$option}.':'.
                            '<label><input type="radio" name="scantroncsv_'.$option.'" value="1"'.$optionson{$option}.' />'.
                            &mt('Yes').'</label>'.('&nbsp;'x2)."\n".
                            '<label><input type="radio" name="scantroncsv_'.$option.'" value="0"'.$optionsoff{$option}.' />'.&mt('No').'</label></span><br />';
              }
              $datatable .= '</fieldset>';
              $itemcount ++;
           }
       }
       $datatable .= '</td></tr>';
       $$rowtotal ++;
       return $datatable;
   }
   
   sub scantronconfig_titles {
       return &Apache::lonlocal::texthash(
                                             dat => 'Standard format (.dat)',
                                             csv => 'Comma separated values (.csv)',
                                             hdr => 'Remove first line in file (contains column titles)',
                                             pad => 'Prepend 0s to PaperID',
                                             rem => 'Remove leading spaces (except Question Response columns)',
                                             CODE => 'CODE',
                                             ID   => 'Student ID',
                                             PaperID => 'Paper ID',
                                             FirstName => 'First Name',
                                             LastName => 'Last Name',
                                             FirstQuestion => 'First Question Response',
                                             Section => 'Section',
       );
   }
   
   sub scantroncsv_fields {
       return ('PaperID','LastName','FirstName','ID','Section','CODE','FirstQuestion');
   }
   
 sub print_coursecategories {  sub print_coursecategories {
     my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;      my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
     my $datatable;      my $datatable;
Line 8828  sub modify_quotas { Line 9009  sub modify_quotas {
                     if ($type eq 'textbooks') {                      if ($type eq 'textbooks') {
                         if ($env{'form.'.$type.'_addbook_image.filename'} ne '') {                          if ($env{'form.'.$type.'_addbook_image.filename'} ne '') {
                             my ($cdom,$cnum) = split(/_/,$newbook{$type});                              my ($cdom,$cnum) = split(/_/,$newbook{$type});
                             my ($imageurl,$error) =                              if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
                                 &process_textbook_image($r,$dom,$confname,$type.'_addbook_image',$cdom,$cnum,$type,                                  my ($imageurl,$error) =
                                                         $configuserok,$switchserver,$author_ok);                                      &process_textbook_image($r,$dom,$confname,$type.'_addbook_image',$cdom,$cnum,$type,
                             if ($imageurl) {                                                              $configuserok,$switchserver,$author_ok);
                                 $confhash{$type}{$newbook{$type}}{'image'} = $imageurl;                                  if ($imageurl) {
                             }                                      $confhash{$type}{$newbook{$type}}{'image'} = $imageurl;
                             if ($error) {                                  }
                                 &Apache::lonnet::logthis($error);                                  if ($error) {
                                 $errors .= '<li><span class="LC_error">'.$error.'</span></li>';                                      &Apache::lonnet::logthis($error);
                                       $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
                                   }
                             }                              }
                         }                          }
                     }                      }
Line 12221  sub modify_scantron { Line 12404  sub modify_scantron {
     my $custom = 'custom.tab';      my $custom = 'custom.tab';
     my $default = 'default.tab';      my $default = 'default.tab';
     my $servadm = $r->dir_config('lonAdmEMail');      my $servadm = $r->dir_config('lonAdmEMail');
     my ($configuserok,$author_ok,$switchserver) =       my ($configuserok,$author_ok,$switchserver) =
         &config_check($dom,$confname,$servadm);          &config_check($dom,$confname,$servadm);
     if ($env{'form.scantronformat.filename'} ne '') {      if ($env{'form.scantronformat.filename'} ne '') {
         my $error;          my $error;
Line 12256  sub modify_scantron { Line 12439  sub modify_scantron {
             if ($env{'form.scantronformat_del'}) {              if ($env{'form.scantronformat_del'}) {
                 $confhash{'scantron'}{'scantronformat'} = '';                  $confhash{'scantron'}{'scantronformat'} = '';
                 $changes{'scantronformat'} = 1;                  $changes{'scantronformat'} = 1;
               } else {
                   $confhash{'scantron'}{'scantronformat'} = $domconfig{'scantron'}{'scantronformat'};
               }
           }
       }
       my @options = ('hdr','pad','rem');
       my @fields = &scantroncsv_fields();
       my %titles = &scantronconfig_titles();
       my @formats = &Apache::loncommon::get_env_multiple('form.scantronconfig');
       my ($newdat,$currdat,%newcol,%currcol);
       if (grep(/^dat$/,@formats)) {
           $confhash{'scantron'}{config}{dat} = 1;
           $newdat = 1;
       } else {
           $newdat = 0;
       }
       if (grep(/^csv$/,@formats)) {
           my %bynum;
           foreach my $field (@fields) {
               if ($env{'form.scantronconfig_csv_'.$field} =~ /^(\d+)$/) {
                   my $posscol = $1;
                   if (($posscol < 20) && (!$bynum{$posscol})) {
                       $confhash{'scantron'}{config}{csv}{fields}{$field} = $posscol;
                       $bynum{$posscol} = $field;
                       $newcol{$field} = $posscol;
                   }
               }
           }
           if (keys(%newcol)) {
               foreach my $option (@options) {
                   if ($env{'form.scantroncsv_'.$option}) {
                       $confhash{'scantron'}{config}{csv}{options}{$option} = 1;
                   }
               }
           }
       }
       $currdat = 1;
       if (ref($domconfig{'scantron'}) eq 'HASH') {
           if (ref($domconfig{'scantron'}{'config'}) eq 'HASH') {
               unless (exists($domconfig{'scantron'}{'config'}{'dat'})) {
                   $currdat = 0;
               }
               if (ref($domconfig{'scantron'}{'config'}{'csv'}) eq 'HASH') {
                   if (ref($domconfig{'scantron'}{'config'}{'csv'}{'fields'}) eq 'HASH') {
                       %currcol = %{$domconfig{'scantron'}{'config'}{'csv'}{'fields'}};
                   }
               }
           }
       }
       if ($currdat != $newdat) {
           $changes{'config'} = 1;
       } else {
           foreach my $field (@fields) {
               if ($currcol{$field} ne '') {
                   if ($currcol{$field} ne $newcol{$field}) {
                       $changes{'config'} = 1;
                       last;
                   }
               } elsif ($newcol{$field} ne '') {
                   $changes{'config'} = 1;
                   last;
             }              }
         }          }
     }      }
Line 12266  sub modify_scantron { Line 12510  sub modify_scantron {
             if (keys(%changes) > 0) {              if (keys(%changes) > 0) {
                 if (ref($confhash{'scantron'}) eq 'HASH') {                  if (ref($confhash{'scantron'}) eq 'HASH') {
                     $resulttext = &mt('Changes made:').'<ul>';                      $resulttext = &mt('Changes made:').'<ul>';
                     if ($confhash{'scantron'}{'scantronformat'} eq '') {                      if ($changes{'scantronformat'}) {
                         $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';                          if ($confhash{'scantron'}{'scantronformat'} eq '') {
                     } else {                              $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
                         $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';                          } else {
                               $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
                           }
                       }
                       if ($changes{'config'}) {
                           if (ref($confhash{'scantron'}{'config'}) eq 'HASH') {
                               if ($confhash{'scantron'}{'config'}{'dat'}) {
                                   $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .dat format').'</li>';
                               }
                               if (ref($confhash{'scantron'}{'config'}{'csv'}) eq 'HASH') {
                                   if (ref($confhash{'scantron'}{'config'}{'csv'}{'fields'}) eq 'HASH') {
                                       if (keys(%{$confhash{'scantron'}{'config'}{'csv'}{'fields'}})) {
                                           $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .csv format, with following fields/column numbers supported:').'<ul>';
                                           foreach my $field (@fields) {
                                               if ($confhash{'scantron'}{'config'}{'csv'}{'fields'}{$field} ne '') {
                                                   my $showcol = $confhash{'scantron'}{'config'}{'csv'}{'fields'}{$field} + 1;
                                                   $resulttext .= '<li>'.$titles{$field}.': '.$showcol.'</li>';
                                               }
                                           }
                                           $resulttext .= '</ul></li>';
                                           if (ref($confhash{'scantron'}{'config'}{'csv'}{'options'}) eq 'HASH') {
                                               if (keys(%{$confhash{'scantron'}{'config'}{'csv'}{'options'}})) {
                                                   $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .csv format, with following options:').'<ul>';
                                                   foreach my $option (@options) {
                                                       if ($confhash{'scantron'}{'config'}{'csv'}{'options'}{$option} ne '') {
                                                           $resulttext .= '<li>'.$titles{$option}.'</li>';
                                                       }
                                                   }
                                                   $resulttext .= '</ul></li>';
                                               }
                                           }
                                       }
                                   }
                               }
                           } else {
                               $resulttext .= '<li>'.&mt('No bubblesheet data upload formats set -- will default to assuming .dat format').'</li>';
                           }
                     }                      }
                     $resulttext .= '</ul>';                      $resulttext .= '</ul>';
                 } else {                  } else {
                     $resulttext = &mt('Changes made to bubblesheet format file.');                      $resulttext = &mt('Changes made to bubblesheet format file.');
                 }                  }
                 $resulttext .= '</ul>';  
                 &Apache::loncommon::devalidate_domconfig_cache($dom);                  &Apache::loncommon::devalidate_domconfig_cache($dom);
                 if (ref($lastactref) eq 'HASH') {                  if (ref($lastactref) eq 'HASH') {
                     $lastactref->{'domainconfig'} = 1;                      $lastactref->{'domainconfig'} = 1;
                 }                  }
             } else {              } else {
                 $resulttext = &mt('No changes made to bubblesheet format file');                  $resulttext = &mt('No changes made to bubblesheet format settings');
             }              }
         } else {          } else {
             $resulttext = '<span class="LC_error">'.              $resulttext = '<span class="LC_error">'.
                 &mt('An error occurred: [_1]',$putresult).'</span>';                  &mt('An error occurred: [_1]',$putresult).'</span>';
         }          }
     } else {      } else {
         $resulttext = &mt('No changes made to bubblesheet format file');           $resulttext = &mt('No changes made to bubblesheet format settings');
     }      }
     if ($errors) {      if ($errors) {
         $resulttext .= &mt('The following errors occurred: ').'<ul>'.          $resulttext .= &mt('The following errors occurred: ').'<ul>'.

Removed from v.1.160.6.84.2.9  
changed lines
  Added in v.1.160.6.84.2.10


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