Diff for /loncom/interface/lonuserutils.pm between versions 1.131 and 1.142

version 1.131, 2010/11/14 20:29:34 version 1.142, 2012/10/02 18:08:12
Line 47  sub modifystudent { Line 47  sub modifystudent {
     # this one.  If $csec is defined, drop them from all other sections of      # this one.  If $csec is defined, drop them from all other sections of
     # this course and add them to section $csec      # this course and add them to section $csec
     my ($cnum,$cdom) = &get_course_identity($courseid);      my ($cnum,$cdom) = &get_course_identity($courseid);
     my $extra = &Apache::lonnet::freeze_escape({'skipcheck' => 1});      my %roles = &Apache::lonnet::dump('roles',$udom,$unam);
     my %roles = &Apache::lonnet::dump('roles',$udom,$unam,'.',undef,$extra);  
     my ($tmp) = keys(%roles);      my ($tmp) = keys(%roles);
     # Bail out if we were unable to get the students roles      # Bail out if we were unable to get the students roles
     return "$1" if ($tmp =~ /^(con_lost|error|no_such_host)/i);      return "$1" if ($tmp =~ /^(con_lost|error|no_such_host)/i);
Line 589  END Line 588  END
 ###############################################################  ###############################################################
 sub upload_manager_javascript_forward_associate {  sub upload_manager_javascript_forward_associate {
     my ($can_assign) = @_;      my ($can_assign) = @_;
     my $auth_update;      my ($auth_update,$numbuttons,$argreset);
     if (ref($can_assign) eq 'HASH') {      if (ref($can_assign) eq 'HASH') {
         if (keys(%{$can_assign}) > 1) {          if ($can_assign->{'krb4'} || $can_assign->{'krb5'}) {
               $argreset .= "      vf.krbarg.value='';\n";
               $numbuttons ++ ;
           }
           if ($can_assign->{'int'}) {
               $argreset .= "      vf.intarg.value='';\n";
               $numbuttons ++;
           }
           if ($can_assign->{'loc'}) {
               $argreset .= "      vf.locarg.value='';\n";
               $numbuttons ++;
           }
           if (!$can_assign->{'int'}) {
               my $warning = &mt('You may not specify an initial password for each user, as this is only available when new users use LON-CAPA internal authentication.\n').
                             &mt('Your current role does not have rights to create users with that authentication type.');
               $auth_update = <<"END";
      // Currently the initial password field is only supported for internal auth
      // (see bug 6368).
      if (nw==9) {
          eval('vf.f'+tf+'.selectedIndex=0;')
          alert('$warning');
      }
   END
           } elsif ($numbuttons > 1) {
             $auth_update = <<"END";              $auth_update = <<"END";
    // If we set the password, make the password form below correspond to     // If we set the password, make the password form below correspond to
    // the new value.     // the new value.
    if (nw==9) {     if (nw==9) {
       changed_radio('int',document.studentform);        changed_radio('int',document.studentform);
       set_auth_radio_buttons('int',document.studentform);        set_auth_radio_buttons('int',document.studentform);
   $argreset
      }
   
 END  END
         }          }
         if ($can_assign->{'krb4'} || $can_assign->{'krb5'}) {  
            $auth_update .= "      vf.krbarg.value='';\n";  
         }  
         if ($can_assign->{'int'}) {  
            $auth_update .= "      vf.intarg.value='';\n";  
         }  
         if ($can_assign->{'loc'}) {  
            $auth_update .= "      vf.locarg.value='';\n";  
         }  
         $auth_update .= "  
    }\n";  
     }      }
   
     return(<<ENDPICK);      return(<<ENDPICK);
Line 708  ENDPICK Line 722  ENDPICK
 ###############################################################  ###############################################################
 sub upload_manager_javascript_reverse_associate {  sub upload_manager_javascript_reverse_associate {
     my ($can_assign) = @_;      my ($can_assign) = @_;
     my $auth_update;       my ($auth_update,$numbuttons,$argreset);
     if (ref($can_assign) eq 'HASH') {      if (ref($can_assign) eq 'HASH') {
         if (keys(%{$can_assign}) > 1) {          if ($can_assign->{'krb4'} || $can_assign->{'krb5'}) {
               $argreset .= "      vf.krbarg.value='';\n";
               $numbuttons ++ ;
           }
           if ($can_assign->{'int'}) {
               $argreset .= "      vf.intarg.value='';\n";
               $numbuttons ++;
           }
           if ($can_assign->{'loc'}) {
               $argreset .= "      vf.locarg.value='';\n";
               $numbuttons ++;
           }
           if (!$can_assign->{'int'}) {
               my $warning = &mt('You may not specify an initial password, as this is only available when new users use LON-CAPA internal authentication.\n').
                             &mt('Your current role does not have rights to create users with that authentication type.');
               $auth_update = <<"END";
      // Currently the initial password field is only supported for internal auth
      // (see bug 6368).
      if (tf==8 && nw!=0) {
          eval('vf.f'+tf+'.selectedIndex=0;')
          alert('$warning');
      }
   END
           } elsif ($numbuttons > 1) {
             $auth_update = <<"END";              $auth_update = <<"END";
    // initial password specified, pick internal authentication     // initial password specified, pick internal authentication
    if (tf==8 && nw!=0) {     if (tf==8 && nw!=0) {
       changed_radio('int',document.studentform);        changed_radio('int',document.studentform);
       set_auth_radio_buttons('int',document.studentform);        set_auth_radio_buttons('int',document.studentform);
   $argreset
      }
   
 END  END
         }          }
         if ($can_assign->{'krb'}) {        
            $auth_update .= "      vf.krbarg.value='';\n";  
         }  
         if ($can_assign->{'int'}) {  
            $auth_update .= "      vf.intarg.value='';\n";  
         }  
         if ($can_assign->{'loc'}) {  
            $auth_update .= "      vf.locarg.value='';\n";  
         }  
         $auth_update .= "  
    }\n";  
     }      }
   
     return(<<ENDPICK);      return(<<ENDPICK);
 function verify(vf,sec_caller) {  function verify(vf,sec_caller) {
     var founduname=0;      var founduname=0;
Line 1391  sub curr_role_permissions { Line 1421  sub curr_role_permissions {
 sub my_custom_roles {  sub my_custom_roles {
     my ($crstype) = @_;      my ($crstype) = @_;
     my %returnhash=();      my %returnhash=();
       my $extra = &Apache::lonnet::freeze_escape({'skipcheck' => 1});
     my %rolehash=&Apache::lonnet::dump('roles');      my %rolehash=&Apache::lonnet::dump('roles');
     foreach my $key (keys(%rolehash)) {      foreach my $key (keys(%rolehash)) {
         if ($key=~/^rolesdef\_(\w+)$/) {          if ($key=~/^rolesdef\_(\w+)$/) {
Line 1413  sub print_userlist { Line 1444  sub print_userlist {
     if ($env{'form.Status'} !~ /^(Any|Expired|Active|Future)$/) {      if ($env{'form.Status'} !~ /^(Any|Expired|Active|Future)$/) {
         $env{'form.Status'} = 'Active';          $env{'form.Status'} = 'Active';
     }      }
       my $onchange = "javascript:updateCols('Status');";
     my $status_select = &Apache::lonhtmlcommon::StatusOptions      my $status_select = &Apache::lonhtmlcommon::StatusOptions
         ($env{'form.Status'});          ($env{'form.Status'},undef,undef,$onchange);
   
     if ($env{'form.showrole'} eq '') {      if ($env{'form.showrole'} eq '') {
         if ($context eq 'course') {          if ($context eq 'course') {
Line 1447  sub print_userlist { Line 1479  sub print_userlist {
     $r->print('<form name="studentform" method="post" action="/adm/createuser">'."\n".      $r->print('<form name="studentform" method="post" action="/adm/createuser">'."\n".
               '<input type="hidden" name="action" value="'.                '<input type="hidden" name="action" value="'.
               $env{'form.action'}.'" />');                $env{'form.action'}.'" />');
     $r->print("<p>\n");      $r->print('<div>'."\n");
     if ($env{'form.action'} ne 'modifystudent') {      if ($env{'form.action'} ne 'modifystudent') {
         my %lt=&Apache::lonlocal::texthash('csv' => "CSV",          my %lt=&Apache::lonlocal::texthash('csv' => "CSV",
                                            'excel' => "Excel",                                             'excel' => "Excel",
                                            'html'  => 'HTML');                                             'html'  => 'HTML');
         my $output_selector = '<select size="1" name="output" >';          my $output_selector = '<select size="1" name="output" onchange="javascript:updateCols('."'output'".');" >';
         foreach my $outputformat ('html','csv','excel') {          foreach my $outputformat ('html','csv','excel') {
             my $option = '<option value="'.$outputformat.'"';              my $option = '<option value="'.$outputformat.'"';
             if ($outputformat eq $env{'form.output'}) {              if ($outputformat eq $env{'form.output'}) {
Line 1462  sub print_userlist { Line 1494  sub print_userlist {
             $output_selector .= "\n".$option;              $output_selector .= "\n".$option;
         }          }
         $output_selector .= '</select>';          $output_selector .= '</select>';
         $r->print('<label><span class="LC_nobreak">'          $r->print('<span class="LC_nobreak">'
                  .&mt('Output Format: [_1]',$output_selector)                   .&mt('Output Format: [_1]',$output_selector)
                  .'</span></label>'.('&nbsp;'x3));                   .'</span>'.('&nbsp;'x3));
     }      }
     $r->print('<label><span class="LC_nobreak">'      $r->print('<span class="LC_nobreak">'
              .&mt('User Status: [_1]',$status_select)               .&mt('User Status: [_1]',$status_select)
              .'</span></label>'.('&nbsp;'x3)."\n");               .'</span>'.('&nbsp;'x3)."\n");
     my $roleselected = '';      my $roleselected = '';
     if ($env{'form.showrole'} eq 'Any') {      if ($env{'form.showrole'} eq 'Any') {
        $roleselected = ' selected="selected"';          $roleselected = ' selected="selected"'; 
Line 1479  sub print_userlist { Line 1511  sub print_userlist {
         ($cnum,$cdom) = &get_course_identity();          ($cnum,$cdom) = &get_course_identity();
         $r->print(&section_group_filter($cnum,$cdom));          $r->print(&section_group_filter($cnum,$cdom));
     }      }
       $r->print('</div><div class="LC_left_float">'.
                 &column_checkboxes($context,$mode,$formname).
                 '</div><br clear="all" />');
     if ($env{'form.phase'} eq '') {      if ($env{'form.phase'} eq '') {
         $r->print('<br /><br />'.&list_submit_button(&mt('Display List of Users')).          $r->print(&list_submit_button(&mt('Display List of Users'))."\n".
                   "\n</p>\n".  
                   '<input type="hidden" name="phase" value="" /></form>');                    '<input type="hidden" name="phase" value="" /></form>');
         return;          return;
     }      }
     if (!(($context eq 'domain') &&       if (!(($context eq 'domain') && 
           (($env{'form.roletype'} eq 'course') || ($env{'form.roletype'} eq 'community')))) {            (($env{'form.roletype'} eq 'course') || ($env{'form.roletype'} eq 'community')))) {
         $r->print(          $r->print(&list_submit_button(&mt('Update Display'))."\n");
             "\n</p>\n"      }
            .'<p>'  
            .&list_submit_button(&mt('Update Display'))      my @cols = &infocolumns($context,$mode);  
            ."</p>\n"      if (!@cols) {
         );           $r->print('<hr /><span class="LC_warning">'.
                      &mt('No user information selected for display.').'</span>'.
                      '<input type="hidden" name="phase" value="display" /></form>'."\n");
            return;
     }      }
     my ($indexhash,$keylist) = &make_keylist_array();      my ($indexhash,$keylist) = &make_keylist_array();
     my (%userlist,%userinfo,$clearcoursepick);      my (%userlist,%userinfo,$clearcoursepick);
Line 1534  sub print_userlist { Line 1571  sub print_userlist {
             $r->print('<hr />'.&mt('Searching').' ...<br />&nbsp;<br />');              $r->print('<hr />'.&mt('Searching').' ...<br />&nbsp;<br />');
         }          }
     } else {      } else {
         $r->print('<hr />'.&mt('Searching').' ...<br />&nbsp;<br />');          $r->print('<hr /><div id="searching">'.&mt('Searching').' ...</div>');
     }      }
     $r->rflush();      $r->rflush();
     if ($context eq 'course') {      if ($context eq 'course') {
Line 1654  sub print_userlist { Line 1691  sub print_userlist {
         }          }
     }      }
     if (keys(%userlist) == 0) {      if (keys(%userlist) == 0) {
           my $msg = '';
         if ($context eq 'author') {          if ($context eq 'author') {
             $r->print(&mt('There are no co-authors to display.')."\n");              $msg = &mt('There are no co-authors to display.');
         } elsif ($context eq 'domain') {          } elsif ($context eq 'domain') {
             if ($env{'form.roletype'} eq 'domain') {              if ($env{'form.roletype'} eq 'domain') {
                 $r->print(&mt('There are no users with domain roles to display.')."\n");                  $msg = &mt('There are no users with domain roles to display.');
             } elsif ($env{'form.roletype'} eq 'author') {              } elsif ($env{'form.roletype'} eq 'author') {
                 $r->print(&mt('There are no authors or co-authors to display.')."\n");                  $msg = &mt('There are no authors or co-authors to display.');
             } elsif ($env{'form.roletype'} eq 'course') {              } elsif ($env{'form.roletype'} eq 'course') {
                 $r->print(&mt('There are no course users to display')."\n");                   $msg = &mt('There are no course users to display');
             } elsif ($env{'form.roletype'} eq 'community') {              } elsif ($env{'form.roletype'} eq 'community') {
                 $r->print(&mt('There are no community users to display')."\n");                  $msg = &mt('There are no community users to display');
             }              }
         } elsif ($context eq 'course') {          } elsif ($context eq 'course') {
             $r->print(&mt('There are no course users to display.')."\n");              $r->print(&mt('There are no course users to display.')."\n");
         }          }
           $r->print('<p class="LC_info"'.$msg.'</p>'."\n") if $msg;
     } else {      } else {
         # Print out the available choices          # Print out the available choices
         my $usercount;          my $usercount;
Line 1680  sub print_userlist { Line 1719  sub print_userlist {
                                $permission,$env{'form.Status'},\%userlist,$keylist);                                 $permission,$env{'form.Status'},\%userlist,$keylist);
         }          }
         if (!$usercount) {          if (!$usercount) {
             $r->print('<br /><span class="LC_warning">'              $r->print('<br /><span class="LC_info">'
                      .&mt('There are no users matching the search criteria.')                       .&mt('There are no users matching the search criteria.')
                      .'</span>'                       .'</span>'
             );               ); 
Line 1688  sub print_userlist { Line 1727  sub print_userlist {
     }      }
     $r->print('<input type="hidden" name="phase" value="'.      $r->print('<input type="hidden" name="phase" value="'.
               $env{'form.phase'}.'" /></form>');                $env{'form.phase'}.'" /></form>');
       return;
 }  }
   
 sub role_filter {  sub role_filter {
Line 1700  sub role_filter { Line 1740  sub role_filter {
     my ($role_select);      my ($role_select);
     if ($context eq 'domain') {      if ($context eq 'domain') {
         $role_select = &domain_roles_select();          $role_select = &domain_roles_select();
         $output = '<label><span class="LC_nobreak">'          $output = '<span class="LC_nobreak">'
                  .&mt('Role Type: [_1]',$role_select)                   .&mt('Role Type: [_1]',$role_select)
                  .'</span></label>';                   .'</span>';
     } else {      } else {
         $role_select = '<select name="showrole">'."\n".          $role_select = '<select name="showrole" onchange="javascript:updateCols('."'showrole'".');">'."\n".
                        '<option value="Any" '.$roleselected.'>'.                         '<option value="Any" '.$roleselected.'>'.
                        &mt('Any role').'</option>';                         &mt('Any role').'</option>';
         my ($roletype,$crstype);          my ($roletype,$crstype);
Line 1731  sub role_filter { Line 1771  sub role_filter {
             $role_select .= '<option value="'.$role.'"'.$roleselected.'>'.$plrole.'</option>';              $role_select .= '<option value="'.$role.'"'.$roleselected.'>'.$plrole.'</option>';
         }          }
         $role_select .= '</select>';          $role_select .= '</select>';
         $output = '<label><span class="LC_nobreak">'          $output = '<span class="LC_nobreak">'
                  .&mt('Role: [_1]',$role_select)                   .&mt('Role: [_1]',$role_select)
                  .'</span></label> ';                   .'</span>';
     }      }
     return $output;      return $output;
 }  }
Line 1796  sub section_group_filter { Line 1836  sub section_group_filter {
     return $output;      return $output;
 }  }
   
   sub infocolumns {
       my ($context,$mode) = @_;
       my @cols;
       if (($mode eq 'pickauthor') || ($mode eq 'autoenroll')) {
           @cols = &get_cols_array($context,$mode);
       } else {
           my @posscols = &get_cols_array($context,$mode);
           if ($env{'form.phase'} ne '') {
               my @checkedcols = &Apache::loncommon::get_env_multiple('form.showcol');
               foreach my $col (@checkedcols) {
                   if (grep(/^$col$/,@posscols)) {
                       push(@cols,$col);
                   }
               }
           } else {
               @cols = @posscols;
           }
       }
       return @cols;
   }
   
   sub get_cols_array {
       my ($context,$mode) = @_;
       my @cols;
       if ($mode eq 'pickauthor') {
           @cols = ('username','fullname','status','email');
       } else {
           @cols = ('username','domain','id','fullname');
           if ($context eq 'course') {
               push(@cols,'section');
           }
           push(@cols,('start','end','role'));
           if ($context eq 'domain') {
               push (@cols,'extent');
           }
           unless (($mode eq 'autoenroll') && ($env{'form.Status'} ne 'Any')) {
               push(@cols,'status');
           }
           if ($context eq 'course') {
               push(@cols,'groups');
           }
           push(@cols,'email');
           if (($context eq 'course') && ($mode ne 'autoenroll')) {
               push(@cols,'lastlogin','clicker');
           }
           if (($context eq 'course') && ($mode ne 'autoenroll') &&
               ($env{'course.'.$env{'request.course.id'}.'.internal.showphoto'})) {
               push(@cols,'photos');
           }
       }
       return @cols;
   }
   
   sub column_checkboxes {
       my ($context,$mode,$formname) = @_;
       my @cols = &get_cols_array($context,$mode);
       my @showncols = &Apache::loncommon::get_env_multiple('form.showcol');
       my (%disabledchk,%unchecked);
       if ($env{'form.phase'} eq '') {
           $disabledchk{'status'} = 1;
           if ($context eq 'course') {
               $disabledchk{'role'} = 1;
               $unchecked{'photo'} = 1;
           }
           $unchecked{'clicker'} = 1;
           $unchecked{'start'} = 1;
           $unchecked{'end'} = 1;
       } else {
           if ($env{'form.Status'} ne 'Any') {
               $disabledchk{'status'} = 1;
           }
           if ($env{'form.showrole'} ne 'Any') {
               $disabledchk{'role'} = 1; 
           }
       }
       my $numposs = scalar(@cols);
       my $numinrow = 8;
       my %lt = &get_column_names($context);
       my $output = '<fieldset><legend>'.&mt('Information to show').'</legend>'."\n".'<span class="LC_nobreak">'.
                    '<input type="button" onclick="javascript:checkAll(document.'.$formname.'.showcol);" value="'.&mt('check all').'" />'.
                    ('&nbsp;'x3).
                    '<input type="button" onclick="javascript:uncheckAll(document.'.$formname.'.showcol);" value="'.&mt('uncheck all').'" />'.
                    '</span><table>';
       
       for (my $i=0; $i<$numposs; $i++) {
           my $rem = $i%($numinrow);
           if ($rem == 0) {
               if ($i > 0) {
                   $output .= '</tr>';
               }
               $output .= '<tr>';
           }
           my $checked;
           if ($env{'form.phase'} eq '') {
               $checked = ' checked="checked"';
               if ($unchecked{$cols[$i]}) { 
                  $checked = '';
               }
               if ($disabledchk{$cols[$i]}) {
                   $checked = ' disabled="disabled"';
               }
           } elsif (grep(/^\Q$cols[$i]\E$/,@showncols)) {
               $checked = ' checked="checked"';
           } elsif ($disabledchk{$cols[$i]}) {
               $checked = ' disabled="disabled"';
           }
           if ($i == $numposs-1) {
               my $colsleft = $numinrow-$rem;
               if ($colsleft > 1) {
                   $output .= '<td colspan="'.$colsleft.'">';
               } else {
                   $output .= '<td>';
               }
           } else {
               $output .= '<td>';
           }
           $output .= '<label><input id="showcol'.$cols[$i].'" type="checkbox" name="showcol" value="'.$cols[$i].'"'.$checked.' />'.
                      $lt{$cols[$i]}.'</label></td>';
   
       }
       $output .= '</tr></table></fieldset>';
       return $output;
   }
   
 sub list_submit_button {  sub list_submit_button {
     my ($text) = @_;      my ($text) = @_;
     return '<input type="button" name="updatedisplay" value="'.$text.'" onclick="javascript:display_update()" />';      return '<input type="button" name="updatedisplay" value="'.$text.'" onclick="javascript:display_update()" />';
 }  }
   
   sub get_column_names {
       my ($context) = @_;
       my %lt = &Apache::lonlocal::texthash(
           'username'   => "username",
           'domain'     => "domain",
           'id'         => 'ID',
           'fullname'   => "name",
           'section'    => "section",
           'groups'     => "active groups",
           'start'      => "start date",
           'end'        => "end date",
           'status'     => "status",
           'role'       => "role",
           'type'       => "enroll type/action",
           'email'      => "e-mail address",
           'photo'      => "photo",
           'lastlogin'  => "last login",
           'extent'     => "extent",
           'ca'         => "check all",
           'ua'         => "uncheck all",
           'clicker'    => "clicker-ID",
       );
       if ($context eq 'domain' && $env{'form.roletype'} eq 'course') {
           $lt{'extent'} = &mt('Course(s): description, section(s), status');
       } elsif ($context eq 'domain' && $env{'form.roletype'} eq 'community') {
           $lt{'extent'} = &mt('Communities: description, section(s), status');
       } elsif ($context eq 'author') {
           $lt{'extent'} = &mt('Author');
       }
       return %lt;
   }
   
 sub gather_userinfo {  sub gather_userinfo {
     my ($context,$format,$userlist,$indexhash,$userinfo,$rolehash,$permission) = @_;      my ($context,$format,$userlist,$indexhash,$userinfo,$rolehash,$permission) = @_;
     my $viewablesec;      my $viewablesec;
Line 2164  sub show_users_list { Line 2360  sub show_users_list {
         $sortby = 'username';          $sortby = 'username';
     }      }
     my $setting = $env{'form.roletype'};      my $setting = $env{'form.roletype'};
     my ($cid,$cdom,$cnum,$classgroups,$displayphotos,$displayclickers,$crstype);      my ($cid,$cdom,$cnum,$classgroups,$crstype);
     if ($context eq 'course') {      if ($context eq 'course') {
         $cid = $env{'request.course.id'};          $cid = $env{'request.course.id'};
         $crstype = &Apache::loncommon::course_type();          $crstype = &Apache::loncommon::course_type();
Line 2174  sub show_users_list { Line 2370  sub show_users_list {
         if ($mode eq 'autoenroll') {          if ($mode eq 'autoenroll') {
             $env{'form.showrole'} = 'st';              $env{'form.showrole'} = 'st';
         } else {          } else {
             if (! exists($env{'form.displayphotos'})) {  
                 $env{'form.displayphotos'} = 'off';  
             }  
             $displayphotos = $env{'form.displayphotos'};  
             if (! exists($env{'form.displayclickers'})) {  
                 $env{'form.displayclickers'} = 'off';  
             }  
             $displayclickers = $env{'form.displayclickers'};  
             if ($env{'course.'.$cid.'.internal.showphoto'}) {              if ($env{'course.'.$cid.'.internal.showphoto'}) {
                 $r->print('                  $r->print('
 <script type="text/javascript">  <script type="text/javascript">
Line 2197  function photowindow(photolink) { Line 2385  function photowindow(photolink) {
 </script>  </script>
                ');                 ');
             }              }
             $r->print(<<END);  
 <input type="hidden" name="displayphotos" value="$displayphotos" />  
 <input type="hidden" name="displayclickers" value="$displayclickers" />  
 END  
         }          }
     } elsif ($context eq 'domain') {      } elsif ($context eq 'domain') {
         if ($setting eq 'community') {          if ($setting eq 'community') {
Line 2210  END Line 2394  END
         }          }
     }      }
     if ($mode ne 'autoenroll' && $mode ne 'pickauthor') {      if ($mode ne 'autoenroll' && $mode ne 'pickauthor') {
         my $check_uncheck_js = &Apache::loncommon::check_uncheck_jscript();  
         my $date_sec_selector = &date_section_javascript($context,$setting,$statusmode);          my $date_sec_selector = &date_section_javascript($context,$setting,$statusmode);
         my $verify_action_js = &bulkaction_javascript($formname);          my $verify_action_js = &bulkaction_javascript($formname);
         $r->print(<<END);          $r->print(<<END);
   
 <script type="text/javascript" language="Javascript">  <script type="text/javascript" language="Javascript">
 // <![CDATA[  // <![CDATA[
 $check_uncheck_js  
   
 $verify_action_js  $verify_action_js
   
Line 2275  END Line 2457  END
     $r->print(<<END);      $r->print(<<END);
 <input type="hidden" name="sortby" value="$sortby" />  <input type="hidden" name="sortby" value="$sortby" />
 END  END
       my @cols = &infocolumns($context,$mode);
     my %lt=&Apache::lonlocal::texthash(      my %coltxt = &get_column_names($context);
                        'username'   => "username",      my %acttxt = &Apache::lonlocal::texthash(
                        'domain'     => "domain",  
                        'id'         => 'ID',  
                        'fullname'   => "name",  
                        'section'    => "section",  
                        'groups'     => "active groups",  
                        'start'      => "start date",  
                        'end'        => "end date",  
                        'status'     => "status",  
                        'role'       => "role",  
                        'type'       => "enroll type/action",  
                        'email'      => "e-mail address",  
                        'photo'      => "photo",  
                        'extent'     => "extent",  
                        'pr'         => "Proceed",                         'pr'         => "Proceed",
                        'ca'         => "check all",  
                        'ua'         => "uncheck all",  
                        'ac'         => "Action to take for selected users",                         'ac'         => "Action to take for selected users",
                        'link'       => "Behavior of clickable username link for each user",                         'link'       => "Behavior of clickable username link for each user",
                        'aboutme'    => "Display a user's personal information page",                         'aboutme'    => "Display a user's personal information page",
                        'owin'       => "Open in a new window",                         'owin'       => "Open in a new window",
                        'modify'     => "Modify a user's information",                         'modify'     => "Modify a user's information",
                        'track'      => "View a user's recent activity",                         'track'      => "View a user's recent activity",
                        'clicker'    => "Clicker-ID",  
                       );                        );
     if ($context eq 'domain' && $env{'form.roletype'} eq 'course') {      my %lt = (%coltxt,%acttxt);
         $lt{'extent'} = &mt('Course(s): description, section(s), status');  
     } elsif ($context eq 'domain' && $env{'form.roletype'} eq 'community') {  
         $lt{'extent'} = &mt('Communities: description, section(s), status');  
     } elsif ($context eq 'author') {  
         $lt{'extent'} = &mt('Author');   
     }  
     my @cols;  
     if ($mode eq 'pickauthor') {  
         @cols = ('username','fullname','status','email');  
     } else {  
         @cols = ('username','domain','id','fullname');  
         if ($context eq 'course') {  
             push(@cols,'section');  
         }  
         if (!($context eq 'domain' && ($env{'form.roletype'} eq 'course')  
                               && ($env{'form.roletype'} eq 'community'))) {   
             push(@cols,('start','end'));  
         }  
         if ($env{'form.showrole'} eq 'Any' || $env{'form.showrole'} eq 'cr') {  
             push(@cols,'role');  
         }  
         if ($context eq 'domain' && ($env{'form.roletype'} eq 'author' ||  
                                     $env{'form.roletype'} eq 'course' ||  
                                     $env{'form.roletype'} eq 'community')) {  
             push (@cols,'extent');  
         }  
         if (($statusmode eq 'Any') &&   
             (!($context eq 'domain' && (($env{'form.roletype'} eq 'course')  
              || ($env{'form.roletype'} eq 'community'))))) {  
             push(@cols,'status');  
         }  
         if ($context eq 'course') {  
             push(@cols,'groups');  
         }  
         push(@cols,'email');  
     }  
   
     my $rolefilter = $env{'form.showrole'};      my $rolefilter = $env{'form.showrole'};
     if ($env{'form.showrole'} eq 'cr') {      if ($env{'form.showrole'} eq 'cr') {
         $rolefilter = &mt('custom');            $rolefilter = &mt('custom');  
Line 2350  END Line 2479  END
     if ($mode ne 'autoenroll') {      if ($mode ne 'autoenroll') {
         $results_description = &results_header_row($rolefilter,$statusmode,          $results_description = &results_header_row($rolefilter,$statusmode,
                                                    $context,$permission,$mode,$crstype);                                                     $context,$permission,$mode,$crstype);
         $r->print('<b>'.$results_description.'</b><br /><br />');          $r->print('<b>'.$results_description.'</b><br clear="all" />');
     }      }
     my ($output,$actionselect,%canchange,%canchangesec);      my ($output,$actionselect,%canchange,%canchangesec);
     if ($mode eq 'html' || $mode eq 'view' || $mode eq 'autoenroll' || $mode eq 'pickauthor') {      if ($mode eq 'html' || $mode eq 'view' || $mode eq 'autoenroll' || $mode eq 'pickauthor') {
Line 2412  END Line 2541  END
                             if (&Apache::lonnet::allowed('c'.$role,$env{'request.course.id'}.'/'.$env{'request.course.sec'})) {                              if (&Apache::lonnet::allowed('c'.$role,$env{'request.course.id'}.'/'.$env{'request.course.sec'})) {
                                 $canchangesec{$role} = $env{'request.course.sec'};                                  $canchangesec{$role} = $env{'request.course.sec'};
                             }                              }
                           } elsif ((($role eq 'co') && ($crstype eq 'Community')) ||
                                    (($role eq 'cc') && ($crstype eq 'Course'))) {
                               if (&is_courseowner($env{'request.course.id'},
                                                   $env{'course.'.$env{'request.course.id'}.'.internal.courseowner'})) {
                                   $canchange{$role} = 1;
                               }
                         }                          }
                     }                      }
                 }                  }
Line 2446  END Line 2581  END
             }              }
             $output .= '</td><td valign="top"  style="border-left: 1px solid;"><span class="LC_nobreak"><input type="checkbox" name="userwin" value="1"'.$checkwin.' />'.$lt{'owin'}.'</span></td></tr></table></fieldset></div>';              $output .= '</td><td valign="top"  style="border-left: 1px solid;"><span class="LC_nobreak"><input type="checkbox" name="userwin" value="1"'.$checkwin.' />'.$lt{'owin'}.'</span></td></tr></table></fieldset></div>';
         }          }
         $output .= "\n".'<div class="LC_clear_float_footer">&nbsp;</div>'."\n".          $output .= "\n".'<br clear="all" />'."\n".
                   &Apache::loncommon::start_data_table().                    &Apache::loncommon::start_data_table().
                   &Apache::loncommon::start_data_table_header_row();                    &Apache::loncommon::start_data_table_header_row();
         if ($mode eq 'autoenroll') {          if ($mode eq 'autoenroll') {
Line 2463  END Line 2598  END
             $output .= "<th><a href=\"javascript:document.$formname.sortby.value='$item';document.$formname.submit();\">$lt{$item}</a></th>\n";              $output .= "<th><a href=\"javascript:document.$formname.sortby.value='$item';document.$formname.submit();\">$lt{$item}</a></th>\n";
         }          }
         my %role_types = &role_type_names();          my %role_types = &role_type_names();
         if ($context eq 'course' && $mode ne 'autoenroll') {  
             if ($env{'form.showrole'} eq 'st' || $env{'form.showrole'} eq 'Any') {  
                 # Clicker display on or off?  
                 my %clicker_options = (  
                                         'on' => 'Show',  
                                         'off' => 'Hide',  
                                       );  
                 my $clickerchg = 'on';  
                 if ($displayclickers eq 'on') {  
                     $clickerchg = 'off';  
                 }  
                 $output .= '    <th>'."\n".'     '  
                         .&mt('[_1]'.$clicker_options{$clickerchg}.'[_2] clicker id'  
                             ,'<a href="javascript:document.'.$formname.'.displayclickers.value='  
                              ."'".$clickerchg."'".';document.'.$formname.'.submit();">'  
                             ,'</a>')  
                         ."\n".'    </th>'."\n";  
   
                 # Photo display on or off?  
                 if ($env{'course.'.$env{'request.course.id'}.'.internal.showphoto'}) {  
                     my %photo_options = &Apache::lonlocal::texthash(  
                                                             'on' => 'Show',  
                                                             'off' => 'Hide',  
                                                                 );  
                     my $photochg = 'on';  
                     if ($displayphotos eq 'on') {  
                         $photochg = 'off';  
                     }  
                     $output .= '    <th>'."\n".'     '.  
                 '<a href="javascript:document.'.$formname.'.displayphotos.value='.  
                       "'".$photochg."'".';document.'.$formname.'.submit();">'.  
                       $photo_options{$photochg}.'</a>&nbsp;'.$lt{'photo'}."\n".  
                       '    </th>'."\n";  
                 }  
             }  
         }  
         $output .= &Apache::loncommon::end_data_table_header_row();          $output .= &Apache::loncommon::end_data_table_header_row();
 # Done with the HTML header line  # Done with the HTML header line
     } elsif ($mode eq 'csv') {      } elsif ($mode eq 'csv') {
Line 2519  END Line 2618  END
             $CSVfile = undef;              $CSVfile = undef;
         }          }
         #          #
         push @cols,'clicker';  
         # Write headers and data to file          # Write headers and data to file
         print $CSVfile '"'.$results_description.'"'."\n";           print $CSVfile '"'.$results_description.'"'."\n"; 
         print $CSVfile '"'.join('","',map {          print $CSVfile '"'.join('","',map {
             &Apache::loncommon::csv_translate($lt{$_})              &Apache::loncommon::csv_translate($lt{$_})
             } (@cols))."\"\n";              } (@cols))."\"\n";
     } elsif ($mode eq 'excel') {      } elsif ($mode eq 'excel') {
         push @cols,'clicker';  
         # Create the excel spreadsheet          # Create the excel spreadsheet
         ($excel_workbook,$excel_filename,$format) =          ($excel_workbook,$excel_filename,$format) =
             &Apache::loncommon::create_workbook($r);              &Apache::loncommon::create_workbook($r);
Line 2562  END Line 2659  END
                                                 Future  => 'Future',                                                  Future  => 'Future',
                                                 Expired => 'Expired',                                                  Expired => 'Expired',
                                                );                                                 );
       # If this is for a single course get last course "log-in".
       my %crslogins;
       if ($context eq 'course') {
           %crslogins=&Apache::lonnet::dump('nohist_crslastlogin',$cdom,$cnum);
       }
     # Get groups, role, permanent e-mail so we can sort on them if      # Get groups, role, permanent e-mail so we can sort on them if
     # necessary.      # necessary.
     foreach my $user (keys(%{$userlist})) {      foreach my $user (keys(%{$userlist})) {
Line 2645  END Line 2747  END
                     }                      }
                 }                  }
                 if ($env{'course.'.$env{'request.course.id'}.'.internal.showphoto'}) {                  if ($env{'course.'.$env{'request.course.id'}.'.internal.showphoto'}) {
                     if (($displayphotos eq 'on') && ($role eq 'st')) {                      if ((grep/^photo$/,@cols) && ($role eq 'st')) {
                         $userlist->{$user}->[$index{'photo'}] =                          $userlist->{$user}->[$index{'photo'}] =
                             &Apache::lonnet::retrievestudentphoto($udom,$uname,'jpg');                              &Apache::lonnet::retrievestudentphoto($udom,$uname,'jpg');
                         $userlist->{$user}->[$index{'thumbnail'}] =                          $userlist->{$user}->[$index{'thumbnail'}] =
Line 2698  END Line 2800  END
         $in{'clicker'} = $clickers;           $in{'clicker'} = $clickers; 
  my $role = $in{'role'};   my $role = $in{'role'};
         $in{'role'}=&Apache::lonnet::plaintext($sdata->[$index{'role'}],$crstype);          $in{'role'}=&Apache::lonnet::plaintext($sdata->[$index{'role'}],$crstype);
         if (! defined($in{'start'}) || $in{'start'} == 0) {          unless ($mode eq 'excel') {
             $in{'start'} = &mt('none');              if (! defined($in{'start'}) || $in{'start'} == 0) {
         } else {                  $in{'start'} = &mt('none');
             $in{'start'} = &Apache::lonlocal::locallocaltime($in{'start'});              } else {
                   $in{'start'} = &Apache::lonlocal::locallocaltime($in{'start'});
               }
               if (! defined($in{'end'}) || $in{'end'} == 0) {
                   $in{'end'} = &mt('none');
               } else {
                   $in{'end'} = &Apache::lonlocal::locallocaltime($in{'end'});
               }
         }          }
         if (! defined($in{'end'}) || $in{'end'} == 0) {          if ($context eq 'course') {
             $in{'end'} = &mt('none');              my $lastlogin = $crslogins{$in{'username'}.':'.$in{'domain'}.':'.$in{'section'}.':'.$role};
         } else {              if ($lastlogin ne '') {
             $in{'end'} = &Apache::lonlocal::locallocaltime($in{'end'});                  $in{'lastlogin'} = &Apache::lonlocal::locallocaltime($lastlogin);
               }
         }          }
         if ($mode eq 'view' || $mode eq 'html' || $mode eq 'autoenroll' || $mode eq 'pickauthor') {          if ($mode eq 'view' || $mode eq 'html' || $mode eq 'autoenroll' || $mode eq 'pickauthor') {
             $r->print(&Apache::loncommon::start_data_table_row());              $r->print(&Apache::loncommon::start_data_table_row());
Line 2752  END Line 2862  END
                     if ($showcheckbox) {                      if ($showcheckbox) {
                         $checkval = $user;                           $checkval = $user; 
                         if ($context eq 'course') {                          if ($context eq 'course') {
                             if ($role eq 'st') {                              if (($role eq 'co' || $role eq 'cc') &&
                                 $checkval .= ':st';                                  ($user =~ /^\Q$env{'user.name'}:$env{'user.domain'}:$role\E/)) {
                             }                                  $showcheckbox = 0;
                             $checkval .= ':'.$in{'section'};                              } else {
                             if ($role eq 'st') {                                  if ($role eq 'st') {
                                 $checkval .= ':'.$in{'type'}.':'.                                      $checkval .= ':st';
                                              $in{'lockedtype'};                                  }
                             }                                  $checkval .= ':'.$in{'section'};
                                   if ($role eq 'st') {
                                       $checkval .= ':'.$in{'type'}.':'.
                                                    $in{'lockedtype'};
                                   }
                                }
                           }
                           if ($showcheckbox) {
                               $r->print('<td><input type="checkbox" name="'.
                                         'actionlist" value="'.$checkval.'" /></td>');
                           } else {
                               $r->print('<td>&nbsp;</td>');
                         }                          }
                         $r->print('<td><input type="checkbox" name="'.  
                                   'actionlist" value="'.$checkval.'" /></td>');  
                     } else {                      } else {
                         $r->print('<td>&nbsp;</td>');                          $r->print('<td>&nbsp;</td>');
                     }                      }
Line 2781  END Line 2900  END
                         $showitem = $ltstatus{$in{$item}};                          $showitem = $ltstatus{$in{$item}};
                     }                      }
                     $r->print('<td>'.$showitem.'</td>'."\n");                      $r->print('<td>'.$showitem.'</td>'."\n");
                 } else {                  } elsif ($item eq 'photo') {
                     $r->print('<td>'.$in{$item}.'</td>'."\n");                       if (($context eq 'course') && ($mode ne 'autoenroll') && 
                 }                           ($env{'course.'.$env{'request.course.id'}.'.internal.showphoto'})) { 
             }                           if ($role eq 'st') {
             if (($context eq 'course') && ($mode ne 'autoenroll')) {                               $r->print('<td align="right"><a href="javascript:photowindow('."'".$in{'photo'}."'".')"><img src="'.$in{'thumbnail'}.'" border="1" alt="" /></a></td>');
                 if ($env{'form.showrole'} eq 'st' || $env{'form.showrole'} eq 'Any') {                           } else {
                     if ($displayclickers eq 'on') {                               $r->print('<td>&nbsp;</td>');
                         my $clickers =                           }
                        }
                   } elsif ($item eq 'clicker') {
                       if (($context eq 'course') && ($mode ne 'autoenroll')) {
                           if ($env{'form.showrole'} eq 'st' || $env{'form.showrole'} eq 'Any') {
                               my $clickers =
                    (&Apache::lonnet::userenvironment($in{'domain'},$in{'username'},'clickers'))[1];                     (&Apache::lonnet::userenvironment($in{'domain'},$in{'username'},'clickers'))[1];
                         if ($clickers!~/\w/) { $clickers='-'; }                              if ($clickers!~/\w/) { $clickers='-'; }
                         $r->print('<td>'.$clickers.'</td>');                              $r->print('<td>'.$clickers.'</td>');
                     } else {  
                         $r->print('    <td>&nbsp;</td>  ');  
                     }  
                     if ($env{'course.'.$env{'request.course.id'}.'.internal.showphoto'}) {  
                         if ($displayphotos eq 'on' && $role eq 'st' && $in{'photo'} ne '') {  
                             $r->print('    <td align="right"><a href="javascript:photowindow('."'".$in{'photo'}."'".')"><img src="'.$in{'thumbnail'}.'" border="1" alt="" /></a></td>');  
                         } else {                          } else {
                             $r->print('    <td>&nbsp;</td>  ');                               $r->print('<td>&nbsp;</td>'."\n");
                         }                          } 
                     }                      } 
                   } else {
                       $r->print('<td>'.$in{$item}.'</td>'."\n");
                 }                  }
             }              }
             $r->print(&Apache::loncommon::end_data_table_row());              $r->print(&Apache::loncommon::end_data_table_row());
         } elsif ($mode eq 'csv') {          } elsif ($mode eq 'csv') {
             next if (! defined($CSVfile));              next if (! defined($CSVfile));
             # no need to bother with $linkto              # no need to bother with $linkto
             if (! defined($in{'start'}) || $in{'start'} == 0) {  
                 $in{'start'} = &mt('none');  
             } else {  
                 $in{'start'} = &Apache::lonlocal::locallocaltime($in{'start'});  
             }  
             if (! defined($in{'end'}) || $in{'end'} == 0) {  
                 $in{'end'} = &mt('none');  
             } else {  
                 $in{'end'} = &Apache::lonlocal::locallocaltime($in{'end'});  
             }  
             my @line = ();              my @line = ();
             foreach my $item (@cols) {              foreach my $item (@cols) {
                 push @line,&Apache::loncommon::csv_translate($in{$item});                  push @line,&Apache::loncommon::csv_translate($in{$item});
Line 2827  END Line 2937  END
             my $col = 0;              my $col = 0;
             foreach my $item (@cols) {              foreach my $item (@cols) {
                 if ($item eq 'start' || $item eq 'end') {                  if ($item eq 'start' || $item eq 'end') {
                     if (defined($item) && $item != 0) {                      if ((defined($in{$item})) && ($in{$item} != 0)) {
                         $excel_sheet->write($row,$col++,                          $excel_sheet->write($row,$col++,
                             &Apache::lonstathelpers::calc_serial($in{item}),                              &Apache::lonstathelpers::calc_serial($in{$item}),
                                     $format->{'date'});                                      $format->{'date'});
                     } else {                      } else {
                         $excel_sheet->write($row,$col++,'none');                          $excel_sheet->write($row,$col++,'none');
Line 3017  sub select_actions { Line 3127  sub select_actions {
     }      }
     if ($context eq 'course') {      if ($context eq 'course') {
         if ($env{'form.showrole'} ne 'Any') {          if ($env{'form.showrole'} ne 'Any') {
              if (!&Apache::lonnet::allowed('c'.$env{'form.showrole'},              my $showactions;
                                            $env{'request.course.id'})) {              if (&Apache::lonnet::allowed('c'.$env{'form.showrole'},
                  if ($env{'request.course.sec'} eq '') {                                            $env{'request.course.id'})) {
                      return;                  $showactions = 1;  
                  } else {              } elsif ($env{'request.course.sec'} ne '') {
                      if (!&Apache::lonnet::allowed('c'.$env{'form.showrole'},$env{'request.course.id'}.'/'.$env{'request.course.sec'})) {                  if (&Apache::lonnet::allowed('c'.$env{'form.showrole'},$env{'request.course.id'}.'/'.$env{'request.course.sec'})) {
                          return;                      $showactions = 1;
                      }                  }
                  }              }
               unless ($showactions) {
                   unless (&is_courseowner($env{'request.course.id'},
                                          $env{'course.'.$env{'request.course.id'}.'.internal.courseowner'})) {
                       return; 
                   }
             }              }
         }          }
     }      }
Line 3969  sub upfile_drop_add { Line 4084  sub upfile_drop_add {
                             official   => 'Institutional',                              official   => 'Institutional',
                             unofficial => 'Non-institutional',                              unofficial => 'Non-institutional',
                         );                          );
         map { $cancreate{$_} = &can_create_user($domain,$context,$_); } keys(%longtypes);          my $newuserdom = $env{'request.role.domain'};
           map { $cancreate{$_} = &can_create_user($newuserdom,$context,$_); } keys(%longtypes);
         # Get new users list          # Get new users list
         foreach my $line (@userdata) {          foreach my $line (@userdata) {
             my @secs;              my @secs;
Line 4124  sub upfile_drop_add { Line 4240  sub upfile_drop_add {
                     my (%rulematch,%inst_results,%idinst_results);                      my (%rulematch,%inst_results,%idinst_results);
                     my $uhome=&Apache::lonnet::homeserver($username,$userdomain);                      my $uhome=&Apache::lonnet::homeserver($username,$userdomain);
                     if ($uhome eq 'no_host') {                      if ($uhome eq 'no_host') {
                         if ($userdomain ne $domain) {                          if ($userdomain ne $newuserdom) {
                             $r->print('<br />'.                              if ($context eq 'course') {
                                 &mt('[_1]: The domain specified ([_2]) is different to that of the course.',                                  $r->print('<br />'.
                                     '<b>'.$username.'</b>',$userdomain).'<br />'.                                            &mt('[_1]: The domain specified ([_2]) is different to that of the course.',
                                 &mt('The user does not already exist, and you may not create a new user in a different domain.'));                                            '<b>'.$username.'</b>',$userdomain).'<br />');
                               } elsif ($context eq 'author') {
                                   $r->print(&mt('[_1]: The domain specified ([_2]) is different to that of the author.',
                                           '<b>'.$username.'</b>',$userdomain).'<br />'); 
                               } else {
                                   $r->print(&mt('[_1]: The domain specified ([_2]) is different to that of your current role.',
                                           '<b>'.$username.'</b>',$userdomain).'<br />');
                               }
                               $r->print(&mt('The user does not already exist, and you may not create a new user in a different domain.'));
                             next;                              next;
                         }                          }
                         $checkid = 1;                          $checkid = 1;
                         $newuser = 1;                          $newuser = 1;
                         my $user = $username.':'.$domain;                          my $user = $username.':'.$newuserdom;
                         my $checkhash;                          my $checkhash;
                         my $checks = { 'username' => 1 };                          my $checks = { 'username' => 1 };
                         $checkhash->{$username.':'.$domain} = { 'newuser' => 1, };                          $checkhash->{$username.':'.$newuserdom} = { 'newuser' => 1, };
                         &Apache::loncommon::user_rule_check($checkhash,$checks,                          &Apache::loncommon::user_rule_check($checkhash,$checks,
                             \%alerts,\%rulematch,\%inst_results,\%curr_rules,                              \%alerts,\%rulematch,\%inst_results,\%curr_rules,
                             \%got_rules);                              \%got_rules);
                         if (ref($alerts{'username'}) eq 'HASH') {                          if (ref($alerts{'username'}) eq 'HASH') {
                             if (ref($alerts{'username'}{$domain}) eq 'HASH') {                              if (ref($alerts{'username'}{$newuserdom}) eq 'HASH') {
                                 if ($alerts{'username'}{$domain}{$username}) {                                  if ($alerts{'username'}{$newuserdom}{$username}) {
                                     $r->print('<br />'.                                      $r->print('<br />'.
                                               &mt('[_1]: matches the username format at your institution, but is not known to your directory service.','<b>'.$username.'</b>').'<br />'.                                                &mt('[_1]: matches the username format at your institution, but is not known to your directory service.','<b>'.$username.'</b>').'<br />'.
                                               &mt('Consequently, the user was not created.'));                                                &mt('Consequently, the user was not created.'));
Line 4159  sub upfile_drop_add { Line 4283  sub upfile_drop_add {
                         unless ($cancreate{$usertype}) {                          unless ($cancreate{$usertype}) {
                             my $showtype = $longtypes{$usertype};                              my $showtype = $longtypes{$usertype};
                             $r->print('<br />'.                              $r->print('<br />'.
                                       &mt("[_1]: The user does not exist, and you are not permitted to create users of type: $showtype.",'<b>'.$username.'</b>'));                                        &mt('[_1]: The user does not exist, and you are not permitted to create users of type: [_2].','<b>'.$username.'</b>',$showtype));
                             next;                              next;
                         }                          }
                     } else {                      } else {
Line 5240  sub can_modify_userinfo { Line 5364  sub can_modify_userinfo {
 }  }
   
 sub check_usertype {  sub check_usertype {
     my ($dom,$uname,$rules) = @_;      my ($dom,$uname,$rules,$curr_rules,$got_rules) = @_;
     my $usertype;      my $usertype;
     if (ref($rules) eq 'HASH') {      if ((ref($got_rules) eq 'HASH') && (ref($curr_rules) eq 'HASH')) {
         my @user_rules = keys(%{$rules});          if (!$got_rules->{$dom}) {
         if (@user_rules > 0) {              my %domconfig = &Apache::lonnet::get_dom('configuration',
             my %rule_check = &Apache::lonnet::inst_rulecheck($dom,$uname,undef,'username',\@user_rules);                                                ['usercreation'],$dom);
             if (keys(%rule_check) > 0) {              if (ref($domconfig{'usercreation'}) eq 'HASH') {
                 $usertype = 'unofficial';                  foreach my $item ('username','id') {
                 foreach my $item (keys(%rule_check)) {                      if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
                     if ($rule_check{$item}) {                          $curr_rules->{$dom}{$item} =
                         $usertype = 'official';                                  $domconfig{'usercreation'}{$item.'_rule'};
                         last;                      }
                   }
               }
               $got_rules->{$dom} = 1;
           }
           if (ref($rules) eq 'HASH') {
               my @user_rules;
               if (ref($curr_rules->{$dom}{'username'}) eq 'ARRAY') {
                   foreach my $rule (keys(%{$rules})) {
                       if (grep(/^\Q$rule\E/,@{$curr_rules->{$dom}{'username'}})) {
                           push(@user_rules,$rule);
                       }
                   } 
               }
               if (@user_rules > 0) {
                   my %rule_check = &Apache::lonnet::inst_rulecheck($dom,$uname,undef,'username',\@user_rules);
                   if (keys(%rule_check) > 0) {
                       $usertype = 'unofficial';
                       foreach my $item (keys(%rule_check)) {
                           if ($rule_check{$item}) {
                               $usertype = 'official';
                               last;
                           }
                     }                      }
                 }                  }
             }              }
Line 5627  sub authcheck_alerts { Line 5773  sub authcheck_alerts {
     return %alerts;      return %alerts;
 }  }
   
   sub is_courseowner {
       my ($thiscourse,$courseowner) = @_;
       if ($courseowner eq '') {
           if ($env{'request.course.id'} eq $thiscourse) {
               $courseowner = $env{'course.'.$env{'request.course.id'}.'.internal.courseowner'};
           }
       }
       if ($courseowner ne '') {
           if ($courseowner eq $env{'user.name'}.':'.$env{'user.domain'}) {
               return 1;
           }
       }
       return;
   }
   
 1;  1;
   

Removed from v.1.131  
changed lines
  Added in v.1.142


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