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

version 1.97.2.25, 2010/11/15 18:50:37 version 1.117, 2010/03/21 14:15:58
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 1762  sub role_filter { Line 1692  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 2347  END Line 2277  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 2288  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 2309  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 2330  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 2375  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 2386  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 2403  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 2656  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 3243  ENDJS Line 3173  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 course role that is not "student", users may have roles in more than one section 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.',
                  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).',
             );              );
Line 3263  ENDJS Line 3193  ENDJS
                                           $permission,$crstype);                                            $permission,$crstype);
     }      }
     $output .= '<h3>'.$headertext.'</h3>'.      $output .= '<h3>'.$headertext.'</h3>'.
                '<form name="'.$formname.'" method="post" action="">'."\n".                 '<form name="'.$formname.'" method="post">'."\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();
         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 community role that is not "member", users may have roles in more than one section 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{'dnap'} = &mt('(Does not apply to member roles).');               $lt{'dnap'} = &mt('(Does not apply to member roles).'); 
         }          }
         my $info;          my $info;
Line 3310  sub section_picker { Line 3240  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 = '<div>'.&Apache::lonhtmlcommon::start_pick_box()."\n";      my $secbox = '<p>'.&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 3323  sub section_picker { Line 3253  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" value="" />'."\n".                     '<input type="text" name="newsec" size="15" />'."\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 3332  sub section_picker { Line 3262  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().'</div>';                 &Apache::lonhtmlcommon::end_pick_box().'</p>';
     return $secbox;      return $secbox;
 }  }
   
Line 3478  sub results_header_row { Line 3408  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 3671  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 3813  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 3920  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 3951  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 4014  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 4060  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 4069  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 4080  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 4133  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 4165  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 4228  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 4498  sub print_drop_menu { Line 4392  sub print_drop_menu {
 # ================================================================== Phase four  # ================================================================== Phase four
   
 sub update_user_list {  sub update_user_list {
     my ($r,$context,$setting,$choice,$crstype) = @_;      my ($r,$context,$setting,$choice) = @_;
     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 4515  sub update_user_list { Line 4410  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(s) for',                                     'chgsec'   => 'Changed section for',
                                    'drop'     => 'Dropped',                                     'drop'     => 'Dropped',
                                  },                                   },
                         error => {'revoke'    => 'revoking',                          error => {'revoke'    => 'revoking',
Line 4532  sub update_user_list { Line 4427  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,          my ($role,$uname,$udom,$cid,$sec,$scope,$result,$type,$locktype,@sections,
             @sections,$scopestem,$singlesec,$showsecs,$warn_singlesec,              $scopestem);
             $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 4644  sub update_user_list { Line 4538  sub update_user_list {
                     }                      }
                 }                  }
                 # remove existing section if not to be retained.                     # remove existing section if not to be retained.   
                 if (!$env{'form.retainsec'} || ($role eq 'st')) {                  if (!$env{'form.retainsec'}) {
                     if ($sec eq '') {                      if ($sec eq '') {
                         if (@newsecs == 0) {                          if (@newsecs == 0) {
                             $result = 'ok';                              $result = &mt('No change in section assignment (none)');
                             $nochg = 1;                              $nochg = 1;
                             $nothingtodo = 1;  
                         } else {                          } else {
                             $revresult =                              $revresult =
                                 &Apache::lonnet::revokerole($udom,$uname,                                  &Apache::lonnet::revokerole($udom,$uname,
Line 4676  sub update_user_list { Line 4569  sub update_user_list {
                 } else {                  } else {
                     if ($sec eq '') {                      if ($sec eq '') {
                         $nochg = 1;                          $nochg = 1;
                         $keepnosection = 1;  
                     } else {                       } 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 4701  sub update_user_list { Line 4584  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);
Line 4743  sub update_user_list { Line 4600  sub update_user_list {
                         }                          }
                     }                      }
                 }                  }
                 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 4762  sub update_user_list { Line 4610  sub update_user_list {
             }              }
         }          }
         if ($result eq 'ok' || $result eq 'ok:') {          if ($result eq 'ok' || $result eq 'ok:') {
             my $dates;              $r->print(&mt("$result_text{'ok'}{$choice} role of '[_1]' in [_2] for [_3]",
             if (($choice eq 'chgsec') || ($choice eq 'chgdates')) {                            $plrole,$extent,$uname.':'.$udom).'<br />');
                 $dates = &dates_feedback($start,$end,$now);              $count++;
             }  
             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,                      $plrole,$extent,$uname.':'.$udom,$result).'<br />');
                     '<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 4819  sub update_user_list { Line 4632  sub update_user_list {
             }              }
         }          }
     }      }
     $r->print('<p><b>'.&mt("$result_text{'ok'}{$choice} for [quant,_1,user role,user roles,no user roles].",$count).'</b></p>');      $r->print('<p><b>'.&mt("$result_text{'ok'}{$choice} role(s) for [quant,_1,user,users,no users].",$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
         $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 4839  sub update_user_list { Line 4652  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 5040  sub setsections_javascript { Line 4832  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 on 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 5078  function setSections(formname,crstype) { Line 4870  function setSections(formname,crstype) {
                     for (var j=0; j<formname.elements[num].length; j++) {                      for (var j=0; j<formname.elements[num].length; j++) {
                         if (formname.elements[num].options[j].selected == true ) {                          if (formname.elements[num].options[j].selected == true ) {
                             var addsec = formname.elements[num].options[j].value;                              var addsec = formname.elements[num].options[j].value;
                             if ((addsec != "") && (addsec != null)) {                              if (addsec != "") {
                                 fromexisting.push(addsec);                                  fromexisting.push(addsec);
                                 if (numsec == 0) {                                  if (numsec == 0) {
                                     sections = addsec;                                      sections = addsec;
Line 5620  sub sectioncheck_alerts { Line 5412  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.117


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