--- loncom/interface/lonmodifycourse.pm 2016/11/10 21:57:10 1.79.2.4 +++ loncom/interface/lonmodifycourse.pm 2017/01/22 19:23:35 1.79.2.5 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # handler for DC-only modifiable course settings # -# $Id: lonmodifycourse.pm,v 1.79.2.4 2016/11/10 21:57:10 raeburn Exp $ +# $Id: lonmodifycourse.pm,v 1.79.2.5 2017/01/22 19:23:35 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -189,23 +189,20 @@ sub print_course_search_page { $settingsoption = &mt('View or modify course settings which only a [_1] may modify.',$dctitle); } } elsif (&Apache::lonnet::allowed('rar',$dom)) { - my %adhocroles = &Apache::lonnet::userenvironment($env{'user.domain'},$env{'user.name'}, - 'adhocroles.'.$dom); - if (keys(%adhocroles)) { - my @adhoc = split(',',$adhocroles{'adhocroles.'.$dom}); - if (@adhoc > 1) { + my ($roles_by_num,$description,$accessref,$accessinfo) = &Apache::lonnet::get_all_adhocroles($dom); + if ((ref($roles_by_num) eq 'ARRAY') && (ref($description) eq 'HASH')) { + if (@{$roles_by_num} > 1) { if ($type eq 'Community') { - $roleoption = &mt('Enter the community with one of the available ad hoc roles: [_1].', - join(', ',@adhoc)); + $roleoption = &mt('Enter the community with one of the available ad hoc roles'); } else { - $roleoption = &mt('Enter the course with one of the available ad hoc roles: [_1].', - join(', ',@adhoc)); + $roleoption = &mt('Enter the course with one of the available ad hoc roles.'); } } else { + my $rolename = $description->{$roles_by_num->[0]}; if ($type eq 'Community') { - $roleoption = &mt('Enter the community with the ad hoc role of: [_1]',$adhoc[0]); + $roleoption = &mt('Enter the community with the ad hoc role of: [_1]',$rolename); } else { - $roleoption = &mt('Enter the course with the ad hoc role of: [_1]',$adhoc[0]); + $roleoption = &mt('Enter the course with the ad hoc role of: [_1]',$rolename); } } } @@ -224,14 +221,131 @@ sub print_course_search_page { } sub print_course_selection_page { - my ($r,$dom,$domdesc) = @_; + my ($r,$dom,$domdesc,$permission) = @_; my $type = $env{'form.type'}; if (!defined($type)) { $type = 'Course'; } &print_header($r,$type); -# Criteria for course search + if ($permission->{'adhocrole'} eq 'custom') { + my %lt = &Apache::lonlocal::texthash( + title => 'Ad hoc role selection', + preamble => 'Please choose an ad hoc role in the course.', + cancel => 'Click "OK" to enter the course, or "Cancel" to choose a different course.', + ); + my %jslt = &Apache::lonlocal::texthash ( + none => 'You are not eligible to use an ad hoc role for the selected course', + ok => 'OK', + exit => 'Cancel', + ); + &js_escape(\%jslt); + $r->print(<<"END"); + + +
+

$lt{'preamble'}

+
+
+
+ + +
+

$lt{'cancel'}

+
+END + } elsif ($permission->{'adhocrole'} eq 'coord') { + $r->print(<<"END"); + +END + } + +# Criteria for course search my ($filterlist,$filter) = &get_filters(); my $action = '/adm/modifycourse'; my $dctitle = &Apache::lonnet::plaintext('dc'); @@ -476,29 +590,25 @@ sub print_modification_menu { } sub print_adhocrole_selected { - my ($r,$type) = @_; + my ($r,$type,$permission) = @_; &print_header($r,$type); my ($cdom,$cnum) = split(/_/,$env{'form.pickedcourse'}); my ($newrole,$selectrole); - if (&Apache::lonnet::allowed('ccc',$cdom)) { + if ($permission->{'adhocrole'} eq 'coord') { if ($type eq 'Community') { $newrole = "co./$cdom/$cnum"; } else { $newrole = "cc./$cdom/$cnum"; } $selectrole = 1; - } elsif (&Apache::lonnet::allowed('rar',$cdom)) { - my %adhocroles = &Apache::lonnet::userenvironment($env{'user.domain'},$env{'user.name'}, - 'adhocroles.'.$cdom); - if (keys(%adhocroles)) { + } elsif ($permission->{'adhocrole'} eq 'custom') { + my ($okroles,$description) = &Apache::lonnet::get_my_adhocroles($env{'form.pickedcourse'},1); + if (ref($okroles) eq 'ARRAY') { my $possrole = $env{'form.adhocrole'}; - if ($possrole ne '') { - my @adhoc = split(',',$adhocroles{'adhocroles.'.$cdom}); - if (grep(/^\Q$possrole\E$/,@adhoc)) { - my $confname = &Apache::lonnet::get_domainconfiguser($cdom); - $newrole = "cr/$cdom/$confname/$possrole./$cdom/$cnum"; - $selectrole = 1; - } + if (($possrole ne '') && (grep(/^\Q$possrole\E$/,@{$okroles}))) { + my $confname = &Apache::lonnet::get_domainconfiguser($cdom); + $newrole = "cr/$cdom/$confname/$possrole./$cdom/$cnum"; + $selectrole = 1; } } } @@ -2044,13 +2154,7 @@ function changePage(formname,newphase) { if ($phase eq 'setparms') { $js .= $javascript_validations; } elsif ($phase eq 'courselist') { - $js .= qq| - -function gochoose(cname,cdom,cdesc) { - document.courselist.pickedcourse.value = cdom+'_'+cname; - document.courselist.submit(); -} - + $js .= <<"ENDJS"; function hide_searching() { if (document.getElementById('searching')) { document.getElementById('searching').style.display = 'none'; @@ -2058,7 +2162,7 @@ function hide_searching() { return; } -|; +ENDJS } elsif ($phase eq 'setquota') { my $invalid = &mt('The quota you entered contained invalid characters.'); my $alert = &mt('You must enter a number'); @@ -2322,6 +2426,7 @@ sub get_permission { catsettings => 'edit', processcat => 'edit', selfenroll => 'edit', + adhocrole => 'coord', ); } elsif (&Apache::lonnet::allowed('rar',$dom)) { $allowed = 1; @@ -2333,6 +2438,7 @@ sub get_permission { setparms => 'view', catsettings => 'view', selfenroll => 'view', + adhocrole => 'custom', ); } return ($allowed,\%permission); @@ -2385,7 +2491,7 @@ sub handler { {href=>"javascript:changePage(document.$phase,'courselist')", text=>$choose_text}); if ($phase eq 'courselist') { - &print_course_selection_page($r,$dom,$domdesc); + &print_course_selection_page($r,$dom,$domdesc,$permission); } else { my ($checked,$cdesc,$coursehash) = &check_course($dom,$domdesc); if ($checked eq 'ok') { @@ -2406,7 +2512,7 @@ sub handler { &Apache::lonhtmlcommon::add_breadcrumb ({href=>"javascript:changePage(document.$phase,'adhocrole')", text=>$enter_text}); - &print_adhocrole_selected($r,$type); + &print_adhocrole_selected($r,$type,$permission); } else { &Apache::lonhtmlcommon::add_breadcrumb ({href=>"javascript:changePage(document.$phase,'menu')",