[LON-CAPA-cvs] cvs: loncom /interface lonwhatsnew.pm
raeburn
lon-capa-cvs@mail.lon-capa.org
Tue, 06 Dec 2005 16:37:28 -0000
This is a MIME encoded message
--raeburn1133887048
Content-Type: text/plain
raeburn Tue Dec 6 11:37:28 2005 EDT
Modified files:
/loncom/interface lonwhatsnew.pm
Log:
Hide All, Show All and individual Hide and Show links now functional. Interval setting for version changes functional.
--raeburn1133887048
Content-Type: text/plain
Content-Disposition: attachment; filename="raeburn-20051206113728.txt"
Index: loncom/interface/lonwhatsnew.pm
diff -u loncom/interface/lonwhatsnew.pm:1.35 loncom/interface/lonwhatsnew.pm:1.36
--- loncom/interface/lonwhatsnew.pm:1.35 Mon Dec 5 14:27:53 2005
+++ loncom/interface/lonwhatsnew.pm Tue Dec 6 11:37:28 2005
@@ -1,5 +1,5 @@
#
-# $Id: lonwhatsnew.pm,v 1.35 2005/12/05 19:27:53 raeburn Exp $
+# $Id: lonwhatsnew.pm,v 1.36 2005/12/06 16:37:28 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -54,39 +54,49 @@
}
&Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['command']);
- my $command;
- if ($env{'form.action'} eq 'reset') {
- $command = 'reset';
- } elsif ($env{'form.action'} eq 'update') {
- $command = 'update';
- } else {
- $command = $env{'form.command'};
- }
+ my $command = $env{'form.command'};
&Apache::loncommon::content_type($r,'text/html');
$r->send_http_header;
- $r->print(&display_header($command));
if (! (($env{'request.course.fn'}) && (&Apache::lonnet::allowed('bre',$env{'request.course.id'})))) {
# Not in a course, or not allowed to view action items
$env{'user.error.msg'}="/adm/whatsnew:bre:0:0:Cannot display what's new screen";
return HTTP_NOT_ACCEPTABLE;
}
+ my %checkallowed = (
+ coursediscussion => &Apache::lonnet::allowed('pch',$env{'request.course.id'}),
+ handgrading => &Apache::lonnet::allowed('mgr',$env{'request.course.id'}),
+ abovethreshold => &Apache::lonnet::allowed('vgr',$env{'request.course.id'}),
+ haserrors => &Apache::lonnet::allowed('opa',$env{'request.course.id'}),
+ versionchanges => &Apache::lonnet::allowed('opa',$env{'request.course.id'}),
+ coursenormalmail => 1,
+ coursecritmail => 1,
+ );
+
+ $r->print(&display_header($command,\%checkallowed));
+
&Apache::lonhtmlcommon::clear_breadcrumbs();
+ &Apache::lonhtmlcommon::add_breadcrumb
+ ({href=>'/adm/whatsnew',
+ text=>"Display Action Items"});
if (($command eq 'chgthreshold') && (&Apache::lonnet::allowed('vgr',$env{'request.course.id'}))) {
&Apache::lonhtmlcommon::add_breadcrumb
- ({href=>'/adm/whatsnew?command=threshold',
+ ({href=>'/adm/whatsnew?command=chgthreshold',
text=>"Change thresholds"});
$r->print(&Apache::lonhtmlcommon::breadcrumbs
(undef,'Course Action Items','Course_Action_Items_Thresholds'));
- } else {
+ } elsif (($command eq 'chginterval') && (&Apache::lonnet::allowed('vgr',$env{'request.course.id'}))) {
&Apache::lonhtmlcommon::add_breadcrumb
- ({href=>'/adm/whatsnew',
- text=>"Display Action Items"});
+ ({href=>'/adm/whatsnew?command=chginterval',
+ text=>"Change interval"});
+ $r->print(&Apache::lonhtmlcommon::breadcrumbs
+ (undef,'Course Action Items','Course_Action_Items_Intervals'));
+ } else {
$r->print(&Apache::lonhtmlcommon::breadcrumbs
(undef,'Course Action Items','Course_Action_Items_Display'));
}
- &display_main_box($r,$command);
+ &display_main_box($r,$command,\%checkallowed);
return OK;
}
@@ -97,7 +107,7 @@
#------------------------------
sub display_main_box {
- my ($r,$command) = @_;
+ my ($r,$command,$checkallowed) = @_;
my $domain=&Apache::loncommon::determinedomain();
my $tabbg=&Apache::loncommon::designparm('coordinator.tabbg',$domain);
$r->print('<table width="100%" border="0" cellpadding="5" cellspacing="0"><tr><td width="100%">');
@@ -107,13 +117,27 @@
degdiff => 'Degree of difficulty',
numstudents => 'Total number of students with submissions',
);
+
+ my %interval_titles = (
+ -1 => 'since start of course',
+ 2592000 => 'since last month',
+ 604800 => 'since last week',
+ 86400 => 'since yesterday',
+ );
+
my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
my $crs = $env{'course.'.$env{'request.course.id'}.'.num'};
- if (($command eq 'chgthreshold') && (&Apache::lonnet::allowed('vgr',$env{'request.course.id'}))) {
- &display_config_box($r,$command,$tabbg,\%threshold_titles,$cdom,$crs);
+ if (($command eq 'chgthreshold') &&
+ (&Apache::lonnet::allowed('vgr',$env{'request.course.id'}))) {
+ &display_threshold_config($r,$command,$tabbg,\%threshold_titles,
+ $cdom,$crs);
+ } elsif (($command eq 'chginterval') &&
+ (&Apache::lonnet::allowed('opa',$env{'request.course.id'}))) {
+ &display_interval_config($r,\%interval_titles);
} else {
- &display_actions_box($r,$command,\%threshold_titles,$cdom,$crs);
+ &display_actions_box($r,$command,\%threshold_titles,\%interval_titles,
+ $cdom,$crs,$checkallowed);
}
$r->print(<<END_OF_BLOCK);
</td>
@@ -132,12 +156,33 @@
#-------------------------------
sub display_header{
+ my ($command,$checkallowed) = @_;
my $html=&Apache::lonxml::xmlbegin();
my $bodytag=&Apache::loncommon::bodytag('Course Action Items');
+ my $scripttag;
+ unless ($command eq 'chgthreshold' || $command eq 'chginterval') {
+ $scripttag = <<"END";
+<script type="text/javascript">
+function change_display(caller,change) {
+ caller.value = change;
+ document.visible.submit();
+}
+
+function changeAll(change) {
+END
+ foreach my $item (keys(%{$checkallowed})) {
+ $scripttag.='document.visible.display_'.$item.'.value=change'."\n";
+ }
+ $scripttag.='document.visible.submit();
+}
+</script>
+';
+ }
return(<<ENDHEAD);
$html
<head>
<title>Course Action Items</title>
+$scripttag
</head>
$bodytag
ENDHEAD
@@ -151,11 +196,25 @@
#-------------------------------
sub display_actions_box() {
- my ($r,$command,$threshold_titles,$cdom,$crs) = @_;
-
+ my ($r,$command,$threshold_titles,$interval_titles,$cdom,$crs,
+ $checkallowed) = @_;
my $rowColor1 = "#ffffff";
my $rowColor2 = "#eeeeee";
+ my $udom = $env{'user.domain'};
+ my $uname = $env{'user.name'};
+ my $cid = $env{'request.course.id'};
+
+ my %lt = &Apache::lonlocal::texthash(
+ 'yacc' => 'You are accessing an invalid course.',
+ 'gtfr' => 'Go to first resource',
+ 'chyp' => 'Change your preferences',
+ 'tsup' => 'to suppress display of this screen when accessing'.
+ ' this course in the future.',
+ 'hial' => 'Hide all',
+ 'shal' => 'Show all',
+ );
+
my %unread = ();
my %ungraded = ();
my %bombed = ();
@@ -193,31 +252,50 @@
my $pgbg=&Apache::loncommon::designparm($function.'.pgbg',$domain);
my $tabbg=&Apache::loncommon::designparm($function.'.tabbg',$domain);
- unless ($env{'request.course.id'}) {
- $r->print('<br /><b><center>You are accessing an invalid course.</center></b><br /><br />');
+ unless ($cid) {
+ $r->print('<br /><b><center>'.$lt{'yacc'}.'</center></b><br /><br />');
return;
}
- my %checkallowed = (
- coursediscussion => &Apache::lonnet::allowed('pch',$env{'request.course.id'}),
- handgrading => &Apache::lonnet::allowed('mgr',$env{'request.course.id'}),
- abovethreshold => &Apache::lonnet::allowed('vgr',$env{'request.course.id'}),
- haserrors => &Apache::lonnet::allowed('opa',$env{'request.course.id'}),
- versionchanges => &Apache::lonnet::allowed('opa',$env{'request.course.id'}),
- coursenormalmail => 1,
- coursecritmail => 1,
- );
+ if (tie(my %bighash,'GDBM_File',$env{'request.course.fn'}.'.db',
+ &GDBM_READER(),0640)) {
+ my $furl=$bighash{'first_url'};
+ $r->print('<font size="+1"><a href="'.$furl.'">'.$lt{'gtfr'}.
+ '</a></font><a href="/adm/preferences?action=changecourseinit">'.
+ '</font><br />'.$lt{'chyp'}.'</a> '.$lt{'tsup'}.'<br /><hr />');
+ untie(%bighash);
+ }
+
+ my $result;
+
+ if ($command eq 'reset') {
+ $result = &process_reset($cdom,$crs);
+ } elsif ($command eq 'update') {
+ $result = &process_update($cdom,$crs,$threshold_titles);
+ } elsif ($command eq 'newinterval') {
+ $result = &store_interval_setting($uname,$udom,$cid,$interval_titles);
+ }
+
+ my $store_result=&store_display_settings($uname,$udom,$cid,$checkallowed);
+
+ unless ($store_result eq 'ok') {
+ &Apache::lonnet::logthis('Error storing whatsnew settings: '.
+ $store_result.' for '.'user '.$uname.':'.$udom.' in course '.$cid);
+ $result .= &mt('Unable to store visibility settings due to [_1]',
+ $store_result);
+ }
+
+ if ($result) {
+ $r->print($result.'<hr width="100%" />');
+ }
+ $r->rflush();
- my $timediff = 604800;
- my %display_settings = &get_display_settings();
+
+ my %display_settings = &get_display_settings($uname,$udom,$cid);
+ my $timediff = $display_settings{$cid.':interval'};
+ unless (defined($timediff)) { $timediff = 604800; }
my $now = time;
- my %intervals = (
- -1 => 'since start of course',
- 2592000 => 'since last month',
- 604800 => 'since last week',
- 86400 => 'since yesterday',
- );
- my $interval = $intervals{$timediff};
+ my $interval = $$interval_titles{$timediff};
if ($timediff == -1) {
$timediff = time;
}
@@ -232,7 +310,7 @@
coursecritmail => 'New critical messages in course',
);
- if ($checkallowed{'abovethreshold'}) {
+ if ($$checkallowed{'abovethreshold'}) {
&get_curr_thresholds(\%threshold,$cdom,$crs);
}
@@ -240,10 +318,10 @@
my @actionorder = ('handgrading','haserrors','abovethreshold','versionchanges','coursediscussion','coursenormalmail','coursecritmail');
- foreach my $key (keys(%checkallowed)) {
+ foreach my $key (keys(%{$checkallowed})) {
$show{$key} = 0;
- if ($checkallowed{$key}) {
- unless ($display_settings{$key} eq 'off') {
+ if ($$checkallowed{$key}) {
+ unless ($display_settings{$cid.':'.$key} eq 'hide') {
$show{$key} = 1;
}
}
@@ -258,26 +336,6 @@
}
}
-
- if (tie(my %bighash,'GDBM_File',$env{'request.course.fn'}.'.db',
- &GDBM_READER(),0640)) {
- my $furl=$bighash{'first_url'};
- $r->print('<font size="+1"><a href="'.$furl.'">Go to first resource</a></font><a href="/adm/preferences?action=changecourseinit"></font><br />Change your preferences</a> to suppress display of this screen when accessing courses as Course Coordinator in the future.<br /><hr />');
- untie(%bighash);
- }
-
- my $result;
-
- if ($command eq 'reset') {
- $result = &process_reset($cdom,$crs);
- } elsif ($command eq 'update') {
- $result = &process_update($cdom,$crs,$threshold_titles);
- }
- if ($result) {
- $r->print($result.'<hr width="100%" />');
- }
- $r->rflush();
-
if ($needitems) {
&getitems(\%unread,\%ungraded,\%bombed,\%triggered,\%changed,\@newdiscussions,\@tograde,\@bombs,\@warnings,$rowColor1,$rowColor2,\%threshold,$cdom,$crs,\%res_title,\%show,$starttime);
}
@@ -288,19 +346,26 @@
&getcritmail(\@critmsgs);
}
- $r->print(qq|<a href="javascript:changeAll('hide');">Hide All</a> <a href="javascript:changeAll('show');">Show All</a>|);
+ $r->print(qq|<a href="javascript:changeAll('hide');">$lt{'hial'}</a>
+ <a href="javascript:changeAll('show');">$lt{'shal'}</a>
+ <form method="post" name="visible" action="/adm/whatsnew">\n|);
+ foreach my $item (keys(%{$checkallowed})) {
+ if ($$checkallowed{$item}) {
+ $r->print('<input type="hidden" name="display_'.$item.'" />'."\n");
+ }
+ }
- $r->print('<br /><table border="0" width="100%" cellpadding="2" cellspacing="4"><tr><td align="left" valign="top" width="45%">');
+ $r->print('</form><br /><table border="0" width="100%" cellpadding="2" cellspacing="4"><tr><td align="left" valign="top" width="45%">');
my $displayed = 0;
- my $totalboxes = keys(%checkallowed);
+ my $totalboxes = keys(%{$checkallowed});
my $halfway = int($totalboxes/2) + $totalboxes%2;
foreach my $actionitem (@actionorder) {
- if ($checkallowed{$actionitem}) {
+ if ($$checkallowed{$actionitem}) {
if ($displayed == $halfway) {
$r->print('</td><td width="5%"> </td><td align="left" valign="top" width-"50%">');
}
- &display_launcher($r,$actionitem,\%checkallowed,$tabbg,$rowColor1,$rowColor2,\%show,\%headings,\%res_title,\@tograde,\%ungraded,\@bombs,\%bombed,\%changed,\@warnings,\%triggered,\@newdiscussions,\%unread,$msgcount,\@newmsgs,$critmsgcount,\@critmsgs,$interval);
+ &display_launcher($r,$actionitem,$checkallowed,$tabbg,$rowColor1,$rowColor2,\%show,\%headings,\%res_title,\@tograde,\%ungraded,\@bombs,\%bombed,\%changed,\@warnings,\%triggered,\@newdiscussions,\%unread,$msgcount,\@newmsgs,$critmsgcount,\@critmsgs,$interval);
$displayed ++;
}
}
@@ -315,13 +380,13 @@
}
#-------------------------------
-# display_config_box
+# display_threshold_config
#
# Display the threshold setting screen
#
#-------------------------------
-sub display_config_box() {
+sub display_threshold_config {
my ($r,$command,$tabbg,$threshold_titles,$cdom,$crs) = @_;
my %threshold = ();
my $rowColor1 = "#ffffff";
@@ -336,7 +401,10 @@
);
&get_curr_thresholds(\%threshold,$cdom,$crs);
- $r->print('<br /><form name="thresholdform" method="post"><table border="0" cellpadding="2" cellspacing="4"><tr><td align="left" valign="top" width="45%">
+ $r->print('<br /><form name="thresholdform" method="post" action="/adm/whatsnew">
+ <table border="0" cellpadding="2" cellspacing="4">
+ <tr>
+ <td align="left" valign="top" width="45%">
<table border="0" cellpadding="0" cellspacing="0" bgcolor="#000000">
<tr>
<td>
@@ -375,10 +443,40 @@
}
$r->print('</table></td></tr></table></td></tr></table>
<br /><input type="submit" name="threshold" value="Make changes" />
- <input type="hidden" name="action" value="update" />
+ <input type="hidden" name="command" value="update" />
</form>');
}
+#-------------------------------
+# display_interval_config
+#
+# Display the interval setting screen
+#
+#-------------------------------
+
+sub display_interval_config {
+ my ($r,$interval_titles) = @_;
+ my $current = &get_curr_interval($env{'user.name'},
+ $env{'user.domain'},$env{'request.course.id'});
+ $r->print('<br />'.&mt('Choose the time window to use for display of version changes for resources in the course.'));
+ unless ($current eq '') {
+ $r->print(' '.&mt('Current value is ').$$interval_titles{$current}.'<br /><br />');
+ }
+ $r->print('<br /><br />
+<form method="post" name="intervalswitch" action="/adm/whatsnew">
+<input type="hidden" name="command" value="newinterval" />
+<select name="interval">
+');
+ foreach my $key (reverse sort ({$a cmp $b} (keys(%{$interval_titles})))) {
+ $r->print('<option value="'.$key.'">Version changes '.$$interval_titles{$key}.
+ '</option>'."\n");
+ }
+ $r->print('</select>
+ <input type="submit" name="display" value="'.
+ &mt('Change interval').'" /></form>');
+ return;
+}
+
sub display_launcher {
my ($r,$action,$checkallowed,$tabbg,$rowColor1,$rowColor2,$show,
$headings,$res_title,$tograde,$ungraded,$bombs,$bombed,$changed,
@@ -403,7 +501,7 @@
$rowColor1,$rowColor2);
} elsif ($action eq 'coursediscussion') { # UNREAD COURSE DISCUSSION
&display_coursediscussion($r,$newdiscussions,$unread,
- $res_title);
+ $res_title,$rowColor1,$rowColor2);
} elsif ($action eq 'coursenormalmail') { # NORMAL MESSAGES
&display_coursenormalmail($r,$msgcount,$newmsgs,$rowColor1,
$rowColor2);
@@ -653,6 +751,19 @@
}
}
+sub get_curr_interval {
+ my ($uname,$udom,$cid);
+ my $interval;
+ my %settings = &Apache::lonnet::dump('nohist_whatsnew',$uname,$udom,$cid,':interval');
+ my ($tmp) = %settings;
+ if ($tmp =~ /^Error/) {
+ &logthis();
+ } else {
+ $interval = $settings{$cid.':interval'};
+ }
+ return $interval;
+}
+
sub process_reset {
my ($dom,$crs) = @_;
my $result = '<b>Counters reset for following problems (and parts):</b><br />';
@@ -900,8 +1011,8 @@
my $warningnum = 0;
if (@{$warnings} > 0) {
@{$warnings} = sort { &cmp_title($a,$b,$res_title) } @{$warnings};
- $r->print('<form name="reset_tracking" method="post">'.
- ' <input type="hidden" name="action" value="reset" />'."\n");
+ $r->print('<form name="reset_tracking" method="post" action="/adm/whatsnew">'.
+ ' <input type="hidden" name="command" value="reset" />'."\n");
$r->print('<tr bgcolor="#cccccc"><td><b><small>'.$lt{'reso'}.'</small></b></td><td align="right"><b><small>'.$lt{'part'}.'</small></b></td><td align="right"><b><small>'.$lt{'nust'}.'</small></b></td><td align="right"><b><small>'.$lt{'avat'}.'</small></b></td><td align="right"><b><small>'.$lt{'dedi'}.'</small></b></td><td align="right"><b><small>'.$lt{'lare'}.'</small></b></td><td align="right"><b><small>'.$lt{'reco'}.'</small></b></td></tr>');
foreach my $res (@{$warnings}) {
if ($warningnum %2 == 1) {
@@ -1055,9 +1166,7 @@
}
sub get_display_settings {
- my $udom = $env{'user.domain'};
- my $uname = $env{'user.name'};
- my $cid = $env{'request.course.id'};
+ my ($uname,$udom,$cid) = @_;
my %settings = &Apache::lonnet::dump('nohist_whatsnew',$udom,$uname,$cid);
my ($tmp) = keys(%settings);
if ($tmp=~/^error:/) {
@@ -1070,6 +1179,49 @@
return %settings;
}
+sub store_display_settings {
+ my ($uname,$udom,$cid,$checkallowed) = @_;
+ my %whatsnew_settings;
+ my $result;
+ foreach my $key (keys(%{$checkallowed})) {
+ if (exists($env{'form.display_'.$key})) {
+ unless ($env{'form.display_'.$key} eq '') {
+ $whatsnew_settings{$cid.':'.$key} = $env{'form.display_'.$key};
+ }
+ }
+ }
+ if (keys(%whatsnew_settings)) {
+ $result = &Apache::lonnet::put('nohist_whatsnew',\%whatsnew_settings,
+ $udom,$uname);
+ } else {
+ $result = 'ok';
+ }
+ return $result;
+}
+
+sub store_interval_setting {
+ my ($uname,$udom,$cid,$interval_titles) = @_;
+ my %interval_settings = ();
+ my $result;
+ if (defined($env{'form.interval'})) {
+ $interval_settings{$cid.':interval'} = $env{'form.interval'};
+ my $outcome = &Apache::lonnet::put('nohist_whatsnew',
+ \%interval_settings,$udom,$uname);
+ if ($outcome eq 'ok') {
+ $result = &mt('Interval set to version changes [_1]',
+ '<b>'.$$interval_titles{$env{'form.interval'}}.'</b><br />');
+
+ } else {
+ &Apache::lonnet::logthis('Error storing whatsnew interval setting'.
+ ' '.$outcome.' for '.$uname.':'.$udom.' in course '.$cid);
+ $result = &mt('Unable to set interval to [_1] due to [_2].',
+ '<b>'.$$interval_titles{$env{'form.interval'}}.'</b>',
+ '<tt>'.$outcome.'</tt>.<br />');
+ }
+ }
+ return $result;
+}
+
sub start_box {
my ($r,$tabbg,$show,$heading,$caller) = @_;
my %lt = &Apache::lonlocal::texthash(
@@ -1078,12 +1230,12 @@
);
my $showhide;
if ($$show{$caller}) {
- $showhide = '<b><a href="javascript:change_display('."'".$caller.
- "','hide'".');">Hide</a></b>';
+ $showhide = '<b><a href="javascript:change_display(document.visible.'.
+ 'display_'.$caller.",'hide'".');">Hide</a></b>';
} else {
- $showhide = '<b><a href="javascript:change_display('."'".$caller.
- "','show'".');">Show</a></b>';
+ $showhide = '<b><a href="javascript:change_display(document.visible.'.
+ 'display_'.$caller.",'show'".');">Show</a></b>';
}
$r->print('
--raeburn1133887048--