Diff for /loncom/interface/lonuserutils.pm between versions 1.150 and 1.166

version 1.150, 2013/03/01 04:55:34 version 1.166, 2014/04/04 23:06:31
Line 401  sub javascript_validations { Line 401  sub javascript_validations {
   
     my $showcredits;      my $showcredits;
     my %domdefaults = &Apache::lonnet::get_domain_defaults($domain);      my %domdefaults = &Apache::lonnet::get_domain_defaults($domain);
     if ($domdefaults{'officialcredits'} || $domdefaults{'unofficialcredits'}) {      if ($domdefaults{'officialcredits'} || $domdefaults{'unofficialcredits'} || $domdefaults{'textbookcredits'}) {
         $showcredits = 1;          $showcredits = 1;
     }      }
   
Line 642  sub upload_manager_javascript_forward_as Line 642  sub upload_manager_javascript_forward_as
             $numbuttons ++;              $numbuttons ++;
         }          }
         if (!$can_assign->{'int'}) {          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'              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.');                            &mt('Your current role does not have rights to create users with that authentication type.');
             $auth_update = <<"END";              $auth_update = <<"END";
    // Currently the initial password field is only supported for internal auth     // Currently the initial password field is only supported for internal auth
Line 1013  sub print_upload_manager_footer { Line 1013  sub print_upload_manager_footer {
                .&Apache::lonhtmlcommon::row_closure();                 .&Apache::lonhtmlcommon::row_closure();
     }      }
     if ($context eq 'course' || $context eq 'domain') {      if ($context eq 'course' || $context eq 'domain') {
         $Str .= &forceid_change($context);          $Str .= &Apache::lonhtmlcommon::row_title(&mt('Student/Employee ID'))
                  .&forceid_change($context)
                  .&Apache::lonhtmlcommon::row_closure(1); # last row in pick_box
     }      }
   
     $Str .= &Apache::lonhtmlcommon::end_pick_box();      $Str .= &Apache::lonhtmlcommon::end_pick_box();
Line 1047  sub get_defaultcredits { Line 1049  sub get_defaultcredits {
     return unless(($cdom =~ /^$match_domain$/) && ($cnum =~ /^$match_courseid$/));       return unless(($cdom =~ /^$match_domain$/) && ($cnum =~ /^$match_courseid$/)); 
     my ($defaultcredits,$domdefcredits);      my ($defaultcredits,$domdefcredits);
     my %domdefaults = &Apache::lonnet::get_domain_defaults($cdom);      my %domdefaults = &Apache::lonnet::get_domain_defaults($cdom);
     if ($domdefaults{'officialcredits'} || $domdefaults{'unofficialcredits'}) {      if ($domdefaults{'officialcredits'} || $domdefaults{'unofficialcredits'} || $domdefaults{'textbookcredits'}) {
         my $instcode = $env{'course.'.$cdom.'_'.$cnum.'.internal.coursecode'};          my $instcode = $env{'course.'.$cdom.'_'.$cnum.'.internal.coursecode'};
         if ($instcode) {          if ($instcode) {
             $domdefcredits = $domdefaults{'officialcredits'};              $domdefcredits = $domdefaults{'officialcredits'};
           } elsif ($env{'course.'.$cdom.'_'.$cnum.'.internal.textbook'}) {
               $domdefcredits = $domdefaults{'textbookcredits'};
         } else {          } else {
             $domdefcredits = $domdefaults{'unofficialcredits'};              $domdefcredits = $domdefaults{'unofficialcredits'};
         }          }
Line 1076  sub get_defaultcredits { Line 1080  sub get_defaultcredits {
 sub forceid_change {  sub forceid_change {
     my ($context) = @_;      my ($context) = @_;
     my $output =       my $output = 
         &Apache::lonhtmlcommon::row_title(&mt('Student/Employee ID'))          '<label><input type="checkbox" name="forceid" value="yes" />'
        .'<label><input type="checkbox" name="forceid" value="yes" />'         .&mt('Force change of existing ID')
        .&mt('Disable Student/Employee ID Safeguard and force change of conflicting IDs')         .'</label>'.&Apache::loncommon::help_open_topic('ForceIDChange')."\n";
        .'</label><br />'."\n"  
        .&mt('(only do if you know what you are doing.)')."\n";  
     if ($context eq 'domain') {      if ($context eq 'domain') {
         $output .= '<br /><label><input type="checkbox" name="recurseid"'.          $output .= 
                    ' value="yes" />'.               '<br />'
   &mt('Update student/employee ID in courses in which user is active/future student,[_1](if forcing change).','<br />').             .'<label><input type="checkbox" name="recurseid" value="yes" />'
                    '</label>'."\n";             .&mt("Update ID in user's course(s).").'</label>'."\n";
     }      }
     $output .= &Apache::lonhtmlcommon::row_closure(1); # last row in pick_box  
     return $output;      return $output;
 }  }
   
Line 1392  sub default_role_selector { Line 1393  sub default_role_selector {
                       &default_course_roles($context,$checkpriv,'Course',%customroles)."\n".                        &default_course_roles($context,$checkpriv,'Course',%customroles)."\n".
                       '</select></td><td>'.                        '</select></td><td>'.
                       '<table class="LC_createuser">'.                        '<table class="LC_createuser">'.
                       '<tr class="LC_section_row"><td valign"top">'.                        '<tr class="LC_section_row"><td valign="top">'.
                       $lt{'exs'}.'<br /><select name="currsec">'.                        $lt{'exs'}.'<br /><select name="currsec">'.
                       ' <option value=""><--'.&mt('Pick course first').                        ' <option value="">&lt;--'.&mt('Pick course first').
                       '</select></td>'.                        '</select></td>'.
                       '<td>&nbsp;&nbsp;</td>'.                        '<td>&nbsp;&nbsp;</td>'.
                       '<td valign="top">'.$lt{'new'}.'<br />'.                        '<td valign="top">'.$lt{'new'}.'<br />'.
Line 1578  sub print_userlist { Line 1579  sub print_userlist {
         @statuses = ('future');          @statuses = ('future');
     }      }
   
 #    if ($context eq 'course') {   
 #        $r->print(&display_adv_courseroles());  
 #    }  
     #  
     # Interface output      # Interface output
     $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="'.
Line 1635  sub print_userlist { Line 1632  sub print_userlist {
   
     my @cols = &infocolumns($context,$mode,$showcredits);        my @cols = &infocolumns($context,$mode,$showcredits);  
     if (!@cols) {      if (!@cols) {
          $r->print('<hr clear="all" /><span class="LC_warning">'.           $r->print('<hr style="clear:both;" /><span class="LC_warning">'.
                    &mt('No user information selected for display.').'</span>'.                     &mt('No user information selected for display.').'</span>'.
                    '<input type="hidden" name="phase" value="display" /></form>'."\n");                     '<input type="hidden" name="phase" value="display" /></form>'."\n");
          return;           return;
     }      }
     my ($indexhash,$keylist) = &make_keylist_array();      my ($indexhash,$keylist) = &make_keylist_array();
     my (%userlist,%userinfo,$clearcoursepick);      my (%userlist,%userinfo,$clearcoursepick,$needauthorquota,$needauthorusage);
     if (($context eq 'domain') &&       if (($context eq 'domain') && 
         ($env{'form.roletype'} eq 'course') ||           ($env{'form.roletype'} eq 'course') || 
         ($env{'form.roletype'} eq 'community')) {          ($env{'form.roletype'} eq 'community')) {
Line 1678  sub print_userlist { Line 1675  sub print_userlist {
             $r->print('<hr />'.&mt('Searching ...').'<br />&nbsp;<br />');              $r->print('<hr />'.&mt('Searching ...').'<br />&nbsp;<br />');
         }          }
     } else {      } else {
         $r->print('<hr clear="all" /><div id="searching">'.&mt('Searching ...').'</div>');          $r->print('<hr style="clear:both;" /><div id="searching">'.&mt('Searching ...').'</div>');
     }      }
     $r->rflush();      $r->rflush();
     if ($context eq 'course') {      if ($context eq 'course') {
Line 1713  sub print_userlist { Line 1710  sub print_userlist {
                              \%cstr_roles,$permission);                               \%cstr_roles,$permission);
         } elsif ($context eq 'domain') {          } elsif ($context eq 'domain') {
             if ($env{'form.roletype'} eq 'domain') {              if ($env{'form.roletype'} eq 'domain') {
                   if (grep(/^authorusage$/,@cols)) {
                       $needauthorusage = 1;
                   }
                   if (grep(/^authorquota$/,@cols)) {
                       $needauthorquota = 1;
                   }
                 %dom_roles = &Apache::lonnet::get_domain_roles($env{'request.role.domain'});                  %dom_roles = &Apache::lonnet::get_domain_roles($env{'request.role.domain'});
                 foreach my $key (keys(%dom_roles)) {                  foreach my $key (keys(%dom_roles)) {
                     if (ref($dom_roles{$key}) eq 'HASH') {                      if (ref($dom_roles{$key}) eq 'HASH') {
Line 1825  sub print_userlist { Line 1828  sub print_userlist {
         } else {          } else {
             ($usercount) = &show_users_list($r,$context,$env{'form.output'},              ($usercount) = &show_users_list($r,$context,$env{'form.output'},
                                $permission,$env{'form.Status'},\%userlist,                                 $permission,$env{'form.Status'},\%userlist,
                                $keylist,'',$showcredits);                                 $keylist,'',$showcredits,$needauthorquota,$needauthorusage);
         }          }
         if (!$usercount) {          if (!$usercount) {
             $r->print('<br /><span class="LC_info">'              $r->print('<br /><span class="LC_info">'
Line 1992  sub get_cols_array { Line 1995  sub get_cols_array {
         }          }
         if (($context eq 'course') && ($mode ne 'autoenroll') &&          if (($context eq 'course') && ($mode ne 'autoenroll') &&
             ($env{'course.'.$env{'request.course.id'}.'.internal.showphoto'})) {              ($env{'course.'.$env{'request.course.id'}.'.internal.showphoto'})) {
             push(@cols,'photos');              push(@cols,'photo');
         }          }
         if ($context eq 'domain') {          if ($context eq 'domain') {
             push (@cols,'extent');              push (@cols,('authorusage','authorquota','extent'));
         }          }
     }      }
     return @cols;      return @cols;
Line 2031  sub column_checkboxes { Line 2034  sub column_checkboxes {
             if (($env{'form.roletype'} eq 'course') ||               if (($env{'form.roletype'} eq 'course') || 
                 ($env{'form.roletype'} eq 'community')) {                  ($env{'form.roletype'} eq 'community')) {
                 $disabledchk{'status'} = 1;                  $disabledchk{'status'} = 1;
                   $disabledchk{'authorusage'} = 1;
                   $disabledchk{'authorquota'} = 1;
             } elsif ($env{'form.roletype'} eq 'domain') {              } elsif ($env{'form.roletype'} eq 'domain') {
                 $disabledchk{'extent'} = 1;                   $disabledchk{'extent'} = 1; 
             }              }
Line 2082  sub column_checkboxes { Line 2087  sub column_checkboxes {
             if (($env{'form.roletype'} eq 'domain') || ($env{'form.roletype'} eq '')) {              if (($env{'form.roletype'} eq 'domain') || ($env{'form.roletype'} eq '')) {
                 $style = ' style="display: none;"';                  $style = ' style="display: none;"';
             }               } 
         }           } elsif (($cols[$i] eq 'authorusage') || ($cols[$i] eq 'authorquota')) {
               if ($env{'form.roletype'} ne 'domain') {
                   $style = ' style="display: none;"';
               }
           }
         $output .= '<span id="show'.$cols[$i].'"'.$style.'><label>'.          $output .= '<span id="show'.$cols[$i].'"'.$style.'><label>'.
                    '<input id="showcol'.$cols[$i].'" type="checkbox" name="showcol" value="'.$cols[$i].'"'.$checked.' /><span id="showcoltext'.$cols[$i].'">'.                     '<input id="showcol'.$cols[$i].'" type="checkbox" name="showcol" value="'.$cols[$i].'"'.$checked.' /><span id="showcoltext'.$cols[$i].'">'.
                    $lt{$cols[$i]}.'</span>'.                     $lt{$cols[$i]}.'</span>'.
Line 2116  sub get_column_names { Line 2125  sub get_column_names {
         'photo'      => "photo",          'photo'      => "photo",
         'lastlogin'  => "last login",          'lastlogin'  => "last login",
         'extent'     => "extent",          'extent'     => "extent",
           'authorusage' => "disk usage (%)",
           'authorquota' => "disk quota (MB)",
         'ca'         => "check all",          'ca'         => "check all",
         'ua'         => "uncheck all",          'ua'         => "uncheck all",
         'clicker'    => "clicker-ID",          'clicker'    => "clicker-ID",
Line 2123  sub get_column_names { Line 2134  sub get_column_names {
     if ($context eq 'domain' && $env{'form.roletype'} eq 'course') {      if ($context eq 'domain' && $env{'form.roletype'} eq 'course') {
         $lt{'extent'} = &mt('course(s): description, section(s), status');          $lt{'extent'} = &mt('course(s): description, section(s), status');
     } elsif ($context eq 'domain' && $env{'form.roletype'} eq 'community') {      } elsif ($context eq 'domain' && $env{'form.roletype'} eq 'community') {
         $lt{'extent'} = &mt('communities: description, section(s), status');          $lt{'extent'} = &mt('community(s): description, section(s), status');
     } elsif (($context eq 'author') ||       } elsif (($context eq 'author') || 
              ($context eq 'domain' && $env{'form.roletype'} eq 'author')) {               ($context eq 'domain' && $env{'form.roletype'} eq 'author')) {
         $lt{'extent'} = &mt('author');          $lt{'extent'} = &mt('author');
Line 2380  sub instcode_from_coursefilter { Line 2391  sub instcode_from_coursefilter {
     return $instcode;      return $instcode;
 }  }
   
 sub display_adv_courseroles {  
     my $output;  
     #  
     # List course personnel  
     my %coursepersonnel =   
        &Apache::lonnet::get_course_adv_roles($env{'request.course.id'});  
     #  
     $output = '<br />'.&Apache::loncommon::start_data_table();  
     foreach my $role (sort(keys(%coursepersonnel))) {  
         next if ($role =~ /^\s*$/);  
         $output .= &Apache::loncommon::start_data_table_row().  
                   '<td>'.$role.'</td><td>';  
         foreach my $user (split(',',$coursepersonnel{$role})) {  
             my ($puname,$pudom)=split(':',$user);  
             $output .= ' '.&Apache::loncommon::aboutmewrapper(  
                        &Apache::loncommon::plainname($puname,$pudom),  
                        $puname,$pudom);  
         }  
         $output .= '</td>'.&Apache::loncommon::end_data_table_row();  
     }  
     $output .= &Apache::loncommon::end_data_table();  
 }  
   
 sub make_keylist_array {  sub make_keylist_array {
     my ($index,$keylist);      my ($index,$keylist);
     $index->{'domain'} = &Apache::loncoursedata::CL_SDOM();      $index->{'domain'} = &Apache::loncoursedata::CL_SDOM();
Line 2422  sub make_keylist_array { Line 2410  sub make_keylist_array {
     $index->{'photo'} = &Apache::loncoursedata::CL_PHOTO();      $index->{'photo'} = &Apache::loncoursedata::CL_PHOTO();
     $index->{'thumbnail'} = &Apache::loncoursedata::CL_THUMBNAIL();      $index->{'thumbnail'} = &Apache::loncoursedata::CL_THUMBNAIL();
     $index->{'credits'} = &Apache::loncoursedata::CL_CREDITS();      $index->{'credits'} = &Apache::loncoursedata::CL_CREDITS();
       $index->{'authorquota'} = &Apache::loncoursedata::CL_AUTHORQUOTA();
       $index->{'authorusage'} = &Apache::loncoursedata::CL_AUTHORUSAGE();
     foreach my $key (keys(%{$index})) {      foreach my $key (keys(%{$index})) {
         $keylist->[$index->{$key}] = $key;          $keylist->[$index->{$key}] = $key;
     }      }
Line 2471  sub process_date_info { Line 2461  sub process_date_info {
   
 sub show_users_list {  sub show_users_list {
     my ($r,$context,$mode,$permission,$statusmode,$userlist,$keylist,$formname,      my ($r,$context,$mode,$permission,$statusmode,$userlist,$keylist,$formname,
         $showcredits)=@_;          $showcredits,$needauthorquota,$needauthorusage)=@_;
     if ($formname eq '') {      if ($formname eq '') {
         $formname = 'studentform';          $formname = 'studentform';
     }      }
       my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
     #      #
     # Variables for excel output      # Variables for excel output
     my ($excel_workbook, $excel_sheet, $excel_filename,$row,$format);      my ($excel_workbook, $excel_sheet, $excel_filename,$row,$format);
Line 2491  sub show_users_list { Line 2482  sub show_users_list {
         }          }
     } else {      } else {
         push(@sortable,'extent');          push(@sortable,'extent');
           if (($context eq 'domain') && ($env{'form.roletype'} eq 'domain') &&
               (($env{'form.showrole'} eq 'Any') || ($env{'form.showrole'} eq 'au'))) {
               push(@sortable,('authorusage','authorquota'));
           }
     }      }
     if ($mode eq 'pickauthor') {      if ($mode eq 'pickauthor') {
         @sortable = ('username','fullname','email','status');          @sortable = ('username','fullname','email','status');
     }      }
     if (!grep(/^\Q$sortby\E$/,@sortable)) {      my %is_sortable;
       map { $is_sortable{$_} = 1; } @sortable;
       unless ($is_sortable{$sortby}) {
         $sortby = 'username';          $sortby = 'username';
     }      }
     my $setting = $env{'form.roletype'};      my $setting = $env{'form.roletype'};
Line 2735  END Line 2732  END
         } else {          } else {
             $output .= "\n".'<th>&nbsp;</th>'."\n";              $output .= "\n".'<th>&nbsp;</th>'."\n";
             if ($actionselect) {              if ($actionselect) {
                 $output .= '<th>'.&mt('Select').'</th>'."\n";                  $output .= '<th class="LC_nobreak" valign="top">'.&mt('Select').'</th>'."\n";
             }              }
         }          }
         foreach my $item (@cols) {          foreach my $item (@cols) {
             $output .= "<th><a href=\"javascript:document.$formname.sortby.value='$item';document.$formname.submit();\">$lt{$item}</a></th>\n";              $output .= '<th class="LC_nobreak" valign="top">';
               if ($is_sortable{$item}) {
                   $output .= "<a href=\"javascript:document.$formname.sortby.value='$item';document.$formname.submit();\" style=\"text-decoration:none;\">$lt{$item}<span class=\"LC_fontsize_small\"> &#9660;</span></a>";
               } else {
                   $output .= $lt{$item};
               }
               $output .= "</th>\n";
         }          }
         my %role_types = &role_type_names();          my %role_types = &role_type_names();
         $output .= &Apache::loncommon::end_data_table_header_row();          $output .= &Apache::loncommon::end_data_table_header_row();
Line 2910  END Line 2913  END
         if ($emails{'permanentemail'} =~ /\S/) {          if ($emails{'permanentemail'} =~ /\S/) {
             $userlist->{$user}->[$index{'email'}] = $emails{'permanentemail'};              $userlist->{$user}->[$index{'email'}] = $emails{'permanentemail'};
         }          }
           if (($context eq 'domain') && ($env{'form.roletype'} eq 'domain') && 
               ($role eq 'au')) {
               my ($disk_quota,$current_disk_usage,$percent); 
               if (($needauthorusage) || ($needauthorquota)) {
                   $disk_quota = &Apache::loncommon::get_user_quota($uname,$udom,'author');
               }
               if ($needauthorusage) {
                   $current_disk_usage =
                       &Apache::lonnet::diskusage($udom,$uname,"$londocroot/priv/$udom/$uname");
                   if ($disk_quota == 0) {
                       $percent = 100.0;
                   } else {
                       $percent = $current_disk_usage/(10 * $disk_quota);
                   }
                   $userlist->{$user}->[$index{'authorusage'}] = sprintf("%.0f",$percent);
               }
               if ($needauthorquota) {
                   $userlist->{$user}->[$index{'authorquota'}] = sprintf("%.2f",$disk_quota);
               }
           }
         $usercount ++;          $usercount ++;
     }      }
     my $autocount = 0;      my $autocount = 0;
Line 2930  END Line 2953  END
     my $index  = $index{$sortby};      my $index  = $index{$sortby};
     my $second = $index{'username'};      my $second = $index{'username'};
     my $third  = $index{'domain'};      my $third  = $index{'domain'};
     my @sorted_users = sort {      my @sorted_users;
         lc($userlist->{$a}->[$index])  cmp lc($userlist->{$b}->[$index])      if (($sortby eq 'authorquota') || ($sortby eq 'authorusage')) {  
             ||          @sorted_users = sort {
         lc($userlist->{$a}->[$second]) cmp lc($userlist->{$b}->[$second])            ||              $userlist->{$b}->[$index] <=> $userlist->{$a}->[$index]           ||
         lc($userlist->{$a}->[$third]) cmp lc($userlist->{$b}->[$third])              lc($userlist->{$a}->[$second]) cmp lc($userlist->{$b}->[$second]) ||
         } (keys(%$userlist));              lc($userlist->{$a}->[$third]) cmp lc($userlist->{$b}->[$third])
               } (keys(%$userlist));
       } else {
           @sorted_users = sort {
               lc($userlist->{$a}->[$index]) cmp lc($userlist->{$b}->[$index])   ||
               lc($userlist->{$a}->[$second]) cmp lc($userlist->{$b}->[$second]) ||
               lc($userlist->{$a}->[$third]) cmp lc($userlist->{$b}->[$third])
               } (keys(%$userlist));
       }
     my $rowcount = 0;      my $rowcount = 0;
     foreach my $user (@sorted_users) {      foreach my $user (@sorted_users) {
         my %in;          my %in;
Line 2946  END Line 2977  END
         }          }
         my $clickers = (&Apache::lonnet::userenvironment($in{'domain'},$in{'username'},'clickers'))[1];          my $clickers = (&Apache::lonnet::userenvironment($in{'domain'},$in{'username'},'clickers'))[1];
         if ($clickers!~/\w/) { $clickers='-'; }          if ($clickers!~/\w/) { $clickers='-'; }
         $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);
         unless ($mode eq 'excel') {          unless ($mode eq 'excel') {
Line 2973  END Line 3004  END
             if ($mode eq 'autoenroll') {              if ($mode eq 'autoenroll') {
                 my $cellentry;                  my $cellentry;
                 if ($in{'type'} eq 'auto') {                  if ($in{'type'} eq 'auto') {
                     $cellentry = '<b>'.&mt('auto').'</b>&nbsp;<label><input type="checkbox" name="chgauto" value="'.$in{'username'}.':'.$in{'domain'}.'" />&nbsp;Change</label>';                      $cellentry = '<b>'.&mt('auto').'</b>&nbsp;<label><input type="checkbox" name="chgauto" value="'.$in{'username'}.':'.$in{'domain'}.'" />&nbsp;'.&mt('Change').'</label>';
                     $autocount ++;                      $autocount ++;
                 } else {                  } else {
                     $cellentry = '<table border="0" cellspacing="0"><tr><td rowspan="2"><b>'.&mt('manual').'</b></td><td><span class="LC_nobreak"><label><input type="checkbox" name="chgmanual" value="'.$in{'username'}.':'.$in{'domain'}.'" />&nbsp;Change</label></span></td></tr><tr><td><span class="LC_nobreak">';                      $cellentry = '<table border="0" cellspacing="0"><tr><td rowspan="2"><b>'.&mt('manual').'</b></td><td><span class="LC_nobreak"><label><input type="checkbox" name="chgmanual" value="'.$in{'username'}.':'.$in{'domain'}.'" />&nbsp;'.&mt('Change').'</label></span></td></tr><tr><td><span class="LC_nobreak">';
                     $manualcount ++;                      $manualcount ++;
                     if ($in{'lockedtype'}) {                      if ($in{'lockedtype'}) {
                         $cellentry .= '<label><input type="checkbox" name="unlockchg" value="'.$in{'username'}.':'.$in{'domain'}.'" />&nbsp;'.&mt('Unlock').'</label>';                          $cellentry .= '<label><input type="checkbox" name="unlockchg" value="'.$in{'username'}.':'.$in{'domain'}.'" />&nbsp;'.&mt('Unlock').'</label>';
Line 3070  END Line 3101  END
                              $r->print('<td>&nbsp;</td>'."\n");                               $r->print('<td>&nbsp;</td>'."\n");
                         }                           } 
                     }                      }
                   } elsif (($item eq 'authorquota') || ($item eq 'authorusage')) {
                       $r->print('<td align="right">'.$in{$item}.'</td>'."\n");
                 } else {                  } else {
                     $r->print('<td>'.$in{$item}.'</td>'."\n");                      $r->print('<td>'.$in{$item}.'</td>'."\n");
                 }                  }
Line 3105  END Line 3138  END
             $r->print(&Apache::loncommon::end_data_table().'<br />');              $r->print(&Apache::loncommon::end_data_table().'<br />');
     } elsif ($mode eq 'excel') {      } elsif ($mode eq 'excel') {
         $excel_workbook->close();          $excel_workbook->close();
  $r->print(&mt('[_1]Your Excel spreadsheet[_2] is ready for download.', '<p><a href="'.$excel_filename.'">','</a>')."</p>\n");   $r->print('<p>'.&mt('[_1]Your Excel spreadsheet[_2] is ready for download.', '<a href="'.$excel_filename.'">','</a>')."</p>\n");
     } elsif ($mode eq 'csv') {      } elsif ($mode eq 'csv') {
         close($CSVfile);          close($CSVfile);
  $r->print(&mt('[_1]Your CSV file[_2] is ready for download.', '<p><a href="'.$CSVfilename.'">','</a>')."</p>\n");   $r->print('<p>'.&mt('[_1]Your CSV file[_2] is ready for download.', '<a href="'.$CSVfilename.'">','</a>')."</p>\n");
         $r->rflush();          $r->rflush();
     }      }
     if ($mode eq 'autoenroll') {      if ($mode eq 'autoenroll') {
Line 3806  sub show_drop_list { Line 3839  sub show_drop_list {
 $check_uncheck_js  $check_uncheck_js
 // ]]>  // ]]>
 </script>  </script>
 <p>  
 <input type="hidden" name="phase" value="four" />  <input type="hidden" name="phase" value="four" />
 END  END
     my ($indexhash,$keylist) = &make_keylist_array();      my ($indexhash,$keylist) = &make_keylist_array();
Line 3843  END Line 3875  END
                                               $classlist,$keylist,$cdom,$cnum);                                                $classlist,$keylist,$cdom,$cnum);
     my %lt=&Apache::lonlocal::texthash('usrn'   => "username",      my %lt=&Apache::lonlocal::texthash('usrn'   => "username",
                                        'dom'    => "domain",                                         'dom'    => "domain",
                                          'id'     => "ID",
                                        'sn'     => "student name",                                         'sn'     => "student name",
                                        'mn'     => "member name",                                         'mn'     => "member name",
                                        'sec'    => "section",                                         'sec'    => "section",
Line 3861  END Line 3894  END
     <th>&nbsp;</th>      <th>&nbsp;</th>
     <th>$lt{'usrn'}</th>      <th>$lt{'usrn'}</th>
     <th>$lt{'dom'}</th>      <th>$lt{'dom'}</th>
     <th>ID</th>      <th>$lt{'id'}</th>
     <th>$nametitle</th>      <th>$nametitle</th>
     <th>$lt{'sec'}</th>      <th>$lt{'sec'}</th>
     <th>$lt{'start'}</th>      <th>$lt{'start'}</th>
Line 3875  END Line 3908  END
         $r->print(<<END);          $r->print(<<END);
     <th>&nbsp;</th>      <th>&nbsp;</th>
     <th>      <th>
        <a href="/adm/createuser?action=$action&sortby=username">$lt{'usrn'}</a>         <a href="/adm/createuser?action=$action&amp;sortby=username">$lt{'usrn'}</a>
     </th><th>      </th><th>
        <a href="/adm/createuser?action=$action&sortby=domain">$lt{'dom'}</a>         <a href="/adm/createuser?action=$action&amp;sortby=domain">$lt{'dom'}</a>
     </th><th>      </th><th>
        <a href="/adm/createuser?action=$action&sortby=id">ID</a>         <a href="/adm/createuser?action=$action&amp;sortby=id">$lt{'id'}</a>
     </th><th>      </th><th>
        <a href="/adm/createuser?action=$action&sortby=fullname">$nametitle</a>         <a href="/adm/createuser?action=$action&amp;sortby=fullname">$nametitle</a>
     </th><th>      </th><th>
        <a href="/adm/createuser?action=$action&sortby=section">$lt{'sec'}</a>         <a href="/adm/createuser?action=$action&amp;sortby=section">$lt{'sec'}</a>
     </th><th>      </th><th>
        <a href="/adm/createuser?action=$action&sortby=start">$lt{'start'}</a>         <a href="/adm/createuser?action=$action&amp;sortby=start">$lt{'start'}</a>
     </th><th>      </th><th>
        <a href="/adm/createuser?action=$action&sortby=end">$lt{'end'}</a>         <a href="/adm/createuser?action=$action&amp;sortby=end">$lt{'end'}</a>
     </th><th>      </th><th>
        <a href="/adm/createuser?action=$action&sortby=groups">$lt{'groups'}</a>         <a href="/adm/createuser?action=$action&amp;sortby=groups">$lt{'groups'}</a>
     </th>      </th>
 END  END
         $r->print(&Apache::loncommon::end_data_table_header_row());          $r->print(&Apache::loncommon::end_data_table_header_row());
Line 3960  END Line 3993  END
         $btn = $lt{'dm'};           $btn = $lt{'dm'}; 
     }      }
     $r->print(<<"END");      $r->print(<<"END");
 </p>  
 <p>  <p>
 <input type="button" value="$lt{'ca'}" onclick="javascript:checkAll(document.studentform.droplist)" /> &nbsp;  <input type="button" value="$lt{'ca'}" onclick="javascript:checkAll(document.studentform.droplist)" /> &nbsp;
 <input type="button" value="$lt{'ua'}" onclick="javascript:uncheckAll(document.studentform.droplist)" />  <input type="button" value="$lt{'ua'}" onclick="javascript:uncheckAll(document.studentform.droplist)" />
Line 4290  sub upfile_drop_add { Line 4322  sub upfile_drop_add {
                     if ($entries{$fields{'username'}} =~ /\s/) {                      if ($entries{$fields{'username'}} =~ /\s/) {
                         $nowhitespace = ' - '.&mt('usernames may not contain spaces.');                          $nowhitespace = ' - '.&mt('usernames may not contain spaces.');
                     }                      }
                     $r->print('<br />'.                      $r->print(
       &mt('[_1]: Unacceptable username for user [_2] [_3] [_4] [_5]',                          '<br />'.
           '<b>'.$entries{$fields{'username'}}.'</b>',$fname,$mname,$lname,$gen).                          &mt('Unacceptable username [_1] for user [_2] [_3] [_4] [_5]',
                               $nowhitespace);                                  '"<b>'.$entries{$fields{'username'}}.'</b>"',
                                   $fname,$mname,$lname,$gen).
                           $nowhitespace);
                     next;                      next;
                 } else {                  } else {
                     $entries{$fields{'domain'}} =~ s/^\s+|\s+$//g;                      $entries{$fields{'domain'}} =~ s/^\s+|\s+$//g;
                     if ($entries{$fields{'domain'}}                       if ($entries{$fields{'domain'}} 
                         ne &LONCAPA::clean_domain($entries{$fields{'domain'}})) {                          ne &LONCAPA::clean_domain($entries{$fields{'domain'}})) {
                         $r->print('<br />'. '<b>'.$entries{$fields{'domain'}}.                          $r->print(
                                   '</b>: '.&mt('Unacceptable domain for user [_1] [_2] [_3] [_4]',$fname,$mname,$lname,$gen));                              '<br />'.
                         next;                              &mt('Unacceptable domain [_1] for user [_2] [_3] [_4] [_5]',
                                      '"<b>'.$entries{$fields{'domain'}}.'</b>"',
                                       $fname,$mname,$lname,$gen));
                       next;
                     }                      }
                     my $username = $entries{$fields{'username'}};                      my $username = $entries{$fields{'username'}};
                     my $userdomain = $entries{$fields{'domain'}};                      my $userdomain = $entries{$fields{'domain'}};
Line 4645  sub upfile_drop_add { Line 4682  sub upfile_drop_add {
             #  Get current classlist              #  Get current classlist
             my $classlist = &Apache::loncoursedata::get_classlist();              my $classlist = &Apache::loncoursedata::get_classlist();
             if (! defined($classlist)) {              if (! defined($classlist)) {
                 $r->print('<form name="studentform" method="post" action="/adm/createuser" />'.                  $r->print('<form name="studentform" method="post" action="/adm/createuser">'.
                           '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />'.                            '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />'.
                           '<p class="LC_info">'.&mt('There are no students with current/future access to the course.').'</p>'.                            '<p class="LC_info">'.&mt('There are no students with current/future access to the course.').'</p>'.
                           '</form>'."\n");                            '</form>'."\n");
Line 4768  sub print_drop_menu { Line 4805  sub print_drop_menu {
         $heading = &mt("Drop Students");          $heading = &mt("Drop Students");
     }      }
     $r->print('<h3>'.$heading.'</h3>'."\n".      $r->print('<h3>'.$heading.'</h3>'."\n".
               '<form name="studentform" method="post">'."\n");                '<form name="studentform" method="post" action="">'."\n");
     my $classlist = &Apache::loncoursedata::get_classlist();      my $classlist = &Apache::loncoursedata::get_classlist();
     if (! defined($classlist)) {      if (! defined($classlist)) {
         my $msg = '';          my $msg = '';
Line 4781  sub print_drop_menu { Line 4818  sub print_drop_menu {
     } else {      } else {
         &show_drop_list($r,$classlist,'nosort',$permission,$crstype);          &show_drop_list($r,$classlist,'nosort',$permission,$crstype);
     }      }
     $r->print('</form>'. &Apache::loncommon::end_page());      $r->print('</form>');
     return;      return;
 }  }
   
Line 5314  sub setsections_javascript { Line 5351  sub setsections_javascript {
         }          }
         $rolecode = "var match = str.split('_');          $rolecode = "var match = str.split('_');
                 var role = match[3];\n";                  var role = match[3];\n";
     } elsif ($formname eq 'enrollstudent') {      } elsif (($formname eq 'enrollstudent') || ($formname eq 'selfenroll')) {
         $checkincluded = 'formname.name == "'.$formname.'"';          $checkincluded = 'formname.name == "'.$formname.'"';
         if ($checkauth) {          if ($checkauth) {
             $finish = "var authcheck = auth_check();\n".              $finish = "var authcheck = auth_check();\n".
Line 5664  sub get_permission { Line 5701  sub get_permission {
         if (&Apache::lonnet::allowed('mdg',$env{'request.course.id'})) {          if (&Apache::lonnet::allowed('mdg',$env{'request.course.id'})) {
             $permission{'grp_manage'} = 1;              $permission{'grp_manage'} = 1;
         }          }
           if ($permission{'cusr'}) {
               my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
               my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
               my %coursehash = (
                   'internal.selfenrollmgrdc' => $env{'course.'.$env{'request.course.id'}.'.internal.selfenrollmgrdc'},
                   'internal.selfenrollmgrcc' => $env{'course.'.$env{'request.course.id'}.'.internal.selfenrollmgrcc'},
                   'internal.coursecode'      => $env{'course.'.$env{'request.course.id'}.'.internal.coursecode'},
                   'internal.textbook'        =>$env{'course.'.$env{'request.course.id'}.'.internal.textbook'},
               );
               my ($managed_by_cc,$managed_by_dc) = &selfenrollment_administration($cdom,$cnum,$crstype,\%coursehash);
               if (ref($managed_by_cc) eq 'ARRAY') {
                   if (@{$managed_by_cc}) {
                       $permission{'selfenrolladmin'} = 1;
                   }
               }
           }
     } elsif ($context eq 'author') {      } elsif ($context eq 'author') {
         $permission{'cusr'} = &authorpriv($env{'user.name'},$env{'request.role.domain'});          $permission{'cusr'} = &authorpriv($env{'user.name'},$env{'request.role.domain'});
         $permission{'view'} = $permission{'cusr'};          $permission{'view'} = $permission{'cusr'};
Line 5994  sub is_courseowner { Line 6047  sub is_courseowner {
     return;      return;
 }  }
   
   sub get_selfenroll_titles {
       my @row = ('types','registered','enroll_dates','access_dates','section',
                  'approval','limit');
       my %lt = &Apache::lonlocal::texthash (
                   types        => 'Users allowed to self-enroll',
                   registered   => 'Registration status (official courses)' ,
                   enroll_dates => 'Dates self-enrollment available',
                   access_dates => 'Access dates for self-enrolling users',
                   section      => "Self-enrolling users' section",
                   approval     => 'Processing of requests',
                   limit        => 'Enrollment limit',
                );
       return (\@row,\%lt);
   }
   
   sub selfenroll_default_descs {
       my %desc = (
                    types => {
                               dom => &mt('Course domain'),
                               all => &mt('Any domain'),
                               ''  => &mt('None'),
                             },
                    limit => {
                               none         => &mt('No limit'),
                               allstudents  => &mt('Limit by total students'),
                               selfenrolled => &mt('Limit by total self-enrolled'),
                             },
                    approval => {
                                   '0' => &mt('Processed automatically'),
                                   '1' => &mt('Queued for approval'),
                                   '2' => &mt('Queued, pending validation'),
                                },
                    registered => {
                                    0 => 'No registration required',
                                    1 => 'Registered students only',
                                  },
                  );
       return %desc;
   }
   
   sub selfenroll_validation_types {
       my @items = ('url','fields','button','markup');
       my %names =  &Apache::lonlocal::texthash (
               url      => 'Web address of validation server/script',
               fields   => 'Form fields to send to validator',
               button   => 'Text for validation button',
               markup   => 'Validation description (HTML)',
       );
       my @fields = ('username','domain','uniquecode','course','token','coursetype','description');
       return (\@items,\%names,\@fields);
   }
   
   sub get_extended_type {
       my ($cdom,$cnum,$crstype,$current) = @_;
       my $type = 'unofficial';
       my %settings;
       if (ref($current) eq 'HASH') {
           %settings = %{$current};
       } else {
           %settings = &Apache::lonnet::get('environment',['internal.coursecode','internal.textbook'],$cdom,$cnum);
       }
       if ($crstype eq 'Community') {
           $type = 'community';
       } elsif ($settings{'internal.coursecode'}) {
           $type = 'official';
       } elsif ($settings{'internal.textbook'}) {
           $type = 'textbook';
       }
       return $type;
   }
   
   sub selfenrollment_administration {
       my ($cdom,$cnum,$crstype,$coursehash) = @_;
       my %settings;
       if (ref($coursehash) eq 'HASH') {
           %settings = %{$coursehash};
       } else {
           %settings = &Apache::lonnet::get('environment',
                           ['internal.selfenrollmgrdc','internal.selfenrollmgrcc',
                            'internal.coursecode','internal.textbook'],$cdom,$cnum);
       }
       my ($possconfigs) = &get_selfenroll_titles(); 
       my %domdefaults = &Apache::lonnet::get_domain_defaults($cdom);
       my $selfenrolltype = &get_extended_type($cdom,$cnum,$crstype,\%settings);
   
       my (@in_course,@in_domain); 
       if ($settings{'internal.selfenrollmgrcc'} ne '') {
           @in_course = split(/,/,$settings{'internal.selfenrollmgrcc'}); 
           my @diffs = &Apache::loncommon::compare_arrays($possconfigs,\@in_course);
           unless (@diffs) {
               return (\@in_course,\@in_domain);
           }
       }
       if ($settings{'internal.selfenrollmgrdc'} ne '') {
           my @in_domain = split(/,/,$settings{'internal.selfenrollmgrdc'});
           my @diffs = &Apache::loncommon::compare_arrays(\@in_domain,$possconfigs);
           unless (@diffs) {
               return (\@in_course,\@in_domain);
           }
       }
       my @combined = @in_course;
       push(@combined,@in_domain);
       my @diffs = &Apache::loncommon::compare_arrays(\@combined,$possconfigs); 
       unless (@diffs) {
           return (\@in_course,\@in_domain);
       }
       if ($domdefaults{$selfenrolltype.'selfenrolladmdc'} eq '') {
           push(@in_course,@diffs);
       } else {
           my @defaultdc = split(/,/,$domdefaults{$selfenrolltype.'selfenrolladmdc'});
           foreach my $item (@diffs) {
               if (grep(/^\Q$item\E$/,@defaultdc)) {
                   push(@in_domain,$item);
               } else {
                   push(@in_course,$item);
               }
           }
       }
       return (\@in_course,\@in_domain);
   }
   
 1;  1;
   

Removed from v.1.150  
changed lines
  Added in v.1.166


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