--- loncom/interface/lonwhatsnew.pm 2024/09/11 05:20:52 1.130 +++ loncom/interface/lonwhatsnew.pm 2025/03/22 20:34:49 1.131 @@ -1,7 +1,7 @@ # The LearningOnline Network # What's New in a course # -# $Id: lonwhatsnew.pm,v 1.130 2024/09/11 05:20:52 raeburn Exp $ +# $Id: lonwhatsnew.pm,v 1.131 2025/03/22 20:34:49 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -118,7 +118,23 @@ sub handler { &Apache::loncommon::content_type($r,'text/html'); $r->send_http_header; - $r->print(&display_header($command,\%checkallowed)); + my $udom = $env{'user.domain'}; + my $uname = $env{'user.name'}; + my $cid = $env{'request.course.id'}; + my $store_result = &store_display_settings($uname,$udom,$cid,\%checkallowed); + my $store_error; + + unless ($store_result eq 'ok') { + my $lctype = lc(&Apache::loncommon::course_type()); + &Apache::lonnet::logthis('Error saving whatsnew settings: '. + $store_result.' for '.'user '.$uname.':'.$udom.' in '.$lctype.' '.$cid); + $store_error = '' + .&mt('Unable to save visibility settings due to [_1]', + $store_result) + .''; + } + + $r->print(&display_header($command,$uname,$udom,$cid,\%checkallowed)); &Apache::lonhtmlcommon::clear_breadcrumbs(); &Apache::lonhtmlcommon::add_breadcrumb @@ -185,7 +201,7 @@ sub handler { ("What's New?",#'Course_Action_Items_Display' )); } - &display_main_box($r,$command,$refpage,\%checkallowed,$cdom,$crs); + &display_main_box($r,$command,$refpage,\%checkallowed,$cdom,$crs,$store_error); return OK; } @@ -196,7 +212,7 @@ sub handler { #------------------------------ sub display_main_box { - my ($r,$command,$refpage,$checkallowed,$cdom,$crs) = @_; + my ($r,$command,$refpage,$checkallowed,$cdom,$crs,$store_error) = @_; my $domain=&Apache::loncommon::determinedomain(); my $function = &Apache::loncommon::get_users_function(); my $lctype = lc(&Apache::loncommon::course_type()); @@ -245,7 +261,7 @@ sub display_main_box { crslogin => \%crslogins, sessions => \%sessions, ); - my %initpage = &Apache::lonlocal::texthash ( + my %initpage = ( firstres => "first resource in the $lctype", whatsnew => "What's New Page", userpref => 'your general user preferences', @@ -277,7 +293,8 @@ sub display_main_box { &display_interval_config($r,$refpage,\%interval_titles,'sessions'); } else { &display_actions_box($r,$command,$refpage,\%threshold_titles, - \%interval_titles,\%initpage,$cdom,$crs,$checkallowed); + \%interval_titles,\%initpage,$cdom,$crs, + $checkallowed,$store_error); } my $end_page = &Apache::loncommon::end_page(); $r->print(< +// + +END + $loadentries{'onload'} = 'toggleCourseInit(document.courseinitswitch);'; + } else { + unless (($command eq 'chgthreshold' && $checkallowed->{'abovethreshold'}) || + ($command eq 'chginterval' && $checkallowed->{'versionchanges'}) || + ($command eq 'chgdisc' && $checkallowed->{'coursediscussion'}) || + ($command eq 'chgoldroleinterval' && $checkallowed->{'oldroles'}) || + ($command eq 'chgnewroleinterval' && $checkallowed->{'newroles'}) || + ($command eq 'chgcrslogininterval' && $checkallowed->{'crslogin'}) || + ($command eq 'chgsessionlimit' && $checkallowed->{'sessions'})) { + my %display_settings = &get_display_settings($uname,$udom,$cid); + $scripttag = <<"END"; ENDTOGG + if (($checkallowed->{'crslogin'}) && ($display_settings{$cid.':crslogin'} ne 'hide')) { + $loadentries{'onload'} = "toggledetails('login');"; + } + if (($checkallowed->{'sessions'}) && ($display_settings{$cid.':sessions'} ne 'hide')) { + $loadentries{'onload'} .= "toggledetails('session');"; + } + } } my $course_type=&Apache::loncommon::course_type(); + if (keys(%loadentries)) { + $args->{'add_entries'} = \%loadentries; + } return &Apache::loncommon::start_page("What's New?", - $scripttag); + $scripttag,$args); } #------------------------------- @@ -390,7 +452,7 @@ ENDTOGG sub display_actions_box { my ($r,$command,$refpage,$threshold_titles,$interval_titles,$initpage, - $cdom,$crs,$checkallowed) = @_; + $cdom,$crs,$checkallowed,$store_error) = @_; my $udom = $env{'user.domain'}; my $uname = $env{'user.name'}; my $cid = $env{'request.course.id'}; @@ -467,7 +529,7 @@ sub display_actions_box { } $header .= &mt('Page set to be displayed after you have selected a role in this '.$lctype).'.' .' ' - .&mt('Currently: [_1].',''.$currinit.'') + .&mt('Currently: [_1].',''.$currinit.'') .'  ' .&mt('[_1]Change[_2] for just [_3]this '.$lctype.'[_4] or for [_5]all your courses/communities[_6].' ,'' @@ -490,15 +552,8 @@ sub display_actions_box { $result = &store_discussion_setting($uname,$udom,$cid); } - my $store_result=&store_display_settings($uname,$udom,$cid,$checkallowed); - - unless ($store_result eq 'ok') { - &Apache::lonnet::logthis('Error saving whatsnew settings: '. - $store_result.' for '.'user '.$uname.':'.$udom.' in '.$lctype.' '.$cid); - $result .= '' - .&mt('Unable to save visibility settings due to [_1]', - $store_result) - .''; + if ($store_error) { + $result = $store_error; } if ($result) { @@ -690,9 +745,13 @@ sub display_actions_box { if ($show{'sessions'}) { $sessioncount = &getsessions($cdom,$crs,\%sessions,$timediff{'sessions'},$classlist); } - $r->print(qq|$lt{'hial'} -   $lt{'shal'} -
\n|); + my $showhideall = <<"END"; +$lt{'hial'} +  $lt{'shal'} +END + $r->print(&Apache::loncommon::head_subbox($showhideall)); + $r->print(qq|\n|); + foreach my $item (keys(%{$checkallowed})) { if ($item =~ /_section$/) { next; } if ($$checkallowed{$item}) { @@ -922,46 +981,49 @@ sub courseinit_config { my ($control,$current) = &curr_courseinit(); my @chgstate = ('userpref','coursespecific'); my @chgentry = ('firstres','whatsnew'); + my $courseinitsty = 'display:none;'; + if ($control eq 'coursespecific') { + $courseinitsty = 'display:inline;'; + } my $lctype = lc(&Apache::loncommon::course_type()); my %lt = &Apache::lonlocal::texthash( 'chwp' => "Choose which page will be displayed when you enter this $lctype after selecting a role.", - 'cuva' => 'Current value is determined by', - 'anis' => 'and is set to display', 'padc' => 'Page display controlled by', - 'chce' => 'Choose '.$lctype.' entry', + 'chce' => "Choose $lctype entry", 'moce' => 'Save', ); - $r->print(<<"END"); + $lt{'cuva'} = &mt('Current value is determined by[_1]'.$initpage->{$control}.'[_2] and is set to display[_1]'.$initpage->{$current}.'[_2].', + ': ',''); + $r->print(<<"END");
$lt{'chwp'} -
$lt{'cuva'}: -$$initpage{$control} $lt{'anis'} -$$initpage{$current}.

+
$lt{'cuva'} +

-$lt{'padc'}:   +
$lt{'padc'} END foreach my $choice (@chgstate) { my $chkstring; if ($choice eq $control) { $chkstring = ' checked="checked" '; - } + } $r->print(''); } - $r->print('

'.&mt('If').' '.$$initpage{'coursespecific'}. - ' -
'.$lt{'chce'}.": \n"); + $r->print('
'. + ''.$lt{'chce'}.''."\n"); foreach my $choice (@chgentry) { my $chkstring; if (($choice eq $current) && ($control eq 'coursespecific')) { $chkstring = ' checked="checked" '; } $r->print(''); + $choice.'"'.$chkstring.'/>'.&mt($initpage->{$choice}). + '   '); } - $r->print('

'); return; } @@ -1924,10 +1986,10 @@ sub display_abovethreshold { $r->print(''. ''. $$triggered{$res}{title}.''); - if (ref($$triggered{$res}{text}) eq 'ARRAY') { - $r->print($$triggered{$res}{text}[0]); - } - $r->print(''); + if (ref($$triggered{$res}{text}) eq 'ARRAY') { + $r->print($$triggered{$res}{text}[0]); + } + $r->print(''); if (ref($$triggered{$res}{text}) eq 'ARRAY') { if (@{$$triggered{$res}{text}} > 1) { for (my $i=1; $i<@{$$triggered{$res}{text}}; $i++) { @@ -2389,7 +2451,7 @@ sub store_courseinit_setting { $result = &Apache::lonhtmlcommon::confirm_success(&mt("Page displayed after role selection in $lctype now set by [_1]user's global preferences[_2].",'','')); } else { $result = &Apache::lonhtmlcommon::confirm_success(&mt('Page displayed after role selection in this '.$lctype.' set to [_1].' - ,''.$$initpage{$env{'form.courseinit_page'}}.'')); + ,''.&mt($initpage->{$env{'form.courseinit_page'}}).'')); } } else { &Apache::lonnet::logthis('Error saving whatsnew courseinit '. @@ -2402,7 +2464,7 @@ sub store_courseinit_setting { ''.$outcome.''),1); } else { $result = &Apache::lonhtmlcommon::confirm_success(&mt('Unable to set page display, after role selection, for this '.$lctype.' to [_1] due to [_2].' - ,''.$$initpage{$env{'form.courseinit_page'}}.'' + ,''.&mt($initpage->{$env{'form.courseinit_page'}}).'' ,''.$outcome.''),1); } }