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

raeburn raeburn@source.lon-capa.org
Tue, 02 Feb 2010 06:05:03 -0000


This is a MIME encoded message

--raeburn1265090703
Content-Type: text/plain

raeburn		Tue Feb  2 06:05:03 2010 EDT

  Modified files:              (Branch: version_2_9_X)
    /loncom/interface	lonuserutils.pm 
  Log:
  - Backport 1.115.
  
  
--raeburn1265090703
Content-Type: text/plain
Content-Disposition: attachment; filename="raeburn-20100202060503.txt"

Index: loncom/interface/lonuserutils.pm
diff -u loncom/interface/lonuserutils.pm:1.97.2.14 loncom/interface/lonuserutils.pm:1.97.2.15
--- loncom/interface/lonuserutils.pm:1.97.2.14	Wed Jan 20 21:49:26 2010
+++ loncom/interface/lonuserutils.pm	Tue Feb  2 06:05:03 2010
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Utility functions for managing LON-CAPA user accounts
 #
-# $Id: lonuserutils.pm,v 1.97.2.14 2010/01/20 21:49:26 raeburn Exp $
+# $Id: lonuserutils.pm,v 1.97.2.15 2010/02/02 06:05:03 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -4835,11 +4835,14 @@
 function setSections(formname,crstype) {
     var re1 = /^currsec_/;
     var re2 =/\\W/;
+    var trimleading = /^\\s+/;
+    var trimtrailing = /\\s+\$/;
     var groups = new Array($groupslist);
     for (var i=0;i<formname.elements.length;i++) {
         var str = formname.elements[i].name;
         var checkcurr = str.match(re1);
         if (checkcurr != null) {
+            var num = i;
             if ($checkincluded) {
                 $rolecode
                 if (role == 'cc' || role == 'co') {
@@ -4851,43 +4854,52 @@
                 } else {
                     var sections = '';
                     var numsec = 0;
-                    var sections;
-                    for (var j=0; j<formname.elements[i].length; j++) {
-                        if (formname.elements[i].options[j].selected == true ) {
-                            if (formname.elements[i].options[j].value != "") {
+                    var fromexisting = new Array();
+                    for (var j=0; j<formname.elements[num].length; j++) {
+                        if (formname.elements[num].options[j].selected == true ) {
+                            var addsec = formname.elements[num].options[j].value;
+                            if (addsec != "") {
+                                fromexisting.push(addsec);
                                 if (numsec == 0) {
-                                    if (formname.elements[i].options[j].value != "") {
-                                        sections = formname.elements[i].options[j].value;
-                                        numsec ++;
-                                    }
-                                }
-                                else {
-                                    sections = sections + "," +  formname.elements[i].options[j].value
-                                    numsec ++;
+                                    sections = addsec;
+                                } else {
+                                    sections = sections + "," +  addsec;
                                 }
+                                numsec ++;
                             }
                         }
                     }
-                    if (numsec > 0) {
-                        if (formname.elements[i+1].value != "" && formname.elements[i+1].value != null) {
-                            sections = sections + "," +  formname.elements[i+1].value;
-                        }
-                    }
-                    else {
-                        sections = formname.elements[i+1].value;
-                    }
-                    var newsecs = formname.elements[i+1].value;
-                    var numsplit;
+                    var newsecs = formname.elements[num+1].value;
                     var validsecs = new Array();
+                    var validsecstr = '';
                     var badsecs = new Array();
                     if (newsecs != null && newsecs != "") {
-                        numsplit = newsecs.split(/,/g);
-                        numsec = numsec + numsplit.length;
+                        var numsplit;
+                        if (newsecs.indexOf(',') == -1) {
+                            numsplit = new Array(newsecs);
+                        } else {
+                            numsplit = newsecs.split(/,/g);
+                        }
                         for (var i=0; i<numsplit.length; i++) {
-                            if (re2.test(numsplit[i]) == true) {
-                                badsecs.push(numsplit[i]);
+                            var newsec = numsplit[i];
+                            newsec = newsec.replace(trimleading,'');
+                            newsec = newsec.replace(trimtrailing,'');
+                            if (re2.test(newsec) == true) {
+                                badsecs.push(newsec);
                             } else {
-                                validsecs.push(numsplit[i]);
+                                if (newsec != '') {
+                                    var isnew = 1;
+                                    if (fromexisting != null) {
+                                        for (var m=0; m<fromexisting.length; m++) {
+                                            if (newsec == fromexisting[m]) {
+                                                isnew = 0;
+                                            }
+                                        }
+                                    }
+                                    if (isnew == 1) {
+                                        validsecs.push(newsec);
+                                    }
+                                }
                             }
                         }
                         if (badsecs.length > 0) {
@@ -4896,7 +4908,6 @@
                         }
                         numsec = numsec + validsecs.length;
                     }
-
                     if ((role == 'st') && (numsec > 1)) {
                         if (crstype == 'Community') {
                             alert("$alerts{'inea'} $alerts{'youh'} "+numsec+" $alerts{'secs'}\\n$alerts{'plmo'}");
@@ -4904,25 +4915,36 @@
                             alert("$alerts{'inco'} $alerts{'youh'} "+numsec+" $alerts{'secs'}\\n$alerts{'plmo'}");
                         }
                         return;
-                    }
-                    else {
-                        if (numsplit != null) {
-                            for (var j=0; j<numsplit.length; j++) {
-                                if ((numsplit[j] == 'all') ||
-                                    (numsplit[j] == 'none')) {
-                                    alert("'"+numsplit[j]+"' $alerts{'mayn'}\\n$alerts{'plch'}");
+                    } else {
+                        if (validsecs != null) {
+                            for (var j=0; j<validsecs.length; j++) {
+                                if (validsecstr == '' || validsecstr == null) {
+                                    validsecstr = validsecs[j];
+                                } else {
+                                    validsecstr += ','+validsecs[j];
+                                }
+                                if ((validsecs[j] == 'all') ||
+                                    (validsecs[j] == 'none')) {
+                                    alert("'"+validsecs[j]+"' $alerts{'mayn'}\\n$alerts{'plch'}");
                                     return;
                                 }
                                 for (var k=0; k<groups.length; k++) {
-                                    if (numsplit[j] == groups[k]) {
-                                        alert("'"+numsplit[j]+"' $alerts{'mnot'}\\n$alerts{'secn'}");
+                                    if (validsecs[j] == groups[k]) {
+                                        alert("'"+validsecs[j]+"' $alerts{'mnot'}\\n$alerts{'secn'}");
                                         return;
                                     }
                                 }
                             }
                         }
-                        formname.elements[i+2].value = sections;
                     }
+                    if ((validsecstr != '') && (validsecstr != null)) {
+                        if (numsec > 0) {
+                            sections = sections + "," + validsecstr;
+                        } else {
+                            sections = validsecstr;
+                        }
+                    }
+                    formname.elements[num+2].value = sections;
                 }
             }
         }

--raeburn1265090703--