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

raeburn lon-capa-cvs@mail.lon-capa.org
Mon, 03 Oct 2005 23:53:30 -0000


raeburn		Mon Oct  3 19:53:30 2005 EDT

  Modified files:              
    /loncom/interface	lonpickcourse.pm 
  Log:
  Allow selection of multiple courses if called from rolefilter form (in lonnotify.pm to display users with roles in specific courses).    
  
  
Index: loncom/interface/lonpickcourse.pm
diff -u loncom/interface/lonpickcourse.pm:1.29 loncom/interface/lonpickcourse.pm:1.30
--- loncom/interface/lonpickcourse.pm:1.29	Wed Sep 14 16:42:36 2005
+++ loncom/interface/lonpickcourse.pm	Mon Oct  3 19:53:25 2005
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # Pick a course
 #
-# $Id: lonpickcourse.pm,v 1.29 2005/09/14 20:42:36 raeburn Exp $
+# $Id: lonpickcourse.pm,v 1.30 2005/10/03 23:53:25 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -115,7 +115,18 @@
             $seclist = join('","',@sections);
         }
     }
-    $r->print(&Apache::loncommon::bodytag("Selecting a Course",undef,$loaditem,undef,undef,undef,undef,1));
+# if called from rolefilter, setup for multiple course selections.
+    my $multflag = 0;
+    my $jscript;
+    my $title = 'Selecting a course';
+    if ($env{'form.form'} eq 'rolefilter') {
+        $multflag = 1;
+        $title = 'Selecting course(s)';
+    }
+    if ($multflag) {
+        $jscript = &Apache::loncommon::check_uncheck_jscript();
+    }
+    $r->print(&Apache::loncommon::bodytag($title,undef,$loaditem,undef,undef,undef,undef,1));
     my %lt=&Apache::lonlocal::texthash(
 				       'cac' => 'Course Activity',
 				       'cde' => 'Course Description',
@@ -144,18 +155,43 @@
     }
     $r->print(<<ENDSCRIPT);
 <script>
-function gochoose(cname,cdom,cdesc) {
-    $name_code
+function gochoose(cname,cdom,cdesc,multflag,caller) {
     var openerForm = "$env{'form.form'}";
-    opener.document.$env{'form.form'}.$env{'form.cnumelement'}.value=cname;
-    if (openerForm == 'cu' || openerForm == 'rolechoice') {
-         opener.document.$env{'form.form'}.$env{'form.cdomelement'}.value=cdom;
+    courseCount = 0;
+    var courses = '';
+    if (multflag) {
+        for (var j=0; j<document.courselist.course_id.length; j++) {
+            if (document.courselist.course_id[j].checked) {
+                courses = courses + document.courselist.course_id[j].value + "&&";
+                courseCount ++;
+            }
+        }
+        opener.document.$env{'form.form'}.coursetotal.value = courseCount;
+        for (var j=0; j<opener.document.$env{'form.form'}.coursepick.length; j++) { 
+            if (opener.document.$env{'form.form'}.coursepick[j].value == 'specific') {  
+                opener.document.$env{'form.form'}.coursepick[j].checked = true;
+            }
+            else {
+                opener.document.$env{'form.form'}.coursepick[j].checked = false;
+            }
+        }
+        if (courseCount > 0) {
+            courses = courses.substr(0,courses.length-2);
+            opener.document.$env{'form.form'}.courselist.value = courses
+        }
     }
     else {
-        var slct=opener.document.$env{'form.form'}.$env{'form.cdomelement'};
-        var i;
-        for (i=0;i<slct.length;i++) {
-            if (slct.options[i].value==cdom) { slct.selectedIndex=i; }
+        $name_code
+        opener.document.$env{'form.form'}.$env{'form.cnumelement'}.value=cname;
+        if (openerForm == 'cu') {
+            opener.document.$env{'form.form'}.$env{'form.cdomelement'}.value=cdom;
+        }
+        else {
+            var slct=opener.document.$env{'form.form'}.$env{'form.cdomelement'};
+            var i;
+            for (i=0;i<slct.length;i++) {
+                if (slct.options[i].value==cdom) { slct.selectedIndex=i; }
+            }
         }
     }
     $autosubmit
@@ -195,9 +231,11 @@
     }
     self.close()
 }
+
+$jscript
 </script>
 $submitopener
-<form method="post">
+<form method="post" name="filterpicker">
 <input type="hidden" name="cnumelement" value="$env{'form.cnumelement'}" />
 <input type="hidden" name="cdomelement" value="$env{'form.cdomelement'}" />
 $name_input
@@ -234,6 +272,7 @@
 	    ($domainfilter,$descriptfilter,$timefilter,$instcodefilter,$ownerfilter,$coursefilter);
 	$r->print('<form name="courselist">');
 	my %by_descrip;
+        my $numcourses = keys %courses;
 	foreach my $course (keys %courses) {
             my $descr;
             if ($courses{$course} =~ m/^([^:]*):/) {
@@ -244,14 +283,20 @@
             my $description = lc($descr);
             push (@{$by_descrip{$description}}, $course);
 	}
+        if ($numcourses > 1 && $multflag) {
+            $r->print('<input type="button" value="check all"
+                    onclick="javascript:checkAll(document.courselist.course_id)" />                    &nbsp;&nbsp;<input type="button" value="uncheck all"
+                    onclick="javascript:uncheckAll(document.courselist.course_id)" />
+                    <br /><br />');
+        }
 	foreach my $description (sort(keys(%by_descrip))) {
             foreach my $course (@{$by_descrip{$description}}) {
 	        my $cleandesc=&HTML::Entities::encode($description,'<>&"');
 	        $cleandesc=~s/'/\\'/g;
 	        my ($cdom,$cnum)=split(/\_/,$course);
                 my ($descr,$instcode,$owner) = split/:/,$courses{$course};
-	        $r->print('<input type="button" value="Select" onClick="gochoose('.
-		      "'".$cnum."','".$cdom."','".$cleandesc."')".'" /> '.$description.' ('.
+                $r->print(&course_chooser($multflag,$cdom,$cnum,$cleandesc));
+	        $r->print($description.'('.
 		      ($Apache::lonnet::domaindescription{$cdom}?
                        $Apache::lonnet::domaindescription{$cdom}:$cdom).")");
                 unless ($instcode eq '') {
@@ -263,7 +308,11 @@
                 $r->print("<br />\n");
             }
 	}
-	if (!%courses) { $r->print(&mt('None found')); }
+	if (!%courses) { 
+            $r->print(&mt('None found'));
+        } elsif ($multflag) {
+            $r->print('<input type="button" value="Submit" onClick="gochoose('."'','','',1)".'" />');
+        }
         $r->print('<input type="hidden" name="form" value="'.$env{'form.form'}.'" />'."\n".
                    '<input type="hidden" name="pickedcourse" value="" />'."\n".
                    '<input type="hidden" name="cnumelement" value="'.$env{'form.cnumelement'}.'" />'."\n".
@@ -274,5 +323,17 @@
     return OK;
 }
 
+sub course_chooser {
+    my ($multflag,$cdom,$cnum,$cleandesc) = @_;
+    my $output; 
+    if ($multflag) {
+        $output = '<input type="checkbox" name="course_id" value="'.$cdom.'_'.$cnum.'" />'."\n";
+    } else {
+        $output = '<input type="button" value="Select" onClick="gochoose('.
+                  "'".$cnum."','".$cdom."','".$cleandesc."')".'" />'."\n";
+    }
+    return $output;
+} 
+
 1;
 __END__