Diff for /loncom/interface/lonpopulate.pm between versions 1.18 and 1.19

version 1.18, 2004/08/23 16:32:35 version 1.19, 2004/08/23 16:53:06
Line 35  use Apache::loncoursedata; Line 35  use Apache::loncoursedata;
 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 localenroll;  
   
 ###############################################################  ###############################################################
 sub header {  sub header {
Line 1303  sub print_setdates_response { Line 1302  sub print_setdates_response {
     my $currstart = $settings{'internal.autostart'};      my $currstart = $settings{'internal.autostart'};
     my $currend = $settings{'internal.autoend'};      my $currend = $settings{'internal.autoend'};
     my $response = '';      my $response = '';
     my ($autostart,$autoend) = &get_dates_from_form();      my $showstart = '';
     my $showstart = &Apache::lonlocal::locallocaltime($autostart);  
     my $showend = '';      my $showend = '';
     my $warning = '';      my $warning = '';
     my $warn_prefix = '';      my $warn_prefix = '';
     if ($autoend) {      my ($autostart,$autoend) = &get_dates_from_form();
  $showend = &Apache::lonlocal::locallocaltime($autoend);      if ( ($autostart eq '') || ($autoend eq '') ) {
     } else {          $response = "There was a problem processing your requested changes. The automated enrollment settings for this course have been left unchanged.<br/>";
  $showend = "'No end date'";      } elsif (($autoend > 0) && ($autoend <= $autostart)) {
     }           $response = 'The date/time selected for starting auto-enrollment was the same or later than the date/time selected for ending auto-enrollment. As this means auto-enrollment will never be active, your requested changes have not been processed, and the existing values remain in effect. Please <a href="javascript:history.go(-1)">go back</a> to the previous page to try your changes again.'."\n";
       } else {       
           $showstart = &Apache::lonlocal::locallocaltime($autostart);
           if ($autoend) {
       $showend = &Apache::lonlocal::locallocaltime($autoend);
           } else {
       $showend = "'No end date'";
           } 
   
     my %cenv = ('internal.autostart' => $autostart,          my %cenv = ('internal.autostart' => $autostart,
  'internal.autoend' => $autoend);       'internal.autoend' => $autoend);
     my $reply = &Apache::lonnet::put('environment',\%cenv,$dom,$crs);          my $reply = &Apache::lonnet::put('environment',\%cenv,$dom,$crs);
     if ($reply !~ /^ok$/) {          if ($reply !~ /^ok$/) {
  $response = "There was a problem processing your requested changes. The automated enrollment settings for this course have been left unchanged.<br/>";      $response = "There was a problem processing your requested changes. The automated enrollment settings for this course have been left unchanged.<br/>";
     } else {          } else {
  if ($currstart == $autostart) {      if ($currstart == $autostart) {
     $response = "The first date for automated enrollment has been left unchanged as $showstart.<br/>";          $response = "The first date for automated enrollment has been left unchanged as $showstart.<br/>";
  } else {      } else {
     $response = "The first date for automated enrollment has been changed to $showstart.<br/>";          $response = "The first date for automated enrollment has been changed to $showstart.<br/>";
  }       } 
  if ($currend == $autoend) {      if ($currend == $autoend) {
     $response .= "The last date for automated enrollment has been left unchanged as $showend.<br/>";          $response .= "The last date for automated enrollment has been left unchanged as $showend.<br/>";
  } else {      } else {
     $response .= "The last date for automated enrollment has been changed to $showend.<br/>";          $response .= "The last date for automated enrollment has been changed to $showend.<br/>";
  }      }
     
 # Generate message in case where old first enrollment date was later than today, but new first enrollment date is now today or earlier.  # Generate message in case where old first enrollment date was later than today, but new first enrollment date is now today or earlier.
   
  my $rosterupdated = 0;      my $rosterupdated = 0;
  my $firstaccess = "";      my $firstaccess = "";
  my $nextupdate = "";      my $nextupdate = "";
  my $lastupdate = "";      my $lastupdate = "";
   
  my $nowstamp = time;      my $nowstamp = time;
  my @date_list=localtime(time);      my @date_list=localtime(time);
  my $cur_year = $date_list[5];      my $cur_year = $date_list[5];
  my $curday = $date_list[3];      my $curday = $date_list[3];
  my $curmonth = $date_list[4];      my $curmonth = $date_list[4];
  my $lastmidnt = timelocal(0,0,0,$date_list[3],$date_list[4],$date_list[5]);      my $lastmidnt = timelocal(0,0,0,$date_list[3],$date_list[4],$date_list[5]);
  my $nextmidnt = 86400 + $lastmidnt;      my $nextmidnt = 86400 + $lastmidnt;
   
  my $todayupdate = timelocal(0,30,1,$date_list[3],$date_list[4],$date_list[5]);      my $todayupdate = timelocal(0,30,1,$date_list[3],$date_list[4],$date_list[5]);
  my $lastupdate = $todayupdate - 86400;      my $lastupdate = $todayupdate - 86400;
  if ($nowstamp < $todayupdate) {      if ($nowstamp < $todayupdate) {
     $nextupdate = "today";        $nextupdate = "today";
  } else {  
     $nextupdate = "tomorrow";  
  }  
  if ($currstart < $lastupdate) {  
     $rosterupdated = 1;  
  }  
  if ($autostart < $nextmidnt ) {  
     if ( $autostart >= $lastmidnt) {  
  $firstaccess = "today";  
     } else {      } else {
  $firstaccess = "a date prior to today";        $nextupdate = "tomorrow";
     }      }
     if (($nowstamp >= $autostart) && ($rosterupdated == 0)) {      if ($currstart < $lastupdate) {
  $response .= qq|<br>Although you have now set the first enrollment date to $firstaccess, automatic enrollment will <b>not</b> occur until the next automatic enrollment update occurs for all LON-CAPA courses at 1.30 am $nextupdate. If you wish to immediately enroll registered students included in the institutional classlist for this class, please visit the <a href="/adm/populate?action=updatenow">roster update page</a>.<br>|;          $rosterupdated = 1;
     }      }
  }      if ($autostart < $nextmidnt ) {
  $warning = &warning_message($dom,$crs,$action);          if ( $autostart >= $lastmidnt) {
  $warn_prefix = "<br/><font size ='+1'><b>Warning</b></font>. Although you set a start and end date for auto-enrollment, additional action is required.<br/>";      $firstaccess = "today";
  unless ($warning eq '') {          } else {
     $response .= $warn_prefix.$warning;        $firstaccess = "a date prior to today";
  }          }
           if (($nowstamp >= $autostart) && ($rosterupdated == 0)) {
       $response .= qq|<br>Although you have now set the first enrollment date to $firstaccess, automatic enrollment will <b>not</b> occur until the next automatic enrollment update occurs for all LON-CAPA courses at 1.30 am $nextupdate. If you wish to immediately enroll registered students included in the institutional classlist for this class, please visit the <a href="/adm/populate?action=updatenow">roster update page</a>.<br>|;
           }
       }
       $warning = &warning_message($dom,$crs,$action);
       $warn_prefix = "<br/><font size ='+1'><b>Warning</b></font>. Although you set a start and end date for auto-enrollment, additional action is required.<br/>";
       unless ($warning eq '') {
           $response .= $warn_prefix.$warning;
       }
           }
     }      }
     &print_reply($r,$response,$$tasktitleref{$action});      &print_reply($r,$response,$$tasktitleref{$action});
     return;      return;
Line 1384  sub print_setaccess_response { Line 1390  sub print_setaccess_response {
     my $autostart = $settings{'internal.autostart'};      my $autostart = $settings{'internal.autostart'};
     my $response = '';      my $response = '';
     my ($startaccess,$endaccess) = &get_dates_from_form();      my ($startaccess,$endaccess) = &get_dates_from_form();
     my $showstart = &Apache::lonlocal::locallocaltime($startaccess);      if (($startaccess eq '') || ($endaccess eq '')) {
     my $showend = '';          $response = "There was a problem processing your requested changes. The default
     my $warning = '';  start and end access dates for this course have been left unchanged.<br/>";
     my $warn_prefix = '';      } elsif (($endaccess > 0) && ($endaccess <= $startaccess)) {
     if ($endaccess) {          $response = 'The default start access date/time you chose was the same or later than the default end access date/time. As this means that roles will never be active, your requested changes have not been processed, and the existing values remain in effect. Please <a href="javascript:history.go(-1)">go back</a> to the previous page to try your changes again.'."\n"; 
  $showend = &Apache::lonlocal::locallocaltime($endaccess);  
     } else {      } else {
  $showend = "'No end date'";          my $showstart = &Apache::lonlocal::locallocaltime($startaccess);
     }          my $showend = '';
           my $warning = '';
           my $warn_prefix = '';
           if ($endaccess) {
       $showend = &Apache::lonlocal::locallocaltime($endaccess);
           } else {
       $showend = "'No end date'";
           }
   
     my %cenv = ('default_enrollment_start_date' => $startaccess,          my %cenv = ('default_enrollment_start_date' => $startaccess,
  'default_enrollment_end_date' => $endaccess);   'default_enrollment_end_date' => $endaccess);
     my $reply = &Apache::lonnet::put('environment',\%cenv,$dom,$crs);          my $reply = &Apache::lonnet::put('environment',\%cenv,$dom,$crs);
     if ($reply !~ /^ok$/) {          if ($reply !~ /^ok$/) {
  $response = "There was a problem processing your requested changes. The automated enrollment settings for this course have been left unchanged.<br/>";      $response = "There was a problem processing your requested changes. The automated enrollment settings for this course have been left unchanged.<br/>";
     } else {          } else {
  if ($currstart == $startaccess) {      if ($currstart == $startaccess) {
     $response = "The first access date for students added via automated enrollment has been left unchanged as $showstart.<br/>";          $response = "The first access date for students added via automated enrollment has been left unchanged as $showstart.<br/>";
  } else {      } else {
     $response = "The first access date for students added via automated enrollment has been changed to          $response = "The first access date for students added via automated enrollment has been changed to
 $showstart.<br/>";  $showstart.<br/>";
  }      }
  if ($currend == $endaccess) {      if ($currend == $endaccess) {
     $response .= "The last access date for students added via automated enrollment has been left unchanged as $showend.<br/>";          $response .= "The last access date for students added via automated enrollment has been left unchanged as $showend.<br/>";
  } else {      } else {
     $response .= "The last access date for students automated enrollment has been changed to          $response .= "The last access date for students automated enrollment has been changed to
 $showend.<br/>";  $showend.<br/>";
  }      }
   
 # Generate message in case where old first access date was later than today, but new first access date is now today or earlier.  # Generate message in case where old first access date was later than today, but new first access date is now today or earlier.
   
  my $accessgiven= 0;      my $accessgiven= 0;
  my $firstaccess = "";      my $firstaccess = "";
  my $nextupdate = "";      my $nextupdate = "";
  my $lastupdate = "";      my $lastupdate = "";
   
  my $nowstamp = time;      my $nowstamp = time;
  my @date_list=localtime(time);      my @date_list=localtime(time);
  my $cur_year = $date_list[5];      my $cur_year = $date_list[5];
  my $curday = $date_list[3];      my $curday = $date_list[3];
  my $curmonth = $date_list[4];      my $curmonth = $date_list[4];
  my $lastmidnt = timelocal(0,0,0,$date_list[3],$date_list[4],$date_list[5]);      my $lastmidnt = timelocal(0,0,0,$date_list[3],$date_list[4],$date_list[5]);
  my $nextmidnt = 86400 + $lastmidnt;      my $nextmidnt = 86400 + $lastmidnt;
   
  my $todayupdate = timelocal(0,30,1,$date_list[3],$date_list[4],$date_list[5]);      my $todayupdate = timelocal(0,30,1,$date_list[3],$date_list[4],$date_list[5]);
  my $tomorrowupdate = $todayupdate + 86400;      my $tomorrowupdate = $todayupdate + 86400;
  my $lastupdate = $todayupdate - 86400;      my $lastupdate = $todayupdate - 86400;
   
  if ($autostart < $nextmidnt) {      if ($autostart < $nextmidnt) {
     if ($nowstamp < $todayupdate) {          if ($nowstamp < $todayupdate) {
  $nextupdate = "at 1.30 am today";      $nextupdate = "at 1.30 am today";
     } else {          } else {
  $nextupdate = "at 1.30 am tomorrow";      $nextupdate = "at 1.30 am tomorrow";
     }          }
  } else {  
     my @enrollstart = localtime($autostart);  
     $nextupdate = timelocal(0,30,1,$enrollstart[3],$enrollstart[4],$enrollstart[5]);  
     unless (($enrollstart[2] < 1) || ($enrollstart[2] == 1 && $enrollstart[1] <=30))  {  
  $nextupdate += 86400;   
     }  
     $nextupdate = &Apache::lonlocal::locallocaltime($nextupdate);  
  }  
  if (($currstart < $lastupdate) && ($autostart < $lastupdate)) {  
     $accessgiven = 1;  
  }  
  if ($startaccess < $nextmidnt ) {  
     if ( $startaccess >= $lastmidnt) {  
  $firstaccess = "today";  
     } else {      } else {
  $firstaccess = "a date prior to today";          my @enrollstart = localtime($autostart);
           $nextupdate = timelocal(0,30,1,$enrollstart[3],$enrollstart[4],$enrollstart[5]);
           unless (($enrollstart[2] < 1) || ($enrollstart[2] == 1 && $enrollstart[1] <=30))  {
       $nextupdate += 86400; 
           }
           $nextupdate = &Apache::lonlocal::locallocaltime($nextupdate);
       }
       if (($currstart < $lastupdate) && ($autostart < $lastupdate)) {
           $accessgiven = 1;
       }
       if ($startaccess < $nextmidnt ) {
           if ( $startaccess >= $lastmidnt) {
           $firstaccess = "today";
           } else {
       $firstaccess = "a date prior to today";
           }
           if (($nowstamp >= $startaccess) && ($accessgiven == 0)) {
       $response .= qq|<br>Although you have now set the first access date to $firstaccess, automatic enrollment will <b>not</b> occur until the next automatic enrollment update occurs for all LON-CAPA courses $nextupdate. If you wish to grant immediate course access for registered students included in the institutional classlist for this class, please visit the <a href="/adm/populate?action=updatenow">roster update page</a>.<br>|;
           }
     }      }
     if (($nowstamp >= $startaccess) && ($accessgiven == 0)) {      $warning = &warning_message($dom,$crs,$action);
  $response .= qq|<br>Although you have now set the first access date to $firstaccess, automatic enrollment will <b>not</b> occur until the next automatic enrollment update occurs for all LON-CAPA courses $nextupdate. If you wish to grant immediate course access for registered students included in the institutional classlist for this class, please visit the <a href="/adm/populate?action=updatenow">roster update page</a>.<br>|;      $warn_prefix = "<br/><font size ='+1'><b>Warning</b></font>. Although you have set default first and last access dates for students who are added via automatic enrollment, additional action is required.<br/>";
       unless ($warning eq '') {
           $response .= $warn_prefix.$warning;
     }      }
  }          }
  $warning = &warning_message($dom,$crs,$action);  
  $warn_prefix = "<br/><font size ='+1'><b>Warning</b></font>. Although you have set default first and last access dates for students who are added via automatic enrollment, additional action is required.<br/>";  
  unless ($warning eq '') {  
     $response .= $warn_prefix.$warning;  
  }  
     }      }
     &print_reply($r,$response,$$tasktitleref{$action});      &print_reply($r,$response,$$tasktitleref{$action});
     return;      return;
Line 2106  sub print_update_result () { Line 2119  sub print_update_result () {
     my $authtype = $settings{'internal.authtype'};      my $authtype = $settings{'internal.authtype'};
     my $autharg = $settings{'internal.autharg'};      my $autharg = $settings{'internal.autharg'};
     my ($startaccess,$endaccess) = &get_dates_from_form();      my ($startaccess,$endaccess) = &get_dates_from_form();
       
     if ( exists($ENV{'form.updateadds'}) ) {      if ( exists($ENV{'form.updateadds'}) ) {
  $updateadds = $ENV{'form.updateadds'};          $updateadds = $ENV{'form.updateadds'};
     }      }
     if ( exists($ENV{'form.updatedrops'}) ) {      if ( exists($ENV{'form.updatedrops'}) ) {
  $updatedrops = $ENV{'form.updatedrops'};          $updatedrops = $ENV{'form.updatedrops'};
     }      }
     if (!$updateadds && !$updatedrops) {      if (($startaccess eq '') || ($endaccess eq '')) {
           $response = "There was a problem processing your requested roster update because start and and access dates could not be determined. No changes have been made to the class roster.<br />"; 
       } elsif ($updateadds && (($endaccess > 0) && ($endaccess <= $startaccess))) {
           $response = 'The start access date/time is the same or later than the end access date/time. As this means that new roles will never be active, your requested roster update has not been carried out, and the roster remains unchanged. Please <a href="javascript:history.go(-1)">go back</a> to the previous page to try your changes again.'."\n";
       } elsif (!$updateadds && !$updatedrops) {
  $response = "An update of the class roster has not been carried out because you indicated that you wanted to neither add new students, nor expire dropped students based on a comparison between the institutional class lists for the course sections and crosslisted courses that contribure enrollment to this LON-CAPA course.";   $response = "An update of the class roster has not been carried out because you indicated that you wanted to neither add new students, nor expire dropped students based on a comparison between the institutional class lists for the course sections and crosslisted courses that contribure enrollment to this LON-CAPA course.";
     } elsif ($coursecode eq '') {      } elsif ($coursecode eq '') {
  $response = "There was a problem retrieving the course code for this LON-CAPA course.  An update of the class roster has not been carried out, and enrollment remains unchanged";   $response = "There was a problem retrieving the course code for this LON-CAPA course.  An update of the class roster has not been carried out, and enrollment remains unchanged";
Line 2161  sub print_update_result () { Line 2177  sub print_update_result () {
  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);
               unless ($outcome eq 'ok') {
                   &Apache::lonnet::logthis("lonpopulate:update roster".
                                            "failed to retrieve classlist".
                                    " data for ".$crs."\@".$dom." by ".
                                    $ENV{'user.name'}." \@ ".$ENV{'user.domain'}.
                                    ": ".$outcome);
               }
     if ($reply{$crs} > 0) {      if ($reply{$crs} > 0) {
  ($changecount,$response) = &LONCAPA::Enrollment::update_LC($dom,$crs,$updateadds,$updatedrops,$startaccess,$endaccess,$authtype,$autharg,\@allcourses,\%LC_code,\$logmsg,\$newusermsg,"updatenow");   ($changecount,$response) = &LONCAPA::Enrollment::update_LC($dom,$crs,$updateadds,$updatedrops,$startaccess,$endaccess,$authtype,$autharg,\@allcourses,\%LC_code,\$logmsg,\$newusermsg,"updatenow");
     } else {      } else {
Line 2177  sub print_update_result () { Line 2200  sub print_update_result () {
     }      }
     unless ($newusermsg eq '') {      unless ($newusermsg eq '') {
  $newusermsg = substr( $newusermsg,0,rindex($newusermsg,'<li>') );   $newusermsg = substr( $newusermsg,0,rindex($newusermsg,'<li>') );
  $newusermsg = "<br/><br/>The following new system user(s) who was/were created will be using internal authentication with an initial randomly generated password. A valid e-mail address was not available for this/these user(s) so LON-CAPA account credentials could not be sent via e-mail.<br/><ul><li>".$newusermsg."</ul><br/>";   $newusermsg = "<br/><br/>The following new system user(s) who was/were created will be using local or internal authentication with an initial randomly generated password. A valid e-mail address was not available for this/these user(s) so LON-CAPA account credentials could not be sent via e-mail.<br/><ul><li>".$newusermsg."</ul><br/>";
     }      }
     $response .= $logmsg.$newusermsg;      $response .= $logmsg.$newusermsg;
     &print_reply($r,$response,$$tasktitleref{$action});      &print_reply($r,$response,$$tasktitleref{$action});

Removed from v.1.18  
changed lines
  Added in v.1.19


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