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

raeburn lon-capa-cvs-allow@mail.lon-capa.org
Mon, 07 Jul 2008 15:20:20 -0000


This is a MIME encoded message

--raeburn1215444020
Content-Type: text/plain

raeburn		Mon Jul  7 11:20:20 2008 EDT

  Modified files:              
    /loncom/interface	coursecatalog.pm 
  Log:
  - Include extra checkbox "Include subcategories within ", if current category contains subcategories.
  - Display of checkboxes used for filter modifiers suppressed when jumping back to "Main Categories" level.
  - Category filter sent to lonnet::courseiddump() includes concatenation of current category with contained subcategories (if include subcat. checked), with & separator.
  - Form input only echoed with echo_form_input() when displaying details for a single course, to avoid duplicate form elements.
  
  
--raeburn1215444020
Content-Type: text/plain
Content-Disposition: attachment; filename="raeburn-20080707112020.txt"

Index: loncom/interface/coursecatalog.pm
diff -u loncom/interface/coursecatalog.pm:1.35 loncom/interface/coursecatalog.pm:1.36
--- loncom/interface/coursecatalog.pm:1.35	Sun Jul  6 13:59:25 2008
+++ loncom/interface/coursecatalog.pm	Mon Jul  7 11:20:18 2008
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Handler for displaying the course catalog interface
 #
-# $Id: coursecatalog.pm,v 1.35 2008/07/06 17:59:25 raeburn Exp $
+# $Id: coursecatalog.pm,v 1.36 2008/07/07 15:20:18 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -74,22 +74,29 @@
 
     my %domconfig =
         &Apache::lonnet::get_dom('configuration',['coursecategories'],$codedom);
-    my (@cats,@trails,%allitems,%idx,@jsarray,$cathash);
+    my (@cats,@trails,%allitems,%idx,@jsarray,%subcathash,$cathash);
     if (ref($domconfig{'coursecategories'}) eq 'HASH') {
         $cathash = $domconfig{'coursecategories'}{'cats'};
     } else {
         $cathash = {};
     }
+    my $subcats;
+    if ($env{'form.withsubcats'}) {
+        $subcats = \%subcathash;
+    }
     &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems,
-                                           \%idx,\@jsarray);
+                                           \%idx,\@jsarray,$subcats);
     if ($env{'form.coursenum'} ne '' && &user_is_known()) {
         &course_details($r,$codedom,$formname,$domdesc,\@trails,\%allitems);
     } else {
-        my $catlinks = &category_breadcrumbs($codedom,@cats);
+        my ($catlinks,$has_subcats) = &category_breadcrumbs($codedom,@cats);
         my $catjs = <<"ENDSCRIPT";
 
 function setCatDepth(depth) {
     document.coursecats.catalog_maxdepth.value = depth;
+    if (depth == '') {
+        document.coursecats.currcat_0.value = '';
+    }
     document.coursecats.submit();
     return;
 }
@@ -120,7 +127,7 @@
             if ($env{'form.currcat_0'} ne '') {
                 $r->print('<form name="'.$formname.
                           '" method="post" action="/adm/coursecatalog">'.
-                          &additional_filters($codedom)."\n");
+                          &additional_filters($codedom,$has_subcats)."\n");
                 my ($currdepth,$deeper) = &get_depth_values();
                 $r->print('<input type="hidden" name="catalog_maxdepth" value="'.
                           $deeper.'" />'."\n");
@@ -136,7 +143,7 @@
                           &mt('Display courses').'" /></form><br /><br />');
             }
             if ($env{'form.state'} eq 'listing') {
-                $r->print(&print_course_listing($codedom,undef,\@trails,\%allitems));
+                $r->print(&print_course_listing($codedom,undef,\@trails,\%allitems,$subcats));
             }
         }
     }
@@ -367,6 +374,7 @@
     my ($currdepth,$deeper) = &get_depth_values();
     my $currcat_str = '<input type="hidden" name="catalog_maxdepth" value="'.$deeper.'" /><input type="hidden" name="showdom" value="'.$dom.'" />';
     my $catlinks = '<td valign="top"><b>'.&mt('Catalog:').'</b></td><td><table><tr>';
+    my $has_subcats;
     for (my $i=0; $i<$deeper; $i++) {
         $currcat_str .= '<input type="hidden" name="currcat_'.$i.'" value="'.$env{'form.currcat_'.$i}.'" />';
         my ($cattitle,$shallower);
@@ -387,22 +395,19 @@
                              '<input type="hidden" name="currcat_0" value="instcode::0" />';
                 $env{'form.currcat_0'} = 'instcode::0';
             } else {
+                $has_subcats = 1;
                 $catlinks .= '<select name="currcat_0">'."\n";
                 if (@{$cats[0]} > 1) {
                     my $selstr;
                     if ($env{'form.currcat_0'} eq '') {
                         $selstr = ' selected="selected" ';
                     }
-                    $catlinks .= '<option value=""'.$selstr.'>'.&mt('Select').'</option>'."\n";
+                    $catlinks .= '<option value=""  selected="selected">'.&mt('Select').'</option>'."\n";
                 }
                 for (my $i=0; $i<@{$cats[0]}; $i++) {
                     my $name = $cats[0][$i];
                     my $item = &escape($name).'::0';
-                    my $selstr;
-                    if ($env{'form.currcat_'.$i} eq $item) {
-                        $selstr = ' selected="selected" ';
-                    }
-                    $catlinks .= '<option value="'.$item.'"'.$selstr.'>';
+                    $catlinks .= '<option value="'.$item.'">';
                     if ($name eq 'instcode') {
                         $catlinks .= &mt('Official courses (with institutional codes)');
                     } else {
@@ -433,8 +438,11 @@
         }
         $catlinks .= '<td>'.$currcat;
         if (ref($cats[$deeper]{$cat}) eq 'ARRAY') {
+            $has_subcats = 1;
+            my $selstr;
             $catlinks .= ':&nbsp;<select name="currcat_'.$deeper.'">'.
-                         '<option value="" selected="selected">'.&mt('Select').'</option>';
+                         '<option value="" selected="selected">'.
+                         &mt('Select').'</option>';
             for (my $k=0; $k<@{$cats[$deeper]{$cat}}; $k++) {
                 my $name = $cats[$deeper]{$cat}[$k];
                 my $item = &escape($name).':'.&escape($cat).':'.$deeper;
@@ -445,7 +453,7 @@
         }
     }
     $catlinks .= $currcat_str.'</td></tr></table></td>';
-    return $catlinks;
+    return ($catlinks,$has_subcats);
 }
 
 sub get_depth_values {
@@ -463,12 +471,40 @@
 }
 
 sub additional_filters {
-    my ($codedom) = @_;
+    my ($codedom,$has_subcats) = @_;
     my $output = '<table>';
+    if (($env{'form.currcat_0'} ne 'instcode::0') && 
+        ($env{'form.currcat_0'} ne '') && ($has_subcats)) {
+        my $include_subcat_status;
+        if ($env{'form.withsubcats'}) {
+            $include_subcat_status = 'checked="checked" ';
+        }
+        my $counter = $env{'form.catalog_maxdepth'};
+        if ($counter > 0) {
+            if ($env{'form.state'} eq 'listing') {
+                $counter --;
+            } elsif ($env{'form.currcat_'.$counter} eq '') {
+                $counter --;
+            }
+        }
+        my ($catname) = split(/:/,$env{'form.currcat_'.$counter});
+        if ($catname ne '') {
+            $output .= '<tr><td><label>'.
+                       '<input type="checkbox" name="withsubcats" value="1" '.
+                       $include_subcat_status.'/>'.
+                       &mt('Include subcategories within "[_1]"',$catname).
+                       '</label></td></tr>';
+        }
+    }
     my $show_selfenroll_status;
     if ($env{'form.showselfenroll'}) {
         $show_selfenroll_status = 'checked="checked" ';
     }
+    $output .= '<tr><td>'.
+               '<label><input type="checkbox" name="showselfenroll" value="1" '.
+               $show_selfenroll_status.'/>'.
+               &mt('Only show courses which allow self-enrollment').
+               '</label></td></tr>';
     if (&user_is_dc($codedom)) {
         my $showdetails_status;
         if ($env{'form.showdetails'}) {
@@ -481,7 +517,7 @@
         my $dc_title = &Apache::lonnet::plaintext('dc');
         $output .= '<tr><td>'."\n".
                    '<label><input type="checkbox" name="showdetails" value="1" '.
-                   $showdetails_status.'/>'."\n".
+                   $showdetails_status.'/>'.
                    &mt('Show full details for each course ([_1] only)',$dc_title).
                    '</label>'."\n".'</td></tr><tr><td>'.
                    '<label><input type="checkbox" name="showhidden" value="1" '.
@@ -489,11 +525,7 @@
                    &mt('Include courses set to be hidden from catalog ([_1] only)',$dc_title).
                    '</label>'."\n".'</td></tr>';
     }
-    $output .= '<tr><td>'.
-               '<label><input type="checkbox" name="showselfenroll" value="1" '.
-               $show_selfenroll_status.'/>'.
-               &mt('Only show courses which allow self-enrollment').
-               '</label></td></tr></table><br />';
+    $output .= '</table><br />';
     return $output;
 }
 
@@ -629,7 +661,7 @@
 }
 
 sub search_courselist {
-    my ($domain) = @_;
+    my ($domain,$subcats) = @_;
     my $cat_maxdepth = $env{'form.catalog_maxdepth'};
     my $filter = $env{'form.currcat_'.$cat_maxdepth};
     if (($filter eq '') && ($cat_maxdepth > 0)) {
@@ -637,7 +669,24 @@
         $filter = $env{'form.currcat_'.$shallower};
     }
     my %courses;
+    my $filterstr;
     if ($filter ne '') {
+        if ($env{'form.withsubcats'}) {
+            if (ref($subcats) eq 'HASH') {
+                if (ref($subcats->{$filter}) eq 'ARRAY') {
+                    $filterstr = join('&',@{$subcats->{$filter}});
+                    if ($filterstr ne '') {
+                        $filterstr = $filter.'&'.$filterstr;
+                    }
+                } else {
+                    $filterstr = $filter;
+                }
+            } else {
+                $filterstr = $filter;
+            }  
+        } else {
+            $filterstr = $filter; 
+        }
         my $showhidden;
         if (&user_is_dc($domain)) {
             $showhidden = $env{'form.showhidden'};
@@ -645,13 +694,13 @@
         %courses = 
             &Apache::lonnet::courseiddump($domain,'.',1,'.','.','.',undef,undef,
                                           '.',1,$env{'form.showselfenroll'},
-                                          $filter,$showhidden,'coursecatalog');
+                                          $filterstr,$showhidden,'coursecatalog');
     }
     return %courses;
 }
 
 sub print_course_listing {
-    my ($domain,$numtitles,$trails,$allitems) = @_;
+    my ($domain,$numtitles,$trails,$allitems,$subcats) = @_;
     my $output;
     my %courses;
     my $knownuser = &user_is_known();
@@ -673,7 +722,7 @@
         if ($env{'form.currcat_0'} eq 'instcode::0') {
             %courses = &search_official_courselist($domain,$numtitles);
         } else {
-            %courses = &search_courselist($domain);
+            %courses = &search_courselist($domain,$subcats);
         }
         if (keys(%courses) == 0) {
             $output = &mt('No courses match the criteria you selected.');
@@ -689,7 +738,9 @@
     my %domconfig =
         &Apache::lonnet::get_dom('configuration',['usercreation'],$domain);
     $output .= &construct_data_table($knownuser,\%courses,$details,undef,$now,\%domconfig,$trails,$allitems);
-    $output .= &Apache::lonhtmlcommon::echo_form_input(['coursenum','state','catalogfilter','sortby','showdetails']);
+    if ($env{'form.coursenum'} ne '') {
+        $output .= &Apache::lonhtmlcommon::echo_form_input(['coursenum','state','catalogfilter','sortby','showdetails']);
+    }
     return $output;
 }
 

--raeburn1215444020--