--- loncom/interface/lonfeedback.pm 2004/07/23 16:56:29 1.103
+++ loncom/interface/lonfeedback.pm 2004/08/10 18:25:53 1.115
@@ -1,7 +1,7 @@
# The LearningOnline Network
# Feedback
#
-# $Id: lonfeedback.pm,v 1.103 2004/07/23 16:56:29 albertel Exp $
+# $Id: lonfeedback.pm,v 1.115 2004/08/10 18:25:53 sakharuk Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -36,6 +36,8 @@ use Apache::loncommon();
use Apache::lontexconvert();
use Apache::lonlocal; # must not have ()
use Apache::lonhtmlcommon();
+use HTML::LCParser();
+use Apache::lonspeller();
sub discussion_open {
my ($status)=@_;
@@ -64,7 +66,6 @@ sub discussion_visible {
sub list_discussion {
my ($mode,$status,$symb)=@_;
-
my $outputtarget=$ENV{'form.grade_target'};
if (not &discussion_visible($status)) { return ''; }
my @bgcols = ("#cccccc","#eeeeee");
@@ -95,12 +96,17 @@ sub list_discussion {
# Get discussion display settings for this discussion
my $lastkey = $ressymb.'_lastread';
my $showkey = $ressymb.'_showonlyunread';
+ my $markkey = $ressymb.'_showonlyunmark',
my $visitkey = $ressymb.'_visit';
my $ondispkey = $ressymb.'_markondisp';
my $userpickkey = $ressymb.'_userpick';
- my %dischash = &Apache::lonnet::get('nohist_'.$ENV{'request.course.id'}.'_discuss',[$lastkey,$showkey,$visitkey,$ondispkey,$userpickkey],$ENV{'user.domain'},$ENV{'user.name'});
+ my $toggkey = $ressymb.'_readtoggle';
+ my $readkey = $ressymb.'_read';
+
+ my %dischash = &Apache::lonnet::get('nohist_'.$ENV{'request.course.id'}.'_discuss',[$lastkey,$showkey,$markkey,$visitkey,$ondispkey,$userpickkey,$toggkey,$readkey],$ENV{'user.domain'},$ENV{'user.name'});
my %discinfo = ();
my $showonlyunread = 0;
+ my $showunmark = 0;
my $markondisp = 0;
my $prevread = 0;
my $previous = 0;
@@ -124,7 +130,7 @@ sub list_discussion {
}
}
-# Get information about students and non-stundents in course for filtering display of posts
+# Get information about students and non-students in course for filtering display of posts
my %roleshash = ();
my %roleinfo = ();
if ($rolefilter) {
@@ -175,6 +181,10 @@ sub list_discussion {
$showonlyunread = $dischash{$showkey};
}
+ if (defined($dischash{$markkey})) {
+ $showunmark = $dischash{$markkey};
+ }
+
if (defined($dischash{$visitkey})) {
$visit = $dischash{$visitkey};
}
@@ -204,7 +214,7 @@ sub list_discussion {
$ENV{'environment.remote'} eq 'off' ) {
$target='target="LONcom"';
}
-
+
my $now = time;
$discinfo{$visitkey} = $visit;
@@ -257,22 +267,40 @@ sub list_discussion {
$numoldver = 1;
}
}
- my $message=$contrib{$idx.':message'};
+ my ($message,$subject);
+ if ($idx > 0) {
+ if ($contrib{$idx.':message'} =~ /^/) {
+ my %versions = ();
+ &get_post_versions(\%versions,$contrib{$idx.':message'},$numoldver);
+ $message = &HTML::Entities::decode($versions{$numoldver});
+ } else {
+ $message = $contrib{$idx.':message'};
+ }
+ } else {
+ $message=$contrib{$idx.':message'};
+ }
+ my $attachmenturls = $contrib{$idx.':attachmenturl'};
$message=~s/\n/\
/g;
- $message=&Apache::lontexconvert::msgtexconverted($message,undef,$numoldver);
- my $subject=$contrib{$idx.':subject'};
+ $message=&Apache::lontexconvert::msgtexconverted($message);
+ if ($idx > 0) {
+ if ($contrib{$idx.':subject'} =~ /^/g;
- $subject=&Apache::lontexconvert::msgtexconverted($subject,undef,$numoldver);
+ $subject=&Apache::lontexconvert::msgtexconverted($subject);
}
- if ($contrib{$idx.':attachmenturl'}) {
- my ($fname)
- =($contrib{$idx.':attachmenturl'}=~m|/([^/]+)$|);
- &Apache::lonnet::allowuploaded('/adm/feedback',
- $contrib{$idx.':attachmenturl'});
- $message.=''.&mt('Attachment').
- ': '.
- $fname.'
';
+ if ($attachmenturls) {
+ my %attachments = ();
+ my %currattach = ();
+ &extract_attachments($attachmenturls,$idx,$numoldver,\$message,\%attachments,\%currattach);
}
if ($message) {
if ($hidden) {
@@ -419,6 +447,12 @@ sub list_discussion {
$vgrlink=&Apache::loncommon::submlink('Submissions',
$contrib{$idx.':sendername'},$contrib{$idx.':senderdomain'},$symb);
}
+ my $ctlink;
+ if ($dischash{$readkey}=~/\.$idx\./) {
+ $ctlink = ''.&mt('Mark unread').'? ';
+ } else {
+ $ctlink = ''.&mt('Mark read').'? ';
+ }
#figure out at what position this needs to print
my $thisindex=$idx;
if ( (($ENV{'environment.threadeddiscussion'}) && (($sortposts eq '') || ($sortposts eq 'ascdate'))) || ($sortposts eq 'thread')) {
@@ -430,7 +464,10 @@ sub list_discussion {
my $spansize = 2;
if ($showonlyunread && $prevread > $posttime) {
$notshown{$idx} = 1;
+ } elsif ($showunmark && $dischash{$readkey}=~/\.$idx\./) {
+ $notshown{$idx} = 1;
} else {
+# apply filters
my $uname = $contrib{$idx.':sendername'};
my $udom = $contrib{$idx.':senderdomain'};
my $poster = $uname.':'.$udom;
@@ -492,11 +529,19 @@ sub list_discussion {
$discussionitems[$idx] .= ' '.
''.$subject.' '.
$sender.' '.$vgrlink.' ('.
- localtime($posttime).') | '.
- ''.$message.'
';
+ &Apache::lonlocal::locallocaltime($posttime).')';
+ if ($dischash{$toggkey}) {
+ $discussionitems[$idx].=' '.
+ $ctlink.' | ';
+ }
+ $discussionitems[$idx].= ''.$message.'
';
if ($contrib{$idx.':history'}) {
my @postversions = ();
- $discussionitems[$idx] .= '
'.&mt('This post has been edited by the author.').'
'.&mt('Earlier version(s) were posted on: ');
+ $discussionitems[$idx] .= '
'.&mt('This post has been edited by the author.');
+ if ($seeid) {
+ $discussionitems[$idx] .= ' '.&mt('Display all versions').'';
+ }
+ $discussionitems[$idx].='
'.&mt('Earlier version(s) were posted on: ');
if ($contrib{$idx.':history'} =~ m/:/) {
@postversions = split/:/,$contrib{$idx.':history'};
} else {
@@ -506,7 +551,6 @@ sub list_discussion {
my $version = $i+1;
$discussionitems[$idx] .= ''.$version.'. - '.&Apache::lonlocal::locallocaltime($postversions[$i]).' ';
}
- $discussionitems[$idx] .= '
';
}
}
}
@@ -523,22 +567,31 @@ sub list_discussion {
'cuse' => 'Current discussion settings',
'allposts' => 'All posts',
'unread' => 'New posts only',
+ 'unmark' => 'Unread only',
'ondisp' => 'Once displayed',
- 'onmark' => 'Once marked read',
+ 'onmark' => 'Once marked not NEW',
+ 'toggoff' => 'Off',
+ 'toggon' => 'On',
'disa' => 'Posts to be displayed',
'npce' => 'Posts cease to be marked "NEW"',
+ 'epcb' => 'Each post can be toggled read/unread',
'chgt' => 'Change',
'disp' => 'Display',
'nolo' => 'Not new',
+ 'togg' => 'Toggle read/unread',
);
my $currdisp = $lt{'allposts'};
my $currmark = $lt{'onmark'};
+ my $currtogg = $lt{'toggoff'};
my $dispchange = $lt{'unread'};
my $markchange = $lt{'ondisp'};
+ my $toggchange = $lt{'toggon'};
my $chglink = '/adm/feedback?modifydisp='.$ressymb;
- my $displink = 'onlyunread';
+ my $displinkA = 'onlyunread';
+ my $displinkB = 'onlyunmark';
my $marklink = 'markondisp';
+ my $togglink = 'toggon';
if ($markondisp) {
$currmark = $lt{'ondisp'};
@@ -549,10 +602,24 @@ sub list_discussion {
if ($showonlyunread) {
$currdisp = $lt{'unread'};
$dispchange = $lt{'allposts'};
- $displink = 'allposts';
+ $displinkA = 'allposts';
}
+
+ if ($showunmark) {
+ $currdisp = $lt{'unmark'};
+ $dispchange = $lt{'unmark'};
+ $displinkA='allposts';
+ $displinkB='onlyunread';
+ $showonlyunread = 0;
+ }
+
+ if ($dischash{$toggkey}) {
+ $currtogg = $lt{'toggon'};
+ $toggchange = $lt{'toggoff'};
+ $togglink = 'toggoff';
+ }
- $chglink .= '&changes='.$displink.'_'.$marklink;
+ $chglink .= '&changes='.$displinkA.'_'.$displinkB.'_'.$marklink.'_'.$togglink;
if ($newpostsflag) {
$chglink .= '&previous='.$prevread;
@@ -576,7 +643,7 @@ sub list_discussion {
}
|;
- $discussion.='
-
+
END
- }
+ }
}
if ($discussiononly) {
+ my $now = time;
+ my $attachnum = 0;
+ my $newattachmsg = '';
+ my @currnewattach = ();
+ my @currdelold = ();
+ my $comment = '';
+ my $subject = '';
+ if ($ENV{'form.origpage'}) {
+ &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['addnewattach','deloldattach','delnewattach','timestamp','idx','subject','comment']);
+ $subject = &HTML::Entities::encode($ENV{'form.subject'},'<>&"');
+ $comment = &HTML::Entities::encode($ENV{'form.comment'},'<>&"');
+ my @keepold = ();
+ &process_attachments(\@currnewattach,\@currdelold,\@keepold);
+ if (@currnewattach > 0) {
+ $attachnum += @currnewattach;
+ }
+ }
$discussion.=(<
-
-Note: in anonymous discussion, your name is visible only to
-course faculty
-Title:
-
-
-Attachment (128 KB max size):
-
-
+
+
+Note: in anonymous discussion, your name is visible only
+to course faculty
+Title:
+
ENDDISCUSS
+ if ($ENV{'form.origpage'}) {
+ $discussion.=''."\n";
+ foreach (@currnewattach) {
+ $discussion.=''."\n";
+ }
+ }
+ $discussion.="\n";
if ($outputtarget ne 'tex') {
+ $discussion.=&generate_attachments_button('',$attachnum,$ressymb,$now,\@currnewattach,\@currdelold,'',$mode);
+ if (@currnewattach > 0) {
+ $newattachmsg .= 'New attachments
';
+ if (@currnewattach > 1) {
+ $newattachmsg .= '';
+ foreach my $item (@currnewattach) {
+ $item =~ m#.*/([^/]+)$#;
+ $newattachmsg .= '- '.$1.'
'."\n";
+ }
+ $newattachmsg .= '
'."\n";
+ } else {
+ $currnewattach[0] =~ m#.*/([^/]+)$#;
+ $newattachmsg .= ''.$1.'
'."\n";
+ }
+ }
+ $discussion.=$newattachmsg;
$discussion.=&generate_preview_button();
}
} else {
@@ -772,27 +895,67 @@ ENDDISCUSS
}
}
}
- return $discussion;
+ return $discussion;
}
sub mail_screen {
my ($r,$feedurl,$options) = @_;
+ if (exists($ENV{'form.origpage'})) {
+ &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['subject','comment','currnewattach','addnewattach','deloldattach','delnewattach','timestamp','idx','anondiscuss','discuss']);
+ }
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='';
my $subject = '';
- my $oldmessage = '';
+ my $comment = '';
my $prevtag = '';
my $parentmsg = '';
- my $anonscript = (< 0) {
+ if ($contrib{$idx.':message'} =~ /^/g;
- $quote=''.&Apache::lontexconvert::msgtexconverted($message,undef,$numoldver).'
';
+ $quote=''.&Apache::lontexconvert::msgtexconverted($message).'
';
if ($idx > 0) {
- if ($contrib{'subject'} =~ /::::\d+::::(.+)$/si) {
- $subject = $1;
+ if ($contrib{$idx.':subject'} =~ /^&"');
} else {
- if ($contrib{$idx.':message'} =~ /::::\d+::::(.+)$/si) {
- $oldmessage = $1;
+ $attachmenturls = $contrib{$idx.':attachmenturl'};
+ if ($contrib{$idx.':message'} =~ /^/) {
+ my %versions = ();
+ &get_post_versions(\%versions,$contrib{$idx.':message'},$numoldver);
+ $comment = $versions{$numoldver};
} else {
- $oldmessage = $contrib{$idx.':message'};
+ $comment = &HTML::Entities::encode($contrib{$idx.':message'},'<>&"');
}
- $oldmessage=&HTML::Entities::encode($oldmessage,'<>&"');
- if ($contrib{$idx.':subject'} =~ /::::\d+::::(.+)$/si) {
- $subject = $1;
+ if ($contrib{$idx.':subject'} =~ //) {
+ my %versions = ();
+ &get_post_versions(\%versions,$contrib{$idx.':subject'},$numoldver);
+ $subject = $versions{$numoldver};
} else {
- $subject = $contrib{$idx.':subject'};
+ $subject = &HTML::Entities::encode($contrib{$idx.':subject'},'<>&"');
}
if (defined($contrib{$idx.':replyto'})) {
$parentmsg = $contrib{$idx.':replyto'};
}
- my $anonflag = 0;
- if ($contrib{$idx.':anonymous'}) {
- $anonflag = 1;
- }
- $anonscript = (<';
}
}
+
+ if ($ENV{'form.origpage'}) {
+ $subject = $ENV{'form.subject'};
+ $comment = $ENV{'form.comment'};
+ &process_attachments(\@currnewattach,\@currdelold,\@keepold);
+ }
my $latexHelp=&Apache::loncommon::helpLatexCheatsheet();
my $htmlheader=&Apache::lonhtmlcommon::htmlareaheaders();
- my $onsubmit='';
- if ((&Apache::lonhtmlcommon::htmlareabrowser()) &&
- (!&Apache::lonhtmlcommon::htmlareablocked())) {
- $onsubmit='document.mailform.onsubmit();';
- }
my $send=&mt('Send');
$r->print(<
@@ -912,12 +1103,15 @@ $htmlheader
}
if (rec) {
- $onsubmit
+ if (typeof(document.mailform.onsubmit)!='undefined') {
+ document.mailform.onsubmit();
+ }
document.mailform.submit();
} else {
alert('Please check a feedback type.');
}
}
+ $anonchk
$anonscript
//-->
@@ -939,7 +1133,7 @@ END
END
}
- $r->print(<print(<
$quote
@@ -948,24 +1142,82 @@ $quote
$latexHelp
Title:
-
+END
+ if ( ($ENV{'form.editdisc'}) || ($ENV{'form.replydisc'}) ) {
+ if ($ENV{'form.origpage'}) {
+ foreach (@currnewattach) {
+ $r->print(''."\n");
+ }
+ foreach (@currdelold) {
+ $r->print(''."\n");
+ }
+ }
+ if ($ENV{'form.editdisc'}) {
+ if ($attachmenturls) {
+ &extract_attachments($attachmenturls,$idx,$numoldver,\$attachmsg,\%attachments,\%currattach,\@currdelold);
+ $attachnum = scalar(keys %currattach);
+ foreach (keys %currattach) {
+ $r->print(''."\n");
+ }
+ }
+ }
+ } else {
+ $r->print(<
+END
+ }
+ $r->print(<
-ENDDOCUMENT
-$r->print(&generate_preview_button().
-&Apache::lonhtmlcommon::htmlareaselectactive('comment').
-'