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