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

version 1.117, 2010/03/21 14:15:58 version 1.118, 2010/03/21 14:58:40
Line 3173  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 role in a course that is not a student role, a user may have roles in more than one section of a course at a time.',                   forn => 'For a course role that is not "student", users may have roles in more than one section at a time.',
                  reta => "Retain each user's current section affiliations?",                    reta => "Retain each user's current section affiliations?",
                  dnap => '(Does not apply to student roles).',                   dnap => '(Does not apply to student roles).',
             );              );
     my ($date_items,$headertext);      my ($date_items,$headertext);
Line 3193  ENDJS Line 3193  ENDJS
                                           $permission,$crstype);                                            $permission,$crstype);
     }      }
     $output .= '<h3>'.$headertext.'</h3>'.      $output .= '<h3>'.$headertext.'</h3>'.
                '<form name="'.$formname.'" method="post">'."\n".                 '<form name="'.$formname.'" method="post" action="">'."\n".
                 $date_items;                  $date_items;
     if ($context eq 'course' && $env{'form.bulkaction'} eq 'chgsec') {      if ($context eq 'course' && $env{'form.bulkaction'} eq 'chgsec') {
         my ($cnum,$cdom) = &get_course_identity();          my ($cnum,$cdom) = &get_course_identity();
         if ($crstype eq 'Community') {          if ($crstype eq 'Community') {
             $lt{'fors'} = &mt('For member roles changing the section, will result in a section switch as members may only be in one section of a community at a time.');              $lt{'fors'} = &mt('For member roles, changing the section will result in a section switch, as members may only be in one section of a community at a time.');
             $lt{'forn'} = &mt('For a role in a community that is not a member role, a user may have roles in more than one section of a community at a time.');              $lt{'forn'} = &mt('For a community role that is not "member", users may have roles in more than one section at a time.');
             $lt{'dnap'} = &mt('(Does not apply to member roles).');               $lt{'dnap'} = &mt('(Does not apply to member roles).'); 
         }          }
         my $info;          my $info;
Line 3240  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 = '<p>'.&Apache::lonhtmlcommon::start_pick_box()."\n";      my $secbox = '<div>'.&Apache::lonhtmlcommon::start_pick_box()."\n";
     if ($mode eq 'upload') {      if ($mode eq 'upload') {
         my ($options,$cb_script,$coursepick) =          my ($options,$cb_script,$coursepick) =
             &default_role_selector($context,1,$crstype);              &default_role_selector($context,1,$crstype);
Line 3253  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" />'."\n".                     '<input type="text" name="newsec" size="15" value="" />'."\n".
                    '<input type="hidden" name="sections" value="" />'."\n".                     '<input type="hidden" name="sections" value="" />'."\n".
                    '</td></tr></table>'."\n";                     '</td></tr></table>'."\n";
     } else {      } else {
Line 3262  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().'</p>';                 &Apache::lonhtmlcommon::end_pick_box().'</div>';
     return $secbox;      return $secbox;
 }  }
   
Line 4392  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) = @_;      my ($r,$context,$setting,$choice,$crstype) = @_;
     my $now = time;      my $now = time;
     my $count=0;      my $count=0;
     my $crstype;      my $crstype;
Line 4410  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 for',                                     'chgsec'   => 'Changed section(s) for',
                                    'drop'     => 'Dropped',                                     'drop'     => 'Dropped',
                                  },                                   },
                         error => {'revoke'    => 'revoking',                          error => {'revoke'    => 'revoking',
Line 4427  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,@sections,          my ($role,$uname,$udom,$cid,$sec,$scope,$result,$type,$locktype,
             $scopestem);              @sections,$scopestem,$singlesec,$showsecs,$warn_singlesec,
               $nothingtodo,$keepnosection);
         if ($choice eq 'drop') {          if ($choice eq 'drop') {
             ($uname,$udom,$sec) = split(/:/,$item,-1);              ($uname,$udom,$sec) = split(/:/,$item,-1);
             $role = 'st';              $role = 'st';
Line 4538  sub update_user_list { Line 4539  sub update_user_list {
                     }                      }
                 }                  }
                 # remove existing section if not to be retained.                     # remove existing section if not to be retained.   
                 if (!$env{'form.retainsec'}) {                  if (!$env{'form.retainsec'} || ($role eq 'st')) {
                     if ($sec eq '') {                      if ($sec eq '') {
                         if (@newsecs == 0) {                          if (@newsecs == 0) {
                             $result = &mt('No change in section assignment (none)');                              $result = 'ok';
                             $nochg = 1;                              $nochg = 1;
                               $nothingtodo = 1;
                         } else {                          } else {
                             $revresult =                              $revresult =
                                 &Apache::lonnet::revokerole($udom,$uname,                                  &Apache::lonnet::revokerole($udom,$uname,
Line 4569  sub update_user_list { Line 4571  sub update_user_list {
                 } else {                  } else {
                     if ($sec eq '') {                      if ($sec eq '') {
                         $nochg = 1;                          $nochg = 1;
                     } else {                           $keepnosection = 1;
                       } else {
                         push(@retained,$sec);                          push(@retained,$sec);
                     }                      }
                 }                  }
                 # add new sections                  # add new sections
                   my (@diffs,@shownew);
                   if (@retained) {
                       @diffs = &Apache::loncommon::compare_arrays(\@retained,\@newsecs);
                   } else {
                       @diffs = @newsecs;
                   }
                 if (@newsecs == 0) {                  if (@newsecs == 0) {
                     if (!$nochg) {                      if ($nochg) {
                           $result = 'ok';
                           $nothingtodo = 1;
                       } else {
                         if ($role eq 'st') {                          if ($role eq 'st') {
                             $result =                               $result = 
                                 &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,undef,$end,$start,$type,$locktype,$cid,'',$context);                                  &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,undef,$end,$start,$type,$locktype,$cid,'',$context);
Line 4584  sub update_user_list { Line 4596  sub update_user_list {
                             $result = &Apache::lonnet::assignrole($udom,$uname,$newscope,$role,$end,$start,'','',$context);                              $result = &Apache::lonnet::assignrole($udom,$uname,$newscope,$role,$end,$start,'','',$context);
                         }                          }
                     }                      }
                       $showsecs = &mt('No section');
                   } elsif (@diffs == 0) {
                       $result = 'ok';
                       $nothingtodo = 1;
                 } else {                  } else {
                     foreach my $newsec (@newsecs) {                       foreach my $newsec (@newsecs) {
                         if (!grep(/^\Q$newsec\E$/,@retained)) {                          if (!grep(/^\Q$newsec\E$/,@retained)) {
                             if ($role eq 'st') {                              if ($role eq 'st') {
                                 $result = &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$newsec,$end,$start,$type,$locktype,$cid,'',$context);                                  $result = &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$newsec,$end,$start,$type,$locktype,$cid,'',$context);
                                   if (@newsecs > 1) {
                                       my $showsingle; 
                                       if ($newsec eq '') {
                                           $showsingle = &mt('No section');
                                       } else {
                                           $showsingle = $newsec;
                                       }
                                       if ($crstype eq 'Community') {
                                           $warn_singlesec = &mt('Although more than one section was indicated, a role was only added for the first section - [_1], as each community member may only be in one section at a time.','<i>'.$showsingle.'</i>');
                                       } else { 
                                           $warn_singlesec = &mt('Although more than one section was indicated, a role was only added for the first section - [_1], as each student may only be in one section of a course at a time.','<i>'.$showsingle.'</i>');
                                       }
                                       $showsecs = $showsingle; 
                                       last;
                                   } else {
                                       if ($newsec eq '') {
                                           $showsecs = &mt('No section');
                                       } else {
                                           $showsecs = $newsec;
                                       }
                                   }
                             } else {                              } else {
                                 my $newscope = $scopestem;                                  my $newscope = $scopestem;
                                 if ($newsec ne '') {                                  if ($newsec ne '') {
                                    $newscope .= '/'.$newsec;                                     $newscope .= '/'.$newsec;
                                      push(@shownew,$newsec); 
                                 }                                  }
                                 $result = &Apache::lonnet::assignrole($udom,$uname,                                  $result = &Apache::lonnet::assignrole($udom,$uname,
                                                         $newscope,$role,$end,$start);                                                          $newscope,$role,$end,$start);
                                   
                             }                              }
                         }                          }
                     }                      }
                 }                  }
                   unless ($role eq 'st') {
                       unless ($showsecs) {
                           my @tolist = sort(@shownew,@retained);
                           if ($keepnosection) {
                               push(@tolist,&mt('No section'));
                           }
                           $showsecs = join(', ',@tolist);
                       }
                   }
             }              }
         }          }
         my $extent = $scope;          my $extent = $scope;
Line 4610  sub update_user_list { Line 4658  sub update_user_list {
             }              }
         }          }
         if ($result eq 'ok' || $result eq 'ok:') {          if ($result eq 'ok' || $result eq 'ok:') {
             $r->print(&mt("$result_text{'ok'}{$choice} role of '[_1]' in [_2] for [_3]",              my $dates;
                           $plrole,$extent,$uname.':'.$udom).'<br />');              if (($choice eq 'chgsec') || ($choice eq 'chgdates')) {
             $count++;                  $dates = &dates_feedback($start,$end,$now);
               }
               if ($choice eq 'chgsec') {
                   if ($nothingtodo) {
                       $r->print(&mt("Section assignment for role of '[_1]' in [_2] for '[_3]' unchanged.",$plrole,$extent,'<i>'.
                             &Apache::loncommon::plainname($uname,$udom).
                             '</i>').' ');
                       if ($sec eq '') {
                           $r->print(&mt('[_1]No section[_2] - [_3]','<b>','</b>',$dates));
                       } else {
                           $r->print(&mt('Section(s): [_1] - [_2]',
                                         '<b>'.$showsecs.'</b>',$dates));
                       }
                       $r->print('<br />');
                   } else {
                       $r->print(&mt("$result_text{'ok'}{$choice} role of '[_1]' in [_2] for '[_3]' to [_4] - [_5]",$plrole,$extent,
                           '<i>'.&Apache::loncommon::plainname($uname,$udom).'</i>',
                           '<b>'.$showsecs.'</b>',$dates).'<br />');
                      $count ++;
                  }
                  if ($warn_singlesec) {
                      $r->print('<div class="LC_warning">'.$warn_singlesec.'</div>');
                  }
               } elsif ($choice eq 'chgdates') {
                   $r->print(&mt("$result_text{'ok'}{$choice} role of '[_1]' in [_2] for '[_3]' - [_4]",$plrole,$extent, 
                         '<i>'.&Apache::loncommon::plainname($uname.':'.$udom).'</i>',
                         $dates).'<br />');
                  $count ++;
               } else {
                   $r->print(&mt("$result_text{'ok'}{$choice} role of '[_1]' in [_2] for '[_3]'.",$plrole,$extent,
                         '<i>'.&Apache::loncommon::plainname($uname.':'.$udom).'</i>').
                             '<br />');
                   $count ++;
               }
         } else {          } else {
             $r->print(              $r->print(
                 &mt("Error $result_text{'error'}{$choice} [_1] in [_2] for [_3]: [_4].",                  &mt("Error $result_text{'error'}{$choice} [_1] in [_2] for '[_3]': [_4].",
                     $plrole,$extent,$uname.':'.$udom,$result).'<br />');                      $plrole,$extent,
                       '<i>'.&Apache::loncommon::plainname($uname.':'.$udom).'</i>',
                       $result).'<br />');
         }          }
     }      }
     $r->print('<form name="studentform" method="post" action="/adm/createuser">'."\n");      $r->print('<form name="studentform" method="post" action="/adm/createuser">'."\n");
Line 4632  sub update_user_list { Line 4715  sub update_user_list {
             }              }
         }          }
     }      }
     $r->print('<p><b>'.&mt("$result_text{'ok'}{$choice} role(s) for [quant,_1,user,users,no users].",$count).'</b></p>');      $r->print('<p><b>'.&mt("$result_text{'ok'}{$choice} for [quant,_1,user role,user roles,no user roles].",$count).'</b></p>');
     if ($count > 0) {      if ($count > 0) {
         if ($choice eq 'revoke' || $choice eq 'drop') {          if ($choice eq 'revoke' || $choice eq 'drop') {
             $r->print('<p>'.&mt('Re-enabling will re-activate data for the role.').'</p>');              $r->print('<p>'.&mt('Re-enabling will re-activate data for the role.').'</p>');
Line 4652  sub update_user_list { Line 4735  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)});

Removed from v.1.117  
changed lines
  Added in v.1.118


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