--- loncom/interface/lonfeedback.pm	2006/02/09 20:30:47	1.179
+++ loncom/interface/lonfeedback.pm	2006/04/13 18:59:02	1.191
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # Feedback
 #
-# $Id: lonfeedback.pm,v 1.179 2006/02/09 20:30:47 raeburn Exp $
+# $Id: lonfeedback.pm,v 1.191 2006/04/13 18:59:02 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -744,17 +744,22 @@ ENDDISCUSS
 	    }
 	}
     } else {
+	$discussion.='<table bgcolor="#BBBBBB"><tr><td>';
         if (&discussion_open($status) &&
             &Apache::lonnet::allowed('pch',
     	        $env{'request.course.id'}.
 	        ($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''))) {
 	    if ($outputtarget ne 'tex') {
-		$discussion.='<table bgcolor="#BBBBBB"><tr><td><a href="/adm/feedback?replydisc='.
+		$discussion.='<a href="/adm/feedback?replydisc='.
 		    &Apache::lonnet::escape($ressymb).':::" '.$target.'>'.
 		    '<img src="'.&Apache::loncommon::lonhttpdurl('/adm/lonMisc/chat.gif').'" border="0" />'.
-		    &mt('Post Discussion').'</a></td></tr></table>';
-	    }
+		    &mt('Post Discussion').'</a><br />';
+            }
 	}
+	$discussion.='<a href="/adm/feedback?sendmessageonly=1&symb='.
+	    &Apache::lonnet::escape($ressymb).
+	    '"><img src="'.&Apache::loncommon::lonhttpdurl('/adm/lonMisc/feedback.gif').'" border="0" />'.
+		    &mt('Send Message').'</td></tr></table>';
     }
     return $discussion;
 }
@@ -906,7 +911,7 @@ sub build_posting_display {
                             } else {
                                 @{$$namesort{$lastname}{$firstname}} = ("$idx");
                             }
-                            if ($env{'course.'.$env{'request.course.id'}.'.allow_discussion_post_editing'} =~ m/yes/i) {
+                            if (&editing_allowed()) {
                                 if (($env{'user.domain'} eq $contrib{$idx.':senderdomain'}) && ($env{'user.name'} eq $contrib{$idx.':sendername'})) {
                                     $sender.=' <a href="/adm/feedback?editdisc='.
                                          $escsymb.':::'.$idx;
@@ -1253,7 +1258,7 @@ END
         }
     }
     if ($type eq 'allversions') {
-        $discussion.=('</ul></body></html>');
+        $discussion.='</ul>';
         return $discussion;
     } else {
         return;
@@ -1303,8 +1308,7 @@ sub mail_screen {
   if (exists($env{'form.origpage'})) {
       &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['subject','comment','currnewattach','addnewattach','deloldattach','delnewattach','timestamp','idx','anondiscuss','discuss','blog']);
   }
-  my $bodytag=&Apache::loncommon::bodytag('Resource Feedback and Discussion',
-                                          '','onLoad="window.focus();setposttype();"');
+
   my $title=&Apache::lonnet::gettitle($feedurl);
   if (!$title) { $title = $feedurl; }
   my $quote='';
@@ -1442,15 +1446,8 @@ END
       &process_attachments(\@currnewattach,\@currdelold,\@keepold);
   }
   my $latexHelp=&Apache::loncommon::helpLatexCheatsheet();
-  my $htmlheader=&Apache::lonhtmlcommon::htmlareaheaders();
   my $send=&mt('Send');
-  my $html=&Apache::lonxml::xmlbegin();
-  $r->print(<<END);
-$html
-<head>
-<title>The LearningOnline Network with CAPA</title>
-<meta http-equiv="pragma" content="no-cache"></meta>
-$htmlheader
+  my $js= <<END;
 <script type="text/javascript">
 //<!--
     function gosubmit() {
@@ -1504,8 +1501,15 @@ $htmlheader
     $anonscript
 //-->
 </script>
-</head>
-$bodytag
+END
+
+  my %onload = ('onload' => 'window.focus();setposttype();');
+  my $start_page=
+      &Apache::loncommon::start_page('Resource Feedback and Discussion',$js,
+				     {'add_entries' => \%onload});
+
+  $r->print(<<END);
+$start_page
 <h2><tt>$title</tt></h2>
 <form action="/adm/feedback" method="post" name="mailform"
 enctype="multipart/form-data">
@@ -1602,7 +1606,8 @@ END
     }
     $r->print(&generate_preview_button().
               &Apache::lonhtmlcommon::htmlareaselectactive('comment').
-              '</body></html>');
+	      &Apache::loncommon::end_page());
+
 }
 
 sub print_display_options {
@@ -1613,11 +1618,8 @@ sub print_display_options {
     my $function = &Apache::loncommon::get_users_function();
     my $tabcolor = &Apache::loncommon::designparm($function.'.tabbg',
                                                     $env{'user.domain'});
-    my $bodytag=&Apache::loncommon::bodytag('Discussion options',
-                                          '','');
 
     my %lt = &Apache::lonlocal::texthash(
-        'dido' => 'Discussion display options',
         'pref' => 'Display Preference',
         'curr' => 'Current setting ',
         'actn' => 'Action',
@@ -1675,13 +1677,9 @@ sub print_display_options {
         $currtogg = $lt{'toggon'};
         $disctogg = 'toggon';
     }
-    my $html=&Apache::lonxml::xmlbegin();
-    $r->print(<<END);
-$html
-<head>
-<title>$lt{'dido'}</title>
-<meta http-equiv="pragma" content="no-cache" />
-<script>
+
+    my $js = <<END;
+<script type="text/javascript">
 function discdispChk(caller) {
     var disctogg = '$toggchg'
     if (caller == 0) {
@@ -1748,9 +1746,15 @@ function setDisp() {
     }
 }
 </script>
-</head>
-$bodytag
-<form name="modifydisp" method="post" action="/adm/feedback">
+END
+
+
+    my $start_page =
+	&Apache::loncommon::start_page('Discussion display options',$js);
+    my $end_page =
+	&Apache::loncommon::end_page();
+    $r->print(<<END);
+<form name="modifydisp" method="POSTx" action="/adm/feedback">
 $lt{'sdpf'}<br/> $lt{'prca'}  <ol><li>$lt{'whpo'}</li><li>$lt{'unwh'}</li><li>$lt{'wipa'}</li></ol>
 <br />
 <table border="0" cellpadding="0" cellspacing="0">
@@ -1800,8 +1804,7 @@ $lt{'sdpf'}<br/> $lt{'prca'}  <ol><li>$l
 <br />
 <br />
 </form>
-</body>
-</html>
+$end_page
 END
     return;
 }
@@ -1838,10 +1841,7 @@ sub print_sortfilter_options {
     my $function = &Apache::loncommon::get_users_function();
     my $tabcolor = &Apache::loncommon::designparm($function.'.tabbg',
                                                     $env{'user.domain'});
-    my $bodytag=&Apache::loncommon::bodytag('Discussion options',
-                                          '','');
     my %lt = &Apache::lonlocal::texthash(
-        'diso' => 'Discussion sorting and filtering options',
         'diop' => 'Display Options',
         'curr' => 'Current setting ',
         'actn' => 'Action',
@@ -1858,12 +1858,8 @@ 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
-<head>
-<title>$lt{'diso'}</title>
-<meta http-equiv="pragma" content="no-cache" />
+
+    my $js = <<END;
 <script type="text/javascript">
 function verifyFilter() {
     var rolenum = 0
@@ -1888,9 +1884,16 @@ function verifyFilter() {
     document.modifyshown.submit();
 }
 </script>
-</head>
-$bodytag
-<form name="modifyshown" method="post" action="/adm/feedback">
+END
+
+    my $start_page=
+	&Apache::loncommon::start_page('Discussion options',$js);
+    my $end_page=
+	&Apache::loncommon::end_page();
+
+    $r->print(<<END);
+$start_page
+<form name="modifyshown" method="POST" action="/adm/feedback">
 <b>$lt{'diso'}</b><br/> $lt{'prca'}
 <br /><br />
 <table border="0">
@@ -1955,8 +1958,7 @@ $bodytag
 <br />
 <br />
 </form>
-</body>
-</html>
+$end_page
 END
 }
 
@@ -1978,11 +1980,7 @@ sub print_showposters {
                           $env{'course.'.$env{'request.course.id'}.'.num'});
     my %namesort = ();
     my %postcounts = ();
-    my %lt=&Apache::lonlocal::texthash(
-                     'diso' => 'Discussion filtering options',
-    );
-    my $bodytag=&Apache::loncommon::bodytag('Discussion options',
-                                          '','');
+
     if ($contrib{'version'}) {
         for (my $idx=1;$idx<=$contrib{'version'};$idx++) {
             my $hidden=($contrib{'hidden'}=~/\.$idx\./);
@@ -2014,14 +2012,11 @@ sub print_showposters {
             }
         }
     }
-    my $html=&Apache::lonxml::xmlbegin();
+
+    my $start_page = &Apache::loncommon::start_page('Discussion options');
+
     $r->print(<<END);
-$html
-<head>
-<title>$lt{'diso'}</title>
-<meta http-equiv="pragma" content="no-cache" />
-</head>
-$bodytag
+$start_page
  <form name="pickpostersform" method="post">
   <table border="0">
    <tr>
@@ -2048,6 +2043,8 @@ END
             }
         }
     }
+
+    my $end_page   = &Apache::loncommon::end_page();
     $r->print(<<END);
      </table>
     </td>
@@ -2058,8 +2055,7 @@ END
 <input type="hidden" name="userpick" value="$symb" />
 <input type="button" name="store" value="Display posts" onClick="javascript:document.pickpostersform.submit()" />
 </form>
-</body>
-</html>
+$end_page
 END
 }
 
@@ -2067,7 +2063,8 @@ sub get_post_versions {
     my ($versions,$incoming,$htmldecode,$numver) = @_;
     if ($incoming =~ /^<version num="0">/) {
         my $p = HTML::LCParser->new(\$incoming);
-        my $done = 0;                                                                       
+        my $done = 0; 
+
         while ( (my $token = $p->get_tag("version")) && (!$done)) {
             my $num = $token->[1]{num};
             my $text = $p->get_text("/version");
@@ -2128,21 +2125,14 @@ 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>
-<meta http-equiv="pragma" content="no-cache" />
-<meta HTTP-EQUIV="Refresh" CONTENT="2; url=$feedurl" />
-</head>
-<body bgcolor="#FFFFFF">
+  $r->print(&Apache::loncommon::start_page('Feedback not sent',undef,
+					   {'redirect'  => [2,$feedurl],
+					    'only_body' => 1,}));
+  $r->print(<<ENDFAILREDIR);
 <img align="right" src="$logo" />
 <b>Sorry, no recipients  ...</b>
-<br /><a href="$feedurl">Continue</a>
-</body>
-</html>
 ENDFAILREDIR
+  $r->print(&Apache::loncommon::end_page());
 }
 
 sub redirect_back {
@@ -2216,15 +2206,16 @@ 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
-<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(); }'>
+  my %onload = ('onload' => "if (window.name!='loncapaclient') { this.document.reldt.submit(); self.window.close(); }");
+  my $start_page=
+      &Apache::loncommon::start_page('New posts marked as read',undef,
+				     {'redirect'    => [2,$feedurl],
+				      'only_body'   => 1,
+				      'add_entries' => \%onload});
+  my $end_page = &Apache::loncommon::end_page();
+
+  $r->print(<<ENDREDIR);
+$start_page
 <img align="right" src="$logo" />
 $typestyle
 <b>Sent $sendsomething message(s), and $sendposts post(s).</b>
@@ -2238,38 +2229,35 @@ $roletag
 $sectag
 $userpicktag
 </form>
-<br /><a href="$feedurl">Continue</a>
-</body>
-</html>
+$end_page
 ENDREDIR
 }
 
 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>
-<meta http-equiv="pragma" content="no-cache" />
-ENDNOREDIR
-
-  if ($feedurl!~/^\/adm\/feedback/) { 
-      $r->print('<meta HTTP-EQUIV="Refresh" CONTENT="2; url='.
-		&Apache::lonenc::check_encrypt($feedurl).'">');
-  }
+ 
+  my %body_options = ('only_body'   => 1,
+		      'bgcolor'     => '#FFFFFF',
+		      'add_entries' => {'onload' => "if (window.name!='loncapaclient') { self.window.close(); }"});
+
+  if ($feedurl !~ m{^/adm/feedback}) { 
+      $body_options{'rediect'} = [2,$feedurl];
+  }
+  my $start_page=
+      &Apache::loncommon::start_page('Feedback not sent',undef,
+				     \%body_options);
+				      
+  my $end_page = &Apache::loncommon::end_page();
+
   $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(); }'>
+$start_page
 <img align="right" src="$logo" />
 <b>$nofeed</b>
-<br /><a href="$feedurl">$continue</a>
-</body>
-</html>
+<br />
+$end_page
 ENDNOREDIRTWO
 }
 
@@ -2301,7 +2289,7 @@ sub screen_header {
 		'</label></p>';
 	}
     }
-    if ($env{'request.course.id'}) {
+    if (($env{'request.course.id'}) && (!$env{'form.sendmessageonly'})) {
 	if (&discussion_open(undef,$symb) &&
 	    &Apache::lonnet::allowed('pch',
 				     $env{'request.course.id'}.
@@ -2314,8 +2302,8 @@ sub screen_header {
 		' <i>('.&mt('name only visible to course faculty').')</i></label> '.
 		'<a href="/adm/preferences?action=changescreenname">'.&mt('Change Screenname').'</a>';
         }
-        #$discussoptions.='<br /><label><input type="checkbox" name="blog" /> '.
-	#    &mt('Add to my public course blog').'</label>';
+        $discussoptions.='<br /><label><input type="checkbox" name="blog" /> '.
+	    &mt('Add to my public course blog').'</label>';
     }
     if ($msgoptions) { $msgoptions='<h2><img src="'.&Apache::loncommon::lonhttpdurl('/adm/lonMisc/feedback.gif').'" />'.&mt('Sending Messages').'</h2>'.$msgoptions; }
     if ($discussoptions) { 
@@ -2478,14 +2466,16 @@ sub feedback_available {
 }
 
 sub send_msg {
-  my ($feedurl,$email,$citations,$attachmenturl,%to)=@_;
+  my ($title,$feedurl,$email,$citations,$attachmenturl,%to)=@_;
   my $status='';
   my $sendsomething=0;
+  if ($title=~/^Error/) { $title=&mt('Feedback').': '.$title; }
+  unless ($title=~/\w/) { $title=&mt('Feedback'); }
   foreach (keys %to) {
     if ($_) {
       my $declutter=&Apache::lonnet::declutter($feedurl);
       unless (&Apache::lonmsg::user_normal_msg(split(/\:/,$_),
-               'Feedback ['.$declutter.']',$email,$citations,$feedurl,
+               $title.' ['.$declutter.']',$email,$citations,$feedurl,
                 $attachmenturl)=~/ok/) {
 	$status.='<br />'.&mt('Error sending message to').' '.$_.'<br />';
       } else {
@@ -2539,7 +2529,6 @@ sub adddiscuss {
     }
     if (($symb) && ($email)) {
         if ($env{'form.editdisc'}) {
-            my %newcontrib = ();
             $contrib{'ip'}=$ENV{'REMOTE_ADDR'};
             $contrib{'host'}=$Apache::lonnet::perlvar{'lonHostID'};
             $contrib{'timestamp'} = time;
@@ -2582,12 +2571,8 @@ sub adddiscuss {
                 }
             }
             $contrib{'history'} .= $oldcontrib{$oldidx.':timestamp'};
-            foreach (keys %contrib) {
-                my $key = $oldidx.':'.&Apache::lonnet::escape($oldsymb).':'.$_;                                                                               
-                $newcontrib{$key} = $contrib{$_};
-            }
             my $put_reply = &Apache::lonnet::putstore($env{'request.course.id'},
-                  \%newcontrib,
+                  $oldsymb,$oldidx,\%contrib,
                   $env{'course.'.$env{'request.course.id'}.'.domain'},
                   $env{'course.'.$env{'request.course.id'}.'.num'});
             $status='Editing class discussion'.($anon?' (anonymous)':'');
@@ -2621,7 +2606,7 @@ sub adddiscuss {
 # ----------------------------------------------------------- Preview function
 
 sub show_preview {
-    my $r=shift;
+    my ($r) = @_;
     &Apache::loncommon::content_type($r,'text/html');
     $r->send_http_header;
     my $message=&clear_out_html($env{'form.comment'});
@@ -2631,11 +2616,15 @@ sub show_preview {
     my $subject=&clear_out_html($env{'form.subject'});
     $subject=~s/\n/\<br \/\>/g;
     $subject=&Apache::lontexconvert::msgtexconverted($subject);
-    my $html=&Apache::lonxml::xmlbegin();
-    $r->print($html.'<head>'.
-	      '</head><body><table border="2"><tr><td>'.
+    my $start_page=
+	&Apache::loncommon::start_page('Preview',undef,
+				       {'only_body'   => 1,});
+					
+    my $end_page = &Apache::loncommon::end_page();
+
+    $r->print($start_page.'<table border="2"><tr><td>'.
 	      '<b>Subject:</b> '.$subject.'<br /><br />'.
-	      $message.'</td></tr></table></body></html>');
+	      $message.'</td></tr></table>'.$end_page);
 }
 
 
@@ -2683,8 +2672,7 @@ sub modify_attachments {
     $subject=&Apache::lontexconvert::msgtexconverted($subject);
     my $timestamp=$env{'form.timestamp'};
     my $numoldver=$env{'form.numoldver'};
-    my $bodytag=&Apache::loncommon::bodytag('Discussion Post Attachments',
-                                          '','');
+
     my $msg = '';
     my %attachments = ();
     my %currattach = ();
@@ -2692,19 +2680,21 @@ 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
-<head>
-<title>Managing Attachments</title>
-<script>
+    my $js = <<END;
+<script type="text/javascript">
  function setAction () {
    document.modattachments.action = document.modattachments.origpage.value;
    document.modattachments.submit();
  }
 </script> 
-</head>
-$bodytag
+END
+
+    my $start_page = 
+	&Apache::loncommon::start_page('Discussion Post Attachments',$js);
+    my $end_page = 
+	&Apache::loncommon::end_page();
+				       
+    $r->print(<<END);
 <form name="modattachments" method="post" enctype="multipart/form-data" action="/adm/feedback?attach=$symb">
  <table border="2">
   <tr>
@@ -2757,8 +2747,7 @@ END
     $r->print(<<END);
  <input type="button" name="rtntoedit" value="Store Changes" onClick="setAction()"/>
 </form>
-</body>
-</html>
+$end_page
 END
     return;
 }
@@ -2991,8 +2980,16 @@ sub handler {
 # --------------------------- Get query string for limited number of parameters
 
   &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
-         ['hide','unhide','deldisc','postdata','preview','replydisc','editdisc','cmd','symb','onlyunread','allposts','onlyunmark','previous','markread','markonread','markondisp','toggoff','toggon','modifydisp','changes','navtime','navmaps','navurl','sortposts','applysort','rolefilter','statusfilter','sectionpick','posterlist','userpick','attach','origpage','currnewattach','deloldattach','keepold','allversions','export']);
-
+         ['hide','unhide','deldisc','postdata','preview','replydisc','editdisc','cmd','symb','onlyunread','allposts','onlyunmark','previous','markread','markonread','markondisp','toggoff','toggon','modifydisp','changes','navtime','navmaps','navurl','sortposts','applysort','rolefilter','statusfilter','sectionpick','posterlist','userpick','attach','origpage','currnewattach','deloldattach','keepold','allversions','export','sendmessageonly']);
+  if ($env{'form.editdisc'}) {
+      if (!(&editing_allowed())) {
+          my $symb=(split(/\:\:\:/,$env{'form.editdisc'}))[0];
+          my ($map,$id,$url)=&Apache::lonnet::decode_symb($symb);
+          my $feedurl=&Apache::lonnet::clutter($url);
+          &redirect_back($r,$feedurl,&mt('Editing not permitted').'<br />',                     '0','0','','',$env{'form.previous'},'','','',);
+          return OK;
+      }
+  } 
   if ($env{'form.discsymb'}) {
       my ($symb,$feedurl) = &get_feedurl_and_clean_symb($env{'form.discsymb'});
       my $readkey = $symb.'_read';
@@ -3021,17 +3018,11 @@ sub handler {
   }
   if ($env{'form.allversions'}) {
       &Apache::loncommon::content_type($r,'text/html');
+      &Apache::loncommon::no_cache($r);
       $r->send_http_header;
-      my $html=&Apache::lonxml::xmlbegin();
-      my $bodytag=&Apache::loncommon::bodytag('Discussion Post Versions');
-      $r->print(<<END);
-$html
-<head>
-<title>Post Versions</title>
-<meta http-equiv="pragma" content="no-cache" />
-</head>
-$bodytag
-END
+
+      $r->print(&Apache::loncommon::start_page('Discussion Post Versions'));
+
       my $crs='/'.$env{'request.course.id'};
       if ($env{'request.course.sec'}) {
           $crs.='_'.$env{'request.course.sec'};
@@ -3052,6 +3043,7 @@ END
                            $env{'course.'.$env{'request.course.id'}.'.num'});
           $r->print(&get_post_contents(\%contrib,$idx,$seeid,'allversions',\%messages,\%subjects,\%allattachments,\%attachmsgs,\%imsfiles,\$screenname,\$plainname));
       }
+      $r->print(&Apache::loncommon::end_page());
       return OK;
   }
   if ($env{'form.posterlist'}) {
@@ -3120,22 +3112,21 @@ 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();
+      my %onload = ('onload' => "if (window.name!='loncapaclient') { this.document.reldt.submit(); self.window.close(); }");
+      my $start_page=
+	  &Apache::loncommon::start_page('New posts marked as read',undef,
+					 {'redirect'    => [2,$feedurl],
+					  'only_body'   => 1,
+					  'add_entries' => \%onload});
+      my $end_page = &Apache::loncommon::end_page();
       $r->print (<<ENDREDIR);
-$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(); }'>
+$start_page
 <img align="right" src="$logo" />
 $textline
 <form name="reldt" action="$feedurl" target="loncapaclient">
 </form>
-<br /><a href="$feedurl">Continue</a>
-</body>
-</html>
+<br />
+$end_page
 ENDREDIR
       return OK;
   } elsif ($env{'form.modifydisp'}) {
@@ -3187,6 +3178,18 @@ ENDREDIR
       my ($symb,$idx)=split(/\:\:\:/,$entry);
       ($symb,my $feedurl)=&get_feedurl_and_clean_symb($symb);
 
+      my $crs='/'.$env{'request.course.id'};
+      if ($env{'request.course.sec'}) {
+          $crs.='_'.$env{'request.course.sec'};
+      }
+      $crs=~s/\_/\//g;
+      my $seeid=&Apache::lonnet::allowed('rin',$crs);
+
+      if ($env{'form.hide'} && !$seeid && !(&editing_allowed())) {
+          &redirect_back($r,$feedurl,&mt('Deletion not permitted').'<br />',                 '0','0','','',$env{'form.previous'},'','','',);
+          return OK;
+      }
+
       my %contrib=&Apache::lonnet::restore($symb,$env{'request.course.id'},
                           $env{'course.'.$env{'request.course.id'}.'.domain'},
 		          $env{'course.'.$env{'request.course.id'}.'.num'});
@@ -3194,13 +3197,6 @@ ENDREDIR
       my $currenthidden=$contrib{'hidden'};
       my $currentstudenthidden=$contrib{'studenthidden'};
 
-      my $crs='/'.$env{'request.course.id'};
-      if ($env{'request.course.sec'}) {
-	  $crs.='_'.$env{'request.course.sec'};
-      }
-      $crs=~s/\_/\//g;
-      my $seeid=&Apache::lonnet::allowed('rin',$crs);
-
       if ($env{'form.hide'}) {
 	  $currenthidden.='.'.$idx.'.';
 	  unless ($seeid) {
@@ -3289,8 +3285,11 @@ ENDREDIR
           $status=$Apache::inputtags::status[-1];
       }
       my $discussion = &list_discussion($mode,$status,$symb); 
-      my $bodytag=&Apache::loncommon::bodytag('Resource Feedback and Discussion');
-      $r->print($bodytag.$discussion);                                     
+      my $start_page = 
+	  &Apache::loncommon::start_page('Resource Feedback and Discussion');
+      my $end_page = 
+	  &Apache::loncommon::end_page();
+      $r->print($start_page.$discussion.$end_page);
       return OK;
   } else {
 # ------------------------------------------------------------- Normal feedback
@@ -3411,7 +3410,7 @@ ENDREDIR
       my ($typestyle,%to) = &decide_receiver($feedurl);
 
 # Actually send mail
-      my ($status,$numsent)=&send_msg($feedurl,$email,$citations,
+      my ($status,$numsent)=&send_msg(&clear_out_html($env{'form.subject'}),$feedurl,$email,$citations,
 				      $attachmenturl,%to);
 
 # Discussion? Store that.
@@ -3477,5 +3476,34 @@ sub get_feedurl_and_clean_symb {
     my $feedurl = &get_feedurl($symb);
     return ($symb,$feedurl);
 }
+
+sub editing_allowed {
+    my $can_edit = 0;
+    my $cid = $env{'request.course.id'};
+    my $role = (split(/\./,$env{'request.role'}))[0];
+    my $section = $env{'request.course.sec'};
+    my $allow_editing_config = 
+	$env{'course.'.$cid.'.allow_discussion_post_editing'};
+    if ($allow_editing_config =~ m/^\s*yes\s*$/i) {
+        $can_edit = 1;
+    } else {
+	foreach my $editor (split(/,/,$allow_editing_config)) {
+	    my ($editor_role,$editor_sec) = split(/:/,$editor);
+	    if ($editor_role eq $role
+		&& defined($editor_sec)
+		&& defined($section)
+		&& $editor_sec eq $section) {
+		$can_edit = 1;
+		last;
+	    }
+	    if ($editor_role eq $role
+		&& !defined($editor_sec)) {
+		$can_edit = 1;
+	    }
+	}
+    }
+    return $can_edit;
+}
+
 1;
 __END__