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

raeburn lon-capa-cvs@mail.lon-capa.org
Thu, 11 May 2006 20:09:49 -0000


This is a MIME encoded message

--raeburn1147378189
Content-Type: text/plain

raeburn		Thu May 11 16:09:49 2006 EDT

  Modified files:              
    /loncom/interface	londropadd.pm 
  Log:
  Include display of active groups in classlist as a column which can be used as a sort key.  Replace reference to Section/Group with Section.  Include protection against section naming with reserved words 'none' or 'all' and also with the name of a course group. 
  
  
--raeburn1147378189
Content-Type: text/plain
Content-Disposition: attachment; filename="raeburn-20060511160949.txt"

Index: loncom/interface/londropadd.pm
diff -u loncom/interface/londropadd.pm:1.141 loncom/interface/londropadd.pm:1.142
--- loncom/interface/londropadd.pm:1.141	Mon May  1 15:37:33 2006
+++ loncom/interface/londropadd.pm	Thu May 11 16:09:47 2006
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Handler to drop and add students in courses 
 #
-# $Id: londropadd.pm,v 1.141 2006/05/01 19:37:33 albertel Exp $
+# $Id: londropadd.pm,v 1.142 2006/05/11 20:09:47 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -307,7 +307,7 @@
          ipass    => 'You need to specify the initial password.',
          name     => 'The optional name field was not specified.',
          snum     => 'The optional student number field was not specified.',
-         section  => 'The optional section or group field was not specified.', 
+         section  => 'The optional section field was not specified.', 
          email    => 'The optional email address field was not specified.',
          continue => 'Continue enrollment?',
          );
@@ -393,6 +393,7 @@
     }
 END
     }
+    my $section_checks;
     my $optional_checks = '';
     if ( ($mode eq 'createcourse') || ($mode eq 'modifycourse') ) {
         $optional_checks = (<<END);
@@ -400,6 +401,7 @@
 }
 END
     } else {
+        $section_checks = &section_check_js();
         $optional_checks = (<<END);
     var message='';
     if (foundname==0) { 
@@ -440,7 +442,7 @@
     if ( ($mode eq 'auth') || ($mode eq 'createcourse') || ($mode eq 'modifycourse')  ) {
         $result .= $auth_checks;
     }
-    $result .= $optional_checks;
+    $result .= $optional_checks."\n".$section_checks;
     if ( ($mode eq 'auth') || ($mode eq 'createcourse') || ($mode eq 'modifycourse')  ) {
         $result .= $authheader;
     }
@@ -451,7 +453,7 @@
 ###############################################################
 sub upload_manager_javascript_forward_associate {
     return(<<ENDPICK);
-function verify(vf) {
+function verify(vf,sec_caller) {
     var founduname=0;
     var foundpwd=0;
     var foundname=0;
@@ -544,7 +546,7 @@
 ###############################################################
 sub upload_manager_javascript_reverse_associate {
     return(<<ENDPICK);
-function verify(vf) {
+function verify(vf,sec_caller) {
     var founduname=0;
     var foundpwd=0;
     var foundname=0;
@@ -640,7 +642,8 @@
     $Str .= &mt('Disable ID/Student Number Safeguard and Force Change '.
                 'of Conflicting IDs (only do if you know what you are doing)').
                 "</label>\n</p><p>\n";
-    $Str .= '<input type="button" onClick="javascript:verify(this.form)" '.
+    $Str .= '<input type="button"'. 
+              'onClick="javascript:verify(this.form,this.form.csec)" '.
         'value="Update Class List" />'."<br />\n";
     $Str .= &mt('Note: for large courses, this operation may be time '.
                 'consuming');
@@ -701,7 +704,7 @@
              ['lname',&mt('Last Name'),       $env{'form.lname_choice'}],
              ['gen',  &mt('Generation'),      $env{'form.gen_choice'}],
              ['id',   &mt('ID/Student Number'),$env{'form.id_choice'}],
-             ['sec',  &mt('Group/Section'),   $env{'form.sec_choice'}],
+             ['sec',  &mt('Section'),          $env{'form.sec_choice'}],
              ['ipwd', &mt('Initial Password'),$env{'form.ipwd_choice'}],
              ['email',&mt('EMail Address'),   $env{'form.email_choice'}]);
 	if ($env{'form.upfile_associate'} eq 'reverse') {	
@@ -1074,7 +1077,7 @@
         # Print it all out
     my %lt=&Apache::lonlocal::texthash(
 		   'cd'   => "Course Data",
-                   'gs'   => "Group/Section",
+                   'gs'   => "Section",
                    'idsn' => "ID/Student Number",
                    'disn' => "Disable ID/Student Number Safeguard and Force Change of Conflicting IDs (only do if you know what you are doing)",
                    'eas'  => "Enroll as student",
@@ -1085,7 +1088,7 @@
 <input type="hidden" name="cuname" value="$username" />
 <input type="hidden" name="lcdomain" value="$domain" />
 <script type="text/javascript" language="Javascript">
-function verify(vf) {
+function verify(vf,sec_caller) {
     var founduname=0;
     var foundpwd=0;
     var foundname=0;
@@ -1102,6 +1105,9 @@
     }
     if ((typeof(vf.csec.value)!="undefined") && (vf.csec.value!='')) {
         foundsec=1;
+        if (validate(sec_caller) == "error") {
+            return;
+        }
     }
     if ((typeof(vf.cstid.value)!="undefined") && (vf.cstid.value!='')) {
 	foundid=1;
@@ -1138,7 +1144,7 @@
 $lt{'disn'}
 </label>
 </p><p>
-<input type="button" onClick="verify(this.form)" value="$lt{'eas'}">
+<input type="button" onClick="verify(this.form,this.form.csec)" value="$lt{'eas'}">
 </p>
 END
     return;
@@ -1243,6 +1249,10 @@
 sub show_class_list {
     my ($r,$mode,$linkto,$statusmode,$classlist,$keylist)=@_;
     my $cid=$env{'request.course.id'};
+    my $cdom = $env{'course.'.$cid.'.domain'};
+    my $cnum = $env{'course.'.$cid.'.num'};
+    my ($classgroups) = &Apache::loncoursedata::get_group_memberships(
+                                              $classlist,$keylist,$cdom,$cnum);
     #
     # Variables for excel output
     my ($excel_workbook, $excel_sheet, $excel_filename,$row,$format);
@@ -1251,7 +1261,7 @@
     my ($CSVfile,$CSVfilename);
     #
     my $sortby = $env{'form.sortby'};
-    if ($sortby !~ /^(username|domain|section|fullname|id|start|end|type)$/) {
+    if ($sortby !~ /^(username|domain|section|groups|fullname|id|start|end|type)$/) {
         $sortby = 'username';
     }
     if (! exists($env{'form.displayphotos'})) {
@@ -1271,15 +1281,16 @@
 END
     if ($mode eq 'html' || $mode eq 'view' || $mode eq 'autoenroll') {
         if ($linkto eq 'aboutme') {
-            $r->print(&mt('Select a user name to view the users personal page.'));
+            $r->print(&mt("Select a user name to view the user's personal page."));
         } elsif ($linkto eq 'modify') {
-            $r->print(&mt('Select a user name to modify the students information'));
+            $r->print(&mt("Select a user name to modify the student's information"));
         }
 	my %lt=&Apache::lonlocal::texthash(
                                            'usrn'   => "username",
                                            'dom'    => "domain",
                                            'sn'     => "student name",
                                            'sec'    => "section",
+                                           'grp'    => "active groups",
                                            'start'  => "start date",
                                            'end'    => "end date",
                                            'type'   => "enroll type/action",
@@ -1333,6 +1344,8 @@
        <a href="javascript:document.studentform.sortby.value='start';document.studentform.submit();">$lt{'start'}</a>
     </th><th>
        <a href="javascript:document.studentform.sortby.value='end';document.studentform.submit();">$lt{'end'}</a>
+    </th><th>
+       <a href="javascript:document.studentform.sortby.value='groups';document.studentform.submit();">$lt{'grp'}</a>
     </th>
 END
         if ($env{'course.'.$env{'request.course.id'}.'.internal.showphoto'}) {
@@ -1373,12 +1386,13 @@
             print $CSVfile '"'.join('","',map {
 		&Apache::loncommon::csv_translate(&mt($_))
                 } ("username","domain","ID","student name",
-                   "section","start date","end date","status")).'"'."\n";
+                   "section","start date","end date","status","active groups"))
+                  .'"'."\n";
         } else {
             print $CSVfile '"'.join('","',map {
 		&Apache::loncommon::csv_translate(&mt($_))
                 } ("username","domain","ID","student name",
-                   "section","start date","end date")).'"'."\n";
+                   "section","start date","end date","active groups")).'"'."\n";
         }
     } elsif ($mode eq 'excel') {
         # Create the excel spreadsheet
@@ -1393,7 +1407,8 @@
         #
         $excel_sheet->write($row++,0,["username","domain","ID",
                                       "student name","section",
-                                      "start date","end date","status"],
+                                      "start date","end date","status",
+                                      "active groups"],
                             $format->{'bold'});
     }
     #
@@ -1403,6 +1418,7 @@
     foreach (@$keylist) {
         $index{$_} = $i++;
     }
+    $index{'groups'} = scalar(@{$keylist});
     my $index  = $index{$sortby};
     my $second = $index{'username'};
     my $third  = $index{'domain'};
@@ -1420,9 +1436,14 @@
     my $lockcount = 0;
     foreach my $student (@Sorted_Students) {
         my $sdata = $classlist->{$student};
+        my $groups = $classgroups->{$student};
         my $username = $sdata->[$index{'username'}];
         my $domain   = $sdata->[$index{'domain'}];
         my $section  = $sdata->[$index{'section'}];
+        my $active_groups;
+        if (ref($groups->{active}) eq 'HASH') {
+            $active_groups = join(', ',keys(%{$groups->{'active'}}));
+        }
         my $name     = $sdata->[$index{'fullname'}];
         my $id       = $sdata->[$index{'id'}];
         my $status   = $sdata->[$index{'status'}];
@@ -1488,6 +1509,7 @@
     <td>$section</td>
     <td>$start</td>
     <td>$end</td>
+    <td>$active_groups</td>
 END
             if ($env{'course.'.$env{'request.course.id'}.
 			 '.internal.showphoto'}) {
@@ -1523,6 +1545,7 @@
             if ($statusmode eq 'Any') {
                 push @line,&Apache::loncommon::csv_translate($status);
             }
+            push @line,&Apache::loncommon::csv_translate($active_groups);
             print $CSVfile '"'.join('","',@line).'"'."\n";
         } elsif ($mode eq 'excel') {
             $excel_sheet->write($row,0,[$username,$domain,$id,
@@ -1538,6 +1561,7 @@
                 }                    
             }
             $excel_sheet->write($row,$col++,$status);
+            $excel_sheet->write($row,$col++,$active_groups);
             $row++;
         }
     }
@@ -1634,7 +1658,19 @@
                    'sec'   => "Section",
                    'sm'    => "Submit Modifications",
 				       );
-    $r->print(<<END);
+# Check if section name is valid
+    my $section_check = &section_check_js();
+    $r->print(<<"END");
+<script type="text/javascript">
+$section_check
+function secverify(formname,caller) {
+    if (validate(caller) == "error") {
+        return;
+    } else {
+        formname.submit();
+    }
+}
+</script>
 <p>
 <font size="+1">
 $lt{'odcc'}
@@ -1670,7 +1706,7 @@
 </p>
 <p>$current_date_description</p>
 <p>$date_table</p>
-<input type="submit" value="$lt{'sm'}" />
+<input type="button" value="$lt{'sm'}" onClick="secverify(this.form,this.form.section)" />
 END
     $r->print(&Apache::loncommon::end_page());
     return;
@@ -1894,9 +1930,13 @@
                                                 ['sortby']);
     }
     my $sortby = $env{'form.sortby'};
-    if ($sortby !~ /^(username|domain|section|fullname|id|start|end)$/) {
+    if ($sortby !~ /^(username|domain|section|groups|fullname|id|start|end)$/) {
         $sortby = 'username';
     }
+    my $cdom = $env{'course.'.$cid.'.domain'};
+    my $cnum = $env{'course.'.$cid,'.num'};
+    my ($classgroups) = &Apache::loncoursedata::get_group_memberships(
+                                                      $classlist,$cdom,$cnum);
     #
     my $action = "drop";
     $r->print(<<END);
@@ -1924,6 +1964,7 @@
                                    'sec'    => "section",
                                    'start'  => "start date",
                                    'end'    => "end date",
+                                   'groups' => "active groups",
                                    );
     if ($nosort) {
 	$r->print(&Apache::loncommon::start_data_table());
@@ -1937,6 +1978,7 @@
     <th>$lt{'sec'}</th>
     <th>$lt{'start'}</th>
     <th>$lt{'end'}</th>
+    <th>$lt{'groups'}</th>
 </tr>
 END
 
@@ -1958,6 +2000,8 @@
        <a href="/adm/dropadd?action=$action&sortby=start">$lt{'start'}</a>
     </th><th>
        <a href="/adm/dropadd?action=$action&sortby=end">$lt{'end'}</a>
+    </th><th>
+       <a href="/adm/dropadd?action=$action&sortby=groups">$lt{'groups'}</a>
     </th>
 </tr>
 END
@@ -1969,6 +2013,7 @@
     foreach (@$keylist) {
         $index{$_} = $i++;
     }
+    $index{'groups'} = scalar(@$keylist);
     my $index  = $index{$sortby};
     my $second = $index{'username'};
     my $third  = $index{'domain'};
@@ -1989,6 +2034,11 @@
         my $id       = $sdata->[$index{'id'}];
         my $start    = $sdata->[$index{'start'}];
         my $end      = $sdata->[$index{'end'}];
+        my $groups = $classgroups->{$student};
+        my $active_groups;
+        if (ref($groups->{active}) eq 'HASH') {
+            $active_groups = join(', ',keys(%{$groups->{'active'}}));
+        }
         if (! defined($start) || $start == 0) {
             $start = &mt('none');
         } else {
@@ -2012,6 +2062,7 @@
     <td>$section</td>
     <td>$start</td>
     <td>$end</td>
+    <td>$active_groups</td>
 END
         $r->print(&Apache::loncommon::end_data_table_row());
     }
@@ -2146,6 +2197,8 @@
         my $count=0;
         my $flushc=0;
         my %student=();
+        # Get information about course groups
+        my %curr_groups = &Apache::loncommon::coursegroups();
         # Get new classlist
         foreach (@studentdata) {
             my %entries=&Apache::loncommon::record_sep($_);
@@ -2186,6 +2239,17 @@
                     }
                     # remove non alphanumeric values from section
                     $sec =~ s/\W//g;
+                    if ($sec eq "none" || $sec eq 'all') {
+                        $r->print('<br />'.
+      &mt('<b>[_1]</b>: Unable to enroll: section name "[_2]" for user [_3] [_4] [_5] [_6] is a reserved word.',
+                        $username,$sec,$fname,$mname,$lname,$gen));
+                        next;
+                    } elsif (($sec ne '') && (exists($curr_groups{$sec}))) {
+                        $r->print('<br />'.
+      &mt('<b>[_1]</b>: Unable to enroll: section name "[_2]" for user [_3] [_4] [_5] [_6] is a course group. Section names and group names must be distinct.',
+                        $username,$sec,$fname,$mname,$lname,$gen));
+                        next;
+                    }
                     # determine student id number
                     my $id='';
                     if (defined($fields{'id'})) {
@@ -2301,6 +2365,33 @@
     $r->print('<p>'.&mt('Re-enrollment will re-activate data.')) if ($count);
 }
 
+sub section_check_js {
+    my $groupslist;
+    my %curr_groups = &Apache::loncommon::coursegroups();
+    if (%curr_groups) {
+        $groupslist = join('","',sort(keys(%curr_groups)));
+    }
+    return <<"END";
+function validate(caller) {
+    var groups = new Array("$groupslist");
+    var secname = caller.value;
+    if ((secname == 'all') || (secname == 'none')) {
+        alert("'"+secname+"' may not be used as the name for a section, as it is a reserved word.\\nPlease choose a different section name.");
+        return 'error';
+    }
+    if (secname != '') {
+        for (var k=0; k<groups.length; k++) {
+            if (secname == groups[k]) {
+                alert("'"+secname+"' may not be used as the name for a section, as it is the name of a course group.\\nSection names and group names must be distinct. Please choose a different section name.");
+                return 'error';
+            }
+        }
+    }
+    return 'ok';
+}
+END
+}
+
 ###################################################################
 ###################################################################
 

--raeburn1147378189--