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