1: # The LearningOnline Network
2: # Feedback
3: #
4: # $Id: lonfeedback.pm,v 1.98 2004/07/05 22:54:33 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::lonhtmlcommon();
39:
40: sub discussion_open {
41: my ($status)=@_;
42: if (defined($status) &&
43: !($status eq 'CAN_ANSWER' || $status eq 'CANNOT_ANSWER'
44: || $status eq 'OPEN')) {
45: return 0;
46: }
47: my $close=&Apache::lonnet::EXT('resource.0.discussend');
48: if (defined($close) && $close ne '' && $close < time) {
49: return 0;
50: }
51: return 1;
52: }
53:
54: sub discussion_visible {
55: my ($status)=@_;
56: if (not &discussion_open($status)) {
57: my $hidden=&Apache::lonnet::EXT('resource.0.discusshide');
58: if (lc($hidden) eq 'yes' or $hidden eq '' or !defined($hidden)) {
59: return 0;
60: }
61: }
62: return 1;
63: }
64:
65: sub list_discussion {
66: my ($mode,$status,$symb)=@_;
67:
68: my $outputtarget=$ENV{'form.grade_target'};
69: if (not &discussion_visible($status)) { return ''; }
70: my @bgcols = ("#cccccc","#eeeeee");
71: my $discussiononly=0;
72: if ($mode eq 'board') { $discussiononly=1; }
73: unless ($ENV{'request.course.id'}) { return ''; }
74: my $crs='/'.$ENV{'request.course.id'};
75: if ($ENV{'request.course.sec'}) {
76: $crs.='_'.$ENV{'request.course.sec'};
77: }
78: $crs=~s/\_/\//g;
79: unless ($symb) {
80: $symb=&Apache::lonnet::symbread();
81: }
82: unless ($symb) { return ''; }
83:
84: # backward compatibility (bulletin boards used to be 'wrapped')
85: my $ressymb=$symb;
86: if ($mode eq 'board') {
87: unless ($ressymb =~ m|bulletin___\d+___adm/wrapper|) {
88: $ressymb=~s|(bulletin___\d+___)|$1adm/wrapper|;
89: }
90: }
91:
92: # Get discussion display settings for this discussion
93: my $lastkey = $ressymb.'_lastread';
94: my $showkey = $ressymb.'_showonlyunread';
95: my $visitkey = $ressymb.'_visit';
96: my $ondispkey = $ressymb.'_markondisp';
97: my %dischash = &Apache::lonnet::get('nohist_'.$ENV{'request.course.id'}.'_discuss',[$lastkey,$showkey,$visitkey,$ondispkey],$ENV{'user.domain'},$ENV{'user.name'});
98: my %discinfo = ();
99: my $showonlyunread = 0;
100: my $markondisp = 0;
101: my $prevread = 0;
102: my $previous = 0;
103: my $visit = 0;
104: my $newpostsflag = 0;
105:
106: # Retain identification of "NEW" posts identified in last display, if continuing 'previous' browsing of posts.
107: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['previous']);
108: $previous = $ENV{'form.previous'};
109: if ($previous > 0) {
110: $prevread = $previous;
111: } elsif (defined($dischash{$lastkey})) {
112: unless ($dischash{$lastkey} eq '') {
113: $prevread = $dischash{$lastkey};
114: }
115: }
116:
117: # Get discussion display default settings for user
118: my %userenv = &Apache::lonnet::get('environment',['discdisplay','discmarkread'],$ENV{'user.domain'},$ENV{'user.name'});
119: my $discdisplay=$userenv{'discdisplay'};
120: if ($discdisplay eq 'unread') {
121: $showonlyunread = 1;
122: }
123: my $discmarkread=$userenv{'discmarkread'};
124: if ($discmarkread eq 'ondisp') {
125: $markondisp = 1;
126: }
127:
128: # Override user's default if user specified display setting for this discussion
129: if (defined($dischash{$ondispkey})) {
130: $markondisp = $dischash{$ondispkey};
131: }
132: if ($markondisp) {
133: $discinfo{$lastkey} = time;
134: }
135:
136: if (defined($dischash{$showkey})) {
137: $showonlyunread = $dischash{$showkey};
138: }
139:
140: if (defined($dischash{$visitkey})) {
141: $visit = $dischash{$visitkey};
142: }
143: $visit ++;
144:
145: my $seeid=&Apache::lonnet::allowed('rin',$crs);
146: my $viewgrades=(&Apache::lonnet::allowed('vgr',$crs)
147: && ($symb=~/\.(problem|exam|quiz|assess|survey|form)$/));
148: my @discussionitems=();
149: my %contrib=&Apache::lonnet::restore($ressymb,$ENV{'request.course.id'},
150: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
151: $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
152: my $visible=0;
153: my @depth=();
154: my @original=();
155: my @index=();
156: my @replies=();
157: my %alldiscussion=();
158: my %notshown = ();
159: my %newitem = ();
160: my $maxdepth=0;
161:
162: my $target='';
163: unless ($ENV{'browser.interface'} eq 'textual' ||
164: $ENV{'environment.remote'} eq 'off' ) {
165: $target='target="LONcom"';
166: }
167:
168: my $now = time;
169: $discinfo{$visitkey} = $visit;
170:
171: &Apache::lonnet::put('nohist_'.$ENV{'request.course.id'}.'_discuss',\%discinfo,$ENV{'user.domain'},$ENV{'user.name'});
172:
173: if ($contrib{'version'}) {
174: my $oldest = $contrib{'1:timestamp'};
175: if ($prevread eq '0') {
176: $prevread = $oldest-1;
177: }
178: for (my $id=1;$id<=$contrib{'version'};$id++) {
179: my $idx=$id;
180: my $posttime = $contrib{$idx.':timestamp'};
181: if ($prevread <= $posttime) {
182: $newpostsflag = 1;
183: }
184: my $hidden=($contrib{'hidden'}=~/\.$idx\./);
185: my $deleted=($contrib{'deleted'}=~/\.$idx\./);
186: my $origindex='0.';
187: if (($contrib{$idx.':replyto'}) && ($ENV{'environment.threadeddiscussion'})) {
188: # this is a follow-up message
189: $original[$idx]=$original[$contrib{$idx.':replyto'}];
190: $depth[$idx]=$depth[$contrib{$idx.':replyto'}]+1;
191: $origindex=$index[$contrib{$idx.':replyto'}];
192: if ($depth[$idx]>$maxdepth) { $maxdepth=$depth[$idx]; }
193: } else {
194: # this is an original message
195: $original[$idx]=0;
196: $depth[$idx]=0;
197: }
198: if ($replies[$depth[$idx]]) {
199: $replies[$depth[$idx]]++;
200: } else {
201: $replies[$depth[$idx]]=1;
202: }
203: unless ((($hidden) && (!$seeid)) || ($deleted)) {
204: $visible++;
205: my $message=$contrib{$idx.':message'};
206: $message=~s/\n/\<br \/\>/g;
207: $message=&Apache::lontexconvert::msgtexconverted($message);
208: my $subject=$contrib{$idx.':subject'};
209: if (defined($subject)) {
210: $subject=~s/\n/\<br \/\>/g;
211: $subject=&Apache::lontexconvert::msgtexconverted($subject);
212: }
213: if ($contrib{$idx.':attachmenturl'}) {
214: my ($fname)
215: =($contrib{$idx.':attachmenturl'}=~m|/([^/]+)$|);
216: &Apache::lonnet::allowuploaded('/adm/feedback',
217: $contrib{$idx.':attachmenturl'});
218: $message.='<p>'.&mt('Attachment').
219: ': <a href="'.$contrib{$idx.':attachmenturl'}.'"><tt>'.
220: $fname.'</tt></a></p>';
221: }
222: if ($message) {
223: if ($hidden) {
224: $message='<font color="#888888">'.$message.'</font>';
225: }
226: my $screenname=&Apache::loncommon::screenname(
227: $contrib{$idx.':sendername'},
228: $contrib{$idx.':senderdomain'});
229: my $plainname=&Apache::loncommon::nickname(
230: $contrib{$idx.':sendername'},
231: $contrib{$idx.':senderdomain'});
232:
233: my $sender=&mt('Anonymous');
234: if ((!$contrib{$idx.':anonymous'}) || ($seeid)) {
235: $sender=&Apache::loncommon::aboutmewrapper(
236: $plainname,
237: $contrib{$idx.':sendername'},
238: $contrib{$idx.':senderdomain'}).' ('.
239: $contrib{$idx.':sendername'}.' at '.
240: $contrib{$idx.':senderdomain'}.')';
241: if ($contrib{$idx.':anonymous'}) {
242: $sender.=' ['.&mt('anonymous').'] '.
243: $screenname;
244: }
245: if ($seeid) {
246: if ($hidden) {
247: $sender.=' <a href="/adm/feedback?unhide='.
248: $ressymb.':::'.$idx;
249: if ($newpostsflag) {
250: $sender .= '&previous='.$prevread;
251: }
252: $sender .= '">'.&mt('Make Visible').'</a>';
253: } else {
254: $sender.=' <a href="/adm/feedback?hide='.
255: $ressymb.':::'.$idx;
256: if ($newpostsflag) {
257: $sender .= '&previous='.$prevread;
258: }
259: $sender .= '">'.&mt('Hide').'</a>';
260: }
261: $sender.=' <a href="/adm/feedback?deldisc='.
262: $ressymb.':::'.$idx;
263: if ($newpostsflag) {
264: $sender .= '&previous='.$prevread;
265: }
266: $sender .= '">'.&mt('Delete').'</a>';
267: }
268: } else {
269: if ($screenname) {
270: $sender='<i>'.$screenname.'</i>';
271: }
272: }
273: if (&discussion_open($status) &&
274: &Apache::lonnet::allowed('pch',
275: $ENV{'request.course.id'}.
276: ($ENV{'request.course.sec'}?'/'.$ENV{'request.course.sec'}:''))) {
277: $sender.=' <a href="/adm/feedback?replydisc='.
278: $ressymb.':::'.$idx;
279: if ($newpostsflag) {
280: $sender .= '&previous='.$prevread;
281: }
282: $sender .= '" '.$target.'>'.&mt('Reply').'</a>';
283: }
284: my $vgrlink;
285: if ($viewgrades) {
286: $vgrlink=&Apache::loncommon::submlink('Submissions',
287: $contrib{$idx.':sendername'},$contrib{$idx.':senderdomain'},$symb);
288: }
289: #figure out at what position this needs to print
290: my $thisindex=$idx;
291: if ($ENV{'environment.threadeddiscussion'}) {
292: $thisindex=$origindex.substr('00'.$replies[$depth[$idx]],-2,2);
293: }
294: $alldiscussion{$thisindex}=$idx;
295: $index[$idx]=$thisindex;
296: my $spansize = 2;
297: if ($showonlyunread && $prevread > $posttime) {
298: $notshown{$idx} = 1;
299: } else {
300: if ($prevread > 0 && $prevread <= $posttime) {
301: $newitem{$idx} = 1;
302: $discussionitems[$idx] .= '
303: <p><table border="0" width="100%">
304: <tr><td align="left"><font color="#FF0000"><b>NEW</b></font></td>';
305: } else {
306: $newitem{$idx} = 0;
307: $discussionitems[$idx] .= '
308: <p><table border="0" width="100%">
309: <tr><td align="left"> </td>';
310: }
311: $discussionitems[$idx] .= '<td align ="left"> '.
312: '<b>'.$subject.'</b> '.
313: $sender.'</b> '.$vgrlink.' ('.
314: localtime($posttime).')</td></tr>'.
315: '</table><blockquote>'.$message.'</blockquote></p>';
316: }
317: }
318: }
319: }
320: }
321:
322: my $discussion='';
323:
324: my $function = &Apache::loncommon::get_users_function();
325: my $color = &Apache::loncommon::designparm($function.'.tabbg',
326: $ENV{'user.domain'});
327: my %lt = &Apache::lonlocal::texthash(
328: 'cuse' => 'Current discussion settings',
329: 'allposts' => 'All posts',
330: 'unread' => 'New posts only',
331: 'ondisp' => 'Once displayed',
332: 'onmark' => 'Once marked read',
333: 'disa' => 'Posts to be displayed',
334: 'npce' => 'Posts cease to be marked "NEW"',
335: 'chgt' => 'Change',
336: 'disp' => 'Display',
337: 'nolo' => 'Not new',
338: );
339:
340: my $currdisp = $lt{'allposts'};
341: my $currmark = $lt{'onmark'};
342: my $dispchange = $lt{'unread'};
343: my $markchange = $lt{'ondisp'};
344: my $chglink = '/adm/feedback?modifydisp='.$ressymb;
345: my $displink = 'onlyunread';
346: my $marklink = 'markondisp';
347:
348: if ($markondisp) {
349: $currmark = $lt{'ondisp'};
350: $markchange = $lt{'onmark'};
351: $marklink = 'markonread';
352: }
353:
354: if ($showonlyunread) {
355: $currdisp = $lt{'unread'};
356: $dispchange = $lt{'allposts'};
357: $displink = 'allposts';
358: }
359:
360: $chglink .= '&changes='.$displink.'_'.$marklink;
361:
362: if ($newpostsflag) {
363: $chglink .= '&previous='.$prevread;
364: }
365:
366: if ($visible) {
367: # Print the discusssion
368: if ($outputtarget ne 'tex') {
369: my $colspan=$maxdepth+1;
370: $discussion.='<table bgcolor="#AAAAAA" cellpadding="2" cellspacing="2" border="0">';
371: $discussion .='<tr><td bgcolor="#DDDDBB" colspan="'.$colspan.'">'.
372: '<table border="0" width="100%" bgcolor="#DDDDBB"><tr>';
373: if ($visible>2) {
374: $discussion.='<td align="left">'.
375: '<a href="/adm/feedback?threadedon='.$ressymb;
376: if ($newpostsflag) {
377: $discussion .= '&previous='.$prevread;
378: }
379: $discussion .='">'.&mt('Threaded View').'</a> '.
380: '<a href="/adm/feedback?threadedoff='.$ressymb;
381: if ($newpostsflag) {
382: $discussion .= '&previous='.$prevread;
383: }
384: $discussion .='">'.&mt('Chronological View').'</a> </td>';
385: }
386: if ($newpostsflag) {
387: if (!$markondisp) {
388: $discussion .='<td align="right"><a href="/adm/feedback?markread='.$ressymb.'">'.&mt('Mark new posts as read').'</a> ';
389: } else {
390: $discussion .= '<td> </td>';
391: }
392: } else {
393: $discussion .= '<td> </td>';
394: }
395: $discussion .= '</tr></table></td></tr>';
396: } else {
397: $discussion.='\vskip 0 mm\noindent\makebox[2 cm][b]{\hrulefill}'.
398: '\textbf{DISCUSSIONS}\makebox[2 cm][b]{\hrulefill}'.
399: '\vskip 0 mm\noindent\textbf{'.$lt{'cuse'}.'}:\vskip 0 mm'.
400: '\noindent\textbf{'.$lt{'disa'}.'}: \textit{'.$currdisp.'}\vskip 0 mm'.
401: '\noindent\textbf{'.$lt{'npce'}.'}: \textit{'.$currmark.'}';
402: }
403: my $numhidden = keys %notshown;
404: if ($numhidden > 0) {
405: my $colspan = $maxdepth+1;
406: $discussion.="\n".'<tr><td bgcolor="#CCCCCC" colspan="'.$colspan.'">'.
407: '<a href="/adm/feedback?allposts='.$ressymb;
408: if ($newpostsflag) {
409: $discussion .= '&previous='.$prevread;
410: }
411: $discussion .= '">'.&mt('Show all posts').'</a> '.&mt('to display').' '.
412: $numhidden.' '.&mt('previously viewed posts').
413: '<br/></td></tr>';
414: }
415: foreach (sort { $a <=> $b } keys %alldiscussion) {
416: unless ($notshown{$alldiscussion{$_}} eq '1') {
417: if ($outputtarget ne 'tex') {
418: $discussion.="\n<tr>";
419: } else {
420: $discussion.='\vskip 0 mm\noindent\makebox[2 cm][b]{\hrulefill}';
421: }
422: my $thisdepth=$depth[$alldiscussion{$_}];
423: if ($outputtarget ne 'tex') {
424: for (1..$thisdepth) {
425: $discussion.='<td> </td>';
426: }
427: }
428: my $colspan=$maxdepth-$thisdepth+1;
429: if ($outputtarget ne 'tex') {
430: $discussion.='<td bgcolor="'.$bgcols[$newitem{$alldiscussion{$_}}].'" colspan="'.$colspan.'">'.
431: $discussionitems[$alldiscussion{$_}].
432: '</td></tr>';
433: } else {
434: #cleanup block
435: $discussionitems[$alldiscussion{$_}]=~s/<table([^>]*)>/<table TeXwidth="90 mm">/;
436: $discussionitems[$alldiscussion{$_}]=~s/<tr([^>]*)><td([^>]*)>/<tr><td TeXwidth="20 mm" align="left">/;
437: my $threadinsert='';
438: if ($thisdepth > 0) {
439: $threadinsert='<br /><strong>Reply: '.$thisdepth.'</strong>';
440: }
441: $discussionitems[$alldiscussion{$_}]=~s/<\/td><td([^>]*)>/$threadinsert<\/td><td TeXwidth="65 mm" align="left">/;
442: $discussionitems[$alldiscussion{$_}]=~s/<a([^>]+)>(Hide|Delete|Reply|Submissions)<\/a>//g;
443: $discussionitems[$alldiscussion{$_}]=~s/(<b>|<\/b>|<\/a>|<a([^>]+)>)//g;
444:
445: #FIXME xmlparse can't be safely called from inside xmlparse
446: # due to the global variables that are use, the safe
447: # space etc. I expect this has unforseen issues that
448: # need resolving.
449:
450: $discussion.=&Apache::lonxml::xmlparse('','tex',$discussionitems[$alldiscussion{$_}]);
451: }
452: }
453: }
454: if ($outputtarget ne 'tex') {
455: my $colspan=$maxdepth+1;
456: $discussion .= <<END;
457: <tr bgcolor="#FFFFFF">
458: <td colspan="$colspan" valign="top">
459: <table border="0" bgcolor="#FFFFFF" width="100%" cellspacing="2" cellpadding="2">
460: <tr>
461: <td align="left">
462: <table border="0" cellpadding="0" cellspacing="4">
463: <tr>
464: <td>
465: <font size="-1"><b>$lt{'cuse'}</b>:</td>
466: <td> </td>
467: END
468: if ($newpostsflag) {
469: $discussion .=
470: '<td><font size="-1">1. '.$lt{'disp'}.' - <i>'.$currdisp.'</i> 2. '.$lt{'nolo'}.' - <i>'.$currmark.'</i></font></td>';
471: } else {
472: $discussion .=
473: '<td><font size="-1">'.$lt{'disp'}.' - <i>'.$currdisp.'</i></font></td>';
474: }
475: $discussion .= <<END;
476: <td> </td>
477: <td>
478: <font size="-1"><b><a href="$chglink">$lt{'chgt'}</a>?</font></b></td>
479: </tr>
480: </table>
481: </td>
482: </tr>
483: </table>
484: </td>
485: </tr>
486: </table>
487: <br /><br />
488: END
489: }
490: }
491: if ($discussiononly) {
492: $discussion.=(<<ENDDISCUSS);
493: <form action="/adm/feedback" method="post" name="mailform" enctype="multipart/form-data">
494: <input type="submit" name="discuss" value="Post Discussion" />
495: <input type="submit" name="anondiscuss" value="Post Anonymous Discussion" />
496: <input type="hidden" name="symb" value="$ressymb" />
497: <input type="hidden" name="sendit" value="true" />
498: <br />
499: <font size="1">Note: in anonymous discussion, your name is visible only to
500: course faculty</font><br />
501: <b>Title:</b> <input type="text" name="subject" value="" size="30" /><br /><br />
502: <textarea name="comment" cols="80" rows="14" wrap="hard"></textarea>
503: <p>
504: Attachment (128 KB max size): <input type="file" name="attachment" />
505: </p>
506: </form>
507: ENDDISCUSS
508: if ($outputtarget ne 'tex') {
509: $discussion.=&generate_preview_button();
510: }
511: } else {
512: if (&discussion_open($status) &&
513: &Apache::lonnet::allowed('pch',
514: $ENV{'request.course.id'}.
515: ($ENV{'request.course.sec'}?'/'.$ENV{'request.course.sec'}:''))) {
516: if ($outputtarget ne 'tex') {
517: $discussion.='<table bgcolor="#BBBBBB"><tr><td><a href="/adm/feedback?replydisc='.
518: $symb.':::" '.$target.'>'.
519: '<img src="/adm/lonMisc/chat.gif" border="0" />'.
520: &mt('Post Discussion').'</a></td></tr></table>';
521: }
522: }
523: }
524: return $discussion;
525: }
526:
527: sub mail_screen {
528: my ($r,$feedurl,$options) = @_;
529: my $bodytag=&Apache::loncommon::bodytag('Resource Feedback and Discussion',
530: '','onLoad="window.focus();"');
531: my $title=&Apache::lonnet::gettitle($feedurl);
532: if (!$title) { $title = $feedurl; }
533: my $quote='';
534: my $subject = '';
535: my $prevtag = '';
536: if ($ENV{'form.replydisc'}) {
537: my ($symb,$idx)=split(/\:\:\:/,$ENV{'form.replydisc'});
538: my %contrib=&Apache::lonnet::restore($symb,$ENV{'request.course.id'},
539: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
540: $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
541: unless (($contrib{'hidden'}=~/\.$idx\./) || ($contrib{'deleted'}=~/\.$idx\./)) {
542: my $message=$contrib{$idx.':message'};
543: $message=~s/\n/\<br \/\>/g;
544: $quote='<blockquote>'.&Apache::lontexconvert::msgtexconverted($message).'</blockquote>';
545: if ($idx > 0) {
546: $subject = 'Re: '.$contrib{$idx.':subject'};
547: }
548: }
549: if ($ENV{'form.previous'}) {
550: $prevtag = '<input type="hidden" name="previous" value="'.$ENV{'form.previous'}.'" />';
551: }
552: }
553: my $latexHelp=&Apache::loncommon::helpLatexCheatsheet();
554: my $htmlheader=&Apache::lonhtmlcommon::htmlareaheaders();
555: my $onsubmit='';
556: if ((&Apache::lonhtmlcommon::htmlareabrowser()) &&
557: (!&Apache::lonhtmlcommon::htmlareablocked())) {
558: $onsubmit='document.mailform.onsubmit();';
559: }
560: my $send=&mt('Send');
561: $r->print(<<ENDDOCUMENT);
562: <html>
563: <head>
564: <title>The LearningOnline Network with CAPA</title>
565: <meta http-equiv="pragma" content="no-cache"></meta>
566: $htmlheader
567: <script type="text/javascript">
568: //<!--
569: function gosubmit() {
570: var rec=0;
571: if (typeof(document.mailform.elements.author)!="undefined") {
572: if (document.mailform.elements.author.checked) {
573: rec=1;
574: }
575: }
576: if (typeof(document.mailform.elements.question)!="undefined") {
577: if (document.mailform.elements.question.checked) {
578: rec=1;
579: }
580: }
581: if (typeof(document.mailform.elements.course)!="undefined") {
582: if (document.mailform.elements.course.checked) {
583: rec=1;
584: }
585: }
586: if (typeof(document.mailform.elements.policy)!="undefined") {
587: if (document.mailform.elements.policy.checked) {
588: rec=1;
589: }
590: }
591: if (typeof(document.mailform.elements.discuss)!="undefined") {
592: if (document.mailform.elements.discuss.checked) {
593: rec=1;
594: }
595: }
596: if (typeof(document.mailform.elements.anondiscuss)!="undefined") {
597: if (document.mailform.elements.anondiscuss.checked) {
598: rec=1;
599: }
600: }
601:
602: if (rec) {
603: $onsubmit
604: document.mailform.submit();
605: } else {
606: alert('Please check a feedback type.');
607: }
608: }
609: //-->
610: </script>
611: </head>
612: $bodytag
613: <h2><tt>$title</tt></h2>
614: <form action="/adm/feedback" method="post" name="mailform"
615: enctype="multipart/form-data">
616: $prevtag
617: <input type="hidden" name="postdata" value="$feedurl" />
618: <input type="hidden" name="replydisc" value="$ENV{'form.replydisc'}" />
619: Please check at least one of the following feedback types:
620: $options<hr />
621: $quote
622: <p>My question/comment/feedback:</p>
623: <p>
624: $latexHelp
625: Title: <input type="text" name="subject" size="30" value="$subject" /></p>
626: <p>
627: <textarea name="comment" id="comment" cols="60" rows="10" wrap="hard">
628: </textarea></p>
629: <p>
630: Attachment (128 KB max size): <input type="file" name="attachment" />
631: </p>
632: <p>
633: <input type="hidden" name="sendit" value="1" />
634: <input type="button" value="$send" onClick='gosubmit();' />
635: </p>
636: </form>
637: ENDDOCUMENT
638: $r->print(&generate_preview_button().
639: &Apache::lonhtmlcommon::htmlareaselectactive('comment').
640: '</body></html>');
641: }
642:
643: sub print_display_options {
644: my ($r,$symb,$previous,$dispchg,$markchg,$feedurl) = @_;
645: # backward compatibility (bulletin boards used to be 'wrapped')
646: if ($feedurl=~m|^/adm/wrapper/adm/.*/bulletinboard$|) {
647: $feedurl=~s|^/adm/wrapper||;
648: }
649:
650: my $function = &Apache::loncommon::get_users_function();
651: my $tabcolor = &Apache::loncommon::designparm($function.'.tabbg',
652: $ENV{'user.domain'});
653: my $bodytag=&Apache::loncommon::bodytag('Discussion options',
654: '','');
655:
656: my %lt = &Apache::lonlocal::texthash(
657: 'dido' => 'Discussion display options',
658: 'pref' => 'Display Preference',
659: 'curr' => 'Current setting ',
660: 'actn' => 'Action',
661: 'deff' => 'Default for all discussions',
662: 'prca' => 'Preferences can be set for this discussion that determine ....',
663: 'whpo' => 'Which posts are displayed when you display this bulletin board or resource, and',
664: 'unwh' => 'Under what circumstances posts are identfied as "New."',
665: 'allposts' => 'All posts',
666: 'unread' => 'New posts only',
667: 'ondisp' => 'Once displayed',
668: 'onmark' => 'Once marked as read',
669: 'disa' => 'Posts displayed?',
670: 'npmr' => 'New posts cease to be identified as "New"?',
671: 'chgt' => 'Change to ',
672: 'mkdf' => 'Set to ',
673: 'yhni' => 'You have not indicated that you wish to change either of the discussion settings',
674: 'ywbr' => 'You will be returned to the previous page if you click OK.'
675: );
676:
677: my $dispchange = $lt{'unread'};
678: my $markchange = $lt{'ondisp'};
679: my $currdisp = $lt{'allposts'};
680: my $currmark = $lt{'onmark'};
681: my $discdisp = 'allposts';
682: my $discmark = 'onmark';
683:
684: if ($dispchg eq 'allposts') {
685: $dispchange = $lt{'allposts'};
686: $currdisp = $lt{'unread'};
687: $discdisp = 'unread';
688: }
689:
690: if ($markchg eq 'markonread') {
691: $markchange = $lt{'onmark'};
692: $currmark = $lt{'ondisp'};
693: $discmark = 'ondisp';
694: }
695: $r->print(<<END);
696: <html>
697: <head>
698: <title>$lt{'dido'}</title>
699: <meta http-equiv="pragma" content="no-cache" />
700: <script>
701: function setDisp() {
702: var prev = "$previous"
703: var chktotal = 0
704: if (document.modifydisp.discdisp.checked == true) {
705: document.modifydisp.$dispchg.value = "$symb"
706: chktotal ++
707: }
708: if (document.modifydisp.discmark.checked == true) {
709: document.modifydisp.$markchg.value = "$symb"
710: chktotal ++
711: }
712: if (chktotal > 0) {
713: document.modifydisp.submit()
714: } else {
715: if(confirm("$lt{'yhni'}. \\n$lt{'ywbr'}")) {
716: if (prev > 0) {
717: location.href = "$feedurl?previous=$previous"
718: } else {
719: location.href = "$feedurl"
720: }
721: }
722: }
723: }
724: </script>
725: </head>
726: $bodytag
727: <form name="modifydisp" method="post" action="/adm/feedback">
728: $lt{'sdpf'}<br/> $lt{'prca'} <ol><li>$lt{'whpo'}</li><li>$lt{'unwh'}</li></ol>
729: <br />
730: <table border="0" cellpadding="0" cellspacing="0">
731: <tr>
732: <td width="100%" bgcolor="#000000">
733: <table width="100%" border="0" cellpadding="1" cellspacing="0">
734: <tr>
735: <td width="100%" bgcolor="#000000">
736: <table border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
737: <tr bgcolor="$tabcolor">
738: <td><b>$lt{'pref'}</b></td>
739: <td><b>$lt{'curr'}</b></td>
740: <td><b>$lt{'actn'}?</b></td>
741: </tr>
742: <tr bgcolor="#dddddd">
743: <td>$lt{'disa'}</td>
744: <td>$lt{$discdisp}</td>
745: <td><input type="checkbox" name="discdisp" /> $lt{'chgt'} "$dispchange"</td>
746: </tr><tr bgcolor="#eeeeee">
747: <td>$lt{'npmr'}</td>
748: <td>$lt{$discmark}</td>
749: <td><input type="checkbox" name="discmark" />$lt{'chgt'} "$markchange"</td>
750: </tr>
751: </table>
752: </td>
753: </tr>
754: </table>
755: </td>
756: </tr>
757: </table>
758: <br />
759: <br />
760: <input type="hidden" name="previous" value="$previous" />
761: <input type="hidden" name="$dispchg" value=""/>
762: <input type="hidden" name="$markchg" value=""/>
763: <input type="button" name="sub" value="Store Changes" onClick="javascript:setDisp()" />
764: <br />
765: <br />
766: </form>
767: </body>
768: </html>
769: END
770: return;
771: }
772:
773: sub fail_redirect {
774: my ($r,$feedurl) = @_;
775: if ($feedurl=~/^\/adm\//) { $feedurl.='?register=1' };
776: $r->print (<<ENDFAILREDIR);
777: <html>
778: <head><title>Feedback not sent</title>
779: <meta http-equiv="pragma" content="no-cache" />
780: <meta HTTP-EQUIV="Refresh" CONTENT="2; url=$feedurl" />
781: </head>
782: <body bgcolor="#FFFFFF">
783: <img align="right" src="/adm/lonIcons/lonlogos.gif" />
784: <b>Sorry, no recipients ...</b>
785: </body>
786: </html>
787: ENDFAILREDIR
788: }
789:
790: sub redirect_back {
791: my ($r,$feedurl,$typestyle,$sendsomething,$sendposts,$status,$previous) = @_;
792: my $prevtag = '';
793: my $qrystr = '';
794: # backward compatibility (bulletin boards used to be 'wrapped')
795: if ($feedurl=~m|^/adm/wrapper/adm/.*/bulletinboard$|) {
796: $feedurl=~s|^/adm/wrapper||;
797: }
798:
799: if ($feedurl=~/^\/adm\//) { $feedurl.='?register=1' };
800: if ($previous > 0) {
801: $qrystr = 'previous='.$previous;
802: if ($feedurl =~ /\?register=1/) {
803: $feedurl .= '&'.$qrystr;
804: } else {
805: $feedurl .= '?'.$qrystr;
806: }
807: $prevtag = '<input type="hidden" name="previous" value="'.$previous.'" />';
808: }
809: $r->print (<<ENDREDIR);
810: <html>
811: <head>
812: <title>Feedback sent</title>
813: <meta http-equiv="pragma" content="no-cache" />
814: <meta HTTP-EQUIV="Refresh" CONTENT="2; url=$feedurl" />
815: </head>
816: <body bgcolor="#FFFFFF" onLoad='if (window.name!="loncapaclient") { this.document.reldt.submit(); self.close(); }'>
817: <img align="right" src="/adm/lonIcons/lonlogos.gif" />
818: $typestyle
819: <b>Sent $sendsomething message(s), and $sendposts post(s).</b>
820: <font color="red">$status</font>
821: <form name="reldt" action="$feedurl" target="loncapaclient">
822: $prevtag
823: </form>
824: </body>
825: </html>
826: ENDREDIR
827: }
828:
829: sub no_redirect_back {
830: my ($r,$feedurl) = @_;
831: $r->print (<<ENDNOREDIR);
832: <html>
833: <head><title>Feedback not sent</title>
834: <meta http-equiv="pragma" content="no-cache" />
835: ENDNOREDIR
836:
837: if ($feedurl!~/^\/adm\/feedback/) {
838: $r->print('<meta HTTP-EQUIV="Refresh" CONTENT="2; url='.$feedurl.'">');
839: }
840:
841: $r->print (<<ENDNOREDIRTWO);
842: </head>
843: <body bgcolor="#FFFFFF" onLoad='if (window.name!="loncapaclient") { self.close(); }'>
844: <img align="right" src="/adm/lonIcons/lonlogos.gif" />
845: <b>Sorry, no feedback possible on this resource ...</b>
846: </body>
847: </html>
848: ENDNOREDIRTWO
849: }
850:
851: sub screen_header {
852: my ($feedurl) = @_;
853: my $msgoptions='';
854: my $discussoptions='';
855: unless ($ENV{'form.replydisc'}) {
856: if (($feedurl=~/^\/res\//) && ($feedurl!~/^\/res\/adm/)) {
857: $msgoptions=
858: '<p><input type="checkbox" name="author" /> '.
859: &mt('Feedback to resource author').'</p>';
860: }
861: if (&feedback_available(1)) {
862: $msgoptions.=
863: '<br /><input type="checkbox" name="question" /> '.
864: &mt('Question about resource content');
865: }
866: if (&feedback_available(0,1)) {
867: $msgoptions.=
868: '<br /><input type="checkbox" name="course" /> '.
869: &mt('Question/Comment/Feedback about course content');
870: }
871: if (&feedback_available(0,0,1)) {
872: $msgoptions.=
873: '<br /><input type="checkbox" name="policy" /> '.
874: &mt('Question/Comment/Feedback about course policy');
875: }
876: }
877: if ($ENV{'request.course.id'}) {
878: if (&discussion_open() &&
879: &Apache::lonnet::allowed('pch',
880: $ENV{'request.course.id'}.
881: ($ENV{'request.course.sec'}?'/'.$ENV{'request.course.sec'}:''))) {
882: $discussoptions='<input type="checkbox" name="discuss" onClick="this.form.anondiscuss.checked=false;" '.
883: ($ENV{'form.replydisc'}?' checked="1"':'').' /> '.
884: &mt('Contribution to course discussion of resource');
885: $discussoptions.='<br /><input type="checkbox" name="anondiscuss" onClick="this.form.discuss.checked=false;" /> '.
886: &mt('Anonymous contribution to course discussion of resource').
887: ' <i>('.&mt('name only visible to course faculty').')</i>';
888: }
889: }
890: if ($msgoptions) { $msgoptions='<h2><img src="/adm/lonMisc/feedback.gif" />'.&mt('Sending Messages').'</h2>'.$msgoptions; }
891: if ($discussoptions) {
892: $discussoptions='<h2><img src="/adm/lonMisc/chat.gif" />'.&mt('Discussion Contributions').'</h2>'.$discussoptions; }
893: return $msgoptions.$discussoptions;
894: }
895:
896: sub resource_output {
897: my ($feedurl) = @_;
898: my $usersaw=&Apache::lonnet::ssi_body($feedurl);
899: $usersaw=~s/\<body[^\>]*\>//gi;
900: $usersaw=~s/\<\/body\>//gi;
901: $usersaw=~s/\<html\>//gi;
902: $usersaw=~s/\<\/html\>//gi;
903: $usersaw=~s/\<head\>//gi;
904: $usersaw=~s/\<\/head\>//gi;
905: $usersaw=~s/action\s*\=/would_be_action\=/gi;
906: return $usersaw;
907: }
908:
909: sub clear_out_html {
910: my ($message,$override)=@_;
911: unless (&Apache::lonhtmlcommon::htmlareablocked()) { return $message; }
912: my $cid=$ENV{'request.course.id'};
913: if (($ENV{"course.$cid.allow_limited_html_in_feedback"} =~ m/yes/i) ||
914: ($override)) {
915: # allows <B> <I> <P> <A> <LI> <OL> <UL> <EM> <BR> <TT> <STRONG>
916: # <BLOCKQUOTE> <DIV .*> <DIV> <IMG> <M> <SPAN> <H1> <H2> <H3> <H4> <SUB>
917: # <SUP>
918: my %html=(B=>1, I=>1, P=>1, A=>1, LI=>1, OL=>1, UL=>1, EM=>1,
919: BR=>1, TT=>1, STRONG=>1, BLOCKQUOTE=>1, DIV=>1, IMG=>1,
920: M=>1, SUB=>1, SUP=>1, SPAN=>1,
921: H1=>1, H2=>1, H3=>1, H4=>1, H5=>1);
922:
923: $message =~ s/\<(\/?\s*(\w+)[^\>\<]*)/
924: {($html{uc($2)}&&(length($1)<1000))?"\<$1":"\<$1"}/ge;
925: $message =~ s/(\<?\s*(\w+)[^\<\>]*)\>/
926: {($html{uc($2)}&&(length($1)<1000))?"$1\>":"$1\>"}/ge;
927: } else {
928: $message=~s/\</\<\;/g;
929: $message=~s/\>/\>\;/g;
930: }
931: return $message;
932: }
933:
934: sub assemble_email {
935: my ($feedurl,$message,$prevattempts,$usersaw,$useranswer)=@_;
936: my $email=<<"ENDEMAIL";
937: Refers to <a href="$feedurl">$feedurl</a>
938:
939: $message
940: ENDEMAIL
941: my $citations=<<"ENDCITE";
942: <h2>Previous attempts of student (if applicable)</h2>
943: $prevattempts
944: <br /><hr />
945: <h2>Original screen output (if applicable)</h2>
946: $usersaw
947: <h2>Correct Answer(s) (if applicable)</h2>
948: $useranswer
949: ENDCITE
950: return ($email,$citations);
951: }
952:
953: sub secapply {
954: my $rec=shift;
955: my $defaultflag=shift;
956: $rec=~s/\s+//g;
957: $rec=~s/\@/\:/g;
958: my ($adr,$sections)=($rec=~/^([^\(]+)\(([^\)]+)\)/);
959: if ($sections) {
960: foreach (split(/\;/,$sections)) {
961: if (($_ eq $ENV{'request.course.sec'}) ||
962: ($defaultflag && ($_ eq '*'))) {
963: return $adr;
964: }
965: }
966: } else {
967: return $rec;
968: }
969: return '';
970: }
971:
972: sub decide_receiver {
973: my ($feedurl,$author,$question,$course,$policy,$defaultflag) = @_;
974: my $typestyle='';
975: my %to=();
976: if ($ENV{'form.author'}||$author) {
977: $typestyle.='Submitting as Author Feedback<br>';
978: $feedurl=~/^\/res\/(\w+)\/(\w+)\//;
979: $to{$2.':'.$1}=1;
980: }
981: if ($ENV{'form.question'}||$question) {
982: $typestyle.='Submitting as Question<br>';
983: foreach (split(/\,/,
984: $ENV{'course.'.$ENV{'request.course.id'}.'.question.email'})
985: ) {
986: my $rec=&secapply($_,$defaultflag);
987: if ($rec) { $to{$rec}=1; }
988: }
989: }
990: if ($ENV{'form.course'}||$course) {
991: $typestyle.='Submitting as Comment<br />';
992: foreach (split(/\,/,
993: $ENV{'course.'.$ENV{'request.course.id'}.'.comment.email'})
994: ) {
995: my $rec=&secapply($_,$defaultflag);
996: if ($rec) { $to{$rec}=1; }
997: }
998: }
999: if ($ENV{'form.policy'}||$policy) {
1000: $typestyle.='Submitting as Policy Feedback<br />';
1001: foreach (split(/\,/,
1002: $ENV{'course.'.$ENV{'request.course.id'}.'.policy.email'})
1003: ) {
1004: my $rec=&secapply($_,$defaultflag);
1005: if ($rec) { $to{$rec}=1; }
1006: }
1007: }
1008: if ((scalar(%to) eq '0') && (!$defaultflag)) {
1009: ($typestyle,%to)=
1010: &decide_receiver($feedurl,$author,$question,$course,$policy,1);
1011: }
1012: return ($typestyle,%to);
1013: }
1014:
1015: sub feedback_available {
1016: my ($question,$course,$policy)=@_;
1017: my ($typestyle,%to)=&decide_receiver('',0,$question,$course,$policy);
1018: return scalar(%to);
1019: }
1020:
1021: sub send_msg {
1022: my ($feedurl,$email,$citations,$attachmenturl,%to)=@_;
1023: my $status='';
1024: my $sendsomething=0;
1025: foreach (keys %to) {
1026: if ($_) {
1027: my $declutter=&Apache::lonnet::declutter($feedurl);
1028: unless (&Apache::lonmsg::user_normal_msg(split(/\:/,$_),
1029: 'Feedback ['.$declutter.']',$email,$citations,$feedurl,
1030: $attachmenturl)=~/ok/) {
1031: $status.='<br />'.&mt('Error sending message to').' '.$_.'<br />';
1032: } else {
1033: $sendsomething++;
1034: }
1035: }
1036: }
1037:
1038: my %record=&Apache::lonnet::restore('_feedback');
1039: my ($temp)=keys %record;
1040: unless ($temp=~/^error\:/) {
1041: my %newrecord=();
1042: $newrecord{'resource'}=$feedurl;
1043: $newrecord{'subnumber'}=$record{'subnumber'}+1;
1044: unless (&Apache::lonnet::cstore(\%newrecord,'_feedback') eq 'ok') {
1045: $status.='<br />'.&mt('Not registered').'<br />';
1046: }
1047: }
1048:
1049: return ($status,$sendsomething);
1050: }
1051:
1052: sub adddiscuss {
1053: my ($symb,$email,$anon,$attachmenturl,$subject)=@_;
1054: my $status='';
1055: if (&discussion_open() &&
1056: &Apache::lonnet::allowed('pch',$ENV{'request.course.id'}.
1057: ($ENV{'request.course.sec'}?'/'.$ENV{'request.course.sec'}:''))) {
1058:
1059: my %contrib=('message' => $email,
1060: 'sendername' => $ENV{'user.name'},
1061: 'senderdomain' => $ENV{'user.domain'},
1062: 'screenname' => $ENV{'environment.screenname'},
1063: 'plainname' => $ENV{'environment.firstname'}.' '.
1064: $ENV{'environment.middlename'}.' '.
1065: $ENV{'environment.lastname'}.' '.
1066: $ENV{'enrironment.generation'},
1067: 'attachmenturl'=> $attachmenturl,
1068: 'subject' => $subject);
1069: if ($ENV{'form.replydisc'}) {
1070: $contrib{'replyto'}=(split(/\:\:\:/,$ENV{'form.replydisc'}))[1];
1071: }
1072: if ($anon) {
1073: $contrib{'anonymous'}='true';
1074: }
1075: if (($symb) && ($email)) {
1076: $status='Adding to class discussion'.($anon?' (anonymous)':'').': '.
1077: &Apache::lonnet::store(\%contrib,$symb,$ENV{'request.course.id'},
1078: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
1079: $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
1080: my %storenewentry=($symb => time);
1081: $status.='<br />'.&mt('Updating discussion time').': '.
1082: &Apache::lonnet::put('discussiontimes',\%storenewentry,
1083: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
1084: $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
1085: }
1086: my %record=&Apache::lonnet::restore('_discussion');
1087: my ($temp)=keys %record;
1088: unless ($temp=~/^error\:/) {
1089: my %newrecord=();
1090: $newrecord{'resource'}=$symb;
1091: $newrecord{'subnumber'}=$record{'subnumber'}+1;
1092: $status.='<br />'.&mt('Registering').': '.
1093: &Apache::lonnet::cstore(\%newrecord,'_discussion');
1094: }
1095: } else {
1096: $status.='Failed.';
1097: }
1098: return $status.'<br />';
1099: }
1100:
1101: # ----------------------------------------------------------- Preview function
1102:
1103: sub show_preview {
1104: my $r=shift;
1105: my $message=&clear_out_html($ENV{'form.comment'});
1106: $message=~s/\n/\<br \/\>/g;
1107: $message=&Apache::lontexconvert::msgtexconverted($message);
1108: my $subject=&clear_out_html($ENV{'form.subject'});
1109: $subject=~s/\n/\<br \/\>/g;
1110: $subject=&Apache::lontexconvert::msgtexconverted($subject);
1111: $r->print('<table border="2"><tr><td>'.
1112: '<b>Subject:</b> '.$subject.'<br /><br />'.
1113: $message.'</td></tr></table>');
1114: }
1115:
1116: sub generate_preview_button {
1117: my $pre=&mt("Show Preview");
1118: return(<<ENDPREVIEW);
1119: <form name="preview" action="/adm/feedback?preview=1" method="post" target="preview">
1120: <input type="hidden" name="subject">
1121: <input type="hidden" name="comment" />
1122: <input type="button" value="$pre"
1123: onClick="document.mailform.onsubmit();this.form.comment.value=document.mailform.comment.value;this.form.subject.value=document.mailform.subject.value;this.form.submit();" />
1124: </form>
1125: ENDPREVIEW
1126: }
1127:
1128: sub handler {
1129: my $r = shift;
1130: if ($r->header_only) {
1131: &Apache::loncommon::content_type($r,'text/html');
1132: $r->send_http_header;
1133: return OK;
1134: }
1135:
1136: # --------------------------- Get query string for limited number of parameters
1137:
1138: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1139: ['hide','unhide','deldisc','postdata','preview','replydisc','threadedon','threadedoff','onlyunread','allposts','previous','markread','markonread','markondisp','modifydisp','changes']);
1140: if ($ENV{'form.modifydisp'}) {
1141: &Apache::loncommon::content_type($r,'text/html');
1142: $r->send_http_header;
1143: my $symb=$ENV{'form.modifydisp'};
1144: my ($map,$ind,$url)=&Apache::lonnet::decode_symb($symb);
1145: my $previous=$ENV{'form.previous'};
1146: my ($dispchg,$markchg) = split/_/,$ENV{'form.changes'};
1147: my $feedurl = &Apache::lonnet::clutter($url);
1148: # backward compatibility (bulletin boards used to be 'wrapped')
1149: if ($feedurl=~m|^/adm/wrapper/adm/.*/bulletinboard$|) {
1150: $feedurl=~s|^/adm/wrapper||;
1151: }
1152: &print_display_options($r,$symb,$previous,$dispchg,$markchg,$feedurl);
1153: return OK;
1154: } elsif (($ENV{'form.markondisp'}) || ($ENV{'form.markonread'}) || ($ENV{'form.allposts'}) || ($ENV{'form.onlyunread'}) ) {
1155: &Apache::loncommon::content_type($r,'text/html');
1156: $r->send_http_header;
1157: my $previous=$ENV{'form.previous'};
1158: my ($map,$ind,$url);
1159: if (($ENV{'form.markondisp'}) || ($ENV{'form.markonread'})) {
1160: # ---------------------- Modify setting for identification of 'NEW' posts in this discussion
1161: my $symb=$ENV{'form.markondisp'}?$ENV{'form.markondisp'}:$ENV{'form.markonread'};
1162: my $ressymb = $symb;
1163: ($map,$ind,$url)=&Apache::lonnet::decode_symb($symb);
1164: unless ($ressymb =~ m|bulletin___\d+___adm/wrapper|) {
1165: $ressymb=~s|(bulletin___\d+___)|$1adm/wrapper|;
1166: }
1167: my %discinfo = ();
1168: my $lastkey = $ressymb.'_lastread';
1169: my $ondispkey = $ressymb.'_markondisp';
1170: if ($ENV{'form.markondisp'}) {
1171: $discinfo{$lastkey} = time;
1172: $discinfo{$ondispkey} = 1;
1173: } elsif ($ENV{'form.markonread'}) {
1174: if ( $previous > 0 ) {
1175: $discinfo{$lastkey} = $previous;
1176: }
1177: $discinfo{$ondispkey} = 0;
1178: }
1179: &Apache::lonnet::put('nohist_'.$ENV{'request.course.id'}.'_discuss',\%discinfo,$ENV{'user.domain'},$ENV{'user.name'});
1180: }
1181: if (($ENV{'form.allposts'}) || ($ENV{'form.onlyunread'})) {
1182: # ----------------------------------------------------------------- Modify display setting for this discussion
1183: my $symb=$ENV{'form.allposts'}?$ENV{'form.allposts'}:$ENV{'form.onlyunread'};
1184: my $ressymb = $symb;
1185: ($map,$ind,$url)=&Apache::lonnet::decode_symb($symb);
1186: unless ($ressymb =~ m|bulletin___\d+___adm/wrapper|) {
1187: $ressymb=~s|(bulletin___\d+___)|$1adm/wrapper|;
1188: }
1189: my %discinfo = ();
1190: if ($ENV{'form.allposts'}) {
1191: $discinfo{$ressymb.'_showonlyunread'} = 0;
1192: } elsif ($ENV{'form.onlyunread'}) {
1193: $discinfo{$ressymb.'_showonlyunread'} = 1;
1194: }
1195: &Apache::lonnet::put('nohist_'.$ENV{'request.course.id'}.'_discuss',\%discinfo,$ENV{'user.domain'},$ENV{'user.name'});
1196: }
1197: if (($ENV{'form.markonread'}) || ($ENV{'form.allposts'}) || ($ENV{'form.onlyunread'}) ) {
1198: &redirect_back($r,&Apache::lonnet::clutter($url),&mt('Changed display status').'<br />','0','0','',$previous);
1199: } else {
1200: &redirect_back($r,&Apache::lonnet::clutter($url),&mt('Changed display status').'<br />','0','0');
1201: }
1202: return OK;
1203: } elsif ($ENV{'form.markread'}) {
1204: # ----------------------------------------------------------------- Mark new posts as read
1205: &Apache::loncommon::content_type($r,'text/html');
1206: $r->send_http_header;
1207: my $symb=$ENV{'form.markread'};
1208: my $ressymb = $symb;
1209: my ($map,$ind,$url)=&Apache::lonnet::decode_symb($symb);
1210: unless ($ressymb =~ m|bulletin___\d+___adm/wrapper|) {
1211: $ressymb=~s|(bulletin___\d+___)|$1adm/wrapper|;
1212: }
1213: my %discinfo = ();
1214: my $lastkey = $ressymb.'_lastread';
1215: $discinfo{$lastkey} = time;
1216: &Apache::lonnet::put('nohist_'.$ENV{'request.course.id'}.'_discuss',\%discinfo,$ENV{'user.domain'},$ENV{'user.name'});
1217: &redirect_back($r,&Apache::lonnet::clutter($url),&mt('Changed reading status').'<br />','0','0');
1218: return OK;
1219: } elsif (($ENV{'form.hide'}) || ($ENV{'form.unhide'})) {
1220: # ----------------------------------------------------------------- Hide/unhide
1221: &Apache::loncommon::content_type($r,'text/html');
1222: $r->send_http_header;
1223:
1224: my $entry=$ENV{'form.hide'}?$ENV{'form.hide'}:$ENV{'form.unhide'};
1225:
1226: my ($symb,$idx)=split(/\:\:\:/,$entry);
1227: my ($map,$ind,$url)=&Apache::lonnet::decode_symb($symb);
1228:
1229: my %contrib=&Apache::lonnet::restore($symb,$ENV{'request.course.id'},
1230: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
1231: $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
1232:
1233:
1234: my $currenthidden=$contrib{'hidden'};
1235:
1236: if ($ENV{'form.hide'}) {
1237: $currenthidden.='.'.$idx.'.';
1238: } else {
1239: $currenthidden=~s/\.$idx\.//g;
1240: }
1241: my %newhash=('hidden' => $currenthidden);
1242:
1243: &Apache::lonnet::store(\%newhash,$symb,$ENV{'request.course.id'},
1244: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
1245: $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
1246:
1247: &redirect_back($r,&Apache::lonnet::clutter($url),
1248: &mt('Changed discussion status').'<br />','0','0','',$ENV{'form.previous'});
1249: } elsif (($ENV{'form.threadedon'}) || ($ENV{'form.threadedoff'})) {
1250: &Apache::loncommon::content_type($r,'text/html');
1251: $r->send_http_header;
1252: if ($ENV{'form.threadedon'}) {
1253: &Apache::lonnet::put('environment',{'threadeddiscussion' => 'on'});
1254: &Apache::lonnet::appenv('environment.threadeddiscussion' => 'on');
1255: } else {
1256: &Apache::lonnet::del('environment',['threadeddiscussion']);
1257: &Apache::lonnet::delenv('environment\.threadeddiscussion');
1258: }
1259: my $symb=$ENV{'form.threadedon'}?$ENV{'form.threadedon'}:$ENV{'form.threadedoff'};
1260: my ($map,$ind,$url)=&Apache::lonnet::decode_symb($symb);
1261: &redirect_back($r,&Apache::lonnet::clutter($url),
1262: &mt('Changed discussion view mode').'<br />','0','0','',$ENV{'form.previous'});
1263: } elsif ($ENV{'form.deldisc'}) {
1264: # --------------------------------------------------------------- Hide for good
1265: &Apache::loncommon::content_type($r,'text/html');
1266: $r->send_http_header;
1267:
1268: my $entry=$ENV{'form.deldisc'};
1269:
1270: my ($symb,$idx)=split(/\:\:\:/,$entry);
1271: my ($map,$ind,$url)=&Apache::lonnet::decode_symb($symb);
1272:
1273: my %contrib=&Apache::lonnet::restore($symb,$ENV{'request.course.id'},
1274: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
1275: $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
1276:
1277:
1278: my $currentdeleted=$contrib{'deleted'};
1279:
1280: $currentdeleted.='.'.$idx.'.';
1281:
1282: my %newhash=('deleted' => $currentdeleted);
1283:
1284: &Apache::lonnet::store(\%newhash,$symb,$ENV{'request.course.id'},
1285: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
1286: $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
1287:
1288: &redirect_back($r,&Apache::lonnet::clutter($url),
1289: &mt('Changed discussion status').'<br />','0','0','',$ENV{'form.previous'});
1290: } elsif ($ENV{'form.preview'}) {
1291: # -------------------------------------------------------- User wants a preview
1292: $r->content_type('text/html');
1293: $r->send_http_header;
1294: &show_preview($r);
1295: } else {
1296: # ------------------------------------------------------------- Normal feedback
1297: my $feedurl=$ENV{'form.postdata'};
1298: $feedurl=~s/^http\:\/\///;
1299: $feedurl=~s/^$ENV{'SERVER_NAME'}//;
1300: $feedurl=~s/^$ENV{'HTTP_HOST'}//;
1301: $feedurl=~s/\?.+$//;
1302:
1303: my $symb;
1304: if ($ENV{'form.replydisc'}) {
1305: $symb=(split(/\:\:\:/,$ENV{'form.replydisc'}))[0];
1306: my ($map,$id,$url)=&Apache::lonnet::decode_symb($symb);
1307: $feedurl=&Apache::lonnet::clutter($url);
1308: } else {
1309: $symb=&Apache::lonnet::symbread($feedurl);
1310: }
1311: unless ($symb) {
1312: $symb=$ENV{'form.symb'};
1313: if ($symb) {
1314: my ($map,$id,$url)=&Apache::lonnet::decode_symb($symb);
1315: $feedurl=&Apache::lonnet::clutter($url);
1316: }
1317: }
1318: my $goahead=1;
1319: if ($feedurl=~/\.(problem|exam|quiz|assess|survey|form)$/) {
1320: unless ($symb) { $goahead=0; }
1321: }
1322: # backward compatibility (bulletin boards used to be 'wrapped')
1323: if ($feedurl=~m|^/adm/wrapper/adm/.*/bulletinboard$|) {
1324: $feedurl=~s|^/adm/wrapper||;
1325: }
1326: if ($goahead) {
1327: # Go ahead with feedback, no ambiguous reference
1328: &Apache::loncommon::content_type($r,'text/html');
1329: $r->send_http_header;
1330:
1331: if (
1332: (
1333: ($feedurl=~m:^/res:) && ($feedurl!~m:^/res/adm:)
1334: )
1335: ||
1336: ($ENV{'request.course.id'} && ($feedurl!~m:^/adm:))
1337: ||
1338: ($ENV{'request.course.id'} && ($symb=~/^bulletin\_\_\_/))
1339: ) {
1340: # --------------------------------------------------- Print login screen header
1341: unless ($ENV{'form.sendit'}) {
1342: my $options=&screen_header($feedurl);
1343: if ($options) {
1344: &mail_screen($r,$feedurl,$options);
1345: } else {
1346: &fail_redirect($r,$feedurl);
1347: }
1348: } else {
1349:
1350: # Get previous user input
1351: my $prevattempts=&Apache::loncommon::get_previous_attempt(
1352: $symb,$ENV{'user.name'},$ENV{'user.domain'},
1353: $ENV{'request.course.id'});
1354:
1355: # Get output from resource
1356: my $usersaw=&resource_output($feedurl);
1357:
1358: # Get resource answer (need to allow student to view grades for this to work)
1359: &Apache::lonnet::appenv(('allowed.vgr'=>'F'));
1360: my $useranswer=&Apache::loncommon::get_student_answers(
1361: $symb,$ENV{'user.name'},$ENV{'user.domain'},
1362: $ENV{'request.course.id'});
1363: &Apache::lonnet::delenv('allowed.vgr');
1364: # Get attachments, if any, and not too large
1365: my $attachmenturl='';
1366: if ($ENV{'form.attachment.filename'}) {
1367: unless (length($ENV{'form.attachment'})>131072) {
1368: $attachmenturl=&Apache::lonnet::userfileupload('attachment',undef,'feedback');
1369: }
1370: }
1371: # Filter HTML out of message (could be nasty)
1372: my $message=&clear_out_html($ENV{'form.comment'});
1373:
1374: # Assemble email
1375: my ($email,$citations)=&assemble_email($feedurl,$message,$prevattempts,
1376: $usersaw,$useranswer);
1377:
1378: # Who gets this?
1379: my ($typestyle,%to) = &decide_receiver($feedurl);
1380:
1381: # Actually send mail
1382: my ($status,$numsent)=&send_msg($feedurl,$email,$citations,
1383: $attachmenturl,%to);
1384:
1385: # Discussion? Store that.
1386:
1387: my $numpost=0;
1388: if ($ENV{'form.discuss'}) {
1389: my $subject = &clear_out_html($ENV{'form.subject'});
1390: $typestyle.=&adddiscuss($symb,$message,0,$attachmenturl,$subject);
1391: $numpost++;
1392: }
1393:
1394: if ($ENV{'form.anondiscuss'}) {
1395: my $subject = &clear_out_html($ENV{'form.subject'});
1396: $typestyle.=&adddiscuss($symb,$message,1,$attachmenturl,$subject);
1397: $numpost++;
1398: }
1399:
1400:
1401: # Receipt screen and redirect back to where came from
1402: &redirect_back($r,$feedurl,$typestyle,$numsent,$numpost,$status,$ENV{'form.previous'});
1403:
1404: }
1405: } else {
1406: # Unable to give feedback
1407: &no_redirect_back($r,$feedurl);
1408: }
1409: } else {
1410: # Ambiguous Problem Resource
1411: if ( &Apache::lonnet::mod_perl_version() == 2 ) {
1412: &Apache::lonnet::cleanenv();
1413: }
1414: $r->internal_redirect('/adm/ambiguous');
1415: }
1416: }
1417: return OK;
1418: }
1419:
1420: 1;
1421: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>