File:
[LON-CAPA] /
loncom /
interface /
lonfeedback.pm
Revision
1.97:
download - view:
text,
annotated -
select for diffs
Sun Jul 4 23:56:58 2004 UTC (20 years ago) by
raeburn
Branches:
MAIN
CVS tags:
HEAD
Bug 3091 fixes.
Discussion settings now appear after posts, and made more succinct. Change link goes to another page, where choices can be made.
Not implemented: (a) filtering using ENV{'user.adv'} to disable these options for students - I actually think students might find these options useful rather than confusing. (b) Code to allow user to make any changes also the default option (PREF) - will add this tomorrow.
Work still needed: (a) modify code that builds display when target is 'tex'
1: # The LearningOnline Network
2: # Feedback
3: #
4: # $Id: lonfeedback.pm,v 1.97 2004/07/04 23:56:58 raeburn Exp $
5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
28: ###
29:
30: package Apache::lonfeedback;
31:
32: use strict;
33: use Apache::Constants qw(:common);
34: use Apache::lonmsg();
35: use Apache::loncommon();
36: use Apache::lontexconvert();
37: use Apache::lonlocal; # must not have ()
38: use Apache::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: my $function = &Apache::loncommon::get_users_function();
646: my $tabcolor = &Apache::loncommon::designparm($function.'.tabbg',
647: $ENV{'user.domain'});
648: my $bodytag=&Apache::loncommon::bodytag('Discussion options',
649: '','');
650:
651: my %lt = &Apache::lonlocal::texthash(
652: 'dido' => 'Discussion display options',
653: 'pref' => 'Display Preference',
654: 'curr' => 'Current setting ',
655: 'actn' => 'Action',
656: 'deff' => 'Default for all discussions',
657: 'prca' => 'Preferences can be set for this discussion that determine ....',
658: 'whpo' => 'Which posts are displayed when you display this bulletin board or resource, and',
659: 'unwh' => 'Under what circumstances posts are identfied as "New."',
660: 'allposts' => 'All posts',
661: 'unread' => 'New posts only',
662: 'ondisp' => 'Once displayed',
663: 'onmark' => 'Once marked as read',
664: 'disa' => 'Posts displayed?',
665: 'npmr' => 'New posts cease to be identified as "New"?',
666: 'chgt' => 'Change to ',
667: 'mkdf' => 'Set to ',
668: 'yhni' => 'You have not indicated that you wish to change either of the discussion settings',
669: 'ywbr' => 'You will be returned to the previous page if you click OK.'
670: );
671:
672: my $dispchange = $lt{'unread'};
673: my $markchange = $lt{'ondisp'};
674: my $currdisp = $lt{'allposts'};
675: my $currmark = $lt{'onmark'};
676: my $discdisp = 'allposts';
677: my $discmark = 'onmark';
678:
679: if ($dispchg eq 'allposts') {
680: $dispchange = $lt{'allposts'};
681: $currdisp = $lt{'unread'};
682: $discdisp = 'unread';
683: }
684:
685: if ($markchg eq 'markonread') {
686: $markchange = $lt{'onmark'};
687: $currmark = $lt{'ondisp'};
688: $discmark = 'ondisp';
689: }
690: $r->print(<<END);
691: <html>
692: <head>
693: <title>$lt{'dido'}</title>
694: <meta http-equiv="pragma" content="no-cache" />
695: <script>
696: function setDisp() {
697: var prev = "$previous"
698: var chktotal = 0
699: if (document.modifydisp.discdisp.checked == true) {
700: document.modifydisp.$dispchg.value = "$symb"
701: chktotal ++
702: }
703: if (document.modifydisp.discmark.checked == true) {
704: document.modifydisp.$markchg.value = "$symb"
705: chktotal ++
706: }
707: if (chktotal > 0) {
708: document.modifydisp.submit()
709: } else {
710: if(confirm("$lt{'yhni'}. \\n$lt{'ywbr'}")) {
711: if (prev > 0) {
712: location.href = "$feedurl?previous=$previous"
713: } else {
714: location.href = "$feedurl"
715: }
716: }
717: }
718: }
719: </script>
720: </head>
721: $bodytag
722: <form name="modifydisp" method="post" action="/adm/feedback">
723: $lt{'sdpf'}<br/> $lt{'prca'} <ol><li>$lt{'whpo'}</li><li>$lt{'unwh'}</li></ol>
724: <br />
725: <table border="0" cellpadding="0" cellspacing="0">
726: <tr>
727: <td width="100%" bgcolor="#000000">
728: <table width="100%" border="0" cellpadding="1" cellspacing="0">
729: <tr>
730: <td width="100%" bgcolor="#000000">
731: <table border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
732: <tr bgcolor="$tabcolor">
733: <td><b>$lt{'pref'}</b></td>
734: <td><b>$lt{'curr'}</b></td>
735: <td><b>$lt{'actn'}?</b></td>
736: </tr>
737: <tr bgcolor="#dddddd">
738: <td>$lt{'disa'}</td>
739: <td>$lt{$discdisp}</td>
740: <td><input type="checkbox" name="discdisp" /> $lt{'chgt'} "$dispchange"</td>
741: </tr><tr bgcolor="#eeeeee">
742: <td>$lt{'npmr'}</td>
743: <td>$lt{$discmark}</td>
744: <td><input type="checkbox" name="discmark" />$lt{'chgt'} "$markchange"</td>
745: </tr>
746: </table>
747: </td>
748: </tr>
749: </table>
750: </td>
751: </tr>
752: </table>
753: <br />
754: <br />
755: <input type="hidden" name="previous" value="$previous" />
756: <input type="hidden" name="$dispchg" value=""/>
757: <input type="hidden" name="$markchg" value=""/>
758: <input type="button" name="sub" value="Store Changes" onClick="javascript:setDisp()" />
759: <br />
760: <br />
761: </form>
762: </body>
763: </html>
764: END
765: return;
766: }
767:
768: sub fail_redirect {
769: my ($r,$feedurl) = @_;
770: if ($feedurl=~/^\/adm\//) { $feedurl.='?register=1' };
771: $r->print (<<ENDFAILREDIR);
772: <html>
773: <head><title>Feedback not sent</title>
774: <meta http-equiv="pragma" content="no-cache" />
775: <meta HTTP-EQUIV="Refresh" CONTENT="2; url=$feedurl" />
776: </head>
777: <body bgcolor="#FFFFFF">
778: <img align="right" src="/adm/lonIcons/lonlogos.gif" />
779: <b>Sorry, no recipients ...</b>
780: </body>
781: </html>
782: ENDFAILREDIR
783: }
784:
785: sub redirect_back {
786: my ($r,$feedurl,$typestyle,$sendsomething,$sendposts,$status,$previous) = @_;
787: my $prevtag = '';
788: my $qrystr = '';
789: if ($feedurl=~/^\/adm\//) { $feedurl.='?register=1' };
790: if ($previous > 0) {
791: $qrystr = 'previous='.$previous;
792: if ($feedurl =~ /\?register=1/) {
793: $feedurl .= '&'.$qrystr;
794: } else {
795: $feedurl .= '?'.$qrystr;
796: }
797: $prevtag = '<input type="hidden" name="previous" value="'.$previous.'" />';
798: }
799: $r->print (<<ENDREDIR);
800: <html>
801: <head>
802: <title>Feedback sent</title>
803: <meta http-equiv="pragma" content="no-cache" />
804: <meta HTTP-EQUIV="Refresh" CONTENT="2; url=$feedurl" />
805: </head>
806: <body bgcolor="#FFFFFF" onLoad='if (window.name!="loncapaclient") { this.document.reldt.submit(); self.close(); }'>
807: <img align="right" src="/adm/lonIcons/lonlogos.gif" />
808: $typestyle
809: <b>Sent $sendsomething message(s), and $sendposts post(s).</b>
810: <font color="red">$status</font>
811: <form name="reldt" action="$feedurl" target="loncapaclient">
812: $prevtag
813: </form>
814: </body>
815: </html>
816: ENDREDIR
817: }
818:
819: sub no_redirect_back {
820: my ($r,$feedurl) = @_;
821: $r->print (<<ENDNOREDIR);
822: <html>
823: <head><title>Feedback not sent</title>
824: <meta http-equiv="pragma" content="no-cache" />
825: ENDNOREDIR
826:
827: if ($feedurl!~/^\/adm\/feedback/) {
828: $r->print('<meta HTTP-EQUIV="Refresh" CONTENT="2; url='.$feedurl.'">');
829: }
830:
831: $r->print (<<ENDNOREDIRTWO);
832: </head>
833: <body bgcolor="#FFFFFF" onLoad='if (window.name!="loncapaclient") { self.close(); }'>
834: <img align="right" src="/adm/lonIcons/lonlogos.gif" />
835: <b>Sorry, no feedback possible on this resource ...</b>
836: </body>
837: </html>
838: ENDNOREDIRTWO
839: }
840:
841: sub screen_header {
842: my ($feedurl) = @_;
843: my $msgoptions='';
844: my $discussoptions='';
845: unless ($ENV{'form.replydisc'}) {
846: if (($feedurl=~/^\/res\//) && ($feedurl!~/^\/res\/adm/)) {
847: $msgoptions=
848: '<p><input type="checkbox" name="author" /> '.
849: &mt('Feedback to resource author').'</p>';
850: }
851: if (&feedback_available(1)) {
852: $msgoptions.=
853: '<br /><input type="checkbox" name="question" /> '.
854: &mt('Question about resource content');
855: }
856: if (&feedback_available(0,1)) {
857: $msgoptions.=
858: '<br /><input type="checkbox" name="course" /> '.
859: &mt('Question/Comment/Feedback about course content');
860: }
861: if (&feedback_available(0,0,1)) {
862: $msgoptions.=
863: '<br /><input type="checkbox" name="policy" /> '.
864: &mt('Question/Comment/Feedback about course policy');
865: }
866: }
867: if ($ENV{'request.course.id'}) {
868: if (&discussion_open() &&
869: &Apache::lonnet::allowed('pch',
870: $ENV{'request.course.id'}.
871: ($ENV{'request.course.sec'}?'/'.$ENV{'request.course.sec'}:''))) {
872: $discussoptions='<input type="checkbox" name="discuss" onClick="this.form.anondiscuss.checked=false;" '.
873: ($ENV{'form.replydisc'}?' checked="1"':'').' /> '.
874: &mt('Contribution to course discussion of resource');
875: $discussoptions.='<br /><input type="checkbox" name="anondiscuss" onClick="this.form.discuss.checked=false;" /> '.
876: &mt('Anonymous contribution to course discussion of resource').
877: ' <i>('.&mt('name only visible to course faculty').')</i>';
878: }
879: }
880: if ($msgoptions) { $msgoptions='<h2><img src="/adm/lonMisc/feedback.gif" />'.&mt('Sending Messages').'</h2>'.$msgoptions; }
881: if ($discussoptions) {
882: $discussoptions='<h2><img src="/adm/lonMisc/chat.gif" />'.&mt('Discussion Contributions').'</h2>'.$discussoptions; }
883: return $msgoptions.$discussoptions;
884: }
885:
886: sub resource_output {
887: my ($feedurl) = @_;
888: my $usersaw=&Apache::lonnet::ssi_body($feedurl);
889: $usersaw=~s/\<body[^\>]*\>//gi;
890: $usersaw=~s/\<\/body\>//gi;
891: $usersaw=~s/\<html\>//gi;
892: $usersaw=~s/\<\/html\>//gi;
893: $usersaw=~s/\<head\>//gi;
894: $usersaw=~s/\<\/head\>//gi;
895: $usersaw=~s/action\s*\=/would_be_action\=/gi;
896: return $usersaw;
897: }
898:
899: sub clear_out_html {
900: my ($message,$override)=@_;
901: unless (&Apache::lonhtmlcommon::htmlareablocked()) { return $message; }
902: my $cid=$ENV{'request.course.id'};
903: if (($ENV{"course.$cid.allow_limited_html_in_feedback"} =~ m/yes/i) ||
904: ($override)) {
905: # allows <B> <I> <P> <A> <LI> <OL> <UL> <EM> <BR> <TT> <STRONG>
906: # <BLOCKQUOTE> <DIV .*> <DIV> <IMG> <M> <SPAN> <H1> <H2> <H3> <H4> <SUB>
907: # <SUP>
908: my %html=(B=>1, I=>1, P=>1, A=>1, LI=>1, OL=>1, UL=>1, EM=>1,
909: BR=>1, TT=>1, STRONG=>1, BLOCKQUOTE=>1, DIV=>1, IMG=>1,
910: M=>1, SUB=>1, SUP=>1, SPAN=>1,
911: H1=>1, H2=>1, H3=>1, H4=>1, H5=>1);
912:
913: $message =~ s/\<(\/?\s*(\w+)[^\>\<]*)/
914: {($html{uc($2)}&&(length($1)<1000))?"\<$1":"\<$1"}/ge;
915: $message =~ s/(\<?\s*(\w+)[^\<\>]*)\>/
916: {($html{uc($2)}&&(length($1)<1000))?"$1\>":"$1\>"}/ge;
917: } else {
918: $message=~s/\</\<\;/g;
919: $message=~s/\>/\>\;/g;
920: }
921: return $message;
922: }
923:
924: sub assemble_email {
925: my ($feedurl,$message,$prevattempts,$usersaw,$useranswer)=@_;
926: my $email=<<"ENDEMAIL";
927: Refers to <a href="$feedurl">$feedurl</a>
928:
929: $message
930: ENDEMAIL
931: my $citations=<<"ENDCITE";
932: <h2>Previous attempts of student (if applicable)</h2>
933: $prevattempts
934: <br /><hr />
935: <h2>Original screen output (if applicable)</h2>
936: $usersaw
937: <h2>Correct Answer(s) (if applicable)</h2>
938: $useranswer
939: ENDCITE
940: return ($email,$citations);
941: }
942:
943: sub secapply {
944: my $rec=shift;
945: my $defaultflag=shift;
946: $rec=~s/\s+//g;
947: $rec=~s/\@/\:/g;
948: my ($adr,$sections)=($rec=~/^([^\(]+)\(([^\)]+)\)/);
949: if ($sections) {
950: foreach (split(/\;/,$sections)) {
951: if (($_ eq $ENV{'request.course.sec'}) ||
952: ($defaultflag && ($_ eq '*'))) {
953: return $adr;
954: }
955: }
956: } else {
957: return $rec;
958: }
959: return '';
960: }
961:
962: sub decide_receiver {
963: my ($feedurl,$author,$question,$course,$policy,$defaultflag) = @_;
964: my $typestyle='';
965: my %to=();
966: if ($ENV{'form.author'}||$author) {
967: $typestyle.='Submitting as Author Feedback<br>';
968: $feedurl=~/^\/res\/(\w+)\/(\w+)\//;
969: $to{$2.':'.$1}=1;
970: }
971: if ($ENV{'form.question'}||$question) {
972: $typestyle.='Submitting as Question<br>';
973: foreach (split(/\,/,
974: $ENV{'course.'.$ENV{'request.course.id'}.'.question.email'})
975: ) {
976: my $rec=&secapply($_,$defaultflag);
977: if ($rec) { $to{$rec}=1; }
978: }
979: }
980: if ($ENV{'form.course'}||$course) {
981: $typestyle.='Submitting as Comment<br />';
982: foreach (split(/\,/,
983: $ENV{'course.'.$ENV{'request.course.id'}.'.comment.email'})
984: ) {
985: my $rec=&secapply($_,$defaultflag);
986: if ($rec) { $to{$rec}=1; }
987: }
988: }
989: if ($ENV{'form.policy'}||$policy) {
990: $typestyle.='Submitting as Policy Feedback<br />';
991: foreach (split(/\,/,
992: $ENV{'course.'.$ENV{'request.course.id'}.'.policy.email'})
993: ) {
994: my $rec=&secapply($_,$defaultflag);
995: if ($rec) { $to{$rec}=1; }
996: }
997: }
998: if ((scalar(%to) eq '0') && (!$defaultflag)) {
999: ($typestyle,%to)=
1000: &decide_receiver($feedurl,$author,$question,$course,$policy,1);
1001: }
1002: return ($typestyle,%to);
1003: }
1004:
1005: sub feedback_available {
1006: my ($question,$course,$policy)=@_;
1007: my ($typestyle,%to)=&decide_receiver('',0,$question,$course,$policy);
1008: return scalar(%to);
1009: }
1010:
1011: sub send_msg {
1012: my ($feedurl,$email,$citations,$attachmenturl,%to)=@_;
1013: my $status='';
1014: my $sendsomething=0;
1015: foreach (keys %to) {
1016: if ($_) {
1017: my $declutter=&Apache::lonnet::declutter($feedurl);
1018: unless (&Apache::lonmsg::user_normal_msg(split(/\:/,$_),
1019: 'Feedback ['.$declutter.']',$email,$citations,$feedurl,
1020: $attachmenturl)=~/ok/) {
1021: $status.='<br />'.&mt('Error sending message to').' '.$_.'<br />';
1022: } else {
1023: $sendsomething++;
1024: }
1025: }
1026: }
1027:
1028: my %record=&Apache::lonnet::restore('_feedback');
1029: my ($temp)=keys %record;
1030: unless ($temp=~/^error\:/) {
1031: my %newrecord=();
1032: $newrecord{'resource'}=$feedurl;
1033: $newrecord{'subnumber'}=$record{'subnumber'}+1;
1034: unless (&Apache::lonnet::cstore(\%newrecord,'_feedback') eq 'ok') {
1035: $status.='<br />'.&mt('Not registered').'<br />';
1036: }
1037: }
1038:
1039: return ($status,$sendsomething);
1040: }
1041:
1042: sub adddiscuss {
1043: my ($symb,$email,$anon,$attachmenturl,$subject)=@_;
1044: my $status='';
1045: if (&discussion_open() &&
1046: &Apache::lonnet::allowed('pch',$ENV{'request.course.id'}.
1047: ($ENV{'request.course.sec'}?'/'.$ENV{'request.course.sec'}:''))) {
1048:
1049: my %contrib=('message' => $email,
1050: 'sendername' => $ENV{'user.name'},
1051: 'senderdomain' => $ENV{'user.domain'},
1052: 'screenname' => $ENV{'environment.screenname'},
1053: 'plainname' => $ENV{'environment.firstname'}.' '.
1054: $ENV{'environment.middlename'}.' '.
1055: $ENV{'environment.lastname'}.' '.
1056: $ENV{'enrironment.generation'},
1057: 'attachmenturl'=> $attachmenturl,
1058: 'subject' => $subject);
1059: if ($ENV{'form.replydisc'}) {
1060: $contrib{'replyto'}=(split(/\:\:\:/,$ENV{'form.replydisc'}))[1];
1061: }
1062: if ($anon) {
1063: $contrib{'anonymous'}='true';
1064: }
1065: if (($symb) && ($email)) {
1066: $status='Adding to class discussion'.($anon?' (anonymous)':'').': '.
1067: &Apache::lonnet::store(\%contrib,$symb,$ENV{'request.course.id'},
1068: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
1069: $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
1070: my %storenewentry=($symb => time);
1071: $status.='<br />'.&mt('Updating discussion time').': '.
1072: &Apache::lonnet::put('discussiontimes',\%storenewentry,
1073: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
1074: $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
1075: }
1076: my %record=&Apache::lonnet::restore('_discussion');
1077: my ($temp)=keys %record;
1078: unless ($temp=~/^error\:/) {
1079: my %newrecord=();
1080: $newrecord{'resource'}=$symb;
1081: $newrecord{'subnumber'}=$record{'subnumber'}+1;
1082: $status.='<br />'.&mt('Registering').': '.
1083: &Apache::lonnet::cstore(\%newrecord,'_discussion');
1084: }
1085: } else {
1086: $status.='Failed.';
1087: }
1088: return $status.'<br />';
1089: }
1090:
1091: # ----------------------------------------------------------- Preview function
1092:
1093: sub show_preview {
1094: my $r=shift;
1095: my $message=&clear_out_html($ENV{'form.comment'});
1096: $message=~s/\n/\<br \/\>/g;
1097: $message=&Apache::lontexconvert::msgtexconverted($message);
1098: my $subject=&clear_out_html($ENV{'form.subject'});
1099: $subject=~s/\n/\<br \/\>/g;
1100: $subject=&Apache::lontexconvert::msgtexconverted($subject);
1101: $r->print('<table border="2"><tr><td>'.
1102: '<b>Subject:</b> '.$subject.'<br /><br />'.
1103: $message.'</td></tr></table>');
1104: }
1105:
1106: sub generate_preview_button {
1107: my $pre=&mt("Show Preview");
1108: return(<<ENDPREVIEW);
1109: <form name="preview" action="/adm/feedback?preview=1" method="post" target="preview">
1110: <input type="hidden" name="subject">
1111: <input type="hidden" name="comment" />
1112: <input type="button" value="$pre"
1113: onClick="document.mailform.onsubmit();this.form.comment.value=document.mailform.comment.value;this.form.subject.value=document.mailform.subject.value;this.form.submit();" />
1114: </form>
1115: ENDPREVIEW
1116: }
1117:
1118: sub handler {
1119: my $r = shift;
1120: if ($r->header_only) {
1121: &Apache::loncommon::content_type($r,'text/html');
1122: $r->send_http_header;
1123: return OK;
1124: }
1125:
1126: # --------------------------- Get query string for limited number of parameters
1127:
1128: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1129: ['hide','unhide','deldisc','postdata','preview','replydisc','threadedon','threadedoff','onlyunread','allposts','previous','markread','markonread','markondisp','modifydisp','changes']);
1130: if ($ENV{'form.modifydisp'}) {
1131: &Apache::loncommon::content_type($r,'text/html');
1132: $r->send_http_header;
1133: my $symb=$ENV{'form.modifydisp'};
1134: my ($map,$ind,$url)=&Apache::lonnet::decode_symb($symb);
1135: my $previous=$ENV{'form.previous'};
1136: my ($dispchg,$markchg) = split/_/,$ENV{'form.changes'};
1137: my $feedurl = &Apache::lonnet::clutter($url);
1138: &print_display_options($r,$symb,$previous,$dispchg,$markchg,$feedurl);
1139: return OK;
1140: } elsif (($ENV{'form.markondisp'}) || ($ENV{'form.markonread'}) || ($ENV{'form.allposts'}) || ($ENV{'form.onlyunread'}) ) {
1141: &Apache::loncommon::content_type($r,'text/html');
1142: $r->send_http_header;
1143: my $previous=$ENV{'form.previous'};
1144: my ($map,$ind,$url);
1145: if (($ENV{'form.markondisp'}) || ($ENV{'form.markonread'})) {
1146: # ---------------------- Modify setting for identification of 'NEW' posts in this discussion
1147: my $symb=$ENV{'form.markondisp'}?$ENV{'form.markondisp'}:$ENV{'form.markonread'};
1148: my $ressymb = $symb;
1149: ($map,$ind,$url)=&Apache::lonnet::decode_symb($symb);
1150: unless ($ressymb =~ m|bulletin___\d+___adm/wrapper|) {
1151: $ressymb=~s|(bulletin___\d+___)|$1adm/wrapper|;
1152: }
1153: my %discinfo = ();
1154: my $lastkey = $ressymb.'_lastread';
1155: my $ondispkey = $ressymb.'_markondisp';
1156: if ($ENV{'form.markondisp'}) {
1157: $discinfo{$lastkey} = time;
1158: $discinfo{$ondispkey} = 1;
1159: } elsif ($ENV{'form.markonread'}) {
1160: if ( $previous > 0 ) {
1161: $discinfo{$lastkey} = $previous;
1162: }
1163: $discinfo{$ondispkey} = 0;
1164: }
1165: &Apache::lonnet::put('nohist_'.$ENV{'request.course.id'}.'_discuss',\%discinfo,$ENV{'user.domain'},$ENV{'user.name'});
1166: }
1167: if (($ENV{'form.allposts'}) || ($ENV{'form.onlyunread'})) {
1168: # ----------------------------------------------------------------- Modify display setting for this discussion
1169: my $symb=$ENV{'form.allposts'}?$ENV{'form.allposts'}:$ENV{'form.onlyunread'};
1170: my $ressymb = $symb;
1171: ($map,$ind,$url)=&Apache::lonnet::decode_symb($symb);
1172: unless ($ressymb =~ m|bulletin___\d+___adm/wrapper|) {
1173: $ressymb=~s|(bulletin___\d+___)|$1adm/wrapper|;
1174: }
1175: my %discinfo = ();
1176: if ($ENV{'form.allposts'}) {
1177: $discinfo{$ressymb.'_showonlyunread'} = 0;
1178: } elsif ($ENV{'form.onlyunread'}) {
1179: $discinfo{$ressymb.'_showonlyunread'} = 1;
1180: }
1181: &Apache::lonnet::put('nohist_'.$ENV{'request.course.id'}.'_discuss',\%discinfo,$ENV{'user.domain'},$ENV{'user.name'});
1182: }
1183: if (($ENV{'form.markonread'}) || ($ENV{'form.allposts'}) || ($ENV{'form.onlyunread'}) ) {
1184: &redirect_back($r,&Apache::lonnet::clutter($url),&mt('Changed display status').'<br />','0','0','',$previous);
1185: } else {
1186: &redirect_back($r,&Apache::lonnet::clutter($url),&mt('Changed display status').'<br />','0','0');
1187: }
1188: return OK;
1189: } elsif ($ENV{'form.markread'}) {
1190: # ----------------------------------------------------------------- Mark new posts as read
1191: &Apache::loncommon::content_type($r,'text/html');
1192: $r->send_http_header;
1193: my $symb=$ENV{'form.markread'};
1194: my $ressymb = $symb;
1195: my ($map,$ind,$url)=&Apache::lonnet::decode_symb($symb);
1196: unless ($ressymb =~ m|bulletin___\d+___adm/wrapper|) {
1197: $ressymb=~s|(bulletin___\d+___)|$1adm/wrapper|;
1198: }
1199: my %discinfo = ();
1200: my $lastkey = $ressymb.'_lastread';
1201: $discinfo{$lastkey} = time;
1202: &Apache::lonnet::put('nohist_'.$ENV{'request.course.id'}.'_discuss',\%discinfo,$ENV{'user.domain'},$ENV{'user.name'});
1203: &redirect_back($r,&Apache::lonnet::clutter($url),&mt('Changed reading status').'<br />','0','0');
1204: return OK;
1205: } elsif (($ENV{'form.hide'}) || ($ENV{'form.unhide'})) {
1206: # ----------------------------------------------------------------- Hide/unhide
1207: &Apache::loncommon::content_type($r,'text/html');
1208: $r->send_http_header;
1209:
1210: my $entry=$ENV{'form.hide'}?$ENV{'form.hide'}:$ENV{'form.unhide'};
1211:
1212: my ($symb,$idx)=split(/\:\:\:/,$entry);
1213: my ($map,$ind,$url)=&Apache::lonnet::decode_symb($symb);
1214:
1215: my %contrib=&Apache::lonnet::restore($symb,$ENV{'request.course.id'},
1216: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
1217: $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
1218:
1219:
1220: my $currenthidden=$contrib{'hidden'};
1221:
1222: if ($ENV{'form.hide'}) {
1223: $currenthidden.='.'.$idx.'.';
1224: } else {
1225: $currenthidden=~s/\.$idx\.//g;
1226: }
1227: my %newhash=('hidden' => $currenthidden);
1228:
1229: &Apache::lonnet::store(\%newhash,$symb,$ENV{'request.course.id'},
1230: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
1231: $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
1232:
1233: &redirect_back($r,&Apache::lonnet::clutter($url),
1234: &mt('Changed discussion status').'<br />','0','0','',$ENV{'form.previous'});
1235: } elsif (($ENV{'form.threadedon'}) || ($ENV{'form.threadedoff'})) {
1236: &Apache::loncommon::content_type($r,'text/html');
1237: $r->send_http_header;
1238: if ($ENV{'form.threadedon'}) {
1239: &Apache::lonnet::put('environment',{'threadeddiscussion' => 'on'});
1240: &Apache::lonnet::appenv('environment.threadeddiscussion' => 'on');
1241: } else {
1242: &Apache::lonnet::del('environment',['threadeddiscussion']);
1243: &Apache::lonnet::delenv('environment\.threadeddiscussion');
1244: }
1245: my $symb=$ENV{'form.threadedon'}?$ENV{'form.threadedon'}:$ENV{'form.threadedoff'};
1246: my ($map,$ind,$url)=&Apache::lonnet::decode_symb($symb);
1247: &redirect_back($r,&Apache::lonnet::clutter($url),
1248: &mt('Changed discussion view mode').'<br />','0','0','',$ENV{'form.previous'});
1249: } elsif ($ENV{'form.deldisc'}) {
1250: # --------------------------------------------------------------- Hide for good
1251: &Apache::loncommon::content_type($r,'text/html');
1252: $r->send_http_header;
1253:
1254: my $entry=$ENV{'form.deldisc'};
1255:
1256: my ($symb,$idx)=split(/\:\:\:/,$entry);
1257: my ($map,$ind,$url)=&Apache::lonnet::decode_symb($symb);
1258:
1259: my %contrib=&Apache::lonnet::restore($symb,$ENV{'request.course.id'},
1260: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
1261: $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
1262:
1263:
1264: my $currentdeleted=$contrib{'deleted'};
1265:
1266: $currentdeleted.='.'.$idx.'.';
1267:
1268: my %newhash=('deleted' => $currentdeleted);
1269:
1270: &Apache::lonnet::store(\%newhash,$symb,$ENV{'request.course.id'},
1271: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
1272: $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
1273:
1274: &redirect_back($r,&Apache::lonnet::clutter($url),
1275: &mt('Changed discussion status').'<br />','0','0','',$ENV{'form.previous'});
1276: } elsif ($ENV{'form.preview'}) {
1277: # -------------------------------------------------------- User wants a preview
1278: $r->content_type('text/html');
1279: $r->send_http_header;
1280: &show_preview($r);
1281: } else {
1282: # ------------------------------------------------------------- Normal feedback
1283: my $feedurl=$ENV{'form.postdata'};
1284: $feedurl=~s/^http\:\/\///;
1285: $feedurl=~s/^$ENV{'SERVER_NAME'}//;
1286: $feedurl=~s/^$ENV{'HTTP_HOST'}//;
1287: $feedurl=~s/\?.+$//;
1288:
1289: my $symb;
1290: if ($ENV{'form.replydisc'}) {
1291: $symb=(split(/\:\:\:/,$ENV{'form.replydisc'}))[0];
1292: my ($map,$id,$url)=&Apache::lonnet::decode_symb($symb);
1293: $feedurl=&Apache::lonnet::clutter($url);
1294: } else {
1295: $symb=&Apache::lonnet::symbread($feedurl);
1296: }
1297: unless ($symb) {
1298: $symb=$ENV{'form.symb'};
1299: if ($symb) {
1300: my ($map,$id,$url)=&Apache::lonnet::decode_symb($symb);
1301: $feedurl=&Apache::lonnet::clutter($url);
1302: }
1303: }
1304: my $goahead=1;
1305: if ($feedurl=~/\.(problem|exam|quiz|assess|survey|form)$/) {
1306: unless ($symb) { $goahead=0; }
1307: }
1308: # backward compatibility (bulltin boards used to be 'wrapped')
1309: if ($feedurl=~m|^/adm/wrapper/adm/.*/bulletinboard$|) {
1310: $feedurl=~s|^/adm/wrapper||;
1311: }
1312: if ($goahead) {
1313: # Go ahead with feedback, no ambiguous reference
1314: &Apache::loncommon::content_type($r,'text/html');
1315: $r->send_http_header;
1316:
1317: if (
1318: (
1319: ($feedurl=~m:^/res:) && ($feedurl!~m:^/res/adm:)
1320: )
1321: ||
1322: ($ENV{'request.course.id'} && ($feedurl!~m:^/adm:))
1323: ||
1324: ($ENV{'request.course.id'} && ($symb=~/^bulletin\_\_\_/))
1325: ) {
1326: # --------------------------------------------------- Print login screen header
1327: unless ($ENV{'form.sendit'}) {
1328: my $options=&screen_header($feedurl);
1329: if ($options) {
1330: &mail_screen($r,$feedurl,$options);
1331: } else {
1332: &fail_redirect($r,$feedurl);
1333: }
1334: } else {
1335:
1336: # Get previous user input
1337: my $prevattempts=&Apache::loncommon::get_previous_attempt(
1338: $symb,$ENV{'user.name'},$ENV{'user.domain'},
1339: $ENV{'request.course.id'});
1340:
1341: # Get output from resource
1342: my $usersaw=&resource_output($feedurl);
1343:
1344: # Get resource answer (need to allow student to view grades for this to work)
1345: &Apache::lonnet::appenv(('allowed.vgr'=>'F'));
1346: my $useranswer=&Apache::loncommon::get_student_answers(
1347: $symb,$ENV{'user.name'},$ENV{'user.domain'},
1348: $ENV{'request.course.id'});
1349: &Apache::lonnet::delenv('allowed.vgr');
1350: # Get attachments, if any, and not too large
1351: my $attachmenturl='';
1352: if ($ENV{'form.attachment.filename'}) {
1353: unless (length($ENV{'form.attachment'})>131072) {
1354: $attachmenturl=&Apache::lonnet::userfileupload('attachment',undef,'feedback');
1355: }
1356: }
1357: # Filter HTML out of message (could be nasty)
1358: my $message=&clear_out_html($ENV{'form.comment'});
1359:
1360: # Assemble email
1361: my ($email,$citations)=&assemble_email($feedurl,$message,$prevattempts,
1362: $usersaw,$useranswer);
1363:
1364: # Who gets this?
1365: my ($typestyle,%to) = &decide_receiver($feedurl);
1366:
1367: # Actually send mail
1368: my ($status,$numsent)=&send_msg($feedurl,$email,$citations,
1369: $attachmenturl,%to);
1370:
1371: # Discussion? Store that.
1372:
1373: my $numpost=0;
1374: if ($ENV{'form.discuss'}) {
1375: my $subject = &clear_out_html($ENV{'form.subject'});
1376: $typestyle.=&adddiscuss($symb,$message,0,$attachmenturl,$subject);
1377: $numpost++;
1378: }
1379:
1380: if ($ENV{'form.anondiscuss'}) {
1381: my $subject = &clear_out_html($ENV{'form.subject'});
1382: $typestyle.=&adddiscuss($symb,$message,1,$attachmenturl,$subject);
1383: $numpost++;
1384: }
1385:
1386:
1387: # Receipt screen and redirect back to where came from
1388: &redirect_back($r,$feedurl,$typestyle,$numsent,$numpost,$status,$ENV{'form.previous'});
1389:
1390: }
1391: } else {
1392: # Unable to give feedback
1393: &no_redirect_back($r,$feedurl);
1394: }
1395: } else {
1396: # Ambiguous Problem Resource
1397: if ( &Apache::lonnet::mod_perl_version() == 2 ) {
1398: &Apache::lonnet::cleanenv();
1399: }
1400: $r->internal_redirect('/adm/ambiguous');
1401: }
1402: }
1403: return OK;
1404: }
1405:
1406: 1;
1407: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>