--- loncom/interface/lonfeedback.pm	2004/11/20 20:40:51	1.143
+++ loncom/interface/lonfeedback.pm	2005/03/01 03:21:04	1.155
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # Feedback
 #
-# $Id: lonfeedback.pm,v 1.143 2004/11/20 20:40:51 raeburn Exp $
+# $Id: lonfeedback.pm,v 1.155 2005/03/01 03:21:04 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -68,13 +68,18 @@ sub discussion_visible {
 }
 
 sub list_discussion {
-    my ($mode,$status,$ressymb)=@_;
+    my ($mode,$status,$ressymb,$imsextras)=@_;
     my $outputtarget=$ENV{'form.grade_target'};
     if (defined($ENV{'form.export'})) {
 	if($ENV{'form.export'}) {
             $outputtarget = 'export';
         }
     }
+    if (defined($imsextras)) {
+        if ($$imsextras{'caller'} eq 'imsexport') {
+            $outputtarget = 'export';
+        }
+    }
     if (not &discussion_visible($status)) { return ''; }
     my @bgcols = ("#cccccc","#eeeeee");
     my $discussiononly=0;
@@ -151,13 +156,18 @@ sub list_discussion {
         %roleshash = &Apache::lonnet::dump('nohist_userroles',$ENV{'course.'.$ENV{'request.course.id'}.'.domain'},$ENV{'course.'.$ENV{'request.course.id'}.'.num'});
         foreach (keys %roleshash) {
             my ($role,$uname,$udom,$sec) = split/:/,$_;
+            if ($role =~ /^cr/) {
+                $role = 'cr';
+            }
             my ($end,$start) = split/:/,$roleshash{$_};
             my $now = time;
             my $status = 'Active';
             if (($now < $start) || ($end > 0 && $now > $end)) {
                 $status = 'Expired';
             }
-            push @{$roleinfo{$uname.':'.$udom}}, $role.':'.$sec.':'.$status;
+            if ($uname && $udom) { 
+                push @{$roleinfo{$uname.':'.$udom}}, $role.':'.$sec.':'.$status;
+            }
         }
         my ($classlist) = &Apache::loncoursedata::get_classlist(
                               $ENV{'request.course.id'},
@@ -320,15 +330,26 @@ sub list_discussion {
         } elsif ($outputtarget eq 'export') {
 # Create temporary directory if this is an export
             my $now = time;
-            $tempexport = $Apache::lonnet::perlvar{'lonDaemons'}.'/tmp/ims_exports';
-            if (!-e $tempexport) {
-                mkdir($tempexport,0700);
-            }
-            $tempexport .= '/'.$now;
-            if (!-e $tempexport) {
-                mkdir($tempexport,0700);
+            if ((defined($imsextras)) && ($$imsextras{'caller'} eq 'imsexport')) {
+                $tempexport = $$imsextras{'tempexport'};
+                if (!-e $tempexport) {
+                    mkdir($tempexport,0700);
+                }
+                $tempexport .= '/'.$$imsextras{'count'};
+                if (!-e $tempexport) {
+                    mkdir($tempexport,0700);
+                }
+            } else {
+                $tempexport = $Apache::lonnet::perlvar{'lonDaemons'}.'/tmp/ims_exports';
+                if (!-e $tempexport) {
+                    mkdir($tempexport,0700);
+                }
+                $tempexport .= '/'.$now;
+                if (!-e $tempexport) {
+                    mkdir($tempexport,0700);
+                }
+                $tempexport .= '/'.$ENV{'user.domain'}.'_'.$ENV{'user.name'};
             }
-            $tempexport .= '/'.$ENV{'user.domain'}.'_'.$ENV{'user.name'};
             if (!-e $tempexport) {
                 mkdir($tempexport,0700);
             }
@@ -408,7 +429,7 @@ imscp_v1p1.xsd http://www.imsglobal.org/
             if ($numhidden > 0) {
                 my $colspan = $maxdepth+1;
                 $discussion.="\n".'<tr><td bgcolor="#CCCCCC" colspan="'.$colspan.'">'.
-                         '<a href="/adm/feedback?allposts='.$ressymb;
+                         '<a href="/adm/feedback?allposts=1&amp;symb='.$ressymb;
                 if ($newpostsflag) {
                     $discussion .= '&previous='.$prevread;
                 }
@@ -446,13 +467,12 @@ imscp_v1p1.xsd http://www.imsglobal.org/
                  }
             }
         } else {
-            $sortposts = 'ascdate';
             @showposts =  (sort { $a <=> $b } keys %alldiscussion);
         }
         my $currdepth = 0;
         my $firstidx = $alldiscussion{$showposts[0]};
         foreach (@showposts) {
-            unless (($sortposts eq 'thread') || ($sortposts eq 'ascdate' && $ENV{'environment.threadeddiscussion'}) || ($outputtarget eq 'export')) {
+            unless (($sortposts eq 'thread') || (($sortposts eq '') && ($ENV{'environment.threadeddiscussion'})) || ($outputtarget eq 'export')) {
                 $alldiscussion{$_} = $_;
             }
             unless ( ($notshown{$alldiscussion{$_}} eq '1') || ($shown{$alldiscussion{$_}} == 0) ) {
@@ -492,8 +512,8 @@ imscp_v1p1.xsd http://www.imsglobal.org/
         $imsitems{$alldiscussion{$_}}{'isvisible'}.'" identifieref="RES-'.$ressymb.'-'.$alldiscussion{$_}.'">'.
         '<title>'.$imsitems{$alldiscussion{$_}}{'title'}.'</title>';
                         $imsresources .= "\n".
-    '<resource identifier="RES-'.$ressymb.'-'.$alldiscussion{$_}.'" type="webcontent" href="'.$postfilename.'">'.
-      '<file href="'.$alldiscussion{$_}.'.html">'."\n".
+    '<resource identifier="RES-'.$ressymb.'-'.$alldiscussion{$_}.'" type="webcontent" href="'.$postfilename.'">'."\n".
+      '<file href="'.$postfilename.'">'."\n".
       $imsfiles{$alldiscussion{$_}}{$imsitems{$alldiscussion{$_}}{'currversion'}}."\n".
     '</resource>';
                     }
@@ -550,7 +570,7 @@ END
             $discussion .= <<END;
                    </font></td>
                    <td>&nbsp;</td>
-                   <td>
+                   <td align="left">
                     <font size="-1"><b><a href="$chglink">$lt{'chgt'}</a>?</font></b>
                    </td>
                   </tr>
@@ -565,13 +585,13 @@ END
 
                 $discussion .= '<td><font size="-1"><b>'.&mt('Sorted by').'</b>: '.$sort_types{$sortposts}.'<br />';
                 if (defined($ENV{'form.totposters'})) {
-                    $discussion .= &mt('Posts by').': ';
+                    $discussion .= &mt('Posts by').':';
                     if ($totposters > 0) {
                         foreach my $poster (@posters) {
                             $poster =~ s/:/\@/;
-                            $discussion .= $poster.',';
+                            $discussion .= ' '.$poster.',';
                         }
-                        $discussion =~ s/,//;
+                        $discussion =~ s/,$//;
                     } else {
                         $discussion .= &mt('None selected');
                     }
@@ -582,11 +602,12 @@ END
                         $filterchoice .= '&nbsp;&nbsp;&nbsp; ';
                     }
                     if (@rolefilter > 0) {
-                        $filterchoice .= '<i>'.&mt('roles').'</i>-&nbsp;';
+                        $filterchoice .= '<i>'.&mt('roles').'</i>-';
                         foreach (@rolefilter) {
-                            $filterchoice .= $role_types{$_}.',&nbsp;';
+                            $filterchoice .= '&nbsp;'.$role_types{$_}.',';
                         }
-                        $filterchoice .= '&nbsp;&nbsp;&nbsp; ';
+                        $filterchoice =~ s/,$//;
+                        $filterchoice .= '<br />&nbsp;&nbsp&nbsp;&nbsp;&nbsp;&nbsp;&nbsp&nbsp;';
                     }
                     if ($statusfilter) {
                         $filterchoice .= '<i>'.&mt('status').'</i>-&nbsp;'.$status_types{$statusfilter};
@@ -629,27 +650,31 @@ END
 </manifest>
                 |;
                 close($manifestfile);
+                if ((defined($imsextras)) && ($$imsextras{'caller'} eq 'imsexport')) {
+                    $discussion = $copyresult;
+                } else {
 
 #Create zip file in prtspool
 
-                my $imszipfile = '/prtspool/'.
-                $ENV{'user.name'}.'_'.$ENV{'user.domain'}.'_'.
-                     time.'_'.rand(1000000000).'.zip';
+                    my $imszipfile = '/prtspool/'.
+                    $ENV{'user.name'}.'_'.$ENV{'user.domain'}.'_'.
+                         time.'_'.rand(1000000000).'.zip';
     # zip can cause an sh launch which can pass along all of %ENV
     # which can be too large for /bin/sh to handle
-                my %oldENV=%ENV;
-                undef(%ENV);
-                my $cwd = &getcwd(); 
-                my $imszip = '/home/httpd/'.$imszipfile;
-                chdir $tempexport;
-                open(OUTPUT, "zip -r $imszip *  2> /dev/null |");
-                close(OUTPUT);
-                chdir $cwd;
-                %ENV=%oldENV;
-                undef(%oldENV);
-                $discussion .= 'Download the zip file from <a href="'.$imszipfile.'">Discussion Posting Archive</a><br />';
-                if ($copyresult) {
-                    $discussion .= 'The following errors occurred during export - <br />'.$copyresult;
+                    my %oldENV=%ENV;
+                    undef(%ENV);
+                    my $cwd = &getcwd(); 
+                    my $imszip = '/home/httpd/'.$imszipfile;
+                    chdir $tempexport;
+                    open(OUTPUT, "zip -r $imszip *  2> /dev/null |");
+                    close(OUTPUT);
+                    chdir $cwd;
+                    %ENV=%oldENV;
+                    undef(%oldENV);
+                    $discussion .= 'Download the zip file from <a href="'.$imszipfile.'">Discussion Posting Archive</a><br />';
+                    if ($copyresult) {
+                        $discussion .= 'The following errors occurred during export - <br />'.$copyresult;
+                    }
                 }
             } else {
                 $discussion .= '<br />Unfortunately you will not be able to retrieve an archive of the discussion posts at this time, because there was a problem creating a manifest file.<br />';
@@ -724,7 +749,7 @@ ENDDISCUSS
 	    if ($outputtarget ne 'tex') {
 		$discussion.='<table bgcolor="#BBBBBB"><tr><td><a href="/adm/feedback?replydisc='.
 		    $ressymb.':::" '.$target.'>'.
-		    '<img src="/adm/lonMisc/chat.gif" border="0" />'.
+		    '<img src="'.&Apache::loncommon::lonhttpdurl('/adm/lonMisc/chat.gif').'" border="0" />'.
 		    &mt('Post Discussion').'</a></td></tr></table>';
 	    }
 	}
@@ -763,7 +788,7 @@ sub build_posting_display {
 	    my $origindex='0.';
             my $numoldver=0;
 	    if ($contrib{$idx.':replyto'}) {
-                if ( (($ENV{'environment.threadeddiscussion'}) && (($sortposts eq '') || ($sortposts eq 'ascdate'))) || ($sortposts eq 'thread') || ($outputtarget eq 'export')) {
+                if ( (($ENV{'environment.threadeddiscussion'}) && ($sortposts eq '')) || ($sortposts eq 'thread') || ($outputtarget eq 'export')) {
 # this is a follow-up message
 		    $original[$idx]=$original[$contrib{$idx.':replyto'}];
 		    $$depth[$idx]=$$depth[$contrib{$idx.':replyto'}]+1;
@@ -949,16 +974,16 @@ sub build_posting_display {
                             $contrib{$idx.':sendername'},$contrib{$idx.':senderdomain'},$ressymb);
 		        }
                         if ($$dischash{$readkey}=~/\.$idx\./) { 
-                            $ctlink = '<b>'.&mt('Mark unread').'?</b>&nbsp;<input type="checkbox" name="postunread_'.$idx.'" />';
+                            $ctlink = '<label><b>'.&mt('Mark unread').'?</b>&nbsp;<input type="checkbox" name="postunread_'.$idx.'" /></label>';
                         } else {
-                            $ctlink = '<b>'.&mt('Mark read').'?</b>&nbsp;<input type="checkbox" name="postread_'.$idx.'" />';
+                            $ctlink = '<label><b>'.&mt('Mark read').'?</b>&nbsp;<input type="checkbox" name="postread_'.$idx.'" /></label>';
                         }
                     }
 #figure out at what position this needs to print
                 }
                 if ($outputtarget eq 'export' || $message) {
 		    my $thisindex=$idx;
-		    if ( (($ENV{'environment.threadeddiscussion'}) && (($sortposts eq '') || ($sortposts eq 'ascdate'))) || ($sortposts eq 'thread') || ($outputtarget eq 'export')) {
+		    if ( (($ENV{'environment.threadeddiscussion'}) && ($sortposts eq '')) || ($sortposts eq 'thread') || ($outputtarget eq 'export')) {
 			$thisindex=$origindex.substr('00'.$$replies[$$depth[$idx]],-2,2);
 		    }
 		    $$alldiscussion{$thisindex}=$idx;
@@ -1016,6 +1041,7 @@ sub build_posting_display {
                                             my $cc_regexp = $roleregexp.':[^:]*:'.$statusregexp;
                                             if ($role =~ /$cc_regexp/) {
                                                 $$shown{$idx} = 1;
+                                                last;
                                             }
                                         } elsif ($role =~ /^$rolematch$/) {
                                             $$shown{$idx} = 1;
@@ -1410,8 +1436,9 @@ END
   my $latexHelp=&Apache::loncommon::helpLatexCheatsheet();
   my $htmlheader=&Apache::lonhtmlcommon::htmlareaheaders();
   my $send=&mt('Send');
+  my $html=&Apache::lonxml::xmlbegin();
   $r->print(<<END);
-<html>
+$html
 <head>
 <title>The LearningOnline Network with CAPA</title>
 <meta http-equiv="pragma" content="no-cache"></meta>
@@ -1635,8 +1662,9 @@ sub print_display_options {
         $currtogg = $lt{'toggon'};
         $disctogg = 'toggon';
     }
+    my $html=&Apache::lonxml::xmlbegin();
     $r->print(<<END);
-<html>
+$html
 <head>
 <title>$lt{'dido'}</title>
 <meta http-equiv="pragma" content="no-cache" />
@@ -1727,18 +1755,18 @@ $lt{'sdpf'}<br/> $lt{'prca'}  <ol><li>$l
        <tr bgcolor="#dddddd">
        <td>$lt{'disa'}</td>
        <td>$lt{$discdisp}</td>
-       <td><input type="checkbox" name="discdisp" onClick="discdispChk('0')" />&nbsp;$lt{'chgt'} "$dispchangeA"
+       <td><label><input type="checkbox" name="discdisp" onClick="discdispChk('0')" />&nbsp;$lt{'chgt'} "$dispchangeA"</label>
            <br />
-           <input type="checkbox" name="discdisp" onClick="discdispChk('1')" />&nbsp;$lt{'chgt'} "$dispchangeB"
+           <label><input type="checkbox" name="discdisp" onClick="discdispChk('1')" />&nbsp;$lt{'chgt'} "$dispchangeB"</label>
        </td>
       </tr><tr bgcolor="#eeeeee">
        <td>$lt{'npmr'}</td>
        <td>$lt{$discmark}</td>
-       <td><input type="checkbox" name="discmark" />$lt{'chgt'} "$markchange"</td>
+       <td><label><input type="checkbox" name="discmark" />$lt{'chgt'} "$markchange"</label></td>
       </tr><tr bgcolor="#dddddd">
        <td>$lt{'dotm'}</td>
        <td>$lt{$disctogg}</td>
-       <td><input type="checkbox" name="disctogg" onClick="discdispChk('2')" />$lt{'chgt'} "$toggchange"</td>
+       <td><label><input type="checkbox" name="disctogg" onClick="discdispChk('2')" />$lt{'chgt'} "$toggchange"</label></td>
       </tr>
      </table>
     </td>
@@ -1776,30 +1804,13 @@ sub print_sortfilter_options {
     my $section_sel = '';
     my $numsections = 0;
     my $numvisible = 5;
-    my ($classlist) = &Apache::loncoursedata::get_classlist(
-                              $ENV{'request.course.id'},
-                              $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
-                              $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
-                                                                                   
-    my $sec_index = &Apache::loncoursedata::CL_SECTION();
-    my $status_index = &Apache::loncoursedata::CL_STATUS();
     my %sectioncount = ();
-    while (my ($student,$data) = each %$classlist) {
-        my ($section,$status) = ($data->[$sec_index],
-                                 $data->[$status_index]);
-        unless ($section eq '' || $section =~ /^\s*$/) {
-            if (!defined($sectioncount{$section})) {
-                $sectioncount{$section} = 1;
-                $numsections ++;
-            } else {
-                $sectioncount{$section} ++;
-            }
-        }
-    }
-                                                                                   
-    if ($ENV{'request.course.sec'} !~ /^\s*$/) {
-        @sections = ($ENV{'request.course.sec'});
-        $numvisible = 1;
+
+    $numsections = &Apache::loncommon::get_sections($ENV{'course.'.$ENV{'request.course.id'}.'.domain'},$ENV{'course.'.$ENV{'request.course.id'}.'.num'},\%sectioncount);
+
+    if ($ENV{'request.course.sec'} !~ /^\s*$/) {  #Restrict section choice to current section 
+        @sections = ('all',$ENV{'request.course.sec'});
+        $numvisible = 2;
     } else {
         @sections = sort {$a cmp $b} keys(%sectioncount);
         unshift(@sections,'all'); # Put 'all' at the front of the list
@@ -1834,12 +1845,36 @@ sub print_sortfilter_options {
     my %role_types = ();
     my %status_types = ();
     &sort_filter_names(\%sort_types,\%role_types,\%status_types);
-
+    my $html=&Apache::lonxml::xmlbegin();
     $r->print(<<END);
-<html>
+$html
 <head>
 <title>$lt{'diso'}</title>
 <meta http-equiv="pragma" content="no-cache" />
+<script type="text/javascript">
+function verifyFilter() {
+    var rolenum = 0
+    for (var i=0; i<document.modifyshown.rolefilter.length; i++) {
+        if (document.modifyshown.rolefilter.options[i].selected == true) {
+            rolenum ++
+        }
+    }
+    if (rolenum == 0) {
+        document.modifyshown.rolefilter.options[0].selected = true
+    }
+
+    var secnum = 0
+    for (var i=0; i<document.modifyshown.sectionpick.length; i++) {
+        if (document.modifyshown.sectionpick.options[i].selected == true) {
+            secnum ++
+        }
+    }
+    if (secnum == 0) {
+        document.modifyshown.sectionpick.options[0].selected = true
+    }
+    document.modifyshown.submit();
+}
+</script>
 </head>
 $bodytag
 <form name="modifyshown" method="post" action="/adm/feedback">
@@ -1860,7 +1895,7 @@ $bodytag
  <tr>
   <td align="center">
    <select name="sortposts">
-    <option value="ascdate" />$sort_types{'ascdate'}
+    <option value="ascdate" selected="selected" />$sort_types{'ascdate'}
     <option value="descdate" />$sort_types{'descdate'}
     <option value="thread" />$sort_types{'thread'}
     <option value="subject" />$sort_types{'subject'}
@@ -1871,7 +1906,7 @@ $bodytag
   <td>&nbsp;</td>
   <td align="center">
    <select name="statusfilter">
-    <option value="all" />$status_types{'all'}
+    <option value="all" selected="selected" />$status_types{'all'}
     <option value="Active" />$status_types{'Active'}
     <option value="Expired" />$status_types{'Expired'}
    </select>
@@ -1896,14 +1931,14 @@ $bodytag
    </select>
   </td>
   <td>&nbsp;</td>
-  <td><input type="checkbox" name="posterlist" value="$symb" />$lt{'shal'}</td>
+  <td><label><input type="checkbox" name="posterlist" value="$symb" />$lt{'shal'}</label></td>
  </tr>
 </table>
 <br />
 <br />
 <input type="hidden" name="previous" value="$previous" />
 <input type="hidden" name="applysort" value="$symb" />
-<input type="button" name="sub" value="Store Changes" onClick="javascript:document.modifyshown.submit()" />
+<input type="button" name="sub" value="Store Changes" onClick="verifyFilter()" />
 <br />
 <br />
 </form>
@@ -1915,6 +1950,9 @@ END
 sub print_showposters {
     my ($r,$symb,$previous,$feedurl,$sortposts) = @_;
 
+    &Apache::loncommon::content_type($r,'text/html');
+    $r->send_http_header;
+
     &Apache::lonenc::check_encrypt(\$symb);
     my $crs='/'.$ENV{'request.course.id'};
     if ($ENV{'request.course.sec'}) {
@@ -1963,8 +2001,9 @@ sub print_showposters {
             }
         }
     }
+    my $html=&Apache::lonxml::xmlbegin();
     $r->print(<<END);
-<html>
+$html
 <head>
 <title>$lt{'diso'}</title>
 <meta http-equiv="pragma" content="no-cache" />
@@ -1991,7 +2030,7 @@ END
                     next;
                 } else {
                     $count ++;
-                    $r->print('<tr bgcolor="#ffffe6"><td align="right">'.$count.'</td><td align="center"><input name="stuinfo" type="checkbox" value="'.$_.'" /></td><td>'.$last.', '.$first.' ('.$uname.','.$udom.')</td><td>'.$postcounts{$_}.'</td></tr>');
+                    $r->print('<tr bgcolor="#ffffe6"><td align="right">'.$count.'</td><td align="center"><label><input name="stuinfo" type="checkbox" value="'.$_.'" /></td><td>'.$last.', '.$first.' ('.$uname.','.$udom.')</label></td><td>'.$postcounts{$_}.'</td></tr>');
                 }
             }
         }
@@ -2072,17 +2111,20 @@ sub get_post_attachments {
     return;
 }
 
-sub fail_redirect {;
+sub fail_redirect {
   my ($r,$feedurl) = @_;
   if ($feedurl=~/^\/adm\//) { $feedurl.='?register=1' };
+  my $logo=&Apache::loncommon::lonhttpdurl('/adm/lonIcons/lonlogos.gif');
+  my $html=&Apache::lonxml::xmlbegin();
   $r->print (<<ENDFAILREDIR);
-<html>
-<head><title>Feedback not sent</title>
+$html
+<head>
+<title>Feedback not sent</title>
 <meta http-equiv="pragma" content="no-cache" />
 <meta HTTP-EQUIV="Refresh" CONTENT="2; url=$feedurl" />
 </head>
 <body bgcolor="#FFFFFF">
-<img align="right" src="/adm/lonIcons/lonlogos.gif" />
+<img align="right" src="$logo" />
 <b>Sorry, no recipients  ...</b>
 <br /><a href="$feedurl">Continue</a>
 </body>
@@ -2160,15 +2202,17 @@ sub redirect_back {
       }
   }
   $feedurl=&Apache::lonenc::check_encrypt($feedurl);
+  my $logo=&Apache::loncommon::lonhttpdurl('/adm/lonIcons/lonlogos.gif');
+  my $html=&Apache::lonxml::xmlbegin();
   $r->print (<<ENDREDIR);
-<html>
+$html
 <head>
 <title>Feedback sent</title>
 <meta http-equiv="pragma" content="no-cache" />
 <meta HTTP-EQUIV="Refresh" CONTENT="2; url=$feedurl" />
 </head>
 <body bgcolor="#FFFFFF" onLoad='if (window.name!="loncapaclient") { this.document.reldt.submit(); self.close(); }'>
-<img align="right" src="/adm/lonIcons/lonlogos.gif" />
+<img align="right" src="$logo" />
 $typestyle
 <b>Sent $sendsomething message(s), and $sendposts post(s).</b>
 <font color="red">$status</font>
@@ -2190,9 +2234,11 @@ sub no_redirect_back {
   my ($r,$feedurl) = @_;
   my $nofeed=&mt('Sorry, no feedback possible on this resource  ...');
   my $continue=&mt('Continue');
+  my $html=&Apache::lonxml::xmlbegin();
   $r->print (<<ENDNOREDIR);
-<html>
-<head><title>Feedback not sent</title>
+$html
+<head>
+<title>Feedback not sent</title>
 <meta http-equiv="pragma" content="no-cache" />
 ENDNOREDIR
 
@@ -2201,10 +2247,11 @@ ENDNOREDIR
 		&Apache::lonenc::check_encrypt($feedurl).'">');
   }
   $feedurl=&Apache::lonenc::check_encrypt($feedurl);
+  my $logo=&Apache::loncommon::lonhttpdurl('/adm/lonIcons/lonlogos.gif');
   $r->print (<<ENDNOREDIRTWO);
 </head>
 <body bgcolor="#FFFFFF" onLoad='if (window.name!="loncapaclient") { self.close(); }'>
-<img align="right" src="/adm/lonIcons/lonlogos.gif" />
+<img align="right" src="$logo" />
 <b>$nofeed</b>
 <br /><a href="$feedurl">$continue</a>
 </body>
@@ -2219,23 +2266,25 @@ sub screen_header {
     unless (($ENV{'form.replydisc'}) || ($ENV{'form.editdisc'})) {
 	if (($feedurl=~/^\/res\//) && ($feedurl!~/^\/res\/adm/)) {
 	    $msgoptions= 
-		'<p><input type="checkbox" name="author" /> '.
-		&mt('Feedback to resource author').'</p>';
+		'<p><label><input type="checkbox" name="author" /> '.
+		&mt('Feedback to resource author').'</label></p>';
 	}
 	if (&feedback_available(1)) {
 	    $msgoptions.=
-		'<br /><input type="checkbox" name="question" /> '.
-		&mt('Question about resource content');
+		'<p><label><input type="checkbox" name="question" /> '.
+		&mt('Question about resource content').'</label></p>';
 	}
 	if (&feedback_available(0,1)) {
 	    $msgoptions.=
-		'<br /><input type="checkbox" name="course" /> '.
-		&mt('Question/Comment/Feedback about course content');
+		'<p><label><input type="checkbox" name="course" /> '.
+		&mt('Question/Comment/Feedback about course content').
+		'</label></p>';
 	}
 	if (&feedback_available(0,0,1)) {
 	    $msgoptions.=
-		'<br /><input type="checkbox" name="policy" /> '.
-		&mt('Question/Comment/Feedback about course policy');
+		'<p><label><input type="checkbox" name="policy" /> '.
+		&mt('Question/Comment/Feedback about course policy').
+		'</label></p>';
 	}
     }
     if ($ENV{'request.course.id'}) {
@@ -2243,17 +2292,17 @@ sub screen_header {
 	    &Apache::lonnet::allowed('pch',
 				     $ENV{'request.course.id'}.
 				     ($ENV{'request.course.sec'}?'/'.$ENV{'request.course.sec'}:''))) {
-	    $discussoptions='<input type="checkbox" name="discuss" onClick="this.form.anondiscuss.checked=false;" '.
+	    $discussoptions='<label><input type="checkbox" name="discuss" onClick="this.form.anondiscuss.checked=false;" '.
 		($ENV{'form.replydisc'}?' checked="1"':'').' /> '.
 		&mt('Contribution to course discussion of resource');
-	    $discussoptions.='<br /><input type="checkbox" name="anondiscuss" onClick="this.form.discuss.checked=false;" /> '.
+	    $discussoptions.='</label><br /><label><input type="checkbox" name="anondiscuss" onClick="this.form.discuss.checked=false;" /> '.
 		&mt('Anonymous contribution to course discussion of resource').
-		' <i>('.&mt('name only visible to course faculty').')</i>';
+		' <i>('.&mt('name only visible to course faculty').')</i></label>';
         }
     }
-    if ($msgoptions) { $msgoptions='<h2><img src="/adm/lonMisc/feedback.gif" />'.&mt('Sending Messages').'</h2>'.$msgoptions; }
+    if ($msgoptions) { $msgoptions='<h2><img src="'.&Apache::loncommon::lonhttpdurl('/adm/lonMisc/feedback.gif').'" />'.&mt('Sending Messages').'</h2>'.$msgoptions; }
     if ($discussoptions) { 
-	$discussoptions='<h2><img src="/adm/lonMisc/chat.gif" />'.&mt('Discussion Contributions').'</h2>'.$discussoptions; }
+	$discussoptions='<h2><img src="'.&Apache::loncommon::lonhttpdurl('/adm/lonMisc/chat.gif').'" />'.&mt('Discussion Contributions').'</h2>'.$discussoptions; }
     return $msgoptions.$discussoptions;
 }
 
@@ -2284,7 +2333,7 @@ sub clear_out_html {
       # <SUP>
       %html=(B=>1, I=>1, P=>1, A=>1, LI=>1, OL=>1, UL=>1, EM=>1,
 	     BR=>1, TT=>1, STRONG=>1, BLOCKQUOTE=>1, DIV=>1, IMG=>1,
-	     M=>1, SUB=>1, SUP=>1, SPAN=>1, 
+	     M=>1, ALGEBRA=>1, SUB=>1, SUP=>1, SPAN=>1, 
 	     H1=>1, H2=>1, H3=>1, H4=>1, H5=>1);
   }
 # Do the substitution of everything that is not explicitly allowed
@@ -2534,9 +2583,11 @@ sub show_preview {
     my $subject=&clear_out_html($ENV{'form.subject'});
     $subject=~s/\n/\<br \/\>/g;
     $subject=&Apache::lontexconvert::msgtexconverted($subject);
-    $r->print('<table border="2"><tr><td>'.
-       '<b>Subject:</b> '.$subject.'<br /><br />'.
-       $message.'</td></tr></table>');
+    my $html=&Apache::lonxml::xmlbegin();
+    $r->print($html.'<head>'.
+	      '</head><body><table border="2"><tr><td>'.
+	      '<b>Subject:</b> '.$subject.'<br /><br />'.
+	      $message.'</td></tr></table></body></html>');
 }
 
 sub generate_preview_button {
@@ -2568,8 +2619,9 @@ sub modify_attachments {
         &extract_attachments($attachmenturls,$idx,$numoldver,\$msg,\%attachments,\%currattach,$currdelold);
     }
     &Apache::lonenc::check_encrypt(\$symb);
+    my $html=&Apache::lonxml::xmlbegin();
     $r->print(<<END);
-<html>
+$html
 <head>
 <title>Managing Attachments</title>
 <script>
@@ -2594,7 +2646,7 @@ END
                 foreach my $id (@currold) {
                     my $attachurl = &HTML::Entities::decode($attachments{$id}{'filename'}); 
                     $attachurl =~ m#/([^/]+)$#;
-                    $r->print('<input type="checkbox" name="deloldattach" value="'.$id.'" />&nbsp;'.$1.'<br />'."\n");
+                    $r->print('<label><input type="checkbox" name="deloldattach" value="'.$id.'" />&nbsp;'.$1.'</label><br />'."\n");
                 }
                 $r->print("<br />");
             }
@@ -2604,7 +2656,7 @@ END
         $r->print("The following attachments have been uploaded for inclusion with this posting.<br />Check the checkboxes for any you wish to remove<br />\n");
         foreach (@{$currnewattach}) {
             $_ =~ m#/([^/]+)$#;
-            $r->print('<input type="checkbox" name="delnewattach" value="'.$_.'" />&nbsp;'.$1.'<br />'."\n");
+            $r->print('<label><input type="checkbox" name="delnewattach" value="'.$_.'" />&nbsp;'.$1.'</label><br />'."\n");
         }
         $r->print("<br />"); 
     }
@@ -2919,9 +2971,10 @@ sub handler {
   if ($ENV{'form.allversions'}) {
       &Apache::loncommon::content_type($r,'text/html');
       $r->send_http_header;
+      my $html=&Apache::lonxml::xmlbegin();
       my $bodytag=&Apache::loncommon::bodytag('Discussion Post Versions');
       $r->print(<<END);
-<html>
+$html
 <head>
 <title>Post Versions</title>
 <meta http-equiv="pragma" content="no-cache" />
@@ -3021,15 +3074,17 @@ END
       }
       &Apache::loncommon::content_type($r,'text/html');
       $r->send_http_header;
+      my $logo=&Apache::loncommon::lonhttpdurl('/adm/lonIcons/lonlogos.gif');
+      my $html=&Apache::lonxml::xmlbegin();
       $r->print (<<ENDREDIR);
-<html>
+$html
 <head>
 <title>New posts marked as read</title>
 <meta http-equiv="pragma" content="no-cache" />
 <meta HTTP-EQUIV="Refresh" CONTENT="2; url=$feedurl" />
 </head>
 <body bgcolor="#FFFFFF" onLoad='if (window.name!="loncapaclient") { this.document.reldt.submit(); self.close(); }'>
-<img align="right" src="/adm/lonIcons/lonlogos.gif" />
+<img align="right" src="$logo" />
 $textline
 <form name="reldt" action="$feedurl" target="loncapaclient">
 </form>