[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:       2003-12-29 16:34:39
Message-ID: cvsraeburn1072715679 () cvsserver
[Download RAW message or body]

This is a MIME encoded message


raeburn		Mon Dec 29 11:34:39 2003 EDT

  Modified files:              
    /loncom/interface	lonpopulate.pm 
  Log:
  Added call to localenroll::new_course() when a new section is added, so that \
checking of valid sections (and valid course owners) will now occur if \
localenroll::new_course has been customized appropriately.  Modified display of \
sections where call to localenroll::get_sections() returns a single section, so that \
(a) a section can be added if one was NOT selected when the course was created, and \
(b) the LON-CAPA section/group ID can be changed for an existing (single section).  
  


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

Index: loncom/interface/lonpopulate.pm
diff -u loncom/interface/lonpopulate.pm:1.7 loncom/interface/lonpopulate.pm:1.8
--- loncom/interface/lonpopulate.pm:1.7	Mon Dec 15 02:55:59 2003
+++ loncom/interface/lonpopulate.pm	Mon Dec 29 11:34:39 2003
@@ -1,5 +1,5 @@
 # automated enrollment configuration handler
-# $Id: lonpopulate.pm,v 1.7 2003/12/15 07:55:59 raeburn Exp $
+# $Id: lonpopulate.pm,v 1.8 2003/12/29 16:34:39 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -645,9 +645,8 @@
           }
       }
       if (@sections > 0) {
-          if (@sections > 1) {
-              my $secshow = @sections;
-              $r->print("
+          my $secshow = @sections;
+          $r->print("
             <form name=\"enter\" method=\"post\"><br/>
             <table width=\"100%\" border=\"0\" cellpadding=\"3\" cellspacing=\"3\">
              <tr>
@@ -669,27 +668,27 @@
               <td><b>LON-CAPA section/group ID</b></td>
               <td><b>Enrollment in this course?</b></td>
              </tr>
-              ");
-              for (my $i=0; $i<@sections; $i++) {
-                  my $colflag = $i%2;
-                  my $shrflag = 0;
-                  $r->print("<tr bgcolor=\"$bgcolors[$colflag]\" align=\"left\">
+          ");
+          for (my $i=0; $i<@sections; $i++) {
+              my $colflag = $i%2;
+              my $shrflag = 0;
+              $r->print("<tr bgcolor=\"$bgcolors[$colflag]\" align=\"left\">
                    <td>$sections[$i]<input type=\"hidden\" name=\"secnum_$i\" \
value=\"$sections[$i]\" /></td>  <td>
-                  ");
-                  if (grep/^$sections[$i]$/,@currsections) {
-                      $r->print("Enrollment active");
-                      $shrflag = 1;
-                  } else {
-                      $r->print("Enrollment inactive");
-                  }
-                  if ($shrflag) {
-                      $r->print("</td><td><input type=\"text\" size=\"10\" \
name=\"loncapasec_$i\" value=\"$sec_id{$sections[$i]}\"></td><td><input \
                type=\"checkbox\" name=\"sec_$i\" checked=\"true\" /></td></tr>"); 
-                  } else {
-                      $r->print("</td><td><input type=\"text\" size=\"10\" \
name=\"loncapasec_$i\" value=\"\"><td><input type=\"checkbox\" name=\"sec_$i\" \
                /></td></tr>");
-                  }
+              ");
+              if (grep/^$sections[$i]$/,@currsections) {
+                  $r->print("Enrollment active");
+                  $shrflag = 1;
+              } else {
+                  $r->print("Enrollment inactive");
               }
-              $r->print("
+              if ($shrflag) {
+                  $r->print("</td><td><input type=\"text\" size=\"10\" \
name=\"loncapasec_$i\" value=\"$sec_id{$sections[$i]}\"></td><td><input \
type=\"checkbox\" name=\"sec_$i\" checked=\"true\" /></td></tr>");  +              } \
else { +                  $r->print("</td><td><input type=\"text\" size=\"10\" \
name=\"loncapasec_$i\" value=\"\"><td><input type=\"checkbox\" name=\"sec_$i\" \
/></td></tr>"); +              }
+          }
+          $r->print("
             </table>
             <br/>
             <table width=\"100%\" border=\"0\" cellspacing=\"3\" cellpadding=\"3\">
@@ -703,23 +702,7 @@
             <input type=\"hidden\" name=\"action\" value=\"$action\">
             <input type=\"hidden\" name=\"state\" value=\"process\">
             </form>
-              ");
-          } else {
-              $r->print("<br/>            
-            <table width=\"100%\" border=\"0\" cellpadding=\"3\" cellspacing=\"3\">
-             <tr>
-              <td align=\"left\">
-               <b>$$tasktitleref{$action}</b><br/>
-              </td>
-             </tr>
-            </table>
-            <table border=\"0\" cellspacing=\"2\" cellpadding=\"2\">
-             <tr>
-              <td>As your institution's course catalog only includes a single \
section for this course, there are no additional sections that can be set for \
                inclusion in the LON-CAPA roster for the course.</td>
-            </tr>
-            </table>
-              ");
-          } 
+          ");
       } else {
           $r->print("
             <form name=\"enter\" method=\"post\"><br/>
@@ -1315,15 +1298,18 @@
 
 sub print_sections_menu () {
   my ($r,$realm,$dom,$crs,$action,$tasktitleref) = @_;
-  my %settings = &Apache::lonnet::get('environment',['internal.sectionnums','internal.coursecode'],$dom,$crs);
 +  my %settings = &Apache::lonnet::get('environment',['internal.sectionnums','internal.coursecode','internal.courseowner'],$dom,$crs);
  my @currsections = ();
   my @sections = ();
+  my @badowner = ();
+  my @badsections = ();
   my $seccount = 0;
   my $removecount = 0;
   my $addcount = 0;
   my $secstr = '';
   my $response = '';
   my $coursecode = $settings{'internal.coursecode'};
+  my $owner = $settings{'internal.courseowner'};
   if ($settings{'internal.sectionnums'} =~ m/,/) {
       @currsections = split/,/,$settings{'internal.sectionnums'};
   } elsif ($settings{'internal.sectionnums'} ne '') {
@@ -1331,35 +1317,49 @@
   }
 
   if ( exists($ENV{'form.secshow'}) ) {
-     for (my $i=0; $i<$ENV{'form.secshow'}; $i++) {
-         my $gp = "loncapasec_".$i;
-         my $secnum = "secnum_".$i;
-         my $sec = "sec_".$i;
-         if ( exists( $ENV{"form.$sec"} ) ) {
-            my $secentry;
-            if ( exists( $ENV{"form.$secnum"} ) ) { 
-                $secentry = $ENV{"form.$secnum"}.':';
-            }
-            if ( exists( $ENV{"form.$gp"} ) ) {
-                $secentry .= $ENV{"form.$gp"};
-            }
-            push @sections, $secentry;
-            $seccount ++;
-            unless (grep/^$ENV{"form.$secnum"}:/,@currsections) {
-                $addcount ++;
-            }
-         }
-     }
-     if (@currsections > 0) {
-         for (my $i=0; $i<@currsections; $i++) {
-             if ($currsections[$i] =~ m/^(\w+:)/ ) {
-                my $oldsec  = $1;
-                unless (grep/^$oldsec/,@sections) {
-                    $removecount ++;
-                }
-             }
-         }
-     }
+      for (my $i=0; $i<$ENV{'form.secshow'}; $i++) {
+          my $gp = "loncapasec_".$i;
+          my $secnum = "secnum_".$i;
+          my $sec = "sec_".$i;
+          if ( exists( $ENV{"form.$sec"} ) ) {
+              my $secentry;
+              if ( exists( $ENV{"form.$secnum"} ) ) { 
+                  $secentry = $ENV{"form.$secnum"}.':';
+              }
+              if ( exists( $ENV{"form.$gp"} ) ) {
+                  $secentry .= $ENV{"form.$gp"};
+              }
+              if ( grep/^$ENV{"form.$secnum"}:/,@currsections) {
+                  push @sections, $secentry;
+                  $seccount ++;
+              } else {
+                  my $newsec = $coursecode.$ENV{"form.$secnum"};
+                  my $coursecheck = &localenroll::validate_courseID($newsec);
+                  if ($coursecheck eq 'ok') {
+                      my $addcheck = &localenroll::new_course($newsec,$owner);
+                      if ($addcheck eq 'ok') {
+                          push @sections,$ENV{"form.$secnum"}.":".$ENV{"form.$gp"};
+                          $seccount ++;
+                          $addcount ++;
+                      } else {
+                          push @badowner,$ENV{"form.$secnum"}.":".$ENV{"form.$gp"};
+                      }
+                  } else {
+                      push @badsections, \
$ENV{"form.$secnum"}.":".$ENV{"form.$gp"}.":".$coursecheck; +                  }
+              }
+          }
+      }
+      if (@currsections > 0) {
+          for (my $i=0; $i<@currsections; $i++) {
+              if ($currsections[$i] =~ m/^(\w+:)/ ) {
+                  my $oldsec  = $1;
+                  unless (grep/^$oldsec/,@sections) {
+                      $removecount ++;
+                  }
+              }
+          }
+      }
   } elsif (@currsections > 0) {
       for (my $i=0; $i<@currsections; $i++) {
           my $sec = "sec_".$i;
@@ -1407,6 +1407,24 @@
       }
   }
 
+  if (@badsections > 0) {
+      $response .= "The sections listed below could not be included in the sections \
for this LON-CAPA course, because they are not valid section numbers according to \
your institution's official schedule of classes and sections.<br/><ul>\n"; +      \
foreach (@badsections) { +          my ($secnum,$gp,$prob) = split/:/,$_;
+          $response .= "<li>$secnum - ID: $gp - Error: $prob</li>\n";
+      }
+      $response .= "</ul><br/><br/>\n";
+  }
+
+  if (@badowner > 0) {
+      $response .= "The sections listed below could not be included in the sections \
for this LON-CAPA course, because the owner of this course - $owner - does not have \
rights to view enrollment in those classes as determined by your instititution's \
policies on access to official classlists.<br/><ul>\n"; +      foreach (@badowner) {
+          my ($secnum,$gp) = split/:/,$_;
+          $response .= "<li>$secnum - ID: $gp</li>\n";
+      }
+      $response .= "</ul><br/><br/>\n";
+  }
+
   if ( exists($ENV{'form.numsec'}) ) {
       my $numsec = $ENV{'form.numsec'};
       if ($numsec > 0) {
@@ -1454,15 +1472,18 @@
 
 sub print_sections_response () {
   my ($r,$realm,$dom,$crs,$action,$tasktitleref) = @_;
-  my %settings = &Apache::lonnet::get('environment',['internal.sectionnums','internal.coursecode'],$dom,$crs);
 +  my %settings = &Apache::lonnet::get('environment',['internal.sectionnums','internal.coursecode','internal.courseowner'],$dom,$crs);
  my @currsections = ();
   my @sections = ();
   my @allsections = ();
+  my @badowner = ();
+  my @badsections = ();
   my $numsec = 0;
   my $secstr =  $settings{'internal.sectionnums'};
   my $coursecode = $settings{'internal.coursecode'};
+  my $owner = $settings{'internal.courseowner'};
   my $response = '';
-                                                                                     \
 +  my $putreply = '';
   if ($secstr =~ m/,/) {
       @allsections = split/,/,$secstr;
   } else {
@@ -1472,18 +1493,31 @@
   if ( exists($ENV{'form.numsec'}) ) {
       $numsec = $ENV{'form.numsec'};
   }
-                                                                                     \
 +
   if ($numsec > 0) {
       for (my $i=0; $i<$numsec; $i++) {
           my $sec = "newsec_".$i;
           my $gp = "newsecgp_".$i;
           if ( exists($ENV{"form.$sec"}) ) {
-              push @sections,$ENV{"form.$sec"}.":".$ENV{"form.$gp"};
+              unless ( (grep/^$ENV{"form.$sec"}:/,@allsections) || \
(grep/^$ENV{"form.$sec"}:/,@sections) ) { +                  my $newsec = \
$coursecode.$ENV{"form.$sec"}; +                  my $coursecheck = \
&localenroll::validate_courseID($newsec); +                  if ($coursecheck eq \
'ok') { +                      my $addcheck = \
&localenroll::new_course($newsec,$owner); +                      if ($addcheck eq \
'ok') { +                          push \
@sections,$ENV{"form.$sec"}.":".$ENV{"form.$gp"}; +                      } else {
+                          push @badowner,$ENV{"form.$sec"}.":".$ENV{"form.$gp"};
+                      }
+                  } else {
+                      push @badsections, \
$ENV{"form.$sec"}.":".$ENV{"form.$gp"}.":".$coursecheck; +                  }
+              }
           }
       }
       push @allsections, @sections;
   }
-                                                                                     \
 +
   if (@sections > 0 ) {
       unless ($secstr eq '') { $secstr .= ","; } 
       if (@sections > 1) {
@@ -1492,20 +1526,39 @@
           $secstr .= $sections[0];
       }
       my %cenv = ('internal.sectionnums' => $secstr);
-      my $reply = &Apache::lonnet::put('environment',\%cenv,$dom,$crs);
-      if ($reply !~ /^ok$/) {
-          $response = "There was a problem processing your requested changes. The \
                automated enrollment settings for this course have been left \
                unchanged.<br/>";
-      } else {
-          $response = "Students enrolling in the sections listed below will be \
automatically added to the class roster for LON-CAPA course $realm ($coursecode), if \
you have chosen to enable a nightly automated enrollment update.<br/><ul>\n"; +      \
$putreply = &Apache::lonnet::put('environment',\%cenv,$dom,$crs); +      if \
($putreply !~ /^ok$/) { +          $response = "There was a problem processing your \
requested changes. The automated enrollment settings for this course have been left \
unchanged.<br/><br/>";  }
   }
-                                                                                     \
                
-  foreach (@allsections) {
-      my ($sec,$gp) = split/:/,$_;
-      $response .= "<li>$sec - ID: $gp</li>\n";
+
+  if ($putreply =~ /^ok/) {
+      $response = "Students enrolling in the sections listed below will be \
automatically added to the class roster for LON-CAPA course $realm ($coursecode), if \
you have chosen to enable a nightly automated enrollment update.<br/><ul>\n"; +      \
foreach (@allsections) { +          my ($sec,$gp) = split/:/,$_;
+          $response .= "<li>$sec - ID: $gp</li>\n";
+      }
+      $response .= "</ul><br/><br/>\n";
   }
-  $response .= "</ul><br/>\n";
-                                                                                     \
 +
+  if (@badsections > 0) {
+      $response .= "The sections listed below could not be included in the sections \
for this LON-CAPA course, because they are not valid section numbers according to \
your institution's official schedule of classes and sections.<br/><ul>\n"; +      \
foreach (@badsections) { +          my ($secnum,$gp,$prob) = split/:/,$_;
+          $response .= "<li>$secnum - ID: $gp - Error: $prob</li>\n";
+      }
+      $response .= "</ul><br/><br/>\n";
+  }
+
+  if (@badowner > 0) {
+      $response .= "The sections listed below could not be included in the sections \
for this LON-CAPA course, because the owner of this course - $owner - does not have \
rights to view enrollment in those classes as determined by your instititution's \
policies on access to official classlists.<br/><ul>\n"; +      foreach (@badowner) {
+          my ($secnum,$gp) = split/:/,$_;
+          $response .= "<li>$secnum - ID: $gp</li>\n";
+      }
+      $response .= "</ul><br/><br/>\n";
+  }
+
   &print_reply($r,$response,$$tasktitleref{$action});
   return;
 }
@@ -1518,7 +1571,7 @@
   if ( exists($ENV{'form.showphotos'}) ) {
       $showphotos=$ENV{'form.showphotos'};
   }
-                                                                                     \
 +
   my $response = "";
   my %cenv = ('internal.showphotos' => $showphotos);
   my $reply = &Apache::lonnet::put('environment',\%cenv,$dom,$crs);



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

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