--- loncom/interface/lonfeedback.pm 2006/11/30 08:51:20 1.225
+++ loncom/interface/lonfeedback.pm 2006/12/08 20:09:29 1.232
@@ -1,7 +1,7 @@
# The LearningOnline Network
# Feedback
#
-# $Id: lonfeedback.pm,v 1.225 2006/11/30 08:51:20 albertel Exp $
+# $Id: lonfeedback.pm,v 1.232 2006/12/08 20:09:29 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -44,7 +44,6 @@ use HTML::LCParser();
use Apache::lonspeller();
use Apache::longroup;
use Cwd;
-use lib '/home/httpd/lib/perl/';
use LONCAPA;
sub discussion_open {
@@ -75,6 +74,9 @@ sub discussion_visible {
sub list_discussion {
my ($mode,$status,$ressymb,$imsextras,$group)=@_;
+ unless ($ressymb) { $ressymb=&Apache::lonnet::symbread(); }
+ unless ($ressymb) { return ''; }
+ $ressymb=&wrap_symb($ressymb);
my $outputtarget=$env{'form.grade_target'};
if (defined($env{'form.export'})) {
if($env{'form.export'}) {
@@ -86,7 +88,12 @@ sub list_discussion {
$outputtarget = 'export';
}
}
- if (not &discussion_visible($status)) { return ''; }
+ if (not &discussion_visible($status)) {
+ if ($mode ne 'board') {
+ my $encsymb=&Apache::lonenc::check_encrypt($ressymb);
+ return &send_message_link($encsymb);
+ }
+ }
if ($group ne '' && $mode eq 'board') {
if (&check_group_priv($group,'vgb') ne 'ok') {
return '';
@@ -95,7 +102,10 @@ sub list_discussion {
my ($blocked,$blocktext) = &blocking_posts('boards',1);
if ($blocked) {
- return $blocktext;
+ if ($mode ne 'board') {
+ my $encsymb=&Apache::lonenc::check_encrypt($ressymb);
+ return $blocktext.'
'.&send_message_link($encsymb);
+ }
}
my @bgcols = ("#cccccc","#eeeeee");
@@ -108,9 +118,6 @@ sub list_discussion {
$crs.='_'.$env{'request.course.sec'};
}
$crs=~s/\_/\//g;
- unless ($ressymb) { $ressymb=&Apache::lonnet::symbread(); }
- unless ($ressymb) { return ''; }
- $ressymb=&wrap_symb($ressymb);
my $encsymb=&Apache::lonenc::check_encrypt($ressymb);
my $viewgrades=(&Apache::lonnet::allowed('vgr',$crs)
&& ($ressymb=~/\.(problem|exam|quiz|assess|survey|form|task)$/));
@@ -723,26 +730,45 @@ END
}
}
} else {
- $discussion.='
';
+ $discussion.='';
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.=''.
- ''.
- &mt('Post Discussion').' ';
+ $discussion.= &send_feedback_link($ressymb,$target).
+ ' ';
}
}
- $discussion.=''.
- &mt('Send Message').' | ';
+ if ($outputtarget ne 'tex') {
+ $discussion.= &send_message_link($ressymb);
+ }
+ $discussion.=' |
';
}
return $discussion;
}
+sub send_feedback_link {
+ my ($ressymb,$target) = @_;
+ my $output = ''.
+ ' '.
+ ''.&mt('Post Discussion').'';
+ return $output;
+}
+
+sub send_message_link {
+ my ($ressymb) = @_;
+ my $output = ''.
+ ' '.&mt('Send Message').'';
+ return $output;
+}
+
sub action_links_bar {
my ($colspan,$ressymb,$visible,$newpostsflag,$group,$prevread,$markondisp) = @_;
my $discussion = ''.
@@ -2711,7 +2737,7 @@ sub decide_receiver {
my %to=();
if ($env{'form.discuss'} eq 'author' ||$author) {
$typestyle.='Submitting as Author Feedback ';
- $feedurl=~/^\/res\/(\w+)\/(\w+)\//;
+ $feedurl=~ m{^/res/($LONCAPA::domain_re)/($LONCAPA::username_re)/};
$to{$2.':'.$1}=1;
}
if ($env{'form.discuss'} eq 'question' ||$question) {
@@ -2817,10 +2843,11 @@ sub adddiscuss {
$contrib{'anonymous'}='true';
}
if (($symb) && ($email)) {
+ my $now = time;
if ($env{'form.editdisc'}) {
$contrib{'ip'}=$ENV{'REMOTE_ADDR'};
$contrib{'host'}=$Apache::lonnet::perlvar{'lonHostID'};
- $contrib{'timestamp'} = time;
+ $contrib{'timestamp'} = $now;
$contrib{'history'} = '';
my $numoldver = 0;
my ($oldsymb,$oldidx)=split(/\:\:\:/,$env{'form.editdisc'});
@@ -2871,7 +2898,7 @@ sub adddiscuss {
$env{'course.'.$env{'request.course.id'}.'.domain'},
$env{'course.'.$env{'request.course.id'}.'.num'});
}
- my %storenewentry=($symb => time);
+ my %storenewentry=($symb => $now);
$status.=' '.&mt('Updating discussion time').': '.
&Apache::lonnet::put('discussiontimes',\%storenewentry,
$env{'course.'.$env{'request.course.id'}.'.domain'},
@@ -2892,6 +2919,48 @@ sub adddiscuss {
return $status.' ';
}
+sub get_discussion_info {
+ my ($idx,%contrib) = @_;
+ my $changelast = 0;
+ my $count = 0;
+ my $hiddenflag = 0;
+ my $deletedflag = 0;
+ my ($hidden,$deleted,%info,$newlastdisc);
+ my $version = $contrib{'version'};
+ if ($version) {
+ for (my $id=$version; $id>0; $id--) {
+ my $vkeys=$contrib{$id.':keys'};
+ my @keys=split(/:/,$vkeys);
+ if (grep(/^hidden$/,@keys)) {
+ if (!$hiddenflag) {
+ $hidden = $contrib{$id.':hidden'};
+ $hiddenflag = 1;
+ }
+ } elsif (grep(/^deleted$/,@keys)) {
+ if (!$deletedflag) {
+ $deleted = $contrib{$id.':deleted'};
+ $deletedflag = 1;
+ }
+ } else {
+ if (($hidden !~/\.$id\./) && ($deleted !~/\.$id\./)) {
+ $count++;
+ $info{$count}{'id'} = $id;
+ $info{$count}{'timestamp'}=$contrib{$id.':timestamp'};
+ }
+ }
+ }
+ if ($info{'1'}{'id'} == $idx) {
+ $changelast = 1;
+ if ($count > 1) {
+ $newlastdisc = $info{'2'}{'timestamp'};
+ } else {
+ $newlastdisc = 0;
+ }
+ }
+ }
+ return ($changelast,$newlastdisc);
+}
+
# ----------------------------------------------------------- Preview function
sub show_preview {
@@ -3560,7 +3629,16 @@ ENDREDIR
if ( ($env{'form.hide'}) && (!$seeid) ) {
$newhash{'studenthidden'} = $currentstudenthidden;
}
-
+ if ($env{'form.hide'}) {
+ my $changelast = 0;
+ my $newlast;
+ ($changelast,$newlast) = &get_discussion_info($idx,%contrib);
+ if ($changelast) {
+ &Apache::lonnet::put('discussiontimes',{$symb => $newlast},
+ $env{'course.'.$env{'request.course.id'}.'.domain'},
+ $env{'course.'.$env{'request.course.id'}.'.num'});
+ }
+ }
&Apache::lonnet::store(\%newhash,$symb,$env{'request.course.id'},
$env{'course.'.$env{'request.course.id'}.'.domain'},
$env{'course.'.$env{'request.course.id'}.'.num'});
@@ -3589,6 +3667,11 @@ ENDREDIR
my %contrib=&Apache::lonnet::restore($symb,$env{'request.course.id'},
$env{'course.'.$env{'request.course.id'}.'.domain'},
$env{'course.'.$env{'request.course.id'}.'.num'});
+ my ($changelast,$newlast) = &get_discussion_info($idx,%contrib);
+ if ($changelast) {
+ &Apache::lonnet::put('discussiontimes',{$symb => $newlast},
+ $env{'course.'.$env{'request.course.id'}.'.domain'}, $env{'course.'.$env{'request.course.id'}.'.num'});
+ }
my %newhash=('deleted' => $contrib{'deleted'}.".$idx.");
&Apache::lonnet::store(\%newhash,$symb,$env{'request.course.id'},
$env{'course.'.$env{'request.course.id'}.'.domain'},
|