--- loncom/interface/lonpopulate.pm 2013/08/15 16:51:02 1.78 +++ loncom/interface/lonpopulate.pm 2016/07/24 14:34:59 1.84 @@ -1,5 +1,5 @@ # automated enrollment configuration handler -# $Id: lonpopulate.pm,v 1.78 2013/08/15 16:51:02 raeburn Exp $ +# $Id: lonpopulate.pm,v 1.84 2016/07/24 14:34:59 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -51,7 +51,7 @@ sub header { sub choose_header { my ($action) = @_; my $notify_check = '/^note_[0-9]+$/'; - my %lt = + my %js_lt = &Apache::lonlocal::texthash( adds => 'You must select either "Enable" or "Disable" for nightly additions based on classlist changes', drop => 'You must select either "Enable" or "Disable" for nightly removals based on classlist changes', @@ -61,8 +61,9 @@ sub choose_header { ynot => 'You have indicated that you want notification of roster changes messages to be sent, but you have not selected any recipients.', atle => 'You must check at least one checkbox, before proceeding to the next page', ); - $lt{'both'} = &mt('You have selected "No" for both addition and removal of students[_1] in the institutional classlist but not in your LON-CAPA course.[_1]','\\n'); - $lt{'nnot'} = &mt('You have indicated that you do not want notification of roster changes messages to be sent, but [_1] have been checked as recipients.[_2]',"'+totalnote+'",'\\n'); + $js_lt{'both'} = &mt('You have selected "No" for both addition and removal of students[_1] in the institutional classlist but not in your LON-CAPA course.[_1]',"\n"); + $js_lt{'nnot'} = &mt('You have indicated that you do not want notification of roster changes messages to be sent, but [_1] have been checked as recipients.[_2]',"'+totalnote+'","\n"); + &js_escape(\%js_lt); my $scripttag = < @@ -88,11 +89,11 @@ function process(calling,numauto,nummanu } } if (rad1 == 0) { - alert('$lt{'adds'}'); + alert('$js_lt{'adds'}'); checker = 0 } if (rad2 == 0) { - alert('$lt{'drop'}'); + alert('$js_lt{'drop'}'); checker = 0 } } @@ -116,15 +117,15 @@ function process(calling,numauto,nummanu } } if (rad1 == 0) { - alert('$lt{'drop'}'); + alert('$js_lt{'drop'}'); checker = 0; } if (rad2 == 0) { - alert('$lt{'ysno'}'); + alert('$js_lt{'ysno'}'); checker = 0; } if (formName.updatedrops[unenrolldis].checked && formName.updateadds[enrolldis].checked ) { - alert('$lt{'both'}$lt{'noup'}'); + alert('$js_lt{'both'}$js_lt{'noup'}'); checker = 0; } } @@ -141,7 +142,7 @@ function process(calling,numauto,nummanu } if (totalnote > 0) { if (formName.notify[1].checked == true) { - if (confirm('$lt{'nnot'}$lt{'eras'}')) { + if (confirm('$js_lt{'nnot'}$js_lt{'eras'}')) { checker = 1; } else { checker = 0; @@ -149,7 +150,7 @@ function process(calling,numauto,nummanu } } else { if (formName.notify[0].checked == true) { - alert('$lt{'ynot'}'); + alert('$js_lt{'ynot'}'); checker = 0; } } @@ -177,7 +178,7 @@ function process(calling,numauto,nummanu document.forms.studentform.state.value = "process"; } if (totcheck == 0) { - alert('$lt{'atle'}') + alert('$js_lt{'atle'}') checker = 0; } } @@ -290,7 +291,7 @@ sub print_main_frame { # Get course settings my %enrollvar; my %settings = &Apache::lonnet::dump('environment',$dom,$crs); - foreach my $item (keys %settings) { + foreach my $item (keys(%settings)) { if ($item =~ m/^internal\.(.+)$/) { $enrollvar{$1} = $settings{$item}; } elsif ($item =~ /^default_enrollment_(start|end)_date$/) { @@ -349,6 +350,10 @@ sub print_main_frame { '.&mt('Use [_1]View students and change type[_2] to display the current course roster, and (optionally) change enrollment type for selected students from "auto" to "manual" and vice versa.','"','"').' +   + '.&mt('Use [_1]Change zero enrollment failsafe[_2] to set number of existing enrollments in an institutional section above which no automated drops occur whenever section enrollment retrieved from institutional data is zero.','"','"').' + +   @@ -422,6 +427,70 @@ sub print_main_frame { '."\n"); + } elsif ($action eq 'chgfailsafe') { + my $autofailsafe; + my %domconfig = + &Apache::lonnet::get_dom('configuration',['autoenroll'],$dom); + if (ref($domconfig{'autoenroll'}) eq 'HASH') { + $autofailsafe = $domconfig{'autoenroll'}->{'autofailsafe'}; + if ($autofailsafe =~ /\D/) { + undef($autofailsafe); + } + } + $r->print(' +

+ + + + +
'.$$tasktitleref{$action}.'

'. + &mt('In a course where multiple institutional sections provide enrollment, the "failsafe" value can prevent automated enrollment from expiring student roles for registered students in one section, in the case where no enrollment is returned for that particular section because of a temporary institutional data retrieval problem external to LON-CAPA.').'

'. + '

'.&mt('For example if this value is set to 10, and the current LON-CAPA enrollment count is 11 or more for a particular course section, no role expiration will occur if the latest retrieved enrollment count is zero for that institutional section (or cross-listing).').'

'); + if ($enrollvar{'autodropfailsafe'} eq '') { + $r->print('

'.&mt('Currently no course-specific failsafe value is set.').' '); + if ($autofailsafe eq '') { + $r->print(&mt('Currently no domain default failsafe is set either.')); + } else { + $r->print(&mt('The current domain default of [_1] will apply, unless a value is set here specific to this course.',$autofailsafe)); + } + $r->print('

'); + } else { + $r->print('

'.&mt('Currently, the course-specific failsafe is set to [_1].',"$enrollvar{'autodropfailsafe'}").'

'); + } + $r->print(' +
+ + + + + + + + + + + + + + +
+ '.&mt('Failsafe (enter an integer)').'   +
'); + if ($enrollvar{'autodropfailsafe'}) { + if ($autofailsafe) { + $r->print(&mt('Leave blank to use domain default of [_1].',$autofailsafe)); + } else { + $r->print(&mt('Leave blank to not use.')); + } + } + $r->print(' +
 
'.&mt('Push "Go" to save your changes').' +
 
+ +
+ + +
'."\n"); } elsif ($action eq 'setdates') { my ($start_table,$end_table) = &date_setting_table($enrollvar{autostart},$enrollvar{autoend},$action); my $oldstartshow = ''; @@ -749,7 +818,7 @@ sub print_main_frame { $r->print( &mt('Currently, this LON-CAPA course is crosslisted with [quant,_1,course section,course sections].',$cross_str).' '. &mt('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.').' '. - &mt('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: [_1; otherwise uncheck it.',"$realm ($enrollvar{coursecode})").' '. + &mt('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: [_1]; otherwise uncheck it.',"$realm ($enrollvar{coursecode})").' '. &mt('If you wish to change the section ID assigned in your LON-CAPA course for a crosslisted course, enter the new section ID in the appropriate textbox.').' '. &mt('The LON-CAPA section ID can be left (or set to) empty, if you do not wish to tie a section ID to this crosslisting.').' '. &mt('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.').' '. @@ -1063,7 +1132,7 @@ sub print_main_frame { - + @@ -1466,28 +1535,15 @@ sub print_doc_base { ################################################################### sub print_chgsettings_response { my ($r,$realm,$dom,$crs,$action,$tasktitleref) = @_; - my %settings = &Apache::lonnet::get('environment',['internal.sectionnums','internal.crosslistings','internal.autostart','internal.autoend','internal.autoadds','internal.autodrops'],$dom,$crs); - my ($currend,$currstart,$currsecs,$currxlists,$curradds,$currdrops, - $autoadds,$autodrops,$response,$warning,$warn_prefix,$warn_suffix, - $warnfiller); + my %settings = &Apache::lonnet::get('environment',['internal.autoadds','internal.autodrops'],$dom,$crs); + my ($curradds,$currdrops,$autoadds,$autodrops,$response,$warning, + $warn_prefix,$warn_suffix,$warnfiller); 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'} - } if ( exists($env{'form.autoadds'}) ) { $autoadds=$env{'form.autoadds'}; } @@ -1537,7 +1593,7 @@ sub print_chgsettings_response { unless ($warning eq '') { $response .= '
'. ''.&mt('Warning.').' '; - if ($autodrops && $autodrops) { + if ($autoadds && $autodrops) { $response .= &mt('Although you indicated that nightly adds and drops should be enabled, additional action is required.'); } elsif ($autoadds) { @@ -1555,6 +1611,39 @@ sub print_chgsettings_response { return; } +sub print_chgfailsafe_response { + my ($r,$realm,$dom,$crs,$action,$tasktitleref) = @_; + my %settings = &Apache::lonnet::get('environment',['internal.autodropfailsafe'], + $dom,$crs); + my ($currfailsafe,$newfailsafe,$response); + if ( defined($settings{'internal.autodropfailsafe'}) ) { + $currfailsafe = $settings{'internal.autodropfailsafe'}; + } + if (exists($env{'form.autodropfailsafe'})) { + $env{'form.autodropfailsafe'} =~ s{^\s+|\s+$}{}g; + if ($env{'form.autodropfailsafe'} !~ /\D/) { + $newfailsafe = $env{'form.autodropfailsafe'}; + } + } + if ($currfailsafe ne $newfailsafe) { + my %cenv = ('internal.autodropfailsafe' => $newfailsafe); + my $reply = &Apache::lonnet::put('environment',\%cenv,$dom,$crs); + if ($reply ne 'ok') { + $response = + &mt('There was a problem processing your requested changes.').' '. + &mt('The automated enrollment settings for this course have been left unchanged.').'
'; + } elsif ($newfailsafe ne '') { + $response = &mt('Automated drop failsafe set to [_1]',$newfailsafe); + } else { + $response = &mt('Course-specific automated drop failsafe deleted.'); + } + } else { + $response = &mt('The new value for the automated drop failsafe was the same as the existing value, so no changes have been made.'); + } + &print_reply($r,$response,$$tasktitleref{$action}); + return; +} + sub print_setdates_response { my ($r,$realm,$dom,$crs,$action,$tasktitleref) = @_; my %settings = @@ -1920,7 +2009,7 @@ sub print_crosslistings_menu { if ($numcross) { $response .= &mt('You indicated that you wish to add an additional [quant,_1,crosslisting].',$numcross).' '. - &mt('For each new crosslisting enter the insititutional 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('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."). '

@@ -2250,7 +2339,7 @@ sub print_sections_menu { if ($numsec > 0) { $response .= &mt('You indicated that you wish to incorporate student enrollment in your LON-CAPA course from an additional [quant,_1,section].',$numsec).' '. - &mt('For each new section enter the insititutional section code (e.g., 004), 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 this particular section.').' '. + &mt('For each new section enter the institutional section code (e.g., 004), 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 this particular section.').' '. &mt('The LON-CAPA section ID can be left blank, if you do not wish to designate a section ID for this course section.').' '. &mt("The institutional section code should only contain letters and/or numbers, and must be consistent with the scheme adopted by your Domain Coordinator to map course section numbers to your institution's student information system.").'

@@ -2726,25 +2815,33 @@ sub print_update_result { my %settings = &Apache::lonnet::get('environment', ['internal.coursecode','internal.sectionnums','internal.crosslistings', - 'internal.authtype','internal.autharg','internal.showphoto','internal.defaultcredits'], + 'internal.authtype','internal.autharg','internal.showphoto','internal.defaultcredits', + 'internal.autodropfailsafe','internal.textbook'], $dom,$crs); my $coursecode = $settings{'internal.coursecode'}; my $authtype = $settings{'internal.authtype'}; my $autharg = $settings{'internal.autharg'}; my $showphotos = $settings{'internal.showphoto'}; + my $textbook = $settings{'internal.textbook'}; my ($showcredits,$defaultcredits); my %domdefaults = &Apache::lonnet::get_domain_defaults($dom); - if ($domdefaults{'officialcredits'} || $domdefaults{'unofficialcredits'}) { + if ($domdefaults{'officialcredits'} || $domdefaults{'unofficialcredits'} || $domdefaults{'textbookcredits'}) { $showcredits = 1; $defaultcredits = $settings{'internal.defaultcredits'}; if ($defaultcredits eq '') { if ($coursecode ne '') { $defaultcredits = $domdefaults{'officialcredits'}; + } elsif ($textbook ne '') { + $defaultcredits = $domdefaults{'textbookcredits'}; } else { $defaultcredits = $domdefaults{'unofficialcredits'}; } } } + my $failsafe = $settings{'internal.autodropfailsafe'}; + if ($failsafe eq '') { + $failsafe = $domdefaults{'autofailsafe'}; + } my ($startaccess,$endaccess) = &get_dates_from_form(); if ( exists($env{'form.updateadds'}) ) { $updateadds = $env{'form.updateadds'}; @@ -2779,7 +2876,7 @@ sub print_update_result { ": ".$outcome); } if ($reply{$crs} > 0) { - ($changecount,$response) = &LONCAPA::Enrollment::update_LC($dom,$crs,$updateadds,$updatedrops,$startaccess,$endaccess,$authtype,$autharg,$showcredits,$defaultcredits,\@allcourses,\%LC_code,\$logmsg,\$newusermsg,"updatenow",\%phototypes); + ($changecount,$response) = &LONCAPA::Enrollment::update_LC($dom,$crs,$updateadds,$updatedrops,$startaccess,$endaccess,$authtype,$autharg,$showcredits,$defaultcredits,$failsafe,\@allcourses,\%LC_code,\$logmsg,\$newusermsg,"updatenow",\%phototypes); } else { $response = &mt('There was a problem retrieving institutional class list data for the course sections and crosslisted courses which contribute enrollment to this course.').' '. &mt('No updates have been carried out, and the roster remains unchanged.'); @@ -3150,6 +3247,7 @@ sub get_task_text { &Apache::lonlocal::texthash( information => 'Task information', chgsettings => 'Automated adds/drops', + chgfailsafe => 'Change zero enrollment failsafe', setdates => 'Change enrollment dates', setaccess => 'Change access dates', notify => 'Notification of changes', @@ -3166,6 +3264,7 @@ sub get_task_text { my %tasktitle = &Apache::lonlocal::texthash( chgsettings => 'Changes to nightly automated enrollments', + chgfailsafe => 'Changes to failsafe protection for data retrieval problems', setdates => 'Changes to first and/or last automated enrollment dates', setaccess => 'Changes to default start and/or end dates for student access', notify => 'Notification of enrollment changes', @@ -3203,7 +3302,7 @@ sub handler { $r->send_http_header; my @tasks = ('information','chgsettings','setdates','setaccess','notify','crosslist', - 'sections','photos','updatenow','updatephotos','viewclass'); + 'sections','photos','updatenow','updatephotos','viewclass','chgfailsafe'); my ($tasklong,$tasktitle) = &get_task_text(); my $realm; @@ -3269,6 +3368,8 @@ sub handler { &print_main_frame($r,$realm,$dom,$crs,$tasktitle); } elsif ($action eq "chgsettings") { &print_chgsettings_response($r,$realm,$dom,$crs,$action,$tasktitle); + } elsif ($action eq "chgfailsafe") { + &print_chgfailsafe_response($r,$realm,$dom,$crs,$action,$tasktitle); } elsif ($action eq "setdates") { &print_setdates_response($r,$realm,$dom,$crs,$action,$tasktitle); } elsif ($action eq "setaccess") {