[LON-CAPA-cvs] cvs: loncom /interface lonfeedback.pm lonparmset.pm /xml lontexconvert.pm
raeburn
lon-capa-cvs@mail.lon-capa.org
Thu, 22 Jul 2004 23:18:01 -0000
This is a MIME encoded message
--raeburn1090538281
Content-Type: text/plain
raeburn Thu Jul 22 19:18:01 2004 EDT
Modified files:
/loncom/xml lontexconvert.pm
/loncom/interface lonparmset.pm lonfeedback.pm
Log:
Allow posters to edit/delete their own discussion postings. Controlled by
course parameter set via PARM. Previous versions of postings are preserved.
Deleted postings are hidden. Course Coordinators etc. will be able to see
all versions of postings (interface still needed). Editing currently works for
resource discussions, but not bulletin boards (work in progress).
--raeburn1090538281
Content-Type: text/plain
Content-Disposition: attachment; filename="raeburn-20040722191801.txt"
Index: loncom/xml/lontexconvert.pm
diff -u loncom/xml/lontexconvert.pm:1.37 loncom/xml/lontexconvert.pm:1.38
--- loncom/xml/lontexconvert.pm:1.37 Tue May 25 02:11:49 2004
+++ loncom/xml/lontexconvert.pm Thu Jul 22 19:18:00 2004
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# TeX Conversion Module
#
-# $Id: lontexconvert.pm,v 1.37 2004/05/25 06:11:49 albertel Exp $
+# $Id: lontexconvert.pm,v 1.38 2004/07/22 23:18:00 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -190,12 +190,16 @@
}
sub msgtexconverted {
- my $message=shift;
- my $email=shift;
+ my ($message,$email,$priorversions) = @_;
$errorstring='';
&init_tth();
my $outmessage='';
my $tex=0;
+ if ($priorversions > 0) {
+ if ($message =~ /::::\d+::::(.+)$/) {
+ $message = $1;
+ }
+ }
foreach (split(/(?:\<\;|\<)\/*m\s*(?:\>\;|\>)/i,$message)) {
if ($tex) {
if ($email) {
Index: loncom/interface/lonparmset.pm
diff -u loncom/interface/lonparmset.pm:1.169 loncom/interface/lonparmset.pm:1.170
--- loncom/interface/lonparmset.pm:1.169 Mon Jul 19 13:57:25 2004
+++ loncom/interface/lonparmset.pm Thu Jul 22 19:18:00 2004
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Handler to set parameters for assessments
#
-# $Id: lonparmset.pm,v 1.169 2004/07/19 17:57:25 matthew Exp $
+# $Id: lonparmset.pm,v 1.170 2004/07/22 23:18:00 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -1592,6 +1592,9 @@
'allow_limited_html_in_feedback'
=> '<b>'.&mt('Allow limited HTML in discussion posts').'</b><br />'.
'('.&mt('Set value to "[_1]" to allow',"<tt>yes</tt>").')',
+ 'allow_discussion_post_editing'
+ => '<b>'.&mt('Allow users to edit/delete their own discussion posts').'</b><br />'.
+ '('.&mt('Set value to "[_1]" to allow',"<tt>yes</tt>").')',
'rndseed'
=> '<b>'.&mt('Randomization algorithm used').'</b> <br />'.
'<font color="red">'.&mt('Modifying this will make problems').' '.
@@ -1634,6 +1637,7 @@
'plc.roles.denied','plc.users.denied',
'pch.roles.denied','pch.users.denied',
'allow_limited_html_in_feedback',
+ 'allow_discussion_post_editing',
'languages',
'nothideprivileged',
'rndseed',
Index: loncom/interface/lonfeedback.pm
diff -u loncom/interface/lonfeedback.pm:1.101 loncom/interface/lonfeedback.pm:1.102
--- loncom/interface/lonfeedback.pm:1.101 Wed Jul 21 19:57:24 2004
+++ loncom/interface/lonfeedback.pm Thu Jul 22 19:18:01 2004
@@ -1,7 +1,7 @@
# The LearningOnline Network
# Feedback
#
-# $Id: lonfeedback.pm,v 1.101 2004/07/21 23:57:24 raeburn Exp $
+# $Id: lonfeedback.pm,v 1.102 2004/07/22 23:18:01 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -222,8 +222,10 @@
$newpostsflag = 1;
}
my $hidden=($contrib{'hidden'}=~/\.$idx\./);
+ my $studenthidden=($contrib{'studenthidden'}=~/\.$idx\./);
my $deleted=($contrib{'deleted'}=~/\.$idx\./);
my $origindex='0.';
+ my $numoldver=0;
if ($contrib{$idx.':replyto'}) {
if ( (($ENV{'environment.threadeddiscussion'}) && (($sortposts eq '') || ($sortposts eq 'ascdate'))) || ($sortposts eq 'thread')) {
# this is a follow-up message
@@ -247,13 +249,21 @@
}
unless ((($hidden) && (!$seeid)) || ($deleted)) {
$visible++;
+ if ($contrib{$idx.':history'}) {
+ if ($contrib{$idx.':history'} =~ /:/) {
+ my @oldversions = split/:/,$contrib{$idx.':history'};
+ $numoldver = @oldversions;
+ } else {
+ $numoldver = 1;
+ }
+ }
my $message=$contrib{$idx.':message'};
$message=~s/\n/\<br \/\>/g;
- $message=&Apache::lontexconvert::msgtexconverted($message);
+ $message=&Apache::lontexconvert::msgtexconverted($message,undef,$numoldver);
my $subject=$contrib{$idx.':subject'};
if (defined($subject)) {
$subject=~s/\n/\<br \/\>/g;
- $subject=&Apache::lontexconvert::msgtexconverted($subject);
+ $subject=&Apache::lontexconvert::msgtexconverted($subject,undef,$numoldver);
}
if ($contrib{$idx.':attachmenturl'}) {
my ($fname)
@@ -267,6 +277,9 @@
if ($message) {
if ($hidden) {
$message='<font color="#888888">'.$message.'</font>';
+ if ($studenthidden) {
+ $message .='<br /><br />Deleted by poster (student).';
+ }
}
my $screenname=&Apache::loncommon::screenname(
$contrib{$idx.':sendername'},
@@ -329,14 +342,29 @@
} else {
@{$namesort{$lastname}{$firstname}} = ("$idx");
}
- if ($seeid) {
- if ($hidden) {
- $sender.=' <a href="/adm/feedback?unhide='.
- $ressymb.':::'.$idx;
+ if ($ENV{"course.$cid.allow_discussion_post_editing"} =~ m/yes/i) {
+ if (($ENV{'user.domain'} eq $contrib{$idx.':senderdomain'}) && ($ENV{'user.name'} eq $contrib{$idx.':sendername'})) {
+ $sender.=' <a href="/adm/feedback?editdisc='.
+ $ressymb.':::'.$idx;
if ($newpostsflag) {
$sender .= '&previous='.$prevread;
}
- $sender .= '">'.&mt('Make Visible').'</a>';
+ $sender .= '" '.$target.'>'.&mt('Edit').'</a>'; unless ($seeid) {
+ $sender.=" <a href=\"javascript:studentdelete('$ressymb','$idx','$newpostsflag','$prevread')";
+ $sender .= '">'.&mt('Delete').'</a>';
+ }
+ }
+ }
+ if ($seeid) {
+ if ($hidden) {
+ unless ($studenthidden) {
+ $sender.=' <a href="/adm/feedback?unhide='.
+ $ressymb.':::'.$idx;
+ if ($newpostsflag) {
+ $sender .= '&previous='.$prevread;
+ }
+ $sender .= '">'.&mt('Make Visible').'</a>';
+ }
} else {
$sender.=' <a href="/adm/feedback?hide='.
$ressymb.':::'.$idx;
@@ -346,7 +374,7 @@
$sender .= '">'.&mt('Hide').'</a>';
}
$sender.=' <a href="/adm/feedback?deldisc='.
- $ressymb.':::'.$idx;
+ $ressymb.':::'.$idx;
if ($newpostsflag) {
$sender .= '&previous='.$prevread;
}
@@ -466,6 +494,20 @@
$sender.'</b> '.$vgrlink.' ('.
localtime($posttime).')</td></tr>'.
'</table><blockquote>'.$message.'</blockquote></p>';
+ if ($contrib{$idx.':history'}) {
+ my @postversions = ();
+ $discussionitems[$idx] .= '<br />'.&mt('This post has been edited by the author.').'<br/>'.&mt('Earlier version(s) were posted on: ');
+ if ($contrib{$idx.':history'} =~ m/:/) {
+ @postversions = split/:/,$contrib{$idx.':history'};
+ } else {
+ @postversions = ("$contrib{$idx.':history'}");
+ }
+ for (my $i=0; $i<@postversions; $i++) {
+ my $version = $i+1;
+ $discussionitems[$idx] .= '<b>'.$version.'.</b> - '.&Apache::lonlocal::locallocaltime($postversions[$i]).' ';
+ }
+ $discussionitems[$idx] .= '<br />';
+ }
}
}
}
@@ -520,6 +562,20 @@
# Print the discusssion
if ($outputtarget ne 'tex') {
my $colspan=$maxdepth+1;
+ $discussion.= qq|
+<script>
+ function studentdelete (symb,idx,newflag,previous) {
+ var symbparm = symb+':::'+idx
+ var prevparm = ""
+ if (newflag == 1) {
+ prevparm = "&previous="+previous
+ }
+ if (confirm("Are you sure you want to delete this post?\\nDeleted posts will no longer be visible to you and other students,\\nbut will continue to be visible to your instructor")) {
+ document.location.href = "/adm/feedback?hide="+symbparm+prevparm
+ }
+ }
+</script>
+ |;
$discussion.='<table bgcolor="#AAAAAA" cellpadding="2" cellspacing="2" border="0">';
$discussion .='<tr><td bgcolor="#DDDDBB" colspan="'.$colspan.'">'.
'<table border="0" width="100%" bgcolor="#DDDDBB"><tr>';
@@ -634,7 +690,7 @@
$threadinsert='<br /><strong>Reply: '.$thisdepth.'</strong>';
}
$discussionitems[$alldiscussion{$_}]=~s/<\/td><td([^>]*)>/$threadinsert<\/td><td TeXwidth="65 mm" align="left">/;
- $discussionitems[$alldiscussion{$_}]=~s/<a([^>]+)>(Hide|Delete|Reply|Submissions)<\/a>//g;
+ $discussionitems[$alldiscussion{$_}]=~s/<a([^>]+)>(Edit|Hide|Delete|Reply|Submissions)<\/a>//g;
$discussionitems[$alldiscussion{$_}]=~s/(<b>|<\/b>|<\/a>|<a([^>]+)>)//g;
#FIXME xmlparse can't be safely called from inside xmlparse
@@ -722,23 +778,83 @@
sub mail_screen {
my ($r,$feedurl,$options) = @_;
my $bodytag=&Apache::loncommon::bodytag('Resource Feedback and Discussion',
- '','onLoad="window.focus();"');
+ '','onLoad="window.focus();setposttype();"');
my $title=&Apache::lonnet::gettitle($feedurl);
if (!$title) { $title = $feedurl; }
my $quote='';
my $subject = '';
+ my $oldmessage = '';
my $prevtag = '';
- if ($ENV{'form.replydisc'}) {
- my ($symb,$idx)=split(/\:\:\:/,$ENV{'form.replydisc'});
+ my $parentmsg = '';
+ my $anonscript = (<<END);
+ function setposttype() {
+ return
+ }
+END
+ if (($ENV{'form.replydisc'}) || ($ENV{'form.editdisc'})) {
+ my ($symb,$idx);
+ if ($ENV{'form.replydisc'}) {
+ ($symb,$idx)=split(/\:\:\:/,$ENV{'form.replydisc'});
+ } else {
+ ($symb,$idx)=split(/\:\:\:/,$ENV{'form.editdisc'});
+ }
my %contrib=&Apache::lonnet::restore($symb,$ENV{'request.course.id'},
$ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
$ENV{'course.'.$ENV{'request.course.id'}.'.num'});
unless (($contrib{'hidden'}=~/\.$idx\./) || ($contrib{'deleted'}=~/\.$idx\./)) {
- my $message=$contrib{$idx.':message'};
- $message=~s/\n/\<br \/\>/g;
- $quote='<blockquote>'.&Apache::lontexconvert::msgtexconverted($message).'</blockquote>';
- if ($idx > 0) {
- $subject = 'Re: '.$contrib{$idx.':subject'};
+ if ($ENV{'form.replydisc'}) {
+ my $numoldver = 0;
+ if ($contrib{$idx.':history'}) {
+ if ($contrib{$idx.':history'} =~ /:/) {
+ my @oldversions = split/:/,$contrib{$idx.':history'};
+ $numoldver = @oldversions;
+ } else {
+ $numoldver = 1;
+ }
+ }
+ my $message=$contrib{$idx.':message'};
+ $message=~s/\n/\<br \/\>/g;
+ $quote='<blockquote>'.&Apache::lontexconvert::msgtexconverted($message,undef,$numoldver).'</blockquote>';
+ if ($idx > 0) {
+ if ($contrib{'subject'} =~ /::::\d+::::(.+)$/si) {
+ $subject = $1;
+ } else {
+ $subject = $contrib{$idx.':subject'};
+ }
+ $subject = 'Re: '.$subject;
+ }
+ } else {
+ if ($contrib{$idx.':message'} =~ /::::\d+::::(.+)$/si) {
+ $oldmessage = $1;
+ } else {
+ $oldmessage = $contrib{$idx.':message'};
+ }
+ if ($contrib{$idx.':subject'} =~ /::::\d+::::(.+)$/si) {
+ $subject = $1;
+ } else {
+ $subject = $contrib{$idx.':subject'};
+ }
+ if (defined($contrib{$idx.':replyto'})) {
+ $parentmsg = $contrib{$idx.':replyto'};
+ }
+ my $anonflag = 0;
+ if ($contrib{$idx.':anonymous'}) {
+ $anonflag = 1;
+ }
+ $anonscript = (<<END);
+ function setposttype () {
+ var currtype = $anonflag
+ if (currtype == 1) {
+ document.mailform.elements.discuss.checked = false
+ document.mailform.elements.anondiscuss.checked = true
+ }
+ if (currtype == 0) {
+ document.mailform.elements.anondiscuss.checked = false
+ document.mailform.elements.discuss.checked = true
+ }
+ return
+ }
+END
}
}
if ($ENV{'form.previous'}) {
@@ -753,7 +869,7 @@
$onsubmit='document.mailform.onsubmit();';
}
my $send=&mt('Send');
- $r->print(<<ENDDOCUMENT);
+ $r->print(<<END);
<html>
<head>
<title>The LearningOnline Network with CAPA</title>
@@ -801,6 +917,7 @@
alert('Please check a feedback type.');
}
}
+ $anonscript
//-->
</script>
</head>
@@ -810,7 +927,18 @@
enctype="multipart/form-data">
$prevtag
<input type="hidden" name="postdata" value="$feedurl" />
+END
+ if ($ENV{'form.replydisc'}) {
+ $r->print(<<END);
<input type="hidden" name="replydisc" value="$ENV{'form.replydisc'}" />
+END
+ } elsif ($ENV{'form.editdisc'}) {
+ $r->print(<<END);
+<input type="hidden" name="editdisc" value ="$ENV{'form.editdisc'}" />
+<input type="hidden" name="parentmsg" value ="$parentmsg" />
+END
+ }
+ $r->print(<<ENDDOCUMENT);
Please check at least one of the following feedback types:
$options<hr />
$quote
@@ -819,7 +947,7 @@
$latexHelp
Title: <input type="text" name="subject" size="30" value="$subject" /></p>
<p>
-<textarea name="comment" id="comment" cols="60" rows="10" wrap="hard">
+<textarea name="comment" id="comment" cols="60" rows="10" wrap="hard">$oldmessage
</textarea></p>
<p>
Attachment (128 KB max size): <input type="file" name="attachment" />
@@ -1118,6 +1246,9 @@
}
}
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);
my %contrib=&Apache::lonnet::restore($ressymb,$ENV{'request.course.id'},
@@ -1322,7 +1453,7 @@
my ($feedurl) = @_;
my $msgoptions='';
my $discussoptions='';
- unless ($ENV{'form.replydisc'}) {
+ unless (($ENV{'form.replydisc'}) || ($ENV{'form.editdisc'})) {
if (($feedurl=~/^\/res\//) && ($feedurl!~/^\/res\/adm/)) {
$msgoptions=
'<p><input type="checkbox" name="author" /> '.
@@ -1543,10 +1674,52 @@
$contrib{'anonymous'}='true';
}
if (($symb) && ($email)) {
- $status='Adding to class discussion'.($anon?' (anonymous)':'').': '.
- &Apache::lonnet::store(\%contrib,$symb,$ENV{'request.course.id'},
+ if ($ENV{'form.editdisc'}) {
+ my %newcontrib = ();
+ $contrib{'ip'}=$ENV{'REMOTE_ADDR'};
+ $contrib{'host'}=$Apache::lonnet::perlvar{'lonHostID'};
+ $contrib{'timestamp'} = time;
+ $contrib{'history'} = '';
+ my $numoldver = 0;
+ my ($oldsymb,$oldidx)=split(/\:\:\:/,$ENV{'form.editdisc'});
+# get timestamp for last post and history
+ my %oldcontrib=&Apache::lonnet::restore($oldsymb,$ENV{'request.course.id'},
+ $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
+ $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
+ if (defined($oldcontrib{$oldidx.':replyto'})) {
+ $contrib{'replyto'} = $oldcontrib{$oldidx.':replyto'};
+ }
+ if (defined($oldcontrib{$oldidx.':history'})) {
+ if ($oldcontrib{$oldidx.':history'} =~ /:/) {
+ my @oldversions = split/:/,$oldcontrib{$oldidx.':history'};
+ $numoldver = @oldversions;
+ } else {
+ $numoldver = 1;
+ }
+ $contrib{'history'} = $oldcontrib{$oldidx.':history'}.':';
+ }
+ if (defined($oldcontrib{$oldidx.':subject'})) {
+ $contrib{'subject'} = $oldcontrib{$oldidx.':subject'}.'::::'.$numoldver.'::::'.$contrib{'subject'};
+ }
+ if (defined($oldcontrib{$oldidx.':message'})) {
+ $contrib{'message'} = $oldcontrib{$oldidx.':message'}.'::::'.$numoldver.'::::'.$contrib{'message'};
+ }
+ $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,
+ $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
+ $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
+ $status='Editing class discussion'.($anon?' (anonymous)':'');
+ } else {
+ $status='Adding to class discussion'.($anon?' (anonymous)':'').': '.
+ &Apache::lonnet::store(\%contrib,$symb,$ENV{'request.course.id'},
$ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
$ENV{'course.'.$ENV{'request.course.id'}.'.num'});
+ }
my %storenewentry=($symb => time);
$status.='<br />'.&mt('Updating discussion time').': '.
&Apache::lonnet::put('discussiontimes',\%storenewentry,
@@ -1606,7 +1779,7 @@
# --------------------------- Get query string for limited number of parameters
&Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
- ['hide','unhide','deldisc','postdata','preview','replydisc','threadedon','threadedoff','onlyunread','allposts','previous','markread','markonread','markondisp','modifydisp','changes','navmaps','navurl','sortfilter','sortposts','applysort','rolefilter','statusfilter','sectionpick','posterlist','userpick']);
+ ['hide','unhide','deldisc','postdata','preview','replydisc','editdisc','threadedon','threadedoff','onlyunread','allposts','previous','markread','markonread','markondisp','modifydisp','changes','navmaps','navurl','sortfilter','sortposts','applysort','rolefilter','statusfilter','sectionpick','posterlist','userpick']);
if ($ENV{'form.posterlist'}) {
&Apache::loncommon::content_type($r,'text/html');
$r->send_http_header;
@@ -1826,13 +1999,27 @@
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) {
+ $currentstudenthidden.='.'.$idx.'.';
+ }
} else {
$currenthidden=~s/\.$idx\.//g;
}
my %newhash=('hidden' => $currenthidden);
+ if ( ($ENV{'form.hide'}) && (!$seeid) ) {
+ $newhash{'studenthidden'} = $currentstudenthidden;
+ }
&Apache::lonnet::store(\%newhash,$symb,$ENV{'request.course.id'},
$ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
@@ -1899,6 +2086,10 @@
$symb=(split(/\:\:\:/,$ENV{'form.replydisc'}))[0];
my ($map,$id,$url)=&Apache::lonnet::decode_symb($symb);
$feedurl=&Apache::lonnet::clutter($url);
+ } elsif ($ENV{'form.editdisc'}) {
+ $symb=(split(/\:\:\:/,$ENV{'form.editdisc'}))[0];
+ my ($map,$id,$url)=&Apache::lonnet::decode_symb($symb);
+ $feedurl=&Apache::lonnet::clutter($url);
} else {
$symb=&Apache::lonnet::symbread($feedurl);
}
--raeburn1090538281--