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