--- loncom/interface/domainprefs.pm 2016/09/05 01:46:07 1.277 +++ loncom/interface/domainprefs.pm 2016/10/25 12:45:33 1.283 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Handler to set domain-wide configuration settings # -# $Id: domainprefs.pm,v 1.277 2016/09/05 01:46:07 raeburn Exp $ +# $Id: domainprefs.pm,v 1.283 2016/10/25 12:45:33 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -218,13 +218,13 @@ sub handler { 'serverstatuses','requestcourses','helpsettings', 'coursedefaults','usersessions','loadbalancing', 'requestauthor','selfenrollment','inststatus', - 'ltitools','ssl'],$dom); + 'ltitools','ssl','trust'],$dom); my @prefs_order = ('rolecolors','login','defaults','quotas','autoenroll', 'autoupdate','autocreate','directorysrch','contacts', 'usercreation','selfcreation','usermodification','scantron', 'requestcourses','requestauthor','coursecategories', 'serverstatuses','helpsettings','coursedefaults', - 'ltitools','selfenrollment','usersessions','ssl'); + 'ltitools','selfenrollment','usersessions','ssl','trust'); my %existing; if (ref($domconfig{'loadbalancing'}) eq 'HASH') { %existing = %{$domconfig{'loadbalancing'}}; @@ -417,10 +417,12 @@ sub handler { modify => \&modify_serverstatuses, }, 'helpsettings' => - {text => 'Help page settings', + {text => 'Support settings', help => 'Domain_Configuration_Help_Settings', - header => [{col1 => 'Help Settings (logged-in users)', - col2 => 'Value'}], + header => [{col1 => 'Help Page Settings (logged-in users)', + col2 => 'Value'}, + {col1 => 'Helpdesk Roles', + col2 => 'Settings'},], print => \&print_helpsettings, modify => \&modify_helpsettings, }, @@ -466,7 +468,7 @@ sub handler { print => \&print_usersessions, modify => \&modify_usersessions, }, - 'loadbalancing' => + 'loadbalancing' => {text => 'Dedicated Load Balancer(s)', help => 'Domain_Configuration_Load_Balancing', header => [{col1 => 'Balancers', @@ -477,7 +479,7 @@ sub handler { print => \&print_loadbalancing, modify => \&modify_loadbalancing, }, - 'ltitools' => + 'ltitools' => {text => 'External Tools (LTI)', help => 'Domain_configuration_LTI_Tools', header => [{col1 => 'Setting', @@ -485,7 +487,7 @@ sub handler { print => \&print_ltitools, modify => \&modify_ltitools, }, - 'ssl' => + 'ssl' => {text => 'LON-CAPA Network (SSL)', help => 'Domain_Configuration_Network_SSL', header => [{col1 => 'Server', @@ -497,6 +499,30 @@ sub handler { print => \&print_ssl, modify => \&modify_ssl, }, + 'trust' => + {text => 'Trust Settings', + help => 'Domain_Configuration_Trust', + header => [{col1 => "Access to this domain's content by others", + col2 => 'Rules'}, + {col1 => "Access to other domain's content by this domain", + col2 => 'Rules'}, + {col1 => "Enrollment in this domain's courses by others", + col2 => 'Rules',}, + {col1 => "Co-author roles in this domain for others", + col2 => 'Rules',}, + {col1 => "Co-author roles for this domain's users elsewhere", + col2 => 'Rules',}, + {col1 => "Domain roles in this domain assignable to others", + col2 => 'Rules'}, + {col1 => "Course catalog for this domain displayed elsewhere", + col2 => 'Rules'}, + {col1 => "Requests for creation of courses in this domain by others", + col2 => 'Rules'}, + {col1 => "Users in other domains can send messages to this domain", + col2 => 'Rules'},], + print => \&print_trust, + modify => \&modify_trust, + }, ); if (keys(%servers) > 1) { $prefs{'login'} = { text => 'Log-in page options', @@ -674,6 +700,8 @@ sub process_changes { $output = &modify_ltitools($r,$dom,$action,$lastactref,%domconfig); } elsif ($action eq 'ssl') { $output = &modify_ssl($dom,$lastactref,%domconfig); + } elsif ($action eq 'trust') { + $output = &modify_trust($dom,$lastactref,%domconfig); } return $output; } @@ -686,6 +714,22 @@ sub print_config_box { $output = &coursecategories_javascript($settings); } elsif ($action eq 'defaults') { $output = &defaults_javascript($settings); + } elsif ($action eq 'helpsettings') { + my (%privs,%levelscurrent); + my %full=(); + my %levels=( + course => {}, + domain => {}, + system => {}, + ); + my $context = 'domain'; + my $crstype = 'Course'; + my $formname = 'display'; + &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent); + my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype); + $output = + &Apache::lonuserutils::custom_roledefs_js($context,$crstype,$formname,\%full, + \@templateroles); } $output .= ' @@ -699,7 +743,6 @@ sub print_config_box { if (ref($item->{'header'}) eq 'ARRAY') { $numheaders = scalar(@{$item->{'header'}}); } -print STDERR "$action num ||$numheaders||\n"; if ($numheaders > 1) { my $colspan = ''; my $rightcolspan = ''; @@ -723,7 +766,7 @@ print STDERR "$action num ||$numheaders| if (($action eq 'autoupdate') || ($action eq 'usercreation') || ($action eq 'selfcreation') || ($action eq 'usermodification') || ($action eq 'defaults') || ($action eq 'coursedefaults') || ($action eq 'selfenrollment') || ($action eq 'usersessions') || ($action eq 'ssl') || - ($action eq 'directorysrch')) { + ($action eq 'directorysrch') || ($action eq 'trust') || ($action eq 'helpsettings')) { $output .= $item->{'print'}->('top',$dom,$settings,\$rowtotal); } elsif ($action eq 'coursecategories') { $output .= $item->{'print'}->('top',$dom,$item,$settings,\$rowtotal); @@ -754,14 +797,45 @@ print STDERR "$action num ||$numheaders| if (($action eq 'autoupdate') || ($action eq 'usercreation') || ($action eq 'selfcreation') || ($action eq 'selfenrollment') || ($action eq 'usersessions') || ($action eq 'coursecategories') || - ($action eq 'ssl')) { + ($action eq 'ssl') || ($action eq 'trust')) { if ($action eq 'coursecategories') { $output .= &print_coursecategories('middle',$dom,$item,$settings,\$rowtotal); $colspan = ' colspan="2"'; + } elsif ($action eq 'trust') { + $output .= $item->{'print'}->('shared',$dom,$settings,\$rowtotal); } else { $output .= $item->{'print'}->('middle',$dom,$settings,\$rowtotal); } - $output .= ' + if ($action eq 'trust') { + $output .= ' +
+ + '; + my @trusthdrs = qw(2 3 4 5 6 7); + my @prefixes = qw(enroll othcoau coaurem domroles catalog reqcrs); + for (my $i=0; $i<@trusthdrs; $i++) { + $output .= ' + + + + + + '. + $item->{'print'}->($prefixes[$i],$dom,$settings,\$rowtotal).' +
'.&mt($item->{'header'}->[$trusthdrs[$i]]->{'col1'}).''.&mt($item->{'header'}->[$trusthdrs[$i]]->{'col2'}).'
+ + '; + } + $output .= ' + + + + + + '. + $item->{'print'}->('bottom',$dom,$settings,\$rowtotal); + } else { + $output .= '
'.&mt($item->{'header'}->[8]->{'col1'}).''.&mt($item->{'header'}->[8]->{'col2'}).'
@@ -772,14 +846,16 @@ print STDERR "$action num ||$numheaders| '.&mt($item->{'header'}->[2]->{'col1'}).' '.&mt($item->{'header'}->[2]->{'col2'}).' '."\n"; - if ($action eq 'coursecategories') { - $output .= &print_coursecategories('bottom',$dom,$item,$settings,\$rowtotal); - } else { - $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal); + if ($action eq 'coursecategories') { + $output .= &print_coursecategories('bottom',$dom,$item,$settings,\$rowtotal); + } else { + $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal); + } } $rowtotal ++; } elsif (($action eq 'usermodification') || ($action eq 'coursedefaults') || - ($action eq 'defaults') || ($action eq 'directorysrch')) { + ($action eq 'defaults') || ($action eq 'directorysrch') || + ($action eq 'helpsettings')) { $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal); } elsif ($action eq 'login') { if ($numheaders == 4) { @@ -942,8 +1018,6 @@ print STDERR "$action num ||$numheaders| $output .= $item->{'print'}->($dom,$settings,\$rowtotal); } elsif ($action eq 'scantron') { $output .= &print_scantronformat($r,$dom,$confname,$settings,\$rowtotal); - } elsif ($action eq 'helpsettings') { - $output .= &print_helpsettings($dom,$confname,$settings,\$rowtotal); } } $output .= ' @@ -2969,18 +3043,92 @@ sub print_contacts { } sub print_helpsettings { - my ($dom,$confname,$settings,$rowtotal) = @_; + my ($position,$dom,$settings,$rowtotal) = @_; + my $confname = $dom.'-domainconfig'; my ($datatable,$itemcount); - $itemcount = 1; - my (%choices,%defaultchecked,@toggles); - $choices{'submitbugs'} = &mt('Display link to: [_1]?', - &Apache::loncommon::modal_link('http://bugs.loncapa.org', - &mt('LON-CAPA bug tracker'),600,500)); - %defaultchecked = ('submitbugs' => 'on'); - @toggles = ('submitbugs',); - - ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked, - \%choices,$itemcount); + if ($position eq 'top') { + $itemcount = 1; + my (%choices,%defaultchecked,@toggles); + $choices{'submitbugs'} = &mt('Display link to: [_1]?', + &Apache::loncommon::modal_link('http://bugs.loncapa.org', + &mt('LON-CAPA bug tracker'),600,500)); + %defaultchecked = ('submitbugs' => 'on'); + @toggles = ('submitbugs'); + ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked, + \%choices,$itemcount); + $$rowtotal ++; + } else { + my $css_class; + my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_'); + my %customroles; + foreach my $key (keys(%existing)) { + if ($key=~/^rolesdef\_(\w+)$/) { + my $rolename = $1; + my %privs; + ($privs{'system'},$privs{'domain'},$privs{'course'}) = split(/\_/,$existing{$key}); + $customroles{$rolename} = \%privs; + } + } + my $count = 0; + my $context = 'domprefs'; + my $crstype = 'Course'; + foreach my $role (sort(keys(%customroles))) { + my $prefix = 'custhelp'.$count; + my %full=(); + my %levels= ( + course => {}, + domain => {}, + system => {}, + ); + my %levelscurrent=( + course => {}, + domain => {}, + system => {}, + ); + &Apache::lonuserutils::custom_role_privs($customroles{$role},\%full,\%levels,\%levelscurrent); + my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype); + $css_class = $itemcount%2?' class="LC_odd_row"':''; + $datatable .= ''. + ''.&mt('Existing helpdesk role:').' '. + ''.$role.'
'. + &Apache::lonuserutils::custom_role_header($context,$crstype, + \@templateroles,$prefix). + &Apache::lonuserutils::custom_role_table($crstype,\%full,\%levels, + \%levelscurrent,$prefix). + '
'; + $count ++; + $itemcount ++; + } + $css_class = $itemcount%2?' class="LC_odd_row"':''; + my $newcust = 'custhelp'.$count; + my (%privs,%levelscurrent); + my %full=(); + my %levels= ( + course => {}, + domain => {}, + system => {}, + ); + &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent); + my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype); + $datatable .= ''. + ''. + ''.&mt('Name of new helpdesk role:').' '. + ''. + '
'. + &Apache::lonuserutils::custom_role_header($context,$crstype, + \@templateroles,$newcust). + &Apache::lonuserutils::custom_role_table('Course',\%full,\%levels, + \%levelscurrent,$newcust). + '

'. + ''; + $count ++; + $$rowtotal += $count; + } return $datatable; } @@ -3620,9 +3768,9 @@ sub print_coursedefaults { $additional .= ''."\n"; %defaultchecked = ('postsubmit' => 'on'); @toggles = ('postsubmit'); - my $current = { - 'postsubmit' => $postsubmitclient, - }; + $current = { + 'postsubmit' => $postsubmitclient, + }; ($table,$itemcount) = &radiobutton_prefs($current,\@toggles,\%defaultchecked, \%choices,$itemcount,$onclick,$additional,'left'); @@ -3873,7 +4021,7 @@ sub print_validation_rows { sub print_usersessions { my ($position,$dom,$settings,$rowtotal) = @_; - my ($css_class,$datatable,%checked,%choices); + my ($css_class,$datatable,$itemcount,%checked,%choices); my (%by_ip,%by_location,@intdoms,@instdoms); &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms); @@ -3881,7 +4029,6 @@ sub print_usersessions { my %serverhomes = %Apache::lonnet::serverhomeIDs; my %servers = &Apache::lonnet::internet_dom_servers($dom); my %altids = &id_for_thisdom(%servers); - my $itemcount = 1; if ($position eq 'top') { if (keys(%serverhomes) > 1) { my %spareid = ¤t_offloads_to($dom,$settings,\%servers); @@ -3894,136 +4041,161 @@ sub print_usersessions { $datatable .= &spares_row($dom,\%servers,\%spareid,\%serverhomes,\%altids,$curroffloadnow,$rowtotal); } else { $datatable .= ''. - &mt('Nothing to set here, as the cluster to which this domain belongs only contains one server.'); + &mt('Nothing to set here, as the cluster to which this domain belongs only contains one server.'). + ''; } } else { - if (keys(%by_location) == 0) { - $datatable .= ''. - &mt('Nothing to set here, as the cluster to which this domain belongs only contains one institution.'); + my %titles = &usersession_titles(); + my ($prefix,@types); + if ($position eq 'bottom') { + $prefix = 'remote'; + @types = ('version','excludedomain','includedomain'); } else { - my %lt = &usersession_titles(); - my $numinrow = 5; - my $prefix; - my @types; - if ($position eq 'bottom') { - $prefix = 'remote'; - @types = ('version','excludedomain','includedomain'); - } else { - $prefix = 'hosted'; - @types = ('excludedomain','includedomain'); - } - my (%current,%checkedon,%checkedoff); - my @lcversions = &Apache::lonnet::all_loncaparevs(); - my @locations = sort(keys(%by_location)); - foreach my $type (@types) { - $checkedon{$type} = ''; - $checkedoff{$type} = ' checked="checked"'; - } - if (ref($settings) eq 'HASH') { - if (ref($settings->{$prefix}) eq 'HASH') { - foreach my $key (keys(%{$settings->{$prefix}})) { - $current{$key} = $settings->{$prefix}{$key}; - if ($key eq 'version') { - if ($current{$key} ne '') { - $checkedon{$key} = ' checked="checked"'; - $checkedoff{$key} = ''; - } - } elsif (ref($current{$key}) eq 'ARRAY') { + $prefix = 'hosted'; + @types = ('excludedomain','includedomain'); + } + ($datatable,$itemcount) = &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles); + } + $$rowtotal += $itemcount; + return $datatable; +} + +sub rules_by_location { + my ($settings,$prefix,$by_location,$by_ip,$types,$titles) = @_; + my ($datatable,$itemcount,$css_class); + if (keys(%{$by_location}) == 0) { + $css_class = $itemcount%2 ? ' class="LC_odd_row"' : ''; + $datatable = ''. + &mt('Nothing to set here, as the cluster to which this domain belongs only contains one institution.'). + ''; + $itemcount = 1; + } else { + $itemcount = 0; + my $numinrow = 5; + my (%current,%checkedon,%checkedoff); + my @locations = sort(keys(%{$by_location})); + foreach my $type (@{$types}) { + $checkedon{$type} = ''; + $checkedoff{$type} = ' checked="checked"'; + } + if (ref($settings) eq 'HASH') { + if (ref($settings->{$prefix}) eq 'HASH') { + foreach my $key (keys(%{$settings->{$prefix}})) { + $current{$key} = $settings->{$prefix}{$key}; + if ($key eq 'version') { + if ($current{$key} ne '') { $checkedon{$key} = ' checked="checked"'; $checkedoff{$key} = ''; } + } elsif (ref($current{$key}) eq 'ARRAY') { + $checkedon{$key} = ' checked="checked"'; + $checkedoff{$key} = ''; } } } - foreach my $type (@types) { - next if ($type ne 'version' && !@locations); - $css_class = $itemcount%2 ? ' class="LC_odd_row"' : ''; - $datatable .= ' - '.$lt{$type}.'
-   -   - '; - if ($type eq 'version') { - my $selector = ''.&mt('Not in use').'  + '; + if ($type eq 'version') { + my @lcversions = &Apache::lonnet::all_loncaparevs(); + my $selector = ' '; - $datatable .= &mt('remote server must be version: [_1] or later',$selector); - } else { - $datatable.= '
'.(' 'x2). - ''. - "\n". - '
'; - my $rem; - for (my $i=0; $i<@locations; $i++) { - my ($showloc,$value,$checkedtype); - if (ref($by_location{$locations[$i]}) eq 'ARRAY') { - my $ip = $by_location{$locations[$i]}->[0]; - if (ref($by_ip{$ip}) eq 'ARRAY') { - $value = join(':',@{$by_ip{$ip}}); - $showloc = join(', ',@{$by_ip{$ip}}); - if (ref($current{$type}) eq 'ARRAY') { - foreach my $loc (@{$by_ip{$ip}}) { - if (grep(/^\Q$loc\E$/,@{$current{$type}})) { - $checkedtype = ' checked="checked"'; - last; - } + $selector .= ' '; + } + $selector .= ' '; + $datatable .= &mt('remote server must be version: [_1] or later',$selector); + } else { + $datatable.= '
'.(' 'x2). + ''. + "\n". + '
'; + my $rem; + for (my $i=0; $i<@locations; $i++) { + my ($showloc,$value,$checkedtype); + if (ref($by_location->{$locations[$i]}) eq 'ARRAY') { + my $ip = $by_location->{$locations[$i]}->[0]; + if (ref($by_ip->{$ip}) eq 'ARRAY') { + $value = join(':',@{$by_ip->{$ip}}); + $showloc = join(', ',@{$by_ip->{$ip}}); + if (ref($current{$type}) eq 'ARRAY') { + foreach my $loc (@{$by_ip->{$ip}}) { + if (grep(/^\Q$loc\E$/,@{$current{$type}})) { + $checkedtype = ' checked="checked"'; + last; } } } } - $rem = $i%($numinrow); - if ($rem == 0) { - if ($i > 0) { - $datatable .= ''; - } - $datatable .= ''; - } - $datatable .= ''; - } - $rem = @locations%($numinrow); - my $colsleft = $numinrow - $rem; - if ($colsleft > 1 ) { - $datatable .= ''; - } elsif ($colsleft == 1) { - $datatable .= ''; } - $datatable .= '
'. - ''. - '  
'; + $rem = $i%($numinrow); + if ($rem == 0) { + if ($i > 0) { + $datatable .= ''; + } + $datatable .= ''; + } + $datatable .= ''. + ''; } - $datatable .= ''; - $itemcount ++; + $rem = @locations%($numinrow); + my $colsleft = $numinrow - $rem; + if ($colsleft > 1 ) { + $datatable .= ''. + ' '; + } elsif ($colsleft == 1) { + $datatable .= ' '; + } + $datatable .= ''; } + $datatable .= ''; + $itemcount ++; } } - $$rowtotal += $itemcount; - return $datatable; + return ($datatable,$itemcount); } sub print_ssl { my ($position,$dom,$settings,$rowtotal) = @_; my ($css_class,$datatable); - my $lonhost = ''; my $itemcount = 1; if ($position eq 'top') { - my %domservers = &Apache::lonnet::get_servers($dom); + my $primary_id = &Apache::lonnet::domain($dom,'primary'); + my $intdom = &Apache::lonnet::internet_dom($primary_id); + my $same_institution; + if ($intdom ne '') { + my $internet_names = &Apache::lonnet::get_internet_names($Apache::lonnet::perlvar{'lonHostID'}); + if (ref($internet_names) eq 'ARRAY') { + if (grep(/^\Q$intdom\E$/,@{$internet_names})) { + $same_institution = 1; + } + } + } $css_class = $itemcount%2?' class="LC_odd_row"':''; - $datatable .= ''. - &LONCAPA::SSL::print_certstatus(\%domservers,'web','domprefs'). - ''; + $datatable = ''; + if ($same_institution) { + my %domservers = &Apache::lonnet::get_servers($dom); + $datatable .= &LONCAPA::SSL::print_certstatus(\%domservers,'web','domprefs'); + } else { + $datatable .= &mt("You need to be logged into one of your own domain's servers to display information about the status of LON-CAPA SSL certificates."); + } + $datatable .= ''; $itemcount ++; } else { my %titles = &ssl_titles(); @@ -4079,86 +4251,16 @@ sub print_ssl { $itemcount ++; } } else { - my $numinrow = 5; my $prefix = 'replication'; my @types = ('certreq','nocertreq'); - my (%current,%checkedon,%checkedoff); - my @locations = sort(keys(%by_location)); - foreach my $type (@types) { - $checkedon{$type} = ''; - $checkedoff{$type} = ' checked="checked"'; - } - if (ref($settings) eq 'HASH') { - if (ref($settings->{$prefix}) eq 'HASH') { - foreach my $key (keys(%{$settings->{$prefix}})) { - $current{$key} = $settings->{$prefix}{$key}; - if (ref($current{$key}) eq 'ARRAY') { - $checkedon{$key} = ' checked="checked"'; - $checkedoff{$key} = ''; - } - } - } - } - if (@locations > 0) { - foreach my $type (@types) { - $css_class = $itemcount%2?' class="LC_odd_row"':''; - $datatable .= ' - '.$titles{$type}.'
-   -   - -
'.(' 'x2)."\n". - ''. - "\n". - '
'; - my $rem; - for (my $i=0; $i<@locations; $i++) { - my ($showloc,$value,$checkedtype); - if (ref($by_location{$locations[$i]}) eq 'ARRAY') { - my $ip = $by_location{$locations[$i]}->[0]; - if (ref($by_ip{$ip}) eq 'ARRAY') { - $value = join(':',@{$by_ip{$ip}}); - $showloc = join(', ',@{$by_ip{$ip}}); - if (ref($current{$type}) eq 'ARRAY') { - foreach my $loc (@{$by_ip{$ip}}) { - if (grep(/^\Q$loc\E$/,@{$current{$type}})) { - $checkedtype = ' checked="checked"'; - last; - } - } - } - } - } - $rem = $i%($numinrow); - if ($rem == 0) { - if ($i > 0) { - $datatable .= ''; - } - $datatable .= ''; - } - $datatable .= ''; - } - $rem = @locations%($numinrow); - my $colsleft = $numinrow - $rem; - if ($colsleft > 1 ) { - $datatable .= ''; - } elsif ($colsleft == 1) { - $datatable .= ''; - } - $datatable .= '
'. - ''. - '  
'; - $itemcount ++; - } - } else { - $datatable .= ''.&mt('Nothing to set here, as there are no other institutions').''; + if (keys(%by_location) == 0) { + $datatable .= ''. + &mt('Nothing to set here, as there are no other institutions'). + ''; $itemcount ++; + } else { + ($datatable,$itemcount) = + &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles); } } } @@ -4179,6 +4281,40 @@ sub ssl_titles { yes => 'SSL Optional (used if available)', req => 'SSL Required', ); +} + +sub print_trust { + my ($prefix,$dom,$settings,$rowtotal) = @_; + my ($css_class,$datatable,%checked,%choices); + my (%by_ip,%by_location,@intdoms,@instdoms); + &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms); + my $itemcount = 1; + my %titles = &trust_titles(); + my @types = ('exc','inc'); + if ($prefix eq 'top') { + $prefix = 'content'; + } elsif ($prefix eq 'bottom') { + $prefix = 'msg'; + } + ($datatable,$itemcount) = &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles); + $$rowtotal += $itemcount; + return $datatable; +} + +sub trust_titles { + return &Apache::lonlocal::texthash( + content => "Access to this domain's content by others", + shared => "Access to other domain's content by this domain", + enroll => "Enrollment in this domain's courses by others", + othcoau => "Co-author roles in this domain for others", + coaurem => "Co-author roles for this domain's users elsewhere", + domroles => "Domain roles in this domain assignable to others", + catalog => "Course Catalog for this domain displayed elsewhere", + reqcrs => "Requests for creation of courses in this domain by others", + msg => "Users in other domains can send messages to this domain", + exc => "Allow all, but exclude specific domains", + inc => "Deny all, but include specific domains", + ); } sub build_location_hashes { @@ -11659,30 +11795,78 @@ sub modify_helpsettings { my %defaultchecked = ('submitbugs' => 'on'); my @offon = ('off','on'); my @toggles = ('submitbugs'); + my %current = ('submitbugs' => ''); if (ref($domconfig{'helpsettings'}) eq 'HASH') { - foreach my $item (@toggles) { - if ($defaultchecked{$item} eq 'on') { - if ($domconfig{'helpsettings'}{$item} eq '') { - if ($env{'form.'.$item} eq '0') { - $changes{$item} = 1; - } - } elsif ($domconfig{'helpsettings'}{$item} ne $env{'form.'.$item}) { + %current = %{$domconfig{'helpsettings'}}; + } + foreach my $item (@toggles) { + if ($defaultchecked{$item} eq 'on') { + if ($current{$item} eq '') { + if ($env{'form.'.$item} eq '0') { $changes{$item} = 1; } - } elsif ($defaultchecked{$item} eq 'off') { - if ($domconfig{'helpsettings'}{$item} eq '') { - if ($env{'form.'.$item} eq '1') { - $changes{$item} = 1; - } - } elsif ($domconfig{'helpsettings'}{$item} ne $env{'form.'.$item}) { + } elsif ($current{$item} ne $env{'form.'.$item}) { + $changes{$item} = 1; + } + } elsif ($defaultchecked{$item} eq 'off') { + if ($current{$item} eq '') { + if ($env{'form.'.$item} eq '1') { $changes{$item} = 1; } + } elsif ($current{$item} ne $env{'form.'.$item}) { + $changes{$item} = 1; + } + } + if (($env{'form.'.$item} eq '0') || ($env{'form.'.$item} eq '1')) { + $helphash{'helpsettings'}{$item} = $env{'form.'.$item}; + } + } + + my @modify = &Apache::loncommon::get_env_multiple('form.modifycusthelp'); + my $confname = $dom.'-domainconfig'; + my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_'); + if (@modify) { + foreach my $num (@modify) { + my $rolename = $env{'form.custhelprole'.$num}; + if ($rolename ne '') { + if (exists($existing{'rolesdef_'.$rolename})) { + my $prefix = 'custhelp'.$num; + my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$prefix); + my %currprivs; + ($currprivs{'s'},$currprivs{'d'},$currprivs{'c'}) = + split(/\_/,$existing{'rolesdef_'.$rolename}); + foreach my $level ('c','d','s') { + if ($newprivs{$level} ne $currprivs{$level}) { + $changes{'customrole'}{$rolename} = 1; + my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'}, + $newprivs{'c'},$confname,$dom); + last; + } + } + } } - if (($env{'form.'.$item} eq '0') || ($env{'form.'.$item} eq '1')) { - $helphash{'helpsettings'}{$item} = $env{'form.'.$item}; + } + } + if ($env{'form.newcusthelp'} ne '') { + my $prefix = 'custhelp'.$env{'form.newcusthelp'}; + my $rolename = $env{'form.newcusthelpname'}; + $rolename=~s/[^A-Za-z0-9]//gs; + if ($rolename ne '') { + unless(exists($existing{'rolesdef_'.$rolename})) { + my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$prefix); + my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'}, + $newprivs{'c'},$confname,$dom); + if ($result eq 'ok') { + $changes{'newcustomrole'} = $rolename; + } else { + $errors .= '
  • '. + &mt('An error occurred storing the new custom role: [_1]', + $result).'
  • '; + } } } } + my $putresult; if (keys(%changes) > 0) { $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom); @@ -11693,6 +11877,16 @@ sub modify_helpsettings { $resulttext .= '
  • '.&mt('Display link to: [_1] set to "'.$offon[$env{'form.'.$item}].'".', &Apache::loncommon::modal_link('http://bugs.loncapa.org', &mt('LON-CAPA bug tracker'),600,500)).'
  • '; + } elsif ($item eq 'customrole') { + if (ref($changes{'customrole'}) eq 'HASH') { + foreach my $role (sort(keys(%{$changes{'customrole'}}))) { + $resulttext .= '
  • '.&mt('Existing custom role modified: [_1]', + $role).'
  • '; + } + } + } elsif ($item eq 'newcustomrole') { + $resulttext .= '
  • '.&mt('New custom role added: [_1]', + $changes{'newcustomrole'}).'
  • '; } } $resulttext .= ''; @@ -12673,7 +12867,6 @@ sub modify_ssl { connect => \@connecttypes, replication => \@reptypes, ); - my $action = 'ssl'; foreach my $prefix (sort(keys(%types))) { foreach my $type (@{$types{$prefix}}) { if ($prefix eq 'connect') { @@ -12807,6 +13000,130 @@ sub modify_ssl { } else { $resulttext = $nochgmsg; } + } else { + $resulttext = ''. + &mt('An error occurred: [_1]',$putresult).''; + } + } else { + $resulttext = $nochgmsg; + } + return $resulttext; +} + +sub modify_trust { + my ($dom,$lastactref,%domconfig) = @_; + my (%by_ip,%by_location,@intdoms,@instdoms); + &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms); + my @locations = sort(keys(%by_location)); + my @prefixes = qw(content shared enroll othcoau coaurem domroles catalog reqcrs msg); + my @types = ('exc','inc'); + my (%defaultshash,%changes); + foreach my $prefix (@prefixes) { + $defaultshash{'trust'}{$prefix} = {}; + } + my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1); + my $resulttext; + foreach my $prefix (@prefixes) { + foreach my $type (@types) { + my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'}; + my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type); + my @okvals; + foreach my $val (@vals) { + if ($val =~ /:/) { + my @items = split(/:/,$val); + foreach my $item (@items) { + if (ref($by_location{$item}) eq 'ARRAY') { + push(@okvals,$item); + } + } + } else { + if (ref($by_location{$val}) eq 'ARRAY') { + push(@okvals,$val); + } + } + } + @okvals = sort(@okvals); + if (ref($domconfig{'trust'}) eq 'HASH') { + if (ref($domconfig{'trust'}{$prefix}) eq 'HASH') { + if (ref($domconfig{'trust'}{$prefix}{$type}) eq 'ARRAY') { + if ($inuse == 0) { + $changes{$prefix}{$type} = 1; + } else { + $defaultshash{'trust'}{$prefix}{$type} = \@okvals; + my @changed = &Apache::loncommon::compare_arrays($domconfig{'trust'}{$prefix}{$type},$defaultshash{'trust'}{$prefix}{$type}); + if (@changed > 0) { + $changes{$prefix}{$type} = 1; + } + } + } else { + if ($inuse == 1) { + $defaultshash{'trust'}{$prefix}{$type} = \@okvals; + $changes{$prefix}{$type} = 1; + } + } + } else { + if ($inuse == 1) { + $defaultshash{'trust'}{$prefix}{$type} = \@okvals; + $changes{$prefix}{$type} = 1; + } + } + } else { + if ($inuse == 1) { + $defaultshash{'trust'}{$prefix}{$type} = \@okvals; + $changes{$prefix}{$type} = 1; + } + } + } + } + my $nochgmsg = &mt('No changes made to trust settings.'); + if (keys(%changes) > 0) { + my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash, + $dom); + if ($putresult eq 'ok') { + if (ref($defaultshash{'trust'}) eq 'HASH') { + foreach my $prefix (@prefixes) { + if (ref($defaultshash{'trust'}{$prefix}) eq 'HASH') { + $domdefaults{'trust'.$prefix} = $defaultshash{'trust'}{$prefix}; + } + } + } + my $cachetime = 24*60*60; + &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime); + if (ref($lastactref) eq 'HASH') { + $lastactref->{'domdefaults'} = 1; + } + if (keys(%changes) > 0) { + my %lt = &trust_titles(); + $resulttext = &mt('Changes made:').'
      '; + foreach my $prefix (@prefixes) { + if (ref($changes{$prefix}) eq 'HASH') { + $resulttext .= '
    • '.$lt{$prefix}.'
        '; + foreach my $type (@types) { + if (defined($changes{$prefix}{$type})) { + my $newvalue; + if (ref($defaultshash{'trust'}) eq 'HASH') { + if (ref($defaultshash{'trust'}{$prefix})) { + if (ref($defaultshash{'trust'}{$prefix}{$type}) eq 'ARRAY') { + if (@{$defaultshash{'trust'}{$prefix}{$type}} > 0) { + $newvalue = join(', ',@{$defaultshash{'trust'}{$prefix}{$type}}); + } + } + } + } + if ($newvalue eq '') { + $resulttext .= '
      • '.&mt('[_1] set to: none',$lt{$type}).'
      • '; + } else { + $resulttext .= '
      • '.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'
      • '; + } + } + } + $resulttext .= '
      '; + } + } + $resulttext .= '
    '; + } else { + $resulttext = $nochgmsg; + } } else { $resulttext = ''. &mt('An error occurred: [_1]',$putresult).'';