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