--- loncom/interface/loncreateuser.pm	2013/12/17 06:41:44	1.383
+++ loncom/interface/loncreateuser.pm	2014/03/26 18:18:24	1.397
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Create a user
 #
-# $Id: loncreateuser.pm,v 1.383 2013/12/17 06:41:44 raeburn Exp $
+# $Id: loncreateuser.pm,v 1.397 2014/03/26 18:18:24 bisitz Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -126,9 +126,7 @@ sub user_quotas {
     my ($ccuname,$ccdomain) = @_;
     my %lt = &Apache::lonlocal::texthash(
                    'usrt'      => "User Tools",
-                   'cuqu'      => "Current quota",
                    'cust'      => "Custom quota",
-                   'defa'      => "Default",
                    'chqu'      => "Change quota",
     );
    
@@ -168,7 +166,7 @@ END_SCRIPT
 
     my %titles = &Apache::lonlocal::texthash (
                     portfolio => "Disk space allocated to user's portfolio files",
-                    author    => "Disk space allocated to user's authoring space (if role assigned)",
+                    author    => "Disk space allocated to user's Authoring Space (if role assigned)",
                  );
     foreach my $name ('portfolio','author') {
         my ($currquota,$quotatype,$inststatus,$defquota) =
@@ -211,8 +209,8 @@ END_SCRIPT
                        '    <td>'.$titles{$name}.'</td>'."\n".
                        '  </tr>'."\n".
                        &Apache::loncommon::start_data_table_row()."\n".
-                       '  <td>'.$lt{'cuqu'}.': '.
-                       $currquota.'&nbsp;MB.&nbsp;&nbsp;'.
+                       '  <td><span class="LC_nobreak">'.
+                       &mt('Current quota: [_1] MB',$currquota).'</span>&nbsp;&nbsp;'.
                        $defaultinfo.'</td>'."\n".
                        &Apache::loncommon::end_data_table_row()."\n".
                        &Apache::loncommon::start_data_table_row()."\n".
@@ -220,13 +218,14 @@ END_SCRIPT
                        ': <label>'.
                        '<input type="radio" name="custom_'.$name.'quota" id="custom_'.$name.'quota_off" '.
                        'value="0" '.$custom_off.' onchange="javascript:quota_changes('."'custom','$name'".');"'.
-                       ' />'.$lt{'defa'}.'&nbsp;('.$defquota.' MB).</label>&nbsp;'.
+                       ' /><span class="LC_nobreak">'.
+                       &mt('Default ([_1] MB)',$defquota).'</span></label>&nbsp;'.
                        '&nbsp;<label><input type="radio" name="custom_'.$name.'quota" id="custom_'.$name.'quota_on" '.
                        'value="1" '.$custom_on.'  onchange="javascript:quota_changes('."'custom','$name'".');"'.
                        ' />'.$lt{'cust'}.':</label>&nbsp;'.
                        '<input type="text" name="'.$name.'quota" id="'.$name.'quota" size ="5" '.
                        'value="'.$showquota.'" onfocus="javascript:quota_changes('."'quota','$name'".');"'.
-                       ' />&nbsp;MB</span></td>'."\n".
+                       ' />&nbsp;'.&mt('MB').'</span></td>'."\n".
                        &Apache::loncommon::end_data_table_row()."\n";
         }
     }
@@ -241,7 +240,7 @@ sub build_tools_display {
     my %lt = &Apache::lonlocal::texthash (
                    'blog'       => "Personal User Blog",
                    'aboutme'    => "Personal Information Page",
-                   'webdav'     => "WebDAV access to authoring spaces (if SSL and author/co-author)",
+                   'webdav'     => "WebDAV access to Authoring Spaces (if SSL and author/co-author)",
                    'portfolio'  => "Personal User Portfolio",
                    'avai'       => "Available",
                    'cusa'       => "availability",
@@ -251,13 +250,14 @@ sub build_tools_display {
                    'official'   => 'Can request creation of official courses',
                    'unofficial' => 'Can request creation of unofficial courses',
                    'community'  => 'Can request creation of communities',
+                   'textbook'   => 'Can request creation of textbook courses',
                    'requestauthor'  => 'Can request author space',
     );
     if ($context eq 'requestcourses') {
         %userenv = &Apache::lonnet::userenvironment($ccdomain,$ccuname,
                       'requestcourses.official','requestcourses.unofficial',
-                      'requestcourses.community');
-        @usertools = ('official','unofficial','community');
+                      'requestcourses.community','requestcourses.textbook');
+        @usertools = ('official','unofficial','community','textbook');
         @options =('norequest','approval','autolimit','validate');
         %validations = &Apache::lonnet::auto_courserequest_checks($ccdomain);
         %reqtitles = &courserequest_titles();
@@ -446,12 +446,13 @@ sub coursereq_externaluser {
                    'official'   => 'Can request creation of official courses',
                    'unofficial' => 'Can request creation of unofficial courses',
                    'community'  => 'Can request creation of communities',
+                   'textbook'   => 'Can request creation of textbook courses',
     );
 
     %userenv = &Apache::lonnet::userenvironment($ccdomain,$ccuname,
                       'reqcrsotherdom.official','reqcrsotherdom.unofficial',
-                      'reqcrsotherdom.community');
-    @usertools = ('official','unofficial','community');
+                      'reqcrsotherdom.community','reqcrsotherdom.textbook');
+    @usertools = ('official','unofficial','community','textbook');
     @options = ('approval','validate','autolimit');
     %validations = &Apache::lonnet::auto_courserequest_checks($cdom);
     my $optregex = join('|',@options);
@@ -531,6 +532,7 @@ sub courserequest_titles {
                                    official   => 'Official',
                                    unofficial => 'Unofficial',
                                    community  => 'Communities',
+                                   textbook   => 'Textbook',
                                    norequest  => 'Not allowed',
                                    approval   => 'Approval by Dom. Coord.',
                                    validate   => 'With validation',
@@ -1227,6 +1229,7 @@ ENDFORMINFO
             }
         }
     }
+    my $title = '';
     if ($newuser) {
         my ($portfolioform,$domroleform);
         if ((&Apache::lonnet::allowed('mpq',$env{'request.role.domain'})) ||
@@ -1240,10 +1243,6 @@ ENDFORMINFO
         }
         &initialize_authen_forms($ccdomain,$formname);
         my %lt=&Apache::lonlocal::texthash(
-                'cnu'            => 'Create New User',
-                'ast'            => 'as a student',
-                'ame'            => 'as a member',
-                'ind'            => 'in domain',
                 'lg'             => 'Login Data',
                 'hs'             => "Home Server",
         );
@@ -1257,20 +1256,24 @@ $loginscript
 // ]]>
 </script>
 <input type='hidden' name='makeuser' value='1' />
-<h2>$lt{'cnu'} "$ccuname" $lt{'ind'} $ccdomain
 ENDTITLE
         if ($env{'form.action'} eq 'singlestudent') {
             if ($crstype eq 'Community') {
-                $r->print(' ('.$lt{'ame'}.')');
+                $title = &mt('Create New User [_1] in domain [_2] as a member',
+                                 '"'.$ccuname.'"','"'.$ccdomain.'"');
             } else {
-                $r->print(' ('.$lt{'ast'}.')');
+                $title = &mt('Create New User [_1] in domain [_2] as a student',
+                                 '"'.$ccuname.'"','"'.$ccdomain.'"');
             }
+        } else {
+                $title = &mt('Create New User [_1] in domain [_2]',
+                                 '"'.$ccuname.'"','"'.$ccdomain.'"');
         }
-        $r->print('</h2>'."\n".'<div class="LC_left_float">');
-        my $personal_table = 
-            &personal_data_display($ccuname,$ccdomain,$newuser,$context,
-                                   $inst_results{$ccuname.':'.$ccdomain});
-        $r->print($personal_table);
+        $r->print('<h2>'.$title.'</h2>'."\n");
+        $r->print('<div class="LC_left_float">');
+        $r->print(&personal_data_display($ccuname,$ccdomain,$newuser,$context,
+                                         $inst_results{$ccuname.':'.$ccdomain}));
+        # Option to disable student/employee ID conflict checking not offerred for new users.
         my ($home_server_pick,$numlib) = 
             &Apache::loncommon::home_server_form_item($ccdomain,'hserver',
                                                       'default','hide');
@@ -1356,35 +1359,23 @@ ENDAUTH
         }
         $r->print('</div><div class="LC_clear_float_footer"></div>');
     } else { # user already exists
-	my %lt=&Apache::lonlocal::texthash(
-                    'cup'  => "Modify existing user: ",
-                    'ens'  => "Enroll one student: ",
-                    'enm'  => "Enroll one member: ",
-                    'id'   => "in domain",
-				       );
-	$r->print(<<ENDCHANGEUSER);
-$start_page
-$forminfo
-<h2>
-ENDCHANGEUSER
+	$r->print($start_page.$forminfo);
         if ($env{'form.action'} eq 'singlestudent') {
             if ($crstype eq 'Community') {
-                $r->print($lt{'enm'});
+                $title = &mt('Enroll one member: [_1] in domain [_2]',
+                                 '"'.$ccuname.'"','"'.$ccdomain.'"');
             } else {
-                $r->print($lt{'ens'});
+                $title = &mt('Enroll one student: [_1] in domain [_2]',
+                                 '"'.$ccuname.'"','"'.$ccdomain.'"');
             }
         } 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});
-        $r->print($personal_table);
-        if ($showforceid) {
-            $r->print('<table>'.&Apache::lonuserutils::forceid_change($context).'</table>');
+            $title = &mt('Modify existing user: [_1] in domain [_2]',
+                             '"'.$ccuname.'"','"'.$ccdomain.'"');
         }
+        $r->print('<h2>'.$title.'</h2>'."\n");
+        $r->print('<div class="LC_left_float">');
+        $r->print(&personal_data_display($ccuname,$ccdomain,$newuser,$context,
+                                         $inst_results{$ccuname.':'.$ccdomain}));
         if (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) {
             $r->print('<br /><h3>'.&mt('User Can Request Creation of Courses/Communities in this Domain?').'</h3>'.
                       &Apache::loncommon::start_data_table());
@@ -1415,8 +1406,8 @@ ENDCHANGEUSER
         if (!&Apache::lonnet::allowed('mpq',$ccdomain)) {
             if (&Apache::lonnet::allowed('mpq',$env{'request.role.domain'})) {
                 my %lt=&Apache::lonlocal::texthash(
-                    'dska'  => "Disk quotas for user's portfolio and authoring space",
-                    'youd'  => "You do not have privileges to modify the portfolio and/or authoring space quotas for this user.",
+                    'dska'  => "Disk quotas for user's portfolio and Authoring Space",
+                    'youd'  => "You do not have privileges to modify the portfolio and/or Authoring Space quotas for this user.",
                     'ichr'  => "If a change is required, contact a domain coordinator for the domain",
                 );
                 $user_text{'quota'} = <<ENDNOPORTPRIV;
@@ -1480,7 +1471,8 @@ ENDNOTOOLSPRIV
         }
         $r->print('<br /><input type="button" value="'.$btntxt.'" onclick="setSections(this.form)" />'."\n");
     } else {
-        $r->print('<fieldset><legend>'.&mt('Add Roles').'</legend>');
+        $r->print('<div class="LC_left_float">'.
+                  '<fieldset><legend>'.&mt('Add Roles').'</legend>');
         my $addrolesdisplay = 0;
         if ($context eq 'domain' || $context eq 'author') {
             $addrolesdisplay = &new_coauthor_roles($r,$ccuname,$ccdomain);
@@ -1491,27 +1483,32 @@ ENDNOTOOLSPRIV
                 $addrolesdisplay = $add_domainroles;
             }
             $r->print(&course_level_dc($env{'request.role.domain'},$showcredits));
-            $r->print('</fieldset><br /><input type="button" value="'.&mt('Save').'" onclick="setCourse()" />'."\n");
+            $r->print('</fieldset></div><div class="LC_clear_float_footer"></div>'.
+                      '<br /><input type="button" value="'.&mt('Save').'" onclick="setCourse()" />'."\n");
         } elsif ($context eq 'author') {
             if ($addrolesdisplay) {
-                $r->print('</fieldset><br /><input type="button" value="'.&mt('Save').'"');
+                $r->print('</fieldset></div><div class="LC_clear_float_footer"></div>'.
+                          '<br /><input type="button" value="'.&mt('Save').'"');
                 if ($newuser) {
                     $r->print(' onclick="auth_check()" \>'."\n");
                 } else {
                     $r->print('onclick="this.form.submit()" \>'."\n");
                 }
             } else {
-                $r->print('</fieldset><br /><a href="javascript:backPage(document.cu)">'.
+                $r->print('</fieldset></div>'.
+                          '<div class="LC_clear_float_footer"></div>'.
+                          '<br /><a href="javascript:backPage(document.cu)">'.
                           &mt('Back to previous page').'</a>');
             }
         } else {
             $r->print(&course_level_table(\%inccourses,$showcredits,$defaultcredits));
-            $r->print('</fieldset><br /><input type="button" value="'.&mt('Save').'" onclick="setSections(this.form)" />'."\n");
+            $r->print('</fieldset></div><div class="LC_clear_float_footer"></div>'.
+                      '<br /><input type="button" value="'.&mt('Save').'" 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="" />');
-    $r->print('<input type="hidden" name="prevphase" value="'.$env{'form.phase'}.'" /></form>');
+    $r->print('<input type="hidden" name="prevphase" value="'.$env{'form.phase'}.'" /></form><br /><br />');
     return;
 }
 
@@ -1816,7 +1813,7 @@ sub display_existing_roles {
             }
         } else {
             $plaintext=
-                &mt('Customrole [_1][_2]defined by [_3]',
+                &mt('Custom role [_1][_2]defined by [_3]',
                         '"'.$croletitle.'"',
                         '<br />',
                         $croleuname.':'.$croleudom);
@@ -1866,7 +1863,7 @@ sub display_existing_roles {
         } else {
             $contextrole = &mt('Existing Roles in this Domain');
         }
-        $r->print('<div>'.
+        $r->print('<div class="LC_left_float">'.
 '<fieldset><legend>'.$contextrole.'</legend>'.
 &Apache::loncommon::start_data_table("LC_createuser").
 &Apache::loncommon::start_data_table_header_row().
@@ -2166,13 +2163,37 @@ sub modify_login_block {
 }
 
 sub personal_data_display {
-    my ($ccuname,$ccdomain,$newuser,$context,$inst_results,$rolesarray) = @_;
-    my ($output,$showforceid,%userenv,%canmodify,%canmodify_status);
+    my ($ccuname,$ccdomain,$newuser,$context,$inst_results,$rolesarray,
+        $now,$captchaform,$emailusername,$usertype) = @_;
+    my ($output,%userenv,%canmodify,%canmodify_status);
     my @userinfo = ('firstname','middlename','lastname','generation',
                     'permanentemail','id');
     my $rowcount = 0;
     my $editable = 0;
-    %canmodify_status = 
+    my %textboxsize = (
+                       firstname      => '15',
+                       middlename     => '15',
+                       lastname       => '15',
+                       generation     => '5',
+                       permanentemail => '25',
+                       id             => '15',
+                      );
+
+    my %lt=&Apache::lonlocal::texthash(
+                'pd'             => "Personal Data",
+                'firstname'      => "First Name",
+                'middlename'     => "Middle Name",
+                'lastname'       => "Last Name",
+                'generation'     => "Generation",
+                'permanentemail' => "Permanent e-mail address",
+                'id'             => "Student/Employee ID",
+                'lg'             => "Login Data",
+                'inststatus'     => "Affiliation",
+                'email'          => 'E-mail address',
+                'valid'          => 'Validation',
+    );
+
+    %canmodify_status =
         &Apache::lonuserutils::can_modify_userinfo($context,$ccdomain,
                                                    ['inststatus'],$rolesarray);
     if (!$newuser) {
@@ -2184,31 +2205,58 @@ sub personal_data_display {
             &Apache::lonuserutils::can_modify_userinfo($context,$ccdomain,
                                                        \@userinfo,$rolesarray);
     } elsif ($context eq 'selfcreate') {
-        %canmodify = &selfcreate_canmodify($context,$ccdomain,\@userinfo,
-                                           $inst_results,$rolesarray);
+        if ($newuser eq 'email') {
+            if (ref($emailusername) eq 'HASH') {
+                if (ref($emailusername->{$usertype}) eq 'HASH') {
+                    my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
+                    @userinfo = ();          
+                    if ((ref($infofields) eq 'ARRAY') && (ref($infotitles) eq 'HASH')) {
+                        foreach my $field (@{$infofields}) { 
+                            if ($emailusername->{$usertype}->{$field}) {
+                                push(@userinfo,$field);
+                                $canmodify{$field} = 1;
+                                unless ($textboxsize{$field}) {
+                                    $textboxsize{$field} = 25;
+                                }
+                                unless ($lt{$field}) {
+                                    $lt{$field} = $infotitles->{$field};
+                                }
+                                if ($emailusername->{$usertype}->{$field} eq 'required') {
+                                    $lt{$field} .= '<b>*</b>';
+                                }
+                            }
+                        }
+                    }
+                }
+            }
+        } else {
+            %canmodify = &selfcreate_canmodify($context,$ccdomain,\@userinfo,
+                                               $inst_results,$rolesarray);
+        }
     }
-    my %lt=&Apache::lonlocal::texthash(
-                'pd'             => "Personal Data",
-                'firstname'      => "First Name",
-                'middlename'     => "Middle Name",
-                'lastname'       => "Last Name",
-                'generation'     => "Generation",
-                'permanentemail' => "Permanent e-mail address",
-                'id'             => "Student/Employee ID",
-                'lg'             => "Login Data",
-                'inststatus'     => "Affiliation",
-    );
-    my %textboxsize = (
-                       firstname      => '15',
-                       middlename     => '15',
-                       lastname       => '15',
-                       generation     => '5',
-                       permanentemail => '25',
-                       id             => '15',
-                      );
+
     my $genhelp=&Apache::loncommon::help_open_topic('Generation');
     $output = '<h3>'.$lt{'pd'}.'</h3>'.
               &Apache::lonhtmlcommon::start_pick_box();
+    if (($context eq 'selfcreate') && ($newuser eq 'email')) {
+        $output .= &Apache::lonhtmlcommon::row_title($lt{'email'}.'<b>*</b>',undef,
+                                                     'LC_oddrow_value')."\n".
+                   '<input type="text" name="uname" size="25" value="" autocomplete="off" />';
+        $rowcount ++;
+        $output .= &Apache::lonhtmlcommon::row_closure(1);
+        my $upassone = '<input type="password" name="upass'.$now.'" size="10" autocomplete="off" />';
+        my $upasstwo = '<input type="password" name="upasscheck'.$now.'" size="10" autocomplete="off" />';
+        $output .= &Apache::lonhtmlcommon::row_title(&mt('Password').'<b>*</b>',
+                                                    'LC_pick_box_title',
+                                                    'LC_oddrow_value')."\n".
+                   $upassone."\n".
+                   &Apache::lonhtmlcommon::row_closure(1)."\n".
+                   &Apache::lonhtmlcommon::row_title(&mt('Confirm password').'<b>*</b>',
+                                                     'LC_pick_box_title',
+                                                     'LC_oddrow_value')."\n".
+                   $upasstwo.
+                   &Apache::lonhtmlcommon::row_closure()."\n";
+    }
     foreach my $item (@userinfo) {
         my $rowtitle = $lt{$item};
         my $hiderow = 0;
@@ -2222,8 +2270,8 @@ sub personal_data_display {
                     $row .= '<input type="hidden" name="c'.$item.'" value="'.$inst_results->{$item}.'" />'.$inst_results->{$item};
                 } else {
                     if ($context eq 'selfcreate') {
-                        if ($canmodify{$item}) { 
-                            $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" />';
+                        if ($canmodify{$item}) {
+                            $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" autocomplete="off" />';
                             $editable ++;
                         } else {
                             $hiderow = 1;
@@ -2238,7 +2286,11 @@ sub personal_data_display {
                         $row .= $ccuname;
                     } else {
                         if ($canmodify{$item}) {
-                            $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" />';
+                            if ($newuser eq 'email') {
+                                $row .= '<input type="text" name="'.$item.'" size="'.$textboxsize{$item}.'" value="" autocomplete="off" />';
+                            } else {
+                                $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" autocomplete="off" />';
+                            }
                             $editable ++;
                         } else {
                             $hiderow = 1;
@@ -2251,12 +2303,12 @@ sub personal_data_display {
         } else {
             if ($canmodify{$item}) {
                 $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="'.$userenv{$item}.'" />';
+                if (($item eq 'id') && (!$newuser)) {
+                    $row .= '<br />'.&Apache::lonuserutils::forceid_change($context);
+                }
             } else {
                 $row .= $userenv{$item};
             }
-            if ($item eq 'id') {
-                $showforceid = $canmodify{$item};
-            }
         }
         $row .= &Apache::lonhtmlcommon::row_closure(1);
         if (!$hiderow) {
@@ -2291,7 +2343,7 @@ sub personal_data_display {
                     }
                 }
                 if (!$hiderow) {
-                    my $row = &Apache::lonhtmlcommon::row_title(&mt('Affliations'),undef,'LC_oddrow_value')."\n".
+                    my $row = &Apache::lonhtmlcommon::row_title(&mt('Affiliations'),undef,'LC_oddrow_value')."\n".
                               $shown.&Apache::lonhtmlcommon::row_closure(1); 
                     if ($context eq 'selfcreate') {
                         $rowcount ++;
@@ -2301,12 +2353,27 @@ sub personal_data_display {
             }
         }
     }
+    if (($context eq 'selfcreate') && ($newuser eq 'email')) {
+        if ($captchaform) {
+            $output .= &Apache::lonhtmlcommon::row_title($lt{'valid'},
+                                                         'LC_pick_box_title')."\n".
+                       $captchaform."\n".'<br /><br />'.
+                       &Apache::lonhtmlcommon::row_closure(1); 
+            $rowcount ++;
+        }
+        my $submit_text = &mt('Create account');
+        $output .= &Apache::lonhtmlcommon::row_title()."\n".
+                   '<br /><input type="submit" name="createaccount" value="'.
+                   $submit_text.'" />'.
+                   '<input type="hidden" name="type" value="'.$usertype.'" />'.
+                   &Apache::lonhtmlcommon::row_closure(1);
+    }
     $output .= &Apache::lonhtmlcommon::end_pick_box();
     if (wantarray) {
         if ($context eq 'selfcreate') {
             return($output,$rowcount,$editable);
         } else {
-            return ($output,$showforceid);
+            return $output;
         }
     } else {
         return $output;
@@ -2471,9 +2538,12 @@ sub update_user_data {
     if (! exists($env{'form.makeuser'})) {
         # Modifying an existing user, so check the validity of the name
         if ($uhome eq 'no_host') {
-            $r->print($error.&mt('Unable to determine home server for ').
-                      $env{'form.ccuname'}.&mt(' in domain ').
-                      $env{'form.ccdomain'}.'.');
+            $r->print(
+                $error
+               .'<p class="LC_error">'
+               .&mt('Unable to determine home server for [_1] in domain [_2].',
+                        '"'.$env{'form.ccuname'}.'"','"'.$env{'form.ccdomain'}.'"')
+               .'</p>');
             return;
         }
     }
@@ -2513,7 +2583,7 @@ sub update_user_data {
     my (%alerts,%rulematch,%inst_results,%curr_rules);
     my @userinfo = ('firstname','middlename','lastname','generation','permanentemail','id');
     my @usertools = ('aboutme','blog','webdav','portfolio');
-    my @requestcourses = ('official','unofficial','community');
+    my @requestcourses = ('official','unofficial','community','textbook');
     my @requestauthor = ('requestauthor');
     my ($othertitle,$usertypes,$types) = 
         &Apache::loncommon::sorted_inst_types($env{'form.ccdomain'});
@@ -2651,7 +2721,7 @@ sub update_user_data {
 	    $r->print($error.'Invalid login mode or password'.$end.$rtnlink);    
 	    return;
 	}
-	# Only allow authentification modification if the person has authority
+	# Only allow authentication modification if the person has authority
 	if (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'})) {
 	    $r->print('Modifying authentication: '.
                       &Apache::lonnet::modifyuserauth(
@@ -2661,7 +2731,7 @@ sub update_user_data {
 		  ($env{'form.ccuname'},$env{'form.ccdomain'}));
 	} else {
 	    # Okay, this is a non-fatal error.
-	    $r->print($error.&mt('You do not have the authority to modify this users authentification information').'.'.$end);    
+	    $r->print($error.&mt('You do not have the authority to modify this users authentication information.').$end);    
 	}
     }
     $r->rflush(); # Finish display of header before time consuming actions start
@@ -2683,8 +2753,9 @@ sub update_user_data {
              'id','permanentemail','portfolioquota','authorquota','inststatus',
              'tools.aboutme','tools.blog','tools.webdav','tools.portfolio',
              'requestcourses.official','requestcourses.unofficial',
-             'requestcourses.community','reqcrsotherdom.official',
-             'reqcrsotherdom.unofficial','reqcrsotherdom.community',
+             'requestcourses.community','requestcourses.textbook',
+             'reqcrsotherdom.official','reqcrsotherdom.unofficial',
+             'reqcrsotherdom.community','reqcrsotherdom.textbook',
              'requestauthor'],
               $env{'form.ccdomain'},$env{'form.ccuname'});
         my ($tmp) = keys(%userenv);
@@ -2949,7 +3020,8 @@ sub update_user_data {
             if ($env{'form.ccdomain'} eq $env{'request.role.domain'}) {
                 &tool_changes('requestcourses',\@requestcourses,\%oldsettings,\%oldsettingstext,
                               \%userenv,\%changeHash,\%changed,\%newsettings,\%newsettingstext);
-                &tool_changes('requestauthor',\@requestauthor,\%oldsettings,\%oldsettingstext,\%userenv,\%changeHash,\%changed,\%newsettings,\%newsettingstext);
+                &tool_changes('requestauthor',\@requestauthor,\%oldsettings,\%oldsettingstext,
+                              \%userenv,\%changeHash,\%changed,\%newsettings,\%newsettingstext);
             } else {
                 &tool_changes('reqcrsotherdom',\@requestcourses,\%oldsettings,\%oldsettingstext,
                               \%userenv,\%changeHash,\%changed,\%newsettings,\%newsettingstext);
@@ -2961,8 +3033,8 @@ sub update_user_data {
             }
         }
         foreach my $name ('portfolio','author') {
-            $oldsettings{'quota'}{$name} = $oldquota{$name}.' MB';
-            $newsettings{'quota'}{$name} = $newquota{$name}.' MB';
+            $oldsettings{'quota'}{$name} = &mt('[_1] MB',$oldquota{$name});
+            $newsettings{'quota'}{$name} = &mt('[_1] MB',$newquota{$name});
         }
         if ((keys(%namechanged) > 0) || (keys(%changed) > 0)) {
             my ($chgresult,$namechgresult);
@@ -3061,9 +3133,12 @@ sub update_user_data {
                     &Apache::lonnet::appenv(\%newenvhash);
                 }
             } else { # error occurred
-                $r->print('<span class="LC_error">'.&mt('Unable to successfully change environment for').' '.
-                      $env{'form.ccuname'}.' '.&mt('in domain').' '.
-                      $env{'form.ccdomain'}.'</span><br />');
+                $r->print(
+                    '<p class="LC_error">'
+                   .&mt('Unable to successfully change environment for [_1] in domain [_2].',
+                            '"'.$env{'form.ccuname'}.'"',
+                            '"'.$env{'form.ccdomain'}.'"')
+                   .'</p>');
             }
         } else { # End of if ($env ... ) logic
             # They did not want to change the users name, quota, tool availability,
@@ -3111,13 +3186,14 @@ sub update_user_data {
     if ($env{'form.action'} eq 'singlestudent') {
         &enroll_single_student($r,$uhome,$amode,$genpwd,$now,$newuser,$context,
                                $crstype,$showcredits,$defaultcredits);
-        $r->print('<p><a href="javascript:backPage(document.userupdate)">');
-        if ($crstype eq 'Community') {
-            $r->print(&mt('Enroll Another Member'));
-        } else {
-            $r->print(&mt('Enroll Another Student'));
-        }
-        $r->print('</a></p>');
+        my $linktext = ($crstype eq 'Community' ?
+            &mt('Enroll Another Member') : &mt('Enroll Another Student'));
+        $r->print(
+            &Apache::lonhtmlcommon::actionbox([
+                '<a href="javascript:backPage(document.userupdate)">'
+               .($crstype eq 'Community' ? 
+                    &mt('Enroll Another Member') : &mt('Enroll Another Student'))
+               .'</a>']));
     } else {
         my @rolechanges = &update_roles($r,$context,$showcredits);
         if (keys(%namechanged) > 0) {
@@ -3172,7 +3248,7 @@ sub display_userinfo {
          'id'             => 'Student/Employee ID',
          'permanentemail' => 'Permanent e-mail address',
          'portfolioquota' => 'Disk space allocated to portfolio files',
-         'authorquota'    => 'Disk space allocated to authoring space',
+         'authorquota'    => 'Disk space allocated to Authoring Space',
          'blog'           => 'Blog Availability',
          'webdav'         => 'WebDAV Availability',
          'aboutme'        => 'Personal Information Page Availability',
@@ -3180,6 +3256,7 @@ sub display_userinfo {
          'official'       => 'Can Request Official Courses',
          'unofficial'     => 'Can Request Unofficial Courses',
          'community'      => 'Can Request Communities',
+         'textbook'       => 'Can Request Textbook Courses',
          'requestauthor'  => 'Can Request Author Role',
          'inststatus'     => "Affiliation",
          'prvs'           => 'Previous Value:',
@@ -3214,7 +3291,7 @@ sub display_userinfo {
                         @items = ($entry);
                     } else {
                         @items = @{$requestcourses};
-                    } 
+                    }
                     foreach my $item (@items) {
                         if (($newsetting->{$item} ne $oldsetting->{$item}) || 
                             ($newsettingtext->{$item} ne $oldsettingtext->{$item})) {
@@ -3938,11 +4015,11 @@ sub enroll_single_student {
         }
         $r->print('.<br />'.$showstart.'; '.$showend);
         if ($startdate <= $now && !$newuser) {
-            $r->print('<p> ');
+            $r->print('<p class="LC_info">');
             if ($crstype eq 'Community') {
-                $r->print(&mt('If the member is currently logged-in to LON-CAPA, the new role will be available when the member next logs in.'));
+                $r->print(&mt('If the member is currently logged-in to LON-CAPA, the new role can be displayed by using the "Check for changes" link on the Roles/Courses page.'));
             } else {
-                $r->print(&mt('If the student is currently logged-in to LON-CAPA, the new role will be available when the student next logs in.'));
+                $r->print(&mt('If the student is currently logged-in to LON-CAPA, the new role can be displayed by using the "Check for changes" link on the Roles/Courses page.'));
            }
            $r->print('</p>');
         }
@@ -4108,6 +4185,7 @@ sub custom_role_editor {
     my $dompriv='';
     my $coursepriv='';
     my $body_top;
+    my $newrole;
     my ($rdummy,$roledef)=
 			 &Apache::lonnet::get('roles',["rolesdef_$rolename"]);
 # ------------------------------------------------------- Does this role exist?
@@ -4120,6 +4198,7 @@ sub custom_role_editor {
             $syspriv =~ s/bre\&S//;   
         }
     } else {
+        $newrole = 1;
 	$body_top .= &mt('New Role').' "';
 	$roledef='';
     }
@@ -4389,6 +4468,7 @@ sub set_custom_role {
                  bread_crumbs_component => 'User Management'}; 
     $r->print(&Apache::loncommon::start_page('Save Custom Role',$jscript,$args));
 
+    my $newrole;
     my ($rdummy,$roledef)=
 	&Apache::lonnet::get('roles',["rolesdef_$rolename"]);
 
@@ -4399,6 +4479,7 @@ sub set_custom_role {
     } else {
 	$r->print(&mt('New Role').' "');
 	$roledef='';
+        $newrole = 1;
     }
     $r->print($rolename.'"</h3>');
 # ------------------------------------------------------- What can be assigned?
@@ -4429,25 +4510,43 @@ sub set_custom_role {
 	    $sysrole.=':'.$item;
 	}
     }
-    $r->print('<br />Defining Role: '.
-	   &Apache::lonnet::definerole($rolename,$sysrole,$domrole,$courole));
+    # Assign role; Compile and show result
+    my $errmsg;
+    my $result =
+        &Apache::lonnet::definerole($rolename,$sysrole,$domrole,$courole);
+    if ($result ne 'ok') {
+        $errmsg = ': '.$result;
+    }
+    my $message =
+        &Apache::lonhtmlcommon::confirm_success(
+            &mt('Defining Role').$errmsg, ($result eq 'ok' ? 0 : 1));
     if ($env{'request.course.id'}) {
         my $url='/'.$env{'request.course.id'};
         $url=~s/\_/\//g;
-	$r->print('<br />'.&mt('Assigning Role to Self').': '.
-	      &Apache::lonnet::assigncustomrole($env{'user.domain'},
-						$env{'user.name'},
-						$url,
-						$env{'user.domain'},
-						$env{'user.name'},
-						$rolename,undef,undef,undef,$context));
+        $result =
+            &Apache::lonnet::assigncustomrole(
+                $env{'user.domain'},$env{'user.name'},
+                $url,
+                $env{'user.domain'},$env{'user.name'},
+                $rolename,undef,undef,undef,$context);
+        if ($result ne 'ok') {
+            $errmsg = ': '.$result;
+        }
+        $message .=
+            '<br />'
+           .&Apache::lonhtmlcommon::confirm_success(
+                &mt('Assigning Role to Self').$errmsg, ($result eq 'ok' ? 0 : 1));
     }
     $r->print(
-        '<p><a href="javascript:backPage(document.customresult,'."'pickrole'".')">'
-       .&mt('Create or edit another custom role')
-       .'</a></p>'
+        &Apache::loncommon::confirmwrapper($message)
+       .'<br />'
+       .&Apache::lonhtmlcommon::actionbox([
+            '<a href="javascript:backPage(document.customresult,'."'pickrole'".')">'
+           .&mt('Create or edit another custom role')
+           .'</a>'])
        .'<form name="customresult" method="post" action="">'
-       .&Apache::lonhtmlcommon::echo_form_input([]).'</form>'
+       .&Apache::lonhtmlcommon::echo_form_input([])
+       .'</form>'
     );
 }
 
@@ -4471,12 +4570,12 @@ sub handler {
 
     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
         ['action','state','callingform','roletype','showrole','bulkaction','popup','phase',
-         'username','domain','srchterm','srchdomain','srchin','srchby','srchtype']);
+         'username','domain','srchterm','srchdomain','srchin','srchby','srchtype','queue']);
     &Apache::lonhtmlcommon::clear_breadcrumbs();
     my $args;
     my $brcrum = [];
     my $bread_crumbs_component = 'User Management';
-    if ($env{'form.action'} ne 'dateselect') {
+    if (($env{'form.action'} ne 'dateselect') && ($env{'form.action'} ne 'displayuserreq')) {
         $brcrum = [{href=>"/adm/createuser",
                     text=>"User Management",
                     help=>'Course_Create_Class_List,Course_Change_Privileges,Course_View_Class_List,Course_Editing_Custom_Roles,Course_Add_Student,Course_Drop_Student,Course_Automated_Enrollment,Course_Self_Enrollment,Course_Manage_Group'}
@@ -4631,7 +4730,7 @@ sub handler {
              (&Apache::lonnet::allowed('cau',$env{'request.role.domain'}))) {
         push(@{$brcrum},
                  {href => '/adm/createuser?action=processauthorreq',
-                  text => 'Authoring space requests',
+                  text => 'Authoring Space requests',
                   help => 'Domain_Role_Approvals'});
         $bread_crumbs_component = 'Authoring requests';
         if ($env{'form.state'} eq 'done') {
@@ -4643,7 +4742,8 @@ sub handler {
         }
         $args = { bread_crumbs           => $brcrum,
                   bread_crumbs_component => $bread_crumbs_component};
-        $r->print(&header(undef,$args));
+        my $js = &usernamerequest_javascript();
+        $r->print(&header(&add_script($js),$args));
         if (!exists($env{'form.state'})) {
             $r->print(&Apache::loncoursequeueadmin::display_queued_requests('requestauthor',
                                                                             $env{'request.role.domain'}));
@@ -4652,6 +4752,124 @@ sub handler {
             $r->print(&Apache::loncoursequeueadmin::update_request_queue('requestauthor',
                                                                          $env{'request.role.domain'}));
         }
+    } elsif (($env{'form.action'} eq 'processusernamereq') &&
+             ($permission->{'cusr'}) &&
+             (&Apache::lonnet::allowed('cau',$env{'request.role.domain'}))) {
+        push(@{$brcrum},
+                 {href => '/adm/createuser?action=processusernamereq',
+                  text => 'LON-CAPA account requests',
+                  help => 'Domain_Username_Approvals'});
+        $bread_crumbs_component = 'Account requests';
+        if ($env{'form.state'} eq 'done') {
+            push(@{$brcrum},
+                     {href => '/adm/createuser?action=usernamereqqueue',
+                      text => 'Result',
+                      help => 'Domain_Username_Approvals'});
+            $bread_crumbs_component = 'LON-CAPA account request result';
+        }
+        $args = { bread_crumbs           => $brcrum,
+                  bread_crumbs_component => $bread_crumbs_component};
+        my $js = &usernamerequest_javascript();
+        $r->print(&header(&add_script($js),$args));
+        if (!exists($env{'form.state'})) {
+            $r->print(&Apache::loncoursequeueadmin::display_queued_requests('requestusername',
+                                                                            $env{'request.role.domain'}));
+        } elsif ($env{'form.state'} eq 'done') {
+            $r->print('<h3>'.&mt('LON-CAPA account request processing').'</h3>'."\n");
+            $r->print(&Apache::loncoursequeueadmin::update_request_queue('requestusername',
+                                                                         $env{'request.role.domain'}));
+        }
+    } elsif (($env{'form.action'} eq 'displayuserreq') &&
+             ($permission->{'cusr'})) {
+        my $dom = $env{'form.domain'};
+        my $uname = $env{'form.username'};
+        my $warning;
+        if (($dom =~ /^$match_domain$/) && (&Apache::lonnet::domain($dom) ne '')) {
+            if (($dom eq $env{'request.role.domain'}) && (&Apache::lonnet::allowed('ccc',$dom))) {
+                if (($uname =~ /^$match_username$/) && ($env{'form.queue'} eq 'approval')) {
+                    my $uhome = &Apache::lonnet::homeserver($uname,$dom);
+                    if ($uhome eq 'no_host') {
+                        my $queue = $env{'form.queue'};
+                        my $reqkey = &escape($uname).'_'.$queue; 
+                        my $namespace = 'usernamequeue';
+                        my $domconfig = &Apache::lonnet::get_domainconfiguser($dom);
+                        my %queued =
+                            &Apache::lonnet::get($namespace,[$reqkey],$dom,$domconfig);
+                        unless ($queued{$reqkey}) {
+                            $warning = &mt('No information was found for this LON-CAPA account request.');
+                        }
+                    } else {
+                        $warning = &mt('A LON-CAPA account already exists for the requested username and domain.');
+                    }
+                } else {
+                    $warning = &mt('LON-CAPA account request status check is for an invalid username.');
+                }
+            } else {
+                $warning = &mt('You do not have rights to view LON-CAPA account requests in the domain specified.');
+            }
+        } else {
+            $warning = &mt('LON-CAPA account request status check is for an invalid domain.');
+        }
+        my $args = { only_body => 1 };
+        $r->print(&header(undef,$args).
+                  '<h3>'.&mt('LON-CAPA Account Request Details').'</h3>');
+        if ($warning ne '') {
+            $r->print('<div class="LC_warning">'.$warning.'</div>');
+        } else {
+            my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
+            my $domconfiguser = &Apache::lonnet::get_domainconfiguser($dom);
+            my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
+            if (ref($domconfig{'usercreation'}) eq 'HASH') {
+                if (ref($domconfig{'usercreation'}{'cancreate'}) eq 'HASH') {
+                    if (ref($domconfig{'usercreation'}{'cancreate'}{'emailusername'}) eq 'HASH') {
+                        my %info =
+                            &Apache::lonnet::get('nohist_requestedusernames',[$uname],$dom,$domconfiguser);
+                        if (ref($info{$uname}) eq 'HASH') {
+                            my $usertype = $info{$uname}{'inststatus'};
+                            unless ($usertype) {
+                                $usertype = 'default';
+                            }
+                            if (ref($domconfig{'usercreation'}{'cancreate'}{'emailusername'}{$usertype}) eq 'HASH') {
+                                if ((ref($infofields) eq 'ARRAY') && (ref($infotitles) eq 'HASH')) {
+                                    $r->print('<div>'.&Apache::lonhtmlcommon::start_pick_box());
+                                    my ($num,$count,$showstatus);
+                                    $count = scalar(keys(%{$domconfig{'usercreation'}{'cancreate'}{'emailusername'}{$usertype}}));
+                                    unless ($usertype eq 'default') {
+                                        my ($othertitle,$usertypes,$types) = 
+                                            &Apache::loncommon::sorted_inst_types($dom);
+                                        if (ref($usertypes) eq 'HASH') {
+                                            if ($usertypes->{$usertype}) {
+                                                $showstatus = $usertypes->{$usertype};
+                                                $count ++;
+                                            }
+                                        }
+                                    }
+                                    foreach my $field (@{$infofields}) {
+                                        next unless ($domconfig{'usercreation'}{'cancreate'}{'emailusername'}{$usertype}{$field});
+                                        next unless ($infotitles->{$field});
+                                        $r->print(&Apache::lonhtmlcommon::row_title($infotitles->{$field}).
+                                                  $info{$uname}{$field});
+                                        $num ++;
+                                        if ($count == $num) {
+                                            $r->print(&Apache::lonhtmlcommon::row_closure(1));
+                                        } else {
+                                            $r->print(&Apache::lonhtmlcommon::row_closure());
+                                        }
+                                    }
+                                    if ($showstatus) {
+                                        $r->print(&Apache::lonhtmlcommon::row_title(&mt('Status type (self-reported)')).
+                                                  $showstatus.
+                                                  &Apache::lonhtmlcommon::row_closure(1));
+                                    }
+                                    $r->print(&Apache::lonhtmlcommon::end_pick_box().'</div>');
+                                }
+                            }
+                        }
+                    }
+                }
+            }
+            $r->print(&close_popup_form());
+        }
     } elsif (($env{'form.action'} eq 'listusers') && 
              ($permission->{'view'} || $permission->{'cusr'})) {
         if ($env{'form.phase'} eq 'bulkchange') {
@@ -4851,6 +5069,32 @@ sub add_script {
           .'</script>'."\n";
 }
 
+sub usernamerequest_javascript {
+    my $js = <<ENDJS;
+
+function openusernamereqdisplay(dom,uname,queue) {
+    var url = '/adm/createuser?action=displayuserreq';
+    url += '&domain='+dom+'&username='+uname+'&queue='+queue;
+    var title = 'Account_Request_Browser';
+    var options = 'scrollbars=1,resizable=1,menubar=0';
+    options += ',width=700,height=600';
+    var stdeditbrowser = open(url,title,options,'1');
+    stdeditbrowser.focus();
+    return;
+}
+ 
+ENDJS
+}
+
+sub close_popup_form {
+    my $close= &mt('Close Window');
+    return << "END";
+<p><form name="displayreq" action="" method="post">
+<input type="button" name="closeme" value="$close" onclick="javascript:self.close();" />
+</form></p>
+END
+}
+
 sub verify_user_display {
     my ($context) = @_;
     my %lt = &Apache::lonlocal::texthash (
@@ -5104,6 +5348,14 @@ sub print_main_menu {
              linktitle => 'Approve or reject author role requests',
             },
             {
+             linktext => 'LON-CAPA Account Requests',
+             icon => 'list-add.png',
+             #help => 'Domain_Username_Approvals',
+             url => '/adm/createuser?action=processusernamereq',
+             permission => $permission->{'cusr'},
+             linktitle => 'Approve or reject LON-CAPA account requests',
+            },
+            {
              linktext => 'Change Log',
              icon => 'document-properties.png',
              #help => 'Course_User_Logs',
@@ -6965,28 +7217,29 @@ sub course_level_dc {
                  &Apache::loncommon::start_data_table().
                  &Apache::loncommon::start_data_table_header_row().
                  '<th>'.$lt{'scc'}.'</th><th>'.$lt{'rol'}.'</th>'."\n".
-                 '<th>'.$lt{'grs'}.'</th><th>'.$lt{'crd'}.'</th>'."\n".
-                 '<th>'.$lt{'sta'}.'</th><th>'.$lt{'end'}.'</th>'."\n".
+                 '<th>'.$lt{'grs'}.'</th>'."\n";
+    $header .=   '<th>'.$lt{'crd'}.'</th>'."\n" if ($showcredits);
+    $header .=   '<th>'.$lt{'sta'}.'</th><th>'.$lt{'end'}.'</th>'."\n".
                  &Apache::loncommon::end_data_table_header_row();
     my $otheritems = &Apache::loncommon::start_data_table_row()."\n".
                      '<td><br /><span class="LC_nobreak"><input type="text" name="coursedesc" value="" onfocus="this.blur();opencrsbrowser('."'cu','dccourse','dcdomain','coursedesc','','','','crstype'".')" />'.
                      $courseform.('&nbsp;' x4).'</span></td>'."\n".
-                     '<td valign><br /><select name="role">'."\n";
+                     '<td valign="top"><br /><select name="role">'."\n";
     foreach my $role (@roles) {
         my $plrole=&Apache::lonnet::plaintext($role);
-        $otheritems .= '  <option value="'.$role.'">'.$plrole;
+        $otheritems .= '  <option value="'.$role.'">'.$plrole.'</option>';
     }
     if ( keys %customroles > 0) {
         foreach my $cust (sort keys %customroles) {
             my $custrole='cr_cr_'.$env{'user.domain'}.
                     '_'.$env{'user.name'}.'_'.$cust;
-            $otheritems .= '  <option value="'.$custrole.'">'.$cust;
+            $otheritems .= '  <option value="'.$custrole.'">'.$cust.'</option>';
         }
     }
     $otheritems .= '</select></td><td>'.
                      '<table border="0" cellspacing="0" cellpadding="0">'.
                      '<tr><td valign="top"><b>'.$lt{'exs'}.'</b><br /><select name="currsec">'.
-                     ' <option value=""><--'.&mt('Pick course first').'</select></td>'.
+                     ' <option value="">&lt;--'.&mt('Pick course first').'</option></select></td>'.
                      '<td>&nbsp;&nbsp;</td>'.
                      '<td valign="top">&nbsp;<b>'.$lt{'new'}.'</b><br />'.
                      '<input type="text" name="newsec" value="" />'.
@@ -6996,7 +7249,7 @@ sub course_level_dc {
                      '</tr></table></td>'."\n";
     if ($showcredits) {
         $otheritems .= '<td><br />'."\n".
-                       '<input type="text" size="3" name="credits" value="" />'."\n";
+                       '<input type="text" size="3" name="credits" value="" /></td>'."\n";
     }
     $otheritems .= <<ENDTIMEENTRY;
 <td><br /><input type="hidden" name="start" value='' />