--- loncom/interface/loncreateuser.pm	2018/12/08 18:30:15	1.450
+++ loncom/interface/loncreateuser.pm	2021/12/10 04:14:52	1.456
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Create a user
 #
-# $Id: loncreateuser.pm,v 1.450 2018/12/08 18:30:15 raeburn Exp $
+# $Id: loncreateuser.pm,v 1.456 2021/12/10 04:14:52 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -71,6 +71,7 @@ use Apache::longroup;
 use Apache::lonuserutils;
 use Apache::loncoursequeueadmin;
 use LONCAPA qw(:DEFAULT :match);
+use HTML::Entities;
 
 my $loginscript; # piece of javascript used in two separate instances
 my $authformnop;
@@ -1511,7 +1512,7 @@ ENDAUTH
              ($env{'request.role.domain'} eq $ccdomain)) {
             $user_text{'requestauthor'} = &domainrole_req($ccuname,$ccdomain);
         }
-        $user_text{'auth'} =  &user_authentication($ccuname,$ccdomain,$formname);
+        $user_text{'auth'} =  &user_authentication($ccuname,$ccdomain,$formname,$crstype,$permission);
         if ((&Apache::lonnet::allowed('mpq',$ccdomain)) ||
             (&Apache::lonnet::allowed('mut',$ccdomain)) ||
             (&Apache::lonnet::allowed('udp',$ccdomain))) {
@@ -2198,7 +2199,7 @@ sub new_domain_roles {
 }
 
 sub user_authentication {
-    my ($ccuname,$ccdomain,$formname) = @_;
+    my ($ccuname,$ccdomain,$formname,$crstype,$permission) = @_;
     my $currentauth=&Apache::lonnet::queryauthenticate($ccuname,$ccdomain);
     my $outcome;
     my %lt=&Apache::lonlocal::texthash(
@@ -2271,6 +2272,43 @@ ENDBADAUTH
             }
             $outcome .= &Apache::loncommon::end_data_table();
         } else {
+            if (($currentauth =~ /^internal:/) &&
+                (&Apache::lonuserutils::can_change_internalpass($ccuname,$ccdomain,$crstype,$permission))) {
+                $outcome = <<"ENDJS";
+<script type="text/javascript">
+// <![CDATA[
+function togglePwd(form) {
+    if (form.newintpwd.length) {
+        if (document.getElementById('LC_ownersetpwd')) {
+            for (var i=0; i<form.newintpwd.length; i++) {
+                if (form.newintpwd[i].checked) {
+                    if (form.newintpwd[i].value == 1) {
+                        document.getElementById('LC_ownersetpwd').style.display = 'inline-block';
+                    } else {
+                        document.getElementById('LC_ownersetpwd').style.display = 'none';
+                    }
+                }
+            }
+        }
+    }
+}
+// ]]>
+</script>
+ENDJS
+
+                $outcome .= '<h3>'.$lt{'ld'}.'</h3>'.
+                            &Apache::loncommon::start_data_table().
+                            &Apache::loncommon::start_data_table_row().
+                            '<td>'.&mt('Internally authenticated').'<br />'.&mt("Change user's password?").
+                            '<label><input type="radio" name="newintpwd" value="0" checked="checked" onclick="togglePwd(this.form);" />'.
+                            &mt('No').'</label>'.('&nbsp;'x2).
+                            '<label><input type="radio" name="newintpwd" value="1" onclick="togglePwd(this.form);" />'.&mt('Yes').'</label>'.
+                            '<div id="LC_ownersetpwd" style="display:none">'.
+                            '&nbsp;&nbsp;'.&mt('Password').' <input type="password" size="15" name="intarg" value="" />'.
+                            '<label><input type="checkbox" name="visible" onclick="if (this.checked) { this.form.intarg.type='."'text'".' } else { this.form.intarg.type='."'password'".' }" />'.&mt('Visible input').'</label></div></td>'.
+                            &Apache::loncommon::end_data_table_row().
+                            &Apache::loncommon::end_data_table();
+            }
             if (&Apache::lonnet::allowed('udp',$ccdomain)) {
                 # Current user has rights to view domain preferences for user's domain
                 my $result;
@@ -2289,7 +2327,7 @@ ENDBADAUTH
                 } elsif ($currentauth =~ /^unix:/) {
                     $result = &mt('Currently Filesystem Authenticated.');
                 } elsif ($currentauth =~ /^lti:/) {
-                    $result = &mt('Currently LTi authenticated.');
+                    $result = &mt('Currently LTI authenticated.');
                 }
                 $outcome = '<h3>'.$lt{'ld'}.'</h3>'.
                            &Apache::loncommon::start_data_table().
@@ -2404,8 +2442,8 @@ sub modify_login_block {
 }
 
 sub personal_data_display {
-    my ($ccuname,$ccdomain,$newuser,$context,$inst_results,$rolesarray,
-        $now,$captchaform,$emailusername,$usertype,$usernameset,$condition,$excluded) = @_;
+    my ($ccuname,$ccdomain,$newuser,$context,$inst_results,$rolesarray,$now,
+        $captchaform,$emailusername,$usertype,$usernameset,$condition,$excluded,$showsubmit) = @_;
     my ($output,%userenv,%canmodify,%canmodify_status);
     my @userinfo = ('firstname','middlename','lastname','generation',
                     'permanentemail','id');
@@ -2530,10 +2568,11 @@ sub personal_data_display {
         if ($usernameset eq 'free') {
             my $onclick = "toggleUsernameDisp(this,'selfcreateusername');"; 
             $output .= &Apache::lonhtmlcommon::row_title($lt{'username'},undef,'LC_oddrow_value')."\n".
-                       &mt('Use e-mail address: ').
-                       '<label><input type="radio" name="emailused" value="1" checked="checked" onclick="'.$onclick.'" />'.&mt('Yes').'</label>'."\n".
-                       ('&nbsp;'x2).
-                       '<label><input type="radio" name="emailused" value="0" onclick="'.$onclick.'" />'.&mt('No').'</label>'."\n".
+                       '<span class="LC_nobreak">'.&mt('Use e-mail address: ').
+                       '<label><input type="radio" name="emailused" value="1" checked="checked" onclick="'.$onclick.'" />'.
+                       &mt('Yes').'</label>'.('&nbsp;'x2).
+                       '<label><input type="radio" name="emailused" value="0" onclick="'.$onclick.'" />'.
+                       &mt('No').'</label></span>'."\n".
                        '<div id="selfcreateusername" style="display: none; font-size: smaller">'.
                        '<br /><span class="LC_nobreak">'.&mt('Preferred username').
                        '&nbsp;<input type="text" name="username" value="" size="20" autocomplete="off"/>'.
@@ -2641,12 +2680,17 @@ sub personal_data_display {
                        &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);
+        if ($showsubmit) {
+            my $submit_text = &mt('Create account');
+            $output .= &Apache::lonhtmlcommon::row_title()."\n".
+                       '<br /><input type="submit" name="createaccount" value="'.
+                       $submit_text.'" />';
+            if ($usertype ne '') {
+                $output .= '<input type="hidden" name="type" value="'.
+                           &HTML::Entities::encode($usertype,'\'<>"&').'" />';
+            }
+            $output .= &Apache::lonhtmlcommon::row_closure(1);
+        }
     }
     $output .= &Apache::lonhtmlcommon::end_pick_box();
     if (wantarray) {
@@ -2730,7 +2774,7 @@ sub get_inststatuses {
 
 # ================================================================= Phase Three
 sub update_user_data {
-    my ($r,$context,$crstype,$brcrum,$showcredits) = @_; 
+    my ($r,$context,$crstype,$brcrum,$showcredits,$permission) = @_; 
     my $uhome=&Apache::lonnet::homeserver($env{'form.ccuname'},
                                           $env{'form.ccdomain'});
     # Error messages
@@ -2999,7 +3043,7 @@ sub update_user_data {
                                           $env{'form.ccdomain'},$env{'form.ccuname'});
             } 
         }
-        $r->print('<br />'.&mt('Home server').': '.$uhome.' '.
+        $r->print('<br />'.&mt('Home Server').': '.$uhome.' '.
                   &Apache::lonnet::hostname($uhome));
     } elsif (($env{'form.login'} ne 'nochange') &&
              ($env{'form.login'} ne ''        )) {
@@ -3014,12 +3058,19 @@ sub update_user_data {
                       &Apache::lonnet::modifyuserauth(
 		       $env{'form.ccdomain'},$env{'form.ccuname'},
                        $amode,$genpwd));
-            $r->print('<br />'.&mt('Home server').': '.&Apache::lonnet::homeserver
+            $r->print('<br />'.&mt('Home Server').': '.&Apache::lonnet::homeserver
 		  ($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 authentication information.').$end);    
+	    $r->print($error.&mt('You do not have privileges to modify the authentication configuration for this user.').$end);
 	}
+    } elsif (($env{'form.intarg'} ne '') &&
+             (&Apache::lonnet::queryauthenticate($env{'form.ccuname'},$env{'form.ccdomain'}) =~ /^internal:/) &&
+             (&Apache::lonuserutils::can_change_internalpass($env{'form.ccuname'},$env{'form.ccdomain'},$crstype,$permission))) {
+        $r->print('Modifying authentication: '.
+                  &Apache::lonnet::modifyuserauth(
+                  $env{'form.ccdomain'},$env{'form.ccuname'},
+                  'internal',$env{'form.intarg'}));
     }
     $r->rflush(); # Finish display of header before time consuming actions start
     &Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state);
@@ -4928,7 +4979,7 @@ sub handler {
                 &print_useraccesslogs_display($r,$ccuname,$ccdomain,$permission,$brcrum);
             }
         } elsif ($env{'form.phase'} eq 'update_user_data') {
-            &update_user_data($r,$context,$crstype,$brcrum,$showcredits);
+            &update_user_data($r,$context,$crstype,$brcrum,$showcredits,$permission);
         } else {
             &print_username_entry_form($r,$context,undef,$srch,undef,$crstype,
                                        $brcrum,$permission);
@@ -7103,9 +7154,10 @@ ENDSCRIPT
     my ($nav_script,$nav_links);
 
 # table header
-    my $tableheader = '<h3>'.
+    my $heading = '<h3>'.
         &mt('User access logs for: [_1]',
-            &Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom),$uname,$udom)).'</h3>'
+            &Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom),$uname,$udom)).'</h3>';
+    my $tableheader = $heading
        .&Apache::loncommon::start_data_table_header_row()
        .'<th>&nbsp;</th>'
        .'<th>'.&mt('When').'</th>'
@@ -7223,7 +7275,7 @@ ENDSCRIPT
         $r->print(&Apache::loncommon::end_data_table().
                   &userlogdisplay_navlinks(\%curr,$more_records));
     } else { # No content displayed above
-        $r->print('<p class="LC_info">'
+        $r->print($heading.'<p class="LC_info">'
                  .&mt('There are no records to display.')
                  .'</p>');
     }