Annotation of loncom/interface/lonfeedback.pm, revision 1.99.2.2
1.1 www 1: # The LearningOnline Network
2: # Feedback
3: #
1.99.2.2! albertel 4: # $Id: lonfeedback.pm,v 1.99.2.1 2004/07/23 20:01:46 albertel 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.74 www 555: my $send=&mt('Send');
1.6 albertel 556: $r->print(<<ENDDOCUMENT);
1.1 www 557: <html>
558: <head>
559: <title>The LearningOnline Network with CAPA</title>
1.7 albertel 560: <meta http-equiv="pragma" content="no-cache"></meta>
1.85 www 561: $htmlheader
1.63 albertel 562: <script type="text/javascript">
563: //<!--
1.5 www 564: function gosubmit() {
565: var rec=0;
1.12 albertel 566: if (typeof(document.mailform.elements.author)!="undefined") {
1.5 www 567: if (document.mailform.elements.author.checked) {
568: rec=1;
569: }
570: }
1.12 albertel 571: if (typeof(document.mailform.elements.question)!="undefined") {
1.5 www 572: if (document.mailform.elements.question.checked) {
573: rec=1;
574: }
575: }
1.12 albertel 576: if (typeof(document.mailform.elements.course)!="undefined") {
1.5 www 577: if (document.mailform.elements.course.checked) {
578: rec=1;
579: }
580: }
1.12 albertel 581: if (typeof(document.mailform.elements.policy)!="undefined") {
1.5 www 582: if (document.mailform.elements.policy.checked) {
583: rec=1;
584: }
585: }
1.12 albertel 586: if (typeof(document.mailform.elements.discuss)!="undefined") {
1.10 www 587: if (document.mailform.elements.discuss.checked) {
588: rec=1;
589: }
590: }
1.14 www 591: if (typeof(document.mailform.elements.anondiscuss)!="undefined") {
592: if (document.mailform.elements.anondiscuss.checked) {
593: rec=1;
594: }
595: }
1.5 www 596:
597: if (rec) {
1.99.2.2! albertel 598: if (typeof(document.mailform.onsubmit)!='undefined') {
! 599: document.mailform.onsubmit();
! 600: }
1.5 www 601: document.mailform.submit();
602: } else {
603: alert('Please check a feedback type.');
604: }
605: }
1.63 albertel 606: //-->
1.5 www 607: </script>
1.1 www 608: </head>
1.29 www 609: $bodytag
1.51 albertel 610: <h2><tt>$title</tt></h2>
1.43 www 611: <form action="/adm/feedback" method="post" name="mailform"
612: enctype="multipart/form-data">
1.80 raeburn 613: $prevtag
1.63 albertel 614: <input type="hidden" name="postdata" value="$feedurl" />
1.68 www 615: <input type="hidden" name="replydisc" value="$ENV{'form.replydisc'}" />
1.5 www 616: Please check at least one of the following feedback types:
1.63 albertel 617: $options<hr />
1.69 www 618: $quote
1.63 albertel 619: <p>My question/comment/feedback:</p>
620: <p>
1.47 bowersj2 621: $latexHelp
1.78 raeburn 622: Title: <input type="text" name="subject" size="30" value="$subject" /></p>
623: <p>
1.94 www 624: <textarea name="comment" id="comment" cols="60" rows="10" wrap="hard">
1.63 albertel 625: </textarea></p>
626: <p>
1.42 www 627: Attachment (128 KB max size): <input type="file" name="attachment" />
628: </p>
629: <p>
630: <input type="hidden" name="sendit" value="1" />
1.74 www 631: <input type="button" value="$send" onClick='gosubmit();' />
1.42 www 632: </p>
1.2 www 633: </form>
1.1 www 634: ENDDOCUMENT
1.99.2.2! albertel 635: $r->print(&generate_preview_button().
1.94 www 636: &Apache::lonhtmlcommon::htmlareaselectactive('comment').
1.85 www 637: '</body></html>');
1.6 albertel 638: }
639:
1.97 raeburn 640: sub print_display_options {
641: my ($r,$symb,$previous,$dispchg,$markchg,$feedurl) = @_;
1.98 raeburn 642: # backward compatibility (bulletin boards used to be 'wrapped')
643: if ($feedurl=~m|^/adm/wrapper/adm/.*/bulletinboard$|) {
644: $feedurl=~s|^/adm/wrapper||;
645: }
646:
1.97 raeburn 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:
1.6 albertel 770: sub fail_redirect {
771: my ($r,$feedurl) = @_;
1.70 www 772: if ($feedurl=~/^\/adm\//) { $feedurl.='?register=1' };
1.6 albertel 773: $r->print (<<ENDFAILREDIR);
1.72 albertel 774: <html>
1.5 www 775: <head><title>Feedback not sent</title>
1.63 albertel 776: <meta http-equiv="pragma" content="no-cache" />
777: <meta HTTP-EQUIV="Refresh" CONTENT="2; url=$feedurl" />
1.5 www 778: </head>
779: <body bgcolor="#FFFFFF">
1.63 albertel 780: <img align="right" src="/adm/lonIcons/lonlogos.gif" />
1.8 www 781: <b>Sorry, no recipients ...</b>
1.5 www 782: </body>
783: </html>
784: ENDFAILREDIR
785: }
1.4 www 786:
1.6 albertel 787: sub redirect_back {
1.80 raeburn 788: my ($r,$feedurl,$typestyle,$sendsomething,$sendposts,$status,$previous) = @_;
789: my $prevtag = '';
790: my $qrystr = '';
1.98 raeburn 791: # backward compatibility (bulletin boards used to be 'wrapped')
792: if ($feedurl=~m|^/adm/wrapper/adm/.*/bulletinboard$|) {
793: $feedurl=~s|^/adm/wrapper||;
794: }
795:
1.70 www 796: if ($feedurl=~/^\/adm\//) { $feedurl.='?register=1' };
1.80 raeburn 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: }
1.6 albertel 806: $r->print (<<ENDREDIR);
1.72 albertel 807: <html>
1.3 www 808: <head>
809: <title>Feedback sent</title>
1.63 albertel 810: <meta http-equiv="pragma" content="no-cache" />
1.80 raeburn 811: <meta HTTP-EQUIV="Refresh" CONTENT="2; url=$feedurl" />
1.2 www 812: </head>
1.49 www 813: <body bgcolor="#FFFFFF" onLoad='if (window.name!="loncapaclient") { this.document.reldt.submit(); self.close(); }'>
1.63 albertel 814: <img align="right" src="/adm/lonIcons/lonlogos.gif" />
1.5 www 815: $typestyle
1.32 albertel 816: <b>Sent $sendsomething message(s), and $sendposts post(s).</b>
1.63 albertel 817: <font color="red">$status</font>
1.49 www 818: <form name="reldt" action="$feedurl" target="loncapaclient">
1.80 raeburn 819: $prevtag
1.49 www 820: </form>
1.2 www 821: </body>
822: </html>
823: ENDREDIR
824: }
1.6 albertel 825:
826: sub no_redirect_back {
827: my ($r,$feedurl) = @_;
828: $r->print (<<ENDNOREDIR);
1.72 albertel 829: <html>
1.2 www 830: <head><title>Feedback not sent</title>
1.63 albertel 831: <meta http-equiv="pragma" content="no-cache" />
1.7 albertel 832: ENDNOREDIR
833:
1.8 www 834: if ($feedurl!~/^\/adm\/feedback/) {
1.7 albertel 835: $r->print('<meta HTTP-EQUIV="Refresh" CONTENT="2; url='.$feedurl.'">');
836: }
837:
1.8 www 838: $r->print (<<ENDNOREDIRTWO);
1.2 www 839: </head>
1.49 www 840: <body bgcolor="#FFFFFF" onLoad='if (window.name!="loncapaclient") { self.close(); }'>
1.63 albertel 841: <img align="right" src="/adm/lonIcons/lonlogos.gif" />
1.8 www 842: <b>Sorry, no feedback possible on this resource ...</b>
1.2 www 843: </body>
844: </html>
1.8 www 845: ENDNOREDIRTWO
1.2 www 846: }
1.6 albertel 847:
848: sub screen_header {
1.65 www 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'}) {
1.92 albertel 875: if (&discussion_open() &&
1.90 albertel 876: &Apache::lonnet::allowed('pch',
1.65 www 877: $ENV{'request.course.id'}.
878: ($ENV{'request.course.sec'}?'/'.$ENV{'request.course.sec'}:''))) {
1.74 www 879: $discussoptions='<input type="checkbox" name="discuss" onClick="this.form.anondiscuss.checked=false;" '.
880: ($ENV{'form.replydisc'}?' checked="1"':'').' /> '.
1.65 www 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>';
1.20 www 885: }
1.65 www 886: }
1.74 www 887: if ($msgoptions) { $msgoptions='<h2><img src="/adm/lonMisc/feedback.gif" />'.&mt('Sending Messages').'</h2>'.$msgoptions; }
1.65 www 888: if ($discussoptions) {
1.74 www 889: $discussoptions='<h2><img src="/adm/lonMisc/chat.gif" />'.&mt('Discussion Contributions').'</h2>'.$discussoptions; }
1.65 www 890: return $msgoptions.$discussoptions;
1.6 albertel 891: }
892:
893: sub resource_output {
894: my ($feedurl) = @_;
1.46 albertel 895: my $usersaw=&Apache::lonnet::ssi_body($feedurl);
1.6 albertel 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 {
1.39 www 907: my ($message,$override)=@_;
1.88 www 908: unless (&Apache::lonhtmlcommon::htmlareablocked()) { return $message; }
1.37 albertel 909: my $cid=$ENV{'request.course.id'};
1.39 www 910: if (($ENV{"course.$cid.allow_limited_html_in_feedback"} =~ m/yes/i) ||
911: ($override)) {
1.37 albertel 912: # allows <B> <I> <P> <A> <LI> <OL> <UL> <EM> <BR> <TT> <STRONG>
1.88 www 913: # <BLOCKQUOTE> <DIV .*> <DIV> <IMG> <M> <SPAN> <H1> <H2> <H3> <H4> <SUB>
914: # <SUP>
1.37 albertel 915: my %html=(B=>1, I=>1, P=>1, A=>1, LI=>1, OL=>1, UL=>1, EM=>1,
1.61 www 916: BR=>1, TT=>1, STRONG=>1, BLOCKQUOTE=>1, DIV=>1, IMG=>1,
1.88 www 917: M=>1, SUB=>1, SUP=>1, SPAN=>1,
918: H1=>1, H2=>1, H3=>1, H4=>1, H5=>1);
1.37 albertel 919:
920: $message =~ s/\<(\/?\s*(\w+)[^\>\<]*)/
1.48 albertel 921: {($html{uc($2)}&&(length($1)<1000))?"\<$1":"\<$1"}/ge;
1.37 albertel 922: $message =~ s/(\<?\s*(\w+)[^\<\>]*)\>/
1.48 albertel 923: {($html{uc($2)}&&(length($1)<1000))?"$1\>":"$1\>"}/ge;
1.37 albertel 924: } else {
925: $message=~s/\</\<\;/g;
926: $message=~s/\>/\>\;/g;
927: }
1.6 albertel 928: return $message;
929: }
930:
931: sub assemble_email {
1.40 albertel 932: my ($feedurl,$message,$prevattempts,$usersaw,$useranswer)=@_;
1.6 albertel 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
1.63 albertel 941: <br /><hr />
1.6 albertel 942: <h2>Original screen output (if applicable)</h2>
943: $usersaw
1.40 albertel 944: <h2>Correct Answer(s) (if applicable)</h2>
945: $useranswer
1.6 albertel 946: ENDCITE
947: return ($email,$citations);
948: }
949:
1.35 www 950: sub secapply {
951: my $rec=shift;
1.36 www 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 '';
1.35 www 967: }
968:
1.6 albertel 969: sub decide_receiver {
1.36 www 970: my ($feedurl,$author,$question,$course,$policy,$defaultflag) = @_;
1.6 albertel 971: my $typestyle='';
972: my %to=();
1.36 www 973: if ($ENV{'form.author'}||$author) {
1.8 www 974: $typestyle.='Submitting as Author Feedback<br>';
1.6 albertel 975: $feedurl=~/^\/res\/(\w+)\/(\w+)\//;
976: $to{$2.':'.$1}=1;
977: }
1.36 www 978: if ($ENV{'form.question'}||$question) {
1.8 www 979: $typestyle.='Submitting as Question<br>';
1.24 harris41 980: foreach (split(/\,/,
981: $ENV{'course.'.$ENV{'request.course.id'}.'.question.email'})
982: ) {
1.36 www 983: my $rec=&secapply($_,$defaultflag);
984: if ($rec) { $to{$rec}=1; }
1.24 harris41 985: }
1.6 albertel 986: }
1.36 www 987: if ($ENV{'form.course'}||$course) {
1.63 albertel 988: $typestyle.='Submitting as Comment<br />';
1.24 harris41 989: foreach (split(/\,/,
990: $ENV{'course.'.$ENV{'request.course.id'}.'.comment.email'})
991: ) {
1.36 www 992: my $rec=&secapply($_,$defaultflag);
993: if ($rec) { $to{$rec}=1; }
1.24 harris41 994: }
1.6 albertel 995: }
1.36 www 996: if ($ENV{'form.policy'}||$policy) {
1.63 albertel 997: $typestyle.='Submitting as Policy Feedback<br />';
1.24 harris41 998: foreach (split(/\,/,
999: $ENV{'course.'.$ENV{'request.course.id'}.'.policy.email'})
1000: ) {
1.36 www 1001: my $rec=&secapply($_,$defaultflag);
1002: if ($rec) { $to{$rec}=1; }
1.24 harris41 1003: }
1.6 albertel 1004: }
1.36 www 1005: if ((scalar(%to) eq '0') && (!$defaultflag)) {
1006: ($typestyle,%to)=
1007: &decide_receiver($feedurl,$author,$question,$course,$policy,1);
1008: }
1.6 albertel 1009: return ($typestyle,%to);
1.36 www 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);
1.6 albertel 1016: }
1017:
1018: sub send_msg {
1.43 www 1019: my ($feedurl,$email,$citations,$attachmenturl,%to)=@_;
1.6 albertel 1020: my $status='';
1021: my $sendsomething=0;
1.24 harris41 1022: foreach (keys %to) {
1.6 albertel 1023: if ($_) {
1.22 www 1024: my $declutter=&Apache::lonnet::declutter($feedurl);
1.8 www 1025: unless (&Apache::lonmsg::user_normal_msg(split(/\:/,$_),
1.43 www 1026: 'Feedback ['.$declutter.']',$email,$citations,$feedurl,
1027: $attachmenturl)=~/ok/) {
1.63 albertel 1028: $status.='<br />'.&mt('Error sending message to').' '.$_.'<br />';
1.6 albertel 1029: } else {
1030: $sendsomething++;
1031: }
1032: }
1.24 harris41 1033: }
1.18 www 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') {
1.63 albertel 1042: $status.='<br />'.&mt('Not registered').'<br />';
1.18 www 1043: }
1044: }
1045:
1.6 albertel 1046: return ($status,$sendsomething);
1047: }
1048:
1.13 www 1049: sub adddiscuss {
1.78 raeburn 1050: my ($symb,$email,$anon,$attachmenturl,$subject)=@_;
1.13 www 1051: my $status='';
1.92 albertel 1052: if (&discussion_open() &&
1.90 albertel 1053: &Apache::lonnet::allowed('pch',$ENV{'request.course.id'}.
1.23 www 1054: ($ENV{'request.course.sec'}?'/'.$ENV{'request.course.sec'}:''))) {
1.20 www 1055:
1.13 www 1056: my %contrib=('message' => $email,
1057: 'sendername' => $ENV{'user.name'},
1.26 www 1058: 'senderdomain' => $ENV{'user.domain'},
1059: 'screenname' => $ENV{'environment.screenname'},
1060: 'plainname' => $ENV{'environment.firstname'}.' '.
1061: $ENV{'environment.middlename'}.' '.
1062: $ENV{'environment.lastname'}.' '.
1.42 www 1063: $ENV{'enrironment.generation'},
1.78 raeburn 1064: 'attachmenturl'=> $attachmenturl,
1065: 'subject' => $subject);
1.65 www 1066: if ($ENV{'form.replydisc'}) {
1.66 www 1067: $contrib{'replyto'}=(split(/\:\:\:/,$ENV{'form.replydisc'}))[1];
1.65 www 1068: }
1.14 www 1069: if ($anon) {
1070: $contrib{'anonymous'}='true';
1071: }
1.13 www 1072: if (($symb) && ($email)) {
1.14 www 1073: $status='Adding to class discussion'.($anon?' (anonymous)':'').': '.
1.13 www 1074: &Apache::lonnet::store(\%contrib,$symb,$ENV{'request.course.id'},
1075: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
1.17 www 1076: $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
1.21 www 1077: my %storenewentry=($symb => time);
1.63 albertel 1078: $status.='<br />'.&mt('Updating discussion time').': '.
1.21 www 1079: &Apache::lonnet::put('discussiontimes',\%storenewentry,
1080: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
1081: $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
1.13 www 1082: }
1.17 www 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;
1.63 albertel 1089: $status.='<br />'.&mt('Registering').': '.
1.21 www 1090: &Apache::lonnet::cstore(\%newrecord,'_discussion');
1.20 www 1091: }
1092: } else {
1093: $status.='Failed.';
1.17 www 1094: }
1.63 albertel 1095: return $status.'<br />';
1.13 www 1096: }
1097:
1.33 www 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);
1.78 raeburn 1105: my $subject=&clear_out_html($ENV{'form.subject'});
1106: $subject=~s/\n/\<br \/\>/g;
1107: $subject=&Apache::lontexconvert::msgtexconverted($subject);
1.33 www 1108: $r->print('<table border="2"><tr><td>'.
1.78 raeburn 1109: '<b>Subject:</b> '.$subject.'<br /><br />'.
1.33 www 1110: $message.'</td></tr></table>');
1111: }
1112:
1113: sub generate_preview_button {
1.65 www 1114: my $pre=&mt("Show Preview");
1.33 www 1115: return(<<ENDPREVIEW);
1116: <form name="preview" action="/adm/feedback?preview=1" method="post" target="preview">
1.78 raeburn 1117: <input type="hidden" name="subject">
1.33 www 1118: <input type="hidden" name="comment" />
1.65 www 1119: <input type="button" value="$pre"
1.99.2.2! albertel 1120: onClick="if (typeof(document.mailform.onsubmit)!='undefined') {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 1121: </form>
1122: ENDPREVIEW
1123: }
1.71 www 1124:
1.6 albertel 1125: sub handler {
1126: my $r = shift;
1.8 www 1127: if ($r->header_only) {
1.71 www 1128: &Apache::loncommon::content_type($r,'text/html');
1.8 www 1129: $r->send_http_header;
1130: return OK;
1131: }
1.15 www 1132:
1133: # --------------------------- Get query string for limited number of parameters
1134:
1.97 raeburn 1135: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.99 raeburn 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'}) {
1.84 raeburn 1185: &Apache::loncommon::content_type($r,'text/html');
1186: $r->send_http_header;
1.97 raeburn 1187: my $symb=$ENV{'form.modifydisp'};
1.84 raeburn 1188: my ($map,$ind,$url)=&Apache::lonnet::decode_symb($symb);
1.97 raeburn 1189: my $previous=$ENV{'form.previous'};
1190: my ($dispchg,$markchg) = split/_/,$ENV{'form.changes'};
1191: my $feedurl = &Apache::lonnet::clutter($url);
1.98 raeburn 1192: # backward compatibility (bulletin boards used to be 'wrapped')
1193: if ($feedurl=~m|^/adm/wrapper/adm/.*/bulletinboard$|) {
1194: $feedurl=~s|^/adm/wrapper||;
1195: }
1.97 raeburn 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'});
1.84 raeburn 1224: }
1.97 raeburn 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;
1.84 raeburn 1238: }
1.97 raeburn 1239: &Apache::lonnet::put('nohist_'.$ENV{'request.course.id'}.'_discuss',\%discinfo,$ENV{'user.domain'},$ENV{'user.name'});
1.84 raeburn 1240: }
1.97 raeburn 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 {
1.84 raeburn 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|;
1.78 raeburn 1256: }
1.84 raeburn 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');
1.78 raeburn 1262: return OK;
1263: } elsif (($ENV{'form.hide'}) || ($ENV{'form.unhide'})) {
1.15 www 1264: # ----------------------------------------------------------------- Hide/unhide
1.71 www 1265: &Apache::loncommon::content_type($r,'text/html');
1.15 www 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);
1.52 www 1271: my ($map,$ind,$url)=&Apache::lonnet::decode_symb($symb);
1.15 www 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);
1.38 www 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),
1.80 raeburn 1292: &mt('Changed discussion status').'<br />','0','0','',$ENV{'form.previous'});
1.69 www 1293: } elsif (($ENV{'form.threadedon'}) || ($ENV{'form.threadedoff'})) {
1.72 albertel 1294: &Apache::loncommon::content_type($r,'text/html');
1295: $r->send_http_header;
1.69 www 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');
1.72 albertel 1302: }
1.69 www 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),
1.80 raeburn 1306: &mt('Changed discussion view mode').'<br />','0','0','',$ENV{'form.previous'});
1.38 www 1307: } elsif ($ENV{'form.deldisc'}) {
1308: # --------------------------------------------------------------- Hide for good
1.71 www 1309: &Apache::loncommon::content_type($r,'text/html');
1.38 www 1310: $r->send_http_header;
1311:
1312: my $entry=$ENV{'form.deldisc'};
1313:
1314: my ($symb,$idx)=split(/\:\:\:/,$entry);
1.52 www 1315: my ($map,$ind,$url)=&Apache::lonnet::decode_symb($symb);
1.38 www 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);
1.15 www 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:
1.30 www 1332: &redirect_back($r,&Apache::lonnet::clutter($url),
1.80 raeburn 1333: &mt('Changed discussion status').'<br />','0','0','',$ENV{'form.previous'});
1.33 www 1334: } elsif ($ENV{'form.preview'}) {
1335: # -------------------------------------------------------- User wants a preview
1.76 albertel 1336: $r->content_type('text/html');
1337: $r->send_http_header;
1.33 www 1338: &show_preview($r);
1.15 www 1339: } else {
1340: # ------------------------------------------------------------- Normal feedback
1.6 albertel 1341: my $feedurl=$ENV{'form.postdata'};
1342: $feedurl=~s/^http\:\/\///;
1343: $feedurl=~s/^$ENV{'SERVER_NAME'}//;
1344: $feedurl=~s/^$ENV{'HTTP_HOST'}//;
1.62 www 1345: $feedurl=~s/\?.+$//;
1.8 www 1346:
1.66 www 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: }
1.31 www 1355: unless ($symb) {
1356: $symb=$ENV{'form.symb'};
1357: if ($symb) {
1.52 www 1358: my ($map,$id,$url)=&Apache::lonnet::decode_symb($symb);
1.31 www 1359: $feedurl=&Apache::lonnet::clutter($url);
1360: }
1361: }
1.8 www 1362: my $goahead=1;
1363: if ($feedurl=~/\.(problem|exam|quiz|assess|survey|form)$/) {
1364: unless ($symb) { $goahead=0; }
1365: }
1.98 raeburn 1366: # backward compatibility (bulletin boards used to be 'wrapped')
1.73 albertel 1367: if ($feedurl=~m|^/adm/wrapper/adm/.*/bulletinboard$|) {
1368: $feedurl=~s|^/adm/wrapper||;
1369: }
1.8 www 1370: if ($goahead) {
1371: # Go ahead with feedback, no ambiguous reference
1.71 www 1372: &Apache::loncommon::content_type($r,'text/html');
1.8 www 1373: $r->send_http_header;
1.6 albertel 1374:
1.8 www 1375: if (
1.7 albertel 1376: (
1377: ($feedurl=~m:^/res:) && ($feedurl!~m:^/res/adm:)
1378: )
1379: ||
1380: ($ENV{'request.course.id'} && ($feedurl!~m:^/adm:))
1.31 www 1381: ||
1382: ($ENV{'request.course.id'} && ($symb=~/^bulletin\_\_\_/))
1.7 albertel 1383: ) {
1.6 albertel 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
1.9 albertel 1395: my $prevattempts=&Apache::loncommon::get_previous_attempt(
1.11 albertel 1396: $symb,$ENV{'user.name'},$ENV{'user.domain'},
1.9 albertel 1397: $ENV{'request.course.id'});
1.6 albertel 1398:
1399: # Get output from resource
1400: my $usersaw=&resource_output($feedurl);
1401:
1.50 albertel 1402: # Get resource answer (need to allow student to view grades for this to work)
1403: &Apache::lonnet::appenv(('allowed.vgr'=>'F'));
1.40 albertel 1404: my $useranswer=&Apache::loncommon::get_student_answers(
1405: $symb,$ENV{'user.name'},$ENV{'user.domain'},
1406: $ENV{'request.course.id'});
1.50 albertel 1407: &Apache::lonnet::delenv('allowed.vgr');
1.42 www 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) {
1.82 albertel 1412: $attachmenturl=&Apache::lonnet::userfileupload('attachment',undef,'feedback');
1.42 www 1413: }
1414: }
1.6 albertel 1415: # Filter HTML out of message (could be nasty)
1.39 www 1416: my $message=&clear_out_html($ENV{'form.comment'});
1.6 albertel 1417:
1418: # Assemble email
1.8 www 1419: my ($email,$citations)=&assemble_email($feedurl,$message,$prevattempts,
1.40 albertel 1420: $usersaw,$useranswer);
1421:
1.6 albertel 1422: # Who gets this?
1423: my ($typestyle,%to) = &decide_receiver($feedurl);
1424:
1425: # Actually send mail
1.43 www 1426: my ($status,$numsent)=&send_msg($feedurl,$email,$citations,
1427: $attachmenturl,%to);
1.13 www 1428:
1429: # Discussion? Store that.
1430:
1.32 albertel 1431: my $numpost=0;
1.13 www 1432: if ($ENV{'form.discuss'}) {
1.78 raeburn 1433: my $subject = &clear_out_html($ENV{'form.subject'});
1434: $typestyle.=&adddiscuss($symb,$message,0,$attachmenturl,$subject);
1.32 albertel 1435: $numpost++;
1.13 www 1436: }
1.6 albertel 1437:
1.14 www 1438: if ($ENV{'form.anondiscuss'}) {
1.78 raeburn 1439: my $subject = &clear_out_html($ENV{'form.subject'});
1440: $typestyle.=&adddiscuss($symb,$message,1,$attachmenturl,$subject);
1.32 albertel 1441: $numpost++;
1.14 www 1442: }
1443:
1444:
1.6 albertel 1445: # Receipt screen and redirect back to where came from
1.80 raeburn 1446: &redirect_back($r,$feedurl,$typestyle,$numsent,$numpost,$status,$ENV{'form.previous'});
1.6 albertel 1447:
1448: }
1.8 www 1449: } else {
1.7 albertel 1450: # Unable to give feedback
1.6 albertel 1451: &no_redirect_back($r,$feedurl);
1.8 www 1452: }
1453: } else {
1454: # Ambiguous Problem Resource
1.60 albertel 1455: if ( &Apache::lonnet::mod_perl_version() == 2 ) {
1.53 albertel 1456: &Apache::lonnet::cleanenv();
1.58 albertel 1457: }
1.53 albertel 1458: $r->internal_redirect('/adm/ambiguous');
1.6 albertel 1459: }
1.15 www 1460: }
1.6 albertel 1461: return OK;
1.1 www 1462: }
1463:
1464: 1;
1465: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>