[LON-CAPA-cvs] cvs: loncom /interface courseclassifier.pm loncommon.pm lonhtmlcommon.pm lonnotify.pm lonsupportreq.pm lonuserutils.pm

raeburn raeburn@source.lon-capa.org
Fri, 09 Jul 2010 14:40:21 -0000


This is a MIME encoded message

--raeburn1278686421
Content-Type: text/plain

raeburn		Fri Jul  9 14:40:21 2010 EDT

  Modified files:              
    /loncom/interface	courseclassifier.pm loncommon.pm lonhtmlcommon.pm 
                     	lonnotify.pm lonsupportreq.pm lonuserutils.pm 
  Log:
  - Bug 6333.
    Ensure that form element names for select boxes for institutional codes
    are always named Year, Semester, Department, Number, for consistency with
    names used in javascript to update select box items dynamically.
  
  - Bug 5848.
    Assembly of institutional code from components conforms to order defined in
    localenroll::instcode_defaults(). 
  
  
--raeburn1278686421
Content-Type: text/plain
Content-Disposition: attachment; filename="raeburn-20100709144021.txt"

Index: loncom/interface/courseclassifier.pm
diff -u loncom/interface/courseclassifier.pm:1.9 loncom/interface/courseclassifier.pm:1.10
--- loncom/interface/courseclassifier.pm:1.9	Thu Jul  8 23:19:19 2010
+++ loncom/interface/courseclassifier.pm	Fri Jul  9 14:40:20 2010
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Utilities for classifying courses based on institutional code
 #
-# $Id: courseclassifier.pm,v 1.9 2010/07/08 23:19:19 raeburn Exp $
+# $Id: courseclassifier.pm,v 1.10 2010/07/09 14:40:20 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -30,6 +30,7 @@
 use strict;
 use lib '/home/httpd/lib/perl/';
 use Apache::lonnet;
+use Apache::loncommon;
 use Apache::lonlocal;
 use LONCAPA;
 
@@ -258,12 +259,16 @@
 sub javascript_code_selections {
     my ($formname,@codetitles) = @_;
     my $numtitles = @codetitles;
+    my %lt = &Apache::lonlocal::texthash(
+                      Select => 'Select',
+                      Pick   => 'Pick',
+             );
     my $output = (<<END_OF_BLOCK);
  var display = new Array($numtitles)
  if (caller == "" || caller == "$codetitles[0]") {
      if (caller == "") {
          document.$formname.Year.length = 0
-         document.$formname.Year.options[0] = new Option("Select","-1",true,true)
+         document.$formname.Year.options[0] = new Option("$lt{'Select'}","-1",true,true)
          display[0] = new Array(idyears.length)
          for (var i=0; i<idyears.length; i++) {
              display[0][i] = idyears[i]
@@ -284,13 +289,13 @@
      document.$formname.Semester.length = 0
      document.$formname.Department.length = 0;
      document.$formname.Number.length = 0
-     document.$formname.Department.options[0] = new Option("<-Pick $codetitles[1]","-1",true,true)
-     document.$formname.Number.options[0] = new Option("<-Pick $codetitles[2]","-1",true,true)
+     document.$formname.Department.options[0] = new Option("<-$lt{'Pick'} $codetitles[1]","-1",true,true)
+     document.$formname.Number.options[0] = new Option("<-$lt{'Pick'} $codetitles[2]","-1",true,true)
      if (idyr == 0 || caller == "") {
-         document.$formname.Semester.options[0] = new Option("<-Pick $codetitles[0]","-1",true,true)
+         document.$formname.Semester.options[0] = new Option("<-$lt{'Pick'} $codetitles[0]","-1",true,true)
      }
      else {
-         document.$formname.Semester.options[0] = new Option("Select","-1",true,true)
+         document.$formname.Semester.options[0] = new Option("$lt{'Select'}","-1",true,true)
          display[1] = new Array(idsems[idyr-1].length)
          for (var i=0; i<idsems[idyr-1].length; i++) {
              display[1][i] = idsems[idyr-1][i]
@@ -309,10 +314,10 @@
    document.$formname.Number.length = 0
    document.$formname.Number.options[0] = new Option("<-Pick $codetitles[2]","-1",true,true)
    if (idsem == 0) {
-     document.$formname.Department.options[0] = new Option("<-Pick $codetitles[1]","-1",true,true)
+     document.$formname.Department.options[0] = new Option("<-$lt{'Pick'} $codetitles[1]","-1",true,true)
    }
    else {
-    document.$formname.Department.options[0] = new Option("Select","-1",true,true)
+    document.$formname.Department.options[0] = new Option("$lt{'Select'}","-1",true,true)
     display[2] = new Array(idcodes[idyr-1][idsem-1].length)
     for (var i=0; i<idcodes[idyr-1][idsem-1].length; i++) {
       display[2][i] = idcodes[idyr-1][idsem-1][i]
@@ -329,7 +334,7 @@
  if (caller == "$codetitles[2]") {
    document.$formname.Number.length = 0
    if (iddept == 0) {
-     document.$formname.Number.options[0] = new Option("<-Pick $codetitles[2]","-1",true,true)
+     document.$formname.Number.options[0] = new Option("<-$lt{'Pick'} $codetitles[2]","-1",true,true)
    }
    else {
     document.$formname.Number.options[0] = new Option("Select","-1",true,true)
@@ -545,7 +550,7 @@
 sub build_instcode_selectors {
     my ($numtitles,$lasttitle,$cat_items,$codetitles,$cat_titles,$cat_order) = @_;
     my $output;
-    my @standardnames = &get_standard_codeitems();
+    my @standardnames = &Apache::loncommon::get_standard_codeitems();
     if ($numtitles > 0) {
         $output .= '<table><tr>';
         for (my $k=0; $k<$lasttitle-1; $k++) {
@@ -821,7 +826,7 @@
         my $defaults_result =
             &Apache::lonnet::auto_instcode_defaults($domain,\%codedefaults,
                                                     \@code_order);
-        my @standardnames = &get_standard_codeitems();
+        my @standardnames = &Apache::loncommon::get_standard_codeitems();
         my %local_to_standard;
         if (ref($codetitles) eq 'ARRAY') {
             for (my $i=0; $i<@{$codetitles}; $i++) {
@@ -850,8 +855,38 @@
     return $instcode;
 }
 
-sub get_standard_codeitems {
-    return ('Year','Semester','Department','Number');
+sub instcode_from_selectors {
+    my ($cdom) = @_;
+    my $instcode;
+    my $caller = 'global';
+    my (%coursecodes,%codes,@codetitles,%cat_titles,%cat_order,
+        %codedefaults,@code_order);
+    my $format_reply =
+        &Apache::lonnet::auto_instcode_format($caller,$cdom,\%coursecodes,
+                            \%codes,\@codetitles,\%cat_titles,\%cat_order);
+    my $defaults_result =
+        &Apache::lonnet::auto_instcode_defaults($cdom,\%codedefaults,
+                                                \@code_order);
+    if (($defaults_result eq 'ok') && ($format_reply eq 'ok')) {
+        my @standardnames = &Apache::loncommon::get_standard_codeitems();
+        my %local_to_standard;
+        for (my $i=0; $i<@codetitles; $i++) {
+            $local_to_standard{$codetitles[$i]} = $standardnames[$i];
+        }
+        foreach my $loctitle (@code_order) {
+            my $category = $local_to_standard{$loctitle};
+            if ($category ne '') {
+                if ($env{'form.'.$category} eq '-1' ) {
+                    $instcode .= $codedefaults{$category};
+                } else {
+                    $instcode .= $env{'form.'.$category};
+                }
+            } else {
+                $instcode .= '.+';
+            }
+        }
+    }
+    return $instcode;
 }
 
 1;
Index: loncom/interface/loncommon.pm
diff -u loncom/interface/loncommon.pm:1.970 loncom/interface/loncommon.pm:1.971
--- loncom/interface/loncommon.pm:1.970	Sun Jun  6 02:40:30 2010
+++ loncom/interface/loncommon.pm	Fri Jul  9 14:40:20 2010
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # a pile of common routines
 #
-# $Id: loncommon.pm,v 1.970 2010/06/06 02:40:30 raeburn Exp $
+# $Id: loncommon.pm,v 1.971 2010/07/09 14:40:20 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -8065,6 +8065,10 @@
     return;
 }
 
+sub get_standard_codeitems {
+    return ('Year','Semester','Department','Number','Section');
+}
+
 =pod
 
 =head1 Slot Helpers
Index: loncom/interface/lonhtmlcommon.pm
diff -u loncom/interface/lonhtmlcommon.pm:1.279 loncom/interface/lonhtmlcommon.pm:1.280
--- loncom/interface/lonhtmlcommon.pm:1.279	Fri Jun 18 09:06:29 2010
+++ loncom/interface/lonhtmlcommon.pm	Fri Jul  9 14:40:20 2010
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # a pile of common html routines
 #
-# $Id: lonhtmlcommon.pm,v 1.279 2010/06/18 09:06:29 bisitz Exp $
+# $Id: lonhtmlcommon.pm,v 1.280 2010/07/09 14:40:20 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -1809,15 +1809,15 @@
 
 sub course_select_row {
     my ($title,$formname,$totcodes,$codetitles,$idlist,$idlist_titles,
-	$css_class,$crstype) = @_;
+	$css_class,$crstype,$standardnames) = @_;
     my $output = &row_title($title,$css_class);
-    $output .= &course_selection($formname,$totcodes,$codetitles,$idlist,$idlist_titles,$crstype);
+    $output .= &course_selection($formname,$totcodes,$codetitles,$idlist,$idlist_titles,$crstype,$standardnames);
     $output .= &row_closure();
     return $output;
 }
 
 sub course_selection {
-    my ($formname,$totcodes,$codetitles,$idlist,$idlist_titles,$crstype) = @_;
+    my ($formname,$totcodes,$codetitles,$idlist,$idlist_titles,$crstype,$standardnames) = @_;
     my $output = qq|
 <script type="text/javascript">
 // <![CDATA[
@@ -1864,7 +1864,7 @@
         if ($numtitles > 0) {
             $output .= '<input type="radio" name="coursepick" value="category" onclick="coursePick(this.form);alert('."'".&mt('Choose categories, from left to right')."'".')" />'.&mt('Pick courses by category:').' <br />';
             $output .= '<table><tr><td>'.$$codetitles[0].'<br />'."\n".
-               '<select name="'.$$codetitles[0].
+               '<select name="'.$standardnames->[0].
                '" onChange="setPick(this.form);courseSet('."'$$codetitles[0]'".')">'."\n".
                ' <option value="-1" />Select'."\n";
             my @items = ();
@@ -1894,7 +1894,7 @@
             $output .= '</select></td>';
             for (my $i=1; $i<$numtitles; $i++) {
                 $output .= '<td>'.$$codetitles[$i].'<br />'."\n".
-                          '<select name="'.$$codetitles[$i].
+                          '<select name="'.$standardnames->[$i].
                           '" onChange="courseSet('."'$$codetitles[$i]'".')">'."\n".
                           '<option value="-1">&lt;-Pick '.$$codetitles[$i-1].'</option>'."\n".
                           '</select>'."\n".
Index: loncom/interface/lonnotify.pm
diff -u loncom/interface/lonnotify.pm:1.36 loncom/interface/lonnotify.pm:1.37
--- loncom/interface/lonnotify.pm:1.36	Fri May 14 18:29:52 2010
+++ loncom/interface/lonnotify.pm	Fri Jul  9 14:40:20 2010
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Sending messages
 #
-# $Id: lonnotify.pm,v 1.36 2010/05/14 18:29:52 bisitz Exp $
+# $Id: lonnotify.pm,v 1.37 2010/07/09 14:40:20 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -413,6 +413,7 @@
             $jscript .= &Apache::courseclassifier::javascript_code_selections($formname,@codetitles);
         }
     }
+    my @standardnames = &Apache::loncommon::get_standard_codeitems();
 
     my $cb_jscript = &Apache::loncommon::coursebrowser_javascript($cdom);
 
@@ -436,7 +437,7 @@
     if (formname.Year.options[formname.Year.selectedIndex].value == -1) {
         return;
     }
-    courseSet('Year');
+    courseSet('$codetitles[0]');
     for (var j=0; j<formname.Semester.length; j++) {
         if (formname.Semester.options[j].value == "$env{'form.Semester'}") {
             formname.Semester.options[j].selected = true;
@@ -445,7 +446,7 @@
     if (formname.Semester.options[formname.Semester.selectedIndex].value == -1) {
         return;
     }
-    courseSet('Semester');
+    courseSet('$codetitles[1]');
     for (var j=0; j<formname.Department.length; j++) {
         if (formname.Department.options[j].value == "$env{'form.Department'}") {
             formname.Department.options[j].selected = true;
@@ -454,7 +455,7 @@
     if (formname.Department.options[formname.Department.selectedIndex].value == -1) {
         return;
     }
-    courseSet('Department');
+    courseSet('$codetitles[2]');
     for (var j=0; j<formname.Number.length; j++) {
         if (formname.Number.options[j].value == "$env{'form.Number'}") {
             formname.Number.options[j].selected = true;
@@ -481,7 +482,7 @@
     my $submit_text = $lt{'comp'};
     my $cmd = 'compose';
     $output .= &Apache::lonhtmlcommon::role_select_row(\@roles,&mt('Roles'));
-    $output .= &Apache::lonhtmlcommon::course_select_row(&mt('Courses'),$formname,$totcodes,\@codetitles,\%idlist,\%idlist_titles);
+    $output .= &Apache::lonhtmlcommon::course_select_row(&mt('Courses'),$formname,$totcodes,\@codetitles,\%idlist,\%idlist_titles,undef,undef,\@standardnames);
     $output .= &Apache::lonhtmlcommon::status_select_row(\%longtypes,&mt('Access status'));
     $output .= &Apache::lonhtmlcommon::email_default_row(\%authtypes,&mt('Username -> E-mail conversion'),$descrip);
     $output .= &Apache::lonhtmlcommon::submit_row(&mt('Submit'),$cmd,$submit_text);
@@ -526,20 +527,15 @@
         %courses = &Apache::lonnet::courseiddump($cdom,'.','.','.','.','.',
                                                  undef,undef,'Course');
     } elsif ($coursefilter eq 'category') {
-        my $instcode = '';
-        my @cats = ('Semester','Year','Department','Number');
-        foreach my $category (@cats) {
-            if (defined($env{'form.'.$category})) {
-                unless ($env{'form.'.$category} eq '-1') {
-                    $instcode .= $env{'form.'.$category};
-                }
-            }
-        }
+        my $instcode = &Apache::courseclassifier::instcode_from_selectors($cdom);
+        my $regexp = '';
         if ($instcode eq '') {
             $instcode = '.';
+        } else {
+            $regexp = 1;
         }
         %courses = &Apache::lonnet::courseiddump($cdom,'.','.',$instcode,'.','.',
-                                                 undef,undef,'Course');
+                                                 undef,undef,'Course',$regexp);
     } elsif ($coursefilter eq 'specific') {
         if ($env{'form.coursetotal'} > 1) {
             my @course_ids = split(/&&/,$env{'form.courselist'});
Index: loncom/interface/lonsupportreq.pm
diff -u loncom/interface/lonsupportreq.pm:1.56 loncom/interface/lonsupportreq.pm:1.57
--- loncom/interface/lonsupportreq.pm:1.56	Wed Apr 14 03:09:35 2010
+++ loncom/interface/lonsupportreq.pm	Fri Jul  9 14:40:20 2010
@@ -1,5 +1,5 @@
 #
-# $Id: lonsupportreq.pm,v 1.56 2010/04/14 03:09:35 raeburn Exp $
+# $Id: lonsupportreq.pm,v 1.57 2010/07/09 14:40:20 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -338,12 +338,13 @@
                 $output .= $lt{'enin'}.':&nbsp;
                   <input type="text" name="coursecode" size="15" value="" />';
             } else {
+                my @standardnames = &Apache::loncommon::get_standard_codeitems();
                 my $lasttitle = $numtitles;
                 if ($numtitles > 4) {
                     $lasttitle = 4;
                 } 
                 $output .= '<table><tr><td>'.$codetitles[0].'<br />'."\n".
-                      '<select name="'.$codetitles[0].'" onchange="courseSet('."'$codetitles[0]'".')">'."\n".
+                      '<select name="'.$standardnames[0].'" onchange="courseSet('."'$codetitles[0]'".')">'."\n".
                       ' <option value="-1" />'.$lt{'sele'}."\n";
                 my @items = ();
                 my @longitems = ();
@@ -372,7 +373,7 @@
                 $output .= '</select></td>';
                 for (my $i=1; $i<$numtitles; $i++) {
                     $output .= '<td>'.$codetitles[$i].'<br />'."\n".
-                     '<select name="'.$codetitles[$i].'" onchange="courseSet('."'$codetitles[$i]'".')">'."\n".
+                     '<select name="'.$standardnames[$i].'" onchange="courseSet('."'$codetitles[$i]'".')">'."\n".
                      '<option value="-1">&lt;-'.$lt{'pick'}.' '.$codetitles[$i-1].'</option>'."\n".
                      '</select>'."\n".
                      '</td>'."\n";
@@ -380,7 +381,7 @@
                 $output .= '</tr></table>';
                 if ($numtitles > 4) {
                     $output .= '<br /><br />'.$codetitles[$numtitles].'<br />'."\n".
-                          '<select name="'.$codetitles[$numtitles].'" onchange="courseSet('."'$codetitles[$numtitles]'".')">'."\n".
+                          '<select name="'.$standardnames[$numtitles].'" onchange="courseSet('."'$codetitles[$numtitles]'".')">'."\n".
                           '<option value="-1">&lt;-'.$lt{'pick'}.' '.$codetitles[$numtitles-1].'</option>'."\n".
                           '</select>'."\n";
                 }
@@ -509,17 +510,20 @@
     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},\@formvars);
     my $coursecode = $env{'form.coursecode'};
     if ($coursecode eq '') {
-        if (defined($env{'form.Year'})) {
-            $coursecode .= $env{'form.Year'};
-        }
-        if (defined($env{'form.Semester'})) {
-            $coursecode .= $env{'form.Semester'};
-        }
-        if (defined($env{'form.Department'})) {
-            $coursecode .= $env{'form.Department'};
-        }
-        if (defined($env{'form.Number'})) {
-            $coursecode .= $env{'form.Number'};
+        my $totcodes = 0;
+        my %coursecodes;
+        $totcodes = &Apache::courseclassifier::retrieve_instcodes(\%coursecodes,$defdom,$totcodes);
+        my $coursecode;
+        my @standardnames = &Apache::loncommon::get_standard_codeitems();
+        if ($totcodes > 0) {
+            $coursecode = &Apache::courseclassifier::instcode_from_selectors($defdom); 
+        } 
+        if ($coursecode eq '') {
+            foreach my $item (@standardnames) {
+                if ((defined($env{'form.'.$item})) && ($env{'form.'.$item} ne '-1')) {
+                    $coursecode .= $env{'form.'.$item};
+                }
+            }
         }
     }
     my %lt = &Apache::lonlocal::texthash (
@@ -559,7 +563,7 @@
                 if (!(grep(/^\Q$cc\E$/,@ok_ccs))) {
                     push(@ok_ccs,$cc);
                 }
-            } else {
+            } elsif ($cc ne '') {
                 if (!(grep(/^\Q$cc\E$/,@bad_ccs))) {
                     push(@bad_ccs,$cc);
                 }
@@ -576,14 +580,14 @@
         }
     }
     $env{'form.user'} = "'".$env{'form.uname'}.':'.$env{'form.udom'}."'";
-    $env{'form.csri'} = $env{'form.title'}.' - '.$coursecode.' - '.$lt{'sect'}.': '.$env{'form.section'};
+    $env{'form.crsi'} = $env{'form.title'}.' - '.$coursecode.' - '.$lt{'sect'}.': '.$env{'form.section'};
     my $supportmsg = <<END;
 $lt{'username'}: $env{'form.username'}
 $lt{'email'}: $env{'form.email'}
 $lt{'cc'}: $okcclist
 $lt{'user'}: $env{'form.user'}
 $lt{'phone'}: $env{'form.phone'}
-$lt{'crsi'}: $env{'form.csri'}
+$lt{'crsi'}: $env{'form.crsi'}
 $lt{'subject'}: $env{'form.subject'}
 $lt{'description'}: $env{'form.description'}
 $lt{'sourceurl'}: $env{'form.sourceurl'}
Index: loncom/interface/lonuserutils.pm
diff -u loncom/interface/lonuserutils.pm:1.119 loncom/interface/lonuserutils.pm:1.120
--- loncom/interface/lonuserutils.pm:1.119	Sat May 22 01:11:53 2010
+++ loncom/interface/lonuserutils.pm	Fri Jul  9 14:40:20 2010
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Utility functions for managing LON-CAPA user accounts
 #
-# $Id: lonuserutils.pm,v 1.119 2010/05/22 01:11:53 raeburn Exp $
+# $Id: lonuserutils.pm,v 1.120 2010/07/09 14:40:20 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -1472,9 +1472,11 @@
             $title = &mt('Select Communities');
             $warning = &mt('Warning: data retrieval for multiple communities can take considerable time, as this operation is not currently optimized.');
         }
+        my @standardnames = &Apache::loncommon::get_standard_codeitems();
         my $courseform =
             &Apache::lonhtmlcommon::course_selection($formname,$numcodes,
-                            $codetitles,$idlist,$idlist_titles,$crstype);
+                            $codetitles,$idlist,$idlist_titles,$crstype,
+                            \@standardnames);
         $r->print('<p>'.&Apache::lonhtmlcommon::start_pick_box()."\n".
                   &Apache::lonhtmlcommon::start_pick_box()."\n".
                   &Apache::lonhtmlcommon::row_title($title,'LC_oddrow_value')."\n".
@@ -1923,7 +1925,7 @@
     if (formname.Year.options[formname.Year.selectedIndex].value == -1) {
         return;
     }
-    courseSet('Year');
+    courseSet('$codetitles[0]');
     for (var j=0; j<formname.Semester.length; j++) {
         if (formname.Semester.options[j].value == "$env{'form.Semester'}") {
             formname.Semester.options[j].selected = true;
@@ -1932,7 +1934,7 @@
     if (formname.Semester.options[formname.Semester.selectedIndex].value == -1) {
         return;
     }
-    courseSet('Semester');
+    courseSet('$codetitles[1]');
     for (var j=0; j<formname.Department.length; j++) {
         if (formname.Department.options[j].value == "$env{'form.Department'}") {            formname.Department.options[j].selected = true;
         }
@@ -1940,7 +1942,7 @@
     if (formname.Department.options[formname.Department.selectedIndex].value == -1) {
         return;
     }
-    courseSet('Department');
+    courseSet('$codetitles[2]');
     for (var j=0; j<formname.Number.length; j++) {
         if (formname.Number.options[j].value == "$env{'form.Number'}") {
             formname.Number.options[j].selected = true;

--raeburn1278686421--