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