Diff for /loncom/interface/lonpopulate.pm between versions 1.86 and 1.87

version 1.86, 2021/03/31 02:19:59 version 1.87, 2021/06/15 20:52:26
Line 37  use Apache::lonuserutils; Line 37  use Apache::lonuserutils;
 use Apache::Constants qw(:common :http REDIRECT);  use Apache::Constants qw(:common :http REDIRECT);
 use Time::Local;  use Time::Local;
 use LONCAPA::Enrollment;  use LONCAPA::Enrollment;
   use LONCAPA qw(:DEFAULT :match);
   
 ###############################################################  ###############################################################
 sub header {  sub header {
Line 903  sub print_main_frame { Line 904  sub print_main_frame {
                  <th>'.&mt('LON-CAPA section ID').'</th>                   <th>'.&mt('LON-CAPA section ID').'</th>
           ');            ');
           $r->print(&Apache::loncommon::end_data_table_row());            $r->print(&Apache::loncommon::end_data_table_row());
           for (my $i=0; $i<@xlists; $i++) {            my @showable;
             &reformat_xlists($dom,$crs,$enrollvar{'coursecode'},\@xlists,\@showable);
             for (my $i=0; $i<@showable; $i++) {
               my $xl = '&nbsp;';                my $xl = '&nbsp;';
               my $lc_sec = '&nbsp;';                my $lc_sec = '&nbsp;';
               if ($xlists[$i] =~ /^([^:]+):?(.*)$/) {                if ($showable[$i] =~ /^([^:]+):?(.*)$/) {
                   $xl = $1;                    $xl = $1;
                   $lc_sec = $2;                    $lc_sec = $2;
               }                               }               
Line 2063  sub print_crosslistings_menu { Line 2066  sub print_crosslistings_menu {
  if ($crosscount > 0) {   if ($crosscount > 0) {
     $response .= &mt('The [quant,_1,course] listed below remain crosslisted with this LON-CAPA course, and students enrolling in these course sections will be automatically added to the class roster for the course, if you have chosen to enable a nightly automated enrollment update.',$crosscount).      $response .= &mt('The [quant,_1,course] listed below remain crosslisted with this LON-CAPA course, and students enrolling in these course sections will be automatically added to the class roster for the course, if you have chosen to enable a nightly automated enrollment update.',$crosscount).
                          '<br /><ul>'."\n";                           '<br /><ul>'."\n";
     foreach my $xl (@xlists) {              my @showable;
  my ($xlist,$lc_sec) = split(/:/,$xl);              &reformat_xlists($dom,$crs,$coursecode,\@xlists,\@showable);
               foreach my $item (@showable) {
                   my ($xlist,$lc_sec) = split(/:/,$item);
  $response .=    $response .= 
                     '<li>'.&mt('[_1] - ID: [_2]',$xlist,$lc_sec).'</li>'."\n";                      '<li>'.&mt('[_1] - ID: [_2]',$xlist,$lc_sec).'</li>'."\n";
     }      }
Line 2074  sub print_crosslistings_menu { Line 2079  sub print_crosslistings_menu {
     if ( exists($env{'form.numcross'}) ) {      if ( exists($env{'form.numcross'}) ) {
  my $numcross = $env{'form.numcross'};   my $numcross = $env{'form.numcross'};
  if ($numcross) {   if ($numcross) {
     $response .=               my (@codetitles,%cat_titles,%cat_order,@code_order);
                 &mt('You indicated that you wish to add an additional [quant,_1,crosslisting].',$numcross).' '.              &Apache::lonnet::auto_possible_instcodes($dom,\@codetitles,\%cat_titles,
                 &mt('For each new crosslisting enter the institutional course section code (e.g., fs03zol101001, for section 001 of zol101 for fs03 semester), and the LON-CAPA section ID you wish to assign to students who will be enrolled in your LON-CAPA class as a result of their registration in the crosslisted course section.').' '.                                                       \%cat_order,\@code_order);       
                 &mt('The LON-CAPA section ID can be left blank, if you do not wish to tie a section ID to this crosslisting.').' '.      $response .=
                 &mt("The institutional course section code should only contain letters and/or numbers, and must be consistent with the scheme adopted by your Domain Coordinator to map course codes (and section numbers) to your institution's student information system.").                  &mt('You indicated that you wish to add an additional [quant,_1,crosslisting].',$numcross).' ';
                 '<br /><br />              if (@codetitles > 0) {
            <form name="enter" method="post" action="">'.                  my $lastitem = pop(@codetitles);
            &Apache::loncommon::start_data_table().                  $response .=
            &Apache::loncommon::start_data_table_row().'                      &mt('For each new crosslisting select [_1], and enter the [_2] and the LON-CAPA section ID.',join(', ',@codetitles),$lastitem).' '.
                  <th>'.&mt('Crosslisting').'</th>                      &mt('The LON-CAPA section ID can be left blank, if you do not wish to tie a section ID to this crosslisting.').' '.
                  <th>'.&mt('LON-CAPA section ID').'</th>'."\n".                      '<br /><br />'.
            &Apache::loncommon::end_data_table_row();                      '<form name="enter" method="post" action="">'."\n".
    for (my $i=0; $i<$numcross; $i++) {                      &Apache::loncommon::start_data_table()."\n".
                $response .=                       &Apache::loncommon::start_data_table_header_row()."\n";
                    &Apache::loncommon::start_data_table_row().'                  foreach my $title (@codetitles) {
                    <td><input type="text" size="15" name="newcross_'.$i.'" /></td>                      if (ref($cat_order{$title}) eq 'ARRAY') {
                     <td align="right"><input type="text" size="10" name="newlcsec_'.$i.'" /></td>'.                          if (@{$cat_order{$title}} > 0) {
                               $response .= '<th>'.$title.'</th>';
                           }
                       }
                   }
                   $response .= '<th>'.$lastitem.'</th>'."\n".
                                '<th>'.&mt('Institutional section').'</th>'."\n".
                                '<th>'.&mt('LON-CAPA section').'</th>'."\n".
                                &Apache::loncommon::end_data_table_header_row()."\n";
                   for (my $i=0; $i<$numcross; $i++) {
                       $response .=
                           &Apache::loncommon::start_data_table_row()."\n";
                       foreach my $title (@codetitles) {
                           if (ref($cat_order{$title}) eq 'ARRAY') {
                               if (@{$cat_order{$title}} > 0) {
                                   $response .= '<td align="center">'.
                                                '<select name="newcross_'.$i.'_'.$title.'">'."\n".
                                                ' <option value="" selected="selected">'.
                                                &mt('Select').'</option>'."\n";
                                   foreach my $item (@{$cat_order{$title}}) {
                                       my $longitem = $item;
                                       if (ref($cat_titles{$title}) eq 'HASH') {
                                           if ($cat_titles{$title}{$item} ne '') {
                                               $longitem = $cat_titles{$title}{$item};
                                           }
                                       }
                                       $response .= '<option value="'.$item.'">'.$longitem.
                                                    '</option>'."\n";
                                   }
                                   $response .= '</select></td>'."\n";
                               }
                           }
                       }
                       $response .= '<td align="center">'.
                                    '<input type="text" size="5" name="newcross_'.$i.'_'.$lastitem.'" />'.
                                    '</td>'."\n".'<td align="center">'.
                                    '<input type="text" size="10" name="newcross_'.$i.'_instsec" />'.
                                    '</td>'."\n".'<td align="center">'.
                                    '<input type="text" size="10" name="newlcsec_'.$i.'" /></td>'.
                                    &Apache::loncommon::end_data_table_row()."\n";
                   }
                   $response .= &Apache::loncommon::end_data_table()."\n";
               } else {
                   $response .=              
                       &mt('For each new crosslisting enter the institutional course section code (e.g., fs03zol101001, for section 001 of zol101 for fs03 semester), and the LON-CAPA section ID you wish to assign to students who will be enrolled in your LON-CAPA class as a result of their registration in the crosslisted course section.').' '.
                       &mt('The LON-CAPA section ID can be left blank, if you do not wish to tie a section ID to this crosslisting.').' '.
                       &mt("The institutional course section code should only contain letters and/or numbers, and must be consistent with the scheme adopted by your Domain Coordinator to map course codes (and section numbers) to your institution's student information system.").
                       '<br /><br />'.
                       '<form name="enter" method="post" action="">'."\n".
                       &Apache::loncommon::start_data_table()."\n".
                       &Apache::loncommon::start_data_table_row()."\n".
                       '<th>'.&mt('Crosslisting').'</th>'."\n".
                       '<th>'.&mt('LON-CAPA section ID').'</th>'."\n".
                     &Apache::loncommon::end_data_table_row();                      &Apache::loncommon::end_data_table_row();
     }         for (my $i=0; $i<$numcross; $i++) {
             $response .= &Apache::loncommon::end_data_table().'                     $response .= 
                          &Apache::loncommon::start_data_table_row().'
                          <td><input type="text" size="15" name="newcross_'.$i.'" /></td>
                          <td align="right"><input type="text" size="10" name="newlcsec_'.$i.'" /></td>'.
                          &Apache::loncommon::end_data_table_row();
           }
                   $response .= &Apache::loncommon::end_data_table();
               }
               $response .= '
               </td>                </td>
              </tr>               </tr>
              <tr>               <tr>
Line 2134  sub print_crosslistings_response { Line 2199  sub print_crosslistings_response {
     }      }
     if ($numcross) {      if ($numcross) {
         my %curr_groups = &Apache::longroup::coursegroups();          my %curr_groups = &Apache::longroup::coursegroups();
           my (@codetitles,%cat_titles,%cat_order,@code_order);
           &Apache::lonnet::auto_possible_instcodes($dom,\@codetitles,\%cat_titles,
                                                    \%cat_order,\@code_order);
           my $lastitem = $codetitles[-1];
  for (my $i=0; $i<$numcross; $i++) {   for (my $i=0; $i<$numcross; $i++) {
     my $xl = "newcross_".$i;      my $xl = '';
               if (@code_order > 0) {
                   foreach my $item (@code_order) {
                       my $possval = $env{'form.newcross_'.$i.'_'.$item};
                       if ($item eq $lastitem) {
                           $xl .= $possval;
                       } else {
                           my $possval = $env{'form.newcross_'.$i.'_'.$item};
                           if (ref($cat_order{$item}) eq 'ARRAY') {
                               if (grep(/^\Q$possval\E$/,@{$cat_order{$item}})) {
                                   $xl .= $possval;
                               }
                           }
                       }
                   }
                   if ($xl ne '') {
                       my $crskey = $crs.':'.$xl;
                       if ($env{'form.newcross_'.$i.'_instsec'} ne '') {
                           my $poss_sec = $env{'form.newcross_'.$i.'_instsec'};
                           my %formatted = &Apache::lonnet::auto_instsec_reformat($dom,'clutter',
                                                                                  {$crskey => [$poss_sec]});
                           if (ref($formatted{$crskey}) eq 'ARRAY') {
                               $xl .= $formatted{$crskey}->[0];
                           }
                       }
                   }
               } else {
                   $xl = $env{'form.newcross_'.$i};
               }
     my $lc_sec = "newlcsec_".$i;      my $lc_sec = "newlcsec_".$i;
     if ( exists($env{"form.$xl"}) ) {      if ($xl ne '') {
                 if (exists($env{"form.$lc_sec"})) {                  if (exists($env{"form.$lc_sec"})) {
                     my $lc_sec_check = &validate_lcsec(\%curr_groups,                      my $lc_sec_check = &validate_lcsec(\%curr_groups,
                                                     $env{"form.$lc_sec"});                                                      $env{"form.$lc_sec"});
                     if ($lc_sec_check eq 'reserved') {                      if ($lc_sec_check eq 'reserved') {
                         push(@reserved,$env{"form.$xl"}.":".$env{"form.$lc_sec"});                          push(@reserved,$xl.':'.$env{"form.$lc_sec"});
                         next;                          next;
                     } elsif ($lc_sec_check eq 'group') {                      } elsif ($lc_sec_check eq 'group') {
                         push(@matchgroup,$env{"form.$xl"}.":".$env{"form.$lc_sec"});                          push(@matchgroup,$xl.':'.$env{"form.$lc_sec"});
                         next;                          next;
                     }                      }
                 }                  }
  my $coursecheck =   my $coursecheck =
                     &Apache::lonnet::auto_validate_courseID($crs,$dom,$env{"form.$xl"});                      &Apache::lonnet::auto_validate_courseID($crs,$dom,$xl);
  if ($coursecheck eq 'ok') {   if ($coursecheck eq 'ok') {
     my $addcheck = '';      my $addcheck = '';
     $addcheck = &Apache::lonnet::auto_new_course($crs,$dom,$env{"form.$xl"},$owner,$coowners);      $addcheck = &Apache::lonnet::auto_new_course($crs,$dom,$xl,$owner,$coowners);
     unless ($addcheck eq 'ok') {      unless ($addcheck eq 'ok') {
                         if ($coowners) {                          if ($coowners) {
                             foreach my $user (split(/,/,$coowners)) {                              foreach my $user (split(/,/,$coowners)) {
                                 if ($user =~ /^($match_username):($match_domain)$/) {                                  if ($user =~ /^($match_username):($match_domain)$/) {
                                     if (&Apache::lonnet::auto_validate_inst_crosslist($crs,$dom,$coursecode,                                      if (&Apache::lonnet::auto_validate_inst_crosslist($crs,$dom,$coursecode,
                                                                                       $env{"form.$xl"},$user) eq 'valid') {                                                                                        $xl,$user) eq 'valid') {
                                         $addcheck = 'ok';                                          $addcheck = 'ok';
                                         last;                                          last;
                                     }                                      }
Line 2168  sub print_crosslistings_response { Line 2265  sub print_crosslistings_response {
                         }                          }
                     }                      }
                     if ($addcheck eq 'ok') {                      if ($addcheck eq 'ok') {
                         push(@xlists,$env{"form.$xl"}.":".$env{"form.$lc_sec"});                          push(@xlists,$xl.':'.$env{"form.$lc_sec"});
                     } else {                       } else { 
  push(@badowner,$env{"form.$xl"}.":".$env{"form.$lc_sec"});   push(@badowner,$xl.':'.$env{"form.$lc_sec"});
     }      }
  } else {   } else {
     push(@badxlists,$env{"form.$xl"}.":".$env{"form.$lc_sec"}.":".$coursecheck);      push(@badxlists,$xl.':'.$env{"form.$lc_sec"}.":".$coursecheck);
  }   }
     }      }
  }   }
Line 2193  sub print_crosslistings_response { Line 2290  sub print_crosslistings_response {
                 '<br /><br />';                  '<br /><br />';
  } else {   } else {
     $response = &mt('The courses listed below are now crosslisted with this LON-CAPA course, and students enrolling in these course sections will be automatically added to the class roster for the course, if you have chosen to enable a nightly automated enrollment update.').'<br /><ul>'."\n";      $response = &mt('The courses listed below are now crosslisted with this LON-CAPA course, and students enrolling in these course sections will be automatically added to the class roster for the course, if you have chosen to enable a nightly automated enrollment update.').'<br /><ul>'."\n";
     foreach my $item (@allxlists) {              my @showable;
               &reformat_xlists($dom,$crs,$coursecode,\@allxlists,\@showable);
               foreach my $item (@showable) {
  my ($xlist,$lc_sec) = split(/:/,$item);   my ($xlist,$lc_sec) = split(/:/,$item);
  $response .= '<li>'.&mt('[_1] - ID: [_2]',$xlist,$lc_sec).'</li>'.   $response .= '<li>'.&mt('[_1] - ID: [_2]',$xlist,$lc_sec).'</li>'.
                               "\n";                                "\n";
Line 2205  sub print_crosslistings_response { Line 2304  sub print_crosslistings_response {
     my @oldxlists = split(/,/,$xliststr);      my @oldxlists = split(/,/,$xliststr);
     $response .= &mt('Although no new crosslistings were added, the courses listed below continue to be crosslisted with your LON-CAPA course.').      $response .= &mt('Although no new crosslistings were added, the courses listed below continue to be crosslisted with your LON-CAPA course.').
                          '<br /><ul>'."\n";                           '<br /><ul>'."\n";
     foreach my $xl (@oldxlists) {              my @showable;
               &reformat_xlists($dom,$crs,$coursecode,\@oldxlists,\@showable);
               foreach my $item (@showable) {
  my ($xlist,$lc_sec) = split(/:/,$xl);   my ($xlist,$lc_sec) = split(/:/,$xl);
  $response .= '<li>'.&mt('[_1] - ID: [_2]',$xlist,$lc_sec).'</li>'.   $response .= '<li>'.&mt('[_1] - ID: [_2]',$xlist,$lc_sec).'</li>'.
                              "\n";                               "\n";
Line 2216  sub print_crosslistings_response { Line 2317  sub print_crosslistings_response {
     if (@badxlists > 0) {      if (@badxlists > 0) {
  $response .= &mt("The courses listed below could not be included in the crosslistings for this LON-CAPA course, because they are not valid courses according to your institution's official schedule of classes and sections.").   $response .= &mt("The courses listed below could not be included in the crosslistings for this LON-CAPA course, because they are not valid courses according to your institution's official schedule of classes and sections.").
                      '<br /><ul>'."\n";                       '<br /><ul>'."\n";
  foreach my $item (@badxlists) {          my @showable;
           &reformat_xlists($dom,$crs,$coursecode,\@badxlists,\@showable);
           foreach my $item (@showable) {
     my ($xlist,$lc_sec,$prob) = split(/:/,$item);      my ($xlist,$lc_sec,$prob) = split(/:/,$item);
     $response .= '<li>'.      $response .= '<li>'.
                          &mt('[_1] - ID: [_2] - Error: [_3]',                           &mt('[_1] - ID: [_2] - Error: [_3]',
Line 2228  sub print_crosslistings_response { Line 2331  sub print_crosslistings_response {
     if (@badowner > 0) {      if (@badowner > 0) {
  $response .= &mt("The courses listed below could not be included in the crosslistings for this LON-CAPA course, because the owner of this course - [_1] - does not have rights to view enrollment in those classes, as determined by your instititution's policies on access to official classlists.",$owner).   $response .= &mt("The courses listed below could not be included in the crosslistings for this LON-CAPA course, because the owner of this course - [_1] - does not have rights to view enrollment in those classes, as determined by your instititution's policies on access to official classlists.",$owner).
                      '<br /><ul>'."\n";                       '<br /><ul>'."\n";
  foreach my $item (@badowner) {          my @showable;
           &reformat_xlists($dom,$crs,$coursecode,\@badowner,\@showable);
           foreach my $item (@showable) {
     my ($xlist,$lc_sec) = split(/:/,$item);      my ($xlist,$lc_sec) = split(/:/,$item);
     $response .= '<li>'.&mt('[_1] - ID: [_2]',$xlist,$lc_sec).'</li>'.      $response .= '<li>'.&mt('[_1] - ID: [_2]',$xlist,$lc_sec).'</li>'.
                          "\n";                           "\n";
Line 2240  sub print_crosslistings_response { Line 2345  sub print_crosslistings_response {
                      &mt('Please [_1]go back[_2]</a> and change the section ID for each of these courses.',                       &mt('Please [_1]go back[_2]</a> and change the section ID for each of these courses.',
                          '<a href="javascript:history(-1)">','>/a>').                           '<a href="javascript:history(-1)">','>/a>').
                      '<br /><ul>'."\n";                         '<br /><ul>'."\n";  
         foreach my $item (@reserved) {          my @showable;
           &reformat_xlists($dom,$crs,$coursecode,\@reserved,\@showable);
           foreach my $item (@showable) {
             my ($xlist,$lc_sec) = split(/:/,$item);              my ($xlist,$lc_sec) = split(/:/,$item);
             $response .= '<li>'.&mt('[_1] - ID: [_2]',$xlist,$lc_sec).'</li>'.              $response .= '<li>'.&mt('[_1] - ID: [_2]',$xlist,$lc_sec).'</li>'.
                          "\n";                           "\n";
Line 2252  sub print_crosslistings_response { Line 2359  sub print_crosslistings_response {
         $response .= &mt('The courses listed below could not be included in the crosslistings for this LON-CAPA course, because the section ID associated with the crosslisted course is the name of a group in this course.').' '.          $response .= &mt('The courses listed below could not be included in the crosslistings for this LON-CAPA course, because the section ID associated with the crosslisted course is the name of a group in this course.').' '.
                      &mt('Please [_1]go back[_2] and change the section ID for each of these courses.','<a href="javascript:history(-1)">','</a>').                       &mt('Please [_1]go back[_2] and change the section ID for each of these courses.','<a href="javascript:history(-1)">','</a>').
                      '<br /><ul>'."\n";                       '<br /><ul>'."\n";
         foreach my $item (@matchgroup) {          my @showable;
           &reformat_xlists($dom,$crs,$coursecode,\@matchgroup,\@showable);
           foreach my $item (@showable) {
             my ($xlist,$lc_sec) = split(/:/,$item);              my ($xlist,$lc_sec) = split(/:/,$item);
             $response .= '<li>'.&mt('[_1] - ID: [_2]',$xlist,$lc_sec).'</li>'.              $response .= '<li>'.&mt('[_1] - ID: [_2]',$xlist,$lc_sec).'</li>'.
                          "\n";                           "\n";
Line 2272  sub print_crosslistings_response { Line 2381  sub print_crosslistings_response {
     return;      return;
 }  }
   
   sub reformat_xlists {
       my ($dom,$crs,$coursecode,$xlistsref,$showxlistsref) = @_;
       return unless ((ref($xlistsref) eq 'ARRAY') && (ref($showxlistsref) eq 'ARRAY'));
       my $crskey = $crs.':'.$coursecode;
       my (@xlcodes,@lcsecs,@extras);
       foreach my $xl (@{$xlistsref}) {
           my ($instcodesec,$lc_sec,$extra) = split(/:/,$xl);
           push(@xlcodes,$instcodesec);
           push(@lcsecs,$lc_sec);
           push(@extras,$extra);
       }
       my %reformatted =
           &Apache::lonnet::auto_instsec_reformat($dom,'declutter',
                                                  {$crskey => \@xlcodes});
       if (ref($reformatted{$crskey}) eq 'ARRAY') {
           @xlcodes = @{$reformatted{$crskey}};
           for (my $i=0; $i<@xlcodes; $i++) {
               my $value = $xlcodes[$i].':'.$lcsecs[$i];
               if ($extras[$i] ne '') {
                   $value .= ':'.$extras[$i];
               }
               push(@{$showxlistsref},$value);
           }
       }
       return;
   }
   
 sub print_sections_menu {  sub print_sections_menu {
     my ($r,$realm,$dom,$crs,$action,$tasktitleref) = @_;      my ($r,$realm,$dom,$crs,$action,$tasktitleref) = @_;
     my %settings =       my %settings = 
Line 2814  sub print_photoupdate_response { Line 2950  sub print_photoupdate_response {
  'internal.sectionnums',   'internal.sectionnums',
  'internal.crosslistings'],   'internal.crosslistings'],
  $dom,$crs);   $dom,$crs);
     &Apache::loncommon::get_institutional_codes(\%settings,\@allcourses,\%LC_code);      &Apache::loncommon::get_institutional_codes($dom,$crs,\%settings,\@allcourses,\%LC_code);
     if (@allcourses > 0) {      if (@allcourses > 0) {
         @{$affiliates{$crs}} = @allcourses;          @{$affiliates{$crs}} = @allcourses;
         $outcome = &Apache::lonnet::auto_photoupdate(\%affiliates,$dom,$crs,\%changes);          $outcome = &Apache::lonnet::auto_photoupdate(\%affiliates,$dom,$crs,\%changes);
Line 2944  sub print_update_result { Line 3080  sub print_update_result {
  $response = &mt('There was a problem retrieving the course code for this LON-CAPA course.').' '.   $response = &mt('There was a problem retrieving the course code for this LON-CAPA course.').' '.
                     &mt('An update of the class roster has not been carried out, and enrollment remains unchanged.');                      &mt('An update of the class roster has not been carried out, and enrollment remains unchanged.');
     } else {      } else {
         &Apache::loncommon::get_institutional_codes(\%settings,\@allcourses,\%LC_code);          &Apache::loncommon::get_institutional_codes($dom,$crs,\%settings,\@allcourses,\%LC_code);
  if (@allcourses > 0) {   if (@allcourses > 0) {
     @{$affiliates{$crs}} = @allcourses;      @{$affiliates{$crs}} = @allcourses;
     my $outcome = &Apache::lonnet::fetch_enrollment_query('updatenow',\%affiliates,\%reply,$dom,$crs);      my $outcome = &Apache::lonnet::fetch_enrollment_query('updatenow',\%affiliates,\%reply,$dom,$crs);

Removed from v.1.86  
changed lines
  Added in v.1.87


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