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