[LON-CAPA-cvs] cvs: loncom /auth lonroles.pm /interface lonhtmlcommon.pm lonpreferences.pm
albertel
lon-capa-cvs@mail.lon-capa.org
Fri, 19 Nov 2004 20:17:52 -0000
albertel Fri Nov 19 15:17:52 2004 EDT
Modified files:
/loncom/auth lonroles.pm
/loncom/interface lonhtmlcommon.pm lonpreferences.pm
Log:
- Mark Lucas's changes to fix BUG#2078
Index: loncom/auth/lonroles.pm
diff -u loncom/auth/lonroles.pm:1.110 loncom/auth/lonroles.pm:1.111
--- loncom/auth/lonroles.pm:1.110 Sun Nov 14 13:27:08 2004
+++ loncom/auth/lonroles.pm Fri Nov 19 15:17:52 2004
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# User Roles Screen
#
-# $Id: lonroles.pm,v 1.110 2004/11/14 18:27:08 raeburn Exp $
+# $Id: lonroles.pm,v 1.111 2004/11/19 20:17:52 albertel Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -135,6 +135,13 @@
if ($tstatus eq 'is') {
$where=~s/^\///;
my ($cdom,$cnum,$csec)=split(/\//,$where);
+# store role if recent_role list being kept
+ if ($ENV{'environment.recentroles'}) {
+ &Apache::lonhtmlcommon::store_recent('roles',
+ $trolecode,' ');
+ }
+
+
# check for keyed access
if (($role eq 'st') &&
($ENV{'course.'.$cdom.'_'.$cnum.'.keyaccess'} eq 'yes')) {
@@ -604,6 +611,24 @@
}
if ($haverole) { $doheaders++; }
}
+
+ if ($ENV{'environment.recentroles'}) {
+ my %recent_roles =
+ &Apache::lonhtmlcommon::get_recent('roles',$ENV{'environment.recentrolesn'});
+ my $output='';
+ foreach (sort(keys(%recent_roles))) {
+ if (defined($roletext{'user.role.'.$_})) {
+ $output.=$roletext{'user.role.'.$_};
+ }
+ }
+ if ($output) {
+ $r->print("<tr bgcolor='#BBffBB'><td align='center' colspan='7'>".
+ &mt('Recent Roles')."</td>");
+ $r->print($output);
+ $r->print("</tr>");
+ }
+ }
+
if ($numdc > 0) {
&display_recent_roles($r,\%roletext,\%recentroles);
}
Index: loncom/interface/lonhtmlcommon.pm
diff -u loncom/interface/lonhtmlcommon.pm:1.96 loncom/interface/lonhtmlcommon.pm:1.97
--- loncom/interface/lonhtmlcommon.pm:1.96 Fri Nov 19 14:31:13 2004
+++ loncom/interface/lonhtmlcommon.pm Fri Nov 19 15:17:52 2004
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# a pile of common html routines
#
-# $Id: lonhtmlcommon.pm,v 1.96 2004/11/19 19:31:13 albertel Exp $
+# $Id: lonhtmlcommon.pm,v 1.97 2004/11/19 20:17:52 albertel Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -141,6 +141,30 @@
return $return;
}
+sub get_recent {
+ my ($area, $n) = @_;
+ my %recent=&Apache::lonnet::dump(&recent_filename($area));
+
+# Create hash with key as time and recent as value
+ my %time_hash = ();
+ foreach (keys %recent) {
+ my $thistime=(split(/\&/,$recent{$_}))[0];
+ $time_hash{$thistime} = $_;
+ }
+
+# Sort by decreasing time and return key value pairs
+ my %return_hash = ();
+ my $idx = 1;
+ foreach (reverse sort keys %time_hash) {
+ $return_hash{$time_hash{$_}} =
+ &Apache::lonnet::unescape((split(/\&/,$recent{$_}))[1]);
+ if ($n && ($idx++ >= $n)) {last;}
+ }
+
+ return %return_hash;
+}
+
+
=pod
Index: loncom/interface/lonpreferences.pm
diff -u loncom/interface/lonpreferences.pm:1.49 loncom/interface/lonpreferences.pm:1.50
--- loncom/interface/lonpreferences.pm:1.49 Mon Nov 1 19:17:24 2004
+++ loncom/interface/lonpreferences.pm Fri Nov 19 15:17:52 2004
@@ -1,7 +1,7 @@
# The LearningOnline Network
# Preferences
#
-# $Id: lonpreferences.pm,v 1.49 2004/11/02 00:17:24 albertel Exp $
+# $Id: lonpreferences.pm,v 1.50 2004/11/19 20:17:52 albertel Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -177,6 +177,83 @@
ENDVCSCREEN
}
+################################################################
+# Roles Page Preference Change Subroutines #
+################################################################
+sub rolesprefchanger {
+ my $r = shift;
+ my $user = $ENV{'user.name'};
+ my $domain = $ENV{'user.domain'};
+ my %userenv = &Apache::lonnet::get
+ ('environment',['recentroles','recentrolesn']);
+ my $hotlist_flag=$userenv{'recentroles'};
+ my $hotlist_n=$userenv{'recentrolesn'};
+ my $checked;
+ if ($hotlist_flag) {
+ $checked = 'checked="checked"';
+ }
+
+ if (!$hotlist_n) { $hotlist_n=3; }
+ my $options;
+ for (my $i=1; $i<10; $i++) {
+ my $select;
+ if ($hotlist_n == $i) { $select = 'selected="selected"'; }
+ $options .= "<option $select>$i</option>\n";
+ }
+
+ $r->print(<<ENDSCREEN);
+<p>Some LON-CAPA users have a long list of roles. The Recent Roles Hotlist
+feature keeps track of the last N roles which have been
+visited and places a table of these at the top of the roles page.
+People with very few roles should leave this feature disabled.
+</p>
+
+<form name="server" action="/adm/preferences" method="post">
+<input type="hidden" name="action" value="verify_and_change_rolespref" />
+<br />Enable Recent Roles Hotlist:
+<input type="checkbox" $checked name="recentroles" value="true" />
+<br />Number of roles in Hotlist:
+<select name="recentrolesn" size="1">
+$options
+</select>
+<br />
+<input type="submit" value="Change" />
+</form>
+ENDSCREEN
+}
+
+sub verify_and_change_rolespref {
+ my $r = shift;
+ my $user = $ENV{'user.name'};
+ my $domain = $ENV{'user.domain'};
+# Recent Roles Hotlist Flag
+ my $hotlist_flag = $ENV{'form.recentroles'};
+ my $hotlist_n = $ENV{'form.recentrolesn'};
+ my $message='';
+ if ($hotlist_flag) {
+ &Apache::lonnet::put('environment',{'recentroles' => $hotlist_flag});
+ &Apache::lonnet::appenv('environment.recentroles' => $hotlist_flag);
+ $message='Recent Roles Hotlist is Enabled';
+ } else {
+ &Apache::lonnet::del('environment',['recentroles']);
+ &Apache::lonnet::delenv('environment\.recentroles');
+ $message='Recent Roles Hotlist is Disabled';
+ }
+ if ($hotlist_n) {
+ &Apache::lonnet::put('environment',{'recentrolesn' => $hotlist_n});
+ &Apache::lonnet::appenv('environment.recentrolesn' => $hotlist_n);
+ if ($hotlist_flag) {
+ $message.="<br />Display $hotlist_n Most Recent Roles\n";
+ }
+ }
+
+ $r->print(<<ENDRPSCREEN);
+</p>
+$message
+ENDRPSCREEN
+}
+
+
################################################################
# Anonymous Discussion Name Change Subroutines #
@@ -953,6 +1030,23 @@
subroutine => \&verify_and_change_discussion, }
));
+ push (@Options,({ action => 'changerolespref',
+ linktext => 'Change Roles Page Preferences',
+ href => '/adm/preferences',
+ subroutine => \&rolesprefchanger,
+ breadcrumb =>
+ { href => '/adm/preferences?action=changerolespref',
+ text => 'Change Roles Pref'},
+ },
+ { action => 'verify_and_change_rolespref',
+ subroutine => \&verify_and_change_rolespref,
+ breadcrumb =>
+ { href => '/adm/preferences?action=changerolespref',
+ text => 'Change Roles Preferences'},
+ printmenu => 'yes',
+ }));
+
+
if ($ENV{'user.name'} =~ /^(albertel|koretemey|korte|hallmat3|turtle)$/) {
push (@Options,({ action => 'debugtoggle',
printmenu => 'yes',