--- loncom/interface/domainprefs.pm 2021/12/24 21:00:55 1.160.6.115 +++ loncom/interface/domainprefs.pm 2024/07/14 23:10:08 1.160.6.124 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Handler to set domain-wide configuration settings # -# $Id: domainprefs.pm,v 1.160.6.115 2021/12/24 21:00:55 raeburn Exp $ +# $Id: domainprefs.pm,v 1.160.6.124 2024/07/14 23:10:08 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -268,7 +268,9 @@ sub handler { header => [{col1 => 'Setting', col2 => 'Value'}, {col1 => 'Institutional user types', - col2 => 'Name displayed'}], + col2 => 'Name displayed'}, + {col1 => 'Mapping for missing usernames via standard log-in', + col2 => 'Rules in use'}], print => \&print_defaults, modify => \&modify_defaults, }, @@ -741,6 +743,8 @@ sub print_config_box { $output .= &wafproxy_javascript($dom); } elsif ($action eq 'autoupdate') { $output .= &autoupdate_javascript(); + } elsif ($action eq 'autoenroll') { + $output .= &autoenroll_javascript(); } elsif ($action eq 'login') { $output .= &saml_javascript(); } elsif ($action eq 'ipaccess') { @@ -820,7 +824,7 @@ sub print_config_box { if (($action eq 'autoupdate') || ($action eq 'usercreation') || ($action eq 'selfcreation') || ($action eq 'selfenrollment') || ($action eq 'usersessions') || ($action eq 'coursecategories') || - ($action eq 'contacts') || ($action eq 'passwords')) { + ($action eq 'contacts') || ($action eq 'passwords') || ($action eq 'defaults')) { if ($action eq 'coursecategories') { $output .= &print_coursecategories('middle',$dom,$item,$settings,\$rowtotal); $colspan = ' colspan="2"'; @@ -874,8 +878,8 @@ sub print_config_box { } $rowtotal ++; } elsif (($action eq 'usermodification') || ($action eq 'coursedefaults') || - ($action eq 'defaults') || ($action eq 'directorysrch') || - ($action eq 'helpsettings') || ($action eq 'wafproxy')) { + ($action eq 'directorysrch') || ($action eq 'helpsettings') || + ($action eq 'wafproxy')) { $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal); } elsif ($action eq 'scantron') { $output .= $item->{'print'}->($r,'bottom',$dom,$confname,$settings,\$rowtotal); @@ -1163,6 +1167,7 @@ sub print_login { } } my @images = ('img','logo','domlogo','login'); + my @alttext = ('img','logo','domlogo'); my @logintext = ('textcol','bgcol'); my @bgs = ('pgbg','mainbg','sidebg'); my @links = ('link','alink','vlink'); @@ -1204,6 +1209,13 @@ sub print_login { $designs{'showlogo'}{$item} = $settings->{'showlogo'}{$item}; } } + foreach my $item (@alttext) { + if (ref($settings->{'alttext'}) eq 'HASH') { + if ($settings->{'alttext'}->{$item} ne '') { + $designs{'alttext'}{$item} = $settings->{'alttext'}{$item}; + } + } + } foreach my $item (@logintext) { if ($settings->{$item} ne '') { $designs{'logintext'}{$item} = $settings->{$item}; @@ -1405,7 +1417,7 @@ sub print_login { $styleon{$lonhost} = 'display:none'; $styleoff{$lonhost} = ''; } - if (ref($settings->{'saml'}) eq 'HASH') { + if ((ref($settings) eq 'HASH') && (ref($settings->{'saml'}) eq 'HASH')) { foreach my $lonhost (keys(%{$settings->{'saml'}})) { if (ref($settings->{'saml'}{$lonhost}) eq 'HASH') { $saml{$lonhost} = 1; @@ -1513,6 +1525,7 @@ sub login_choices { current => "Current", samllanding => "Dual login?", samloptions => "Options", + alttext => "Alt text", ); return %choices; } @@ -1858,7 +1871,7 @@ sub display_color_options { $css_class = $itemcount%2?' class="LC_odd_row"':''; $datatable .= '<tr'.$css_class.'>'. '<td>'.$choices->{$img}; - my ($imgfile,$img_import,$login_hdr_pick,$logincolors); + my ($imgfile,$img_import,$login_hdr_pick,$logincolors,$alttext); if ($role eq 'login') { if ($img eq 'login') { $login_hdr_pick = @@ -1866,8 +1879,13 @@ sub display_color_options { $logincolors = &login_text_colors($img,$role,$logintext,$phase,$choices, $designs,$defaults); - } elsif ($img ne 'domlogo') { - $datatable.= &logo_display_options($img,$defaults,$designs); + } else { + if ($img ne 'domlogo') { + $datatable.= &logo_display_options($img,$defaults,$designs); + } + if (ref($designs->{'alttext'}) eq 'HASH') { + $alttext = $designs->{'alttext'}{$img}; + } } } $datatable .= '</td>'; @@ -1959,6 +1977,11 @@ sub display_color_options { $datatable .=' <input type="file" name="'.$role.'_'.$img.'" />'; } } + if (($role eq 'login') && ($img ne 'login')) { + $datatable .= (' ' x2).' <span class="LC_nobreak"><label>'.$choices->{'alttext'}.':'. + '<input type="text" name="'.$role.'_alt_'.$img.'" size="10" value="'.$alttext.'" />'. + '</label></span>'; + } $datatable .= '</td></tr>'; } $itemcount ++; @@ -2985,6 +3008,41 @@ function toggleLastActiveDays(form) { ENDSCRIPT } +sub autoenroll_javascript { + return <<"ENDSCRIPT"; +<script type="text/javascript"> +// <![CDATA[ +function toggleFailsafe(form) { + var radioname = 'autoenroll_failsafe'; + var divid = 'autoenroll_failsafe_div'; + var num = form.elements[radioname].length; + if (num) { + var setvis = ''; + for (var i=0; i<num; i++) { + if (form.elements[radioname][i].checked) { + if ((form.elements[radioname][i].value == 'zero') || (form.elements[radioname][i].value == 'any')) { + if (document.getElementById(divid)) { + document.getElementById(divid).style.display = 'inline-block'; + } + setvis = 1; + } + break; + } + } + if (!setvis) { + if (document.getElementById(divid)) { + document.getElementById(divid).style.display = 'none'; + } + } + } + return; +} +// ]]> +</script> + +ENDSCRIPT +} + sub saml_javascript { return <<"ENDSCRIPT"; <script type="text/javascript"> @@ -3098,7 +3156,12 @@ ENDSCRIPT sub print_autoenroll { my ($dom,$settings,$rowtotal) = @_; my $autorun = &Apache::lonnet::auto_run(undef,$dom), - my ($defdom,$runon,$runoff,$coownerson,$coownersoff,$failsafe); + my ($defdom,$runon,$runoff,$coownerson,$coownersoff, + $failsafe,$autofailsafe,$failsafesty,%failsafechecked); + $failsafesty = 'none'; + %failsafechecked = ( + off => ' checked="checked"', + ); if (ref($settings) eq 'HASH') { if (exists($settings->{'run'})) { if ($settings->{'run'} eq '0') { @@ -3132,8 +3195,24 @@ sub print_autoenroll { if (exists($settings->{'sender_domain'})) { $defdom = $settings->{'sender_domain'}; } - if (exists($settings->{'autofailsafe'})) { - $failsafe = $settings->{'autofailsafe'}; + if (exists($settings->{'failsafe'})) { + $failsafe = $settings->{'failsafe'}; + if ($failsafe eq 'zero') { + $failsafechecked{'zero'} = ' checked="checked"'; + $failsafechecked{'off'} = ''; + $failsafesty = 'inline-block'; + } elsif ($failsafe eq 'any') { + $failsafechecked{'any'} = ' checked="checked"'; + $failsafechecked{'off'} = ''; + } + $autofailsafe = $settings->{'autofailsafe'}; + } elsif (exists($settings->{'autofailsafe'})) { + $autofailsafe = $settings->{'autofailsafe'}; + if ($autofailsafe ne '') { + $failsafechecked{'zero'} = ' checked="checked"'; + $failsafe = 'zero'; + $failsafechecked{'off'} = ''; + } } } else { if ($autorun) { @@ -3172,9 +3251,15 @@ sub print_autoenroll { $coownersoff.' value="0" />'.&mt('No').'</label></span></td>'. '</tr><tr>'. '<td>'.&mt('Failsafe for no drops when institutional data missing').'</td>'. - '<td class="LC_right_item"><span class="LC_nobreak">'. - '<input type="text" name="autoenroll_failsafe"'. - ' value="'.$failsafe.'" size="4" /></span></td></tr>'; + '<td class="LC_left_item"><span class="LC_nobreak">'. + '<span class="LC_nobreak"><label><input type="radio" name="autoenroll_failsafe" value="off" onclick="toggleFailsafe(this.form)"'.$failsafechecked{'off'}.' />'.&mt('Not in use').'</label></span> '. + '<span class="LC_nobreak"><label><input type="radio" name="autoenroll_failsafe" value="zero" onclick="toggleFailsafe(this.form)"'.$failsafechecked{'zero'}.' />'.&mt('Retrieved section enrollment is zero').'</label></span><br />'. + '<span class="LC_nobreak"><label><input type="radio" name="autoenroll_failsafe" value="any" onclick="toggleFailsafe(this.form)"'.$failsafechecked{'any'}.' />'.&mt('Retrieved section enrollment is zero or greater').'</label></span>'. + '<div class="LC_floatleft" style="display:'.$failsafesty.';" id="autoenroll_failsafe_div">'. + '<span class="LC_nobreak">'. + &mt('Threshold for number of students in section to drop: [_1]', + '<input type="text" name="autoenroll_autofailsafe" value="'.$autofailsafe.'" size="4" />'). + '</span></div></td></tr>'; $$rowtotal += 4; return $datatable; } @@ -5438,8 +5523,10 @@ sub print_wafproxy { my $dom_in_effect; my $aliasrows = '<tr>'. '<td class="LC_left_item" style="vertical-align: baseline;">'. - &mt('Hostname').': '. - '<i>'.&Apache::lonnet::hostname($server).'</i></td><td> </td>'; + &mt('Hostname').': '. + '<span class="LC_nobreak LC_cusr_emph">'. + &Apache::lonnet::hostname($server). + '</span></td><td> </td>'; if ($othercontrol{$server}) { $dom_in_effect = $othercontrol{$server}; my ($current,$forsaml); @@ -7341,7 +7428,7 @@ sub user_formats_row { 'username' => 'new usernames', 'id' => 'IDs', ); - unless ($type eq 'email') { + unless (($type eq 'email') || ($type eq 'unamemap')) { my $css_class = $rowcount%2?' class="LC_odd_row"':''; $output = '<tr '.$css_class.'>'. '<td><span class="LC_nobreak">'. @@ -7396,9 +7483,9 @@ sub user_formats_row { } elsif ($colsleft == 1) { $output .= '<td class="LC_left_item"> </td>'; } - $output .= '</tr></table>'; - unless ($type eq 'email') { - $output .= '</td></tr>'; + $output .= '</tr>'; + unless (($type eq 'email') || ($type eq 'unamemap')) { + $output .= '</table></td></tr>'; } return $output; } @@ -7539,7 +7626,7 @@ sub print_defaults { $datatable .= '</td></tr>'; $rownum ++; } - } else { + } elsif ($position eq 'middle') { my %defaults; if (ref($settings) eq 'HASH') { if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) { @@ -7589,6 +7676,22 @@ sub print_defaults { $rownum ++; } } + } else { + my ($unamemaprules,$ruleorder) = + &Apache::lonnet::inst_userrules($dom,'unamemap'); + $css_class = $rownum%2?' class="LC_odd_row"':''; + if ((ref($unamemaprules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) { + my $numinrow = 2; + $datatable .= '<tr'.$css_class.'><td>'.&mt('Available conversions').'</td><td><table>'. + &user_formats_row('unamemap',$settings,$unamemaprules, + $ruleorder,$numinrow). + '</table></td></tr>'; + } + if ($datatable eq '') { + $datatable .= '<tr'.$css_class.'><td colspan="2">'. + &mt('No rules set for domain in customized localenroll.pm'). + '</td></tr>'; + } } $$rowtotal += $rownum; return $datatable; @@ -10031,13 +10134,18 @@ sub modify_colors { $domconfig->{$role} = {}; } foreach my $img (@images) { - if (($role eq 'login') && (($img eq 'img') || ($img eq 'logo'))) { - if (defined($env{'form.login_showlogo_'.$img})) { - $confhash->{$role}{'showlogo'}{$img} = 1; - } else { - $confhash->{$role}{'showlogo'}{$img} = 0; + if ($role eq 'login') { + if (($img eq 'img') || ($img eq 'logo')) { + if (defined($env{'form.login_showlogo_'.$img})) { + $confhash->{$role}{'showlogo'}{$img} = 1; + } else { + $confhash->{$role}{'showlogo'}{$img} = 0; + } } - } + if ($env{'form.login_alt_'.$img} ne '') { + $confhash->{$role}{'alttext'}{$img} = $env{'form.login_alt_'.$img}; + } + } if ( ! $env{'form.'.$role.'_'.$img.'.filename'} && !defined($domconfig->{$role}{$img}) && !$env{'form.'.$role.'_del_'.$img} @@ -10112,15 +10220,29 @@ sub modify_colors { $changes{$role}{'images'}{$img} = 1; } } - if (($role eq 'login') && (($img eq 'logo') || ($img eq 'img'))) { - if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') { - if ($confhash->{$role}{'showlogo'}{$img} ne - $domconfig->{$role}{'showlogo'}{$img}) { - $changes{$role}{'showlogo'}{$img} = 1; + if ($role eq 'login') { + if (($img eq 'logo') || ($img eq 'img')) { + if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') { + if ($confhash->{$role}{'showlogo'}{$img} ne + $domconfig->{$role}{'showlogo'}{$img}) { + $changes{$role}{'showlogo'}{$img} = 1; + } + } else { + if ($confhash->{$role}{'showlogo'}{$img} == 0) { + $changes{$role}{'showlogo'}{$img} = 1; + } } - } else { - if ($confhash->{$role}{'showlogo'}{$img} == 0) { - $changes{$role}{'showlogo'}{$img} = 1; + } + if ($img ne 'login') { + if (ref($domconfig->{$role}{'alttext'}) eq 'HASH') { + if ($confhash->{$role}{'alttext'}{$img} ne + $domconfig->{$role}{'alttext'}{$img}) { + $changes{$role}{'alttext'}{$img} = 1; + } + } else { + if ($confhash->{$role}{'alttext'}{$img} ne '') { + $changes{$role}{'alttext'}{$img} = 1; + } } } } @@ -10231,6 +10353,11 @@ sub default_change_checker { if ($confhash->{$role}{'showlogo'}{$img} == 0) { $changes->{$role}{'showlogo'}{$img} = 1; } + if (ref($confhash->{$role}{'alttext'}) eq 'HASH') { + if ($confhash->{$role}{'alttext'}{$img} ne '') { + $changes->{$role}{'alttext'}{$img} = 1; + } + } } } if ($confhash->{$role}{'font'}) { @@ -10269,6 +10396,13 @@ sub display_colorchgs { } else { $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>'; } + } elsif (($role eq 'login') && ($key eq 'alttext')) { + if ($confhash->{$role}{$key}{$item} ne '') { + $resulttext .= '<li>'.&mt("$choices{$key} for $choices{$item} set to [_1].", + $confhash->{$role}{$key}{$item}).'</li>'; + } else { + $resulttext .= '<li>'.&mt("$choices{$key} for $choices{$item} deleted.").'</li>'; + } } elsif ($confhash->{$role}{$item} eq '') { $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>'; } else { @@ -11320,6 +11454,7 @@ sub modify_quotas { $resulttext .= '<li>'.&mt('Validated course requests identified as processed by: [_1]', '<b>'.$changes{'validation'}{'dc'}.'</b>').'</li>'; } + $resulttext .= '</ul></li>'; } } } @@ -11387,7 +11522,7 @@ sub modify_autoenroll { my %title = ( run => 'Auto-enrollment active', sender => 'Sender for notification messages', coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)', - failsafe => 'Failsafe for no drops if institutional data missing for a section'); + autofailsafe => 'Failsafe for no drops if institutional data missing for a section'); my @offon = ('off','on'); my $sender_uname = $env{'form.sender_uname'}; my $sender_domain = $env{'form.sender_domain'}; @@ -11397,17 +11532,23 @@ sub modify_autoenroll { $sender_domain = ''; } my $coowners = $env{'form.autoassign_coowners'}; + my $autofailsafe = $env{'form.autoenroll_autofailsafe'}; + $autofailsafe =~ s{^\s+|\s+$}{}g; + if ($autofailsafe =~ /\D/) { + undef($autofailsafe); + } my $failsafe = $env{'form.autoenroll_failsafe'}; - $failsafe =~ s{^\s+|\s+$}{}g; - if ($failsafe =~ /\D/) { - undef($failsafe); + unless (($failsafe eq 'zero') || ($failsafe eq 'any')) { + $failsafe = 'off'; + undef($autofailsafe); } my %autoenrollhash = ( autoenroll => { 'run' => $env{'form.autoenroll_run'}, 'sender_uname' => $sender_uname, 'sender_domain' => $sender_domain, 'co-owners' => $coowners, - 'autofailsafe' => $failsafe, + 'autofailsafe' => $autofailsafe, + 'failsafe' => $failsafe, } ); my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash, @@ -11435,9 +11576,12 @@ sub modify_autoenroll { } elsif ($coowners) { $changes{'coowners'} = 1; } - if ($currautoenroll{'autofailsafe'} ne $failsafe) { + if ($currautoenroll{'autofailsafe'} ne $autofailsafe) { $changes{'autofailsafe'} = 1; } + if ($currautoenroll{'failsafe'} ne $failsafe) { + $changes{'failsafe'} = 1; + } if (keys(%changes) > 0) { $resulttext = &mt('Changes made:').'<ul>'; if ($changes{'run'}) { @@ -11458,11 +11602,24 @@ sub modify_autoenroll { } } if ($changes{'autofailsafe'}) { - if ($failsafe ne '') { - $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section set to: [_1]',$failsafe).'</li>'; + if ($autofailsafe ne '') { + $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section set to: [_1]',$autofailsafe).'</li>'; } else { - $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section: deleted'); + $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section not in use').'</li>'; } + } + if ($changes{'failsafe'}) { + if ($failsafe eq 'off') { + unless ($changes{'autofailsafe'}) { + $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section not in use').'</li>'; + } + } elsif ($failsafe eq 'zero') { + $resulttext .= '<li>'.&mt('Failsafe applies if retrieved section enrollment is zero').'</li>'; + } else { + $resulttext .= '<li>'.&mt('Failsafe applies if retrieved section enrollment is zero or greater').'</li>'; + } + } + if (($changes{'autofailsafe'}) || ($changes{'failsafe'})) { &Apache::lonnet::get_domain_defaults($dom,1); if (ref($lastactref) eq 'HASH') { $lastactref->{'domdefaults'} = 1; @@ -14447,6 +14604,41 @@ sub modify_defaults { $newvalues{$item} = $staticdefaults{$item}; } } + my ($unamemaprules,$ruleorder); + my @possunamemaprules = &Apache::loncommon::get_env_multiple('form.unamemap_rule'); + if (@possunamemaprules) { + ($unamemaprules,$ruleorder) = + &Apache::lonnet::inst_userrules($dom,'unamemap'); + if ((ref($unamemaprules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) { + if (@{$ruleorder} > 0) { + my %possrules; + map { $possrules{$_} = 1; } @possunamemaprules; + foreach my $rule (@{$ruleorder}) { + if ($possrules{$rule}) { + push(@{$newvalues{'unamemap_rule'}},$rule); + } + } + } + } + } + if (ref($domdefaults{'unamemap_rule'}) eq 'ARRAY') { + if (ref($newvalues{'unamemap_rule'}) eq 'ARRAY') { + my @rulediffs = &Apache::loncommon::compare_arrays($domdefaults{'unamemap_rule'}, + $newvalues{'unamemap_rule'}); + if (@rulediffs) { + $changes{'unamemap_rule'} = 1; + $domdefaults{'unamemap_rule'} = $newvalues{'unamemap_rule'}; + } + } elsif (@{$domdefaults{'unamemap_rule'}} > 0) { + $changes{'unamemap_rule'} = 1; + delete($domdefaults{'unamemap_rule'}); + } + } elsif (ref($newvalues{'unamemap_rule'}) eq 'ARRAY') { + if (@{$newvalues{'unamemap_rule'}} > 0) { + $changes{'unamemap_rule'} = 1; + $domdefaults{'unamemap_rule'} = $newvalues{'unamemap_rule'}; + } + } my %defaults_hash = ( defaults => \%newvalues, ); @@ -14563,6 +14755,26 @@ sub modify_defaults { $resulttext .= '<li>'.&mt('Institutional user status types deleted').'</li>'; } } + } elsif ($item eq 'unamemap_rule') { + if (ref($newvalues{'unamemap_rule'}) eq 'ARRAY') { + my @rulenames; + if (ref($unamemaprules) eq 'HASH') { + foreach my $rule (@{$newvalues{'unamemap_rule'}}) { + if (ref($unamemaprules->{$rule}) eq 'HASH') { + push(@rulenames,$unamemaprules->{$rule}->{'name'}); + } + } + } + if (@rulenames) { + $resulttext .= '<li>'.&mt('Mapping for missing usernames includes: [_1]', + '<ul><li>'.join('</li><li>',@rulenames).'</li></ul>'). + '</li>'; + } else { + $resulttext .= '<li>'.&mt('No mapping for missing usernames via standard log-in').'</li>'; + } + } else { + $resulttext .= '<li>'.&mt('Mapping for missing usernames via standard log-in deleted').'</li>'; + } } else { my $value = $env{'form.'.$item}; if ($value eq '') { @@ -16370,7 +16582,7 @@ sub modify_wafproxy { } } $output = &mt('Changes were made to Web Application Firewall/Reverse Proxy').'<ul>'; - foreach my $item ('alias','remoteip','ipheader','trusted','vpnint','vpnext','sslopt') { + foreach my $item ('alias','saml','remoteip','ipheader','trusted','vpnint','vpnext','sslopt') { if ($changes{$item}) { if ($item eq 'alias') { my $numaliased = 0; @@ -16457,6 +16669,7 @@ sub modify_wafproxy { } } } + $output .= '</ul>'; } else { $output = '<span class="LC_error">'. &mt('An error occurred: [_1]',$putresult).'</span>'; @@ -17098,8 +17311,13 @@ sub modify_loadbalancing { } } if ($changes{'curr'}{$balancer}{'cookie'}) { - $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- cookie use enabled', - $balancer).'</li>'; + if ($currcookies{$balancer}) { + $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- cookie use disabled', + $balancer).'</li>'; + } else { + $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- cookie use enabled', + $balancer).'</li>'; + } } } }