[LON-CAPA-cvs] cvs: loncom /interface lonuserutils.pm

raeburn raeburn@source.lon-capa.org
Sun, 21 Mar 2010 14:58:40 -0000


This is a MIME encoded message

--raeburn1269183520
Content-Type: text/plain

raeburn		Sun Mar 21 14:58:40 2010 EDT

  Modified files:              
    /loncom/interface	lonuserutils.pm 
  Log:
  - Improvements to feedback to user when using: 
    "Change section associated with user roles" from the list users screen in a course.
    - New routine:  &dates_feedback() generates information to display about start/end     dates for roles included in section switching.
    - Detect cases where no sections occurred, and report that.
    - Detect cases where multiple sections were requested for a student role for a user,
      and report (as a warning) that only the first section assignment was made.
  - xhml
  - wording changes
  
  
--raeburn1269183520
Content-Type: text/plain
Content-Disposition: attachment; filename="raeburn-20100321145840.txt"

Index: loncom/interface/lonuserutils.pm
diff -u loncom/interface/lonuserutils.pm:1.117 loncom/interface/lonuserutils.pm:1.118
--- loncom/interface/lonuserutils.pm:1.117	Sun Mar 21 14:15:58 2010
+++ loncom/interface/lonuserutils.pm	Sun Mar 21 14:58:40 2010
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Utility functions for managing LON-CAPA user accounts
 #
-# $Id: lonuserutils.pm,v 1.117 2010/03/21 14:15:58 raeburn Exp $
+# $Id: lonuserutils.pm,v 1.118 2010/03/21 14:58:40 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -3173,9 +3173,9 @@
     my %lt = &Apache::lonlocal::texthash (
                  chac => 'Access dates to apply for 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.',
-                 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?", 
+                 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.',
+                 reta => "Retain each user's current section affiliations?",
                  dnap => '(Does not apply to student roles).',
             );
     my ($date_items,$headertext);
@@ -3193,13 +3193,13 @@
                                           $permission,$crstype);
     }
     $output .= '<h3>'.$headertext.'</h3>'.
-               '<form name="'.$formname.'" method="post">'."\n".
+               '<form name="'.$formname.'" method="post" action="">'."\n".
                 $date_items;
     if ($context eq 'course' && $env{'form.bulkaction'} eq 'chgsec') {
         my ($cnum,$cdom) = &get_course_identity();
         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{'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{'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{'dnap'} = &mt('(Does not apply to member roles).'); 
         }
         my $info;
@@ -3240,7 +3240,7 @@
     my ($cdom,$cnum,$role,$rowtitle,$permission,$context,$mode,$crstype) = @_;
     my %sections_count = &Apache::loncommon::get_sections($cdom,$cnum);
     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') {
         my ($options,$cb_script,$coursepick) =
             &default_role_selector($context,1,$crstype);
@@ -3253,7 +3253,7 @@
                    '<td align="center">'.&mt('Existing sections')."\n".
                    '<br />'.$sections_select.'</td><td align="center">'.
                    &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".
                    '</td></tr></table>'."\n";
     } else {
@@ -3262,7 +3262,7 @@
                    $env{'request.course.sec'};
     }
     $secbox .= &Apache::lonhtmlcommon::row_closure(1)."\n".
-               &Apache::lonhtmlcommon::end_pick_box().'</p>';
+               &Apache::lonhtmlcommon::end_pick_box().'</div>';
     return $secbox;
 }
 
@@ -4392,7 +4392,7 @@
 # ================================================================== Phase four
 
 sub update_user_list {
-    my ($r,$context,$setting,$choice) = @_;
+    my ($r,$context,$setting,$choice,$crstype) = @_;
     my $now = time;
     my $count=0;
     my $crstype;
@@ -4410,7 +4410,7 @@
                                    'reenable' => 'Re-enabled',
                                    'activate' => 'Activated',
                                    'chgdates' => 'Changed Access Dates for',
-                                   'chgsec'   => 'Changed section for',
+                                   'chgsec'   => 'Changed section(s) for',
                                    'drop'     => 'Dropped',
                                  },
                         error => {'revoke'    => 'revoking',
@@ -4427,8 +4427,9 @@
         ($startdate,$enddate) = &get_dates_from_form();
     }
     foreach my $item (@changelist) {
-        my ($role,$uname,$udom,$cid,$sec,$scope,$result,$type,$locktype,@sections,
-            $scopestem);
+        my ($role,$uname,$udom,$cid,$sec,$scope,$result,$type,$locktype,
+            @sections,$scopestem,$singlesec,$showsecs,$warn_singlesec,
+            $nothingtodo,$keepnosection);
         if ($choice eq 'drop') {
             ($uname,$udom,$sec) = split(/:/,$item,-1);
             $role = 'st';
@@ -4538,11 +4539,12 @@
                     }
                 }
                 # remove existing section if not to be retained.   
-                if (!$env{'form.retainsec'}) {
+                if (!$env{'form.retainsec'} || ($role eq 'st')) {
                     if ($sec eq '') {
                         if (@newsecs == 0) {
-                            $result = &mt('No change in section assignment (none)');
+                            $result = 'ok';
                             $nochg = 1;
+                            $nothingtodo = 1;
                         } else {
                             $revresult =
                                 &Apache::lonnet::revokerole($udom,$uname,
@@ -4569,13 +4571,23 @@
                 } else {
                     if ($sec eq '') {
                         $nochg = 1;
-                    } else { 
+                        $keepnosection = 1;
+                    } else {
                         push(@retained,$sec);
                     }
                 }
                 # add new sections
+                my (@diffs,@shownew);
+                if (@retained) {
+                    @diffs = &Apache::loncommon::compare_arrays(\@retained,\@newsecs);
+                } else {
+                    @diffs = @newsecs;
+                }
                 if (@newsecs == 0) {
-                    if (!$nochg) {
+                    if ($nochg) {
+                        $result = 'ok';
+                        $nothingtodo = 1;
+                    } else {
                         if ($role eq 'st') {
                             $result = 
                                 &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,undef,$end,$start,$type,$locktype,$cid,'',$context);
@@ -4584,22 +4596,58 @@
                             $result = &Apache::lonnet::assignrole($udom,$uname,$newscope,$role,$end,$start,'','',$context);
                         }
                     }
+                    $showsecs = &mt('No section');
+                } elsif (@diffs == 0) {
+                    $result = 'ok';
+                    $nothingtodo = 1;
                 } else {
-                    foreach my $newsec (@newsecs) { 
+                    foreach my $newsec (@newsecs) {
                         if (!grep(/^\Q$newsec\E$/,@retained)) {
                             if ($role eq 'st') {
                                 $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 {
                                 my $newscope = $scopestem;
                                 if ($newsec ne '') {
                                    $newscope .= '/'.$newsec;
+                                   push(@shownew,$newsec); 
                                 }
                                 $result = &Apache::lonnet::assignrole($udom,$uname,
                                                         $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;
@@ -4610,13 +4658,48 @@
             }
         }
         if ($result eq 'ok' || $result eq 'ok:') {
-            $r->print(&mt("$result_text{'ok'}{$choice} role of '[_1]' in [_2] for [_3]",
-                          $plrole,$extent,$uname.':'.$udom).'<br />');
-            $count++;
+            my $dates;
+            if (($choice eq 'chgsec') || ($choice eq 'chgdates')) {
+                $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 {
             $r->print(
-                &mt("Error $result_text{'error'}{$choice} [_1] in [_2] for [_3]: [_4].",
-                    $plrole,$extent,$uname.':'.$udom,$result).'<br />');
+                &mt("Error $result_text{'error'}{$choice} [_1] in [_2] for '[_3]': [_4].",
+                    $plrole,$extent,
+                    '<i>'.&Apache::loncommon::plainname($uname.':'.$udom).'</i>',
+                    $result).'<br />');
         }
     }
     $r->print('<form name="studentform" method="post" action="/adm/createuser">'."\n");
@@ -4632,7 +4715,7 @@
             }
         }
     }
-    $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 ($choice eq 'revoke' || $choice eq 'drop') {
             $r->print('<p>'.&mt('Re-enabling will re-activate data for the role.').'</p>');
@@ -4652,6 +4735,27 @@
     $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 {
     my ($scope,$uname,$udom,$now) = @_;
     my ($cdom,$cnum) = ($scope=~m{^/($match_domain)/($match_courseid)});

--raeburn1269183520--