Diff for /loncom/interface/loncreateuser.pm between versions 1.406.2.14.4.1 and 1.406.2.20

version 1.406.2.14.4.1, 2017/11/16 17:57:13 version 1.406.2.20, 2021/12/13 20:53:06
Line 71  use Apache::longroup; Line 71  use Apache::longroup;
 use Apache::lonuserutils;  use Apache::lonuserutils;
 use Apache::loncoursequeueadmin;  use Apache::loncoursequeueadmin;
 use LONCAPA qw(:DEFAULT :match);  use LONCAPA qw(:DEFAULT :match);
   use HTML::Entities;
   
 my $loginscript; # piece of javascript used in two separate instances  my $loginscript; # piece of javascript used in two separate instances
 my $authformnop;  my $authformnop;
Line 1486  ENDAUTH Line 1487  ENDAUTH
              ($env{'request.role.domain'} eq $ccdomain)) {               ($env{'request.role.domain'} eq $ccdomain)) {
             $user_text{'requestauthor'} = &domainrole_req($ccuname,$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)) ||          if ((&Apache::lonnet::allowed('mpq',$ccdomain)) ||
             (&Apache::lonnet::allowed('mut',$ccdomain)) ||              (&Apache::lonnet::allowed('mut',$ccdomain)) ||
             (&Apache::lonnet::allowed('udp',$ccdomain))) {              (&Apache::lonnet::allowed('udp',$ccdomain))) {
Line 2164  sub new_domain_roles { Line 2165  sub new_domain_roles {
 }  }
   
 sub user_authentication {  sub user_authentication {
     my ($ccuname,$ccdomain,$formname) = @_;      my ($ccuname,$ccdomain,$formname,$crstype,$permission) = @_;
     my $currentauth=&Apache::lonnet::queryauthenticate($ccuname,$ccdomain);      my $currentauth=&Apache::lonnet::queryauthenticate($ccuname,$ccdomain);
     my $outcome;      my $outcome;
     my %lt=&Apache::lonlocal::texthash(      my %lt=&Apache::lonlocal::texthash(
Line 2236  ENDBADAUTH Line 2237  ENDBADAUTH
             }              }
             $outcome .= &Apache::loncommon::end_data_table();              $outcome .= &Apache::loncommon::end_data_table();
         } else {          } 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)) {              if (&Apache::lonnet::allowed('udp',$ccdomain)) {
                 # Current user has rights to view domain preferences for user's domain                  # Current user has rights to view domain preferences for user's domain
                 my $result;                  my $result;
Line 2344  sub modify_login_block { Line 2382  sub modify_login_block {
 }  }
   
 sub personal_data_display {  sub personal_data_display {
     my ($ccuname,$ccdomain,$newuser,$context,$inst_results,$rolesarray,      my ($ccuname,$ccdomain,$newuser,$context,$inst_results,$rolesarray,$now,
         $now,$captchaform,$emailusername,$usertype) = @_;          $captchaform,$emailusername,$usertype,$usernameset,$condition,$excluded,$showsubmit) = @_;
     my ($output,%userenv,%canmodify,%canmodify_status);      my ($output,%userenv,%canmodify,%canmodify_status);
     my @userinfo = ('firstname','middlename','lastname','generation',      my @userinfo = ('firstname','middlename','lastname','generation',
                     'permanentemail','id');                      'permanentemail','id');
Line 2372  sub personal_data_display { Line 2410  sub personal_data_display {
                 'inststatus'     => "Affiliation",                  'inststatus'     => "Affiliation",
                 'email'          => 'E-mail address',                  'email'          => 'E-mail address',
                 'valid'          => 'Validation',                  'valid'          => 'Validation',
                   'username'       => 'Username',
     );      );
   
     %canmodify_status =      %canmodify_status =
Line 2390  sub personal_data_display { Line 2429  sub personal_data_display {
             if (ref($emailusername) eq 'HASH') {              if (ref($emailusername) eq 'HASH') {
                 if (ref($emailusername->{$usertype}) eq 'HASH') {                  if (ref($emailusername->{$usertype}) eq 'HASH') {
                     my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();                      my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
                     @userinfo = ();                                @userinfo = ();
                     if ((ref($infofields) eq 'ARRAY') && (ref($infotitles) eq 'HASH')) {                      if ((ref($infofields) eq 'ARRAY') && (ref($infotitles) eq 'HASH')) {
                         foreach my $field (@{$infofields}) {                           foreach my $field (@{$infofields}) { 
                             if ($emailusername->{$usertype}->{$field}) {                              if ($emailusername->{$usertype}->{$field}) {
Line 2420  sub personal_data_display { Line 2459  sub personal_data_display {
     $output = '<h3>'.$lt{'pd'}.'</h3>'.      $output = '<h3>'.$lt{'pd'}.'</h3>'.
               &Apache::lonhtmlcommon::start_pick_box();                &Apache::lonhtmlcommon::start_pick_box();
     if (($context eq 'selfcreate') && ($newuser eq 'email')) {      if (($context eq 'selfcreate') && ($newuser eq 'email')) {
           my $size = 25;
           if ($condition) {
               if ($condition =~ /^\@[^\@]+$/) {
                   $size = 10;
               } else {
                   undef($condition);
               }
           }
           if ($excluded) {
               unless ($excluded =~ /^\@[^\@]+$/) {
                   undef($condition);
               }
           }
         $output .= &Apache::lonhtmlcommon::row_title($lt{'email'}.'<b>*</b>',undef,          $output .= &Apache::lonhtmlcommon::row_title($lt{'email'}.'<b>*</b>',undef,
                                                      'LC_oddrow_value')."\n".                                                       'LC_oddrow_value')."\n".
                    '<input type="text" name="uname" size="25" value="" autocomplete="off" />';                     '<input type="text" name="uname" size="'.$size.'" value="" autocomplete="off" />';
           if ($condition) {
               $output .= $condition;
           } elsif ($excluded) {
               $output .= '<br /><span style="font-size: smaller">'.&mt('You must use an e-mail address that does not end with [_1]',
                                                                        $excluded).'</span>';
           }
           if ($usernameset eq 'first') {
               $output .= '<br /><span style="font-size: smaller">';
               if ($condition) {
                   $output .= &mt('Your username in LON-CAPA will be the part of your e-mail address before [_1]',
                                         $condition);
               } else {
                   $output .= &mt('Your username in LON-CAPA will be the part of your e-mail address before the @');
               }
               $output .= '</span>';
           }
         $rowcount ++;          $rowcount ++;
         $output .= &Apache::lonhtmlcommon::row_closure(1);          $output .= &Apache::lonhtmlcommon::row_closure(1);
         my $upassone = '<input type="password" name="upass'.$now.'" size="20" autocomplete="off" />';          my $upassone = '<input type="password" name="upass'.$now.'" size="20" autocomplete="off" />';
Line 2437  sub personal_data_display { Line 2505  sub personal_data_display {
                                                      'LC_oddrow_value')."\n".                                                       'LC_oddrow_value')."\n".
                    $upasstwo.                     $upasstwo.
                    &Apache::lonhtmlcommon::row_closure()."\n";                     &Apache::lonhtmlcommon::row_closure()."\n";
           if ($usernameset eq 'free') {
               my $onclick = "toggleUsernameDisp(this,'selfcreateusername');";
               $output .= &Apache::lonhtmlcommon::row_title($lt{'username'},undef,'LC_oddrow_value')."\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"/>'.
                          '</span></div>'."\n".&Apache::lonhtmlcommon::row_closure(1);
               $rowcount ++;
           }
     }      }
     foreach my $item (@userinfo) {      foreach my $item (@userinfo) {
         my $rowtitle = $lt{$item};          my $rowtitle = $lt{$item};
Line 2538  sub personal_data_display { Line 2620  sub personal_data_display {
                        &Apache::lonhtmlcommon::row_closure(1)                         &Apache::lonhtmlcommon::row_closure(1)
             $rowcount ++;              $rowcount ++;
         }          }
         my $submit_text = &mt('Create account');          if ($showsubmit) {
         $output .= &Apache::lonhtmlcommon::row_title()."\n".              my $submit_text = &mt('Create account');
                    '<br /><input type="submit" name="createaccount" value="'.              $output .= &Apache::lonhtmlcommon::row_title()."\n".
                    $submit_text.'" />'.                         '<br /><input type="submit" name="createaccount" value="'.
                    '<input type="hidden" name="type" value="'.$usertype.'" />'.                         $submit_text.'" />';
                    &Apache::lonhtmlcommon::row_closure(1);              if ($usertype ne '') {
                   $output .= '<input type="hidden" name="type" value="'.$usertype.'" />'.
                              &Apache::lonhtmlcommon::row_closure(1);
               }
           }
     }      }
     $output .= &Apache::lonhtmlcommon::end_pick_box();      $output .= &Apache::lonhtmlcommon::end_pick_box();
     if (wantarray) {      if (wantarray) {
Line 2627  sub get_inststatuses { Line 2713  sub get_inststatuses {
   
 # ================================================================= Phase Three  # ================================================================= Phase Three
 sub update_user_data {  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'},      my $uhome=&Apache::lonnet::homeserver($env{'form.ccuname'},
                                           $env{'form.ccdomain'});                                            $env{'form.ccdomain'});
     # Error messages      # Error messages
Line 2893  sub update_user_data { Line 2979  sub update_user_data {
                                           $env{'form.ccdomain'},$env{'form.ccuname'});                                            $env{'form.ccdomain'},$env{'form.ccuname'});
             }               } 
         }          }
         $r->print('<br />'.&mt('Home server').': '.$uhome.' '.          $r->print('<br />'.&mt('Home Server').': '.$uhome.' '.
                   &Apache::lonnet::hostname($uhome));                    &Apache::lonnet::hostname($uhome));
     } elsif (($env{'form.login'} ne 'nochange') &&      } elsif (($env{'form.login'} ne 'nochange') &&
              ($env{'form.login'} ne ''        )) {               ($env{'form.login'} ne ''        )) {
Line 2908  sub update_user_data { Line 2994  sub update_user_data {
                       &Apache::lonnet::modifyuserauth(                        &Apache::lonnet::modifyuserauth(
        $env{'form.ccdomain'},$env{'form.ccuname'},         $env{'form.ccdomain'},$env{'form.ccuname'},
                        $amode,$genpwd));                         $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'}));    ($env{'form.ccuname'},$env{'form.ccdomain'}));
  } else {   } else {
     # Okay, this is a non-fatal error.      # 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      $r->rflush(); # Finish display of header before time consuming actions start
     &Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state);      &Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state);
Line 4819  sub handler { Line 4912  sub handler {
                 &print_useraccesslogs_display($r,$ccuname,$ccdomain,$permission,$brcrum);                  &print_useraccesslogs_display($r,$ccuname,$ccdomain,$permission,$brcrum);
             }              }
         } elsif ($env{'form.phase'} eq 'update_user_data') {          } 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 {          } else {
             &print_username_entry_form($r,$context,undef,$srch,undef,$crstype,              &print_username_entry_form($r,$context,undef,$srch,undef,$crstype,
                                        $brcrum,$permission);                                         $brcrum,$permission);
Line 4935  sub handler { Line 5028  sub handler {
                             unless ($usertype) {                              unless ($usertype) {
                                 $usertype = 'default';                                  $usertype = 'default';
                             }                              }
                               my ($showstatus,$showemail,$pickstart);
                               my $numextras = 0;
                               my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
                               if ((ref($types) eq 'ARRAY') && (@{$types} > 0)) {
                                   if (ref($usertypes) eq 'HASH') {
                                       if ($usertypes->{$usertype}) {
                                           $showstatus = $usertypes->{$usertype};
                                       } else {
                                           $showstatus = $othertitle;
                                       }
                                       if ($showstatus) {
                                           $numextras ++;
                                       }
                                   }
                               }
                               if (($info{$uname}{'email'} ne '') && ($info{$uname}{'email'} ne $uname)) {
                                   $showemail = $info{$uname}{'email'};
                                   $numextras ++;
                               }
                             if (ref($domconfig{'usercreation'}{'cancreate'}{'emailusername'}{$usertype}) eq 'HASH') {                              if (ref($domconfig{'usercreation'}{'cancreate'}{'emailusername'}{$usertype}) eq 'HASH') {
                                 if ((ref($infofields) eq 'ARRAY') && (ref($infotitles) eq 'HASH')) {                                  if ((ref($infofields) eq 'ARRAY') && (ref($infotitles) eq 'HASH')) {
                                       $pickstart = 1;
                                     $r->print('<div>'.&Apache::lonhtmlcommon::start_pick_box());                                      $r->print('<div>'.&Apache::lonhtmlcommon::start_pick_box());
                                     my ($num,$count,$showstatus);                                      my ($num,$count);
                                     $count = scalar(keys(%{$domconfig{'usercreation'}{'cancreate'}{'emailusername'}{$usertype}}));                                      $count = scalar(keys(%{$domconfig{'usercreation'}{'cancreate'}{'emailusername'}{$usertype}}));
                                     unless ($usertype eq 'default') {                                      $count += $numextras;
                                         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}) {                                      foreach my $field (@{$infofields}) {
                                         next unless ($domconfig{'usercreation'}{'cancreate'}{'emailusername'}{$usertype}{$field});                                          next unless ($domconfig{'usercreation'}{'cancreate'}{'emailusername'}{$usertype}{$field});
                                         next unless ($infotitles->{$field});                                          next unless ($infotitles->{$field});
                                         $r->print(&Apache::lonhtmlcommon::row_title($infotitles->{$field}).                                          $r->print(&Apache::lonhtmlcommon::row_title($infotitles->{$field}).
                                                   $info{$uname}{$field});                                                    $info{$uname}{$field});
                                         $num ++;                                          $num ++;
                                         if ($count == $num) {                                          unless ($count == $num) {
                                             $r->print(&Apache::lonhtmlcommon::row_closure(1));  
                                         } else {  
                                             $r->print(&Apache::lonhtmlcommon::row_closure());                                              $r->print(&Apache::lonhtmlcommon::row_closure());
                                         }                                          }
                                     }                                      }
                                     if ($showstatus) {                                  }
                                         $r->print(&Apache::lonhtmlcommon::row_title(&mt('Status type (self-reported)')).                              }
                                                   $showstatus.                              if ($numextras) {
                                                   &Apache::lonhtmlcommon::row_closure(1));                                  unless ($pickstart) {
                                       $r->print('<div>'.&Apache::lonhtmlcommon::start_pick_box());
                                       $pickstart = 1;
                                   }
                                   if ($showemail) {
                                       my $closure = '';
                                       unless ($showstatus) {
                                           $closure = 1;
                                     }                                      }
                                     $r->print(&Apache::lonhtmlcommon::end_pick_box().'</div>');                                      $r->print(&Apache::lonhtmlcommon::row_title(&mt('E-mail address')).
                                                 $showemail.
                                                 &Apache::lonhtmlcommon::row_closure($closure));
                                   }
                                   if ($showstatus) {
                                       $r->print(&Apache::lonhtmlcommon::row_title(&mt('Status type[_1](self-reported)','<br />')).
                                                 $showstatus.
                                                 &Apache::lonhtmlcommon::row_closure(1));
                                 }                                  }
                             }                              }
                               if ($pickstart) {
                                   $r->print(&Apache::lonhtmlcommon::end_pick_box().'</div>');
                               } else {
                                   $r->print('<div>'.&mt('No information to display for this account request.').'</div>');
                               }
                           } else {
                               $r->print('<div>'.&mt('No information available for this account request.').'</div>');
                         }                          }
                     }                      }
                 }                  }
             }              }
             $r->print(&close_popup_form());  
         }          }
           $r->print(&close_popup_form());
     } elsif (($env{'form.action'} eq 'listusers') &&       } elsif (($env{'form.action'} eq 'listusers') && 
              ($permission->{'view'} || $permission->{'cusr'})) {               ($permission->{'view'} || $permission->{'cusr'})) {
         my $helpitem = 'Course_View_Class_List';          my $helpitem = 'Course_View_Class_List';
Line 6960  ENDSCRIPT Line 7083  ENDSCRIPT
     my ($nav_script,$nav_links);      my ($nav_script,$nav_links);
   
 # table header  # table header
     my $tableheader = '<h3>'.      my $heading = '<h3>'.
         &mt('User access logs for: [_1]',          &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()         .&Apache::loncommon::start_data_table_header_row()
        .'<th>&nbsp;</th>'         .'<th>&nbsp;</th>'
        .'<th>'.&mt('When').'</th>'         .'<th>'.&mt('When').'</th>'
Line 7080  ENDSCRIPT Line 7204  ENDSCRIPT
         $r->print(&Apache::loncommon::end_data_table().          $r->print(&Apache::loncommon::end_data_table().
                   &userlogdisplay_navlinks(\%curr,$more_records));                    &userlogdisplay_navlinks(\%curr,$more_records));
     } else { # No content displayed above      } 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.')                   .&mt('There are no records to display.')
                  .'</p>');                   .'</p>');
     }      }
Line 7269  sub role_display_filter { Line 7393  sub role_display_filter {
                &mt('Context:').'</b><br /><select name="chgcontext">';                 &mt('Context:').'</b><br /><select name="chgcontext">';
     my @posscontexts;      my @posscontexts;
     if ($context eq 'course') {      if ($context eq 'course') {
         @posscontexts = ('any','automated','updatenow','createcourse','course','domain','selfenroll','requestcourses');          @posscontexts = ('any','automated','updatenow','createcourse','course','domain','selfenroll','requestcourses','chgtype');
     } elsif ($context eq 'domain') {      } elsif ($context eq 'domain') {
         @posscontexts = ('any','domain','requestauthor','domconfig','server');          @posscontexts = ('any','domain','requestauthor','domconfig','server');
     } else {      } else {
         @posscontexts = ('any','author','domain');          @posscontexts = ('any','author','domain');
     }       }
     foreach my $chgtype (@posscontexts) {      foreach my $chgtype (@posscontexts) {
         my $selstr = '';          my $selstr = '';
         if ($curr->{'chgcontext'} eq $chgtype) {          if ($curr->{'chgcontext'} eq $chgtype) {
Line 7318  sub rolechg_contexts { Line 7442  sub rolechg_contexts {
         %lt = &Apache::lonlocal::texthash (          %lt = &Apache::lonlocal::texthash (
                                              any          => 'Any',                                               any          => 'Any',
                                              automated    => 'Automated Enrollment',                                               automated    => 'Automated Enrollment',
                                                chgtype      => 'Enrollment Type/Lock Change',
                                              updatenow    => 'Roster Update',                                               updatenow    => 'Roster Update',
                                              createcourse => 'Course Creation',                                               createcourse => 'Course Creation',
                                              course       => 'User Management in course',                                               course       => 'User Management in course',

Removed from v.1.406.2.14.4.1  
changed lines
  Added in v.1.406.2.20


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>