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

raeburn lon-capa-cvs@mail.lon-capa.org
Tue, 15 Nov 2005 21:08:47 -0000


This is a MIME encoded message

--raeburn1132088927
Content-Type: text/plain

raeburn		Tue Nov 15 16:08:47 2005 EDT

  Modified files:              
    /loncom/interface	lonnotify.pm lonhtmlcommon.pm 
  Log:
  Improvements to echo_form_input() and addition of set_form_elements() to facilitate movement back through a multi-page form using breadcrumb trail.  This type of use is implemented in lonnotify.  
  
  
--raeburn1132088927
Content-Type: text/plain
Content-Disposition: attachment; filename="raeburn-20051115160847.txt"

Index: loncom/interface/lonnotify.pm
diff -u loncom/interface/lonnotify.pm:1.7 loncom/interface/lonnotify.pm:1.8
--- loncom/interface/lonnotify.pm:1.7	Fri Oct 28 15:24:25 2005
+++ loncom/interface/lonnotify.pm	Tue Nov 15 16:08:47 2005
@@ -53,35 +53,50 @@
     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
                                             ['command']);
     my $command = $env{'form.command'};
+    my $origin = $env{'form.origin'};
+
     &Apache::lonhtmlcommon::clear_breadcrumbs();
     my %ltext=&Apache::lonlocal::texthash(
                'note' => 'Notification E-mail',
     );
     my $function = &Apache::loncommon::get_users_function();
+    my $loadcode;
     my $tablecolor = &Apache::loncommon::designparm($function.'.tabbg');
-    my $bodytag = &Apache::loncommon::bodytag('Broadcast e-mail to users');
+    if ((defined($env{'form.origin'})) && ($command eq 'compose' || $command eq 'pick_target' || $command eq 'pick_display')) {
+        unless ($env{'form.origin'} eq '') {
+            $loadcode = 'javascript:setFormElements(document.'.$env{'form.command'}.')';
+            if (($command eq 'pick_target') && (
+                     ($origin eq 'compose') || ($origin eq 'process'))) {
+                if ($env{'form.coursepick'} eq 'category') {
+                    $loadcode .= ';javascript:setCourseCat(document.'.$env{'form.command'}.')';
+                }
+            }
+        }
+    }
+    my $loaditems = ' onLoad="'.$loadcode.'" '; 
+    my $bodytag = &Apache::loncommon::bodytag('Broadcast e-mail to users',$function,$loaditems);
     my $html=&Apache::lonxml::xmlbegin();
     &Apache::lonhtmlcommon::add_breadcrumb
         ({href=>'/adm/notify',
           text=>"Broadcast E-mail"});
     if ($command eq 'process') {
-        &print_request_receipt($r,$cdom,$tablecolor,$bodytag,$html,\%ltext);
+        &print_request_receipt($r,$command,$cdom,$tablecolor,$bodytag,$html,\%ltext);
     } elsif ($command eq 'compose') {
-        &print_composition_form($r,$cdom,$tablecolor,$bodytag,$html,\%ltext);
+        &print_composition_form($r,$command,$cdom,$tablecolor,$bodytag,$html,\%ltext);
     } elsif ($command eq 'pick_target') {
-        &print_selection_form($r,$cdom,$tablecolor,$bodytag,$html,\%ltext);
+        &print_selection_form($r,$command,$cdom,$tablecolor,$bodytag,$html,\%ltext);
     } elsif ($command eq 'pick_display') {
-        &print_display_option_form($r,$cdom,$tablecolor,$bodytag,$html,\%ltext);
+        &print_display_option_form($r,$command,$cdom,$tablecolor,$bodytag,$html,\%ltext);
     } elsif ($command eq 'display') {
-        &print_display($r,$cdom,$tablecolor,$bodytag,$html,\%ltext);
+        &print_display($r,$command,$cdom,$tablecolor,$bodytag,$html,\%ltext);
     } else {
-        &print_front_page($r,$cdom,$tablecolor,$bodytag,$html,\%ltext);
+        &print_front_page($r,'front',$cdom,$tablecolor,$bodytag,$html,\%ltext);
     }
     return OK;
 }
 
 sub print_front_page {
-    my ($r,$cdom,$tablecolor,$bodytag,$html,$ltext) = @_;
+    my ($r,$formname,$cdom,$tablecolor,$bodytag,$html,$ltext) = @_;
     my $breadcrumbs = &Apache::lonhtmlcommon::breadcrumbs
             (undef,'Broadcast e-mail to Domain','Broadcast_system_email');
     my $jscript = qq|
@@ -110,7 +125,7 @@
 $breadcrumbs
 <br />
 ENDONE
-    $output .= '<form name="front" method="post">'.
+    $output .= '<form name="'.$formname.'" method="post">'.
               '<input type="hidden" name="command" />';
     $output .= &Apache::lonhtmlcommon::start_pick_box();
     $output .= '<table cellspacing="8" cellpadding="8">'.
@@ -129,14 +144,13 @@
 }
 
 sub print_display_option_form {
-    my ($r,$cdom,$tablecolor,$bodytag,$html,$ltext) = @_;
+    my ($r,$formname,$cdom,$tablecolor,$bodytag,$html,$ltext) = @_;
     &Apache::lonhtmlcommon::add_breadcrumb
          ({text=>"Display options"});
     my $breadcrumbs = &Apache::lonhtmlcommon::breadcrumbs
             (undef,'Broadcast e-mail display options','Broadcast_system_email');
     my $table_width = '';
     my $col_width = '200';
-    my $formname = 'display_options';
     my $cmd = 'display';
     my $submit_text = 'Display e-mail';
     my @roles = ('dc');
@@ -150,7 +164,22 @@
     my $enddateform = &Apache::lonhtmlcommon::date_setter($formname,
                                                           'enddate',
                                                           $now);
-    my $jscript;
+    my %elements = (
+        startdate_month => 'selectbox',
+        startdate_hour => 'selectbox',
+        enddate_month => 'selectbox',
+        enddate_hour => 'selectbox',
+        startdate_day => 'text',
+        startdate_year => 'text',
+        startdate_minute => 'text',
+        startdate_second => 'text',
+        enddate_day => 'text',
+        enddate_year => 'text',
+        enddate_minute => 'text',
+        enddate_second => 'text',
+        sender => 'checkbox',
+    );
+    my $jscript = &Apache::lonhtmlcommon::set_form_elements(\%elements);
     my $output = <<"ENDONE";
 $html
 <head>
@@ -199,9 +228,9 @@
 }
 
 sub print_display {
-    my ($r,$cdom,$tablecolor,$bodytag,$html,$ltext) = @_;
+    my ($r,$formname,$cdom,$tablecolor,$bodytag,$html,$ltext) = @_;
     &Apache::lonhtmlcommon::add_breadcrumb
-         ({href=>'/adm/notify?command=pick_display',
+         ({href=>"javascript:goBack('pick_display')",
           text=>"Display options"},
          {text=>"E-mail display"});
     my $breadcrumbs = &Apache::lonhtmlcommon::breadcrumbs
@@ -212,7 +241,6 @@
     my $rowColor2 = "#eeeeee";
     my $rowColor;
     my $msgcount = 0;
-    my $formname = 'display_sent';
     my $start = &Apache::lonhtmlcommon::get_date_from_form('startdate');
     my $end = &Apache::lonhtmlcommon::get_date_from_form('enddate');
     my @senders = &Apache::loncommon::get_env_multiple('form.sender');
@@ -221,9 +249,15 @@
     my %Sortby = ();
     my $jscript = <<"ENDSCRIPT";
 function changeSort(caller) {
+    document.$formname.command.value = '$formname';
     document.$formname.sortby.value = caller;
-    document.$formname.submit();   
+    document.$formname.submit();
+}
+function goBack(target) {
+    document.$formname.command.value = target;
+    document.$formname.submit();
 }
+
 ENDSCRIPT
     my $output = <<"ENDONE";
 $html
@@ -338,10 +372,16 @@
         $output .= '<tr bgcolor="#ffffff"><td>&nbsp;</td><td><br><center><i><b><small>&nbsp;&nbsp;No mail sent matching supplied criteria&nbsp;&nbsp;</small><br><br></b></i></td><td>&nbsp;</td></tr>';
     }
     $output .= &Apache::lonhtmlcommon::end_pick_box();
-    $output .= &echo_form_input();
-    unless (defined($env{'form.sortby'})) {
-        $output .= qq(<input type="hidden" name="sortby" value="date" />\n);
-    } 
+    $output .= &Apache::lonhtmlcommon::echo_form_input(['sortby','command','origin']);
+    my $curr_sortby;
+    if (defined($env{'form.sortby'})) {
+        $curr_sortby = $env{'form.sortby'};
+    } else {
+        $curr_sortby = 'date';
+    }
+    $output .= qq(<input type="hidden" name="origin" value="$formname" />\n);
+    $output .= qq(<input type="hidden" name="command" />\n);
+    $output .= qq(<input type="hidden" name="sortby" value="$curr_sortby" />\n);
     $output .= qq(
 </form>
 </body>
@@ -351,7 +391,7 @@
 }
 
 sub print_selection_form {
-    my ($r,$cdom,$tablecolor,$bodytag,$html,$ltext) = @_;
+    my ($r,$formname,$cdom,$tablecolor,$bodytag,$html,$ltext) = @_;
     my %coursecodes = ();
     my %codes = ();
     my @codetitles = ();
@@ -364,7 +404,6 @@
     my $totcodes = 0;
     my $format_reply;
     my $jscript = '';
-    my $formname = 'rolefilter';
     my $table_width = '100%';
     my $col_width = '200';
     my %lt=&Apache::lonlocal::texthash(
@@ -374,11 +413,6 @@
                'infs' => 'Internal, Filesystem and Local authentication: enter single default.',
                'comp' => 'Compose Message'
            );
-    my $loaditems = qq|
-function initialize_codes() {
-    return;
-}
-    |;
     &Apache::lonhtmlcommon::add_breadcrumb
           ({text=>"Select Audience"});
 
@@ -389,13 +423,60 @@
             my $numtypes = @codetitles;
             &Apache::lonsupportreq::build_code_selections(\%codes,\@codetitles,\%cat_titles,\%cat_order,\%idlist,\%idnums,\%idlist_titles);
             &Apache::lonsupportreq::javascript_code_selections($formname,$numtypes,\%cat_titles,\$jscript,\%idlist,\%idnums,\%idlist_titles,\@codetitles);
-            $loaditems = '';
         }
     }
 
     my $breadcrumbs = &Apache::lonhtmlcommon::breadcrumbs
             (undef,'Choose e-mail audience','Broadcast_system_email');
     my $cb_jscript = &Apache::loncommon::coursebrowser_javascript($cdom);
+
+    my %elements = (
+                     roles => 'selectbox',
+                     types => 'selectbox',
+                     Year => 'selectbox',
+                     coursepick => 'radio',
+                     coursetotal => 'text',
+                     courselist => 'text',
+                     internal => 'text',
+                     krb4 => 'text',
+                     krb5 => 'text',
+                     local => 'text',
+                     unix => 'text',
+                   );
+    $jscript .= &Apache::lonhtmlcommon::set_form_elements(\%elements);
+    if ($env{'form.coursepick'} eq 'category') {
+        $jscript .= qq|
+function setCourseCat(formname) {
+    if (formname.Year.options[formname.Year.selectedIndex].value == -1) {
+        return;
+    }
+    courseSet('Year');
+    for (var j=0; j<formname.Semester.length; j++) {
+        if (formname.Semester.options[j].value == "$env{'form.Semester'}") {
+            formname.Semester.options[j].selected = true;
+        }
+    }
+    if (formname.Semester.options[formname.Semester.selectedIndex].value == -1) {
+        return;
+    }
+    courseSet('Semester');
+    for (var j=0; j<formname.Department.length; j++) {
+        if (formname.Department.options[j].value == "$env{'form.Department'}") {
+            formname.Department.options[j].selected = true;
+        }
+    }
+    if (formname.Department.options[formname.Department.selectedIndex].value == -1) {
+        return;
+    }
+    courseSet('Department');
+    for (var j=0; j<formname.Number.length; j++) {
+        if (formname.Number.options[j].value == "$env{'form.Number'}") {
+            formname.Number.options[j].selected = true;
+        }
+    }
+}
+|; 
+    }
     my $output = <<"ENDONE";
 $html
 <head>
@@ -411,7 +492,7 @@
 <form method="post" name="$formname">
 ENDONE
    $output .= &Apache::lonhtmlcommon::start_pick_box($table_width);
-   my @roles = ('ow','cc','in','ta','ep','ad','st','cr');
+   my @roles = ('ow','cc','in','ta','ep','st','cr');
    my %longtypes = ();
    my %authtypes = ();
    &form_elements(\%longtypes,\%authtypes);
@@ -437,12 +518,18 @@
 }
 
 sub print_composition_form {
-    my ($r,$cdom,$tablecolor,$bodytag,$html,$ltext) = @_;
+    my ($r,$formname,$cdom,$tablecolor,$bodytag,$html,$ltext) = @_;
     &Apache::lonhtmlcommon::add_breadcrumb
-        ({href=>'/adm/notify?command=pick_target',
+        ({href=>"javascript:goBack('pick_target')",
           text=>"Select Audience"},
          {text=>"Compose Message"});
     my $jscript = &Apache::loncommon::check_uncheck_jscript();
+    $jscript .= qq|
+function goBack(target) {
+    document.$formname.command.value = target;
+    document.$formname.submit();
+}
+|;
     my $breadcrumbs = (&Apache::lonhtmlcommon::breadcrumbs
         (undef,'Broadcast e-mail to users','Broadcast_system_email'));
 
@@ -451,6 +538,14 @@
                       'nore' => 'No recipients identified',
                       'emad' => 'e-mail address',
                    );
+    my %elements = (
+                     subject => 'text',
+                     message => 'text',
+                     sender => 'text',
+                     recipient => 'checkbox',
+                   );
+    $jscript .= &Apache::lonhtmlcommon::set_form_elements(\%elements);
+
     $r->print(<<ENDONE);
 $html
 <head>
@@ -529,6 +624,7 @@
     my %recipients = ();
     my %users = ();
     my %access = ();
+    my @sections = ();
     my $totalrecip = 0;
     my @unmatched = ();
     foreach my $role (@roles) {
@@ -539,7 +635,7 @@
     }
     foreach my $course_id (keys(%courses)) {
         my ($cdom,$cnum) = split(/_/,$course_id);
-        &Apache::loncommon::get_course_users($cdom,$cnum,\%access,\@roles,\%users);
+        &Apache::loncommon::get_course_users($cdom,$cnum,\%access,\@roles,\@sections,\%users);
     }
     foreach my $role (keys(%users)) {
         foreach my $user (keys(%{$users{$role}})) {
@@ -553,7 +649,7 @@
             }
         }
     }
-    my $output  = '<form name="compose" method="post">'."\n";
+    my $output  = '<form name="'.$formname.'" method="post">'."\n";
   
     if ($totalrecip > 0) {
         $output .= &Apache::lonhtmlcommon::start_pick_box($table_width);
@@ -576,7 +672,7 @@
         foreach my $username (sort(keys(%recipients))) {
             if ($recipients{$username} =~ /\@/) {
                 my $value=&Apache::lonnet::escape($username).':'.&Apache::lonnet::escape($recipients{$username});
-                $output .= '<tr><td><input type="checkbox" name="recipient" value="'.$value.'" checked="checked" /></td><td>'.$username.'</td><td>&nbsp;&nbsp;</td><td>'.$recipients{$username}.'</td></tr>';
+                $output .= '<tr><td><input type="checkbox" name="recipient" value="'.$value.'" /></td><td>'.$username.'</td><td>&nbsp;&nbsp;</td><td>'.$recipients{$username}.'</td></tr>';
             }
         }
         $output .= '</table>';
@@ -595,9 +691,11 @@
         $output .= &Apache::lonhtmlcommon::submit_row($col_width,$tablecolor,&mt('Submit'),'process',&mt('Send Message'));
         $output .= &Apache::lonhtmlcommon::end_pick_box();
     } else {
-        $output .= $lt{'nore'};
+        $output .= $lt{'nore'}."\n".
+                   '<input type="hidden" name="command" value="" />'."\n";
     }
-    $output .= &echo_form_input('command');
+    $output .= '<input type="hidden" name="origin" value="'.$formname.'" />'."\n";
+    $output .= &Apache::lonhtmlcommon::echo_form_input(['command','origin','subject','message','recipient','sender'],);
     $output .= '</form></body></html>';
     $r->print($output);
     return;
@@ -605,25 +703,25 @@
 
 
 sub print_request_receipt {
-    my ($r,$dom,$tablecolor,$bodytag,$html,$ltext) =@_;
+    my ($r,$formname,$dom,$tablecolor,$bodytag,$html,$ltext) =@_;
     my @recipients = &Apache::loncommon::get_env_multiple('form.recipient');
     my $subject = $env{'form.subject'};
     my $message = $env{'form.message'};
     my $from = $env{'form.sender'};
     my $jscript = <<ENDSCRIPT;
-function showCompose() {
-    document.goback.command.value = 'compose';
-    document.goback.submit();
+function goBack(target) {
+    document.$formname.command.value = target;
+    document.$formname.submit();
 }
 ENDSCRIPT
     &Apache::lonhtmlcommon::add_breadcrumb
-        ({href=>'/adm/notify?command=pick_target',
+        ({href=>"javascript:goBack('pick_target')",
           text=>"Select audience"});
     &Apache::lonhtmlcommon::add_breadcrumb
-        ({href=>'javascript:showCompose()',
+        ({href=>"javascript:goBack('compose')",
           text=>"Compose Message"});
     &Apache::lonhtmlcommon::add_breadcrumb
-        ({href=>'/adm/notify?command=process',
+        ({href=>"/adm/notify?command=process",
           text=>"Outcome"});
     my $breadcrumbs = &Apache::lonhtmlcommon::breadcrumbs
             (undef,'E-mail Delivery','Broadcast_system_email');
@@ -631,14 +729,14 @@
 $html
 <head>
  <title>LON-CAPA Notification E-mail</title>
-<script type"text/javascript">
+<script type="text/javascript">
 $jscript
 </script>
 </head>
 $bodytag
 $breadcrumbs
 <br />
-<form name="goback" method="post">
+<form name="$formname" method="post">
 ENDONE
     $output .= &Apache::lonhtmlcommon::start_pick_box();
     my @deliveries = ();
@@ -674,7 +772,9 @@
     }
     $output .= &Apache::lonhtmlcommon::end_pick_box();
     $output .= '<br /><a href="/adm/notify">Send another message?</a>'."\n";
-    $output .= &echo_form_input();
+    $output .= '<input type="hidden" name="command" />'."\n".
+               '<input type="hidden" name="origin" value="'.$formname.'" />'."\n";
+    $output .= &Apache::lonhtmlcommon::echo_form_input(['command','origin']);
     $output .= '
 </form>
 </body>
@@ -685,7 +785,7 @@
 
 sub broadcast_email {
     my ($recipients,$subject,$from,$message,$deliveries,$ltext)=@_;
-# find some way to spread out delivery for large numbers of recipients.
+# Should implement staggered delivery for large numbers of recipients?.
     foreach my $user (@{$recipients}) {
         my $msg = new Mail::Send;
         my ($username,$to) = split(/:/,$user);
@@ -845,30 +945,10 @@
     return %content;
 }
 
-sub echo_form_input {
-    my (@excluded) = @_;
-    my $output = '';
-    foreach my $key (keys(%env)) {
-        if ($key =~ /^form\.(.+)$/) {
-            if ((!@excluded) || (!grep/^$1$/,@excluded)) {
-                if (ref($env{$key})) {
-                    foreach my $value (@{$env{$key}}) {
-                        $output .= qq(<input type="hidden" name="$1" value="$value" />\n);
-                    }
-                } else {
-                    $output .= qq(<input type="hidden" name="$1" value="$env{$key}" />\n);
-                }
-            }
-        }
-    }
-    return $output;
-}
-
 sub cr_to_br {
     my $incoming = shift;
     $incoming =~ s/\n/\<br \/\>/g;
     return $incoming;
 }
 
-
 1;
Index: loncom/interface/lonhtmlcommon.pm
diff -u loncom/interface/lonhtmlcommon.pm:1.118 loncom/interface/lonhtmlcommon.pm:1.119
--- loncom/interface/lonhtmlcommon.pm:1.118	Tue Nov 15 15:46:40 2005
+++ loncom/interface/lonhtmlcommon.pm	Tue Nov 15 16:08:47 2005
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # a pile of common html routines
 #
-# $Id: lonhtmlcommon.pm,v 1.118 2005/11/15 20:46:40 raeburn Exp $
+# $Id: lonhtmlcommon.pm,v 1.119 2005/11/15 21:08:47 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -1337,7 +1337,7 @@
     if (defined($title)) {
         $output = &row_title($col_width,$tablecolor,$title);
     }
-    $output .= qq|               <td>
+    $output .= qq|               <td valign="top">
                                   <select name="roles" multiple >\n|;
     foreach my $role (@$roles) {
         my $plrole;
@@ -1444,7 +1444,7 @@
     if (defined($title)) {
         $output = &row_title($col_width,$tablecolor,$title);
     }
-    $output .= qq|              <td>
+    $output .= qq|              <td valign="top">
                                     <select name="types" multiple>\n|;
     foreach my $status_type (sort(keys(%{$types}))) {
         $output .= '  <option value="'.$status_type.'">'.$$types{$status_type}.'</option>';
@@ -1500,6 +1500,194 @@
     return $output;
 }
 
+##############################################
+##############################################
+                                                                             
+# echo_form_input
+#
+# Generates html markup to add form elements from the referrer page
+# as hidden form elements (values encoded) in the new page.
+#
+# Intended to support two types of use 
+# (a) to allow backing up to earlier pages in a multi-page 
+# form submission process using a breadcrumb trail.
+#
+# (b) to allow the current page to be reloaded with form elements
+# set on previous page to remain unchanged.  An example would
+# be where the a page containing a dynamically-built table of data is 
+# is to be redisplayed, with only the sort order of the data changed. 
+#  
+# Inputs:
+# 1. Reference to array of form elements in the submitted form on 
+# the referrer page which are to be excluded from the echoed elements.
+#
+# 2. Reference to array of regular expressions, which if matched in the  
+# name of the form element n the referrer page will be omitted from echo. 
+#
+# Outputs: A scalar containing the html markup for the echoed form
+# elements (all as hidden elements, with values encoded). 
+
+
+sub echo_form_input {
+    my ($excluded,$regexps) = @_;
+    my $output = '';
+    foreach my $key (keys(%env)) {
+        if ($key =~ /^form\.(.+)$/) {
+            my $name = $1;
+            my $match = 0;
+            if ((!@{$excluded}) || (!grep/^$name$/,@{$excluded})) {
+                if (defined($regexps)) {
+                    if (@{$regexps} > 0) {
+                        foreach my $regexp (@{$regexps}) {
+                            if ($name =~ /\Q$regexp\E/) {
+                                $match = 1;
+                                last;
+                            }
+                        }
+                    }
+                }
+                if (!$match) {
+                    if (ref($env{$key})) {
+                        foreach my $value (@{$env{$key}}) {
+                            $value = &HTML::Entities::encode($value,'<>&"');
+                            $output .= '<input type="hidden" name="'.$name.
+                                             '" value="'.$value.'" />'."\n";
+                        }
+                    } else {
+                        my $value = &HTML::Entities::encode($env{$key},'<>&"');
+                        $output .= '<input type="hidden" name="'.$name.
+                                             '" value="'.$value.'" />'."\n";
+                    }
+                }
+            }
+        }
+    }
+    return $output;
+}
+
+##############################################
+##############################################
+                                                                             
+# set_form_elements
+#
+# Generates javascript to set form elements to values based on
+# corresponding values for the same form elements when the page was
+# previously submitted.
+#     
+# Last submission values are read from hidden form elements in referring 
+# page which have the same name, i.e., generated by &echo_form_input(). 
+#
+# Intended to be called by onload event.
+#
+# Input:
+# Reference to hash of echoed form elements to be set.
+#
+# In the hash, keys are the form element names, and the values are the
+# element type (selectbox, radio, checkbox or text -for textbox, textarea or
+# hidden).
+# 
+# Output:
+#  
+# javascript function - set_form_elements() which sets form elements,
+# expects an argument: formname - the name of the form according to 
+# the DOM, e.g., document.compose
+
+sub set_form_elements {
+    my ($elements) = @_;
+    my $output .= 'function setFormElements(courseForm) {
+';      
+    foreach my $key (keys(%env)) {
+        if ($key =~ /^form\.(.+)$/) {
+            my $name = $1;
+            if (exists($$elements{$name})) {
+                my @values = &Apache::loncommon::get_env_multiple($key);
+                for (my $i=0; $i<@values; $i++) {
+                    $values[$i] = &HTML::Entities::decode($values[$i],'<>&"');
+                    $values[$i] =~ s/([\r\n\f]+)/\\n/g;
+                    $values[$i] =~ s/"/\\"/g;
+                }
+                if ($$elements{$name} eq 'text') {
+                    my $numvalues = @values;
+                    if ($numvalues > 1) {
+                        my $valuestring = join('","',@values);
+                        $output .= qq|
+  var textvalues = new Array ("$valuestring");
+  var total = courseForm.$name.length;
+  if (total > $numvalues) {
+      total = $numvalues;
+  }    
+  for (var i=0; i<total; i++) {
+      courseForm.$name\[i].value = textvalues[i];
+  }
+|;
+                    } else {
+                        $output .= qq|
+  courseForm.$name.value = "$values[0]";
+|;
+                    }
+                } else {
+                    $output .=  qq|
+  var elementLength = courseForm.$name.length;
+  if (elementLength==undefined) {
+|;
+                    foreach my $value (@values) {
+                        if ($$elements{$name} eq 'selectbox') {
+                            $output .=  qq|
+      if (courseForm.$name.options[0].value == "$value") {
+          courseForm.$name.options[0].selected = true;
+      }|;
+                        } elsif (($$elements{$name} eq 'radio') ||
+                                 ($$elements{$name} eq 'checkbox')) {
+                            $output .= qq|
+      if (courseForm.$name.value == "$value") {
+          courseForm.$name.checked = true;
+      }|;
+                        }
+                    }
+                    $output .= qq|
+  }
+  else {
+      for (var i=0; i<courseForm.$name.length; i++) {
+|;
+                    if ($$elements{$name} eq 'selectbox') {
+                        $output .=  qq|
+          courseForm.$name.options[i].selected = false;|;
+                    } elsif (($$elements{$name} eq 'radio') || 
+                             ($$elements{$name} eq 'checkbox')) {
+                        $output .= qq|
+          courseForm.$name\[i].checked = false;|; 
+                    }
+                    $output .= qq|
+      }
+      for (var j=0; j<courseForm.$name.length; j++) {
+|;
+                    foreach my $value (@values) {
+                        if ($$elements{$name} eq 'selectbox') {
+                            $output .=  qq|
+          if (courseForm.$name.options[j].value == "$value") {
+              courseForm.$name.options[j].selected = true;
+          }|;
+                        } elsif (($$elements{$name} eq 'radio') ||
+                                 ($$elements{$name} eq 'checkbox')) { 
+                            $output .= qq|
+          if (courseForm.$name\[j].value == "$value") {
+              courseForm.$name\[j].checked = true;
+          }|;
+                        }
+                    }
+                    $output .= qq|
+      }
+  }
+|;
+                }
+            }
+        }
+    }
+    $output .= "
+}\n";
+    return $output;
+}
+
 1;
 
 __END__

--raeburn1132088927--