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