File:
[LON-CAPA] /
loncom /
interface /
lonfeedback.pm
Revision
1.349:
download - view:
text,
annotated -
select for diffs
Sat Mar 17 04:02:28 2012 UTC (12 years, 6 months ago) by
raeburn
Branches:
MAIN
CVS tags:
HEAD
- Change to aggregate data stored for likes/votes totals for posters.
- replace totalvotes with totalunlikes (totalvotes now computed
when needed from totalunlikes + totallikes, to avoid multiple counts
in totalvotes when voter changes his/her mind.
- context (like, unlike, delete, undelete, hide, unhide) stored for each
record in poster's aggregate data instead of likes (was 1 or -1).
- deletion, undeletion, hiding and unhiding a post cause totalunlikes and
totallikes for poster to be updated appropriately.
1: # The LearningOnline Network
2: # Feedback
3: #
4: # $Id: lonfeedback.pm,v 1.349 2012/03/17 04:02:28 raeburn Exp $
5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
28: ###
29:
30: package Apache::lonfeedback;
31:
32: use strict;
33: use Apache::Constants qw(:common);
34: use Apache::lonmsg();
35: use Apache::loncommon();
36: use Apache::lontexconvert();
37: use Apache::lonlocal; # must not have ()
38: use Apache::lonnet;
39: use Apache::lonhtmlcommon();
40: use Apache::lonnavmaps;
41: use Apache::lonenc();
42: use Apache::lonrss();
43: use HTML::LCParser();
44: #use HTML::Tidy::libXML;
45: use Apache::lonspeller();
46: use Apache::longroup;
47: use Cwd;
48: use LONCAPA;
49:
50: sub discussion_open {
51: my ($status,$symb)=@_;
52: # Advanced roles can always discuss
53: if ($env{'request.role.adv'}) { return 1; }
54: # Get discussion closing date
55: my $close=&Apache::lonnet::EXT('resource.0.discussend',$symb);
56: # If it is defined and in the future, the instructor wants this discussion to be open
57: if (defined($close) && $close ne '' && $close > time) {
58: return 1;
59: }
60: # It was not explicitly open, check if the problem is available.
61: # If the problem is not available, close the discussion
62: if (defined($status) &&
63: !($status eq 'CAN_ANSWER' || $status eq 'CANNOT_ANSWER'
64: || $status eq 'OPEN')) {
65: return 0;
66: }
67: # The problem is available, but check if the instructor explictly closed discussion
68: if (defined($close) && $close ne '' && $close < time) {
69: return 0;
70: }
71: return 1;
72: }
73:
74: sub discussion_visible {
75: my ($status)=@_;
76: if (not &discussion_open($status)) {
77: my $hidden=&Apache::lonnet::EXT('resource.0.discusshide');
78: if (lc($hidden) eq 'yes' or $hidden eq '' or !defined($hidden)) {
79: if (!$env{'request.role.adv'}) { return 0; }
80: }
81: }
82: return 1;
83: }
84:
85: sub discussion_vote_available {
86: my ($status,$symb)=@_;
87: my $canvote=&Apache::lonnet::EXT('resource.0.discussvote',$symb);
88: if ((lc($canvote) eq 'yes') ||
89: ((lc($canvote) eq 'notended') && (&discussion_open($status,$symb)))) {
90: return 1;
91: }
92: }
93:
94: sub get_realsymb {
95: my ($symb) = @_;
96: my $realsymb = $symb;
97: if ($symb=~/^bulletin___/) {
98: my $filename=(&Apache::lonnet::decode_symb($symb))[2];
99: $filename=~s{^adm/wrapper/}{};
100: $realsymb=&Apache::lonnet::symbread($filename);
101: }
102: return $realsymb;
103: }
104:
105: sub list_discussion {
106: my ($mode,$status,$ressymb,$imsextras,$group)=@_;
107: unless ($ressymb) { $ressymb=&Apache::lonnet::symbread(); }
108: unless ($ressymb) { return ''; }
109: $ressymb=&wrap_symb($ressymb);
110: my $outputtarget=$env{'form.grade_target'};
111: if (defined($env{'form.export'})) {
112: if($env{'form.export'}) {
113: $outputtarget = 'export';
114: }
115: }
116: if (defined($imsextras)) {
117: if ($$imsextras{'caller'} eq 'imsexport') {
118: $outputtarget = 'export';
119: }
120: }
121: if (not &discussion_visible($status)) {
122: if ($mode ne 'board') {
123: &Apache::lonenc::check_encrypt(\$ressymb);
124: return '<br /><div class="LC_feedback_link">'.&send_message_link($ressymb)."</div>";
125: }
126: }
127: if ($group ne '' && $mode eq 'board') {
128: if (&check_group_priv($group,'vgb') ne 'ok') {
129: return '';
130: }
131: }
132:
133: my ($blocked,$blocktext) =
134: &Apache::loncommon::blocking_status('boards');
135: if ($blocked) {
136: $blocktext = '<br /><div class="LC_feedback_link"><span class="LC_feedback_link">'.$blocktext."</span>";
137: &Apache::lonenc::check_encrypt(\$ressymb);
138: if ($mode ne 'board') {
139: $blocktext.=&send_message_link($ressymb).'</div>';
140: }else{
141: $blocktext.="</div>";
142: }
143: return $blocktext;
144: }
145:
146: my @bgcols = ("LC_disc_old_item","LC_disc_new_item");
147: my $discussiononly=0;
148: if ($mode eq 'board') { $discussiononly=1; }
149: unless ($env{'request.course.id'}) { return ''; }
150: my $crs='/'.$env{'request.course.id'};
151: my $cid=$env{'request.course.id'};
152: if ($env{'request.course.sec'}) {
153: $crs.='_'.$env{'request.course.sec'};
154: }
155: $crs=~s/\_/\//g;
156: my $encsymb=&Apache::lonenc::check_encrypt($ressymb);
157: my $viewgrades=(&Apache::lonnet::allowed('vgr',$crs)
158: && ($ressymb=~/$LONCAPA::assess_re/));
159:
160: my %usernamesort = ();
161: my %namesort =();
162: my %subjectsort = ();
163:
164: # Get discussion display settings for this discussion
165: my $lastkey = $ressymb.'_lastread';
166: my $showkey = $ressymb.'_showonlyunread';
167: my $markkey = $ressymb.'_showonlyunmark',
168: my $visitkey = $ressymb.'_visit';
169: my $ondispkey = $ressymb.'_markondisp';
170: my $userpickkey = $ressymb.'_userpick';
171: my $toggkey = $ressymb.'_readtoggle';
172: my $readkey = $ressymb.'_read';
173: $ressymb=$encsymb;
174: my %dischash = &Apache::lonnet::get('nohist_'.$cid.'_discuss',[$lastkey,$showkey,$markkey,$visitkey,$ondispkey,$userpickkey,$toggkey,$readkey],$env{'user.domain'},$env{'user.name'});
175: my %discinfo = ();
176: my $showonlyunread = 0;
177: my $showunmark = 0;
178: my $markondisp = 0;
179: my $prevread = 0;
180: my $previous = 0;
181: my $visit = 0;
182: my $newpostsflag = 0;
183: my @posters = split(/\&/,$dischash{$userpickkey});
184:
185: # Retain identification of "NEW" posts identified in last display, if continuing 'previous' browsing of posts.
186: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['previous','sortposts','rolefilter','statusfilter','sectionpick','grouppick','totposters']);
187: my $sortposts = $env{'form.sortposts'};
188: my $statusfilter = $env{'form.statusfilter'};
189: my @sectionpick = split(/,/,$env{'form.sectionpick'});
190: my @grouppick = split(/,/,$env{'form.grouppick'});
191: my @rolefilter = split(/,/,$env{'form.rolefilter'});
192:
193: my $totposters = $env{'form.totposters'};
194: $previous = $env{'form.previous'};
195: if ($previous > 0) {
196: $prevread = $previous;
197: } elsif (defined($dischash{$lastkey})) {
198: unless ($dischash{$lastkey} eq '') {
199: $prevread = $dischash{$lastkey};
200: }
201: }
202:
203: my $cdom = $env{'course.'.$cid.'.domain'};
204: my $cnum = $env{'course.'.$cid.'.num'};
205: my $crstype = &Apache::loncommon::course_type();
206:
207: # Get information about students and non-students in course for filtering display of posts
208: my %roleshash = ();
209: my %roleinfo = ();
210: my ($classgroups,$studentgroups);
211: if ($env{'form.rolefilter'}) {
212: %roleshash = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
213: foreach my $rolekey (keys(%roleshash)) {
214: my ($role,$uname,$udom,$sec) = split(/:/,$rolekey);
215: if ($role =~ /^cr/) {
216: $role = 'cr';
217: }
218: my ($end,$start) = split(/:/,$roleshash{$rolekey});
219: my $now = time;
220: my $status = 'Active';
221: if (($now < $start) || ($end > 0 && $now > $end)) {
222: $status = 'Expired';
223: }
224: if ($uname && $udom) {
225: push(@{$roleinfo{$uname.':'.$udom}}, $role.':'.$sec.':'.$status);
226: }
227: }
228: my ($classlist,$keylist) =
229: &Apache::loncoursedata::get_classlist($cdom,$cnum);
230: my $sec_index = &Apache::loncoursedata::CL_SECTION();
231: my $status_index = &Apache::loncoursedata::CL_STATUS();
232: while (my ($student,$data) = each %$classlist) {
233: my ($section,$status) = ($data->[$sec_index],
234: $data->[$status_index]);
235: push(@{$roleinfo{$student}}, 'st:'.$section.':'.$status);
236: }
237: ($classgroups,$studentgroups) =
238: &Apache::loncoursedata::get_group_memberships($classlist,$keylist,
239: $cdom,$cnum);
240: }
241:
242: # Get discussion display default settings for user
243: if ($env{'environment.discdisplay'} eq 'unread') {
244: $showonlyunread = 1;
245: }
246: if ($env{'environment.discmarkread'} eq 'ondisp') {
247: $markondisp = 1;
248: }
249:
250: # Override user's default if user specified display setting for this discussion
251: if (defined($dischash{$ondispkey})) {
252: unless ($dischash{$ondispkey} eq '') {
253: $markondisp = $dischash{$ondispkey};
254: }
255: }
256: if ($markondisp) {
257: $discinfo{$lastkey} = time;
258: }
259:
260: if (defined($dischash{$showkey})) {
261: unless ($dischash{$showkey} eq '') {
262: $showonlyunread = $dischash{$showkey};
263: }
264: }
265:
266: if (defined($dischash{$markkey})) {
267: unless ($dischash{$markkey} eq '') {
268: $showunmark = $dischash{$markkey};
269: }
270: }
271:
272: if (defined($dischash{$visitkey})) {
273: unless ($dischash{$visitkey} eq '') {
274: $visit = $dischash{$visitkey};
275: }
276: }
277: $visit ++;
278:
279: my $seeid;
280: if (&Apache::lonnet::allowed('rin',$env{'request.course.id'}.($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''))) {
281: $seeid = 1;
282: }
283: my $seehidden = &can_see_hidden($mode,$ressymb,undef,$group,$cdom,$cnum,$crs);
284:
285: # Is voting on discussions available
286: my $realsymb = &get_realsymb($ressymb);
287: my $canvote = &discussion_vote_available($status,$realsymb);
288:
289: my @discussionitems=();
290: my %shown = ();
291: my @posteridentity=();
292:
293: my $current=0;
294: my $visible=0;
295: my @depth=();
296: my @replies = ();
297: my %alldiscussion=();
298: my %imsitems=();
299: my %imsfiles=();
300: my %notshown = ();
301: my %newitem = ();
302: my $maxdepth=0;
303: my %anonhash=();
304: my $anoncnt=0;
305:
306: my $now = time;
307: $discinfo{$visitkey} = $visit;
308:
309: &Apache::lonnet::put('nohist_'.$cid.'_discuss',\%discinfo,$env{'user.domain'},$env{'user.name'});
310: &build_posting_display(\%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,$encsymb,$readkey,$showunmark,$showonlyunread,$totposters,\@rolefilter,\@sectionpick,\@grouppick,$classgroups,$statusfilter,$toggkey,$outputtarget,\%anonhash,$anoncnt,$group);
311:
312: my $discussion='';
313: my $manifestfile;
314: my $manifestok=0;
315: my $tempexport;
316: my $imsresources;
317: my $copyresult;
318:
319: my $function = &Apache::loncommon::get_users_function();
320: my %lt = &Apache::lonlocal::texthash(
321: 'cuse' => 'My settings for this discussion',
322: 'allposts' => 'All posts',
323: 'unread' => 'New posts only',
324: 'unmark' => 'Unread only',
325: 'ondisp' => 'Once displayed',
326: 'onmark' => 'Once marked not NEW',
327: 'toggoff' => 'Off',
328: 'toggon' => 'On',
329: 'disa' => 'Posts to be displayed',
330: 'npce' => 'Posts cease to be marked "NEW"',
331: 'epcb' => 'Each post can be toggled read/unread',
332: 'chgt' => 'Change',
333: 'disp' => 'Display',
334: 'nolo' => 'Not new',
335: 'togg' => 'Toggle read/unread',
336: 'aner' => 'An error occurred opening the manifest file.',
337: 'difo' => 'Discussion for',
338: 'aerr' => 'An error occurred opening the export file for posting',
339: 'aysu' => 'Are you sure you want to delete this post?',
340: 'dpwn' => 'Deleted posts will no longer be visible to you and other students',
341: 'bwco' => 'but will continue to be visible to your instructor',
342: 'depo' => 'Deleted posts will no longer be visible to you or anyone else.',
343: 'discussions' => 'DISCUSSIONS'
344: );
345:
346: my $currdisp = $lt{'allposts'};
347: my $currmark = $lt{'onmark'};
348: my $currtogg = $lt{'toggoff'};
349: my $dispchange = $lt{'unread'};
350: my $markchange = $lt{'ondisp'};
351: my $toggchange = $lt{'toggon'};
352: my $chglink = '/adm/feedback?modifydisp='.$ressymb;
353: my $displinkA = 'onlyunread';
354: my $displinkB = 'onlyunmark';
355: my $marklink = 'markondisp';
356: my $togglink = 'toggon';
357:
358: if ($markondisp) {
359: $currmark = $lt{'ondisp'};
360: $markchange = $lt{'onmark'};
361: $marklink = 'markonread';
362: }
363:
364: if ($showonlyunread) {
365: $currdisp = $lt{'unread'};
366: $dispchange = $lt{'allposts'};
367: $displinkA = 'allposts';
368: }
369:
370: if ($showunmark) {
371: $currdisp = $lt{'unmark'};
372: $dispchange = $lt{'unmark'};
373: $displinkA='allposts';
374: $displinkB='onlyunread';
375: $showonlyunread = 0;
376: }
377:
378: if ($dischash{$toggkey}) {
379: $currtogg = $lt{'toggon'};
380: $toggchange = $lt{'toggoff'};
381: $togglink = 'toggoff';
382: }
383:
384: $chglink .= '&changes='.$displinkA.'_'.$displinkB.'_'.$marklink.'_'.$togglink;
385:
386: if ($newpostsflag) {
387: $chglink .= '&previous='.$prevread;
388: }
389: $chglink.=&group_args($group);
390:
391: if ($visible) {
392: # Print the discusssion
393: if ($outputtarget eq 'tex') {
394: $discussion.='<tex>{\tiny \vskip 0 mm\noindent\makebox[2 cm][b]{\hrulefill}'.
395: '\textbf{'.$lt{'discussions'}.'}\makebox[2 cm][b]{\hrulefill}\vskip 0 mm'.
396: '\noindent\textbf{'.$lt{'disa'}.'}: \textit{'.$currdisp.'}\vskip 0 mm'.
397: '\noindent\textbf{'.$lt{'npce'}.'}: \textit{'.$currmark.'}}</tex>';
398: } elsif ($outputtarget eq 'export') {
399: # Create temporary directory if this is an export
400: my $now = time;
401: if ((defined($imsextras)) && ($$imsextras{'caller'} eq 'imsexport')) {
402: $tempexport = $$imsextras{'tempexport'};
403: if (!-e $tempexport) {
404: mkdir($tempexport,0700);
405: }
406: $tempexport .= '/'.$$imsextras{'count'};
407: if (!-e $tempexport) {
408: mkdir($tempexport,0700);
409: }
410: } else {
411: $tempexport = $Apache::lonnet::perlvar{'lonDaemons'}.'/tmp/ims_exports';
412: if (!-e $tempexport) {
413: mkdir($tempexport,0700);
414: }
415: $tempexport .= '/'.$now;
416: if (!-e $tempexport) {
417: mkdir($tempexport,0700);
418: }
419: $tempexport .= '/'.$env{'user.domain'}.'_'.$env{'user.name'};
420: }
421: if (!-e $tempexport) {
422: mkdir($tempexport,0700);
423: }
424: # open manifest file
425: my $manifest = '/imsmanifest.xml';
426: my $manifestfilename = $tempexport.$manifest;
427: if ($manifestfile = Apache::File->new('>'.$manifestfilename)) {
428: $manifestok=1;
429: print $manifestfile qq|<?xml version="1.0" encoding="UTF-8"?>
430: <manifest xmlns="http://www.imsglobal.org/xsd/imscp_v1p1" xmlns:imsmd="http://www.imsglobal.org/xsd/imsmd_v1p2"
431: xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
432: identifier="MANIFEST-$ressymb" xsi:schemaLocation="http://www.imsglobal.org/xsd/imscp_v1p1
433: imscp_v1p1.xsd http://www.imsglobal.org/xsd/imsmd_v1p2 imsmd_v1p2p2.xsd">
434: <organizations default="$ressymb">
435: <organization identifier="$ressymb">
436: <title>$lt{'difo'} $ressymb</title>\n|;
437: } else {
438: $discussion .= $lt{'aner'}.'<br />';
439: }
440: } else {
441: my $colspan=$maxdepth+1;
442: $discussion.= &Apache::lonhtmlcommon::scripttag(qq|
443: function verifydelete (caller,symb,idx,newflag,previous,groupparm) {
444: var symbparm = symb+':::'+idx
445: var prevparm = ""
446: if (newflag == 1) {
447: prevparm = "&previous="+previous
448: }
449: if (caller == 'studentdelete') {
450: if (confirm("$lt{'aysu'}\\n$lt{'dpwn'},\\n$lt{'bwco'}")) {
451: document.location.href = "/adm/feedback?hide="+symbparm+prevparm+groupparm
452: }
453: } else {
454: if (caller == 'seeiddelete') {
455: if (confirm("$lt{'aysu'}\\n$lt{'depo'}")) {
456: document.location.href = "/adm/feedback?deldisc="+symbparm+prevparm+groupparm
457: }
458: }
459: }
460: }
461: |);
462: $discussion.='<form name="readchoices" method="post" action="/adm/feedback?chgreads='.$ressymb.'" >'.
463: "\n".'<table width="100%" class="LC_discussion">';
464: $discussion .= &action_links_bar($colspan,$ressymb,$visible,
465: $newpostsflag,$group,
466: $prevread,$markondisp,$seehidden);
467: my $escsymb=&escape($ressymb);
468: my $numhidden = keys(%notshown);
469: if ($numhidden > 0) {
470: my $colspan = $maxdepth+1;
471: $discussion.="\n".'<tr><td bgcolor="#CCCCCC" colspan="'.$colspan.'">'.
472: '<a href="/adm/feedback?allposts=1&symb='.$escsymb;
473: if ($newpostsflag) {
474: $discussion .= '&previous='.$prevread;
475: }
476: $discussion .= &group_args($group);
477: $discussion .= '">'.&mt('Show all posts').'</a> '.&mt('to display').' '.
478: $numhidden.' ';
479: if ($showunmark) {
480: $discussion .= &mt('posts previously marked read');
481: } else {
482: $discussion .= &mt('previously viewed posts');
483: }
484: $discussion .= '<br/></td></tr>';
485: }
486: }
487:
488: # Choose sort mechanism
489: my @showposts = ();
490: if ($sortposts eq 'descdate') {
491: @showposts = (sort { $b <=> $a } keys(%alldiscussion));
492: } elsif ($sortposts eq 'thread') {
493: @showposts = (sort { $a <=> $b } keys(%alldiscussion));
494: } elsif ($sortposts eq 'subject') {
495: foreach my $key (sort(keys(%subjectsort))) {
496: push(@showposts, @{$subjectsort{$key}});
497: }
498: } elsif ($sortposts eq 'username') {
499: foreach my $domain (sort(keys(%usernamesort))) {
500: foreach my $key (sort(keys(%{$usernamesort{$domain}}))) {
501: push(@showposts, @{$usernamesort{$domain}{$key}});
502: }
503: }
504: } elsif ($sortposts eq 'lastfirst') {
505: foreach my $last (sort(keys(%namesort))) {
506: foreach my $key (sort(keys(%{$namesort{$last}}))) {
507: push(@showposts, @{$namesort{$last}{$key}});
508: }
509: }
510: } else {
511: @showposts = (sort { $a <=> $b } keys(%alldiscussion));
512: }
513: my $currdepth = 0;
514: my $firstidx = $alldiscussion{$showposts[0]};
515: foreach my $post (@showposts) {
516: unless (($sortposts eq 'thread') || (($sortposts eq '') && ($env{'environment.threadeddiscussion'})) || ($outputtarget eq 'export')) {
517: $alldiscussion{$post} = $post;
518: }
519: unless ( ($notshown{$alldiscussion{$post}} eq '1') || ($shown{$alldiscussion{$post}} == 0) ) {
520: if ($outputtarget ne 'tex' && $outputtarget ne 'export') {
521: $discussion.="\n<tr>";
522: }
523: my $thisdepth=$depth[$alldiscussion{$post}];
524: if ($outputtarget ne 'tex' && $outputtarget ne 'export') {
525: for (1..$thisdepth) {
526: $discussion.='<td> </td>';
527: }
528: }
529: my $colspan=$maxdepth-$thisdepth+1;
530: if ($outputtarget eq 'tex') {
531: #cleanup block
532: $discussionitems[$alldiscussion{$post}]=~s/<table([^>]*)>/<table TeXwidth="90 mm">/;
533: $discussionitems[$alldiscussion{$post}]=~s/<tr([^>]*)><td([^>]*)>/<tr><td TeXwidth="20 mm" align="left">/;
534: my $threadinsert='';
535: if ($thisdepth > 0) {
536: $threadinsert='<br /><strong>Reply: '.$thisdepth.'</strong>';
537: }
538: $discussionitems[$alldiscussion{$post}]=~s/<\/td><td([^>]*)>/$threadinsert<\/td><td TeXwidth="65 mm" align="left">/;
539: $discussionitems[$alldiscussion{$post}]=~s/(<b>|<\/b>|<\/a>|<a([^>]+)>)//g;
540:
541: $discussionitems[$alldiscussion{$post}]='<tex>\vskip 0 mm\noindent\makebox[2 cm][b]{\hrulefill}</tex>'.$discussionitems[$alldiscussion{$post}];
542: $discussion.=$discussionitems[$alldiscussion{$post}];
543: } elsif ($outputtarget eq 'export') {
544: my $postfilename = $alldiscussion{$post}.'-'.$imsitems{$alldiscussion{$post}}{'timestamp'}.'.html';
545: if ($manifestok) {
546: if (($depth[$alldiscussion{$post}] <= $currdepth) && ($alldiscussion{$post} != $firstidx)) {
547: print $manifestfile ' </item>'."\n";
548: }
549: $currdepth = $depth[$alldiscussion{$post}];
550: print $manifestfile "\n".
551: '<item identifier="ITEM-'.$ressymb.'-'.$alldiscussion{$post}.'" isvisible="'.
552: $imsitems{$alldiscussion{$post}}{'isvisible'}.'" identifieref="RES-'.$ressymb.'-'.$alldiscussion{$post}.'">'.
553: '<title>'.$imsitems{$alldiscussion{$post}}{'title'}.'</title></item>';
554: $imsresources .= "\n".
555: '<resource identifier="RES-'.$ressymb.'-'.$alldiscussion{$post}.'" type="webcontent" href="'.$postfilename.'">'."\n".
556: '<file href="'.$postfilename.'">'."\n".
557: $imsfiles{$alldiscussion{$post}}{$imsitems{$alldiscussion{$post}}{'currversion'}}.'</file>'."\n".
558: '</resource>';
559: }
560: my $postingfile;
561: my $postingfilename = $tempexport.'/'.$postfilename;
562: if ($postingfile = Apache::File->new('>'.$postingfilename)) {
563: print $postingfile '<html><head><title>Discussion Post</title></head><body>'.
564: $imsitems{$alldiscussion{$post}}{'title'}.' '.
565: $imsitems{$alldiscussion{$post}}{'sender'}.
566: $imsitems{$alldiscussion{$post}}{'timestamp'}.'<br /><br />'.
567: $imsitems{$alldiscussion{$post}}{'message'}.'<br />'.
568: $imsitems{$alldiscussion{$post}}{'attach'}.'</body></html>'."\n";
569: close($postingfile);
570: } else {
571: $discussion .= $lt{'aerr'}.' '.$alldiscussion{$post}.'<br />';
572: }
573: $copyresult.=&replicate_attachments($imsitems{$alldiscussion{$post}}{'allattachments'},$tempexport);
574: } else {
575: $discussion.='<td class="'.$bgcols[$newitem{$alldiscussion{$post}}].
576: '" colspan="'.$colspan.'">'. $discussionitems[$alldiscussion{$post}].
577: '</td></tr>';
578: }
579: }
580: }
581: unless ($outputtarget eq 'tex' || $outputtarget eq 'export') {
582: my $colspan=$maxdepth+1;
583: $discussion .= <<END;
584: <tr>
585: <td colspan="$colspan">
586: <table width="100%">
587: <tr>
588: <td class="LC_disc_action_left">
589: <font size="-1"><b>$lt{'cuse'}</b>:
590: END
591: if ($newpostsflag) {
592: $discussion .=
593: '1. '.$lt{'disp'}.' - <i>'.$currdisp.'</i> 2. '.$lt{'nolo'}.' - <i>'.$currmark.'</i>';
594: if ($dischash{$toggkey}) {
595: $discussion .= ' 3. '.$lt{'togg'}.' - <i>'.$currtogg.'</i>';
596: }
597: } else {
598: if ($dischash{$toggkey}) {
599: $discussion .= '1. '.$lt{'disp'}.' - <i>'.$currdisp.'</i> 2. '.$lt{'togg'}.' - <i>'.$currtogg.'</i>';
600: } else {
601: $discussion .=
602: $lt{'disp'}.' - <i>'.$currdisp.'</i>';
603: }
604: }
605: $discussion .= <<END;
606: <b><a href="$chglink">$lt{'chgt'}</a></b></font>
607: </td>
608: END
609: if ($sortposts) {
610: my %sort_types = ();
611: my %role_types = ();
612: my %status_types = ();
613: &sort_filter_names(\%sort_types,\%role_types,\%status_types,$crstype);
614:
615: $discussion .= '<td class="LC_disc_action_right"><font size="-1"><b>'.&mt('Sorted by').'</b>: '.$sort_types{$sortposts}.'<br />';
616: if (defined($env{'form.totposters'})) {
617: $discussion .= &mt('Posts by').':';
618: if ($totposters > 0) {
619: foreach my $poster (@posters) {
620: $discussion .= ' '.$poster.',';
621: }
622: $discussion =~ s/,$//;
623: } else {
624: $discussion .= &mt('None selected');
625: }
626: } else {
627: my $filterchoice ='';
628: if (@sectionpick > 0) {
629: $filterchoice = '<i>'.&mt('sections').'</i>- '.$env{'form.sectionpick'};
630: $filterchoice .= ' ';
631: }
632: if (@grouppick > 0) {
633: $filterchoice = '<i>'.&mt('groups').'</i>- '.$env{'form.grouppick'};
634: $filterchoice .= ' ';
635: }
636: if (@rolefilter > 0) {
637: $filterchoice .= '<i>'.&mt('roles').'</i>-';
638: foreach my $role (@rolefilter) {
639: $filterchoice .= ' '.$role_types{$role}.',';
640: }
641: $filterchoice =~ s/,$//;
642: $filterchoice .= '<br />'.(' ' x8);
643: }
644: if ($statusfilter) {
645: $filterchoice .= '<i>'.&mt('status').'</i>- '.$status_types{$statusfilter};
646: }
647: if ($filterchoice) {
648: $discussion .= '<b>'.&mt('Filters').'</b>: '.$filterchoice;
649: }
650: }
651: $discussion .= '</font></td>';
652:
653: }
654: if ($dischash{$toggkey}) {
655: my $storebutton = &mt('Save read/unread changes');
656: $discussion.='<td align="right">'.
657: '<input type="hidden" name="discsymb" value="'.$ressymb.'" />'."\n".
658: '<input type="button" name="readoptions" value="'.$storebutton.'"'.
659: ' onclick="this.form.submit();" />'."\n".
660: '</td>';
661: }
662: $discussion .= (<<END);
663: </tr>
664: </table>
665: </td>
666: </tr>
667: END
668: $discussion .= &action_links_bar($colspan,$ressymb,$visible,
669: $newpostsflag,$group,
670: $prevread,$markondisp,$seehidden);
671: $discussion .= "</table></form>\n";
672: }
673: if ($outputtarget eq 'export') {
674: if ($manifestok) {
675: while ($currdepth > 0) {
676: print $manifestfile " </item>\n";
677: $currdepth --;
678: }
679: print $manifestfile qq|
680: </organization>
681: </organizations>
682: <resources>
683: $imsresources
684: </resources>
685: </manifest>
686: |;
687: close($manifestfile);
688: if ((defined($imsextras)) && ($$imsextras{'caller'} eq 'imsexport')) {
689: $discussion = $copyresult;
690: } else {
691:
692: #Create zip file in prtspool
693:
694: my $imszipfile = '/prtspool/'.
695: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
696: time.'_'.rand(1000000000).'.zip';
697: my $cwd = &getcwd();
698: my $imszip = '/home/httpd/'.$imszipfile;
699: chdir $tempexport;
700: open(OUTPUT, "zip -r $imszip * 2> /dev/null |");
701: close(OUTPUT);
702: chdir $cwd;
703: $discussion .= &mt('Download the zip file from [_1]Discussion Posting Archive','<a href="'.$imszipfile.'">').'</a><br />';
704: if ($copyresult) {
705: $discussion .= &mt('The following errors occurred during export').' - <br />'.$copyresult;
706: }
707: }
708: } else {
709: $discussion .= '<br />'.&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.').'<br />';
710: }
711: return $discussion;
712: }
713: }
714: if ($discussiononly) {
715: my $now = time;
716: my $attachnum = 0;
717: my $currnewattach = [];
718: my $currdelold = [];
719: my $comment = '';
720: my $subject = '';
721: if ($env{'form.origpage'}) {
722: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['addnewattach','deloldattach','delnewattach','timestamp','idx','subject','comment']);
723: $subject = &unescape($env{'form.subject'});
724: $comment = &unescape($env{'form.comment'});
725: my @keepold = ();
726: &process_attachments($currnewattach,$currdelold,\@keepold);
727: if (@{$currnewattach} > 0) {
728: $attachnum += @{$currnewattach};
729: }
730: }
731: if ((&discussion_open($status)) && ($outputtarget ne 'tex')) {
732: if (($group ne '') && ($mode eq 'board')) {
733: if ((&check_group_priv($group,'pgd') eq 'ok') &&
734: ($ressymb =~ m{^bulletin___\d+___adm/wrapper/adm/\Q$cdom\E/\Q$cnum\E/\d+/bulletinboard$})) {
735: $discussion .=
736: &postingform_display($mode,$ressymb,$now,$subject,
737: $comment,$outputtarget,$attachnum,
738: $currnewattach,$currdelold,
739: $group,$crstype);
740: }
741: } else {
742: if (&Apache::lonnet::allowed('pch',$env{'request.course.id'}.
743: ($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''))) {
744:
745: $discussion.=
746: &postingform_display($mode,$ressymb,$now,$subject,
747: $comment,$outputtarget,$attachnum,
748: $currnewattach,$currdelold,'',$crstype);
749: } else {
750: $discussion.= '<span class="LC_feedback_link">'.
751: &mt('This discussion is closed.').'</span>';
752: }
753: }
754: }
755: if (!(&discussion_open($status)) && ($outputtarget ne 'tex')) {
756: $discussion.= '<span class="LC_feedback_link">'.
757: &mt('This discussion is closed.').'</span>';
758: }
759: } elsif ($outputtarget ne 'tex') {
760: $discussion.='<div class="LC_feedback_link">';
761: if (&discussion_open($status) &&
762: &Apache::lonnet::allowed('pch',
763: $env{'request.course.id'}.
764: ($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''))) {
765: $discussion.= &send_feedback_link($ressymb);
766: if ($env{'request.role.adv'}) {
767: my $close = &Apache::lonnet::EXT('resource.0.discussend',$ressymb);
768: my $canvote = &Apache::lonnet::EXT('resource.0.discussvote',$ressymb);
769: if (defined($close) && $close ne '' && $close < time) {
770: if ($canvote eq 'notended') {
771: $discussion .= ' '.&mt('(Posting and voting closed for [_1] roles)',
772: &Apache::lonnet::plaintext('st',$crstype));
773: } else {
774: $discussion .= ' '.&mt('(Closed for [_1] roles)',
775: &Apache::lonnet::plaintext('st',$crstype));
776: }
777: }
778: }
779: } else {
780: $discussion.= '<span class="LC_feedback_link">'.&mt('This discussion is closed.').'</span>';
781: }
782: $discussion.= &send_message_link($ressymb).'</div>';
783: }
784: return $discussion;
785: }
786:
787: sub can_see_hidden {
788: my ($mode,$ressymb,$feedurl,$group,$cdom,$cnum,$crs) = @_;
789: my $seehidden;
790: if ($env{'request.course.id'}) {
791: unless ($cdom ne '' && $cnum ne '') {
792: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
793: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
794: }
795: if ($crs eq '') {
796: $crs = '/'.$env{'request.course.id'};
797: if ($env{'request.course.sec'}) {
798: $crs.='_'.$env{'request.course.sec'};
799: }
800: $crs=~s{_}{/}g;
801: }
802: if ($mode eq '') {
803: $mode='board';
804: if ($feedurl =~ /$LONCAPA::assess_re/) {
805: $mode='problem';
806: }
807: }
808: if (($group ne '') && ($mode eq 'board') &&
809: ($ressymb =~ m{^bulletin___\d+\Q___adm/wrapper/adm/$cdom/$cnum/\E\d+/bulletinboard$})) {
810: if (&check_group_priv($group,'dgp') eq 'ok') {
811: $seehidden = 1;
812: }
813: } else {
814: $seehidden=&Apache::lonnet::allowed('rin',$crs);
815: }
816: }
817: return $seehidden;
818: }
819:
820: sub discussion_link {
821: my ($ressymb,$linktext,$cmd,$item,$flag,$prev,$adds,$title)=@_;
822: my $link='/adm/feedback?inhibitmenu=yes&modal=yes&'.$cmd.'='.&escape($ressymb).':::'.$item;
823: if ($flag) { $link .= '&previous='.$prev; }
824: if ($adds) { $link .= $adds; }
825: my $width=600;
826: my $height=600;
827: if (($cmd eq 'hide') || ($cmd eq 'unhide') || ($cmd eq 'like') || ($cmd eq 'unlike')) {
828: $width=300;
829: $height=200;
830: }
831: return &Apache::loncommon::modal_link($link,$linktext,$width,$height,undef,undef,$title);
832: }
833:
834:
835: sub send_feedback_link {
836: my ($ressymb) = @_;
837: return '<span class="LC_feedback_link">'.
838: &discussion_link($ressymb,
839: '<img alt="" class="LC_noBorder" src="'.
840: &Apache::loncommon::lonhttpdurl('/adm/lonMisc/chat.gif').
841: '" border="0" /><span class="LC_menubuttons_inline_text">'.&mt('Post Discussion').'</span>',
842: 'replydisc').
843: '</span>';
844: }
845:
846: sub send_message_link {
847: my ($ressymb) = @_;
848: my $output = '<span class="LC_message_link">'.
849: &discussion_link($ressymb,
850: '<img alt="" class="LC_noBorder" src="'.
851: &Apache::loncommon::lonhttpdurl('/res/adm/pages/feedback.png').
852: '" border="0" /><span class="LC_menubuttons_inline_text">'.&mt('Send Feedback').'</span>',
853: 'sendmessageonly').
854: '</span>';
855: return $output;
856: }
857:
858: sub action_links_bar {
859: my ($colspan,$ressymb,$visible,$newpostsflag,$group,$prevread,$markondisp,
860: $seehidden) = @_;
861: my $discussion = '<tr><td colspan="'.$colspan.'">'.
862: '<table width="100%"><tr>'.
863: '<td class="LC_disc_action_left">';
864: my $escsymb=&escape($ressymb);
865: if ($visible) {
866: $discussion .= '<a href="/adm/feedback?cmd=threadedon&symb='.$escsymb;
867: if ($newpostsflag) {
868: $discussion .= '&previous='.$prevread;
869: }
870: $discussion .= &group_args($group);
871: $discussion .='">'.&mt('Threaded View').'</a> '.
872: '<a href="/adm/feedback?cmd=threadedoff&symb='.$escsymb;
873: if ($newpostsflag) {
874: $discussion .= '&previous='.$prevread;
875: }
876: $discussion .= &group_args($group);
877: $discussion .='">'.&mt('Chronological View').'</a> ';
878:
879: my $otherviewurl='/adm/feedback?cmd=sortfilter&symb='.$escsymb.'&inhibitmenu=yes&modal=yes';
880: if ($newpostsflag) {
881: $otherviewurl .= '&previous='.$prevread;
882: }
883: $otherviewurl .= &group_args($group);
884: $discussion .= &Apache::loncommon::modal_link($otherviewurl,&mt('Other Views ...'),800,340);
885: $discussion .= '<br />';
886: }
887: $discussion .='<a href="/adm/feedback?export='.$escsymb;
888: if ($newpostsflag) {
889: $discussion .= '&previous='.$prevread;
890: }
891: $discussion .= &group_args($group);
892: $discussion .= '">'.&mt('Export').'</a>';
893: if ($seehidden) {
894: $discussion .= ' ';
895: $discussion .='<a href="/adm/feedback?undeleteall='.$escsymb;
896: if ($newpostsflag) {
897: $discussion .= '&previous='.$prevread;
898: }
899: $discussion .= &group_args($group);
900: $discussion .= '">'.&mt('Undelete all deleted entries').'</a>';
901: }
902: $discussion.='</td>';
903: if ($newpostsflag) {
904: if (!$markondisp) {
905: $discussion .='<td class="LC_disc_action_right"><a href="/adm/preferences?action=changediscussions';
906: $discussion .= &group_args($group);
907: $discussion .= '">'.
908: &mt('My general preferences on what is marked as NEW').
909: '</a><br /><a href="/adm/feedback?markread=1&symb='.$escsymb;
910: $discussion .= &group_args($group);
911: $discussion .= '">'.&mt('Mark NEW posts no longer new').'</a></td>';
912: } else {
913: $discussion .= '<td> </td>';
914: }
915: } else {
916: $discussion .= '<td> </td>';
917: }
918: $discussion .= '</tr></table></td></tr>';
919: return $discussion;
920: }
921:
922: sub postingform_display {
923: my ($mode,$ressymb,$now,$subject,$comment,$outputtarget,$attachnum,
924: $currnewattach,$currdelold,$group,$crstype) = @_;
925: my $newattachmsg;
926: my %lt = &Apache::lonlocal::texthash(
927: 'note' => 'Note: in anonymous discussion, your name is visible only to course faculty',
928: 'title' => 'Title',
929: 'podi' => 'Post Discussion',
930: 'poan' => 'Post Anonymous Discussion',
931: 'newa' => 'New attachments',
932: );
933: if ($crstype eq 'Community') {
934: $lt{'note'} = &mt('Note: in anonymous discussion, your name is visible only to community facilitators');
935: }
936: my ($postingform,$textareaclass);
937: if (&Apache::lonhtmlcommon::htmlareabrowser()) {
938: $postingform = &Apache::lonhtmlcommon::htmlareaselectactive();
939: $textareaclass = 'class="LC_richDefaultOff"';
940: if ($env{'request.course.id'}) {
941: unless (($env{'course.'.$env{'request.course.id'}.'.allow_limited_html_in_feedback'} =~ /^\s*yes\s*$/i) || ($env{'form.sendmessageonly'})) {
942: undef($textareaclass);
943: }
944: }
945: }
946: $postingform .= (<<ENDDISCUSS);
947: <form action="/adm/feedback" method="post" name="mailform" enctype="multipart/form-data"> <input type="submit" name="discuss" value="$lt{'podi'}" />
948: <input type="submit" name="anondiscuss" value="$lt{'poan'}" /> <input type="hidden" name="symb" value="$ressymb" />
949: <input type="hidden" name="sendit" value="true" />
950: <input type="hidden" name="timestamp" value="$now" />
951: <a name="newpost"></a>
952: <font size="1">$lt{'note'}</font><br />
953: <b>$lt{'title'}:</b> <input type="text" name="subject" value="$subject" size="30" /><br />
954: <textarea name="comment" cols="80" rows="14" id="comment" $textareaclass>$comment</textarea>
955: ENDDISCUSS
956: if ($env{'form.origpage'}) {
957: $postingform .= '<input type="hidden" name="origpage" value="'.
958: $env{'form.origpage'}.'" />'."\n";
959: foreach my $att (@{$currnewattach}) {
960: $postingform .= '<input type="hidden" name="currnewattach" '.
961: 'value="'.$att.'" />'."\n";
962: }
963: }
964: if (exists($env{'form.ref'})) {
965: $postingform .= '<input type="hidden" name="ref" value="'.
966: $env{'form.ref'}.'" />';
967: }
968: if ($group ne '') {
969: $postingform .='<input type="hidden" name="group" value="'.$group.'" />';
970: }
971: my $blockblog = &Apache::loncommon::blocking_status('blogs');
972: if (!$blockblog) {
973: $postingform .= &add_blog_checkbox($crstype);
974: }
975: $postingform .= "</form>\n";
976: $postingform .= &generate_attachments_button('',$attachnum,$ressymb,
977: $now,$currnewattach,
978: $currdelold,'',$mode,
979: $blockblog);
980: if ((ref($currnewattach) eq 'ARRAY') && (@{$currnewattach} > 0)) {
981: $newattachmsg = '<br /><b>'.$lt{'newa'}.'</b><br />';
982: if (@{$currnewattach} > 1) {
983: $newattachmsg .= '<ol>';
984: foreach my $item (@{$currnewattach}) {
985: $item =~ m#.*/([^/]+)$#;
986: $newattachmsg .= '<li><a href="'.$item.'">'.$1.'</a></li>'."\n";
987: }
988: $newattachmsg .= '</ol>'."\n";
989: } else {
990: $$currnewattach[0] =~ m#.*/([^/]+)$#;
991: $newattachmsg .= '<a href="'.$$currnewattach[0].'">'.$1.'</a><br />'."\n";
992: }
993: }
994: $postingform .= $newattachmsg;
995: $postingform .= &generate_preview_button();
996: return $postingform;
997: }
998:
999: sub build_posting_display {
1000: 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,$readkey,$showunmark,$showonlyunread,$totposters,$rolefilter,$sectionpick,$grouppick,$classgroups,$statusfilter,$toggkey,$outputtarget,$anonhash,$anoncnt,$group) = @_;
1001: my @original=();
1002: my @index=();
1003: my $skip_group_check = 0;
1004: my $symb=&Apache::lonenc::check_decrypt($ressymb);
1005: my $escsymb=&escape($ressymb);
1006: # These are the discussion contributions
1007: my %contrib=&Apache::lonnet::restore($symb,$env{'request.course.id'},
1008: $env{'course.'.$env{'request.course.id'}.'.domain'},
1009: $env{'course.'.$env{'request.course.id'}.'.num'});
1010: my (%likes,%userlikes,%userunlikes,@theselikes,$oneplus,$twoplus,$oneminus,$twominus);
1011: my $thisuser=$env{'user.name'}.':'.$env{'user.domain'};
1012: if ($seeid || $canvote) {
1013: # And these are the likes/unlikes
1014: %likes=&Apache::lonnet::dump('disclikes',
1015: $env{'course.'.$env{'request.course.id'}.'.domain'},
1016: $env{'course.'.$env{'request.course.id'}.'.num'},
1017: '^'.$symb.':');
1018: # Array with likes to figure out averages, etc.
1019: @theselikes=();
1020: # Hashes containing likes and unlikes for this user.
1021: %userlikes=();
1022: %userunlikes=();
1023: }
1024: # Is the user allowed to see the real name behind anonymous postings?
1025: my $see_anonymous =
1026: &Apache::lonnet::allowed('rin',$env{'request.course.id'}.($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''));
1027:
1028: if ((@{$grouppick} == 0) || (grep(/^all$/,@{$grouppick}))) {
1029: $skip_group_check = 1;
1030: }
1031: # Deletions and hiddens are just lists. Split them up into a hash for quicker lookup
1032: my (%deletions,%hiddens);
1033: if ($contrib{'deleted'}) {
1034: my $deleted = $contrib{'deleted'};
1035: $deleted =~ s/^\.//;
1036: $deleted =~ s/\.$//;
1037: %deletions = map { $_ => 1 } (split(/\.\./,$deleted));
1038: }
1039: if ($contrib{'hidden'}) {
1040: my $hidden = $contrib{'hidden'};
1041: $hidden =~ s/^\.//;
1042: $hidden =~ s/\.$//;
1043: %hiddens = map { $_ => 1 } (split(/\.\./,$hidden));
1044: }
1045: # Versions if store/restore are used to actually store the messages.
1046: if ($contrib{'version'}) {
1047: my $oldest = $contrib{'1:timestamp'};
1048: if ($prevread eq '0') {
1049: $prevread = $oldest-1;
1050: }
1051: my ($skiptest,$rolematch,$roleregexp,$secregexp,$statusregexp);
1052: if ($sortposts) {
1053: ($skiptest,$roleregexp,$secregexp,$statusregexp) =
1054: &filter_regexp($rolefilter,$sectionpick,$statusfilter);
1055: $rolematch = $roleregexp.':'.$secregexp.':'.$statusregexp;
1056: }
1057: if ($seeid || $canvote) {
1058: # We need to go through this twice, first to get the likes/dislikes, then to actually build the display
1059: for (my $id=1;$id<=$contrib{'version'};$id++) {
1060: my $idx=$id;
1061: next if ($contrib{$idx.':deleted'});
1062: next if ($contrib{$idx.':hidden'});
1063: unless ((($hiddens{$idx}) && (!$seehidden)) || ($deletions{$idx}) || (!$contrib{$idx.':message'})) {
1064: if ($likes{$symb.':'.$idx.':likes'} ne '') {
1065: push(@theselikes,$likes{$symb.':'.$idx.':likes'});
1066: if (ref($likes{$symb.':'.$idx.':likers'}) eq 'HASH') {
1067: if (exists($likes{$symb.':'.$idx.':likers'}{$thisuser})) {
1068: $userlikes{$idx} = 1;
1069: }
1070: }
1071: if (ref($likes{$symb.':'.$idx.':unlikers'}) eq 'HASH') {
1072: if (exists($likes{$symb.':'.$idx.':unlikers'}{$thisuser})) {
1073: $userunlikes{$idx} = 1;
1074: }
1075: }
1076: }
1077: }
1078: }
1079: # Figure out average likes and standard deviation if there are enough
1080: # discussions to warrant that
1081: my $ave=0;
1082: my $stddev=10000;
1083: if ($#theselikes>1) {
1084: my $sum=0;
1085: my $num=$#theselikes+1;
1086: foreach my $thislike (@theselikes) {
1087: $sum+=$thislike;
1088: }
1089: $ave=$sum/$num;
1090: my $sumsq=0;
1091: foreach my $thislike (@theselikes) {
1092: $sumsq+=($thislike-$ave)*($thislike-$ave);
1093: }
1094: $stddev=sqrt($sumsq/$num);
1095: }
1096: # Now we know the average likes $ave and the standard deviation $stddev
1097: # Get the boundaries for markup
1098: $oneplus=$ave+$stddev;
1099: $twoplus=$ave+2.*$stddev;
1100: $oneminus=$ave-$stddev;
1101: $twominus=$ave-2.*$stddev;
1102: }
1103: #
1104: # This is now the real loop. Go through all entries, pick up what we need
1105: #
1106: for (my $id=1;$id<=$contrib{'version'};$id++) {
1107: my $idx=$id;
1108: next if ($contrib{$idx.':deleted'});
1109: next if ($contrib{$idx.':hidden'});
1110: # If we get here, we are actually going to display the message - we don't know where and we don't know if we display
1111: # previous edits, but it counts as one entry
1112: my $posttime = $contrib{$idx.':timestamp'};
1113: if ($prevread <= $posttime) {
1114: $$newpostsflag = 1;
1115: }
1116: my $studenthidden=($contrib{'studenthidden'}=~/\.$idx\./);
1117: my $origindex='0.';
1118: my $numoldver=0;
1119: if ($contrib{$idx.':replyto'}) {
1120: if ( (($env{'environment.threadeddiscussion'}) && ($sortposts eq '')) || ($sortposts eq 'thread') || ($outputtarget eq 'export')) {
1121: # this is a follow-up message
1122: $original[$idx]=$original[$contrib{$idx.':replyto'}];
1123: $$depth[$idx]=$$depth[$contrib{$idx.':replyto'}]+1;
1124: $origindex=$index[$contrib{$idx.':replyto'}];
1125: if ($$depth[$idx]>$$maxdepth) { $$maxdepth=$$depth[$idx]; }
1126: } else {
1127: $original[$idx]=0;
1128: $$depth[$idx]=0;
1129: }
1130: } else {
1131: # this is an original message
1132: $original[$idx]=0;
1133: $$depth[$idx]=0;
1134: }
1135: if ($$replies[$$depth[$idx]]) {
1136: $$replies[$$depth[$idx]]++;
1137: } else {
1138: $$replies[$$depth[$idx]]=1;
1139: }
1140: unless ((($hiddens{$idx}) && (!$seehidden)) || ($deletions{$idx})) {
1141: $$visible++;
1142: if ($contrib{$idx.':history'}) {
1143: if ($contrib{$idx.':history'} =~ /:/) {
1144: my @oldversions = split(/:/,$contrib{$idx.':history'});
1145: $numoldver = @oldversions;
1146: } else {
1147: $numoldver = 1;
1148: }
1149: }
1150: $$current = $numoldver;
1151: my %messages = ();
1152: my %subjects = ();
1153: my %attachtxt = ();
1154: my %allattachments = ();
1155: my ($screenname,$plainname,$showaboutme);
1156: my $sender = &mt('Anonymous');
1157: # Anonymous users getting number within a discussion
1158: # Since idx is in static order, this should give the same sequence every time.
1159: my $key=$contrib{$idx.':sendername'}.'@'.$contrib{$idx.':senderdomain'};
1160: unless ($$anonhash{$key}) {
1161: $anoncnt++;
1162: $$anonhash{$key}=&mt('Anonymous').' '.$anoncnt;
1163: }
1164: my ($message,$subject,$vgrlink,$ctlink);
1165: &get_post_contents(\%contrib,$idx,$seeid,$seehidden,$outputtarget,\%messages,\%subjects,\%allattachments,\%attachtxt,$imsfiles,\$screenname,\$plainname,\$showaboutme,$numoldver);
1166:
1167:
1168: # Set up for sorting by subject
1169: unless ($outputtarget eq 'export') {
1170: $message=$messages{$numoldver};
1171: $message.=$attachtxt{$numoldver};
1172: $subject=$subjects{$numoldver};
1173: if ($message) {
1174: if ($hiddens{$idx}) {
1175: $message='<font color="#888888">'.$message.'</font>';
1176: if ($studenthidden) {
1177: $message .='<br /><br />Deleted by poster (student).';
1178: }
1179: }
1180:
1181: if ($subject eq '') {
1182: if (defined($$subjectsort{'__No subject'})) {
1183: push(@{$$subjectsort{'__No subject'}}, $idx);
1184: } else {
1185: @{$$subjectsort{'__No subject'}} = ("$idx");
1186: }
1187: } else {
1188: if (defined($$subjectsort{$subject})) {
1189: push(@{$$subjectsort{$subject}}, $idx);
1190: } else {
1191: @{$$subjectsort{$subject}} = ("$idx");
1192: }
1193: }
1194: if (!$contrib{$idx.':anonymous'} || $see_anonymous) {
1195: if ($showaboutme) {
1196: $sender = &Apache::loncommon::aboutmewrapper(
1197: $plainname,
1198: $contrib{$idx.':sendername'},
1199: $contrib{$idx.':senderdomain'});
1200: } else {
1201: $sender = $plainname;
1202: }
1203: if ($see_anonymous) {
1204: $sender .= ' ('.$contrib{$idx.':sendername'}.':'.
1205: $contrib{$idx.':senderdomain'}.')';
1206: }
1207: $sender = '<b>'.$sender.'</b>';
1208: if ($contrib{$idx.':anonymous'}) {
1209: $sender.=' <font color="red"><b>['.$$anonhash{$key}.']</b></font> '.
1210: $screenname;
1211: }
1212: if ($see_anonymous) {
1213: $sender.=&Apache::loncommon::student_image_tag($contrib{$idx.':senderdomain'},$contrib{$idx.':sendername'});
1214: }
1215: # Set up for sorting by domain, then username
1216: unless (defined($$usernamesort{$contrib{$idx.':senderdomain'}})) {
1217: %{$$usernamesort{$contrib{$idx.':senderdomain'}}} = ();
1218: }
1219: if (defined($$usernamesort{$contrib{$idx.':senderdomain'}}{$contrib{$idx.':sendername'}})) {
1220: push(@{$$usernamesort{$contrib{$idx.':senderdomain'}}{$contrib{$idx.':sendername'}}}, $idx);
1221: } else {
1222: @{$$usernamesort{$contrib{$idx.':senderdomain'}}{$contrib{$idx.':sendername'}}} = ("$idx");
1223: }
1224: # Set up for sorting by last name, then first name
1225: my %names = &Apache::lonnet::get('environment',
1226: ['firstname','lastname'],$contrib{$idx.':senderdomain'},
1227: ,$contrib{$idx.':sendername'});
1228: my $lastname = $names{'lastname'};
1229: my $firstname = $names{'firstname'};
1230: if ($lastname eq '') {
1231: $lastname = '_';
1232: }
1233: if ($firstname eq '') {
1234: $firstname = '_';
1235: }
1236: unless (defined($$namesort{$lastname})) {
1237: %{$$namesort{$lastname}} = ();
1238: }
1239: if (defined($$namesort{$lastname}{$firstname})) {
1240: push(@{$$namesort{$lastname}{$firstname}}, $idx);
1241: } else {
1242: @{$$namesort{$lastname}{$firstname}} = ("$idx");
1243: }
1244: if ($outputtarget ne 'tex') {
1245: # Add karma stars
1246: my $karma=&userkarma($contrib{$idx.':sendername'},$contrib{$idx.':senderdomain'});
1247: for (my $i=1;$i<=$karma;$i++) {
1248: $sender.='<img border="0" src="/res/adm/pages/star.gif" alt="'.&mt('Contributor Kudos').'" />';
1249: }
1250: # Can people edit this?
1251: if (&editing_allowed($escsymb.':::'.$idx,$group)) {
1252: if (($env{'user.domain'} eq $contrib{$idx.':senderdomain'}) && ($env{'user.name'} eq $contrib{$idx.':sendername'})) {
1253: $sender.=' '.
1254: &discussion_link($symb,&mt('Edit'),'editdisc',$idx,$$newpostsflag,$prevread,&group_args($group));
1255: unless ($seehidden) {
1256: my $grpargs = &group_args($group);
1257: $sender.=" <a href=\"javascript:verifydelete('studentdelete','$escsymb','$idx','$$newpostsflag','$prevread','$grpargs')";
1258: $sender .= '">'.&mt('Delete').'</a>';
1259: }
1260: }
1261: }
1262: if ($seehidden) {
1263: if ($hiddens{$idx}) {
1264: unless ($studenthidden) {
1265: $sender.=' '.
1266: &discussion_link($symb,&mt('Make Visible'),'unhide',$idx,$$newpostsflag,$prevread,&group_args($group));
1267: }
1268: } else {
1269: $sender.=' '.
1270: &discussion_link($symb,&mt('Hide'),'hide',$idx,$$newpostsflag,$prevread,&group_args($group));
1271: }
1272: my $grpargs = &group_args($group);
1273: $sender.=
1274: " <a href=\"javascript:verifydelete('seeiddelete','$escsymb','$idx','$$newpostsflag','$prevread','$grpargs')\">";
1275: $sender .= &mt('Delete').'</a>';
1276: }
1277: }
1278: } else {
1279: if ($screenname) {
1280: $sender='<i>'.$screenname.'</i>';
1281: } else {
1282: $sender='<i>'.$$anonhash{$key}.'</i>';
1283: }
1284: $sender = '<b>'.$sender.'</b>';
1285: # Set up for sorting by domain, then username for anonymous
1286: unless (defined($$usernamesort{'__anon'})) {
1287: %{$$usernamesort{'__anon'}} = ();
1288: }
1289: if (defined($$usernamesort{'__anon'}{'__anon'})) {
1290: push(@{$$usernamesort{'__anon'}{'__anon'}}, $idx);
1291: } else {
1292: @{$$usernamesort{'__anon'}{'__anon'}} = ("$idx");
1293: }
1294: # Set up for sorting by last name, then first name for anonymous
1295: unless (defined($$namesort{'__anon'})) {
1296: %{$$namesort{'__anon'}} = ();
1297: }
1298: if (defined($$namesort{'__anon'}{'__anon'})) {
1299: push(@{$$namesort{'__anon'}{'__anon'}}, $idx);
1300: } else {
1301: @{$$namesort{'__anon'}{'__anon'}} = ("$idx");
1302: }
1303: }
1304: if ($outputtarget ne 'tex') {
1305: if (&discussion_open($status)) {
1306: if (($group ne '') &&
1307: (&check_group_priv($group,'pgd') eq 'ok')) {
1308: $sender.=' '.
1309: &discussion_link($symb,&mt('Reply'),'replydisc',$idx,$$newpostsflag,$prevread,&group_args($group));
1310: } elsif (&Apache::lonnet::allowed('pch',
1311: $env{'request.course.id'}.
1312: ($env{'request.course.sec'}?'/'.
1313: $env{'request.course.sec'}:''))) {
1314: $sender.=' '.
1315: &discussion_link($symb,&mt('Reply'),'replydisc',$idx,$$newpostsflag,$prevread);
1316: }
1317: }
1318: if ($viewgrades) {
1319: $vgrlink=&Apache::loncommon::submlink(&mt('Submissions'),
1320: $contrib{$idx.':sendername'},$contrib{$idx.':senderdomain'},$ressymb);
1321: }
1322: if ($$dischash{$readkey}=~/\.$idx\./) {
1323: $ctlink = '<label><b>'.&mt('Mark unread').'?</b> <input type="checkbox" name="postunread_'.$idx.'" /></label>';
1324: } else {
1325: $ctlink = '<label><b>'.&mt('Mark read').'?</b> <input type="checkbox" name="postread_'.$idx.'" /></label>';
1326: }
1327: }
1328: }
1329: #figure out at what position this needs to print
1330: }
1331: if ($outputtarget eq 'export' || $message) {
1332: my $thisindex=$idx;
1333: if ( (($env{'environment.threadeddiscussion'}) && ($sortposts eq '')) || ($sortposts eq 'thread') || ($outputtarget eq 'export')) {
1334: $thisindex=$origindex.substr('00'.$$replies[$$depth[$idx]],-2,2);
1335: }
1336: $$alldiscussion{$thisindex}=$idx;
1337: $$shown{$idx} = 0;
1338: $index[$idx]=$thisindex;
1339: }
1340: if ($outputtarget eq 'export') {
1341: %{$$imsitems{$idx}} = ();
1342: $$imsitems{$idx}{'isvisible'}='true';
1343: if ($hiddens{$idx}) {
1344: $$imsitems{$idx}{'isvisible'}='false';
1345: }
1346: $$imsitems{$idx}{'title'}=$subjects{$numoldver};
1347: $$imsitems{$idx}{'message'}=$messages{$numoldver};
1348: $$imsitems{$idx}{'attach'}=$attachtxt{$numoldver};
1349: $$imsitems{$idx}{'timestamp'}=$contrib{$idx.':timestamp'};
1350: $$imsitems{$idx}{'sender'}=$plainname.' ('.
1351: $contrib{$idx.':sendername'}.':'.
1352: $contrib{$idx.':senderdomain'}.')';
1353: $$imsitems{$idx}{'isanonymous'}='false';
1354: if ($contrib{$idx.':anonymous'}) {
1355: $$imsitems{$idx}{'isanonymous'}='true';
1356: }
1357: $$imsitems{$idx}{'currversion'}=$numoldver;
1358: %{$$imsitems{$idx}{'allattachments'}}=%allattachments;
1359: unless ($messages{$numoldver} eq '' && $attachtxt{$numoldver} eq '') {
1360: $$shown{$idx} = 1;
1361: }
1362: } else {
1363: if ($message) {
1364: my $spansize = 2;
1365: my ($uname,$udom);
1366: if ($showonlyunread && $prevread > $posttime) {
1367: $$notshown{$idx} = 1;
1368: } elsif ($showunmark && $$dischash{$readkey}=~/\.$idx\./) {
1369: $$notshown{$idx} = 1;
1370: } else {
1371: # apply filters
1372: $uname = $contrib{$idx.':sendername'};
1373: $udom = $contrib{$idx.':senderdomain'};
1374: my $poster = $uname.':'.$udom;
1375: if ($env{'form.totposters'} ne '') {
1376: if ($totposters == 0) {
1377: $$shown{$idx} = 0;
1378: } elsif ($totposters > 0) {
1379: if (grep/^$poster$/,@{$posters}) {
1380: $$shown{$idx} = 1;
1381: }
1382: }
1383: } elsif ($sortposts) {
1384: if ($skiptest) {
1385: $$shown{$idx} = 1;
1386: } else {
1387: foreach my $role (@{$$roleinfo{$poster}}) {
1388: if ($role =~ /^cc:/) {
1389: my $cc_regexp = $roleregexp.':[^:]*:'.$statusregexp;
1390: if ($role =~ /$cc_regexp/) {
1391: $$shown{$idx} = 1;
1392: last;
1393: }
1394: } elsif ($role =~ /^$rolematch$/) {
1395: $$shown{$idx} = 1;
1396: last;
1397: }
1398: }
1399: }
1400: if ($$shown{$idx} && !$skip_group_check) {
1401: my $showflag = 0;
1402: if (ref($$classgroups{$poster}{active}) eq 'HASH') {
1403: foreach my $grp (@{$grouppick}) {
1404: if (grep/^\Q$grp\E$/,
1405: keys(%{$$classgroups{$poster}{active}})) {
1406: $showflag = 1;
1407: last;
1408: }
1409: }
1410: }
1411: if ($showflag) {
1412: $$shown{$idx} = 1;
1413: } else {
1414: $$shown{$idx} = 0;
1415: }
1416: }
1417: } else {
1418: $$shown{$idx} = 1;
1419: }
1420: }
1421: unless ($$notshown{$idx} == 1) {
1422: if ($prevread > 0 && $prevread <= $posttime) {
1423: $$newitem{$idx} = 1;
1424: $$discussionitems[$idx] .= '<font color="#FF0000"><b>'.&mt('NEW').' </b></font>';
1425: } else {
1426: $$newitem{$idx} = 0;
1427: }
1428: $$discussionitems[$idx] .= '<b>'.$subject.'</b> '.
1429: $sender.' '.$vgrlink.' ('.
1430: &Apache::lonlocal::locallocaltime($posttime).')';
1431: if ($$dischash{$toggkey}) {
1432: $$discussionitems[$idx].=' '.$ctlink;
1433: }
1434: my $thislikes=$likes{$symb.':'.$idx.':likes'};
1435: my $likesize="100";
1436: if ($seeid || $canvote) {
1437: # Figure out size based on likes
1438: my $thislikes=$likes{$symb.':'.$idx.':likes'};
1439: if ($thislikes>$twoplus) {
1440: $likesize="200";
1441: } elsif ($thislikes>$oneplus) {
1442: $likesize="150";
1443: }
1444: if ($thislikes<$twominus) {
1445: $likesize="50";
1446: } elsif ($thislikes<$oneminus) {
1447: $likesize="75";
1448: }
1449: }
1450: # Actually glue in the message itself
1451: $$discussionitems[$idx].= '<br /><blockquote>'.
1452: "<div style='font-size:$likesize%'>".
1453: $message.
1454: '</div></blockquote>';
1455: if ($canvote) {
1456: # Put in the like and unlike buttons
1457: if (($uname eq $env{'user.name'}) && ($udom eq $env{'user.domain'})) {
1458: my $novote = &mt('No voting for your own posts');
1459: $$discussionitems[$idx].=
1460: '<a href="javascript:alert('."'$novote'".');" style="text-decoration: none;">'.
1461: '<img border="0" src="/res/adm/pages/thumbsup_novote.png" alt="'.$novote.'" /> '.
1462: '<img border="0" src="/res/adm/pages/thumbsdown_novote.png" alt="'.$novote.'" /></a>';
1463: } else {
1464: if ($userlikes{$idx}) {
1465: $$discussionitems[$idx].='<img border="0" src="/res/adm/pages/thumbsup_gray.png" alt="'.&mt('You like this posting').'" />';
1466: } else {
1467: $$discussionitems[$idx].=' '.&discussion_link($symb,'<img border="0" src="/res/adm/pages/thumbsup.png" alt="'.&mt('Like').'" />','like',$idx,$$newpostsflag,$prevread,&group_args($group),&mt("Like this posting"));
1468: }
1469: if ($userunlikes{$idx}) {
1470: $$discussionitems[$idx].='<img border="0" src="/res/adm/pages/thumbsdown_gray.png" alt="'.&mt('You unlike this posting').'" />';
1471: } else {
1472: $$discussionitems[$idx].=' '.&discussion_link($symb,'<img border="0" src="/res/adm/pages/thumbsdown.png" alt="'.&mt('Unlike').'" />','unlike',$idx,$$newpostsflag,$prevread,&group_args($group),&mt("Unlike this posting"));
1473: }
1474: }
1475: }
1476: if ($seeid || $canvote) {
1477: my $thislikes=$likes{$symb.':'.$idx.':likes'};
1478: if ($thislikes>0) {
1479: $$discussionitems[$idx].=' ('.&mt("[_1] likes",$thislikes).')';
1480: } elsif ($thislikes<0) {
1481: $$discussionitems[$idx].=' ('.&mt("[_1] unlikes",abs($thislikes)).')';
1482: }
1483: }
1484: # If there is any history to this post, inform the reader
1485: if ($contrib{$idx.':history'}) {
1486: my @postversions = ();
1487: $$discussionitems[$idx] .= ' '.&mt('This post has been edited by the author.');
1488: if ($seehidden) {
1489: $$discussionitems[$idx] .= ' '.
1490: &discussion_link($symb,&mt('Display all versions'),'allversions',$idx,$$newpostsflag,$prevread,&group_args($group));
1491: }
1492: $$discussionitems[$idx].='<br/>'.&mt('Earlier version(s) were posted on: ');
1493: if ($contrib{$idx.':history'} =~ m/:/) {
1494: @postversions = split(/:/,$contrib{$idx.':history'});
1495: } else {
1496: @postversions = ("$contrib{$idx.':history'}");
1497: }
1498: for (my $i=0; $i<@postversions; $i++) {
1499: my $version = $i+1;
1500: $$discussionitems[$idx] .= '<b>'.$version.'.</b> - '.&Apache::lonlocal::locallocaltime($postversions[$i]).' ';
1501: }
1502: }
1503: # end of unless ($$notshown ...)
1504: }
1505: # end of if ($message) ...
1506: }
1507: # end of the else-branch of target being export
1508: }
1509: # end of unless hidden or deleted
1510: }
1511: # end of the loop over all discussion entries
1512: }
1513: # end of "if there actually are any discussions
1514: }
1515: # end of subroutine "build_posting_display"
1516: }
1517:
1518: sub filter_regexp {
1519: my ($rolefilter,$sectionpick,$statusfilter) = @_;
1520: my ($roleregexp,$secregexp,$statusregexp);
1521: my $skiptest = 1;
1522: if (@{$rolefilter} > 0) {
1523: my @okrolefilter = ();
1524: foreach my $role (@{$rolefilter}) {
1525: unless ($role eq '') {
1526: push(@okrolefilter, $role);
1527: }
1528: }
1529: if (@okrolefilter > 0) {
1530: if (grep/^all$/,@okrolefilter) {
1531: $roleregexp='[^:]+';
1532: } else {
1533: if (@okrolefilter == 1) {
1534: $roleregexp=$okrolefilter[0];
1535: } else {
1536: $roleregexp='('.join('|',@okrolefilter).')';
1537: }
1538: $skiptest = 0;
1539: }
1540: }
1541: }
1542: if (@{$sectionpick} > 0) {
1543: my @oksectionpick = ();
1544: foreach my $sec (@{$sectionpick}) {
1545: unless ($sec eq '') {
1546: push(@oksectionpick, $sec);
1547: }
1548: }
1549: if ((@oksectionpick > 0) && (!grep/^all$/,@oksectionpick)) {
1550: if (@oksectionpick == 1) {
1551: $secregexp = $oksectionpick[0];
1552: } else {
1553: $secregexp .= '('.join('|',@oksectionpick).')';
1554: }
1555: $skiptest = 0;
1556: } else {
1557: $secregexp .= '[^:]*';
1558: }
1559: }
1560:
1561: if (defined($statusfilter) && $statusfilter ne '') {
1562: if ($statusfilter eq 'all') {
1563: $statusregexp = '[^:]+';
1564: } else {
1565: $statusregexp = $statusfilter;
1566: $skiptest = 0;
1567: }
1568: }
1569: return ($skiptest,$roleregexp,$secregexp,$statusregexp);
1570: }
1571:
1572:
1573: sub get_post_contents {
1574: my ($contrib,$idx,$seeid,$seehidden,$type,$messages,$subjects,$allattachments,$attachtxt,$imsfiles,$screenname,$plainname,$showaboutme,$numver) = @_;
1575: my $discussion = '';
1576: my $start=$numver;
1577: my $end=$numver + 1;
1578: %{$$imsfiles{$idx}}=();
1579: if ($type eq 'allversions') {
1580: unless($seehidden) {
1581: $discussion=&mt('You do not have privileges to view all versions of posts.').' '.&mt('Please select a different role.');
1582: return $discussion;
1583: }
1584: }
1585: # $$screenname=&Apache::loncommon::screenname(
1586: # $$contrib{$idx.':sendername'},
1587: # $$contrib{$idx.':senderdomain'});
1588: $$plainname=&Apache::loncommon::nickname(
1589: $$contrib{$idx.':sendername'},
1590: $$contrib{$idx.':senderdomain'});
1591: $$screenname=$$contrib{$idx.':screenname'};
1592: $$showaboutme = &Apache::lonnet::usertools_access($$contrib{$idx.':sendername'},
1593: $$contrib{$idx.':senderdomain'},
1594: 'aboutme');
1595: my $sender = $$plainname;
1596: if ($$showaboutme) {
1597: $sender = &Apache::loncommon::aboutmewrapper(
1598: $$plainname,
1599: $$contrib{$idx.':sendername'},
1600: $$contrib{$idx.':senderdomain'});
1601: }
1602: if ($seeid) {
1603: $sender .= ' ('.$$contrib{$idx.':sendername'}.':'.
1604: $$contrib{$idx.':senderdomain'}.')';
1605: }
1606: my $attachmenturls = $$contrib{$idx.':attachmenturl'};
1607: my @postversions = ();
1608: if ($type eq 'allversions' || $type eq 'export') {
1609: $start = 0;
1610: if ($$contrib{$idx.':history'}) {
1611: @postversions = split(/:/,$$contrib{$idx.':history'});
1612: }
1613: &get_post_versions($messages,$$contrib{$idx.':message'},1);
1614: &get_post_versions($subjects,$$contrib{$idx.':subject'},1);
1615: push(@postversions,$$contrib{$idx.':timestamp'});
1616: $end = @postversions;
1617: } else {
1618: &get_post_versions($messages,$$contrib{$idx.':message'},1,$numver);
1619: &get_post_versions($subjects,$$contrib{$idx.':subject'},1,$numver);
1620: }
1621:
1622: if ($$contrib{$idx.':anonymous'}) {
1623: $sender.=' ['.&mt('anonymous').'] '.$$screenname;
1624: }
1625: if ($type eq 'allversions') {
1626: $discussion=('<b>'.$sender.'</b><br /><ul>');
1627: }
1628: for (my $i=$start; $i<$end; $i++) {
1629: my ($timesent,$attachmsg);
1630: my %currattach = ();
1631: $timesent = &Apache::lonlocal::locallocaltime($postversions[$i]);
1632: unless (&contains_block_html($messages->{$i})) {
1633: &newline_to_br(\$messages->{$i});
1634: }
1635: $$messages{$i}=&Apache::lontexconvert::msgtexconverted($$messages{$i});
1636: $$subjects{$i}=~s/\n/\<br \/\>/g;
1637: $$subjects{$i}=&Apache::lontexconvert::msgtexconverted($$subjects{$i});
1638: if ($attachmenturls) {
1639: &extract_attachments($attachmenturls,$idx,$i,\$attachmsg,$allattachments,\%currattach);
1640: }
1641: if ($type eq 'export') {
1642: $$imsfiles{$idx}{$i} = '';
1643: if ($attachmsg) {
1644: $$attachtxt{$i} = '<br />'.&mt('Attachments').':<br />';
1645: foreach my $key (sort(keys(%currattach))) {
1646: if ($$allattachments{$key}{'filename'} =~ m-^/uploaded/([^/]+/[^/]+)(/feedback)?(/?\d*)/([^/]+)$-) {
1647: my $fname = $1.$3.'/'.$4;
1648: $$imsfiles{$idx}{$i} .= '<file href="'.$fname.'" />'."\n";
1649: $$attachtxt{$i}.= '<a href="'.$fname.'">'.$4.'</a><br />';
1650: }
1651: }
1652: }
1653: } else {
1654: if ($attachmsg) {
1655: $$attachtxt{$i} = '<br />'.&mt('Attachments').':'.$attachmsg.'<br />';
1656: } else {
1657: $$attachtxt{$i} = '';
1658: }
1659: }
1660: if ($type eq 'allversions') {
1661: $discussion.= <<"END";
1662: <li><b>$$subjects{$i}</b>, $timesent<br />
1663: $$messages{$i}<br />
1664: $$attachtxt{$i}</li>
1665: END
1666: }
1667: }
1668: if ($type eq 'allversions') {
1669: $discussion.='</ul>';
1670: return $discussion;
1671: } else {
1672: return;
1673: }
1674: }
1675:
1676: sub replicate_attachments {
1677: my ($attachrefs,$tempexport) = @_;
1678: my $response;
1679: foreach my $id (keys(%{$attachrefs})) {
1680: if ($$attachrefs{$id}{'filename'} =~ m-^/uploaded/([^/]+)/([^/]+)(/feedback)?(/?\d*)/([^/]+)$-) {
1681: my $path = $tempexport;
1682: my $tail = $1.'/'.$2.$4;
1683: my @extras = split(/\//,$tail);
1684: my $destination = $tempexport.'/'.$1.'/'.$2.$4.'/'.$5;
1685: if (!-e $destination) {
1686: my $i= 0;
1687: while ($i<@extras) {
1688: $path .= '/'.$extras[$i];
1689: if (!-e $path) {
1690: mkdir($path,0700);
1691: }
1692: $i ++;
1693: }
1694: my ($content,$rtncode);
1695: my $uploadreply = &Apache::lonnet::getuploaded('GET',$$attachrefs{$id}{'filename'},$1,$2,$content,$rtncode);
1696: if ($uploadreply eq 'ok') {
1697: my $attachcopy;
1698: if ($attachcopy = Apache::File->new('>'.$destination)) {
1699: print $attachcopy $content;
1700: close($attachcopy);
1701: } else {
1702: $response .= &mt('Error copying file attachment - [_1] to IMS package',$5).': '.$!.'<br />'."\n";
1703: }
1704: } else {
1705: &Apache::lonnet::logthis("Replication of attachment failed when building IMS export of discussion posts - domain: $1, course: $2, file: $$attachrefs{$id}{'filename'} -error: $rtncode");
1706: $response .= &mt('Error copying file attachment - [_1] to IMS package: ',$5).$rtncode.'<br />'."\n";
1707: }
1708: }
1709: }
1710: }
1711: return $response;
1712: }
1713:
1714: sub mail_screen {
1715: my ($r,$feedurl,$options,$caller_symb,$attachmaxtext) = @_;
1716: if (exists($env{'form.origpage'})) {
1717: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['subject','comment','currnewattach','addnewattach','deloldattach','delnewattach','timestamp','idx','anondiscuss','discuss','blog','group','ref']);
1718: }
1719:
1720: my %lt = &Apache::lonlocal::texthash(
1721: 'myqu' => 'Question/comment/feedback:',
1722: 'title' => 'Title',
1723: 'reta' => 'Retained attachments',
1724: 'atta' => 'Attachment',
1725: );
1726: if($env{'form.editdisc'} || $env{'form.replydisc'}){
1727: %lt = &Apache::lonlocal::texthash(
1728: 'myqu' => 'Post Discussion',
1729: );
1730: }
1731: my $restitle = &get_resource_title($caller_symb,$feedurl);
1732: my $quote='';
1733: my $subject = '';
1734: my $comment = '';
1735: my $prevtag = '';
1736: my $parentmsg = '';
1737: my ($symb,$idx,$attachmenturls);
1738: my $numoldver = 0;
1739: my $attachmsg = '';
1740: my $newattachmsg = '';
1741: my @currnewattach = ();
1742: my @currdelold = ();
1743: my @keepold = ();
1744: my %attachments = ();
1745: my %currattach = ();
1746: my $attachnum = 0;
1747: my $anonchk = (<<END);
1748: function anonchk() {
1749: for (var i=0; i < document.mailform.discuss.length; i++) {
1750: if (document.mailform.discuss[i].checked) {
1751: document.attachment.discuss.value =
1752: document.mailform.discuss[i].value;
1753: }
1754: }
1755: if (document.mailform.blog.checked) {
1756: document.attachment.blog.value = 1;
1757: }
1758: return
1759: }
1760: END
1761: my $anonscript;
1762: if (exists($env{'form.origpage'})) {
1763: $anonscript = (<<END);
1764: function setposttype() {
1765: var disc = "$env{'form.discuss'}";
1766: for (var i=0; i < document.mailform.discuss.length; i++) {
1767: if (disc == document.mailform.discuss[i].value) {
1768: document.mailform.discuss[i].checked = 1;
1769: }
1770: }
1771: var blog = "$env{'form.blog'}";
1772: if (blog == 1) {
1773: document.mailform.blog.checked=1;
1774: }
1775: return
1776: }
1777: END
1778: } else {
1779: $anonscript = (<<END);
1780: function setposttype() {
1781: return
1782: }
1783: END
1784: }
1785: if (($env{'form.replydisc'}) || ($env{'form.editdisc'})) {
1786: if ($env{'form.replydisc'}) {
1787: ($symb,$idx)=split(/\:\:\:/,$env{'form.replydisc'});
1788: } else {
1789: ($symb,$idx)=split(/\:\:\:/,$env{'form.editdisc'});
1790: }
1791: my %contrib=&Apache::lonnet::restore($symb,$env{'request.course.id'},
1792: $env{'course.'.$env{'request.course.id'}.'.domain'},
1793: $env{'course.'.$env{'request.course.id'}.'.num'});
1794: unless (($contrib{'hidden'}=~/\.$idx\./) || ($contrib{'deleted'}=~/\.$idx\./)) {
1795: if ($contrib{$idx.':history'}) {
1796: if ($contrib{$idx.':history'} =~ /:/) {
1797: my @oldversions = split(/:/,$contrib{$idx.':history'});
1798: $numoldver = @oldversions;
1799: } else {
1800: $numoldver = 1;
1801: }
1802: }
1803: if ($env{'form.replydisc'}) {
1804: if ($contrib{$idx.':history'}) {
1805: if ($contrib{$idx.':history'} =~ /:/) {
1806: my @oldversions = split(/:/,$contrib{$idx.':history'});
1807: $numoldver = @oldversions;
1808: } else {
1809: $numoldver = 1;
1810: }
1811: }
1812: if ($idx > 0) {
1813: my %msgversions = ();
1814: &get_post_versions(\%msgversions,$contrib{$idx.':message'},0,$numoldver);
1815: $quote = $msgversions{$numoldver};
1816: }
1817: if ($idx > 0) {
1818: my %subversions = ();
1819: &get_post_versions(\%subversions,$contrib{$idx.':subject'},1,$numoldver);
1820: $subject = &mt('Re: ').$subversions{$numoldver};
1821: }
1822: $subject = &HTML::Entities::encode($subject,'<>&"');
1823: } else {
1824: $attachmenturls = $contrib{$idx.':attachmenturl'};
1825: if ($idx > 0) {
1826: my %msgversions = ();
1827: &get_post_versions(\%msgversions,$contrib{$idx.':message'},0,$numoldver);
1828: $comment = $msgversions{$numoldver};
1829: my %subversions = ();
1830: &get_post_versions(\%subversions,$contrib{$idx.':subject'},0,$numoldver);
1831: $subject = $subversions{$numoldver};
1832: }
1833: if (defined($contrib{$idx.':replyto'})) {
1834: $parentmsg = $contrib{$idx.':replyto'};
1835: }
1836: unless (exists($env{'form.origpage'})) {
1837: my $anonflag = 'nonanon';
1838: if ($contrib{$idx.':anonymous'}) {
1839: $anonflag = 'anon';
1840: }
1841: $anonscript = (<<END);
1842: function setposttype () {
1843: var currtype = "$anonflag";
1844: for (var i=0; i<document.mailform.discuss.length; i++) {
1845: if (document.mailform.elements.discuss[i].value == currtype ) {
1846: document.mailform.elements.discuss[i].checked=1;
1847: }
1848: }
1849: return
1850: }
1851: END
1852: }
1853: }
1854: }
1855: if ($env{'form.previous'}) {
1856: $prevtag = '<input type="hidden" name="previous" value="'.$env{'form.previous'}.'" />';
1857: }
1858: }
1859:
1860: if ($env{'form.origpage'}) {
1861: $subject = &unescape($env{'form.subject'});
1862: $comment = &unescape($env{'form.comment'});
1863: &process_attachments(\@currnewattach,\@currdelold,\@keepold);
1864: }
1865: my $latexHelp=&Apache::loncommon::helpLatexCheatsheet(undef,undef,1,($env{'form.modal'}?'popup':0));
1866: my $send=&mt('Send');
1867: my $alert = &mt('Please select a feedback type.');
1868: my $js= <<END;
1869: <script type="text/javascript">
1870: //<!--
1871: function gosubmit() {
1872: var rec=0;
1873: if (typeof(document.mailform.elements.discuss)!="undefined") {
1874: if (typeof(document.mailform.elements.discuss.length) == "undefined") {
1875: if (document.mailform.elements.discuss.checked ) {
1876: rec=1;
1877: }
1878: } else {
1879: for (var i=0; i<document.mailform.elements.discuss.length; i++) {
1880: if (document.mailform.elements.discuss[i].checked ) {
1881: rec=1;
1882: }
1883: }
1884: }
1885: }
1886: if (typeof(document.mailform.elements.blog)!="undefined") {
1887: if (document.mailform.elements.blog.checked) {
1888: rec=1;
1889: }
1890: }
1891:
1892: if (rec) {
1893: if (typeof(document.mailform.onsubmit)=='function') {
1894: document.mailform.onsubmit();
1895: }
1896: document.mailform.submit();
1897: } else {
1898: alert('$alert');
1899: }
1900: }
1901: $anonchk
1902: $anonscript
1903: //-->
1904: </script>
1905: END
1906:
1907: my ($textareaheader,$textareaclass);
1908: if (&Apache::lonhtmlcommon::htmlareabrowser()) {
1909: $textareaheader = &Apache::lonhtmlcommon::htmlareaselectactive();
1910: $textareaclass = 'class="LC_richDefaultOff"';
1911: if ($env{'request.course.id'}) {
1912: unless (($env{'course.'.$env{'request.course.id'}.'.allow_limited_html_in_feedback'} =~ /^\s*yes\s*$/i) || ($env{'form.sendmessageonly'})) {
1913: undef($textareaclass);
1914: }
1915: }
1916: }
1917:
1918: # Breadcrumbs
1919: my $brcrum = [{'href' => '',
1920: 'text' => 'Resource Feedback and Discussion'}];
1921:
1922: my %onload = ('onload' => 'window.focus();setposttype();');
1923: my %parms=('add_entries' => \%onload);
1924: if ($env{'form.modal'} ne 'yes') { 'bread_crumbs' => $brcrum }
1925: my $start_page=
1926: &Apache::loncommon::start_page('Resource Feedback and Discussion',$js,\%parms);
1927:
1928: if ($quote ne '') {
1929: $quote = &HTML::Entities::decode($quote);
1930: unless (&contains_block_html($quote)) {
1931: &newline_to_br(\$quote);
1932: }
1933: $quote='<blockquote>'.&Apache::lontexconvert::msgtexconverted($quote).'</blockquote>';
1934: }
1935: my $header='';
1936: unless ($env{'form.modal'}) {
1937: $header="<h2><tt>$restitle</tt></h2>";
1938: }
1939: $r->print(<<END);
1940: $start_page
1941: <h1>$lt{'myqu'}</h1>
1942: $header
1943: <form action="/adm/feedback" method="post" name="mailform"
1944: enctype="multipart/form-data">
1945: $prevtag
1946: <input type="hidden" name="postdata" value="$feedurl" />
1947: <input type="hidden" name="modal" value="$env{'form.modal'}" />
1948: END
1949: if ($env{'form.replydisc'}) {
1950: $r->print(<<END);
1951: <input type="hidden" name="replydisc" value="$env{'form.replydisc'}" />
1952: END
1953: } elsif ($env{'form.editdisc'}) {
1954: $r->print(<<END);
1955: <input type="hidden" name="editdisc" value="$env{'form.editdisc'}" />
1956: <input type="hidden" name="parentmsg" value="$parentmsg" />
1957: END
1958: }
1959: $r->print(<<END);
1960: $options
1961: $quote
1962: <p>
1963: $textareaheader
1964: </p>
1965: <br>
1966: <p>
1967: $latexHelp
1968: </p>
1969: <p>
1970: END
1971:
1972: $r->print(&Apache::lonhtmlcommon::start_pick_box());
1973: $r->print(&Apache::lonhtmlcommon::row_title(&mt('Subject')));
1974: $r->print('<input type="text" name="subject" size="30" value="'.
1975: $subject.'" /></p>');
1976: $r->print(&Apache::lonhtmlcommon::row_closure());
1977: $r->print(&Apache::lonhtmlcommon::row_title(&mt('Message')));
1978: $r->print('<textarea name="comment" id="comment" cols="60" rows="10" '.
1979: $textareaclass.'>'.$comment.
1980: '</textarea>');
1981: $r->print(&Apache::lonhtmlcommon::row_closure(1));
1982: $r->print(&Apache::lonhtmlcommon::end_pick_box());
1983:
1984: if ( ($env{'form.editdisc'}) || ($env{'form.replydisc'}) ) {
1985: if ($env{'form.origpage'}) {
1986: foreach my $attach (@currnewattach) {
1987: $r->print('<input type="hidden" name="currnewattach" value="'.$attach.'" />'."\n");
1988: }
1989: foreach my $oldatt (@currdelold) {
1990: $r->print('<input type="hidden" name="deloldattach" value="'.$oldatt.'" />'."\n");
1991: }
1992: }
1993: if ($env{'form.editdisc'}) {
1994: if ($attachmenturls) {
1995: &extract_attachments($attachmenturls,$idx,$numoldver,\$attachmsg,\%attachments,\%currattach,\@currdelold);
1996: $attachnum = scalar(keys(%currattach));
1997: foreach my $key (keys(%currattach)) {
1998: $r->print('<input type="hidden" name="keepold" value="'.$key.'" />'."\n");
1999: }
2000: }
2001: }
2002: } else {
2003: $r->print(<<END);
2004: <p>
2005: $lt{'atta'} $attachmaxtext: <input type="file" name="attachment" />
2006: </p>
2007: END
2008: }
2009: if (exists($env{'form.group'})) {
2010: $r->print('<input type="hidden" name="group" value="'.$env{'form.group'}.'" />');
2011: }
2012: if (exists($env{'form.ref'})) {
2013: $r->print('<input type="hidden" name="ref" value="'.$env{'form.ref'}.'" />');
2014: }
2015: $r->print(<<END);
2016: <p>
2017: <input type="hidden" name="sendit" value="1" />
2018: <input type="button" value="$send" onclick='gosubmit();' />
2019: </p>
2020: </form>
2021: END
2022: if ($env{'form.editdisc'} || $env{'form.replydisc'}) {
2023: my $now = time;
2024: my $ressymb = $symb;
2025: &Apache::lonenc::check_encrypt(\$ressymb);
2026: my $postidx = '';
2027: if ($env{'form.editdisc'}) {
2028: $postidx = $idx;
2029: }
2030: if (@currnewattach > 0) {
2031: $attachnum += @currnewattach;
2032: }
2033: my $blockblog = &Apache::loncommon::blocking_status('blogs');
2034: $r->print(&generate_attachments_button($postidx,$attachnum,$ressymb,$now,\@currnewattach,\@currdelold,$numoldver,'',$blockblog));
2035: if ($attachnum > 0) {
2036: if (@currnewattach > 0) {
2037: $newattachmsg .= '<br /><b>'.&mt('New attachments').'</b><br />';
2038: if (@currnewattach > 1) {
2039: $newattachmsg .= '<ol>';
2040: foreach my $item (@currnewattach) {
2041: $item =~ m#.*/([^/]+)$#;
2042: $newattachmsg .= '<li><a href="'.$item.'">'.$1.'</a></li>'."\n";
2043: }
2044: $newattachmsg .= '</ol>'."\n";
2045: } else {
2046: $currnewattach[0] =~ m#.*/([^/]+)$#;
2047: $newattachmsg .= '<a href="'.$currnewattach[0].'">'.$1.'</a><br />'."\n";
2048: }
2049: }
2050: if ($attachmsg) {
2051: $r->print("<br /><b>$lt{'reta'}</b>:$attachmsg<br />\n");
2052: }
2053: if ($newattachmsg) {
2054: $r->print("$newattachmsg<br />");
2055: }
2056: }
2057: }
2058: $r->print(&generate_preview_button().
2059: &Apache::loncommon::end_page());
2060:
2061: }
2062:
2063: sub print_display_options {
2064: my ($r,$symb,$previous,$dispchgA,$dispchgB,$markchg,$toggchg,$feedurl) = @_;
2065: &Apache::loncommon::content_type($r,'text/html');
2066: $r->send_http_header;
2067:
2068: my $function = &Apache::loncommon::get_users_function();
2069: my $tabcolor = &Apache::loncommon::designparm($function.'.tabbg',
2070: $env{'user.domain'});
2071:
2072: my %lt = &Apache::lonlocal::texthash(
2073: 'pref' => 'Display Preference',
2074: 'curr' => 'Current setting ',
2075: 'actn' => 'Action',
2076: 'deff' => 'Default for all discussions',
2077: 'prca' => 'Preferences can be set for this discussion that determine ....',
2078: 'whpo' => 'Which posts are displayed when you display this discussion board or resource, and',
2079: 'unwh' => 'Under what circumstances posts are identified as "NEW", and',
2080: 'wipa' => 'Whether individual posts can be marked as read/unread',
2081: 'allposts' => 'All posts',
2082: 'unread' => 'New posts only',
2083: 'unmark' => 'Posts not marked read',
2084: 'ondisp' => 'Once displayed',
2085: 'onmark' => 'Once marked not NEW',
2086: 'toggon' => 'Shown',
2087: 'toggoff' => 'Not shown',
2088: 'disa' => 'Posts displayed?',
2089: 'npmr' => 'New posts cease to be identified as "NEW"?',
2090: 'dotm' => 'Option to mark each post as read/unread?',
2091: 'chgt' => 'Change to ',
2092: 'mkdf' => 'Set to ',
2093: 'yhni' => 'You have not indicated that you wish to change any of the discussion settings',
2094: 'ywbr' => 'You will be returned to the previous page if you click OK.'
2095: );
2096:
2097: my $dispchangeA = $lt{'unread'};
2098: my $dispchangeB = $lt{'unmark'};
2099: my $markchange = $lt{'ondisp'};
2100: my $toggchange = $lt{'toggon'};
2101: my $currdisp = $lt{'allposts'};
2102: my $currmark = $lt{'onmark'};
2103: my $discdisp = 'allposts';
2104: my $discmark = 'onmark';
2105: my $currtogg = $lt{'toggoff'};
2106: my $disctogg = 'toggoff';
2107:
2108: if ($dispchgA eq 'allposts') {
2109: $dispchangeA = $lt{'allposts'};
2110: $currdisp = $lt{'unread'};
2111: $discdisp = 'unread';
2112: }
2113:
2114: if ($markchg eq 'markonread') {
2115: $markchange = $lt{'onmark'};
2116: $currmark = $lt{'ondisp'};
2117: $discmark = 'ondisp';
2118: }
2119:
2120: if ($dispchgB eq 'onlyunread') {
2121: $dispchangeB = $lt{'unread'};
2122: $currdisp = $lt{'unmark'};
2123: $discdisp = 'unmark';
2124: }
2125: if ($toggchg eq 'toggoff') {
2126: $toggchange = $lt{'toggoff'};
2127: $currtogg = $lt{'toggon'};
2128: $disctogg = 'toggon';
2129: }
2130:
2131: my $js = <<END;
2132: <script type="text/javascript">
2133: function discdispChk(caller) {
2134: var disctogg = '$toggchg'
2135: if (caller == 0) {
2136: if (document.modifydisp.discdisp[0].checked == true) {
2137: if (document.modifydisp.discdisp[1].checked == true) {
2138: document.modifydisp.discdisp[1].checked = false
2139: }
2140: }
2141: }
2142: if (caller == 1) {
2143: if (document.modifydisp.discdisp[1].checked == true) {
2144: if (document.modifydisp.discdisp[0].checked == true) {
2145: document.modifydisp.discdisp[0].checked = false
2146: }
2147: if (disctogg == 'toggon') {
2148: document.modifydisp.disctogg.checked = true
2149: }
2150: if (disctogg == 'toggoff') {
2151: document.modifydisp.disctogg.checked = false
2152: }
2153: }
2154: }
2155: if (caller == 2) {
2156: var dispchgB = '$dispchgB'
2157: if (disctogg == 'toggoff') {
2158: if (document.modifydisp.disctogg.checked == true) {
2159: if (dispchgB == 'onlyunmark') {
2160: document.modifydisp.discdisp[1].checked = false
2161: }
2162: }
2163: }
2164: }
2165: }
2166:
2167: function setDisp() {
2168: var prev = "$previous"
2169: var chktotal = 0
2170: if (document.modifydisp.discdisp[0].checked == true) {
2171: document.modifydisp.$dispchgA.value = "$symb"
2172: chktotal ++
2173: }
2174: if (document.modifydisp.discdisp[1].checked == true) {
2175: document.modifydisp.$dispchgB.value = "$symb"
2176: chktotal ++
2177: }
2178: if (document.modifydisp.discmark.checked == true) {
2179: document.modifydisp.$markchg.value = "$symb"
2180: chktotal ++
2181: }
2182: if (document.modifydisp.disctogg.checked == true) {
2183: document.modifydisp.$toggchg.value = "$symb"
2184: chktotal ++
2185: }
2186: if (chktotal > 0) {
2187: document.modifydisp.submit()
2188: } else {
2189: if(confirm("$lt{'yhni'}. \\n$lt{'ywbr'}")) {
2190: if (prev > 0) {
2191: location.href = "$feedurl?previous=$previous"
2192: } else {
2193: location.href = "$feedurl"
2194: }
2195: }
2196: }
2197: }
2198: </script>
2199: END
2200:
2201:
2202: my $start_page =
2203: &Apache::loncommon::start_page('Discussion display options',$js);
2204: my $end_page =
2205: &Apache::loncommon::end_page();
2206: $r->print(<<END);
2207: $start_page
2208: <form name="modifydisp" method="post" action="/adm/feedback">
2209: $lt{'sdpf'}<br/> $lt{'prca'} <ol><li>$lt{'whpo'}</li><li>$lt{'unwh'}</li><li>$lt{'wipa'}</li></ol>
2210: <br />
2211: END
2212: $r->print(&Apache::loncommon::start_data_table());
2213: $r->print(<<END);
2214: <tr>
2215: <th>$lt{'pref'}</td>
2216: <th>$lt{'curr'}</td>
2217: <th>$lt{'actn'}?</td>
2218: </tr>
2219: END
2220: $r->print(&Apache::loncommon::start_data_table_row());
2221: $r->print(<<END);
2222: <td>$lt{'disa'}</td>
2223: <td>$lt{$discdisp}</td>
2224: <td><label><input type="checkbox" name="discdisp" onclick="discdispChk('0')" /> $lt{'chgt'} "$dispchangeA"</label>
2225: <br />
2226: <label><input type="checkbox" name="discdisp" onclick="discdispChk('1')" /> $lt{'chgt'} "$dispchangeB"</label>
2227: </td>
2228: END
2229: $r->print(&Apache::loncommon::end_data_table_row());
2230: $r->print(&Apache::loncommon::start_data_table_row());
2231: $r->print(<<END);
2232: <td>$lt{'npmr'}</td>
2233: <td>$lt{$discmark}</td>
2234: <td><label><input type="checkbox" name="discmark" />$lt{'chgt'} "$markchange"</label></td>
2235: END
2236: $r->print(&Apache::loncommon::end_data_table_row());
2237: $r->print(&Apache::loncommon::start_data_table_row());
2238: $r->print(<<END);
2239: <td>$lt{'dotm'}</td>
2240: <td>$lt{$disctogg}</td>
2241: <td><label><input type="checkbox" name="disctogg" onclick="discdispChk('2')" />$lt{'chgt'} "$toggchange"</label></td>
2242: END
2243: my $save = &mt('Save');
2244: $r->print(&Apache::loncommon::end_data_table_row());
2245: $r->print(&Apache::loncommon::end_data_table());
2246: $r->print(<<END);
2247: <br />
2248: <br />
2249: <input type="hidden" name="symb" value="$symb" />
2250: <input type="hidden" name="previous" value="$previous" />
2251: <input type="hidden" name="$dispchgA" value="" />
2252: <input type="hidden" name="$dispchgB" value="" />
2253: <input type="hidden" name="$markchg" value="" />
2254: <input type="hidden" name="$toggchg" value="" />
2255: <input type="button" name="sub" value="$save" onclick="javascript:setDisp()" />
2256: END
2257: if (exists($env{'form.group'})) {
2258: $r->print('<input type="hidden" name="group" value="'.$env{'form.group'}.'" />');
2259: }
2260: if (exists($env{'form.ref'})) {
2261: $r->print('<input type="hidden" name="ref" value="'.$env{'form.ref'}.'" />');
2262: }
2263: $r->print("
2264: <br />
2265: <br />
2266: </form>
2267: $end_page
2268: ");
2269: return;
2270: }
2271:
2272: sub print_sortfilter_options {
2273: my ($r,$symb,$previous,$feedurl) = @_;
2274:
2275: &Apache::loncommon::content_type($r,'text/html');
2276: $r->send_http_header;
2277:
2278: &Apache::lonenc::check_encrypt(\$symb);
2279: my @sections;
2280: my $section_sel = '';
2281: my $numvisible = 5;
2282: my @groups;
2283: my $group_sel = '';
2284: my $numgroupvis = 5;
2285: my %sectioncount = &Apache::loncommon::get_sections();
2286: my @courseroles = qw(st ad ep ta in);
2287: my $crstype = &Apache::loncommon::course_type();
2288: my $ccrole = 'cc';
2289: if ($crstype eq 'Community') {
2290: $ccrole = 'co';
2291: }
2292: push(@courseroles,$ccrole);
2293:
2294: if ($env{'request.course.sec'} !~ /^\s*$/) { #Restrict section choice to current section
2295: @sections = ('all',$env{'request.course.sec'});
2296: $numvisible = 2;
2297: } else {
2298: @sections = sort {$a cmp $b} keys(%sectioncount);
2299: if (scalar(@sections) < 4) {
2300: $numvisible = scalar(@sections) + 1;
2301: }
2302: unshift(@sections,'all'); # Put 'all' at the front of the list
2303:
2304: }
2305: foreach my $sec (@sections) {
2306: $section_sel .= " <option value=\"$sec\">$sec</option>\n";
2307: }
2308:
2309: if (&check_group_priv() eq 'ok') {
2310: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
2311: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
2312: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
2313: @groups = sort {$a cmp $b} keys(%curr_groups);
2314: if (scalar(@groups) < 4) {
2315: $numgroupvis = scalar(@groups) + 1;
2316: }
2317: unshift(@groups,'all'); # Put 'all' at the front of the list
2318: } else {
2319: my @coursegroups = split(/:/,$env{'request.course.groups'});
2320: if (@coursegroups > 0) {
2321: @coursegroups = sort {$a cmp $b} @coursegroups;
2322: @groups = ('all',@coursegroups);
2323: if (scalar(@groups) < 4) {
2324: $numgroupvis = scalar(@groups) + 1;
2325: }
2326: } else {
2327: @groups = ('all');
2328: $numgroupvis = 1;
2329: }
2330: }
2331: foreach my $group (@groups) {
2332: $group_sel .= " <option value=\"$group\">$group</option>\n";
2333: }
2334:
2335: my $function = &Apache::loncommon::get_users_function();
2336: my $tabcolor = &Apache::loncommon::designparm($function.'.tabbg',
2337: $env{'user.domain'});
2338: my %lt = &Apache::lonlocal::texthash(
2339: 'diop' => 'Display Options',
2340: 'curr' => 'Current setting ',
2341: 'actn' => 'Action',
2342: 'prca' => 'Set options that control the sort order of posts, and/or which posts are displayed.',
2343: 'soor' => 'Sort order',
2344: 'spur' => 'Specific user roles',
2345: 'sprs' => 'Specific role status',
2346: 'spse' => 'Specific sections',
2347: 'spgr' => 'Specific groups',
2348: 'psub' => 'Pick specific users (by name)',
2349: 'shal' => 'Show a list of current posters',
2350: 'stor' => 'Save changes',
2351: );
2352:
2353: my %sort_types = ();
2354: my %role_types = ();
2355: my %status_types = ();
2356: &sort_filter_names(\%sort_types,\%role_types,\%status_types,$crstype);
2357:
2358: my $js = <<END;
2359: <script type="text/javascript">
2360: function verifyFilter() {
2361: var rolenum = 0
2362: for (var i=0; i<document.modifyshown.rolefilter.length; i++) {
2363: if (document.modifyshown.rolefilter.options[i].selected == true) {
2364: rolenum ++
2365: }
2366: }
2367: if (rolenum == 0) {
2368: document.modifyshown.rolefilter.options[0].selected = true
2369: }
2370:
2371: var secnum = 0
2372: for (var i=0; i<document.modifyshown.sectionpick.length; i++) {
2373: if (document.modifyshown.sectionpick.options[i].selected == true) {
2374: secnum ++
2375: }
2376: }
2377: if (secnum == 0) {
2378: document.modifyshown.sectionpick.options[0].selected = true
2379: }
2380:
2381: var grpnum = 0
2382: for (var i=0; i<document.modifyshown.grouppick.length; i++) {
2383: if (document.modifyshown.grouppick.options[i].selected == true) {
2384: grpnum ++
2385: }
2386: }
2387: if (grpnum == 0) {
2388: document.modifyshown.grouppick.options[0].selected = true
2389: }
2390:
2391: document.modifyshown.submit();
2392: }
2393: </script>
2394: END
2395:
2396: my $start_page=
2397: &Apache::loncommon::start_page('Discussion options',$js);
2398: my $end_page=
2399: &Apache::loncommon::end_page();
2400:
2401: $r->print(<<END);
2402: $start_page
2403: <form name="modifyshown" method="post" action="/adm/feedback">
2404: <b>$lt{'diso'}</b><br/> $lt{'prca'}
2405: <br />
2406: <table border="0">
2407: <tr>
2408: <th>$lt{'soor'}</th>
2409: <th> </th>
2410: <th>$lt{'sprs'}</th>
2411: <th> </th>
2412: <th>$lt{'spur'}</th>
2413: <th> </th>
2414: <th>$lt{'spse'}</th>
2415: <th> </th>
2416: <th>$lt{'spgr'}</th>
2417: <th> </th>
2418: <th>$lt{'psub'}</th>
2419: </tr>
2420: <tr>
2421: <td align="center" valign="top">
2422: <select name="sortposts">
2423: <option value="ascdate" selected="selected">$sort_types{'ascdate'}</option>
2424: <option value="descdate">$sort_types{'descdate'}</option>
2425: <option value="thread">$sort_types{'thread'}</option>
2426: <option value="subject">$sort_types{'subject'}</option>
2427: <option value="username">$sort_types{'username'}</option>
2428: <option value="lastfirst">$sort_types{'lastfirst'}</option>
2429: </select>
2430: </td>
2431: <td> </td>
2432: <td align="center" valign="top">
2433: <select name="statusfilter">
2434: <option value="all" selected="selected">$status_types{'all'}</option>
2435: <option value="Active">$status_types{'Active'}</option>
2436: <option value="Expired">$status_types{'Expired'}</option>
2437: <option value="Future">$status_types{'Future'}</option>
2438: </select>
2439: </td>
2440: <td> </td>
2441: <td align="center" valign="top">
2442: <select name="rolefilter" multiple="multiple" size="5">
2443: <option value="all">$role_types{'all'}</option>
2444: <option value="st">$role_types{'st'}</option>
2445: <option value="$ccrole">$role_types{$ccrole}</option>
2446: <option value="in">$role_types{'in'}</option>
2447: <option value="ta">$role_types{'ta'}</option>
2448: <option value="ep">$role_types{'ep'}</option>
2449: <option value="ad">$role_types{'ad'}</option>
2450: <option value="cr">$role_types{'cr'}</option>
2451: </select>
2452: </td>
2453: <td> </td>
2454: <td align="center" valign="top">
2455: <select name="sectionpick" multiple="multiple" size="$numvisible">
2456: $section_sel
2457: </select>
2458: </td>
2459: <td> </td>
2460: <td align="center" valign="top">
2461: <select name="grouppick" multiple="multiple" size="$numvisible">
2462: $group_sel
2463: </select>
2464: </td>
2465: <td> </td>
2466: <td valign="top"><label><input type="checkbox" name="posterlist" value="$symb" />$lt{'shal'}</label></td>
2467: </tr>
2468: </table>
2469: <br />
2470: <input type="hidden" name="inhibitmenu" value="$env{'form.inhibitmenu'}" />
2471: <input type="hidden" name="modal" value="$env{'form.modal'}" />
2472: <input type="hidden" name="previous" value="$previous" />
2473: <input type="hidden" name="applysort" value="$symb" />
2474: <input type="button" name="sub" value="$lt{'stor'}" onclick="verifyFilter()" />
2475: END
2476: if (exists($env{'form.group'})) {
2477: $r->print('<input type="hidden" name="group" value="'.$env{'form.group'}.'" />');
2478: }
2479: if (exists($env{'form.ref'})) {
2480: $r->print('<input type="hidden" name="ref" value="'.$env{'form.ref'}.'" />');
2481: }
2482: $r->print("
2483: <br />
2484: <br />
2485: </form>
2486: $end_page
2487: ");
2488: }
2489:
2490: sub print_showposters {
2491: my ($r,$symb,$previous,$feedurl,$sortposts) = @_;
2492:
2493: &Apache::loncommon::content_type($r,'text/html');
2494: $r->send_http_header;
2495:
2496: &Apache::lonenc::check_encrypt(\$symb);
2497: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
2498: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
2499: my $group = $env{'form.group'};
2500: my $ressymb = &wrap_symb($symb);
2501: my $seehidden = &can_see_hidden('',$ressymb,$feedurl,$group,$cdom,$cnum);
2502: my %contrib=&Apache::lonnet::restore($symb,$env{'request.course.id'},
2503: $cdom,$cnum);
2504: my %namesort = ();
2505: my %postcounts = ();
2506:
2507: my %lt = &Apache::lonlocal::texthash(
2508: sele => 'Select',
2509: full => 'Fullname',
2510: usdo => 'Username:domain',
2511: post => 'Posts',
2512: );
2513: if ($contrib{'version'}) {
2514: for (my $idx=1;$idx<=$contrib{'version'};$idx++) {
2515: my $hidden=($contrib{'hidden'}=~/\.$idx\./);
2516: my $deleted=($contrib{'deleted'}=~/\.$idx\./);
2517: unless ((($hidden) && (!$seehidden)) || ($deleted)) {
2518: if ((!$contrib{$idx.':anonymous'}) || (&Apache::lonnet::allowed('rin',$env{'request.course.id'}.($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:'')))) {
2519: my %names = &Apache::lonnet::get('environment',['firstname','lastname'],$contrib{$idx.':senderdomain'},$contrib{$idx.':sendername'});
2520: my $lastname = $names{'lastname'};
2521: my $firstname = $names{'firstname'};
2522: if ($lastname eq '') {
2523: $lastname = '_';
2524: }
2525: if ($firstname eq '') {
2526: $firstname = '_';
2527: }
2528: unless (defined($namesort{$lastname})) {
2529: %{$namesort{$lastname}} = ();
2530: }
2531: my $poster = $contrib{$idx.':sendername'}.':'.$contrib{$idx.':senderdomain'};
2532: $postcounts{$poster} ++;
2533: if (defined($namesort{$lastname}{$firstname})) {
2534: if (!grep/^$poster$/,@{$namesort{$lastname}{$firstname}}) {
2535: push(@{$namesort{$lastname}{$firstname}}, $poster);
2536: }
2537: } else {
2538: @{$namesort{$lastname}{$firstname}} = ("$poster");
2539: }
2540: }
2541: }
2542: }
2543: }
2544:
2545: my $start_page = &Apache::loncommon::start_page('Discussion options');
2546: my $table_start =&Apache::loncommon::start_data_table();
2547: $r->print(<<END);
2548: $start_page
2549: <form name="pickpostersform" method="post">
2550: <br />
2551: $table_start
2552: <tr>
2553: <th>#</th>
2554: <th>$lt{'sele'}</th>
2555: <th>$lt{'full'} <font color="#999999">($lt{'usdo'})</font></th>
2556: <th>$lt{'post'}</th>
2557: </tr>
2558: END
2559: my $count = 0;
2560: foreach my $last (sort(keys(%namesort))) {
2561: foreach my $first (sort(keys(%{$namesort{$last}}))) {
2562: foreach my $user (sort(@{$namesort{$last}{$first}})) {
2563: my ($uname,$udom) = split(/:/,$user);
2564: if (!$uname || !$udom) {
2565: next;
2566: } else {
2567: $count ++;
2568: $r->print(&Apache::loncommon::start_data_table_row().
2569: '<td align="right">'.$count.'</td>
2570: <td align="center"><label><input name="stuinfo" type="checkbox" value="'.$user.'" /></td>
2571: <td>'.$last.', '.$first.' ('.$uname.':'.$udom.')</label></td>
2572: <td>'.$postcounts{$user}.'</td>'.
2573: &Apache::loncommon::end_data_table_row());
2574: }
2575: }
2576: }
2577: }
2578: $r->print(&Apache::loncommon::end_data_table());
2579: my $end_page = &Apache::loncommon::end_page();
2580: $r->print(<<END);
2581: <br />
2582: <input type="hidden" name="sortposts" value="$sortposts" />
2583: <input type="hidden" name="modal" value="$env{'form.modal'}" />
2584: <input type="hidden" name="userpick" value="$symb" />
2585: <input type="button" name="store" value="Display posts" onclick="javascript:document.pickpostersform.submit()" />
2586: </form>
2587: $end_page
2588: END
2589: }
2590:
2591: sub get_post_versions {
2592: my ($versions,$incoming,$htmldecode,$numver) = @_;
2593: if ($incoming =~ /^<version num="0">/) {
2594: my $p = HTML::LCParser->new(\$incoming);
2595: my $done = 0;
2596:
2597: while ( (my $token = $p->get_tag("version")) && (!$done)) {
2598: my $num = $token->[1]{num};
2599: my $text = $p->get_text("/version");
2600: if (defined($numver)) {
2601: if ($num == $numver) {
2602: if ($htmldecode) {
2603: $text = &HTML::Entities::decode($text);
2604: }
2605: $$versions{$numver}=$text;
2606: $done = 1;
2607: }
2608: } else {
2609: if ($htmldecode) {
2610: $text = &HTML::Entities::decode($text);
2611: }
2612: $$versions{$num}=$text;
2613: }
2614: }
2615: } else {
2616: if (!defined($numver)) {
2617: $numver = 0;
2618: }
2619: if ($htmldecode) {
2620: $$versions{$numver} = $incoming;
2621: } else {
2622: $$versions{$numver} = &HTML::Entities::encode($incoming,'<>&"');
2623: }
2624: }
2625: return;
2626: }
2627:
2628: sub get_post_attachments {
2629: my ($attachments,$attachmenturls) = @_;
2630: my $num;
2631: if ($attachmenturls =~ m/^<attachment id="0">/) {
2632: my $p = HTML::LCParser->new(\$attachmenturls);
2633: while (my $token = $p->get_tag("attachment","filename","post")) {
2634: if ($token->[0] eq "attachment") {
2635: $num = $token->[1]{id};
2636: %{$$attachments{$num}} =();
2637: } elsif ($token->[0] eq "filename") {
2638: $$attachments{$num}{'filename'} = $p->get_text("/filename");
2639: } elsif ($token->[0] eq "post") {
2640: my $id = $token->[1]{id};
2641: $$attachments{$num}{$id} = $p->get_text("/post");
2642: }
2643: }
2644: } else {
2645: %{$$attachments{'0'}} = ();
2646: $$attachments{'0'}{'filename'} = $attachmenturls;
2647: $$attachments{'0'}{'0'} = 'n';
2648: }
2649:
2650: return;
2651: }
2652:
2653: sub fail_redirect {
2654: my ($r,$feedurl) = @_;
2655: if ($feedurl=~/^\/adm\//) { $feedurl.='?register=1' };
2656: my %lt = &Apache::lonlocal::texthash(
2657: 'sorr' => 'Sorry, no recipients ...',
2658: );
2659: my $logo=&Apache::loncommon::lonhttpdurl('/adm/lonIcons/lonlogos.gif');
2660: $r->print(&Apache::loncommon::start_page('Feedback not sent',undef,
2661: {'redirect' => [2,$feedurl],
2662: 'only_body' => 1,}));
2663: $r->print(<<ENDFAILREDIR);
2664: <img align="right" src="$logo" />
2665: <b>$lt{'sorr'}</b>
2666: ENDFAILREDIR
2667: $r->print(&Apache::loncommon::end_page());
2668: }
2669:
2670: sub redirect_back {
2671: my ($r,$feedurl,$typestyle,$sendsomething,$sendposts,$blog,$status,$previous,$sort,$rolefilter,$statusfilter,$sectionpick,$grouppick,$numpicks,$group,$toolarge) = @_;
2672: my $sorttag = '';
2673: my $roletag = '';
2674: my $statustag = '';
2675: my $sectag = '';
2676: my $grptag = '';
2677: my $userpicktag = '';
2678: my $qrystr = '';
2679: my $prevtag = '';
2680:
2681: &Apache::loncommon::content_type($r,'text/html');
2682: $r->send_http_header;
2683: &dewrapper(\$feedurl);
2684: if ($feedurl=~/^\/adm\//) { $feedurl.='?register=1' };
2685: if ($previous > 0) {
2686: $qrystr = 'previous='.$previous;
2687: if ($feedurl =~ /\?register=1/) {
2688: $feedurl .= '&'.$qrystr;
2689: } else {
2690: $feedurl .= '?'.$qrystr;
2691: }
2692: $prevtag = '<input type="hidden" name="previous" value="'.$previous.'" />';
2693: }
2694: if (defined($sort)) {
2695: my $sortqry = 'sortposts='.$sort;
2696: if (($feedurl =~ /\?register=1/) || ($feedurl =~ /\?previous=/)) {
2697: $feedurl .= '&'.$sortqry;
2698: } else {
2699: $feedurl .= '?'.$sortqry;
2700: }
2701: $sorttag = '<input type="hidden" name="sortposts" value="'.$sort.'" />';
2702: if (defined($numpicks)) {
2703: my $userpickqry = 'totposters='.$numpicks;
2704: $feedurl .= '&'.$userpickqry;
2705: $userpicktag = '<input type="hidden" name="totposters" value="'.$numpicks.'" />';
2706: } else {
2707: if (ref($sectionpick) eq 'ARRAY') {
2708: $feedurl .= '&sectionpick=';
2709: $sectag .= '<input type="hidden" name="sectionpick" value="';
2710: foreach my $sec (@{$sectionpick}) {
2711: $feedurl .= $sec.',';
2712: $sectag .= $sec.',';
2713: }
2714: $feedurl =~ s/,$//;
2715: $sectag =~ s/,$//;
2716: $sectag .= '" />';
2717: } else {
2718: $feedurl .= '&sectionpick='.$sectionpick;
2719: $sectag = '<input type="hidden" name="sectionpick" value="'.$sectionpick.'" />';
2720: }
2721: if (ref($grouppick) eq 'ARRAY') {
2722: $feedurl .= '&grouppick=';
2723: $sectag .= '<input type="hidden" name="grouppick" value="';
2724: foreach my $grp (@{$grouppick}) {
2725: $feedurl .= $grp.',';
2726: $grptag .= $grp.',';
2727: }
2728: $feedurl =~ s/,$//;
2729: $grptag =~ s/,$//;
2730: $grptag .= '" />';
2731: } else {
2732: $feedurl .= '&grouppick='.$grouppick;
2733: $grptag = '<input type="hidden" name="grouppick" value="'.$grouppick.'" />';
2734: }
2735: if (ref($rolefilter) eq 'ARRAY') {
2736: $feedurl .= '&rolefilter=';
2737: $roletag .= '<input type="hidden" name="rolefilter" value="';
2738: foreach my $role (@{$rolefilter}) {
2739: $feedurl .= $role.',';
2740: $roletag .= $role.',';
2741: }
2742: $feedurl =~ s/,$//;
2743: $roletag =~ s/,$//;
2744: $roletag .= '" />';
2745: } else {
2746: $feedurl .= '&rolefilter='.$rolefilter;
2747: $roletag = '<input type="hidden" name="rolefilter" value="'.$rolefilter.'" />';
2748: }
2749: $feedurl .= '&statusfilter='.$statusfilter;
2750: $statustag ='<input type="hidden" name="statusfilter" value="'.$statusfilter.'" />';
2751: }
2752: }
2753: my $grouptag;
2754: if ($group ne '') {
2755: $grouptag = '<input type="hidden" name="group" value="'.$group.'" />';
2756: my $refarg;
2757: if (exists($env{'form.ref'})) {
2758: $refarg = '&ref='.$env{'form.ref'};
2759: $grouptag .= '<input type="hidden" name="ref" value="'.$env{'form.ref'}.'" />';
2760: }
2761: if ($feedurl =~ /\?/) {
2762: $feedurl .= '&group='.$group.$refarg;
2763: } else {
2764: $feedurl .= '?group='.$group.$refarg;
2765: }
2766: }
2767: &Apache::lonenc::check_encrypt(\$feedurl);
2768: my $logo=&Apache::loncommon::lonhttpdurl('/adm/lonIcons/lonlogos.gif');
2769: my %parms=('only_body' => 1);
2770: if ($env{'form.modal'}) {
2771: $parms{'add_entries'}={'onLoad' => 'document.forms.reldt.submit()'};
2772: } else {
2773: $parms{'redirect'}=[0,$feedurl];
2774: }
2775: my $start_page=
2776: &Apache::loncommon::start_page('Feedback sent',undef,\%parms);
2777: my $end_page = &Apache::loncommon::end_page();
2778: $r->print(<<ENDREDIR);
2779: $start_page
2780: <img align="right" src="$logo" />
2781: $typestyle
2782: <b>Sent $sendsomething message(s), and $sendposts post(s).</b>
2783: $blog
2784: $toolarge
2785: <font color="red">$status</font>
2786: <form name="reldt" action="$feedurl" target="loncapaclient">
2787: $prevtag
2788: $sorttag
2789: $statustag
2790: $roletag
2791: $sectag
2792: $grptag
2793: $userpicktag
2794: $grouptag
2795: </form>
2796: $end_page
2797: ENDREDIR
2798: }
2799:
2800: sub no_redirect_back {
2801: my ($r,$feedurl) = @_;
2802: my $nofeed=&mt('Sorry, no feedback possible on this resource ...');
2803:
2804: my %onload;
2805:
2806: my %body_options = ('only_body' => 1,
2807: 'bgcolor' => '#FFFFFF',
2808: 'add_entries' => \%onload,);
2809:
2810: if ($feedurl !~ m{^/adm/feedback}) {
2811: $body_options{'redirect'} = [2,$feedurl];
2812: }
2813: my $start_page=
2814: &Apache::loncommon::start_page('Feedback not sent',undef,
2815: \%body_options);
2816:
2817: my $end_page = &Apache::loncommon::end_page();
2818:
2819: &Apache::lonenc::check_encrypt(\$feedurl);
2820: my $logo=&Apache::loncommon::lonhttpdurl('/adm/lonIcons/lonlogos.gif');
2821: $r->print (<<ENDNOREDIRTWO);
2822: $start_page
2823: <img align="right" src="$logo" />
2824: <b>$nofeed</b>
2825: <br />
2826: $end_page
2827: ENDNOREDIRTWO
2828: }
2829:
2830: sub screen_header {
2831: my ($feedurl,$symb,$group) = @_;
2832: my $crscontent = &mt('Question/Comment/Feedback about course content');
2833: my $crspolicy = &mt('Question/Comment/Feedback about course policy');
2834: my $contribdisc = &mt('Contribution to course discussion of resource');
2835: my $anoncontrib = &mt('Anonymous contribution to course discussion of resource');
2836: my $namevis = &mt('name only visible to course faculty');
2837: my $crstype;
2838: if ($env{'request.course.id'}) {
2839: $crstype = &Apache::loncommon::course_type();
2840: if ($crstype eq 'Community') {
2841: $crscontent = &mt('Question/Comment/Feedback about community content');
2842: $crspolicy = &mt('Question/Comment/Feedback about community policy');
2843: $contribdisc = &mt('Contribution to community discussion of resource');
2844: $anoncontrib = &mt('Anonymous contribution to community discussion of resource');
2845: $namevis = &mt('name only visible to community facilitators');
2846: }
2847: }
2848: my $msgoptions='';
2849: my $discussoptions='';
2850: unless (($env{'form.replydisc'}) || ($env{'form.editdisc'})) {
2851: if (($feedurl=~/^\/res\//) && ($feedurl!~/^\/res\/adm/) && ($env{'user.adv'})) {
2852: $msgoptions=
2853: '<label><input type="radio" name="discuss" value="author" /> '.
2854: &mt('Feedback to resource author').'</label><br />';
2855: }
2856: my %optionhash=();
2857: foreach my $type ('question','comment','policy') {
2858: $optionhash{$type}=$env{'course.'.$env{'request.course.id'}.'.'.$type.'.email.text'};
2859: }
2860: if (&feedback_available(1)) {
2861: $msgoptions.=
2862: '<label><input type="radio" name="discuss" value="question" /> '.
2863: ($optionhash{'question'}?$optionhash{'question'}:&mt('Question about resource content')).'</label><br />';
2864: }
2865: if (&feedback_available(0,1)) {
2866: $msgoptions.=
2867: '<label><input type="radio" name="discuss" value="course" /> '.
2868: ($optionhash{'comment'}?$optionhash{'comment'}:$crscontent).
2869: '</label><br />';
2870: }
2871: if (&feedback_available(0,0,1)) {
2872: $msgoptions.=
2873: '<label><input type="radio" name="discuss" value="policy" /> '.
2874: ($optionhash{'policy'}?$optionhash{'policy'}:$crspolicy).
2875: '</label><br />';
2876: }
2877: }
2878: if (($env{'request.course.id'}) && (!$env{'form.sendmessageonly'})) {
2879: my ($blocked,$blocktext) = &Apache::loncommon::blocking_status('boards');
2880: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
2881: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
2882: my $realsymb = &get_realsymb($symb);
2883: if (!$blocked && &discussion_open(undef,$realsymb) &&
2884: (&Apache::lonnet::allowed('pch',
2885: $env{'request.course.id'}.
2886: ($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:'')) ||
2887: (($group ne '') && ($symb =~ m{^bulletin___\d+___adm/wrapper/adm/\Q$cdom\E/\Q$cnum\E/\d+/bulletinboard$}) && (&check_group_priv($group,'pgd') eq 'ok')))) {
2888: $discussoptions='<label><input type="radio" name="discuss" value="nonanon" checked="checked" /> '.
2889: $contribdisc.
2890: '</label><br /><label><input type="radio" name="discuss" value="anon" /> '.
2891: $anoncontrib.
2892: ' <i>('.$namevis.')</i></label> '.
2893: '<a href="/adm/preferences?action=changescreenname">'.&mt('Change Screenname').'</a>';
2894: my $blockblog = &Apache::loncommon::blocking_status('blogs');
2895: if (!$blockblog) {
2896: $discussoptions.= &add_blog_checkbox($crstype);
2897: }
2898: }
2899: }
2900: if ($msgoptions) {
2901: $msgoptions='<tr><th><img src="'.&Apache::loncommon::lonhttpdurl('/res/adm/pages/feedback.png').'" />'
2902: .'<br />'.&mt('Send Feedback').'<br />'.&Apache::lonhtmlcommon::coursepreflink(&mt('Feedback Settings'),'feedback').'</th>'.
2903: '<td>'.$msgoptions.'</td></tr>';
2904: }
2905: if ($discussoptions) {
2906: $discussoptions='<tr><th><img src="'.&Apache::loncommon::lonhttpdurl('/adm/lonMisc/chat.gif').'" alt="" />'
2907: .'<br />'.&mt('Discussion Contributions').'<br />'.&Apache::lonhtmlcommon::coursepreflink(&mt('Discussion Settings'),'discussion').'</th>'.
2908: '<td>'.$discussoptions.'</td></tr>';
2909: }
2910: return &Apache::loncommon::start_data_table().$msgoptions.$discussoptions.&Apache::loncommon::end_data_table();
2911: }
2912:
2913: sub resource_output {
2914: my ($feedurl) = @_;
2915: my $usersaw=&Apache::lonnet::ssi_body($feedurl);
2916: $usersaw=~s/\<body[^\>]*\>//gi;
2917: $usersaw=~s/\<\/body\>//gi;
2918: $usersaw=~s/\<html\>//gi;
2919: $usersaw=~s/\<\/html\>//gi;
2920: $usersaw=~s/\<head\>//gi;
2921: $usersaw=~s/\<\/head\>//gi;
2922: $usersaw=~s/action\s*\=/would_be_action\=/gi;
2923: return $usersaw;
2924: }
2925:
2926: sub clear_out_html {
2927: my ($message,$override)=@_;
2928: # Always allow the <m>-tag
2929: my %html=(M=>1);
2930: # Check if more is allowed
2931: my $cid=$env{'request.course.id'};
2932: if (($env{"course.$cid.allow_limited_html_in_feedback"} =~ m/yes/i) ||
2933: ($override)) {
2934: # allows <B> <I> <P> <A> <LI> <OL> <UL> <EM> <BR> <TT> <STRONG>
2935: # <BLOCKQUOTE> <DIV .*> <DIV> <IMG> <M> <SPAN> <H1> <H2> <H3> <H4> <SUB>
2936: # <SUP> <TABLE> <TR> <TD> <TH> <TBODY>
2937: %html=(B=>1, I=>1, P=>1, A=>1, LI=>1, OL=>1, UL=>1, EM=>1,
2938: BR=>1, TT=>1, STRONG=>1, BLOCKQUOTE=>1, PRE=>1, DIV=>1, IMG=>1,
2939: M=>1, CHEM=>1, ALGEBRA=>1, SUB=>1, SUP=>1, SPAN=>1,
2940: H1=>1, H2=>1, H3=>1, H4=>1, H5=>1, H6=>1,
2941: TABLE=>1, TR=>1, TD=>1, TH=>1, TBODY=>1);
2942: }
2943: # Do the substitution of everything that is not explicitly allowed
2944: $message =~ s/\<(\/?\s*(\w+)[^\>\<]*)/
2945: {($html{uc($2)}&&(length($1)<1000))?"\<$1":"\<$1"}/ge;
2946: $message =~ s/(\<?\s*(\w+)[^\<\>]*)\>/
2947: {($html{uc($2)}&&(length($1)<1000))?"$1\>":"$1\>"}/ge;
2948: return $message;
2949: }
2950:
2951: sub assemble_email {
2952: my ($message,$prevattempts,$usersaw,$useranswer)=@_;
2953: my %lt = &Apache::lonlocal::texthash(
2954: 'prev' => 'Previous attempts of student (if applicable)',
2955: 'orig' => 'Original screen output (if applicable)',
2956: 'corr' => 'Correct Answer(s) (if applicable)',
2957: );
2958: if (&Apache::loncommon::course_type() eq 'Community') {
2959: $lt{'prev'} = &mt('Previous attempts of member (if applicable)');
2960: }
2961: my $email=<<"ENDEMAIL";
2962: $message
2963: ENDEMAIL
2964: my $citations=<<"ENDCITE";
2965: <h2>$lt{'prev'}</h2>
2966: $prevattempts
2967: <br /><hr />
2968: <h2>$lt{'orig'}</h2>
2969: $usersaw
2970: <h2>$lt{'corr'}</h2>
2971: $useranswer
2972: ENDCITE
2973: return ($email,$citations);
2974: }
2975:
2976:
2977: sub feedback_available {
2978: my ($question,$course,$policy)=@_;
2979: my ($typestyle,%to)=&Apache::lonmsg::decide_receiver('',0,$question,
2980: $course,$policy);
2981: return scalar(%to);
2982: }
2983:
2984: sub send_msg {
2985: my ($title,$feedurl,$email,$citations,$attachmenturl,$symb,%to)=@_;
2986: my $status='';
2987: my $sendsomething=0;
2988: my $restitle = &get_resource_title($symb,$feedurl);
2989: if ($title=~/^Error/) { $title=&mt('Feedback').': '.$title; }
2990: unless ($title=~/\w/) { $title=&mt('Feedback'); }
2991: foreach my $key (keys(%to)) {
2992: if ($key) {
2993: my ($user,$domain) = split(/\:/,$key,2);
2994: if (!defined($user)) {
2995: $status.='<br />'.&mt('Error sending message to [_1], no user specified.',$key);
2996: } elsif (!defined($domain)) {
2997: $status.='<br />'.&mt('Error sending message to [_1], no domain specified.',$key);
2998: } else {
2999: unless (&Apache::lonmsg::user_normal_msg($user,$domain,
3000: $title.' ['.$restitle.']',$email,$citations,$feedurl,
3001: $attachmenturl,undef,undef,$symb,$restitle)=~/ok/) {
3002: $status.='<br />'.&mt('Error sending message to').' '.$key.'<br />';
3003: } else {
3004: $sendsomething++;
3005: }
3006: }
3007: }
3008: }
3009:
3010: # Records of number of feedback messages are kept under the "symb" called "_feedback"
3011: # There are two entries within the framework of a course:
3012: # - the URLs for which feedback was provided
3013: # - the total number of contributions
3014: if ($sendsomething) {
3015: my %record=&getfeedbackrecords();
3016: my ($temp)=keys(%record);
3017: unless ($temp=~/^error\:/) {
3018: my %newrecord=();
3019: $newrecord{'resource'}=$feedurl;
3020: $newrecord{'subnumber'}=$record{'subnumber'}+1;
3021: unless (&Apache::lonnet::cstore(\%newrecord,'_feedback') eq 'ok') {
3022: $status.='<br />'.&mt('Not registered').'<br />';
3023: }
3024: }
3025: }
3026: return ($status,$sendsomething);
3027: }
3028:
3029: # Routine to get the complete feedback records
3030:
3031: sub getfeedbackrecords {
3032: my ($uname,$udom,$course)=@_;
3033: unless ($uname) { $uname=$env{'user.name'}; }
3034: unless ($udom) { $udom=$env{'user.domain'}; }
3035: unless ($course) { $course=$env{'request.course.id'}; }
3036: my %record=&Apache::lonnet::restore('_feedback',$course,$udom,$uname);
3037: return %record;
3038: }
3039:
3040: # Routine to get feedback statistics
3041:
3042: sub getfeedbackstats {
3043: my %record=&getfeedbackrecords(@_);
3044: return ($record{'subnumber'},$record{'points'},$record{'totallikes'});
3045: }
3046:
3047: # Store feedback credit
3048:
3049: sub storefeedbackpoints {
3050: my ($points,$uname,$udom,$course)=@_;
3051: unless ($points) { $points=0; }
3052: unless ($uname) { $uname=$env{'user.name'}; }
3053: unless ($udom) { $udom=$env{'user.domain'}; }
3054: unless ($course) { $course=$env{'request.course.id'}; }
3055: my %record=('grader_user' => $env{'user.name'},
3056: 'grader_domain' => $env{'user.domain'},
3057: 'points' => $points);
3058: return &Apache::lonnet::cstore(\%record,'_feedback',$course,$udom,$uname);
3059: }
3060:
3061: # Store feedback "likes"
3062:
3063: sub storefeedbacklikes {
3064: my ($likes,$uname,$udom,$course)=@_;
3065: unless ($likes) { $likes=0; }
3066: if ($likes>0) { $likes=1; }
3067: if ($likes<0) { $likes=-1; }
3068: unless ($uname) { $uname=$env{'user.name'}; }
3069: unless ($udom) { $udom=$env{'user.domain'}; }
3070: unless ($course) { $course=$env{'request.course.id'}; }
3071: my %record=&getfeedbackrecords($uname,$udom,$course);
3072: my $totallikes=$record{'totallikes'};
3073: $totallikes+=$likes;
3074: my %newrecord=('likes_user' => $env{'user.name'},
3075: 'likes_domain' => $env{'user.domain'},
3076: 'likes' => $likes,
3077: 'totallikes' => $totallikes);
3078: return &Apache::lonnet::cstore(\%newrecord,'_feedback',$course,$udom,$uname);
3079: }
3080:
3081:
3082: sub adddiscuss {
3083: my ($symb,$email,$anon,$attachmenturl,$subject,$group)=@_;
3084: my $status='';
3085: my $realsymb = &get_realsymb($symb);
3086: my ($cnum,$cdom);
3087: if ($env{'request.course.id'}) {
3088: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
3089: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
3090: }
3091: if (&discussion_open(undef,$realsymb) &&
3092: (&Apache::lonnet::allowed('pch',$env{'request.course.id'}.
3093: ($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:'')) ||
3094: (($group ne '') && (&check_group_priv($group,'pgd') eq 'ok') &&
3095: ($symb =~ m{^bulletin___\d+___adm/wrapper/adm/\Q$cdom\E/\Q$cnum\E/\d+/bulletinboard$})))) {
3096:
3097: my %contrib=('message' => $email,
3098: 'sendername' => $env{'user.name'},
3099: 'senderdomain' => $env{'user.domain'},
3100: 'screenname' => $env{'environment.screenname'},
3101: 'plainname' => $env{'environment.firstname'}.' '.
3102: $env{'environment.middlename'}.' '.
3103: $env{'environment.lastname'}.' '.
3104: $env{'enrironment.generation'},
3105: 'attachmenturl'=> $attachmenturl,
3106: 'subject' => $subject);
3107: if ($env{'form.replydisc'}) {
3108: $contrib{'replyto'}=(split(/\:\:\:/,$env{'form.replydisc'}))[1];
3109: }
3110: if ($anon) {
3111: $contrib{'anonymous'}='true';
3112: }
3113: if (($symb) && ($email)) {
3114: my $now = time;
3115: if ($env{'form.editdisc'}) {
3116: $contrib{'ip'}=$ENV{'REMOTE_ADDR'};
3117: $contrib{'host'}=$Apache::lonnet::perlvar{'lonHostID'};
3118: $contrib{'timestamp'} = $now;
3119: $contrib{'history'} = '';
3120: my $numoldver = 0;
3121: my ($oldsymb,$oldidx)=split(/\:\:\:/,$env{'form.editdisc'});
3122: &Apache::lonenc::check_decrypt(\$oldsymb);
3123: $oldsymb=~s|(bulletin___\d+___)adm/wrapper/|$1|;
3124: # get timestamp for last post and history
3125: my %oldcontrib=&Apache::lonnet::restore($oldsymb,$env{'request.course.id'},
3126: $env{'course.'.$env{'request.course.id'}.'.domain'},
3127: $env{'course.'.$env{'request.course.id'}.'.num'});
3128: if (defined($oldcontrib{$oldidx.':replyto'})) {
3129: $contrib{'replyto'} = $oldcontrib{$oldidx.':replyto'};
3130: }
3131: if (defined($oldcontrib{$oldidx.':history'})) {
3132: if ($oldcontrib{$oldidx.':history'} =~ /:/) {
3133: my @oldversions = split(/:/,$oldcontrib{$oldidx.':history'});
3134: $numoldver = @oldversions;
3135: } else {
3136: $numoldver = 1;
3137: }
3138: $contrib{'history'} = $oldcontrib{$oldidx.':history'}.':';
3139: }
3140: my $numnewver = $numoldver + 1;
3141: if (defined($oldcontrib{$oldidx.':subject'})) {
3142: if ($oldcontrib{$oldidx.':subject'} =~ /^<version num="0">/) {
3143: $contrib{'subject'} = '<version num="'.$numnewver.'">'.&HTML::Entities::encode($contrib{'subject'},'<>&"').'</version>';
3144: $contrib{'subject'} = $oldcontrib{$oldidx.':subject'}.$contrib{'subject'};
3145: } else {
3146: $contrib{'subject'} = '<version num="0">'.&HTML::Entities::encode($oldcontrib{$oldidx.':subject'},'<>&"').'</version><version num="1">'.&HTML::Entities::encode($contrib{'subject'},'<>&"').'</version>';
3147: }
3148: }
3149: if (defined($oldcontrib{$oldidx.':message'})) {
3150: if ($oldcontrib{$oldidx.':message'} =~ /^<version num="0">/) {
3151: $contrib{'message'} = '<version num="'.$numnewver.'">'.&HTML::Entities::encode($contrib{'message'},'<>&"').'</version>';
3152: $contrib{'message'} = $oldcontrib{$oldidx.':message'}.$contrib{'message'};
3153: } else {
3154: $contrib{'message'} = '<version num="0">'.&HTML::Entities::encode($oldcontrib{$oldidx.':message'},'<>&"').'</version><version num="1">'.&HTML::Entities::encode($contrib{'message'},'<>&"').'</version>';
3155: }
3156: }
3157: $contrib{'history'} .= $oldcontrib{$oldidx.':timestamp'};
3158: my $put_reply = &Apache::lonnet::putstore($env{'request.course.id'},
3159: $oldsymb,$oldidx,\%contrib,
3160: $env{'course.'.$env{'request.course.id'}.'.domain'},
3161: $env{'course.'.$env{'request.course.id'}.'.num'});
3162: $status='Editing class discussion'.($anon?' (anonymous)':'');
3163: } else {
3164: $status='Adding to class discussion'.($anon?' (anonymous)':'').': '.
3165: &Apache::lonnet::store(\%contrib,$symb,$env{'request.course.id'},
3166: $env{'course.'.$env{'request.course.id'}.'.domain'},
3167: $env{'course.'.$env{'request.course.id'}.'.num'});
3168: }
3169: my %storenewentry=($symb => $now);
3170: $status.='<br />'.&mt('Updating discussion time').': '.
3171: &Apache::lonnet::put('discussiontimes',\%storenewentry,
3172: $env{'course.'.$env{'request.course.id'}.'.domain'},
3173: $env{'course.'.$env{'request.course.id'}.'.num'});
3174: }
3175: my %record=&getdiscussionrecords();
3176: my ($temp)=keys(%record);
3177: unless ($temp=~/^error\:/) {
3178: my %newrecord=();
3179: $newrecord{'resource'}=$symb;
3180: $newrecord{'subnumber'}=$record{'subnumber'}+1;
3181: $status.='<br />'.&mt('Registering').': '.
3182: &Apache::lonnet::cstore(\%newrecord,'_discussion');
3183: &updatekarma();
3184: }
3185: } else {
3186: $status.='Failed.';
3187: }
3188: return $status.'<br />';
3189: }
3190:
3191:
3192: # Routine to get the complete discussion records
3193:
3194: sub getdiscussionrecords {
3195: my ($uname,$udom,$course)=@_;
3196: unless ($uname) { $uname=$env{'user.name'}; }
3197: unless ($udom) { $udom=$env{'user.domain'}; }
3198: unless ($course) { $course=$env{'request.course.id'}; }
3199: my %record=&Apache::lonnet::restore('_discussion',$course,$udom,$uname);
3200: return %record;
3201: }
3202:
3203: # Routine to get discussion statistics
3204:
3205: sub getdiscussionstats {
3206: my %record=&getdiscussionrecords(@_);
3207: my $totalvotes = $record{'totallikes'} + $record{'totalunlikes'};
3208: return ($record{'subnumber'},$record{'points'},$record{'totallikes'},$totalvotes);
3209: }
3210:
3211: # Calculate discussion karma
3212:
3213: sub calcdiscussionkarma {
3214: my ($subs,$pts,$likes,$votes)=&getdiscussionstats(@_);
3215: my $karma=0;
3216: if ($votes>0) {
3217: $karma=int(.1+5.*(1.-exp(-$subs/10.))*$likes/$votes);
3218: if ($karma<0) { $karma=0; }
3219: if ($karma>5) { $karma=5; }
3220: }
3221: return $karma;
3222: }
3223:
3224: # Update karma
3225:
3226: sub updatekarma {
3227: my ($uname,$udom,$course)=@_;
3228: unless ($uname) { $uname=$env{'user.name'}; }
3229: unless ($udom) { $udom=$env{'user.domain'}; }
3230: unless ($course) { $course=$env{'request.course.id'}; }
3231: my $karma=&calcdiscussionkarma($uname,$udom,$course);
3232: &Apache::lonnet::cstore({ 'karma' => $karma },'_discussion',$course,$udom,$uname);
3233: &Apache::lonnet::do_cache_new('karma',$uname.':'.$udom.':'.$course,$karma,3600);
3234: return $karma;
3235: }
3236:
3237: # Retrieve karma
3238:
3239: sub userkarma {
3240: my ($uname,$udom,$course)=@_;
3241: unless ($uname) { $uname=$env{'user.name'}; }
3242: unless ($udom) { $udom=$env{'user.domain'}; }
3243: unless ($course) { $course=$env{'request.course.id'}; }
3244: my $hashkey=$uname.':'.$udom.':'.$course;
3245: my ($karma,$cached)=&Apache::lonnet::is_cached_new('karma',$hashkey);
3246: if ($cached) {
3247: return $karma;
3248: }
3249: my %userdisc=&getdiscussionrecords($uname,$udom,$course);
3250: $karma=$userdisc{'karma'};
3251: &Apache::lonnet::do_cache_new('karma',$hashkey,$karma,3600);
3252: return $karma;
3253: }
3254:
3255: # Store discussion credit
3256:
3257: sub storediscussionpoints {
3258: my ($points,$uname,$udom,$course)=@_;
3259: unless ($points) { $points=0; }
3260: unless ($uname) { $uname=$env{'user.name'}; }
3261: unless ($udom) { $udom=$env{'user.domain'}; }
3262: unless ($course) { $course=$env{'request.course.id'}; }
3263: my %record=('grader_user' => $env{'user.name'},
3264: 'grader_domain' => $env{'user.domain'},
3265: 'points' => $points);
3266: return &Apache::lonnet::cstore(\%record,'_discussion',$course,$udom,$uname);
3267: }
3268:
3269: # Store discussion "likes"
3270:
3271: sub storediscussionlikes {
3272: my ($chglikes,$chgunlikes,$uname,$udom,$course,$context)=@_;
3273: unless ($uname) { $uname=$env{'user.name'}; }
3274: unless ($udom) { $udom=$env{'user.domain'}; }
3275: unless ($course) { $course=$env{'request.course.id'}; }
3276: my %record=&getdiscussionrecords($uname,$udom,$course);
3277: my $totallikes=$record{'totallikes'};
3278: my $totalunlikes=$record{'totalunlikes'};
3279: $totallikes += $chglikes;
3280: $totalunlikes += $chgunlikes;
3281: my %newrecord=('likes_user' => $env{'user.name'},
3282: 'likes_domain' => $env{'user.domain'},
3283: 'totallikes' => $totallikes,
3284: 'totalunlikes' => $totalunlikes,
3285: 'context' => $context);
3286: my $status=&Apache::lonnet::cstore(\%newrecord,'_discussion',$course,$udom,$uname);
3287: if ($status eq 'ok') {
3288: &updatekarma($uname,$udom,$course);
3289: }
3290: return $status;
3291: }
3292:
3293: sub get_discussion_info {
3294: my ($idx,%contrib) = @_;
3295: my $changelast = 0;
3296: my $count = 0;
3297: my $hiddenflag = 0;
3298: my $deletedflag = 0;
3299: my ($hidden,$deleted,%info,$newlastdisc);
3300: my $version = $contrib{'version'};
3301: if ($version) {
3302: for (my $id=$version; $id>0; $id--) {
3303: my $vkeys=$contrib{$id.':keys'};
3304: my @keys=split(/:/,$vkeys);
3305: if (grep(/^hidden$/,@keys)) {
3306: if (!$hiddenflag) {
3307: $hidden = $contrib{$id.':hidden'};
3308: $hiddenflag = 1;
3309: }
3310: } elsif (grep(/^deleted$/,@keys)) {
3311: if (!$deletedflag) {
3312: $deleted = $contrib{$id.':deleted'};
3313: $deletedflag = 1;
3314: }
3315: } else {
3316: if (($hidden !~/\.$id\./) && ($deleted !~/\.$id\./)) {
3317: $count++;
3318: $info{$count}{'id'} = $id;
3319: $info{$count}{'timestamp'}=$contrib{$id.':timestamp'};
3320: }
3321: }
3322: }
3323: if ($info{'1'}{'id'} == $idx) {
3324: $changelast = 1;
3325: if ($count > 1) {
3326: $newlastdisc = $info{'2'}{'timestamp'};
3327: } else {
3328: $newlastdisc = 0;
3329: }
3330: }
3331: }
3332: return ($changelast,$newlastdisc);
3333: }
3334:
3335: # ----------------------------------------------------------- Preview function
3336:
3337: sub show_preview {
3338: my ($r) = @_;
3339: &Apache::loncommon::content_type($r,'text/html');
3340: $r->send_http_header;
3341: my $start_page=
3342: &Apache::loncommon::start_page('Preview',undef,
3343: {'only_body' => 1,});
3344:
3345: my $message=&clear_out_html($env{'form.comment'});
3346: &newline_to_br(\$message);
3347: $message=&Apache::lonspeller::markeduptext($message);
3348: $message=&Apache::lontexconvert::msgtexconverted($message);
3349: my $subject=&clear_out_html($env{'form.subject'});
3350: $subject=~s/\n/\<br \/\>/g;
3351: $subject=&Apache::lontexconvert::msgtexconverted($subject);
3352:
3353: my $end_page = &Apache::loncommon::end_page();
3354:
3355: $r->print($start_page
3356: .'<h1>'.&mt('Preview').'</h1>'
3357: .&Apache::lonhtmlcommon::start_pick_box()
3358: .&Apache::lonhtmlcommon::row_title(&mt('Subject'))
3359: .$subject
3360: .&Apache::lonhtmlcommon::row_closure()
3361: .&Apache::lonhtmlcommon::row_title(&mt('Message'))
3362: .$message
3363: .&Apache::lonhtmlcommon::row_closure(1)
3364: .&Apache::lonhtmlcommon::end_pick_box()
3365: .$end_page
3366: );
3367: }
3368:
3369: sub contains_block_html {
3370: my ($message)=@_;
3371: return ($message =~ m{
3372: <(br|h1|h2|h3|h4|h5|h6|p|ol|ul|table|pre|address|blockquote|center|div)
3373: \s*
3374: (\w+\=['"]\w+['"])*
3375: \s*
3376: (
3377: \s*/>|
3378: >.*</\1\s*>
3379: )}xs
3380: );
3381: }
3382:
3383: sub tidy_html {
3384: my ($message)=@_;
3385: # my $tidy = HTML::Tidy::libXML->new();
3386: # my $xhtml = $tidy->clean($message, 'utf-8', 1);
3387: # $xhtml =~ m/<body>(.*)<\/body>/is;
3388: # my $clean = $1;
3389: # # remove any empty block-level tags
3390: # $clean =~ s/<(table|p|div|tbody|blockquote|m|pre|algebra|center|ol|ul|span|h1|h2|h3|h4|h5|h6)\s*\/>//i;
3391: # $message=$clean;
3392: return $message;
3393: }
3394:
3395: sub newline_to_br {
3396: my ($message)=@_;
3397: my $newmessage;
3398: my $parser=HTML::LCParser->new($message);
3399: while (my $token=$parser->get_token()) {
3400: if ($token->[0] eq 'T') {
3401: my $text=$token->[1];
3402: $text=~s/\n/\<br \/\>/g;
3403: $newmessage.=$text;
3404: } elsif ($token->[0] eq 'D' || $token->[0] eq 'C') {
3405: $newmessage.=$token->[1];
3406: } elsif ($token->[0] eq 'PI' || $token->[0] eq 'E') {
3407: $newmessage.=$token->[2];
3408: } elsif ($token->[0] eq 'S') {
3409: $newmessage.=$token->[4];
3410: }
3411:
3412: }
3413: $$message=$newmessage;
3414: }
3415:
3416: sub generate_preview_button {
3417: my ($formname,$fieldname)=@_;
3418: unless ($formname) { $formname='mailform'; }
3419: unless ($fieldname) { $fieldname='comment'; }
3420: my $pre=&mt("Show Preview and Check Spelling");
3421: return(<<ENDPREVIEW);
3422: <br />
3423: <form name="preview" action="/adm/feedback?preview=1" method="post" target="preview">
3424: <input type="hidden" name="subject" />
3425: <input type="hidden" name="comment" />
3426: <input type="button" value="$pre"
3427: onclick="if (typeof(document.$formname.onsubmit)=='function') {document.$formname.onsubmit();};this.form.comment.value=document.$formname.$fieldname.value;this.form.subject.value=document.$formname.subject.value;this.form.submit();" />
3428: </form>
3429: ENDPREVIEW
3430: }
3431:
3432: sub modify_attachments {
3433: my ($r,$currnewattach,$currdelold,$symb,$idx,$attachmenturls,
3434: $attachmaxtext,$toolarge)=@_;
3435:
3436: my %lt = &Apache::lonlocal::texthash(
3437: 'subj' => 'Subject',
3438: 'chth' => 'Check the checkboxes for any you wish to remove.',
3439: 'thef' => 'The following attachments have been uploaded for inclusion with this posting.',
3440: 'adda' => 'Add a new attachment to this post',
3441: 'stch' => 'Save Changes',
3442: 'clic' => 'Add/remove attachments',
3443: );
3444: my $js = <<END;
3445: <script type="text/javascript">
3446: function setAction () {
3447: document.modattachments.action = document.modattachments.origpage.value;
3448: document.modattachments.submit();
3449: }
3450: </script>
3451: END
3452:
3453: # Breadcrumbs
3454: my $brcrum = [{'href' => '',
3455: 'text' => 'Discussion Post Attachments'}];
3456: my %parms=('only_body' => 1);
3457: if ($env{'form.modal'} ne 'yes') { 'bread_crumbs' => $brcrum }
3458:
3459: my $start_page =
3460: &Apache::loncommon::start_page('Discussion Post Attachments',$js,\%parms);
3461:
3462: my $orig_subject = &unescape($env{'form.subject'});
3463: my $subject=&clear_out_html($orig_subject);
3464: $subject=~s/\n/\<br \/\>/g;
3465: $subject=&Apache::lontexconvert::msgtexconverted($subject);
3466: my $timestamp=$env{'form.timestamp'};
3467: my $numoldver=$env{'form.numoldver'};
3468:
3469: my $msg = '';
3470: my %attachments = ();
3471: my %currattach = ();
3472: if ($idx) {
3473: &extract_attachments($attachmenturls,$idx,$numoldver,\$msg,\%attachments,\%currattach,$currdelold);
3474: }
3475: &Apache::lonenc::check_encrypt(\$symb);
3476:
3477: my $end_page =
3478: &Apache::loncommon::end_page();
3479:
3480: $r->print(<<END);
3481: $start_page
3482: $toolarge
3483: <form name="modattachments" method="post" enctype="multipart/form-data" action="/adm/feedback?attach=$symb">
3484: <br />
3485: <h1>$lt{'clic'}</h1>
3486: END
3487: $r->print(&Apache::lonhtmlcommon::start_pick_box());
3488: $r->print(&Apache::lonhtmlcommon::row_title(&mt('Subject')));
3489: $r->print('<b>'.$subject.'</b>');
3490: $r->print(&Apache::lonhtmlcommon::row_closure());
3491: $r->print(&Apache::lonhtmlcommon::row_title($lt{'adda'}));
3492: $r->print('<input type="file" name="addnewattach" /><input type="button" name="upload" value="Upload" onclick="this.form.submit()" /> '.$attachmaxtext);
3493: if(($idx)||(ref($currnewattach) eq 'ARRAY') && (@{$currnewattach} > 0)){
3494: $r->print(&Apache::lonhtmlcommon::row_closure());
3495: $r->print(&Apache::lonhtmlcommon::row_title(&mt('Attachments')));
3496: if ($idx) {
3497: if ($attachmenturls) {
3498: my @currold = keys(%currattach);
3499: if (@currold > 0) {
3500: $r->print($lt{'thfo'}.'<br />'.$lt{'chth'}.'<br />'."\n");
3501: foreach my $id (@currold) {
3502: my $attachurl = &HTML::Entities::decode($attachments{$id}{'filename'});
3503: $attachurl =~ m#/([^/]+)$#;
3504: $r->print('<label><input type="checkbox" name="deloldattach" value="'.$id.'" /> '.$1.'</label><br />'."\n");
3505: }
3506: $r->print("<br />");
3507: }
3508: }
3509: }
3510: if ((ref($currnewattach) eq 'ARRAY') && (@{$currnewattach} > 0)) {
3511: $r->print($lt{'chth'}.'<br />'."\n");
3512: foreach my $attach (@{$currnewattach}) {
3513: $attach =~ m#/([^/]+)$#;
3514: $r->print('<label><input type="checkbox" name="delnewattach" value="'.$attach.'" /> '.$1.'</label><br />'."\n");
3515: }
3516: }
3517: }
3518: $r->print(&Apache::lonhtmlcommon::row_closure(1));
3519: $r->print(&Apache::lonhtmlcommon::end_pick_box());
3520: $r->print(<<END);
3521: <input type="hidden" name="subject" value="$env{'form.subject'}" />
3522: <input type="hidden" name="comment" value="$env{'form.comment'}" />
3523: <input type="hidden" name="timestamp" value="$env{'form.timestamp'}" />
3524: <input type="hidden" name="idx" value="$env{'form.idx'}" />
3525: <input type="hidden" name="numoldver" value="$env{'form.numoldver'}" />
3526: <input type="hidden" name="origpage" value="$env{'form.origpage'}" />
3527: <input type="hidden" name="blog" value="$env{'form.blog'}" />
3528: <input type="hidden" name="discuss" value="$env{'form.discuss'}" />
3529: END
3530: foreach my $item (@{$currnewattach}) {
3531: $r->print('<input type="hidden" name="currnewattach" value="'.$item.'" />'."\n");
3532: }
3533: foreach my $item (@{$currdelold}) {
3534: $r->print('<input type="hidden" name="deloldattach" value="'.$item.'" />'."\n");
3535: }
3536: $r->print(<<END);
3537: <input type="button" name="rtntoedit" value="$lt{'stch'}" onclick="setAction()" />
3538: </form>
3539: $end_page
3540: END
3541: return;
3542: }
3543:
3544: sub process_attachments {
3545: my ($currnewattach,$currdelold,$keepold) = @_;
3546:
3547: @{$currnewattach}=
3548: &Apache::loncommon::get_env_multiple('form.currnewattach');
3549: @{$currdelold}=
3550: &Apache::loncommon::get_env_multiple('form.deloldattach');
3551: if (exists($env{'form.delnewattach'})) {
3552: my @currdelnew =
3553: &Apache::loncommon::get_env_multiple('form.delnewattach');
3554: my @currnew = ();
3555: foreach my $newone (@{$currnewattach}) {
3556: my $delflag = 0;
3557: foreach my $item (@currdelnew) {
3558: if ($newone eq $item) {
3559: $delflag = 1;
3560: last;
3561: }
3562: }
3563: unless ($delflag) {
3564: push(@currnew, $newone);
3565: }
3566: }
3567: @{$currnewattach} = @currnew;
3568: }
3569: @{$keepold} = &Apache::loncommon::get_env_multiple('form.keepold');
3570: }
3571:
3572: sub generate_attachments_button {
3573: my ($idx,$attachnum,$ressymb,$now,$currnewattach,$deloldattach,
3574: $numoldver,$mode,$blockblog) = @_;
3575: my $origpage = $ENV{'REQUEST_URI'};
3576: my $att=$attachnum.' '.&mt("attachments");
3577: my %lt = &Apache::lonlocal::texthash(
3578: 'clic' => 'Add/remove attachments',
3579: );
3580: my $response = (<<END);
3581: <br />
3582: <form name="attachment" action="/adm/feedback?attach=$ressymb" method="post">
3583: <input type="button" value="$lt{'clic'}"
3584: onclick="if (typeof(document.mailform.onsubmit)=='function') {document.mailform.onsubmit();};this.form.comment.value=escape(document.mailform.comment.value);this.form.subject.value=escape(document.mailform.subject.value);
3585: END
3586: if (!$blockblog) {
3587: $response .= 'setblogvalue();';
3588: }
3589: unless ($mode eq 'board') {
3590: $response .= 'javascript:anonchk();';
3591: }
3592: $response .= (<<ENDATTACH);
3593: this.form.submit();" />
3594: <input type="hidden" name="origpage" value="$origpage" />
3595: <input type="hidden" name="idx" value="$idx" />
3596: <input type="hidden" name="timestamp" value="$now" />
3597: <input type="hidden" name="subject" />
3598: <input type="hidden" name="comment" />
3599: <input type="hidden" name="blog" value="0" />
3600: <input type="hidden" name="discuss" value="0" />
3601: <input type="hidden" name="numoldver" value="$numoldver" />
3602: ENDATTACH
3603: if (defined($deloldattach)) {
3604: if (@{$deloldattach} > 0) {
3605: foreach my $delatt (@{$deloldattach}) {
3606: $response .= '<input type="hidden" name="deloldattach" value="'.$delatt.'" />'."\n";
3607: }
3608: }
3609: }
3610: if (defined($currnewattach)) {
3611: if (@{$currnewattach} > 0) {
3612: foreach my $attach (@{$currnewattach}) {
3613: $response .= '<input type="hidden" name="currnewattach" value="'.$attach.'" />'."\n";
3614: }
3615: }
3616: }
3617: $response .= '</form>';
3618: return $response;
3619: }
3620:
3621: sub extract_attachments {
3622: my ($attachmenturls,$idx,$numoldver,$message,$attachments,$currattach,$currdelold) = @_;
3623: %{$attachments}=();
3624: &get_post_attachments($attachments,$attachmenturls);
3625: foreach my $id (sort(keys(%{$attachments}))) {
3626: if (exists($$attachments{$id}{$numoldver})) {
3627: if (defined($currdelold)) {
3628: if (@{$currdelold} > 0) {
3629: unless (grep/^$id$/,@{$currdelold}) {
3630: $$currattach{$id} = $$attachments{$id}{$numoldver};
3631: }
3632: } else {
3633: $$currattach{$id} = $$attachments{$id}{$numoldver};
3634: }
3635: } else {
3636: $$currattach{$id} = $$attachments{$id}{$numoldver};
3637: }
3638: }
3639: }
3640: my @attached = (sort { $a <=> $b } keys(%{$currattach}));
3641: if (@attached == 1) {
3642: my $id = $attached[0];
3643: my $attachurl;
3644: if ($attachmenturls =~ m/^<attachment id="0">/) {
3645: $attachurl = &HTML::Entities::decode($$attachments{$id}{'filename'});
3646: } else {
3647: $attachurl = $$attachments{$id}{'filename'};
3648: }
3649: $attachurl=~m|/([^/]+)$|;
3650: $$message.='<br /><a href="'.$attachurl.'"><tt>'.
3651: $1.'</tt></a><br />';
3652: &Apache::lonnet::allowuploaded('/adm/feedback',
3653: $attachurl);
3654: } elsif (@attached > 1) {
3655: $$message.='<ol>';
3656: foreach my $attach (@attached) {
3657: my $id = $attach;
3658: my $attachurl = &HTML::Entities::decode($$attachments{$id}{'filename'});
3659: my ($fname)
3660: =($attachurl=~m|/([^/]+)$|);
3661: $$message .= '<li><a href="'.$attachurl.
3662: '"><tt>'.
3663: $fname.'</tt></a></li>';
3664: &Apache::lonnet::allowuploaded('/adm/feedback',
3665: $attachurl);
3666: }
3667: $$message .= '</ol>';
3668: }
3669: }
3670:
3671: sub construct_attachmenturl {
3672: my ($currnewattach,$keepold,$symb,$idx)=@_;
3673: my $oldattachmenturl;
3674: my $newattachmenturl;
3675: my $startnum = 0;
3676: my $currver = 0;
3677: if (($env{'form.editdisc'}) && ($idx)) {
3678: my %contrib=&Apache::lonnet::restore($symb,$env{'request.course.id'},
3679: $env{'course.'.$env{'request.course.id'}.'.domain'},
3680: $env{'course.'.$env{'request.course.id'}.'.num'});
3681: $oldattachmenturl = $contrib{$idx.':attachmenturl'};
3682: if ($contrib{$idx.':history'}) {
3683: if ($contrib{$idx.':history'} =~ /:/) {
3684: my @oldversions = split(/:/,$contrib{$idx.':history'});
3685: $currver = 1 + scalar(@oldversions);
3686: } else {
3687: $currver = 2;
3688: }
3689: } else {
3690: $currver = 1;
3691: }
3692: if ($oldattachmenturl) {
3693: if ($oldattachmenturl =~ m/^<attachment id="0">/) {
3694: my %attachments = ();
3695: my $prevver = $currver-1;
3696: &get_post_attachments(\%attachments,$oldattachmenturl);
3697: my $numattach = scalar(keys(%attachments));
3698: $startnum += $numattach;
3699: foreach my $num (sort {$a <=> $b} keys(%attachments)) {
3700: $newattachmenturl .= '<attachment id="'.$num.'"><filename>'.$attachments{$num}{'filename'}.'</filename>';
3701: foreach my $item (sort {$a <=> $b} keys(%{$attachments{$num}})) {
3702: unless ($item eq 'filename') {
3703: $newattachmenturl .= '<post id="'.$item.'">'.$attachments{$num}{$item}.'</post>';
3704: }
3705: }
3706: if (grep/^$num$/,@{$keepold}) {
3707: $newattachmenturl .= '<post id="'.$currver.'">'.$attachments{$num}{$prevver}.'</post>';
3708: }
3709: $newattachmenturl .= '</attachment>';
3710: }
3711: } else {
3712: $newattachmenturl = '<attachment id="0"><filename>'.&HTML::Entities::encode($oldattachmenturl).'</filename><post id="0">n</post>';
3713: unless (grep/^0$/,@{$keepold}) {
3714: $newattachmenturl .= '<post id="1">n</post>';
3715: }
3716: $newattachmenturl .= '</attachment>';
3717: $startnum ++;
3718: }
3719: }
3720: }
3721: for (my $i=0; $i<@{$currnewattach}; $i++) {
3722: my $attachnum = $startnum + $i;
3723: $newattachmenturl .= '<attachment id="'.$attachnum.'"><filename>'.&HTML::Entities::encode($$currnewattach[$i]).'</filename><post id="'.$currver.'">n</post></attachment>';
3724: }
3725: return $newattachmenturl;
3726: }
3727:
3728: sub add_blog_checkbox {
3729: my ($crstype) = @_;
3730: my $checkstatus;
3731: if ($env{'form.blog'}) {
3732: $checkstatus = 'checked="checked"';
3733: }
3734: my $output = '
3735: <script type="text/javascript">
3736: function setblogvalue() {
3737: if (document.mailform.blog.checked) {
3738: document.attachment.blog.value = 1;
3739: } else {
3740: document.attachment.blog.value = 0;
3741: }
3742: }
3743: </script><br />
3744: <label><input type="checkbox" name="blog" '.$checkstatus.' /> ';
3745: if ($crstype eq 'Community') {
3746: $output .= &mt('Add to my public community blog');
3747: } else {
3748: $output .= &mt('Add to my public course blog');
3749: }
3750: $output .= '</label><br />'."\n";
3751: return $output;
3752: }
3753:
3754: sub has_discussion {
3755: my $resourcesref = shift;
3756: my $navmap = Apache::lonnavmaps::navmap->new();
3757: if (defined($navmap)) {
3758: my @allres=$navmap->retrieveResources();
3759: foreach my $resource (@allres) {
3760: if ($resource->hasDiscussion()) {
3761: my $ressymb = $resource->wrap_symb();
3762: if (ref($resourcesref) eq 'ARRAY') {
3763: push(@{$resourcesref}, $ressymb);
3764: }
3765: }
3766: }
3767: } else {
3768: &Apache::lonnet::logthis('Has discussion check failed - could not create navmap object.');
3769: }
3770: return;
3771: }
3772:
3773: sub sort_filter_names {
3774: my ($sort_types,$role_types,$status_types,$crstype) = @_;
3775: if (ref($sort_types) eq 'HASH') {
3776: %{$sort_types} = (
3777: ascdate => 'Date order - oldest first',
3778: descdate => 'Date order - newest first',
3779: thread => 'Threaded',
3780: subject => 'By subject',
3781: username => 'By domain and username',
3782: lastfirst => 'By last name, first name'
3783: );
3784: }
3785: my @courseroles = qw(st in ta ep ad);
3786: if ($crstype eq 'Community') {
3787: push(@courseroles,'co');
3788: } else {
3789: push(@courseroles,'cc');
3790: }
3791: if (ref($role_types) eq 'HASH') {
3792: foreach my $role (@courseroles) {
3793: $role_types->{$role} = &Apache::lonnet::plaintext($role,$crstype);
3794: }
3795: $role_types->{'all'} = 'All roles';
3796: $role_types->{'cr'} = 'Custom role';
3797: }
3798: if (ref($status_types) eq 'HASH') {
3799: %{$status_types} = (
3800: all => 'Roles of any status',
3801: Active => 'Only active roles',
3802: Expired => 'Only past roles',
3803: Future => 'Only future roles',
3804: );
3805: }
3806: }
3807:
3808: sub handler {
3809: my $r = shift;
3810: if ($r->header_only) {
3811: &Apache::loncommon::content_type($r,'text/html');
3812: $r->send_http_header;
3813: return OK;
3814: }
3815:
3816: # --------------------------- Get query string for limited number of parameters
3817:
3818: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
3819: ['like','unlike','modal','hide','unhide','deldisc','undeleteall','postdata','preview','replydisc','editdisc','cmd','symb','onlyunread','allposts','onlyunmark','previous','markread','markonread','markondisp','toggoff','toggon','modifydisp','changes','navtime','navmaps','navurl','sortposts','applysort','rolefilter','statusfilter','sectionpick','groupick','posterlist','userpick','attach','origpage','currnewattach','deloldattach','keepold','allversions','export','sendmessageonly','group','ref']);
3820: my $group = $env{'form.group'};
3821: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
3822: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
3823:
3824: my %attachmax = (
3825: text => &mt('(128 KB max size)'),
3826: num => 131072,
3827: );
3828: if ($env{'form.editdisc'}) {
3829: if (!(&editing_allowed($env{'form.editdisc'},$group))) {
3830: my $symb=(split(/\:\:\:/,$env{'form.editdisc'}))[0];
3831: my ($map,$id,$url)=&Apache::lonnet::decode_symb($symb);
3832: my $feedurl=&Apache::lonnet::clutter($url);
3833: &redirect_back($r,$feedurl,&mt('Editing not permitted').'<br />', '0','0','','',$env{'form.previous'},undef,undef,undef,
3834: undef,undef,undef,$group);
3835: return OK;
3836: }
3837: }
3838: if ($env{'form.discsymb'}) {
3839: my ($symb,$feedurl) = &get_feedurl_and_clean_symb($env{'form.discsymb'});
3840: my $readkey = $symb.'_read';
3841: my $chgcount = 0;
3842: my %readinghash = &Apache::lonnet::get('nohist_'.$env{'request.course.id'}.'_discuss',[$readkey],$env{'user.domain'},$env{'user.name'});
3843: foreach my $key (keys(%env)) {
3844: if ($key =~ m/^form\.postunread_(\d+)/) {
3845: if ($readinghash{$readkey} =~ /\.$1\./) {
3846: $readinghash{$readkey} =~ s/\.$1\.//;
3847: $chgcount ++;
3848: }
3849: } elsif ($key =~ m/^form\.postread_(\d+)/) {
3850: unless ($readinghash{$readkey} =~ /\.$1\./) {
3851: $readinghash{$readkey} .= '.'.$1.'.';
3852: $chgcount ++;
3853: }
3854: }
3855: }
3856: if ($chgcount > 0) {
3857: &Apache::lonnet::put('nohist_'.$env{'request.course.id'}.'_discuss',
3858: \%readinghash,$env{'user.domain'},$env{'user.name'});
3859: }
3860: &redirect_back($r,$feedurl,&mt('Marked postings read/unread').'<br />',
3861: '0','0','','',$env{'form.previous'},'','','',
3862: undef,undef,undef,$group);
3863: return OK;
3864: }
3865: if ($env{'form.allversions'}) {
3866: &Apache::loncommon::content_type($r,'text/html');
3867: &Apache::loncommon::no_cache($r);
3868: $r->send_http_header;
3869:
3870: # Breadcrumbs
3871: my $brcrum = [{'href' => '',
3872: 'text' => 'Discussion Post Versions'}];
3873:
3874: my %parms=();
3875: if ($env{'form.modal'} ne 'yes') { 'bread_crumbs' => $brcrum }
3876:
3877: $r->print(&Apache::loncommon::start_page('Discussion Post Versions',undef,\%parms));
3878:
3879: my ($symb,$idx)=split(/\:\:\:/,$env{'form.allversions'});
3880: ($symb, my $feedurl)=&get_feedurl_and_clean_symb($symb);
3881: my $ressymb = &wrap_symb($symb);
3882: my $seeid;
3883: if (&Apache::lonnet::allowed('rin',$env{'request.course.id'}.($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''))) {
3884: $seeid = 1;
3885: }
3886: my $seehidden = &can_see_hidden('',$ressymb,$feedurl,$group,$cdom,$cnum);
3887: if ($idx > 0) {
3888: my %messages = ();
3889: my %subjects = ();
3890: my %attachmsgs = ();
3891: my %allattachments = ();
3892: my %imsfiles = ();
3893: my ($screenname,$plainname,$showaboutme);
3894: my %contrib=&Apache::lonnet::restore($symb,$env{'request.course.id'},
3895: $cdom,$cnum);
3896: $r->print(&get_post_contents(\%contrib,$idx,$seeid,$seehidden,'allversions',\%messages,\%subjects,\%allattachments,\%attachmsgs,\%imsfiles,\$screenname,\$plainname,\$showaboutme));
3897: }
3898: $r->print(&Apache::loncommon::end_page());
3899: return OK;
3900: }
3901: if ($env{'form.posterlist'}) {
3902: my ($symb,$feedurl)=&get_feedurl_and_clean_symb($env{'form.applysort'});
3903: &print_showposters($r,$symb,$env{'form.previous'},$feedurl,
3904: $env{'form.sortposts'});
3905: return OK;
3906: }
3907: if ($env{'form.userpick'}) {
3908: my @posters = &Apache::loncommon::get_env_multiple('form.stuinfo');
3909: my ($symb,$feedurl)=&get_feedurl_and_clean_symb($env{'form.userpick'});
3910: my $numpicks = @posters;
3911: my %discinfo;
3912: $discinfo{$symb.'_userpick'} = join('&',@posters);
3913: &Apache::lonnet::put('nohist_'.$env{'request.course.id'}.'_discuss',
3914: \%discinfo,$env{'user.domain'},$env{'user.name'});
3915: &redirect_back($r,$feedurl,&mt('Changed sort/filter').'<br />','0','0','',
3916: '',$env{'form.previous'},$env{'form.sortposts'},'','','',
3917: '',$numpicks,$group);
3918: return OK;
3919: }
3920: if ($env{'form.applysort'}) {
3921: my ($symb,$feedurl)=&get_feedurl_and_clean_symb($env{'form.applysort'});
3922: &redirect_back($r,$feedurl,&mt('Changed sort/filter').'<br />','0','0','',
3923: '',$env{'form.previous'},$env{'form.sortposts'},
3924: $env{'form.rolefilter'},$env{'form.statusfilter'},
3925: $env{'form.sectionpick'},$env{'form.grouppick'},
3926: undef,$group);
3927: return OK;
3928: } elsif ($env{'form.cmd'} eq 'sortfilter') {
3929: my ($symb,$feedurl)=&get_feedurl_and_clean_symb($env{'form.symb'});
3930: &print_sortfilter_options($r,$symb,$env{'form.previous'},$feedurl);
3931: return OK;
3932: } elsif ($env{'form.navtime'}) {
3933: my %discinfo = ();
3934: my @resources = ();
3935: if (defined($env{'form.navmaps'})) {
3936: if ($env{'form.navmaps'} =~ /:/) {
3937: @resources = split(/:/,$env{'form.navmaps'});
3938: } else {
3939: @resources = ("$env{'form.navmaps'}");
3940: }
3941: } else {
3942: &has_discussion(\@resources);
3943: }
3944: my $numitems = @resources;
3945: my $feedurl = '/adm/navmaps';
3946: if ($env{'form.navurl'}) { $feedurl .= '?'.$env{'form.navurl'}; }
3947: my %lt = &Apache::lonlocal::texthash(
3948: 'mnpa' => 'Marked "New" posts as read in a total of',
3949: 'robb' => 'resources/bulletin boards.',
3950: 'twnp' => 'There are currently no resources or discussion boards with unread discussion postings.'
3951: );
3952: foreach my $res (@resources) {
3953: my $ressymb=$res;
3954: &Apache::lonenc::check_decrypt(\$ressymb);
3955: my $lastkey = $ressymb.'_lastread';
3956: $discinfo{$lastkey} = $env{'form.navtime'};
3957: }
3958: my $textline = "<b>$lt{'mnpa'} $numitems $lt{'robb'}</b>";
3959: if ($numitems > 0) {
3960: &Apache::lonnet::put('nohist_'.$env{'request.course.id'}.'_discuss',
3961: \%discinfo,$env{'user.domain'},$env{'user.name'});
3962: } else {
3963: $textline = "<b>$lt{'twnp'}</b>";
3964: }
3965: &Apache::loncommon::content_type($r,'text/html');
3966: $r->send_http_header;
3967: my $logo=&Apache::loncommon::lonhttpdurl('/adm/lonIcons/lonlogos.gif');
3968: my %onload;
3969:
3970: my $start_page=
3971: &Apache::loncommon::start_page('New posts marked as read',undef,
3972: {'redirect' => [2,$feedurl],
3973: 'only_body' => 1,
3974: 'add_entries' => \%onload});
3975: my $end_page = &Apache::loncommon::end_page();
3976: $r->print (<<ENDREDIR);
3977: $start_page
3978: <img align="right" src="$logo" />
3979: $textline
3980: <form name="reldt" action="$feedurl" target="loncapaclient">
3981: </form>
3982: <br />
3983: $end_page
3984: ENDREDIR
3985: return OK;
3986: } elsif ($env{'form.modifydisp'}) {
3987: my ($symb,$feedurl)=&get_feedurl_and_clean_symb($env{'form.modifydisp'});
3988: my ($dispchgA,$dispchgB,$markchg,$toggchg) =
3989: split(/_/,$env{'form.changes'});
3990: &print_display_options($r,$symb,$env{'form.previous'},$dispchgA,
3991: $dispchgB,$markchg,$toggchg,$feedurl);
3992: return OK;
3993: } elsif ($env{'form.markondisp'} || $env{'form.markonread'} ||
3994: $env{'form.allposts'} || $env{'form.onlyunread'} ||
3995: $env{'form.onlyunmark'} || $env{'form.toggoff'} ||
3996: $env{'form.toggon'} || $env{'form.markread'}) {
3997: my ($symb,$feedurl)=&get_feedurl_and_clean_symb($env{'form.symb'});
3998: my %discinfo;
3999: # ------------------------ Modify setting for read/unread toggle for each post
4000: if ($env{'form.toggoff'}) { $discinfo{$symb.'_readtoggle'}=0; }
4001: if ($env{'form.toggon'}) { $discinfo{$symb.'_readtoggle'}=1; }
4002: # --------- Modify setting for identification of 'NEW' posts in this discussion
4003: if ($env{'form.markondisp'}) {
4004: $discinfo{$symb.'_lastread'} = time;
4005: $discinfo{$symb.'_markondisp'} = 1;
4006: }
4007: if ($env{'form.markonread'}) {
4008: if ( $env{'form.previous'} > 0 ) {
4009: $discinfo{$symb.'_lastread'} = $env{'form.previous'};
4010: }
4011: $discinfo{$symb.'_markondisp'} = 0;
4012: }
4013: # --------------------------------- Modify display setting for this discussion
4014: if ($env{'form.allposts'}) {
4015: $discinfo{$symb.'_showonlyunread'} = 0;
4016: $discinfo{$symb.'_showonlyunmark'} = 0;
4017: }
4018: if ($env{'form.onlyunread'}) { $discinfo{$symb.'_showonlyunread'} = 1; }
4019: if ($env{'form.onlyunmark'}) { $discinfo{$symb.'_showonlyunmark'} = 1; }
4020: # ----------------------------------------------------- Mark new posts not NEW
4021: if ($env{'form.markread'}) { $discinfo{$symb.'_lastread'} = time; }
4022: &Apache::lonnet::put('nohist_'.$env{'request.course.id'}.'_discuss',
4023: \%discinfo,$env{'user.domain'},$env{'user.name'});
4024: my $previous=$env{'form.previous'};
4025: if ($env{'form.markondisp'}) { $previous=undef; }
4026: &redirect_back($r,$feedurl,&mt('Changed display status').'<br />',
4027: '0','0','','',$previous,'','','','','','',$group);
4028: return OK;
4029: } elsif (($env{'form.hide'}) || ($env{'form.unhide'})) {
4030: # ----------------------------------------------------------------- Hide/unhide
4031: my $entry=$env{'form.hide'}?$env{'form.hide'}:$env{'form.unhide'};
4032: my ($symb,$idx)=split(/\:\:\:/,$entry);
4033: ($symb,my $feedurl)=&get_feedurl_and_clean_symb($symb);
4034: my $ressymb = &wrap_symb($symb);
4035:
4036: my $seehidden = &can_see_hidden('',$ressymb,$feedurl,$group,$cdom,$cnum);
4037: unless (($seehidden) || (&editing_allowed($env{'form.hide'},$group))) {
4038: &redirect_back($r,$feedurl,&mt('Hiding not permitted').'<br />',
4039: '0','0','','',$env{'form.previous'},'','','','',
4040: undef,undef,$group,);
4041: return OK;
4042: }
4043:
4044: my %contrib=&Apache::lonnet::restore($symb,$env{'request.course.id'},
4045: $cdom,$cnum);
4046:
4047: my $currenthidden=$contrib{'hidden'};
4048: my $currentstudenthidden=$contrib{'studenthidden'};
4049:
4050: if ($env{'form.hide'}) {
4051: $currenthidden.='.'.$idx.'.';
4052: unless ($seehidden) {
4053: $currentstudenthidden.='.'.$idx.'.';
4054: }
4055: } else {
4056: $currenthidden=~s/\.$idx\.//g;
4057: }
4058: my %newhash=('hidden' => $currenthidden);
4059: if ( ($env{'form.hide'}) && (!$seehidden) ) {
4060: $newhash{'studenthidden'} = $currentstudenthidden;
4061: }
4062: if ($env{'form.hide'}) {
4063: my $changelast = 0;
4064: my $newlast;
4065: ($changelast,$newlast) = &get_discussion_info($idx,%contrib);
4066: if ($changelast) {
4067: &Apache::lonnet::put('discussiontimes',{$symb => $newlast},
4068: $cdom,$cnum);
4069: }
4070: }
4071: my $result;
4072: if (&Apache::lonnet::store(\%newhash,$symb,$env{'request.course.id'},
4073: $cdom,$cnum) eq 'ok') {
4074: my $prefix=$symb.':'.$idx.':';
4075: my %likes=&Apache::lonnet::dump('disclikes',$cdom,$cnum,
4076: '^'.$prefix);
4077: my ($totallikes,$totalunlikes);
4078: if (ref($likes{$prefix.'likers'}) eq 'HASH') {
4079: $totallikes = scalar(keys(%{$likes{$prefix.'likers'}}));
4080: }
4081: if (ref($likes{$prefix.'unlikers'}) eq 'HASH') {
4082: $totalunlikes = scalar(keys(%{$likes{$prefix.'unlikers'}}));
4083: }
4084: if ($totallikes || $totalunlikes) {
4085: my ($chglikes,$chgunlikes,$context);
4086: if ($env{'form.hide'}) {
4087: $chglikes = -1 * $totallikes;
4088: $chgunlikes = -1 * $totalunlikes;
4089: $context = 'hide';
4090: } else {
4091: $chglikes = $totallikes;
4092: $chgunlikes = $totalunlikes;
4093: $context = 'unhide';
4094: }
4095: &storediscussionlikes($chglikes,$chgunlikes,
4096: $contrib{$idx.':sendername'},
4097: $contrib{$idx.':senderdomain'},
4098: $env{'request.course.id'},
4099: $context);
4100:
4101: }
4102: $result = &mt('Changed discussion status');
4103: } else {
4104: $result = &mt('Discussion status unchanged');
4105: }
4106: &redirect_back($r,$feedurl,$result.'<br />','0','0','','',
4107: $env{'form.previous'},undef,undef,undef,
4108: undef,undef,undef,$group);
4109: return OK;
4110: } elsif (($env{'form.like'}) || ($env{'form.unlike'})) {
4111: # ----------------------------------------------------------------- Like/unlike
4112: my $entry=$env{'form.like'}?$env{'form.like'}:$env{'form.unlike'};
4113: my ($symb,$idx)=split(/\:\:\:/,$entry);
4114: ($symb,my $feedurl)=&get_feedurl_and_clean_symb($symb);
4115: my $result;
4116: if ($idx > 0) {
4117: my $realsymb = &get_realsymb($symb);
4118: my $status='OPEN';
4119: if ($Apache::lonhomework::parsing_a_problem ||
4120: $Apache::lonhomework::parsing_a_task) {
4121: $status=$Apache::inputtags::status[-1];
4122: }
4123: if (&discussion_vote_available($status,$realsymb)) {
4124: my %contrib=&Apache::lonnet::restore($symb,$env{'request.course.id'},
4125: $cdom,$cnum);
4126: if (($contrib{$idx.':sendername'} eq $env{'user.name'}) &&
4127: ($contrib{$idx.':senderdomain'} eq $env{'user.domain'})) {
4128: $result = &mt("Vote not registered. No voting for your own posts.");
4129: } else {
4130:
4131: #
4132: # Likes and unlikes are in db-file "disclikes" of the course
4133: # The prefix is the $symb to identify the resource discussion,
4134: # and the $idx to identify the entry
4135: #
4136: my $prefix=$symb.':'.$idx.':';
4137: my %likes=&Apache::lonnet::dump('disclikes',$cdom,$cnum,
4138: '^'.$prefix);
4139:
4140: # Get current like or unlike status for the $idx for this user.
4141: my $thisuser=$env{'user.name'}.':'.$env{'user.domain'};
4142: my ($userlikes,$userunlikes);
4143: if (ref($likes{$prefix.'likers'}) eq 'HASH') {
4144: if (exists($likes{$prefix.'likers'}{$thisuser})) {
4145: $userlikes = 1;
4146: }
4147: }
4148: if (ref($likes{$prefix.'unlikers'}) eq 'HASH') {
4149: if (exists($likes{$prefix.'unlikers'}{$thisuser})) {
4150: $userunlikes = 1;
4151: }
4152: }
4153: # Get the current "likes" count
4154: my $likescount=$likes{$prefix.'likes'};
4155: # Find out if they already voted
4156: # Users cannot like a post twice, or unlike it twice.
4157: # They can change their mind, though.
4158: my $alreadyflag=0;
4159: my $votetype;
4160: if ($env{'form.like'}) {
4161: if ($userlikes) {
4162: $alreadyflag=1;
4163: } elsif ($userunlikes) {
4164: delete($likes{$prefix.'unlikers'}{$thisuser});
4165: $votetype = 'switch';
4166: $likescount++;
4167: } else {
4168: if (ref($likes{$prefix.'likers'}) eq 'HASH') {
4169: $likes{$prefix.'likers'}{$thisuser} = 1;
4170: } else {
4171: $likes{$prefix.'likers'} = {$thisuser => 1};
4172: }
4173: $likescount++;
4174: }
4175: } else {
4176: if ($userunlikes) {
4177: $alreadyflag=1;
4178: } elsif ($userlikes) {
4179: delete($likes{$prefix.'likers'}{$thisuser});
4180: $votetype = 'switch';
4181: $likescount--;
4182: } else {
4183: if (ref($likes{$prefix.'unlikers'}) eq 'HASH') {
4184: $likes{$prefix.'unlikers'}{$thisuser} = 1;
4185: } else {
4186: $likes{$prefix.'unlikers'} = {$thisuser => 1};
4187: }
4188: $likescount--;
4189: }
4190: }
4191: # $alreadyflag would be 1 if they tried to double-like or double-unlike
4192: if ($alreadyflag) {
4193: if ($env{'form.like'}) {
4194: $result= &mt("'Like' already registered");
4195: } else {
4196: $result= &mt("'Unlike' already registered");
4197: }
4198: } else {
4199: my %newhash=($prefix.'likes' => $likescount,
4200: $prefix.'likers' => $likes{$prefix.'likers'},
4201: $prefix.'unlikers' => $likes{$prefix.'unlikers'});
4202: # Store data in db-file "disclikes"
4203: if (&Apache::lonnet::put('disclikes',\%newhash,$cdom,$cnum) eq 'ok') {
4204: # Also store with the person who posted the liked/unliked entry
4205: my ($chglike,$chgunlike);
4206: if ($env{'form.like'}) {
4207: if ($votetype eq 'switch') {
4208: $chglike = 0;
4209: $chgunlike = -1;
4210: } else {
4211: $chglike = 1;
4212: $chgunlike = 0;
4213: }
4214: &storediscussionlikes($chglike,$chgunlike,
4215: $contrib{$idx.':sendername'},
4216: $contrib{$idx.':senderdomain'},
4217: $env{'request.course.id'},'like');
4218: $result=&mt("Registered 'Like'");
4219: } else {
4220: if ($votetype eq 'switch') {
4221: $chglike = -1;
4222: $chgunlike = 0;
4223: } else {
4224: $chglike = 0;
4225: $chgunlike = 1;
4226: }
4227: &storediscussionlikes($chglike,$chgunlike,
4228: $contrib{$idx.':sendername'},
4229: $contrib{$idx.':senderdomain'},
4230: $env{'request.course.id'},'unlike');
4231: $result=&mt("Registered 'Unlike'");
4232: }
4233: } else {
4234: # Oops, something went wrong
4235: $result=&mt("Failed to register vote");
4236: }
4237: }
4238: }
4239: } else {
4240: $result=&mt('Voting unavailable for this discussion');
4241: }
4242: } else {
4243: $result=&mt('Invalid post number');
4244: }
4245: &redirect_back($r,$feedurl,$result.'<br />',
4246: '0','0','','',$env{'form.previous'},undef,undef,undef,
4247: undef,undef,undef,$group);
4248: return OK;
4249: } elsif ($env{'form.cmd'}=~/^(threadedoff|threadedon)$/) {
4250: my ($symb,$feedurl)=&get_feedurl_and_clean_symb($env{'form.symb'});
4251: if ($env{'form.cmd'} eq 'threadedon') {
4252: &Apache::lonnet::put('environment',{'threadeddiscussion' => 'on'});
4253: &Apache::lonnet::appenv({'environment.threadeddiscussion' => 'on'});
4254: } else {
4255: &Apache::lonnet::del('environment',['threadeddiscussion']);
4256: &Apache::lonnet::delenv('environment.threadeddiscussion');
4257: }
4258: &redirect_back($r,$feedurl,&mt('Changed discussion view mode').'<br />',
4259: '0','0','','',$env{'form.previous'},undef,undef,undef,
4260: undef,undef,undef,$group);
4261: return OK;
4262: } elsif ($env{'form.deldisc'}) {
4263: # --------------------------------------------------------------- Hide for good
4264: my ($symb,$idx)=split(/\:\:\:/,$env{'form.deldisc'});
4265: ($symb,my $feedurl)=&get_feedurl_and_clean_symb($symb);
4266: my $ressymb=&wrap_symb($symb);
4267:
4268: unless (&can_see_hidden('',$ressymb,$feedurl,$group,$cdom,$cnum)) {
4269: &redirect_back($r,$feedurl,&mt('Deletion not permitted').'<br />',
4270: '0','0','','',$env{'form.previous'},'','','','',
4271: undef,undef,$group);
4272: return OK;
4273: }
4274: my %contrib=&Apache::lonnet::restore($symb,$env{'request.course.id'},
4275: $cdom,$cnum);
4276: my ($changelast,$newlast) = &get_discussion_info($idx,%contrib);
4277: if ($changelast) {
4278: &Apache::lonnet::put('discussiontimes',{$symb => $newlast},
4279: $cdom,$cnum);
4280: }
4281: my %newhash=('deleted' => $contrib{'deleted'}.".$idx.");
4282:
4283: my $result;
4284: if (&Apache::lonnet::store(\%newhash,$symb,$env{'request.course.id'},
4285: $cdom,$cnum) eq 'ok') {
4286: $result = &mt('Changed discussion status');
4287: my $prefix=$symb.':'.$idx.':';
4288: my %likes=&Apache::lonnet::dump('disclikes',$cdom,$cnum,
4289: '^'.$prefix);
4290: my ($totallikes,$totalunlikes);
4291: if (ref($likes{$prefix.'likers'}) eq 'HASH') {
4292: $totallikes = scalar(keys(%{$likes{$prefix.'likers'}}));
4293: }
4294: if (ref($likes{$prefix.'unlikers'}) eq 'HASH') {
4295: $totalunlikes = scalar(keys(%{$likes{$prefix.'unlikers'}}));
4296: }
4297: if ($totallikes || $totalunlikes) {
4298: my $chglikes = -1 * $totallikes;
4299: my $chgunlikes = -1 * $totalunlikes;
4300: &storediscussionlikes($chglikes,$chgunlikes,
4301: $contrib{$idx.':sendername'},
4302: $contrib{$idx.':senderdomain'},
4303: $env{'request.course.id'},
4304: 'delete');
4305: }
4306: } else {
4307: $result = &mt('Discussion status unchanged');
4308: }
4309: &redirect_back($r,$feedurl,$result.'<br />','0','0','','',
4310: $env{'form.previous'},undef,undef,undef,
4311: undef,undef,undef,$group);
4312: return OK;
4313: } elsif ($env{'form.preview'}) {
4314: # -------------------------------------------------------- User wants a preview
4315: &show_preview($r);
4316: return OK;
4317: } elsif ($env{'form.attach'}) {
4318: # -------------------------------------------------------- Work on attachments
4319: &Apache::loncommon::content_type($r,'text/html');
4320: $r->send_http_header;
4321: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['subject','comment','addnewattach','delnewattach','timestamp','numoldver','idx','discuss','blog']);
4322: my (@currnewattach,@currdelold,@keepold,$toolarge);
4323: &process_attachments(\@currnewattach,\@currdelold,\@keepold);
4324: if (exists($env{'form.addnewattach.filename'})) {
4325: if (length($env{'form.addnewattach'})<=$attachmax{'num'}) {
4326: my $subdir = 'feedback/'.$env{'form.timestamp'};
4327: my $newattachment=&Apache::lonnet::userfileupload('addnewattach',undef,$subdir);
4328: push(@currnewattach, $newattachment);
4329: } else {
4330: $toolarge = '<p><span class="LC_warning">'.&mt('Attachment not included - exceeded permitted length').'</span><br /></p>';
4331: }
4332: }
4333: my $attachmenturls;
4334: my ($symb) = &get_feedurl_and_clean_symb($env{'form.attach'});
4335: my $idx = $env{'form.idx'};
4336: if ($idx) {
4337: my %contrib=&Apache::lonnet::restore($symb,$env{'request.course.id'},
4338: $cdom,$cnum);
4339: $attachmenturls = $contrib{$idx.':attachmenturl'};
4340: }
4341: &modify_attachments($r,\@currnewattach,\@currdelold,$symb,$idx,
4342: $attachmenturls,$attachmax{'text'},$toolarge);
4343: return OK;
4344: } elsif ($env{'form.export'}) {
4345: &Apache::loncommon::content_type($r,'text/html');
4346: $r->send_http_header;
4347: my ($symb,$feedurl) = &get_feedurl_and_clean_symb($env{'form.export'});
4348: my $mode='board';
4349: my $status='OPEN';
4350: my $previous=$env{'form.previous'};
4351: if ($feedurl =~ /$LONCAPA::assess_re/) {
4352: $mode='problem';
4353: $status=$Apache::inputtags::status[-1];
4354: }
4355:
4356: my $discussion = &list_discussion($mode,$status,$symb);
4357: my $start_page =
4358: &Apache::loncommon::start_page('Resource Feedback and Discussion');
4359: my $end_page =
4360: &Apache::loncommon::end_page();
4361: $r->print($start_page.$discussion.$end_page);
4362: return OK;
4363:
4364: } elsif ($env{'form.undeleteall'}) {
4365: &Apache::loncommon::content_type($r,'text/html');
4366: $r->send_http_header;
4367: my ($symb,$feedurl) = &get_feedurl_and_clean_symb($env{'form.undeleteall'});
4368: my $ressymb=&wrap_symb($symb);
4369: $r->print(&Apache::loncommon::start_page('Undelete all deleted discussion entries'));
4370: if (&can_see_hidden('',$ressymb,$feedurl,$group,$cdom,$cnum)) {
4371: my %contrib=&Apache::lonnet::restore($symb,$env{'request.course.id'},
4372: $cdom,$cnum);
4373: $contrib{'deleted'} =~ s/^\.//;
4374: $contrib{'deleted'} =~ s/\.$//;
4375: if ($contrib{'deleted'} ne '') {
4376: if (&Apache::lonnet::store({'deleted' => ''},$symb,$env{'request.course.id'},
4377: $cdom,$cnum) eq 'ok') {
4378: my %likes=&Apache::lonnet::dump('disclikes',$cdom,$cnum,'^'.$symb.':');
4379: my @ids = split(/\.\./,$contrib{'deleted'});
4380: my (%chglikes,%chgunlikes);
4381: foreach my $idx (@ids) {
4382: my $uname = $contrib{$idx.':sendername'};
4383: my $udom = $contrib{$idx.':senderdomain'};
4384: my ($totallikes,$totalunlikes);
4385: if (ref($likes{$symb.':'.$idx.':likers'}) eq 'HASH') {
4386: $totallikes = scalar(keys(%{$likes{$symb.':'.$idx.':likers'}}));
4387: }
4388: if (ref($likes{$symb.':'.$idx.':unlikers'}) eq 'HASH') {
4389: $totalunlikes = scalar(keys(%{$likes{$symb.':'.$idx.':unlikers'}}));
4390: }
4391: if ($totallikes || $totalunlikes) {
4392: $chglikes{$uname.':'.$udom} += $totallikes;
4393: $chgunlikes{$uname.':'.$udom} += $totalunlikes;
4394: }
4395: }
4396: foreach my $user (keys(%chglikes)) {
4397: my ($uname,$udom) = split(/:/,$user);
4398: &storediscussionlikes($chglikes{$user},$chgunlikes{$user},
4399: $uname,$udom,$env{'request.course.id'},
4400: 'undelete');
4401: }
4402: $r->print(&Apache::lonhtmlcommon::confirm_success(&mt("Undeleted all entries")));
4403: } else {
4404: $r->print(&Apache::lonhtmlcommon::confirm_success(&mt("Failed to undelete entries"),1));
4405: }
4406: } else {
4407: $r->print(&Apache::lonhtmlcommon::confirm_success(&mt("No entries to undelete"),1));
4408: }
4409: $r->print("<br /><a href='$feedurl'>".&mt("Return and reload")."</a>");
4410: }
4411: $r->print(&Apache::loncommon::end_page());
4412: return OK;
4413: } else {
4414: # ------------------------------------------------------------- Normal feedback
4415: my $feedurl=$env{'form.postdata'};
4416: $feedurl=~s/^https?\:\/\///;
4417: $feedurl=~s/^$ENV{'SERVER_NAME'}//;
4418: $feedurl=~s/^$ENV{'HTTP_HOST'}//;
4419: $feedurl=~s/\?.+$//;
4420:
4421: my $symb;
4422: if ($env{'form.replydisc'}) {
4423: $symb=(split(/\:\:\:/,$env{'form.replydisc'}))[0];
4424: } elsif ($env{'form.editdisc'}) {
4425: $symb=(split(/\:\:\:/,$env{'form.editdisc'}))[0];
4426: } elsif ($env{'form.origpage'}) {
4427: $symb="";
4428: } elsif ($env{'form.sendmessageonly'}) {
4429: $symb=(split(/\:\:\:/,$env{'form.sendmessageonly'}))[0];
4430: } else {
4431: $symb=&Apache::lonnet::symbread($feedurl);
4432: }
4433: unless ($symb) {
4434: $symb=$env{'form.symb'};
4435: }
4436: if (defined($symb)) {
4437: ($symb,$feedurl)=&get_feedurl_and_clean_symb($symb);
4438: } else {
4439: # backward compatibility (bulletin boards used to be 'wrapped')
4440: &Apache::lonenc::check_decrypt(\$feedurl);
4441: &dewrapper(\$feedurl);
4442: }
4443: my $goahead=1;
4444: if ($feedurl=~/$LONCAPA::assess_re/) {
4445: unless ($symb) { $goahead=0; }
4446: }
4447: if (!$goahead) {
4448: # Ambiguous Problem Resource
4449: $r->internal_redirect('/adm/ambiguous');
4450: return OK;
4451: }
4452: # Go ahead with feedback, no ambiguous reference
4453: unless (
4454: (
4455: ($feedurl=~m:^/res:) && ($feedurl!~m:^/res/adm:)
4456: )
4457: ||
4458: ($env{'request.course.id'} && ($feedurl!~m:^/adm:))
4459: ||
4460: ($env{'request.course.id'} && ($symb=~/^bulletin\_\_\_/))
4461: ) {
4462: &Apache::loncommon::content_type($r,'text/html');
4463: $r->send_http_header;
4464: # Unable to give feedback
4465: &Apache::lonenc::check_encrypt(\$feedurl);
4466: &no_redirect_back($r,$feedurl);
4467: return OK;
4468: }
4469: # --------------------------------------------------- Print login screen header
4470: unless ($env{'form.sendit'}) {
4471: &Apache::lonenc::check_encrypt(\$feedurl);
4472: &Apache::loncommon::content_type($r,'text/html');
4473: $r->send_http_header;
4474: if (($env{'form.replydisc'}) || ($env{'form.editdisc'})) {
4475: my ($blocked,$blocktext) =
4476: &Apache::loncommon::blocking_status('boards');
4477: if ($blocked) {
4478: $r->print(&blocked_reply_or_edit($blocktext));
4479: return OK;
4480: }
4481: }
4482: my $options=&screen_header($feedurl,$symb,$group);
4483: if ($options) {
4484: &mail_screen($r,$feedurl,$options,$symb,$attachmax{'text'});
4485: } else {
4486: &fail_redirect($r,$feedurl);
4487: }
4488: return OK;
4489: }
4490:
4491: # Get previous user input
4492: my $prevattempts=&Apache::loncommon::get_previous_attempt(
4493: $symb,$env{'user.name'},$env{'user.domain'},
4494: $env{'request.course.id'});
4495:
4496: # Get output from resource
4497: &Apache::lonenc::check_encrypt(\$feedurl);
4498: my $usersaw=&resource_output($feedurl);
4499:
4500: # Get resource answer (need to allow student to view grades for this to work)
4501: &Apache::lonnet::appenv({'allowed.vgr'=>'F'});
4502: my $usersymb = &Apache::lonenc::check_encrypt($symb);
4503: my $useranswer=
4504: &Apache::loncommon::get_student_answers(
4505: $usersymb,$env{'user.name'},$env{'user.domain'},
4506: $env{'request.course.id'});
4507: &Apache::lonnet::delenv('allowed.vgr');
4508: # Get attachments, if any, and not too large
4509: my $attachmenturl='';
4510: my $toolarge='';
4511: if (($env{'form.origpage'}) || ($env{'form.editdisc'}) ||
4512: ($env{'form.replydisc'})) {
4513: my ($symb,$idx);
4514: if ($env{'form.replydisc'}) {
4515: ($symb,$idx)=split(/\:\:\:/,$env{'form.replydisc'});
4516: } elsif ($env{'form.editdisc'}) {
4517: ($symb,$idx)=split(/\:\:\:/,$env{'form.editdisc'});
4518: } elsif ($env{'form.origpage'}) {
4519: $symb = $env{'form.symb'};
4520: }
4521: &Apache::lonenc::check_decrypt(\$symb);
4522: my @currnewattach = ();
4523: my @deloldattach = ();
4524: my @keepold = ();
4525: &process_attachments(\@currnewattach,\@deloldattach,\@keepold);
4526: $symb=~s|(bulletin___\d+___)adm/wrapper/|$1|;
4527: $attachmenturl=&construct_attachmenturl(\@currnewattach,\@keepold,$symb,$idx);
4528: } elsif ($env{'form.attachment.filename'}) {
4529: if (length($env{'form.attachment'})<=$attachmax{'num'}) {
4530: my $now = time;
4531: my $subdir = 'feedback/'.$now;
4532: $attachmenturl=&Apache::lonnet::userfileupload('attachment',undef,$subdir);
4533: } else {
4534: $toolarge = '<p><span class="LC_warning">'.&mt('Attachment not included - exceeded permitted length').'</span><br /></p>';
4535: }
4536: }
4537: # Filter HTML out of message (could be nasty)
4538: my $override;
4539: if ($env{'form.discuss'} =~ /^(?:author|question|course|policy)$/) {
4540: $override = 1;
4541: }
4542: my $message=&clear_out_html($env{'form.comment'},$override);
4543:
4544: # Assemble email
4545: my ($email,$citations)=&assemble_email($message,$prevattempts,
4546: $usersaw,$useranswer);
4547:
4548: # Who gets this?
4549: my ($typestyle,%to) = &Apache::lonmsg::decide_receiver($feedurl);
4550:
4551: # Actually send mail
4552: my ($status,$numsent)=&send_msg(&clear_out_html($env{'form.subject'}),
4553: $feedurl,$email,$citations,
4554: $attachmenturl,$usersymb,%to);
4555:
4556: # Discussion? Store that.
4557: my $numpost=0;
4558: if ( ($env{'form.discuss'} ne ''
4559: && $env{'form.discuss'} !~ /^(?:author|question|course|policy)/)
4560: || $env{'form.anondiscuss'} ne '') {
4561: my $subject = &clear_out_html($env{'form.subject'});
4562: my $anonmode=($env{'form.discuss'} eq 'anon' || $env{'form.anondiscuss'} );
4563: $typestyle.=&adddiscuss($symb,$message,$anonmode,$attachmenturl,
4564: $subject,$group);
4565: $numpost++;
4566: }
4567:
4568: # Add to blog?
4569:
4570: my $blog='';
4571: if ($env{'form.blog'}) {
4572: my $subject = &clear_out_html($env{'form.subject'});
4573: $status.=&Apache::lonrss::addentry($env{'user.name'},
4574: $env{'user.domain'},
4575: 'CourseBlog_'.$env{'request.course.id'},
4576: $subject,$message,$feedurl,'public');
4577: if (&Apache::loncommon::course_type() eq 'Community') {
4578: $blog='<br />'.&mt('Added to my community blog').'<br />';
4579: } else {
4580: $blog='<br />'.&mt('Added to my course blog').'<br />';
4581: }
4582: }
4583:
4584: # Receipt screen and redirect back to where came from
4585: &redirect_back($r,$feedurl,$typestyle,$numsent,$numpost,$blog,$status,$env{'form.previous'},undef,undef,undef,undef,undef,undef,$group,$toolarge);
4586: }
4587: return OK;
4588: }
4589:
4590: sub blocked_reply_or_edit {
4591: my ($blocktext) = @_;
4592: return
4593: &Apache::loncommon::start_page('Resource Feedback and Discussion').
4594: $blocktext.'<br /><br /><a href="javascript:history.go(-1)">'.
4595: &mt('Back to previous page').
4596: &Apache::loncommon::end_page();
4597: }
4598:
4599: sub wrap_symb {
4600: my ($ressymb)=@_;
4601: if ($ressymb =~ /bulletin___\d+___/) {
4602: unless ($ressymb =~ m|bulletin___\d+___adm/wrapper|) {
4603: $ressymb=~s|(bulletin___\d+___)|$1adm/wrapper|;
4604: }
4605: }
4606: return $ressymb;
4607: }
4608:
4609: sub dewrapper {
4610: my ($feedurl)=@_;
4611: if ($$feedurl=~m|^/adm/wrapper/adm/.*/bulletinboard$|) {
4612: $$feedurl=~s|^/adm/wrapper||;
4613: }
4614: }
4615:
4616: sub get_feedurl {
4617: my ($symb)=@_;
4618: my ($map,$ind,$url)=&Apache::lonnet::decode_symb($symb);
4619: my $feedurl = &Apache::lonnet::clutter($url);
4620: &dewrapper(\$feedurl);
4621: return $feedurl;
4622: }
4623:
4624: sub get_feedurl_and_clean_symb {
4625: my ($symb)=@_;
4626: &Apache::lonenc::check_decrypt(\$symb);
4627: # backward compatibility (bulletin boards used to be 'wrapped')
4628: unless ($symb =~ m|bulletin___\d+___adm/wrapper|) {
4629: $symb=~s|(bulletin___\d+___)|$1adm/wrapper|;
4630: }
4631: my $feedurl = &get_feedurl($symb);
4632: return ($symb,$feedurl);
4633: }
4634:
4635: sub editing_allowed {
4636: my ($postid,$group) = @_;
4637: $postid = &unescape($postid);
4638: my $can_edit = 0;
4639: if ($group ne '') {
4640: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
4641: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
4642: if ($postid =~ m|^bulletin___\d+___adm/wrapper(/adm/\Q$cdom\E/\Q$cnum\E/\d+/bulletinboard)|) {
4643: if (&check_group_priv($group,'egp') eq 'ok') {
4644: $can_edit = 1;
4645: }
4646: return $can_edit;
4647: }
4648: }
4649: my $cid = $env{'request.course.id'};
4650: my $role = (split(/\./,$env{'request.role'}))[0];
4651: my $section = $env{'request.course.sec'};
4652: my $allow_editing_config =
4653: $env{'course.'.$cid.'.allow_discussion_post_editing'};
4654: if ($allow_editing_config =~ m/^\s*yes\s*$/i) {
4655: $can_edit = 1;
4656: } else {
4657: foreach my $editor (split(/,/,$allow_editing_config)) {
4658: my ($editor_role,$editor_sec) = split(/:/,$editor);
4659: if ($editor_role eq $role
4660: && defined($editor_sec)
4661: && defined($section)
4662: && $editor_sec eq $section) {
4663: $can_edit = 1;
4664: last;
4665: }
4666: if ($editor_role eq $role
4667: && !defined($editor_sec)) {
4668: $can_edit = 1;
4669: }
4670: }
4671: }
4672: return $can_edit;
4673: }
4674:
4675: sub check_group_priv {
4676: my ($group,$grp_priv) = @_;
4677: foreach my $priv ('mdg','vcg') {
4678: my $checkcourse = $env{'request.course.id'}.
4679: ($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:'');
4680: if (&Apache::lonnet::allowed($priv,$checkcourse)) {
4681: return 'ok';
4682: }
4683: }
4684: if ($grp_priv && $group ne '') {
4685: if (&Apache::lonnet::allowed($grp_priv,$env{'request.course.id'}.'/'.$group)) {
4686: return 'ok';
4687: }
4688: }
4689: return '';
4690: }
4691:
4692: sub group_args {
4693: my ($group) = @_;
4694: if ($group eq '') { return ''; }
4695: my $extra_args = '&group='.$group;
4696: if (exists($env{'form.ref'})) {
4697: $extra_args .= '&ref='.$env{'form.ref'};
4698: }
4699: return $extra_args;
4700: }
4701:
4702: sub get_resource_title {
4703: my ($symb,$feedurl) = @_;
4704: my ($restitle,$plainurl);
4705: if (defined($symb)) {
4706: my $plain_symb = &Apache::lonenc::check_decrypt($symb);
4707: $restitle = &Apache::lonnet::gettitle($plain_symb);
4708: }
4709: if (defined($feedurl)) {
4710: $plainurl = &Apache::lonenc::check_decrypt($feedurl);
4711: }
4712: if (!defined($restitle)) {
4713: if (defined($feedurl)) {
4714: $restitle = &Apache::lonnet::gettitle($plainurl);
4715: }
4716: }
4717: if ($plainurl ne $feedurl) {
4718: my ($plain_filename) = ($plainurl =~ m-/([^/]+)$-);
4719: if ($plain_filename eq $restitle) {
4720: $restitle = &mt('Untitled resource');
4721: }
4722: }
4723: if ($restitle eq '') {
4724: $restitle = &mt('Untitled resource');
4725: }
4726: return $restitle;
4727: }
4728:
4729: 1;
4730: __END__
4731:
4732:
4733: =pod
4734:
4735: =head1 NAME
4736:
4737: Apache::lonfeedback.pm
4738:
4739: =head1 SYNOPSIS
4740:
4741: Handles feedback from students to instructors and system administrators.
4742:
4743: Provides a screenshot of the current resource, as well as previous attempts if the resource was a homework.
4744:
4745: Used by lonmsg.pm.
4746:
4747: This is part of the LearningOnline Network with CAPA project
4748: described at http://www.lon-capa.org.
4749:
4750: =head1 OVERVIEW
4751:
4752: None
4753:
4754: =head1 SUBROUTINES
4755:
4756: =over
4757:
4758: =item discussion_open()
4759:
4760: =item discussion_visible()
4761:
4762: =item discussion_vote_available()
4763:
4764: =item get_realsymb()
4765:
4766: =item list_discussion()
4767:
4768: =item can_see_discussion()
4769:
4770: =item send_feedback_link()
4771:
4772: =item send_message_link()
4773:
4774: =item action_links_bar()
4775:
4776: =item postingform_display()
4777:
4778: =item build_posting_display
4779:
4780: =item filter_regexp()
4781:
4782: =item get_post_contents()
4783:
4784: =item replicate_attachments()
4785:
4786: =item mail_screen()
4787:
4788: =item print_display_options()
4789:
4790: =item print_sortfilter_options()
4791:
4792: =item print_showposters()
4793:
4794: =item get_post_versions()
4795:
4796: =item get_post_attachments()
4797:
4798: =item fail_redirect()
4799:
4800: =item redirect_back()
4801:
4802: =item no_redirect_back()
4803:
4804: =item screen_header()
4805:
4806: =item resource_output()
4807:
4808: =item clear_out_html()
4809:
4810: =item assemble_email()
4811:
4812: =item feedback_available()
4813:
4814: =item send_msg()
4815:
4816: =item adddiscuss()
4817:
4818: =item get_discussion_info()
4819:
4820: =item show_preview()
4821:
4822: =item newline_to_br()
4823:
4824: =item tidy_html()
4825:
4826: =item generate_preview_button()
4827:
4828: =item modify_attachments()
4829:
4830: =item process_attachments()
4831:
4832: =item generate_attachments_button()
4833:
4834: =item extract_attachments()
4835:
4836: =item construct_attachmenturl()
4837:
4838: =item add_blog_checkbox()
4839:
4840: =item has_discussion()
4841:
4842: =item sort_filter_names()
4843:
4844: =item handler()
4845:
4846: =item blocked_reply_or_edit()
4847:
4848: =item wrap_symb()
4849:
4850: =item dewrapper()
4851:
4852: =item get_feedurl()
4853:
4854: =item get_feedurl_and_clean_symb()
4855:
4856: =item editing_allowed()
4857:
4858: =item check_group_priv()
4859:
4860: =item group_args()
4861:
4862: =item get_resource_title()
4863:
4864: =back
4865:
4866: =cut
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>