Diff for /loncom/interface/lonuserutils.pm between versions 1.109.2.2 and 1.136.6.1

version 1.109.2.2, 2010/01/05 22:08:48 version 1.136.6.1, 2012/02/08 16:27:28
Line 47  sub modifystudent { Line 47  sub modifystudent {
     # this one.  If $csec is defined, drop them from all other sections of      # this one.  If $csec is defined, drop them from all other sections of
     # this course and add them to section $csec      # this course and add them to section $csec
     my ($cnum,$cdom) = &get_course_identity($courseid);      my ($cnum,$cdom) = &get_course_identity($courseid);
     my %roles = &Apache::lonnet::dump('roles',$udom,$unam);      my $extra = &Apache::lonnet::freeze_escape({'skipcheck' => 1});
       my %roles = &Apache::lonnet::dump('roles',$udom,$unam,'.',undef,$extra);
     my ($tmp) = keys(%roles);      my ($tmp) = keys(%roles);
     # Bail out if we were unable to get the students roles      # Bail out if we were unable to get the students roles
     return "$1" if ($tmp =~ /^(con_lost|error|no_such_host)/i);      return "$1" if ($tmp =~ /^(con_lost|error|no_such_host)/i);
Line 295  sub hidden_input { Line 296  sub hidden_input {
 }  }
   
 sub print_upload_manager_header {  sub print_upload_manager_header {
     my ($r,$datatoken,$distotal,$krbdefdom,$context,$permission,$crstype)=@_;      my ($r,$datatoken,$distotal,$krbdefdom,$context,$permission,$crstype,
           $can_assign)=@_;
     my $javascript;      my $javascript;
     #      #
     if (! exists($env{'form.upfile_associate'})) {      if (! exists($env{'form.upfile_associate'})) {
Line 309  sub print_upload_manager_header { Line 311  sub print_upload_manager_header {
         }          }
     }      }
     if ($env{'form.upfile_associate'} eq 'reverse') {      if ($env{'form.upfile_associate'} eq 'reverse') {
         $javascript=&upload_manager_javascript_reverse_associate();          $javascript=&upload_manager_javascript_reverse_associate($can_assign);
     } else {      } else {
         $javascript=&upload_manager_javascript_forward_associate();          $javascript=&upload_manager_javascript_forward_associate($can_assign);
     }      }
     #      #
     # Deal with restored settings      # Deal with restored settings
Line 532  END Line 534  END
         if (message!='') {          if (message!='') {
             message+='\\n';              message+='\\n';
         }          }
           message+='$alert{'section'}';
     }      }
     if (foundemail==0) {      if (foundemail==0) {
         if (message!='') {          if (message!='') {
Line 585  END Line 588  END
 ###############################################################  ###############################################################
 ###############################################################  ###############################################################
 sub upload_manager_javascript_forward_associate {  sub upload_manager_javascript_forward_associate {
       my ($can_assign) = @_;
       my ($auth_update,$numbuttons,$argreset);
       if (ref($can_assign) eq 'HASH') {
           if ($can_assign->{'krb4'} || $can_assign->{'krb5'}) {
               $argreset .= "      vf.krbarg.value='';\n";
               $numbuttons ++ ;
           }
           if ($can_assign->{'int'}) {
               $argreset .= "      vf.intarg.value='';\n";
               $numbuttons ++;
           }
           if ($can_assign->{'loc'}) {
               $argreset .= "      vf.locarg.value='';\n";
               $numbuttons ++;
           }
           if (!$can_assign->{'int'}) {
               my $warning = &mt('You may not specify an initial password for each user, as this is only available when new users use LON-CAPA internal authentication.\n').
                             &mt('Your current role does not have rights to create users with that authentication type.');
               $auth_update = <<"END";
      // Currently the initial password field is only supported for internal auth
      // (see bug 6368).
      if (nw==9) {
          eval('vf.f'+tf+'.selectedIndex=0;')
          alert('$warning');
      }
   END
           } elsif ($numbuttons > 1) {
               $auth_update = <<"END";
      // If we set the password, make the password form below correspond to
      // the new value.
      if (nw==9) {
         changed_radio('int',document.studentform);
         set_auth_radio_buttons('int',document.studentform);
   $argreset
      }
   
   END
           }
       }
   
     return(<<ENDPICK);      return(<<ENDPICK);
 function verify(vf,sec_caller) {  function verify(vf,sec_caller) {
     var founduname=0;      var founduname=0;
Line 661  function flip(vf,tf) { Line 704  function flip(vf,tf) {
          }           }
       }        }
    }     }
    // If we set the password, make the password form below correspond to     $auth_update
    // the new value.  
    if (nw==9) {  
        changed_radio('int',document.studentform);  
        set_auth_radio_buttons('int',document.studentform);  
        vf.intarg.value='';  
        vf.krbarg.value='';  
        vf.locarg.value='';  
    }  
 }  }
   
 function clearpwd(vf) {  function clearpwd(vf) {
Line 687  ENDPICK Line 722  ENDPICK
 ###############################################################  ###############################################################
 ###############################################################  ###############################################################
 sub upload_manager_javascript_reverse_associate {  sub upload_manager_javascript_reverse_associate {
       my ($can_assign) = @_;
       my ($auth_update,$numbuttons,$argreset);
       if (ref($can_assign) eq 'HASH') {
           if ($can_assign->{'krb4'} || $can_assign->{'krb5'}) {
               $argreset .= "      vf.krbarg.value='';\n";
               $numbuttons ++ ;
           }
           if ($can_assign->{'int'}) {
               $argreset .= "      vf.intarg.value='';\n";
               $numbuttons ++;
           }
           if ($can_assign->{'loc'}) {
               $argreset .= "      vf.locarg.value='';\n";
               $numbuttons ++;
           }
           if (!$can_assign->{'int'}) {
               my $warning = &mt('You may not specify an initial password, as this is only available when new users use LON-CAPA internal authentication.\n').
                             &mt('Your current role does not have rights to create users with that authentication type.');
               $auth_update = <<"END";
      // Currently the initial password field is only supported for internal auth
      // (see bug 6368).
      if (tf==8 && nw!=0) {
          eval('vf.f'+tf+'.selectedIndex=0;')
          alert('$warning');
      }
   END
           } elsif ($numbuttons > 1) {
               $auth_update = <<"END";
      // initial password specified, pick internal authentication
      if (tf==8 && nw!=0) {
         changed_radio('int',document.studentform);
         set_auth_radio_buttons('int',document.studentform);
   $argreset
      }
   
   END
           }
       }
   
     return(<<ENDPICK);      return(<<ENDPICK);
 function verify(vf,sec_caller) {  function verify(vf,sec_caller) {
     var founduname=0;      var founduname=0;
Line 694  function verify(vf,sec_caller) { Line 768  function verify(vf,sec_caller) {
     var foundname=0;      var foundname=0;
     var foundid=0;      var foundid=0;
     var foundsec=0;      var foundsec=0;
       var foundemail=0;
     var foundrole=0;      var foundrole=0;
     var founddomain=0;      var founddomain=0;
     var foundinststatus=0;      var foundinststatus=0;
Line 705  function verify(vf,sec_caller) { Line 780  function verify(vf,sec_caller) {
         if (i==6 && tw!=0) { foundid=1; }          if (i==6 && tw!=0) { foundid=1; }
         if (i==7 && tw!=0) { foundsec=1; }          if (i==7 && tw!=0) { foundsec=1; }
         if (i==8 && tw!=0) { foundpwd=1; }          if (i==8 && tw!=0) { foundpwd=1; }
         if (i==9 && tw!=0) { foundrole=1; }          if (i==9 && tw!=0) { foundemail=1; }
         if (i==10 && tw!=0) { founddomain=1; }          if (i==10 && tw!=0) { foundrole=1; }
         if (i==13 && tw!=0) { foundinstatus=1; }          if (i==11 && tw!=0) { founddomain=1; }
           if (i==12 && tw!=0) { foundinstatus=1; }
     }      }
     verify_message(vf,founduname,foundpwd,foundname,foundid,foundsec,foundrole,founddomain,foundinststatus);      verify_message(vf,founduname,foundpwd,foundname,foundid,foundsec,foundemail,foundrole,founddomain,foundinststatus);
 }  }
   
 function flip(vf,tf) {  function flip(vf,tf) {
Line 726  function flip(vf,tf) { Line 802  function flip(vf,tf) {
    if ((tf>=2) && (tf<=5) && (nw!=0)) {     if ((tf>=2) && (tf<=5) && (nw!=0)) {
       eval('vf.f1.selectedIndex=0;')        eval('vf.f1.selectedIndex=0;')
    }     }
    // intial password specified, pick internal authentication     $auth_update
    if (tf==8 && nw!=0) {  
        changed_radio('int',document.studentform);  
        set_auth_radio_buttons('int',document.studentform);  
        vf.krbarg.value='';  
        vf.intarg.value='';  
        vf.locarg.value='';  
    }  
 }  }
   
 function clearpwd(vf) {  function clearpwd(vf) {
Line 978  sub print_upload_manager_form { Line 1047  sub print_upload_manager_form {
     my ($krbdef,$krbdefdom) =      my ($krbdef,$krbdefdom) =
         &Apache::loncommon::get_kerberos_defaults($defdom);          &Apache::loncommon::get_kerberos_defaults($defdom);
     #      #
       my ($authnum,%can_assign) =  &Apache::loncommon::get_assignable_auth($defdom);
     &print_upload_manager_header($r,$datatoken,$distotal,$krbdefdom,$context,      &print_upload_manager_header($r,$datatoken,$distotal,$krbdefdom,$context,
                                  $permission,$crstype);                                   $permission,$crstype,\%can_assign);
     my $i;      my $i;
     my $keyfields;      my $keyfields;
     if ($total>=0) {      if ($total>=0) {
Line 1185  sub default_role_selector { Line 1255  sub default_role_selector {
                     'exs'  => "Existing sections",                      'exs'  => "Existing sections",
                     'new'  => "New section",                      'new'  => "New section",
                   );                    );
     $options = '<select name="defaultrole">'."\n";      $options = '<select name="defaultrole">'."\n".
     unless (($context eq 'course') && (&Apache::loncommon::needs_gci_custom())) {                 ' <option value="">'.&mt('Please select').'</option>'."\n"; 
         $options .= ' <option value="">'.&mt('Please select').'</option>'."\n";  
     }  
     if ($context eq 'course') {      if ($context eq 'course') {
         $options .= &default_course_roles($context,$checkpriv,$crstype,%customroles);          $options .= &default_course_roles($context,$checkpriv,$crstype,%customroles);
     } elsif ($context eq 'author') {      } elsif ($context eq 'author') {
Line 1450  sub print_userlist { Line 1518  sub print_userlist {
     }      }
     if (!(($context eq 'domain') &&       if (!(($context eq 'domain') && 
           (($env{'form.roletype'} eq 'course') || ($env{'form.roletype'} eq 'community')))) {            (($env{'form.roletype'} eq 'course') || ($env{'form.roletype'} eq 'community')))) {
         $r->print('&nbsp;'.&list_submit_button(&mt('Update Display')).          $r->print(
                   "\n</p>\n");              "\n</p>\n"
              .'<p>'
              .&list_submit_button(&mt('Update Display'))
              ."</p>\n"
           );
     }      }
     my ($indexhash,$keylist) = &make_keylist_array();      my ($indexhash,$keylist) = &make_keylist_array();
     my (%userlist,%userinfo,$clearcoursepick);      my (%userlist,%userinfo,$clearcoursepick);
Line 1470  sub print_userlist { Line 1542  sub print_userlist {
             $title = &mt('Select Communities');              $title = &mt('Select Communities');
             $warning = &mt('Warning: data retrieval for multiple communities can take considerable time, as this operation is not currently optimized.');              $warning = &mt('Warning: data retrieval for multiple communities can take considerable time, as this operation is not currently optimized.');
         }          }
           my @standardnames = &Apache::loncommon::get_standard_codeitems();
         my $courseform =          my $courseform =
             &Apache::lonhtmlcommon::course_selection($formname,$numcodes,              &Apache::lonhtmlcommon::course_selection($formname,$numcodes,
                             $codetitles,$idlist,$idlist_titles,$crstype);                              $codetitles,$idlist,$idlist_titles,$crstype,
                               \@standardnames);
         $r->print('<p>'.&Apache::lonhtmlcommon::start_pick_box()."\n".          $r->print('<p>'.&Apache::lonhtmlcommon::start_pick_box()."\n".
                   &Apache::lonhtmlcommon::start_pick_box()."\n".                    &Apache::lonhtmlcommon::start_pick_box()."\n".
                   &Apache::lonhtmlcommon::row_title($title,'LC_oddrow_value')."\n".                    &Apache::lonhtmlcommon::row_title($title,'LC_oddrow_value')."\n".
Line 1690  sub role_filter { Line 1764  sub role_filter {
         $role_select .= '</select>';          $role_select .= '</select>';
         $output = '<label><span class="LC_nobreak">'          $output = '<label><span class="LC_nobreak">'
                  .&mt('Role: [_1]',$role_select)                   .&mt('Role: [_1]',$role_select)
                  .'</span></label>';                   .'</span></label> ';
     }      }
     return $output;      return $output;
 }  }
Line 1730  sub section_group_filter { Line 1804  sub section_group_filter {
         }          }
         if (@options > 0) {          if (@options > 0) {
             my $currsel;              my $currsel;
             $markup = '<select name="'.$name{$item}.'" />'."\n";              $markup = '<select name="'.$name{$item}.'">'."\n";
             foreach my $option ('all','none',@options) {               foreach my $option ('all','none',@options) { 
                 $currsel = '';                  $currsel = '';
                 if ($env{'form.'.$name{$item}} eq $option) {                  if ($env{'form.'.$name{$item}} eq $option) {
Line 1745  sub section_group_filter { Line 1819  sub section_group_filter {
                 $markup .= '</option>'."\n";                  $markup .= '</option>'."\n";
             }              }
             $markup .= '</select>'."\n";              $markup .= '</select>'."\n";
             $output .= ('&nbsp;'x3).'<label>'.$title{$item}.': '.$markup.'</label>';              $output .= ('&nbsp;'x3).'<span class="LC_nobreak">'
                         .'<label>'.$title{$item}.': '.$markup.'</label>'
                         .'</span> ';
         }          }
     }      }
     return $output;      return $output;
Line 1919  function setCourseCat(formname) { Line 1995  function setCourseCat(formname) {
     if (formname.Year.options[formname.Year.selectedIndex].value == -1) {      if (formname.Year.options[formname.Year.selectedIndex].value == -1) {
         return;          return;
     }      }
     courseSet('Year');      courseSet('$codetitles[0]');
     for (var j=0; j<formname.Semester.length; j++) {      for (var j=0; j<formname.Semester.length; j++) {
         if (formname.Semester.options[j].value == "$env{'form.Semester'}") {          if (formname.Semester.options[j].value == "$env{'form.Semester'}") {
             formname.Semester.options[j].selected = true;              formname.Semester.options[j].selected = true;
Line 1928  function setCourseCat(formname) { Line 2004  function setCourseCat(formname) {
     if (formname.Semester.options[formname.Semester.selectedIndex].value == -1) {      if (formname.Semester.options[formname.Semester.selectedIndex].value == -1) {
         return;          return;
     }      }
     courseSet('Semester');      courseSet('$codetitles[1]');
     for (var j=0; j<formname.Department.length; j++) {      for (var j=0; j<formname.Department.length; j++) {
         if (formname.Department.options[j].value == "$env{'form.Department'}") {            formname.Department.options[j].selected = true;          if (formname.Department.options[j].value == "$env{'form.Department'}") {            formname.Department.options[j].selected = true;
         }          }
Line 1936  function setCourseCat(formname) { Line 2012  function setCourseCat(formname) {
     if (formname.Department.options[formname.Department.selectedIndex].value == -1) {      if (formname.Department.options[formname.Department.selectedIndex].value == -1) {
         return;          return;
     }      }
     courseSet('Department');      courseSet('$codetitles[2]');
     for (var j=0; j<formname.Number.length; j++) {      for (var j=0; j<formname.Number.length; j++) {
         if (formname.Number.options[j].value == "$env{'form.Number'}") {          if (formname.Number.options[j].value == "$env{'form.Number'}") {
             formname.Number.options[j].selected = true;              formname.Number.options[j].selected = true;
Line 2245  END Line 2321  END
                        'type'       => "enroll type/action",                         'type'       => "enroll type/action",
                        'email'      => "e-mail address",                         'email'      => "e-mail address",
                        'photo'      => "photo",                         'photo'      => "photo",
                          'lastlogin'  => "last login"
                        'extent'     => "extent",                         'extent'     => "extent",
                        'pr'         => "Proceed",                         'pr'         => "Proceed",
                        'ca'         => "check all",                         'ca'         => "check all",
Line 2293  END Line 2370  END
             push(@cols,'groups');              push(@cols,'groups');
         }          }
         push(@cols,'email');          push(@cols,'email');
           if ($context eq 'course') {
               push(@cols,'lastlogin');
           }
     }      }
   
     my $rolefilter = $env{'form.showrole'};      my $rolefilter = $env{'form.showrole'};
Line 2399  END Line 2479  END
             if ($env{'form.userwin'}) {              if ($env{'form.userwin'}) {
                 $checkwin = ' checked="checked"';                  $checkwin = ' checked="checked"';
             }              }
             $output .= '</td><td valign="top"><span class="LC_nobreak"><input type="checkbox" name="userwin" value="1"'.$checkwin.' />'.$lt{'owin'}.'</span></td></tr></table></fieldset></div>';              $output .= '</td><td valign="top"  style="border-left: 1px solid;"><span class="LC_nobreak"><input type="checkbox" name="userwin" value="1"'.$checkwin.' />'.$lt{'owin'}.'</span></td></tr></table></fieldset></div>';
         }          }
         $output .= "\n".'<div class="LC_clear_float_footer">&nbsp;</div>'."\n".          $output .= "\n".'<div class="LC_clear_float_footer">&nbsp;</div>'."\n".
                   &Apache::loncommon::start_data_table().                    &Apache::loncommon::start_data_table().
Line 2517  END Line 2597  END
                                                 Future  => 'Future',                                                  Future  => 'Future',
                                                 Expired => 'Expired',                                                  Expired => 'Expired',
                                                );                                                 );
       # If this is for a single course get last course "log-in".
       my %crslogins;
       if ($context eq 'course') {
           %crslogins=&Apache::lonnet::dump('nohist_crslastlogin',$cdom,$cnum);
       }
     # Get groups, role, permanent e-mail so we can sort on them if      # Get groups, role, permanent e-mail so we can sort on them if
     # necessary.      # necessary.
     foreach my $user (keys(%{$userlist})) {      foreach my $user (keys(%{$userlist})) {
Line 2653  END Line 2738  END
         $in{'clicker'} = $clickers;           $in{'clicker'} = $clickers; 
  my $role = $in{'role'};   my $role = $in{'role'};
         $in{'role'}=&Apache::lonnet::plaintext($sdata->[$index{'role'}],$crstype);          $in{'role'}=&Apache::lonnet::plaintext($sdata->[$index{'role'}],$crstype);
         if (! defined($in{'start'}) || $in{'start'} == 0) {          unless ($mode eq 'excel') {
             $in{'start'} = &mt('none');              if (! defined($in{'start'}) || $in{'start'} == 0) {
         } else {                  $in{'start'} = &mt('none');
             $in{'start'} = &Apache::lonlocal::locallocaltime($in{'start'});              } else {
                   $in{'start'} = &Apache::lonlocal::locallocaltime($in{'start'});
               }
               if (! defined($in{'end'}) || $in{'end'} == 0) {
                   $in{'end'} = &mt('none');
               } else {
                   $in{'end'} = &Apache::lonlocal::locallocaltime($in{'end'});
               }
         }          }
         if (! defined($in{'end'}) || $in{'end'} == 0) {          if ($context eq 'course') {
             $in{'end'} = &mt('none');              my $lastlogin = $crslogins{$in{'username'}.':'.$in{'domain'}.':'.$in{'section'}.':'.$role};
         } else {              if ($lastlogin ne '') {
             $in{'end'} = &Apache::lonlocal::locallocaltime($in{'end'});                  $in{'lastlogin'} = &Apache::lonlocal::locallocaltime($lastlogin);
               }
         }          }
         if ($mode eq 'view' || $mode eq 'html' || $mode eq 'autoenroll' || $mode eq 'pickauthor') {          if ($mode eq 'view' || $mode eq 'html' || $mode eq 'autoenroll' || $mode eq 'pickauthor') {
             $r->print(&Apache::loncommon::start_data_table_row());              $r->print(&Apache::loncommon::start_data_table_row());
Line 2763  END Line 2856  END
         } elsif ($mode eq 'csv') {          } elsif ($mode eq 'csv') {
             next if (! defined($CSVfile));              next if (! defined($CSVfile));
             # no need to bother with $linkto              # no need to bother with $linkto
             if (! defined($in{'start'}) || $in{'start'} == 0) {  
                 $in{'start'} = &mt('none');  
             } else {  
                 $in{'start'} = &Apache::lonlocal::locallocaltime($in{'start'});  
             }  
             if (! defined($in{'end'}) || $in{'end'} == 0) {  
                 $in{'end'} = &mt('none');  
             } else {  
                 $in{'end'} = &Apache::lonlocal::locallocaltime($in{'end'});  
             }  
             my @line = ();              my @line = ();
             foreach my $item (@cols) {              foreach my $item (@cols) {
                 push @line,&Apache::loncommon::csv_translate($in{$item});                  push @line,&Apache::loncommon::csv_translate($in{$item});
Line 2782  END Line 2865  END
             my $col = 0;              my $col = 0;
             foreach my $item (@cols) {              foreach my $item (@cols) {
                 if ($item eq 'start' || $item eq 'end') {                  if ($item eq 'start' || $item eq 'end') {
                     if (defined($item) && $item != 0) {                      if ((defined($in{$item})) && ($in{$item} != 0)) {
                         $excel_sheet->write($row,$col++,                          $excel_sheet->write($row,$col++,
                             &Apache::lonstathelpers::calc_serial($in{item}),                              &Apache::lonstathelpers::calc_serial($in{$item}),
                                     $format->{'date'});                                      $format->{'date'});
                     } else {                      } else {
                         $excel_sheet->write($row,$col++,'none');                          $excel_sheet->write($row,$col++,'none');
Line 2939  sub print_username_link { Line 3022  sub print_username_link {
         $output = $in->{'username'};          $output = $in->{'username'};
     } else {      } else {
         $output = '<a href="javascript:username_display_launch('.          $output = '<a href="javascript:username_display_launch('.
                   "'$in->{'username'}','$in->{'domain'}'".')" />'.                    "'$in->{'username'}','$in->{'domain'}'".')">'.
                   $in->{'username'}.'</a>';                    $in->{'username'}.'</a>';
     }      }
     return $output;      return $output;
Line 3169  ENDJS Line 3252  ENDJS
     my %lt = &Apache::lonlocal::texthash (      my %lt = &Apache::lonlocal::texthash (
                  chac => 'Access dates to apply for selected users',                   chac => 'Access dates to apply for selected users',
                  chse => 'Changes in section affiliation to apply to selected users',                   chse => 'Changes in section affiliation to apply to selected users',
                  fors => 'For student roles changing the section, will result in a section switch as students may only be in one section of a course at a time.',                   fors => 'For student roles, changing the section will result in a section switch as students may only be in one section of a course at a time.',
                  forn => 'For a role in a course that is not a student role, a user may have roles in more than one section of a course at a time.',                   forn => 'For a course role that is not "student", users may have roles in more than one section at a time.',
                  reta => "Retain each user's current section affiliations?",                    reta => "Retain each user's current section affiliations?",
                  dnap => '(Does not apply to student roles).',                   dnap => '(Does not apply to student roles).',
             );              );
     my ($date_items,$headertext);      my ($date_items,$headertext);
Line 3189  ENDJS Line 3272  ENDJS
                                           $permission,$crstype);                                            $permission,$crstype);
     }      }
     $output .= '<h3>'.$headertext.'</h3>'.      $output .= '<h3>'.$headertext.'</h3>'.
                '<form name="'.$formname.'" method="post">'."\n".                 '<form name="'.$formname.'" method="post" action="">'."\n".
                 $date_items;                  $date_items;
     if ($context eq 'course' && $env{'form.bulkaction'} eq 'chgsec') {      if ($context eq 'course' && $env{'form.bulkaction'} eq 'chgsec') {
         my ($cnum,$cdom) = &get_course_identity();          my ($cnum,$cdom) = &get_course_identity();
         my $crstype = &Apache::loncommon::course_type();  
         if ($crstype eq 'Community') {          if ($crstype eq 'Community') {
             $lt{'fors'} = &mt('For member roles changing the section, will result in a section switch as members may only be in one section of a community at a time.');              $lt{'fors'} = &mt('For member roles, changing the section will result in a section switch, as members may only be in one section of a community at a time.');
             $lt{'forn'} = &mt('For a role in a community that is not a member role, a user may have roles in more than one section of a community at a time.');              $lt{'forn'} = &mt('For a community role that is not "member", users may have roles in more than one section at a time.');
             $lt{'dnap'} = &mt('(Does not apply to member roles).');               $lt{'dnap'} = &mt('(Does not apply to member roles).'); 
         }          }
         my $info;          my $info;
Line 3237  sub section_picker { Line 3319  sub section_picker {
     my ($cdom,$cnum,$role,$rowtitle,$permission,$context,$mode,$crstype) = @_;      my ($cdom,$cnum,$role,$rowtitle,$permission,$context,$mode,$crstype) = @_;
     my %sections_count = &Apache::loncommon::get_sections($cdom,$cnum);      my %sections_count = &Apache::loncommon::get_sections($cdom,$cnum);
     my $sections_select .= &course_sections(\%sections_count,$role);      my $sections_select .= &course_sections(\%sections_count,$role);
     my $secbox = '<p>'.&Apache::lonhtmlcommon::start_pick_box()."\n";      my $secbox = '<div>'.&Apache::lonhtmlcommon::start_pick_box()."\n";
     if ($mode eq 'upload') {      if ($mode eq 'upload') {
         my ($options,$cb_script,$coursepick) =          my ($options,$cb_script,$coursepick) =
             &default_role_selector($context,1,$crstype);              &default_role_selector($context,1,$crstype);
Line 3250  sub section_picker { Line 3332  sub section_picker {
                    '<td align="center">'.&mt('Existing sections')."\n".                     '<td align="center">'.&mt('Existing sections')."\n".
                    '<br />'.$sections_select.'</td><td align="center">'.                     '<br />'.$sections_select.'</td><td align="center">'.
                    &mt('New section').'<br />'."\n".                     &mt('New section').'<br />'."\n".
                    '<input type="text" name="newsec" size="15" />'."\n".                     '<input type="text" name="newsec" size="15" value="" />'."\n".
                    '<input type="hidden" name="sections" value="" />'."\n".                     '<input type="hidden" name="sections" value="" />'."\n".
                    '</td></tr></table>'."\n";                     '</td></tr></table>'."\n";
     } else {      } else {
Line 3259  sub section_picker { Line 3341  sub section_picker {
                    $env{'request.course.sec'};                     $env{'request.course.sec'};
     }      }
     $secbox .= &Apache::lonhtmlcommon::row_closure(1)."\n".      $secbox .= &Apache::lonhtmlcommon::row_closure(1)."\n".
                &Apache::lonhtmlcommon::end_pick_box().'</p>';                 &Apache::lonhtmlcommon::end_pick_box().'</div>';
     return $secbox;      return $secbox;
 }  }
   
Line 3400  sub results_header_row { Line 3482  sub results_header_row {
                 if ($rolefilter eq 'Any') {                  if ($rolefilter eq 'Any') {
                     $description .= &mt('All users with co-author roles in domain',$showfilter);                      $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);
                 }                  }
             }              }
         } elsif (($env{'form.roletype'} eq 'course') ||           } elsif (($env{'form.roletype'} eq 'course') || 
Line 3657  sub print_first_users_upload_form { Line 3739  sub print_first_users_upload_form {
     $str .= '<input type="hidden" name="action" value="upload" />';      $str .= '<input type="hidden" name="action" value="upload" />';
     $str .= '<input type="hidden" name="state"  value="got_file" />';      $str .= '<input type="hidden" name="state"  value="got_file" />';
   
     $str .= '<h3>'.&mt('Upload a file containing information about users').'</h3>'."\n";      $str .= '<h2>'.&mt('Upload a file containing information about users').'</h2>'."\n";
   
     # Excel and CSV Help      # Excel and CSV Help
     $str .= '<div class="LC_left_float">'      $str .= '<div class="LC_left_float">'
Line 3668  sub print_first_users_upload_form { Line 3750  sub print_first_users_upload_form {
                 &mt("How do I create a CSV file from a spreadsheet"))                  &mt("How do I create a CSV file from a spreadsheet"))
            .'</div><br clear="all" />'."\n";             .'</div><br clear="all" />'."\n";
     $str .= &Apache::lonhtmlcommon::start_pick_box()      $str .= &Apache::lonhtmlcommon::start_pick_box()
            .&Apache::lonhtmlcommon::row_title(&mt('File'))             .&Apache::lonhtmlcommon::row_title(&mt('File'));
            .&Apache::loncommon::upfile_select_html()      if (&Apache::lonlocal::current_language() ne 'en') {
           if ($context eq 'course') { 
               $str .= '<p class="LC_info">'."\n"
                      .&mt('Please upload an UTF8 encoded file to ensure a correct character encoding in your classlist.')."\n"
                      .'</p>'."\n";
           }
       }
       $str .= &Apache::loncommon::upfile_select_html()
            .&Apache::lonhtmlcommon::row_closure()             .&Apache::lonhtmlcommon::row_closure()
            .&Apache::lonhtmlcommon::row_title(             .&Apache::lonhtmlcommon::row_title(
                 '<label for="noFirstLine">'                  '<label for="noFirstLine">'
Line 3910  sub upfile_drop_add { Line 3999  sub upfile_drop_add {
                 $r->print($groupwarn.'<br />');                  $r->print($groupwarn.'<br />');
             }              }
         }          }
         my (%curr_rules,%got_rules,%alerts);          my (%curr_rules,%got_rules,%alerts,%cancreate);
         my %customroles = &my_custom_roles($crstype);          my %customroles = &my_custom_roles($crstype);
         my @permitted_roles =           my @permitted_roles = 
             &roles_on_upload($context,$setting,$crstype,%customroles);               &roles_on_upload($context,$setting,$crstype,%customroles);
           my %longtypes = &Apache::lonlocal::texthash(
                               official   => 'Institutional',
                               unofficial => 'Non-institutional',
                           );
           my $newuserdom = $env{'request.role.domain'};
           map { $cancreate{$_} = &can_create_user($newuserdom,$context,$_); } keys(%longtypes);
         # Get new users list          # Get new users list
         foreach my $line (@userdata) {          foreach my $line (@userdata) {
             my @secs;              my @secs;
             my %entries=&Apache::loncommon::record_sep($line);              my %entries=&Apache::loncommon::record_sep($line);
             # Determine user name              # Determine user name
               $entries{$fields{'username'}} =~ s/^\s+|\s+$//g;
             unless (($entries{$fields{'username'}} eq '') ||              unless (($entries{$fields{'username'}} eq '') ||
                     (!defined($entries{$fields{'username'}}))) {                      (!defined($entries{$fields{'username'}}))) {
                 my ($fname, $mname, $lname,$gen) = ('','','','');                  my ($fname, $mname, $lname,$gen) = ('','','','');
Line 3939  sub upfile_drop_add { Line 4035  sub upfile_drop_add {
                         $gen=$entries{$fields{'gen'}};                          $gen=$entries{$fields{'gen'}};
                     }                      }
                 }                  }
   
                 if ($entries{$fields{'username'}}                  if ($entries{$fields{'username'}}
                     ne &LONCAPA::clean_username($entries{$fields{'username'}})) {                      ne &LONCAPA::clean_username($entries{$fields{'username'}})) {
                       my $nowhitespace;
                       if ($entries{$fields{'username'}} =~ /\s/) {
                           $nowhitespace = ' - '.&mt('usernames may not contain spaces.');
                       }
                     $r->print('<br />'.                      $r->print('<br />'.
       &mt('[_1]: Unacceptable username for user [_2] [_3] [_4] [_5]',        &mt('[_1]: Unacceptable username for user [_2] [_3] [_4] [_5]',
           '<b>'.$entries{$fields{'username'}}.'</b>',$fname,$mname,$lname,$gen));            '<b>'.$entries{$fields{'username'}}.'</b>',$fname,$mname,$lname,$gen).
                                 $nowhitespace);
                     next;                      next;
                 } else {                  } else {
                       $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('<br />'. '<b>'.$entries{$fields{'domain'}}.
Line 4004  sub upfile_drop_add { Line 4107  sub upfile_drop_add {
                     # determine email address                      # determine email address
                     my $email='';                      my $email='';
                     if (defined($fields{'email'})) {                      if (defined($fields{'email'})) {
                           $entries{$fields{'email'}} =~ s/^\s+|\s+$//g;
                         if (defined($entries{$fields{'email'}})) {                          if (defined($entries{$fields{'email'}})) {
                             $email=$entries{$fields{'email'}};                              $email=$entries{$fields{'email'}};
                             unless ($email=~/^[^\@]+\@[^\@]+$/) { $email=''; }                              unless ($email=~/^[^\@]+\@[^\@]+$/) { $email=''; }
Line 4050  sub upfile_drop_add { Line 4154  sub upfile_drop_add {
                         $role = $defaultrole;                          $role = $defaultrole;
                     }                      }
                     # Clean up whitespace                      # Clean up whitespace
                     foreach (\$id,\$fname,\$mname,\$lname,\$gen) {                      foreach (\$id,\$fname,\$mname,\$lname,\$gen,\$inststatus) {
                         $$_ =~ s/(\s+$|^\s+)//g;                          $$_ =~ s/(\s+$|^\s+)//g;
                     }                      }
                     # check against rules                      # check against rules
Line 4059  sub upfile_drop_add { Line 4163  sub upfile_drop_add {
                     my (%rulematch,%inst_results,%idinst_results);                      my (%rulematch,%inst_results,%idinst_results);
                     my $uhome=&Apache::lonnet::homeserver($username,$userdomain);                      my $uhome=&Apache::lonnet::homeserver($username,$userdomain);
                     if ($uhome eq 'no_host') {                      if ($uhome eq 'no_host') {
                         next if ($userdomain ne $domain);                          if ($userdomain ne $newuserdom) {
                               if ($context eq 'course') {
                                   $r->print('<br />'.
                                             &mt('[_1]: The domain specified ([_2]) is different to that of the course.',
                                             '<b>'.$username.'</b>',$userdomain).'<br />');
                               } elsif ($context eq 'author') {
                                   $r->print(&mt('[_1]: The domain specified ([_2]) is different to that of the author.',
                                           '<b>'.$username.'</b>',$userdomain).'<br />'); 
                               } else {
                                   $r->print(&mt('[_1]: The domain specified ([_2]) is different to that of your current role.',
                                           '<b>'.$username.'</b>',$userdomain).'<br />');
                               }
                               $r->print(&mt('The user does not already exist, and you may not create a new user in a different domain.'));
                               next;
                           }
                         $checkid = 1;                          $checkid = 1;
                         $newuser = 1;                          $newuser = 1;
                           my $user = $username.':'.$newuserdom;
                         my $checkhash;                          my $checkhash;
                         my $checks = { 'username' => 1 };                          my $checks = { 'username' => 1 };
                         $checkhash->{$username.':'.$domain} = { 'newuser' => 1, };                          $checkhash->{$username.':'.$newuserdom} = { 'newuser' => 1, };
                         &Apache::loncommon::user_rule_check($checkhash,$checks,                          &Apache::loncommon::user_rule_check($checkhash,$checks,
                             \%alerts,\%rulematch,\%inst_results,\%curr_rules,                              \%alerts,\%rulematch,\%inst_results,\%curr_rules,
                             \%got_rules);                              \%got_rules);
                         if (ref($alerts{'username'}) eq 'HASH') {                          if (ref($alerts{'username'}) eq 'HASH') {
                             if (ref($alerts{'username'}{$domain}) eq 'HASH') {                              if (ref($alerts{'username'}{$newuserdom}) eq 'HASH') {
                                 next if ($alerts{'username'}{$domain}{$username});                                  if ($alerts{'username'}{$newuserdom}{$username}) {
                                       $r->print('<br />'.
                                                 &mt('[_1]: matches the username format at your institution, but is not known to your directory service.','<b>'.$username.'</b>').'<br />'.
                                                 &mt('Consequently, the user was not created.'));
                                       next;
                                   }
                               }
                           }
                           my $usertype = 'unofficial';
                           if (ref($rulematch{$user}) eq 'HASH') {
                               if ($rulematch{$user}{'username'}) {
                                   $usertype = 'official';
                             }                              }
                         }                          }
                           unless ($cancreate{$usertype}) {
                               my $showtype = $longtypes{$usertype};
                               $r->print('<br />'.
                                         &mt('[_1]: The user does not exist, and you are not permitted to create users of type: [_2].','<b>'.$username.'</b>',$showtype));
                               next;
                           }
                     } else {                      } else {
                         if ($context eq 'course' || $context eq 'author') {                          if ($context eq 'course' || $context eq 'author') {
                             if ($userdomain eq $domain ) {                              if ($userdomain eq $domain ) {
Line 4123  sub upfile_drop_add { Line 4259  sub upfile_drop_add {
                                 \%got_rules);                                  \%got_rules);
                             if (ref($alerts{'id'}) eq 'HASH') {                              if (ref($alerts{'id'}) eq 'HASH') {
                                 if (ref($alerts{'id'}{$userdomain}) eq 'HASH') {                                  if (ref($alerts{'id'}{$userdomain}) eq 'HASH') {
                                     next if ($alerts{'id'}{$userdomain}{$id});                                      if ($alerts{'id'}{$userdomain}{$id}) {
                                           $r->print(&mt('[_1]: has a student/employee ID matching the format at your institution, but the ID is found by your directory service.',
                                                     '<b>'.$username.'</b>').'<br />'.
                                                     &mt('Consequently, the user was not created.'));
                                           next;
                                       }
                                 }                                  }
                             }                              }
                         }                          }
Line 4218  sub upfile_drop_add { Line 4359  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
         &Apache::lonnet::flushcourselogs();          $r->register_cleanup(\&Apache::lonnet::flushcourselogs);
         $r->print("</p>\n<p>\n".&mt('Processed [quant,_1,user].',$counts{'user'}).          $r->print("</p>\n<p>\n".&mt('Processed [quant,_1,user].',$counts{'user'}).
                   "</p>\n");                    "</p>\n");
         if ($counts{'role'} > 0) {          if ($counts{'role'} > 0) {
Line 4382  sub print_drop_menu { Line 4523  sub print_drop_menu {
 # ================================================================== Phase four  # ================================================================== Phase four
   
 sub update_user_list {  sub update_user_list {
     my ($r,$context,$setting,$choice) = @_;      my ($r,$context,$setting,$choice,$crstype) = @_;
     my $now = time;      my $now = time;
     my $count=0;      my $count=0;
     my $crstype;  
     if ($context eq 'course') {      if ($context eq 'course') {
         $crstype = &Apache::loncommon::course_type();          $crstype = &Apache::loncommon::course_type();
     }      }
Line 4400  sub update_user_list { Line 4540  sub update_user_list {
                                    'reenable' => 'Re-enabled',                                     'reenable' => 'Re-enabled',
                                    'activate' => 'Activated',                                     'activate' => 'Activated',
                                    'chgdates' => 'Changed Access Dates for',                                     'chgdates' => 'Changed Access Dates for',
                                    'chgsec'   => 'Changed section for',                                     'chgsec'   => 'Changed section(s) for',
                                    'drop'     => 'Dropped',                                     'drop'     => 'Dropped',
                                  },                                   },
                         error => {'revoke'    => 'revoking',                          error => {'revoke'    => 'revoking',
Line 4417  sub update_user_list { Line 4557  sub update_user_list {
         ($startdate,$enddate) = &get_dates_from_form();          ($startdate,$enddate) = &get_dates_from_form();
     }      }
     foreach my $item (@changelist) {      foreach my $item (@changelist) {
         my ($role,$uname,$udom,$cid,$sec,$scope,$result,$type,$locktype,@sections,          my ($role,$uname,$udom,$cid,$sec,$scope,$result,$type,$locktype,
             $scopestem);              @sections,$scopestem,$singlesec,$showsecs,$warn_singlesec,
               $nothingtodo,$keepnosection);
         if ($choice eq 'drop') {          if ($choice eq 'drop') {
             ($uname,$udom,$sec) = split(/:/,$item,-1);              ($uname,$udom,$sec) = split(/:/,$item,-1);
             $role = 'st';              $role = 'st';
Line 4517  sub update_user_list { Line 4658  sub update_user_list {
             } elsif ($choice eq 'chgsec') {              } elsif ($choice eq 'chgsec') {
                 my (@newsecs,$revresult,$nochg,@retained);                  my (@newsecs,$revresult,$nochg,@retained);
                 if (($role ne 'cc') && ($role ne 'co')) {                  if (($role ne 'cc') && ($role ne 'co')) {
                     @newsecs = split(/,/,$env{'form.newsecs'});                      my @secs = sort(split(/,/,$env{'form.newsecs'}));
                       if (@secs) {
                           my %curr_groups = &Apache::longroup::coursegroups();
                           foreach my $sec (@secs) {
                               next if (($sec =~ /\W/) || ($sec eq 'none') ||
                               (exists($curr_groups{$sec})));
                               push(@newsecs,$sec);
                           }
                       }
                 }                  }
                 # remove existing section if not to be retained.                     # remove existing section if not to be retained.   
                 if (!$env{'form.retainsec'}) {                  if (!$env{'form.retainsec'} || ($role eq 'st')) {
                     if ($sec eq '') {                      if ($sec eq '') {
                         if (@newsecs == 0) {                          if (@newsecs == 0) {
                             $result = &mt('No change in section assignment (none)');                              $result = 'ok';
                             $nochg = 1;                              $nochg = 1;
                               $nothingtodo = 1;
                         } else {                          } else {
                             $revresult =                              $revresult =
                                 &Apache::lonnet::revokerole($udom,$uname,                                  &Apache::lonnet::revokerole($udom,$uname,
Line 4551  sub update_user_list { Line 4701  sub update_user_list {
                 } else {                  } else {
                     if ($sec eq '') {                      if ($sec eq '') {
                         $nochg = 1;                          $nochg = 1;
                     } else {                           $keepnosection = 1;
                       } else {
                         push(@retained,$sec);                          push(@retained,$sec);
                     }                      }
                 }                  }
                 # add new sections                  # add new sections
                   my (@diffs,@shownew);
                   if (@retained) {
                       @diffs = &Apache::loncommon::compare_arrays(\@retained,\@newsecs);
                   } else {
                       @diffs = @newsecs;
                   }
                 if (@newsecs == 0) {                  if (@newsecs == 0) {
                     if (!$nochg) {                      if ($nochg) {
                           $result = 'ok';
                           $nothingtodo = 1;
                       } else {
                         if ($role eq 'st') {                          if ($role eq 'st') {
                             $result =                               $result = 
                                 &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,undef,$end,$start,$type,$locktype,$cid,'',$context);                                  &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,undef,$end,$start,$type,$locktype,$cid,'',$context);
Line 4566  sub update_user_list { Line 4726  sub update_user_list {
                             $result = &Apache::lonnet::assignrole($udom,$uname,$newscope,$role,$end,$start,'','',$context);                              $result = &Apache::lonnet::assignrole($udom,$uname,$newscope,$role,$end,$start,'','',$context);
                         }                          }
                     }                      }
                       $showsecs = &mt('No section');
                   } elsif (@diffs == 0) {
                       $result = 'ok';
                       $nothingtodo = 1;
                 } else {                  } else {
                     foreach my $newsec (@newsecs) {                       foreach my $newsec (@newsecs) {
                         if (!grep(/^\Q$newsec\E$/,@retained)) {                          if (!grep(/^\Q$newsec\E$/,@retained)) {
                             if ($role eq 'st') {                              if ($role eq 'st') {
                                 $result = &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$newsec,$end,$start,$type,$locktype,$cid,'',$context);                                  $result = &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$newsec,$end,$start,$type,$locktype,$cid,'',$context);
                                   if (@newsecs > 1) {
                                       my $showsingle; 
                                       if ($newsec eq '') {
                                           $showsingle = &mt('No section');
                                       } else {
                                           $showsingle = $newsec;
                                       }
                                       if ($crstype eq 'Community') {
                                           $warn_singlesec = &mt('Although more than one section was indicated, a role was only added for the first section - [_1], as each community member may only be in one section at a time.','<i>'.$showsingle.'</i>');
                                       } else { 
                                           $warn_singlesec = &mt('Although more than one section was indicated, a role was only added for the first section - [_1], as each student may only be in one section of a course at a time.','<i>'.$showsingle.'</i>');
                                       }
                                       $showsecs = $showsingle; 
                                       last;
                                   } else {
                                       if ($newsec eq '') {
                                           $showsecs = &mt('No section');
                                       } else {
                                           $showsecs = $newsec;
                                       }
                                   }
                             } else {                              } else {
                                 my $newscope = $scopestem;                                  my $newscope = $scopestem;
                                 if ($newsec ne '') {                                  if ($newsec ne '') {
                                    $newscope .= '/'.$newsec;                                     $newscope .= '/'.$newsec;
                                      push(@shownew,$newsec); 
                                 }                                  }
                                 $result = &Apache::lonnet::assignrole($udom,$uname,                                  $result = &Apache::lonnet::assignrole($udom,$uname,
                                                         $newscope,$role,$end,$start);                                                          $newscope,$role,$end,$start);
                                   
                             }                              }
                         }                          }
                     }                      }
                 }                  }
                   unless ($role eq 'st') {
                       unless ($showsecs) {
                           my @tolist = sort(@shownew,@retained);
                           if ($keepnosection) {
                               push(@tolist,&mt('No section'));
                           }
                           $showsecs = join(', ',@tolist);
                       }
                   }
             }              }
         }          }
         my $extent = $scope;          my $extent = $scope;
Line 4592  sub update_user_list { Line 4788  sub update_user_list {
             }              }
         }          }
         if ($result eq 'ok' || $result eq 'ok:') {          if ($result eq 'ok' || $result eq 'ok:') {
             $r->print(&mt("$result_text{'ok'}{$choice} role of '[_1]' in [_2] for [_3]",              my $dates;
                           $plrole,$extent,$uname.':'.$udom).'<br />');              if (($choice eq 'chgsec') || ($choice eq 'chgdates')) {
             $count++;                  $dates = &dates_feedback($start,$end,$now);
               }
               if ($choice eq 'chgsec') {
                   if ($nothingtodo) {
                       $r->print(&mt("Section assignment for role of '[_1]' in [_2] for '[_3]' unchanged.",$plrole,$extent,'<i>'.
                             &Apache::loncommon::plainname($uname,$udom).
                             '</i>').' ');
                       if ($sec eq '') {
                           $r->print(&mt('[_1]No section[_2] - [_3]','<b>','</b>',$dates));
                       } else {
                           $r->print(&mt('Section(s): [_1] - [_2]',
                                         '<b>'.$showsecs.'</b>',$dates));
                       }
                       $r->print('<br />');
                   } else {
                       $r->print(&mt("$result_text{'ok'}{$choice} role of '[_1]' in [_2] for '[_3]' to [_4] - [_5]",$plrole,$extent,
                           '<i>'.&Apache::loncommon::plainname($uname,$udom).'</i>',
                           '<b>'.$showsecs.'</b>',$dates).'<br />');
                      $count ++;
                  }
                  if ($warn_singlesec) {
                      $r->print('<div class="LC_warning">'.$warn_singlesec.'</div>');
                  }
               } elsif ($choice eq 'chgdates') {
                   $r->print(&mt("$result_text{'ok'}{$choice} role of '[_1]' in [_2] for '[_3]' - [_4]",$plrole,$extent, 
                         '<i>'.&Apache::loncommon::plainname($uname,$udom).'</i>',
                         $dates).'<br />');
                  $count ++;
               } else {
                   $r->print(&mt("$result_text{'ok'}{$choice} role of '[_1]' in [_2] for '[_3]'.",$plrole,$extent,
                         '<i>'.&Apache::loncommon::plainname($uname,$udom).'</i>').
                             '<br />');
                   $count ++;
               }
         } else {          } else {
             $r->print(              $r->print(
                 &mt("Error $result_text{'error'}{$choice} [_1] in [_2] for [_3]: [_4].",                  &mt("Error $result_text{'error'}{$choice} [_1] in [_2] for '[_3]': [_4].",
                     $plrole,$extent,$uname.':'.$udom,$result).'<br />');                      $plrole,$extent,
                       '<i>'.&Apache::loncommon::plainname($uname,$udom).'</i>',
                       $result).'<br />');
         }          }
     }      }
     $r->print('<form name="studentform" method="post" action="/adm/createuser">'."\n");      $r->print('<form name="studentform" method="post" action="/adm/createuser">'."\n");
Line 4614  sub update_user_list { Line 4845  sub update_user_list {
             }              }
         }          }
     }      }
     $r->print('<p><b>'.&mt("$result_text{'ok'}{$choice} role(s) for [quant,_1,user,users,no users].",$count).'</b></p>');      $r->print('<p><b>'.&mt("$result_text{'ok'}{$choice} for [quant,_1,user role,user roles,no user roles].",$count).'</b></p>');
     if ($count > 0) {      if ($count > 0) {
         if ($choice eq 'revoke' || $choice eq 'drop') {          if ($choice eq 'revoke' || $choice eq 'drop') {
             $r->print('<p>'.&mt('Re-enabling will re-activate data for the role.').'</p>');              $r->print('<p>'.&mt('Re-enabling will re-activate data for the role.').'</p>');
         }          }
         # Flush the course logs so reverse user roles immediately updated          # Flush the course logs so reverse user roles immediately updated
         &Apache::lonnet::flushcourselogs();          $r->register_cleanup(\&Apache::lonnet::flushcourselogs);
     }      }
     if ($env{'form.makedatesdefault'}) {      if ($env{'form.makedatesdefault'}) {
         if ($choice eq 'chgdates' || $choice eq 'reenable' || $choice eq 'activate') {          if ($choice eq 'chgdates' || $choice eq 'reenable' || $choice eq 'activate') {
Line 4634  sub update_user_list { Line 4865  sub update_user_list {
     $r->print('<a href="javascript:document.studentform.submit()">'.$linktext.'</a></form>'."\n");      $r->print('<a href="javascript:document.studentform.submit()">'.$linktext.'</a></form>'."\n");
 }  }
   
   sub dates_feedback {
       my ($start,$end,$now) = @_;
       my $dates;
       if ($start < $now) {
           if ($end == 0) {
               $dates .= &mt('role(s) active now; no end date');
           } elsif ($end > $now) {
               $dates = &mt('role(s) active now; ends [_1].',&Apache::lonlocal::locallocaltime($end));
           } else {
               $dates = &mt('role(s) expired: [_1].',&Apache::lonlocal::locallocaltime($end));
           }
        } else {
           if ($end == 0 || $end > $now) {
               $dates = &mt('future role(s); starts: [_1].',&Apache::lonlocal::locallocaltime($start));
           } else {
               $dates = &mt('role(s) expired: [_1].',&Apache::lonlocal::locallocaltime($end));
           }
       }
       return $dates;
   }
   
 sub classlist_drop {  sub classlist_drop {
     my ($scope,$uname,$udom,$now) = @_;      my ($scope,$uname,$udom,$now) = @_;
     my ($cdom,$cnum) = ($scope=~m{^/($match_domain)/($match_courseid)});      my ($cdom,$cnum) = ($scope=~m{^/($match_domain)/($match_courseid)});
Line 4814  sub setsections_javascript { Line 5066  sub setsections_javascript {
                     accr => 'A course coordinator role will be added with access to all sections.',                      accr => 'A course coordinator role will be added with access to all sections.',
                     acor => 'A coordinator role will be added with access to all sections',                      acor => 'A coordinator role will be added with access to all sections',
                     inea => 'In each course, each user may only have one student role at a time.',                      inea => 'In each course, each user may only have one student role at a time.',
                     inec => 'In each community, each user may only have on member role at a time.',                      inco => 'In each community, each user may only have one member role at a time.',
                     youh => 'You had selected ',                      youh => 'You had selected ',
                     secs => 'sections.',                      secs => 'sections.',
                     plmo => 'Please modify your selections so they include no more than one section.',                      plmo => 'Please modify your selections so they include no more than one section.',
Line 4822  sub setsections_javascript { Line 5074  sub setsections_javascript {
                     plch => 'Please choose a different section name.',                      plch => 'Please choose a different section name.',
                     mnot => 'may not be used as a section name, as it is the name of a course group.',                      mnot => 'may not be used as a section name, as it is the name of a course group.',
                     secn => 'Section names and group names must be distinct. Please choose a different section name.',                      secn => 'Section names and group names must be distinct. Please choose a different section name.',
                       nonw => 'Section names may only contain letters or numbers.',
                  );                                   );                
     $setsection_js .= <<"ENDSECCODE";      $setsection_js .= <<"ENDSECCODE";
   
 function setSections(formname,crstype) {  function setSections(formname,crstype) {
     var re1 = /^currsec_/;      var re1 = /^currsec_/;
       var re2 =/\\W/;
       var trimleading = /^\\s+/;
       var trimtrailing = /\\s+\$/;
     var groups = new Array($groupslist);      var groups = new Array($groupslist);
     for (var i=0;i<formname.elements.length;i++) {      for (var i=0;i<formname.elements.length;i++) {
         var str = formname.elements[i].name;          var str = formname.elements[i].name;
         var checkcurr = str.match(re1);          var checkcurr = str.match(re1);
         if (checkcurr != null) {          if (checkcurr != null) {
               var num = i;
             if ($checkincluded) {              if ($checkincluded) {
                 $rolecode                  $rolecode
                 if (role == 'cc' || role == 'co') {                  if (role == 'cc' || role == 'co') {
Line 4843  function setSections(formname,crstype) { Line 5100  function setSections(formname,crstype) {
                 } else {                  } else {
                     var sections = '';                      var sections = '';
                     var numsec = 0;                      var numsec = 0;
                     var sections;                      var fromexisting = new Array();
                     for (var j=0; j<formname.elements[i].length; j++) {                      for (var j=0; j<formname.elements[num].length; j++) {
                         if (formname.elements[i].options[j].selected == true ) {                          if (formname.elements[num].options[j].selected == true ) {
                             if (formname.elements[i].options[j].value != "") {                              var addsec = formname.elements[num].options[j].value;
                               if ((addsec != "") && (addsec != null)) {
                                   fromexisting.push(addsec);
                                 if (numsec == 0) {                                  if (numsec == 0) {
                                     if (formname.elements[i].options[j].value != "") {                                      sections = addsec;
                                         sections = formname.elements[i].options[j].value;                                  } else {
                                         numsec ++;                                      sections = sections + "," +  addsec;
                                     }  
                                 }  
                                 else {  
                                     sections = sections + "," +  formname.elements[i].options[j].value  
                                     numsec ++;  
                                 }                                  }
                                   numsec ++;
                             }                              }
                         }                          }
                     }                      }
                     if (numsec > 0) {                      var newsecs = formname.elements[num+1].value;
                         if (formname.elements[i+1].value != "" && formname.elements[i+1].value != null) {                      var validsecs = new Array();
                             sections = sections + "," +  formname.elements[i+1].value;                      var validsecstr = '';
                         }                      var badsecs = new Array();
                     }  
                     else {  
                         sections = formname.elements[i+1].value;  
                     }  
                     var newsecs = formname.elements[i+1].value;  
                     var numsplit;  
                     if (newsecs != null && newsecs != "") {                      if (newsecs != null && newsecs != "") {
                         numsplit = newsecs.split(/,/g);                          var numsplit;
                         numsec = numsec + numsplit.length;                          if (newsecs.indexOf(',') == -1) {
                               numsplit = new Array(newsecs);
                           } else {
                               numsplit = newsecs.split(/,/g);
                           }
                           for (var m=0; m<numsplit.length; m++) {
                               var newsec = numsplit[m];
                               newsec = newsec.replace(trimleading,'');
                               newsec = newsec.replace(trimtrailing,'');
                               if (re2.test(newsec) == true) {
                                   badsecs.push(newsec);
                               } else {
                                   if (newsec != '') {
                                       var isnew = 1;
                                       if (fromexisting != null) {
                                           for (var n=0; n<fromexisting.length; n++) {
                                               if (newsec == fromexisting[n]) {
                                                   isnew = 0;
                                               }
                                           }
                                       }
                                       if (isnew == 1) {
                                           validsecs.push(newsec);
                                       }
                                   }
                               }
                           }
                           if (badsecs.length > 0) {
                               alert("$alerts{'nonw'}\\n$alerts{'plch'}");
                               return;
                           }
                           numsec = numsec + validsecs.length;
                     }                      }
   
                     if ((role == 'st') && (numsec > 1)) {                      if ((role == 'st') && (numsec > 1)) {
                         if (crstype == 'Community') {                          if (crstype == 'Community') {
                             alert("$alerts{'inea'} $alerts{'youh'} "+numsec+" $alerts{'secs'}\\n$alerts{'plmo'}");                              alert("$alerts{'inea'} $alerts{'youh'} "+numsec+" $alerts{'secs'}\\n$alerts{'plmo'}");
Line 4882  function setSections(formname,crstype) { Line 5161  function setSections(formname,crstype) {
                             alert("$alerts{'inco'} $alerts{'youh'} "+numsec+" $alerts{'secs'}\\n$alerts{'plmo'}");                              alert("$alerts{'inco'} $alerts{'youh'} "+numsec+" $alerts{'secs'}\\n$alerts{'plmo'}");
                         }                          }
                         return;                          return;
                     }                      } else {
                     else {                          if (validsecs != null) {
                         if (numsplit != null) {                              for (var j=0; j<validsecs.length; j++) {
                             for (var j=0; j<numsplit.length; j++) {                                  if (validsecstr == '' || validsecstr == null) {
                                 if ((numsplit[j] == 'all') ||                                      validsecstr = validsecs[j];
                                     (numsplit[j] == 'none')) {                                  } else {
                                     alert("'"+numsplit[j]+"' $alerts{'mayn'}\\n$alerts{'plch'}");                                      validsecstr += ','+validsecs[j];
                                   }
                                   if ((validsecs[j] == 'all') ||
                                       (validsecs[j] == 'none')) {
                                       alert("'"+validsecs[j]+"' $alerts{'mayn'}\\n$alerts{'plch'}");
                                     return;                                      return;
                                 }                                  }
                                 for (var k=0; k<groups.length; k++) {                                  for (var k=0; k<groups.length; k++) {
                                     if (numsplit[j] == groups[k]) {                                      if (validsecs[j] == groups[k]) {
                                         alert("'"+numsplit[j]+"' $alerts{'mnot'}\\n$alerts{'secn'}");                                          alert("'"+validsecs[j]+"' $alerts{'mnot'}\\n$alerts{'secn'}");
                                         return;                                          return;
                                     }                                      }
                                 }                                  }
                             }                              }
                         }                          }
                         formname.elements[i+2].value = sections;  
                     }                      }
                       if ((validsecstr != '') && (validsecstr != null)) {
                           if ((sections == '') || (sections == null)) {
                               sections = validsecstr;
                           } else {
                               sections = sections + "," + validsecstr;
                           }
                       }
                       formname.elements[num+2].value = sections;
                 }                  }
             }              }
         }          }
Line 4997  sub can_modify_userinfo { Line 5287  sub can_modify_userinfo {
 }  }
   
 sub check_usertype {  sub check_usertype {
     my ($dom,$uname,$rules) = @_;      my ($dom,$uname,$rules,$curr_rules,$got_rules) = @_;
     my $usertype;      my $usertype;
     if (ref($rules) eq 'HASH') {      if ((ref($got_rules) eq 'HASH') && (ref($curr_rules) eq 'HASH')) {
         my @user_rules = keys(%{$rules});          if (!$got_rules->{$dom}) {
         if (@user_rules > 0) {              my %domconfig = &Apache::lonnet::get_dom('configuration',
             my %rule_check = &Apache::lonnet::inst_rulecheck($dom,$uname,undef,'username',\@user_rules);                                                ['usercreation'],$dom);
             if (keys(%rule_check) > 0) {              if (ref($domconfig{'usercreation'}) eq 'HASH') {
                 $usertype = 'unofficial';                  foreach my $item ('username','id') {
                 foreach my $item (keys(%rule_check)) {                      if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
                     if ($rule_check{$item}) {                          $curr_rules->{$dom}{$item} =
                         $usertype = 'official';                                  $domconfig{'usercreation'}{$item.'_rule'};
                         last;                      }
                   }
               }
               $got_rules->{$dom} = 1;
           }
           if (ref($rules) eq 'HASH') {
               my @user_rules;
               if (ref($curr_rules->{$dom}{'username'}) eq 'ARRAY') {
                   foreach my $rule (keys(%{$rules})) {
                       if (grep(/^\Q$rule\E/,@{$curr_rules->{$dom}{'username'}})) {
                           push(@user_rules,$rule);
                       }
                   } 
               }
               if (@user_rules > 0) {
                   my %rule_check = &Apache::lonnet::inst_rulecheck($dom,$uname,undef,'username',\@user_rules);
                   if (keys(%rule_check) > 0) {
                       $usertype = 'unofficial';
                       foreach my $item (keys(%rule_check)) {
                           if ($rule_check{$item}) {
                               $usertype = 'official';
                               last;
                           }
                     }                      }
                 }                  }
             }              }
Line 5025  sub roles_by_context { Line 5337  sub roles_by_context {
         if ($env{'request.role'} =~ m{^dc\./}) {          if ($env{'request.role'} =~ m{^dc\./}) {
             push(@allroles,'ad');              push(@allroles,'ad');
         }          }
         if (&Apache::loncommon::needs_gci_custom()) {          push(@allroles,('ta','ep','in'));
             if ($crstype eq 'Community') {          if ($crstype eq 'Community') {
                 push(@allroles,'co');              push(@allroles,'co');
             } else {  
                 push(@allroles,'cc');  
             }  
         } else {          } else {
             push(@allroles,('ta','ep','in'));              push(@allroles,'cc');
             if ($crstype eq 'Community') {          }
                 push(@allroles,'co');          if ($custom) {
             } else {              push(@allroles,'cr');
                 push(@allroles,'cc');  
             }  
             if ($custom) {  
                 push(@allroles,'cr');  
             }  
         }          }
     } elsif ($context eq 'author') {      } elsif ($context eq 'author') {
         @allroles = ('ca','aa');          @allroles = ('ca','aa');

Removed from v.1.109.2.2  
changed lines
  Added in v.1.136.6.1


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