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

raeburn lon-capa-cvs-allow@mail.lon-capa.org
Wed, 02 Jan 2008 08:01:22 -0000


raeburn		Wed Jan  2 03:01:22 2008 EDT

  Modified files:              
    /loncom/interface	lonuserutils.pm 
  Log:
  - Confirmation dialog for bulk actions including warnings if no start or end date have been selected, or no section has been selected.
  - Correct javascript to pass value of checked retainsec radio button in pop-up window to opener.
  - Expire sectionless role if retainsec set to off, and section is being switched. 
  
  
Index: loncom/interface/lonuserutils.pm
diff -u loncom/interface/lonuserutils.pm:1.39 loncom/interface/lonuserutils.pm:1.40
--- loncom/interface/lonuserutils.pm:1.39	Tue Jan  1 15:27:29 2008
+++ loncom/interface/lonuserutils.pm	Wed Jan  2 03:01:22 2008
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Utility functions for managing LON-CAPA user accounts
 #
-# $Id: lonuserutils.pm,v 1.39 2008/01/01 20:27:29 raeburn Exp $
+# $Id: lonuserutils.pm,v 1.40 2008/01/02 08:01:22 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -1907,7 +1907,19 @@
         my $alert = &mt("You must select at least one user by checking a user's 'Select' checkbox");
         my $singconfirm = &mt(' for a single user?');
         my $multconfirm = &mt(' for multiple users?');
-        my $date_sec_selector = &date_section_javascript($context,$setting,$statusmode); 
+        my $date_sec_selector = &date_section_javascript($context,$setting,$statusmode);
+        my %lt = &Apache::lonlocal::texthash( 
+              acwi => 'Access will be set to start immediately',
+              asyo => 'as you did not select an end date in the pop-up window',
+              accw => 'Access will be set to continue indefinitely',
+              asyd => 'as you did not select an end date in the pop-up window',
+              sewi => "Sections will be switched to 'No section'",
+              ayes => "as you either selected the 'No section' option",
+              oryo => 'or you did not select a section in the pop-up window',
+              arol => 'A role with no section will be added',
+              swbs => 'Sections will be switched to:',
+              rwba => 'Roles will be added for section(s):',
+        );
         $r->print(<<END);
 
 <script type="text/javascript" language="Javascript">
@@ -1933,12 +1945,47 @@
     } 
     else {
         var message = document.studentform.bulkaction[document.studentform.bulkaction.selectedIndex].text;
+        var choice = document.studentform.bulkaction[document.studentform.bulkaction.selectedIndex].value;
         if (numchecked == 1) { 
             message += singconf;
         } 
         else {
             message += multconf; 
         }
+        if (choice == 'chgdates' || choice == 'reenable' || choice == 'activate') {
+            var datemsg = '';
+            if ((document.studentform.startdate_month.value == '') && 
+                (document.studentform.startdate_day.value  == '') &&
+                (document.studentform.startdate_year.value == '')) {
+                datemsg = "\\n$lt{'acwi'},\\n$lt{'asyo'}.\\n";
+            }
+            if ((document.studentform.enddate_month.value == '') &&
+                (document.studentform.enddate_day.value  == '') &&
+                (document.studentform.enddate_year.value == '')) {
+                datemsg += "\\n$lt{'accw'},\\n$lt{'asyd'}.\\n";
+            }
+            if (datemsg != '') {
+                message += "\\n"+datemsg;
+            }
+        }
+        if (choice == 'chgsec') {
+            var rolefilter = document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value;
+            var retained =  document.studentform.retainsec.value;
+            var secshow = document.studentform.newsecs.value;
+            if (secshow == '') {
+                if (rolefilter == 'st' || retained == 0 || retained == "") {
+                    message += "\\n\\n$lt{'sewi'},\\n$lt{'ayes'},\\n$lt{'oryo'}.\\n"; 
+                } else {
+                    message += "\\n\\n$lt{'arol'}\\n$lt{'ayes'},\\n$lt{'oryo'}.\\n";
+                }
+            } else {
+                if (rolefilter == 'st' || retained == 0 || retained == "") {
+                    message += "\\n\\n$lt{'swbs'} "+secshow+".\\n";
+                } else {
+                    message += "\\n\\n$lt{'rwba'} "+secshow+".\\n";
+                }
+            }
+        }
         if (confirm(message)) {
             document.studentform.phase.value = 'bulkchange';
             document.studentform.submit();
@@ -2665,7 +2712,15 @@
 END
     if ($env{'form.bulkaction'} eq 'chgsec') {
         $output .= <<"END";
-        opener.document.$callingform.retainsec.value = formname.retainsec.value;
+        if (formname.retainsec.length > 1) {  
+            for (var i=0; i<formname.retainsec.length; i++) {
+                if (formname.retainsec[i].checked == true) {
+                    opener.document.$callingform.retainsec.value = formname.retainsec[i].value;
+                }
+            }
+        } else {
+            opener.document.$callingform.retainsec.value = formname.retainsec.value;
+        }
         setSections(formname);
         if (seccheck == 'ok') {
             opener.document.$callingform.newsecs.value = formname.sections.value;
@@ -3939,7 +3994,11 @@
                         if (@newsecs == 0) {
                             $result = &mt('No change in section assignment (none)');
                             $nochg = 1;
-                        }
+                        } else {
+                            $revresult =
+                                &Apache::lonnet::revokerole($udom,$uname,
+                                                            $scope,$role);
+                        } 
                     } else {
                         if (@newsecs > 0) {
                             if (grep(/^\Q$sec\E$/,@newsecs)) {