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