--- loncom/interface/loncreateuser.pm	2007/12/01 03:49:08	1.197
+++ loncom/interface/loncreateuser.pm	2007/12/05 17:31:28	1.200
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Create a user
 #
-# $Id: loncreateuser.pm,v 1.197 2007/12/01 03:49:08 albertel Exp $
+# $Id: loncreateuser.pm,v 1.200 2007/12/05 17:31:28 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -627,82 +627,8 @@ sub print_user_modification_page {
     }
 ENDSCRIPT
     } else {
-        $nondc_setsection_code = <<"ENDSECCODE";
-    function setSections() {
-        var re1 = /^currsec_/;
-        var groups = new Array($groupslist);
-        for (var i=0;i<document.cu.elements.length;i++) {
-            var str = document.cu.elements[i].name;
-            var checkcurr = str.match(re1);
-            if (checkcurr != null) {
-                if (document.cu.elements[i-1].checked == true) {
-		    var match = str.split('_');
-                    var role = match[3];
-                    if (role == 'cc') {
-                        alert("Section designations do not apply to Course Coordinator roles.\\nA course coordinator role will be added with access to all sections.");
-                    }
-                    else {
-                        var sections = '';
-                        var numsec = 0;
-                        var sections;
-                        for (var j=0; j<document.cu.elements[i].length; j++) {
-                            if (document.cu.elements[i].options[j].selected == true ) {
-                                if (document.cu.elements[i].options[j].value != "") {
-                                    if (numsec == 0) {
-                                        if (document.cu.elements[i].options[j].value != "") {
-                                            sections = document.cu.elements[i].options[j].value;
-                                            numsec ++;
-                                        }
-                                    }
-                                    else {
-                                        sections = sections + "," +  document.cu.elements[i].options[j].value
-                                        numsec ++;
-                                    }
-                                }
-                            }
-                        }
-                        if (numsec > 0) {
-                            if (document.cu.elements[i+1].value != "" && document.cu.elements[i+1].value != null) {
-                                sections = sections + "," +  document.cu.elements[i+1].value;
-                            }
-                        }
-                        else {
-                            sections = document.cu.elements[i+1].value;
-                        }
-                        var newsecs = document.cu.elements[i+1].value;
-			var numsplit;
-                        if (newsecs != null && newsecs != "") {
-                            numsplit = newsecs.split(/,/g);
-                            numsec = numsec + numsplit.length;
-                        }
-
-                        if ((role == 'st') && (numsec > 1)) {
-                            alert("In each course, each user may only have one student role at a time. You had selected "+numsec+" sections.\\nPlease modify your selections so they include no more than one section.")
-                            return;
-                        }
-                        else if (numsplit != null) {
-                            for (var j=0; j<numsplit.length; j++) {
-                                if ((numsplit[j] == 'all') ||
-                                    (numsplit[j] == 'none')) {
-                                    alert("'"+numsplit[j]+"' may not be used as the name for a section, as it is a reserved word.\\nPlease choose a different section name.");
-                                    return;
-                                }
-                                for (var k=0; k<groups.length; k++) {
-                                    if (numsplit[j] == groups[k]) {
-                                        alert("'"+numsplit[j]+"' may not be used as a section name, as it is the name of a course group.\\nSection names and group names must be distinct. Please choose a different section name.");
-                                        return;
-                                    }
-                                }
-                            }
-                        }
-                        document.cu.elements[i+2].value = sections;
-                    }
-                }
-            }
-        }
-        document.cu.submit();
-    }
-ENDSECCODE
+        $nondc_setsection_code =
+            &Apache::lonuserutils::setsections_javascript('cu',$groupslist);
     }
     my $js = &user_modification_js($pjump_def,$dc_setcourse_code,
                                    $nondc_setsection_code,$groupslist);
@@ -792,9 +718,6 @@ $lt{'hs'}: $home_server_pick
         } else {
             $r->print($home_server_pick);
         }
-        if ($context eq 'domain') {
-            $r->print(&Apache::lonuserutils::forceid_change());
-        }
         $r->print('</div>'."\n".'<div class="LC_left_float"><h3>'.
                   $lt{'lg'}.'</h3>');
         my ($fixedauth,$varauth,$authmsg); 
@@ -862,8 +785,11 @@ $forminfo
 ENDCHANGEUSER
         $r->print('<div class="LC_left_float">'.
                   &personal_data_display($ccuname,$ccdomain,$newuser,
-                                         %inst_results).
-                  '</div>');
+                                         %inst_results));
+        if ($context eq 'domain') {
+            $r->print(&Apache::lonuserutils::forceid_change());
+        }
+        $r->print('</div>');
         my $user_auth_text = 
             &user_authentication($ccuname,$ccdomain,$krbdefdom,\%abv_auth);
         my $user_quota_text;
@@ -1214,7 +1140,7 @@ ENDNOPORTPRIV
         }
     } else {
         $r->print(&course_level_table(%inccourses));
-        $r->print('<br /><input type="button" value="'.&mt('Modify User').'" onClick="setSections()" />'."\n");
+        $r->print('<br /><input type="button" value="'.&mt('Modify User').'" onClick="setSections(this.form)" />'."\n");
     }
     $r->print(&Apache::lonhtmlcommon::echo_form_input(['phase','userrole','ccdomain','prevphase','currstate','ccuname','ccdomain']));
     $r->print('<input type="hidden" name="currstate" value="" />');
@@ -1272,6 +1198,10 @@ ENDBADAUTH
         }
     } else { # Authentication type is valid
         &initialize_authen_forms($ccdomain,$currentauth);
+        my $authformnop_row;
+        if (&Apache::lonnet::allowed('mau',$ccdomain)) {
+            $authformnop_row = &Apache::loncommon::start_data_table_row();
+        }
         my ($authformcurrent,$authform_other,$can_modify) =
             &modify_login_block($ccdomain,$currentauth);
         if (&Apache::lonnet::allowed('mau',$ccdomain)) {
@@ -1287,7 +1217,7 @@ ENDBADAUTH
                        '</script>'."\n".
                        '<h3>'.$lt{'ld'}.'</h3>'.
                        &Apache::loncommon::start_data_table().
-                       &Apache::loncommon::start_data_table_row().
+                       $authformnop_row.
                        '<td>'.$authformnop;
             if ($can_modify) {
                 $outcome .= '</td>'."\n".
@@ -1296,7 +1226,8 @@ ENDBADAUTH
                             '<td>'.$authformcurrent.'</td>'.
                             &Apache::loncommon::end_data_table_row()."\n";
             } else {
-                $outcome .= '&nbsp;('.$authformcurrent.')</td>';
+                $outcome .= '&nbsp;('.$authformcurrent.')</td>'.
+                            &Apache::loncommon::end_data_table_row()."\n";
             }
             if ($authform_other ne '') {
                 $outcome .= $authform_other;
@@ -1876,8 +1807,10 @@ END
 	        $r->print(&mt('Revoking [_1] in [_2]: [_3]',
 			      $role,$scope,'<b>'.$result.'</b>').'<br />');
 		if ($role eq 'st') {
-		    my $result = &classlist_drop($scope,$env{'form.ccuname'},
-						 $env{'form.ccdomain'},$now);
+                    my $result =
+                        &Apache::lonuserutils::classlist_drop($scope,
+                            $env{'form.ccuname'},$env{'form.ccdomain'},
+                            $now);
 		    $r->print($result);
 		}
 	    }
@@ -1901,8 +1834,10 @@ END
 	        $r->print(&mt('Deleting [_1] in [_2]: [_3]',$role,$scope,
 			      '<b>'.$result.'</b>').'<br />');
 		if ($role eq 'st') {
-		    my $result = &classlist_drop($scope,$env{'form.ccuname'},
-						 $env{'form.ccdomain'},$now);
+                    my $result =
+                        &Apache::lonuserutils::classlist_drop($scope,
+                            $env{'form.ccuname'},$env{'form.ccdomain'},
+                            $now);
 		    $r->print($result);
 		}
             }
@@ -2101,30 +2036,6 @@ sub update_result_form {
     return $outcome;
 }
 
-sub classlist_drop {
-    my ($scope,$uname,$udom,$now) = @_;
-    my ($cdom,$cnum) = ($scope=~m{^/($match_domain)/($match_courseid)});
-    my $cid=$cdom.'_'.$cnum;
-    my $user = $uname.':'.$udom;
-    if (!&active_student_roles($cnum,$cdom,$uname,$udom)) {
-	my $result = 
-	    &Apache::lonnet::cput('classlist',
-				  { $user => $now },
-				  $env{'course.'.$cid.'.domain'},
-				  $env{'course.'.$cid.'.num'});
-	return &mt('Drop from classlist: [_1]',
-		   '<b>'.$result.'</b>').'<br />';
-    }
-}
-
-sub active_student_roles {
-    my ($cnum,$cdom,$uname,$udom) = @_;
-    my %roles = 
-	&Apache::lonnet::get_my_roles($uname,$udom,'userroles',
-				      ['future','active'],['st']);
-    return exists($roles{"$cnum:$cdom:st"});
-}
-
 sub quota_admin {
     my ($setquota,$changeHash) = @_;
     my $quotachanged;
@@ -3230,7 +3141,9 @@ sub course_level_table {
 <td>'.$area.'<br />Domain: '.$domain.'</td>'."\n";
 	        if ($role ne 'cc') {
                     if (%sections_count) {
-                        my $currsec = &course_sections(\%sections_count,$protectedcourse.'_'.$role);
+                        my $currsec =
+                            &Apache::lonuserutils::course_sections(\%sections_count,
+                                                       $protectedcourse.'_'.$role);
                         $table .= 
                     '<td><table class="LC_createuser">'.
                      '<tr class="LC_section_row">
@@ -3270,7 +3183,9 @@ ENDTIMEENTRY
 <td>'.$plrole.'</td>
 <td>'.$area.'</td>'."\n";
                 if (%sections_count) {
-                    my $currsec = &course_sections(\%sections_count,$customrole);
+                    my $currsec =
+                        &Apache::lonuserutils::course_sections(\%sections_count,
+                                                               $customrole);
                     $table.=
                    '<td><table class="LC_createuser">'.
                    '<tr class="LC_section_row"><td valign="top">'.
@@ -3314,28 +3229,6 @@ $table.
     return $result;
 }
 
-sub course_sections {
-    my ($sections_count,$role) = @_;
-    my $output = '';
-    my @sections = (sort {$a <=> $b} keys %{$sections_count});
-    if (scalar(@sections) == 1) {
-        $output = '<select name="currsec_'.$role.'" >'."\n".
-                  '  <option value="">Select</option>'."\n".
-                  '  <option value="">No section</option>'."\n".
-                  '  <option value="'.$sections[0].'" >'.$sections[0].'</option>'."\n";
-    } else {
-        $output = '<select name="currsec_'.$role.'" ';
-        my $multiple = 4;
-        if (scalar(@sections) < 4) { $multiple = scalar(@sections); }
-        $output .= 'multiple="multiple" size="'.$multiple.'">'."\n";
-        foreach my $sec (@sections) {
-            $output .= '<option value="'.$sec.'">'.$sec."</option>\n";
-        }
-    }
-    $output .= '</select>'; 
-    return $output;
-}
-
 sub course_level_dc {
     my ($dcdom) = @_;
     my %customroles=&Apache::lonuserutils::my_custom_roles();