--- loncom/interface/lonpreferences.pm 2004/03/26 20:29:35 1.41 +++ loncom/interface/lonpreferences.pm 2004/05/25 22:00:21 1.43 @@ -1,7 +1,7 @@ # The LearningOnline Network # Preferences # -# $Id: lonpreferences.pm,v 1.41 2004/03/26 20:29:35 www Exp $ +# $Id: lonpreferences.pm,v 1.43 2004/05/25 22:00:21 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -626,6 +626,149 @@ ENDERROR return; } +################################################################ +# discussion display subroutines +################################################################ +sub discussionchanger { + my $r = shift; + my $user = $ENV{'user.name'}; + my $domain = $ENV{'user.domain'}; + my %userenv = &Apache::lonnet::get + ('environment',['discdisplay','discmarkread']); + my $discdisp = 'allposts'; + my $discmark = 'onmark'; + + if (defined($userenv{'discdisplay'})) { + unless ($userenv{'discdisplay'} eq '') { + $discdisp = $userenv{'discdisplay'}; + } + } + if (defined($userenv{'discmarkread'})) { + unless ($userenv{'discdisplay'} eq '') { + $discmark = $userenv{'discmarkread'}; + } + } + + my $newdisp = 'unread'; + my $newmark = 'ondisp'; + + my $function = &Apache::loncommon::get_users_function(); + my $color = &Apache::loncommon::designparm($function.'.tabbg', + $ENV{'user.domain'}); + my %lt = &Apache::lonlocal::texthash( + 'pref' => 'Display Preference', + 'curr' => 'Current setting ', + 'actn' => 'Action', + 'sdpf' => 'Set display preferences for discussion posts for both bulletin boards and individual resources in all your courses.', + 'prca' => 'Preferences can be set that determine', + 'whpo' => 'Which posts are displayed when you display a bulletin board or resource, and', + 'unwh' => 'Under what circumstances posts are identfied as "New"', + 'allposts' => 'All posts', + 'unread' => 'New posts only', + 'ondisp' => 'Once displayed', + 'onmark' => 'Once marked as read', + 'disa' => 'Posts displayed?', + 'npmr' => 'New posts cease to be identified as "New"?', + 'thde' => 'The preferences you set here can be overridden within each individual discussion.', + 'chgt' => 'Change to ' + ); + my $dispchange = $lt{'unread'}; + my $markchange = $lt{'ondisp'}; + my $currdisp = $lt{'allposts'}; + my $currmark = $lt{'onmark'}; + + if ($discdisp eq 'unread') { + $dispchange = $lt{'allposts'}; + $currdisp = $lt{'unread'}; + $newdisp = 'allposts'; + } + + if ($discmark eq 'ondisp') { + $markchange = $lt{'onmark'}; + $currmark = $lt{'ondisp'}; + $newmark = 'onmark'; + } + + $r->print(<<"END"); +<form name="server" action="/adm/preferences" method="post"> +<input type="hidden" name="action" value="verify_and_change_discussion" /> +<br /> +$lt{'sdpf'}<br/> $lt{'prca'} <ol><li>$lt{'whpo'}</li><li>$lt{'unwh'}</li></ol> +<br /> +<br /> +<table border="0" cellpadding="0" cellspacing="0"> + <tr> + <td width="100%" bgcolor="#000000"> + <table width="100%" border="0" cellpadding="1" cellspacing="0"> + <tr> + <td width="100%" bgcolor="#000000"> + <table border="0" cellpadding="3" cellspacing="3" bgcolor="#FFFFFF"> + <tr bgcolor="$color"> + <td><b>$lt{'pref'}</b></td> + <td><b>$lt{'curr'}</b></td> + <td><b>$lt{'actn'}?</b></td> + </tr> + <tr bgcolor="#dddddd"> + <td>$lt{'disa'}</td> + <td>$lt{$discdisp}</td> + <td><input type="checkbox" name="discdisp" /><input type="hidden" name="newdisp" value="$newdisp" /> $lt{'chgt'} "$dispchange"</td> + </tr><tr bgcolor="#eeeeee"> + <td>$lt{'npmr'}</td> + <td>$lt{$discmark}</td> + <td><input type="checkbox" name="discmark" /><input type="hidden" name="newmark" value="$newmark" /> $lt{'chgt'} "$markchange"</td> + </tr> + </table> + </td> + </tr> + </table> + </td> +</tr> +</table> +<br /> +<br /> +<input type="submit" name="sub" value="Store Changes" /> +<br /> +<br /> +Note: $lt{'thde'} +</form> +END +} + +sub verify_and_change_discussion { + my $r = shift; + my $user = $ENV{'user.name'}; + my $domain = $ENV{'user.domain'}; + my $message=''; + if (defined($ENV{'form.discdisp'}) ) { + my $newdisp = $ENV{'form.newdisp'}; + if ($newdisp eq 'unread') { + $message .='In discussions: only new posts will be displayed.<br/>'; + &Apache::lonnet::put('environment',{'discdisplay' => $newdisp}); + &Apache::lonnet::appenv('environment.discdisplay' => $newdisp); + } else { + $message .= 'In discussions: all posts will be displayed.<br/>'; + &Apache::lonnet::del('environment',['discdisplay']); + &Apache::lonnet::delenv('environment\.discdisplay'); + } + } + if (defined($ENV{'form.discmark'}) ) { + my $newmark = $ENV{'form.newmark'}; + if ($newmark eq 'ondisp') { + $message.='In discussions: new posts will be cease to be identified as "new" after display.<br/>'; + &Apache::lonnet::put('environment',{'discmarkread' => $newmark}); + &Apache::lonnet::appenv('environment.discmarkread' => $newmark); + } else { + $message.='In discussions: posts will be identified as "new" until marked as read by the reader.<br/>'; + &Apache::lonnet::del('environment',['discmarkread']); + &Apache::lonnet::delenv('environment\.discmarkread'); + } + } + $r->print(<<ENDVCSCREEN); +</p> +$message +ENDVCSCREEN +} + ###################################################### # other handler subroutines # ###################################################### @@ -742,6 +885,22 @@ sub handler { printmenu => 'yes', subroutine=>\&verify_and_change_languages, } )); + push (@Options,({ action => 'changediscussions', + linktext => 'Change Discussion Display Preferences', + href => '/adm/preferences', + breadcrumb => + { href => '/adm/preferences?action=changediscussions', + text => 'Change Discussion Preferences'}, + subroutine => \&discussionchanger, + }, + { action => 'verify_and_change_discussion', + breadcrumb => + { href => '/adm/preferences?action=changediscussions', + text => 'Change Discussion Preferences'}, + printmenu => 'yes', + subroutine => \&verify_and_change_discussion, } + )); + if ($ENV{'user.name'} =~ /^(albertel|koretemey|korte|hallmat3|turtle)$/) { push (@Options,({ action => 'debugtoggle', printmenu => 'yes',