[LON-CAPA-cvs] cvs: loncom(loncapaMITrelate_1) /interface lonwhatsnew.pm

raeburn raeburn at source.lon-capa.org
Wed Feb 8 12:07:02 EST 2012


raeburn		Wed Feb  8 17:07:02 2012 EDT

  Modified files:              (Branch: loncapaMITrelate_1)
    /loncom/interface	lonwhatsnew.pm 
  Log:
  - Customization for MITrelate
   - New What's New item - Last login for users (day, week, month, ever).
   - Changes same as 1.98.2.1 -> 1.98.2.2 
  
  
-------------- next part --------------
Index: loncom/interface/lonwhatsnew.pm
diff -u loncom/interface/lonwhatsnew.pm:1.101.2.1 loncom/interface/lonwhatsnew.pm:1.101.2.1.2.1
--- loncom/interface/lonwhatsnew.pm:1.101.2.1	Thu May 12 16:53:02 2011
+++ loncom/interface/lonwhatsnew.pm	Wed Feb  8 17:07:02 2012
@@ -1,5 +1,5 @@
 #
-# $Id: lonwhatsnew.pm,v 1.101.2.1 2011/05/12 16:53:02 raeburn Exp $
+# $Id: lonwhatsnew.pm,v 1.101.2.1.2.1 2012/02/08 17:07:02 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -72,6 +72,7 @@
 			    ['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'};
@@ -143,6 +144,13 @@
         $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'
@@ -188,10 +196,17 @@
                    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",
@@ -220,6 +235,9 @@
     } 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);
@@ -245,9 +263,11 @@
     
     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();
@@ -264,6 +284,52 @@
         }
         $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>
 ';
     }
@@ -315,6 +381,8 @@
     my %expired;
     my $activecount;
     my %activated;
+    my %loggedin;
+    my $logincount;
     my %res_title = ();
     my %show = ();
     my $needitems = 0;
@@ -445,6 +513,20 @@
         $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;
@@ -461,6 +543,12 @@
     }
     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';
@@ -474,7 +562,7 @@
 	    $threshold{'av_attempts'},$threshold{'degdiff'},
 	    '<br />',$threshold{'numstudents'});
 
-    my @actionorder = ('handgrading','haserrors','abovethreshold','versionchanges','coursediscussion','coursenormalmail','coursecritmail','newroles','oldroles');
+    my @actionorder = ('handgrading','haserrors','abovethreshold','versionchanges','coursediscussion','coursenormalmail','coursecritmail','newroles','oldroles','crslogin');
 
     foreach my $key (keys(%{$checkallowed})) {
 	if ($key =~ /_section$/) { next; }
@@ -512,6 +600,9 @@
     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>
        <a href="javascript:changeAll('show');">$lt{'shal'}</a>
      <form method="post" name="visible" action="/adm/whatsnew">\n|);
@@ -540,7 +631,7 @@
             if ($displayed == $halfway) {
                 $r->print('</td><td> </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);
             $displayed ++; 
         }
     }
@@ -628,6 +719,8 @@
         $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 />');
     }
@@ -793,7 +886,7 @@
         $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) = @_;
 
     if ($$checkallowed{$action}) {
         &start_box($r,$show,$headings,$action,$refpage,$action);
@@ -820,6 +913,10 @@
             } 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);
@@ -1418,6 +1515,39 @@
     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);
@@ -1674,6 +1804,92 @@
     }
     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) = @_;
@@ -1835,6 +2051,8 @@
             $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'};
         }
@@ -1989,7 +2207,15 @@
                 <td class="LC_subheader" colspan="2"><a href="/adm/whatsnew?command=chgoldroleinterval&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();" /> '.&mt('Summary').'</label><label><input type="radio" name="logindetails" value="1" onclick="javascript:togglelogins();" /> '.&mt('Details').'</label></span></td><td class="LC_subheader"><a href="/adm/whatsnew?command=chgcrslogininterval&refpage='.$refpage.'">'.$lt{'chin'}.'</a></td>
+              </tr>');
+        }
+    }
+
     $r->print('
               <tr>
                <td colspan="2">


More information about the LON-CAPA-cvs mailing list