Diff for /loncom/interface/lonuserutils.pm between versions 1.2 and 1.6

version 1.2, 2007/11/06 04:39:19 version 1.6, 2007/12/01 03:48:20
Line 85  sub modifystudent { Line 85  sub modifystudent {
 sub modifyuserrole {  sub modifyuserrole {
     my ($context,$setting,$changeauth,$cid,$udom,$uname,$uid,$umode,$upass,      my ($context,$setting,$changeauth,$cid,$udom,$uname,$uid,$umode,$upass,
         $first,$middle,$last,$gene,$sec,$forceid,$desiredhome,$email,$role,          $first,$middle,$last,$gene,$sec,$forceid,$desiredhome,$email,$role,
         $end,$start) = @_;          $end,$start,$checkid) = @_;
     my ($scope,$userresult,$authresult,$roleresult);      my ($scope,$userresult,$authresult,$roleresult,$idresult);
     if ($setting eq 'course' || $context eq 'course') {      if ($setting eq 'course' || $context eq 'course') {
         $scope = '/'.$cid;          $scope = '/'.$cid;
         $scope =~ s/\_/\//g;          $scope =~ s/\_/\//g;
         if ($role ne 'cc' && $sec ne '') {          if ($role ne 'cc' && $sec ne '') {
             $scope .='/'.$sec;              $scope .='/'.$sec;
         }          }
     } elsif ($setting eq 'domain') {      } elsif ($context eq 'domain') {
         $scope = '/'.$env{'request.role.domain'}.'/';          $scope = '/'.$env{'request.role.domain'}.'/';
     } elsif ($setting eq 'construction_space') {      } elsif ($context eq 'construction_space') {
         $scope =  '/'.$env{'user.domain'}.'/'.$env{'user.name'};          $scope =  '/'.$env{'user.domain'}.'/'.$env{'user.name'};
     }      }
     if ($context eq 'domain') {      if ($context eq 'domain') {
         my $uhome = &Apache::lonnet::homeserver($uname,$udom);          my $uhome = &Apache::lonnet::homeserver($uname,$udom);
         if ($uhome ne 'no_host') {          if ($uhome ne 'no_host') {
             if (($changeauth) && (&Apache::lonnet::allowed('mau',$udom))) {              if (($changeauth eq 'Yes') && (&Apache::lonnet::allowed('mau',$udom))) {
                 if ((($umode =~ /^krb4|krb5|internal$/) && $upass ne '') ||                  if ((($umode =~ /^krb4|krb5|internal$/) && $upass ne '') ||
                     ($umode eq 'localauth')) {                      ($umode eq 'localauth')) {
                     $authresult = &Apache::lonnet::modifyuserauth($udom,$uname,$umode,$upass);                      $authresult = &Apache::lonnet::modifyuserauth($udom,$uname,$umode,$upass);
                 }                  }
             }              }
               if (($forceid) && (&Apache::lonnet::allowed('mau',$udom)) &&
                   ($env{'form.recurseid'}) && ($checkid)) {
                   my %userupdate = (
                                     lastname   => $last,
                                     middlename => $middle,
                                     firstname  => $first,
                                     generation => $gene,
                                     id         => $uid,
                                    );
                   $idresult = &propagate_id_change($uname,$udom,\%userupdate);
               }
         }          }
     }      }
     $userresult =      $userresult =
Line 114  sub modifyuserrole { Line 125  sub modifyuserrole {
                                     $middle,$last,$gene,$forceid,$desiredhome,                                      $middle,$last,$gene,$forceid,$desiredhome,
                                     $email,$role,$start,$end);                                      $email,$role,$start,$end);
     if ($userresult eq 'ok') {      if ($userresult eq 'ok') {
         if ($role ne '') {           if ($role ne '') {
             $roleresult = &Apache::lonnet::assignrole($udom,$uname,$scope,              $roleresult = &Apache::lonnet::assignrole($udom,$uname,$scope,
                                                       $role,$end,$start);                                                        $role,$end,$start);
         }          }
     }      }
     return ($userresult,$authresult,$roleresult);      return ($userresult,$authresult,$roleresult,$idresult);
   }
   
   sub propagate_id_change {
       my ($uname,$udom,$user) = @_;
       my (@types,@roles,@cdoms);
       @types = ('active','future');
       @roles = ('st');
       my $idresult;
       my %roleshash = &Apache::lonnet::get_my_roles($uname,
                           $udom,'userroles',\@types,\@roles,\@cdoms);
       foreach my $item (keys(%roleshash)) {
           my ($cnum,$cdom,$role) = split(/:/,$item);
           my ($start,$end) = split(/:/,$roleshash{$item});
           if (&Apache::lonnet::is_course($cdom,$cnum)) {
               my %userupdate;
               my $result = &update_classlist($cdom,$cnum,$udom,$uname,\%userupdate);
               if ($result eq 'ok') {
                   $idresult .= "Classlist change: $uname:$udom - class -> $cnum:$cdom\n";
               } else {
                   $idresult .= "Error - $result -during classlist update for $uname:$udom in $cnum:$cdom\n";
               }
           }
       }
       return $idresult;
 }  }
   
   sub update_classlist {
       my ($cdom,$cnum,$udom,$uname,$user) = @_;
       my ($uid,$classlistentry);
       my $fullname =
           &Apache::lonnet::format_name($user->{'firstname'},$user->{'middlename'},
                                        $user->{'lastname'},$user->{'generation'},
                                        'lastname');
       my %classhash = &Apache::lonnet::get('classlist',[$uname.':'.$udom],
                                            $cdom,$cnum);
       my @classinfo = split(/:/,$classhash{$uname.':'.$udom});
       my $ididx=&Apache::loncoursedata::CL_ID() - 2;
       my $nameidx=&Apache::loncoursedata::CL_FULLNAME() - 2;
       for (my $i=0; $i<@classinfo; $i++) {
           if ($i == $ididx) {
               if (defined($user->{'id'})) {
                   $classlistentry .= $user->{'id'}.':';
               } else {
                   $classlistentry .= $classinfo[$i].':';
               }
           } elsif ($i == $nameidx) {
               $classlistentry .= $fullname.':';
           } else {
               $classlistentry .= $classinfo[$i].':';
           }
       }
       $classlistentry =~ s/:$//;
       my $reply=&Apache::lonnet::cput('classlist',
                                       {"$uname:$udom" => $classlistentry},
                                       $cdom,$cnum);
       if (($reply eq 'ok') || ($reply eq 'delayed')) {
           return 'ok';
       } else {
           return 'error: '.$reply;
       }
   }
   
   
 ###############################################################  ###############################################################
 ###############################################################  ###############################################################
 # build a role type and role selection form  # build a role type and role selection form
Line 156  sub domain_roles_select { Line 228  sub domain_roles_select {
             @roles = &construction_space_roles();              @roles = &construction_space_roles();
         } else {          } else {
             @roles = &course_roles('domain');              @roles = &course_roles('domain');
               unshift(@roles,'cr');
         }          }
         my $order = ['Any',@roles];          my $order = ['Any',@roles];
         $select_menus{$roletype}->{'order'} = $order;           $select_menus{$roletype}->{'order'} = $order; 
         foreach my $role (@roles) {          foreach my $role (@roles) {
             $select_menus{$roletype}->{'select2'}->{$role} =               if ($role eq 'cr') {
                           &Apache::lonnet::plaintext($role);                  $select_menus{$roletype}->{'select2'}->{$role} =
                                 &mt('Custom role');
               } else {
                   $select_menus{$roletype}->{'select2'}->{$role} = 
                                 &Apache::lonnet::plaintext($role);
               }
         }          }
         $select_menus{$roletype}->{'select2'}->{'Any'} = &mt('Any');          $select_menus{$roletype}->{'select2'}->{'Any'} = &mt('Any');
     }      }
Line 637  sub print_upload_manager_footer { Line 715  sub print_upload_manager_footer {
     my ($options,$cb_script,$coursepick) = &default_role_selector($context,'defaultrole',1);      my ($options,$cb_script,$coursepick) = &default_role_selector($context,'defaultrole',1);
     if ($context eq 'domain') {      if ($context eq 'domain') {
         $Str .= '<span class="LC_role_level">'.&mt('Domain Level').'</span><br />'.$options.'<br /><br /><span class="LC_role_level">'.&mt('Course Level').'</span><br />'.$cb_script.$coursepick;          $Str .= '<span class="LC_role_level">'.&mt('Domain Level').'</span><br />'.$options.'<br /><br /><span class="LC_role_level">'.&mt('Course Level').'</span><br />'.$cb_script.$coursepick;
     } else {      } elsif ($context eq 'construction_space') {
         $Str .= $options;          $Str .= $options;
       } else {
           $Str .= '<table><tr><td><span class="LC_nobreak"<b>'.&mt('role').':&nbsp;</b>'.
                   $options.'</span></td><td>&nbsp;</td><td><span class="LC_nobreak">'.
                   '<b>'.&mt('section').':&nbsp;</b><input type="text" name="section" value="" size="12" /></span></td></tr></table>';
     }      }
     if ($context eq 'course') {      if ($context eq 'course') {
         $Str .= "<h3>".&mt('Full Update')."</h3>\n".          $Str .= "<h3>".&mt('Full Update')."</h3>\n".
Line 646  sub print_upload_manager_footer { Line 728  sub print_upload_manager_footer {
                 ' '.&mt('Full update (also print list of users not enrolled anymore)').                  ' '.&mt('Full update (also print list of users not enrolled anymore)').
                 "</label></p>\n";                  "</label></p>\n";
     }      }
     $Str .= "<h3>".&mt('ID/Student Number')."</h3>\n";      if ($context eq 'course' || $context eq 'domain') {
     $Str .= "<p>\n".'<label><input type="checkbox" name="forceid" value="yes">';          $Str .= &forceid_change($context);
     $Str .= &mt('Disable ID/Student Number Safeguard and Force Change '.      }
                 'of Conflicting IDs').  
                 '</label><br />'."\n".  
                 &mt('(only do if you know what you are doing.)')."</p><p>\n";  
     $Str .= '</div><div class="LC_clear_float_footer"><br /><input type="button"'.      $Str .= '</div><div class="LC_clear_float_footer"><br /><input type="button"'.
               'onClick="javascript:verify(this.form,this.form.csec)" '.                'onClick="javascript:verify(this.form,this.form.csec)" '.
         'value="Update Users" />'."<br />\n";          'value="Update Users" />'."<br />\n";
Line 664  sub print_upload_manager_footer { Line 743  sub print_upload_manager_footer {
     return;      return;
 }  }
   
   sub forceid_change {
       my ($context) = @_;
       my $output = 
           "<h3>".&mt('ID/Student Number')."</h3>\n".
           "<p>\n".'<label><input type="checkbox" name="forceid" value="yes">'.
           &mt('Disable ID/Student Number Safeguard and Force Change '.
           'of Conflicting IDs').'</label><br />'."\n".
           &mt('(only do if you know what you are doing.)')."</br><br />\n";
       if ($context eq 'domain') {
           $output .= '<label><input type="checkbox" name="recurseid"'.
                      ' value="yes">'. 
     &mt('Update ID/Student Number in courses in which user is an Active or Future student, (if forcing change).').
                      '</label></p>'."\n";
       }
       return $output;
   }
   
 ###############################################################  ###############################################################
 ###############################################################  ###############################################################
 sub print_upload_manager_form {  sub print_upload_manager_form {
Line 1130  sub print_userlist { Line 1226  sub print_userlist {
     }      }
     my ($indexhash,$keylist) = &make_keylist_array();      my ($indexhash,$keylist) = &make_keylist_array();
     my (%userlist,%userinfo);      my (%userlist,%userinfo);
       if ($context eq 'domain' && $env{'form.roletype'} eq 'course') {
           my $courseform =
               &Apache::lonhtmlcommon::course_selection($formname,$totcodes,
                                            $codetitles,$idlist,$idlist_titles);
           $r->print('<p>'.&Apache::lonhtmlcommon::start_pick_box()."\n".
                     &Apache::lonhtmlcommon::start_pick_box()."\n".
                     &Apache::lonhtmlcommon::row_title(&mt('Select Course(s)'),
                                                       'LC_oddrow_value')."\n".
                     $courseform."\n".
                     &Apache::lonhtmlcommon::row_closure(1).
                     &Apache::lonhtmlcommon::end_pick_box().'</p>'.
                     '<p>'.&list_submit_button(&mt('Update Display')).
                     "\n</p>\n");
       }
       $r->print('<hr />'.&mt('Searching').' ...<br />&nbsp;<br />');
       $r->rflush();
     if ($context eq 'course') {      if ($context eq 'course') {
         #          my $classlist = &Apache::loncoursedata::get_classlist();
         # Print the userlist          my $secidx = &Apache::loncoursedata::CL_SECTION();
         $r->print('<h2>'.&mt('Current User List').'</h2>');          foreach my $student (keys(%{$classlist})) {
         (my $classlist,$keylist)=&Apache::loncoursedata::get_classlist();              if (exists($permission->{'view_section'})) {
                   if ($classlist->{$student}[$secidx] ne $permission->{'view_section'}) {
         if (exists($permission->{'view_section'})) {                      next;
             my $sec = &Apache::loncoursedata::CL_SECTION();                  } else {
             foreach my $student (keys(%{$classlist})) {                      $userlist{$student} = $classlist->{$student};
                 if ($userlist{$student}[$sec] ne $permission->{'view_section'}) {  
                     delete($userlist{$student});  
                 }                  }
               } else {
                   $userlist{$student} = $classlist->{$student};
             }              }
         }          }
         foreach my $item (keys(%{$classlist})) {  
             $userlist{$item} = $classlist->{$item};  
         }  
         my $cid =$env{'request.course.id'};          my $cid =$env{'request.course.id'};
         my $cdom=$env{'course.'.$cid.'.domain'};          my $cdom=$env{'course.'.$cid.'.domain'};
         my $cnum=$env{'course.'.$cid.'.num'};          my $cnum=$env{'course.'.$cid.'.num'};
Line 1206  sub print_userlist { Line 1315  sub print_userlist {
                     }                      }
                 }                  }
             } elsif ($env{'form.roletype'} eq 'course') {              } elsif ($env{'form.roletype'} eq 'course') {
                 my $courseform =   
                     &Apache::lonhtmlcommon::course_selection($formname,$totcodes,  
                                            $codetitles,$idlist,$idlist_titles);  
                 my $output='<p>'.&Apache::lonhtmlcommon::start_pick_box()."\n".  
                            &Apache::lonhtmlcommon::start_pick_box()."\n".  
                      &Apache::lonhtmlcommon::row_title(&mt('Select Course(s)'),  
                                                        'LC_oddrow_value')."\n".  
                            $courseform."\n".  
                            &Apache::lonhtmlcommon::row_closure(1).  
                            &Apache::lonhtmlcommon::end_pick_box().'</p>';  
                 $r->print($output);  
                 $r->print('<p>'.&list_submit_button(&mt('Update Display')).  
                           "\n</p>\n");  
                 if ($env{'form.coursepick'}) {                  if ($env{'form.coursepick'}) {
                     my %courses = &process_coursepick();                      my %courses = &process_coursepick();
                     my %allusers;                       my %allusers; 
Line 1229  sub print_userlist { Line 1325  sub print_userlist {
                         my $cnum = $coursehash{'num'};                          my $cnum = $coursehash{'num'};
                         my $cdesc = $coursehash{'description'};                          my $cdesc = $coursehash{'description'};
                         my (@roles,@sections,%access,%users,%userdata,                          my (@roles,@sections,%access,%users,%userdata,
                             %users,%statushash);                              %statushash);
                         if ($env{'form.showrole'} eq 'Any') {                          if ($env{'form.showrole'} eq 'Any') {
                             @roles = &course_roles($context);                              @roles = &course_roles($context);
                               unshift(@roles,'cr');
                         } else {                          } else {
                             @roles = ($env{'form.showrole'});                              @roles = ($env{'form.showrole'});
                         }                          }
Line 1264  sub print_userlist { Line 1361  sub print_userlist {
                 }                  }
             }              }
         }          }
         if (keys(%userlist) == 0) {      }
             if ($context eq 'construction_space') {      if (keys(%userlist) == 0) {
                 $r->print(&mt('There are no co-authors to display.')."\n");          if ($context eq 'construction_space') {
             } elsif ($context eq 'domain') {              $r->print(&mt('There are no co-authors to display.')."\n");
                 if ($env{'form.roletype'} eq 'domain') {          } elsif ($context eq 'domain') {
                     $r->print(&mt('There are no users with domain roles to display.')."\n");              if ($env{'form.roletype'} eq 'domain') {
                 } elsif ($env{'form.roletype'} eq 'construction_space') {                  $r->print(&mt('There are no users with domain roles to display.')."\n");
                     $r->print(&mt('There are no authors or co-authors to display.')."\n");              } elsif ($env{'form.roletype'} eq 'construction_space') {
                 } elsif ($env{'form.roletype'} eq 'course') {                  $r->print(&mt('There are no authors or co-authors to display.')."\n");
                     $r->print(&mt('There are no course users to display')."\n");               } elsif ($env{'form.roletype'} eq 'course') {
                 }                  $r->print(&mt('There are no course users to display')."\n"); 
             } elsif ($context eq 'course') {  
                 $r->print(&mt('There are no course users to display.')."\n");  
             }              }
         } else {          } elsif ($context eq 'course') {
             # Print out the available choices              $r->print(&mt('There are no course users to display.')."\n");
             if ($env{'form.action'} eq 'modifystudent') {          }
                 &show_users_list($r,$context,'view','modify',      } else {
                                  $env{'form.Status'},\%userlist,$keylist);          # Print out the available choices
             } else {          my $usercount;
                 &show_users_list($r,$context,$env{'form.output'},'aboutme',          if ($env{'form.action'} eq 'modifystudent') {
               ($usercount) = &show_users_list($r,$context,'view','modify',
                                  $env{'form.Status'},\%userlist,$keylist);                                   $env{'form.Status'},\%userlist,$keylist);
             }          } else {
               ($usercount) = &show_users_list($r,$context,$env{'form.output'},
                                  'aboutme',$env{'form.Status'},\%userlist,$keylist);
           }
           if (!$usercount) {
               $r->print('<br />'.&mt('There are no users matching the search criteria.')); 
         }          }
     }      }
     $r->print('</form>');      $r->print('</form>');
Line 1388  sub courses_selector { Line 1489  sub courses_selector {
     my %idnums = ();      my %idnums = ();
     my %idlist_titles = ();      my %idlist_titles = ();
     my $caller = 'global';      my $caller = 'global';
     my $totcodes = 0;  
     my $format_reply;      my $format_reply;
     my $jscript = '';      my $jscript = '';
   
Line 1603  sub show_users_list { Line 1703  sub show_users_list {
     my ($CSVfile,$CSVfilename);      my ($CSVfile,$CSVfilename);
     #      #
     my $sortby = $env{'form.sortby'};      my $sortby = $env{'form.sortby'};
       my @sortable = ('username','domain','id','fullname','start','end','email','role');
     if ($context eq 'course') {      if ($context eq 'course') {
         if ($sortby !~ /^(username|domain|section|groups|fullname|id|start|end|type)$/) {          push(@sortable,('section','groups','type'));
             $sortby = 'username';  
         }  
     } else {      } else {
         if ($sortby !~ /^(username|domain|id|fullname|start|end|role|email|extent)$/) {          push(@sortable,'extent');
             $sortby = 'username';      }
         }      if (!grep(/^\Q$sortby\E$/,@sortable)) {
           $sortby = 'username';
     }      }
     my ($cid,$cdom,$cnum,$classgroups,$displayphotos,$displayclickers);      my ($cid,$cdom,$cnum,$classgroups,$displayphotos,$displayclickers);
     if ($context eq 'course') {      if ($context eq 'course') {
Line 1683  END Line 1783  END
     if (!($context eq 'domain' && $env{'form.roletype'} eq 'course')) {       if (!($context eq 'domain' && $env{'form.roletype'} eq 'course')) { 
         push(@cols,('start','end'));          push(@cols,('start','end'));
     }      }
     if ($env{'form.showrole'} eq 'Any') {      if ($env{'form.showrole'} eq 'Any' || $env{'form.showrole'} eq 'cr') {
         push(@cols,'role');          push(@cols,'role');
     }      }
     if ($context eq 'domain' && ($env{'form.roletype'} eq 'construction_space' ||      if ($context eq 'domain' && ($env{'form.roletype'} eq 'construction_space' ||
Line 1699  END Line 1799  END
     }      }
     push(@cols,'email');      push(@cols,'email');
   
     my $rolefilter;      my $rolefilter = $env{'form.showrole'};
     if ($env{'form.showrole'} ne 'Any') {      if ($env{'form.showrole'} eq 'cr') {
           $rolefilter = &mt('custom');  
       } elsif ($env{'form.showrole'} ne 'Any') {
         $rolefilter = &Apache::lonnet::plaintext($env{'form.showrole'});          $rolefilter = &Apache::lonnet::plaintext($env{'form.showrole'});
     }      }
     my $results_description = &results_header_row($rolefilter,$statusmode,      my $results_description = &results_header_row($rolefilter,$statusmode,
                                                   $context);                                                    $context);
       $r->print('<b>'.$results_description.'</b><br />');
       my $output;
     if ($mode eq 'html' || $mode eq 'view') {      if ($mode eq 'html' || $mode eq 'view') {
         $r->print('<hr />'.&mt('Searching').' ...<br />&nbsp;<br />');  
         $r->rflush();  
         $r->print('<b>'.$results_description.'</b><br />');  
         if ($linkto eq 'aboutme') {  
             $r->print(&mt("Select a user name to view the user's personal page."));  
         } elsif ($linkto eq 'modify') {  
             $r->print(&mt("Select a user name to modify the user's information"));  
         }  
         $r->print(<<END);          $r->print(<<END);
 <input type="hidden" name="sname"  value="" />  <input type="hidden" name="sname"  value="" />
 <input type="hidden" name="sdom"   value="" />  <input type="hidden" name="sdom"   value="" />
 END  END
         $r->print("\n<p>\n".          if ($linkto eq 'aboutme') {
               $output = &mt("Select a user name to view the user's personal page.");
           } elsif ($linkto eq 'modify') {
               $output = &mt("Select a user name to modify the user's information");
           }
           $output .= "\n<p>\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') {
             $r->print("              $output .= "
  <th><a href=\"javascript:document.studentform.sortby.value='type';document.studentform.submit();\">$lt{'type'}</a></th>   <th><a href=\"javascript:document.studentform.sortby.value='type';document.studentform.submit();\">$lt{'type'}</a></th>
             ");              ";
         } else {          } else {
             $r->print("              $output .= "
 <th>Count</th>  <th>Count</th>
             ");              ";
         }          }
         foreach my $item (@cols) {          foreach my $item (@cols) {
             $r->print("<th><a href=\"javascript:document.studentform.sortby.value='$item';document.studentform.submit();\">$lt{$item}</a></th>\n");              $output .= "<th><a href=\"javascript:document.studentform.sortby.value='$item';document.studentform.submit();\">$lt{$item}</a></th>\n";
         }          }
         my %role_types = &role_type_names();          my %role_types = &role_type_names();
         if ($context eq 'course') {          if ($context eq 'course') {
             # Clicker display on or off?              if ($env{'form.showrole'} eq 'st' || $env{'form.showrole'} eq 'Any') {
             my %clicker_options = &Apache::lonlocal::texthash(                  # Clicker display on or off?
                                                         'on' => 'Show',                  my %clicker_options = &Apache::lonlocal::texthash(
                                                         'off' => 'Hide',                                                              'on' => 'Show',
                                                        );                                                              'off' => 'Hide',
             my $clickerchg = 'on';                                                             );
             if ($displayclickers eq 'on') {                  my $clickerchg = 'on';
                 $clickerchg = 'off';                  if ($displayclickers eq 'on') {
             }                      $clickerchg = 'off';
             $r->print('    <th>'."\n".'     '.                  }
                 '<a href="javascript:document.studentform.displayclickers.value='.                  $output .= '    <th>'."\n".'     '.
                       '<a href="javascript:document.studentform.displayclickers.value='.
                       "'".$clickerchg."'".';document.studentform.submit();">'.                        "'".$clickerchg."'".';document.studentform.submit();">'.
                       $clicker_options{$clickerchg}.'</a>&nbsp;'.$lt{'clicker'}."\n".                        $clicker_options{$clickerchg}.'</a>&nbsp;'.$lt{'clicker'}."\n".
                       '    </th>'."\n");                        '    </th>'."\n";
   
             # Photo display on or off?                  # Photo display on or off?
             if ($env{'course.'.$env{'request.course.id'}.'.internal.showphoto'}) {                  if ($env{'course.'.$env{'request.course.id'}.'.internal.showphoto'}) {
                 my %photo_options = &Apache::lonlocal::texthash(                      my %photo_options = &Apache::lonlocal::texthash(
                                                         'on' => 'Show',                                                              'on' => 'Show',
                                                         'off' => 'Hide',                                                              'off' => 'Hide',
                                                             );                                                                  );
                 my $photochg = 'on';                      my $photochg = 'on';
                 if ($displayphotos eq 'on') {                      if ($displayphotos eq 'on') {
                     $photochg = 'off';                          $photochg = 'off';
                 }                      }
                 $r->print('    <th>'."\n".'     '.                      $output .= '    <th>'."\n".'     '.
             '<a href="javascript:document.studentform.displayphotos.value='.                  '<a href="javascript:document.studentform.displayphotos.value='.
                       "'".$photochg."'".';document.studentform.submit();">'.                        "'".$photochg."'".';document.studentform.submit();">'.
                       $photo_options{$photochg}.'</a>&nbsp;'.$lt{'photo'}."\n".                        $photo_options{$photochg}.'</a>&nbsp;'.$lt{'photo'}."\n".
                       '    </th>'."\n");                        '    </th>'."\n";
                   }
             }              }
             $r->print(&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 1808  END Line 1910  END
     foreach my $idx (@$keylist) {      foreach my $idx (@$keylist) {
         $index{$idx} = $i++;          $index{$idx} = $i++;
     }      }
       my $usercount = 0;
     # 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})) {
         my ($uname,$udom,$role,$groups,$email);          my ($uname,$udom,$role,$groups,$email);
           if (($statusmode ne 'Any') && 
                    ($userlist->{$user}->[$index{'status'}] ne $statusmode)) {
               delete($userlist->{$user});
               next;
           }
         if ($context eq 'domain') {          if ($context eq 'domain') {
             if ($env{'form.roletype'} eq 'domain') {              if ($env{'form.roletype'} eq 'domain') {
                 ($role,$uname,$udom) = split(/:/,$user);                  ($role,$uname,$udom) = split(/:/,$user);
Line 1842  END Line 1950  END
         if ($emails{'permanentemail'} =~ /\S/) {          if ($emails{'permanentemail'} =~ /\S/) {
             $userlist->{$user}->[$index{'email'}] = $emails{'permanentemail'};              $userlist->{$user}->[$index{'email'}] = $emails{'permanentemail'};
         }          }
           $usercount ++;
       }
       my $autocount = 0;
       my $manualcount = 0;
       my $lockcount = 0;
       my $unlockcount = 0;
       if ($usercount) {
           $r->print($output);
       } else {
           if ($mode eq 'autoenroll') {
               return ($usercount,$autocount,$manualcount,$lockcount,$unlockcount);
           } else {
               return;
           }
     }      }
   
     #      #
     # Sort the users      # Sort the users
     my $index  = $index{$sortby};      my $index  = $index{$sortby};
Line 1855  END Line 1976  END
         lc($userlist->{$a}->[$second]) cmp lc($userlist->{$b}->[$second])            ||          lc($userlist->{$a}->[$second]) cmp lc($userlist->{$b}->[$second])            ||
         lc($userlist->{$a}->[$third]) cmp lc($userlist->{$b}->[$third])          lc($userlist->{$a}->[$third]) cmp lc($userlist->{$b}->[$third])
         } (keys(%$userlist));          } (keys(%$userlist));
     my $usercount = 0;      my $rowcount = 0;
     my $autocount = 0;  
     my $manualcount = 0;  
     my $lockcount = 0;  
     my $unlockcount = 0;  
     foreach my $user (@sorted_users) {      foreach my $user (@sorted_users) {
         my $sdata = $userlist->{$user};  
         my %in;          my %in;
           my $sdata = $userlist->{$user};
           $rowcount ++; 
         foreach my $item (@{$keylist}) {          foreach my $item (@{$keylist}) {
             $in{$item} = $sdata->[$index{$item}];              $in{$item} = $sdata->[$index{$item}];
         }          }
         next if (($statusmode ne 'Any') && ($in{'status'} ne $statusmode));  
         $in{'role'}=&Apache::lonnet::plaintext($sdata->[$index{'role'}]);           $in{'role'}=&Apache::lonnet::plaintext($sdata->[$index{'role'}]); 
         if (! defined($in{'start'}) || $in{'start'} == 0) {          if (! defined($in{'start'}) || $in{'start'} == 0) {
             $in{'start'} = &mt('none');              $in{'start'} = &mt('none');
Line 1878  END Line 1995  END
         } else {          } else {
             $in{'end'} = &Apache::lonlocal::locallocaltime($in{'end'});              $in{'end'} = &Apache::lonlocal::locallocaltime($in{'end'});
         }          }
         $usercount ++;  
         if ($mode eq 'view' || $mode eq 'html' || $mode eq 'autoenroll') {          if ($mode eq 'view' || $mode eq 'html' || $mode eq 'autoenroll') {
             $r->print(&Apache::loncommon::start_data_table_row());              $r->print(&Apache::loncommon::start_data_table_row());
             $r->print("<td>$usercount</td>\n");              $r->print("<td>$rowcount</td>\n");
             if ($linkto eq 'aboutme') {              if ($linkto eq 'aboutme') {
                 $in{'username'} =                   $in{'username'} = 
                     &Apache::loncommon::aboutmewrapper($in{'username'},                      &Apache::loncommon::aboutmewrapper($in{'username'},
Line 1900  END Line 2016  END
                 $r->print('<td>'.$in{$item}.'</td>'."\n");                  $r->print('<td>'.$in{$item}.'</td>'."\n");
             }              }
             if ($context eq 'course') {              if ($context eq 'course') {
                 if ($displayclickers eq 'on') {                  if ($env{'form.showrole'} eq 'st' || $env{'form.showrole'} eq 'Any') {
                     my $clickers =                      if ($displayclickers eq 'on') {
                           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 ($displayphotos eq 'on') {  
                     if ($env{'course.'.$env{'request.course.id'}.  
                         '.internal.showphoto'}) {  
                         my $imgurl =  
                &Apache::lonnet::retrievestudentphoto($in{'domain'},$in{'username'},'gif','thumbnail');  
                         $r->print('    <td align="right"><a href="javascript:photowindow('."'".&Apache::lonnet::studentphoto($in{'domain'},$in{'username'},'jpg')."'".')"><img src="'.$imgurl.'" border="1"></a></td>');  
                     } else {                      } else {
                         $r->print('    <td>&nbsp;</td>  ');                          $r->print('    <td>&nbsp;</td>  ');
                     }                      }
                       if ($env{'course.'.$env{'request.course.id'}.'.internal.showphoto'}) {
                           if ($displayphotos eq 'on' && $sdata->[$index{'role'}] eq 'st') {
                               my $imgurl =
                           &Apache::lonnet::retrievestudentphoto($in{'domain'},$in{'username'},
                                                             'gif','thumbnail');
                               $r->print('    <td align="right"><a href="javascript:photowindow('."'".&Apache::lonnet::studentphoto($in{'domain'},$in{'username'},'jpg')."'".')"><img src="'.$imgurl.'" border="1"></a></td>');
                           } else {
                               $r->print('    <td>&nbsp;</td>  ');
                           }
                       }
                 }                  }
             }              }
             $r->print(&Apache::loncommon::end_data_table_row());              $r->print(&Apache::loncommon::end_data_table_row());
Line 1971  END Line 2089  END
     }      }
     if ($mode eq 'autoenroll') {      if ($mode eq 'autoenroll') {
         return ($usercount,$autocount,$manualcount,$lockcount,$unlockcount);          return ($usercount,$autocount,$manualcount,$lockcount,$unlockcount);
       } else {
           return ($usercount);
     }      }
     return;  
 }  }
   
 sub role_type_names {  sub role_type_names {
Line 1986  sub role_type_names { Line 2105  sub role_type_names {
   
 sub results_header_row {  sub results_header_row {
     my ($rolefilter,$statusmode,$context) = @_;      my ($rolefilter,$statusmode,$context) = @_;
     my $description;      my ($description,$showfilter);
       if ($rolefilter ne 'Any') {
           $showfilter = $rolefilter;
       }
     if ($context eq 'course') {      if ($context eq 'course') {
         $description = &mt('Course - ').$env{'course.'.env{'request.course.id'}.'.description'}.': ';          $description = &mt('Course - ').$env{'course.'.$env{'request.course.id'}.'.description'}.': ';
         if ($statusmode eq 'Expired') {          if ($statusmode eq 'Expired') {
             $description .= &mt('Users in course with expired [_1] roles',$rolefilter);              $description .= &mt('Users in course with expired [_1] roles',$showfilter);
         }          }
         if ($statusmode eq 'Future') {          if ($statusmode eq 'Future') {
             $description .= &mt('Users in course with future [_1] roles',$rolefilter);              $description .= &mt('Users in course with future [_1] roles',$showfilter);
         } elsif ($statusmode eq 'Active') {          } elsif ($statusmode eq 'Active') {
             $description .= &mt('Users in course with active [_1] roles',$rolefilter);              $description .= &mt('Users in course with active [_1] roles',$showfilter);
         } else {          } else {
             if ($rolefilter eq 'Any') {              if ($rolefilter eq 'Any') {
                 $description .= &mt('All users in course');                  $description .= &mt('All users in course');
Line 2006  sub results_header_row { Line 2128  sub results_header_row {
     } elsif ($context eq 'construction_space') {      } elsif ($context eq 'construction_space') {
         $description = &mt('Author space for [_1].').' ';          $description = &mt('Author space for [_1].').' ';
         if ($statusmode eq 'Expired') {          if ($statusmode eq 'Expired') {
             $description .= &mt('Co-authors with expired [_1] roles',$rolefilter);              $description .= &mt('Co-authors with expired [_1] roles',$showfilter);
         } elsif ($statusmode eq 'Future') {          } elsif ($statusmode eq 'Future') {
             $description .= &mt('Co-authors with future [_1] roles',$rolefilter);              $description .= &mt('Co-authors with future [_1] roles',$showfilter);
         } elsif ($statusmode eq 'Active') {          } elsif ($statusmode eq 'Active') {
             $description .= &mt('Co-authors with active [_1] roles',$rolefilter);              $description .= &mt('Co-authors with active [_1] roles',$showfilter);
         } else {          } else {
             if ($rolefilter eq 'Any') {              if ($rolefilter eq 'Any') {
                 $description .= &mt('All co-authors',$rolefilter);                  $description .= &mt('All co-authors');
             } else {              } else {
                 $description .= &mt('All co-authors with [_1] roles',$rolefilter);                  $description .= &mt('All co-authors with [_1] roles',$rolefilter);
             }              }
Line 2023  sub results_header_row { Line 2145  sub results_header_row {
         $description = &mt('Domain - ').$domdesc.': ';          $description = &mt('Domain - ').$domdesc.': ';
         if ($env{'form.roletype'} eq 'domain') {          if ($env{'form.roletype'} eq 'domain') {
             if ($statusmode eq 'Expired') {              if ($statusmode eq 'Expired') {
                 $description .= &mt('Users in domain with expired [_1] roles',$rolefilter);                  $description .= &mt('Users in domain with expired [_1] roles',$showfilter);
             } elsif ($statusmode eq 'Future') {              } elsif ($statusmode eq 'Future') {
                 $description .= &mt('Users in domain with future [_1] roles',$rolefilter);                  $description .= &mt('Users in domain with future [_1] roles',$showfilter);
             } elsif ($statusmode eq 'Active') {              } elsif ($statusmode eq 'Active') {
                 $description .= &mt('Users in domain with active [_1] roles',$rolefilter);                  $description .= &mt('Users in domain with active [_1] roles',$showfilter);
             } else {              } else {
                 if ($rolefilter eq 'Any') {                  if ($rolefilter eq 'Any') {
                     $description .= &mt('All users in domain',$rolefilter);                      $description .= &mt('All users in domain');
                 } else {                  } else {
                     $description .= &mt('All users in domain with [_1] roles',$rolefilter);                      $description .= &mt('All users in domain with [_1] roles',$rolefilter);
                 }                  }
             }              }
         } elsif ($env{'form.roletype'} eq 'construction_space') {          } elsif ($env{'form.roletype'} eq 'construction_space') {
             if ($statusmode eq 'Expired') {              if ($statusmode eq 'Expired') {
                 $description .= &mt('Co-authors in domain with expired [_1] roles',$rolefilter);                  $description .= &mt('Co-authors in domain with expired [_1] roles',$showfilter);
             } elsif ($statusmode eq 'Future') {              } elsif ($statusmode eq 'Future') {
                 $description .= &mt('Co-authors in domain with future [_1] roles',$rolefilter);                  $description .= &mt('Co-authors in domain with future [_1] roles',$showfilter);
             } elsif ($statusmode eq 'Active') {              } elsif ($statusmode eq 'Active') {
                $description .= &mt('Co-authors in domain with active [_1] roles',$rolefilter);                 $description .= &mt('Co-authors in domain with active [_1] roles',$showfilter);
             } else {              } else {
                 if ($rolefilter eq 'Any') {                  if ($rolefilter eq 'Any') {
                     $description .= &mt('All users with co-author roles in domain',$rolefilter);                      $description .= &mt('All users with co-author roles in domain',$showfilter);
                 } else {                  } else {
                     $description .= &mt('All co-authors in domain  with [_1] roles',$rolefilter);                      $description .= &mt('All co-authors in domain  with [_1] roles',$rolefilter);
                 }                  }
Line 2064  sub results_header_row { Line 2186  sub results_header_row {
                 $description .= &mt('All courses in domain').' - ';                  $description .= &mt('All courses in domain').' - ';
             }              }
             if ($statusmode eq 'Expired') {              if ($statusmode eq 'Expired') {
                 $description .= &mt('users with expired [_1] roles',$rolefilter);                  $description .= &mt('users with expired [_1] roles',$showfilter);
             } elsif ($statusmode eq 'Future') {              } elsif ($statusmode eq 'Future') {
                 $description .= &mt('users with future [_1] roles',$rolefilter);                  $description .= &mt('users with future [_1] roles',$showfilter);
             } elsif ($statusmode eq 'Active') {              } elsif ($statusmode eq 'Active') {
                 $description .= &mt('users with active [_1] roles',$rolefilter);                  $description .= &mt('users with active [_1] roles',$showfilter);
             } else {              } else {
                 if ($rolefilter eq 'Any') {                  if ($rolefilter eq 'Any') {
                     $description .= &mt('all users');                      $description .= &mt('all users');
Line 2402  sub upfile_drop_add { Line 2524  sub upfile_drop_add {
             # Get information about course groups              # Get information about course groups
             %curr_groups = &Apache::longroup::coursegroups();              %curr_groups = &Apache::longroup::coursegroups();
         }          }
           my (%curr_rules,%got_rules,%alerts);
         # Get new users list          # Get new users list
         foreach (@userdata) {          foreach (@userdata) {
             my %entries=&Apache::loncommon::record_sep($_);              my %entries=&Apache::loncommon::record_sep($_);
Line 2433  sub upfile_drop_add { Line 2556  sub upfile_drop_add {
           $entries{$fields{'username'}},$fname,$mname,$lname,$gen).            $entries{$fields{'username'}},$fname,$mname,$lname,$gen).
                               '</b>');                                '</b>');
                 } else {                  } else {
                     my $username = $entries{$fields{'username'}};                       my $username = $entries{$fields{'username'}};
                     my $sec;                      my $sec;
                     if ($context eq 'course' || $setting eq 'course') {                      if ($context eq 'course' || $setting eq 'course') {
                         # determine section number                          # determine section number
Line 2504  sub upfile_drop_add { Line 2627  sub upfile_drop_add {
                              \$lname,\$gen,\$sec,\$role) {                               \$lname,\$gen,\$sec,\$role) {
                         $$_ =~ s/(\s+$|^\s+)//g;                          $$_ =~ s/(\s+$|^\s+)//g;
                     }                      }
                       # check against rules
                       my $checkid = 0;
                       my $newuser = 0;
                       my (%rulematch,%inst_results,%idinst_results);
                       my $uhome=&Apache::lonnet::homeserver($username,$domain);
                       if ($uhome eq 'no_host') {
                           $checkid = 1;
                           $newuser = 1;
                           my $checkhash;
                           my $checks = { 'username' => 1 };
                           $checkhash->{$username.':'.$domain} = { 'newuser' => 1, };
                           &Apache::loncommon::user_rule_check($checkhash,$checks,
                               \%alerts,\%rulematch,\%inst_results,\%curr_rules,
                               \%got_rules);
                           if (ref($alerts{'username'}) eq 'HASH') {
                               if (ref($alerts{'username'}{$domain}) eq 'HASH') {
                                   next if ($alerts{'username'}{$domain}{$username});
                               }
                           }
                       }
                       if ($id ne '') {
                           if (!$newuser) {
                               my %idhash = &Apache::lonnet::idrget($domain,($username));
                               if ($idhash{$username} ne $id) {
                                   $checkid = 1;
                               }
                           }
                           if ($checkid) {
                               my $checkhash;
                               my $checks = { 'id' => 1 };
                               $checkhash->{$username.':'.$domain} = { 'newuser' => $newuser,
                                                                       'id'  => $id };
                               &Apache::loncommon::user_rule_check($checkhash,$checks,
                                   \%alerts,\%rulematch,\%idinst_results,\%curr_rules,
                                   \%got_rules);
                               if (ref($alerts{'id'}) eq 'HASH') {
                                   if (ref($alerts{'id'}{$domain}) eq 'HASH') {
                                       next if ($alerts{'id'}{$domain}{$id});
                                   }
                               }
                           }
                       }
                     if ($password || $env{'form.login'} eq 'loc') {                      if ($password || $env{'form.login'} eq 'loc') {
                         my ($userresult,$authresult,$roleresult);                          my ($userresult,$authresult,$roleresult);
                         if ($role eq 'st') {                          if ($role eq 'st') {
Line 2522  sub upfile_drop_add { Line 2687  sub upfile_drop_add {
                                     $id,$amode,$password,$fname,                                      $id,$amode,$password,$fname,
                                     $mname,$lname,$gen,$sec,                                      $mname,$lname,$gen,$sec,
                                     $env{'form.forceid'},$desiredhost,                                      $env{'form.forceid'},$desiredhost,
                                     $email,$role,$enddate,$startdate);                                      $email,$role,$enddate,$startdate,$checkid);
                         }                          }
                         $flushc =                           $flushc = 
                             &user_change_result($r,$userresult,$authresult,                              &user_change_result($r,$userresult,$authresult,
Line 2547  sub upfile_drop_add { Line 2712  sub upfile_drop_add {
             }              }
         } # end of foreach (@userdata)          } # end of foreach (@userdata)
         # Flush the course logs so reverse user roles immediately updated          # Flush the course logs so reverse user roles immediately updated
         if ($context eq 'course' || ($context eq 'domain' && $setting eq 'course')) {          &Apache::lonnet::flushcourselogs();
             &Apache::lonnet::flushcourselogs();  
         }  
         $r->print("</p>\n<p>\n".&mt('Processed [_1] user(s).',$counts{'user'}).          $r->print("</p>\n<p>\n".&mt('Processed [_1] user(s).',$counts{'user'}).
                   "</p>\n");                    "</p>\n");
         if ($counts{'role'} > 0) {          if ($counts{'role'} > 0) {
Line 2561  sub upfile_drop_add { Line 2724  sub upfile_drop_add {
                       &mt('Authentication changed for [_1] existing users.',                        &mt('Authentication changed for [_1] existing users.',
                           $counts{'auth'})."</p>\n");                            $counts{'auth'})."</p>\n");
         }          }
           if (keys(%alerts) > 0) {
               if (ref($alerts{'username'}) eq 'HASH') {
                   foreach my $dom (sort(keys(%{$alerts{'username'}}))) {
                       my $count;
                       if (ref($alerts{'username'}{$dom}) eq 'HASH') {
                           $count = keys(%{$alerts{'username'}{$dom}});
                       } 
                       my $domdesc = &Apache::lonnet::domain($domain,'description');
                       if (ref($curr_rules{$dom}) eq 'HASH') {
                           $r->print(&Apache::loncommon::instrule_disallow_msg(
                                    'username',$domdesc,$count,'upload'));
                       }
                       $r->print(&Apache::loncommon::user_rule_formats($dom,
                                 $domdesc,$curr_rules{$dom}{'username'},
                                'username'));
                   }
               }
               if (ref($alerts{'id'}) eq 'HASH') {
                   foreach my $dom (sort(keys(%{$alerts{'id'}}))) {
                       my $count;
                       if (ref($alerts{'id'}{$dom}) eq 'HASH') {
                           $count = keys(%{$alerts{'id'}{$dom}});
                       }
                       my $domdesc = &Apache::lonnet::domain($domain,'description');
                       if (ref($curr_rules{$dom}) eq 'HASH') {
                           $r->print(&Apache::loncommon::instrule_disallow_msg(
                                    'id',$domdesc,$count,'upload'));
                       }
                       $r->print(&Apache::loncommon::user_rule_formats($dom,
                                 $domdesc,$curr_rules{$dom}{'id'},'id'));
                   }
               }
           }
         $r->print('<form name="uploadresult" action="/adm/createuser">');          $r->print('<form name="uploadresult" action="/adm/createuser">');
         $r->print(&Apache::lonhtmlcommon::echo_form_input(['phase','prevphase','currstate']));          $r->print(&Apache::lonhtmlcommon::echo_form_input(['phase','prevphase','currstate']));
         $r->print('</form>');          $r->print('</form>');

Removed from v.1.2  
changed lines
  Added in v.1.6


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