[LON-CAPA-cvs] cvs: loncom /interface loncommon.pm

raeburn lon-capa-cvs-allow@mail.lon-capa.org
Fri, 21 Dec 2007 05:13:08 -0000


raeburn		Fri Dec 21 00:13:08 2007 EDT

  Modified files:              
    /loncom/interface	loncommon.pm 
  Log:
  - Detect 'refused' as error condition from &commit_studentrole() and display contents of logmsg.
  - Localization for logmsg output generated in &commit_studentrole()
  - Display feedback about prior section and new section, when adding a student role
  requires expiring an old section-ed or sectionless role, and error="refused" because user has a section-specific cst privilege.
  
  
Index: loncom/interface/loncommon.pm
diff -u loncom/interface/loncommon.pm:1.625 loncom/interface/loncommon.pm:1.626
--- loncom/interface/loncommon.pm:1.625	Wed Dec 12 18:59:41 2007
+++ loncom/interface/loncommon.pm	Fri Dec 21 00:13:07 2007
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # a pile of common routines
 #
-# $Id: loncommon.pm,v 1.625 2007/12/12 23:59:41 raeburn Exp $
+# $Id: loncommon.pm,v 1.626 2007/12/21 05:13:07 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -7765,8 +7765,8 @@
         my $result = &commit_studentrole(\$logmsg,$udom,$uname,$url,$three,$start,$end,
                                          $one,$two,$sec,$context);
         if (($result =~ /^error/) || ($result eq 'not_in_class') || 
-            ($result eq 'unknown_course')) {
-            $output = "Error: $result\n"; 
+            ($result eq 'unknown_course') || ($result eq 'refused')) {
+            $output = $logmsg.' '.&mt('Error: ').$result."\n"; 
         } else {
             $output = $logmsg.$linefeed.&mt('Assigning').' '.$three.' in '.$url.
                ($start?', '.&mt('starting').' '.localtime($start):'').
@@ -7795,7 +7795,7 @@
 
 sub commit_studentrole {
     my ($logmsg,$udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context) = @_;
-    my ($result,$linefeed);
+    my ($result,$linefeed,$oldsecurl,$newsecurl);
     if ($context eq 'auto') {
         $linefeed = "\n";
     } else {
@@ -7815,6 +7815,7 @@
                 if ($oldsec) {
                     $uurl.='/'.$oldsec;
                 }
+                $oldsecurl = $uurl;
                 $expire_role_result = &Apache::lonnet::assignrole($udom,$uname,$uurl,'st',time);
                 $result = $expire_role_result;
             }
@@ -7823,21 +7824,35 @@
             $modify_section_result = &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,'','',$cid);
             if ($modify_section_result =~ /^ok/) {
                 if ($secchange == 1) {
-                    $$logmsg .= "Section for $uname switched from old section: $oldsec to new section: $sec".$linefeed;
+                    $$logmsg .= &mt('Section for [_1] switched from old section: [_2] to new section: [_3].',$uname,$oldsec,$sec).$linefeed;
                 } elsif ($oldsec eq '-1') {
-                    $$logmsg .= "New student role for $uname in section $sec in course $cid".$linefeed;
+                    $$logmsg .= &mt('New student role for [_1] in section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
                 } else {
-                    $$logmsg .= "Student $uname assigned to unchanged section $sec in course $cid".$linefeed;
+                    $$logmsg .= &mt('Student [_1] assigned to unchanged section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
                 }
             } else {
-                $$logmsg .= "Error when attempting section change for $uname from old section $oldsec to new section: $sec in course $cid -error: $modify_section_result".$linefeed;
+                $$logmsg .= &mt('Error when attempting section change for [_1] from old section [_2] to new section: [_3] in course [_4] -error:',$uname,$oldsec,$sec,$cid).' '.$modify_section_result.$linefeed;
             }
             $result = $modify_section_result;
         } elsif ($secchange == 1) {
-            $$logmsg .= "Error when attempting to expire role for $uname in old section $oldsec in course $cid -error: $expire_role_result".$linefeed;
+            $$logmsg .= &mt('Error when attempting to expire role for [_1] in old section [_2] in course [_3] -error: ',$uname,$oldsec,$cid).' '.$expire_role_result.$linefeed;
+            if ($expire_role_result eq 'refused') {
+                my $newsecurl = '/'.$cid;
+                $newsecurl =~ s/\_/\//g;
+                if ($sec ne '') {
+                    $newsecurl.='/'.$sec;
+                }
+                if (&Apache::lonnet::allowed('cst',$newsecurl) && !(&Apache::lonnet::allowed('cst',$oldsecurl))) {
+                    if ($sec eq '') {
+                        $$logmsg .= &mt('Although your current role has privileges to add students to section "[_1]", you do not have privileges to modify existing enrollments unaffiliated with any section.',$sec).$linefeed;
+                    } else {
+                        $$logmsg .= &mt('Although your current role has privileges to add students to section "[_1]", you do not have privileges to modify existing enrollments in other sections.',$sec).$linefeed;
+                    }
+                }
+            }
         }
     } else {
-        $$logmsg .= "Incomplete course id defined.  Addition of user $uname from domain $udom to course $one\_$two, section $sec not completed.$linefeed";
+        $$logmsg .= &mt('Incomplete course id defined.').$linefeed.&mt('Addition of user [_1] from domain [_2] to course [_3], section [_4] not completed.',$uname,$udom,$one.'_'.$two,$sec).$linefeed;
         $result = "error: incomplete course id\n";
     }
     return $result;