[LON-CAPA-cvs] cvs: loncom /auth lonroles.pm

www lon-capa-cvs@mail.lon-capa.org
Thu, 29 Jan 2004 00:44:06 -0000


www		Wed Jan 28 19:44:06 2004 EDT

  Modified files:              
    /loncom/auth	lonroles.pm 
  Log:
  If there is only one choice, immediately select it. Also, better message
  for users who currently have no roles.
  
  
Index: loncom/auth/lonroles.pm
diff -u loncom/auth/lonroles.pm:1.83 loncom/auth/lonroles.pm:1.84
--- loncom/auth/lonroles.pm:1.83	Tue Jan 27 17:54:59 2004
+++ loncom/auth/lonroles.pm	Wed Jan 28 19:44:06 2004
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # User Roles Screen
 #
-# $Id: lonroles.pm,v 1.83 2004/01/27 22:54:59 albertel Exp $
+# $Id: lonroles.pm,v 1.84 2004/01/29 00:44:06 www Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -306,13 +306,11 @@
 		      "<br />\n");
 	    $r->print(&mt(
       "Author and Co-Author roles may not be available on servers other than your home server."));
-        } else {
-	    $r->print("<h2>".&mt('Select a Course to Enter')."</h2>\n");
         }
         if (($ENV{'REDIRECT_QUERY_STRING'}) && ($fn)) {
     	    $fn.='?'.$ENV{'REDIRECT_QUERY_STRING'};
         }
-        $r->print('<form method=post action="'.(($fn)?$fn:$r->uri).'">');
+        $r->print('<form method="post" name="rolechoice" action="'.(($fn)?$fn:$r->uri).'">');
         $r->print('<input type=hidden name=orgurl value="'.$fn.'">');
         $r->print('<input type=hidden name=selectrole value=1>');
     }
@@ -322,14 +320,11 @@
 	if ($ENV{'form.showall'}) { $r->print(' checked'); }
 	$r->print('><input type=submit value="'.&mt('Display').'">');
     }
-# ----------------------------------------------------------------------- Table
-    $r->print('<br /><table><tr>');
-    unless ($nochoose) { $r->print('<th>&nbsp;</th>'); }
-    $r->print('<th>'.&mt('User Role').'</th><th colspan=2>'.&mt('Extent').
-         '</th><th>'.&mt('Start').'</th><th>'.&mt('End').'</th><th>'.
-	      &mt('Remark').'</th></tr>'."\n");
 
     my (%roletext,%sortrole,%roleclass);
+    my $countactive=0;
+    my $inrole=0;
+    my $possiblerole='';
     foreach $envkey (sort keys %ENV) {
         my $button = 1;
         my $switchserver='';
@@ -370,6 +365,8 @@
                 if ($tstatus eq 'is') {
                     $tbg='#77FF77';
                     $tfont='#003300';
+		    $possiblerole=$trolecode;
+		    $countactive++;
                 } elsif ($tstatus eq 'future') {
                     $tbg='#FFFF77';
                     $button=0;
@@ -386,6 +383,7 @@
                 } elsif ($tstatus eq 'selected') {
                     $tbg='#11CC55';
                     $tfont='#002200';
+		    $inrole=1;
                     $tremark.=&mt('Currently selected. ');
                 }
                 my $trole;
@@ -530,6 +528,35 @@
 	    }
         }
     }
+# No active roles
+    if ($countactive==0) {
+	if ($inrole) {
+	    $r->print('<h2>'.&mt('Currently no additional roles or courses').'</h2>');
+	} else {
+	    $r->print('<h2>'.&mt('Currently no active roles or courses').'</h2>');
+	}
+	$r->print('</form></body></html>');
+	return OK;
+# Is there only one choice?
+    } elsif ($countactive==1) {
+	$r->print('<h3>'.&mt('Please stand by.').'</h3>'.
+	    '<input type="hidden" name="'.$possiblerole.'" value="1" />');
+	$r->print("</form>\n");
+	$r->rflush();
+	$r->print('<script>document.forms.rolechoice.submit();</script>');
+	$r->print('</body></html>');
+	return OK;
+    }
+# More than one possible role
+# ----------------------------------------------------------------------- Table
+    unless (($advanced) || ($nochoose)) {
+	$r->print("<h2>".&mt('Select a Course to Enter')."</h2>\n");
+    }
+    $r->print('<br /><table><tr>');
+    unless ($nochoose) { $r->print('<th>&nbsp;</th>'); }
+    $r->print('<th>'.&mt('User Role').'</th><th colspan=2>'.&mt('Extent').
+         '</th><th>'.&mt('Start').'</th><th>'.&mt('End').'</th><th>'.
+	      &mt('Remark').'</th></tr>'."\n");
     my $doheaders=-1;
     foreach my $type ('Construction Space','Course','Domain','System') {
 	my $haverole=0;