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