Diff for /loncom/interface/loncreateuser.pm between versions 1.449 and 1.468

version 1.449, 2018/03/23 01:01:21 version 1.468, 2023/06/20 14:03:52
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 246  sub build_tools_display { Line 247  sub build_tools_display {
                    'aboutme'    => "Personal Information Page",                     '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",                     'portfolio'  => "Personal User Portfolio",
                      'timezone'   => "Can set Time Zone",
                    'avai'       => "Available",                     'avai'       => "Available",
                    'cusa'       => "availability",                     'cusa'       => "availability",
                    'chse'       => "Change setting",                     'chse'       => "Change setting",
Line 259  sub build_tools_display { Line 261  sub build_tools_display {
                    'lti'        => 'Can request creation of LTI courses',                     'lti'        => 'Can request creation of LTI courses',
                    'requestauthor'  => 'Can request author space',                     'requestauthor'  => 'Can request author space',
     );      );
       $isadv = &Apache::lonnet::is_advanced_user($ccdomain,$ccuname);
     if ($context eq 'requestcourses') {      if ($context eq 'requestcourses') {
         %userenv = &Apache::lonnet::userenvironment($ccdomain,$ccuname,          %userenv = &Apache::lonnet::userenvironment($ccdomain,$ccuname,
                       'requestcourses.official','requestcourses.unofficial',                        'requestcourses.official','requestcourses.unofficial',
Line 272  sub build_tools_display { Line 275  sub build_tools_display {
         $colspan = ' colspan="2"';          $colspan = ' colspan="2"';
         %domconfig =          %domconfig =
             &Apache::lonnet::get_dom('configuration',['requestcourses'],$ccdomain);              &Apache::lonnet::get_dom('configuration',['requestcourses'],$ccdomain);
         $isadv = &Apache::lonnet::is_advanced_user($ccdomain,$ccuname);  
     } elsif ($context eq 'requestauthor') {      } elsif ($context eq 'requestauthor') {
         %userenv = &Apache::lonnet::userenvironment($ccdomain,$ccuname,          %userenv = &Apache::lonnet::userenvironment($ccdomain,$ccuname,
                                                     'requestauthor');                                                      'requestauthor');
Line 286  sub build_tools_display { Line 288  sub build_tools_display {
     } else {      } else {
         %userenv = &Apache::lonnet::userenvironment($ccdomain,$ccuname,          %userenv = &Apache::lonnet::userenvironment($ccdomain,$ccuname,
                           'tools.aboutme','tools.portfolio','tools.blog',                            'tools.aboutme','tools.portfolio','tools.blog',
                           'tools.webdav');                            'tools.webdav','tools.timezone');
         @usertools = ('aboutme','blog','webdav','portfolio');          @usertools = ('aboutme','blog','webdav','portfolio','timezone');
     }      }
     foreach my $item (@usertools) {      foreach my $item (@usertools) {
         my ($custom_access,$curr_access,$cust_on,$cust_off,$tool_on,$tool_off,          my ($custom_access,$curr_access,$cust_on,$cust_off,$tool_on,$tool_off,
             $currdisp,$custdisp,$custradio);              $currdisp,$custdisp,$custradio);
         $cust_off = 'checked="checked" ';          $cust_off = 'checked="checked" ';
         $tool_on = 'checked="checked" ';          $tool_on = 'checked="checked" ';
         $curr_access =            $curr_access =
             &Apache::lonnet::usertools_access($ccuname,$ccdomain,$item,undef,              &Apache::lonnet::usertools_access($ccuname,$ccdomain,$item,undef,
                                               $context);                                                $context,\%userenv,'',
                                                 {'is_adv' => $isadv});
         if ($context eq 'requestauthor') {          if ($context eq 'requestauthor') {
             if ($userenv{$context} ne '') {              if ($userenv{$context} ne '') {
                 $cust_on = ' checked="checked" ';                  $cust_on = ' checked="checked" ';
Line 1484  ENDAUTH Line 1487  ENDAUTH
                                          $inst_results{$ccuname.':'.$ccdomain}));                                           $inst_results{$ccuname.':'.$ccdomain}));
         if ((&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) ||          if ((&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) ||
             (&Apache::lonnet::allowed('udp',$env{'request.role.domain'}))) {              (&Apache::lonnet::allowed('udp',$env{'request.role.domain'}))) {
             $r->print('<br /><h3>'.&mt('User Can Request Creation of Courses/Communities in this Domain?').'</h3>'.              $r->print('<br /><h3>'.&mt('User Can Request Creation of Courses/Communities in this Domain?').'</h3>'."\n");
                       &Apache::loncommon::start_data_table());              if (($env{'request.role.domain'} eq $ccdomain) ||
             if ($env{'request.role.domain'} eq $ccdomain) {                  (&Apache::lonnet::will_trust('reqcrs',$ccdomain,$env{'request.role.domain'}))) {
                 $r->print(&build_tools_display($ccuname,$ccdomain,'requestcourses'));                  $r->print(&Apache::loncommon::start_data_table());
             } else {                  if ($env{'request.role.domain'} eq $ccdomain) {
                 if (&Apache::lonnet::will_trust('reqcrs',$ccdomain,$env{'request.role.domain'})) {                      $r->print(&build_tools_display($ccuname,$ccdomain,'requestcourses'));
                   } else {
                     $r->print(&coursereq_externaluser($ccuname,$ccdomain,                      $r->print(&coursereq_externaluser($ccuname,$ccdomain,
                                                       $env{'request.role.domain'}));                                                        $env{'request.role.domain'}));
                 }                  }
                   $r->print(&Apache::loncommon::end_data_table());
               } else {
                   $r->print(&mt('Domain configuration for this domain prohibits course creation by users from domain: "[_1]"',
                                 &Apache::lonnet::domain($ccdomain,'description')));
             }              }
             $r->print(&Apache::loncommon::end_data_table());  
         }          }
         $r->print('</div>');          $r->print('</div>');
         my @order = ('auth','quota','tools','requestauthor');          my @order = ('auth','quota','tools','requestauthor');
Line 1507  ENDAUTH Line 1514  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 1612  ENDNOTOOLSPRIV Line 1619  ENDNOTOOLSPRIV
                 if ($newuser) {                  if ($newuser) {
                     $r->print(' onclick="auth_check()" \>'."\n");                      $r->print(' onclick="auth_check()" \>'."\n");
                 } else {                  } else {
                     $r->print('onclick="this.form.submit()" \>'."\n");                      $r->print(' onclick="this.form.submit()" \>'."\n");
                 }                  }
             } else {              } else {
                 $r->print('</fieldset></div>'.                  $r->print('</fieldset></div>'.
Line 2194  sub new_domain_roles { Line 2201  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 2267  ENDBADAUTH Line 2274  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 2285  ENDBADAUTH Line 2329  ENDBADAUTH
                 } elsif ($currentauth =~ /^unix:/) {                  } elsif ($currentauth =~ /^unix:/) {
                     $result = &mt('Currently Filesystem Authenticated.');                      $result = &mt('Currently Filesystem Authenticated.');
                 } elsif ($currentauth =~ /^lti:/) {                  } elsif ($currentauth =~ /^lti:/) {
                     $result = &mt('Currently LTi authenticated.');                      $result = &mt('Currently LTI authenticated.');
                 }                  }
                 $outcome = '<h3>'.$lt{'ld'}.'</h3>'.                  $outcome = '<h3>'.$lt{'ld'}.'</h3>'.
                            &Apache::loncommon::start_data_table().                             &Apache::loncommon::start_data_table().
Line 2400  sub modify_login_block { Line 2444  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,$usernameset,$condition,$excluded) = @_;          $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 2511  sub personal_data_display { Line 2555  sub personal_data_display {
         }          }
         $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="new-password" />';
         my $upasstwo = '<input type="password" name="upasscheck'.$now.'" size="20" autocomplete="off" />';          my $upasstwo = '<input type="password" name="upasscheck'.$now.'" size="20" autocomplete="new-password" />';
         $output .= &Apache::lonhtmlcommon::row_title(&mt('Password').'<b>*</b>',          $output .= &Apache::lonhtmlcommon::row_title(&mt('Password').'<b>*</b>',
                                                     'LC_pick_box_title',                                                      'LC_pick_box_title',
                                                     'LC_oddrow_value')."\n".                                                      'LC_oddrow_value')."\n".
Line 2526  sub personal_data_display { Line 2570  sub personal_data_display {
         if ($usernameset eq 'free') {          if ($usernameset eq 'free') {
             my $onclick = "toggleUsernameDisp(this,'selfcreateusername');";               my $onclick = "toggleUsernameDisp(this,'selfcreateusername');"; 
             $output .= &Apache::lonhtmlcommon::row_title($lt{'username'},undef,'LC_oddrow_value')."\n".              $output .= &Apache::lonhtmlcommon::row_title($lt{'username'},undef,'LC_oddrow_value')."\n".
                        &mt('Use e-mail address: ').                         '<span class="LC_nobreak">'.&mt('Use e-mail address: ').
                        '<label><input type="radio" name="emailused" value="1" checked="checked" onclick="'.$onclick.'" />'.&mt('Yes').'</label>'."\n".                         '<label><input type="radio" name="emailused" value="1" checked="checked" onclick="'.$onclick.'" />'.
                        ('&nbsp;'x2).                         &mt('Yes').'</label>'.('&nbsp;'x2).
                        '<label><input type="radio" name="emailused" value="0" onclick="'.$onclick.'" />'.&mt('No').'</label>'."\n".                         '<label><input type="radio" name="emailused" value="0" onclick="'.$onclick.'" />'.
                          &mt('No').'</label></span>'."\n".
                        '<div id="selfcreateusername" style="display: none; font-size: smaller">'.                         '<div id="selfcreateusername" style="display: none; font-size: smaller">'.
                        '<br /><span class="LC_nobreak">'.&mt('Preferred username').                         '<br /><span class="LC_nobreak">'.&mt('Preferred username').
                        '&nbsp;<input type="text" name="username" value="" size="20" autocomplete="off"/>'.                         '&nbsp;<input type="text" name="username" value="" size="20" autocomplete="off"/>'.
Line 2637  sub personal_data_display { Line 2682  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="'.
                              &HTML::Entities::encode($usertype,'\'<>"&').'" />';
               }
               $output .= &Apache::lonhtmlcommon::row_closure(1);
           }
     }      }
     $output .= &Apache::lonhtmlcommon::end_pick_box();      $output .= &Apache::lonhtmlcommon::end_pick_box();
     if (wantarray) {      if (wantarray) {
Line 2726  sub get_inststatuses { Line 2776  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 2865  sub update_user_data { Line 2915  sub update_user_data {
   
     my (%alerts,%rulematch,%inst_results,%curr_rules);      my (%alerts,%rulematch,%inst_results,%curr_rules);
     my @userinfo = ('firstname','middlename','lastname','generation','permanentemail','id');      my @userinfo = ('firstname','middlename','lastname','generation','permanentemail','id');
     my @usertools = ('aboutme','blog','webdav','portfolio');      my @usertools = ('aboutme','blog','webdav','portfolio','timezone');
     my @requestcourses = ('official','unofficial','community','textbook','placement','lti');      my @requestcourses = ('official','unofficial','community','textbook','placement','lti');
     my @requestauthor = ('requestauthor');      my @requestauthor = ('requestauthor');
     my ($othertitle,$usertypes,$types) =       my ($othertitle,$usertypes,$types) = 
Line 2995  sub update_user_data { Line 3045  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 3010  sub update_user_data { Line 3060  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 3034  sub update_user_data { Line 3091  sub update_user_data {
         my %userenv = &Apache::lonnet::get          my %userenv = &Apache::lonnet::get
             ('environment',['firstname','middlename','lastname','generation',              ('environment',['firstname','middlename','lastname','generation',
              'id','permanentemail','portfolioquota','authorquota','inststatus',               'id','permanentemail','portfolioquota','authorquota','inststatus',
              'tools.aboutme','tools.blog','tools.webdav','tools.portfolio',               'tools.aboutme','tools.blog','tools.webdav',
                'tools.portfolio','tools.timezone',
              'requestcourses.official','requestcourses.unofficial',               'requestcourses.official','requestcourses.unofficial',
              'requestcourses.community','requestcourses.textbook',               'requestcourses.community','requestcourses.textbook',
                'requestcourses.lti','requestauthor',
              'reqcrsotherdom.official','reqcrsotherdom.unofficial',               'reqcrsotherdom.official','reqcrsotherdom.unofficial',
              'reqcrsotherdom.community','reqcrsotherdom.textbook',               'reqcrsotherdom.community','reqcrsotherdom.textbook',
              'reqcrsotherdom.placement','requestauthor'],               'reqcrsotherdom.placement'],
               $env{'form.ccdomain'},$env{'form.ccuname'});                $env{'form.ccdomain'},$env{'form.ccuname'});
         my ($tmp) = keys(%userenv);          my ($tmp) = keys(%userenv);
         if ($tmp =~ /^(con_lost|error)/i) {           if ($tmp =~ /^(con_lost|error)/i) { 
Line 3069  sub update_user_data { Line 3128  sub update_user_data {
                 }                  }
             } elsif ($context eq 'author') {              } elsif ($context eq 'author') {
                 if ($rolenum eq $auname && $roledom eq $audom) {                  if ($rolenum eq $auname && $roledom eq $audom) {
                     if (!grep(/^\Q$role\E$/,@userroles)) {                       if (!grep(/^\Q$role\E$/,@userroles)) {
                         push(@userroles,$role);                          push(@userroles,$role);
                     }                      }
                 }                  }
Line 3368  sub update_user_data { Line 3427  sub update_user_data {
                             &Apache::lonnet::appenv(\%newenvhash);                              &Apache::lonnet::appenv(\%newenvhash);
                         }                          }
                     }                      }
                       if ($changed{'aboutme'}) {
                           &Apache::loncommon::devalidate_aboutme_cache($env{'form.ccuname'},
                                                                        $env{'form.ccdomain'});
                       }
                 }                  }
             }              }
             if (keys(%namechanged) > 0) {              if (keys(%namechanged) > 0) {
Line 3537  sub display_userinfo { Line 3600  sub display_userinfo {
          'webdav'         => 'WebDAV Availability',           'webdav'         => 'WebDAV Availability',
          'aboutme'        => 'Personal Information Page Availability',           'aboutme'        => 'Personal Information Page Availability',
          'portfolio'      => 'Portfolio Availability',           'portfolio'      => 'Portfolio Availability',
            'timezone'       => 'Can set own Time Zone',
          'official'       => 'Can Request Official Courses',           'official'       => 'Can Request Official Courses',
          'unofficial'     => 'Can Request Unofficial Courses',           'unofficial'     => 'Can Request Unofficial Courses',
          'community'      => 'Can Request Communities',           'community'      => 'Can Request Communities',
Line 3913  sub update_roles { Line 3977  sub update_roles {
     my ($r,$context,$showcredits) = @_;      my ($r,$context,$showcredits) = @_;
     my $now=time;      my $now=time;
     my @rolechanges;      my @rolechanges;
     my %disallowed;      my (%disallowed,%got_role_approvals,%got_instdoms,%process_by,%instdoms,
           %pending,%reject,%notifydc,%status,%unauthorized,%currqueued);
       $got_role_approvals{$context} = '';
       $process_by{$context} = {};
       my @domroles = &Apache::lonuserutils::domain_roles();
       my @cstrroles = &Apache::lonuserutils::construction_space_roles();
       my @courseroles = &Apache::lonuserutils::roles_by_context('course',1);
     $r->print('<h3>'.&mt('Modifying Roles').'</h3>');      $r->print('<h3>'.&mt('Modifying Roles').'</h3>');
     foreach my $key (keys(%env)) {      foreach my $key (keys(%env)) {
  next if (! $env{$key});   next if (! $env{$key});
Line 4015  sub update_roles { Line 4085  sub update_roles {
     if ($key=~/^form\.ren\:([^\_]+)\_([^\_\.]+)$/) {      if ($key=~/^form\.ren\:([^\_]+)\_([^\_\.]+)$/) {
                 my $url = $1;                  my $url = $1;
                 my $role = $2;                  my $role = $2;
                   my $id = $url.'_'.$role;
                 my $logmsg;                  my $logmsg;
                 my $output;                  my $output;
                 if ($role eq 'st') {                  if ($role eq 'st') {
Line 4022  sub update_roles { Line 4093  sub update_roles {
                         my ($cdom,$cnum,$csec) = ($1,$2,$3);                          my ($cdom,$cnum,$csec) = ($1,$2,$3);
                         my $credits;                          my $credits;
                         if ($showcredits) {                          if ($showcredits) {
                             my $defaultcredits =                               my $defaultcredits =
                                 &Apache::lonuserutils::get_defaultcredits($cdom,$cnum);                                  &Apache::lonuserutils::get_defaultcredits($cdom,$cnum);
                             $credits = &get_user_credits($defaultcredits,$cdom,$cnum);                              $credits = &get_user_credits($defaultcredits,$cdom,$cnum);
                         }                          }
                           unless ($udom eq $cdom) {
                               next if (&Apache::lonuserutils::restricted_dom($context,$id,$udom,
                                            $uname,$role,$now,0,$cdom,$cnum,$csec,$credits,
                                            \%process_by,\%instdoms,\%got_role_approvals,
                                            \%got_instdoms,\%reject,\%pending,\%notifydc,
                                            \%status,\%unauthorized,\%currqueued));
                           }
                         my $result = &Apache::loncommon::commit_studentrole(\$logmsg,$udom,$uname,$url,$role,$now,0,$cdom,$cnum,$csec,$context,$credits);                          my $result = &Apache::loncommon::commit_studentrole(\$logmsg,$udom,$uname,$url,$role,$now,0,$cdom,$cnum,$csec,$context,$credits);
                         if (($result =~ /^error/) || ($result eq 'not_in_class') || ($result eq 'unknown_course') || ($result eq 'refused')) {                          if (($result =~ /^error/) || ($result eq 'not_in_class') || ($result eq 'unknown_course') || ($result eq 'refused')) {
                             if ($result eq 'refused' && $logmsg) {                              if ($result eq 'refused' && $logmsg) {
Line 4041  sub update_roles { Line 4119  sub update_roles {
                         }                          }
                     }                      }
                 } else {                  } else {
                       my ($cdom,$cnum,$csec);
                       if (grep(/^\Q$role\E$/,@cstrroles)) {
                           ($cdom,$cnum) = ($url =~ m{^/($match_domain)/($match_username)$});
                       } elsif (grep(/^\Q$role\E$/,@domroles)) {
                           ($cdom) = ($url =~ m{^/($match_domain)/$});
                       } elsif ($url =~ m-^/($match_domain)/($match_courseid)/?(\w*)$-) {
                           ($cdom,$cnum,$csec) = ($1,$2,$3);
                       }
                       if ($cdom ne '') {
                           unless ($udom eq $cdom) {
                               next if (&Apache::lonuserutils::restricted_dom($context,$id,$udom,
                                            $uname,$role,$now,0,$cdom,$cnum,$csec,'',\%process_by,
                                            \%instdoms,\%got_role_approvals,\%got_instdoms,\%reject,
                                            \%pending,\%notifydc,\%status,\%unauthorized,\%currqueued));
                           }
                       }
     my $result=&Apache::lonnet::assignrole($env{'form.ccdomain'},      my $result=&Apache::lonnet::assignrole($env{'form.ccdomain'},
                                $env{'form.ccuname'},$url,$role,0,$now,'','',                                 $env{'form.ccuname'},$url,$role,0,$now,'','',
                                $context);                                 $context);
                         $output = &Apache::lonhtmlcommon::confirm_success(&mt('Re-enabling [_1] in [_2]',                      $output = &Apache::lonhtmlcommon::confirm_success(&mt('Re-enabling [_1] in [_2]',
                                         &Apache::lonnet::plaintext($role),                                      &Apache::lonnet::plaintext($role),
                                         &Apache::loncommon::show_role_extent($url,$context,$role)),$result ne "ok").'<br />';                                      &Apache::loncommon::show_role_extent($url,$context,$role)),$result ne "ok").'<br />';
                     if ($result ne "ok") {                      if ($result ne "ok") {
                         $output .= &mt('Error: [_1]',$result).'<br />';                          $output .= &mt('Error: [_1]',$result).'<br />';
                     }                      }
Line 4059  sub update_roles { Line 4153  sub update_roles {
 # Re-enable custom role  # Re-enable custom role
     if ($key=~m{^form\.ren\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}) {      if ($key=~m{^form\.ren\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}) {
                 my ($url,$rdom,$rnam,$rolename) = ($1,$2,$3,$4);                  my ($url,$rdom,$rnam,$rolename) = ($1,$2,$3,$4);
                   my $id = $url.'_cr'."/$rdom/$rnam/$rolename";
                   my $role = "cr/$rdom/$rnam/$rolename";
                   if ($url =~ m-^/($match_domain)/($match_courseid)/?(\w*)$-) {
                       my ($cdom,$cnum,$csec) = ($1,$2,$3);
                       unless ($udom eq $cdom) {
                           next if (&Apache::lonuserutils::restricted_dom($context,$id,$udom,
                                        $uname,$role,$now,0,$cdom,$cnum,$csec,'',\%process_by,
                                        \%instdoms,\%got_role_approvals,\%got_instdoms,\%reject,
                                        \%pending,\%notifydc,\%status,\%unauthorized,\%currqueued));
                       }
                   }
                 my $result = &Apache::lonnet::assigncustomrole(                  my $result = &Apache::lonnet::assigncustomrole(
                                $env{'form.ccdomain'}, $env{'form.ccuname'},                                 $env{'form.ccdomain'}, $env{'form.ccuname'},
                                $url,$rdom,$rnam,$rolename,0,$now,undef,$context);                                 $url,$rdom,$rnam,$rolename,0,$now,undef,$context);
Line 4080  sub update_roles { Line 4185  sub update_roles {
                 # Activate a custom role                  # Activate a custom role
  my ($one,$two,$three,$four,$five)=($1,$2,$3,$4,$5);   my ($one,$two,$three,$four,$five)=($1,$2,$3,$4,$5);
  my $url='/'.$one.'/'.$two;   my $url='/'.$one.'/'.$two;
                   my $id = $url.'_cr/'."$three/$four/$five";
                   my $role = "cr/$three/$four/$five";
  my $full=$one.'_'.$two.'_cr_cr_'.$three.'_'.$four.'_'.$five;   my $full=$one.'_'.$two.'_cr_cr_'.$three.'_'.$four.'_'.$five;
   
                 my $start = ( $env{'form.start_'.$full} ?                  my $start = ( $env{'form.start_'.$full} ?
Line 4088  sub update_roles { Line 4195  sub update_roles {
                 my $end   = ( $env{'form.end_'.$full} ?                  my $end   = ( $env{'form.end_'.$full} ?
                               $env{'form.end_'.$full} :                                $env{'form.end_'.$full} :
                               0 );                                0 );
                                                                                        
                 # split multiple sections                  # split multiple sections
                 my %sections = ();                  my %sections = ();
                 my $num_sections = &build_roles($env{'form.sec_'.$full},\%sections,$5);                  my $num_sections = &build_roles($env{'form.sec_'.$full},\%sections,$five);
                 if ($num_sections == 0) {                  if ($num_sections == 0) {
                       unless ($udom eq $one) {
                           next if (&Apache::lonuserutils::restricted_dom($context,$id,$udom,
                                        $uname,$role,$start,$end,$one,$two,'','',\%process_by,
                                        \%instdoms,\%got_role_approvals,\%got_instdoms,\%reject,
                                        \%pending,\%notifydc,\%status,\%unauthorized,\%currqueued));
                       }
                     $r->print(&Apache::loncommon::commit_customrole($udom,$uname,$url,$three,$four,$five,$start,$end,$context));                      $r->print(&Apache::loncommon::commit_customrole($udom,$uname,$url,$three,$four,$five,$start,$end,$context));
                 } else {                  } else {
     my %curr_groups =      my %curr_groups =
  &Apache::longroup::coursegroups($one,$two);   &Apache::longroup::coursegroups($one,$two);
                       my ($restricted,$numchanges);
                     foreach my $sec (sort {$a cmp $b} keys(%sections)) {                      foreach my $sec (sort {$a cmp $b} keys(%sections)) {
                         if (($sec eq 'none') || ($sec eq 'all') ||                           if (($sec eq 'none') || ($sec eq 'all') || 
                             exists($curr_groups{$sec})) {                              exists($curr_groups{$sec})) {
Line 4104  sub update_roles { Line 4218  sub update_roles {
                             next;                              next;
                         }                          }
                         my $securl = $url.'/'.$sec;                          my $securl = $url.'/'.$sec;
                           my $secid = $securl.'_cr'."/$three/$four/$five";
                           undef($restricted);
                           unless ($udom eq $one) {
                               next if (&Apache::lonuserutils::restricted_dom($context,$secid,$udom,
                                            $uname,$role,$start,$end,$one,$two,$sec,'',\%process_by,
                                            \%instdoms,\%got_role_approvals,\%got_instdoms,\%reject,
                                            \%pending,\%notifydc,\%status,\%unauthorized,\%currqueued));
                           }
                           $numchanges ++;
         $r->print(&Apache::loncommon::commit_customrole($udom,$uname,$securl,$three,$four,$five,$start,$end,$context));          $r->print(&Apache::loncommon::commit_customrole($udom,$uname,$securl,$three,$four,$five,$start,$end,$context));
                     }                      }
                       next unless ($numchanges);
                 }                  }
                 if (!grep(/^cr$/,@rolechanges)) {                  if (!grep(/^cr$/,@rolechanges)) {
                     push(@rolechanges,'cr');                      push(@rolechanges,'cr');
Line 4114  sub update_roles { Line 4238  sub update_roles {
  # Activate roles for sections with 3 id numbers   # Activate roles for sections with 3 id numbers
  # set start, end times, and the url for the class   # set start, end times, and the url for the class
  my ($one,$two,$three)=($1,$2,$3);   my ($one,$two,$three)=($1,$2,$3);
  my $start = ( $env{'form.start_'.$one.'_'.$two.'_'.$three} ?    my $start = ( $env{'form.start_'.$one.'_'.$two.'_'.$three} ?
       $env{'form.start_'.$one.'_'.$two.'_'.$three} :         $env{'form.start_'.$one.'_'.$two.'_'.$three} :
       $now );        $now );
  my $end   = ( $env{'form.end_'.$one.'_'.$two.'_'.$three} ?    my $end   = ( $env{'form.end_'.$one.'_'.$two.'_'.$three} ?
       $env{'form.end_'.$one.'_'.$two.'_'.$three} :        $env{'form.end_'.$one.'_'.$two.'_'.$three} :
       0 );        0 );
  my $url='/'.$one.'/'.$two;   my $url='/'.$one.'/'.$two;
                 my $type = 'three';                  my $id = $url.'_'.$three;
                 # split multiple sections                  # split multiple sections
                 my %sections = ();                  my %sections = ();
                 my $num_sections = &build_roles($env{'form.sec_'.$one.'_'.$two.'_'.$three},\%sections,$three);                  my $num_sections = &build_roles($env{'form.sec_'.$one.'_'.$two.'_'.$three},\%sections,$three);
                 my $credits;                  my ($credits,$numchanges);
                 if ($three eq 'st') {                  if ($three eq 'st') {
                     if ($showcredits) {                       if ($showcredits) {
                         my $defaultcredits =                           my $defaultcredits = 
                             &Apache::lonuserutils::get_defaultcredits($one,$two);                              &Apache::lonuserutils::get_defaultcredits($one,$two);
                         $credits = $env{'form.credits_'.$one.'_'.$two.'_'.$three};                          $credits = $env{'form.credits_'.$one.'_'.$two.'_'.$three};
Line 4138  sub update_roles { Line 4262  sub update_roles {
                     }                      }
                 }                  }
                 if ($num_sections == 0) {                  if ($num_sections == 0) {
                       unless ($udom eq $one) {
                           next if (&Apache::lonuserutils::restricted_dom($context,$id,$udom,
                                        $uname,$three,$start,$end,$one,$two,'',$credits,\%process_by,
                                        \%instdoms,\%got_role_approvals,\%got_instdoms,\%reject,
                                        \%pending,\%notifydc,\%status,\%unauthorized,\%currqueued));
                       }
                       $numchanges ++;
                     $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$three,$start,$end,$one,$two,'',$context,$credits));                      $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$three,$start,$end,$one,$two,'',$context,$credits));
                 } else {                  } else {
                     my %curr_groups =                       my %curr_groups = 
  &Apache::longroup::coursegroups($one,$two);   &Apache::longroup::coursegroups($one,$two);
                     my $emptysec = 0;                      my $emptysec = 0;
                       my $restricted;
                     foreach my $sec (sort {$a cmp $b} keys(%sections)) {                      foreach my $sec (sort {$a cmp $b} keys(%sections)) {
                         $sec =~ s/\W//g;                          $sec =~ s/\W//g;
                         if ($sec ne '') {                          if ($sec ne '') {
Line 4152  sub update_roles { Line 4284  sub update_roles {
                                 next;                                  next;
                             }                              }
                             my $securl = $url.'/'.$sec;                              my $securl = $url.'/'.$sec;
                               my $secid = $securl.'_'.$three;
                               unless ($udom eq $one) {
                                   undef($restricted);
                                   $restricted = &Apache::lonuserutils::restricted_dom($context,$secid,$udom,
                                                     $uname,$three,$start,$end,$one,$two,$sec,$credits,\%process_by,
                                                     \%instdoms,\%got_role_approvals,\%got_instdoms,\%reject,
                                                     \%pending,\%notifydc,\%status,\%unauthorized,\%currqueued);
                                   next if ($restricted);
                               }
                               $numchanges ++;
                             $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$securl,$three,$start,$end,$one,$two,$sec,$context,$credits));                              $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$securl,$three,$start,$end,$one,$two,$sec,$context,$credits));
                         } else {                          } else {
                             $emptysec = 1;                              $emptysec = 1;
                         }                          }
                     }                      }
                     if ($emptysec) {                      if ($emptysec) {
                           unless ($udom eq $one) {
                               undef($restricted);
                               $restricted = &Apache::lonuserutils::restricted_dom($context,$id,$udom,
                                                 $uname,$three,$start,$end,$one,$two,'',$credits,\%process_by,
                                                 \%instdoms,\%got_role_approvals,\%got_instdoms,\%reject,
                                                 \%pending,\%notifydc,\%status,\%unauthorized,\%currqueued);
                               next if ($restricted);
                           }
                           $numchanges ++;
                         $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$three,$start,$end,$one,$two,'',$context,$credits));                          $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$three,$start,$end,$one,$two,'',$context,$credits));
                     }                      }
                       next unless ($numchanges);
                 }                  }
                 if (!grep(/^\Q$three\E$/,@rolechanges)) {                  if (!grep(/^\Q$three\E$/,@rolechanges)) {
                     push(@rolechanges,$three);                      push(@rolechanges,$three);
Line 4167  sub update_roles { Line 4319  sub update_roles {
     } elsif ($key=~/^form\.act\_([^\_]+)\_([^\_]+)$/) {      } elsif ($key=~/^form\.act\_([^\_]+)\_([^\_]+)$/) {
  # Activate roles for sections with two id numbers   # Activate roles for sections with two id numbers
  # set start, end times, and the url for the class   # set start, end times, and the url for the class
  my $start = ( $env{'form.start_'.$1.'_'.$2} ?    my $start = ( $env{'form.start_'.$1.'_'.$2} ?
       $env{'form.start_'.$1.'_'.$2} :         $env{'form.start_'.$1.'_'.$2} :
       $now );        $now );
  my $end   = ( $env{'form.end_'.$1.'_'.$2} ?    my $end   = ( $env{'form.end_'.$1.'_'.$2} ?
       $env{'form.end_'.$1.'_'.$2} :        $env{'form.end_'.$1.'_'.$2} :
       0 );        0 );
                 my $one = $1;                  my $one = $1;
                 my $two = $2;                  my $two = $2;
  my $url='/'.$one.'/';   my $url='/'.$one.'/';
                   my $id = $url.'_'.$two;
                   my ($cdom,$cnum) = split(/\//,$one);
                 # split multiple sections                  # split multiple sections
                 my %sections = ();                  my %sections = ();
                   my ($restricted,$numchanges);
                 my $num_sections = &build_roles($env{'form.sec_'.$one.'_'.$two},\%sections,$two);                  my $num_sections = &build_roles($env{'form.sec_'.$one.'_'.$two},\%sections,$two);
                 if ($num_sections == 0) {                  if ($num_sections == 0) {
                       unless ($udom eq $one) {
                           $restricted = &Apache::lonuserutils::restricted_dom($context,$id,$udom,
                                             $uname,$two,$start,$end,$cdom,$cnum,'','',\%process_by,
                                             \%instdoms,\%got_role_approvals,\%got_instdoms,\%reject,
                                             \%pending,\%notifydc,\%status,\%unauthorized,\%currqueued);
                           next if ($restricted);
                       }
                       $numchanges ++;
                     $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$two,$start,$end,$one,undef,'',$context));                      $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$two,$start,$end,$one,undef,'',$context));
                 } else {                  } else {
                     my $emptysec = 0;                      my $emptysec = 0;
                     foreach my $sec (sort {$a cmp $b} keys(%sections)) {                      foreach my $sec (sort {$a cmp $b} keys(%sections)) {
                         if ($sec ne '') {                          if ($sec ne '') {
                             my $securl = $url.'/'.$sec;                              my $securl = $url.'/'.$sec;
                               my $secid = $securl.'_'.$two;
                               unless ($udom eq $one) {
                                   undef($restricted);
                                   $restricted = &Apache::lonuserutils::restricted_dom($context,$secid,$udom,
                                                     $uname,$two,$start,$end,$cdom,$cnum,$sec,'',\%process_by,
                                                     \%instdoms,\%got_role_approvals,\%got_instdoms,\%reject,
                                                     \%pending,\%notifydc,\%status,\%unauthorized,\%currqueued);
                                   next if ($restricted);
                               }
                               $numchanges ++;
                             $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$securl,$two,$start,$end,$one,undef,$sec,$context));                              $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$securl,$two,$start,$end,$one,undef,$sec,$context));
                         } else {                          } else {
                             $emptysec = 1;                              $emptysec = 1;
                         }                          }
                     }                      }
                     if ($emptysec) {                      if ($emptysec) {
                           unless ($udom eq $one) {
                               undef($restricted);
                               $restricted = &Apache::lonuserutils::restricted_dom($context,$id,$udom,
                                                 $uname,$two,$start,$end,$cdom,$cnum,'','',\%process_by,
                                                 \%instdoms,\%got_role_approvals,\%got_instdoms,\%reject,
                                                 \%pending,\%notifydc,\%status,\%unauthorized,\%currqueued);
                               next if ($restricted);
                           }
                           $numchanges ++;
                         $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$two,$start,$end,$one,undef,'',$context));                          $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$two,$start,$end,$one,undef,'',$context));
                     }                      }
                       next unless ($numchanges); 
                 }                  }
                 if (!grep(/^\Q$two\E$/,@rolechanges)) {                  if (!grep(/^\Q$two\E$/,@rolechanges)) {
                     push(@rolechanges,$two);                      push(@rolechanges,$two);
Line 4217  sub update_roles { Line 4400  sub update_roles {
             }              }
  }   }
     } # End of foreach (keys(%env))      } # End of foreach (keys(%env))
       if ((keys(%reject)) || (keys(%unauthorized))) {
           $r->print(&Apache::lonuserutils::print_roles_rejected($context,\%reject,\%unauthorized));
       }
       if ((keys(%pending)) || (keys(%currqueued))) {
           $r->print(&Apache::lonuserutils::print_roles_queued($context,\%pending,\%notifydc,\%currqueued));
       }
 # Flush the course logs so reverse user roles immediately updated  # Flush the course logs so reverse user roles immediately updated
     $r->register_cleanup(\&Apache::lonnet::flushcourselogs);      $r->register_cleanup(\&Apache::lonnet::flushcourselogs);
     if (@rolechanges == 0) {      if (@rolechanges == 0) {
Line 4271  sub enroll_single_student { Line 4460  sub enroll_single_student {
             }              }
         }          }
     }      }
       my ($startdate,$enddate) = &Apache::lonuserutils::get_dates_from_form();
       my (%got_role_approvals,%got_instdoms,%process_by,%instdoms,%pending,%reject,%notifydc,
           %status,%unauthorized,%currqueued);
       unless ($env{'form.ccdomain'} eq $env{'course.'.$env{'request.course.id'}.'.domain'}) {
           my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
           my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
           my $csec = $env{'form.sections'};
           my $id = "/$cdom/$cnum";
           if ($csec ne '') {
               $id .= "/$csec";
           }
           $id .= '_st';
           if (&Apache::lonuserutils::restricted_dom($context,$id,$env{'form.ccdomain'},$env{'form.ccuname'},
                                                     'st',$startdate,$enddate,$cdom,$cnum,$csec,$credits,
                                                     \%process_by,\%instdoms,\%got_role_approvals,\%got_instdoms,
                                                     \%reject,\%pending,\%notifydc,\%status,\%unauthorized,\%currqueued)) {
               if ((keys(%reject)) || (keys(%unauthorized))) {
                   $r->print(&Apache::lonuserutils::print_roles_rejected($context,\%reject,\%unauthorized));
               }
               if ((keys(%pending)) || (keys(%currqueued))) {
                   $r->print(&Apache::lonuserutils::print_roles_queued($context,\%pending,\%notifydc,\%currqueued));
               }
               return;
           }
       }
   
     # Clean out any old student roles the user has in this class.      # Clean out any old student roles the user has in this class.
     &Apache::lonuserutils::modifystudent($env{'form.ccdomain'},      &Apache::lonuserutils::modifystudent($env{'form.ccdomain'},
          $env{'form.ccuname'},$env{'request.course.id'},undef,$uhome);           $env{'form.ccuname'},$env{'request.course.id'},undef,$uhome);
     my ($startdate,$enddate) = &Apache::lonuserutils::get_dates_from_form();  
     my $enroll_result =      my $enroll_result =
         &Apache::lonnet::modify_student_enrollment($env{'form.ccdomain'},          &Apache::lonnet::modify_student_enrollment($env{'form.ccdomain'},
             $env{'form.ccuname'},$env{'form.cid'},$env{'form.cfirstname'},              $env{'form.ccuname'},$env{'form.cid'},$env{'form.cfirstname'},
Line 4637  sub set_custom_role { Line 4850  sub set_custom_role {
     );      );
 }  }
   
   sub show_role_requests {
       my ($caller,$dom) = @_;
       my $showrolereqs;
       my %domconfig = &Apache::lonnet::get_dom('configuration',['privacy'],$dom);
       if (ref($domconfig{'privacy'}) eq 'HASH') {
           if (ref($domconfig{'privacy'}{'approval'}) eq 'HASH') {
               my %approvalconf = %{$domconfig{'privacy'}{'approval'}};
               foreach my $key ('instdom','extdom') {
                   if (ref($approvalconf{$key}) eq 'HASH') {
                       if (keys(%{$approvalconf{$key}})) {
                           foreach my $context ('domain','author','course','community') {
                               if ($approvalconf{$key}{$context} eq $caller) {
                                   $showrolereqs = 1;
                                   last if ($showrolereqs);
                               }
                           }
                       }
                   }
                   last if ($showrolereqs);
               }
           }
       }
       return $showrolereqs;
   }
   
 # ================================================================ Main Handler  # ================================================================ Main Handler
 sub handler {  sub handler {
     my $r = shift;      my $r = shift;
Line 4924  sub handler { Line 5162  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 5302  sub handler { Line 5540  sub handler {
                      '<span class="LC_error">'.&mt('You do not have permission to view change logs').'</span>');                       '<span class="LC_error">'.&mt('You do not have permission to view change logs').'</span>');
         }          }
     } elsif ($env{'form.action'} eq 'helpdesk') {      } elsif ($env{'form.action'} eq 'helpdesk') {
         if (($permission->{'owner'}) || ($permission->{'co-owner'})) {          if (($permission->{'owner'} || $permission->{'co-owner'}) &&
               ($permission->{'cusr'} || $permission->{'view'})) {
             if ($env{'form.state'} eq 'process') {              if ($env{'form.state'} eq 'process') {
                 if ($permission->{'owner'}) {                  if ($permission->{'owner'}) {
                     &update_helpdeskaccess($r,$permission,$brcrum);                      &update_helpdeskaccess($r,$permission,$brcrum);
Line 5316  sub handler { Line 5555  sub handler {
             $r->print(&header(undef,{'no_nav_bar' => 1}).              $r->print(&header(undef,{'no_nav_bar' => 1}).
                       '<span class="LC_error">'.&mt('You do not have permission to view helpdesk access').'</span>');                        '<span class="LC_error">'.&mt('You do not have permission to view helpdesk access').'</span>');
         }          }
       } elsif ($env{'form.action'} eq 'rolerequests') {
           if ($permission->{cusr} || $permission->{view}) {
               &print_queued_roles($r,$context,$permission,$brcrum);
           }
       } elsif ($env{'form.action'} eq 'queuedroles') {
           if (($permission->{cusr}) && ($context eq 'domain')) {
               if (&show_role_requests($context,$env{'request.role.domain'})) {
                   if ($env{'form.state'} eq 'done') {
                       &process_pendingroles($r,$context,$permission,$brcrum);
                   } else {
                       &print_pendingroles($r,$context,$permission,$brcrum);
                   }
               } else {
                   $r->print(&header(undef,{'no_nav_bar' => 1}).
                             '<span class="LC_info">'.&mt('Domain coordinator approval of requests from other domains for assignment of roles to users from this domain not in use.').'</span>');
               }
           } else {
               $r->print(&header(undef,{'no_nav_bar' => 1}).
                        '<span class="LC_error">'.&mt('You do not have permission to view queued requests from other domains for assignment of roles to users from this domain.').'</span>');
           }
     } else {      } else {
         $bread_crumbs_component = 'User Management';          $bread_crumbs_component = 'User Management';
         $args = { bread_crumbs           => $brcrum,          $args = { bread_crumbs           => $brcrum,
Line 5567  sub print_main_menu { Line 5826  sub print_main_menu {
                             listusers  => 'Show and manage users in this community.',                              listusers  => 'Show and manage users in this community.',
                            },                             },
                 );                  );
   
   if ($linkcontext eq 'domain') {    if ($linkcontext eq 'domain') {
       unless ($permission->{'cusr'}) {        unless ($permission->{'cusr'}) {
           $links{'domain'}{'singleuser'} = 'View a User';            $links{'domain'}{'singleuser'} = 'View a User';
Line 5732  sub print_main_menu { Line 5992  sub print_main_menu {
              icon => 'helpdesk-access.png',               icon => 'helpdesk-access.png',
              #help => 'Course_Helpdesk_Access',               #help => 'Course_Helpdesk_Access',
              url => '/adm/createuser?action=helpdesk',               url => '/adm/createuser?action=helpdesk',
              permission => ($permission->{'owner'} || $permission->{'co-owner'}),               permission => (($permission->{'owner'} || $permission->{'co-owner'}) &&
                               ($permission->{'view'} || $permission->{'cusr'})),
              linktitle => 'Helpdesk access options',               linktitle => 'Helpdesk access options',
             },              },
             {              {
Line 5811  sub print_main_menu { Line 6072  sub print_main_menu {
             },              },
         );          );
     }      }
       push(@{ $menu[2]->{items} },
           {
            linktext => 'Role Requests (other domains)',
            icon => 'edit-find.png',
            #help => 'Role_Requests',
            url => '/adm/createuser?action=rolerequests',
            permission => $permission->{'cusr'},
            linktitle => 'Role requests for users in other domains',
           },
       );
       if (&show_role_requests($context,$env{'request.role.domain'})) {
           push(@{ $menu[2]->{items} },
               {
                linktext => 'Queued Role Assignments (this domain)',
                icon => 'edit-find.png',
                #help => 'Role_Approvals',
                url => '/adm/createuser?action=queuedroles',
                permission => $permission->{'cusr'},
                linktitle => "Role requests for this domain's users",
               },
           );
       }
     return Apache::lonhtmlcommon::generate_menu(@menu);      return Apache::lonhtmlcommon::generate_menu(@menu);
 #               { text => 'View Log-in History',  #               { text => 'View Log-in History',
 #                 help => 'Course_User_Logins',  #                 help => 'Course_User_Logins',
Line 6787  ENDSCRIPT Line 7070  ENDSCRIPT
                      chgcontext         => 'any',                       chgcontext         => 'any',
                      rolelog_start_date => $defstart,                       rolelog_start_date => $defstart,
                      rolelog_end_date   => $now,                       rolelog_end_date   => $now,
                        approvals          => 'any',
                    );                     );
     my $more_records = 0;      my $more_records = 0;
   
     # set current      # set current
     my %curr;      my %curr;
     foreach my $item ('show','page','role','chgcontext') {      foreach my $item ('show','page','role','chgcontext','approvals') {
         $curr{$item} = $env{'form.'.$item};          $curr{$item} = $env{'form.'.$item};
     }      }
     my ($startdate,$enddate) =       my ($startdate,$enddate) = 
Line 6866  ENDSCRIPT Line 7150  ENDSCRIPT
         if (($context eq 'course') && ($viewablesec ne '')) {          if (($context eq 'course') && ($viewablesec ne '')) {
             next if ($roleslog{$id}{'logentry'}{'section'} ne $viewablesec);              next if ($roleslog{$id}{'logentry'}{'section'} ne $viewablesec);
         }          }
           if ($curr{'approvals'} eq 'none') {
               next if ($roleslog{$id}{'logentry'}{'approval'});
           } elsif ($curr{'approvals'} ne 'any') { 
               next if ($roleslog{$id}{'logentry'}{'approval'} ne $curr{'approvals'});
           }
         $count ++;          $count ++;
         next if ($count < $minshown);          next if ($count < $minshown);
         unless ($showntableheader) {          unless ($showntableheader) {
Line 6912  ENDSCRIPT Line 7201  ENDSCRIPT
         if ($chgcontext ne '' && $lt{$chgcontext} ne '') {          if ($chgcontext ne '' && $lt{$chgcontext} ne '') {
             $chgcontext = $lt{$chgcontext};              $chgcontext = $lt{$chgcontext};
         }          }
           my ($showreqby,%reqby);
           if (($roleslog{$id}{'logentry'}{'approval'}) &&
               ($roleslog{$id}{'logentry'}{'requester'})) {
               if ($reqby{$roleslog{$id}{'logentry'}{'requester'}} eq '') {
                   my ($requname,$requdom) = split(/:/,$roleslog{$id}{'logentry'}{'requester'});
                   $reqby{$roleslog{$id}{'logentry'}{'requester'}} =
                       &Apache::loncommon::plainname($requname,$requdom);
               }
               $showreqby = &mt('Requester').': <span class="LC_nobreak">'.$reqby{$roleslog{$id}{'logentry'}{'requester'}}.'</span><br />';
               if ($roleslog{$id}{'logentry'}{'approval'} eq 'domain') {
                   $showreqby .= &mt('Adjudicator').': <span class="LC_nobreak">'.
                                 $whodunit{$roleslog{$id}{'exe_uname'}.':'.$roleslog{$id}{'exe_udom'}}.
                                 '</span>';
               } else {
                   $showreqby .= '<span class="LC_nobreak">'.&mt('User approved').'</span>';
               }
           } else {
               $showreqby = $whodunit{$roleslog{$id}{'exe_uname'}.':'.$roleslog{$id}{'exe_udom'}};
           }
         $r->print(          $r->print(
             &Apache::loncommon::start_data_table_row()              &Apache::loncommon::start_data_table_row()
            .'<td>'.$count.'</td>'             .'<td>'.$count.'</td>'
            .'<td>'.&Apache::lonlocal::locallocaltime($roleslog{$id}{'exe_time'}).'</td>'             .'<td>'.&Apache::lonlocal::locallocaltime($roleslog{$id}{'exe_time'}).'</td>'
            .'<td>'.$whodunit{$roleslog{$id}{'exe_uname'}.':'.$roleslog{$id}{'exe_udom'}}.'</td>'             .'<td>'.$showreqby.'</td>'
            .'<td>'.$changed{$roleslog{$id}{'uname'}.':'.$roleslog{$id}{'udom'}}.'</td>'             .'<td>'.$changed{$roleslog{$id}{'uname'}.':'.$roleslog{$id}{'udom'}}.'</td>'
            .'<td>'.&Apache::lonnet::plaintext($roleslog{$id}{'logentry'}{'role'},$crstype).'</td>');             .'<td>'.&Apache::lonnet::plaintext($roleslog{$id}{'logentry'}{'role'},$crstype).'</td>');
         if ($context eq 'course') {           if ($context eq 'course') { 
Line 7099  ENDSCRIPT Line 7407  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 7219  ENDSCRIPT Line 7528  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 activity_display_filter { Line 7578  sub activity_display_filter {
     my $nolink = 1;      my $nolink = 1;
     my $output = '<table><tr><td valign="top">'.      my $output = '<table><tr><td valign="top">'.
                  '<span class="LC_nobreak"><b>'.&mt('Actions/page:').'</b></span><br />'.                   '<span class="LC_nobreak"><b>'.&mt('Actions/page:').'</b></span><br />'.
                  &Apache::lonmeta::selectbox('show',$curr->{'show'},undef,                   &Apache::lonmeta::selectbox('show',$curr->{'show'},'',undef,
                                               (&mt('all'),5,10,20,50,100,1000,10000)).                                                (&mt('all'),5,10,20,50,100,1000,10000)).
                  '</td><td>&nbsp;&nbsp;</td>';                   '</td><td>&nbsp;&nbsp;</td>';
     my $startform =      my $startform =
Line 7356  sub userlogdisplay_navlinks { Line 7665  sub userlogdisplay_navlinks {
   
 sub role_display_filter {  sub role_display_filter {
     my ($context,$formname,$cdom,$cnum,$curr,$version,$crstype) = @_;      my ($context,$formname,$cdom,$cnum,$curr,$version,$crstype) = @_;
     my $lctype;  
     if ($context eq 'course') {  
         $lctype = lc($crstype);  
     }  
     my $nolink = 1;      my $nolink = 1;
     my $output = '<table><tr><td valign="top">'.      my $output = '<table><tr><td valign="top">'.
                  '<span class="LC_nobreak"><b>'.&mt('Changes/page:').'</b></span><br />'.                   '<span class="LC_nobreak"><b>'.&mt('Changes/page:').'</b></span><br />'.
                  &Apache::lonmeta::selectbox('show',$curr->{'show'},undef,                   &Apache::lonmeta::selectbox('show',$curr->{'show'},'',undef,
                                               (&mt('all'),5,10,20,50,100,1000,10000)).                                                (&mt('all'),5,10,20,50,100,1000,10000)).
                  '</td><td>&nbsp;&nbsp;</td>';                   '</td><td>&nbsp;&nbsp;</td>';
     my $startform =      my $startform =
Line 7387  sub role_display_filter { Line 7692  sub role_display_filter {
     if ($curr->{'role'} eq 'any') {      if ($curr->{'role'} eq 'any') {
         $output .= ' selected="selected"';          $output .= ' selected="selected"';
     }      }
     $output .=  '>'.&mt('Any').'</option>'."\n";      $output .= '>'.&mt('Any').'</option>'."\n";
     my @roles = &Apache::lonuserutils::roles_by_context($context,1,$crstype);      my @roles = &Apache::lonuserutils::roles_by_context($context,1,$crstype);
     foreach my $role (@roles) {      foreach my $role (@roles) {
         my $plrole;          my $plrole;
Line 7408  sub role_display_filter { Line 7713  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','ltienroll');
     } 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 7426  sub role_display_filter { Line 7731  sub role_display_filter {
         }          }
         $output .= '<option value="'.$chgtype.'"'.$selstr.'>'.$lt{$chgtype}.'</option>'."\n";          $output .= '<option value="'.$chgtype.'"'.$selstr.'>'.$lt{$chgtype}.'</option>'."\n";
     }      }
     $output .= '</select></td>'      my @possapprovals = ('any','none','domain','user');
               .'</tr></table>';      my %apptxt = &approval_types();
       $output .= '</select></td>'.
                  '<td>&nbsp;&nbsp;</td>'.
                  '<td valign="top"><b>'.
                  &mt('Approvals:').'</b><br /><select name="approvals">';
       foreach my $approval (@possapprovals) {
           my $selstr = '';
           if ($curr->{'approvals'} eq $approval) {
               $selstr = ' selected="selected"';
           }    
           $output .= '<option value="'.$approval.'"'.$selstr.'>'.$apptxt{$approval}.'</option>';
       }
       $output .= '</select></td></tr></table>';
   
     # Update Display button      # Update Display button
     $output .= '<p>'      $output .= '<p>'
Line 7457  sub rolechg_contexts { Line 7774  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',
                                              domain       => 'User Management in domain',                                               domain       => 'User Management in domain',
                                              selfenroll   => 'Self-enrolled',                                               selfenroll   => 'Self-enrolled',
                                              requestcourses => 'Course Request',                                               requestcourses => 'Course Request',
                                                ltienroll    => 'Enrollment via LTI',
                                          );                                           );
         if ($crstype eq 'Community') {          if ($crstype eq 'Community') {
             $lt{'createcourse'} = &mt('Community Creation');              $lt{'createcourse'} = &mt('Community Creation');
Line 7487  sub rolechg_contexts { Line 7806  sub rolechg_contexts {
     return %lt;      return %lt;
 }  }
   
   sub approval_types {
       return &Apache::lonlocal::texthash (
                                             any => 'Any',
                                             none => 'No approval needed',
                                             user => 'Role recipient approval',
                                             domain => 'Domain coordinator approval',
                                          );
   }
   
 sub print_helpdeskaccess_display {  sub print_helpdeskaccess_display {
     my ($r,$permission,$brcrum) = @_;      my ($r,$permission,$brcrum) = @_;
     my $formname = 'helpdeskaccess';      my $formname = 'helpdeskaccess';
Line 7893  ENDJS Line 8221  ENDJS
     return;      return;
 }  }
   
   sub print_queued_roles {
       my ($r,$context,$permission,$brcrum) = @_;
       push (@{$brcrum},
                {href => '/adm/createuser?action=rolerequests',
                 text => 'Role Requests (other domains)',
                 help => ''});
       my $bread_crumbs_component = 'Role Requests';
       my $args = { bread_crumbs           => $brcrum,
                    bread_crumbs_component => $bread_crumbs_component};
       # print page header
       $r->print(&header('',$args));
       my ($dom,$cnum);
       $dom = $env{'request.role.domain'};
       if ($context eq 'course') {
           if ($env{'request.course.id'}) {
               if (&Apache::loncommon::course_type() eq 'Community') {
                   $context = 'community';
               }
               $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
           }
       } elsif ($context eq 'author') {
           $cnum = $env{'user.name'};
       }
       $r->print(&Apache::loncoursequeueadmin::display_queued_requests('othdomqueue',$dom,$cnum,$context));
       return;
   }
   
   sub print_pendingroles {
       my ($r,$context,$permission,$brcrum) = @_;
       push (@{$brcrum},
                {href => '/adm/createuser?action=queuedroles',
                 text => 'Queued Role Assignments (users in this domain)',
                 help => ''});
       my $bread_crumbs_component = 'Queued Role Assignments';
       my $args = { bread_crumbs           => $brcrum,
                    bread_crumbs_component => $bread_crumbs_component};
       # print page header
       $r->print(&header('',$args));
       $r->print(&Apache::loncoursequeueadmin::display_queued_requests('othdomaction',$env{'request.role.domain'},'','domain'));
       return;
   }
   
   sub process_pendingroles {
       my ($r,$context,$permission,$brcrum) = @_;
       push (@{$brcrum},
                {href => '/adm/createuser?action=queuedroles',
                 text => 'Queued Role Assignments (users in this domain)',
                 help => ''},
                {href => '/adm/createuser?action=processrolereq',
                 text => 'Process Queue',
                 help => ''});
       my $bread_crumbs_component = 'Queued Role Assignments';
       my $args = { bread_crumbs           => $brcrum,
                    bread_crumbs_component => $bread_crumbs_component};
       # print page header
       $r->print(&header('',$args));
       $r->print(&Apache::loncoursequeueadmin::update_request_queue('othdombydc',
                                                                    $env{'request.role.domain'}));
       return;
   }
   
 sub domain_adhoc_access {  sub domain_adhoc_access {
     my ($roles,$domcurrent,$accesstypes,$usertypes,$othertitle) = @_;      my ($roles,$domcurrent,$accesstypes,$usertypes,$othertitle) = @_;
     my %domusage;      my %domusage;

Removed from v.1.449  
changed lines
  Added in v.1.468


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