Diff for /loncom/interface/lonuserutils.pm between versions 1.97.2.25 and 1.120

version 1.97.2.25, 2010/11/15 18:50:37 version 1.120, 2010/07/09 14:40:20
Line 47  sub modifystudent { Line 47  sub modifystudent {
     # this one.  If $csec is defined, drop them from all other sections of      # this one.  If $csec is defined, drop them from all other sections of
     # this course and add them to section $csec      # this course and add them to section $csec
     my ($cnum,$cdom) = &get_course_identity($courseid);      my ($cnum,$cdom) = &get_course_identity($courseid);
     my $extra = &Apache::lonnet::freeze_escape({'skipcheck' => 1});      my %roles = &Apache::lonnet::dump('roles',$udom,$unam);
     my %roles = &Apache::lonnet::dump('roles',$udom,$unam,'.',undef,$extra);  
     my ($tmp) = keys(%roles);      my ($tmp) = keys(%roles);
     # Bail out if we were unable to get the students roles      # Bail out if we were unable to get the students roles
     return "$1" if ($tmp =~ /^(con_lost|error|no_such_host)/i);      return "$1" if ($tmp =~ /^(con_lost|error|no_such_host)/i);
Line 296  sub hidden_input { Line 295  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 311  sub print_upload_manager_header { Line 309  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($can_assign);          $javascript=&upload_manager_javascript_reverse_associate();
     } else {      } else {
         $javascript=&upload_manager_javascript_forward_associate($can_assign);          $javascript=&upload_manager_javascript_forward_associate();
     }      }
     #      #
     # Deal with restored settings      # Deal with restored settings
Line 534  END Line 532  END
         if (message!='') {          if (message!='') {
             message+='\\n';              message+='\\n';
         }          }
         message+='$alert{'section'}';  
     }      }
     if (foundemail==0) {      if (foundemail==0) {
         if (message!='') {          if (message!='') {
Line 588  END Line 585  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 704  function flip(vf,tf) { Line 661  function flip(vf,tf) {
          }           }
       }        }
    }     }
    $auth_update     // 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);
          vf.intarg.value='';
          vf.krbarg.value='';
          vf.locarg.value='';
      }
 }  }
   
 function clearpwd(vf) {  function clearpwd(vf) {
Line 722  ENDPICK Line 687  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 768  function verify(vf,sec_caller) { Line 694  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 780  function verify(vf,sec_caller) { Line 705  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) { foundemail=1; }          if (i==9 && tw!=0) { foundrole=1; }
         if (i==10 && tw!=0) { foundrole=1; }          if (i==10 && tw!=0) { founddomain=1; }
         if (i==11 && tw!=0) { founddomain=1; }          if (i==13 && tw!=0) { foundinstatus=1; }
         if (i==12 && tw!=0) { foundinstatus=1; }  
     }      }
     verify_message(vf,founduname,foundpwd,foundname,foundid,foundsec,foundemail,foundrole,founddomain,foundinststatus);      verify_message(vf,founduname,foundpwd,foundname,foundid,foundsec,foundrole,founddomain,foundinststatus);
 }  }
   
 function flip(vf,tf) {  function flip(vf,tf) {
Line 802  function flip(vf,tf) { Line 726  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;')
    }     }
    $auth_update     // intial password specified, pick internal authentication
      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 1047  sub print_upload_manager_form { Line 978  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,\%can_assign);                                   $permission,$crstype);
     my $i;      my $i;
     my $keyfields;      my $keyfields;
     if ($total>=0) {      if ($total>=0) {
Line 1517  sub print_userlist { Line 1447  sub print_userlist {
         return;          return;
     }      }
     if (!(($context eq 'domain') &&       if (!(($context eq 'domain') && 
         (($env{'form.roletype'} eq 'course') || ($env{'form.roletype'} eq 'community')))) {            (($env{'form.roletype'} eq 'course') || ($env{'form.roletype'} eq 'community')))) {
         $r->print(          $r->print(
             "\n</p>\n"              "\n</p>\n"
            .'<p>'             .'<p>'
Line 1528  sub print_userlist { Line 1458  sub print_userlist {
     my ($indexhash,$keylist) = &make_keylist_array();      my ($indexhash,$keylist) = &make_keylist_array();
     my (%userlist,%userinfo,$clearcoursepick);      my (%userlist,%userinfo,$clearcoursepick);
     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')) {
         my ($crstype,$numcodes,$title,$warning);          my ($crstype,$numcodes,$title,$warning);
         if ($env{'form.roletype'} eq 'course') {          if ($env{'form.roletype'} eq 'course') {
Line 1542  sub print_userlist { Line 1472  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 1762  sub role_filter { Line 1694  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 1993  function setCourseCat(formname) { Line 1925  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 2002  function setCourseCat(formname) { Line 1934  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 2010  function setCourseCat(formname) { Line 1942  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 2347  END Line 2279  END
             push(@cols,'section');              push(@cols,'section');
         }          }
         if (!($context eq 'domain' && ($env{'form.roletype'} eq 'course')          if (!($context eq 'domain' && ($env{'form.roletype'} eq 'course')
                               && ($env{'form.roletype'} eq 'community'))) {                                && ($env{'form.roletype'} eq 'community'))) { 
             push(@cols,('start','end'));              push(@cols,('start','end'));
         }          }
         if ($env{'form.showrole'} eq 'Any' || $env{'form.showrole'} eq 'cr') {          if ($env{'form.showrole'} eq 'Any' || $env{'form.showrole'} eq 'cr') {
Line 2358  END Line 2290  END
                                     $env{'form.roletype'} eq 'community')) {                                      $env{'form.roletype'} eq 'community')) {
             push (@cols,'extent');              push (@cols,'extent');
         }          }
         if (($statusmode eq 'Any') &&          if (($statusmode eq 'Any') && 
             (!($context eq 'domain' && (($env{'form.roletype'} eq 'course')              (!($context eq 'domain' && (($env{'form.roletype'} eq 'course')
              || ($env{'form.roletype'} eq 'community'))))) {               || ($env{'form.roletype'} eq 'community'))))) {
             push(@cols,'status');              push(@cols,'status');
Line 2379  END Line 2311  END
     if ($mode ne 'autoenroll') {      if ($mode ne 'autoenroll') {
         $results_description = &results_header_row($rolefilter,$statusmode,          $results_description = &results_header_row($rolefilter,$statusmode,
                                                    $context,$permission,$mode,$crstype);                                                     $context,$permission,$mode,$crstype);
   
         $r->print('<b>'.$results_description.'</b><br /><br />');          $r->print('<b>'.$results_description.'</b><br /><br />');
     }      }
     my ($output,$actionselect,%canchange,%canchangesec);      my ($output,$actionselect,%canchange,%canchangesec);
Line 2401  END Line 2332  END
 END  END
             if ($actionselect) {              if ($actionselect) {
                 $output .= <<"END";                  $output .= <<"END";
 <div class="LC_left_float"><fieldset><legend><b>$lt{'ac'}</b></legend>  <div class="LC_left_float"><fieldset><legend>$lt{'ac'}</legend>
 $actionselect  $actionselect
 <br/><br /><input type="button" value="$lt{'ca'}" onclick="javascript:checkAll(document.$formname.actionlist)" /> &nbsp;  <br/><br /><input type="button" value="$lt{'ca'}" onclick="javascript:checkAll(document.$formname.actionlist)" /> &nbsp;
 <input type="button" value="$lt{'ua'}" onclick="javascript:uncheckAll(document.$formname.actionlist)" /><br /><input type="button" value="$lt{'pr'}" onclick="javascript:verify_action('actionlist')" /></fieldset></div>  <input type="button" value="$lt{'ua'}" onclick="javascript:uncheckAll(document.$formname.actionlist)" /><br /><input type="button" value="$lt{'pr'}" onclick="javascript:verify_action('actionlist')" /></fieldset></div>
Line 2446  END Line 2377  END
                     }                      }
                 }                  }
             }              }
             $output .= '<div class="LC_left_float"><fieldset><legend><b>'.$lt{'link'}.'</b></legend>'.              $output .= '<div class="LC_left_float"><fieldset><legend>'.$lt{'link'}.'</legend>'.
                        '<table><tr>';                         '<table><tr>';
             my @linkdests = ('aboutme');              my @linkdests = ('aboutme');
             if ($permission->{'cusr'}) {              if ($permission->{'cusr'}) {
Line 2457  END Line 2388  END
                                          $env{'request.course.sec'})) {                                           $env{'request.course.sec'})) {
                 push(@linkdests,'track');                  push(@linkdests,'track');
             }              }
   
             $output .= '<td>';              $output .= '<td>';
             my $usernamelink = $env{'form.usernamelink'};              my $usernamelink = $env{'form.usernamelink'};
             if ($usernamelink eq '') {              if ($usernamelink eq '') {
Line 2473  END Line 2405  END
             if ($env{'form.userwin'}) {              if ($env{'form.userwin'}) {
                 $checkwin = ' checked="checked"';                  $checkwin = ' checked="checked"';
             }              }
             $output .= '</td><td valign="top" style="border-left: 1px solid;><span class="LC_nobreak"><input type="checkbox" name="userwin" value="1"'.$checkwin.' />'.$lt{'owin'}.'</span></td></tr></table></fieldset></div>';              $output .= '</td><td valign="top"  style="border-left: 1px solid;"><span class="LC_nobreak"><input type="checkbox" name="userwin" value="1"'.$checkwin.' />'.$lt{'owin'}.'</span></td></tr></table></fieldset></div>';
         }          }
         $output .= "\n".'<div class="LC_clear_float_footer">&nbsp;</div>'."\n".          $output .= "\n".'<div class="LC_clear_float_footer">&nbsp;</div>'."\n".
                   &Apache::loncommon::start_data_table().                    &Apache::loncommon::start_data_table().
Line 2726  END Line 2658  END
         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);
         if (! defined($in{'start'}) || $in{'start'} == 0) {          if (! defined($in{'start'}) || $in{'start'} == 0) {
             $in{'start'} = &mt('none');              $in{'start'} = &mt('none');
         } else {          } else {
Line 3245  ENDJS Line 3177  ENDJS
                  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 course role that is not "student", users may have roles in more than one section 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 3478  sub results_header_row { Line 3410  sub results_header_row {
             }              }
         } elsif (($env{'form.roletype'} eq 'course') ||           } elsif (($env{'form.roletype'} eq 'course') || 
                  ($env{'form.roletype'} eq 'community')) {                   ($env{'form.roletype'} eq 'community')) {
   
             my $coursefilter = $env{'form.coursepick'};              my $coursefilter = $env{'form.coursepick'};
             if ($env{'form.roletype'} eq 'course') {              if ($env{'form.roletype'} eq 'course') {
                 if ($coursefilter eq 'category') {                  if ($coursefilter eq 'category') {
Line 3742  sub print_first_users_upload_form { Line 3673  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 3877  sub upfile_drop_add { Line 3815  sub upfile_drop_add {
         } elsif ($setting eq 'course') {          } elsif ($setting eq 'course') {
             $defaultrole = $env{'form.courserole'};              $defaultrole = $env{'form.courserole'};
             $defaultsec = $env{'form.sections'};              $defaultsec = $env{'form.sections'};
         }          }  
     } elsif ($context eq 'author') {      } elsif ($context eq 'author') {
         $defaultrole = $env{'form.defaultrole'};          $defaultrole = $env{'form.defaultrole'};
     } elsif ($context eq 'course') {      } elsif ($context eq 'course') {
Line 3984  sub upfile_drop_add { Line 3922  sub upfile_drop_add {
                 $r->print($groupwarn.'<br />');                  $r->print($groupwarn.'<br />');
             }              }
         }          }
         my (%curr_rules,%got_rules,%alerts,%cancreate);          my (%curr_rules,%got_rules,%alerts);
         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',  
                         );  
         map { $cancreate{$_} = &can_create_user($domain,$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 4021  sub upfile_drop_add { Line 3953  sub upfile_drop_add {
                 }                  }
                 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 4090  sub upfile_drop_add { Line 4016  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 4137  sub upfile_drop_add { Line 4062  sub upfile_drop_add {
                         $role = $defaultrole;                          $role = $defaultrole;
                     }                      }
                     # Clean up whitespace                      # Clean up whitespace
                     foreach (\$id,\$fname,\$mname,\$lname,\$gen,\$inststatus) {                      foreach (\$id,\$fname,\$mname,\$lname,\$gen) {
                         $$_ =~ s/(\s+$|^\s+)//g;                          $$_ =~ s/(\s+$|^\s+)//g;
                     }                      }
                     # check against rules                      # check against rules
Line 4146  sub upfile_drop_add { Line 4071  sub upfile_drop_add {
                     my (%rulematch,%inst_results,%idinst_results);                      my (%rulematch,%inst_results,%idinst_results);
                     my $uhome=&Apache::lonnet::homeserver($username,$userdomain);                      my $uhome=&Apache::lonnet::homeserver($username,$userdomain);
                     if ($uhome eq 'no_host') {                      if ($uhome eq 'no_host') {
                         if ($userdomain ne $domain) {                          next if ($userdomain ne $domain);
                             $r->print('<br />'.  
                                 &mt('[_1]: The domain specified ([_2]) is different to that of the course.',  
                                     '<b>'.$username.'</b>',$userdomain).'<br />'.  
                                 &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.':'.$domain;  
                         my $checkhash;                          my $checkhash;
                         my $checks = { 'username' => 1 };                          my $checks = { 'username' => 1 };
                         $checkhash->{$username.':'.$domain} = { 'newuser' => 1, };                          $checkhash->{$username.':'.$domain} = { 'newuser' => 1, };
Line 4164  sub upfile_drop_add { Line 4082  sub upfile_drop_add {
                             \%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'}{$domain}) eq 'HASH') {
                                 if ($alerts{'username'}{$domain}{$username}) {                                  next if ($alerts{'username'}{$domain}{$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 4234  sub upfile_drop_add { Line 4135  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') {
                                     if ($alerts{'id'}{$userdomain}{$id}) {                                      next 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 4271  sub upfile_drop_add { Line 4167  sub upfile_drop_add {
                                         $role = 'cr_'.$env{'user.domain'}.'_'.                                          $role = 'cr_'.$env{'user.domain'}.'_'.
                                                 $env{'user.name'}.'_'.$role;                                                  $env{'user.name'}.'_'.$role;
                                     }                                      }
                                     if (($role ne 'cc') && ($role ne 'co')) {                                      if (($role ne 'cc') && ($role ne 'co')) { 
                                         if (@secs > 1) {                                          if (@secs > 1) {
                                             $multiple = 1;                                              $multiple = 1;
                                             foreach my $sec (@secs) {                                              foreach my $sec (@secs) {
Line 4334  sub upfile_drop_add { Line 4230  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
         $r->register_cleanup(\&Apache::lonnet::flushcourselogs);          &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 4677  sub update_user_list { Line 4573  sub update_user_list {
                     if ($sec eq '') {                      if ($sec eq '') {
                         $nochg = 1;                          $nochg = 1;
                         $keepnosection = 1;                          $keepnosection = 1;
                     } else {                       } else {
                         push(@retained,$sec);                          push(@retained,$sec);
                     }                      }
                 }                  }
Line 4706  sub update_user_list { Line 4602  sub update_user_list {
                     $result = 'ok';                      $result = 'ok';
                     $nothingtodo = 1;                      $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) {                                  if (@newsecs > 1) {
                                     my $showsingle;                                      my $showsingle; 
                                     if ($newsec eq '') {                                      if ($newsec eq '') {
                                         $showsingle = &mt('No section');                                          $showsingle = &mt('No section');
                                     } else {                                      } else {
Line 4719  sub update_user_list { Line 4615  sub update_user_list {
                                     }                                      }
                                     if ($crstype eq 'Community') {                                      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>');                                          $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 {                                      } 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>');                                          $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;                                      $showsecs = $showsingle; 
                                     last;                                      last;
                                 } else {                                  } else {
                                     if ($newsec eq '') {                                      if ($newsec eq '') {
Line 4735  sub update_user_list { Line 4631  sub update_user_list {
                                 my $newscope = $scopestem;                                  my $newscope = $scopestem;
                                 if ($newsec ne '') {                                  if ($newsec ne '') {
                                    $newscope .= '/'.$newsec;                                     $newscope .= '/'.$newsec;
                                    push(@shownew,$newsec);                                     push(@shownew,$newsec); 
                                 }                                  }
                                 $result = &Apache::lonnet::assignrole($udom,$uname,                                  $result = &Apache::lonnet::assignrole($udom,$uname,
                                                         $newscope,$role,$end,$start);                                                          $newscope,$role,$end,$start);
                                   
                             }                              }
                         }                          }
                     }                      }
Line 4788  sub update_user_list { Line 4685  sub update_user_list {
                    $r->print('<div class="LC_warning">'.$warn_singlesec.'</div>');                     $r->print('<div class="LC_warning">'.$warn_singlesec.'</div>');
                }                 }
             } elsif ($choice eq 'chgdates') {              } elsif ($choice eq 'chgdates') {
                 $r->print(&mt("$result_text{'ok'}{$choice} role of '[_1]' in [_2] for '[_3]' - [_4]",$plrole,$extent,                  $r->print(&mt("$result_text{'ok'}{$choice} role of '[_1]' in [_2] for '[_3]' - [_4]",$plrole,$extent, 
                       '<i>'.&Apache::loncommon::plainname($uname,$udom).'</i>',                        '<i>'.&Apache::loncommon::plainname($uname.':'.$udom).'</i>',
                       $dates).'<br />');                        $dates).'<br />');
                $count ++;                 $count ++;
             } else {              } else {
                 $r->print(&mt("$result_text{'ok'}{$choice} role of '[_1]' in [_2] for '[_3]'.",$plrole,$extent,                  $r->print(&mt("$result_text{'ok'}{$choice} role of '[_1]' in [_2] for '[_3]'.",$plrole,$extent,
                       '<i>'.&Apache::loncommon::plainname($uname,$udom).'</i>').                        '<i>'.&Apache::loncommon::plainname($uname.':'.$udom).'</i>').
                           '<br />');                            '<br />');
                 $count ++;                  $count ++;
             }              }
Line 4802  sub update_user_list { Line 4699  sub update_user_list {
             $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,                      $plrole,$extent,
                     '<i>'.&Apache::loncommon::plainname($uname,$udom).'</i>',                      '<i>'.&Apache::loncommon::plainname($uname.':'.$udom).'</i>',
                     $result).'<br />');                      $result).'<br />');
         }          }
     }      }
Line 4825  sub update_user_list { Line 4722  sub update_user_list {
             $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
         $r->register_cleanup(\&Apache::lonnet::flushcourselogs);          &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 5040  sub setsections_javascript { Line 4937  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.',
                     inco => 'In each community, each user may only have one member role at a time.',                      inec => '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 5620  sub sectioncheck_alerts { Line 5517  sub sectioncheck_alerts {
     my %alerts = &Apache::lonlocal::texthash(      my %alerts = &Apache::lonlocal::texthash(
                     curd => 'You must select a course or community in the current domain',                      curd => 'You must select a course or community in the current domain',
                     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',
                     inco => 'In each community, each user may only have one 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',
                     sect => 'sections',                      sect => 'sections',
                     plsm => 'Please modify your selections so they include no more than one section',                      plsm => 'Please modify your selections so they include no more than one section',

Removed from v.1.97.2.25  
changed lines
  Added in v.1.120


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