--- loncom/interface/lonwhatsnew.pm	2008/12/20 01:39:47	1.84
+++ loncom/interface/lonwhatsnew.pm	2010/09/19 15:05:59	1.98.2.4
@@ -1,5 +1,5 @@
 #
-# $Id: lonwhatsnew.pm,v 1.84 2008/12/20 01:39:47 raeburn Exp $
+# $Id: lonwhatsnew.pm,v 1.98.2.4 2010/09/19 15:05:59 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -42,6 +42,7 @@ use Time::Local;
 use GDBM_File;
 use lib '/home/httpd/lib/perl/';
 use LONCAPA;
+use HTML::Entities;
 
 #----------------------------
 # handler
@@ -71,6 +72,7 @@ sub handler {
 			    ['mdc','versionchanges',0],
                             ['vcl','newroles',1],
                             ['vcl','oldroles',1],
+                            ['whn','crslogin',1],
 			    ) {
 	my ($perm,$key,$check_section) = @{ $perm_check };
 	my $scope = $env{'request.course.id'};
@@ -99,7 +101,7 @@ sub handler {
     &Apache::lonhtmlcommon::clear_breadcrumbs();
     &Apache::lonhtmlcommon::add_breadcrumb
             ({href=>'/adm/whatsnew',
-              text=>"Display Action Items"});
+              text=>"What's New?"});
     if (($command eq 'chgthreshold') && $checkallowed{'abovethreshold'}) {
         &Apache::lonhtmlcommon::add_breadcrumb
             ({href=>'/adm/whatsnew?command=chgthreshold&refpage='.$refpage,
@@ -142,6 +144,13 @@ sub handler {
         $r->print(&Apache::lonhtmlcommon::breadcrumbs
             ("What's New?",#'Course_Action_Items_Intervals'
              ));
+    } elsif ($command eq 'chgcrslogininterval' && $checkallowed{'crslogin'}) {
+        &Apache::lonhtmlcommon::add_breadcrumb
+            ({href=>'/adm/whatsnew?command=chgcrslogininterval&refpage='.$refpage,
+              text=>"Change interval"});
+        $r->print(&Apache::lonhtmlcommon::breadcrumbs
+            ("What's New?",#'Course_Action_Items_Intervals'
+             ));
     } else {
         $r->print(&Apache::lonhtmlcommon::breadcrumbs
             ("What's New?",#'Course_Action_Items_Display'
@@ -187,14 +196,21 @@ sub display_main_box {
                    604800 => 'roles which expired since last week',
                     86400 => 'roles which expired since yesterday',
                    );
+    my %crslogins = (
+                       -1 => 'last logins for anyone who has ever logged in',
+                  2592000 => 'last logins for users in last 30 days',
+                   604800 => 'last logins for users in last 7 days',
+                    86400 => 'last logins for users in last 24 hours',
+                   );
     my %interval_titles = (
         versions => \%versions,
         newroles => \%newroles,
         oldroles => \%oldroles,
+        crslogin => \%crslogins,
     );
     my %initpage = &Apache::lonlocal::texthash (
                      firstres => "first resource in the $lctype",
-                     whatsnew => "what's new? page",
+                     whatsnew => "What's New Page",
                      userpref => 'your general user preferences',
                      coursespecific => "specific setting for this $lctype",
                    );
@@ -219,6 +235,9 @@ sub display_main_box {
     } elsif (($command eq 'chgoldroleinterval')
              && $checkallowed->{'oldroles'}) {
         &display_interval_config($r,$refpage,\%interval_titles,'oldroles');
+    } elsif (($command eq 'chgcrslogininterval')
+             && $checkallowed->{'crslogin'}) {
+        &display_interval_config($r,$refpage,\%interval_titles,'crslogin'); 
     } else {
         &display_actions_box($r,$command,$refpage,\%threshold_titles,
                         \%interval_titles,\%initpage,$cdom,$crs,$checkallowed);
@@ -244,9 +263,11 @@ sub display_header {
     
     my $scripttag;
     unless ($command eq 'chgthreshold' || $command eq 'chginterval' || 
-            $command eq 'chgoldroleinterval' || $command eq 'chgnewroleinterval') {
+            $command eq 'chgoldroleinterval' || 
+            $command eq 'chgnewroleinterval' || $command eq 'chgcrslogininterval') {
        $scripttag = <<"END";
 <script type="text/javascript">
+// <![CDATA[
 function change_display(caller,change) {
     caller.value = change;
     document.visible.submit();
@@ -263,11 +284,57 @@ END
         }
         $scripttag.='document.visible.submit();
 }
+
+function togglelogins() {
+    var total = document.visible.logincount.value;
+    var sumrow = document.visible.loginrow.value;
+    if (total == 0) {
+        return;
+    }
+    var showlogindetails = 0;
+    for (var i=0; i<document.visible.logindetails.length; i++) {
+        if (document.visible.logindetails[i].checked) {
+            showlogindetails = document.visible.logindetails[i].value;
+        }
+    }
+    var detval = "none";
+    var sumval = "";
+    if (showlogindetails == 1) {
+        detval = "";
+        sumval = "none";   
+    }
+    for (var j=0; j<total; j++) {
+        var counter = j+1;
+        var itemid = "logindet_"+counter; 
+        personele = document.getElementById(itemid);
+        if (personele != null) {
+            personele.style.display = detval;
+        }
+    }
+    var detheaderele = document.getElementById("logintitledet");
+    if (detheaderele != null) {
+        detheaderele.style.display = detval;
+    }
+    for (var k=0; k<sumrow; k++) {
+        var counter = k+1;
+        var itemid = "loginsum_"+counter;
+        logincatele = document.getElementById(itemid);
+        if (logincatele != null) {
+            logincatele.style.display = sumval;
+        }
+    }
+    var sumheaderele = document.getElementById("logintitlesum");
+    if (sumheaderele != null) {
+        sumheaderele.style.display = sumval;
+    }
+    return;
+}
+// ]]>
 </script>
 ';
     }
     my $course_type=&Apache::loncommon::course_type();
-    return &Apache::loncommon::start_page($course_type.' Action Items',
+    return &Apache::loncommon::start_page("What's New?",
 					  $scripttag);
 }
 
@@ -281,6 +348,7 @@ END
 sub display_actions_box {
     my ($r,$command,$refpage,$threshold_titles,$interval_titles,$initpage,
         $cdom,$crs,$checkallowed) = @_;
+    my $custommenu = &Apache::loncommon::needs_gci_custom();
     my $udom = $env{'user.domain'};
     my $uname = $env{'user.name'};
     my $cid = $env{'request.course.id'};
@@ -288,7 +356,7 @@ sub display_actions_box {
     my $lctype = lc($crstype);
     my %stulabel = (
                     'Course' => 'students',
-                    'Group' => 'members',
+                    'Community' => 'members',
                    );
     my %lt = &Apache::lonlocal::texthash(
                  'yacc' => 'You are accessing an invalid course',
@@ -314,6 +382,8 @@ sub display_actions_box {
     my %expired;
     my $activecount;
     my %activated;
+    my %loggedin;
+    my $logincount;
     my %res_title = ();
     my %show = ();
     my $needitems = 0;
@@ -327,7 +397,7 @@ sub display_actions_box {
     my %threshold = ();
     my %pagedesc = &Apache::lonlocal::texthash (
                      firstres => 'First resource',
-                     whatsnew => "What's New? page",
+                     whatsnew => "What's New Page",
                      userpref => 'user preference',
                      coursespecific => $lctype.' only',
                      default => 'default',
@@ -341,27 +411,32 @@ sub display_actions_box {
         return;
     }
 
-    if ($refpage eq 'start') {
+    my $header = '';
+    if (($refpage eq 'start') && (!$custommenu)) {
         if (tie(my %bighash,'GDBM_File',$env{'request.course.fn'}.'.db',
             &GDBM_READER(),0640)) {
-            my $furl=$bighash{'first_url'};
+            my $furl=&HTML::Entities::encode($bighash{'first_url'},'"<>&');
             untie(%bighash);
-            $r->print('<span style="font-size: larger;"><a href="'.$furl.'">'.$lt{'gtfr'}.
-                  '</a></span><br />');
+            $header .= '<b><a href="'.$furl.'">'.$lt{'gtfr'}.
+                  '</a></b><br />';
         }
     }
-    $r->print(&mt('Page set to be displayed after you have selected a role in this '.$lctype).'.'
+    unless ($custommenu) {
+        $header .= &mt('Page set to be displayed after you have selected a role in this '.$lctype).'.'
               .' <span class="LC_nobreak">'
               .&mt('Currently: [_1].','<i>'.$currinit.'</i>')
               .'&nbsp;&nbsp;'
-              .&mt('[_1]Change[_2] for just [_3]this course[_4] or for all [_5]your courses[_6].'
+              .&mt('[_1]Change[_2] for just [_3]this '.$lctype.'[_4] or for [_5]all your courses/communities[_6].'
                   ,'<b>'
                   ,'</b>'
                   ,'<a href="/adm/whatsnew?command=courseinit&amp;refpage='.$refpage.'">'
                   ,'</a>'
                   ,'<a href="/adm/preferences?action=changecourseinit&amp;refpage='.$refpage.'">'
                   ,'</a>')
-              .' </span><br /><hr />');
+              .' </span>';
+
+        $r->print(&Apache::loncommon::head_subbox($header));
+    }
 
     if ($command eq 'reset') {
         $result = &process_reset($cdom,$crs);
@@ -378,12 +453,14 @@ sub display_actions_box {
     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); 
+        $result .= '<span class="LC_error">'
+                  .&mt('Unable to save visibility settings due to [_1]',
+                       $store_result)
+                  .'</span>';
     }
 
     if ($result) {
-        $r->print($result.'<hr width="100%" />');
+        $r->print($result.'<hr />');
     }
     $r->rflush();
 
@@ -439,6 +516,20 @@ sub display_actions_box {
         $headings{'newroles'} = &mt('Roles for which access to '.$lctype.' has become available since yesterday');
     }
 
+    $timediff{'crslogin'} = $display_settings{$cid.':crslogininterval'};
+    unless (defined($timediff{'crslogin'})) { $timediff{'crslogin'} = 604800; }
+    $interval{'crslogin'} = $interval_titles->{'crslogin'}->{$timediff{'crslogin'}};
+
+    if ($timediff{'crslogin'} == -1) {
+        $headings{'crslogin'} = &mt('Last login for anyone who has ever logged in');
+    } elsif ($timediff{'crslogin'} == 2592000) {
+        $headings{'crslogin'} = &mt('Last login for users in last 30 days');
+    } elsif ($timediff{'crslogin'} == 604800) {
+        $headings{'crslogin'} = &mt('Last login for users in last 7 days');
+    } elsif ($timediff{'crslogin'} == 86400) {
+        $headings{'crslogin'} = &mt('Last login for users in last 24 hours');
+    }
+
     my $now = time;
     if ($timediff{'versions'} == -1) {
         $timediff{'versions'} = time;
@@ -453,22 +544,38 @@ sub display_actions_box {
     if ($timediff{'oldroles'} == -1) {
         $timediff{'oldroles'} = time;
     }
+
     my $expiredstart = $now - $timediff{'oldroles'};
 
+    if ($timediff{'crslogin'} == -1) {
+        $timediff{'crslogin'} = time;
+    }
+
+    my $crsloginstart = $now - $timediff{'crslogin'};
+
     my $countunread = $display_settings{$cid.':countunread'};
     unless (defined($countunread)) {
         $countunread = 'on';
     }
     if ($$checkallowed{'abovethreshold'}) {
-        &get_curr_thresholds(\%threshold,$uname,$udom,$cid,$cdom,$crs);
+        &get_curr_thresholds(\%threshold,$uname,$udom,$cid,$cdom,$crs,$custommenu);
     }
 
-    $headings{'abovethreshold'} = 
-	&mt('(Problems with av. attempts &ge; [_1] or deg. difficulty &ge; [_2]) [_3] and total number of '.$stulabel{$crstype}.' with submissions &ge; [_4]',
-	    $threshold{'av_attempts'},$threshold{'degdiff'},
-	    '<br />',$threshold{'numstudents'});
+    if ($custommenu) {
+        $headings{'abovethreshold'} = &mt('Questions with submissions');  
+    } else {
+        $headings{'abovethreshold'} = 
+	    &mt('(Problems with av. attempts &ge; [_1] or deg. difficulty &ge; [_2]) [_3] and total number of '.$stulabel{$crstype}.' with submissions &ge; [_4]',
+	        $threshold{'av_attempts'},$threshold{'degdiff'},
+	        '<br />',$threshold{'numstudents'});
+    }
 
-    my @actionorder = ('handgrading','haserrors','abovethreshold','versionchanges','coursediscussion','coursenormalmail','coursecritmail','newroles','oldroles');
+    my @actionorder;
+    if ($custommenu) {
+        @actionorder = ('coursenormalmail','coursecritmail','abovethreshold','newroles','oldroles','crslogin');
+    } else {
+        @actionorder = ('handgrading','haserrors','abovethreshold','versionchanges','coursediscussion','coursenormalmail','coursecritmail','newroles','oldroles');
+    }
 
     foreach my $key (keys(%{$checkallowed})) {
 	if ($key =~ /_section$/) { next; }
@@ -492,7 +599,7 @@ sub display_actions_box {
 
     my $itemserror;
     if ($needitems) {
-        $itemserror = &getitems(\%unread,\%ungraded,\%bombed,\%triggered,\%changed,\@newdiscussions,\@tograde,\@bombs,\@warnings,\%threshold,$cdom,$crs,\%res_title,\%show,$starttime,$countunread);
+        $itemserror = &getitems(\%unread,\%ungraded,\%bombed,\%triggered,\%changed,\@newdiscussions,\@tograde,\@bombs,\@warnings,\%threshold,$cdom,$crs,\%res_title,\%show,$starttime,$countunread,$custommenu);
     }
     if ($show{'coursenormalmail'}) {
         $msgcount = &getnormalmail(\@newmsgs);
@@ -506,6 +613,10 @@ sub display_actions_box {
     if ($show{'newroles'}) {
         $activecount = &getactivated(\%activated,$activatedstart,'active');
     }
+    if ($show{'crslogin'}) {
+        $logincount = &getloggedin($cdom,$crs,\%loggedin,$crsloginstart);
+    }
+
     $r->print(qq|<a href="javascript:changeAll('hide');">$lt{'hial'}</a>
      &nbsp;&nbsp;<a href="javascript:changeAll('show');">$lt{'shal'}</a>
      <form method="post" name="visible" action="/adm/whatsnew">\n|);
@@ -516,7 +627,11 @@ sub display_actions_box {
         }
     }
 
-    $r->print('<input type="hidden" name="refpage" value="'.$refpage.'" /></form><table class="LC_double_column"><tr><td class="LC_left_col">');
+    $r->print('<input type="hidden" name="refpage" value="'.$refpage.'" />');
+    unless($custommenu) {
+        $r->print('</form>');
+    }
+    $r->print('<table class="LC_double_column"><tr><td class="LC_left_col">');
 
     my $displayed = 0;
     my $totalboxes = 0;
@@ -529,12 +644,15 @@ sub display_actions_box {
     }
     my $halfway = 4;
 #    my $halfway = int($totalboxes/2) + $totalboxes%2;
+    if ($custommenu) {
+        $halfway = 3;
+    }
     foreach my $actionitem (@actionorder) {
         if ($$checkallowed{$actionitem}) {
             if ($displayed == $halfway) {
                 $r->print('</td><td>&nbsp;</td><td class="LC_right_col" >');
             }
-            &display_launcher($r,$actionitem,$refpage,$checkallowed,\%show,\%headings,\%res_title,\@tograde,\%ungraded,\@bombs,\%bombed,\%changed,\@warnings,\%triggered,\@newdiscussions,\%unread,$msgcount,\@newmsgs,$critmsgcount,\@critmsgs,\%interval,$countunread,\%expired,$expirecount,\%activated,$activecount,$crstype,$itemserror);
+            &display_launcher($r,$actionitem,$refpage,$checkallowed,\%show,\%headings,\%res_title,\@tograde,\%ungraded,\@bombs,\%bombed,\%changed,\@warnings,\%triggered,\@newdiscussions,\%unread,$msgcount,\@newmsgs,$critmsgcount,\@critmsgs,\%interval,$countunread,\%expired,$expirecount,\%activated,$activecount,$crstype,$itemserror,\%loggedin,$logincount,$custommenu);
             $displayed ++; 
         }
     }
@@ -543,6 +661,9 @@ sub display_actions_box {
     </tr>
    </table>
 ');
+    if ($custommenu) {
+        $r->print("</form>\n");
+    }
 }
 
 #-------------------------------
@@ -594,7 +715,7 @@ sub display_threshold_config {
                  &Apache::loncommon::end_data_table_row());
     }
     $r->print(&Apache::loncommon::end_data_table()."\n".
-          '<br /><input type="submit" name="threshold" value="'.&mt('Make changes').'" />
+          '<br /><input type="submit" name="threshold" value="'.&mt('Save').'" />
                  <input type="hidden" name="command" value="update" />
                  <input type="hidden" name="refpage" value="'.$refpage.'" />
                </form>');
@@ -622,6 +743,8 @@ sub display_interval_config {
         $r->print('<br />'.&mt('Choose the time window to use to display roles for which access to the '.$lctype.' expired.').'<br />');
     } elsif ($context eq 'newroles') {
         $r->print('<br />'.&mt('Choose the time window to use to display roles for which access to the '.$lctype.' became available.').'<br />');
+    } elsif ($context eq 'crslogin') {
+        $r->print('<br />'.&mt('Choose the time window to use to display the last login by a user in the '.$lctype).'<br />');
     } else {
         $r->print('<br />'.&mt('Choose the time window to use to display resources in the '.$lctype.' with version changes.').'<br />');
     }
@@ -650,7 +773,7 @@ sub display_interval_config {
     }
     $r->print('</select>&nbsp;&nbsp;
                <input type="submit" name="display" value="'.
-               &mt('Change interval').'" /></form>');
+               &mt('Save').'" /></form>');
     return;
 }
 
@@ -673,17 +796,19 @@ sub display_discussion_config {
                       'off' => 'on',
                     );
     $r->print('<script type="text/javascript">
+// <![CDATA[
 function toggle_countunread(choice) {
     if (choice == "unchanged") {
         document.discussionswitch.command.value = "";
     }
     document.discussionswitch.submit();
 }
+// ]]>
 </script>');
     $r->print('<br />'
-             .&mt('Choose whether or not to display a count of the number of new posts for each resource or bulletin board which has unread posts.')
+             .&mt('Choose whether or not to display a count of the number of new posts for each resource or discussion board which has unread posts.')
              .'<br />'
-             .&mt("This can increase the time taken to gather data for the '<i>What's New?</i>' page by a few seconds.")
+             .&mt("This can increase the time taken to gather data for the [_1]What's New Page[_2] by a few seconds.",'<i>','</i>')
              .'&nbsp;&nbsp;'
              .&mt('Currently set to [_1].','<b>'.$current.'</b>.')
     );
@@ -725,7 +850,7 @@ sub courseinit_config {
                              'anis' => 'and is set to display',
                              'padc' => 'Page display controlled by',
                              'chce' => 'Choose '.$lctype.' entry',
-                             'moce' => 'Modify '.$lctype.' entry',
+                             'moce' => 'Save',
     );
     $r->print(<<"END"); 
 <br />$lt{'chwp'}
@@ -787,10 +912,10 @@ sub display_launcher {
         $tograde,$ungraded,$bombs,$bombed,$changed,$warnings,$triggered,
         $newdiscussions,$unread,$msgcount,$newmsgs,$critmsgcount,$critmsgs,
         $interval,$countunread,$expired,$expirecount,$activated,$activecount,
-        $crstype,$itemserror) = @_;
+        $crstype,$itemserror,$loggedin,$logincount,$custommenu) = @_;
 
     if ($$checkallowed{$action}) {
-        &start_box($r,$show,$headings,$action,$refpage,$action);
+        &start_box($r,$show,$headings,$action,$refpage,$action,$custommenu);
         if ($$show{$action}) {
             if ($action eq 'handgrading') {    # UNGRADED ITEMS
                 &display_handgrade($r,$tograde,$ungraded,$itemserror);
@@ -800,7 +925,7 @@ sub display_launcher {
                 &display_versionchanges($r,$changed,$res_title,$interval->{'versions'},$itemserror);
             } elsif ($action eq 'abovethreshold') { # DEGDIFF/AV. TRIES TRIGGERS
                 &display_abovethreshold($r,$refpage,$warnings,$triggered,
-					$res_title,$itemserror);
+					$res_title,$itemserror,$custommenu);
             } elsif ($action eq 'coursediscussion') { # UNREAD COURSE DISCUSSION
                 &display_coursediscussion($r,$newdiscussions,$unread,
                                 $countunread,$res_title,$itemserror);
@@ -814,6 +939,10 @@ sub display_launcher {
             } elsif ($action eq 'oldroles') { # EXPIRED ROLES
                 &display_rolechanges($r,$expirecount,$expired,$interval->{'oldroles'},
                                      $crstype);
+            } elsif ($action eq 'crslogin') { #LAST LOGIN
+                &display_crslogins($r,$logincount,$loggedin,$interval->{'crslogin'},
+                                   $crstype);
+                                     
             }
         }
         &end_box($r);
@@ -824,7 +953,7 @@ sub display_launcher {
 sub getitems {
     my ($unread,$ungraded,$bombed,$triggered,$changed,$newdiscussions,
         $tograde,$bombs,$warnings,$threshold,$cdom,$crs,$res_title,$show,
-        $starttime,$countunread) = @_;
+        $starttime,$countunread,$custommenu) = @_;
     my $navmap = Apache::lonnavmaps::navmap->new();
     if (!defined($navmap)) {
         my $itemserror = '<span class="LC_warning">'.&mt('An error occurred retrieving information about the course.').'<br />'.&mt('It is recommended that you [_1]re-select the course[_2].','<a href="/adm/roles">','</a>').'</span>';
@@ -884,7 +1013,7 @@ sub getitems {
 # Maxtries and degree of difficulty for problem parts, unless handgradeable
         if ($$show{'abovethreshold'}) {  
             &check_thresholds($resource,$symb,\%resourcetracker,
-			      $triggered,$threshold,$warnings);
+			      $triggered,$threshold,$warnings,$custommenu);
         }
 
     }
@@ -958,7 +1087,7 @@ sub check_bombed {
 }
 
 sub check_thresholds {
-    my ($resource,$symb,$resourcetracker,$triggered,$threshold,$warnings) = @_;
+    my ($resource,$symb,$resourcetracker,$triggered,$threshold,$warnings,$custommenu) = @_;
 # Compile maxtries and degree of difficulty for problem parts, unless handgradeable
     my @parts = @{$resource->parts()};
     my %stats;
@@ -1016,12 +1145,17 @@ sub check_thresholds {
                     $$triggered{$symb}{text}[$partcount] = '
                      <td>'.&mt('single part').'</td>';
                 }
-                $$triggered{$symb}{text}[$partcount] .= '
-                     <td>'.$stats{$part}{users}.'</td>
-                     <td>'.$stats{$part}{attempts}.'</td>
-                     <td>'.$stats{$part}{degdiff}.'</td>
-                     <td>'.$lastreset{$part}.'</td>
-                     <td><input type="checkbox" name="'.$resetname.'" /><input type="hidden" name="'.$resettitle.'" value="'.&escape($$triggered{$symb}{title}).'" /></td>';
+                if ($custommenu) {
+                    $$triggered{$symb}{text}[$partcount] .= '
+                         <td class="LC_right_item">'.$stats{$part}{users}.'</td>';
+                } else {
+                    $$triggered{$symb}{text}[$partcount] .= '
+                         <td>'.$stats{$part}{users}.'</td>
+                         <td>'.$stats{$part}{attempts}.'</td>
+                         <td>'.$stats{$part}{degdiff}.'</td>
+                         <td>'.$lastreset{$part}.'</td>
+                         <td><input type="checkbox" name="'.$resetname.'" /><input type="hidden" name="'.$resettitle.'" value="'.&escape($$triggered{$symb}{title}).'" /></td>';
+                }
                 $partcount ++;
             }
             $$triggered{$symb}{numparts} = $partcount;
@@ -1032,7 +1166,14 @@ sub check_thresholds {
 
 
 sub get_curr_thresholds {
-    my ($threshold,$uname,$udom,$cid,$cdom,$crs) = @_;
+    my ($threshold,$uname,$udom,$cid,$cdom,$crs,$custommenu) = @_;
+    if ($custommenu) {
+        %$threshold = (av_attempts => 0,
+                  degdiff => 0.00000000000000,
+                  numstudents => 1
+                  );
+        return;
+    }
     # set default values
     %$threshold = (av_attempts => 2,
                   degdiff => 0.5,
@@ -1161,9 +1302,9 @@ sub getnormalmail {
         if (($fromcid) && ($fromcid eq $env{'request.course.id'})) {
             if (defined($sendtime) && $sendtime!~/error/) {
                 my $numsendtime = $sendtime;
-                $sendtime = &Apache::lonlocal::locallocaltime($sendtime);
                 if ($status eq 'new') {
-                    $msgcount ++;
+                $sendtime = &Apache::lonlocal::locallocaltime($sendtime);
+		    $msgcount ++;
                     if ($shortsubj eq '') {
                         $shortsubj = &mt('No subject');
                     }
@@ -1411,6 +1552,39 @@ sub getrolechanges {
     return $rolechgcount;
 }
 
+sub getloggedin {
+    my ($cdom,$crs,$lastlogins,$starttime) = @_;
+    my $context = 'course';
+    my ($permission,$allowed) =
+        &Apache::lonuserutils::get_permission($context);
+    my $viewablesec = &Apache::lonuserutils::viewable_section($permission);
+    my %crslogins=&Apache::lonnet::dump('nohist_crslastlogin',$cdom,$crs);
+    my $logincount = 0;
+    my ($tmp) = keys(%crslogins);
+    unless ($tmp =~ /^(con_lost|error|no_such_host)/i) {
+        if (keys(%crslogins) > 0) {
+            foreach my $key (keys(%crslogins)) {
+                my ($uname,$udom,$section,$role) = split(/:/,$key);
+                my $eventtime = $crslogins{$key};
+                if ($eventtime > $starttime) {
+                    if (($viewablesec ne '') && ($section ne '')) {
+                        next if ($viewablesec ne $section);
+                    }
+                    my %chginfo = (
+                                   'section' => $section,
+                                   'uname'   => $uname,
+                                   'udom'    => $udom,
+                                   'role'    => $role,
+                    );
+                    $logincount ++;
+                    push (@{$lastlogins->{$eventtime}},\%chginfo);
+                }
+            }
+        }
+    }
+    return $logincount;
+} 
+
 sub checkversions {
     my ($cdom,$crs,$navmap,$changed,$starttime) = @_;
     my %changes=&Apache::lonnet::dump('versionupdate',$cdom,$crs);
@@ -1511,7 +1685,7 @@ sub display_haserrors {
 }
 
 sub display_abovethreshold {
-    my ($r,$refpage,$warnings,$triggered,$res_title,$itemserror) = @_;
+    my ($r,$refpage,$warnings,$triggered,$res_title,$itemserror,$custommenu) = @_;
     my %lt = &Apache::lonlocal::texthash(
                  reso => 'Resource',
                  part => 'Part',
@@ -1525,16 +1699,35 @@ sub display_abovethreshold {
     );
     if (@{$warnings} > 0) {
         @{$warnings} = sort { &cmp_title($a,$b,$res_title) } @{$warnings};
-        $r->print('<form name="reset_tracking" method="post" action="/adm/whatsnew">'.
+        if ($custommenu) {
+            my (%bynum,@overthresh);
+            foreach my $item (@{$warnings}) {
+                my ($probnum) = ($res_title->{$item} =~ /^Problem\s+(\d+)$/);
+                if ($probnum ne '') {
+                    $bynum{$probnum} = $item;
+                }
+            }
+            foreach my $num (sort { $a <=> $b } keys(%bynum)) {
+                push(@overthresh,$bynum{$num});
+            }
+            @{$warnings} = @overthresh;
+        }
+        if ($custommenu) {
+            $r->print('<tr class="LC_info_row">'.
+                      '<td class="LC_left_item">'.$lt{'reso'}.'</td>'.
+                      '<td>'.$lt{'part'}.'</td><td class="LC_right_item">'.$lt{'nust'}.'</td></tr>');
+        } else {
+            $r->print('<form name="reset_tracking" method="post" action="/adm/whatsnew">'.
                 ' <input type="hidden" name="command" value="reset" />'."\n".
                 ' <input type="hidden" name="refpage" value="'.$refpage.'" />'.
                 "\n");
-        $r->print('<tr class="LC_info_row">'.
-		  '<td class="LC_left_item">'.$lt{'reso'}.'</td>'.
-		  '<td>'.$lt{'part'}.'</td><td>'.$lt{'nust'}.'</td>'.
-		  '<td>'.$lt{'avat'}.'</td><td>'.$lt{'dedi'}.'</td>'.
-		  '<td>'.$lt{'lare'}.'</td><td  class="LC_right_item">'.
-                  $lt{'reco'}.'</td></tr>');
+            $r->print('<tr class="LC_info_row">'.
+		      '<td class="LC_left_item">'.$lt{'reso'}.'</td>'.
+		      '<td>'.$lt{'part'}.'</td><td>'.$lt{'nust'}.'</td>'.
+		      '<td>'.$lt{'avat'}.'</td><td>'.$lt{'dedi'}.'</td>'.
+		      '<td>'.$lt{'lare'}.'</td><td  class="LC_right_item">'.
+                      $lt{'reco'}.'</td></tr>');
+        }
 	my $row;
         foreach my $res (@{$warnings}) {
 	    $row++;
@@ -1566,7 +1759,9 @@ sub display_abovethreshold {
                 }
             }
         }
-        $r->print('<tr class="LC_info_row"><td colspan="7" class="LC_right_item"><br /><input type="submit" name="counters" value="'.$lt{'rese'}.'" /></td></tr></form>');
+        unless ($custommenu) {
+            $r->print('<tr class="LC_info_row"><td colspan="7" class="LC_right_item"><br /><input type="submit" name="counters" value="'.$lt{'rese'}.'" /></td></tr></form>');
+        }
     } elsif ($itemserror) {
         $r->print('<tr class="LC_empty_row"><td>'.$itemserror.'</td></tr>');
     } else {
@@ -1667,6 +1862,92 @@ sub display_rolechanges {
     }
     return;
 }
+
+sub display_crslogins {
+    my ($r,$logincount,$loggedin,$interval,$crstype) = @_;
+    my %lt = &Apache::lonlocal::texthash(
+        'user'   => 'User',
+        'role'   => 'Role',
+        'sec'    => 'Section',
+        'number' => 'Total number of logins',
+    );
+    if ($logincount) {
+      
+        my $hdr = '<tr class="LC_info_row" style="display:none" id="logintitledet">'.
+                  '<td class="LC_left_item">'.$lt{'user'}.'</td>'.
+                  '<td class="LC_left_item">'.$lt{'role'}.'</td>'.
+                  '<td class="LC_left_item">'.$lt{'sec'}.'</td></tr>'.
+                  '<tr class="LC_info_row" id="logintitlesum">'.
+                  '<td class="LC_left_item">'.$lt{'number'}.'</td>'.
+                  '<td class="LC_left_item">'.$lt{'role'}.'</td>'.
+                  '<td class="LC_left_item">'.$lt{'sec'};
+        my (%bylastname,%counts);
+        if (ref($loggedin) eq 'HASH') {
+            my @logins = sort { $b <=> $a } (keys(%{$loggedin}));
+            my $numlogin = 0;
+            foreach my $item (@logins) {
+                if (ref($loggedin->{$item}) eq 'ARRAY') {
+                    foreach my $user (@{$loggedin->{$item}}) {
+                        if (ref($user) eq 'HASH') {
+                            my $section;
+                            my $role =
+                                &Apache::lonnet::plaintext($user->{'role'},$crstype);
+                            my $status = &mt($user->{'status'});
+                            if ($user->{'section'} eq '') {
+                                $section = &mt('none');
+                            } else {
+                                $section = $user->{'section'};
+                            }
+                            $counts{$user->{'role'}}{$section} ++;
+                            my $uname = $user->{'uname'};
+                            my $udom = $user->{'udom'};
+                            my $fullname = &Apache::loncommon::plainname($uname,$udom,'lastname');
+                            my $link =
+                                &Apache::loncommon::aboutmewrapper($fullname,$uname,$udom);
+                            push(@{$bylastname{$fullname}},
+                                                          '<td>'.$link.'</td>'.
+                                                          '<td>'.$role.'</td>'.
+                                                          '<td>'.$section.'</td>');
+                        }
+                    }
+                }
+            }
+            my $table;
+            foreach my $person (sort(keys(%bylastname))) {
+                if (ref($bylastname{$person}) eq 'ARRAY') { 
+                    foreach my $item (@{$bylastname{$person}}) { 
+                        $numlogin ++;
+                        my $css_class = $numlogin%2?' class="LC_odd_row"':'';
+                        $table .= '<tr'.$css_class.' style="display:none;"  id="logindet_'.$numlogin.'">'.$item.'</tr>'; 
+                    }
+                }
+            }
+            my $numrow = 0;
+            foreach my $role (sort(keys(%counts))) {
+                my $showrole = &Apache::lonnet::plaintext($role,$crstype);
+                if (ref($counts{$role}) eq 'HASH') { 
+                    foreach my $sec (sort { $b <=> $a } (keys(%{$counts{$role}}))) {
+                        $numrow ++;
+                        my $css_class = $numrow%2?' class="LC_odd_row"':'';
+                        $table .= '<tr '.$css_class.' id="loginsum_'.$numrow.'">'.
+                                  '<td>'.$counts{$role}{$sec}.'</td>'.
+                                  '<td>'.$showrole.'</td>'.
+                                  '<td>'.$sec.'</td></tr>';
+                   }
+                }
+            }
+            $r->print($hdr.'<input type="hidden" name="logincount" value="'.$numlogin.
+                      '" /><input type="hidden" name="loginrow" value="'.$numrow.
+                      '" /></td></tr>'.$table);
+        }
+    } else {
+        $r->print('<tr class="LC_empty_row"><td>'.
+                  &mt('There are no '.$interval).
+                  '<input type="hidden" name="logincount" value="'.$logincount.
+                  '." /></td></tr>');
+    }
+    return;
+}
  
 sub display_coursediscussion {
     my ($r,$newdiscussions,$unread,$countunread,$res_title,$itemserror) = @_;
@@ -1699,7 +1980,7 @@ sub display_coursediscussion {
             my $feedurl=&Apache::lonfeedback::get_feedurl($ressymb);
             my $disclink = $feedurl.'?symb='.$$unread{$ressymb}{symb};
             if ($feedurl =~ /bulletinboard/) {
-                $type = 'Bulletin Board';
+                $type = 'Discussion Board';
             }
             if ($$unread{$ressymb}{'enclink'}) {
                 $disclink = $$unread{$ressymb}{'enclink'}.'?symb='.$$unread{$ressymb}{'encsymb'};
@@ -1828,6 +2109,8 @@ sub store_interval_setting {
             $interval_settings{$cid.':oldroleinterval'} = $env{'form.interval'};
         } elsif ($context eq 'newroles') {
             $interval_settings{$cid.':newroleinterval'} = $env{'form.interval'};
+        } elsif ($context eq 'crslogin') {
+            $interval_settings{$cid.':crslogininterval'} = $env{'form.interval'};
         } else {
             $interval_settings{$cid.':interval'} = $env{'form.interval'};
         }
@@ -1924,7 +2207,7 @@ sub store_courseinit_setting {
 }
 
 sub start_box {
-    my ($r,$show,$heading,$caller,$refpage) = @_;
+    my ($r,$show,$heading,$caller,$refpage,$action,$custommenu) = @_;
     my %lt = &Apache::lonlocal::texthash( 
                        chth => 'Change thresholds?',
                        chin => 'Change interval?',
@@ -1949,41 +2232,49 @@ sub start_box {
            <th class="LC_right_item">'.$showhide.'</th>
           </tr>');
      if (($caller eq 'abovethreshold') && ($$show{$caller})) {
-         if ($$show{$caller}) {
+         if ($$show{$caller} && !$custommenu) {
              $r->print('
               <tr>
-                <td class="LC_subheader" colspan="2"><a href="/adm/whatsnew?command=chgthreshold&refpage='.$refpage.'">'.$lt{'chth'}.'</a></td>
+                <td class="LC_subheader" colspan="2"><a href="/adm/whatsnew?command=chgthreshold&amp;refpage='.$refpage.'">'.$lt{'chth'}.'</a></td>
               </tr>');
          }
      } elsif (($caller eq 'versionchanges') && ($$show{$caller})) {
          if ($$show{$caller}) {
              $r->print('
               <tr>
-                <td class="LC_subheader" colspan="2"><a href="/adm/whatsnew?command=chginterval&refpage='.$refpage.'">'.$lt{'chin'}.'</a></td>
+                <td class="LC_subheader" colspan="2"><a href="/adm/whatsnew?command=chginterval&amp;refpage='.$refpage.'">'.$lt{'chin'}.'</a></td>
               </tr>');
          }
      } elsif ($caller eq 'coursediscussion') {
          if ($$show{$caller}) {
              $r->print('
               <tr>
-                <td class="LC_subheader" colspan="2"><a href="/adm/whatsnew?command=chgdisc&refpage='.$refpage.'">'.$lt{'chop'}.'</a></td>
+                <td class="LC_subheader" colspan="2"><a href="/adm/whatsnew?command=chgdisc&amp;refpage='.$refpage.'">'.$lt{'chop'}.'</a></td>
               </tr>');
          }
      } elsif (($caller eq 'newroles') && ($$show{$caller})) {
          if ($$show{$caller}) {
              $r->print('
               <tr>
-                <td class="LC_subheader" colspan="2"><a href="/adm/whatsnew?command=chgnewroleinterval&refpage='.$refpage.'">'.$lt{'chin'}.'</a></td>
+                <td class="LC_subheader" colspan="2"><a href="/adm/whatsnew?command=chgnewroleinterval&amp;refpage='.$refpage.'">'.$lt{'chin'}.'</a></td>
               </tr>');
          }
      } elsif (($caller eq 'oldroles') && ($$show{$caller})) {
          if ($$show{$caller}) {
              $r->print('
               <tr>
-                <td class="LC_subheader" colspan="2"><a href="/adm/whatsnew?command=chgoldroleinterval&refpage='.$refpage.'">'.$lt{'chin'}.'</a></td>
+                <td class="LC_subheader" colspan="2"><a href="/adm/whatsnew?command=chgoldroleinterval&amp;refpage='.$refpage.'">'.$lt{'chin'}.'</a></td>
+              </tr>');
+         }
+     } elsif (($caller eq 'crslogin') && ($$show{$caller})) {
+         if ($$show{$caller}) {
+             $r->print('
+              <tr>
+                <td class="LC_subheader" align="left"><span class="LC_nobreak"><label><input type="radio" name="logindetails" value="0" checked="checked" onclick="javascript:togglelogins();" />&nbsp;'.&mt('Summary').'</label><label><input type="radio" name="logindetails" value="1" onclick="javascript:togglelogins();" />&nbsp;'.&mt('Details').'</label></span></td><td class="LC_subheader"><a href="/adm/whatsnew?command=chgcrslogininterval&amp;refpage='.$refpage.'">'.$lt{'chin'}.'</a></td>
               </tr>');
          }
      }
+
     $r->print('
               <tr>
                <td colspan="2">