--- loncom/interface/lonpopulate.pm 2003/12/08 17:06:26 1.2 +++ loncom/interface/lonpopulate.pm 2004/06/08 22:09:44 1.12 @@ -1,14 +1,39 @@ +# automated enrollment configuration handler +# $Id: lonpopulate.pm,v 1.12 2004/06/08 22:09:44 raeburn Exp $ +# +# Copyright Michigan State University Board of Trustees +# +# This file is part of the LearningOnline Network with CAPA (LON-CAPA). +# +# LON-CAPA is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# LON-CAPA is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with LON-CAPA; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# /home/httpd/html/adm/gpl.txt +# +# http://www.lon-capa.org/ +# package Apache::lonpopulate; use strict; use lib qw(/home/httpd/lib/perl); -use Apache::lonnet (); -use Apache::loncommon (); -use Apache::lonhtmlcommon (); -use Apache::lonlocal (); +use Apache::lonnet; +use Apache::loncommon; +use Apache::lonhtmlcommon; +use Apache::lonlocal; use Apache::Constants qw(:common :http REDIRECT); use Time::Local; -use LONCAPA::Enrollment (); +use LONCAPA::Enrollment; use localenroll; ############################################################### @@ -182,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'}; @@ -304,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
@@ -414,76 +451,111 @@ ENDTWO "); - my $option_str = ''; - my $lastpname = ''; - my $option_count = 0; - - my %coursepersonnel=&Apache::lonnet::get_course_adv_roles($dom.'/'.$crs); - foreach (sort keys %coursepersonnel) { - if ($_ eq &Apache::lonlocal::mt("Course Coordinator") ) - { - my @ccs = (); - if ($coursepersonnel{$_} =~ m/,/) { - @ccs = split(/,/,$coursepersonnel{$_}); - } else { - @ccs = $coursepersonnel{$_}; - } - foreach (@ccs) { - my ($puname,$pudom)=split(/\:/,$_); - my $pname = &Apache::loncommon::plainname($puname,$pudom); - if (grep/^$puname\@$pudom$/,@notified) { - $option_str .="\n"; + my @coursepersonnel = &Apache::lonnet::getkeys('nohist_userroles',$dom,$crs); + my @ccs = (); + my @oldccs = (); + my %pname = (); + my %notifystate = (); + foreach (@coursepersonnel) { + my @roleinfo = split/:/,$_; + if ($roleinfo[0] eq 'cc') { + unless (grep/^$roleinfo[1]\@$roleinfo[2]/,@ccs) { + my $active_cc = &LONCAPA::Enrollment::check_user_status($roleinfo[2],$roleinfo[1],$dom,$crs,'cc'); + if ($active_cc eq 'ok') { + push @ccs, "$roleinfo[1]\@$roleinfo[2]"; + $pname{"$roleinfo[1]\@$roleinfo[2]"} = &Apache::loncommon::plainname($roleinfo[1],$roleinfo[2]); + if (grep/^$roleinfo[1]\@$roleinfo[2]$/,@notified) { + $notifystate{"$roleinfo[1]\@$roleinfo[2]"} = 1; + } else { + $notifystate{"$roleinfo[1]\@$roleinfo[2]"} = 0; + } } else { - $option_str .="\n"; + push @oldccs, "$roleinfo[1]\@$roleinfo[2]"; } - $option_count ++; - $lastpname = $pname.'@'.$pudom; } } } - if ($option_count > 1) { - my $optionsize = $option_count; - if ($optionsize > 6) { - $optionsize = 6; - } + if ($notifycount > 0) { + foreach my $person (@notified) { + unless ( (grep/^$person$/,@ccs) || ($person eq '') || (grep/^$person$/,@oldccs) ) { + push @ccs, $person; + my ($puname,$pdom) = split/\@/,$person; + $pname{$person} = &Apache::loncommon::plainname($puname,$pdom); + $notifystate{$person} = 1; + } + } + } + my $viewer = $ENV{'user.name'}.'@'.$ENV{'user.domain'}; + unless ( (grep/^$viewer$/,@ccs) || ($viewer eq '') ) { + push @ccs,$viewer; + $pname{$viewer} = &Apache::loncommon::plainname($ENV{'user.name'},$ENV{'user.domain'}); + $notifystate{$viewer} = 0; + } + + my $notifyshow = @ccs; + + if (@ccs > 0) { + @ccs = sort @ccs; $r->print(" - -Select which course coordinators should receive information about roster changes whenever any adds or drops occur during the nightly enrollment check.

- + The table below contains a list of course coordinators in this course. Uncheck the 'Notification?' checkbox for each person who is to be removed from the list of recipients who are currently informed of roster changes whenever any adds or drops occur during the nightly enrollment check. To include individuals who are not currently recipients, simply check the 'Notification?' checkbox. Click 'Go' to store your changes. - Select more than one recipient by using the following keyboard and mouse combinations:
- - - + + + + + + + "); - } else { + for (my $i=0; $i<@ccs; $i++) { + my $colflag = $i%2; + $r->print(" + + + "); + } else { + $r->print(""); + } + } $r->print(" - - - +
NameusernameCurrent statusNotification?
$pname{$ccs[$i]}$ccs[$i] + "); + if ($notifystate{$ccs[$i]} == 1) { + $r->print("Notification active"); + } else { + $r->print("Notification inactive"); + } + if ($notifystate{$ccs[$i]} == 1) { + $r->print("
-As you are the only user with the role of course coordinator in this course, if you choose to enable notification of roster changes, you will be the sole recipient of LON-CAPA messages generated whenever any adds or drops occur during the nightly enrollment check. - -
+
+ + + + +
+ +
+ + "); + } else { + $r->print(" + + + No course coordinators found. + + "); } $r->print(" - - - - - - - - - + + + + + "); } elsif ($action eq "crosslist") { my @xlists = (); @@ -501,7 +573,7 @@ As you are the only user with the role o "); if ($cross_str > 0) { $r->print(" - Currently, LON-CAPA course: $realm ($enrollvar{coursecode}) is crosslisted with $cross_str course section(s). 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. For each crosslisting, leave the checkbox checked if you want registered students in that course to be included in the student roster for LON-CAPA course: $realm ($enrollvar{coursecode}); otherwise uncheck it. If you wish to change the section/group ID assigned in your LON-CAPA course for a crosslisted course, enter the new section/group ID in the appropriate textbox. The LON-CAPA section/group ID can be left (or set to) empty, if you do not wish to tie a section/group ID to this crosslisting. If you wish to add new crosslisted courses, enter the number of new courses to add in the textbox at the bottom of the page. You will provide information about each of the new crosslistings on a subsequent page. Click 'Go' to store your changes. + Currently, this LON-CAPA course is crosslisted with $cross_str course section(s). 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. For each crosslisting, leave the checkbox checked if you want registered students in that course to be included in the student roster for LON-CAPA course: $realm ($enrollvar{coursecode}); otherwise uncheck it. If you wish to change the section/group ID assigned in your LON-CAPA course for a crosslisted course, enter the new section/group ID in the appropriate textbox. The LON-CAPA section/group ID can be left (or set to) empty, if you do not wish to tie a section/group ID to this crosslisting. If you wish to add new crosslisted courses, enter the number of new courses to add in the textbox at the bottom of the page. You will provide information about each of the new crosslistings on a subsequent page. Click 'Go' to store your changes. @@ -569,7 +641,8 @@ As you are the only user with the role o "); } 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 = (); @@ -585,9 +658,8 @@ As you are the only user with the role o } } if (@sections > 0) { - if (@sections > 1) { - my $secshow = @sections; - $r->print(" + my $secshow = @sections; + $r->print("

@@ -597,75 +669,53 @@ As you are the only user with the role o - +
For each section, check the checkbox if you want registered students in that section to be included in the student roster for LON-CAPA course: $realm ($enrollvar{coursecode}); otherwise uncheck it. If you want to change the section/group designation used for this section in LON-CAPA, delete the currecnt value in the LON-CAPA section/group textbox and enter the new value. The LON-CAPA section/group ID can be left (or set to) empty, if you do not wish to tie a section/group ID to this section. If you wish to add new course section, enter the number of new sections to add in the textbox at the bottom of the page. You will provide information about each of the new sections on a subsequent page. Click 'Go' to store your changes.For each section, check the checkbox if you want registered students in that section to be included in the student roster for LON-CAPA course: $realm ($enrollvar{coursecode}); otherwise uncheck it. If you want to change the section/group designation used for this section in LON-CAPA, delete the current value in the LON-CAPA section/group textbox and enter the new value. The LON-CAPA section/group ID can be left (or set to) empty, if you do not wish to tie a section/group ID to this section. To add a new section, check the 'Enrollment in this course?' checkbox, and enter the desired LON-CAPA section/groupID in the appropriate textbox. Click 'Go' to store +your changes.

- - -
- - - - - - - "); - for (my $i=0; $i<@sections; $i++) { - my $colflag = $i%2; - my $shrflag = 0; - $r->print(" - - -
Course code/td> - Current statusLON-CAPA section/group IDEnrollment in this course?
$sections[$i]/td> + + + + + + + + "); + for (my $i=0; $i<@sections; $i++) { + my $colflag = $i%2; + my $shrflag = 0; + $r->print(" + "); - } else { - $r->print(""); - } - } - $r->print(" - -
SectionCurrent statusLON-CAPA section/group IDEnrollment in this course?
$sections[$i] - "); - if (grep/^$sections[$i]$/,@currsections) { - $r->print("Enrollment active"); - $shrflag = 1; - } else { - $r->print("Enrollment inactive"); - } - if ($shrflag) { - $r->print("
-
-
- - - - -
- - -
- - - "); - } else { - $r->print("
- - - "); + } else { + $r->print(""); + } + } + $r->print(" +
- $$tasktitleref{$action}
+ if (grep/^$sections[$i]$/,@currsections) { + $r->print("Enrollment active"); + $shrflag = 1; + } else { + $r->print("Enrollment inactive"); + } + if ($shrflag) { + $r->print("
+
+ + +
+ +
- - - - -
As your institution's course catalog only includes a single section for this course, there are no additional sections that can be set for inclusion in the LON-CAPA roster for the course.
- "); - } + + + + "); } else { $r->print("

@@ -676,7 +726,7 @@ As you are the only user with the role o if (@currsections) { my $secshow = @currsections; $r->print(" - Currently, LON-CAPA course: $realm ($enrollvar{coursecode}) incorporates enrollment from $secshow sections. Students enrolling in any of 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. For each section, uncheck the checkbox if you want registered students in that section to cease being included in the student roster for LON-CAPA course: $realm ($enrollvar{coursecode}); otherwise leave it checked. If you want to change the section/group designation used for this section in LON-CAPA, delete the current value in the LON-CAPA section/groupID textbox and enter the new value. If you wish to add new course section, enter the number of new sections to add in the textbox at the bottom of the page. You will provide information about each of the new sections on a subsequent page. Click 'Go' to store your changes. + Currently, this LON-CAPA course incorporates enrollment from $secshow sections. Students enrolling in any of 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. For each section, uncheck the checkbox if you want registered students in that section to cease being included in the student roster for LON-CAPA course: $realm ($enrollvar{coursecode}); otherwise leave it checked. If you want to change the section/group designation used for this section in LON-CAPA, delete the current value in the LON-CAPA section/groupID textbox and enter the new value. If you wish to add new course section, enter the number of new sections to add in the textbox at the bottom of the page. You will provide information about each of the new sections on a subsequent page. Click 'Go' to store your changes.
@@ -848,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 = ''; @@ -862,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); @@ -873,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
"; @@ -894,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; @@ -908,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 { @@ -928,7 +1025,7 @@ sub print_setdates_response { if ($currend == $autoend) { $response .= "The last date for automated enrollment has been left unchanged as $showend.
"; } else { - $response .= "The last date for enrollment has been left unchanged as $showend.
"; + $response .= "The last date for automated enrollment has been changed to $showend.
"; } # Generate message in case where old first access date was later than today, but new first access date is now today or earlier. @@ -946,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"; @@ -963,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; @@ -981,11 +1083,14 @@ sub print_notify_response { my @currpeople = (); my $notify = 0; my @people = (); + my $peoplestr = ""; + my $response = ""; + my $noprocess = 0; if ($notifylist =~ m/,/) { @currpeople = split/,/,$notifylist; } else { - @currpeople = $notifylist; + $currpeople[0] = $notifylist; } my $currcount = 0; foreach (@currpeople) { @@ -994,43 +1099,56 @@ sub print_notify_response { if ( exists($ENV{'form.notify'}) ) { $notify=$ENV{'form.notify'}; - } - if ( exists($ENV{'form.notifylist'}) ) { - if (ref($ENV{'form.notifylist'})) { - @people=@{ $ENV{'form.notifylist'} }; - } else { - $people[0]=$ENV{'form.notifylist'}; - } } - my $response = ""; - my $peoplestr = ""; - if ($notify) { $peoplestr = join(",",@people); } - my %cenv = ('internal.notifylist' => $peoplestr); - my $reply = &Apache::lonnet::put('environment',\%cenv,$dom,$crs); - if ($reply !~ /^ok$/) { - $response = "There was a problem processing your requested changes. The notification settings for this course have been left unchanged.
"; + if ( exists($ENV{'form.notifyshow'}) ) { + my $notifyshow = $ENV{'form.notifyshow'}; + for (my $i=0; $i<$notifyshow; $i++) { + if ( exists($ENV{"form.note_$i"}) ) { + if ( exists($ENV{"form.notifyname_$i"}) ) { + unless ( $ENV{"form.notifyname_$i"} eq '' ) { + push @people, $ENV{"form.notifyname_$i"}; + } + } + } + } + if ($notify) { $peoplestr = join(",",@people); } } else { if ($notify) { - if (@people) { - if ($currcount) { - $response = "Notification of enrollment changes still enabled
"; - } else { - $response = "Notification of enrollment changes now enabled
"; - } - $response .= "
The following will receive notification if there are any changes in enrollment in LON-CAPA course: $realm ($coursecode) as a result of -the nightly enrollment check:
\n"; - } else { - $response = "Notification of enrollment changes was not enabled as no course coordinators were selected as recipients.
"; + if ($currcount) { + $response = "There was a problem retrieving the updated list of recipients of notification messages. The notification settings for this course have been left unchanged.
."; + $peoplestr = $notifylist; + @people = @currpeople; + $noprocess = 1; } + } + } + unless ($noprocess == 1) { + my %cenv = ('internal.notifylist' => $peoplestr); + my $reply = &Apache::lonnet::put('environment',\%cenv,$dom,$crs); + if ($reply !~ /^ok$/) { + $response = "There was a problem processing your requested changes. The notification settings for this course have been left unchanged.
"; } else { - if ($currcount) { - $response = "Notification of enrollment changes now disabled
"; + if ($notify) { + if (@people) { + if ($currcount) { + $response .= "Notification of enrollment changes still enabled
"; + } else { + $response .= "Notification of enrollment changes now enabled
"; + } + $response .= "
The following will receive notification if there are any changes in enrollment in LON-CAPA course: $realm ($coursecode) as a result of the nightly enrollment check:
\n"; + } else { + $response = "Notification of enrollment changes was not enabled as no course coordinators were selected as recipients.
"; + } } else { - $response = "Notification of enrollment changes still disabled
"; + if ($currcount) { + $response = "Notification of enrollment changes now disabled
"; + } else { + $response = "Notification of enrollment changes still disabled
"; + } } } } @@ -1039,7 +1157,7 @@ the nightly enrollment check: