[prev in list] [next in list] [prev in thread] [next in thread] 

List:       lon-capa-cvs
Subject:    [LON-CAPA-cvs] cvs: loncom /interface lonpopulate.pm
From:       raeburn <lon-capa-cvs () mail ! lon-capa ! org>
Date:       2006-07-27 23:24:19
Message-ID: cvsraeburn1154042659 () cvsserver
[Download RAW message or body]

This is a MIME encoded message


raeburn		Thu Jul 27 19:24:19 2006 EDT

  Modified files:              
    /loncom/interface	lonpopulate.pm 
  Log:
  Bug 4536.  Domain coordinators displaying notification selection page will display \
all Course Coordinators, as well as all users with DC role in the course's domain.  \
For CCs, status of role is also displayed. For non-DC users, all CCs are displayed as \
well as any DCs currently on the "notified" list. Changes to studentphot setting \
interfaces to handle storage of course owners as username:domain; backwards \
compatible with username only mode.  
  


["raeburn-20060727192419.txt" (text/plain)]

Index: loncom/interface/lonpopulate.pm
diff -u loncom/interface/lonpopulate.pm:1.43 loncom/interface/lonpopulate.pm:1.44
--- loncom/interface/lonpopulate.pm:1.43	Wed May 17 21:08:51 2006
+++ loncom/interface/lonpopulate.pm	Thu Jul 27 19:24:19 2006
@@ -1,5 +1,5 @@
 # automated enrollment configuration handler
-# $Id: lonpopulate.pm,v 1.43 2006/05/18 01:08:51 raeburn Exp $
+# $Id: lonpopulate.pm,v 1.44 2006/07/27 23:24:19 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -479,6 +479,8 @@
   } elsif ($action eq "notify") {
       my $notifycount = 0;
       my @notified = split(/,/,$enrollvar{notifylist});
+      my @domcoord;
+      my @showdom;
       for (my $i=0; $i<@notified; $i++) {
           if ($notified[$i] !~ /:/) {
               $notified[$i] =~ s/\@/:/;
@@ -491,7 +493,15 @@
       } else {
           $noteset = "OFF";
       }
-    
+      my %dompersonnel = &Apache::lonnet::get_domain_roles($dom,['dc']);
+      foreach my $server (keys %dompersonnel) {
+          foreach my $user (sort(keys %{$dompersonnel{$server}})) {
+              my ($trole,$uname,$udom,$runame,$rudom,$rsec) = split(/:/,$user);
+              if (!grep/^$uname:$udom$/,@domcoord) {
+                  push(@domcoord,$uname.':'.$udom);
+              }
+          }
+      }
       $r->print("
                   <form name=\"enter\" method=\"post\"><br/>
                    <table width=\"100%\" border=\"0\" cellpadding=\"6\" \
cellspacing=\"0\"> @@ -521,113 +531,135 @@
               </td>
              </tr>
       ");
-      my @coursepersonnel = &Apache::lonnet::getkeys('nohist_userroles',$dom,$crs);
-      my @ccs = ();
-      my @oldccs = ();
-      my %pname = ();
-      my %notifystate = ();
-      foreach (@coursepersonnel) {
-          my @roleinfo = split/:/,$_;
-          if ($roleinfo[0] eq 'cc')  {
-              unless (grep/^$roleinfo[1]\:$roleinfo[2]/,@ccs) {
-                  my $active_cc = \
                &Apache::loncommon::check_user_status($roleinfo[2],$roleinfo[1],$dom,$crs,'cc');
                
-                  if ($active_cc eq 'active') {
-                      push @ccs, $roleinfo[1].':'.$roleinfo[2];
-                      $pname{$roleinfo[1].':'.$roleinfo[2]} = \
                &Apache::loncommon::plainname($roleinfo[1],$roleinfo[2]);
-                      if (grep/^$roleinfo[1]\:$roleinfo[2]$/,@notified) {
-                          $notifystate{$roleinfo[1].':'.$roleinfo[2]} = 1;
-                      } else {
-                          $notifystate{$roleinfo[1].':'.$roleinfo[2]} = 0;
-                      }
+      my %coursepersonnel = &Apache::lonnet::dump('nohist_userroles',$dom,$crs);
+      my @ccs;
+      my %pname;
+      my %notifystate;
+      my %status;
+      my $now = time;
+      foreach my $person (sort(keys(%coursepersonnel))) {
+          my $match = 0;
+          my ($role,$user,$usec) = ($person =~ /^([^:]+):([^:]+:[^:]+):([^:]*)/);
+          $user =~ s/:$//;
+          my ($end,$start) = split(/:/,$coursepersonnel{$person});
+          if ($end == -1 || $start == -1) {
+              next;
+          }
+          if ($role eq 'cc')  {
+              unless (grep/^$user$/,@ccs) {
+                  if ($end && $end < $now) {
+                      $status{$user} = 'previous';
+                  } elsif ($start > $now) {
+                      $status{$user} = 'future';
                   } else {
-                      push @oldccs, $roleinfo[1].':'.$roleinfo[2];
+                      $status{$user} = 'active';
+                  }
+                  push(@ccs,$user);
+                  my ($uname,$udom) = split(/:/,$user);
+                  $pname{$user} = 
+                           &Apache::loncommon::plainname($uname,$udom);
+                  if (grep/^$user$/,@notified) {
+                      $notifystate{$user} = 1;
+                  } else {
+                      $notifystate{$user} = 0;
                   }
               }
           }
       }
-      if ($notifycount > 0) {
-          foreach my $person (@notified) {
-              unless ( (grep/^$person$/,@ccs) || ($person eq '') || \
                (grep/^$person$/,@oldccs) ) {
-                  push @ccs, $person;
-                  my ($puname,$pdom) = split/:/,$person;
-                  $pname{$person} =  &Apache::loncommon::plainname($puname,$pdom);
-                  $notifystate{$person} = 1;
-              }
-          }
-      }
-      my $viewer = $env{'user.name'}.':'.$env{'user.domain'};
-      unless ( (grep/^$viewer$/,@ccs) || ($viewer eq '') )  {
-          push @ccs,$viewer;
-          $pname{$viewer} =  \
                &Apache::loncommon::plainname($env{'user.name'},$env{'user.domain'});
-          $notifystate{$viewer} = 0;
-      }
-
       my $notifyshow = @ccs;
-
+      my %lt = &Apache::lonlocal::texthash(
+                                  name => 'Name',
+                                  usnm => 'username:domain',
+                                  coac => 'Course Access',
+                                  curn => 'Current notification status',
+                                  notf => 'Notification?',
+                                  ntac => 'Notification active',
+                                  ntin => 'Notification inactive',
+      );
       if (@ccs > 0) {
           @ccs = sort @ccs;
           $r->print("
              <tr>
-               <td>The table below contains a list of course coordinators in this \
course. Uncheck the 'Notification?' checkbox for each person who is to be removed \
from the list of recipients who are currently informed of roster changes whenever any \
adds or drops occur during the nightly enrollment check. To include individuals who \
are not currently recipients, simply check the 'Notification?' checkbox. Click 'Go' \
to store your changes. +               <td>".&mt('The table below contains a list of \
[_1]s in this course.',&Apache::lonnet::plaintext('cc'))."  </td>
              </tr>
              <tr>
               <td>");
-          $r->print(&Apache::loncommon::start_data_table());
-          $r->print(&Apache::loncommon::start_data_table_row());
+          $r->print(&notifier_tables('cc',\%lt,\@ccs,\%status,\%notifystate,
+                                     \%pname,\$notifyshow));
+          $r->print("</td></tr>");
+      } else {
           $r->print("
-                 <th>Name</th>
-                 <th>username:domain</th>
-                 <th>Current status</th>
-                 <th>Notification?</th>
-          ");
-          $r->print(&Apache::loncommon::end_data_table_row());
-          for (my $i=0; $i<@ccs; $i++) {
-              $r->print(&Apache::loncommon::start_data_table_row());
-              $r->print("
-                 <td>$pname{$ccs[$i]}</td>
-                 <td><input type=\"hidden\" name=\"notifyname_$i\" \
                value=\"$ccs[$i]\" />$ccs[$i]</td>
-                 <td>
-              ");
-              if ($notifystate{$ccs[$i]} == 1) {
-                  $r->print("Notification active");
-              } else {
-                  $r->print("Notification inactive");
-              }
-              if ($notifystate{$ccs[$i]} == 1) {
-                  $r->print("</td><td><input type=\"checkbox\" name=\"note_$i\" \
checked=\"true\" /></td>"); +             <tr>
+              <td>".
+             &mt('No [_1]s found.',&Apache::lonnet::plaintext('cc'))."
+            </td>
+           </tr>");
+      }
+      my $viewer = $env{'user.name'}.':'.$env{'user.domain'};
+      my $showalldc = 0;
+      if (grep(/^$viewer$/,@domcoord)) {
+          $showalldc = 1;
+      }
+      foreach my $dc (@domcoord) {
+          if (!grep(/^$dc$/,@ccs)) {
+              if (grep(/^$dc$/,@notified)) {
+                  $notifystate{$dc} = 1;
               } else {
-                  $r->print("</td><td><input type=\"checkbox\" name=\"note_$i\" \
/></td>"); +                  $notifystate{$dc} = 0;
+                  if (!$showalldc) {
+                      next;
+                  }
               }
-              $r->print(&Apache::loncommon::end_data_table_row());
+              my ($dcuname,$dcdom) = split(/:/,$dc);
+              $pname{$dc} =  &Apache::loncommon::plainname($dcuname,$dcdom);
+              push(@showdom,$dc);
           }
-          $r->print(&Apache::loncommon::end_data_table());
+      }
+      my $showdomnum = scalar(@showdom);
+      if ($showdomnum) {
           $r->print("
-               <br/>
-               <table width=\"100%\" border=\"0\" cellspadding=\"2\" \
                cellspacing=\"2\">
-                <tr>
-                 <td align=\"right\">
-                  <input type=\"button\" name=\"notifyset\" value=\"Go\" \
                onclick=\"process('notify')\" />
-                 </td>
-                </tr>
-               </table>
+             <tr>
+              <td>&nbsp;</td>
+             </tr><tr>
+              <td>");
+          if ($showalldc) {
+              $r->print(&mt("The table below contains a list of [_1]s from this \
course's domain who are not also \
[_2]s.",&Apache::lonnet::plaintext('dc'),&Apache::lonnet::plaintext('cc'))); +        \
} else { +              $r->print(&mt("The table below contains a list of [_1] from \
this course's domain who currently receive notification, and are not also \
[_2]s.",&Apache::lonnet::plaintext('dc'),&Apache::lonnet::plaintext('cc'))); +        \
} +          $r->print(" 
               </td>
              </tr>
-          ");
-      } else {
-          $r->print("
              <tr>
-              <td>
-             No course coordinators found.
-            </td>
-           </tr>");
+              <td>");
+          $r->print(&notifier_tables('dc',\%lt,\@showdom,\%status,\%notifystate,
+                                     \%pname,\$notifyshow));
+          $r->print("
+             </td>
+          </tr>");
+      }
+      if ($notifycount || @showdom > 0) {
+          $r->print("<tr><td>&nbsp;</td></tr><tr><td>".
+                &mt("Uncheck the 'Notification?' checkbox for each person who is to \
be removed from the list of recipients who are currently informed of roster changes \
whenever any adds or drops occur during the nightly enrollment check.").' '.&mt("To \
include individuals who are not currently recipients, simply check the \
'Notification?' checkbox. Click 'Go' to store your changes.")." +           <br/>
+           <table width=\"100%\" border=\"0\" cellspadding=\"2\" cellspacing=\"2\">
+            <tr>
+             <td align=\"right\">
+              <input type=\"button\" name=\"notifyset\" value=\"Go\" \
onclick=\"process('notify')\" /> +             </td>
+            </tr>
+           </table>
+          </td>
+         </tr>
+      ");
       }
       $r->print("
-          </table>
-          <input type=\"hidden\" name=\"notifyshow\" value=\"$notifyshow\" />
-          <input type=\"hidden\" name=\"action\" value=\"$action\" />
-          <input type=\"hidden\" name=\"state\" value=\"process\" />
-          </form>
+      </table>
+      <input type=\"hidden\" name=\"notifyshow\" value=\"$notifyshow\" />
+      <input type=\"hidden\" name=\"action\" value=\"$action\" />
+      <input type=\"hidden\" name=\"state\" value=\"process\" />
+      </form>
       ");
   } elsif ($action eq "crosslist") {
       my @xlists;
@@ -881,16 +913,22 @@
       my ($result,$perm_reqd)=&Apache::lonnet::auto_photo_permission($crs,$dom);
       my $can_enable = 1;
       my $institution = $Apache::lonnet::domaindescription{$dom};
+      my $user;
+      if ($enrollvar{'courseowner'} =~ /^[^:]+:[^:]+$/) {
+          $user = $env{'user.name'}.':'.$env{'user.domain'};
+      } else {
+          $user = $env{'user.name'};
+      }
       if ($result eq 'ok') {
           if ($perm_reqd eq 'yes') {
               if (!($enrollvar{'photopermission'} eq 'yes')) {
                   $can_enable = 0;
               } else {
-                  if ($env{'user.name'} eq $enrollvar{'courseowner'}) {
+                  if ($user eq $enrollvar{'courseowner'}) {
                       $r->print('
                     <tr>
                      <td>'.
-&mt('Previously the owner of this course agreed to the conditions of use of digital \
student photos required by [_1].', $institution).'<br />'.&mt('As a result Course \
Coordinators can choose to automatically import student photos into this \
course.').'<br /><nobr><label>'.&mt('[_1] owner acceptance of these conditions of \
use?','<b>Cancel</b>').'&nbsp;<input type="checkbox" name="cancel_agreement" \
value="1" /></label></nobr> +&mt('Previously the owner of this course agreed to the \
conditions of use of digital student photos required by [_1].', $institution).'<br \
/>'.&mt('As a result [_1]s can choose to automatically import student photos into \
this course.',&Apache::lonnet::plaintext('cc')).'<br /><nobr><label>'.&mt('[_1] owner \
acceptance of these conditions of use?','<b>Cancel</b>').'&nbsp;<input \
type="checkbox" name="cancel_agreement" value="1" /></label></nobr>  </td>
                     </tr>
                       ');
@@ -919,7 +957,7 @@
                     </tr>
 ');
       } else {
-          if ($env{'user.name'} eq $enrollvar{'courseowner'}) {
+          if ($user eq $enrollvar{'courseowner'}) {
               $r->print('
                     <tr>
                      <td>'.
@@ -937,7 +975,7 @@
               $r->print('
                     <tr>
                      <td>'.
-&mt('The policies of your institution [_1] require that the course owner [_2] must \
indicate acceptance of the conditions of use of digital photos of registered \
students, before they may be made available for use in a \
course.',$institution,$ownername).'<br /><br />'.&mt('Please direct the course owner \
[_1] to visit the "Student photos" page in the Automated Enrollment Manager to \
indicate acceptance of these conditions of use.',$emailstr).'<br /><br /><input \
type="button" name="mainmenu" value="Go back" onclick="javascript:history.go(-1);" /> \
+&mt('The policies of your institution ([_1]) require that the course owner ([_2]) \
must indicate acceptance of the conditions of use of digital photos of registered \
students, before they may be made available for use in a \
course.',$institution,$ownername).'<br /><br />'.&mt('Please direct the course owner \
[_1] to visit the "Student photos" page in the Automated Enrollment Manager to \
indicate acceptance of these conditions of use.',$emailstr).'<br /><br /><input \
type="button" name="mainmenu" value="Go back" onclick="javascript:history.go(-1);" /> \
</td>  </tr>
                   </form>
@@ -1133,6 +1171,44 @@
   }
 }
 
+sub notifier_tables {
+    my ($role,$lt,$users,$status,$notifystate,$pname,$notifyshow) = @_;
+    my $output = &Apache::loncommon::start_data_table();
+    $output .= &Apache::loncommon::start_data_table_header_row();
+    $output .= "<th>$$lt{name}</th>
+                <th>$$lt{usnm}</th>";
+    if ($role eq 'cc') {
+        $output .= "<th>$$lt{coac}</th>";
+    } 
+    $output .=  "<th>$$lt{curn}</th>
+                 <th>$$lt{notf}</th>";
+    $output .= &Apache::loncommon::end_data_table_header_row();
+    for (my $i=0; $i<@{$users}; $i++) {
+        $output .= &Apache::loncommon::start_data_table_row();
+        $output .= '<td>'.$$pname{$$users[$i]}.'</td>'.
+                   '<td><input type="hidden" name="notifyname_'.$$notifyshow.
+                   '" value="'.$$users[$i].'" />'.$$users[$i].'</td>';
+        if ($role eq 'cc') {
+            $output .= '<td>'.$$status{$$users[$i]}.'</td>';
+        }
+        $output .= '<td>';
+        if ($$notifystate{$$users[$i]} == 1) {
+            $output .= $$lt{ntac};
+        } else {
+            $output .= $$lt{ntin};
+        }
+        $output .= '</td><td><input type="checkbox" name="note_'.$$notifyshow.'"'; 
+        if ($$notifystate{$$users[$i]} == 1) {
+            $output .= ' checked="checked"';
+        }
+        $output .= ' /></td>';
+        $output .= &Apache::loncommon::end_data_table_row();
+        $$notifyshow ++;
+    }
+    $output .= &Apache::loncommon::end_data_table();
+    return $output;
+}
+
 sub print_accessdate_table {
     my ($r,$enrollvar,$tasktitleref,$action) = @_;
     my ($start_table,$end_table) = \
&date_setting_table($$enrollvar{'default_enrollment_start_date'},$$enrollvar{'default_enrollment_end_date'},$action);
 @@ -1612,7 +1688,7 @@
 		    }
 		    $response .= "</ul>\n";
 		} else {
-		    $response = "Notification of enrollment changes was <b> not enabled</b> as no \
course coordinators were selected as recipients.<br/>"; +		    $response = \
&mt('Notification of enrollment changes was <b> not enabled</b> as no [_1]s were \
selected as recipients.<br/>',&Apache::lonnet::plaintext('cc'));  }
 	    } else {
 		if ($currcount) {
@@ -2287,8 +2363,12 @@
   </form>
 ';
     } else {
-        my ($ownername,$owneremail) = &get_oenerinfo($dom,$courseowner);
-        $response = &mt('The policies of your institution [_1] require that the \
course owner [_2] must indicate acceptance of the conditions of use of digital photos \
of registered students, before they may be made available for use in a \
course.',$institution,$ownername).'<br /><br />'.&mt('Please direct the course owner \
(e-mail: [_1]) to visit the "Student photos" page in the Automated Enrollment Manager \
to indicate acceptance of these conditions of use',$owneremail); +        my \
($ownername,$owneremail) = &get_ownerinfo($dom,$courseowner); +        my $emailstr;
+        if ($owneremail) {
+            $emailstr = "(e-mail: $owneremail)";
+        }
+        $response = &mt('The policies of your institution [_1] require that the \
course owner [_2] must indicate acceptance of the conditions of use of digital photos \
of registered students, before they may be made available for use in a \
course.',$institution,$ownername).'<br /><br />'.&mt('Please direct the course owner \
[_1] to visit the "Student photos" page in the Automated Enrollment Manager to \
indicate acceptance of these conditions of use',$emailstr);  }
     &print_reply($r,$response,$$tasktitleref{$action});
 }
@@ -2426,11 +2506,19 @@
 
 sub get_ownerinfo {
     my ($dom,$owner) = @_; 
-    my ($ownername,$owneremail);
+    my ($ownername,$owneremail,$own_uname,$own_udom);
     if ($owner) {
-        $ownername=&Apache::loncommon::plainname($owner,$dom,'firstname');
+        if ($owner =~ /^([^:]+):([^:]+)$/) {
+            $own_uname = $1;
+            $own_udom = $2; 
+        } else {
+            $own_uname = $owner;
+            $own_udom = $dom; 
+        }
+        $ownername=&Apache::loncommon::plainname($own_uname,$own_udom,
+                                                 'firstname');
         my %ownerinfo = &Apache::lonnet::get('environment',['permanentemail'],
-					     $dom,$owner);
+					     $own_udom,$own_uname);
         $owneremail = $ownerinfo{'permanentemail'};
     }
     return ($ownername,$owneremail);


_______________________________________________
LON-CAPA-cvs mailing list
LON-CAPA-cvs@mail.lon-capa.org
http://mail.lon-capa.org/mailman/listinfo/lon-capa-cvs

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic