--- loncom/interface/lonpopulate.pm 2004/01/15 01:47:21 1.9 +++ loncom/interface/lonpopulate.pm 2004/06/08 22:09:44 1.12 @@ -1,5 +1,5 @@ # automated enrollment configuration handler -# $Id: lonpopulate.pm,v 1.9 2004/01/15 01:47:21 raeburn Exp $ +# $Id: lonpopulate.pm,v 1.12 2004/06/08 22:09:44 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -207,7 +207,7 @@ ENDONE ############################################################### sub print_main_frame { - my ($r,$realm,$dom,$crs,$tasktitleref) = @_; + my ($r,$realm,$dom,$crs,$tasktitleref,$homeserver,$server) = @_; my $action = "information"; if (exists($ENV{'form.action'}) ) { $action = $ENV{'form.action'}; @@ -329,17 +329,29 @@ Note: Any students added manually by cou "); } elsif ($action eq "setdates") { my ($start_table,$end_table) = &date_setting_table($enrollvar{autostart},$enrollvar{autoend}); - my $oldstartshow = localtime($enrollvar{autostart}); - my $oldendshow = localtime($enrollvar{autoend}); - if ($enrollvar{autoend} == 0) { - $oldendshow = "No ending date"; + my $oldstartshow = ''; + my $oldendshow = ''; + if ( defined($enrollvar{autostart}) ) { + $oldstartshow = localtime($enrollvar{autostart}); + } + if ( defined($enrollvar{autoend}) ) { + $oldendshow = localtime($enrollvar{autoend}); + if ($enrollvar{autoend} == 0) { + $oldendshow = "No ending date"; + } + } + my $dateshow; + if ( ($oldendshow eq '') && ($oldstartshow eq '') ) { + $dateshow = "
Warning. Currently NO first enrollment or last enrollment dates are set. You must use this menu to set a start date and an end date (or check the 'no ending date' checkbox) if you plan to utilise automated adds and/or drops in this course.\n"; + } else { + $dateshow = "Currently: First enrollment: $oldstartshow, Last enrollment: $oldendshow\n"; } $r->print(<
-
$$tasktitleref{$action}
- Currently: First enrollment: $oldstartshow, Last enrollment: $oldendshow +
$$tasktitleref{$action}

+ $dateshow
@@ -629,7 +641,8 @@ ENDTWO "); } elsif ($action eq "sections") { - my @sections = &localenroll::get_sections($enrollvar{coursecode}); + my @sections = (); + @sections = &Apache::lonnet::auto_get_sections($homeserver,$enrollvar{coursecode}); my @storedsections = (); my @currsections = (); my %sec_id = (); @@ -885,9 +898,31 @@ ENDBASE ################################################################### sub print_chgsettings_response { my ($r,$realm,$dom,$crs,$action,$tasktitleref) = @_; - my %settings = &Apache::lonnet::get('environment',['internal.autoadds','internal.autodrops'],$dom,$crs); - my $curradds = $settings{'internal.autoadds'}; - my $currdrops = $settings{'internal.autodrops'}; + my %settings = &Apache::lonnet::get('environment',['internal.sectionnums','internal.crosslistings','internal.autostart','internal.autoend','internal.autoadds','internal.autodrops'],$dom,$crs); + my $currend = ''; + my $currstart = ''; + my $currsecs = ''; + my $currxlists = ''; + my $curradds = ''; + my $currdrops = ''; + if ( defined($settings{'internal.autoadds'}) ) { + $curradds = $settings{'internal.autoadds'}; + } + if ( defined($settings{'internal.autodrops'}) ) { + $currdrops = $settings{'internal.autodrops'}; + } + if ( defined($settings{'internal.autostart'}) ) { + $currstart = $settings{'internal.autostart'}; + } + if ( defined($settings{'internal.autoend'}) ) { + $currend = $settings{'internal.autoend'}; + } + if ( defined($settings{'internal.sectionnums'}) ) { + $currsecs = $settings{'internal.sectionnums'}; + } + if ( defined($settings{'internal.crosslistings'}) ) { + $currxlists = $settings{'internal.crosslistings'} + } my $autoadds = ''; my $autodrops = ''; @@ -899,6 +934,10 @@ sub print_chgsettings_response { } my $response = ""; + my $warning = ""; + my $warn_prefix = ""; + my $warn_suffix = ""; + my $warnfiller = ""; my %cenv = ('internal.autoadds' => $autoadds, 'internal.autodrops' => $autodrops); my $reply = &Apache::lonnet::put('environment',\%cenv,$dom,$crs); @@ -910,7 +949,7 @@ sub print_chgsettings_response { $response = "Nightly additions based on classlist changes still enabled
"; } else { $response = "Nightly additions based on classlist changes now enabled
"; - } + } } else { if ($curradds) { $response = "Nightly additions based on classlist changes now disabled
"; @@ -931,6 +970,25 @@ sub print_chgsettings_response { $response .= "Nightly removals based on classlist changes still disabled"; } } + if ($autoadds || $autodrops) { + $warning = &warning_message($dom,$crs,$action); + $warn_prefix = "
Warning. Although you indicated that nightly "; + $warn_suffix = " should be enabled, additional action is required.
"; + } + if ($autoadds) { + if ($autodrops) { + $warnfiller = "adds and drops"; + } else { + $warnfiller = "adds"; + } + } else { + if ($autodrops) { + $warnfiller = "drops"; + } + } + unless ($warning eq '') { + $response = $warn_prefix.$warnfiller.$warn_suffix.$warning; + } } &print_reply($r,$response,$$tasktitleref{$action}); return; @@ -945,6 +1003,8 @@ sub print_setdates_response { my ($autostart,$autoend) = &get_dates_from_form(); my $showstart = localtime($autostart); my $showend = ''; + my $warning = ''; + my $warn_prefix = ''; if ($autoend) { $showend = localtime($autoend); } else { @@ -983,7 +1043,7 @@ sub print_setdates_response { my $lastmidnt = timelocal(0,0,0,$date_list[3],$date_list[4],$date_list[5]); my $nextmidnt = 86400 + $lastmidnt; - my $todayupdate = timelocal(0,40,4,$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; if ($nowstamp < $todayupdate) { $nextupdate = "today"; @@ -1000,9 +1060,14 @@ sub print_setdates_response { $firstaccess = "a date prior to today"; } if (($nowstamp >= $autostart) && ($rosterupdated == 0)) { - $response .= qq|
Although you have now set the first enrollment date to $firstaccess, automatic enrollment will not occur until the next automatic enrollment update occurs for all LON-CAPA courses at 4.40 am $nextupdate. If you wish to grant immediate course access for registered students included in the institutional classlist for this class, please visit the roster update page.
|; + $response .= qq|
Although you have now set the first enrollment date to $firstaccess, automatic enrollment will not occur until the next automatic enrollment update occurs for all LON-CAPA courses at 1.30 am $nextupdate. If you wish to grant immediate course access for registered students included in the institutional classlist for this class, please visit the roster update page.
|; } } + $warning = &warning_message($dom,$crs,$action); + $warn_prefix = "
Warning. Although you set a start and end date for auto-enrollment, additional action is required.
"; + unless ($warning eq '') { + $response .= $warn_prefix.$warning; + } } &print_reply($r,$response,$$tasktitleref{$action}); return; @@ -1092,7 +1157,7 @@ sub print_notify_response { } sub print_crosslistings_menu () { - my ($r,$realm,$dom,$crs,$action,$tasktitleref) = @_; + my ($r,$realm,$dom,$crs,$action,$tasktitleref,$homeserver,$server) = @_; my %settings = &Apache::lonnet::get('environment',['internal.crosslistings','internal.coursecode'],$dom,$crs); my @currxlists = (); my @xlists = (); @@ -1195,7 +1260,7 @@ sub print_crosslistings_menu () { } sub print_crosslistings_response () { - my ($r,$realm,$dom,$crs,$action,$tasktitleref) = @_; + my ($r,$realm,$dom,$crs,$action,$tasktitleref,$homeserver,$server) = @_; my %settings = &Apache::lonnet::get('environment',['internal.crosslistings','internal.coursecode','internal.courseowner'],$dom,$crs); my @currxlists = (); my @xlists = (); @@ -1207,6 +1272,8 @@ sub print_crosslistings_response () { my $coursecode = $settings{'internal.coursecode'}; my $owner = $settings{'internal.courseowner'}; my $response = ''; + my $warning = ''; + my $warn_prefix = ''; if ($xliststr =~ m/,/) { @allxlists = split/,/,$xliststr; @@ -1223,14 +1290,24 @@ sub print_crosslistings_response () { my $xl = "newcross_".$i; my $gp = "newgroupid_".$i; if ( exists($ENV{"form.$xl"}) ) { - my $coursecheck = &localenroll::validate_courseID($ENV{"form.$xl"}); + my $coursecheck = ''; +# if ($homeserver eq $server) { +# $coursecheck = &localenroll::validate_courseID($ENV{"form.$xl"}); +# } else { + $coursecheck = &Apache::lonnet::auto_validate_courseID($homeserver,$ENV{"form.$xl"}); +# } if ($coursecheck eq 'ok') { - my $addcheck = &localenroll::new_course($ENV{"form.$xl"},$owner); + my $addcheck = ''; +# if ($homeserver eq $server) { +# $addcheck = &localenroll::new_course($ENV{"form.$xl"},$owner); +# } else { + $addcheck = &Apache::lonnet::auto_new_course($homeserver,$ENV{"form.$xl"},$owner); +# } if ($addcheck eq 'ok') { push @xlists,$ENV{"form.$xl"}.":".$ENV{"form.$gp"}; } else { push @badowner,$ENV{"form.$xl"}.":".$ENV{"form.$gp"}; - } + } } else { push @badxlists, $ENV{"form.$xl"}.":".$ENV{"form.$gp"}.":".$coursecheck; } @@ -1292,12 +1369,20 @@ sub print_crosslistings_response () { $response .= "

\n"; } + if (@allxlists > 0) { + $warning = &warning_message($dom,$crs,$action); + $warn_prefix = "
Warning. Although you have selected crosslisted courses to contribute enrollment to this course, additional action is required.
"; + unless ($warning eq '') { + $response .= $warn_prefix.$warning; + } + } + &print_reply($r,$response,$$tasktitleref{$action}); return; } sub print_sections_menu () { - my ($r,$realm,$dom,$crs,$action,$tasktitleref) = @_; + my ($r,$realm,$dom,$crs,$action,$tasktitleref,$homeserver,$server) = @_; my %settings = &Apache::lonnet::get('environment',['internal.sectionnums','internal.coursecode','internal.courseowner'],$dom,$crs); my @currsections = (); my @sections = (); @@ -1308,6 +1393,8 @@ sub print_sections_menu () { my $addcount = 0; my $secstr = ''; my $response = ''; + my $warning = ""; + my $warn_prefix = ""; my $coursecode = $settings{'internal.coursecode'}; my $owner = $settings{'internal.courseowner'}; if ($settings{'internal.sectionnums'} =~ m/,/) { @@ -1334,9 +1421,19 @@ sub print_sections_menu () { $seccount ++; } else { my $newsec = $coursecode.$ENV{"form.$secnum"}; - my $coursecheck = &localenroll::validate_courseID($newsec); + my $coursecheck = ''; +# if ($homeserver eq $server) { +# $coursecheck = &localenroll::validate_courseID($newsec); +# } else { + $coursecheck = &Apache::lonnet::auto_validate_courseID($homeserver,$newsec); +# } if ($coursecheck eq 'ok') { - my $addcheck = &localenroll::new_course($newsec,$owner); + my $addcheck = ''; +# if ($homeserver eq $server) { +# $addcheck = &localenroll::new_course($newsec,$owner); +# } else { + $addcheck = &Apache::lonnet::auto_new_course($homeserver,$newsec,$owner); +# } if ($addcheck eq 'ok') { push @sections,$ENV{"form.$secnum"}.":".$ENV{"form.$gp"}; $seccount ++; @@ -1425,6 +1522,14 @@ sections which contribute to enrollment $response .= "

\n"; } + if ($seccount > 0) { + $warning = &warning_message($dom,$crs,$action); + $warn_prefix = "
Warning. Although you have selected sections to contribute enrollment to this course, additional action is required.
"; + unless ($warning eq '') { + $response .= $warn_prefix.$warning; + } + } + if ( exists($ENV{'form.numsec'}) ) { my $numsec = $ENV{'form.numsec'}; if ($numsec > 0) { @@ -1471,7 +1576,7 @@ sections which contribute to enrollment } sub print_sections_response () { - my ($r,$realm,$dom,$crs,$action,$tasktitleref) = @_; + my ($r,$realm,$dom,$crs,$action,$tasktitleref,$homeserver,$server) = @_; my %settings = &Apache::lonnet::get('environment',['internal.sectionnums','internal.coursecode','internal.courseowner'],$dom,$crs); my @currsections = (); my @sections = (); @@ -1484,6 +1589,8 @@ sub print_sections_response () { my $owner = $settings{'internal.courseowner'}; my $response = ''; my $putreply = ''; + my $warning = ''; + my $warn_prefix = ''; if ($secstr =~ m/,/) { @allsections = split/,/,$secstr; } else { @@ -1501,9 +1608,19 @@ sub print_sections_response () { if ( exists($ENV{"form.$sec"}) ) { unless ( (grep/^$ENV{"form.$sec"}:/,@allsections) || (grep/^$ENV{"form.$sec"}:/,@sections) ) { my $newsec = $coursecode.$ENV{"form.$sec"}; - my $coursecheck = &localenroll::validate_courseID($newsec); + my $coursecheck = ''; +# if ($homeserver eq $server) { +# $coursecheck = &localenroll::validate_courseID($newsec); +# } else { + $coursecheck = &Apache::lonnet::auto_validate_courseID($homeserver,$newsec); +# } if ($coursecheck eq 'ok') { - my $addcheck = &localenroll::new_course($newsec,$owner); + my $addcheck = ''; +# if ($homeserver eq $server) { +# $addcheck = &localenroll::new_course($newsec,$owner); +# } else { + $addcheck = &Apache::lonnet::auto_new_course($homeserver,$newsec,$owner); +# } if ($addcheck eq 'ok') { push @sections,$ENV{"form.$sec"}.":".$ENV{"form.$gp"}; } else { @@ -1559,6 +1676,14 @@ sub print_sections_response () { $response .= "

\n"; } + if (@allsections > 0) { + $warning = &warning_message($dom,$crs,$action); + $warn_prefix = "
Warning. Although you have selected sections to contribute enrollment to this course, additional action is required.
"; + unless ($warning eq '') { + $response .= $warn_prefix.$warning; + } + } + &print_reply($r,$response,$$tasktitleref{$action}); return; } @@ -1597,7 +1722,7 @@ sub print_photos_response () { } sub print_update_result () { - my ($r,$realm,$dom,$crs,$action,$tasktitleref) = @_; + my ($r,$realm,$dom,$crs,$action,$tasktitleref,$homeserver,$server) = @_; my $response = ''; my $updateadds = 0; my $updatedrops = 0; @@ -1669,7 +1794,11 @@ sub print_update_result () { if (@allcourses > 0) { @{$affiliates{$crs}} = @allcourses; - &localenroll::fetch_enrollment($dom,\%affiliates,\%reply); +# if ($homeserver eq $server) { +# &localenroll::fetch_enrollment($dom,\%affiliates,\%reply); +# } else { + &Apache::lonnet::fetch_enrollment_query($homeserver,$dom,\%affiliates,\%reply); +# } if ($reply{$crs} > 0) { ($changecount,$response) = &LONCAPA::Enrollment::update_LC($dom,$crs,$updateadds,$updatedrops,$autostart,$autoend,$authtype,$autharg,\@allcourses,\%LC_code,\$logmsg,\$newusermsg,"updatenow"); } else { @@ -1693,6 +1822,52 @@ sub print_update_result () { return; } +sub warning_message { + my ($dom,$crs,$caller) = @_; + my %settings = &Apache::lonnet::get('environment',['internal.autoadds','internal.autodrops','internal.sectionnums','internal.crosslistings','internal.autostart','internal.autoend'],$dom,$crs); + my $currend = ''; + my $currstart = ''; + my $currsecs = ''; + my $currxlists = ''; + my $warning = ''; + my $curradds = ''; + my $currdrops = ''; + if ( defined($settings{'internal.autoadds'}) ) { + $curradds = $settings{'internal.autoadds'}; + } + if (defined($settings{'internal.autodrops'}) ) { + $currdrops = $settings{'internal.autodrops'}; + } + if ( defined($settings{'internal.autostart'}) ) { + $currstart = $settings{'internal.autostart'}; + } + if ( defined($settings{'internal.autoend'}) ) { + $currend = $settings{'internal.autoend'}; + } + if ( defined($settings{'internal.sectionnums'}) ) { + $currsecs = $settings{'internal.sectionnums'}; + } + if ( defined($settings{'internal.crosslistings'}) ) { + $currxlists = $settings{'internal.crosslistings'} + } + unless ($caller eq 'setdates') { + if ( ($currstart eq '') && ($currend eq '') ) { + $warning = "You must now use Change enrollment dates to set a start date and an end date for the enrollment (or check the 'No end date' checkbox) for the nightly adds process to actually occur.

"; + } + } + unless ( ($caller eq 'sections') || ($caller eq 'crosslist') ) { + if ( ($currsecs eq '') && ($currxlists eq '') ) { + $warning .= "You must now use Section settings and/or Change crosslistings to choose at least one section of the course, or at least one crosslisted course which will contribute enrollment to this LON-CAPA course. At present there are NO sections or crosslisted courses that are affiliated with this course that are set to contribute to the automated enrollment process.

"; + } + } + unless ( $caller eq 'chgsettings') { + if ( (!$curradds) && (!$currdrops) ) { + $warning .= "You must now use Automated adds/drops to enable automated adds and/or drops if you want automatic enrollment updates to occur in this course.

."; + } + } + return $warning; +} + sub print_reply () { my ($r,$response,$caller) = @_; $r->print(" @@ -1708,9 +1883,6 @@ sub print_reply () { sub setup_date_selectors { my ($starttime,$endtime) = @_; - if ($endtime == 0) { - $endtime = 1999915200; - } if (! defined($starttime)) { $starttime = time; if (exists($ENV{'course.'.$ENV{'request.course.id'}. @@ -1867,6 +2039,10 @@ sub handler { } } } + +# Determine course home server and current server + my $homeserver = &Apache::lonnet::homeserver($crs,$dom); + my $server = $Apache::lonnet::perlvar{'lonHostID'}; my $reply = 0; unless ($state eq "choose") { $reply = 1; } @@ -1875,7 +2051,7 @@ sub handler { &print_navmenu($r,\@tasks,\%tasklong); if (($state eq "choose") || ($action eq "information")) { - &print_main_frame($r,$realm,$dom,$crs,\%tasktitle); + &print_main_frame($r,$realm,$dom,$crs,\%tasktitle,$homeserver,$server); } elsif ($action eq "chgsettings") { &print_chgsettings_response($r,$realm,$dom,$crs,$action,\%tasktitle); } elsif ($action eq "setdates") { @@ -1883,17 +2059,17 @@ sub handler { } elsif ($action eq "notify") { &print_notify_response($r,$realm,$dom,$crs,$action,\%tasktitle); } elsif ($action eq "sections") { - &print_sections_menu($r,$realm,$dom,$crs,$action,\%tasktitle); + &print_sections_menu($r,$realm,$dom,$crs,$action,\%tasktitle,$homeserver,$server); } elsif ($action eq "crosslist") { - &print_crosslistings_menu($r,$realm,$dom,$crs,$action,\%tasktitle); + &print_crosslistings_menu($r,$realm,$dom,$crs,$action,\%tasktitle,$homeserver,$server); } elsif ($action eq "updatenow") { - &print_update_result($r,$realm,$dom,$crs,$action,\%tasktitle); + &print_update_result($r,$realm,$dom,$crs,$action,\%tasktitle,$homeserver,$server); } elsif ($action eq "photos") { &print_photos_response($r,$realm,$dom,$crs,$action,\%tasktitle); } elsif ($action eq "newcross") { - &print_crosslistings_response($r,$realm,$dom,$crs,$action,\%tasktitle); + &print_crosslistings_response($r,$realm,$dom,$crs,$action,\%tasktitle,$homeserver,$server); } elsif ($action eq "newsections") { - &print_sections_response($r,$realm,$dom,$crs,$action,\%tasktitle); + &print_sections_response($r,$realm,$dom,$crs,$action,\%tasktitle,$homeserver,$server); } &print_doc_base($r); return OK;