--- loncom/interface/courseprefs.pm 2023/06/03 02:29:57 1.122 +++ loncom/interface/courseprefs.pm 2025/03/15 01:03:33 1.134 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Handler to set configuration settings for a course # -# $Id: courseprefs.pm,v 1.122 2023/06/03 02:29:57 raeburn Exp $ +# $Id: courseprefs.pm,v 1.134 2025/03/15 01:03:33 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -316,7 +316,7 @@ sub handler { idnu => 'Course ID or number', unco => 'Unique code', desc => 'Course Description', - cred => 'Student credits', + cred => 'Student credits', ownr => 'Course Owner', cown => 'Course Co-owners', catg => 'Categorize course', @@ -372,6 +372,12 @@ sub handler { my %values=&Apache::lonnet::dump('environment',$cdom,$cnum); my %linkprot=&Apache::lonnet::dump('lti',$cdom,$cnum,undef,undef,undef,1); + my %domdefs = &Apache::lonnet::get_domain_defaults($cdom); + unless ($phase eq 'process') { + if (ref($domdefs{'linkprotsuggested'}) eq 'HASH') { + $values{'suggested'} = $domdefs{'linkprotsuggested'}; + } + } my %ltienc = &Apache::lonnet::dump('nohist_ltienc',$cdom,$cnum,undef,undef,undef,1); my %ltitools = &Apache::lonnet::dump('ltitools',$cdom,$cnum,undef,undef,undef,1); my %ltitoolsenc = &Apache::lonnet::dump('nohist_toolsenc',$cdom,$cnum,undef,undef,undef,1); @@ -522,7 +528,7 @@ sub handler { uselcmath => 'Student formula entry uses inline preview, not DragMath pop-up', usejsme => 'Molecule editor uses JSME (HTML5) in place of JME (Java)', inline_chem => 'Chemical reaction response uses inline preview, not pop-up', - extresource => 'Display of external resources', + extresource => 'Display of external resources', }, }, 'grading' => @@ -694,6 +700,8 @@ sub get_allitems { if ($item eq 'feedback') { push(@allitems,(map { $_.'.text'; } @{$prefs{$item}{'ordered'}})); } + } elsif (($item eq 'linkprot') || ($item eq 'ltitools')) { + push(@allitems,$item); } } } @@ -791,9 +799,38 @@ sub print_config_box {
'. + $settings->{'suggested'}->{$key}->{'name'}.' | '. + ''. + $settings->{'suggested'}->{$key}->{'info'}. + ' | |||
'.&mt('Recommendation(s) for specific launcher application(s)').' | '. + '||||
'.&mt('Launcher Application').' | '. + ''.&mt('Recommendation(s)').' | |||
'.&mt($item->{'header'}->[0]->{'col1'}).' | '; if (($action eq 'courseinfo') || ($action eq 'localization') || @@ -820,7 +857,7 @@ sub print_config_box { } elsif ($action eq 'appearance') { $output .= &print_appearance($cdom,$settings,$ordered,$itemtext,\$rowtotal,$crstype,$noedit); } elsif ($action eq 'grading') { - $output .= &print_grading($cdom,$settings,$ordered,$itemtext,\$rowtotal,$crstype,$noedit); + $output .= &print_grading($cdom,$cnum,$settings,$ordered,$itemtext,\$rowtotal,$crstype,$noedit); } elsif ($action eq 'printouts') { $output .= &print_printouts($cdom,$settings,$ordered,$itemtext,\$rowtotal,$crstype,$noedit); } elsif ($action eq 'spreadsheet') { @@ -1337,14 +1374,14 @@ sub process_changes { my ($classorder,$classtitles) = &discussion_vote_classes(); my $fontchange = 0; foreach my $class (@{$classorder}) { - my $ext_entry = $entry.'_'.$class; + my $ext_entry = $entry.'_'.$class; my $size = $env{'form.'.$ext_entry.'_size'}; my $unit = $env{'form.'.$ext_entry.'_unit'}; my $weight = $env{'form.'.$ext_entry.'_weight'}; my $style = $env{'form.'.$ext_entry.'_style'}; my $other = $env{'form.'.$ext_entry.'_other'}; $size =~ s/,//g; - $unit =~ s/,//g; + $unit =~ s/,//g; $weight =~ s/,//g; $style =~ s/,//g; $other =~ s/[^\w;:\s\-\%.]//g; @@ -1352,7 +1389,7 @@ sub process_changes { $newvalues{$ext_entry} = join(',',($size.$unit,$weight,$style,$other)); my $current = $values->{$ext_entry}; if ($values->{$ext_entry} eq '') { - $current = ',,,'; + $current = ',,,'; } if ($newvalues{$ext_entry} ne $current) { $changes->{$ext_entry} = $newvalues{$ext_entry}; @@ -1361,7 +1398,7 @@ sub process_changes { } if ($fontchange) { $changes->{$entry} = 1; - } + } } elsif ($entry eq 'nothideprivileged') { my @curr_nothide; my @new_nothide; @@ -1436,7 +1473,7 @@ sub process_changes { my $newtext = $maxnum-1; $newhdr[$env{'form.printfmthdr_pos_'.$newtext}] = $env{'form.printfmthdr_text_'.$newtext}; $newvalues{$entry} = join('',@newhdr); - } elsif (($entry eq 'languages') || + } elsif (($entry eq 'languages') || ($entry eq 'checkforpriv')) { my $settings; my $total = $env{'form.'.$entry.'_total'}; @@ -1452,7 +1489,7 @@ sub process_changes { } if ($env{'form.'.$entry.'_'.$total} ne '') { my $new = $env{'form.'.$entry.'_'.$total}; - if ($entry eq 'languages') { + if ($entry eq 'languages') { my %langchoices = &get_lang_choices(); if ($langchoices{$new}) { $settings .= $new; @@ -1548,10 +1585,37 @@ sub process_changes { } elsif ($values->{$entry}) { $changes->{$entry} = ''; } + } elsif ($entry eq 'grading') { + if ($env{'form.'.$entry} eq 'standard') { + if ($env{'form.hidetotals'}) { + my %sections = &Apache::loncommon::get_sections($cdom,$cnum); + if (keys(%sections)) { + my @secs = &Apache::loncommon::get_env_multiple('form.hidetotals_sections'); + if (grep(/^all$/,@secs)) { + $newvalues{'hidetotals'} = 'all'; + } elsif (@secs) { + $newvalues{'hidetotals'} = ''; + foreach my $sec (sort {$a <=> $b} @secs) { + if (exists($sections{$sec})) { + $newvalues{'hidetotals'} .= $sec.',' + } + } + $newvalues{'hidetotals'} =~ s/,$//; + } + } else { + $newvalues{'hidetotals'} = 'all'; + } + } + } + if ($newvalues{'hidetotals'} ne $values->{'hidetotals'}) { + $changes->{'hidetotals'} = $newvalues{'hidetotals'}; + $changes->{'grading'} = $env{'form.'.$entry}; + } + $newvalues{$entry} = $env{'form.'.$entry}; } else { $newvalues{$entry} = $env{'form.'.$entry}; } - unless (($entry eq 'co-owners') || ($entry eq 'discussion_post_fonts') || + unless (($entry eq 'co-owners') || ($entry eq 'discussion_post_fonts') || ($entry eq 'extresource') || ($entry eq 'timezone')) { if ($newvalues{$entry} ne $values->{$entry}) { $changes->{$entry} = $newvalues{$entry}; @@ -1680,6 +1744,9 @@ sub process_linkprot { $haschanges{$itemid} = 1; } } + if ($env{$urlparamname} ne '') { + $linkprot{$itemid}{'returnurl'} = $env{$urlparamname}; + } if ($env{$passbackparamname} ne '') { $linkprot{$itemid}{'passback'} = 1; $linkprot{$itemid}{'passbackformat'} = $env{$passbackparamname}; @@ -1794,7 +1861,7 @@ sub get_linkprot_id { $tries ++; sleep (0.1); if ($context eq 'domain') { - $gotlock = &Apache::lonnet::newput_dom('linkprot',$lockhash,$cdom); + $gotlock = &Apache::lonnet::newput_dom('linkprot',$lockhash,$cdom); } else { $gotlock = &Apache::lonnet::newput('lti',$lockhash,$cdom,$cnum); } @@ -1832,7 +1899,7 @@ sub get_linkprot_id { $error = 'nonumber'; } } - my $dellockoutcome; + my $dellockoutcome; if ($context eq 'domain') { $dellockoutcome = &Apache::lonnet::del_dom('linkprot',['lock'],$cdom); } else { @@ -1911,7 +1978,7 @@ sub process_ltitools { if ($env{'form.ltitools_add'}) { my $title = $env{'form.ltitools_add_title'}; $title =~ s/(`)/'/g; - my ($newid,$error) = &get_ltitools_id($context,$cdom,$cnum,$title); + my ($newid,$error) = &Apache::lonnet::get_ltitools_id($context,$cdom,$cnum,$title); if ($newid) { my $position = $env{'form.ltitools_add_pos'}; $position =~ s/\D+//g; @@ -1959,10 +2026,14 @@ sub process_ltitools { } else { $ltitools{$newid}{'display'}{'target'} = 'iframe'; } - foreach my $item ('passback','roster') { + foreach my $item ('passback','roster','returnurl') { if ($env{'form.ltitools_'.$item.'_add'}) { $ltitools{$newid}{$item} = 1; - if ($env{'form.ltitools_'.$item.'valid_add'} ne '') { + if ($item eq 'returnurl') { + if ($env{'form.ltitools_crs'.$item.'_add'}) { + $ltitools{$newid}{'crsconf'}{$item} = 1; + } + } elsif ($env{'form.ltitools_'.$item.'valid_add'} ne '') { my $lifetime = $env{'form.ltitools_'.$item.'valid_add'}; $lifetime =~ s/^\s+|\s+$//g; if ($lifetime =~ /^\d+\.?\d*$/) { @@ -2146,10 +2217,21 @@ sub process_ltitools { } else { $haschanges{$itemid} = 1; } - foreach my $extra ('passback','roster') { + foreach my $extra ('passback','roster','returnurl') { if ($env{'form.ltitools_'.$extra.'_'.$i}) { $ltitools{$itemid}{$extra} = 1; - if ($env{'form.ltitools_'.$extra.'valid_'.$i} ne '') { + if ($extra eq 'returnurl') { + if ($env{'form.ltitools_crs'.$extra.'_'.$i}) { + $ltitools{$itemid}{'crsconf'}{$extra} = 1; + if (ref($values->{$itemid}{'crsconf'}) eq 'HASH') { + if (!$values->{$itemid}{'crsconf'}{$extra}) { + $haschanges{$itemid} = 1; + } + } else { + $haschanges{$itemid} = 1; + } + } + } elsif ($env{'form.ltitools_'.$extra.'valid_'.$i} ne '') { my $lifetime = $env{'form.ltitools_'.$extra.'valid_'.$i}; $lifetime =~ s/^\s+|\s+$//g; if ($lifetime =~ /^\d+\.?\d*$/) { @@ -2365,73 +2447,6 @@ sub process_ltitools { return $errors; } -sub get_ltitools_id { - my ($context,$cdom,$cnum,$title) = @_; - my ($lockhash,$tries,$gotlock,$id,$error); - - # get lock on ltitools db - $lockhash = { - lock => $env{'user.name'}. - ':'.$env{'user.domain'}, - }; - $tries = 0; - if ($context eq 'domain') { - $gotlock = &Apache::lonnet::newput_dom('ltitools',$lockhash,$cdom); - } else { - $gotlock = &Apache::lonnet::newput('ltitools',$lockhash,$cdom,$cnum); - } - while (($gotlock ne 'ok') && ($tries<10)) { - $tries ++; - sleep (0.1); - if ($context eq 'domain') { - $gotlock = &Apache::lonnet::newput_dom('ltitools',$lockhash,$cdom); - } else { - $gotlock = &Apache::lonnet::newput('ltitools',$lockhash,$cdom,$cnum); - } - } - if ($gotlock eq 'ok') { - my %currids; - if ($context eq 'domain') { - %currids = &Apache::lonnet::dump_dom('ltitools',$cdom); - } else { - %currids = &Apache::lonnet::dump('ltitools',$cdom,$cnum); - } - if ($currids{'lock'}) { - delete($currids{'lock'}); - if (keys(%currids)) { - my @curr = sort { $a <=> $b } keys(%currids); - if ($curr[-1] =~ /^\d+$/) { - $id = 1 + $curr[-1]; - } - } else { - $id = 1; - } - if ($id) { - if ($context eq 'domain') { - unless (&Apache::lonnet::newput_dom('ltitools',{ $id => $title },$cdom) eq 'ok') { - $error = 'nostore'; - } - } else { - unless (&Apache::lonnet::newput('ltitools',{ $id => $title },$cdom,$cnum) eq 'ok') { - $error = 'nostore'; - } - } - } else { - $error = 'nonumber'; - } - } - my $dellockoutcome; - if ($context eq 'domain') { - $dellockoutcome = &Apache::lonnet::del_dom('ltitools',['lock'],$cdom); - } else { - $dellockoutcome = &Apache::lonnet::del('ltitools',['lock'],$cdom,$cnum); - } - } else { - $error = 'nolock'; - } - return ($id,$error); -} - sub process_ltitools_image { my ($r,$context,$dom,$cnum,$confname,$caller,$itemid,$configuserok,$switch,$author_ok,$currimg) = @_; my $filename = $env{'form.'.$caller.'.filename'}; @@ -2693,6 +2708,40 @@ sub store_changes { unless (($key eq 'co-owners') || ($key eq 'discussion_post_fonts') || ($key eq 'extresource')) { $displayval = $changes->{$item}{$key}; } + if (($item eq 'grading') && ($key eq 'grading')) { + if ($displayval eq 'standard') { + my $hidetotals; + if (exists($changes->{$item}{'hidetotals'})) { + if ($changes->{$item}{'hidetotals'} eq '') { + if (exists($values->{'hidetotals'})) { + push(@delkeys,'hidetotals'); + } + } else { + $hidetotals = $changes->{$item}{'hidetotals'}; + } + } elsif (exists($values->{'hidetotals'})) { + $hidetotals = $values->{'hidetotals'}; + } + if ($hidetotals eq '') { + $displayval = &mt('standard with "hide course totals" set to "No"'); + if (exists($values->{'hidetotals'})) { + push(@delkeys,'hidetotals'); + } + } elsif ($hidetotals =~ /^([\w,]+)$/) { + my $secstr = $1; + my @secs = split(/,/,$secstr); + if (grep(/^all$/,@secs)) { + $displayval = &mt('standard with "hide course totals" set to "Yes" for all users'); + $hidetotals = 'all'; + } else { + $displayval = &mt('standard with "hide course totals" set to "Yes" for users in section(s): [_1]',join(', ',@secs)); + } + $storehash{'hidetotals'} = $hidetotals; + } + } elsif (exists($values->{'hidetotals'})) { + push(@delkeys,'hidetotals'); + } + } if ($item eq 'feedback') { if ($key =~ /^(question|policy|comment)(\.email)\.text$/) { $text = $prefs->{$item}->{'itemtext'}{$1.$2}; @@ -2701,14 +2750,14 @@ sub store_changes { $displayname = &mt('Recipients of '.$text.' questions'); } } elsif ($item eq 'discussion') { - if ($key =~ /^p(lc|ch)\.roles\.denied/) { + if ($key =~ /^p(lc|ch|ac)\.roles\.denied/) { $displayname = &mt("$text (role-based)"); if ($displayval ne '') { my @roles = split(',',$displayval); @roles = map { &Apache::lonnet::plaintext($_); } @roles; $displayval = join(', ',@roles); } - } elsif ($key =~ /^p(lc|ch)\.users\.denied/) { + } elsif ($key =~ /^p(lc|ch|ac)\.users\.denied/) { $displayname = &mt("$text (specific user(s))"); } else { if ($key eq 'allow_discussion_post_editing') { @@ -3120,7 +3169,7 @@ sub store_linkprot { } } elsif ($title eq 'returnurl') { if ($values{$title}) { - $display .= &mt('Return URL parameter').': '.$values{$title}.', '; + $display .= &mt('Return URL parameter').': '.$values{$title}.', '; } } elsif ($title eq 'passbackformat') { if ($values{$title} eq '1.0') { @@ -3286,7 +3335,13 @@ sub store_ltitools { } } } - $output .= ''.$rev.' | '.$lt{$type}.' | '; @@ -4847,7 +4954,7 @@ sub display_loncaparev_constraints { &Apache::lonrelrequtils::update_reqd_loncaparev($major,$minor, $reqdmajor,$reqdminor); $checkedrev{$key} = 1; - } + } push(@{$byresponsetype{$symb}{$rev}},$key); $allmaps{$enclosing_map} = 1; } @@ -5099,7 +5206,7 @@ sub show_contents_view { sub releases_by_map { my ($r,$bymap,$url,$scopeorder,$lt) = @_; return unless ((ref($bymap) eq 'HASH') && (ref($scopeorder) eq 'ARRAY')); - my $newrow = 0; + my $newrow = 0; if (ref($bymap->{$url}) eq 'HASH') { foreach my $rev (sort(keys(%{$bymap->{$url}}))) { if ($newrow) { @@ -5216,8 +5323,7 @@ sub update_releasereq { } $modified_courses = []; } - undef($registered_cleanup); - return; + return OK; } sub show_autocoowners { @@ -5420,7 +5526,7 @@ sub print_localization { undef,$includeempty,$disabled); } else { if ($settings->{$item} eq '') { - unless ($noedit) { + unless ($noedit) { $datatable .= ' | '. &Apache::loncommon::select_language('languages_0','',1); } @@ -5457,8 +5563,8 @@ sub print_localization { &Apache::loncommon::select_language('languages_'.$num,'',1). ''. ' | '.&Apache::loncommon::end_data_table_row(); - } - $datatable .= &Apache::loncommon::end_data_table().'