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