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

raeburn lon-capa-cvs-allow@mail.lon-capa.org
Fri, 21 Dec 2007 12:41:26 -0000


This is a MIME encoded message

--raeburn1198240886
Content-Type: text/plain

raeburn		Fri Dec 21 07:41:26 2007 EDT

  Modified files:              
    /loncom/interface	lonuserutils.pm loncreateuser.pm 
  Log:
  loncreateuser.pm
  - "Enroll a Single Student" and "Drop Students" links added to CUSR main menu in cours context.
  - Automated Enrollment Manager link not shown if user with CUSR priv has section-sepecific priv.
  - &date_sections_select() added to display both a table for etting tart/end access dates and  section for role.
  
  lonuserutils.pm 
  - &get_course_identity() - retrieves course number, domain and description for courseID passed in, or from $env{'request.course.id'} if no arg passed
  - &roles_by_context() - returns array of roles for context (course, domain or author). Adds in 'cr' role, if $custom arg passed to it is true.
  - &section_picker() - provide box containing dropdown for current sections, and textbox for new section - used to pick section(s) to associate with a role.
    - for a user with section-specific cst priv, only section available to pick is section of current role. 
  - &print_expire_menu() renamed as &print_drop_menu()
  - &update_user_list() now includes action for $choice = drop (used to drop students).
  - &get_permission() will set $permission{'cusr_section'} if section-specific user has 'cst' priv  
  - check/uncheck javascript in &show_drop_list() from &Apache::loncommon::check_uncheck_jscript()
  - eliminate links to /adm/dropadd 
  
  
--raeburn1198240886
Content-Type: text/plain
Content-Disposition: attachment; filename="raeburn-20071221074126.txt"

Index: loncom/interface/lonuserutils.pm
diff -u loncom/interface/lonuserutils.pm:1.16 loncom/interface/lonuserutils.pm:1.17
--- loncom/interface/lonuserutils.pm:1.16	Thu Dec 13 19:20:53 2007
+++ loncom/interface/lonuserutils.pm	Fri Dec 21 07:41:25 2007
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Utility functions for managing LON-CAPA user accounts
 #
-# $Id: lonuserutils.pm,v 1.16 2007/12/14 00:20:53 raeburn Exp $
+# $Id: lonuserutils.pm,v 1.17 2007/12/21 12:41:25 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -46,8 +46,7 @@
     # if $csec is undefined, drop the student from all the courses matching
     # this one.  If $csec is defined, drop them from all other sections of
     # this course and add them to section $csec
-    my $cdom = $env{'course.'.$courseid.'.domain'};
-    my $cnum = $env{'course.'.$courseid.'.num'};
+    my ($cnum,$cdom) = &get_course_identity($courseid);
     my %roles = &Apache::lonnet::dump('roles',$udom,$unam);
     my ($tmp) = keys(%roles);
     # Bail out if we were unable to get the students roles
@@ -236,8 +235,8 @@
         } elsif ($roletype eq 'author') {
             @roles = &construction_space_roles();
         } else {
-            @roles = &course_roles('domain');
-            unshift(@roles,'cr');
+            my $custom = 1;
+            @roles = &course_roles('domain',undef,$custom);
         }
         my $order = ['Any',@roles];
         $select_menus{$roletype}->{'order'} = $order; 
@@ -962,11 +961,10 @@
     my ($startdate,$enddate,$context) = @_;
     my $result = '';
     if ($context eq 'course') {
-        my $dom = $env{'course.'.$env{'request.course.id'}.'.domain'};
-        my $crs = $env{'course.'.$env{'request.course.id'}.'.num'};
+        my ($cnum,$cdom) = &get_course_identity();
         my $put_result = &Apache::lonnet::put('environment',
                 {'default_enrollment_start_date'=>$startdate,
-                 'default_enrollment_end_date'  =>$enddate},$dom,$crs);
+                 'default_enrollment_end_date'  =>$enddate},$cdom,$cnum);
         if ($put_result eq 'ok') {
             $result .= &mt('Set default start and end dates for course').
                        '<br />'."\n";
@@ -1048,7 +1046,8 @@
 sub default_course_roles {
     my ($context,$checkpriv,%customroles) = @_;
     my $output;
-    my @roles = &course_roles($context,$checkpriv);
+    my $custom = 1;
+    my @roles = &course_roles($context,$checkpriv,$custom);
     foreach my $role (@roles) {
         my $plrole=&Apache::lonnet::plaintext($role);
         $output .= '  <option value="'.$role.'">'.$plrole.'</option>';
@@ -1066,7 +1065,7 @@
 
 sub construction_space_roles {
     my ($checkpriv) = @_;
-    my @allroles = ('ca','aa');
+    my @allroles = &roles_by_context('author');
     my @roles;
     if ($checkpriv) {
         foreach my $role (@allroles) {
@@ -1082,7 +1081,7 @@
 
 sub domain_roles {
     my ($checkpriv) = @_;
-    my @allroles = ('dc','li','dg','au','sc');
+    my @allroles = &roles_by_context('domain');
     my @roles;
     if ($checkpriv) {
         foreach my $role (@allroles) {
@@ -1097,8 +1096,8 @@
 }
 
 sub course_roles {
-    my ($context,$checkpriv) = @_;
-    my @allroles = ('st','ta','ep','in','cc');
+    my ($context,$checkpriv,$custom) = @_;
+    my @allroles = &roles_by_context('course',$custom);
     my @roles;
     if ($context eq 'domain') {
         @roles = @allroles;
@@ -1128,17 +1127,18 @@
 
 sub curr_role_permissions {
     my ($context,$setting,$checkpriv) = @_; 
+    my $custom = 1;
     my @roles;
     if ($context eq 'author') {
         @roles = &construction_space_roles($checkpriv);
     } elsif ($context eq 'domain') {
         if ($setting eq 'course') {
-            @roles = &course_roles($context,$checkpriv); 
+            @roles = &course_roles($context,$checkpriv,$custom); 
         } else {
             @roles = &domain_roles($checkpriv);
         }
     } elsif ($context eq 'course') {
-        @roles = &course_roles($context,$checkpriv);
+        @roles = &course_roles($context,$checkpriv,$custom);
     }
     return @roles;
 }
@@ -1287,8 +1287,7 @@
             }
         }
         my $cid =$env{'request.course.id'};
-        my $cdom=$env{'course.'.$cid.'.domain'};
-        my $cnum=$env{'course.'.$cid.'.num'};
+        my ($cnum,$cdom) = &get_course_identity($cid);
         my $showroles;
         if ($env{'form.showrole'} ne 'Any') {
             $showroles = [$env{'form.showrole'}];
@@ -1303,7 +1302,7 @@
         my (%cstr_roles,%dom_roles);
         if ($context eq 'author') {
             # List co-authors and assistant co-authors
-            my @possroles = ('ca','aa');
+            my @possroles = &roles_by_context($context);
             %cstr_roles = &Apache::lonnet::get_my_roles(undef,undef,undef,
                                               \@statuses,\@possroles);
             &gather_userinfo($context,$format,\%userlist,$indexhash,\%userinfo,
@@ -1328,7 +1327,7 @@
                         } else {
                             my @possroles;
                             if ($env{'form.showrole'} eq 'Any') {
-                                @possroles = ('ca','aa');
+                                my @possroles = &roles_by_context($context);
                             } else {
                                 @possroles = ($env{'form.showrole'}); 
                             }
@@ -1351,14 +1350,13 @@
                     foreach my $cid (keys(%courses)) {
                         my %coursehash =
                             &Apache::lonnet::coursedescription($cid,{'one_time' => 1});
-                        my $cdom = $coursehash{'domain'};
-                        my $cnum = $coursehash{'num'};
+                        my ($cnum,$cdom,$cdesc) = &get_course_identity($cid);
                         next if ($cnum eq '' || $cdom eq '');
-                        my $cdesc = $coursehash{'description'};
+                        my $custom = 1;
                         my (@roles,@sections,%access,%users,%userdata,
                             %statushash);
                         if ($env{'form.showrole'} eq 'Any') {
-                            @roles = &course_roles($context);
+                            @roles = &course_roles($context,undef,$custom);
                             unshift(@roles,'cr');
                         } else {
                             @roles = ($env{'form.showrole'});
@@ -1760,8 +1758,7 @@
     my ($cid,$cdom,$cnum,$classgroups,$displayphotos,$displayclickers);
     if ($context eq 'course') {
         $cid=$env{'request.course.id'};
-        $cdom = $env{'course.'.$cid.'.domain'};
-        $cnum = $env{'course.'.$cid.'.num'};
+        ($cnum,$cdom) = &get_course_identity($cid);
         ($classgroups) = &Apache::loncoursedata::get_group_memberships(
                                      $userlist,$keylist,$cdom,$cnum);
         if ($mode eq 'autoenroll') {
@@ -2511,8 +2508,7 @@
                '<form name="'.$formname.'" method="post">'."\n".
                 $date_items;
     if ($context eq 'course' && $env{'form.bulkaction'} eq 'chgsec') {
-        my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
-        my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
+        my ($cnum,$cdom) = &get_course_identity();
         my %sections_count =
             &Apache::loncommon::get_sections($cdom,$cnum);
         my $info;
@@ -2560,6 +2556,36 @@
     return $output;
 }
 
+sub section_picker {
+    my ($cdom,$cnum,$role,$rowtitle,$permission,$context,$mode) = @_;
+    my %sections_count = &Apache::loncommon::get_sections($cdom,$cnum);
+    my $sections_select .= &course_sections(\%sections_count,$role);
+    my $secbox = '<p>'.&Apache::lonhtmlcommon::start_pick_box()."\n";
+    if ($mode eq 'upload') {
+        my ($options,$cb_script,$coursepick) =
+            &default_role_selector($context,1);
+        $secbox .= &Apache::lonhtmlcommon::row_title('role','LC_oddrow_value').
+                   $options. &Apache::lonhtmlcommon::row_closure(1)."\n";
+    }
+    $secbox .= &Apache::lonhtmlcommon::row_title($rowtitle,'LC_oddrow_value')."\n";
+    if ($env{'request.course.sec'} eq '') {
+        $secbox .= '<table class="LC_createuser"><tr class="LC_section_row">'."\n".
+                   '<td align="center">'.&mt('Existing sections')."\n".
+                   '<br />'.$sections_select.'</td><td align="center">'.
+                   &mt('New section').'<br />'."\n".
+                   '<input type="text" name="newsec" size="15" />'."\n".
+                   '<input type="hidden" name="sections" value="" />'."\n".
+                   '</td></tr></table>'."\n";
+    } else {
+       $secbox .= '<input type="hidden" name="sections" value="'.
+                   $env{'request.course.sec'}.'" />'.
+                   $env{'request.course.sec'};
+    }
+    $secbox .= &Apache::lonhtmlcommon::row_closure(1)."\n".
+               &Apache::lonhtmlcommon::end_pick_box().'</p>';
+    return $secbox;
+}
+
 sub results_header_row {
     my ($rolefilter,$statusmode,$context,$permission) = @_;
     my ($description,$showfilter);
@@ -2671,8 +2697,9 @@
 #################################################
 #################################################
 sub show_drop_list {
-    my ($r,$classlist,$keylist,$nosort)=@_;
+    my ($r,$classlist,$keylist,$nosort,$permission)=@_;
     my $cid=$env{'request.course.id'};
+    my ($cnum,$cdom) = &get_course_identity($cid);
     if (! exists($env{'form.sortby'})) {
         &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
                                                 ['sortby']);
@@ -2681,26 +2708,17 @@
     if ($sortby !~ /^(username|domain|section|groups|fullname|id|start|end)$/) {
         $sortby = 'username';
     }
-    my $cdom = $env{'course.'.$cid.'.domain'};
-    my $cnum = $env{'course.'.$cid,'.num'};
     my ($classgroups) = &Apache::loncoursedata::get_group_memberships(
                                               $classlist,$keylist,$cdom,$cnum);
     #
     my $action = "drop";
+    my $check_uncheck_js = &Apache::loncommon::check_uncheck_jscript();
     $r->print(<<END);
 <input type="hidden" name="sortby" value="$sortby" />
 <input type="hidden" name="action" value="$action" />
 <input type="hidden" name="state"  value="done" />
-<script>
-function checkAll(field) {
-    for (i = 0; i < field.length; i++)
-        field[i].checked = true ;
-}
-
-function uncheckAll(field) {
-    for (i = 0; i < field.length; i++)
-        field[i].checked = false ;
-}
+<script type="text/javascript" language="Javascript">
+$check_uncheck_js
 </script>
 <p>
 <input type="hidden" name="phase" value="four">
@@ -2715,9 +2733,9 @@
                                    'groups' => "active groups",
                                    );
     if ($nosort) {
-        $r->print(&Apache::loncommon::start_data_table());
+        $r->print(&Apache::loncommon::start_data_table().
+                  &Apache::loncommon::start_data_table_header_row());
         $r->print(<<END);
-<tr>
     <th>&nbsp;</th>
     <th>$lt{'usrn'}</th>
     <th>$lt{'dom'}</th>
@@ -2727,32 +2745,32 @@
     <th>$lt{'start'}</th>
     <th>$lt{'end'}</th>
     <th>$lt{'groups'}</th>
-</tr>
 END
-
+        $r->print(&Apache::loncommon::end_data_table_header_row());
     } else  {
-        $r->print(&Apache::loncommon::start_data_table());
+        $r->print(&Apache::loncommon::start_data_table().
+                  &Apache::loncommon::start_data_table_header_row());
         $r->print(<<END);
-<tr><th>&nbsp;</th>
+    <th>&nbsp;</th>
     <th>
-       <a href="/adm/dropadd?action=$action&sortby=username">$lt{'usrn'}</a>
+       <a href="/adm/createuser?action=$action&sortby=username">$lt{'usrn'}</a>
     </th><th>
-       <a href="/adm/dropadd?action=$action&sortby=domain">$lt{'dom'}</a>
+       <a href="/adm/createuser?action=$action&sortby=domain">$lt{'dom'}</a>
     </th><th>
-       <a href="/adm/dropadd?action=$action&sortby=id">ID</a>
+       <a href="/adm/createuser?action=$action&sortby=id">ID</a>
     </th><th>
-       <a href="/adm/dropadd?action=$action&sortby=fullname">$lt{'sn'}</a>
+       <a href="/adm/createuser?action=$action&sortby=fullname">$lt{'sn'}</a>
     </th><th>
-       <a href="/adm/dropadd?action=$action&sortby=section">$lt{'sec'}</a>
+       <a href="/adm/createuser?action=$action&sortby=section">$lt{'sec'}</a>
     </th><th>
-       <a href="/adm/dropadd?action=$action&sortby=start">$lt{'start'}</a>
+       <a href="/adm/createuser?action=$action&sortby=start">$lt{'start'}</a>
     </th><th>
-       <a href="/adm/dropadd?action=$action&sortby=end">$lt{'end'}</a>
+       <a href="/adm/createuser?action=$action&sortby=end">$lt{'end'}</a>
     </th><th>
-       <a href="/adm/dropadd?action=$action&sortby=groups">$lt{'groups'}</a>
+       <a href="/adm/createuser?action=$action&sortby=groups">$lt{'groups'}</a>
     </th>
-</tr>
 END
+        $r->print(&Apache::loncommon::end_data_table_header_row());
     }
     #
     # Sort the students
@@ -2799,6 +2817,13 @@
         }
         my $status   = $sdata->[$index{'status'}];
         next if ($status ne 'Active');
+        if ($env{'request.course.sec'} ne '') {
+            if ($section ne $env{'request.course.sec'}) {
+                next;
+            }
+        }
+        my $studentkey = $student.':'.$section;
+        my $startitem = '<input type="hidden" name="'.$studentkey.'_start" value="'.$sdata->[$index{'start'}].'" />';
         #
         $r->print(&Apache::loncommon::start_data_table_row());
         $r->print(<<"END");
@@ -3309,9 +3334,10 @@
 }
 
 # ========================================================= Menu Phase Two Drop
-sub print_expire_menu {
-    my ($r,$context) = @_;
-    $r->print("<h3>".&mt("Expire Users' Roles")."</h3>");
+sub print_drop_menu {
+    my ($r,$context,$permission) = @_;
+    $r->print('<h3>'.&mt("Drop Students").'</h3>'."\n".
+              '<form name="studentform" method="post">'."\n");
     my $cid=$env{'request.course.id'};
     my ($classlist,$keylist) = &Apache::loncoursedata::get_classlist();
     if (! defined($classlist)) {
@@ -3319,11 +3345,11 @@
         return;
     }
     # Print out the available choices
-    &show_drop_list($r,$classlist,$keylist);
+    &show_drop_list($r,$classlist,$keylist,$permission);
+    $r->print('</form>'. &Apache::loncommon::end_page());
     return;
 }
 
-
 # ================================================================== Phase four
 
 sub update_user_list {
@@ -3339,12 +3365,18 @@
     my %result_text = ( ok    => { 'revoke'   => 'Revoked',
                                    'delete'   => 'Deleted',
                                    'reenable' => 'Re-enabled',
-                                   'activate' => 'Activated', 
+                                   'activate' => 'Activated',
+                                   'chgdates' => 'Changed Access Dates for',
+                                   'chgsec'   => 'Changed section for',
+                                   'drop'     => 'Dropped',
                                  },
                         error => {'revoke'    => 'revoking',
                                   'delete'    => 'deleting',
                                   'reenable'  => 're-enabling',
                                   'activate'  => 'activating',
+                                  'chgdates'  => 'changing access dates for',
+                                  'chgsec'    => 'changing section for',
+                                  'drop'      => 'dropping',
                                  },
                       );
     my ($startdate,$enddate);
@@ -3354,7 +3386,18 @@
     foreach my $item (@changelist) {
         my ($role,$uname,$udom,$cid,$sec,$scope,$result,$type,$locktype,@sections,
             $scopestem);
-        if ($context eq 'course') {
+        if ($choice eq 'drop') {
+            ($uname,$udom,$sec) = split(/:/,$item,-1);
+            $role = 'st';
+            $cid = $env{'request.course.id'};
+            $scopestem = '/'.$cid;
+            $scopestem =~s/\_/\//g;
+            if ($sec eq '') {
+                $scope = $scopestem;
+            } else {
+                $scope = $scopestem.'/'.$sec;
+            }
+        } elsif ($context eq 'course') {
             ($uname,$udom,$role,$sec,$type,$locktype) = split(/\:/,$item,-1);
             $cid = $env{'request.course.id'};
             $scopestem = '/'.$cid;
@@ -3387,8 +3430,14 @@
         my ($uid,$first,$middle,$last,$gene,$sec);
         my $start = $env{'form.'.$item.'_start'};
         my $end = $env{'form.'.$item.'_end'};
-        # revoke or delete user role
-        if ($choice eq 'revoke') {
+        if ($choice eq 'drop') {
+            # drop students
+            $end = $now;
+            $type = 'manual';
+            $result =
+                &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,$type,$locktype,$cid);
+        } elsif ($choice eq 'revoke') {
+            # revoke or delete user role
             $end = $now; 
             if ($role eq 'st') {
                 $result = 
@@ -3490,19 +3539,26 @@
                 }
             }
         }
+        my $extent = $scope;
+        if ($choice eq 'drop' || $context eq 'course') {
+            my ($cnum,$cdom,$cdesc) = &get_course_identity($cid);
+            if ($cdesc) {
+                $extent = $cdesc;
+            }
+        }
         if ($result eq 'ok' || $result eq 'ok:') {
             $r->print(&mt("$result_text{'ok'}{$choice} role of '[_1]' in [_2] for [_3]",
-                          $plrole,$scope,$uname.':'.$udom).'<br />');
+                          $plrole,$extent,$uname.':'.$udom).'<br />');
             $count++;
         } else {
             $r->print(
                 &mt("Error $result_text{'error'}{$choice} [_1] in [_2] for [_3]:[_4]",
-                    $plrole,$scope,$uname.':'.$udom,$result).'<br />');
+                    $plrole,$extent,$uname.':'.$udom,$result).'<br />');
         }
     }
     $r->print('<p><b>'.&mt("$result_text{'ok'}{$choice} role(s) for [quant,_1,user,users,users].",$count).'</b></p>');
     if ($count > 0) {
-        if ($choice eq 'revoke') {
+        if ($choice eq 'revoke' || $choice eq 'drop') {
             $r->print('<p>'.&mt('Re-enabling will re-activate data for the role.</p>'));
         }
         # Flush the course logs so reverse user roles immediately updated
@@ -3754,19 +3810,33 @@
     return $cancreate;
 }
 
+sub roles_by_context {
+    my ($context,$custom) = @_;
+    my @allroles;
+    if ($context eq 'course') {
+        @allroles = ('st','ad','ta','ep','in','cc');
+        if ($custom) {
+            push(@allroles,'cr');
+        }
+    } elsif ($context eq 'author') {
+        @allroles = ('ca','aa');
+    } elsif ($context eq 'domain') {
+        @allroles = ('li','dg','sc','au','dc');
+    }
+    return @allroles;
+}
+
 sub get_permission {
-    my ($context) = @_;
+    my ($context,$roles) = @_;
     my %permission;
     if ($context eq 'course') {
-        if ((&Apache::lonnet::allowed('cta',$env{'request.course.id'})) ||
-            (&Apache::lonnet::allowed('cin',$env{'request.course.id'})) ||
-            (&Apache::lonnet::allowed('ccr',$env{'request.course.id'})) ||
-            (&Apache::lonnet::allowed('cep',$env{'request.course.id'})) ||
-            (&Apache::lonnet::allowed('cst',$env{'request.course.id'}))) {
-            $permission{'cusr'} = 1;
-            $permission{'view'} =
-                 &Apache::lonnet::allowed('vcl',$env{'request.course.id'});
-
+        my $custom = 1;
+        my @allroles = &roles_by_context($context,$custom);
+        foreach my $role (@allroles) {
+            if (&Apache::lonnet::allowed('c'.$role,$env{'request.course.id'})) {
+                $permission{'cusr'} = 1;
+                last;
+            }
         }
         if (&Apache::lonnet::allowed('ccr',$env{'request.course.id'})) {
             $permission{'custom'} = 1;
@@ -3781,6 +3851,15 @@
                 $permission{'view_section'} = $env{'request.course.sec'};
             }
         }
+        if (!$permission{'cusr'}) {
+            if ($env{'request.course.sec'} ne '') {
+                my $scope = $env{'request.course.id'}.'/'.$env{'request.course.sec'};
+                $permission{'cusr'} = (&Apache::lonnet::allowed('cst',$scope));
+                if ($permission{'cusr'}) {
+                    $permission{'cusr_section'} = $env{'request.course.sec'};
+                }
+            }
+        }
         if (&Apache::lonnet::allowed('mdg',$env{'request.course.id'})) {
             $permission{'grp_manage'} = 1;
         }
@@ -3788,13 +3867,16 @@
         $permission{'cusr'} = &authorpriv($env{'user.name'},$env{'request.role.domain'});
         $permission{'view'} = $permission{'cusr'};
     } else {
-        if ((&Apache::lonnet::allowed('cad',$env{'request.role.domain'})) ||
-            (&Apache::lonnet::allowed('cli',$env{'request.role.domain'})) ||
-            (&Apache::lonnet::allowed('cau',$env{'request.role.domain'})) ||
-            (&Apache::lonnet::allowed('csc',$env{'request.role.domain'})) ||
-            (&Apache::lonnet::allowed('cdg',$env{'request.role.domain'})) ||
-            (&Apache::lonnet::allowed('mau',$env{'request.role.domain'}))) {
-            $permission{'cusr'} = 1;
+        my @allroles = &roles_by_context($context);
+        foreach my $role (@allroles) {
+            if (&Apache::lonnet::allowed('c'.$role,$env{'request.role.domain'})) {                $permission{'cusr'} = 1;
+                last;
+            }
+        }
+        if (!$permission{'cusr'}) {
+            if (&Apache::lonnet::allowed('mau',$env{'request.role.domain'})) {
+                $permission{'cusr'} = 1;
+            }
         }
         if (&Apache::lonnet::allowed('ccr',$env{'request.role.domain'})) {
             $permission{'custom'} = 1;
@@ -3816,5 +3898,28 @@
          || (&Apache::lonnet::allowed('caa',$audom.'/'.$auname))) { return ''; }    return 1;
 }
 
+sub get_course_identity {
+    my ($cid) = @_;
+    my ($cnum,$cdom,$cdesc);
+    if ($cid eq '') {
+        $cid = $env{'request.course.id'}
+    }
+    if ($cid ne '') {
+        $cnum = $env{'course.'.$cid.'.num'};
+        $cdom = $env{'course.'.$cid.'.domain'};
+        $cdesc = $env{'course.'.$cid.'.description'};
+        if ($cnum eq '' || $cdom eq '') {
+            my %coursehash =
+                &Apache::lonnet::coursedescription($cid,{'one_time' => 1});
+            $cdom = $coursehash{'domain'};
+            $cnum = $coursehash{'num'};
+            $cdesc = $coursehash{'description'};
+        }
+    }
+    return ($cnum,$cdom,$cdesc);
+}
+
+
+
 1;
 
Index: loncom/interface/loncreateuser.pm
diff -u loncom/interface/loncreateuser.pm:1.212 loncom/interface/loncreateuser.pm:1.213
--- loncom/interface/loncreateuser.pm:1.212	Fri Dec 21 00:40:43 2007
+++ loncom/interface/loncreateuser.pm	Fri Dec 21 07:41:25 2007
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Create a user
 #
-# $Id: loncreateuser.pm,v 1.212 2007/12/21 05:40:43 raeburn Exp $
+# $Id: loncreateuser.pm,v 1.213 2007/12/21 12:41:25 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -249,6 +249,7 @@
 				       );
     my $help = &Apache::loncommon::help_open_menu(undef,undef,282,'Instructor Interface');
     my $helpsiur=&Apache::loncommon::help_open_topic('Course_Change_Privileges');
+    my $helpsist=&Apache::loncommon::help_open_topic('Course_Add_Student');
     my $helpecpr=&Apache::loncommon::help_open_topic('Course_Editing_Custom_Roles');
     my $sellink=&Apache::loncommon::selectstudent_link('crtuser','srchterm','srchdomain');
     if ($sellink) {
@@ -272,6 +273,17 @@
 </form>
 ENDCUSTOM
         }
+    } else {
+        my $actiontext = $lt{'mod'}.$helpsiur;
+        if ($env{'form.action'} eq 'singlestudent') {
+            $actiontext = $lt{'enrl'}.$helpsist;
+        }
+        $r->print("
+<h3>$lt{'srch'} $sellink $actiontext</h3>");
+        if ($env{'form.origform'} ne 'crtusername') {
+            $r->print("\n".$response);
+        }
+        $r->print(&entry_form($defdom,$srch,$forcenewuser,$context,$response));
     }
     $r->print(&Apache::loncommon::end_page());
 }
@@ -478,6 +490,14 @@
 	&print_username_entry_form($r,$context,$usermsg);
         return;
     }
+    my ($form,$formname);
+    if ($env{'form.action'} eq 'singlestudent') {
+        $form = 'document.enrollstudent';
+        $formname = 'enrollstudent';
+    } else {
+        $form = 'document.cu';
+        $formname = 'cu';
+    }
     my %abv_auth = &auth_abbrev();
     my ($curr_authtype,%rulematch,%inst_results,$curr_kerb_ver,$newuser,
         %alerts,%curr_rules,%got_rules);
@@ -721,6 +741,7 @@
         &initialize_authen_forms($ccdomain);
         my %lt=&Apache::lonlocal::texthash(
                 'cnu'            => 'Create New User',
+                'ast'            => 'as a student',
                 'ind'            => 'in domain',
                 'lg'             => 'Login Data',
                 'hs'             => "Home Server",
@@ -736,7 +757,10 @@
 <input type='hidden' name='makeuser' value='1' />
 <h2>$lt{'cnu'} "$ccuname" $lt{'ind'} $ccdomain</h2>
 ENDTITLE
-        $r->print('<div class="LC_left_float">');
+        if ($env{'form.action'} eq 'singlestudent') {
+            $r->print(' ('.$lt{'ast'}.')');
+        }
+        $r->print('</h2>'."\n".'<div class="LC_left_float">');
         my $personal_table = 
             &personal_data_display($ccuname,$ccdomain,$newuser,$context,
                                    $inst_results{$ccuname.':'.$ccdomain});
@@ -802,22 +826,26 @@
         } else {
             $r->print(&Apache::lonuserutils::set_login($ccdomain,$authformkrb,$authformint,$authformloc)); 
         }
-        $r->print(<<ENDPORT);
-        $portfolioform
-</div><div class="LC_clear_float_footer"></div>
-ENDPORT
-    } else { # user already exists
+        $r->print('</h2>'."\n".'<div class="LC_left_float">');
+    } else { # user already exist-
 	my %lt=&Apache::lonlocal::texthash(
                     'cup'  => "Modify existing user: ",
+                    'ens'  => "Enroll one student: ",
                     'id'   => "in domain",
 				       );
 	$r->print(<<ENDCHANGEUSER);
 $start_page
 $crumbs
 $forminfo
-<h2>$lt{'cup'} "$ccuname" $lt{'id'} "$ccdomain"</h2>
+<h2>
 ENDCHANGEUSER
-        $r->print('<div class="LC_left_float">');
+        if ($env{'form.action'} eq 'singlestudent') {
+            $r->print($lt{'ens'});
+        } else {
+            $r->print($lt{'cup'});
+        }
+        $r->print(' "'.$ccuname.'" '.$lt{'id'}.' "'.$ccdomain.'"</h2>'.
+                  "\n".'<div class="LC_left_float">');
         my ($personal_table,$showforceid) = 
             &personal_data_display($ccuname,$ccdomain,$newuser,$context,
                                    $inst_results{$ccuname.':'.$ccdomain});
@@ -852,12 +880,21 @@
             if ($user_quota_text ne '') {
                 $r->print($user_quota_text);
             }
-            $r->print('</div>');
-
+            if ($env{'form.action'} eq 'singlestudent') {
+                $r->print(&date_sections_select($context,$newuser,$formname));
+            }
         } elsif ($user_quota_text ne '') {
-            $r->print('<div class="LC_left_float">'.$user_quota_text.'</div>');
+            $r->print('<div class="LC_left_float">'.$user_quota_text);
+            if ($env{'form.action'} eq 'singlestudent') {
+                $r->print(&date_sections_select($context,$newuser,$formname));
+            }
+        } else {
+            if ($env{'form.action'} eq 'singlestudent') {
+                $r->print('<div class="LC_left_float">'.
+                          &date_sections_select($context,$newuser,$formname));
+            }
         }
-        $r->print('<div class="LC_clear_float_footer"></div>');
+        $r->print('</div><div class="LC_clear_float_footer"></div>');
         my %rolesdump=&Apache::lonnet::dump('roles',$ccdomain,$ccuname);
         # Build up table of user roles to allow revocation of a role.
         my ($tmp) = keys(%rolesdump);
@@ -1186,6 +1223,35 @@
     $r->print("</form>".&Apache::loncommon::end_page());
 }
 
+sub singleuser_breadcrumb {
+    my %breadcrumb_text;
+    if ($env{'form.action'} eq 'singlestudent') {
+        $breadcrumb_text{'search'} = 'Enroll a student';
+        $breadcrumb_text{'userpicked'} = 'Select a user',
+        $breadcrumb_text{'modify'} = 'Set section/dates',
+    } else {
+        $breadcrumb_text{'search'} = 'Create/modify user';
+        $breadcrumb_text{'userpicked'} = 'Select a user',
+        $breadcrumb_text{'modify'} = 'Set user role',
+    }
+    return %breadcrumb_text;
+}
+
+sub date_sections_select {
+    my ($context,$newuser,$formname,$permission) = @_;
+    my $cid = $env{'request.course.id'};
+    my ($cnum,$cdom) = &Apache::lonuserutils::get_course_identity($cid);
+    my $date_table = '<h3>'.&mt('Starting and Ending Dates').'</h3>'."\n".
+        &Apache::lonuserutils::date_setting_table(undef,undef,$context,
+                                                  undef,$formname,$permission);
+    my $rowtitle = 'Section';
+    my $secbox = '<h3>'.&mt('Section').'</h3>'."\n".
+        &Apache::lonuserutils::section_picker($cdom,$cnum,'st',$rowtitle,
+                                              $permission);
+    my $output = $date_table.$secbox;
+    return $output;
+}
+
 sub user_authentication {
     my ($ccuname,$ccdomain,$krbdefdom,$abv_auth) = @_;
     my $currentauth=&Apache::lonnet::queryauthenticate($ccuname,$ccdomain);
@@ -1459,20 +1525,20 @@
     } else {
         $title='Modify User Privileges';
     }
-
+    my $newuser = 0;
     my ($jsback,$elements) = &crumb_utilities();
     my $jscript = '<script type="text/javascript">'."\n".
                   $jsback."\n".'</script>'."\n";
-
+    my %breadcrumb_text = &singleuser_breadcrumb();
     $r->print(&Apache::loncommon::start_page($title,$jscript));
     &Apache::lonhtmlcommon::add_breadcrumb
        ({href=>"javascript:backPage(document.userupdate)",
-         text=>"Create/modify user",
+         text=>$breadcrumb_text{'search'},
          faq=>282,bug=>'Instructor Interface',});
     if ($env{'form.prevphase'} eq 'userpicked') {
         &Apache::lonhtmlcommon::add_breadcrumb
            ({href=>"javascript:backPage(document.userupdate,'get_user_info','select')",
-             text=>"Select a user",
+             text=>$breadcrumb_text{'userpicked'},
              faq=>282,bug=>'Instructor Interface',});
     }
     &Apache::lonhtmlcommon::add_breadcrumb
@@ -1632,6 +1698,10 @@
 	}
     }
     ##
+    my (@userroles,%userupdate,$cnum,$cdom,$namechanged);
+    if ($context eq 'course') {
+        ($cnum,$cdom) = &Apache::lonuserutils::get_course_identity();
+    }
     if (! $env{'form.makeuser'} ) {
         # Check for need to change
         my %userenv = &Apache::lonnet::get
@@ -1647,10 +1717,9 @@
         my %domconfig =
             &Apache::lonnet::get_dom('configuration',['usermodification'],
                                      $env{'form.ccdomain'});
-        my @roletypes = ('active','future');
-        my %roles = &Apache::lonnet::get_my_roles($env{'form.ccuname'},$env{'form.ccdomain'},'userroles',\@roletypes,undef,$env{'request.role.domain'});
-        my @userroles;
-        my ($cnum,$cdom,$auname,$audom);
+        my @statuses = ('active','future');
+        my %roles = &Apache::lonnet::get_my_roles($env{'form.ccuname'},$env{'form.ccdomain'},'userroles',\@statuses,undef,$env{'request.role.domain'});
+        my ($auname,$audom);
         if ($context eq 'course') {
             $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
             $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
@@ -1783,7 +1852,7 @@
                 }
             }
         }
-        my ($quotachanged,$namechanged,$oldportfolioquota,$newportfolioquota,
+        my ($quotachanged,$oldportfolioquota,$newportfolioquota,
             $inststatus,$oldisdefault,$newisdefault,$olddefquotatext,
             $newdefquotatext);
         my ($defquota,$settingstatus) = 
@@ -1918,7 +1987,7 @@
                          ($env{'form.ccuname'} => $env{'form.cid'}));
                     if (($recurseid) &&
                         (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'}))) {
-                        my %userupdate = (
+                        %userupdate = (
                                   lastname   => $env{'form.clasaname'},
                                   middlename => $env{'form.cmiddlename'},
                                   firstname  => $env{'form.cfirstname'},
@@ -2655,7 +2724,8 @@
             &Apache::lonuserutils::print_first_users_upload_form($r,$context);
         }
         $r->print('</form>'.&Apache::loncommon::end_page());
-    } elsif ($env{'form.action'} eq 'singleuser' && $permission->{'cusr'}) {
+    } elsif ((($env{'form.action'} eq 'singleuser') || ($env{'form.action'}
+             eq 'singlestudent')) && ($permission->{'cusr'})) {
         my $phase = $env{'form.phase'};
         my @search = ('srchterm','srchby','srchin','srchtype','srchdomain');
 	&Apache::loncreateuser::restore_prev_selections();
@@ -2768,6 +2838,26 @@
                          $formname,$totcodes,$codetitles,$idlist,$idlist_titles);
             $r->print(&Apache::loncommon::end_page());
         }
+    } elsif ($env{'form.action'} eq 'drop' && $permission->{'cusr'}) {
+        $r->print(&header());
+        &Apache::lonhtmlcommon::add_breadcrumb
+            ({href=>'/adm/createuser?action=drop',
+              text=>"Drop Students"});
+        if (!exists($env{'form.state'})) {
+            $r->print(&Apache::lonhtmlcommon::breadcrumbs('Drop Students',
+                                                          'Course_Drop_Student'));
+
+            &Apache::lonuserutils::print_drop_menu($r,$context,$permission);
+        } elsif ($env{'form.state'} eq 'done') {
+            &Apache::lonhtmlcommon::add_breadcrumb
+            ({href=>'/adm/createuser?action=drop',
+              text=>"Result"});
+            $r->print(&Apache::lonhtmlcommon::breadcrumbs('Drop Students',
+                                                          'Course_Drop_Student'));
+            &Apache::lonuserutils::update_user_list($r,$context,undef,
+                                                    $env{'form.action'});
+        }
+        $r->print(&Apache::loncommon::end_page());
     } elsif ($env{'form.action'} eq 'dateselect') {
         if ($permission->{'cusr'}) {
             $r->print(&header(undef,undef,{'no_nav_bar' => 1}).
@@ -2866,21 +2956,33 @@
         push(@menu,$customlink);
     }
     if ($context eq 'course') {
-        my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
-        my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'}; 
-        my @courselinks = 
+        my ($cnum,$cdom) = &Apache::lonuserutils::get_course_identity();
+        my @courselinks =
             (
-               { text => 'Automated Enrollment Manager',
+              { text => 'Enroll a Single Student',
+                 help => 'Course_Single_Student',
+                 action => 'singlestudent',
+                 permission => $permission->{'cusr'},
+                 },
+              { text => 'Drop Students',
+                help => 'Course_Drop_Student',
+                action => 'drop',
+                permission => $permission->{'cusr'},
+              });
+        if (!exists($permission->{'cusr_section'})) {
+            push(@courselinks,
+               { text => 'Automated Student Enrollment Manager',
                  permission => (&Apache::lonnet::auto_run($cnum,$cdom)
                                 && $permission->{'cusr'}),
                  url  => '/adm/populate',
-                 },
+                 });
+        }
+        push(@courselinks,
                { text => 'Manage Course Groups',
                  help => 'Course_Manage_Group',
                  permission => $permission->{'grp_manage'},
                  url => '/adm/coursegroups?refpage=cusr',
-               },
-            );
+               });
         push(@menu,@courselinks);
     }
     my $menu_html = '';
@@ -3378,7 +3480,8 @@
 		    &Apache::loncommon::get_sections($domain,$cnum);
             }
         }
-	foreach my $role ('st','ta','ep','in','cc') {
+        my @roles = &Apache::lonuserutils::roles_by_context('course');
+	foreach my $role (@roles) {
 	    if (&Apache::lonnet::allowed('c'.$role,$thiscourse)) {
 		my $plrole=&Apache::lonnet::plaintext($role);
 		$table .= &Apache::loncommon::start_data_table_row().
@@ -3478,6 +3581,7 @@
 sub course_level_dc {
     my ($dcdom) = @_;
     my %customroles=&Apache::lonuserutils::my_custom_roles();
+    my @roles = &Apache::lonuserutils::roles_by_context('course');
     my $hiddenitems = '<input type="hidden" name="dcdomain" value="'.$dcdom.'" />'.
                       '<input type="hidden" name="origdom" value="'.$dcdom.'" />'.
                       '<input type="hidden" name="dccourse" value="" />';
@@ -3502,7 +3606,7 @@
     my $otheritems = &Apache::loncommon::start_data_table_row()."\n".
                      '<td><input type="text" name="coursedesc" value="" onFocus="this.blur();opencrsbrowser('."'cu','dccourse','dcdomain','coursedesc',''".')" /></td>'."\n".
                      '<td><select name="role">'."\n";
-    foreach  my $role ('st','ta','ep','in','cc') {
+    foreach my $role (@roles) {
         my $plrole=&Apache::lonnet::plaintext($role);
         $otheritems .= '  <option value="'.$role.'">'.$plrole;
     }

--raeburn1198240886--