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