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