[LON-CAPA-cvs] cvs: loncom(version_2_11_X) /interface lonmodifycourse.pm
raeburn
raeburn at source.lon-capa.org
Sun Jan 22 14:23:35 EST 2017
raeburn Sun Jan 22 19:23:35 2017 EDT
Modified files: (Branch: version_2_11_X)
/loncom/interface lonmodifycourse.pm
Log:
- For 2.11
- Backport 1.90, 1.91
-------------- next part --------------
Index: loncom/interface/lonmodifycourse.pm
diff -u loncom/interface/lonmodifycourse.pm:1.79.2.4 loncom/interface/lonmodifycourse.pm:1.79.2.5
--- loncom/interface/lonmodifycourse.pm:1.79.2.4 Thu Nov 10 21:57:10 2016
+++ loncom/interface/lonmodifycourse.pm Sun Jan 22 19:23:35 2017
@@ -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 @@
$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(', ', at 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(', ', at 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_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");
+<script type="text/javascript">
+// <![CDATA[
+\$(document).ready(function(){
+ \$( "#LC_adhocrole_chooser" ).dialog({ autoOpen: false });
+});
+
+function gochoose(cname,cdom,cdesc) {
+ document.courselist.pickedcourse.value = cdom+'_'+cname;
+ \$("#LC_choose_adhoc").empty();
+ var pickedaction = \$('input[name=phase]:checked', '#LCcoursepicker').val();
+ if (pickedaction == 'adhocrole') {
+ var http = new XMLHttpRequest();
+ var url = "/adm/pickcourse";
+ var params = "cid="+cdom+"_"+cname+"&context=adhoc";
+ http.open("POST", url, true);
+ http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
+ http.onreadystatechange = function() {
+ if (http.readyState == 4 && http.status == 200) {
+ var data = \$.parseJSON(http.responseText);
+ var len = data.roles.length;
+ if (len == '' || len == null || len == 0) {
+ alert('$jslt{none}');
+ } else {
+ if (len == 1) {
+ \$( '[name="adhocrole"]' )[0].value = data.roles[0].name;
+ document.courselist.submit();
+ } else {
+ var str = '';
+ for (var i=0; i<data.roles.length; i++) {
+ \$("<label><input type='radio' value='"+data.roles[i].name+"' name='LC_get_role' id='LC_get_role_"+i+"' />"+data.roles[i].desc+"</label><span> </span>")
+ .appendTo("#LC_choose_adhoc");
+ }
+ \$( "#LC_get_role_0").prop("checked", true);
+ \$( "#LC_adhocrole_chooser" ).dialog({ autoOpen: false });
+ \$( "#LC_adhocrole_chooser" ).dialog("open");
+ \$( "#LC_adhocrole_chooser" ).dialog({
+ height: 400,
+ width: 500,
+ modal: true,
+ resizable: false,
+ buttons: [
+ {
+ text: "$jslt{'ok'}",
+ click: function() {
+ var rolename = \$('input[name=LC_get_role]:checked', '#LChelpdeskpicker').val();
+ \$( '[name="adhocrole"]' )[0].value = rolename;
+ document.courselist.submit();
+ }
+ },
+ {
+ text: "$jslt{'exit'}",
+ click: function() {
+ \$("#LC_adhocrole_chooser").dialog( "close" );
+ }
+ }
+ ],
+ });
+ \$( "#LC_adhocrole_chooser" ).find( "form" ).on( "submit", function( event ) {
+ event.preventDefault();
+ var rolename = \$('input[name=LC_get_role]:checked', '#LChelpdeskpicker').val()
+ \$( '[name="adhocrole"]' )[0].value = rolename;
+ document.courselist.submit();
+ \$("#LC_adhocrole_chooser").dialog( "close" );
+ });
+ }
+ }
+ }
+ }
+ http.send(params);
+ } else {
+ document.courselist.submit();
+ }
+ return;
+}
+// ]]>
+</script>
+
+<div id="LC_adhocrole_chooser" title="$lt{'title'}">
+ <p>$lt{'preamble'}</p>
+ <form name="LChelpdeskadhoc" id="LChelpdeskpicker" action="">
+ <div id="LC_choose_adhoc">
+ </div>
+ <input type="hidden" name="adhocrole" id="LCadhocrole" value="" />
+ <input type="submit" tabindex="-1" style="position:absolute; top:-1000px" />
+ </form>
+ <p>$lt{'cancel'}</p>
+</div>
+END
+ } elsif ($permission->{'adhocrole'} eq 'coord') {
+ $r->print(<<"END");
+<script type="text/javascript">
+// <![CDATA[
+
+function gochoose(cname,cdom,cdesc) {
+ document.courselist.pickedcourse.value = cdom+'_'+cname;
+ document.courselist.submit();
+ return;
+}
+
+// ]]>
+</script>
+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_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$/, at 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 @@
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 @@
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 @@
catsettings => 'edit',
processcat => 'edit',
selfenroll => 'edit',
+ adhocrole => 'coord',
);
} elsif (&Apache::lonnet::allowed('rar',$dom)) {
$allowed = 1;
@@ -2333,6 +2438,7 @@
setparms => 'view',
catsettings => 'view',
selfenroll => 'view',
+ adhocrole => 'custom',
);
}
return ($allowed,\%permission);
@@ -2385,7 +2491,7 @@
{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 @@
&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')",
More information about the LON-CAPA-cvs
mailing list