--- loncom/interface/lonmodifycourse.pm 2022/02/20 19:22:30 1.79.2.9.2.2
+++ loncom/interface/lonmodifycourse.pm 2023/07/05 18:57:55 1.79.2.9.2.3
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# handler for DC-only modifiable course settings
#
-# $Id: lonmodifycourse.pm,v 1.79.2.9.2.2 2022/02/20 19:22:30 raeburn Exp $
+# $Id: lonmodifycourse.pm,v 1.79.2.9.2.3 2023/07/05 18:57:55 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -411,6 +411,7 @@ sub print_modification_menu {
'selfenroll' => 'View/Modify Self-Enrollment configuration',
'setpostsubmit' => 'View/Modify submit button behavior, post-submission',
'setltiauth' => 'View/Modify re-authentication requirement for LTI launch of deep-linked item',
+ 'setexttool' => 'View/Modify External Tools permissions',
);
} else {
%linktext = (
@@ -419,6 +420,7 @@ sub print_modification_menu {
'selfenroll' => 'View Self-Enrollment configuration',
'setpostsubmit' => 'View submit button behavior, post-submission',
'setltiauth' => 'View re-authentication requirement for LTI launch of deep-linked item',
+ 'setexttool' => 'View External Tools permissions',
);
}
if ($type eq 'Community') {
@@ -457,7 +459,8 @@ sub print_modification_menu {
my $anon_text = &mt('Responder threshold required to display anonymous survey submissions.');
my $postsubmit_text = &mt('Override defaults for submit button behavior post-submission for this specific course.');
my $mysqltables_text = &mt('Override default for lifetime of "temporary" MySQL tables containing student performance data.');
- my $ltiauth_text = &mt('Override default for requirement for re-authentication for LTI-limited launch of deep-linked item');
+ my $ltiauth_text = &mt('Override default for requirement for re-authentication for LTI-limited launch of deep-linked item.');
+ my $exttool_text = &mt('Override default permissions for external tools use for this specific course.');
$linktext{'viewparms'} = 'Display current settings for automated enrollment';
my %domconf = &Apache::lonnet::get_dom('configuration',['coursecategories'],$dom);
@@ -547,6 +550,14 @@ sub print_modification_menu {
permission => $permission->{'setltiauth'},
linktitle => '',
},
+ {
+ linktext => $linktext{'setexttool'},
+ icon => 'exttool.png',
+ #help => '',
+ url => &phaseurl('setexttool'),
+ permission => $permission->{'setexttool'},
+ linktitle => '',
+ },
]
},
);
@@ -578,7 +589,8 @@ sub print_modification_menu {
'
'.$setuploadquota_text.''."\n".
''.$anon_text.''."\n".
''.$postsubmit_text.''."\n".
- ''.$ltiauth_text.''."\n";
+ ''.$ltiauth_text.''."\n".
+ ''.$exttool_text.''."\n";
my ($categories_link_start,$categories_link_end);
if ($permission->{'catsettings'} eq 'edit') {
$categories_link_start = '';
@@ -924,15 +936,7 @@ ENDDOCUMENT
sub domain_postsubtimeout {
my ($cdom,$type,$settings) = @_;
return unless (ref($settings) eq 'HASH');
- my $lctype = lc($type);
- unless ($type eq 'Community') {
- $lctype = 'unofficial';
- if ($settings->{'internal.coursecode'}) {
- $lctype = 'official';
- } elsif ($settings->{'internal.textbook'}) {
- $lctype = 'textbook';
- }
- }
+ my $lctype = &get_lctype($type,$settings);
my %domconfig =
&Apache::lonnet::get_dom('configuration',['coursedefaults'],$cdom);
my $postsubtimeout = 60;
@@ -948,6 +952,22 @@ sub domain_postsubtimeout {
return $postsubtimeout;
}
+sub get_lctype {
+ my ($type,$settings) = @_;
+ my $lctype = lc($type);
+ unless ($type eq 'Community') {
+ $lctype = 'unofficial';
+ if (ref($settings) eq 'HASH') {
+ if ($settings->{'internal.coursecode'}) {
+ $lctype = 'official';
+ } elsif ($settings->{'internal.textbook'}) {
+ $lctype = 'textbook';
+ }
+ }
+ }
+ return $lctype;
+}
+
sub print_catsettings {
my ($r,$cdom,$cnum,$cdesc,$type,$readonly) = @_;
&print_header($r,$type);
@@ -1266,10 +1286,10 @@ sub print_set_ltiauth {
);
my ($domdef,$checkeddom,$checkedcrs,$domdefdisplay,$divsty,$authok,$authno);
$domdef = 0;
- $checkeddom = 'checked="checked "';
+ $checkeddom = ' checked="checked"';
$domdefdisplay = $lt{'logi'};
$divsty = 'display:none';
- $authno = 'checked="checked" ';
+ $authno = ' checked="checked"';
my %domconfig =
&Apache::lonnet::get_dom('configuration',['coursedefaults'],$cdom);
if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
@@ -1286,7 +1306,7 @@ sub print_set_ltiauth {
$checkeddom = '';
$divsty = 'display:inline-block';
if ($ltiauth) {
- $authok = 'checked="checked "';
+ $authok = ' checked="checked"';
}
}
&print_header($r,$type);
@@ -1303,16 +1323,16 @@ sub print_set_ltiauth {
$helpitem $lt{'requ'} $cdesc
$lt{'curd'}: $domdefdisplay
-
+
-
+
$submit
@@ -1324,6 +1344,126 @@ ENDDOCUMENT
return;
}
+sub print_set_exttool {
+ my ($r,$cdom,$cnum,$cdesc,$type,$readonly) = @_;
+ my %titles = &exttool_titles($type);
+ my ($domdef,$domdefdom,$checkeddom,$checkedcrs,$domdefdisplay,$divsty);
+ $domdef = 0;
+ $domdefdom = 1;
+ $checkeddom = ' checked="checked"';
+ $divsty = 'display:none';
+ my %settings = &Apache::lonnet::get('environment',['internal.coursecode',
+ 'internal.textbook'],$cdom,$cnum);
+ my $lctype = &get_lctype($type,\%settings);
+ my %domconfig =
+ &Apache::lonnet::get_dom('configuration',['coursedefaults'],$cdom);
+ if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
+ if (ref($domconfig{'coursedefaults'}{'exttool'}) eq 'HASH') {
+ if (exists($domconfig{'coursedefaults'}{'exttool'}{$lctype})) {
+ $domdef = $domconfig{'coursedefaults'}{'exttool'}{$lctype};
+ }
+ }
+ if (ref($domconfig{'coursedefaults'}{'domexttool'}) eq 'HASH') {
+ if (exists($domconfig{'coursedefaults'}{'domexttool'}{$lctype})) {
+ $domdefdom = $domconfig{'coursedefaults'}{'domexttool'}{$lctype};
+ }
+ }
+ }
+ if ($domdef && $domdefdom) {
+ $domdefdisplay = $titles{'both'};
+ } elsif ($domdef) {
+ $domdefdisplay = $titles{'crs'};
+ } elsif ($domdefdom) {
+ $domdefdisplay = $titles{'dom'};
+ } else {
+ $domdefdisplay = $titles{'none'};
+ }
+ my %settings = &Apache::lonnet::get('environment',['internal.exttool'],$cdom,$cnum);
+ my $crsexttool = $settings{'internal.exttool'};
+ my %crschecked = (
+ both => ' checked="checked"',
+ dom => '',
+ crs => '',
+ none => '',
+ );
+ if ($crsexttool ne '') {
+ $checkedcrs = $checkeddom;
+ $checkeddom = '';
+ $divsty = 'display:inline-block';
+ foreach my $option ('both','dom','crs','none') {
+ if ($crsexttool eq $option) {
+ $crschecked{$option} = ' checked="checked"';
+ } else {
+ $crschecked{$option} = '';
+ }
+ }
+ }
+ &print_header($r,$type);
+ my $hidden_elements = &hidden_form_elements();
+ my ($disabled,$submit);
+ if ($readonly) {
+ $disabled = ' disabled="disabled"';
+ } else {
+ $submit = '';
+ }
+ my $helpitem = &Apache::loncommon::help_open_topic('Modify_Course_External_Tool');
+ $r->print(<
+$helpitem $titles{'extt'}
+$type: $cdesc
+$titles{'curd'}: $domdefdisplay
+
+
+
+
+
+$submit
+
+$hidden_elements
+$titles{'back'}
+
+ENDDOCUMENT
+ return;
+}
+
+sub exttool_titles {
+ my ($type) = @_;
+ my %titles = &Apache::lonlocal::texthash(
+ 'extt' => 'External Tool permissions',
+ 'none' => 'Use of external tools not permitted',
+ 'crs' => 'Only external tools defined in course may be used',
+ 'dom' => 'Only external tools defined in domain may be used',
+ 'both' => 'External tools defined/configured in either domain or course may be used',
+ 'used' => 'Use domain default',
+ 'cour' => 'Use course-specific setting',
+ 'curd' => 'Current domain default is',
+ 'valu' => 'Value for this course',
+ 'modi' => 'Save',
+ 'back' => 'Pick another action',
+ );
+ if ($type eq 'Community') {
+ $titles{'crs'} = &mt('Only external tools defined in community may be used');
+ $titles{'both'} = &mt('External tools defined/configured in either domain or community may be used');
+ $titles{'cour'} = &mt('Use community-specific setting');
+ $titles{'valu'} = &mt('Value for this community');
+ }
+ return %titles;
+}
+
sub modify_selfenrollconfig {
my ($r,$type,$cdesc,$coursehash) = @_;
return unless(ref($coursehash) eq 'HASH');
@@ -1387,6 +1527,8 @@ sub gather_authenitems {
$curr_authtype = 'int';
} elsif ($enrollvar->{'authtype'} eq 'localauth' ) {
$curr_authtype = 'loc';
+ } elsif ($enrollvar->{'authtype'} eq 'lti' ) {
+ $curr_authtype = 'lti';
}
}
unless ($curr_authtype eq '') {
@@ -1407,7 +1549,8 @@ sub gather_authenitems {
$authform{'krb'} = &Apache::loncommon::authform_kerberos(%param);
$authform{'int'} = &Apache::loncommon::authform_internal(%param);
$authform{'loc'} = &Apache::loncommon::authform_local(%param);
- foreach my $item ('krb','int','loc') {
+ $authform{'lti'} = &Apache::loncommon::authform_lti(%param);
+ foreach my $item ('krb','int','loc','lti') {
if ($authform{$item} ne '') {
$authenitems .= $authform{$item}.'
';
}
@@ -1478,6 +1621,8 @@ sub modify_course {
if ((defined($env{'form.locarg'})) && ($env{'form.locarg'})) {
$newattr{'autharg'} = $env{'form.locarg'};
}
+ } elsif ($env{'form.login'} eq 'lti') {
+ $newattr{'authtype'} = 'lti';
}
if ( $newattr{'authtype'}=~ /^krb/) {
if ($newattr{'autharg'} eq '') {
@@ -2414,7 +2559,115 @@ sub modify_ltiauth {
$r->print('
'.$status);
$r->print(''.
''.
- &mt('Pick another action').'
');
+ $lt{'back'}.'');
+ $r->print(&hidden_form_elements().'');
+ return;
+}
+
+sub modify_exttool {
+ my ($r,$cdom,$cnum,$cdesc,$domdesc,$type) = @_;
+ my %titles = &exttool_titles($type);
+ &print_header($r,$type);
+ $r->print('');
return;
}
@@ -2603,6 +2856,35 @@ function toggleLTIOptions(form) {
}
ENDJS
+ } elsif ($phase eq 'setexttool') {
+ $js .= <<"ENDJS";
+function toggleExtToolOptions(form) {
+ var radioname = 'exttoolset';
+ var divid = 'crsexttool';
+ var num = form.elements[radioname].length;
+ if (num) {
+ var setvis = '';
+ for (var i=0; i {'onload' => "toggleLTIOptions(document.setltiauth);"},
};
+ } elsif ($env{'form.phase'} eq 'setexttool') {
+ $starthash = {
+ add_entries => {'onload' => "toggleExtToolOptions(document.setexttool);"},
+ };
}
$r->print(&Apache::loncommon::start_page('View/Modify Course/Community Settings',
&Apache::lonhtmlcommon::scripttag($js),
@@ -2714,8 +3000,8 @@ sub hidden_form_elements {
'locarg','krbarg','krbver','counter','hidefromcat','usecategory',
'threshold','postsubmit','postsubtimeout','defaultcredits','uploadquota',
'selfenrollmgrdc','selfenrollmgrcc','action','state','currsec_st',
- 'sections','newsec','mysqltables','nopasswdchg','ltiauth','ltiauthset'],
- ['^selfenrollmgr_','^selfenroll_'])."\n".
+ 'sections','newsec','mysqltables','nopasswdchg','ltiauth','ltiauthset',
+ 'exttoolset','exttool'],['^selfenrollmgr_','^selfenroll_'])."\n".
'';
return $hidden_elements;
}
@@ -2750,6 +3036,8 @@ sub get_permission {
adhocrole => 'coord',
setltiauth => 'edit',
processltiauth => 'edit',
+ setexttool => 'edit',
+ processexttool => 'edit',
);
if ($passwdconf{'crsownerchg'}) {
$permission{passwdchg} = 'edit';
@@ -2766,6 +3054,7 @@ sub get_permission {
selfenroll => 'view',
adhocrole => 'custom',
setltiauth => 'view',
+ setexttool => 'view',
);
if ($passwdconf{'crsownerchg'}) {
$permission{passwdchg} = 'view';
@@ -2973,11 +3262,22 @@ sub handler {
} elsif (($phase eq 'processltiauth') && ($permission->{'processltiauth'})) {
&Apache::lonhtmlcommon::add_breadcrumb
({href=>"javascript:changePage(document.$phase,'setltiauth')",
- text=>"Requirement for re-authentication for LTI launch of deep-linked item"});
+ text=>"Requirement for re-authentication for LTI launch of deep-linked item"},
+ {href=>"javascript:changePage(document.$phase,'$phase')",
+ text=>"Result"});
+ &modify_ltiauth($r,$cdom,$cnum,$cdesc,$domdesc,$type);
+ } elsif (($phase eq 'setexttool') && ($permission->{'setexttool'})) {
&Apache::lonhtmlcommon::add_breadcrumb
({href=>"javascript:changePage(document.$phase,'$phase')",
+ text=>"External Tool permission"});
+ &print_set_exttool($r,$cdom,$cnum,$cdesc,$type,$readonly);
+ } elsif (($phase eq 'processexttool') && ($permission->{'processexttool'})) {
+ &Apache::lonhtmlcommon::add_breadcrumb
+ ({href=>"javascript:changePage(document.$phase,'setexttool')",
+ text=>"External Tool permission"},
+ {href=>"javascript:changePage(document.$phase,'$phase')",
text=>"Result"});
- &modify_ltiauth($r,$cdom,$cnum,$cdesc,$domdesc,$type);
+ &modify_exttool($r,$cdom,$cnum,$cdesc,$domdesc,$type);
}
}
} else {