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