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

raeburn lon-capa-cvs@mail.lon-capa.org
Thu, 09 Nov 2006 22:18:29 -0000


This is a MIME encoded message

--raeburn1163110709
Content-Type: text/plain

raeburn		Thu Nov  9 17:18:29 2006 EDT

  Modified files:              
    /loncom/interface	lonpickcourse.pm 
  Log:
  Documentation added.  Reorganization of handler() continues.  Dynamic population of roles, access type, section and groups select boxes as required when adding course-based access control for a portfolio file moved to portfolio.pm.  Similarly dynamic population of section numbers when DC is using CUSR to add a course-level role moved to opener window - loncommon::setsec_javascript() - to satisfy IE 6 limitations which do not permit child window to change select box options in opener window.  Required data is sent to opener window in comma-separated text strings to hidden form elements.
  
  
--raeburn1163110709
Content-Type: text/plain
Content-Disposition: attachment; filename="raeburn-20061109171829.txt"

Index: loncom/interface/lonpickcourse.pm
diff -u loncom/interface/lonpickcourse.pm:1.54 loncom/interface/lonpickcourse.pm:1.55
--- loncom/interface/lonpickcourse.pm:1.54	Sun Nov  5 15:59:17 2006
+++ loncom/interface/lonpickcourse.pm	Thu Nov  9 17:18:28 2006
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # Pick a course
 #
-# $Id: lonpickcourse.pm,v 1.54 2006/11/05 20:59:17 raeburn Exp $
+# $Id: lonpickcourse.pm,v 1.55 2006/11/09 22:18:28 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -46,17 +46,16 @@
 
 # ------------------------------------------------------------ Print the screen
 
-# Get parameters from query string
+    # Get parameters from query string
     &Apache::loncommon::get_unprocessed_cgi
-        ($ENV{'QUERY_STRING'},['domainfilter','descriptfilter',
-			       'sincefilter','form','cnumelement',
+        ($ENV{'QUERY_STRING'},['domainfilter','form','cnumelement',
 			       'cdomelement','cnameelement','roleelement',
-                               'pickedcourse','instcodefilter',
-                               'ownerfilter','coursefilter','multiple',
-                               'type','ownerdomfilter']);
+                               'multiple','type','setroles']);
 
-    my ($type,$title,$jscript,$multelement,$multiple,$name_code,$name_input,
-        $roleelement);
+    my ($type,$title,$jscript,$multelement,$multiple,$roleelement,
+        $lastaction,$autosubmit,$submitopener);
+
+    # Get course type - Course or Non-standard course.
     $type = $env{'form.type'};
     if (!defined($env{'form.type'})) {
         $type = 'Course';
@@ -64,26 +63,13 @@
     $title = &mt('Selecting a [_1]',$type);
 
     # Setup for multiple course selections, if flag for multiples set.
-    ($title,$jscript,$multelement,$multiple) = &multiples_tag($type,$title);
-
-    if (defined($env{'form.cnameelement'}) && $env{'form.cnameelement'} ne '') {
-        $name_code = "opener.document.$env{'form.form'}.$env{'form.cnameelement'}.".
-                     "value=cdesc;";
-        $name_input ='<input type="hidden" name="cnameelement" value="'.
-                     $env{'form.cnameelement'}.'" />';
+    $multiple = $env{'form.multiple'};
+    if ($multiple) {
+        ($jscript,$multelement) = &multiples_tag();
+        $title = &mt('Selecting [_1](s)',lc($type));
     }
 
-    my $submitopener = '';
-    my $autosubmit = '';
-    my $lastaction = 'self.close()';
-    if ($env{'form.form'} eq 'cu') {
-        $lastaction = 'document.courselist.pickedcourse.value = cdom+"_"+cname;'."\n".
-                      'document.courselist.submit();';
-    }
-    if ($env{'form.form'} eq 'portform') {
-        $lastaction = 'document.courselist.pickedcourse.value = cdom+"_"+cname;'."\n".
-                      'document.courselist.submit();';
-    }
+    # if called when a DC is selecting a course 
     my $roledom = $env{'form.roleelement'};
     if ($roledom) {
         $roleelement = '<input type="hidden" name="roleelement" value="'.$roledom.'" />';
@@ -91,132 +77,56 @@
         $autosubmit = 'process_pick("'.$roledom.'")';
     }
 
-    my (%filter,%list);
-    my $filterdisplay;
     my $onlyown = 0;
+    # if called to assign course-based portfolio access control
     if ((($env{'form.form'} eq 'portform') && ($env{'user.adv'}))) {
         $onlyown = 1;
-    } else {   
-        $filterdisplay = &build_filters($type,$name_input,$roleelement,
-                                        $multelement, \%filter,\%list);
-    }
-# if called from loncreateuser, report sections, then close
-    my (%loaditem,$seclist,$groupslist,$roleslist,$rolesnameslist,
-	$accesslist,$accessnameslist);
-    my $sec_element = 'currsec';
-    my $grplist_element = 'groups';
-    my $num_sections = 0;
-    my $num_groups = 0;
-    my $num_roles = 0;
-    my $num_access = 0;
-    my ($cdom,$cnum);
-    if ($env{'form.pickedcourse'}) {
-        ($cdom,$cnum) = split/_/,$env{'form.pickedcourse'};
     }
+
+    my %loaditem;
     if ($env{'form.form'} eq 'cu' && $env{'form.pickedcourse'}) {
         $loaditem{'onload'} ="setSections()";
-        ($seclist,$num_sections,$groupslist,$num_groups) = 
-             &build_selection_lists($cdom,$cnum,$type,undef,undef,
-                                    $env{'form.form'});
-    }
-# if called from portfolio, report roles, sections, groups and close
-    my ($roles_element,$groups_element,$status_element,$setitems_function);
-    if ($env{'form.form'} eq 'portform' && $env{'form.pickedcourse'}) {
-        $loaditem{'onload'} ="setItems()";
-        ($seclist,$num_sections,$groupslist,$num_groups,$roleslist,$num_roles,
-         $rolesnameslist,$accesslist,$num_access,$accessnameslist) =
-            &build_selection_lists($cdom,$cnum,$type,1,1,$env{'form.form'});
-        ($sec_element,$grplist_element,$setitems_function) = 
-            &setitems_javascript($seclist,$num_sections,$groupslist,$num_groups,
-                                 $roleslist,$num_roles,$rolesnameslist,
-                                 $accesslist,$num_access,$accessnameslist);
     }
     $r->print(&Apache::loncommon::start_page($title,undef,
 					     {'add_entries' => \%loaditem,
 					      'no_nav_bar'  => 1, }));
-    my %elements = (
-                     'Course' => {
-                                 name  => 'coursepick',
-                                 total => 'coursetotal',
-                                 list  => 'courselist',
-                               },
-                     'Non-standard course' => {
-                                 name  => 'grouppick',
-                                 total => 'grouptotal',
-                                 list  => 'grouplist',
-                             },
-                    );
-    my $setsec_func = &setsec_javascript($seclist,$sec_element,$grplist_element,
-                                         $groupslist,$num_sections);
-    $r->print(<<ENDSCRIPT);
-<script>
-function gochoose(cname,cdom,cdesc,multiple,caller) {
-    var openerForm = "$env{'form.form'}";
-    courseCount = 0;
-    var courses = '';
-    if (multiple) {
-	if (typeof(document.courselist.course_id.length) == 'undefined') {
-	    // only 1 course checkbox was created
-	    if (document.courselist.course_id.checked) {
-		courses = courses + document.courselist.course_id.value + "&&";
-		courseCount ++;
-	    }
-	} else {
-	    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'}.$elements{$type}{'total'}.value = courseCount;
-	if (typeof(opener.document.$env{'form.form'}.$elements{$type}{'name'}.length) ==
-	    'undefined') {
-	    if (opener.document.$env{'form.form'}.$elements{$type}{'name'}.value == 'specific') {  
-		opener.document.$env{'form.form'}.$elements{$type}{'name'}.checked = true;
-	    } else {
-		opener.document.$env{'form.form'}.$elements{$type}{'name'}.checked = false;
-	    }
-	} else {
-	    for (var j=0; j<opener.document.$env{'form.form'}.$elements{$type}{'name'}.length; j++) { 
-		if (opener.document.$env{'form.form'}.$elements{$type}{'name'}\[j].value == 'specific') {  
-		    opener.document.$env{'form.form'}.$elements{$type}{'name'}\[j].checked = true;
-		} else {
-		    opener.document.$env{'form.form'}.$elements{$type}{'name'}\[j].checked = false;
-		}
-	    }
-	}
-	if (courseCount > 0) {
-	    courses = courses.substr(0,courses.length-2);
-	    opener.document.$env{'form.form'}.$elements{$type}{'list'}.value = courses;
-	}
+
+    if ($env{'form.form'} eq 'portform') {
+        $lastaction = 'document.courselist.submit()';
+    } elsif ($env{'form.form'} eq 'cu') {
+        $lastaction = 
+             'document.courselist.pickedcourse.value = cdom+"_"+cname;'."\n".
+             'document.courselist.submit();';
     } else {
-        $name_code
-        opener.document.$env{'form.form'}.$env{'form.cnumelement'}.value=cname;
-        var slct=opener.document.$env{'form.form'}.$env{'form.cdomelement'};
-        if (slct.options == undefined) {
-            opener.document.$env{'form.form'}.$env{'form.cdomelement'}.value=cdom;
-        }
-        else {
-            var i;
-            for (i=0;i<slct.length;i++) {
-                if (slct.options[i].value==cdom) { slct.selectedIndex=i; }
-            }
-        }
+        $lastaction = 'self.close()';
     }
-    $autosubmit
-    $lastaction
-}
 
-$setsec_func
+    # if called to assign a role in a course to a user via CUSR
+    if ($env{'form.form'} eq 'cu') {
+        $r->print(&create_user_javascript($type)); 
+    }
 
-$setitems_function
+    # print javascript functions for choosing a course 
+    if ($env{'form.gosearch'} || $onlyown) {
+        $r->print(&gochoose_javascript($type,$autosubmit,$lastaction));
+    }
+    $r->print('<script type="text/javascript">'.$jscript.'</script>');
+    $r->print($submitopener);
 
-$jscript
-</script>
-$submitopener
-ENDSCRIPT
-    $r->print($filterdisplay);
+# ------------------------------------------ Display of filters to limit search
+    my (%filter,%list);
+    if (!$onlyown) {
+        my $filterlist = ['domainfilter','descriptfilter',
+                          'instcodefilter','ownerfilter',
+                          'ownerdomfilter'];
+        # course ID filter for DCs only
+        if ($env{'user.adv'} && $env{'form.domainfilter'} &&
+            exists($env{'user.role.dc./'.$env{'form.domainfilter'}.'/'})) {
+            push(@{$filterlist},'coursefilter');
+        }
+        $r->print(&build_filters($filterlist,$type,$roleelement,$multelement,
+                                 \%filter,\%list));
+    }
 
 # ---------------------------------------------------------------- Get the data
     if ($env{'form.gosearch'} || $onlyown) {
@@ -227,9 +137,41 @@
     return OK;
 }
 
+sub create_user_javascript {
+    my ($type) = @_;
+    my $output;
+    #javascript for reporting sections and groups then closing
+    if ($env{'form.pickedcourse'}) {
+        my ($cdom,$cnum) = split/_/,$env{'form.pickedcourse'};
+        my $sec_element = 'currsec';
+        my $grplist_element = 'groups';
+        my ($sections,$groups) =
+          &Apache::loncommon::get_secgrprole_info($cdom,$cnum,'',$type);
+        my $num_sections = scalar(@{$sections});
+        my $seclist = join(',',@{$sections});
+        my $num_groups = scalar(@{$groups});
+        my $groupslist = join(',',@{$groups});
+        $output = qq|
+<script type="text/javascript">
+function setSections() {
+    opener.document.$env{"form.form"}.$grplist_element.value='$groupslist';
+    window.opener.setSect('$seclist');
+    self.close()
+}
+</script>
+|;
+;
+    }
+    return $output;
+}
+
 sub display_matched_courses {
     my ($r,$type,$multiple,%courses) = @_;
-    $r->print('<form name="courselist" method="post" action="/adm/pickcourse">');
+    my $action = '/adm/pickcourse';
+    if ($env{'form.form'} eq 'portform') {
+        $action = '/adm/portfolio';
+    }
+    $r->print('<form name="courselist" method="post" action="'.$action.'">');
     my %by_descrip;
     my $numcourses = keys(%courses);
     foreach my $course (keys(%courses)) {
@@ -266,7 +208,7 @@
                 $r->print(", owner - ".&unescape($owner));
             }
             unless ($ttype eq '') {
-                $r->print('('.&Apache::lonnet::unescape($ttype).')');
+                $r->print('('.&unescape($ttype).')');
             }
             if ($multiple) { $r->print("</label>\n"); }
             $r->print("<br />\n");
@@ -286,36 +228,29 @@
         $r->print('<input type="hidden" name="roleelement" value="'.
                   $env{'form.roleelement'}.'" />'."\n");
     }
+    if ($env{'form.form'} eq 'portform') {
+        $r->print('<input type="hidden" name="cnum" value="" />');
+        $r->print('<input type="hidden" name="cdom" value="" />');
+        $r->print('<input type="hidden" name="setroles" value="'.$env{'form.setroles'}.'" />');
+        $r->print('<input type="hidden" name="action" value="rolepicker" />');
+    }
     $r->print("</form>\n");
     return;
 }
 
 
 sub multiples_tag {
-    my ($type,$title) = @_;
-    my ($jscript,$multelement,$multiple);
-    $multiple = $env{'form.multiple'};
-    if ($multiple) {
-        $title = &mt('Selecting [_1](s)',lc($type));
-        $jscript = &Apache::loncommon::check_uncheck_jscript();
-        $multelement = '<input type="hidden" name="multiple" value="'.$multiple.'" />';
-    }
-    return ($title,$jscript,$multelement,$multiple);
+    my $jscript = &Apache::loncommon::check_uncheck_jscript();
+    my $multelement = '<input type="hidden" name="multiple" value="1" />';
+    return ($jscript,$multelement);
 }
 
 sub build_filters {
-    my ($type,$name_input,$roleelement,$multelement,$filter,$list) = @_;
-    my @filters = ('domainfilter','descriptfilter','instcodefilter','ownerfilter','ownerdomfilter');
-    # course ID filter for DCs only
-    my ($courseidtag,$domainselectform,$sincefilterform,$ownerdomselectform,
+    my ($filterlist,$type,$roleelement,$multelement,$filter) = @_;
+    my $list;
+    my ($domainselectform,$sincefilterform,$ownerdomselectform,
         $instcodeform,$typeselectform);
-    if ($env{'user.adv'} && $env{'form.domainfilter'} &&
-        exists($env{'user.role.dc./'.$env{'form.domainfilter'}})) {
-        push(@filters,'coursefilter');
-        $courseidtag=&mt('LON-CAPA course ID').
-                     '<input type="text" name="coursefilter" size="25" value="'.                     $list->{'coursefilter'}.'" /><br />';
-    }
-    foreach my $item (@filters) {
+    foreach my $item (@{$filterlist}) {
         $filter->{$item} = $env{'form.'.$item};
         if ($item ne 'descriptfilter' && $item ne 'instcodefilter') {
             $filter->{$item} =~ s/\W//g;
@@ -371,6 +306,16 @@
             ($posstype eq $type ? 'selected="selected" ' : ''). ">$posstype</option>\n";
     }
     $typeselectform.="</select>";
+    my $name_input;
+    if ($env{'form.cnameelement'} ne '') {
+        $name_input ='<input type="hidden" name="cnameelement" value="'.
+                     $env{'form.cnameelement'}.'" />';
+    }
+    my $courseidtag;
+    if (exists($filter->{'coursefilter'})) {
+        $courseidtag=&mt('LON-CAPA course ID').
+                     '<input type="text" name="coursefilter" size="25" value="'.                     $list->{'coursefilter'}.'" /><br />';
+    }
     my $output = <<"END";
 <form method="post" name="filterpicker" action="/adm/pickcourse">
 <input type="hidden" name="cnumelement" value="$env{'form.cnumelement'}" />
@@ -450,181 +395,284 @@
     return $output;
 }
 
-sub setsec_javascript {
-    my ($seclist,$sec_element,$grplist_element,$groupslist,$num_sections) = @_;
-    my $sectsections = qq|
-function setSections() {
-    var numSections = $num_sections
-    var sectionsArray = new Array("$seclist")
-    opener.document.$env{"form.form"}.$sec_element.length = 0
-    if (numSections == 0) {
-        opener.document.$env{"form.form"}.$sec_element.multiple=false
-        opener.document.$env{"form.form"}.$sec_element.size=1;
-        opener.document.$env{"form.form"}.$sec_element.options[0] = new Option('No existing sections','',false,false)
-    } else {
-        if (numSections == 1) {
-            opener.document.$env{"form.form"}.$sec_element.multiple=false;
-            opener.document.$env{"form.form"}.$sec_element.size=1;
-            opener.document.$env{"form.form"}.$sec_element.options[0] = new Option('Select','',true,true);
-            opener.document.$env{"form.form"}.$sec_element.options[1] = new Option('No section','',false,false)
-            opener.document.$env{"form.form"}.$sec_element.options[2] = new Option(sectionsArray[0],sectionsArray[0],false,false);
-        } else {
-            for (var i=0; i<numSections; i++) {
-                opener.document.$env{"form.form"}.$sec_element.options[i] = new Option(sectionsArray[i],sectionsArray[i],false,false)
-            }
-            opener.document.$env{"form.form"}.$sec_element.multiple=true
-            if (numSections < 3) {
-                opener.document.$env{"form.form"}.$sec_element.size=numSections;            } else {
-                opener.document.$env{"form.form"}.$sec_element.size=3;
-            }
-            opener.document.$env{"form.form"}.$sec_element.options[0].selected = false
-        }
+sub gochoose_javascript {
+    my ($type,$autosubmit,$lastaction) = @_;
+    my %elements = (
+                     'Course' => {
+                                 name  => 'coursepick',
+                                 total => 'coursetotal',
+                                 list  => 'courselist',
+                                 },
+                     'Non-standard course' => {
+                                 name  => 'grouppick',
+                                 total => 'grouptotal',
+                                 list  => 'grouplist',
+                              },
+                    );
+    my $name_code;
+    if ($env{'form.cnameelement'} ne '') {
+        $name_code = 'opener.document.'.$env{'form.form'}.'.'.
+                      $env{'form.cnameelement'}.'.value=cdesc;';
     }
-    opener.document.$env{"form.form"}.$grplist_element.value='$groupslist';
-    self.close()
-}
-|;
-}
-
-sub setitems_javascript {
-    my ($seclist,$num_sections,$groupslist,$num_groups,$roleslist,$num_roles,
-        $rolesnameslist,$accesslist,$num_access,$accessnameslist) = @_;
-    my ($row_id) = ($env{'form.cnumelement'} =~ /^crsnum_(\d+)$/);
-    my $roles_element = 'role_'.$row_id.'_1';
-    my $groups_element = 'group_'.$row_id.'_1';
-    my $sec_element = 'section_'.$row_id.'_1';
-    my $status_element = 'access_'.$row_id.'_1';
-    my $grplist_element = 'grplist_'.$row_id.'_1';
-    my $setitems_function = qq|
-function setItems() {
-    opener.document.$env{"form.form"}.activate.checked = true;
-    setRoles();
-    setGroups();
-    setStatus();
-    setSections();
-}
-
-function setRoles() {
-    var numRoles = $num_roles
-    var rolesArray = new Array("$roleslist");
-    var roleNamesArray = new Array("$rolesnameslist");
-    opener.document.$env{"form.form"}.$roles_element.length = 0;
-    if (numRoles == 0) {
-        opener.document.$env{"form.form"}.$roles_element.multiple=false;
-        opener.document.$env{"form.form"}.$roles_element.size=1;
-        opener.document.$env{"form.form"}.$roles_element.options[0] = new Option('No existing roles','',false,false);
-    } else {
-        if (numRoles == 1) {
-            opener.document.$env{"form.form"}.$roles_element.multiple=false;
-            opener.document.$env{"form.form"}.$roles_element.size=1;
-            opener.document.$env{"form.form"}.$roles_element.options[0] = new Option('Select','',true,true);
-            opener.document.$env{"form.form"}.$roles_element.options[1] = new Option(roleNamesArray[0],rolesArray[0],false,false);
+    my $output .= <<"ENDSCRIPT";
+<script type="text/javascript">
+function gochoose(cname,cdom,cdesc,multiple,caller) {
+    var openerForm = "$env{'form.form'}";
+    courseCount = 0;
+    var courses = '';
+    if (multiple) {
+        if (typeof(document.courselist.course_id.length) == 'undefined') {
+            // only 1 course checkbox was created
+            if (document.courselist.course_id.checked) {
+                courses = courses + document.courselist.course_id.value + "&&";
+                courseCount ++;
+            }
         } else {
-            for (var i=0; i<numRoles; i++) {
-                opener.document.$env{"form.form"}.$roles_element.options[i] = new Option(roleNamesArray[i],rolesArray[i],false,false);
+            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"}.$roles_element.multiple=true;
-            if (numRoles < 3) {
-                opener.document.$env{"form.form"}.$roles_element.size=numRoles;
+        }
+        opener.document.$env{'form.form'}.$elements{$type}{'total'}.value = courseCount;
+        if (typeof(opener.document.$env{'form.form'}.$elements{$type}{'name'}.length) ==
+            'undefined') {
+            if (opener.document.$env{'form.form'}.$elements{$type}{'name'}.value == 'specific') {
+                opener.document.$env{'form.form'}.$elements{$type}{'name'}.checked = true;
             } else {
-                opener.document.$env{"form.form"}.$roles_element.size=3;
+                opener.document.$env{'form.form'}.$elements{$type}{'name'}.checked = false;
             }
-            opener.document.$env{"form.form"}.$roles_element.options[0].selected = false;
-        }
-    }
-}
-
-function setStatus() {
-    var numStatus = $num_access;
-    var statusArray = new Array("$accesslist");
-    var statusNamesArray = new Array("$accessnameslist");
-    opener.document.$env{"form.form"}.$status_element.multiple=true;
-    opener.document.$env{"form.form"}.$status_element.size=3;
-    for (var i=0; i<numStatus; i++) {
-        opener.document.$env{"form.form"}.$status_element.options[i] = new Option(statusNamesArray[i],statusArray[i],false,false);
-    }
-}
-
-function setGroups() {
-    var numGroups = $num_groups;
-    var groupsArray = new Array("$groupslist");
-    opener.document.$env{"form.form"}.$groups_element.length = 0;
-    if (numGroups == 0) {
-        opener.document.$env{"form.form"}.$groups_element.multiple=false;
-        opener.document.$env{"form.form"}.$groups_element.size=1;
-        opener.document.$env{"form.form"}.$groups_element.options[0] = new Option('No existing groups','',false,false);
-    } else {
-        if (numGroups == 1) {
-            opener.document.$env{"form.form"}.$groups_element.multiple=false;
-            opener.document.$env{"form.form"}.$groups_element.size=1;
-            opener.document.$env{"form.form"}.$groups_element.options[0] = new Option('Select','',true,true);
-            opener.document.$env{"form.form"}.$groups_element.options[1] = new Option('No group','',false,false);
-            opener.document.$env{"form.form"}.$groups_element.options[2] = new Option(groupsArray[0],groupsArray[0],false,false);
         } else {
-            for (var i=0; i<numGroups; i++) {
-                opener.document.$env{"form.form"}.$groups_element.options[i] = new Option(groupsArray[i],groupsArray[i],false,false);
-            }
-            opener.document.$env{"form.form"}.$groups_element.multiple=true;
-            if (numGroups < 3) {
-                opener.document.$env{"form.form"}.$groups_element.size=numGroups;
-            } else {
-                opener.document.$env{"form.form"}.$groups_element.size=3;
+            for (var j=0; j<opener.document.$env{'form.form'}.$elements{$type}{'name'}.length; j++) {
+                if (opener.document.$env{'form.form'}.$elements{$type}{'name'}\[j].value == 'specific') {
+                    opener.document.$env{'form.form'}.$elements{$type}{'name'}\[j].checked = true;
+                } else {
+                    opener.document.$env{'form.form'}.$elements{$type}{'name'}\[j].checked = false;
+                }
             }
-            opener.document.$env{"form.form"}.$groups_element.options[0].selected = false;
         }
-    }
-}
-
-|;
-    return ($sec_element,$grplist_element,$setitems_function);
-
-}
-
-sub build_selection_lists {
-    my ($cdom,$cnum,$type,$needroles,$needaccess,$caller) = @_;
-    my ($sections,$groups,$allroles,$roleshash,$accesshash) = 
-          &Apache::loncommon::get_secgrprole_info($cdom,$cnum,$needroles,$type);
-    if ($caller eq 'portform') {
-        if (@{$sections} == 0) {
-            @{$sections} = ('none');
-        } else {
-            unshift(@{$sections},('all','none'));
+        if (courseCount > 0) {
+            courses = courses.substr(0,courses.length-2);
+            opener.document.$env{'form.form'}.$elements{$type}{'list'}.value = courses;
         }
-        if (@{$groups} == 0) {
-            @{$groups} = ('none');
-        } else {
-            unshift(@{$groups},('all','none'));
+    } else {
+        $name_code
+        opener.document.$env{'form.form'}.$env{'form.cnumelement'}.value=cname;
+        var slct=opener.document.$env{'form.form'}.$env{'form.cdomelement'};
+        if (slct.options == undefined) {
+            opener.document.$env{'form.form'}.$env{'form.cdomelement'}.value=cdom;
         }
-
-    } 
-    my $num_sections = scalar(@{$sections});
-    my $seclist = join('","',@{$sections});
-    my $num_groups = scalar(@{$groups});
-    my $groupslist = join('","',@{$groups});
-    my ($roleslist,$num_roles,$rolesnameslist,$num_access,$accesslist,
-        $accessnameslist);
-    if ($needroles) {
-        $num_roles = @{$allroles};
-        $roleslist = join('","',@{$allroles});
-        my @allrolesnames; 
-        foreach my $role (@{$allroles}) {
-            push(@allrolesnames,$$roleshash{$role});
-        }  
-        $rolesnameslist = join('","',@allrolesnames);
-    }
-    if ($needaccess) {
-        $num_access = keys(%{$accesshash});
-        my (@allaccess,@allaccessnames);
-        foreach my $key (sort(keys(%{$accesshash}))) {
-            push(@allaccess,$key);
-            push(@allaccessnames,$$accesshash{$key}); 
+        else {
+            var i;
+            for (i=0;i<slct.length;i++) {
+                if (slct.options[i].value==cdom) { slct.selectedIndex=i; }
+            }
         }
-        $accesslist = join('","',@allaccess);
-        $accessnameslist = join('","',@allaccessnames);
     }
-    return ($seclist,$num_sections,$groupslist,$num_groups,$roleslist,
-            $num_roles,$rolesnameslist,$accesslist,$num_access,$accessnameslist);
+    if (openerForm == 'portform') {
+        document.courselist.cnum.value = cname;
+        document.courselist.cdom.value = cdom;
+    }
+    $autosubmit
+    $lastaction
+}
+</script>
+ENDSCRIPT
+    return $output;
 }
 
 1;
 __END__
+
+=pod
+
+=head1 NAME
+
+Apache::lonpickcourse - Search for course(s) based on user-specified criteria.   
+
+=head1 SYNOPSIS
+
+Invoked by other LON-CAPA modules, when course(s) need to be selected by the user. 
+
+=head1 OVERVIEW
+
+Two screens are typically displayed to the user.  The first is a set of criteria which are used to constrain the search for courses.
+
+=head2 Search Criteria (Screen One)
+
+=head3 Criteria:
+
+=over 4
+
+=item *
+Course Activity - how recently was course last visited by anyone.
+
+=item *
+Course Domain - the domain of the course
+
+=item *
+Course Type - Course or Non-standard course
+
+=item *
+Course Institutional Code - the institutional identifier assigned to the course
+
+=item * 
+Course Owner's Username - the username of the owner of the course (assigned by the Domain Coordinator and/or when the course was created).
+
+=item *
+Course Owner's Domain - the domain of the owner of the course
+
+=item * 
+Course Description - text which appears in the Course Description (or title), as set in the Course Parameters.
+
+=item *
+Course ID - the internal course number (course ID part after initial 'domain_') used by LON-CAPA (this criterion is only displayed to Domain Coordinators selecting a course in the same domain as their DC role).
+
+=back
+
+The criteria setting screen is not displayed if course picking is done by a user who does not have advanced privileges (as defined by $env{'user.adv'}).
+
+=head2 Course Display (Screen Two)
+
+A list of courses matching the search criteria is displayed.  If the user is not an advanced user, screen one will have been skipped and the courses displayed will be all courses in which the user has currently active roles. The information displayed for each course is:
+
+=over 4
+
+=item *
+Course description
+
+=item *
+Domain description of course domain
+
+=item *
+Course institutional code
+
+=item * 
+Course owner (username:domain)   
+ 
+=back
+
+Depending on context, the display may include a single select box for each course, allowing selection of only a single course, or may include checkboxes allowing selection of more than one course.
+
+Following selection, and/or submission, the course description, number and domain are transferred to the browser window from which the course picker window was opened.  In most cases, the child window containing the course picker screens will be closed.  However, in some cases closure will be delayed until a third screen has been displayed (e.g., setting of course-based conditional access controls for portfolio files).  In this case the page is generated via /adm/portfolio and the page features select boxes to allow the user to select roles, access types, sections and groups.
+
+=head1 SUBROUTINES
+
+=over 4
+
+=item *
+X<create_user_javascript()>
+B<create_user_javascript($type)>:
+
+Input: 1 - $type  - the course type - Course or Non-standard course
+
+Output: 1 - $output - javascript wrapped in E<lt>scriptE<gt>E<lt>/scriptE<gt> tags 
+
+Side Effects: None 
+
+javascript code for reporting selected sections (as a string of comma separated sections) and groups in the selected course (as a comma separated list) then calling setSect() javscript function in the opener window (to populate section select box) then closing current window.
+
+
+=item *
+X<display_matched_courses()>
+B<display_matched_courses($r,$type,$multiple,%courses)>:
+
+Input: 4 - request object, course type, multiple (0 or 1), hash of courses.
+
+Output: 0
+
+Side Effects: prints select buttons (multiple = 0) or checkboxes (multiple = 1) and hidden form elements for selection of one or more courses which met search criteria.
+
+=item *
+X<multiples_tag()>
+B<multiples_tag()>:
+
+
+Input: 0
+
+Output: 2 - $jscript - javascript for check all/uncheck all checkboxes; $multelement - hidden form element with multiple set to 1.
+
+Side Effects: None
+
+=item *
+X<build_filters()>
+B<build_filters($filterlist,$type,$roleelement,$multelement,$filter)>:
+
+
+Input: 5 - anonymous array of search criteria; course type; $roleelement ; $multelement ; anonymous hash of criteria and their values.
+
+Output: 1 - $output - HTML for display of search criteria, and hidden form elements. 
+
+Side Effects: None
+
+=item *
+X<search_courses()>
+B<search_courses($r,$type,$onlyown,$filter)>:
+
+
+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.
+
+Output: 1 - %courses - hash of courses satisfying search criteria, keys = course IDs, values are corresponding colon-separated escaped description, institutional code, owner and type.
+
+Side Effects: None
+
+
+=item *
+X<course_chooser()>
+B<course_chooser($multiple,$cdom,$cnum,$cleandesc)>:
+
+Input: 4 - single (0) or multiple (1) courses; course domain, course number; course description. 
+
+Output: 1 - HTML for either checkbox (multiple=1) or select button (multiple=0) for user yo indicate course selection.
+
+Side Effects: None
+
+
+=item *
+X<gochoose_javascript()>
+B<gochoose_javascript($type,$autosubmit,$lastaction)>:
+
+Input: 3 - course type; in context of DC selecting a CC role in a course: javascript code from Apache::lonroles::processpick(); final action to take after user chooses course(s):  either close window, or submit form for display of next page etc.
+
+Output: 1  $output - javascript wrapped in E<lt>scriptE<gt>E<lt>/scriptE<gt> tags
+
+Side Effects: None
+
+javascript functions used when user selects a course(s). Different behavior depending on context:
+
+=back
+
+=over 8
+
+=item
+
+(a) Domain Coordinator using MAIL to select recipients of broadcast e-mail - && separated list of selected courses written to hidden form element in opener window. Child window closes.
+
+=item
+
+(b) Domain Coordinator choosing a course for adoption of a CC role from roles screen - write course identifying information to hidden form elements in opener window and automatically submit role selection form in opener window. Child window closes.
+
+=item
+
+(c) Domain Coordinator creating a course, and selecting a course to clone - course number and domain written to visible form elements in opener window. Child window closes.
+
+=item
+
+(d) User selecting a course for course-based conditional access control for a portfolio file - form is submitted, and new page is displayed for selection of roles, access types, sections and groups to be used in conditional ACL. New page is generated by /adm/portfolio. 
+
+=item
+
+(e) Domain Coordinator assigning a role to a user - form is submitted, and new page does an onload call to a javascript function to (a) write lists of sections and groups to hidden elements in opener window, (b) call function in opener window to dynamically populate select box showing current sections.
+
+=item
+
+(f) Author modifying a rights entry in a .rights file - selected course number and domain are witten to visible form elements in opener window.  Child window closes. 
+
+=item
+
+(g) Scantron Operator uploading a scantron file to a course - course number is written to visible form element in opener window. Child window closes.
+
+=back
+     
+=cut

--raeburn1163110709--