[LON-CAPA-cvs] cvs: loncom /auth lonroles.pm
raeburn
lon-capa-cvs-allow@mail.lon-capa.org
Fri, 18 Jul 2008 16:17:39 -0000
raeburn Fri Jul 18 12:17:39 2008 EDT
Modified files:
/loncom/auth lonroles.pm
Log:
- If user has only one active role do not show "Select a Course to Enter" header line.
- If user has only one active role do not show "No role specified" line, since automatic role selection for users with a single role means role type "cm" is inaccessible.
- If user has a single active role, and that role is au, ca or aa, only do automatic role selection if user's session is on home server for corresponding author; display a switch server link if not (we don't automatically switch in case the home server is overloaded and we could get into an infinite loop of switching/offloading).
Index: loncom/auth/lonroles.pm
diff -u loncom/auth/lonroles.pm:1.201 loncom/auth/lonroles.pm:1.202
--- loncom/auth/lonroles.pm:1.201 Mon Jul 14 06:21:52 2008
+++ loncom/auth/lonroles.pm Fri Jul 18 12:17:39 2008
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# User Roles Screen
#
-# $Id: lonroles.pm,v 1.201 2008/07/14 10:21:52 raeburn Exp $
+# $Id: lonroles.pm,v 1.202 2008/07/18 16:17:39 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -714,19 +714,31 @@
$r->print(&Apache::loncommon::end_page());
return OK;
# Is there only one choice?
- } elsif (($countactive==1) && ($env{'request.role'} eq 'cm')) {
- $r->print('<h3>'.&mt('Please stand by.').'</h3>'.
- '<input type="hidden" name="'.$possiblerole.'" value="1" />'.
+ } elsif ($countactive==1) {
+ my $needs_switchserver;
+ if ($env{'user.author'}) {
+ $needs_switchserver = &check_needs_switchserver($possiblerole);
+ }
+ if ((!$needs_switchserver) && ($env{'request.role'} eq 'cm')) {
+ $r->print('<h3>'.&mt('Please stand by.').'</h3>'.
+ '<input type="hidden" name="'.$possiblerole.'" value="1" />'.
'<noscript><br /><input type="submit" name="submit" value="'.&mt('Continue').'" /></noscript>');
- $r->print("</form>\n");
- $r->rflush();
- $r->print('<script type="text/javascript">document.forms.rolechoice.submit();</script>');
- $r->print(&Apache::loncommon::end_page());
- return OK;
+ $r->print("</form>\n");
+ $r->rflush();
+ $r->print('<script type="text/javascript">document.forms.rolechoice.submit();</script>');
+ $r->print(&Apache::loncommon::end_page());
+ return OK;
+ }
+ if ($needs_switchserver) {
+ $r->print("<h2>".&mt('Server Switch Required')."</h2>\n".
+ &mt('Construction Space access is only available from '.
+ 'the home server of the corresponding Author.').'<br />'.
+ &mt("Click the 'Switch Server' link to go there.").'<br />');
+ }
}
# More than one possible role
# ----------------------------------------------------------------------- Table
- unless ((!&Apache::lonmenu::show_course()) || ($nochoose)) {
+ unless ((!&Apache::lonmenu::show_course()) || ($nochoose) || ($countactive==1)) {
$r->print("<h2>".&mt('Select a Course to Enter')."</h2>\n");
}
my $doheaders = &roletable_headers($r,\%roleclass,\%sortrole,$nochoose);
@@ -761,27 +773,28 @@
&Apache::loncommon::authorbrowser_javascript());
}
&print_rolerows($r,$doheaders,\%roleclass,\%sortrole,\%dcroles,\%roletext);
- my $tremark='';
- my $tfont='#003300';
- if ($env{'request.role'} eq 'cm') {
- $r->print('<tr bgcolor="#11CC55">');
- $tremark=&mt('Currently selected. ');
- $tfont='#002200';
- } else {
- $r->print('<tr bgcolor="#77FF77">');
- }
- unless ($nochoose) {
- if ($env{'request.role'} ne 'cm') {
- $r->print('<td><input type="submit" value="'.
- &mt('Select').'" name="cm" /></td>');
- } else {
- $r->print('<td> </td>');
- }
- }
- $r->print('<td colspan="3"><font color="'.$tfont.'"><span class="LC_rolesinfo">'.&mt('No role specified').
- '</span></font></td><td><font color="'.$tfont.'">'.$tremark.
- ' </font></td></tr>'."\n");
-
+ if ($countactive > 1) {
+ my $tremark='';
+ my $tfont='#003300';
+ if ($env{'request.role'} eq 'cm') {
+ $r->print('<tr bgcolor="#11CC55">');
+ $tremark=&mt('Currently selected. ');
+ $tfont='#002200';
+ } else {
+ $r->print('<tr bgcolor="#77FF77">');
+ }
+ unless ($nochoose) {
+ if ($env{'request.role'} ne 'cm') {
+ $r->print('<td><input type="submit" value="'.
+ &mt('Select').'" name="cm" /></td>');
+ } else {
+ $r->print('<td> </td>');
+ }
+ }
+ $r->print('<td colspan="3"><font color="'.$tfont.'"><span class="LC_rolesinfo">'.&mt('No role specified').
+ '</span></font></td><td><font color="'.$tfont.'">'.$tremark.
+ ' </font></td></tr>'."\n");
+ }
$r->print('</table>');
unless ($nochoose) {
$r->print("</form>\n");
@@ -1019,6 +1032,24 @@
return $roletext;
}
+sub check_needs_switchserver {
+ my ($possiblerole) = @_;
+ my $needs_switchserver;
+ my ($role,$where) = split(/\./,$possiblerole,2);
+ my (undef,$tdom,$twho) = split(/\//,$where);
+ my ($server_status,$home);
+ if (($role eq 'ca') || ($role eq 'aa')) {
+ ($server_status,$home) = &check_author_homeserver($twho,$tdom);
+ } else {
+ ($server_status,$home) = &check_author_homeserver($env{'user.name'},
+ $env{'user.domain'});
+ }
+ if ($server_status eq 'switchserver') {
+ $needs_switchserver = 1;
+ }
+ return $needs_switchserver;
+}
+
sub check_author_homeserver {
my ($uname,$udom)=@_;
if (($uname eq '') || ($udom eq '')) {