";
- } else {
- $discussion.='\vskip 0 mm\noindent\makebox[2 cm][b]{\hrulefill}';
}
- my $thisdepth=$depth[$alldiscussion{$_}];
- if ($outputtarget ne 'tex') {
+ my $thisdepth=$depth[$alldiscussion{$post}];
+ if ($outputtarget ne 'tex' && $outputtarget ne 'export') {
for (1..$thisdepth) {
$discussion.='
';
}
}
my $colspan=$maxdepth-$thisdepth+1;
- if ($outputtarget ne 'tex') {
- $discussion.='
\n";
+ }
+ if ($outputtarget eq 'export') {
+ if ($manifestok) {
+ while ($currdepth > 0) {
+ print $manifestfile " \n";
+ $currdepth --;
+ }
+ print $manifestfile qq|
+
+
+
+ $imsresources
+
+
+ |;
+ close($manifestfile);
+ if ((defined($imsextras)) && ($$imsextras{'caller'} eq 'imsexport')) {
+ $discussion = $copyresult;
+ } else {
+
+#Create zip file in prtspool
+
+ my $imszipfile = '/prtspool/'.
+ $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
+ time.'_'.rand(1000000000).'.zip';
+ my $cwd = &getcwd();
+ my $imszip = '/home/httpd/'.$imszipfile;
+ chdir $tempexport;
+ open(OUTPUT, "zip -r $imszip * 2> /dev/null |");
+ close(OUTPUT);
+ chdir $cwd;
+ $discussion .= &mt('Download the zip file from [_1]Discussion Posting Archive','').' ';
+ if ($copyresult) {
+ $discussion .= &mt('The following errors occurred during export').' - '.$copyresult;
+ }
+ }
+ } else {
+ $discussion .= ' '.&mt('Unfortunately you will not be able to retrieve an archive of the discussion posts at this time, because there was a problem creating a manifest file.').' ';
+ }
+ return $discussion;
+ }
}
if ($discussiononly) {
- $discussion.=(<
-
-
-
-
-
-Note: in anonymous discussion, your name is visible only to
-course faculty
-Title:
-
-
-Attachment (128 KB max size):
-
-
-ENDDISCUSS
- if ($outputtarget ne 'tex') {
- $discussion.=&generate_preview_button();
+ my $now = time;
+ my $attachnum = 0;
+ 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 = &unescape($env{'form.subject'});
+ $comment = &unescape($env{'form.comment'});
+ my @keepold = ();
+ &process_attachments($currnewattach,$currdelold,\@keepold);
+ if (@{$currnewattach} > 0) {
+ $attachnum += @{$currnewattach};
+ }
+ }
+ if ((&discussion_open($status)) && ($outputtarget ne 'tex')) {
+ if (($group ne '') && ($mode eq 'board')) {
+ if ((&check_group_priv($group,'pgd') eq 'ok') &&
+ ($ressymb =~ m{^bulletin___\d+___adm/wrapper/adm/\Q$cdom\E/\Q$cnum\E/\d+/bulletinboard$})) {
+ $discussion .=
+ &postingform_display($mode,$ressymb,$now,$subject,
+ $comment,$outputtarget,$attachnum,
+ $currnewattach,$currdelold,
+ $group,$crstype);
+ }
+ } else {
+ if (&Apache::lonnet::allowed('pch',$env{'request.course.id'}.
+ ($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''))) {
+
+ $discussion.=
+ &postingform_display($mode,$ressymb,$now,$subject,
+ $comment,$outputtarget,$attachnum,
+ $currnewattach,$currdelold,'',$crstype);
+ } else {
+ $discussion.= ''.
+ &mt('This discussion is closed.').'';
+ }
+ }
}
+ if (!(&discussion_open($status)) && ($outputtarget ne 'tex')) {
+ $discussion.= ''.
+ &mt('This discussion is closed.').'';
+ }
+ } elsif ($outputtarget ne 'tex') {
+ $discussion.='
';
+ if (&discussion_open($status) &&
+ &Apache::lonnet::allowed('pch',
+ $env{'request.course.id'}.
+ ($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''))) {
+ $discussion.= &send_feedback_link($ressymb,$target);
+ if ($env{'request.role.adv'}) {
+ my $close = &Apache::lonnet::EXT('resource.0.discussend',$ressymb);
+ my $canvote = &Apache::lonnet::EXT('resource.0.discussvote',$ressymb);
+ if (defined($close) && $close ne '' && $close < time) {
+ if ($canvote eq 'notended') {
+ $discussion .= ' '.&mt('(Posting and voting closed for [_1] roles)',
+ &Apache::lonnet::plaintext('st',$crstype));
+ } else {
+ $discussion .= ' '.&mt('(Closed for [_1] roles)',
+ &Apache::lonnet::plaintext('st',$crstype));
+ }
+ }
+ }
+ } else {
+ $discussion.= ''.&mt('This discussion is closed.').'';
+ }
+ $discussion.= &send_message_link($ressymb).'
'."\n";
+ }
+ $newattachmsg .= ''."\n";
+ } else {
+ $$currnewattach[0] =~ m#.*/([^/]+)$#;
+ $newattachmsg .= ''.$1.' '."\n";
+ }
+ }
+ $postingform .= $newattachmsg;
+ $postingform .= &generate_preview_button();
+ return $postingform;
+}
+
+sub build_posting_display {
+ my ($usernamesort,$subjectsort,$namesort,$notshown,$newitem,$dischash,$shown,$alldiscussion,$imsitems,$imsfiles,$roleinfo,$discussionitems,$replies,$depth,$posters,$maxdepth,$visible,$newpostsflag,$current,$status,$viewgrades,$seeid,$seehidden,$canvote,$prevread,$sortposts,$ressymb,$target,$readkey,$showunmark,$showonlyunread,$totposters,$rolefilter,$sectionpick,$grouppick,$classgroups,$statusfilter,$toggkey,$outputtarget,$anonhash,$anoncnt,$group) = @_;
+ my @original=();
+ my @index=();
+ my $skip_group_check = 0;
+ my $symb=&Apache::lonenc::check_decrypt($ressymb);
+ my $escsymb=&escape($ressymb);
+# These are the discussion contributions
+ 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 (%likes,%userlikes,%userunlikes,@theselikes,$oneplus,$twoplus,$oneminus,$twominus);
+# And these are the likes/unlikes
+ my $thisuser=$env{'user.name'}.':'.$env{'user.domain'};
+ if ($seeid || $canvote) {
+ %likes=&Apache::lonnet::dump('disclikes',
+ $env{'course.'.$env{'request.course.id'}.'.domain'},
+ $env{'course.'.$env{'request.course.id'}.'.num'},
+ '^'.$symb.':');
+# Array with likes to figure out averages, etc.
+ @theselikes=();
+# Hashes containing likes and unlikes for this user.
+ %userlikes=();
+ %userunlikes=();
+ }
+# Is the user allowed to see the real name behind anonymous postings?
+ my $see_anonymous =
+ &Apache::lonnet::allowed('rin',$env{'request.course.id'}.($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''));
+
+ if ((@{$grouppick} == 0) || (grep(/^all$/,@{$grouppick}))) {
+ $skip_group_check = 1;
+ }
+ my (%deletions,%hiddens);
+ if ($contrib{'deleted'}) {
+ my $deleted = $contrib{'deleted'};
+ $deleted =~ s/^\.//;
+ $deleted =~ s/\.$//;
+ %deletions = map { $_ => 1 } (split(/\.\./,$deleted));
+ }
+ if ($contrib{'hidden'}) {
+ my $hidden = $contrib{'hidden'};
+ $hidden =~ s/^\.//;
+ $hidden =~ s/\.$//;
+ %hiddens = map { $_ => 1 } (split(/\.\./,$hidden));
+ }
+ if ($contrib{'version'}) {
+ my $oldest = $contrib{'1:timestamp'};
+ if ($prevread eq '0') {
+ $prevread = $oldest-1;
+ }
+ my ($skiptest,$rolematch,$roleregexp,$secregexp,$statusregexp);
+ if ($sortposts) {
+ ($skiptest,$roleregexp,$secregexp,$statusregexp) =
+ &filter_regexp($rolefilter,$sectionpick,$statusfilter);
+ $rolematch = $roleregexp.':'.$secregexp.':'.$statusregexp;
+ }
+ if ($seeid || $canvote) {
+# We need to go through this twice, first to get the likes/dislikes, then to actually build the display
+ for (my $id=1;$id<=$contrib{'version'};$id++) {
+ my $idx=$id;
+ next if ($contrib{$idx.':deleted'});
+ next if ($contrib{$idx.':hidden'});
+ unless ((($hiddens{$idx}) && (!$seehidden)) || ($deletions{$idx}) || (!$contrib{$idx.':message'})) {
+ if ($likes{$symb.':'.$idx.':likes'} ne '') {
+ push(@theselikes,$likes{$symb.':'.$idx.':likes'});
+ if (ref($likes{$symb.':'.$idx.':likers'}) eq 'HASH') {
+ if (exists($likes{$symb.':'.$idx.':likers'}{$thisuser})) {
+ $userlikes{$idx} = 1;
+ }
+ }
+ if (ref($likes{$symb.':'.$idx.':unlikers'}) eq 'HASH') {
+ if (exists($likes{$symb.':'.$idx.':unlikers'}{$thisuser})) {
+ $userunlikes{$idx} = 1;
+ }
+ }
+ }
+ }
+ }
+# Figure out average likes and standard deviation if there are enough
+# discussions to warrant that
+ my $ave=0;
+ my $stddev=10000;
+ if ($#theselikes>1) {
+ my $sum=0;
+ my $num=$#theselikes+1;
+ foreach my $thislike (@theselikes) {
+ $sum+=$thislike;
+ }
+ $ave=$sum/$num;
+ my $sumsq=0;
+ foreach my $thislike (@theselikes) {
+ $sumsq+=($thislike-$ave)*($thislike-$ave);
+ }
+ $stddev=sqrt($sumsq/$num);
+ }
+# Now we know the average likes $ave and the standard deviation $stddev
+# Get the boundaries for markup
+ $oneplus=$ave+$stddev;
+ $twoplus=$ave+2.*$stddev;
+ $oneminus=$ave-$stddev;
+ $twominus=$ave-2.*$stddev;
+ }
+#
+# This is now the real loop. Go through all entries, pick up what we need
+#
+ for (my $id=1;$id<=$contrib{'version'};$id++) {
+ my $idx=$id;
+ next if ($contrib{$idx.':deleted'});
+ next if ($contrib{$idx.':hidden'});
+ my $posttime = $contrib{$idx.':timestamp'};
+ if ($prevread <= $posttime) {
+ $$newpostsflag = 1;
+ }
+ my $studenthidden=($contrib{'studenthidden'}=~/\.$idx\./);
+ my $origindex='0.';
+ my $numoldver=0;
+ if ($contrib{$idx.':replyto'}) {
+ if ( (($env{'environment.threadeddiscussion'}) && ($sortposts eq '')) || ($sortposts eq 'thread') || ($outputtarget eq 'export')) {
+# 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 {
+ $original[$idx]=0;
+ $$depth[$idx]=0;
+ }
+ } 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 ((($hiddens{$idx}) && (!$seehidden)) || ($deletions{$idx})) {
+ $$visible++;
+ if ($contrib{$idx.':history'}) {
+ if ($contrib{$idx.':history'} =~ /:/) {
+ my @oldversions = split(/:/,$contrib{$idx.':history'});
+ $numoldver = @oldversions;
+ } else {
+ $numoldver = 1;
+ }
+ }
+ $$current = $numoldver;
+ my %messages = ();
+ my %subjects = ();
+ my %attachtxt = ();
+ my %allattachments = ();
+ my ($screenname,$plainname,$showaboutme);
+ my $sender = &mt('Anonymous');
+# Anonymous users getting number within a discussion
+# Since idx is in static order, this should give the same sequence every time.
+ my $key=$contrib{$idx.':sendername'}.'@'.$contrib{$idx.':senderdomain'};
+ unless ($$anonhash{$key}) {
+ $anoncnt++;
+ $$anonhash{$key}=&mt('Anonymous').' '.$anoncnt;
+ }
+ my ($message,$subject,$vgrlink,$ctlink);
+ &get_post_contents(\%contrib,$idx,$seeid,$seehidden,$outputtarget,\%messages,\%subjects,\%allattachments,\%attachtxt,$imsfiles,\$screenname,\$plainname,\$showaboutme,$numoldver);
+
+
+# Set up for sorting by subject
+ unless ($outputtarget eq 'export') {
+ $message=$messages{$numoldver};
+ $message.=$attachtxt{$numoldver};
+ $subject=$subjects{$numoldver};
+ if ($message) {
+ if ($hiddens{$idx}) {
+ $message=''.$message.'';
+ if ($studenthidden) {
+ $message .='
Deleted by poster (student).';
+ }
+ }
+
+ if ($subject eq '') {
+ if (defined($$subjectsort{'__No subject'})) {
+ push(@{$$subjectsort{'__No subject'}}, $idx);
+ } else {
+ @{$$subjectsort{'__No subject'}} = ("$idx");
+ }
+ } else {
+ if (defined($$subjectsort{$subject})) {
+ push(@{$$subjectsort{$subject}}, $idx);
+ } else {
+ @{$$subjectsort{$subject}} = ("$idx");
+ }
+ }
+ if (!$contrib{$idx.':anonymous'} || $see_anonymous) {
+ if ($showaboutme) {
+ $sender = &Apache::loncommon::aboutmewrapper(
+ $plainname,
+ $contrib{$idx.':sendername'},
+ $contrib{$idx.':senderdomain'});
+ } else {
+ $sender = $plainname;
+ }
+ if ($see_anonymous) {
+ $sender .= ' ('.$contrib{$idx.':sendername'}.':'.
+ $contrib{$idx.':senderdomain'}.')';
+ }
+ $sender = ''.$sender.'';
+ if ($contrib{$idx.':anonymous'}) {
+ $sender.=' ['.$$anonhash{$key}.'] '.
+ $screenname;
+ }
+ if ($see_anonymous) {
+ $sender.=&Apache::loncommon::student_image_tag($contrib{$idx.':senderdomain'},$contrib{$idx.':sendername'});
+ }
+# Set up for sorting by domain, then username
+ unless (defined($$usernamesort{$contrib{$idx.':senderdomain'}})) {
+ %{$$usernamesort{$contrib{$idx.':senderdomain'}}} = ();
+ }
+ if (defined($$usernamesort{$contrib{$idx.':senderdomain'}}{$contrib{$idx.':sendername'}})) {
+ push(@{$$usernamesort{$contrib{$idx.':senderdomain'}}{$contrib{$idx.':sendername'}}}, $idx);
+ } else {
+ @{$$usernamesort{$contrib{$idx.':senderdomain'}}{$contrib{$idx.':sendername'}}} = ("$idx");
+ }
+# Set up for sorting by last name, then first name
+ my %names = &Apache::lonnet::get('environment',
+ ['firstname','lastname'],$contrib{$idx.':senderdomain'},
+ ,$contrib{$idx.':sendername'});
+ my $lastname = $names{'lastname'};
+ my $firstname = $names{'firstname'};
+ if ($lastname eq '') {
+ $lastname = '_';
+ }
+ if ($firstname eq '') {
+ $firstname = '_';
+ }
+ unless (defined($$namesort{$lastname})) {
+ %{$$namesort{$lastname}} = ();
+ }
+ if (defined($$namesort{$lastname}{$firstname})) {
+ push(@{$$namesort{$lastname}{$firstname}}, $idx);
+ } else {
+ @{$$namesort{$lastname}{$firstname}} = ("$idx");
+ }
+ if ($outputtarget ne 'tex') {
+ if (&editing_allowed($escsymb.':::'.$idx,$group)) {
+ if (($env{'user.domain'} eq $contrib{$idx.':senderdomain'}) && ($env{'user.name'} eq $contrib{$idx.':sendername'})) {
+ $sender.=' '.&mt('Edit').'';
+
+ unless ($seehidden) {
+ my $grpargs = &group_args($group);
+ $sender.=" ';
+ }
+ }
+ }
+ if ($seehidden) {
+ if ($hiddens{$idx}) {
+ unless ($studenthidden) {
+ $sender.=' '.&mt('Make Visible').'';
+ }
+ } else {
+ $sender.=' '.&mt('Hide').'';
+ }
+ my $grpargs = &group_args($group);
+ $sender.=
+ " ";
+ $sender .= &mt('Delete').'';
+ }
+ }
+ } else {
+ if ($screenname) {
+ $sender=''.$screenname.'';
+ } else {
+ $sender=''.$$anonhash{$key}.'';
+ }
+ $sender = ''.$sender.'';
+# Set up for sorting by domain, then username for anonymous
+ unless (defined($$usernamesort{'__anon'})) {
+ %{$$usernamesort{'__anon'}} = ();
+ }
+ if (defined($$usernamesort{'__anon'}{'__anon'})) {
+ push(@{$$usernamesort{'__anon'}{'__anon'}}, $idx);
+ } else {
+ @{$$usernamesort{'__anon'}{'__anon'}} = ("$idx");
+ }
+# Set up for sorting by last name, then first name for anonymous
+ unless (defined($$namesort{'__anon'})) {
+ %{$$namesort{'__anon'}} = ();
+ }
+ if (defined($$namesort{'__anon'}{'__anon'})) {
+ push(@{$$namesort{'__anon'}{'__anon'}}, $idx);
+ } else {
+ @{$$namesort{'__anon'}{'__anon'}} = ("$idx");
+ }
+ }
+ if ($outputtarget ne 'tex') {
+ if (&discussion_open($status)) {
+ if (($group ne '') &&
+ (&check_group_priv($group,'pgd') eq 'ok')) {
+ $sender.=' '.&mt('Reply').'';
+ } elsif (&Apache::lonnet::allowed('pch',
+ $env{'request.course.id'}.
+ ($env{'request.course.sec'}?'/'.
+ $env{'request.course.sec'}:''))) {
+ $sender.=' '.&mt('Reply').'';
+ }
+ }
+ if ($viewgrades) {
+ $vgrlink=&Apache::loncommon::submlink(&mt('Submissions'),
+ $contrib{$idx.':sendername'},$contrib{$idx.':senderdomain'},$ressymb);
+ }
+ if ($$dischash{$readkey}=~/\.$idx\./) {
+ $ctlink = '';
+ } else {
+ $ctlink = '';
+ }
+ }
+ }
+#figure out at what position this needs to print
+ }
+ if ($outputtarget eq 'export' || $message) {
+ my $thisindex=$idx;
+ if ( (($env{'environment.threadeddiscussion'}) && ($sortposts eq '')) || ($sortposts eq 'thread') || ($outputtarget eq 'export')) {
+ $thisindex=$origindex.substr('00'.$$replies[$$depth[$idx]],-2,2);
+ }
+ $$alldiscussion{$thisindex}=$idx;
+ $$shown{$idx} = 0;
+ $index[$idx]=$thisindex;
+ }
+ if ($outputtarget eq 'export') {
+ %{$$imsitems{$idx}} = ();
+ $$imsitems{$idx}{'isvisible'}='true';
+ if ($hiddens{$idx}) {
+ $$imsitems{$idx}{'isvisible'}='false';
+ }
+ $$imsitems{$idx}{'title'}=$subjects{$numoldver};
+ $$imsitems{$idx}{'message'}=$messages{$numoldver};
+ $$imsitems{$idx}{'attach'}=$attachtxt{$numoldver};
+ $$imsitems{$idx}{'timestamp'}=$contrib{$idx.':timestamp'};
+ $$imsitems{$idx}{'sender'}=$plainname.' ('.
+ $contrib{$idx.':sendername'}.':'.
+ $contrib{$idx.':senderdomain'}.')';
+ $$imsitems{$idx}{'isanonymous'}='false';
+ if ($contrib{$idx.':anonymous'}) {
+ $$imsitems{$idx}{'isanonymous'}='true';
+ }
+ $$imsitems{$idx}{'currversion'}=$numoldver;
+ %{$$imsitems{$idx}{'allattachments'}}=%allattachments;
+ unless ($messages{$numoldver} eq '' && $attachtxt{$numoldver} eq '') {
+ $$shown{$idx} = 1;
+ }
+ } else {
+ if ($message) {
+ my $spansize = 2;
+ my ($uname,$udom);
+ if ($showonlyunread && $prevread > $posttime) {
+ $$notshown{$idx} = 1;
+ } elsif ($showunmark && $$dischash{$readkey}=~/\.$idx\./) {
+ $$notshown{$idx} = 1;
+ } else {
+# apply filters
+ $uname = $contrib{$idx.':sendername'};
+ $udom = $contrib{$idx.':senderdomain'};
+ my $poster = $uname.':'.$udom;
+ if ($env{'form.totposters'} ne '') {
+ if ($totposters == 0) {
+ $$shown{$idx} = 0;
+ } elsif ($totposters > 0) {
+ if (grep/^$poster$/,@{$posters}) {
+ $$shown{$idx} = 1;
+ }
+ }
+ } elsif ($sortposts) {
+ if ($skiptest) {
+ $$shown{$idx} = 1;
+ } else {
+ foreach my $role (@{$$roleinfo{$poster}}) {
+ if ($role =~ /^cc:/) {
+ my $cc_regexp = $roleregexp.':[^:]*:'.$statusregexp;
+ if ($role =~ /$cc_regexp/) {
+ $$shown{$idx} = 1;
+ last;
+ }
+ } elsif ($role =~ /^$rolematch$/) {
+ $$shown{$idx} = 1;
+ last;
+ }
+ }
+ }
+ if ($$shown{$idx} && !$skip_group_check) {
+ my $showflag = 0;
+ if (ref($$classgroups{$poster}{active}) eq 'HASH') {
+ foreach my $grp (@{$grouppick}) {
+ if (grep/^\Q$grp\E$/,
+ keys(%{$$classgroups{$poster}{active}})) {
+ $showflag = 1;
+ last;
+ }
+ }
+ }
+ if ($showflag) {
+ $$shown{$idx} = 1;
+ } else {
+ $$shown{$idx} = 0;
+ }
+ }
+ } else {
+ $$shown{$idx} = 1;
+ }
+ }
+ unless ($$notshown{$idx} == 1) {
+ if ($prevread > 0 && $prevread <= $posttime) {
+ $$newitem{$idx} = 1;
+ $$discussionitems[$idx] .= '
+