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