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