--- loncom/interface/lonmodifycourse.pm 2023/08/03 15:57:23 1.102 +++ loncom/interface/lonmodifycourse.pm 2023/12/23 02:17:38 1.104 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # handler for DC-only modifiable course settings # -# $Id: lonmodifycourse.pm,v 1.102 2023/08/03 15:57:23 raeburn Exp $ +# $Id: lonmodifycourse.pm,v 1.104 2023/12/23 02:17:38 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -104,7 +104,7 @@ sub get_enrollment_settings { my ($cdom,$cnum) = @_; my ($internals,$accessdates) = &autoenroll_keys(); my @items; - if ((ref($internals) eq 'ARRAY') && (ref($accessdates) eq 'ARRAY')) { + if ((ref($internals) eq 'ARRAY') && (ref($accessdates) eq 'ARRAY')) { @items = map { 'internal.'.$_; } (@{$internals}); push(@items,@{$accessdates}); } @@ -433,6 +433,7 @@ sub print_modification_menu { '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', + 'setcrsauthor' => 'View/Modify In-course Authoring permissions', ); } else { %linktext = ( @@ -442,10 +443,11 @@ sub print_modification_menu { 'setpostsubmit' => 'View submit button behavior, post-submission', 'setltiauth' => 'View re-authentication requirement for LTI launch of deep-linked item', 'setexttool' => 'View External Tools permissions', + 'setcrsauthor' => 'View In-course Authoring permissions', ); } if ($type eq 'Community') { - if ($permission->{'setparms'} eq 'edit') { + if ($permission->{'setparms'} eq 'edit') { $categorytitle = 'View/Modify Community Settings'; $linktext{'setparms'} = 'View/Modify community owner, self-enrollment and table lifetime'; $linktext{'catsettings'} = 'View/Modify catalog settings for community'; @@ -455,7 +457,7 @@ sub print_modification_menu { $linktext{'catsettings'} = 'View catalog settings for community'; } $setquota_text = &mt('Total disk space allocated for storage of portfolio files in all groups in a community.'); - $setuploadquota_text = &mt('Disk space allocated for storage of content uploaded directly to a community via Content Editor.'); + $setuploadquota_text = &mt('Disk space allocated for storage of content uploaded directly to a community via Content Editor.'); } else { if ($permission->{'setparms'} eq 'edit') { $categorytitle = 'View/Modify Course Settings'; @@ -481,7 +483,7 @@ sub print_modification_menu { $extendedtype = ucfirst(&Apache::lonuserutils::get_extended_type($cdom,$cnum,$type,\%settings)); } 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 $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 $exttool_text = &mt('Override default permissions for external tools use for this specific course.'); @@ -582,6 +584,14 @@ sub print_modification_menu { permission => $permission->{'setexttool'}, linktitle => '', }, + { + linktext => $linktext{'setcrsauthor'}, + icon => 'crsauthor.png', + #help => '', + url => &phaseurl('setcrsauthor'), + permission => $permission->{'setcrsauthor'}, + linktitle => '', + }, ] }, ); @@ -615,9 +625,9 @@ sub print_adhocrole_selected { } $selectrole = 1; } elsif ($permission->{'adhocrole'} eq 'custom') { - my ($okroles,$description) = &Apache::lonnet::get_my_adhocroles($env{'form.pickedcourse'},1); + my ($okroles,$description) = &Apache::lonnet::get_my_adhocroles($env{'form.pickedcourse'},1); if (ref($okroles) eq 'ARRAY') { - my $possrole = $env{'form.adhocrole'}; + my $possrole = $env{'form.adhocrole'}; if (($possrole ne '') && (grep(/^\Q$possrole\E$/,@{$okroles}))) { my $confname = &Apache::lonnet::get_domainconfiguser($cdom); $newrole = "cr/$cdom/$confname/$possrole./$cdom/$cnum"; @@ -817,7 +827,7 @@ sub print_set_anonsurvey_threshold { my %settings = &Apache::lonnet::get('environment',['internal.anonsurvey_threshold'],$cdom,$cnum); my $threshold = $settings{'internal.anonsurvey_threshold'}; if ($threshold eq '') { - my %domconfig = + my %domconfig = &Apache::lonnet::get_dom('configuration',['coursedefaults'],$cdom); if (ref($domconfig{'coursedefaults'}) eq 'HASH') { $threshold = $domconfig{'coursedefaults'}{'anonsurvey_threshold'}; @@ -832,7 +842,7 @@ sub print_set_anonsurvey_threshold { my $hidden_elements = &hidden_form_elements(); my ($disabled,$submit); if ($readonly) { - $disabled = ' disabled="disabled"'; + $disabled = ' disabled="disabled"'; } else { $submit = ''; } @@ -872,11 +882,11 @@ sub print_postsubmit_config { if ($postsubmit eq '') { my %domconfig = &Apache::lonnet::get_dom('configuration',['coursedefaults'],$cdom); - $postsubmit = 1; + $postsubmit = 1; if (ref($domconfig{'coursedefaults'}) eq 'HASH') { if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') { if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'off') { - $postsubmit = 0; + $postsubmit = 0; } } } @@ -910,7 +920,7 @@ sub print_postsubmit_config {

$showtype: $cdesc

-$helpitem $lt{'disa'}: +$helpitem $lt{'disa'}:   

'.$lt{'visi'}.'

'. '

'. @@ -1083,7 +1093,7 @@ sub print_course_modification_page { 'gobt' => "Save", 'sett' => 'Setting', 'domd' => 'Domain default', - 'whom' => 'Who configures', + 'whom' => 'Who configures', ); my ($ownertable,$ccrole,$javascript_validations,$authenitems,$ccname,$disabled); my %enrollvar = &get_enrollment_settings($cdom,$cnum); @@ -1117,11 +1127,11 @@ sub print_course_modification_page { $cc_status{$uname.':'.$udom} = $lt{'actv'}; } } - if (($enrollvar{'courseowner'} ne '') && + if (($enrollvar{'courseowner'} ne '') && (!grep(/^$enrollvar{'courseowner'}$/,@local_ccs))) { push(@local_ccs,$enrollvar{'courseowner'}); my ($owneruname,$ownerdom) = split(/:/,$enrollvar{'courseowner'}); - $pname{$enrollvar{'courseowner'}} = + $pname{$enrollvar{'courseowner'}} = &Apache::loncommon::plainname($owneruname,$ownerdom); my $active_cc = &Apache::loncommon::check_user_status($ownerdom,$owneruname, $cdom,$cnum,$ccrole); @@ -1151,7 +1161,7 @@ sub print_course_modification_page { } else { $ownertable .= ''."\n"; } - $ownertable .= + $ownertable .= ''.$pname{$cc}.''."\n". ''.$cc.''."\n". ''.$cc_status{$cc}.' '.$ccname.''."\n". @@ -1228,7 +1238,7 @@ sub print_course_modification_page { ''.$lt{'whom'}.''. &Apache::loncommon::end_data_table_header_row()."\n"); my %optionname; - $optionname{''} = &mt('Use domain default'); + $optionname{''} = &mt('Use domain default'); $optionname{'0'} = $dctitle; $optionname{'1'} = $cctitle; foreach my $item (@{$selfenrollrows}) { @@ -1243,12 +1253,12 @@ sub print_course_modification_page { $checked{'1'} = ' checked="checked"'; } else { $checked{''} = ' checked="checked"'; - } + } $r->print(&Apache::loncommon::start_data_table_row()."\n". ''.$selfenrolltitles->{$item}.''."\n". ''.&mt('[_1] configures',$default).''."\n". ''); - foreach my $option ('','0','1') { + foreach my $option ('','0','1') { $r->print('

$showtype: $cdesc

- -

$lt{'curd'}: $domdefdisplay

-

-
- -

-
-$lt{'valu'} - - -
- - - -

-$submit -$hidden_elements -

-
-ENDDOCUMENT - my @actions = - (''. - $lt{'back'}.''); - $r->print('
'.&Apache::lonhtmlcommon::actionbox(\@actions)); - 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}; + foreach my $option (@{$options}) { + if ($currcrsval eq $option) { + $crschecked{$option} = ' checked="checked"'; + } else { + $crschecked{$option} = ''; } } - } - 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 { + foreach my $option (@{$options}) { + if ($crsdefault 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 = ''; + $submit = ''; + } + foreach my $option (@{$options}) { + $crselements .= ''. + ''. + '
'."\n"; } - my $helpitem = &Apache::loncommon::help_open_topic('Modify_Course_External_Tool'); + &print_header($r,$type); + my $hidden_elements = &hidden_form_elements(); + my $helpitem = &Apache::loncommon::help_open_topic($helpfile); my $showtype = &mt($type); $r->print(<$helpitem $titles{'extt'} +

$helpitem $title

$showtype: $cdesc

-
+

$titles{'curd'}: $domdefdisplay

-
+
-

-
+

+
$titles{'valu'} - - -
- - -
- - -
- - - +$crselements

$submit $hidden_elements @@ -1473,20 +1388,26 @@ $hidden_elements

ENDDOCUMENT my @actions = - (''. + (''. $titles{'back'}.''); $r->print('
'.&Apache::lonhtmlcommon::actionbox(\@actions)); return; } -sub exttool_titles { +sub default_overrides_titles { my ($type) = @_; my %titles = &Apache::lonlocal::texthash( + 'requ' => 'Requirement for re-authentication for student LTI-limited launch of deep-linked item', + 'link' => 'Link protection can be set to accept username for an enrolled student (if sent by Consumer)', + 'logi' => 'Login needed, regardless of user information sent by LTI Consumer in (signed) parameters', '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', + 'stan' => "'In-course' authoring of standard LON-CAPA problems", + 'on' => 'In-course authoring available', + 'off' => 'In-course authoring unavailable', 'used' => 'Use domain default', 'cour' => 'Use course-specific setting', 'curd' => 'Current domain default is', @@ -1503,6 +1424,85 @@ sub exttool_titles { return %titles; } +sub default_overrides_common { + my ($item,$cdom,$cnum,$type,$titles) = @_; + my ($title,$domdef,$domdefdom,$domdefdisplay,%settings,%optiontext,@options); + if ($item eq 'ltiauth') { + %settings = &Apache::lonnet::get('environment',['internal.'.$item],$cdom,$cnum); + $title = $titles->{'requ'}; + $domdef = 0; + @options = ('0','1'); + %optiontext = ( + 0 => $titles->{'logi'}, + 1 => $titles->{'link'}, + ); + } else { + %settings = + &Apache::lonnet::get('environment',['internal.'.$item,'internal.coursecode', + 'internal.textbook'],$cdom,$cnum); + if ($item eq 'exttool') { + $title = $titles->{'extt'}; + $domdefdom = 1; + $domdef = 0; + @options = ('both','dom','crs','none'); + map { $optiontext{$_} = $titles->{$_}; } @options; + } elsif ($item eq 'crsauthor') { + $title = $titles->{'stan'}; + $domdef = 1; + @options = ('1','0'); + %optiontext = ( + 1 => $titles->{'on'}, + 0 => $titles->{'off'}, + ); + } + } + my %domconfig = + &Apache::lonnet::get_dom('configuration',['coursedefaults'],$cdom); + if (ref($domconfig{'coursedefaults'}) eq 'HASH') { + if ($item eq 'ltiauth') { + $domdef = $domconfig{'coursedefaults'}{$item}; + } else { + my $lctype = &get_lctype($type,\%settings); + if (ref($domconfig{'coursedefaults'}{$item}) eq 'HASH') { + if (exists($domconfig{'coursedefaults'}{$item}{$lctype})) { + $domdef = $domconfig{'coursedefaults'}{$item}{$lctype}; + } + } + if ($item eq 'exttool') { + if (ref($domconfig{'coursedefaults'}{'domexttool'}) eq 'HASH') { + if (exists($domconfig{'coursedefaults'}{'domexttool'}{$lctype})) { + $domdefdom = $domconfig{'coursedefaults'}{'domexttool'}{$lctype}; + } + } + } + } + } + if ($item eq 'ltiauth') { + if ($domdef) { + $domdefdisplay = $titles->{'link'}; + } else { + $domdefdisplay = $titles->{'logi'}; + } + } elsif ($item eq 'exttool') { + if ($domdef && $domdefdom) { + $domdefdisplay = $titles->{'both'}; + } elsif ($domdef) { + $domdefdisplay = $titles->{'crs'}; + } elsif ($domdefdom) { + $domdefdisplay = $titles->{'dom'}; + } else { + $domdefdisplay = $titles->{'none'}; + } + } elsif ($item eq 'crsauthor') { + if ($domdef) { + $domdefdisplay = $titles->{'on'}; + } else { + $domdefdisplay = $titles->{'off'}; + } + } + return ($title,$domdefdisplay,\%settings,\%optiontext,\@options); +} + sub modify_selfenrollconfig { my ($r,$type,$cdesc,$coursehash) = @_; return unless(ref($coursehash) eq 'HASH'); @@ -1577,7 +1577,7 @@ sub gather_authenitems { unless ($curr_authtype eq '') { $curr_authfield = $curr_authtype.'arg'; } - my $javascript_validations = + my $javascript_validations = &Apache::lonuserutils::javascript_validations('modifycourse',$krbdefdom, $curr_authtype,$curr_authfield); my %param = ( formname => 'document.'.$env{'form.phase'}, @@ -1611,7 +1611,7 @@ sub modify_course { unless (($type eq 'Community') || ($type eq 'Placement')) { push(@items,('internal.coursecode','internal.authtype','internal.autharg', 'internal.sectionnums','internal.crosslistings')); - if (&showcredits($cdom)) { + if (&showcredits($cdom)) { push(@items,'internal.defaultcredits'); } my %passwdconf = &Apache::lonnet::get_passwdconf($cdom); @@ -1734,7 +1734,7 @@ sub modify_course { $newattr{'courseowner'}=$env{'form.courseowner'}; unless ( $newattr{'courseowner'} eq $currattr{'courseowner'} ) { $changed{'owner'} = 1; - } + } } if ($changed{'owner'} || $changed{'code'} || $changed{'passwd'}) { @@ -1801,7 +1801,7 @@ sub modify_course { } else { if ($env{'course.'.$cdom.'_'.$cnum.'.description'} ne '') { my %newenv; - map { $newenv{'course.'.$cdom.'_'.$cnum.'.internal.'.$_} = $newattr{$_}; } @changes; + map { $newenv{'course.'.$cdom.'_'.$cnum.'.internal.'.$_} = $newattr{$_}; } @changes; &Apache::lonnet::appenv(\%newenv); } foreach my $attr (@modifiable_params) { @@ -1860,7 +1860,6 @@ sub modify_course { if ($course_check eq 'ok') { my $outcome = &Apache::lonnet::auto_new_course($cnum,$cdom,$inst_course_id,$newattr{'courseowner'},$coowners); unless ($outcome eq 'ok') { - push(@warnings,&mt('If automatic enrollment is enabled for "[_1]", automated enrollment may fail for "[_2]" - section: [_3] for the following reason: "[_4]".',$description,$newattr{'coursecode'},$instsec,$outcome).'
'); } } else { @@ -1924,7 +1923,7 @@ sub modify_course { $nochgresponse .= "

"; } my ($warning,$numwarnings); - my $numwarnings = scalar(@warnings); + my $numwarnings = scalar(@warnings); if ($numwarnings) { $warning = &mt('The following [quant,_1,warning was,warnings were] generated when applying your changes to automated enrollment:',$numwarnings).'

    '; foreach my $warn (@warnings) { @@ -2156,7 +2155,7 @@ sub modify_quota { $showresult{$item} = 1; } } else { - if ($item eq 'coursequota') { + if ($item eq 'coursequota') { $r->print(&mt('The proposed group portfolio quota contained invalid characters, so the quota is unchanged.').'
    '); } else { $r->print(&mt('The proposed quota for content uploaded via the Content Editor contained invalid characters, so the quota is unchanged.').'
    '); @@ -2169,7 +2168,7 @@ sub modify_quota { my $putreply = &Apache::lonnet::put('environment',\%cenv,$cdom, $cnum); foreach my $key (sort(keys(%showresult))) { - if (($oldsettings{'internal.'.$key} eq '') && + if (($oldsettings{'internal.'.$key} eq '') && ($env{'form.'.$key} == $default{$key})) { if ($key eq 'uploadquota') { if ($type eq 'Community') { @@ -2179,7 +2178,7 @@ sub modify_quota { $r->print(&mt('The disk space allocated for files uploaded to this course via the Content Editor is the default quota for this domain: [_1] MB.', $default{$key}).'
    '); } - } else { + } else { if ($type eq 'Community') { $r->print(&mt('The disk space allocated for group portfolio files in this community is the default quota for this domain: [_1] MB.', $default{$key}).'
    '); @@ -2239,7 +2238,7 @@ sub modify_anonsurvey_threshold { my %oldsettings = &Apache::lonnet::get('environment',['internal.anonsurvey_threshold'],$cdom,$cnum); my %domconfig = &Apache::lonnet::get_dom('configuration',['coursedefaults'],$cdom); - my $defaultthreshold; + my $defaultthreshold; if (ref($domconfig{'coursedefaults'}) eq 'HASH') { $defaultthreshold = $domconfig{'coursedefaults'}{'anonsurvey_threshold'}; if ($defaultthreshold eq '') { @@ -2306,14 +2305,14 @@ sub modify_postsubmit_config { $r->print('

    '.$lt{'subb'}.'

    '."\n". '

    '.&mt($type).': '.$cdesc.'

    '."\n". '

    '."\n"); - my %oldsettings = + my %oldsettings = &Apache::lonnet::get('environment',['internal.postsubmit','internal.postsubtimeout','internal.coursecode','internal.textbook'],$cdom,$cnum); my $postsubmit = $env{'form.postsubmit'}; if ($postsubmit eq '1') { my $postsubtimeout = $env{'form.postsubtimeout'}; $postsubtimeout =~ s/[^\d\.]+//g; if (($oldsettings{'internal.postsubmit'} eq $postsubmit) && ($oldsettings{'internal.postsubtimeout'} eq $postsubtimeout)) { - $r->print($lt{'unch'}); + $r->print($lt{'unch'}); } else { my %cenv = ( 'internal.postsubmit' => $postsubmit, @@ -2329,12 +2328,12 @@ sub modify_postsubmit_config { } else { $r->print($lt{'erro'}); } - } else { + } else { $cenv{'internal.postsubtimeout'} = $postsubtimeout; my $putreply = &Apache::lonnet::put('environment',\%cenv,$cdom,$cnum); if ($putreply eq 'ok') { if ($postsubtimeout eq '0') { - $r->print(&mt('Submit button will be disabled after student submission until page is reloaded.')); + $r->print(&mt('Submit button will be disabled after student submission until page is reloaded.')); } else { $r->print(&mt('Submit button will be disabled after student submission for [quant,_1,second].',$postsubtimeout)); } @@ -2348,7 +2347,7 @@ sub modify_postsubmit_config { $r->print($lt{'unch'}); } else { if (exists($oldsettings{'internal.postsubtimeout'})) { - &Apache::lonnet::del('environment',['internal.postsubtimeout'],$cdom,$cnum); + &Apache::lonnet::del('environment',['internal.postsubtimeout'],$cdom,$cnum); } my %cenv = ( 'internal.postsubmit' => $postsubmit, @@ -2393,7 +2392,7 @@ sub modify_catsettings { my (%cenv,@changes,@nochanges); my %currsettings = &Apache::lonnet::get('environment',['hidefromcat','categories'],$cdom,$cnum); - my (@newcategories,%showitem); + my (@newcategories,%showitem); if (grep(/^togglecats$/,@cat_params)) { if ($currsettings{'hidefromcat'} ne $env{'form.hidefromcat'}) { push(@changes,'hidefromcat'); @@ -2439,9 +2438,9 @@ sub modify_catsettings { foreach my $cat (@newcategories) { if (!grep(/^\Q$cat\E$/,@currcategories)) { $catchg = 1; - last; - } - } + last; + } + } } } else { if (@newcategories > 0) { @@ -2509,182 +2508,70 @@ sub modify_catsettings { return; } -sub modify_ltiauth { - my ($r,$cdom,$cnum,$cdesc,$domdesc,$type) = @_; - my %lt = &Apache::lonlocal::texthash( - 'requ' => 'Requirement for re-authentication for student LTI-limited launch of deep-linked item', - 'link' => 'Link protection can be set to accept username for an enrolled student (if sent by Consumer)', - 'logi' => 'Login needed, regardless of user information sent by LTI Consumer in (signed) parameters', - 'used' => 'Use domain default', - 'cour' => 'Use course-specific setting', - 'modi' => 'Save', - 'back' => 'Pick another action', - ); - &print_header($r,$type); - $r->print('

    '.$lt{'requ'}.'

    '."\n". - '

    '.&mt($type).': '.$cdesc.'

    '."\n". - ''."\n"); - my %oldsettings = &Apache::lonnet::get('environment',['internal.ltiauth'],$cdom,$cnum); - my $oldltiauth = $oldsettings{'internal.ltiauth'}; - my $domdef; - my %domconfig = - &Apache::lonnet::get_dom('configuration',['coursedefaults'],$cdom); - if (ref($domconfig{'coursedefaults'}) eq 'HASH') { - $domdef = $domconfig{'coursedefaults'}{'ltiauth'}; - } - my ($newltiauth,$nochange,$change,$status,$error,$ltiauth); - if ($env{'form.ltiauthset'} eq 'dom') { - if ($oldltiauth eq '') { - $nochange = 1; - } else { - $change = 1; - } - } elsif ($env{'form.ltiauthset'} eq 'course') { - if ($env{'form.ltiauth'} =~ /^0|1$/) { - $newltiauth = $env{'form.ltiauth'}; - } - if ($oldltiauth == $newltiauth) { - $nochange = 1; - } else { - $change = 1; - } - } - if ($change) { - if ($newltiauth ne '') { - my %cenv = ( - 'internal.ltiauth' => $newltiauth, - ); - if (&Apache::lonnet::put('environment',\%cenv,$cdom,$cnum) eq 'ok') { - if ($env{'course.'.$cdom.'_'.$cnum.'.description'} ne '') { - &Apache::lonnet::appenv( - {'course.'.$cdom.'_'.$cnum.'.internal.ltiauth' => $newltiauth}); - } - } else { - $error = 1; - } - } else { - if (&Apache::lonnet::del('environment',['internal.ltiauth'],$cdom,$cnum) eq 'ok') { - if (exists($env{'course.'.$cdom.'_'.$cnum.'.internal.ltiauth'})) { - &Apache::lonnet::delenv('course.'.$cdom.'_'.$cnum.'.internal.ltiauth'); - } - } else { - $error = 1; - } - } - } - if ($error) { - $nochange = 1; - } - if ($nochange) { - $ltiauth = $oldltiauth; - } else { - $ltiauth = $newltiauth; - } - if ($ltiauth eq '') { - $status = $lt{'used'}.': '; - if ($domdef) { - $status .= ''.$lt{'link'}.''; - } else { - $status .= ''.$lt{'logi'}.''; - } - } else { - $status = $lt{'cour'}.': '; - if ($ltiauth) { - $status .= ''.$lt{'link'}.''; - } else { - $status .= ''.$lt{'logi'}.''; - } - } - if ($error) { - $r->print('

    '.&mt('An error occurred when saving your changes').'

    '); +sub modify_default_overrides { + my ($r,$cdom,$cnum,$cdesc,$domdesc,$type,$item) = @_; + my (%titles,$oldcrsval,$newcrsval,%resulttext,$itemvalue,$nochange,$change,$status,$error); + %titles = &default_overrides_titles($type); + my ($title,$domdefdisplay,$oldsettings,$optiontext,$options) = + &default_overrides_common($item,$cdom,$cnum,$type,\%titles); + $oldcrsval = $oldsettings->{'internal.'.$item}; + if ($item eq 'ltiauth') { + %resulttext = + &Apache::lonlocal::texthash( + chg => 'Re-authentication requirement for LTI launch of deep-linked changed', + nochg => 'Re-authentication requirement for LTI launch of deep-linked item is unchanged', + ); + } elsif ($item eq 'exttool') { + %resulttext = + &Apache::lonlocal::texthash( + chg => 'External Tool permissions changed', + nochg => 'External Tool permissions unchanged', + ); + } elsif ($item eq 'crsauthor') { + %resulttext = + &Apache::lonlocal::texthash( + chg => 'In-course authoring permissions changed', + nochg => 'In-course authoring permissions unchanged', + ); } - $r->print('

    '); - if ($nochange) { - $r->print(&mt('Re-authentication requirement for LTI launch of deep-linked item is unchanged')); - } elsif ($change) { - $r->print(&mt('Re-authentication requirement for LTI launch of deep-linked changed')); - } - $r->print('
    '.$status.'

    '. - &hidden_form_elements().'
    '); - my @actions = - (''. - $lt{'back'}.''); - $r->print('
    '.&Apache::lonhtmlcommon::actionbox(\@actions)); - return; -} - -sub modify_exttool { - my ($r,$cdom,$cnum,$cdesc,$domdesc,$type) = @_; - my %titles = &exttool_titles($type); &print_header($r,$type); - $r->print('

    '.$titles{'extt'}.'

    '."\n". - '

    '.$type.': '.$cdesc.'

    '."\n". - '
    '."\n"); - my %oldsettings = &Apache::lonnet::get('environment',['internal.exttool'],$cdom,$cnum); - my $oldcrsexttool = $oldsettings{'internal.exttool'}; - my $domdefdom = 1; - my $domdef = 0; - my $domdefdisplay; - 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'}{'domexttool'}) eq 'HASH') { - if (exists($domconfig{'coursedefaults'}{'domexttool'}{$lctype})) { - $domdefdom = $domconfig{'coursedefaults'}{'domexttool'}{$lctype}; - } - } - if (ref($domconfig{'coursedefaults'}{'exttool'}) eq 'HASH') { - if (exists($domconfig{'coursedefaults'}{'exttool'}{$lctype})) { - $domdef = $domconfig{'coursedefaults'}{'exttool'}{$lctype}; - } - } - } - if ($domdef && $domdefdom) { - $domdefdisplay = $titles{'both'}; - } elsif ($domdef) { - $domdefdisplay = $titles{'crs'}; - } elsif ($domdefdom) { - $domdefdisplay = $titles{'dom'}; - } else { - $domdefdisplay = $titles{'none'}; - } - my ($newcrsexttool,$nochange,$change,$status,$error,$exttool); - if ($env{'form.exttoolset'} eq 'dom') { - if ($oldcrsexttool eq '') { + $r->print('

    '.$title.'

    '."\n". + '

    '.&mt($type).': '.$cdesc.'

    '."\n". + ''."\n"); + if ($env{'form.'.$item.'set'} eq 'dom') { + if ($oldcrsval eq '') { $nochange = 1; } else { $change = 1; } - } elsif ($env{'form.exttoolset'} eq 'course') { - if ($env{'form.exttool'} =~ /^both|dom|crs|none$/) { - $newcrsexttool = $env{'form.exttool'}; + } elsif ($env{'form.'.$item.'set'} eq 'course') { + my $posscrsval = $env{'form.'.$item}; + if (grep(/^\Q$posscrsval\E$/,@{$options})) { + $newcrsval = $posscrsval; } - if ($oldcrsexttool eq $newcrsexttool) { + if ($oldcrsval eq $newcrsval) { $nochange = 1; } else { $change = 1; } } if ($change) { - if ($newcrsexttool ne '') { + if ($newcrsval ne '') { my %cenv = ( - 'internal.exttool' => $newcrsexttool, + 'internal.'.$item => $newcrsval, ); if (&Apache::lonnet::put('environment',\%cenv,$cdom,$cnum) eq 'ok') { if ($env{'course.'.$cdom.'_'.$cnum.'.description'} ne '') { &Apache::lonnet::appenv( - {'course.'.$cdom.'_'.$cnum.'.internal.exttool' => $newcrsexttool}); + {'course.'.$cdom.'_'.$cnum.'.internal.'.$item => $newcrsval}); } } else { $error = 1; } } else { - if (&Apache::lonnet::del('environment',['internal.exttool'],$cdom,$cnum) eq 'ok') { - if (exists($env{'course.'.$cdom.'_'.$cnum.'.internal.exttool'})) { - &Apache::lonnet::delenv('course.'.$cdom.'_'.$cnum.'.internal.exttool'); + if (&Apache::lonnet::del('environment',['internal.'.$item],$cdom,$cnum) eq 'ok') { + if (exists($env{'course.'.$cdom.'_'.$cnum.'.internal.'.$item})) { + &Apache::lonnet::delenv('course.'.$cdom.'_'.$cnum.'.internal.'.$item); } } else { $error = 1; @@ -2695,28 +2582,30 @@ sub modify_exttool { $nochange = 1; } if ($nochange) { - $exttool = $oldcrsexttool; + $itemvalue = $oldcrsval; } else { - $exttool = $newcrsexttool; + $itemvalue = $newcrsval; } - if ($exttool eq '') { - $status = $titles{'used'}.': '.$domdefdisplay.''; + if ($itemvalue eq '') { + $status = $titles{'used'}.': '. + ''.$domdefdisplay.''; } else { - $status = $titles{'cour'}.': '.$titles{$exttool}.''; + $status = $titles{'cour'}.': '. + ''.$optiontext->{$itemvalue}.''; } if ($error) { $r->print('

    '.&mt('An error occurred when saving your changes').'

    '); } $r->print('

    '); if ($nochange) { - $r->print(&mt('External Tool permissions unchanged')); + $r->print($resulttext{'nochg'}); } elsif ($change) { - $r->print(&mt('External Tool permissions changed')); + $r->print($resulttext{'chg'}); } $r->print('
    '.$status.'

    '. &hidden_form_elements().'
    '); my @actions = - (''. + (''. $titles{'back'}.''); $r->print('
    '.&Apache::lonhtmlcommon::actionbox(\@actions)); return; @@ -2808,7 +2697,7 @@ ENDSCRIPT &js_escape(\$alert); my $regexp = ' /^\s*\d+\s*$/'; - $js .= <<"ENDSCRIPT"; + $js .= <<"ENDSCRIPT"; function verify_postsubmit() { var optionsElement = document.setpostsubmit.postsubmit; @@ -2840,7 +2729,7 @@ function verify_postsubmit() { } } else { if (currval == 0) { - verified = 'ok'; + verified = 'ok'; } else { alert('$invalid'); return false; @@ -2858,7 +2747,7 @@ function togglePostsubmit(caller) { var optionsElement = document.setpostsubmit.postsubmit; if (document.getElementById(caller)) { var divitem = document.getElementById(caller); - var optionsElement = document.setpostsubmit.postsubmit; + var optionsElement = document.setpostsubmit.postsubmit; if (optionsElement.length) { var currval; for (var i=0; i {'onload' => "hide_searching(); courseSet(document.filterpicker.official, 'load');"}, }; - } elsif ($env{'form.phase'} eq 'setltiauth') { - $starthash = { - add_entries => {'onload' => "toggleLTIOptions(document.setltiauth);"}, - }; - } elsif ($env{'form.phase'} eq 'setexttool') { + } elsif ($env{'form.phase'} =~ /^set(ltiauth|exttool|crsauthor)$/) { $starthash = { - add_entries => {'onload' => "toggleExtToolOptions(document.setexttool);"}, + add_entries => {'onload' => "toggleOptions(document.$env{'form.phase'},'$env{'form.phase'}');"}, }; } $r->print(&Apache::loncommon::start_page('View/Modify Course/Community Settings', @@ -3055,14 +2921,15 @@ sub course_settings_descrip { } sub hidden_form_elements { - my $hidden_elements = + my $hidden_elements = &Apache::lonhtmlcommon::echo_form_input(['gosearch','updater','coursecode', 'prevphase','numlocalcc','courseowner','login','coursequota','intarg', 'locarg','krbarg','krbver','counter','hidefromcat','usecategory', 'threshold','postsubmit','postsubtimeout','defaultcredits','uploadquota', 'selfenrollmgrdc','selfenrollmgrcc','action','state','currsec_st', 'sections','newsec','mysqltables','nopasswdchg','ltiauth','ltiauthset', - 'exttoolset','exttool'],['^selfenrollmgr_','^selfenroll_'])."\n". + 'exttoolset','exttool','crsauthorset','crsauthor'], + ['^selfenrollmgr_','^selfenroll_'])."\n". ''; return $hidden_elements; } @@ -3099,6 +2966,8 @@ sub get_permission { processltiauth => 'edit', setexttool => 'edit', processexttool => 'edit', + setcrsauthor => 'edit', + processcrsauthor => 'edit', ); if ($passwdconf{'crsownerchg'}) { $permission{passwdchg} = 'edit'; @@ -3116,6 +2985,7 @@ sub get_permission { adhocrole => 'custom', setltiauth => 'view', setexttool => 'view', + setcrsauthor => 'view', ); if ($passwdconf{'crsownerchg'}) { $permission{passwdchg} = 'view'; @@ -3185,7 +3055,7 @@ sub handler { $choose_text = "Choose a placement test"; } else { $choose_text = "Choose a course"; - } + } &Apache::lonhtmlcommon::add_breadcrumb ({href=>"javascript:changePage(document.$firstform,'')", text=>"Course/Community search"}, @@ -3200,7 +3070,7 @@ sub handler { if ($type eq 'Community') { $enter_text = 'Enter community'; } elsif ($type eq 'Placement') { - $enter_text = 'Enter placement test'; + $enter_text = 'Enter placement test'; } else { $enter_text = 'Enter course'; } @@ -3223,11 +3093,11 @@ sub handler { my ($cdom,$cnum) = split(/_/,$env{'form.pickedcourse'}); my ($readonly,$linktext); if ($permission->{$phase} eq 'view') { - $readonly = 1; + $readonly = 1; } if (($phase eq 'setquota') && ($permission->{'setquota'})) { if ($permission->{'setquota'} eq 'view') { - $linktext = 'Set quota'; + $linktext = 'Set quota'; } else { $linktext = 'Display quota'; } @@ -3235,7 +3105,7 @@ sub handler { ({href=>"javascript:changePage(document.$phase,'$phase')", text=>$linktext}); &print_setquota($r,$cdom,$cnum,$cdesc,$type,$readonly); - } elsif (($phase eq 'processquota') && ($permission->{'processquota'})) { + } elsif (($phase eq 'processquota') && ($permission->{'processquota'})) { &Apache::lonhtmlcommon::add_breadcrumb ({href=>"javascript:changePage(document.$phase,'setquota')", text=>"Set quota"}); @@ -3314,7 +3184,7 @@ sub handler { if (!exists($env{'form.state'})) { &print_selfenrollconfig($r,$type,$cdesc,$coursehash,$readonly); } elsif ($env{'form.state'} eq 'done') { - &Apache::lonhtmlcommon::add_breadcrumb + &Apache::lonhtmlcommon::add_breadcrumb ({href=>"javascript:changePage(document.$phase,'$phase')", text=>"Result"}); &modify_selfenrollconfig($r,$type,$cdesc,$coursehash); @@ -3322,27 +3192,39 @@ sub handler { } elsif (($phase eq 'setltiauth') && ($permission->{'setltiauth'})) { &Apache::lonhtmlcommon::add_breadcrumb ({href=>"javascript:changePage(document.$phase,'$phase')", - text=>"Requirement for re-authentication for LTI launch of deep-linked item"}); - &print_set_ltiauth($r,$cdom,$cnum,$cdesc,$type,$readonly); + text=>"Authentication post-LTI launch"}); + &print_default_overrides($r,$cdom,$cnum,$cdesc,$type,$readonly,'ltiauth'); } 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=>"Authentication post-LTI launch"}, {href=>"javascript:changePage(document.$phase,'$phase')", text=>"Result"}); - &modify_ltiauth($r,$cdom,$cnum,$cdesc,$domdesc,$type); + &modify_default_overrides($r,$cdom,$cnum,$cdesc,$domdesc,$type,'ltiauth'); } 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); + &print_default_overrides($r,$cdom,$cnum,$cdesc,$type,$readonly,'exttool'); } 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_exttool($r,$cdom,$cnum,$cdesc,$domdesc,$type); + &modify_default_overrides($r,$cdom,$cnum,$cdesc,$domdesc,$type,'exttool'); + } elsif (($phase eq 'setcrsauthor') && ($permission->{'setcrsauthor'})) { + &Apache::lonhtmlcommon::add_breadcrumb + ({href=>"javascript:changePage(document.$phase,'$phase')", + text=>"In-course authoring permission"}); + &print_default_overrides($r,$cdom,$cnum,$cdesc,$type,$readonly,'crsauthor'); + } elsif (($phase eq 'processcrsauthor') && ($permission->{'processcrsauthor'})) { + &Apache::lonhtmlcommon::add_breadcrumb + ({href=>"javascript:changePage(document.$phase,'setcrsauthor')", + text=>"In-course authoring permission"}, + {href=>"javascript:changePage(document.$phase,'$phase')", + text=>"Result"}); + &modify_default_overrides($r,$cdom,$cnum,$cdesc,$domdesc,$type,'crsauthor'); } } } else {