--- loncom/interface/domainprefs.pm 2017/01/21 21:51:56 1.160.6.76
+++ loncom/interface/domainprefs.pm 2017/01/22 13:28:05 1.160.6.77
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Handler to set domain-wide configuration settings
#
-# $Id: domainprefs.pm,v 1.160.6.76 2017/01/21 21:51:56 raeburn Exp $
+# $Id: domainprefs.pm,v 1.160.6.77 2017/01/22 13:28:05 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -632,7 +632,7 @@ sub process_changes {
} elsif ($action eq 'requestauthor') {
$output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
} elsif ($action eq 'helpsettings') {
- $output = &modify_helpsettings($r,$dom,$confname,%domconfig);
+ $output = &modify_helpsettings($r,$dom,$confname,$lastactref,%domconfig);
} elsif ($action eq 'coursedefaults') {
$output = &modify_coursedefaults($dom,$lastactref,%domconfig);
} elsif ($action eq 'selfenrollment') {
@@ -2884,6 +2884,7 @@ sub print_contacts {
sub print_helpsettings {
my ($position,$dom,$settings,$rowtotal) = @_;
my $confname = $dom.'-domainconfig';
+ my $formname = 'display';
my ($datatable,$itemcount);
if ($position eq 'top') {
$itemcount = 1;
@@ -2899,20 +2900,69 @@ sub print_helpsettings {
} else {
my $css_class;
my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
- my %customroles;
- foreach my $key (keys(%existing)) {
+ my (%customroles,%ordered,%current);
+ if (ref($settings->{'adhoc'}) eq 'HASH') {
+ %current = %{$settings->{'adhoc'}};
+ }
+ my $count = 0;
+ foreach my $key (sort(keys(%existing))) {
if ($key=~/^rolesdef\_(\w+)$/) {
my $rolename = $1;
- my %privs;
+ my (%privs,$order);
($privs{'system'},$privs{'domain'},$privs{'course'}) = split(/\_/,$existing{$key});
$customroles{$rolename} = \%privs;
+ if (ref($current{$rolename}) eq 'HASH') {
+ $order = $current{$rolename}{'order'};
+ }
+ if ($order eq '') {
+ $order = $count;
+ }
+ $ordered{$order} = $rolename;
+ $count++;
}
}
- my $count = 0;
+ my $maxnum = scalar(keys(%ordered));
+ my @roles_by_num = ();
+ foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
+ push(@roles_by_num,$item);
+ }
+ my $context = 'domprefs';
+ my $crstype = 'Course';
+ my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
+ my @accesstypes = ('all','none');
+ my ($numstatustypes,@jsarray);
+ if (ref($types) eq 'ARRAY') {
+ if (@{$types} > 0) {
+ $numstatustypes = scalar(@{$types});
+ push(@accesstypes,'status');
+ @jsarray = ('bystatus');
+ }
+ }
+ my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh']);
+ if (keys(%domhelpdesk)) {
+ push(@accesstypes,('inc','exc'));
+ push(@jsarray,('notinc','notexc'));
+ }
+ my $hiddenstr = join("','",@jsarray);
+ $datatable .= &helpsettings_javascript(\@roles_by_num,$maxnum,$hiddenstr,$formname);
my $context = 'domprefs';
my $crstype = 'Course';
- foreach my $role (sort(keys(%customroles))) {
- my $prefix = 'custhelp'.$count;
+ my $prefix = 'helproles_';
+ my $add_class = 'LC_hidden';
+ foreach my $num (@roles_by_num) {
+ my $role = $ordered{$num};
+ my ($desc,$access,@statuses);
+ if (ref($current{$role}) eq 'HASH') {
+ $desc = $current{$role}{'desc'};
+ $access = $current{$role}{'access'};
+ if (ref($current{$role}{'insttypes'}) eq 'ARRAY') {
+ @statuses = @{$current{$role}{'insttypes'}};
+ }
+ }
+ if ($desc eq '') {
+ $desc = $role;
+ }
+ my $identifier = 'custhelp'.$num;
my %full=();
my %levels= (
course => {},
@@ -2927,18 +2977,32 @@ sub print_helpsettings {
&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('Modify').' '.
- ''.&mt('Existing helpdesk role:').' '.
- ''.$role.' '.
- &Apache::lonuserutils::custom_role_header($context,$crstype,
- \@templateroles,$prefix).
+ my $chgstr = ' onchange="javascript:reorderHelpRoles(this.form,'."'helproles_".$num."_pos'".');"';
+ $datatable .= ' '.$role.' '.
+ '';
+ for (my $k=0; $k<=$maxnum; $k++) {
+ my $vpos = $k+1;
+ my $selstr;
+ if ($k == $num) {
+ $selstr = ' selected="selected" ';
+ }
+ $datatable .= ''.$vpos.' ';
+ }
+ $datatable .= ' '.(' 'x2).
+ ' '.
+ ' '.
+ ''.&mt('Role name').' '.
+ &mt('Name shown to users:').
+ ' '.
+ ' '.
+ &helpdeskroles_access($dom,$prefix,$num,$add_class,$current{$role},\@accesstypes,
+ $othertitle,$usertypes,$types,\%domhelpdesk).
+ ''.
+ ''.&mt('Role privileges').&adhocbutton($prefix,$num,'privs','show').' '.
&Apache::lonuserutils::custom_role_table($crstype,\%full,\%levels,
- \%levelscurrent,$prefix).
- ' ';
- $count ++;
+ \%levelscurrent,$identifier,
+ 'LC_hidden',$prefix.$num.'_privs').
+ '';
$itemcount ++;
}
$css_class = $itemcount%2?' class="LC_odd_row"':'';
@@ -2952,25 +3016,250 @@ sub print_helpsettings {
);
&Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
- $datatable .= ''.
+ my $chgstr = ' onchange="javascript:reorderHelpRoles(this.form,'."'helproles_".$count."_pos'".');"';
+ $datatable .= ''.
+ ' '."\n".
+ '';
+ for (my $k=0; $k<$maxnum+1; $k++) {
+ my $vpos = $k+1;
+ my $selstr;
+ if ($k == $maxnum) {
+ $selstr = ' selected="selected" ';
+ }
+ $datatable .= ''.$vpos.' ';
+ }
+ $datatable .= ' '."\n".
' '. &mt('Add').
' '.
- ''.
- ''.&mt('Name of new helpdesk role:').' '.
- ' '.
- ' '.
+ ''.&mt('Role name').' '.
+ ''.
+ &mt('Internal name:').
+ ' '.
+ ' '.(' 'x4).
+ ''.
+ &mt('Name shown to users:').
+ ' '.
+ ' '.
+ &helpdeskroles_access($dom,$prefix,$count,'',undef,\@accesstypes,$othertitle,
+ $usertypes,$types,\%domhelpdesk).
+ ''.&mt('Role privileges').' '.
&Apache::lonuserutils::custom_role_header($context,$crstype,
\@templateroles,$newcust).
&Apache::lonuserutils::custom_role_table('Course',\%full,\%levels,
\%levelscurrent,$newcust).
- ' '.
- ' ';
+ ' ';
$count ++;
$$rowtotal += $count;
}
return $datatable;
}
+sub adhocbutton {
+ my ($prefix,$num,$field,$visibility) = @_;
+ my %lt = &Apache::lonlocal::texthash(
+ show => 'Show details',
+ hide => 'Hide details',
+ );
+ return ''.(' 'x10).
+ ' '.(' 'x2).' '.(' 'x2);
+}
+
+sub helpsettings_javascript {
+ my ($roles_by_num,$total,$hiddenstr,$formname) = @_;
+ return unless(ref($roles_by_num) eq 'ARRAY');
+ my %html_js_lt = &Apache::lonlocal::texthash(
+ show => 'Show details',
+ hide => 'Hide details',
+ );
+ &html_escape(\%html_js_lt);
+ my $jstext = ' var helproles = Array('."'".join("','",@{$roles_by_num})."'".');'."\n";
+ return <<"ENDSCRIPT";
+
+
+ENDSCRIPT
+}
+
+sub helpdeskroles_access {
+ my ($dom,$prefix,$num,$add_class,$current,$accesstypes,$othertitle,
+ $usertypes,$types,$domhelpdesk) = @_;
+ return unless ((ref($accesstypes) eq 'ARRAY') && (ref($domhelpdesk) eq 'HASH'));
+ my %lt = &Apache::lonlocal::texthash(
+ 'rou' => 'Role usage',
+ 'whi' => 'Which helpdesk personnel may use this role?',
+ 'all' => 'All',
+ 'none' => 'None',
+ 'status' => 'Determined based on institutional status',
+ 'inc' => 'Include all, but exclude specific personnel',
+ 'exc' => 'Exclude all, but include specific personnel',
+ );
+ my %usecheck = (
+ all => ' checked="checked"',
+ );
+ my %displaydiv = (
+ status => 'none',
+ inc => 'none',
+ exc => 'none',
+ priv => 'block',
+ );
+ my $output;
+ if (ref($current) eq 'HASH') {
+ if (($current->{'access'} ne '') && ($current->{'access'} ne 'all')) {
+ if (grep(/^\Q$current->{access}\E$/,@{$accesstypes})) {
+ $usecheck{$current->{access}} = $usecheck{'all'};
+ delete($usecheck{'all'});
+ if ($current->{access} =~ /^(status|inc|exc)$/) {
+ my $access = $1;
+ $displaydiv{$access} = 'inline';
+ } elsif ($current->{access} eq 'none') {
+ $displaydiv{'priv'} = 'none';
+ }
+ }
+ }
+ }
+ $output = ''.$lt{'rou'}.' '.
+ ''.$lt{'whi'}.'
';
+ foreach my $access (@{$accesstypes}) {
+ $output .= ' '.
+ $lt{$access}.' ';
+ if ($access eq 'status') {
+ $output .= '
'.
+ &Apache::lonuserutils::adhoc_status_types($dom,$prefix,$num,$current->{$access},
+ $othertitle,$usertypes,$types).
+ '
';
+ } elsif (($access eq 'inc') && (keys(%{$domhelpdesk}) > 0)) {
+ $output .= ''.
+ &Apache::lonuserutils::adhoc_staff($access,$prefix,$num,$current->{$access},$domhelpdesk).
+ '
';
+ } elsif (($access eq 'exc') && (keys(%{$domhelpdesk}) > 0)) {
+ $output .= ''.
+ &Apache::lonuserutils::adhoc_staff($access,$prefix,$num,$current->{$access},$domhelpdesk).
+ '
';
+ }
+ $output .= '';
+ }
+ $output .= ' ';
+ return $output;
+}
+
sub radiobutton_prefs {
my ($settings,$toggles,$defaultchecked,$choices,$itemcount,$onclick,
$additional,$align) = @_;
@@ -7655,7 +7944,7 @@ sub modify_quotas {
}
if ($env{'form.validationdc'}) {
my $newval = $env{'form.validationdc'};
- my %domcoords = &get_active_dcs($dom);
+ my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
if (exists($domcoords{$newval})) {
$confhash{'validation'}{'dc'} = $newval;
}
@@ -8391,7 +8680,7 @@ sub modify_autocreate {
$newvals{$item} = 0 if ($newvals{$item} eq '');
}
$newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
- my %domcoords = &get_active_dcs($dom);
+ my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
unless (exists($domcoords{$newvals{'xmldc'}})) {
$newvals{'xmldc'} = '';
}
@@ -10547,15 +10836,18 @@ sub modify_serverstatuses {
}
sub modify_helpsettings {
- my ($r,$dom,$confname,%domconfig) = @_;
+ my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
my ($resulttext,$errors,%changes,%helphash);
my %defaultchecked = ('submitbugs' => 'on');
my @offon = ('off','on');
my @toggles = ('submitbugs');
- my %current = ('submitbugs' => '');
+ my %current = ('submitbugs' => '',
+ 'adhoc' => {},
+ );
if (ref($domconfig{'helpsettings'}) eq 'HASH') {
%current = %{$domconfig{'helpsettings'}};
}
+ my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
foreach my $item (@toggles) {
if ($defaultchecked{$item} eq 'on') {
if ($current{$item} eq '') {
@@ -10578,57 +10870,203 @@ sub modify_helpsettings {
$helphash{'helpsettings'}{$item} = $env{'form.'.$item};
}
}
-
- my @modify = &Apache::loncommon::get_env_multiple('form.modifycusthelp');
+ my $maxnum = $env{'form.helproles_maxnum'};
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;
+ my (@allpos,%newsettings,%changedprivs,$newrole);
+ my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
+ my @accesstypes = ('all','none','status','inc','exc');
+ my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh']);
+ my %lt = &Apache::lonlocal::texthash(
+ s => 'system',
+ d => 'domain',
+ order => 'Display order',
+ access => 'Role usage',
+ all => 'All',
+ none => 'None',
+ status => 'Determined based on institutional status',
+ inc => 'Include all, but exclude specific personnel',
+ exc => 'Exclude all, but include specific personnel',
+ );
+ for (my $num=0; $num<=$maxnum; $num++) {
+ my ($prefix,$identifier,$rolename,%curr);
+ if ($num == $maxnum) {
+ next unless ($env{'form.newcusthelp'} == $maxnum);
+ $identifier = 'custhelp'.$num;
+ $prefix = 'helproles_'.$num;
+ $rolename = $env{'form.custhelpname'.$num};
+ $rolename=~s/[^A-Za-z0-9]//gs;
+ next if ($rolename eq '');
+ next if (exists($existing{'rolesdef_'.$rolename}));
+ my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
+ my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
+ $newprivs{'c'},$confname,$dom);
+ if ($result ne 'ok') {
+ $errors .= ''.
+ &mt('An error occurred storing the new custom role: [_1]',
+ $result).' ';
+ next;
+ } else {
+ $changedprivs{$rolename} = \%newprivs;
+ $newrole = $rolename;
+ }
+ } else {
+ $prefix = 'helproles_'.$num;
+ $rolename = $env{'form.'.$prefix};
+ next if ($rolename eq '');
+ next unless (exists($existing{'rolesdef_'.$rolename}));
+ $identifier = 'custhelp'.$num;
+ my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
+ my %currprivs;
+ ($currprivs{'s'},$currprivs{'d'},$currprivs{'c'}) =
+ split(/\_/,$existing{'rolesdef_'.$rolename});
+ foreach my $level ('c','d','s') {
+ if ($newprivs{$level} ne $currprivs{$level}) {
+ my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
+ $newprivs{'c'},$confname,$dom);
+ if ($result ne 'ok') {
+ $errors .= ''.
+ &mt('An error occurred storing privileges for existing role [_1]: [_2]',
+ $rolename,$result).' ';
+ } else {
+ $changedprivs{$rolename} = \%newprivs;
+ }
+ last;
+ }
+ }
+ if (ref($current{'adhoc'}) eq 'HASH') {
+ if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
+ %curr = %{$current{'adhoc'}{$rolename}};
+ }
+ }
+ }
+ my $newpos = $env{'form.'.$prefix.'_pos'};
+ $newpos =~ s/\D+//g;
+ $allpos[$newpos] = $rolename;
+ my $newdesc = $env{'form.'.$prefix.'_desc'};
+ $helphash{'helpsettings'}{'adhoc'}{$rolename}{'desc'} = $newdesc;
+ if ($curr{'desc'}) {
+ if ($curr{'desc'} ne $newdesc) {
+ $changes{'customrole'}{$rolename}{'desc'} = 1;
+ $newsettings{$rolename}{'desc'} = $newdesc;
+ }
+ } elsif ($newdesc ne '') {
+ $changes{'customrole'}{$rolename}{'desc'} = 1;
+ $newsettings{$rolename}{'desc'} = $newdesc;
+ }
+ my $access = $env{'form.'.$prefix.'_access'};
+ if (grep(/^\Q$access\E$/,@accesstypes)) {
+ $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = $access;
+ if ($access eq 'status') {
+ my @statuses = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_status');
+ if (scalar(@statuses) == 0) {
+ $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'none';
+ } else {
+ my (@shownstatus,$numtypes);
+ $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
+ if (ref($types) eq 'ARRAY') {
+ $numtypes = scalar(@{$types});
+ foreach my $type (sort(@statuses)) {
+ if ($type eq 'default') {
+ push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
+ } elsif (grep(/^\Q$type\E$/,@{$types})) {
+ push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
+ push(@shownstatus,$usertypes->{$type});
+ }
}
}
+ if (grep(/^default$/,@statuses)) {
+ push(@shownstatus,$othertitle);
+ }
+ if (scalar(@shownstatus) == 1+$numtypes) {
+ $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'all';
+ delete($helphash{'helpsettings'}{'adhoc'}{$rolename}{'status'});
+ } else {
+ $newsettings{$rolename}{'status'} = join(' '.&mt('or').' ',@shownstatus);
+ if (ref($curr{'status'}) eq 'ARRAY') {
+ my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
+ if (@diffs) {
+ $changes{'customrole'}{$rolename}{$access} = 1;
+ }
+ } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
+ $changes{'customrole'}{$rolename}{$access} = 1;
+ }
+ }
+ }
+ } elsif (($access eq 'inc') || ($access eq 'exc')) {
+ my @personnel = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_staff_'.$access);
+ my @newspecstaff;
+ $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
+ foreach my $person (sort(@personnel)) {
+ if ($domhelpdesk{$person}) {
+ push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$person);
+ }
+ }
+ if (ref($curr{$access}) eq 'ARRAY') {
+ my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
+ if (@diffs) {
+ $changes{'customrole'}{$rolename}{$access} = 1;
+ }
+ } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
+ $changes{'customrole'}{$rolename}{$access} = 1;
}
+ foreach my $person (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
+ my ($uname,$udom) = split(/:/,$person);
+ push(@newspecstaff,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom,'lastname'),$uname,$udom));
+ }
+ $newsettings{$rolename}{$access} = join(', ',sort(@newspecstaff));
}
+ } else {
+ $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}= 'all';
+ }
+ unless ($curr{'access'} eq $access) {
+ $changes{'customrole'}{$rolename}{'access'} = 1;
+ $newsettings{$rolename}{'access'} = $lt{$helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}};
}
}
- 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).' ';
+ if (@allpos > 0) {
+ my $idx = 0;
+ foreach my $rolename (@allpos) {
+ if ($rolename ne '') {
+ $helphash{'helpsettings'}{'adhoc'}{$rolename}{'order'} = $idx;
+ if (ref($current{'adhoc'}) eq 'HASH') {
+ if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
+ if ($current{'adhoc'}{$rolename}{'order'} ne $idx) {
+ $changes{'customrole'}{$rolename}{'order'} = 1;
+ $newsettings{$rolename}{'order'} = $idx+1;
+ }
+ }
}
+ $idx ++;
}
}
}
-
my $putresult;
if (keys(%changes) > 0) {
$putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
if ($putresult eq 'ok') {
- $resulttext = &mt('Changes made:').'';
+ if (ref($helphash{'helpsettings'}) eq 'HASH') {
+ $domdefaults{'submitbugs'} = $helphash{'helpsettings'}{'submitbugs'};
+ if (ref($helphash{'helpsettings'}{'adhoc'}) eq 'HASH') {
+ $domdefaults{'adhocroles'} = $helphash{'helpsettings'}{'adhoc'};
+ }
+ }
+ my $cachetime = 24*60*60;
+ &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
+ if (ref($lastactref) eq 'HASH') {
+ $lastactref->{'domdefaults'} = 1;
+ }
+ } else {
+ $errors .= ''.
+ &mt('An error occurred storing the settings: [_1]',
+ $putresult).' ';
+ }
+ }
+ if ((keys(%changes) && ($putresult eq 'ok')) || (keys(%changedprivs))) {
+ $resulttext = &mt('Changes made:').'';
+ my (%shownprivs,@levelorder);
+ @levelorder = ('c','d','s');
+ if ((keys(%changes)) && ($putresult eq 'ok')) {
foreach my $item (sort(keys(%changes))) {
if ($item eq 'submitbugs') {
$resulttext .= ''.&mt('Display link to: [_1] set to "'.$offon[$env{'form.'.$item}].'".',
@@ -10636,27 +11074,86 @@ sub modify_helpsettings {
&mt('LON-CAPA bug tracker'),600,500)).' ';
} elsif ($item eq 'customrole') {
if (ref($changes{'customrole'}) eq 'HASH') {
+ my @keyorder = ('order','desc','access','status','exc','inc');
+ my %keytext = &Apache::lonlocal::texthash(
+ order => 'Order',
+ desc => 'Role description',
+ access => 'Role usage',
+ status => 'Allowed instituional types',
+ exc => 'Allowed personnel',
+ inc => 'Disallowed personnel',
+ );
foreach my $role (sort(keys(%{$changes{'customrole'}}))) {
- $resulttext .= ''.&mt('Existing custom role modified: [_1]',
- $role).' ';
+ if (ref($changes{'customrole'}{$role}) eq 'HASH') {
+ if ($role eq $newrole) {
+ $resulttext .= ''.&mt('New custom role added: [_1]',
+ $role).'';
+ } else {
+ $resulttext .= ''.&mt('Existing custom role modified: [_1]',
+ $role).'';
+ }
+ foreach my $key (@keyorder) {
+ if ($changes{'customrole'}{$role}{$key}) {
+ $resulttext .= ''.&mt("[_1] set to: [_2]",
+ $keytext{$key},$newsettings{$role}{$key}).
+ ' ';
+ }
+ }
+ if (ref($changedprivs{$role}) eq 'HASH') {
+ $shownprivs{$role} = 1;
+ $resulttext .= ''.&mt('Privileges set to :').'';
+ foreach my $level (@levelorder) {
+ foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
+ next if ($item eq '');
+ my ($priv) = split(/\&/,$item,2);
+ if (&Apache::lonnet::plaintext($priv)) {
+ $resulttext .= ''.&Apache::lonnet::plaintext($priv);
+ unless ($level eq 'c') {
+ $resulttext .= ' ('.$lt{$level}.')';
+ }
+ $resulttext .= ' ';
+ }
+ }
+ }
+ $resulttext .= ' ';
+ }
+ $resulttext .= ' ';
+ }
}
}
- } elsif ($item eq 'newcustomrole') {
- $resulttext .= ''.&mt('New custom role added: [_1]',
- $changes{'newcustomrole'}).' ';
}
}
- $resulttext .= ' ';
- } else {
- $resulttext = &mt('No changes made to help settings');
- $errors .= ' '.
- &mt('An error occurred storing the settings: [_1]',
- $putresult).' ';
}
+ if (keys(%changedprivs)) {
+ foreach my $role (sort(keys(%changedprivs))) {
+ unless ($shownprivs{$role}) {
+ $resulttext .= ''.&mt('Existing custom role modified: [_1]',
+ $role).''.
+ ''.&mt('Privileges set to :').'';
+ foreach my $level (@levelorder) {
+ foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
+ next if ($item eq '');
+ my ($priv) = split(/\&/,$item,2);
+ if (&Apache::lonnet::plaintext($priv)) {
+ $resulttext .= ''.&Apache::lonnet::plaintext($priv);
+ unless ($level eq 'c') {
+ $resulttext .= ' ('.$lt{$level}.')';
+ }
+ $resulttext .= ' ';
+ }
+ }
+ }
+ $resulttext .= ' ';
+ }
+ }
+ }
+ $resulttext .= ' ';
+ } else {
+ $resulttext = &mt('No changes made to help settings');
}
if ($errors) {
$resulttext .= ' '.&mt('The following errors occurred: ').'';
+ $errors.' ';
}
return $resulttext;
}
@@ -11892,24 +12389,9 @@ sub recurse_cat_deletes {
return;
}
-sub get_active_dcs {
- my ($dom) = @_;
- my $now = time;
- my %dompersonnel = &Apache::lonnet::get_domain_roles($dom,['dc'],$now,$now);
- my %domcoords;
- my $numdcs = 0;
- foreach my $server (keys(%dompersonnel)) {
- foreach my $user (sort(keys(%{$dompersonnel{$server}}))) {
- my ($trole,$uname,$udom,$runame,$rudom,$rsec) = split(/:/,$user);
- $domcoords{$uname.':'.$udom} = $dompersonnel{$server}{$user};
- }
- }
- return %domcoords;
-}
-
sub active_dc_picker {
my ($dom,$numinrow,$inputtype,$name,%currhash) = @_;
- my %domcoords = &get_active_dcs($dom);
+ my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
my @domcoord = keys(%domcoords);
if (keys(%currhash)) {
foreach my $dc (keys(%currhash)) {