[LON-CAPA-cvs] cvs: loncom /interface coursecatalog.pm courseclassifier.pm loncreatecourse.pm lonmodifycourse.pm lonpickcourse.pm

raeburn raeburn@source.lon-capa.org
Thu, 08 Jul 2010 23:19:19 -0000


This is a MIME encoded message

--raeburn1278631159
Content-Type: text/plain

raeburn		Thu Jul  8 23:19:19 2010 EDT

  Modified files:              
    /loncom/interface	courseclassifier.pm coursecatalog.pm 
                     	lonpickcourse.pm lonmodifycourse.pm 
                     	loncreatecourse.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.
    - Names of categories in domain from localenroll::instcode_format():
      codetitles array can differ from these form element names.  
  
  
--raeburn1278631159
Content-Type: text/plain
Content-Disposition: attachment; filename="raeburn-20100708231919.txt"

Index: loncom/interface/courseclassifier.pm
diff -u loncom/interface/courseclassifier.pm:1.8 loncom/interface/courseclassifier.pm:1.9
--- loncom/interface/courseclassifier.pm:1.8	Wed Jul 29 22:32:44 2009
+++ loncom/interface/courseclassifier.pm	Thu Jul  8 23:19:19 2010
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Utilities for classifying courses based on institutional code
 #
-# $Id: courseclassifier.pm,v 1.8 2009/07/29 22:32:44 raeburn Exp $
+# $Id: courseclassifier.pm,v 1.9 2010/07/08 23:19:19 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -545,6 +545,7 @@
 sub build_instcode_selectors {
     my ($numtitles,$lasttitle,$cat_items,$codetitles,$cat_titles,$cat_order) = @_;
     my $output;
+    my @standardnames = &get_standard_codeitems();
     if ($numtitles > 0) {
         $output .= '<table><tr>';
         for (my $k=0; $k<$lasttitle-1; $k++) {
@@ -562,8 +563,8 @@
                 @longitems = @items;
             }
             $output .= '<td align="center">'.$codetitles->[$k].'<br />'."\n".
-                       '<select name="'.$codetitles->[$k].'" onChange="courseSet(this)"'.
-                       '>'."\n".'<option value="0" />All'."\n";
+                       '<select name="'.$standardnames[$k].'" onChange="courseSet(this)"'.
+                       '>'."\n".'<option value="0">'.&mt('All').'</option>'."\n";
             for (my $i=0; $i<@items; $i++) {
                 if ($longitems[$i] eq '') {
                     $longitems[$i] = $items[$i];
@@ -573,13 +574,13 @@
             $output .= '</select></td>';
         }
         $output .= '<td align="center">'.$codetitles->[$lasttitle-1].'<br />'."\n".
-                   '<select name="'.$codetitles->[$lasttitle-1].'">'."\n".
+                   '<select name="'.$standardnames[$lasttitle-1].'">'."\n".
                    '<option value="0">'.&mt('All')."\n".
                    '</option>'."\n".'</select>'."\n".
                    '</td></tr></table>'."\n";
         if ($numtitles > 4) {
             $output .= '<br /><br />'.$codetitles->[$numtitles-1].'<br />'."\n".
-                       '<input type="text" name="'.$codetitles->[$numtitles-1].
+                       '<input type="text" name="'.$standardnames[$numtitles-1].
                        '" /><br />'."\n";
         }
         $output .= '<br />';
@@ -811,7 +812,7 @@
 }
 
 sub instcode_search_str {
-    my ($domain,$numtitles) = @_;
+    my ($domain,$numtitles,$codetitles) = @_;
     my $instcode;
     if (defined($numtitles) && $numtitles == 0) {
         $instcode = '.+';
@@ -820,13 +821,25 @@
         my $defaults_result =
             &Apache::lonnet::auto_instcode_defaults($domain,\%codedefaults,
                                                     \@code_order);
+        my @standardnames = &get_standard_codeitems();
+        my %local_to_standard;
+        if (ref($codetitles) eq 'ARRAY') {
+            for (my $i=0; $i<@{$codetitles}; $i++) {
+                $local_to_standard{$codetitles->[$i]} = $standardnames[$i];
+            }
+        }
         if ($defaults_result eq 'ok') {
             $instcode ='^';
-            foreach my $item (@code_order) {
-                if ($env{'form.'.$item} eq '0' ) {
-                    $instcode .= $codedefaults{$item};
+            foreach my $loctitle (@code_order) {
+                my $item = $local_to_standard{$loctitle};
+                if ($item ne '') {
+                    if ($env{'form.'.$item} eq '0' ) {
+                        $instcode .= $codedefaults{$item};
+                    } else {
+                        $instcode .= $env{'form.'.$item};
+                    }
                 } else {
-                    $instcode .= $env{'form.'.$item};
+                    $instcode .= '.+';
                 }
             }
             $instcode .= '$';
@@ -837,5 +850,9 @@
     return $instcode;
 }
 
+sub get_standard_codeitems {
+    return ('Year','Semester','Department','Number');
+}
+
 1;
 
Index: loncom/interface/coursecatalog.pm
diff -u loncom/interface/coursecatalog.pm:1.62 loncom/interface/coursecatalog.pm:1.63
--- loncom/interface/coursecatalog.pm:1.62	Tue Jun  8 16:37:20 2010
+++ loncom/interface/coursecatalog.pm	Thu Jul  8 23:19:19 2010
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Handler for displaying the course catalog interface
 #
-# $Id: coursecatalog.pm,v 1.62 2010/06/08 16:37:20 bisitz Exp $
+# $Id: coursecatalog.pm,v 1.63 2010/07/08 23:19:19 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -87,8 +87,13 @@
     }
     &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems,
                                            \%idx,\@jsarray,$subcats);
+    my ($numtitles,@codetitles);
     if ($env{'form.coursenum'} ne '' && &user_is_known()) {
-        &course_details($r,$codedom,$formname,$domdesc,\@trails,\%allitems);
+        if ($env{'form.currcat_0'} eq 'instcode::0') {
+            $numtitles = &instcode_course_selector($r,$codedom,$formname,$domdesc,
+                                                   undef,undef,\@codetitles);
+        }
+        &course_details($r,$codedom,$formname,$domdesc,\@trails,\%allitems,\@codetitles);
     } else {
         my ($catlinks,$has_subcats,$selitem) = &category_breadcrumbs($codedom,@cats);
         my $catjs = <<"ENDSCRIPT";
@@ -114,12 +119,12 @@
 
 ENDSCRIPT
         $catjs .= &courselink_javascript(); 
-        my $numtitles;
         if ($env{'form.currcat_0'} eq 'instcode::0') {
             $numtitles = &instcode_course_selector($r,$codedom,$formname,$domdesc,
-                                                   $catlinks,$catjs);
+                                                   $catlinks,$catjs,\@codetitles);
             if ($env{'form.state'} eq 'listing') {
-                $r->print(&print_course_listing($codedom,$numtitles));
+                $r->print(&print_course_listing($codedom,$numtitles,undef,undef,undef,
+                                                \@codetitles));
             }
         } else {
             my (%add_entries);
@@ -164,7 +169,7 @@
                           $display_button.'" /></form><br /><br />');
             }
             if ($env{'form.state'} eq 'listing') {
-                $r->print(&print_course_listing($codedom,undef,\@trails,\%allitems,$subcats));
+                $r->print(&print_course_listing($codedom,undef,\@trails,\%allitems,$subcats,\@codetitles));
             }
         }
     }
@@ -173,7 +178,7 @@
 }
 
 sub course_details {
-    my ($r,$codedom,$formname,$domdesc,$trails,$allitems) = @_;
+    my ($r,$codedom,$formname,$domdesc,$trails,$allitems,$codetitles) = @_;
     my $output;
     my %add_entries = (topmargin    => "0",
                        marginheight => "0",);
@@ -206,7 +211,7 @@
         $r->print(&mt('Detailed course information:'));
     }
     $r->print('<br /><br />'.
-              &print_course_listing($codedom,undef,$trails,$allitems).
+              &print_course_listing($codedom,undef,$trails,$allitems,undef,$codetitles).
               '<br /><br />');
     $r->print('<form name="'.$formname.'" method="post" action="/adm/coursecatalog">'.
               '<a href = "javascript:document.coursecatalog.submit()">');
@@ -248,10 +253,9 @@
 }
 
 sub instcode_course_selector {
-    my ($r,$codedom,$formname,$domdesc,$catlinks,$catjs) = @_;
+    my ($r,$codedom,$formname,$domdesc,$catlinks,$catjs,$codetitles) = @_;
     my %coursecodes = ();
     my %codes = ();
-    my @codetitles = ();
     my %cat_titles = ();
     my %cat_order = ();
     my %cat_items;
@@ -261,7 +265,7 @@
                        marginheight => "0",);
     my ($jscript,$totcodes,$numtitles,$lasttitle) = 
         &Apache::courseclassifier::instcode_selectors_data($codedom,$formname,
-                           \%cat_items,\@codetitles,\%cat_titles,\%cat_order);
+                           \%cat_items,$codetitles,\%cat_titles,\%cat_order);
     my $js = '<script type"text/javascript">'."\n$jscript\n$catjs\n".
               '</script>';
     if ($totcodes) {
@@ -278,7 +282,7 @@
         if ($numtitles > 0) {
             $r->print('<b>'.&mt('Choose which course(s) to list.').'</b><br />'.
                       &Apache::courseclassifier::build_instcode_selectors($numtitles,
-                       $lasttitle,\%cat_items,\@codetitles,\%cat_titles,\%cat_order));
+                       $lasttitle,\%cat_items,$codetitles,\%cat_titles,\%cat_order));
         }
         $r->print('<input type="hidden" name="coursenum" value="" />'."\n".
                   '<input type="hidden" name="sortby" value="" />'."\n".
@@ -575,8 +579,8 @@
 }
 
 sub search_official_courselist {
-    my ($domain,$numtitles) = @_;
-    my $instcode = &Apache::courseclassifier::instcode_search_str($domain,$numtitles);
+    my ($domain,$numtitles,$codetitles) = @_;
+    my $instcode = &Apache::courseclassifier::instcode_search_str($domain,$numtitles,$codetitles);
     my $showhidden;
     if (&user_is_dc($domain)) {
         $showhidden = $env{'form.showhidden'};
@@ -633,7 +637,7 @@
 }
 
 sub print_course_listing {
-    my ($domain,$numtitles,$trails,$allitems,$subcats) = @_;
+    my ($domain,$numtitles,$trails,$allitems,$subcats,$codetitles) = @_;
     my $output;
     my %courses;
     my $knownuser = &user_is_known();
@@ -657,7 +661,7 @@
         }
     } else {
         if ($env{'form.currcat_0'} eq 'instcode::0') {
-            %courses = &search_official_courselist($domain,$numtitles);
+            %courses = &search_official_courselist($domain,$numtitles,$codetitles);
         } else {
             %courses = &search_courselist($domain,$subcats);
         }
Index: loncom/interface/lonpickcourse.pm
diff -u loncom/interface/lonpickcourse.pm:1.98 loncom/interface/lonpickcourse.pm:1.99
--- loncom/interface/lonpickcourse.pm:1.98	Fri Jun 25 04:37:49 2010
+++ loncom/interface/lonpickcourse.pm	Thu Jul  8 23:19:19 2010
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # Pick a course
 #
-# $Id: lonpickcourse.pm,v 1.98 2010/06/25 04:37:49 raeburn Exp $
+# $Id: lonpickcourse.pm,v 1.99 2010/07/08 23:19:19 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -140,7 +140,7 @@
 # ------------------------------------------ Display of filters to limit search
     my $filter = {};
     my $action = '/adm/pickcourse';
-    my ($numtitles,$showroles,$nohost);
+    my ($numtitles,$showroles,$nohost,@codetitles);
     if (!$onlyown) {
         my $filterlist = ['domainfilter'];
         # created filter for DCs only
@@ -177,7 +177,7 @@
 
         $r->print(&build_filters($filterlist,$type,$roleelement,$multelement,
                                  $filter,$action,\$numtitles,undef,$cloneruname,
-                                 $clonerudom,$typeelement));
+                                 $clonerudom,$typeelement,\@codetitles));
     }
 
 # ---------------------------------------------------------------- Get the data
@@ -191,7 +191,7 @@
             }
         }
         my %courses = &search_courses($r,$type,$onlyown,$filter,$numtitles,
-                                      $cloneruname,$clonerudom,$domcloner);
+                                      $cloneruname,$clonerudom,$domcloner,\@codetitles);
         if ($nohost) {
             $r->print ('<span class="LC_warning">'.
                        &mt('User does not exist - username: [_1], domain: [_2].',
@@ -543,7 +543,7 @@
 
 sub build_filters {
     my ($filterlist,$type,$roleelement,$multelement,$filter,$action,
-        $numtitlesref,$caller,$cloneruname,$clonerudom,$typeelement) = @_;
+        $numtitlesref,$caller,$cloneruname,$clonerudom,$typeelement,$codetitlesref) = @_;
     my ($list,$formname,$fixeddom,$codedom,$jscript);
     $codedom = $env{'request.role.domain'};
     if (defined($env{'form.form'})) {
@@ -677,7 +677,7 @@
                 || ($formname eq 'modifycourse')) {
                 $officialjs = 1;
                 ($instcodeform,$jscript,$$numtitlesref) = 
-                    &instcode_selectors($codedom,'filterpicker',$officialjs);
+                    &instcode_selectors($codedom,'filterpicker',$officialjs,$codetitlesref);
                 if ($jscript) {
                     $jscript = '<script type="text/javascript" language="Javascript">'.
                                $jscript.'</script>'."\n";
@@ -853,11 +853,11 @@
 }
 
 sub instcode_selectors {
-    my ($codedom,$formname,$officialjs) = @_;
-    my ($output,@codetitles,%cat_titles,%cat_order,%cat_items);
+    my ($codedom,$formname,$officialjs,$codetitles) = @_;
+    my ($output,%cat_titles,%cat_order,%cat_items);
     my ($jscript,$totcodes,$numtitles,$lasttitle) =
         &Apache::courseclassifier::instcode_selectors_data($codedom,$formname,
-                           \%cat_items,\@codetitles,\%cat_titles,\%cat_order,$officialjs);
+                           \%cat_items,$codetitles,\%cat_titles,\%cat_order,$officialjs);
     if ($numtitles > 0) {
         my $official = ' checked="checked" ';
         my $unofficial = '';
@@ -871,7 +871,7 @@
                    '<input type="radio" name="official" value="off"'.$unofficial.
                    ' onclick="toggleOfficial();" />'.&mt('No').'</label></span><br />'.
                    &Apache::courseclassifier::build_instcode_selectors($numtitles,
-                   $lasttitle,\%cat_items,\@codetitles,\%cat_titles,\%cat_order)."\n".
+                   $lasttitle,\%cat_items,$codetitles,\%cat_titles,\%cat_order)."\n".
                    '<input type="hidden" name="numtitles" value="'.$numtitles.'" />'."\n".
                    '<input type="hidden" name="state" value="listing" />'."\n";
  
@@ -880,7 +880,7 @@
 }
 
 sub search_courses {
-    my ($r,$type,$onlyown,$filter,$numtitles,$cloneruname,$clonerudom,$domcloner) = @_;
+    my ($r,$type,$onlyown,$filter,$numtitles,$cloneruname,$clonerudom,$domcloner,$codetitles) = @_;
     my (%courses,%showcourses,$cloner,$ccrole);
     if ($type eq 'Community') {
         $ccrole = 'co';
@@ -912,10 +912,10 @@
         if ($numtitles) {
             if ($env{'form.official'} eq 'on') {
                 $instcodefilter = 
-                    &Apache::courseclassifier::instcode_search_str($filter->{'domainfilter'},$numtitles);
+                    &Apache::courseclassifier::instcode_search_str($filter->{'domainfilter'},$numtitles,$codetitles);
                 $regexpok = 1;
             } elsif ($env{'form.official'} eq 'off') {
-                $instcodefilter = &Apache::courseclassifier::instcode_search_str($filter->{'domainfilter'},$numtitles);
+                $instcodefilter = &Apache::courseclassifier::instcode_search_str($filter->{'domainfilter'},$numtitles,$codetitles);
                 unless ($instcodefilter eq '') {
                     $regexpok = -1;
                 }
@@ -1209,10 +1209,10 @@
 
 =item *
 X<build_filters()>
-B<build_filters($filterlist,$type,$roleelement,$multelement,$filter,$action,$numfiltersref,$caller,$cloneruname,$clonerudom,$typeelem)>:
+B<build_filters($filterlist,$type,$roleelement,$multelement,$filter,$action,$numfiltersref,$caller,$cloneruname,$clonerudom,$typeelem,$codetitlesref>:
 
 
-Input: 11 - anonymous array of search criteria; course type; $roleelement ; $multelement ; anonymous hash of criteria and their values; form action; ref to scalar (count of number of elements in institutional codes -- e.g., 4 for year, semester, department, and number); caller context (e.g., set to 'modifycourse' when routine is called from lonmodifycourse.pm), username and domain of new course owner who wants to clone, $tyepelem 
+Input: 12 - anonymous array of search criteria; course type; $roleelement ; $multelement ; anonymous hash of criteria and their values; form action; ref to scalar (count of number of elements in institutional codes -- e.g., 4 for year, semester, department, and number); caller context (e.g., set to 'modifycourse' when routine is called from lonmodifycourse.pm); username and domain of new course owner who wants to clone, $typeelem; reference to array of titles of components in institutional codes (official courses). 
 
 Output: 1 - $output - HTML for display of search criteria, and hidden form elements. 
 
@@ -1221,11 +1221,11 @@
 =item *
 X<search_courses()>
 B<search_courses($r,$type,$onlyown,$filter,$numtitles,$cloneruname,$clonerudom,
-                 $domcloner)>:
+                 $domcloner,$codetitles)>:
 
 
-Input: 8 -  request object, course type, search scope: only courses in which user has active role (1), or any course (0); anonymous hash of criteria and their values; for institutional codes - number of categories; optional username of new course owner, optional domain of new course owner). Last two needed when search is for courses to clone from course request form, or course creation form (DC). Optional "domcloner" flag (has value=1 if user has ccc priv in  
-domain being filtered by (used when DC is using course creation form).
+Input: 9 -  request object, course type, search scope: only courses in which user has active role (1), or any course (0); anonymous hash of criteria and their values; for institutional codes - number of categories; optional username of new course owner, optional domain of new course owner). Seventh and eighth needed when search is for courses to clone from course request form, or course creation form (DC). Optional "domcloner" flag (has value=1 if user has ccc priv in  
+domain being filtered by (used when DC is using course creation form). Ninth is reference to array of titles of components in institutional codes (official courses).
 
 Output: 1 - %courses - hash of courses satisfying search criteria, keys = course IDs, values are corresponding colon-separated escaped description, institutional code, owner and type.
 
Index: loncom/interface/lonmodifycourse.pm
diff -u loncom/interface/lonmodifycourse.pm:1.55 loncom/interface/lonmodifycourse.pm:1.56
--- loncom/interface/lonmodifycourse.pm:1.55	Fri May 28 17:09:06 2010
+++ loncom/interface/lonmodifycourse.pm	Thu Jul  8 23:19:19 2010
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # handler for DC-only modifiable course settings
 #
-# $Id: lonmodifycourse.pm,v 1.55 2010/05/28 17:09:06 bisitz Exp $
+# $Id: lonmodifycourse.pm,v 1.56 2010/07/08 23:19:19 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -149,7 +149,7 @@
                       'instcodefilter','ownerfilter',
                       'coursefilter'];
     my $filter = {};
-    my ($numtitles,$cctitle,$dctitle);
+    my ($numtitles,$cctitle,$dctitle,@codetitles);
     my $ccrole = 'cc';
     if ($type eq 'Community') {
         $ccrole = 'co';
@@ -163,7 +163,8 @@
         $r->print('<h3>'.&mt('Search for a course in the [_1] domain',$domdesc).'</h3>');
     }   
     $r->print(&Apache::lonpickcourse::build_filters($filterlist,$type,
-                             undef,undef,$filter,$action,\$numtitles,'modifycourse'));
+                             undef,undef,$filter,$action,\$numtitles,'modifycourse',
+                             undef,undef,undef,\@codetitles));
     if ($type eq 'Community') {
         $r->print(&mt('Actions available after searching for a community:').'<ul>'.
                   '<li>'.&mt('Enter the community with the role of [_1]',$cctitle).'</li>'."\n".
@@ -192,14 +193,16 @@
     my %filter;
     my $action = '/adm/modifycourse';
     my $dctitle = &Apache::lonnet::plaintext('dc');
-    my $numtitles;
+    my ($numtitles,@codetitles);
     $r->print(&Apache::lonpickcourse::js_changer());
     $r->print(&mt('Revise your search criteria for this domain').' ('.$domdesc.').<br />');
     $r->print(&Apache::lonpickcourse::build_filters($filterlist,$type,
-                                       undef,undef,\%filter,$action,\$numtitles));
+                                       undef,undef,\%filter,$action,\$numtitles,
+                                       undef,undef,undef,undef,\@codetitles));
     $filter{'domainfilter'} = $dom;
     my %courses = &Apache::lonpickcourse::search_courses($r,$type,0,
-                                                         \%filter,$numtitles);
+                                                         \%filter,$numtitles,undef,
+                                                         undef,undef,\@codetitles);
     &Apache::lonpickcourse::display_matched_courses($r,$type,0,$action,undef,undef,undef,
                                                     %courses);
     return;
Index: loncom/interface/loncreatecourse.pm
diff -u loncom/interface/loncreatecourse.pm:1.140 loncom/interface/loncreatecourse.pm:1.141
--- loncom/interface/loncreatecourse.pm:1.140	Fri May 28 17:09:06 2010
+++ loncom/interface/loncreatecourse.pm	Thu Jul  8 23:19:19 2010
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # Create a course
 #
-# $Id: loncreatecourse.pm,v 1.140 2010/05/28 17:09:06 bisitz Exp $
+# $Id: loncreatecourse.pm,v 1.141 2010/07/08 23:19:19 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -932,7 +932,7 @@
     if ($numtitles) {
         if (($curr{'type'} eq 'official') || ($curr{'type'} eq 'unofficial')) {
             $instcodefilter = &instcode_srchstr($dom,$numtitles);
-                &Apache::courseclassifier::instcode_search_str($dom,$numtitles);
+                &Apache::courseclassifier::instcode_search_str($dom,$numtitles,\@codetitles);
             if ($curr{'type'} eq 'official') {
                 $regexpok = 1;
             } else {

--raeburn1278631159--