# The LearningOnline Network
# Feedback
#
# $Id: lonfeedback.pm,v 1.78 2004/04/28 21:13:13 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
# This file is part of the LearningOnline Network with CAPA (LON-CAPA).
#
# LON-CAPA is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# LON-CAPA is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with LON-CAPA; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# /home/httpd/html/adm/gpl.txt
#
# http://www.lon-capa.org/
#
###
package Apache::lonfeedback;
use strict;
use Apache::Constants qw(:common);
use Apache::lonmsg();
use Apache::loncommon();
use Apache::lontexconvert();
use Apache::lonlocal;
sub list_discussion {
my ($mode,$status,$symb)=@_;
# &Apache::lonnet::logthis("status is $status");
if (!($status eq 'CAN_ANSWER' || $status eq 'CANNOT_ANSWER'
|| $status eq 'OPEN')) {
return '';
}
my $discussiononly=0;
if ($mode eq 'board') { $discussiononly=1; }
unless ($ENV{'request.course.id'}) { return ''; }
my $crs='/'.$ENV{'request.course.id'};
if ($ENV{'request.course.sec'}) {
$crs.='_'.$ENV{'request.course.sec'};
}
$crs=~s/\_/\//g;
unless ($symb) {
$symb=&Apache::lonnet::symbread();
}
unless ($symb) { return ''; }
my %dischash = &Apache::lonnet::restore($symb,$ENV{'request.course.id'}.'_discuss',$ENV{'user.domain'},$ENV{'user.name'});
my %readids = ();
my $showonlyunread;
foreach my $key (keys %dischash) {
if ($key eq 'showonlyunread') {
$showonlyunread = $dischash{$key};
} else {
if ($dischash{$key} eq 'read') {
$readids{$key} = 1;
}
}
}
my $seeid=&Apache::lonnet::allowed('rin',$crs);
my $viewgrades=(&Apache::lonnet::allowed('vgr',$crs)
&& ($symb=~/\.(problem|exam|quiz|assess|survey|form)$/));
my @discussionitems=();
# backward compatibility (bulletin boards used to be 'wrapped')
my $ressymb=$symb;
if ($mode eq 'board') {
$ressymb=~s|(bulletin___\d+___)|$1adm/wrapper|;
}
my %contrib=&Apache::lonnet::restore($ressymb,$ENV{'request.course.id'},
$ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
$ENV{'course.'.$ENV{'request.course.id'}.'.num'});
my $visible=0;
my @depth=();
my @original=();
my @index=();
my @replies=();
my %alldiscussion=();
my $maxdepth=0;
my $target='';
unless ($ENV{'browser.interface'} eq 'textual' ||
$ENV{'environment.remote'} eq 'off' ) {
$target='target="LONcom"';
}
if ($contrib{'version'}) {
for (my $id=1;$id<=$contrib{'version'};$id++) {
my $idx=$id;
my $hidden=($contrib{'hidden'}=~/\.$idx\./);
my $deleted=($contrib{'deleted'}=~/\.$idx\./);
my $origindex='0.';
if (($contrib{$idx.':replyto'}) && ($ENV{'environment.threadeddiscussion'})) {
# this is a follow-up message
$original[$idx]=$original[$contrib{$idx.':replyto'}];
$depth[$idx]=$depth[$contrib{$idx.':replyto'}]+1;
$origindex=$index[$contrib{$idx.':replyto'}];
if ($depth[$idx]>$maxdepth) { $maxdepth=$depth[$idx]; }
} else {
# this is an original message
$original[$idx]=0;
$depth[$idx]=0;
}
if ($replies[$depth[$idx]]) {
$replies[$depth[$idx]]++;
} else {
$replies[$depth[$idx]]=1;
}
unless ((($hidden) && (!$seeid)) || ($deleted)) {
$visible++;
my $message=$contrib{$idx.':message'};
$message=~s/\n/\
/g;
$message=&Apache::lontexconvert::msgtexconverted($message);
my $subject=$contrib{$idx.':subject'};
if (defined($subject)) {
$subject=~s/\n/\
/g;
$subject=&Apache::lontexconvert::msgtexconverted($subject);
}
if ($contrib{$idx.':attachmenturl'}) {
my ($fname,$ft)
=($contrib{$idx.':attachmenturl'}=~/\/(\w+)\.(\w+)$/);
$message.='
'.&mt('Attachment').': '.$fname.'.'.$ft.'
'; } if ($message) { if ($hidden) { $message=''.$message.''; } my $screenname=&Apache::loncommon::screenname( $contrib{$idx.':sendername'}, $contrib{$idx.':senderdomain'}); my $plainname=&Apache::loncommon::nickname( $contrib{$idx.':sendername'}, $contrib{$idx.':senderdomain'}); my $sender=&mt('Anonymous'); if ((!$contrib{$idx.':anonymous'}) || ($seeid)) { $sender=&Apache::loncommon::aboutmewrapper( $plainname, $contrib{$idx.':sendername'}, $contrib{$idx.':senderdomain'}).' ('. $contrib{$idx.':sendername'}.' at '. $contrib{$idx.':senderdomain'}.')'; if ($contrib{$idx.':anonymous'}) { $sender.=' ['.&mt('anonymous').'] '. $screenname; } if ($seeid) { if ($hidden) { $sender.=' '.&mt('Make Visible').''; } else { $sender.=' '.&mt('Hide').''; } $sender.=' '.&mt('Delete').''; } } else { if ($screenname) { $sender=''.$screenname.''; } } if (&Apache::lonnet::allowed('pch', $ENV{'request.course.id'}. ($ENV{'request.course.sec'}?'/'.$ENV{'request.course.sec'}:''))) { $sender.=' '.&mt('Reply').''; } my $vgrlink; my $ctlink; if ($readids{$idx} == 1) { $ctlink = ''.&mt('Mark unread').'? '. ''; } else { $ctlink = ''.&mt('Mark read').'? '. ''; } if ($viewgrades) { $vgrlink=&Apache::loncommon::submlink('Submissions', $contrib{$idx.':sendername'},$contrib{$idx.':senderdomain'},$symb); } #figure out at what position this needs to print my $thisindex=$idx; if ($ENV{'environment.threadeddiscussion'}) { $thisindex=$origindex.substr('00'.$replies[$depth[$idx]],-2,2); } $alldiscussion{$thisindex}=$idx; $index[$idx]=$thisindex; $discussionitems[$idx]=''.$subject.' '. $sender.' '.$vgrlink.' ('. localtime($contrib{$idx.':timestamp'}). ') | '.$ctlink.' |
Check "Show all posts?" or "Mark unread?", then "Save read settings" to display message |
'.$message.''; } } } } } my $discussion=''; if ($visible) { # Print a the discusssion $discussion .= ''; } if ($discussiononly) { $discussion.=(<
Attachment (128 KB max size):
ENDDISCUSS $discussion.=&generate_preview_button(); } else { if (&Apache::lonnet::allowed('pch', $ENV{'request.course.id'}. ($ENV{'request.course.sec'}?'/'.$ENV{'request.course.sec'}:''))) { $discussion.=''. ''. &mt('Post Discussion').' |
'.&Apache::lontexconvert::msgtexconverted($message).''; $subject = 'Re: '.$contrib{$idx.':subject'}; } } my $latexHelp = Apache::loncommon::helpLatexCheatsheet(); my $send=&mt('Send'); $r->print(<