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