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

raeburn raeburn@source.lon-capa.org
Fri, 01 May 2009 01:38:20 -0000


This is a MIME encoded message

--raeburn1241141900
Content-Type: text/plain

raeburn		Fri May  1 01:38:20 2009 EDT

  Modified files:              
    /loncom/interface	lonpickcourse.pm 
  Log:
  - Course Picking screen for Scantron Operators:
     - Domain select box replaced with static domain ($env{'request.role.domain'}
     - If domain is static, and domain has institutional code formats defined
       - Replace institutional code textbox with liked select boxes as used in Course Catalog, to pick: (for example) year, semester, department, number.
  
  - &instcode_selectors() routine added (uses courseclassifier to build the linked slect boxes).
  
  
--raeburn1241141900
Content-Type: text/plain
Content-Disposition: attachment; filename="raeburn-20090501013820.txt"

Index: loncom/interface/lonpickcourse.pm
diff -u loncom/interface/lonpickcourse.pm:1.77 loncom/interface/lonpickcourse.pm:1.78
--- loncom/interface/lonpickcourse.pm:1.77	Mon Mar 16 16:05:40 2009
+++ loncom/interface/lonpickcourse.pm	Fri May  1 01:38:20 2009
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # Pick a course
 #
-# $Id: lonpickcourse.pm,v 1.77 2009/03/16 16:05:40 bisitz Exp $
+# $Id: lonpickcourse.pm,v 1.78 2009/05/01 01:38:20 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -35,6 +35,7 @@
 use Apache::lonnet;
 use Apache::lonlocal;
 use Apache::longroup;
+use Apache::courseclassifier;
 use LONCAPA;
 
 sub handler {
@@ -49,7 +50,7 @@
     &Apache::loncommon::get_unprocessed_cgi
         ($ENV{'QUERY_STRING'},['domainfilter','form','cnumelement',
 			       'cdomelement','cnameelement','roleelement',
-                               'multiple','type','setroles']);
+                               'multiple','type','setroles','fixeddom']);
 
     my ($type,$title,$jscript,$multelement,$multiple,$roleelement,
         $lastaction,$autosubmit,$submitopener);
@@ -83,9 +84,13 @@
     }
 
     my %loaditem;
+    if ($env{'form.numtitles'}) {
+        $loaditem{'onload'} = 'setElements(); ';
+    }
+
     if ((($env{'form.form'} eq 'cu') || ($env{'form.form'} eq 'studentform')) && 
         ($env{'form.pickedcourse'})) {
-        $loaditem{'onload'} ="setSections()";
+            $loaditem{'onload'} .= 'setSections()';
     }
     $r->print(&Apache::loncommon::start_page($title,undef,
 					     {'add_entries' => \%loaditem,
@@ -117,6 +122,7 @@
 # ------------------------------------------ Display of filters to limit search
     my $filter = {};
     my $action = '/adm/pickcourse';
+    my $numtitles;
     if (!$onlyown) {
         my $filterlist = ['domainfilter','descriptfilter',
                           'instcodefilter','ownerfilter',
@@ -127,12 +133,12 @@
             push(@{$filterlist},'coursefilter');
         }
         $r->print(&build_filters($filterlist,$type,$roleelement,$multelement,
-                                 $filter,$action));
+                                 $filter,$action,\$numtitles));
     }
 
 # ---------------------------------------------------------------- Get the data
     if ($env{'form.gosearch'} || $onlyown) {
-        my %courses = &search_courses($r,$type,$onlyown,$filter);
+        my %courses = &search_courses($r,$type,$onlyown,$filter,$numtitles);
         &display_matched_courses($r,$type,$multiple,$action,%courses);
     }
     $r->print(&Apache::loncommon::end_page());
@@ -348,18 +354,25 @@
         $r->print('<input type="hidden" name="setroles" value="'.$env{'form.setroles'}.'" />');
         $r->print('<input type="hidden" name="action" value="rolepicker" />');
     } elsif ($env{'form.form'} eq 'modifycourse') {
-        $r->print(&Apache::lonhtmlcommon::echo_form_input(['phase','pickedcourse','type','form']));
+        $r->print(&Apache::lonhtmlcommon::echo_form_input(['phase','pickedcourse','type','form','numtitles','state']));
     } else {
         $r->print('<input type="hidden" name="cnumelement" value="'.
                   $env{'form.cnumelement'}.'" />'."\n".  
                   '<input type="hidden" name="cdomelement" value="'.
                   $env{'form.cdomelement'}.'" />'."\n");
     }
+    if ((exists($env{'form.fixeddom'})) && ($env{'form.form'} eq 'rules')) {
+        $r->print('<input type="hidden" name="fixeddom" value="'.
+                  $env{'form.fixeddom'}.'" />');
+    }
+    if ($env{'form.numtitles'}) {
+        $r->print('<input type="hidden" name="numtitles" value="'.
+                  $env{'form.numtitles'}.'" />');
+    }
     $r->print("</form>\n");
     return;
 }
 
-
 sub multiples_tag {
     my $jscript = &Apache::loncommon::check_uncheck_jscript();
     my $multelement = '<input type="hidden" name="multiple" value="1" />';
@@ -368,16 +381,15 @@
 
 sub build_filters {
     my ($filterlist,$type,$roleelement,$multelement,$filter,$action,
-        $caller) = @_;
+        $numtitlesref) = @_;
     my $list;
     my $formname;
+    my ($fixeddom,$codedom,$jscript);
     if (defined($env{'form.form'})) {
          $formname = $env{'form.form'};
-    } else {
-         $formname = $caller;
     }
     my ($domainselectform,$sincefilterform,$ownerdomselectform,
-        $instcodeform,$typeselectform);
+        $instcodeform,$typeselectform,$instcodetitle);
     foreach my $item (@{$filterlist}) {
         $filter->{$item} = $env{'form.'.$item};
         if ($item ne 'descriptfilter' && $item ne 'instcodefilter') {
@@ -403,10 +415,19 @@
                 $filter->{$item} ||= $env{'request.role.domain'};
                 $allow_blank=0;
             }
-            $domainselectform =
-		&Apache::loncommon::select_dom_form($filter->{$item},
-						    'domainfilter',
-						    $allow_blank);
+            if ($env{'form.fixeddom'}) {
+                $domainselectform = '<input type="hidden" name="domainfilter"'.
+                                    'value="'.$env{'request.role.domain'}.'" />'.
+                                    &Apache::lonnet::domain($env{'request.role.domain'},
+                                                            'description');
+                $codedom = $env{'request.role.domain'};
+            } else {    
+                $domainselectform =
+		    &Apache::loncommon::select_dom_form($filter->{$item},
+		    				        'domainfilter',
+						        $allow_blank);
+                $codedom = $filter->{'domainfilter'};
+            }
         } elsif ($item eq 'ownerdomfilter') {
             $ownerdomselectform =
      &Apache::loncommon::select_dom_form($filter->{$item},'ownerdomfilter',1);
@@ -435,7 +456,8 @@
               'cac' => &mt("$type Activity"),
               'cde' => &mt("$type Title"),
               'cdo' => &mt("$type Domain"),
-              'cin' => &mt('Course Institutional Code'),
+              'ins' => &mt('Institutional Code'),
+              'inc' => &mt('Institutional Categorization'),
               'cow' => &mt("$type Owner's Username"),
               'cod' => &mt("$type Owner's Domain"),
               'cog' => &mt('Course Type')
@@ -443,9 +465,25 @@
 
     $typeselectform =  '<select name="type" size="1">'."\n";
     if ($type eq 'Course') {
-        $instcodeform = 
+        if ($env{'form.fixeddom'}) {
+            ($instcodeform,$jscript,$$numtitlesref) = 
+                &instcode_selectors($codedom,'filterpicker');
+        }
+        if ($instcodeform eq '') {
+            $instcodeform = 
                 '<input type="text" name="instcodefilter" size="10" value="'.
                 $list->{'instcodefilter'}.'" />';
+            $instcodetitle = $lt{'ins'};
+        } else {
+            $instcodetitle = $lt{'inc'};
+        }
+        if ($env{'form.fixeddom'}) {
+            $instcodetitle .= '<br />('.$codedom.')';
+        }
+        if ($jscript ne '') {
+            $jscript = '<script type="text/javascript" language="Javascript">'.$jscript.
+                       '</script>'."\n";
+        }
     }
     foreach my $posstype ('Course','Non-standard Course') {
         $typeselectform.='<option value="'.$posstype.'"'.
@@ -474,10 +512,12 @@
 $multelement
 |;
         if ($formname eq 'portform') {
-            $output .= '<input type="hidden" name="setroles" value="'.$env{'form.setroles'}.'" />';
+            $output .= '<input type="hidden" name="setroles" value="'.$env{'form.setroles'}.'" />'."\n";
         }
     }
-
+    if ($env{'form.fixeddom'}) { 
+        $output .= '<input type="hidden" name="fixeddom" value="'.$env{'form.fixeddom'}.'" />'."\n";
+    }
     $output .= "<br />\n".&Apache::lonhtmlcommon::start_pick_box();
     if ($sincefilterform) { 
         $output .= &Apache::lonhtmlcommon::row_title($lt{'cac'})
@@ -488,14 +528,14 @@
         $output .= &Apache::lonhtmlcommon::row_title($lt{'cdo'})
                   .$domainselectform
                   .&Apache::lonhtmlcommon::row_closure();
-    }
+    } 
     if ($typeselectform) {
         $output .= &Apache::lonhtmlcommon::row_title($lt{'cog'})
                   .$typeselectform
                   .&Apache::lonhtmlcommon::row_closure();
     }
     if ($instcodeform) {
-        $output .= &Apache::lonhtmlcommon::row_title($lt{'cin'})
+        $output .= &Apache::lonhtmlcommon::row_title($instcodetitle)
                   .$instcodeform
                   .&Apache::lonhtmlcommon::row_closure();
     }
@@ -523,11 +563,27 @@
     $output .= &Apache::lonhtmlcommon::end_pick_box();
     $output .= '<p><input type="submit" name="gosearch" value="'. 
                &mt('Search').'" /></p>'."\n".'</form>'."\n".'<hr />'."\n";
-    return $output; 
+    return $jscript.$output;
+}
+
+sub instcode_selectors {
+    my ($codedom,$formname) = @_;
+    my ($output,@codetitles,%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);
+    if ($numtitles > 0) {
+        $output = &Apache::courseclassifier::build_instcode_selectors($numtitles,
+                  $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";
+ 
+    }
+    return ($output,$jscript,$numtitles);
 }
 
 sub search_courses {
-    my ($r,$type,$onlyown,$filter) = @_;
+    my ($r,$type,$onlyown,$filter,$numtitles) = @_;
     my %courses;
     if (!$onlyown) {
         $r->print(&mt('Searching ...').'<br />&nbsp;<br />');
@@ -546,14 +602,23 @@
         if ($type eq '') { $type = '.'; }
         my $timefilter = 
            ($filter->{'sincefilter'}==-1?1:time-$filter->{'sincefilter'});
+        my ($instcodefilter,$regexpok);
+        if ($numtitles) {
+            $instcodefilter = 
+                &Apache::courseclassifier::instcode_search_str($filter->{'domainfilter'},
+                                                               $numtitles);
+            $regexpok = 1;
+        } else {
+            $instcodefilter = $filter->{'instcodefilter'};
+        }
         %courses = 
             &Apache::lonnet::courseiddump($filter->{'domainfilter'},
                                           $filter->{'descriptfilter'},
                                           $timefilter,
-                                          $filter->{'instcodefilter'},
+                                          $instcodefilter,
                                           $filter->{'combownerfilter'},
                                           $filter->{'coursefilter'},
-                                          undef,undef,$type);
+                                          undef,undef,$type,$regexpok);
     } else {
         $r->print('<br />');
         my %coursehash = &Apache::loncommon::findallcourses(); 
@@ -786,10 +851,10 @@
 
 =item *
 X<build_filters()>
-B<build_filters($filterlist,$type,$roleelement,$multelement,$filter,$action)>:
+B<build_filters($filterlist,$type,$roleelement,$multelement,$filter,$action,$numfiltersref)>:
 
 
-Input: 6 - anonymous array of search criteria; course type; $roleelement ; $multelement ; anonymous hash of criteria and their values; form action.
+Input: 7 - 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).  
 
 Output: 1 - $output - HTML for display of search criteria, and hidden form elements. 
 
@@ -797,10 +862,10 @@
 
 =item *
 X<search_courses()>
-B<search_courses($r,$type,$onlyown,$filter)>:
+B<search_courses($r,$type,$onlyown,$filter,$numtitles)>:
 
 
-Input: 5 -  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.
+Input: 5 -  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).  
 
 Output: 1 - %courses - hash of courses satisfying search criteria, keys = course IDs, values are corresponding colon-separated escaped description, institutional code, owner and type.
 

--raeburn1241141900--